Skip to content

Commit

Permalink
fix: SPIPortManager für ESP32S3 (1.Test)
Browse files Browse the repository at this point in the history
  • Loading branch information
skippermeister committed Jul 31, 2024
1 parent 95e1759 commit a2c91ef
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 15 deletions.
132 changes: 132 additions & 0 deletions docs/DeviceProfiles/ESP32_S3_USB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[
{
"name": "ESP32S3USB CMT+NRF24+SH1106",
"nrf24":{
"miso": 9,
"mosi": 10,
"clk": 11,
"irq": 12,
"en": 13,
"cs": 14
},
"cmt":{
"clk": 4,
"cs": 5,
"fcs": 6,
"sdio": 7,
"gpio2": 15,
"gpio3": 16
},
"victron": {
"rs232_rx": 17,
"rs232_tx": 18,
"rs232_rx2": 8,
"rs232_tx2": 3
},
"battery": {
"rs485_rx": 1,
"rs485_tx": 2,
"rs485_rts": 42,
"wakeup": -1
},
"charger":{
"can0_rx":41,
"can0_tx":40
},
"mcp2515": {
"miso": -1,
"mosi": -1,
"clk": -1,
"irq": -1,
"cs": -1
},
"led": {
"led0": -1,
"led1": -1,
"rgb": 38
},
"display": {
"type": 0,
"data": -1,
"clk": -1,
"cs": -1,
"reset": -1,
"busy": -1,
"dc": -1
},
"powermeter": {
"sdm_rs485_rx": 48,
"sdm_rs485_tx": 47,
"sdm_rs485_rts": 45
},
"batteryConnectedInverter":{
"pre_charge":39,
"full_power":21
}
},
{
"name": "ESP32S3USB CMT+NRF24+disabled",
"nrf24":{
"miso": 13,
"mosi": 12,
"clk": 11,
"irq": 14,
"en": 9,
"cs": 10
},
"cmt":{
"clk": 4,
"cs": 5,
"fcs": 6,
"sdio": 7,
"gpio2": 15,
"gpio3": 16
},
"victron": {
"rs232_rx": 17,
"rs232_tx": 18,
"rs232_rx2": 8,
"rs232_tx2": 3
},
"battery": {
"rs485_rx": 1,
"rs485_tx": 2,
"rs485_rts": 42,
"wakeup": -1
},
"charger":{
"can0_rx":41,
"can0_tx":40
},
"mcp2515": {
"miso": -1,
"mosi": -1,
"clk": -1,
"irq": -1,
"cs": -1
},
"led": {
"led0": -1,
"led1": -1,
"rgb": 38
},
"display": {
"type": 0,
"data": -1,
"clk": -1,
"cs": -1,
"reset": -1,
"busy": -1,
"dc": -1
},
"powermeter": {
"sdm_rs485_rx": 48,
"sdm_rs485_tx": 47,
"sdm_rs485_rts": 45
},
"batteryConnectedInverter":{
"pre_charge":39,
"full_power":21
}
}
]
62 changes: 62 additions & 0 deletions docs/DeviceProfiles/ESP32_S3_USB_CMT_HUAWEI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"name": "ESP32S3USB CMT+HUAWEI+SH1106",
"nrf24": {
"miso": -1,
"mosi": -1,
"clk": -1,
"irq": -1,
"en": -1,
"cs": -1
},
"huawei": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"cs": 37,
"power": 38
},
"cmt": {
"clk": 6,
"cs": 4,
"fcs": 21,
"sdio": 5,
"gpio2": 3,
"gpio3": 8
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"victron": {
"rx": 9,
"tx": 10,
"rx2": 11,
"tx2": 12
},
"battery": {
"rx": 13,
"tx": 14
},
"led": {
"led0": 17,
"led1": 18
},
"display": {
"type": 3,
"data": 2,
"clk": 1
},
"powermeter": {
"rx": 15,
"tx": 16,
"dere": 7
}
}
]
15 changes: 12 additions & 3 deletions include/SPIPortManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ class SPIPortManagerClass {
std::optional<uint8_t> allocatePort(std::string const& owner);
void freePort(std::string const& owner);

private:
// the amount of SPIs available on supported ESP32 chips
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
static size_t constexpr _num_controllers = 4;
static size_t constexpr _num_controllers = 2;
#else
static size_t constexpr _num_controllers = 1;
#endif
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
static int8_t constexpr _start_spi_num = 0;
static int8_t constexpr _offset_spi_num = 1;
#else
static size_t constexpr _num_controllers = 3;
static int8_t constexpr _start_spi_num = 2;
static int8_t constexpr _offset_spi_num = -1;
#endif

private:

std::array<std::string, _num_controllers> _ports = { "" };
};

Expand Down
117 changes: 112 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = my_very_special_board
;default_envs = my_very_special_board
;default_envs = opendtufusionv2
;default_envs = generic_esp32s3_usb
default_envs = generic_esp32s3_16mb_psram_usb
;default_envs = generic_esp32_4mb_no_ota
extra_configs =
platformio_override.ini
Expand Down Expand Up @@ -221,27 +221,134 @@ build_flags = ${env.build_flags}
-DUSE_PROMETHEUS=1
-DUSE_HASS=1


[env:generic_esp32s3_usb]
board = esp32-s3-devkitc-1
board_build.partitions = partitions_custom_16mb.csv
upload_protocol = esp-builtin
monitor_port = COM6
;upload_port = COM5
build_flags = ${env.build_flags}
-DUSE_RADIO_NRF=1
-DNRF24_PIN_MISO=-1
-DNRF24_PIN_MOSI=-1
-DNRF24_PIN_SCLK=-1
-DNRF24_PIN_IRQ=-1
-DNRF24_PIN_CE=-1
-DNRF24_PIN_CS=-1
-DUSE_RADIO_CMT=1
-DCMT_CLK=-1
-DCMT_CS=-1
-DCMT_FCS=-1
-DCMT_GPIO2=-1
-DCMT_GPIO3=-1
-DCMT_SDIO=-1
-DUSE_PYLONTECH_RS485_RECEIVER=1
-DBATTERY_PIN_RX=-1 ; RS485 HW Serial (Pylontech Battery via RS485, Daly BMS via RS485/RS232 or JK BMS via RS485/RS232)
-DBATTERY_PIN_TX=-1
-DBATTERY_PIN_RTS=-1
-DBATTERY_PIN_WAKEUP=-1
-DUSE_MQTT_BATTERY=1
-DUSE_JKBMS_CONTROLLER=1
-DUSE_DALYBMS_CONTROLLER=1
-DUSE_VICTRON_SMART_SHUNT=1
; -DUSE_PYTES_CAN_RECEIVER=1
-DUSE_PYTES_CAN_RECEIVER=1
-DCHARGER_USE_CAN0=1
-DCAN0_PIN_RX=-1 ; CAN0 connected to Meanwell Charger
-DCAN0_PIN_TX=-1 ; CAN0 connected to Meanwell Charger
-DMCP2515_PIN_MISO=-1
-DMCP2515_PIN_MOSI=-1
-DMCP2515_PIN_SCLK=-1
-DMCP2515_PIN_CS=-1
-DMCP2515_PIN_IRQ=-1
; -DCHARGER_HUAWEI=1
-DVICTRON_PIN_TX=-1
-DVICTRON_PIN_RX=-1
-DVICTRON_PIN_TX2=-1
-DVICTRON_PIN_RX2=-1
-DVICTRON_PIN_TX3=-1
-DVICTRON_PIN_RX3=-1
-DUSE_LED_SINGLE=1
-DLED0=-1 ; blue LED
-DLED1=-1 ; white LED
; -DUSE_LED_STRIP=1
; -DLED_RGB=-1
-DUSE_DISPLAY_GRAPHIC=1
-DDISPLAY_TYPE=0 ; SSD1306 I2C
-DDISPLAY_DATA=-1
-DDISPLAY_CLK=-1
-DPRE_CHARGE_PIN=-1 ; MosFET Transitor
-DFULL_POWER_PIN=-1 ; MosFET Transitor
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
-DUSE_PROMETHEUS=1
-DUSE_HASS=1

[env:generic_esp32s3_16mb_psram_usb]
board = esp32-s3-devkitc-1
;board = esp32-s3-devkitc-1-n16r8v
;board_upload.flash_size = 16MB
board_build.partitions = partitions_custom_16mb.csv
;board_build.arduino.memory_type = qio_opi ; NEEDED FOR PSRAM also dio_qspi/qsi_qspi for other configs
upload_protocol = esp-builtin
monitor_port = COM6
;upload_port = COM5
build_flags = ${env.build_flags}
-DUSE_RADIO_NRF=1
-DNRF24_PIN_MISO=-1
-DNRF24_PIN_MOSI=-1
-DNRF24_PIN_SCLK=-1
-DNRF24_PIN_IRQ=-1
-DNRF24_PIN_CE=-1
-DNRF24_PIN_CS=-1
-DUSE_RADIO_CMT=1
-DCMT_CLK=-1
-DCMT_CS=-1
-DCMT_FCS=-1
-DCMT_GPIO2=-1
-DCMT_GPIO3=-1
-DCMT_SDIO=-1
-DUSE_PYLONTECH_RS485_RECEIVER=1
-DBATTERY_PIN_RX=-1 ; RS485 HW Serial (Pylontech Battery via RS485, Daly BMS via RS485/RS232 or JK BMS via RS485/RS232)
-DBATTERY_PIN_TX=-1
-DBATTERY_PIN_RTS=-1
-DBATTERY_PIN_WAKEUP=-1
-DUSE_MQTT_BATTERY=1
-DUSE_JKBMS_CONTROLLER=1
-DUSE_DALYBMS_CONTROLLER=1
-DUSE_VICTRON_SMART_SHUNT=1
-DUSE_PYTES_CAN_RECEIVER=1
-DCHARGER_USE_CAN0=1
-DCAN0_PIN_RX=-1 ; CAN0 connected to Meanwell Charger
-DCAN0_PIN_TX=-1 ; CAN0 connected to Meanwell Charger
-DMCP2515_PIN_MISO=-1
-DMCP2515_PIN_MOSI=-1
-DMCP2515_PIN_SCLK=-1
-DMCP2515_PIN_CS=-1
-DMCP2515_PIN_IRQ=-1
; -DCHARGER_HUAWEI=1
-DVICTRON_PIN_TX=-1
-DVICTRON_PIN_RX=-1
-DVICTRON_PIN_TX2=-1
-DVICTRON_PIN_RX2=-1
-DVICTRON_PIN_TX3=-1
-DVICTRON_PIN_RX3=-1
-DUSE_LED_SINGLE=1
-DLED0=-1 ; blue LED
-DLED1=-1 ; white LED
; -DUSE_LED_STRIP=1
; -DLED_RGB=-1
-DUSE_DISPLAY_GRAPHIC=1
-DDISPLAY_TYPE=0 ; SSD1306 I2C
-DDISPLAY_DATA=-1
-DDISPLAY_CLK=-1
-DPRE_CHARGE_PIN=-1 ; MosFET Transitor
-DFULL_POWER_PIN=-1 ; MosFET Transitor
-DUSE_PROMETHEUS=1
-DUSE_HASS=1
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1

-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue

[env:olimex_esp32_poe]
; https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware
Expand Down
4 changes: 2 additions & 2 deletions src/InverterSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void InverterSettingsClass::init(Scheduler& scheduler)
#ifdef USE_RADIO_CMT
if (PinMapping.isValidCmt2300Config()) {
auto oSPInum = SPIPortManager.allocatePort("CMT2300A");
if (oSPInum) { // SPInum_HOST is SPInum-1
Hoymiles.initCMT(*oSPInum - 1, pin.cmt_sdio, pin.cmt_clk, pin.cmt_cs, pin.cmt_fcs, pin.cmt_gpio2, pin.cmt_gpio3);
if (oSPInum) {
Hoymiles.initCMT(*oSPInum + SPIPortManagerClass::_offset_spi_num, pin.cmt_sdio, pin.cmt_clk, pin.cmt_cs, pin.cmt_fcs, pin.cmt_gpio2, pin.cmt_gpio3);
MessageOutput.println(" Setting CMT target frequency... ");
Hoymiles.getRadioCmt()->setInverterTargetFrequency(config.Dtu.Cmt.Frequency);
}
Expand Down
Loading

0 comments on commit a2c91ef

Please sign in to comment.