Skip to content

Commit d5a59e7

Browse files
author
ficeto
committed
Merge pull request #10 from esp8266/esp8266
pull latest changes
2 parents b752822 + 2db45e7 commit d5a59e7

File tree

6 files changed

+69
-33
lines changed

6 files changed

+69
-33
lines changed

README.md

+35-18
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ $ ant dist
2727

2828
#### Basic Wiring functions ####
2929

30-
```pinMode```, ```digitalRead```, ```digitalWrite``` work as usual.
30+
```pinMode```, ```digitalRead```, ```digitalWrite```, ```analogWrite``` work as usual.
3131

3232
Pin numbers correspond directly to the esp8266 GPIO pin numbers. To read GPIO2,
3333
call ```digitalRead(2);```
3434

3535
GPIO0-GPIO15 can be ```INPUT```, ```OUTPUT```, ```INPUT_PULLUP```, and ```OUTPUT_OPEN_DRAIN```.
3636
GPIO16 can be ```INPUT``` or ```OUTPUT```.
3737

38-
```analogRead(0)``` reads the value of the ADC channel connected to the TOUT pin.
38+
```analogRead(A0)``` reads the value of the ADC channel connected to the TOUT pin.
39+
40+
```analogWrite(pin, value)``` enables software PWM on the given pin. PWM may be used on pins 0 to 15.
41+
Call ```analogWrite(pin, 0)``` to disable PWM on the pin.
3942

4043
Pin interrupts are supported through ```attachInterrupt```, ```detachInterrupt``` functions.
4144
Interrupts may be attached to any GPIO pin, except GPIO16. Standard Arduino interrupt
@@ -62,7 +65,13 @@ more than 20 milliseconds is not recommended.
6265

6366
```Serial``` object works much the same way as on a regular Arduino. Apart from hardware FIFO (128 bytes for TX and RX) HardwareSerial has additional 256-byte TX and RX buffers. Both transmit and receive is interrupt-driven. Write and read functions only block the sketch execution when the respective FIFO/buffers are full/empty.
6467

65-
By default the diagnostic output from WiFi libraries is disabled when you call ```Serial.begin```. To enable debug output again, call ```Serial.setDebugOutput(true);```
68+
```Serial``` uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling ```Serial.swap();``` after ```Serial.begin();```. Calling ```swap``` again maps UART0 back to GPIO1 and GPIO3.
69+
70+
```Serial1``` uses UART1 which is a transmit-only UART. UART1 TX pin is GPIO2. To use ```Serial1```, call ```Serial1.begin```.
71+
72+
By default the diagnostic output from WiFi libraries is disabled when you call ```Serial.begin```. To enable debug output again, call ```Serial.setDebugOutput(true);```. To redirect debug output to ```Serial1``` instead, call ```Serial1.setDebugOutput(true);```.
73+
74+
Both ```Serial``` and ```Serial1``` objects support 5, 6, 7, 8 data bits, odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the desired mode, call ```Serial.begin(baudrate, SERIAL_8N1);```, ```Serial.begin(baudrate, SERIAL_6E2);```, etc.
6675

6776
#### WiFi(ESP8266WiFi library) ####
6877

@@ -91,6 +100,9 @@ Four samples are provided for this library.
91100

92101
Library for calling functions repeatedly with a certain period. Two examples included.
93102

103+
It is currently not recommended to do blocking IO operations (network, serial, file) from Ticker
104+
callback functions. Instead, set a flag inside the ticker callback and check for that flag inside the loop function.
105+
94106
#### EEPROM ####
95107

96108
This is a bit different from standard EEPROM class. You need to call ```EEPROM.begin(size)```
@@ -101,29 +113,43 @@ Size can be anywhere between 4 and 4096 bytes.
101113
whenever you wish to save changes to flash. ```EEPROM.end()``` will also commit, and will
102114
release the RAM copy of EEPROM contents.
103115

116+
EEPROM library uses one sector of flash located at 0x7b000 for storage.
117+
104118
Three examples included.
105119

106120
#### I2C (Wire library) ####
107121

108-
Only master mode works, and ```Wire.setClock``` has not been verified to give exactly correct frequency.
122+
Wire library currently supports master mode up to approximately 450KHz (at 80 MHz CPU clock).
109123
Before using I2C, pins for SDA and SCL need to be set by calling
110-
```Wire.pins(int sda, int scl)```, i.e. ```Wire.pins(0, 2);``` on ESP-01.
124+
```Wire.begin(int sda, int scl)```, i.e. ```Wire.begin(0, 2);``` on ESP-01.
111125

112126
#### SPI ####
113127

114-
An initial SPI support for the HSPI interface (GPIO12-15) was implemented by [Sermus](https://github.com/Sermus).
115-
The implementation supports the entire Arduino SPI API including transactions, except setting phase and polarity as it's unclear how to set them in ESP8266 yet.
128+
SPI library supports the entire Arduino SPI API including transactions, including setting phase and polarity.
116129

117130
#### ESP-specific APIs ####
118131

119132
APIs related to deep sleep and watchdog timer are available in the ```ESP``` object.
120133

121-
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
134+
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_RF_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
122135

123136
```ESP.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
124137

125138
```ESP.reset()``` resets the CPU.
126139

140+
```ESP.getFreeHeap()``` returns the free heap size.
141+
142+
```ESP.getChipId()``` returns the ESP8266 chip ID as a 32-bit integer.
143+
144+
Several APIs may be used to get flash chip info:
145+
146+
```ESP.getFlashChipId()``` returns the flash chip ID as a 32-bit integer.
147+
148+
```ESP.getFlashChipSize()``` returns the flash chip size, in bytes, as seen by the SDK (may be less than actual size).
149+
150+
```ESP.getFlashChipSpeed(void)``` returns the flash chip frequency, in Hz.
151+
152+
127153
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
128154

129155
Library was adapted to work with ESP8266 by including register definitions into OneWire.h
@@ -133,6 +159,7 @@ instead of the one that comes with the Arduino IDE (this one).
133159
#### mDNS responder (ESP8266mDNS library) ####
134160

135161
Allows the sketch to respond to multicast DNS queries for domain names like "foo.local".
162+
Currently the library only works on STA interface, AP interface is not supported.
136163
See attached example and library README file for details.
137164

138165
#### Other libraries (not included with the IDE)
@@ -150,16 +177,6 @@ Pick the correct serial port.
150177
You need to put ESP8266 into bootloader mode before uploading code (pull GPIO0 low and
151178
toggle power).
152179

153-
### Things not done yet ###
154-
155-
- analogWrite (PWM). ESP8266 has only one hardware PWM source. It is not yet clear how to use it with analogWrite API. Software PWM is also an option, but apparently it causes issues with WiFi connectivity.
156-
- pulseIn
157-
- I2C slave mode
158-
- WiFi.RSSI. SDK doesn't seem to have an API to get RSSI for the current network. So far the only
159-
way to obtain RSSI is to disconnect, perform a scan, and get the RSSI value from there.
160-
- Upload sketches via WiFi. Conceptually and technically simple, but need to figure out how to provide the best UX for this feature.
161-
- Samples for all the libraries
162-
163180
### Issues and support ###
164181

165182
Forum: http://www.esp8266.com/arduino

libraries/EEPROM/EEPROM.cpp

+22-10
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#include "spi_flash.h"
3131
}
3232

33-
#define CONFIG_START_SECTOR 0x3C
33+
#define CONFIG_START_SECTOR 0x7b
3434
#define CONFIG_SECTOR (CONFIG_START_SECTOR + 0)
3535
#define CONFIG_ADDR (SPI_FLASH_SEC_SIZE * CONFIG_SECTOR)
3636

3737
EEPROMClass::EEPROMClass()
38-
: _data(0), _size(0)
38+
: _data(0), _size(0), _dirty(false)
3939
{
4040
}
4141

@@ -67,31 +67,43 @@ void EEPROMClass::end()
6767

6868
uint8_t EEPROMClass::read(int address)
6969
{
70-
if (address < 0 || address >= _size)
70+
if (address < 0 || (size_t)address >= _size)
7171
return 0;
7272

7373
return _data[address];
7474
}
7575

7676
void EEPROMClass::write(int address, uint8_t value)
7777
{
78-
if (address < 0 || address >= _size)
78+
if (address < 0 || (size_t)address >= _size)
7979
return;
8080

8181
_data[address] = value;
8282
_dirty = true;
8383
}
8484

85-
void EEPROMClass::commit()
85+
bool EEPROMClass::commit()
8686
{
87-
if (!_size || !_dirty)
88-
return;
87+
bool ret = false;
88+
if (!_size)
89+
return false;
90+
if(!_dirty)
91+
return true;
8992

9093
ETS_UART_INTR_DISABLE();
91-
spi_flash_erase_sector(CONFIG_SECTOR);
92-
spi_flash_write(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size);
94+
if(spi_flash_erase_sector(CONFIG_SECTOR) == SPI_FLASH_RESULT_OK) {
95+
if(spi_flash_write(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size) == SPI_FLASH_RESULT_OK) {
96+
_dirty = false;
97+
ret = true;
98+
}
99+
}
93100
ETS_UART_INTR_ENABLE();
94-
_dirty = false;
101+
return ret;
102+
}
103+
104+
uint8_t * EEPROMClass::getDataPtr()
105+
{
106+
return &_data[0];
95107
}
96108

97109

libraries/EEPROM/EEPROM.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ class EEPROMClass
3333
void begin(size_t size);
3434
uint8_t read(int address);
3535
void write(int address, uint8_t val);
36-
void commit();
36+
bool commit();
3737
void end();
3838

39+
uint8_t * getDataPtr();
40+
3941
template<typename T> T &get(int address, T &t)
4042
{
4143
if (address < 0 || address + sizeof(T) > _size)

libraries/Wire/Wire.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ TwoWire::TwoWire(){}
5252
// Public Methods //////////////////////////////////////////////////////////////
5353

5454
void TwoWire::begin(int sda, int scl){
55-
twi_init(sda, scl);
56-
flush();
55+
twi_init(sda, scl);
56+
flush();
57+
}
58+
59+
void TwoWire::pins(int sda, int scl){
60+
twi_init(sda, scl);
5761
}
5862

5963
void TwoWire::begin(void){

libraries/Wire/Wire.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TwoWire : public Stream
5151
public:
5252
TwoWire();
5353
void begin(int sda, int scl);
54+
void pins(int sda, int scl) __attribute__((deprecated)); // use begin(sda, scl) in new code
5455
void begin();
5556
void begin(uint8_t);
5657
void begin(int);

platform.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ recipe.objcopy.eep.pattern=
7474
## Create hex
7575
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
7676

77-
recipe.objcopy.hex.pattern="{compiler.tools.path}{compiler.esptool.cmd}" -eo "{build.path}/{build.project_name}.elf" -bo "{build.path}/{build.project_name}_00000.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bs .data -bs .rodata -bc -ec -eo "{build.path}/{build.project_name}.elf" -es .irom0.text "{build.path}/{build.project_name}_40000.bin" -ec
77+
recipe.objcopy.hex.pattern="{compiler.tools.path}{compiler.esptool.cmd}" -eo "{build.path}/{build.project_name}.elf" -bo "{build.path}/{build.project_name}_00000.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bs .data -bs .rodata -bc -ec -eo "{build.path}/{build.project_name}.elf" -es .irom0.text "{build.path}/{build.project_name}_10000.bin" -ec
7878

7979
## Compute size
8080
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
@@ -91,4 +91,4 @@ tools.esptool.path={runtime.ide.path}/hardware/tools/esp8266
9191
tools.esptool.upload.protocol=esp
9292
tools.esptool.upload.params.verbose=-vv
9393
tools.esptool.upload.params.quiet=
94-
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x40000 -cf "{build.path}/{build.project_name}_40000.bin"
94+
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x10000 -cf "{build.path}/{build.project_name}_10000.bin"

0 commit comments

Comments
 (0)