Skip to content

Commit e7b62b6

Browse files
committed
Update core
-Core libraries -Example libraries -Sketches -Add new libraries and sketches
1 parent 08a8468 commit e7b62b6

File tree

468 files changed

+22234
-10060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

468 files changed

+22234
-10060
lines changed

cores/esp32/Arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#define interrupts() sei()
7979
#define noInterrupts() cli()
8080

81-
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
81+
#define clockCyclesPerMicrosecond() ( (long int)getCpuFrequencyMhz() )
8282
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
8383
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
8484

@@ -88,7 +88,7 @@
8888
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
8989
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
9090
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
91-
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
91+
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
9292

9393
// avr-libc defines _NOP() since 1.6.2
9494
#ifndef _NOP

cores/esp32/Esp.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,33 @@ uint8_t EspClass::getChipRevision(void)
218218
return chip_info.revision;
219219
}
220220

221+
const char * EspClass::getChipModel(void)
222+
{
223+
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
224+
uint32_t pkg_ver = chip_ver & 0x7;
225+
switch (pkg_ver) {
226+
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 :
227+
return "ESP32-D0WDQ6";
228+
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 :
229+
return "ESP32-D0WDQ5";
230+
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 :
231+
return "ESP32-D2WDQ5";
232+
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 :
233+
return "ESP32-PICO-D2";
234+
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 :
235+
return "ESP32-PICO-D4";
236+
default:
237+
return "Unknown";
238+
}
239+
}
240+
241+
uint8_t EspClass::getChipCores(void)
242+
{
243+
esp_chip_info_t chip_info;
244+
esp_chip_info(&chip_info);
245+
return chip_info.cores;
246+
}
247+
221248
const char * EspClass::getSdkVersion(void)
222249
{
223250
return esp_get_idf_version();
@@ -309,6 +336,20 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size)
309336
return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
310337
}
311338

339+
bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size)
340+
{
341+
return esp_partition_erase_range(partition, offset, size) == ESP_OK;
342+
}
343+
344+
bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size)
345+
{
346+
return esp_partition_write(partition, offset, data, size) == ESP_OK;
347+
}
348+
349+
bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size)
350+
{
351+
return esp_partition_read(partition, offset, data, size) == ESP_OK;
352+
}
312353

313354
uint64_t EspClass::getEfuseMac(void)
314355
{

cores/esp32/Esp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define ESP_H
2222

2323
#include <Arduino.h>
24+
#include <esp_partition.h>
2425

2526
/**
2627
* AVR macros for WDT managment
@@ -75,6 +76,8 @@ class EspClass
7576
uint32_t getMaxAllocPsram();
7677

7778
uint8_t getChipRevision();
79+
const char * getChipModel();
80+
uint8_t getChipCores();
7881
uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); }
7982
inline uint32_t getCycleCount() __attribute__((always_inline));
8083
const char * getSdkVersion();
@@ -97,6 +100,10 @@ class EspClass
97100
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
98101
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
99102

103+
bool partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size);
104+
bool partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size);
105+
bool partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size);
106+
100107
uint64_t getEfuseMac();
101108

102109
};

cores/esp32/HardwareSerial.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
5353
}
5454

5555
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
56+
_tx_pin = txPin;
57+
_rx_pin = rxPin;
5658

5759
if(!baud) {
5860
uartStartDetectBaudrate(_uart);
@@ -70,6 +72,8 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
7072
} else {
7173
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
7274
_uart = NULL;
75+
_tx_pin = 255;
76+
_rx_pin = 255;
7377
}
7478
}
7579
}
@@ -84,7 +88,8 @@ void HardwareSerial::end()
8488
if(uartGetDebug() == _uart_nr) {
8589
uartSetDebug(0);
8690
}
87-
uartEnd(_uart);
91+
log_v("pins %d %d",_tx_pin, _rx_pin);
92+
uartEnd(_uart, _tx_pin, _rx_pin);
8893
_uart = 0;
8994
}
9095

@@ -131,11 +136,34 @@ int HardwareSerial::read(void)
131136
return -1;
132137
}
133138

134-
void HardwareSerial::flush()
139+
// read characters into buffer
140+
// terminates if size characters have been read, or no further are pending
141+
// returns the number of characters placed in the buffer
142+
// the buffer is NOT null terminated.
143+
size_t HardwareSerial::read(uint8_t *buffer, size_t size)
144+
{
145+
size_t avail = available();
146+
if (size < avail) {
147+
avail = size;
148+
}
149+
size_t count = 0;
150+
while(count < avail) {
151+
*buffer++ = uartRead(_uart);
152+
count++;
153+
}
154+
return count;
155+
}
156+
157+
void HardwareSerial::flush(void)
135158
{
136159
uartFlush(_uart);
137160
}
138161

162+
void HardwareSerial::flush(bool txOnly)
163+
{
164+
uartFlushTxOnly(_uart, txOnly);
165+
}
166+
139167
size_t HardwareSerial::write(uint8_t c)
140168
{
141169
uartWrite(_uart, c);
@@ -156,3 +184,8 @@ HardwareSerial::operator bool() const
156184
{
157185
return true;
158186
}
187+
188+
void HardwareSerial::setRxInvert(bool invert)
189+
{
190+
uartSetRxInvert(_uart, invert);
191+
}

cores/esp32/HardwareSerial.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,19 @@ class HardwareSerial: public Stream
6262
int availableForWrite(void);
6363
int peek(void);
6464
int read(void);
65+
size_t read(uint8_t *buffer, size_t size);
66+
inline size_t read(char * buffer, size_t size)
67+
{
68+
return read((uint8_t*) buffer, size);
69+
}
6570
void flush(void);
71+
void flush( bool txOnly);
6672
size_t write(uint8_t);
6773
size_t write(const uint8_t *buffer, size_t size);
68-
74+
inline size_t write(const char * buffer, size_t size)
75+
{
76+
return write((uint8_t*) buffer, size);
77+
}
6978
inline size_t write(const char * s)
7079
{
7180
return write((uint8_t*) s, strlen(s));
@@ -91,16 +100,22 @@ class HardwareSerial: public Stream
91100

92101
size_t setRxBufferSize(size_t);
93102
void setDebugOutput(bool);
103+
104+
void setRxInvert(bool);
94105

95106
protected:
96107
int _uart_nr;
97108
uart_t* _uart;
109+
uint8_t _tx_pin;
110+
uint8_t _rx_pin;
98111
};
99112

113+
extern void serialEventRun(void) __attribute__((weak));
114+
100115
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
101116
extern HardwareSerial Serial;
102117
extern HardwareSerial Serial1;
103118
extern HardwareSerial Serial2;
104119
#endif
105120

106-
#endif
121+
#endif // HardwareSerial_h

cores/esp32/Print.cpp

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,37 @@ size_t Print::print(unsigned int n, int base)
110110
}
111111

112112
size_t Print::print(long n, int base)
113+
{
114+
int t = 0;
115+
if (base == 10 && n < 0) {
116+
t = print('-');
117+
n = -n;
118+
}
119+
return printNumber(static_cast<unsigned long>(n), base) + t;
120+
}
121+
122+
size_t Print::print(unsigned long n, int base)
113123
{
114124
if(base == 0) {
115125
return write(n);
116-
} else if(base == 10) {
117-
if(n < 0) {
118-
int t = print('-');
119-
n = -n;
120-
return printNumber(n, 10) + t;
121-
}
122-
return printNumber(n, 10);
123126
} else {
124127
return printNumber(n, base);
125128
}
126129
}
127130

128-
size_t Print::print(unsigned long n, int base)
131+
size_t Print::print(long long n, int base)
129132
{
130-
if(base == 0) {
133+
int t = 0;
134+
if (base == 10 && n < 0) {
135+
t = print('-');
136+
n = -n;
137+
}
138+
return printNumber(static_cast<unsigned long long>(n), base) + t;
139+
}
140+
141+
size_t Print::print(unsigned long long n, int base)
142+
{
143+
if (base == 0) {
131144
return write(n);
132145
} else {
133146
return printNumber(n, base);
@@ -226,6 +239,20 @@ size_t Print::println(unsigned long num, int base)
226239
return n;
227240
}
228241

242+
size_t Print::println(long long num, int base)
243+
{
244+
size_t n = print(num, base);
245+
n += println();
246+
return n;
247+
}
248+
249+
size_t Print::println(unsigned long long num, int base)
250+
{
251+
size_t n = print(num, base);
252+
n += println();
253+
return n;
254+
}
255+
229256
size_t Print::println(double num, int digits)
230257
{
231258
size_t n = print(num, digits);
@@ -251,7 +278,7 @@ size_t Print::println(struct tm * timeinfo, const char * format)
251278

252279
size_t Print::printNumber(unsigned long n, uint8_t base)
253280
{
254-
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
281+
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
255282
char *str = &buf[sizeof(buf) - 1];
256283

257284
*str = '\0';
@@ -262,11 +289,34 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
262289
}
263290

264291
do {
265-
unsigned long m = n;
292+
char c = n % base;
293+
n /= base;
294+
295+
*--str = c < 10 ? c + '0' : c + 'A' - 10;
296+
} while (n);
297+
298+
return write(str);
299+
}
300+
301+
size_t Print::printNumber(unsigned long long n, uint8_t base)
302+
{
303+
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
304+
char* str = &buf[sizeof(buf) - 1];
305+
306+
*str = '\0';
307+
308+
// prevent crash if called with base == 1
309+
if (base < 2) {
310+
base = 10;
311+
}
312+
313+
do {
314+
auto m = n;
266315
n /= base;
267316
char c = m - base * n;
317+
268318
*--str = c < 10 ? c + '0' : c + 'A' - 10;
269-
} while(n);
319+
} while (n);
270320

271321
return write(str);
272322
}

cores/esp32/Print.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Print
3636
private:
3737
int write_error;
3838
size_t printNumber(unsigned long, uint8_t);
39+
size_t printNumber(unsigned long long, uint8_t);
3940
size_t printFloat(double, uint8_t);
4041
protected:
4142
void setWriteError(int err = 1)
@@ -72,6 +73,11 @@ class Print
7273
}
7374

7475
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
76+
77+
// add availableForWrite to make compatible with Arduino Print.h
78+
// default to zero, meaning "a single write may block"
79+
// should be overriden by subclasses with buffering
80+
virtual int availableForWrite() { return 0; }
7581
size_t print(const __FlashStringHelper *);
7682
size_t print(const String &);
7783
size_t print(const char[]);
@@ -81,6 +87,8 @@ class Print
8187
size_t print(unsigned int, int = DEC);
8288
size_t print(long, int = DEC);
8389
size_t print(unsigned long, int = DEC);
90+
size_t print(long long, int = DEC);
91+
size_t print(unsigned long long, int = DEC);
8492
size_t print(double, int = 2);
8593
size_t print(const Printable&);
8694
size_t print(struct tm * timeinfo, const char * format = NULL);
@@ -94,6 +102,8 @@ class Print
94102
size_t println(unsigned int, int = DEC);
95103
size_t println(long, int = DEC);
96104
size_t println(unsigned long, int = DEC);
105+
size_t println(long long, int = DEC);
106+
size_t println(unsigned long long, int = DEC);
97107
size_t println(double, int = 2);
98108
size_t println(const Printable&);
99109
size_t println(struct tm * timeinfo, const char * format = NULL);

0 commit comments

Comments
 (0)