Makuna / NeoPixelBus

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
1.18k stars 264 forks source link

RPi PICO Support (RP2040) #578

Closed Barilium8 closed 8 months ago

Barilium8 commented 2 years ago

I have tried with just lib NeoPixelBus.h...

include

And then tried...

include

include

include

Either way the VARIANT_MCK (and F_CPU) not declared... errors occur. Any help would be appreciated.

Here is the beginning of the output form the compiler...

Executing task: C:\Users\steve.platformio\penv\Scripts\platformio.exe run --target upload < Processing pico (platform: raspberrypi; board: pico; framework: arduino) ---------------- Verbose mode can be enabled via -v, --verbose option ---------------- CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/pico.html PLATFORM: Raspberry Pi RP2040 (1.7.0) > Raspberry Pi Pico HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, raspberrypi-swd) PACKAGES:

  • framework-arduino-mbed @ 3.1.1
  • tool-openocd-raspberrypi @ 2.1100.0 (11.0)
  • tool-rp2040tools @ 1.0.2
  • toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1) LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 40 compatible libraries Scanning dependencies... Dependency Graph |-- MIDI Library @ 5.0.2 |-- NeoPixelBus @ 2.7.0 | |-- SPI |-- CLabs_Proto_Modules |-- SPI Building in release mode Compiling .pio\build\pico\src\main.cpp.o Compiling .pio\build\pico\liba32\NeoPixelBus\internal\NeoGamma.cpp.o Compiling .pio\build\pico\liba32\NeoPixelBus\internal\NeoPixelAnimator.cpp.o In file included from .pio\libdeps\pico\NeoPixelBus\src/NeoPixelBus.h:123, from .pio\libdeps\pico\NeoPixelBus\src\internal\NeoGamma.cpp:28: .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:710:26: error: 'VARIANT_MCK' was not declared in this scope
    710 | #define ARM_OTHER_SCALE VARIANT_MCK / 2UL / 1000000UL | ^~~ .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:716:69: note: in expansion of macro 'ARM_OTHER_SCALE' 716 | static const uint32_t CyclesT0h = static_cast((0.40 ARM_OTHER_SCALE + 0.5) - (5 ARM_OTHER_INST)); | ^~~~~~~ .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:711:33: error: 'F_CPU' was not declared in this scope 711 | #define ARM_OTHER_INST (2UL F_CPU / VARIANT_MCK) | ^~~~~ .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:716:99: note: in expansion of macro 'ARM_OTHER_INST' 716 | static const uint32_t CyclesT0h = static_cast((0.40 ARM_OTHER_SCALE + 0.5) - (5 ARM_OTHER_INST)); | ^~~~~~
    .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:711:41: error: 'VARIANT_MCK' was not declared in this scope
    711 | #define ARM_OTHER_INST (2UL
    F_CPU / VARIANT_MCK) | ^~~ .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:716:99: note: in expansion of macro 'ARM_OTHER_INST' 716 | static const uint32_t CyclesT0h = static_cast((0.40 ARM_OTHER_SCALE + 0.5) - (5 ARM_OTHER_INST)); | ^~~~~~
    .pio\libdeps\pico\NeoPixelBus\src/internal/NeoArmMethod.h:710:26: error: 'VARIANT_MCK' was not declared in this scope 710 | #define ARM_OTHER_SCALE VARIANT_MCK / 2UL / 1000000UL
Makuna commented 2 years ago

This board is not supported by my library.

The generic ARM implementation requires some basic support that is not present with this boards Arduino support. This is common with MBED and SAMD boards support.

Further, this specific chip is dual core, meaning that more than likely the generic bit bang support even if ported would not work well and would require the use of a hardware feature specific to the chip/board.

NOTES: These are the ARDUINOARCH defined for this board when using the Arduin IDE with the Arduino (not SEEED) board support installed. ARDUINO_ARCH_MBED ARDUINO_ARCH_MBED_RP2040 ARDUINO_ARCH_RP2040 Section 3.6.2. in the rp2040-datasheet.pdf contains a section specific to the hardware support for WS2812. https://github.com/raspberrypi/pico-examples/tree/master/pio/ws2812

Makuna commented 2 years ago

PIO - a feature of the RP2040 would allow for a bitbang code that is run within up to 8 internal IO CPUs (limited ASM instructions but good enough to do this) and will run these independent of the primary two cores. This is the solution to use.

Python Example:
https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython/using-pio-to-drive-a-neopixel https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython/advanced-using-pio-to-drive-neopixels-in-the-background

PIO and Arduino: https://github.com/arduino/ArduinoCore-mbed/issues/184

Modified Adafruit Neopixel using PIO: https://github.com/Bodmer/Adafruit_NeoPixel

DMA can be used with PIO: https://gregchadwick.co.uk/blog/playing-with-the-pico-pt2/ https://github.com/adafruit/Adafruit_NeoPXL8

More advanced Arduino RP2040 board support that includes the pioasm.exe https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json found from https://github.com/LifeWithDavid/Raspberry-Pi-Pico-PIO/blob/7a2236b4c6fcffb71231792e9fab8367e1386c0c/Episode%2013%20Arduino%20IDE%20files.txt

Online PioAsm.exe (probably the best choice for now to make some progress) https://wokwi.com/tools/pioasm

Makuna commented 8 months ago

Should have something to show this next week.

DMA driven, with four channels per PIO, so theatrically 8 separate DMA driven channels.

Makuna commented 8 months ago

https://github.com/Makuna/NeoPixelBus/pull/779

You can instance the NeoPixelBus four times on each PIO, for a theoretical eight channels. But this will stop any other uses of PIO as there are only two PIO engines.

Defaults to using PIO1 on IRQ 1.

Makuna commented 8 months ago

https://github.com/Makuna/NeoPixelBus/releases/tag/2.7.9