8000 add esp32s2 support · marcelkottmann/esp32-javascript@6c41b68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c41b68

Browse files
add esp32s2 support
1 parent aaa10ae commit 6c41b68

File tree

293 files changed

+92520
-713
lines changed

Some content is hidden

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

293 files changed

+92520
-713
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.5)
55
# set BOARD_VARIANT to define your ESP32 board. Valid values
66
# are the directory names below ./components/arduino-esp32/include/variants/
77
# or esp32-javascript/include/variants/
8-
set(ENV{BOARD_VARIANT} "../esp32-javascript/include/variants/my")
8+
set(ENV{BOARD_VARIANT} "../arduino-esp32/include/variants/esp32s2")
99

1010
# set ESP32_JS_PROJECT_NAME to define your project component name.
1111
# Place your component below ./components directory. Set to ""
@@ -14,6 +14,7 @@ set(ENV{ESP32_JS_PROJECT_NAME} "")
1414
#################################################
1515

1616
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
17+
add_compile_options(-Wp,-w)
1718
project(esp32-javascript)
1819

1920
add_custom_target(cp_modules ALL

components/arduino-esp32/Esp.cpp

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,33 @@
1919

2020
#include "Arduino.h"
2121
#include "Esp.h"
22-
#include "rom/spi_flash.h"
2322
#include "esp_sleep.h"
2423
#include "esp_spi_flash.h"
2524
#include <memory>
2625
#include <soc/soc.h>
27-
#include <soc/efuse_reg.h>
2826
#include <esp_partition.h>
2927
extern "C" {
3028
#include "esp_ota_ops.h"
3129
#include "esp_image_format.h"
3230
}
3331
#include <MD5Builder.h>
3432

33+
#include "esp_system.h"
34+
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
35+
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
36+
#include "esp32/rom/spi_flash.h"
37+
#include "soc/efuse_reg.h"
38+
#elif CONFIG_IDF_TARGET_ESP32S2
39+
#include "esp32s2/rom/spi_flash.h"
40+
#elif CONFIG_IDF_TARGET_ESP32C3
41+
#include "esp32c3/rom/spi_flash.h"
42+
#else
43+
#error Target CONFIG_IDF_TARGET is not supported
44+
#endif
45+
#else // ESP32 Before IDF 4.0
46+
#include "rom/spi_flash.h"
47+
#endif
48+
3549
/**
3650
* User-defined Literals
3751
* usage:
@@ -121,24 +135,36 @@ uint32_t EspClass::getMaxAllocHeap(void)
121135

122136
uint32_t EspClass::getPsramSize(void)
123137
{
124-
multi_heap_info_t info;
125-
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
126-
return info.total_free_bytes + info.total_allocated_bytes;
138+
if(psramFound()){
139+
multi_heap_info_t info;
140+
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
141+
return info.total_free_bytes + info.total_allocated_bytes;
142+
}
143+
return 0;
127144
}
128145

129146
uint32_t EspClass::getFreePsram(void)
130147
{
131-
return heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
148+
if(psramFound()){
149+
return heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
150+
}
151+
return 0;
132152
}
133153

134154
uint32_t EspClass::getMinFreePsram(void)
135155
{
136-
return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM);
156+
if(psramFound()){
157+
return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM);
158+
}
159+
return 0;
137160
}
138161

139162
uint32_t EspClass::getMaxAllocPsram(void)
140163
{
141-
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
164+
if(psramFound()){
165+
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
166+
}
167+
return 0;
142168
}
143169

144170
static uint32_t sketchSize(sketchSize_t response) {
@@ -218,6 +244,43 @@ uint8_t EspClass::getChipRevision(void)
218244
return chip_info.revision;
219245
}
220246

247+
const char * EspClass::getChipModel(void)
248+
{
249+
#if CONFIG_IDF_TARGET_ESP32
250+
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
251+
uint32_t pkg_ver = chip_ver & 0x7;
252+
switch (pkg_ver) {
253+
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 :
254+
return "ESP32-D0WDQ6";
255+
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 :
256+
return "ESP32-D0WDQ5";
257+
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 :
258+
return "ESP32-D2WDQ5";
259+
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 :
260+
return "ESP32-PICO-D2";
261+
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 :
262+
return "ESP32-PICO-D4";
263+
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302 :
264+
return "ESP32-PICO-V3-02";
265+
default:
266+
return "Unknown";
267+
}
268+
#elif CONFIG_IDF_TARGET_ESP32S2
269+
return "ESP32-S2";
270+
#elif CONFIG_IDF_TARGET_ESP32S3
271+
return "ESP32-S3";
272+
#elif CONFIG_IDF_TARGET_ESP32C3
273+
return "ESP32-C3";
274+
#endif
275+
}
276+
277+
uint8_t EspClass::getChipCores(void)
278+
{
279+
esp_chip_info_t chip_info;
280+
esp_chip_info(&chip_info);
281+
return chip_info.cores;
282+
}
283+
221284
const char * EspClass::getSdkVersion(void)
222285
{
223286
return esp_get_idf_version();
@@ -309,6 +372,20 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size)
309372
return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
310373
}
311374

375+
bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size)
376+
{
377+
return esp_partition_erase_range(partition, offset, size) == ESP_OK;
378+
}
379+
380+
bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size)
381+
{
382+
return esp_partition_write(partition, offset, data, size) == ESP_OK;
383+
}
384+
385+
bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size)
386+
{
387+
return esp_partition_read(partition, offset, data, size) == ESP_OK;
388+
}
312389

313390
uint64_t EspClass::getEfuseMac(void)
314391
{

components/arduino-esp32/FunctionalInterrupt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern "C"
1616
extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type, bool functional);
1717
}
1818

19-
void IRAM_ATTR interruptFunctional(void* arg)
19+
void ARDUINO_ISR_ATTR interruptFunctional(void* arg)
2020
{
2121
InterruptArgStructure* localArg = (InterruptArgStructure*)arg;
2222
if (localArg->interruptFunction)

components/arduino-esp32/HardwareSerial.cpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "pins_arduino.h"
77
#include "HardwareSerial.h"
88

9+
#if CONFIG_IDF_TARGET_ESP32
10+
911
#ifndef RX1
1012
#define RX1 9
1113
#endif
@@ -22,15 +24,33 @@
2224
#define TX2 17
2325
#endif
2426

27+
#else
28+
29+
#ifndef RX1
30+
#define RX1 18
31+
#endif
32+
33+
#ifndef TX1
34+
#define TX1 17
35+
#endif
36+
37+
#endif
38+
2539
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
40+
#if ARDUINO_SERIAL_PORT //Serial used for USB CDC
41+
HardwareSerial Serial0(0);
42+
#else
2643
HardwareSerial Serial(0);
44+
#endif
2745
HardwareSerial Serial1(1);
46+
#if CONFIG_IDF_TARGET_ESP32
2847
HardwareSerial Serial2(2);
2948
#endif
49+
#endif
3050

3151
HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL) {}
3252

33-
void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms)
53+
void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd)
3454
{
3555
if(0 > _uart_nr || _uart_nr > 2) {
3656
log_e("Serial number is invalid, please use 0, 1 or 2");
@@ -40,19 +60,30 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
4060
end();
4161
}
4262
if(_uart_nr == 0 && rxPin < 0 && txPin < 0) {
63+
#if CONFIG_IDF_TARGET_ESP32
4364
rxPin = 3;
4465
txPin = 1;
66+
#elif CONFIG_IDF_TARGET_ESP32S2
67+
rxPin = 44;
68+
txPin = 43;
69+
#elif CONFIG_IDF_TARGET_ESP32C3
70+
rxPin = 20;
71+
txPin = 21;
72+
#endif
4573
}
4674
if(_uart_nr == 1 && rxPin < 0 && txPin < 0) {
4775
rxPin = RX1;
4876
txPin = TX1;
4977
}
78+
#if CONFIG_IDF_TARGET_ESP32
5079
if(_uart_nr == 2 && rxPin < 0 && txPin < 0) {
5180
rxPin = RX2;
5281
txPin = TX2;
5382
}
54-
55-
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
83+
#endif
84+
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert, rxfifo_full_thrhd);
85+
_tx_pin = txPin;
86+
_rx_pin = rxPin;
5687

5788
if(!baud) {
5889
uartStartDetectBaudrate(_uart);
@@ -66,10 +97,12 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
6697

6798
if(detectedBaudRate) {
6899
delay(100); // Give some time...
69-
_uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, 256, invert);
100+
_uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, 256, invert, rxfifo_full_thrhd);
70101
} else {
71102
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
72103
_uart = NULL;
104+
_tx_pin = 255;
105+
_rx_pin = 255;
73106
}
74107
}
75108
}
@@ -84,7 +117,9 @@ void HardwareSerial::end()
84117
if(uartGetDebug() == _uart_nr) {
85118
uartSetDebug(0);
86119
}
87-
uartEnd(_uart);
120+
delay(10);
121+
log_v("pins %d %d",_tx_pin, _rx_pin);
122+
uartEnd(_uart, _tx_pin, _rx_pin);
88123
_uart = 0;
89124
}
90125

@@ -101,7 +136,7 @@ void HardwareSerial::setDebugOutput(bool en)
101136
uartSetDebug(_uart);
102137
} else {
103138
if(uartGetDebug() == _uart_nr) {
104-
uartSetDebug(0);
139+
uartSetDebug(NULL);
105140
}
106141
}
107142
}
@@ -179,3 +214,8 @@ HardwareSerial::operator bool() const
179214
{
180215
return true;
181216
}
217+
218+
void HardwareSerial::setRxInvert(bool invert)
219+
{
220+
uartSetRxInvert(_uart, invert);
221+
}

0 commit comments

Comments
 (0)
0