Skip to content

Commit

Permalink
ESP32 support (#1344)
Browse files Browse the repository at this point in the history
* esp-idf

* fix, add s2, s3

* fix + ci

* fix naming

* ota

* adc

* reboot reason

* wdt + uart

* dht + ds1820

* fix esp32

* pwm

* uart hack

* fix build

* charts

* increase stack size

* tests

* fix timer

* optimize

* further c2 optimization

* gpio test, wifi reconnect fix

* gpio test

* Revert ledc freq

* cht83xx, increase inttemp stack size

* fix

* S3 fix, enable sht3x, pwm freq selection

* gpio & i2c fix attempt

* s2 fix

* Update defines for DHT

* Update sdk

---------

Co-authored-by: openshwprojects <85486843+openshwprojects@users.noreply.github.com>
  • Loading branch information
NonPIayerCharacter and openshwprojects authored Nov 6, 2024
1 parent df400e3 commit c505156
Show file tree
Hide file tree
Showing 49 changed files with 2,549 additions and 379 deletions.
46 changes: 45 additions & 1 deletion .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
echo "::set-output name=short_ref::${BRANCHTRANSLATED}"
echo "::set-output name=sha_short::SHA-$(git rev-parse --short=12 HEAD)"
echo "::set-output name=version::${VERSION}"
build2:
name: Build Simulator
needs: refs
Expand Down Expand Up @@ -101,6 +102,7 @@ jobs:
with:
name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }}
path: output/${{ needs.refs.outputs.version }}/obkSimulator_${{ needs.refs.outputs.version }}.zip

build:
name: Build
needs: refs
Expand Down Expand Up @@ -152,10 +154,52 @@ jobs:
output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}_OTA.bin.xz.ota
if-no-files-found: warn

build_idf:
name: Build IDF
needs: refs
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
platform: [OpenESP32, OpenESP32C3, OpenESP32C2, OpenESP32C6, OpenESP32S3, OpenESP32S2]
steps:
- name: Source checkout
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v2
with:
python-version: '3.8'
architecture: 'x64'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install make cmake python3-venv
pip3 install pycryptodomex
pip3 install configobj
pip3 install toml
pip3 install fdt
- name: Run make
run: |
cd sdk/esp-idf
./install.sh > /dev/null
. ./export.sh
. ./add_path.sh
cd ../..
make APP_VERSION=${{ needs.refs.outputs.version }} APP_NAME=${{ matrix.platform }} ${{ matrix.platform }}
- name: Save build assets
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }}
path: |
output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.img
output/${{ needs.refs.outputs.version }}/${{ matrix.platform }}_${{ needs.refs.outputs.version }}.factory.bin
if-no-files-found: warn

release:
name: Semantic Release Images and Artifacts
runs-on: ubuntu-20.04
needs: [ refs, build, build2 ]
needs: [ refs, build, build_idf, build2 ]
if: always() && needs.refs.outputs.new_release == 'true' && (github.ref == 'refs/heads/main' || github.ref_name == 'alpha')
steps:
- name: Source checkout
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
[submodule "sdk/OpenLN882H"]
path = sdk/OpenLN882H
url = https://github.com/openshwprojects/OpenLN882H.git
[submodule "sdk/esp-idf"]
path = sdk/esp-idf
url = https://github.com/espressif/esp-idf.git
branch = release/v5.3
80 changes: 68 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else
endif

update-submodules: submodules
git add sdk/OpenBK7231T sdk/OpenBK7231N sdk/OpenXR809 sdk/OpenBL602 sdk/OpenW800 sdk/OpenW600 sdk/OpenLN882H
git add sdk/OpenBK7231T sdk/OpenBK7231N sdk/OpenXR809 sdk/OpenBL602 sdk/OpenW800 sdk/OpenW600 sdk/OpenLN882H sdk/esp-idf
ifdef GITHUB_ACTIONS
git config user.name github-actions
git config user.email github-actions@github.com
Expand Down Expand Up @@ -74,7 +74,7 @@ sdk/OpenLN882H/project/OpenBeken/app:
@mkdir -p "sdk/OpenLN882H/project/OpenBeken"
ln -s "$(shell pwd)/" "sdk/OpenLN882H/project/OpenBeken/app"

.PHONY: prebuild_OpenBK7231N prebuild_OpenBK7231T prebuild_OpenBL602 prebuild_OpenLN882H prebuild_OpenW600 prebuild_OpenW800 prebuild_OpenXR809
.PHONY: prebuild_OpenBK7231N prebuild_OpenBK7231T prebuild_OpenBL602 prebuild_OpenLN882H prebuild_OpenW600 prebuild_OpenW800 prebuild_OpenXR809 prebuild_ESPIDF

prebuild_OpenBK7231N:
@if [ -e platforms/BK7231N/pre_build.sh ]; then \
Expand All @@ -83,58 +83,54 @@ prebuild_OpenBK7231N:
else echo "prebuild for OpenBK7231N not found ... "; \
fi


prebuild_OpenBK7231T:
@if [ -e platforms/BK7231T/pre_build.sh ]; then \
echo "prebuild found for OpenBK7231T"; \
sh platforms/BK7231T/pre_build.sh; \
else echo "prebuild for OpenBK7231T not found ... "; \
fi


prebuild_OpenBL602:
@if [ -e platforms/BL602/pre_build.sh ]; then \
echo "prebuild found for OpenBL602"; \
sh platforms/BL602/pre_build.sh; \
else echo "prebuild for OpenBL602 not found ... "; \
fi


prebuild_OpenLN882H:
@if [ -e platforms/LN882H/pre_build.sh ]; then \
echo "prebuild found for OpenLN882H"; \
sh platforms/LN882H/pre_build.sh; \
else echo "prebuild for OpenLN882H not found ... "; \
fi


prebuild_OpenW600:
@if [ -e platforms/W600/pre_build.sh ]; then \
echo "prebuild found for OpenW600"; \
sh platforms/W600/pre_build.sh; \
else echo "prebuild for OpenW600 not found ... "; \
fi


prebuild_OpenW800:
@if [ -e platforms/W800/pre_build.sh ]; then \
echo "prebuild found for OpenW800"; \
sh platforms/W800/pre_build.sh; \
else echo "prebuild for OpenW800 not found ... "; \
fi


prebuild_OpenXR809:
@if [ -e platforms/XR809/pre_build.sh ]; then \
echo "prebuild found for OpenXR809"; \
sh platforms/XR809/pre_build.sh; \
else echo "prebuild for OpenXR809 not found ... "; \
fi





prebuild_ESPIDF:
@if [ -e platforms/ESP-IDF/pre_build.sh ]; then \
echo "prebuild found for ESP-IDF"; \
sh platforms/ESP-IDF/pre_build.sh; \
else echo "prebuild for ESP-IDF not found ... "; \
fi

# Build main binaries
OpenBK7231T: prebuild_OpenBK7231T
Expand Down Expand Up @@ -209,6 +205,60 @@ OpenLN882H: submodules sdk/OpenLN882H/project/OpenBeken/app prebuild_OpenLN882H
cp sdk/OpenLN882H/build/bin/flashimage.bin output/$(APP_VERSION)/OpenLN882H_$(APP_VERSION).bin
cp sdk/OpenLN882H/build/bin/flashimage-ota-xz-v0.1.bin output/$(APP_VERSION)/OpenLN882H_$(APP_VERSION)_OTA.bin

.PHONY: OpenESP32
OpenESP32: prebuild_ESPIDF
-rm platforms/ESP-IDF/sdkconfig
IDF_TARGET="esp32" USER_SW_VER=$(APP_VERSION) cmake platforms/ESP-IDF -B platforms/ESP-IDF/build-32
IDF_TARGET="esp32" USER_SW_VER=$(APP_VERSION) cmake --build ./platforms/ESP-IDF/build-32 -j $(shell nproc)
mkdir -p output/$(APP_VERSION)
esptool.py -c esp32 merge_bin -o output/$(APP_VERSION)/OpenESP32_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 4MB 0x1000 ./platforms/ESP-IDF/build-32/bootloader/bootloader.bin 0x8000 ./platforms/ESP-IDF/build-32/partition_table/partition-table.bin 0x10000 ./platforms/ESP-IDF/build-32/OpenBeken.bin
cp ./platforms/ESP-IDF/build-32/OpenBeken.bin output/$(APP_VERSION)/OpenESP32_$(APP_VERSION).img

.PHONY: OpenESP32C3
OpenESP32C3: prebuild_ESPIDF
-rm platforms/ESP-IDF/sdkconfig
IDF_TARGET="esp32c3" USER_SW_VER=$(APP_VERSION) cmake platforms/ESP-IDF -B platforms/ESP-IDF/build-c3
IDF_TARGET="esp32c3" USER_SW_VER=$(APP_VERSION) cmake --build ./platforms/ESP-IDF/build-c3 -j $(shell nproc)
mkdir -p output/$(APP_VERSION)
esptool.py -c esp32c3 merge_bin -o output/$(APP_VERSION)/OpenESP32C3_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 2MB 0x0 ./platforms/ESP-IDF/build-c3/bootloader/bootloader.bin 0x8000 ./platforms/ESP-IDF/build-c3/partition_table/partition-table.bin 0x10000 ./platforms/ESP-IDF/build-c3/OpenBeken.bin
cp ./platforms/ESP-IDF/build-c3/OpenBeken.bin output/$(APP_VERSION)/OpenESP32C3_$(APP_VERSION).img

.PHONY: OpenESP32C2
OpenESP32C2: prebuild_ESPIDF
-rm platforms/ESP-IDF/sdkconfig
IDF_TARGET="esp32c2" USER_SW_VER=$(APP_VERSION) cmake platforms/ESP-IDF -B platforms/ESP-IDF/build-c2
IDF_TARGET="esp32c2" USER_SW_VER=$(APP_VERSION) cmake --build ./platforms/ESP-IDF/build-c2 -j $(shell nproc)
mkdir -p output/$(APP_VERSION)
esptool.py -c esp32c2 merge_bin -o output/$(APP_VERSION)/OpenESP32C2_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 2MB 0x0 ./platforms/ESP-IDF/build-c2/bootloader/bootloader.bin 0x8000 ./platforms/ESP-IDF/build-c2/partition_table/partition-table.bin 0x10000 ./platforms/ESP-IDF/build-c2/OpenBeken.bin
cp ./platforms/ESP-IDF/build-c2/OpenBeken.bin output/$(APP_VERSION)/OpenESP32C2_$(APP_VERSION).img

.PHONY: OpenESP32C6
OpenESP32C6: prebuild_ESPIDF
-rm platforms/ESP-IDF/sdkconfig
IDF_TARGET="esp32c6" USER_SW_VER=$(APP_VERSION) cmake platforms/ESP-IDF -B platforms/ESP-IDF/build-c6
IDF_TARGET="esp32c6" USER_SW_VER=$(APP_VERSION) cmake --build ./platforms/ESP-IDF/build-c6 -j $(shell nproc)
mkdir -p output/$(APP_VERSION)
esptool.py -c esp32c6 merge_bin -o output/$(APP_VERSION)/OpenESP32C6_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 4MB 0x0 ./platforms/ESP-IDF/build-c6/bootloader/bootloader.bin 0x8000 ./platforms/ESP-IDF/build-c6/partition_table/partition-table.bin 0x10000 ./platforms/ESP-IDF/build-c6/OpenBeken.bin
cp ./platforms/ESP-IDF/build-c6/OpenBeken.bin output/$(APP_VERSION)/OpenESP32C6_$(APP_VERSION).img

.PHONY: OpenESP32S2
OpenESP32S2: prebuild_ESPIDF
-rm platforms/ESP-IDF/sdkconfig
IDF_TARGET="esp32s2" USER_SW_VER=$(APP_VERSION) cmake platforms/ESP-IDF -B platforms/ESP-IDF/build-s2
IDF_TARGET="esp32s2" USER_SW_VER=$(APP_VERSION) cmake --build ./platforms/ESP-IDF/build-s2 -j $(shell nproc)
mkdir -p output/$(APP_VERSION)
esptool.py -c esp32s2 merge_bin -o output/$(APP_VERSION)/OpenESP32S2_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 4MB 0x1000 ./platforms/ESP-IDF/build-s2/bootloader/bootloader.bin 0x8000 ./platforms/ESP-IDF/build-s2/partition_table/partition-table.bin 0x10000 ./platforms/ESP-IDF/build-s2/OpenBeken.bin
cp ./platforms/ESP-IDF/build-s2/OpenBeken.bin output/$(APP_VERSION)/OpenESP32S2_$(APP_VERSION).img

.PHONY: OpenESP32S3
OpenESP32S3: prebuild_ESPIDF
-rm platforms/ESP-IDF/sdkconfig
IDF_TARGET="esp32s3" USER_SW_VER=$(APP_VERSION) cmake platforms/ESP-IDF -B platforms/ESP-IDF/build-s3
IDF_TARGET="esp32s3" USER_SW_VER=$(APP_VERSION) cmake --build ./platforms/ESP-IDF/build-s3 -j $(shell nproc)
mkdir -p output/$(APP_VERSION)
esptool.py -c esp32s3 merge_bin -o output/$(APP_VERSION)/OpenESP32S3_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 4MB 0x0 ./platforms/ESP-IDF/build-s3/bootloader/bootloader.bin 0x8000 ./platforms/ESP-IDF/build-s3/partition_table/partition-table.bin 0x10000 ./platforms/ESP-IDF/build-s3/OpenBeken.bin
cp ./platforms/ESP-IDF/build-s3/OpenBeken.bin output/$(APP_VERSION)/OpenESP32S3_$(APP_VERSION).img

# clean .o files and output directory
.PHONY: clean
clean:
Expand All @@ -219,6 +269,12 @@ clean:
$(MAKE) -C sdk/OpenW800 clean
$(MAKE) -C sdk/OpenW600 clean
test -d ./sdk/OpenLN882H/build && cmake --build ./sdk/OpenLN882H/build --target clean
test -d ./platforms/ESP-IDF/build-32 && cmake --build ./platforms/ESP-IDF/build-32 --target clean
test -d ./platforms/ESP-IDF/build-c3 && cmake --build ./platforms/ESP-IDF/build-c3 --target clean
test -d ./platforms/ESP-IDF/build-c2 && cmake --build ./platforms/ESP-IDF/build-c2 --target clean
test -d ./platforms/ESP-IDF/build-c6 && cmake --build ./platforms/ESP-IDF/build-c6 --target clean
test -d ./platforms/ESP-IDF/build-s2 && cmake --build ./platforms/ESP-IDF/build-s2 --target clean
test -d ./platforms/ESP-IDF/build-s3 && cmake --build ./platforms/ESP-IDF/build-s3 --target clean

# Add custom Makefile if required
-include custom.mk
Expand Down
2 changes: 2 additions & 0 deletions platforms/ESP-IDF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build*
sdkconfig
11 changes: 11 additions & 0 deletions platforms/ESP-IDF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_compile_definitions(PLATFORM_ESPIDF=1)
add_compile_definitions(MQTT_OUTPUT_RINGBUF_SIZE=2048)
add_compile_definitions(MQTT_VAR_HEADER_BUFFER_LEN=256)
add_compile_definitions(MQTT_REQ_MAX_IN_FLIGHT=16)
add_compile_definitions(LWIP_NOASSERT=1)
add_definitions( -DUSER_SW_VER="$ENV{USER_SW_VER}" )
set(PROJECT_VER "$ENV{USER_SW_VER}")
project(OpenBeken)
idf_build_set_property(COMPILE_OPTIONS "-Wno-format-truncation" APPEND)
131 changes: 131 additions & 0 deletions platforms/ESP-IDF/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
set(PROJ_ALL_SRC
../../../src/base64/base64.c
../../../src/bitmessage/bitmessage_read.c
../../../src/bitmessage/bitmessage_write.c
../../../src/cJSON/cJSON.c
../../../src/cmnds/cmd_channels.c
../../../src/cmnds/cmd_eventHandlers.c
../../../src/cmnds/cmd_if.c
../../../src/cmnds/cmd_main.c
../../../src/cmnds/cmd_newLEDDriver_colors.c
../../../src/cmnds/cmd_newLEDDriver.c
../../../src/cmnds/cmd_repeatingEvents.c
../../../src/cmnds/cmd_script.c
# ../../../src/cmnds/cmd_send.c
../../../src/cmnds/cmd_simulatorOnly.c
../../../src/cmnds/cmd_tasmota.c
../../../src/cmnds/cmd_tcp.c
../../../src/cmnds/cmd_test.c
../../../src/cmnds/cmd_tokenizer.c
../../../src/devicegroups/deviceGroups_read.c
../../../src/devicegroups/deviceGroups_util.c
../../../src/devicegroups/deviceGroups_write.c
../../../src/driver/drv_adcButton.c
../../../src/driver/drv_adcSmoother.c
../../../src/driver/drv_aht2x.c
../../../src/driver/drv_battery.c
../../../src/driver/drv_bl_shared.c
../../../src/driver/drv_bl0937.c
# ../../../src/driver/drv_bl0942.c
../../../src/driver/drv_bmp280.c
../../../src/driver/drv_bmpi2c.c
../../../src/driver/drv_bp1658cj.c
../../../src/driver/drv_bp5758d.c
../../../src/driver/drv_bridge_driver.c
../../../src/driver/drv_chargingLimit.c
../../../src/driver/drv_charts.c
../../../src/driver/drv_cht8305.c
../../../src/driver/drv_cse7766.c
../../../src/driver/drv_ddp.c
../../../src/driver/drv_debouncer.c
../../../src/driver/drv_dht_internal.c
../../../src/driver/drv_dht.c
# ../../../src/driver/drv_doorSensorWithDeepSleep.c
../../../src/driver/drv_gn6932.c
../../../src/driver/drv_hd2015.c
../../../src/driver/drv_ht16k33.c
../../../src/driver/drv_httpButtons.c
../../../src/driver/drv_hue.c
../../../src/driver/drv_kp18058.c
../../../src/driver/drv_kp18068.c
../../../src/driver/drv_main.c
../../../src/driver/drv_max72xx_clock.c
../../../src/driver/drv_max72xx_internal.c
../../../src/driver/drv_max72xx_single.c
../../../src/driver/drv_mcp9808.c
../../../src/driver/drv_ntp_events.c
../../../src/driver/drv_ntp.c
../../../src/driver/drv_pt6523.c
../../../src/driver/drv_pwm_groups.c
../../../src/driver/drv_pwmToggler.c
../../../src/driver/drv_pwrCal.c
# ../../../src/driver/drv_rn8209.c
../../../src/driver/drv_sgp.c
../../../src/driver/drv_shiftRegister.c
../../../src/driver/drv_sht3x.c
# ../../../src/driver/drv_sm15155e.c
# ../../../src/driver/drv_sm16703P.c
../../../src/driver/drv_sm2135.c
../../../src/driver/drv_sm2235.c
../../../src/driver/drv_soft_i2c.c
../../../src/driver/drv_soft_spi.c
# ../../../src/driver/drv_spi_flash.c
# ../../../src/driver/drv_spi.c
# ../../../src/driver/drv_spidma.c
../../../src/driver/drv_ssdp.c
../../../src/driver/drv_tasmotaDeviceGroups.c
../../../src/driver/drv_test_drivers.c
../../../src/driver/drv_textScroller.c
../../../src/driver/drv_tm_gn_display_shared.c
../../../src/driver/drv_tm1637.c
../../../src/driver/drv_tm1638.c
../../../src/driver/drv_tuyaMCU.c
../../../src/driver/drv_tuyaMCUSensor.c
../../../src/driver/drv_uart.c
# ../../../src/driver/drv_ucs1912.c
../../../src/driver/drv_wemo.c
../../../src/driver/drv_ds1820_simple.c
../../../src/hal/espidf/hal_adc_espidf.c
../../../src/hal/espidf/hal_flashConfig_espidf.c
../../../src/hal/espidf/hal_flashVars_espidf.c
../../../src/hal/espidf/hal_generic_espidf.c
../../../src/hal/espidf/hal_main_espidf.c
../../../src/hal/espidf/hal_pins_espidf.c
../../../src/hal/espidf/hal_wifi_espidf.c
../../../src/httpserver/hass.c
../../../src/httpserver/http_basic_auth.c
../../../src/httpserver/http_fns.c
../../../src/httpserver/http_tcp_server_nonblocking.c
../../../src/httpserver/http_tcp_server.c
../../../src/httpserver/json_interface.c
../../../src/httpserver/new_http.c
../../../src/httpserver/rest_interface.c
# ../../../src/httpclient/http_client.c
# ../../../src/httpclient/utils_net.c
# ../../../src/httpclient/utils_timer.c
../../../src/i2c/drv_i2c_lcd_pcf8574t.c
../../../src/i2c/drv_i2c_main.c
../../../src/i2c/drv_i2c_mcp23017.c
../../../src/i2c/drv_i2c_tc74.c
../../../src/jsmn/jsmn.c
../../../src/littlefs/lfs_util.c
../../../src/littlefs/lfs.c
../../../src/littlefs/our_lfs.c
../../../src/logging/logging.c
# ../../../src/memory/memtest.c
../../../src/mqtt/new_mqtt_deduper.c
../../../src/mqtt/new_mqtt.c
../../../src/new_cfg.c
../../../src/new_common.c
../../../src/new_ping.c
../../../src/new_pins.c
# ../../../src/ota/ota.c
../../../src/rgb2hsv.c
# ../../../src/sim/sim_uart.c
../../../src/tiny_crc8.c
../../../src/user_main.c
$ENV{IDF_PATH}/components/lwip/lwip/src/apps/mqtt/mqtt.c
app.c
)
idf_component_register(SRCS ${PROJ_ALL_SRC}
PRIV_REQUIRES mqtt lwip esp_wifi nvs_flash esp_driver_tsens esp_driver_gpio esp_pm esp_partition app_update esp_adc esp_driver_uart esp_driver_ledc)
Loading

0 comments on commit c505156

Please sign in to comment.