Skip to content

Commit

Permalink
Add support for Pico (rp2040) boards (#34)
Browse files Browse the repository at this point in the history
* HyperSPI support for Pico (rp2040)

* Adafruit RP2040 Scorpio support (ItsyBitsy uses default build)

No support for rp2040 Pimoroni level shifter boards because of missing GPIO SPI pins.

* Update README.md

* Update hyperspi.cpp

* Update README.md

* Update README.md
  • Loading branch information
awawa-dev committed Mar 14, 2024
1 parent 2bc11ce commit be49554
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 15 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/push-master-pico.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: HyperSPI Pico CI Build

on: [push]

jobs:

#############################
#### HyperSPI for Pico ######
#############################

HyperSpiPico:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rp2040
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install GNU Arm Embedded Toolchain
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '12.2.Rel1'

- name: Build packages
shell: bash
run: |
mkdir build
cd build
cmake ..
cmake --build . --config Release
- uses: actions/upload-artifact@v3
name: Upload artifacts (commit)
if: (startsWith(github.event.ref, 'refs/tags') != true)
with:
path: |
rp2040/HyperSerialPico/firmware/*.uf2
- uses: actions/upload-artifact@v3
name: Upload artifacts (release)
if: startsWith(github.ref, 'refs/tags/')
with:
name: firmware-release
path: |
rp2040/HyperSerialPico/firmware/*.uf2
- name: Build packages for Adafruit Feather RP2040 Scorpio
shell: bash
run: |
cd build
rm *.*
rm ../HyperSerialPico/firmware/*
echo "Neopixel is using GPIO16(OUTPUT_DATA_PIN) on output 0." > ../HyperSerialPico/firmware/Firmwares_for_Adafruit_Feather_RP2040_Scorpio.txt
cmake -DOVERRIDE_DATA_PIN=16 -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
zip -j ../HyperSerialPico/firmware/Adafruit_Feather_RP2040_Scorpio.zip ../HyperSerialPico/firmware/*
- uses: actions/upload-artifact@v3
name: Upload artifacts (Adafruit_Feather)
if: (startsWith(github.event.ref, 'refs/tags') != true)
with:
path: |
rp2040/HyperSerialPico/firmware/*.zip
- uses: actions/upload-artifact@v3
name: Upload artifacts (release for Adafruit_Feather)
if: startsWith(github.ref, 'refs/tags/')
with:
name: firmware-release
path: |
rp2040/HyperSerialPico/firmware/*.zip
################################
###### Publish Releases ########
################################

publish:
name: Publish Releases
if: startsWith(github.event.ref, 'refs/tags')
needs: [HyperSpiPico]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# generate environment variables
- name: Generate environment variables from version and tag
run: |
echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo "preRelease=false" >> $GITHUB_ENV
# If version contains alpha or beta, mark draft release as pre-release
- name: Mark release as pre-release
if: contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta')
run: echo "preRelease=true" >> $GITHUB_ENV

- uses: actions/download-artifact@v3
with:
name: firmware-release

# create draft release and upload artifacts
- name: Create draft release
uses: softprops/action-gh-release@v1
with:
name: HyperSPI ${{ env.VERSION }}
tag_name: ${{ env.TAG }}
files: |
*.uf2
*.zip
draft: true
prerelease: ${{ env.preRelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: HyperSPI CI Build
name: HyperSPI ESP32/8266 CI Build

on: [push]

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "rp2040/HyperSerialPico"]
path = rp2040/HyperSerialPico
url = https://github.com/awawa-dev/HyperSerialPico
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# HyperSPI
SPI bridge for AWA protocol to control a LED strip from HyperHDR.
Diagnostic and performance data available at the serial port output [read more](#performancedebug-output).
Rpi acts as a master, ESP8266/ESP32/ESP32-S2 is in slave mode.
Raspberry Pi acts as a master, ESP8266/ESP32/ESP32-S2/rp2040(Raspberry Pi Pico) is in slave mode.

| LED strip / Device | ESP8266<br>(limited performance) | ESP32 / ESP32-S2 mini |
|--------------------------------|:-------:|:-----------:|
| SK6812 cold white | yes | yes |
| SK6812 neutral white | yes | yes |
| WS281x | yes | yes |
| LED strip / Device | rp2040 / Pico | ESP8266<br>(limited performance) | ESP32 / ESP32-S2 mini
|--------------------------------|:-------:|:-----------:|:-------:|
| SK6812 cold white | yes | yes | yes |
| SK6812 neutral white | yes | yes | yes |
| WS281x | yes | yes | yes |


# Why this project was created?
Expand All @@ -23,9 +23,19 @@ Rpi acts as a master, ESP8266/ESP32/ESP32-S2 is in slave mode.

If you are using an ESP board compatible with the Wemos board (ESP8266 Wemos D1/pro, ESP32 MH-ET Live, ESP32-S2 lolin mini), the SPI connection uses the same pinout location on the ESP board! The pin positions of the LED output may vary. Cables (including ground) should not exceed 15-20cm or it may be necessary to lower the SPI speed.

The photos below use the same home-made adapter throughout, so you can see a repeating pattern and the cable colors should help you locate the correct pins. However, always consult the GPIO diagram for your boards to confirm that you have connected the cables correctly, because if you make a mistake and connect to the 5V GPIO line, it may damage both devices.

As you can also notice, the pinout of the SPI0 interface is identical for the entire Raspberry Pi SBC family: 3, 4, 5, Zero 2W, etc.

<table>
<tr>
<td colspan="2"><p align="center">See how easy it is to connect ESP to Raspberry Pi using SPI</p></td>
<td colspan="2"><p align="center">See how easy it is to connect Raspberry Pi Pico (rp2040) to Raspberry Pi 5 using SPI</p></td>
</tr>
<tr>
<td colspan="2"><img src="https://github.com/awawa-dev/HyperSPI/assets/69086569/7f24f87e-f7e0-43f3-a568-39d0f6beced1"/></td>
</tr>
<tr>
<td colspan="2"><p align="center">or if you prefer ESP32/ESP32-S2/Esp8266</p></td>
</tr>
<tr>
<td><img src="https://github.com/awawa-dev/HyperSPI/assets/69086569/1e500ca3-e93d-4082-af59-b701e6274a29"/></td>
Expand All @@ -52,13 +62,16 @@ If you are using an ESP board compatible with the Wemos board (ESP8266 Wemos D1/

## Default pinout (can be changed for esp32 and esp32-s2)

| PINOUT | ESP8266 | ESP32 | ESP32-S2 lolin mini|
|-------------|-----------|-----------|-----------|
| Clock (SCK) | GPIO 14 | GPIO 18 | GPIO 7 |
| Data (MOSI) | GPIO 13 | GPIO 23 | GPIO 11 |
| SPI Chip Select(e.g. CE0) | not used | GPIO 5 | GPIO 12 |
| GROUND | mandatory | mandatory | mandatory |
| LED output | GPIO 2 | GPIO 2 | GPIO 2 |
| PINOUT | ESP8266 | ESP32 | ESP32-S2 lolin mini| Pico (rp2040)
|-------------|-----------|-----------|-----------|-----------|
| Clock (SCK) | GPIO 14 | GPIO 18 | GPIO 7 | GPIO 2 |
| Data (MOSI) | GPIO 13 | GPIO 23 | GPIO 11 | GPIO 4 |
| SPI Chip Select(e.g. CE0) | not used | GPIO 5 | GPIO 12 | GPIO 5 |
| GROUND | mandatory | mandatory | mandatory | mandatory |
| LED output | GPIO 2 | GPIO 2 | GPIO 2 | GPIO 14 |

> [!CAUTION]
> The ground connection between both GPIOs is as important as the other SPI data connections. The ground cable should be of a similar length as them and run directly next to them.
# Flashing the firmware

Expand Down
2 changes: 2 additions & 0 deletions rp2040/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
vscode
42 changes: 42 additions & 0 deletions rp2040/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
set(CMAKE_SYSTEM_NAME Generic)
# User configuration section starts here

# Some boards, such as the first Adafruit revisions, may have trouble booting properly
# due to bad componets used in the design.
# Turn this setting to ON if your rp2040 is not detected after firmware upload and reset
set(BOOT_WORKAROUND ON)

# Default output data pin for the non-SPI LED strips (only for sk6812/ws2812b)
set(OUTPUT_DATA_PIN 14)

# Use multi-segment, starting index of second led strip or OFF to disable
set(SECOND_SEGMENT_INDEX OFF)

# If multi-segment is used and it's reversed, set this option to ON to enable reversing
set(SECOND_SEGMENT_REVERSED OFF)

# HyperSPI communication interface with Raspberry Pi
set(OUTPUT_SPI_DATA_PIN 4)
set(OUTPUT_SPI_CLOCK_PIN 2)
set(OUTPUT_SPI_CHIP_SELECT 5)
set(OUTPUT_SPI_INTERFACE spi0)

# User configuration section ends here
# Usually you don't need to change anything below this section
cmake_minimum_required(VERSION 3.13)

set(PICO_SDK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/HyperSerialPico/sdk/pico)
set(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/HyperSerialPico/sdk/freertos)
include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)
include(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)

project(HyperSPI_Pico C CXX ASM)
pico_sdk_init()

set(PICO_PROGRAM_MAIN_ENTRY "../hyperspi.cpp")
set(DISABLE_SPI_LEDS ON)
add_definitions(-DSPI_INTERFACE=${OUTPUT_SPI_INTERFACE}
-DSPI_DATA_PIN=${OUTPUT_SPI_DATA_PIN}
-DSPI_CLOCK_PIN=${OUTPUT_SPI_CLOCK_PIN}
-DSPI_CHIP_SELECT=${OUTPUT_SPI_CHIP_SELECT})
add_subdirectory(HyperSerialPico)
1 change: 1 addition & 0 deletions rp2040/HyperSerialPico
Submodule HyperSerialPico added at 5bf475
Loading

0 comments on commit be49554

Please sign in to comment.