From d35938d2962b0178ab5cb0e6ca155ce02e7e8dcf Mon Sep 17 00:00:00 2001 From: Awawa <69086569+awawa-dev@users.noreply.github.com> Date: Thu, 27 Jul 2023 01:51:55 +0200 Subject: [PATCH] Support for 5v level-shifter on Adafruit and Pimoroni boards (#8) * Add GA script for Adafruit and Pimoroni boards Build firmware automatically. These boards have a built-in level shifter. * Update README.md * Update README.md * Add Adafruit ItsyBitsy rp2040 --- .github/workflows/push-master.yml | 89 ++++++++++++++++++++++++++++++- CMakeLists.txt | 44 +++++++++++++-- README.md | 20 ++++--- 3 files changed, 139 insertions(+), 14 deletions(-) diff --git a/.github/workflows/push-master.yml b/.github/workflows/push-master.yml index e5d8c26..0b6691d 100644 --- a/.github/workflows/push-master.yml +++ b/.github/workflows/push-master.yml @@ -34,7 +34,7 @@ jobs: if: (startsWith(github.event.ref, 'refs/tags') != true) with: path: | - firmwares/*.uf2 + firmware/*.uf2 - uses: actions/upload-artifact@v3 name: Upload artifacts (release) @@ -42,7 +42,91 @@ jobs: with: name: firmware-release path: | - firmwares/*.uf2 + firmware/*.uf2 + + - name: Build packages for Adafruit Feather RP2040 Scorpio (release-only) + if: startsWith(github.ref, 'refs/tags/') + shell: bash + run: | + cd build + rm *.* + rm ../firmware/* + echo "Neopixel is using GPIO16(OUTPUT_DATA_PIN) on output 0." > ../firmware/Firmwares_for_Adafruit_Feather_RP2040_Scorpio.txt + echo "SPI is using spi0 interface pins: GPIO19(OUTPUT_SPI_DATA_PIN) and GPIO18(OUTPUT_SPI_CLOCK_PIN) on output 3 and 2 respectively." >> ../firmware/Firmwares_for_Adafruit_Feather_RP2040_Scorpio.txt + cmake -DOVERRIDE_DATA_PIN=16 -DOVERRIDE_SPI_DATA_PIN=19 -DOVERRIDE_SPI_CLOCK_PIN=18 -DCMAKE_BUILD_TYPE=Release .. + cmake --build . + zip -j ../firmware/Adafruit_Feather_RP2040_Scorpio.zip ../firmware/* + + - uses: actions/upload-artifact@v3 + name: Upload artifacts (release Adafruit_Feather) + if: startsWith(github.ref, 'refs/tags/') + with: + name: firmware-release + path: | + firmware/*.zip + + - name: Build packages for Adafruit ItsyBitsy RP2040 (release-only) + if: startsWith(github.ref, 'refs/tags/') + shell: bash + run: | + cd build + rm *.* + rm ../firmware/* + echo "Neopixel is using GPIO14(OUTPUT_DATA_PIN) on output 5." > ../firmware/Firmwares_for_Adafruit_ItsyBitsy_2040.txt + cmake -DOVERRIDE_DATA_PIN=14 -DCMAKE_BUILD_TYPE=Release .. + cmake --build . + rm ../firmware/*_Spi.uf2 + zip -j ../firmware/Adafruit_ItsyBitsy_2040.zip ../firmware/* + + - uses: actions/upload-artifact@v3 + name: Upload artifacts (release Adafruit_ItsyBitsy) + if: startsWith(github.ref, 'refs/tags/') + with: + name: firmware-release + path: | + firmware/*.zip + + - name: Build packages for Pimoroni Plasma Stick 2040 W (release-only) + if: startsWith(github.ref, 'refs/tags/') + shell: bash + run: | + cd build + rm *.* + rm ../firmware/* + echo "Neopixel is using GPIO15(OUTPUT_DATA_PIN) on output PIXELS." > ../firmware/Firmwares_for_Pimoroni_Plasma_Stick_2040_W.txt + cmake -DOVERRIDE_DATA_PIN=15 -DCMAKE_BUILD_TYPE=Release .. + cmake --build . + rm ../firmware/*_Spi.uf2 + zip -j ../firmware/Pimoroni_Plasma_Stick_2040_W.zip ../firmware/* + + - uses: actions/upload-artifact@v3 + name: Upload artifacts (release Pimoroni_Plasma_Stick_W) + if: startsWith(github.ref, 'refs/tags/') + with: + name: firmware-release + path: | + firmware/*.zip + + - name: Build packages for Pimoroni Plasma 2040 (release-only) + if: startsWith(github.ref, 'refs/tags/') + shell: bash + run: | + cd build + rm *.* + rm ../firmware/* + echo "Neopixel is using GPIO15(OUTPUT_DATA_PIN) on output DA." > ../firmware/Firmwares_for_Pimoroni_Plasma_2040.txt + echo "SPI is using spi1 interface pins: GPIO15(OUTPUT_SPI_DATA_PIN) and GPIO14(OUTPUT_SPI_CLOCK_PIN) on output DA and CL respectively." >> ../firmware/Firmwares_for_Pimoroni_Plasma_2040.txt + cmake -DOVERRIDE_DATA_PIN=15 -DOVERRIDE_SPI_INTERFACE=spi1 -DOVERRIDE_SPI_DATA_PIN=15 -DOVERRIDE_SPI_CLOCK_PIN=14 -DCMAKE_BUILD_TYPE=Release .. + cmake --build . + zip -j ../firmware/Pimoroni_Plasma_2040.zip ../firmware/* + + - uses: actions/upload-artifact@v3 + name: Upload artifacts (release Pimoroni_Plasma) + if: startsWith(github.ref, 'refs/tags/') + with: + name: firmware-release + path: | + firmware/*.zip ################################ ###### Publish Releases ######## @@ -79,6 +163,7 @@ jobs: tag_name: ${{ env.TAG }} files: | *.uf2 + *.zip draft: true prerelease: ${{ env.preRelease }} env: diff --git a/CMakeLists.txt b/CMakeLists.txt index a849f5b..99d7a4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(OUTPUT_DATA_PIN 2) # only certain pairs of pins are allowed for selected SPI interface (refer to "readme.md") set(OUTPUT_SPI_DATA_PIN 3) set(OUTPUT_SPI_CLOCK_PIN 2) -set(SPI_INTERFACE spi0) +set(OUTPUT_SPI_INTERFACE spi0) # Use multi-segment, starting index of second led strip or OFF to disable set(SECOND_SEGMENT_INDEX OFF) @@ -49,7 +49,43 @@ pico_sdk_init() set(HyperSerialPicoCompanionLibs FreeRTOS-Kernel FreeRTOS-Kernel-Heap1 pico_stdlib pico_multicore hardware_pio hardware_dma hardware_spi) set(HyperSerialPicoCompanionIncludes ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/sdk/config) file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/generated) -file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/firmwares) +file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/firmware) + +if(NOT CMAKE_HOST_WIN32) + string(ASCII 27 EscChar) + set(ColorReset "${EscChar}[m") + set(GreenColor "${EscChar}[32m") + set(YellowColor "${EscChar}[33m") +endif() + +if (OVERRIDE_DATA_PIN) + set(OUTPUT_DATA_PIN ${OVERRIDE_DATA_PIN}) + message( STATUS "${YellowColor}Overriding Neopixel Data GPIO: ${OUTPUT_DATA_PIN}${ColorReset}") +endif() + +if (OVERRIDE_SPI_DATA_PIN) + set(OUTPUT_SPI_DATA_PIN ${OVERRIDE_SPI_DATA_PIN}) + message( STATUS "${YellowColor}Overriding SPI Data GPIO: ${OUTPUT_SPI_DATA_PIN}${ColorReset}") +endif() + +if (OVERRIDE_SPI_CLOCK_PIN) + set(OUTPUT_SPI_CLOCK_PIN ${OVERRIDE_SPI_CLOCK_PIN}) + message( STATUS "${YellowColor}Overriding SPI Clock GPIO: ${OUTPUT_SPI_CLOCK_PIN}${ColorReset}") +endif() + +if (OVERRIDE_SPI_INTERFACE) + set(OUTPUT_SPI_INTERFACE ${OVERRIDE_SPI_INTERFACE}) + message( STATUS "${YellowColor}Overriding SPI Interface: ${OUTPUT_SPI_INTERFACE}${ColorReset}") +endif() + +message( STATUS "---------------------------") +message( STATUS "Neopixel Data GPIO: ${GreenColor}${OUTPUT_DATA_PIN}${ColorReset}") +message( STATUS "SPI Data GPIO: ${GreenColor}${OUTPUT_SPI_DATA_PIN}${ColorReset}") +message( STATUS "SPI Clock GPIO: ${GreenColor}${OUTPUT_SPI_CLOCK_PIN}${ColorReset}") +message( STATUS "SPI Interface: ${GreenColor}${OUTPUT_SPI_INTERFACE}${ColorReset}") +message( STATUS "---------------------------") + +add_compile_options(-ftrack-macro-expansion=0 -fno-diagnostics-show-caret -fdiagnostics-color=auto) macro(HyperSerialPicoTarget HyperSerialPicoTargetName) add_executable(${HyperSerialPicoTargetName} ${CMAKE_SOURCE_DIR}/source/main.cpp) @@ -60,13 +96,13 @@ macro(HyperSerialPicoTarget HyperSerialPicoTargetName) pico_enable_stdio_uart(${HyperSerialPicoTargetName} 0) pico_generate_pio_header(${HyperSerialPicoTargetName} ${CMAKE_SOURCE_DIR}/pio/neopixel.pio OUTPUT_DIR ${CMAKE_SOURCE_DIR}/generated) pico_generate_pio_header(${HyperSerialPicoTargetName} ${CMAKE_SOURCE_DIR}/pio/neopixel_ws2812b.pio OUTPUT_DIR ${CMAKE_SOURCE_DIR}/generated) - add_custom_command(TARGET ${HyperSerialPicoTargetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${HyperSerialPicoTargetName}.uf2 ${CMAKE_SOURCE_DIR}/firmwares) + add_custom_command(TARGET ${HyperSerialPicoTargetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${HyperSerialPicoTargetName}.uf2 ${CMAKE_SOURCE_DIR}/firmware) endmacro() # targets for different LED strips IF(NOT SECOND_SEGMENT_INDEX) HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_Spi") - target_compile_definitions("${CMAKE_PROJECT_NAME}_Spi" PRIVATE -DSPILED_APA102 -DSPI_INTERFACE=${SPI_INTERFACE} -DDATA_PIN=${OUTPUT_SPI_DATA_PIN} -DCLOCK_PIN=${OUTPUT_SPI_CLOCK_PIN}) + target_compile_definitions("${CMAKE_PROJECT_NAME}_Spi" PRIVATE -DSPILED_APA102 -DSPI_INTERFACE=${OUTPUT_SPI_INTERFACE} -DDATA_PIN=${OUTPUT_SPI_DATA_PIN} -DCLOCK_PIN=${OUTPUT_SPI_CLOCK_PIN}) HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_sk6812Cold") target_compile_definitions("${CMAKE_PROJECT_NAME}_sk6812Cold" PRIVATE -DNEOPIXEL_RGBW -DCOLD_WHITE -DDATA_PIN=${OUTPUT_DATA_PIN}) HyperSerialPicoTarget("${CMAKE_PROJECT_NAME}_sk6812Neutral") diff --git a/README.md b/README.md index 0c0a0af..3238483 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Adalight serial port LED driver implementation for Raspberry Pi Pico RP2040.
# Recommended boards with a built-in level shifter -To ensure the LEDs will work properly with the Pico board, a 3.3V to 5V level shifter is needed. You can use an external one e.g. SN74AHCT125N or just buy a model of rp2040 that already has it built-in: Adafruit Feather RP2040 Scorpio (output: GPIO16-23), Pimoroni Plasma 2040 (GPIO14-15) or Pimoroni Plasma Stick 2040 W (GPIO15). +To ensure the LEDs will work properly with the Pico board, a 3.3V to 5V level shifter is needed. You can use an external one e.g. SN74AHCT125N or just buy a model of rp2040 that already has it built-in: Adafruit Feather RP2040 Scorpio (output: GPIO16-23), Adafruit ItsyBitsy RP2040 (output: GPIO14), Pimoroni Plasma 2040 (GPIO14-15) or Pimoroni Plasma Stick 2040 W (GPIO15). - + # Supported LED strips | LED strip / Device | Single lane | Multi-segment | @@ -22,15 +22,19 @@ To ensure the LEDs will work properly with the Pico board, a 3.3V to 5V level sh # How to flash it? It's very easy and you don't need any special flasher. -First download the firmware directly from the [Release folder](https://github.com/awawa-dev/HyperSerialPico/releases). - -For HyperHDR choose `HyperSerialPico_