From ed2fb0dcc006cbbca566bd494b82c6353269e12b Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 15 Jun 2019 22:43:47 +0300 Subject: [PATCH] add --- libraries/FastLED-3.2.0/.gitignore | 2 - .../examples/DemoReelESP32/DemoReelESP32.ino | 181 ----- .../examples/RGBCalibrate/RGBCalibrate.ino | 70 -- .../platforms/esp/32/fastled_esp32.h | 5 - .../FastLED.cpp | 0 .../FastLED.h | 16 +- .../{FastLED-3.2.0 => FastLED-3.2.9}/LICENSE | 0 .../PORTING.md | 0 .../README.md | 8 +- .../bitswap.cpp | 0 .../bitswap.h | 0 .../chipsets.h | 206 +++-- .../{FastLED-3.2.0 => FastLED-3.2.9}/color.h | 0 .../colorpalettes.cpp | 0 .../colorpalettes.h | 0 .../colorutils.cpp | 0 .../colorutils.h | 0 libraries/FastLED-3.2.9/component.mk | 1 + .../controller.h | 15 +- .../cpp_compat.h | 0 .../{FastLED-3.2.0 => FastLED-3.2.9}/dmx.h | 0 .../docs/Doxyfile | 0 .../docs/mainpage.dox | 0 .../examples/AnalogOutput/AnalogOutput.ino | 0 .../examples/Blink/Blink.ino | 0 .../examples/ColorPalette/ColorPalette.ino | 2 +- .../ColorTemperature/ColorTemperature.ino | 0 .../examples/Cylon/Cylon.ino | 0 .../examples/DemoReel100/DemoReel100.ino | 0 .../examples/Fire2012/Fire2012.ino | 0 .../Fire2012WithPalette.ino | 0 .../examples/FirstLight/FirstLight.ino | 0 .../ArrayOfLedArrays/ArrayOfLedArrays.ino | 0 .../MirroringSample/MirroringSample.ino | 0 .../Multiple/MultiArrays/MultiArrays.ino | 0 .../MultipleStripsInOneArray.ino | 0 .../OctoWS2811Demo/OctoWS2811Demo.ino | 0 .../ParallelOutputDemo/ParallelOutputDemo.ino | 0 .../examples/Noise/Noise.ino | 0 .../NoisePlayground/NoisePlayground.ino | 0 .../NoisePlusPalette/NoisePlusPalette.ino | 0 .../examples/Pintest/Pintest.ino | 0 .../PJRCSpectrumAnalyzer.ino | 0 .../examples/RGBCalibrate/RGBCalibrate.ino | 72 ++ .../examples/RGBSetDemo/RGBSetDemo.ino | 0 .../examples/SmartMatrix/SmartMatrix.ino | 0 .../examples/XYMatrix/XYMatrix.ino | 0 .../extras/AppleII.s65 | 0 .../extras/FastLED6502.s65 | 0 .../extras/RainbowDemo.bin.zip | Bin .../extras/RainbowDemo.s65 | 0 .../fastled_config.h | 4 + .../fastled_delay.h | 0 .../fastled_progmem.h | 2 +- .../fastpin.h | 0 .../fastspi.h | 5 + .../fastspi_bitbang.h | 12 + .../fastspi_dma.h | 0 .../fastspi_nop.h | 0 .../fastspi_ref.h | 0 .../fastspi_types.h | 0 .../hsv2rgb.cpp | 0 .../hsv2rgb.h | 0 .../keywords.txt | 11 + .../led_sysdefs.h | 6 +- .../lib8tion.cpp | 0 .../lib8tion.h | 2 +- .../lib8tion/math8.h | 29 + .../lib8tion/random8.h | 0 .../lib8tion/scale8.h | 0 .../lib8tion/trig8.h | 0 .../library.json | 17 +- .../library.properties | 2 +- .../noise.cpp | 0 .../{FastLED-3.2.0 => FastLED-3.2.9}/noise.h | 0 .../pixelset.h | 0 .../pixeltypes.h | 12 +- libraries/FastLED-3.2.9/platforms.cpp | 40 + .../platforms.h | 6 +- .../platforms/arm/common/m0clockless.h | 215 +++-- .../platforms/arm/d21/clockless_arm_d21.h | 0 .../platforms/arm/d21/fastled_arm_d21.h | 0 .../platforms/arm/d21/fastpin_arm_d21.h | 68 +- .../platforms/arm/d21/led_sysdefs_arm_d21.h | 2 +- .../platforms/arm/d51/README.txt | 4 + .../platforms/arm/d51/clockless_arm_d51.h | 128 +++ .../platforms/arm/d51/fastled_arm_d51.h | 7 + .../platforms/arm/d51/fastpin_arm_d51.h | 116 +++ .../platforms/arm/d51/led_sysdefs_arm_d51.h | 27 + .../platforms/arm/k20/clockless_arm_k20.h | 0 .../arm/k20/clockless_block_arm_k20.h | 0 .../platforms/arm/k20/fastled_arm_k20.h | 0 .../platforms/arm/k20/fastpin_arm_k20.h | 0 .../platforms/arm/k20/fastspi_arm_k20.h | 0 .../platforms/arm/k20/led_sysdefs_arm_k20.h | 0 .../platforms/arm/k20/octows2811_controller.h | 0 .../platforms/arm/k20/smartmatrix_t3.h | 0 .../arm/k20/ws2812serial_controller.h | 0 .../platforms/arm/k66/clockless_arm_k66.h | 0 .../arm/k66/clockless_block_arm_k66.h | 0 .../platforms/arm/k66/fastled_arm_k66.h | 0 .../platforms/arm/k66/fastpin_arm_k66.h | 0 .../platforms/arm/k66/fastspi_arm_k66.h | 0 .../platforms/arm/k66/led_sysdefs_arm_k66.h | 0 .../platforms/arm/kl26/clockless_arm_kl26.h | 0 .../platforms/arm/kl26/fastled_arm_kl26.h | 0 .../platforms/arm/kl26/fastpin_arm_kl26.h | 0 .../platforms/arm/kl26/fastspi_arm_kl26.h | 0 .../platforms/arm/kl26/led_sysdefs_arm_kl26.h | 0 .../platforms/arm/nrf51/clockless_arm_nrf51.h | 0 .../platforms/arm/nrf51/fastled_arm_nrf51.h | 0 .../platforms/arm/nrf51/fastpin_arm_nrf51.h | 0 .../platforms/arm/nrf51/fastspi_arm_nrf51.h | 0 .../arm/nrf51/led_sysdefs_arm_nrf51.h | 0 .../platforms/arm/nrf52/arbiter_nrf52.h | 115 +++ .../platforms/arm/nrf52/clockless_arm_nrf52.h | 371 +++++++++ .../platforms/arm/nrf52/fastled_arm_nrf52.h | 11 + .../platforms/arm/nrf52/fastpin_arm_nrf52.h | 328 ++++++++ .../arm/nrf52/fastpin_arm_nrf52_variants.h | 579 +++++++++++++ .../platforms/arm/nrf52/fastspi_arm_nrf52.h | 341 ++++++++ .../arm/nrf52/led_sysdefs_arm_nrf52.h | 58 ++ .../platforms/arm/sam/clockless_arm_sam.h | 0 .../arm/sam/clockless_block_arm_sam.h | 0 .../platforms/arm/sam/fastled_arm_sam.h | 0 .../platforms/arm/sam/fastpin_arm_sam.h | 0 .../platforms/arm/sam/fastspi_arm_sam.h | 0 .../platforms/arm/sam/led_sysdefs_arm_sam.h | 0 .../platforms/arm/stm32/clockless_arm_stm32.h | 0 .../platforms/arm/stm32/cm3_regs.h | 63 ++ .../platforms/arm/stm32/fastled_arm_stm32.h | 0 .../platforms/arm/stm32/fastpin_arm_stm32.h | 65 +- .../arm/stm32/led_sysdefs_arm_stm32.h | 34 +- .../platforms/avr/clockless_trinket.h | 84 +- .../platforms/avr/fastled_avr.h | 0 .../platforms/avr/fastpin_avr.h | 12 +- .../platforms/avr/fastspi_avr.h | 177 ++++ .../platforms/avr/led_sysdefs_avr.h | 4 +- .../platforms/esp/32/clockless_block_esp32.h | 0 .../platforms/esp/32/clockless_esp32.h.orig | 0 .../platforms/esp/32/clockless_i2s_esp32.h | 767 ++++++++++++++++++ .../platforms/esp/32/clockless_rmt_esp32.h} | 100 +-- .../platforms/esp/32/fastled_esp32.h | 11 + .../platforms/esp/32/fastpin_esp32.h | 0 .../platforms/esp/32/led_sysdefs_esp32.h | 2 +- .../esp/8266/clockless_block_esp8266.h | 0 .../platforms/esp/8266/clockless_esp8266.h | 2 +- .../platforms/esp/8266/fastled_esp8266.h | 0 .../platforms/esp/8266/fastpin_esp8266.h | 0 .../platforms/esp/8266/led_sysdefs_esp8266.h | 2 +- .../power_mgt.cpp | 0 .../power_mgt.h | 0 .../preview_changes.txt | 0 .../release_notes.md | 68 +- .../wiring.cpp | 0 libraries/ПРОЧТИ МЕНЯ!!!!11111.txt | 8 + 155 files changed, 3946 insertions(+), 549 deletions(-) delete mode 100644 libraries/FastLED-3.2.0/.gitignore delete mode 100644 libraries/FastLED-3.2.0/examples/DemoReelESP32/DemoReelESP32.ino delete mode 100644 libraries/FastLED-3.2.0/examples/RGBCalibrate/RGBCalibrate.ino delete mode 100644 libraries/FastLED-3.2.0/platforms/esp/32/fastled_esp32.h rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/FastLED.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/FastLED.h (97%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/LICENSE (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/PORTING.md (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/README.md (83%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/bitswap.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/bitswap.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/chipsets.h (70%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/color.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/colorpalettes.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/colorpalettes.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/colorutils.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/colorutils.h (100%) create mode 100644 libraries/FastLED-3.2.9/component.mk rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/controller.h (92%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/cpp_compat.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/dmx.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/docs/Doxyfile (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/docs/mainpage.dox (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/AnalogOutput/AnalogOutput.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Blink/Blink.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/ColorPalette/ColorPalette.ino (99%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/ColorTemperature/ColorTemperature.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Cylon/Cylon.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/DemoReel100/DemoReel100.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Fire2012/Fire2012.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Fire2012WithPalette/Fire2012WithPalette.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/FirstLight/FirstLight.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Multiple/MirroringSample/MirroringSample.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Multiple/MultiArrays/MultiArrays.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Multiple/MultipleStripsInOneArray/MultipleStripsInOneArray.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Multiple/OctoWS2811Demo/OctoWS2811Demo.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Multiple/ParallelOutputDemo/ParallelOutputDemo.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Noise/Noise.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/NoisePlayground/NoisePlayground.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/NoisePlusPalette/NoisePlusPalette.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Pintest/Pintest.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/Ports/PJRCSpectrumAnalyzer/PJRCSpectrumAnalyzer.ino (100%) create mode 100644 libraries/FastLED-3.2.9/examples/RGBCalibrate/RGBCalibrate.ino rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/RGBSetDemo/RGBSetDemo.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/SmartMatrix/SmartMatrix.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/examples/XYMatrix/XYMatrix.ino (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/extras/AppleII.s65 (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/extras/FastLED6502.s65 (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/extras/RainbowDemo.bin.zip (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/extras/RainbowDemo.s65 (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastled_config.h (91%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastled_delay.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastled_progmem.h (98%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastpin.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastspi.h (95%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastspi_bitbang.h (97%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastspi_dma.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastspi_nop.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastspi_ref.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/fastspi_types.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/hsv2rgb.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/hsv2rgb.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/keywords.txt (97%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/led_sysdefs.h (85%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/lib8tion.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/lib8tion.h (99%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/lib8tion/math8.h (93%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/lib8tion/random8.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/lib8tion/scale8.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/lib8tion/trig8.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/library.json (75%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/library.properties (96%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/noise.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/noise.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/pixelset.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/pixeltypes.h (98%) create mode 100644 libraries/FastLED-3.2.9/platforms.cpp rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms.h (81%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/common/m0clockless.h (61%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/d21/clockless_arm_d21.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/d21/fastled_arm_d21.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/d21/fastpin_arm_d21.h (80%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/d21/led_sysdefs_arm_d21.h (92%) create mode 100644 libraries/FastLED-3.2.9/platforms/arm/d51/README.txt create mode 100644 libraries/FastLED-3.2.9/platforms/arm/d51/clockless_arm_d51.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/d51/fastled_arm_d51.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/d51/fastpin_arm_d51.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/d51/led_sysdefs_arm_d51.h rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/clockless_arm_k20.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/clockless_block_arm_k20.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/fastled_arm_k20.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/fastpin_arm_k20.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/fastspi_arm_k20.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/led_sysdefs_arm_k20.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/octows2811_controller.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/smartmatrix_t3.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k20/ws2812serial_controller.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k66/clockless_arm_k66.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k66/clockless_block_arm_k66.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k66/fastled_arm_k66.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k66/fastpin_arm_k66.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k66/fastspi_arm_k66.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/k66/led_sysdefs_arm_k66.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/kl26/clockless_arm_kl26.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/kl26/fastled_arm_kl26.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/kl26/fastpin_arm_kl26.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/kl26/fastspi_arm_kl26.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/kl26/led_sysdefs_arm_kl26.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/nrf51/clockless_arm_nrf51.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/nrf51/fastled_arm_nrf51.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/nrf51/fastpin_arm_nrf51.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/nrf51/fastspi_arm_nrf51.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/nrf51/led_sysdefs_arm_nrf51.h (100%) create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/arbiter_nrf52.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/clockless_arm_nrf52.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/fastled_arm_nrf52.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52_variants.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/fastspi_arm_nrf52.h create mode 100644 libraries/FastLED-3.2.9/platforms/arm/nrf52/led_sysdefs_arm_nrf52.h rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/sam/clockless_arm_sam.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/sam/clockless_block_arm_sam.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/sam/fastled_arm_sam.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/sam/fastpin_arm_sam.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/sam/fastspi_arm_sam.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/sam/led_sysdefs_arm_sam.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/stm32/clockless_arm_stm32.h (100%) create mode 100644 libraries/FastLED-3.2.9/platforms/arm/stm32/cm3_regs.h rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/stm32/fastled_arm_stm32.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/stm32/fastpin_arm_stm32.h (71%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/arm/stm32/led_sysdefs_arm_stm32.h (59%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/avr/clockless_trinket.h (88%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/avr/fastled_avr.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/avr/fastpin_avr.h (96%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/avr/fastspi_avr.h (70%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/avr/led_sysdefs_avr.h (92%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/32/clockless_block_esp32.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/32/clockless_esp32.h.orig (100%) create mode 100644 libraries/FastLED-3.2.9/platforms/esp/32/clockless_i2s_esp32.h rename libraries/{FastLED-3.2.0/platforms/esp/32/clockless_esp32.h => FastLED-3.2.9/platforms/esp/32/clockless_rmt_esp32.h} (90%) create mode 100644 libraries/FastLED-3.2.9/platforms/esp/32/fastled_esp32.h rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/32/fastpin_esp32.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/32/led_sysdefs_esp32.h (96%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/8266/clockless_block_esp8266.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/8266/clockless_esp8266.h (99%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/8266/fastled_esp8266.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/8266/fastpin_esp8266.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/platforms/esp/8266/led_sysdefs_esp8266.h (97%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/power_mgt.cpp (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/power_mgt.h (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/preview_changes.txt (100%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/release_notes.md (80%) rename libraries/{FastLED-3.2.0 => FastLED-3.2.9}/wiring.cpp (100%) create mode 100644 libraries/ПРОЧТИ МЕНЯ!!!!11111.txt diff --git a/libraries/FastLED-3.2.0/.gitignore b/libraries/FastLED-3.2.0/.gitignore deleted file mode 100644 index 60b7a71..0000000 --- a/libraries/FastLED-3.2.0/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -html/ -*.gch diff --git a/libraries/FastLED-3.2.0/examples/DemoReelESP32/DemoReelESP32.ino b/libraries/FastLED-3.2.0/examples/DemoReelESP32/DemoReelESP32.ino deleted file mode 100644 index 3a32d4c..0000000 --- a/libraries/FastLED-3.2.0/examples/DemoReelESP32/DemoReelESP32.ino +++ /dev/null @@ -1,181 +0,0 @@ -#include "FastLED.h" - -FASTLED_USING_NAMESPACE - -// FastLED "100-lines-of-code" demo reel, showing just a few -// of the kinds of animation patterns you can quickly and easily -// compose using FastLED. -// -// This example also shows one easy way to define multiple -// animations patterns and have them automatically rotate. -// -// -Mark Kriegsman, December 2014 - -#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) -#warning "Requires FastLED 3.1 or later; check github for latest code." -#endif - -#define DATA_PIN 12 -//#define CLK_PIN 4 -#define LED_TYPE WS2811 -#define COLOR_ORDER GRB -#define NUM_LEDS 27 -CRGB leds[NUM_LEDS]; - -#define BRIGHTNESS 60 -#define FRAMES_PER_SECOND 120 - -// -- The core to run FastLED.show() -#define FASTLED_SHOW_CORE 0 - -// -- Task handles for use in the notifications -static TaskHandle_t FastLEDshowTaskHandle = 0; -static TaskHandle_t userTaskHandle = 0; - -/** show() for ESP32 - * Call this function instead of FastLED.show(). It signals core 0 to issue a show, - * then waits for a notification that it is done. - */ -void FastLEDshowESP32() -{ - if (userTaskHandle == 0) { - // -- Store the handle of the current task, so that the show task can - // notify it when it's done - userTaskHandle = xTaskGetCurrentTaskHandle(); - - // -- Trigger the show task - xTaskNotifyGive(FastLEDshowTaskHandle); - - // -- Wait to be notified that it's done - const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 ); - ulTaskNotifyTake(pdTRUE, xMaxBlockTime); - userTaskHandle = 0; - } -} - -/** show Task - * This function runs on core 0 and just waits for requests to call FastLED.show() - */ -void FastLEDshowTask(void *pvParameters) -{ - // -- Run forever... - for(;;) { - // -- Wait for the trigger - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - - // -- Do the show (synchronously) - FastLED.show(); - - // -- Notify the calling task - xTaskNotifyGive(userTaskHandle); - } -} - -void setup() { - delay(3000); // 3 second delay for recovery - Serial.begin(115200); - - // tell FastLED about the LED strip configuration - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - - // set master brightness control - FastLED.setBrightness(BRIGHTNESS); - - int core = xPortGetCoreID(); - Serial.print("Main code running on core "); - Serial.println(core); - - // -- Create the FastLED show task - xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, &FastLEDshowTaskHandle, FASTLED_SHOW_CORE); -} - - -// List of patterns to cycle through. Each is defined as a separate function below. -typedef void (*SimplePatternList[])(); -SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; - -uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current -uint8_t gHue = 0; // rotating "base color" used by many of the patterns - -void loop() -{ - // Call the current pattern function once, updating the 'leds' array - gPatterns[gCurrentPatternNumber](); - - // send the 'leds' array out to the actual LED strip - FastLEDshowESP32(); - // FastLED.show(); - // insert a delay to keep the framerate modest - FastLED.delay(1000/FRAMES_PER_SECOND); - - // do some periodic updates - EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow - EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically -} - -#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) - -void nextPattern() -{ - // add one to the current pattern number, and wrap around at the end - gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); -} - -void rainbow() -{ - // FastLED's built-in rainbow generator - fill_rainbow( leds, NUM_LEDS, gHue, 7); -} - -void rainbowWithGlitter() -{ - // built-in FastLED rainbow, plus some random sparkly glitter - rainbow(); - addGlitter(80); -} - -void addGlitter( fract8 chanceOfGlitter) -{ - if( random8() < chanceOfGlitter) { - leds[ random16(NUM_LEDS) ] += CRGB::White; - } -} - -void confetti() -{ - // random colored speckles that blink in and fade smoothly - fadeToBlackBy( leds, NUM_LEDS, 10); - int pos = random16(NUM_LEDS); - leds[pos] += CHSV( gHue + random8(64), 200, 255); -} - -void sinelon() -{ - // a colored dot sweeping back and forth, with fading trails - fadeToBlackBy( leds, NUM_LEDS, 20); - int pos = beatsin16( 13, 0, NUM_LEDS-1 ); - leds[pos] += CHSV( gHue, 255, 192); -} - -void bpm() -{ - // colored stripes pulsing at a defined Beats-Per-Minute (BPM) - uint8_t BeatsPerMinute = 62; - CRGBPalette16 palette = PartyColors_p; - uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); - for( int i = 0; i < NUM_LEDS; i++) { //9948 - leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10)); - } -} - -void juggle() { - // eight colored dots, weaving in and out of sync with each other - fadeToBlackBy( leds, NUM_LEDS, 20); - byte dothue = 0; - for( int i = 0; i < 8; i++) { - leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255); - dothue += 32; - } -} - diff --git a/libraries/FastLED-3.2.0/examples/RGBCalibrate/RGBCalibrate.ino b/libraries/FastLED-3.2.0/examples/RGBCalibrate/RGBCalibrate.ino deleted file mode 100644 index 8bc4b12..0000000 --- a/libraries/FastLED-3.2.0/examples/RGBCalibrate/RGBCalibrate.ino +++ /dev/null @@ -1,70 +0,0 @@ -#include - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// RGB Calibration code -// -// Use this sketch to determine what the RGB ordering for your chipset should be. Steps for setting up to use: - -// * Uncomment the line in setup that corresponds to the LED chipset that you are using. (Note that they -// all explicitly specify the RGB order as RGB) -// * Define DATA_PIN to the pin that data is connected to. -// * (Optional) if using software SPI for chipsets that are SPI based, define CLOCK_PIN to the clock pin -// * Compile/upload/run the sketch - -// You should see six leds on. If the RGB ordering is correct, you should see 1 red led, 2 green -// leds, and 3 blue leds. If you see different colors, the count of each color tells you what the -// position for that color in the rgb orering should be. So, for example, if you see 1 Blue, and 2 -// Red, and 3 Green leds then the rgb ordering should be BRG (Blue, Red, Green). - -// You can then test this ordering by setting the RGB ordering in the addLeds line below to the new ordering -// and it should come out correctly, 1 red, 2 green, and 3 blue. -// -////////////////////////////////////////////////// - -#define NUM_LEDS 6 - -// Data pin that led data will be written out over -#define DATA_PIN 6 -// Clock pin only needed for SPI based chipsets when not using hardware SPI -//#define CLOCK_PIN 8 - -CRGB leds[NUM_LEDS]; - -void setup() { - // sanity check delay - allows reprogramming if accidently blowing power w/leds - delay(2000); - - // Uncomment one of the following lines for your leds arrangement. - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.setBrightness(CRGB(255,255,255)); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - FastLED.addLeds(leds, NUM_LEDS); - - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); - // FastLED.addLeds(leds, NUM_LEDS); -} - -void loop() { - leds[0] = CRGB(255,0,0); - leds[1] = CRGB(0,255,0); - leds[2] = CRGB(0,255,0); - leds[3] = CRGB(0,0,255); - leds[4] = CRGB(0,0,255); - leds[5] = CRGB(0,0,255); - FastLED.show(); - delay(1000); -} diff --git a/libraries/FastLED-3.2.0/platforms/esp/32/fastled_esp32.h b/libraries/FastLED-3.2.0/platforms/esp/32/fastled_esp32.h deleted file mode 100644 index fabbfed..0000000 --- a/libraries/FastLED-3.2.0/platforms/esp/32/fastled_esp32.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "fastpin_esp32.h" -#include "clockless_esp32.h" -// #include "clockless_block_esp32.h" diff --git a/libraries/FastLED-3.2.0/FastLED.cpp b/libraries/FastLED-3.2.9/FastLED.cpp similarity index 100% rename from libraries/FastLED-3.2.0/FastLED.cpp rename to libraries/FastLED-3.2.9/FastLED.cpp diff --git a/libraries/FastLED-3.2.0/FastLED.h b/libraries/FastLED-3.2.9/FastLED.h similarity index 97% rename from libraries/FastLED-3.2.0/FastLED.h rename to libraries/FastLED-3.2.9/FastLED.h index b0aa3fa..8fe2b55 100644 --- a/libraries/FastLED-3.2.0/FastLED.h +++ b/libraries/FastLED-3.2.9/FastLED.h @@ -4,19 +4,16 @@ ///@file FastLED.h /// central include file for FastLED, defines the CFastLED class/object -#define xstr(s) str(s) -#define str(s) #s - #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) #define FASTLED_HAS_PRAGMA_MESSAGE #endif -#define FASTLED_VERSION 3002000 +#define FASTLED_VERSION 3002009 #ifndef FASTLED_INTERNAL # ifdef FASTLED_HAS_PRAGMA_MESSAGE -# pragma message "FastLED version 3.002.000" +# pragma message "FastLED version 3.002.009" # else -# warning FastLED version 3.002.000 (Not really a warning, just telling you here.) +# warning FastLED version 3.002.009 (Not really a warning, just telling you here.) # endif #endif @@ -72,6 +69,7 @@ FASTLED_NAMESPACE_BEGIN /// definitions for the spi chipset constants enum ESPIChipsets { + LPD6803, LPD8806, WS2801, WS2803, @@ -92,6 +90,7 @@ template class PIXIE : public PixieControlle #ifdef FASTLED_HAS_CLOCKLESS template class NEOPIXEL : public WS2812Controller800Khz {}; +template class SM16703 : public SM16703Controller {}; template class TM1829 : public TM1829Controller800Khz {}; template class TM1812 : public TM1809Controller800Khz {}; template class TM1809 : public TM1809Controller800Khz {}; @@ -104,6 +103,7 @@ template class UCS2903 : public UCS2903Contr template class WS2812 : public WS2812Controller800Khz {}; template class WS2852 : public WS2812Controller800Khz {}; template class WS2812B : public WS2812Controller800Khz {}; +template class GS1903 : public WS2812Controller800Khz {}; template class SK6812 : public SK6812Controller {}; template class SK6822 : public SK6822Controller {}; template class APA106 : public SK6822Controller {}; @@ -112,6 +112,7 @@ template class WS2811 : public WS2811Control template class WS2813 : public WS2813Controller {}; template class APA104 : public WS2811Controller800Khz {}; template class WS2811_400 : public WS2811Controller400Khz {}; +template class GE8822 : public GE8822Controller800Khz {}; template class GW6205 : public GW6205Controller800Khz {}; template class GW6205_400 : public GW6205Controller400Khz {}; template class LPD1886 : public LPD1886Controller1250Khz {}; @@ -221,6 +222,7 @@ public: /// @returns a reference to the added controller template CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { switch(CHIPSET) { + case LPD6803: { static LPD6803Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case LPD8806: { static LPD8806Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case WS2801: { static WS2801Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case WS2803: { static WS2803Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } @@ -234,6 +236,7 @@ public: template static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { switch(CHIPSET) { + case LPD6803: { static LPD6803Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case LPD8806: { static LPD8806Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case WS2801: { static WS2801Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case WS2803: { static WS2803Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } @@ -247,6 +250,7 @@ public: template static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { switch(CHIPSET) { + case LPD6803: { static LPD6803Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case LPD8806: { static LPD8806Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case WS2801: { static WS2801Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } case WS2803: { static WS2803Controller c; return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } diff --git a/libraries/FastLED-3.2.0/LICENSE b/libraries/FastLED-3.2.9/LICENSE similarity index 100% rename from libraries/FastLED-3.2.0/LICENSE rename to libraries/FastLED-3.2.9/LICENSE diff --git a/libraries/FastLED-3.2.0/PORTING.md b/libraries/FastLED-3.2.9/PORTING.md similarity index 100% rename from libraries/FastLED-3.2.0/PORTING.md rename to libraries/FastLED-3.2.9/PORTING.md diff --git a/libraries/FastLED-3.2.0/README.md b/libraries/FastLED-3.2.9/README.md similarity index 83% rename from libraries/FastLED-3.2.0/README.md rename to libraries/FastLED-3.2.9/README.md index ebf3bf0..11a4fd7 100644 --- a/libraries/FastLED-3.2.0/README.md +++ b/libraries/FastLED-3.2.9/README.md @@ -1,9 +1,10 @@ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/FastLED/public) +[![arduino-library-badge](https://www.ardu-badge.com/badge/FastLED.svg)](https://www.ardu-badge.com/FastLED) IMPORTANT NOTE: For AVR based systems, avr-gcc 4.8.x is supported and tested. This means Arduino 1.6.5 and later. -FastLED 3.1 +FastLED 3.2 =========== This is a library for easily & efficiently controlling a wide variety of LED chipsets, like the ones @@ -22,7 +23,7 @@ We have multiple goals with this library: ## Getting help -If you need help with using the library, please consider going to the google+ community first, which is at http://fastled.io/+ - there are hundreds of people in that group and many times you will get a quicker answer to your question there, as you will be likely to run into other people who have had the same issue. If you run into bugs with the library (compilation failures, the library doing the wrong thing), or if you'd like to request that we support a particular platform or LED chipset, then please open an issue at http://fastled.io/issues and we will try to figure out what is going wrong. +If you need help with using the library, please consider going to the reddit community first, which is at http://fastled.io/r (or https://reddit.com/r/FastLED) - there are hundreds of people in that group and many times you will get a quicker answer to your question there, as you will be likely to run into other people who have had the same issue. If you run into bugs with the library (compilation failures, the library doing the wrong thing), or if you'd like to request that we support a particular platform or LED chipset, then please open an issue at http://fastled.io/issues and we will try to figure out what is going wrong. ## Simple example @@ -54,9 +55,10 @@ Here's a list of all the LED chipsets are supported. More details on the led ch * P9813 - aka Cool Neon's Total Control Lighting * DMX - send rgb data out over DMX using arduino DMX libraries * SmartMatrix panels - needs the SmartMatrix library - https://github.com/pixelmatix/SmartMatrix +* LPD6803 - SPI based chpiset, chip CMODE pin must be set to 1 (inside oscillator mode) -LPD6803, HL1606, and "595"-style shift registers are no longer supported by the library. The older Version 1 of the library ("FastSPI_LED") has support for these, but is missing many of the advanced features of current versions and is no longer being maintained. +HL1606, and "595"-style shift registers are no longer supported by the library. The older Version 1 of the library ("FastSPI_LED") has support for these, but is missing many of the advanced features of current versions and is no longer being maintained. ## Supported platforms diff --git a/libraries/FastLED-3.2.0/bitswap.cpp b/libraries/FastLED-3.2.9/bitswap.cpp similarity index 100% rename from libraries/FastLED-3.2.0/bitswap.cpp rename to libraries/FastLED-3.2.9/bitswap.cpp diff --git a/libraries/FastLED-3.2.0/bitswap.h b/libraries/FastLED-3.2.9/bitswap.h similarity index 100% rename from libraries/FastLED-3.2.0/bitswap.h rename to libraries/FastLED-3.2.9/bitswap.h diff --git a/libraries/FastLED-3.2.0/chipsets.h b/libraries/FastLED-3.2.9/chipsets.h similarity index 70% rename from libraries/FastLED-3.2.0/chipsets.h rename to libraries/FastLED-3.2.9/chipsets.h index 659eeb2..d452abf 100644 --- a/libraries/FastLED-3.2.0/chipsets.h +++ b/libraries/FastLED-3.2.9/chipsets.h @@ -143,6 +143,53 @@ protected: template class WS2803Controller : public WS2801Controller {}; +/// LPD6803 controller class (LPD1101). +/// 16 bit (1 bit - const "1", 5 bit - red, 5 bit - green, 5 bit blue). +/// In chip CMODE pin must be set to 1 (inside oscillator mode). +/// Datasheet: https://cdn-shop.adafruit.com/datasheets/LPD6803.pdf +/// @tparam DATA_PIN the data pin for these leds +/// @tparam CLOCK_PIN the clock pin for these leds +/// @tparam RGB_ORDER the RGB ordering for these leds +/// @tparam SPI_SPEED the clock divider used for these leds. Set using the DATA_RATE_MHZ/DATA_RATE_KHZ macros. Defaults to DATA_RATE_MHZ(12) +template +class LPD6803Controller : public CPixelLEDController { + typedef SPIOutput SPI; + SPI mSPI; + + void startBoundary() { mSPI.writeByte(0); mSPI.writeByte(0); mSPI.writeByte(0); mSPI.writeByte(0); } + +public: + LPD6803Controller() {} + + virtual void init() { + mSPI.init(); + } + +protected: + + virtual void showPixels(PixelController & pixels) { + mSPI.select(); + + startBoundary(); + while(pixels.has(1)) { + register uint16_t command; + command = 0x8000; + command |= (pixels.loadAndScale0() & 0xF8) << 7; // red is the high 5 bits + command |= (pixels.loadAndScale1() & 0xF8) << 2; // green is the middle 5 bits + mSPI.writeByte((command >> 8) & 0xFF); + command |= pixels.loadAndScale2() >> 3 ; // blue is the low 5 bits + mSPI.writeByte(command & 0xFF); + + pixels.stepDithering(); + pixels.advanceData(); + } + //endBoundary(pixels.size()); + mSPI.waitFully(); + mSPI.release(); + } + +}; + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // APA102 definition - takes data/clock/select pin values (N.B. should take an SPI definition?) @@ -162,8 +209,19 @@ class APA102Controller : public CPixelLEDController { void startBoundary() { mSPI.writeWord(0); mSPI.writeWord(0); } void endBoundary(int nLeds) { int nDWords = (nLeds/32); do { mSPI.writeByte(0xFF); mSPI.writeByte(0x00); mSPI.writeByte(0x00); mSPI.writeByte(0x00); } while(nDWords--); } - inline void writeLed(uint8_t b0, uint8_t b1, uint8_t b2) __attribute__((always_inline)) { - mSPI.writeByte(0xFF); mSPI.writeByte(b0); mSPI.writeByte(b1); mSPI.writeByte(b2); + inline void writeLed(uint8_t brightness, uint8_t b0, uint8_t b1, uint8_t b2) __attribute__((always_inline)) { +#ifdef FASTLED_SPI_BYTE_ONLY + mSPI.writeByte(0xE0 | brightness); + mSPI.writeByte(b0); + mSPI.writeByte(b1); + mSPI.writeByte(b2); +#else + uint16_t b = 0xE000 | (brightness << 8) | (uint16_t)b0; + mSPI.writeWord(b); + uint16_t w = b1 << 8; + w |= b2; + mSPI.writeWord(w); +#endif } public: @@ -178,24 +236,25 @@ protected: virtual void showPixels(PixelController & pixels) { mSPI.select(); - startBoundary(); - while(pixels.has(1)) { -#ifdef FASTLED_SPI_BYTE_ONLY - mSPI.writeByte(0xFF); - mSPI.writeByte(pixels.loadAndScale0()); - mSPI.writeByte(pixels.loadAndScale1()); - mSPI.writeByte(pixels.loadAndScale2()); + uint8_t s0 = pixels.getScale0(), s1 = pixels.getScale1(), s2 = pixels.getScale2(); +#if FASTLED_USE_GLOBAL_BRIGHTNESS == 1 + const uint16_t maxBrightness = 0x1F; + uint16_t brightness = ((((uint16_t)max(max(s0, s1), s2) + 1) * maxBrightness - 1) >> 8) + 1; + s0 = (maxBrightness * s0 + (brightness >> 1)) / brightness; + s1 = (maxBrightness * s1 + (brightness >> 1)) / brightness; + s2 = (maxBrightness * s2 + (brightness >> 1)) / brightness; #else - uint16_t b = 0xFF00 | (uint16_t)pixels.loadAndScale0(); - mSPI.writeWord(b); - uint16_t w = pixels.loadAndScale1() << 8; - w |= pixels.loadAndScale2(); - mSPI.writeWord(w); + const uint8_t brightness = 0x1F; #endif + + startBoundary(); + while (pixels.has(1)) { + writeLed(brightness, pixels.loadAndScale0(0, s0), pixels.loadAndScale1(0, s1), pixels.loadAndScale2(0, s2)); pixels.stepDithering(); pixels.advanceData(); } endBoundary(pixels.size()); + mSPI.waitFully(); mSPI.release(); } @@ -215,8 +274,19 @@ class SK9822Controller : public CPixelLEDController { void startBoundary() { mSPI.writeWord(0); mSPI.writeWord(0); } void endBoundary(int nLeds) { int nLongWords = (nLeds/32); do { mSPI.writeByte(0x00); mSPI.writeByte(0x00); mSPI.writeByte(0x00); mSPI.writeByte(0x00); } while(nLongWords--); } - inline void writeLed(uint8_t b0, uint8_t b1, uint8_t b2) __attribute__((always_inline)) { - mSPI.writeByte(0xFF); mSPI.writeByte(b0); mSPI.writeByte(b1); mSPI.writeByte(b2); + inline void writeLed(uint8_t brightness, uint8_t b0, uint8_t b1, uint8_t b2) __attribute__((always_inline)) { +#ifdef FASTLED_SPI_BYTE_ONLY + mSPI.writeByte(0xE0 | brightness); + mSPI.writeByte(b0); + mSPI.writeByte(b1); + mSPI.writeByte(b2); +#else + uint16_t b = 0xE000 | (brightness << 8) | (uint16_t)b0; + mSPI.writeWord(b); + uint16_t w = b1 << 8; + w |= b2; + mSPI.writeWord(w); +#endif } public: @@ -231,20 +301,20 @@ protected: virtual void showPixels(PixelController & pixels) { mSPI.select(); - startBoundary(); - while(pixels.has(1)) { -#ifdef FASTLED_SPI_BYTE_ONLY - mSPI.writeByte(0xFF); - mSPI.writeByte(pixels.loadAndScale0()); - mSPI.writeByte(pixels.loadAndScale1()); - mSPI.writeByte(pixels.loadAndScale2()); + uint8_t s0 = pixels.getScale0(), s1 = pixels.getScale1(), s2 = pixels.getScale2(); +#if FASTLED_USE_GLOBAL_BRIGHTNESS == 1 + const uint16_t maxBrightness = 0x1F; + uint16_t brightness = ((((uint16_t)max(max(s0, s1), s2) + 1) * maxBrightness - 1) >> 8) + 1; + s0 = (maxBrightness * s0 + (brightness >> 1)) / brightness; + s1 = (maxBrightness * s1 + (brightness >> 1)) / brightness; + s2 = (maxBrightness * s2 + (brightness >> 1)) / brightness; #else - uint16_t b = 0xFF00 | (uint16_t)pixels.loadAndScale0(); - mSPI.writeWord(b); - uint16_t w = pixels.loadAndScale1() << 8; - w |= pixels.loadAndScale2(); - mSPI.writeWord(w); + const uint8_t brightness = 0x1F; #endif + + startBoundary(); + while (pixels.has(1)) { + writeLed(brightness, pixels.loadAndScale0(0, s0), pixels.loadAndScale1(0, s1), pixels.loadAndScale2(0, s2)); pixels.stepDithering(); pixels.advanceData(); } @@ -358,6 +428,16 @@ protected: // // Clockless template instantiations - see clockless.h for how the timing values are used // +// Base template for clockless controllers. These controllers have 3 control points in their cycle for each bit. +// At T=0 : the line is raised hi to start a bit +// At T=T1 : the line is dropped low to transmit a zero bit +// At T=T1+T2 : the line is dropped low to transmit a one bit +// At T=T1+T2+T3 : the cycle is concluded (next bit can be sent) +// +// The units used for T1, T2, and T3 is nanoseconds. +// For 8MHz/16MHz/24MHz frequencies, these values are also guaranteed +// to be integral multiples of an 8MHz clock (125ns increments). +// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef FASTLED_HAS_CLOCKLESS @@ -365,10 +445,21 @@ protected: /// Provides timing definitions for the variety of clockless controllers supplied by the library. /// @{ +// Allow clock that clockless controller is based on to have different +// frequency than the CPU. +#if !defined(CLOCKLESS_FREQUENCY) + #define CLOCKLESS_FREQUENCY F_CPU +#endif + // We want to force all avr's to use the Trinket controller when running at 8Mhz, because even the 328's at 8Mhz // need the more tightly defined timeframes. -#if (F_CPU == 8000000 || F_CPU == 16000000 || F_CPU == 24000000) // || F_CPU == 48000000 || F_CPU == 96000000) // 125ns/clock -#define FMUL (F_CPU/8000000) +#if (CLOCKLESS_FREQUENCY == 8000000 || CLOCKLESS_FREQUENCY == 16000000 || CLOCKLESS_FREQUENCY == 24000000) // || CLOCKLESS_FREQUENCY == 48000000 || CLOCKLESS_FREQUENCY == 96000000) // 125ns/clock +#define FMUL (CLOCKLESS_FREQUENCY/8000000) + +// GE8822 +template +class GE8822Controller800Khz : public ClocklessController {}; + // LPD1886 template class LPD1886Controller1250Khz : public ClocklessController {}; @@ -393,6 +484,9 @@ class WS2811Controller400Khz : public ClocklessController class SK6822Controller : public ClocklessController {}; +template +class SM16703Controller : public ClocklessController {}; + template class SK6812Controller : public ClocklessController {}; @@ -415,7 +509,7 @@ template class TM1803Controller400Khz : public ClocklessController {}; template -class TM1829Controller800Khz : public ClocklessController {}; +class TM1829Controller800Khz : public ClocklessController {}; template class GW6205Controller400Khz : public ClocklessController {}; @@ -427,75 +521,87 @@ template class PL9823Controller : public ClocklessController {}; #else + +// Similar to NS() macro, this calculates the number of cycles for +// the clockless chipset (which may differ from CPU cycles) +#define C_NS(_NS) (((_NS * ((CLOCKLESS_FREQUENCY / 1000000L)) + 999)) / 1000) + +// GE8822 - 350ns 660ns 350ns +template +class GE8822Controller800Khz : public ClocklessController {}; + // GW6205@400khz - 800ns, 800ns, 800ns template -class GW6205Controller400Khz : public ClocklessController {}; +class GW6205Controller400Khz : public ClocklessController {}; // GW6205@400khz - 400ns, 400ns, 400ns template -class GW6205Controller800Khz : public ClocklessController {}; +class GW6205Controller800Khz : public ClocklessController {}; // UCS1903 - 500ns, 1500ns, 500ns template -class UCS1903Controller400Khz : public ClocklessController {}; +class UCS1903Controller400Khz : public ClocklessController {}; // UCS1903B - 400ns, 450ns, 450ns template -class UCS1903BController800Khz : public ClocklessController {}; +class UCS1903BController800Khz : public ClocklessController {}; // UCS1904 - 400ns, 400ns, 450ns template -class UCS1904Controller800Khz : public ClocklessController {}; +class UCS1904Controller800Khz : public ClocklessController {}; // UCS2903 - 250ns, 750ns, 250ns template -class UCS2903Controller : public ClocklessController {}; +class UCS2903Controller : public ClocklessController {}; // TM1809 - 350ns, 350ns, 550ns template -class TM1809Controller800Khz : public ClocklessController {}; +class TM1809Controller800Khz : public ClocklessController {}; // WS2811 - 320ns, 320ns, 640ns template -class WS2811Controller800Khz : public ClocklessController {}; +class WS2811Controller800Khz : public ClocklessController {}; // WS2813 - 320ns, 320ns, 640ns template -class WS2813Controller : public ClocklessController {}; +class WS2813Controller : public ClocklessController {}; // WS2812 - 250ns, 625ns, 375ns template -class WS2812Controller800Khz : public ClocklessController {}; +class WS2812Controller800Khz : public ClocklessController {}; // WS2811@400khz - 800ns, 800ns, 900ns template -class WS2811Controller400Khz : public ClocklessController {}; +class WS2811Controller400Khz : public ClocklessController {}; // 750NS, 750NS, 750NS template -class TM1803Controller400Khz : public ClocklessController {}; +class TM1803Controller400Khz : public ClocklessController {}; template -class TM1829Controller800Khz : public ClocklessController {}; +class TM1829Controller800Khz : public ClocklessController {}; template -class TM1829Controller1600Khz : public ClocklessController {}; +class TM1829Controller1600Khz : public ClocklessController {}; template -class LPD1886Controller1250Khz : public ClocklessController {}; +class LPD1886Controller1250Khz : public ClocklessController {}; template -class LPD1886Controller1250Khz_8bit : public ClocklessController {}; +class LPD1886Controller1250Khz_8bit : public ClocklessController {}; template -class SK6822Controller : public ClocklessController {}; +class SK6822Controller : public ClocklessController {}; template -class SK6812Controller : public ClocklessController {}; +class SK6812Controller : public ClocklessController {}; template -class PL9823Controller : public ClocklessController {}; +class SM16703Controller : public ClocklessController {}; + +template +class PL9823Controller : public ClocklessController {}; #endif ///@} diff --git a/libraries/FastLED-3.2.0/color.h b/libraries/FastLED-3.2.9/color.h similarity index 100% rename from libraries/FastLED-3.2.0/color.h rename to libraries/FastLED-3.2.9/color.h diff --git a/libraries/FastLED-3.2.0/colorpalettes.cpp b/libraries/FastLED-3.2.9/colorpalettes.cpp similarity index 100% rename from libraries/FastLED-3.2.0/colorpalettes.cpp rename to libraries/FastLED-3.2.9/colorpalettes.cpp diff --git a/libraries/FastLED-3.2.0/colorpalettes.h b/libraries/FastLED-3.2.9/colorpalettes.h similarity index 100% rename from libraries/FastLED-3.2.0/colorpalettes.h rename to libraries/FastLED-3.2.9/colorpalettes.h diff --git a/libraries/FastLED-3.2.0/colorutils.cpp b/libraries/FastLED-3.2.9/colorutils.cpp similarity index 100% rename from libraries/FastLED-3.2.0/colorutils.cpp rename to libraries/FastLED-3.2.9/colorutils.cpp diff --git a/libraries/FastLED-3.2.0/colorutils.h b/libraries/FastLED-3.2.9/colorutils.h similarity index 100% rename from libraries/FastLED-3.2.0/colorutils.h rename to libraries/FastLED-3.2.9/colorutils.h diff --git a/libraries/FastLED-3.2.9/component.mk b/libraries/FastLED-3.2.9/component.mk new file mode 100644 index 0000000..27ad11a --- /dev/null +++ b/libraries/FastLED-3.2.9/component.mk @@ -0,0 +1 @@ +COMPONENT_ADD_INCLUDEDIRS := . diff --git a/libraries/FastLED-3.2.0/controller.h b/libraries/FastLED-3.2.9/controller.h similarity index 92% rename from libraries/FastLED-3.2.0/controller.h rename to libraries/FastLED-3.2.9/controller.h index 61b5a94..30e4c11 100644 --- a/libraries/FastLED-3.2.0/controller.h +++ b/libraries/FastLED-3.2.9/controller.h @@ -357,11 +357,18 @@ struct PixelController { template __attribute__((always_inline)) inline static uint8_t advanceAndLoadAndScale(PixelController & pc) { pc.advanceData(); return pc.loadAndScale(pc); } template __attribute__((always_inline)) inline static uint8_t advanceAndLoadAndScale(PixelController & pc, int lane) { pc.advanceData(); return pc.loadAndScale(pc, lane); } + template __attribute__((always_inline)) inline static uint8_t advanceAndLoadAndScale(PixelController & pc, int lane, uint8_t scale) { pc.advanceData(); return pc.loadAndScale(pc, lane, scale); } - template __attribute__((always_inline)) inline static uint8_t getd(PixelController & pc) { return pc.d[RO(SLOT)]; } - template __attribute__((always_inline)) inline static uint8_t getscale(PixelController & pc) { return pc.mScale.raw[RO(SLOT)]; } + template __attribute__((always_inline)) inline static uint8_t getd(PixelController & pc) { return pc.d[RO(SLOT)]; } + template __attribute__((always_inline)) inline static uint8_t getscale(PixelController & pc) { return pc.mScale.raw[RO(SLOT)]; } // Helper functions to get around gcc stupidities + __attribute__((always_inline)) inline uint8_t loadAndScale0(int lane, uint8_t scale) { return loadAndScale<0>(*this, lane, scale); } + __attribute__((always_inline)) inline uint8_t loadAndScale1(int lane, uint8_t scale) { return loadAndScale<1>(*this, lane, scale); } + __attribute__((always_inline)) inline uint8_t loadAndScale2(int lane, uint8_t scale) { return loadAndScale<2>(*this, lane, scale); } + __attribute__((always_inline)) inline uint8_t advanceAndLoadAndScale0(int lane, uint8_t scale) { return advanceAndLoadAndScale<0>(*this, lane, scale); } + __attribute__((always_inline)) inline uint8_t stepAdvanceAndLoadAndScale0(int lane, uint8_t scale) { stepDithering(); return advanceAndLoadAndScale<0>(*this, lane, scale); } + __attribute__((always_inline)) inline uint8_t loadAndScale0(int lane) { return loadAndScale<0>(*this, lane); } __attribute__((always_inline)) inline uint8_t loadAndScale1(int lane) { return loadAndScale<1>(*this, lane); } __attribute__((always_inline)) inline uint8_t loadAndScale2(int lane) { return loadAndScale<2>(*this, lane); } @@ -373,6 +380,10 @@ struct PixelController { __attribute__((always_inline)) inline uint8_t loadAndScale2() { return loadAndScale<2>(*this); } __attribute__((always_inline)) inline uint8_t advanceAndLoadAndScale0() { return advanceAndLoadAndScale<0>(*this); } __attribute__((always_inline)) inline uint8_t stepAdvanceAndLoadAndScale0() { stepDithering(); return advanceAndLoadAndScale<0>(*this); } + + __attribute__((always_inline)) inline uint8_t getScale0() { return getscale<0>(*this); } + __attribute__((always_inline)) inline uint8_t getScale1() { return getscale<1>(*this); } + __attribute__((always_inline)) inline uint8_t getScale2() { return getscale<2>(*this); } }; template class CPixelLEDController : public CLEDController { diff --git a/libraries/FastLED-3.2.0/cpp_compat.h b/libraries/FastLED-3.2.9/cpp_compat.h similarity index 100% rename from libraries/FastLED-3.2.0/cpp_compat.h rename to libraries/FastLED-3.2.9/cpp_compat.h diff --git a/libraries/FastLED-3.2.0/dmx.h b/libraries/FastLED-3.2.9/dmx.h similarity index 100% rename from libraries/FastLED-3.2.0/dmx.h rename to libraries/FastLED-3.2.9/dmx.h diff --git a/libraries/FastLED-3.2.0/docs/Doxyfile b/libraries/FastLED-3.2.9/docs/Doxyfile similarity index 100% rename from libraries/FastLED-3.2.0/docs/Doxyfile rename to libraries/FastLED-3.2.9/docs/Doxyfile diff --git a/libraries/FastLED-3.2.0/docs/mainpage.dox b/libraries/FastLED-3.2.9/docs/mainpage.dox similarity index 100% rename from libraries/FastLED-3.2.0/docs/mainpage.dox rename to libraries/FastLED-3.2.9/docs/mainpage.dox diff --git a/libraries/FastLED-3.2.0/examples/AnalogOutput/AnalogOutput.ino b/libraries/FastLED-3.2.9/examples/AnalogOutput/AnalogOutput.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/AnalogOutput/AnalogOutput.ino rename to libraries/FastLED-3.2.9/examples/AnalogOutput/AnalogOutput.ino diff --git a/libraries/FastLED-3.2.0/examples/Blink/Blink.ino b/libraries/FastLED-3.2.9/examples/Blink/Blink.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Blink/Blink.ino rename to libraries/FastLED-3.2.9/examples/Blink/Blink.ino diff --git a/libraries/FastLED-3.2.0/examples/ColorPalette/ColorPalette.ino b/libraries/FastLED-3.2.9/examples/ColorPalette/ColorPalette.ino similarity index 99% rename from libraries/FastLED-3.2.0/examples/ColorPalette/ColorPalette.ino rename to libraries/FastLED-3.2.9/examples/ColorPalette/ColorPalette.ino index 0fdfb59..4d64efb 100644 --- a/libraries/FastLED-3.2.0/examples/ColorPalette/ColorPalette.ino +++ b/libraries/FastLED-3.2.9/examples/ColorPalette/ColorPalette.ino @@ -165,7 +165,7 @@ const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM = -// Additionl notes on FastLED compact palettes: +// Additional notes on FastLED compact palettes: // // Normally, in computer graphics, the palette (or "color lookup table") // has 256 entries, each containing a specific 24-bit RGB color. You can then diff --git a/libraries/FastLED-3.2.0/examples/ColorTemperature/ColorTemperature.ino b/libraries/FastLED-3.2.9/examples/ColorTemperature/ColorTemperature.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/ColorTemperature/ColorTemperature.ino rename to libraries/FastLED-3.2.9/examples/ColorTemperature/ColorTemperature.ino diff --git a/libraries/FastLED-3.2.0/examples/Cylon/Cylon.ino b/libraries/FastLED-3.2.9/examples/Cylon/Cylon.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Cylon/Cylon.ino rename to libraries/FastLED-3.2.9/examples/Cylon/Cylon.ino diff --git a/libraries/FastLED-3.2.0/examples/DemoReel100/DemoReel100.ino b/libraries/FastLED-3.2.9/examples/DemoReel100/DemoReel100.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/DemoReel100/DemoReel100.ino rename to libraries/FastLED-3.2.9/examples/DemoReel100/DemoReel100.ino diff --git a/libraries/FastLED-3.2.0/examples/Fire2012/Fire2012.ino b/libraries/FastLED-3.2.9/examples/Fire2012/Fire2012.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Fire2012/Fire2012.ino rename to libraries/FastLED-3.2.9/examples/Fire2012/Fire2012.ino diff --git a/libraries/FastLED-3.2.0/examples/Fire2012WithPalette/Fire2012WithPalette.ino b/libraries/FastLED-3.2.9/examples/Fire2012WithPalette/Fire2012WithPalette.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Fire2012WithPalette/Fire2012WithPalette.ino rename to libraries/FastLED-3.2.9/examples/Fire2012WithPalette/Fire2012WithPalette.ino diff --git a/libraries/FastLED-3.2.0/examples/FirstLight/FirstLight.ino b/libraries/FastLED-3.2.9/examples/FirstLight/FirstLight.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/FirstLight/FirstLight.ino rename to libraries/FastLED-3.2.9/examples/FirstLight/FirstLight.ino diff --git a/libraries/FastLED-3.2.0/examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino b/libraries/FastLED-3.2.9/examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino rename to libraries/FastLED-3.2.9/examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino diff --git a/libraries/FastLED-3.2.0/examples/Multiple/MirroringSample/MirroringSample.ino b/libraries/FastLED-3.2.9/examples/Multiple/MirroringSample/MirroringSample.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Multiple/MirroringSample/MirroringSample.ino rename to libraries/FastLED-3.2.9/examples/Multiple/MirroringSample/MirroringSample.ino diff --git a/libraries/FastLED-3.2.0/examples/Multiple/MultiArrays/MultiArrays.ino b/libraries/FastLED-3.2.9/examples/Multiple/MultiArrays/MultiArrays.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Multiple/MultiArrays/MultiArrays.ino rename to libraries/FastLED-3.2.9/examples/Multiple/MultiArrays/MultiArrays.ino diff --git a/libraries/FastLED-3.2.0/examples/Multiple/MultipleStripsInOneArray/MultipleStripsInOneArray.ino b/libraries/FastLED-3.2.9/examples/Multiple/MultipleStripsInOneArray/MultipleStripsInOneArray.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Multiple/MultipleStripsInOneArray/MultipleStripsInOneArray.ino rename to libraries/FastLED-3.2.9/examples/Multiple/MultipleStripsInOneArray/MultipleStripsInOneArray.ino diff --git a/libraries/FastLED-3.2.0/examples/Multiple/OctoWS2811Demo/OctoWS2811Demo.ino b/libraries/FastLED-3.2.9/examples/Multiple/OctoWS2811Demo/OctoWS2811Demo.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Multiple/OctoWS2811Demo/OctoWS2811Demo.ino rename to libraries/FastLED-3.2.9/examples/Multiple/OctoWS2811Demo/OctoWS2811Demo.ino diff --git a/libraries/FastLED-3.2.0/examples/Multiple/ParallelOutputDemo/ParallelOutputDemo.ino b/libraries/FastLED-3.2.9/examples/Multiple/ParallelOutputDemo/ParallelOutputDemo.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Multiple/ParallelOutputDemo/ParallelOutputDemo.ino rename to libraries/FastLED-3.2.9/examples/Multiple/ParallelOutputDemo/ParallelOutputDemo.ino diff --git a/libraries/FastLED-3.2.0/examples/Noise/Noise.ino b/libraries/FastLED-3.2.9/examples/Noise/Noise.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Noise/Noise.ino rename to libraries/FastLED-3.2.9/examples/Noise/Noise.ino diff --git a/libraries/FastLED-3.2.0/examples/NoisePlayground/NoisePlayground.ino b/libraries/FastLED-3.2.9/examples/NoisePlayground/NoisePlayground.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/NoisePlayground/NoisePlayground.ino rename to libraries/FastLED-3.2.9/examples/NoisePlayground/NoisePlayground.ino diff --git a/libraries/FastLED-3.2.0/examples/NoisePlusPalette/NoisePlusPalette.ino b/libraries/FastLED-3.2.9/examples/NoisePlusPalette/NoisePlusPalette.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/NoisePlusPalette/NoisePlusPalette.ino rename to libraries/FastLED-3.2.9/examples/NoisePlusPalette/NoisePlusPalette.ino diff --git a/libraries/FastLED-3.2.0/examples/Pintest/Pintest.ino b/libraries/FastLED-3.2.9/examples/Pintest/Pintest.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Pintest/Pintest.ino rename to libraries/FastLED-3.2.9/examples/Pintest/Pintest.ino diff --git a/libraries/FastLED-3.2.0/examples/Ports/PJRCSpectrumAnalyzer/PJRCSpectrumAnalyzer.ino b/libraries/FastLED-3.2.9/examples/Ports/PJRCSpectrumAnalyzer/PJRCSpectrumAnalyzer.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/Ports/PJRCSpectrumAnalyzer/PJRCSpectrumAnalyzer.ino rename to libraries/FastLED-3.2.9/examples/Ports/PJRCSpectrumAnalyzer/PJRCSpectrumAnalyzer.ino diff --git a/libraries/FastLED-3.2.9/examples/RGBCalibrate/RGBCalibrate.ino b/libraries/FastLED-3.2.9/examples/RGBCalibrate/RGBCalibrate.ino new file mode 100644 index 0000000..72e2150 --- /dev/null +++ b/libraries/FastLED-3.2.9/examples/RGBCalibrate/RGBCalibrate.ino @@ -0,0 +1,72 @@ +#include "FastLED.h" + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// RGB Calibration code +// +// Use this sketch to determine what the RGB ordering for your chipset should be. Steps for setting up to use: + +// * Uncomment the line in setup that corresponds to the LED chipset that you are using. (Note that they +// all explicitly specify the RGB order as RGB) +// * Define DATA_PIN to the pin that data is connected to. +// * (Optional) if using software SPI for chipsets that are SPI based, define CLOCK_PIN to the clock pin +// * Compile/upload/run the sketch + +// You should see six leds on. If the RGB ordering is correct, you should see 1 red led, 2 green +// leds, and 3 blue leds. If you see different colors, the count of each color tells you what the +// position for that color in the rgb orering should be. So, for example, if you see 1 Blue, and 2 +// Red, and 3 Green leds then the rgb ordering should be BRG (Blue, Red, Green). + +// You can then test this ordering by setting the RGB ordering in the addLeds line below to the new ordering +// and it should come out correctly, 1 red, 2 green, and 3 blue. +// +////////////////////////////////////////////////// + +#define NUM_LEDS 6 + +// Data pin that led data will be written out over +#define DATA_PIN 6 +// Clock pin only needed for SPI based chipsets when not using hardware SPI +//#define CLOCK_PIN 8 + +CRGB leds[NUM_LEDS]; + +void setup() { + // sanity check delay - allows reprogramming if accidently blowing power w/leds + delay(2000); + + // Uncomment one of the following lines for your leds arrangement. + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.setBrightness(CRGB(255,255,255)); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + FastLED.addLeds(leds, NUM_LEDS); + + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); + // FastLED.addLeds(leds, NUM_LEDS); +} + +void loop() { + leds[0] = CRGB(255,0,0); + leds[1] = CRGB(0,255,0); + leds[2] = CRGB(0,255,0); + leds[3] = CRGB(0,0,255); + leds[4] = CRGB(0,0,255); + leds[5] = CRGB(0,0,255); + leds[6] = CRGB(0,0,0); + FastLED.show(); + delay(1000); +} \ No newline at end of file diff --git a/libraries/FastLED-3.2.0/examples/RGBSetDemo/RGBSetDemo.ino b/libraries/FastLED-3.2.9/examples/RGBSetDemo/RGBSetDemo.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/RGBSetDemo/RGBSetDemo.ino rename to libraries/FastLED-3.2.9/examples/RGBSetDemo/RGBSetDemo.ino diff --git a/libraries/FastLED-3.2.0/examples/SmartMatrix/SmartMatrix.ino b/libraries/FastLED-3.2.9/examples/SmartMatrix/SmartMatrix.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/SmartMatrix/SmartMatrix.ino rename to libraries/FastLED-3.2.9/examples/SmartMatrix/SmartMatrix.ino diff --git a/libraries/FastLED-3.2.0/examples/XYMatrix/XYMatrix.ino b/libraries/FastLED-3.2.9/examples/XYMatrix/XYMatrix.ino similarity index 100% rename from libraries/FastLED-3.2.0/examples/XYMatrix/XYMatrix.ino rename to libraries/FastLED-3.2.9/examples/XYMatrix/XYMatrix.ino diff --git a/libraries/FastLED-3.2.0/extras/AppleII.s65 b/libraries/FastLED-3.2.9/extras/AppleII.s65 similarity index 100% rename from libraries/FastLED-3.2.0/extras/AppleII.s65 rename to libraries/FastLED-3.2.9/extras/AppleII.s65 diff --git a/libraries/FastLED-3.2.0/extras/FastLED6502.s65 b/libraries/FastLED-3.2.9/extras/FastLED6502.s65 similarity index 100% rename from libraries/FastLED-3.2.0/extras/FastLED6502.s65 rename to libraries/FastLED-3.2.9/extras/FastLED6502.s65 diff --git a/libraries/FastLED-3.2.0/extras/RainbowDemo.bin.zip b/libraries/FastLED-3.2.9/extras/RainbowDemo.bin.zip similarity index 100% rename from libraries/FastLED-3.2.0/extras/RainbowDemo.bin.zip rename to libraries/FastLED-3.2.9/extras/RainbowDemo.bin.zip diff --git a/libraries/FastLED-3.2.0/extras/RainbowDemo.s65 b/libraries/FastLED-3.2.9/extras/RainbowDemo.s65 similarity index 100% rename from libraries/FastLED-3.2.0/extras/RainbowDemo.s65 rename to libraries/FastLED-3.2.9/extras/RainbowDemo.s65 diff --git a/libraries/FastLED-3.2.0/fastled_config.h b/libraries/FastLED-3.2.9/fastled_config.h similarity index 91% rename from libraries/FastLED-3.2.0/fastled_config.h rename to libraries/FastLED-3.2.9/fastled_config.h index 99500c9..6e41527 100644 --- a/libraries/FastLED-3.2.0/fastled_config.h +++ b/libraries/FastLED-3.2.9/fastled_config.h @@ -61,5 +61,9 @@ #define FASTLED_INTERRUPT_RETRY_COUNT 2 #endif +// Use this toggle to enable global brightness in contollers that support is (ADA102 and SK9822). +// It changes how color scaling works and uses global brightness before scaling down color values. +// This enable much more accurate color control on low brightness settings. +//#define FASTLED_USE_GLOBAL_BRIGHTNESS 1 #endif diff --git a/libraries/FastLED-3.2.0/fastled_delay.h b/libraries/FastLED-3.2.9/fastled_delay.h similarity index 100% rename from libraries/FastLED-3.2.0/fastled_delay.h rename to libraries/FastLED-3.2.9/fastled_delay.h diff --git a/libraries/FastLED-3.2.0/fastled_progmem.h b/libraries/FastLED-3.2.9/fastled_progmem.h similarity index 98% rename from libraries/FastLED-3.2.0/fastled_progmem.h rename to libraries/FastLED-3.2.9/fastled_progmem.h index cafb536..5527c62 100644 --- a/libraries/FastLED-3.2.0/fastled_progmem.h +++ b/libraries/FastLED-3.2.9/fastled_progmem.h @@ -69,7 +69,7 @@ FASTLED_NAMESPACE_BEGIN // force 4-byte alignment as needed. The FastLED gradient // palette code uses 'read dword', and now uses this macro // to make sure that gradient palettes are 4-byte aligned. -#ifdef FASTLED_ARM +#if defined(FASTLED_ARM) || defined(ESP32) #define FL_ALIGN_PROGMEM __attribute__ ((aligned (4))) #else #define FL_ALIGN_PROGMEM diff --git a/libraries/FastLED-3.2.0/fastpin.h b/libraries/FastLED-3.2.9/fastpin.h similarity index 100% rename from libraries/FastLED-3.2.0/fastpin.h rename to libraries/FastLED-3.2.9/fastpin.h diff --git a/libraries/FastLED-3.2.0/fastspi.h b/libraries/FastLED-3.2.9/fastspi.h similarity index 95% rename from libraries/FastLED-3.2.0/fastspi.h rename to libraries/FastLED-3.2.9/fastspi.h index 8e2a593..fc0843b 100644 --- a/libraries/FastLED-3.2.0/fastspi.h +++ b/libraries/FastLED-3.2.9/fastspi.h @@ -40,6 +40,11 @@ template class SPIOutput : public NRF51SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {}; #endif +#if defined(NRF52_SERIES) && defined(FASTLED_ALL_PINS_HARDWARE_SPI) +template +class SPIOutput : public NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER> {}; +#endif + #if defined(SPI_DATA) && defined(SPI_CLOCK) #if defined(FASTLED_TEENSY3) && defined(ARM_HARDWARE_SPI) diff --git a/libraries/FastLED-3.2.0/fastspi_bitbang.h b/libraries/FastLED-3.2.9/fastspi_bitbang.h similarity index 97% rename from libraries/FastLED-3.2.0/fastspi_bitbang.h rename to libraries/FastLED-3.2.9/fastspi_bitbang.h index 3add2b9..d48e32b 100644 --- a/libraries/FastLED-3.2.0/fastspi_bitbang.h +++ b/libraries/FastLED-3.2.9/fastspi_bitbang.h @@ -123,12 +123,24 @@ public: //cli(); if(b & (1 << BIT)) { FastPin::hi(); +#ifdef ESP32 + // try to ensure we never have adjacent write opcodes to the same register + FastPin::lo(); + FastPin::hi(); CLOCK_HI_DELAY; + FastPin::toggle(); CLOCK_LO_DELAY; +#else FastPin::hi(); CLOCK_HI_DELAY; FastPin::lo(); CLOCK_LO_DELAY; +#endif } else { FastPin::lo(); FastPin::hi(); CLOCK_HI_DELAY; +#ifdef ESP32 + // try to ensure we never have adjacent write opcodes to the same register + FastPin::toggle(); CLOCK_HI_DELAY; +#else FastPin::lo(); CLOCK_LO_DELAY; +#endif } //sei(); } diff --git a/libraries/FastLED-3.2.0/fastspi_dma.h b/libraries/FastLED-3.2.9/fastspi_dma.h similarity index 100% rename from libraries/FastLED-3.2.0/fastspi_dma.h rename to libraries/FastLED-3.2.9/fastspi_dma.h diff --git a/libraries/FastLED-3.2.0/fastspi_nop.h b/libraries/FastLED-3.2.9/fastspi_nop.h similarity index 100% rename from libraries/FastLED-3.2.0/fastspi_nop.h rename to libraries/FastLED-3.2.9/fastspi_nop.h diff --git a/libraries/FastLED-3.2.0/fastspi_ref.h b/libraries/FastLED-3.2.9/fastspi_ref.h similarity index 100% rename from libraries/FastLED-3.2.0/fastspi_ref.h rename to libraries/FastLED-3.2.9/fastspi_ref.h diff --git a/libraries/FastLED-3.2.0/fastspi_types.h b/libraries/FastLED-3.2.9/fastspi_types.h similarity index 100% rename from libraries/FastLED-3.2.0/fastspi_types.h rename to libraries/FastLED-3.2.9/fastspi_types.h diff --git a/libraries/FastLED-3.2.0/hsv2rgb.cpp b/libraries/FastLED-3.2.9/hsv2rgb.cpp similarity index 100% rename from libraries/FastLED-3.2.0/hsv2rgb.cpp rename to libraries/FastLED-3.2.9/hsv2rgb.cpp diff --git a/libraries/FastLED-3.2.0/hsv2rgb.h b/libraries/FastLED-3.2.9/hsv2rgb.h similarity index 100% rename from libraries/FastLED-3.2.0/hsv2rgb.h rename to libraries/FastLED-3.2.9/hsv2rgb.h diff --git a/libraries/FastLED-3.2.0/keywords.txt b/libraries/FastLED-3.2.9/keywords.txt similarity index 97% rename from libraries/FastLED-3.2.0/keywords.txt rename to libraries/FastLED-3.2.9/keywords.txt index 64f5d37..c30552d 100644 --- a/libraries/FastLED-3.2.0/keywords.txt +++ b/libraries/FastLED-3.2.9/keywords.txt @@ -9,6 +9,7 @@ CFastLED KEYWORD1 CHSV KEYWORD1 CRGB KEYWORD1 +CRGBArray KEYWORD1 LEDS KEYWORD1 FastLED KEYWORD1 FastPin KEYWORD1 @@ -34,10 +35,14 @@ setBrightness KEYWORD2 getBrightness KEYWORD2 show KEYWORD2 clear KEYWORD2 +clearData KEYWORD2 showColor KEYWORD2 setTemperature KEYWORD2 setCorrection KEYWORD2 setDither KEYWORD2 +setMaxPowerInMilliWatts KEYWORD2 +setMaxPowerInVoltsAndMilliamps KEYWORD2 +setMaxRefreshRate KEYWORD2 countFPS KEYWORD2 getFPS KEYWORD2 @@ -289,6 +294,7 @@ CRGB::YellowGreen KEYWORD2 ####################################### # Chipsets +LPD6803 LITERAL1 LPD8806 LITERAL1 WS2801 LITERAL1 WS2803 LITERAL1 @@ -318,6 +324,11 @@ OCTOWS2811_400 LITERAL1 OCTOWS2813 LITERAL1 WS2812SERIAL LITERAL1 SMART_MATRIX LITERAL1 +GE8822 LITERAL1 +SM16703 LITERAL1 +GS1903 LITERAL1 +LPD6803 LITERAL1 + # RGB orderings RGB LITERAL1 diff --git a/libraries/FastLED-3.2.0/led_sysdefs.h b/libraries/FastLED-3.2.9/led_sysdefs.h similarity index 85% rename from libraries/FastLED-3.2.0/led_sysdefs.h rename to libraries/FastLED-3.2.9/led_sysdefs.h index 424ab84..7abcd15 100644 --- a/libraries/FastLED-3.2.0/led_sysdefs.h +++ b/libraries/FastLED-3.2.9/led_sysdefs.h @@ -7,6 +7,8 @@ #if defined(NRF51) || defined(__RFduino__) || defined (__Simblee__) #include "platforms/arm/nrf51/led_sysdefs_arm_nrf51.h" +#elif defined(NRF52_SERIES) +#include "platforms/arm/nrf52/led_sysdefs_arm_nrf52.h" #elif defined(__MK20DX128__) || defined(__MK20DX256__) // Include k20/T3 headers #include "platforms/arm/k20/led_sysdefs_arm_k20.h" @@ -19,9 +21,9 @@ #elif defined(__SAM3X8E__) // Include sam/due headers #include "platforms/arm/sam/led_sysdefs_arm_sam.h" -#elif defined(STM32F10X_MD) +#elif defined(STM32F10X_MD) || defined(__STM32F1__) #include "platforms/arm/stm32/led_sysdefs_arm_stm32.h" -#elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) +#elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) || defined(__SAMD51G19A__) || defined(__SAMD51J19A__) #include "platforms/arm/d21/led_sysdefs_arm_d21.h" #elif defined(ESP8266) #include "platforms/esp/8266/led_sysdefs_esp8266.h" diff --git a/libraries/FastLED-3.2.0/lib8tion.cpp b/libraries/FastLED-3.2.9/lib8tion.cpp similarity index 100% rename from libraries/FastLED-3.2.0/lib8tion.cpp rename to libraries/FastLED-3.2.9/lib8tion.cpp diff --git a/libraries/FastLED-3.2.0/lib8tion.h b/libraries/FastLED-3.2.9/lib8tion.h similarity index 99% rename from libraries/FastLED-3.2.0/lib8tion.h rename to libraries/FastLED-3.2.9/lib8tion.h index 42f985d..24c5d0a 100644 --- a/libraries/FastLED-3.2.0/lib8tion.h +++ b/libraries/FastLED-3.2.9/lib8tion.h @@ -477,7 +477,7 @@ LIB8STATIC uint16_t lerp16by16( uint16_t a, uint16_t b, fract16 frac) uint16_t result; if( b > a ) { uint16_t delta = b - a; - uint32_t scaled = scale16(delta, frac); + uint16_t scaled = scale16(delta, frac); result = a + scaled; } else { uint16_t delta = a - b; diff --git a/libraries/FastLED-3.2.0/lib8tion/math8.h b/libraries/FastLED-3.2.9/lib8tion/math8.h similarity index 93% rename from libraries/FastLED-3.2.0/lib8tion/math8.h rename to libraries/FastLED-3.2.9/lib8tion/math8.h index 7f062c6..4dab820 100644 --- a/libraries/FastLED-3.2.0/lib8tion/math8.h +++ b/libraries/FastLED-3.2.9/lib8tion/math8.h @@ -312,6 +312,35 @@ LIB8STATIC uint8_t addmod8( uint8_t a, uint8_t b, uint8_t m) return a; } +/// Subtract two numbers, and calculate the modulo +/// of the difference and a third number, M. +/// In other words, it returns (A-B) % M. +/// It is designed as a compact mechanism for +/// incrementing a 'mode' switch and wrapping +/// around back to 'mode 0' when the switch +/// goes past the end of the available range. +/// e.g. if you have seven modes, this switches +/// to the next one and wraps around if needed: +/// mode = addmod8( mode, 1, 7); +///LIB8STATIC_ALWAYS_INLINESee 'mod8' for notes on performance. +LIB8STATIC uint8_t submod8( uint8_t a, uint8_t b, uint8_t m) +{ +#if defined(__AVR__) + asm volatile ( + " sub %[a],%[b] \n\t" + "L_%=: sub %[a],%[m] \n\t" + " brcc L_%= \n\t" + " add %[a],%[m] \n\t" + : [a] "+r" (a) + : [b] "r" (b), [m] "r" (m) + ); +#else + a -= b; + while( a >= m) a -= m; +#endif + return a; +} + /// 8x8 bit multiplication, with 8 bit result LIB8STATIC_ALWAYS_INLINE uint8_t mul8( uint8_t i, uint8_t j) { diff --git a/libraries/FastLED-3.2.0/lib8tion/random8.h b/libraries/FastLED-3.2.9/lib8tion/random8.h similarity index 100% rename from libraries/FastLED-3.2.0/lib8tion/random8.h rename to libraries/FastLED-3.2.9/lib8tion/random8.h diff --git a/libraries/FastLED-3.2.0/lib8tion/scale8.h b/libraries/FastLED-3.2.9/lib8tion/scale8.h similarity index 100% rename from libraries/FastLED-3.2.0/lib8tion/scale8.h rename to libraries/FastLED-3.2.9/lib8tion/scale8.h diff --git a/libraries/FastLED-3.2.0/lib8tion/trig8.h b/libraries/FastLED-3.2.9/lib8tion/trig8.h similarity index 100% rename from libraries/FastLED-3.2.0/lib8tion/trig8.h rename to libraries/FastLED-3.2.9/lib8tion/trig8.h diff --git a/libraries/FastLED-3.2.0/library.json b/libraries/FastLED-3.2.9/library.json similarity index 75% rename from libraries/FastLED-3.2.0/library.json rename to libraries/FastLED-3.2.9/library.json index 189460c..ca8f09e 100644 --- a/libraries/FastLED-3.2.0/library.json +++ b/libraries/FastLED-3.2.9/library.json @@ -18,12 +18,23 @@ "type": "git", "url": "https://github.com/FastLED/FastLED.git" }, - "version": "3.2.0", + "version": "3.2.9", "license": "MIT", "homepage": "http://fastled.io", "frameworks": "arduino", - "platforms": "atmelavr, atmelsam, freescalekinetis, nordicnrf51, nxplpc, ststm32, teensy, espressif8266, espressif32", + "platforms": "atmelavr, atmelsam, freescalekinetis, nordicnrf51, nxplpc, ststm32, teensy, espressif8266, espressif32, nordicnrf52", + "export": { + "exclude": [ + "docs", + "extras" + ] + }, "build": { + "srcFilter": [ + "+<*.c>", + "+<*.cpp>", + "+<*.h>" + ], "libArchive": false - } + } } diff --git a/libraries/FastLED-3.2.0/library.properties b/libraries/FastLED-3.2.9/library.properties similarity index 96% rename from libraries/FastLED-3.2.0/library.properties rename to libraries/FastLED-3.2.9/library.properties index 5503088..25460b1 100644 --- a/libraries/FastLED-3.2.0/library.properties +++ b/libraries/FastLED-3.2.9/library.properties @@ -1,5 +1,5 @@ name=FastLED -version=3.2.0 +version=3.2.9 author=Daniel Garcia maintainer=Daniel Garcia sentence=Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions. diff --git a/libraries/FastLED-3.2.0/noise.cpp b/libraries/FastLED-3.2.9/noise.cpp similarity index 100% rename from libraries/FastLED-3.2.0/noise.cpp rename to libraries/FastLED-3.2.9/noise.cpp diff --git a/libraries/FastLED-3.2.0/noise.h b/libraries/FastLED-3.2.9/noise.h similarity index 100% rename from libraries/FastLED-3.2.0/noise.h rename to libraries/FastLED-3.2.9/noise.h diff --git a/libraries/FastLED-3.2.0/pixelset.h b/libraries/FastLED-3.2.9/pixelset.h similarity index 100% rename from libraries/FastLED-3.2.0/pixelset.h rename to libraries/FastLED-3.2.9/pixelset.h diff --git a/libraries/FastLED-3.2.0/pixeltypes.h b/libraries/FastLED-3.2.9/pixeltypes.h similarity index 98% rename from libraries/FastLED-3.2.0/pixeltypes.h rename to libraries/FastLED-3.2.9/pixeltypes.h index 075c794..ff327fd 100644 --- a/libraries/FastLED-3.2.0/pixeltypes.h +++ b/libraries/FastLED-3.2.9/pixeltypes.h @@ -478,10 +478,14 @@ struct CRGB { uint8_t max = red; if( green > max) max = green; if( blue > max) max = blue; - uint16_t factor = ((uint16_t)(limit) * 256) / max; - red = (red * factor) / 256; - green = (green * factor) / 256; - blue = (blue * factor) / 256; + + // stop div/0 when color is black + if(max > 0) { + uint16_t factor = ((uint16_t)(limit) * 256) / max; + red = (red * factor) / 256; + green = (green * factor) / 256; + blue = (blue * factor) / 256; + } } /// return a new CRGB object after performing a linear interpolation between this object and the passed in object diff --git a/libraries/FastLED-3.2.9/platforms.cpp b/libraries/FastLED-3.2.9/platforms.cpp new file mode 100644 index 0000000..47a0088 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms.cpp @@ -0,0 +1,40 @@ +#define FASTLED_INTERNAL + + +// Interrupt handlers cannot be defined in the header. +// They must be defined as C functions, or they won't +// be found (due to name mangling), and thus won't +// override any default weak definition. +#if defined(NRF52_SERIES) + + #include "platforms/arm/nrf52/led_sysdefs_arm_nrf52.h" + #include "platforms/arm/nrf52/arbiter_nrf52.h" + + uint32_t isrCount; + + #ifdef __cplusplus + extern "C" { + #endif + // NOTE: Update platforms.cpp in root of FastLED library if this changes + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE0) + void PWM0_IRQHandler(void) { isrCount++; PWM_Arbiter<0>::isr_handler(); } + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE1) + void PWM1_IRQHandler(void) { isrCount++; PWM_Arbiter<1>::isr_handler(); } + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE2) + void PWM2_IRQHandler(void) { isrCount++; PWM_Arbiter<2>::isr_handler(); } + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE3) + void PWM3_IRQHandler(void) { isrCount++; PWM_Arbiter<3>::isr_handler(); } + #endif + #ifdef __cplusplus + } + #endif + +#endif // defined(NRF52_SERIES) + + + +// FASTLED_NAMESPACE_BEGIN +// FASTLED_NAMESPACE_END diff --git a/libraries/FastLED-3.2.0/platforms.h b/libraries/FastLED-3.2.9/platforms.h similarity index 81% rename from libraries/FastLED-3.2.0/platforms.h rename to libraries/FastLED-3.2.9/platforms.h index 5a53637..82d7d99 100644 --- a/libraries/FastLED-3.2.0/platforms.h +++ b/libraries/FastLED-3.2.9/platforms.h @@ -7,6 +7,8 @@ #if defined(NRF51) #include "platforms/arm/nrf51/fastled_arm_nrf51.h" +#elif defined(NRF52_SERIES) +#include "platforms/arm/nrf52/fastled_arm_nrf52.h" #elif defined(__MK20DX128__) || defined(__MK20DX256__) // Include k20/T3 headers #include "platforms/arm/k20/fastled_arm_k20.h" @@ -19,10 +21,12 @@ #elif defined(__SAM3X8E__) // Include sam/due headers #include "platforms/arm/sam/fastled_arm_sam.h" -#elif defined(STM32F10X_MD) +#elif defined(STM32F10X_MD) || defined(__STM32F1__) #include "platforms/arm/stm32/fastled_arm_stm32.h" #elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) #include "platforms/arm/d21/fastled_arm_d21.h" +#elif defined(__SAMD51G19A__) || defined(__SAMD51J19A__) +#include "platforms/arm/d51/fastled_arm_d51.h" #elif defined(ESP8266) #include "platforms/esp/8266/fastled_esp8266.h" #elif defined(ESP32) diff --git a/libraries/FastLED-3.2.0/platforms/arm/common/m0clockless.h b/libraries/FastLED-3.2.9/platforms/arm/common/m0clockless.h similarity index 61% rename from libraries/FastLED-3.2.0/platforms/arm/common/m0clockless.h rename to libraries/FastLED-3.2.9/platforms/arm/common/m0clockless.h index 11512fd..d5a0cf6 100644 --- a/libraries/FastLED-3.2.0/platforms/arm/common/m0clockless.h +++ b/libraries/FastLED-3.2.9/platforms/arm/common/m0clockless.h @@ -210,12 +210,12 @@ showLedData(volatile uint32_t *_port, uint32_t _bitmask, const uint8_t *_leds, u // now for some convinience macros to make building our lines a bit cleaner #define LOOP " loop_%=:" #define HI2 " qset2 %[bitmask], %[port], %[hi_off];" -#define D1 " mod_delay %c[T1],2,0,%[scratch];" +#define _D1 " mod_delay %c[T1],2,0,%[scratch];" #define QLO4 " qlo4 %[b],%[bitmask],%[port], %[lo_off];" #define LOADLEDS3(X) " loadleds3 %[leds], %[bn], %[led" #X "] ,%[scratch];" -#define D2(ADJ) " mod_delay %c[T2],4," #ADJ ",%[scratch];" +#define _D2(ADJ) " mod_delay %c[T2],4," #ADJ ",%[scratch];" #define LO2 " qset2 %[bitmask], %[port], %[lo_off];" -#define D3(ADJ) " mod_delay %c[T3],2," #ADJ ",%[scratch];" +#define _D3(ADJ) " mod_delay %c[T3],2," #ADJ ",%[scratch];" #define LOADDITHER7(X) " loaddither7 %[bn], %[d], %[base], %[led" #X "];" #define DITHER5 " dither5 %[bn], %[d];" #define SCALE4(X) " scale4 %[bn], %[base], %[scale" #X "], %[scratch];" @@ -225,7 +225,122 @@ showLedData(volatile uint32_t *_port, uint32_t _bitmask, const uint8_t *_leds, u #define CMPLOOP5 " cmploop5 %[counter], loop_%=;" #define NOTHING "" -#if !(defined(SEI_CHK) && (FASTLED_ALLOW_INTERRUPTS == 1)) +#if (defined(SEI_CHK) && (FASTLED_ALLOW_INTERRUPTS == 1)) + // We're allowing interrupts and have hardware timer support defined - + // track the loop outside the asm code, to allow inserting the interrupt + // overrun checks. + asm __volatile__ ( + // pre-load byte 0 + LOADLEDS3(0) LOADDITHER7(0) DITHER5 SCALE4(0) ADJDITHER7(0) SWAPBBN1 + M0_ASM_ARGS); + + do { + asm __volatile__ ( + // Write out byte 0, prepping byte 1 + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(1) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(1) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(1) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(1) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(0) + + // Write out byte 1, prepping byte 2 + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(2) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(2) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(2) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(2) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(0) + + // Write out byte 2, prepping byte 0 + HI2 _D1 QLO4 INCLEDS3 _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(0) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(0) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(0) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(0) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(5) + + M0_ASM_ARGS + ); + SEI_CHK; INNER_SEI; --counter; CLI_CHK; + } while(counter); +#elif (FASTLED_ALLOW_INTERRUPTS == 1) + // We're allowing interrupts - track the loop outside the asm code, and + // re-enable interrupts in between each iteration. + asm __volatile__ ( + // pre-load byte 0 + LOADLEDS3(0) LOADDITHER7(0) DITHER5 SCALE4(0) ADJDITHER7(0) SWAPBBN1 + M0_ASM_ARGS); + + do { + asm __volatile__ ( + // Write out byte 0, prepping byte 1 + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(1) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(1) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(1) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(1) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(0) + + // Write out byte 1, prepping byte 2 + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(2) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(2) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(2) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(2) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 INCLEDS3 _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(0) + + // Write out byte 2, prepping byte 0 + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(0) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(0) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(0) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(0) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(5) + + M0_ASM_ARGS + ); + + uint32_t ticksBeforeInterrupts = SysTick->VAL; + sei(); + --counter; + cli(); + + // If more than 45 uSecs have elapsed, give up on this frame and start over. + // Note: this isn't completely correct. It's possible that more than one + // millisecond will elapse, and so SysTick->VAL will lap + // ticksBeforeInterrupts. + // Note: ticksBeforeInterrupts DECREASES + const uint32_t kTicksPerMs = VARIANT_MCK / 1000; + const uint32_t kTicksPerUs = kTicksPerMs / 1000; + const uint32_t kTicksIn45us = kTicksPerUs * 45; + + const uint32_t currentTicks = SysTick->VAL; + + if (ticksBeforeInterrupts < currentTicks) { + // Timer started over + if ((ticksBeforeInterrupts + (kTicksPerMs - currentTicks)) > kTicksIn45us) { + return 0; + } + } else { + if ((ticksBeforeInterrupts - currentTicks) > kTicksIn45us) { + return 0; + } + } + } while(counter); +#else // We're not allowing interrupts - run the entire loop in asm to keep things // as tight as possible. In an ideal world, we should be pushing out ws281x // leds (or other 3-wire leds) with zero gaps between pixels. @@ -236,81 +351,37 @@ showLedData(volatile uint32_t *_port, uint32_t _bitmask, const uint8_t *_leds, u // loop over writing out the data LOOP // Write out byte 0, prepping byte 1 - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 LOADLEDS3(1) D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADDITHER7(1) D2(7) LO2 D3(0) - HI2 D1 QLO4 DITHER5 D2(5) LO2 D3(0) - HI2 D1 QLO4 SCALE4(1) D2(4) LO2 D3(0) - HI2 D1 QLO4 ADJDITHER7(1) D2(7) LO2 D3(0) - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 SWAPBBN1 D2(1) LO2 D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(1) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(1) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(1) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(1) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(0) // Write out byte 1, prepping byte 2 - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 LOADLEDS3(2) D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADDITHER7(2) D2(7) LO2 D3(0) - HI2 D1 QLO4 DITHER5 D2(5) LO2 D3(0) - HI2 D1 QLO4 SCALE4(2) D2(4) LO2 D3(0) - HI2 D1 QLO4 ADJDITHER7(2) D2(7) LO2 D3(0) - HI2 D1 QLO4 INCLEDS3 D2(3) LO2 D3(0) - HI2 D1 QLO4 SWAPBBN1 D2(1) LO2 D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(2) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(2) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(2) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(2) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 INCLEDS3 _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(0) // Write out byte 2, prepping byte 0 - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 LOADLEDS3(0) D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADDITHER7(0) D2(7) LO2 D3(0) - HI2 D1 QLO4 DITHER5 D2(5) LO2 D3(0) - HI2 D1 QLO4 SCALE4(0) D2(4) LO2 D3(0) - HI2 D1 QLO4 ADJDITHER7(0) D2(7) LO2 D3(0) - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 SWAPBBN1 D2(1) LO2 D3(5) CMPLOOP5 + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 LOADLEDS3(0) _D2(3) LO2 _D3(0) + HI2 _D1 QLO4 LOADDITHER7(0) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 DITHER5 _D2(5) LO2 _D3(0) + HI2 _D1 QLO4 SCALE4(0) _D2(4) LO2 _D3(0) + HI2 _D1 QLO4 ADJDITHER7(0) _D2(7) LO2 _D3(0) + HI2 _D1 QLO4 NOTHING _D2(0) LO2 _D3(0) + HI2 _D1 QLO4 SWAPBBN1 _D2(1) LO2 _D3(5) CMPLOOP5 M0_ASM_ARGS ); -#else - // We're allowing interrupts - track the loop outside the asm code, to allow - // inserting the interrupt overrun checks. - asm __volatile__ ( - // pre-load byte 0 - LOADLEDS3(0) LOADDITHER7(0) DITHER5 SCALE4(0) ADJDITHER7(0) SWAPBBN1 - M0_ASM_ARGS); - - do { - asm __volatile__ ( - // Write out byte 0, prepping byte 1 - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 LOADLEDS3(1) D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADDITHER7(1) D2(7) LO2 D3(0) - HI2 D1 QLO4 DITHER5 D2(5) LO2 D3(0) - HI2 D1 QLO4 SCALE4(1) D2(4) LO2 D3(0) - HI2 D1 QLO4 ADJDITHER7(1) D2(7) LO2 D3(0) - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 SWAPBBN1 D2(1) LO2 D3(0) - - // Write out byte 1, prepping byte 2 - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 LOADLEDS3(2) D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADDITHER7(2) D2(7) LO2 D3(0) - HI2 D1 QLO4 DITHER5 D2(5) LO2 D3(0) - HI2 D1 QLO4 SCALE4(2) D2(4) LO2 D3(0) - HI2 D1 QLO4 ADJDITHER7(2) D2(7) LO2 D3(0) - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 SWAPBBN1 D2(1) LO2 D3(0) - - // Write out byte 2, prepping byte 0 - HI2 D1 QLO4 INCLEDS3 D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADLEDS3(0) D2(3) LO2 D3(0) - HI2 D1 QLO4 LOADDITHER7(0) D2(7) LO2 D3(0) - HI2 D1 QLO4 DITHER5 D2(5) LO2 D3(0) - HI2 D1 QLO4 SCALE4(0) D2(4) LO2 D3(0) - HI2 D1 QLO4 ADJDITHER7(0) D2(7) LO2 D3(0) - HI2 D1 QLO4 NOTHING D2(0) LO2 D3(0) - HI2 D1 QLO4 SWAPBBN1 D2(1) LO2 D3(5) - - M0_ASM_ARGS - ); - SEI_CHK; INNER_SEI; --counter; CLI_CHK; - } while(counter); #endif return num_leds; } diff --git a/libraries/FastLED-3.2.0/platforms/arm/d21/clockless_arm_d21.h b/libraries/FastLED-3.2.9/platforms/arm/d21/clockless_arm_d21.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/d21/clockless_arm_d21.h rename to libraries/FastLED-3.2.9/platforms/arm/d21/clockless_arm_d21.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/d21/fastled_arm_d21.h b/libraries/FastLED-3.2.9/platforms/arm/d21/fastled_arm_d21.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/d21/fastled_arm_d21.h rename to libraries/FastLED-3.2.9/platforms/arm/d21/fastled_arm_d21.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/d21/fastpin_arm_d21.h b/libraries/FastLED-3.2.9/platforms/arm/d21/fastpin_arm_d21.h similarity index 80% rename from libraries/FastLED-3.2.0/platforms/arm/d21/fastpin_arm_d21.h rename to libraries/FastLED-3.2.9/platforms/arm/d21/fastpin_arm_d21.h index 90b0d9f..1606d65 100644 --- a/libraries/FastLED-3.2.0/platforms/arm/d21/fastpin_arm_d21.h +++ b/libraries/FastLED-3.2.9/platforms/arm/d21/fastpin_arm_d21.h @@ -34,24 +34,23 @@ public: inline static void setOutput() { pinMode(PIN, OUTPUT); } // TODO: perform MUX config { _PDDR::r() |= _MASK; } inline static void setInput() { pinMode(PIN, INPUT); } // TODO: preform MUX config { _PDDR::r() &= ~_MASK; } - inline static void hi() __attribute__ ((always_inline)) { PORT->Group[_GRP].OUTSET.reg = _MASK; } - inline static void lo() __attribute__ ((always_inline)) { PORT->Group[_GRP].OUTCLR.reg = _MASK; } - // inline static void lo() __attribute__ ((always_inline)) { PORT->Group[_GRP].BSRR = (_MASK<<16); } - inline static void set(register port_t val) __attribute__ ((always_inline)) { PORT->Group[_GRP].OUT.reg = val; } + inline static void hi() __attribute__ ((always_inline)) { PORT_IOBUS->Group[_GRP].OUTSET.reg = _MASK; } + inline static void lo() __attribute__ ((always_inline)) { PORT_IOBUS->Group[_GRP].OUTCLR.reg = _MASK; } + inline static void set(register port_t val) __attribute__ ((always_inline)) { PORT_IOBUS->Group[_GRP].OUT.reg = val; } inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); } - inline static void toggle() __attribute__ ((always_inline)) { PORT->Group[_GRP].OUTTGL.reg = _MASK; } + inline static void toggle() __attribute__ ((always_inline)) { PORT_IOBUS->Group[_GRP].OUTTGL.reg = _MASK; } inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); } inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); } inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; } - inline static port_t hival() __attribute__ ((always_inline)) { return PORT->Group[_GRP].OUT.reg | _MASK; } - inline static port_t loval() __attribute__ ((always_inline)) { return PORT->Group[_GRP].OUT.reg & ~_MASK; } - inline static port_ptr_t port() __attribute__ ((always_inline)) { return &PORT->Group[_GRP].OUT.reg; } - inline static port_ptr_t sport() __attribute__ ((always_inline)) { return &PORT->Group[_GRP].OUTSET.reg; } - inline static port_ptr_t cport() __attribute__ ((always_inline)) { return &PORT->Group[_GRP].OUTCLR.reg; } + inline static port_t hival() __attribute__ ((always_inline)) { return PORT_IOBUS->Group[_GRP].OUT.reg | _MASK; } + inline static port_t loval() __attribute__ ((always_inline)) { return PORT_IOBUS->Group[_GRP].OUT.reg & ~_MASK; } + inline static port_ptr_t port() __attribute__ ((always_inline)) { return &PORT_IOBUS->Group[_GRP].OUT.reg; } + inline static port_ptr_t sport() __attribute__ ((always_inline)) { return &PORT_IOBUS->Group[_GRP].OUTSET.reg; } + inline static port_ptr_t cport() __attribute__ ((always_inline)) { return &PORT_IOBUS->Group[_GRP].OUTCLR.reg; } inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; } }; @@ -74,6 +73,31 @@ _DEFPIN_ARM(A1,0, 5); _DEFPIN_ARM(A2,0, 6); _DEFPIN_ARM(A3,0, 7); _DEFPIN_ARM(A0 #define HAS_HARDWARE_PIN_SUPPORT 1 + +#elif defined(ADAFRUIT_HALLOWING) + +#define MAX_PIN 20 +// 0 & 1 +_DEFPIN_ARM( 0, 0, 9); _DEFPIN_ARM( 1, 0, 10); +// 2, 3, 4 +_DEFPIN_ARM( 2, 0, 14); _DEFPIN_ARM( 3, 0, 11); _DEFPIN_ARM( 4, 0, 8); +// 5, 6, 7 +_DEFPIN_ARM( 5, 0, 15); _DEFPIN_ARM( 6, 0, 18); _DEFPIN_ARM( 7, 0, 0); +// 8, 9, 10 +_DEFPIN_ARM( 8, 0, 12); _DEFPIN_ARM( 9, 0, 19); _DEFPIN_ARM(10, 0, 20); +// 11, 12, 13 +_DEFPIN_ARM(11, 0, 21); _DEFPIN_ARM(12, 0, 22); _DEFPIN_ARM(13, 0, 23); +// 14, 15, 16 (A0 - A2) +_DEFPIN_ARM(14, 0, 2); _DEFPIN_ARM(15, 1, 8); _DEFPIN_ARM(16, 1, 9); +// 17, 18, 19 (A3 - A5) +_DEFPIN_ARM(17, 0, 4); _DEFPIN_ARM(18, 0, 5); _DEFPIN_ARM(19, 0, 6); + +#define SPI_DATA PIN_SPI_MOSI +#define SPI_CLOCK PIN_SPI_SCK + +#define HAS_HARDWARE_PIN_SUPPORT 1 + + #elif defined(ARDUINO_SAMD_ZERO) #define MAX_PIN 42 @@ -148,24 +172,40 @@ _DEFPIN_ARM( 20, 0, 6); _DEFPIN_ARM( 21, 0, 7); #elif defined(ARDUINO_GEMMA_M0) #define MAX_PIN 4 -_DEFPIN_ARM( 0, 0, 4); _DEFPIN_ARM( 1, 0, 2); _DEFPIN_ARM( 2, 0, 5); +_DEFPIN_ARM( 0, 0, 4); _DEFPIN_ARM( 1, 0, 2); _DEFPIN_ARM( 2, 0, 5); _DEFPIN_ARM( 3, 0, 0); _DEFPIN_ARM( 4, 0, 1); #define HAS_HARDWARE_PIN_SUPPORT 1 #elif defined(ADAFRUIT_TRINKET_M0) -#define MAX_PIN 5 +#define MAX_PIN 7 _DEFPIN_ARM( 0, 0, 8); _DEFPIN_ARM( 1, 0, 2); _DEFPIN_ARM( 2, 0, 9); -_DEFPIN_ARM( 3, 0, 7); _DEFPIN_ARM( 4, 0, 6); +_DEFPIN_ARM( 3, 0, 7); _DEFPIN_ARM( 4, 0, 6); _DEFPIN_ARM( 7, 0, 0); _DEFPIN_ARM( 8, 0, 1); #define SPI_DATA 4 #define SPI_CLOCK 3 #define HAS_HARDWARE_PIN_SUPPORT 1 -#endif +#elif defined(ADAFRUIT_ITSYBITSY_M0) +#define MAX_PIN 16 +_DEFPIN_ARM( 2, 0, 14); _DEFPIN_ARM( 3, 0, 9); _DEFPIN_ARM( 4, 0, 8); +_DEFPIN_ARM( 5, 0, 15); _DEFPIN_ARM( 6, 0, 20); _DEFPIN_ARM( 7, 0, 21); +_DEFPIN_ARM( 8, 0, 6); _DEFPIN_ARM( 9, 0, 7); _DEFPIN_ARM( 10, 0, 18); +_DEFPIN_ARM( 11, 0, 16); _DEFPIN_ARM( 12, 0, 19); _DEFPIN_ARM( 13, 0, 17); +_DEFPIN_ARM( 29, 0, 10); // MOSI +_DEFPIN_ARM( 30, 0, 11); // SCK +_DEFPIN_ARM( 40, 0, 0); //APA102 Clock +_DEFPIN_ARM( 41, 0, 1) //APA102 Data + +#define SPI_DATA 29 +#define SPI_CLOCK 30 + +#define HAS_HARDWARE_PIN_SUPPORT 1 + +#endif #endif // FASTLED_FORCE_SOFTWARE_PINS diff --git a/libraries/FastLED-3.2.0/platforms/arm/d21/led_sysdefs_arm_d21.h b/libraries/FastLED-3.2.9/platforms/arm/d21/led_sysdefs_arm_d21.h similarity index 92% rename from libraries/FastLED-3.2.0/platforms/arm/d21/led_sysdefs_arm_d21.h rename to libraries/FastLED-3.2.9/platforms/arm/d21/led_sysdefs_arm_d21.h index b343d3f..a48db10 100644 --- a/libraries/FastLED-3.2.0/platforms/arm/d21/led_sysdefs_arm_d21.h +++ b/libraries/FastLED-3.2.9/platforms/arm/d21/led_sysdefs_arm_d21.h @@ -11,7 +11,7 @@ // Default to allowing interrupts #ifndef FASTLED_ALLOW_INTERRUPTS -#define FASTLED_ALLOW_INTERRUPTS 0 +#define FASTLED_ALLOW_INTERRUPTS 1 #endif #if FASTLED_ALLOW_INTERRUPTS == 1 diff --git a/libraries/FastLED-3.2.9/platforms/arm/d51/README.txt b/libraries/FastLED-3.2.9/platforms/arm/d51/README.txt new file mode 100644 index 0000000..b00fb67 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/d51/README.txt @@ -0,0 +1,4 @@ +FastLED updates for adafruit FEATHER M4 and fixes to ITSBITSY M4 compiles + SAMD51 + +only tested on FEATHER M4 with DOTSTAR and neopixel strips diff --git a/libraries/FastLED-3.2.9/platforms/arm/d51/clockless_arm_d51.h b/libraries/FastLED-3.2.9/platforms/arm/d51/clockless_arm_d51.h new file mode 100644 index 0000000..0c3f6d4 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/d51/clockless_arm_d51.h @@ -0,0 +1,128 @@ +#ifndef __INC_CLOCKLESS_ARM_D51 +#define __INC_CLOCKLESS_ARM_D51 + +FASTLED_NAMESPACE_BEGIN + +// Definition for a single channel clockless controller for SAMD51 +// See clockless.h for detailed info on how the template parameters are used. +#define ARM_DEMCR (*(volatile uint32_t *)0xE000EDFC) // Debug Exception and Monitor Control +#define ARM_DEMCR_TRCENA (1 << 24) // Enable debugging & monitoring blocks +#define ARM_DWT_CTRL (*(volatile uint32_t *)0xE0001000) // DWT control register +#define ARM_DWT_CTRL_CYCCNTENA (1 << 0) // Enable cycle count +#define ARM_DWT_CYCCNT (*(volatile uint32_t *)0xE0001004) // Cycle count register + + +#define FASTLED_HAS_CLOCKLESS 1 + +template +class ClocklessController : public CPixelLEDController { + typedef typename FastPin::port_ptr_t data_ptr_t; + typedef typename FastPin::port_t data_t; + + data_t mPinMask; + data_ptr_t mPort; + CMinWait mWait; +public: + virtual void init() { + FastPin::setOutput(); + mPinMask = FastPin::mask(); + mPort = FastPin::port(); + } + + virtual uint16_t getMaxRefreshRate() const { return 400; } + +protected: + + virtual void showPixels(PixelController & pixels) { + mWait.wait(); + if(!showRGBInternal(pixels)) { + sei(); delayMicroseconds(WAIT_TIME); cli(); + showRGBInternal(pixels); + } + mWait.mark(); + } + + template __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & next_mark, register data_ptr_t port, register data_t hi, register data_t lo, register uint8_t & b) { + for(register uint32_t i = BITS-1; i > 0; i--) { + while(ARM_DWT_CYCCNT < next_mark); + next_mark = ARM_DWT_CYCCNT + (T1+T2+T3); + FastPin::fastset(port, hi); + if(b&0x80) { + while((next_mark - ARM_DWT_CYCCNT) > (T3+(2*(F_CPU/24000000)))); + FastPin::fastset(port, lo); + } else { + while((next_mark - ARM_DWT_CYCCNT) > (T2+T3+(2*(F_CPU/24000000)))); + FastPin::fastset(port, lo); + } + b <<= 1; + } + + while(ARM_DWT_CYCCNT < next_mark); + next_mark = ARM_DWT_CYCCNT + (T1+T2+T3); + FastPin::fastset(port, hi); + + if(b&0x80) { + while((next_mark - ARM_DWT_CYCCNT) > (T3+(2*(F_CPU/24000000)))); + FastPin::fastset(port, lo); + } else { + while((next_mark - ARM_DWT_CYCCNT) > (T2+T3+(2*(F_CPU/24000000)))); + FastPin::fastset(port, lo); + } + } + + // This method is made static to force making register Y available to use for data on AVR - if the method is non-static, then + // gcc will use register Y for the this pointer. + static uint32_t showRGBInternal(PixelController pixels) { + // Get access to the clock + ARM_DEMCR |= ARM_DEMCR_TRCENA; + ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; + ARM_DWT_CYCCNT = 0; + + register data_ptr_t port = FastPin::port(); + register data_t hi = *port | FastPin::mask();; + register data_t lo = *port & ~FastPin::mask();; + *port = lo; + + // Setup the pixel controller and load/scale the first byte + pixels.preStepFirstByteDithering(); + register uint8_t b = pixels.loadAndScale0(); + + cli(); + uint32_t next_mark = ARM_DWT_CYCCNT + (T1+T2+T3); + + while(pixels.has(1)) { + pixels.stepDithering(); + #if (FASTLED_ALLOW_INTERRUPTS == 1) + cli(); + // if interrupts took longer than 45µs, punt on the current frame + if(ARM_DWT_CYCCNT > next_mark) { + if((ARM_DWT_CYCCNT-next_mark) > ((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US)) { sei(); return 0; } + } + + hi = *port | FastPin::mask(); + lo = *port & ~FastPin::mask(); + #endif + // Write first byte, read next byte + writeBits<8+XTRA0>(next_mark, port, hi, lo, b); + b = pixels.loadAndScale1(); + + // Write second byte, read 3rd byte + writeBits<8+XTRA0>(next_mark, port, hi, lo, b); + b = pixels.loadAndScale2(); + + // Write third byte, read 1st byte of next pixel + writeBits<8+XTRA0>(next_mark, port, hi, lo, b); + b = pixels.advanceAndLoadAndScale0(); + #if (FASTLED_ALLOW_INTERRUPTS == 1) + sei(); + #endif + }; + + sei(); + return ARM_DWT_CYCCNT; + } +}; + +FASTLED_NAMESPACE_END + +#endif diff --git a/libraries/FastLED-3.2.9/platforms/arm/d51/fastled_arm_d51.h b/libraries/FastLED-3.2.9/platforms/arm/d51/fastled_arm_d51.h new file mode 100644 index 0000000..0c14bf2 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/d51/fastled_arm_d51.h @@ -0,0 +1,7 @@ +#ifndef __INC_FASTLED_ARM_D51_H +#define __INC_FASTLED_ARM_D51_H + +#include "fastpin_arm_d51.h" +#include "clockless_arm_d51.h" + +#endif diff --git a/libraries/FastLED-3.2.9/platforms/arm/d51/fastpin_arm_d51.h b/libraries/FastLED-3.2.9/platforms/arm/d51/fastpin_arm_d51.h new file mode 100644 index 0000000..6d14c63 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/d51/fastpin_arm_d51.h @@ -0,0 +1,116 @@ +#ifndef __INC_FASTPIN_ARM_D51_H +#define __INC_FASTPIN_ARM_D51_H + +FASTLED_NAMESPACE_BEGIN + +#if defined(FASTLED_FORCE_SOFTWARE_PINS) +#warning "Software pin support forced, pin access will be slightly slower." +#define NO_HARDWARE_PIN_SUPPORT +#undef HAS_HARDWARE_PIN_SUPPORT + +#else + +/// Template definition for STM32 style ARM pins, providing direct access to the various GPIO registers. Note that this +/// uses the full port GPIO registers. In theory, in some way, bit-band register access -should- be faster, however I have found +/// that something about the way gcc does register allocation results in the bit-band code being slower. It will need more fine tuning. +/// The registers are data output, set output, clear output, toggle output, input, and direction + +template class _ARMPIN { +public: + typedef volatile uint32_t * port_ptr_t; + typedef uint32_t port_t; + + #if 0 + inline static void setOutput() { + if(_BIT<8) { + _CRL::r() = (_CRL::r() & (0xF << (_BIT*4)) | (0x1 << (_BIT*4)); + } else { + _CRH::r() = (_CRH::r() & (0xF << ((_BIT-8)*4))) | (0x1 << ((_BIT-8)*4)); + } + } + inline static void setInput() { /* TODO */ } // TODO: preform MUX config { _PDDR::r() &= ~_MASK; } + #endif + + inline static void setOutput() { pinMode(PIN, OUTPUT); } // TODO: perform MUX config { _PDDR::r() |= _MASK; } + inline static void setInput() { pinMode(PIN, INPUT); } // TODO: preform MUX config { _PDDR::r() &= ~_MASK; } + + inline static void hi() __attribute__ ((always_inline)) { PORT->Group[_GRP].OUTSET.reg = _MASK; } + inline static void lo() __attribute__ ((always_inline)) { PORT->Group[_GRP].OUTCLR.reg = _MASK; } + inline static void set(register port_t val) __attribute__ ((always_inline)) { PORT->Group[_GRP].OUT.reg = val; } + + inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); } + + inline static void toggle() __attribute__ ((always_inline)) { PORT->Group[_GRP].OUTTGL.reg = _MASK; } + + inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); } + inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); } + inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; } + + inline static port_t hival() __attribute__ ((always_inline)) { return PORT->Group[_GRP].OUT.reg | _MASK; } + inline static port_t loval() __attribute__ ((always_inline)) { return PORT->Group[_GRP].OUT.reg & ~_MASK; } + inline static port_ptr_t port() __attribute__ ((always_inline)) { return &PORT->Group[_GRP].OUT.reg; } + inline static port_ptr_t sport() __attribute__ ((always_inline)) { return &PORT->Group[_GRP].OUTSET.reg; } + inline static port_ptr_t cport() __attribute__ ((always_inline)) { return &PORT->Group[_GRP].OUTCLR.reg; } + inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; } +}; + +#define _R(T) struct __gen_struct_ ## T +#define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline volatile PortGroup * r() { return T; } }; + +#define _IO32(L) _RD32(GPIO ## L) + +#define _DEFPIN_ARM(PIN, L, BIT) template<> class FastPin : public _ARMPIN {}; + +// Actual pin definitions +#if defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + +#define MAX_PIN 19 +// D0-D13, including D6+D8 (DotStar CLK + DATA) +_DEFPIN_ARM( 0, 0, 16); _DEFPIN_ARM( 1, 0, 17); _DEFPIN_ARM( 2, 0, 7); _DEFPIN_ARM( 3, 1, 22); +_DEFPIN_ARM( 4, 0, 14); _DEFPIN_ARM( 5, 0, 15); _DEFPIN_ARM( 6, 1, 2); _DEFPIN_ARM( 7, 0, 18); +_DEFPIN_ARM( 8, 1, 3); _DEFPIN_ARM( 9, 0, 19); _DEFPIN_ARM(10, 0, 20); _DEFPIN_ARM(11, 0, 21); +_DEFPIN_ARM(12, 0, 23); _DEFPIN_ARM(13, 0, 22); +// A0-A5 +_DEFPIN_ARM(14, 0, 2); _DEFPIN_ARM(15, 0, 5); _DEFPIN_ARM(16, 1, 8); _DEFPIN_ARM(17, 1, 9); +_DEFPIN_ARM(18, 0, 4); _DEFPIN_ARM(19, 0, 6); /* A6 is present in variant.h but couldn't find it on the schematic */ +// SDA/SCL +_DEFPIN_ARM(21, 0, 12); _DEFPIN_ARM(22, 0, 13); + +// 23..25 MISO/SCK/MOSI +_DEFPIN_ARM(23, 1, 23); _DEFPIN_ARM(24, 0, 1); _DEFPIN_ARM(25, 0, 0); + +#define SPI_DATA 25 +#define SPI_CLOCK 24 + +#define HAS_HARDWARE_PIN_SUPPORT 1 + +#elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + +#define MAX_PIN 19 +// D0-D13, including D8 (neopixel) no pins 2 3 +_DEFPIN_ARM( 0, 1, 17); _DEFPIN_ARM( 1, 1, 16); +_DEFPIN_ARM( 4, 0, 14); _DEFPIN_ARM( 5, 0, 16); _DEFPIN_ARM( 6, 0, 18); +_DEFPIN_ARM( 8, 1, 3); _DEFPIN_ARM( 9, 0, 19); _DEFPIN_ARM(10, 0, 20); _DEFPIN_ARM(11, 0, 21); +_DEFPIN_ARM(12, 0, 22); _DEFPIN_ARM(13, 0, 23); +// A0-A5 +_DEFPIN_ARM(14, 0, 2); _DEFPIN_ARM(15, 0, 5); _DEFPIN_ARM(16, 1, 8); _DEFPIN_ARM(17, 1, 9); +_DEFPIN_ARM(18, 0, 4); _DEFPIN_ARM(19, 0, 6); /* A6 is present in variant.h but couldn't find it on the schematic */ +// SDA/SCL +_DEFPIN_ARM(21, 0, 12); _DEFPIN_ARM(22, 0, 13); +// 23..25 MISO/MOSI/SCK +_DEFPIN_ARM(23, 1, 22); _DEFPIN_ARM(24, 1, 23); _DEFPIN_ARM(25, 0, 17); + +#define SPI_DATA 24 +#define SPI_CLOCK 25 + +#define HAS_HARDWARE_PIN_SUPPORT 1 +#endif + + + +#endif // FASTLED_FORCE_SOFTWARE_PINS + +FASTLED_NAMESPACE_END + + +#endif // __INC_FASTPIN_ARM_D51_H diff --git a/libraries/FastLED-3.2.9/platforms/arm/d51/led_sysdefs_arm_d51.h b/libraries/FastLED-3.2.9/platforms/arm/d51/led_sysdefs_arm_d51.h new file mode 100644 index 0000000..fd6a25e --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/d51/led_sysdefs_arm_d51.h @@ -0,0 +1,27 @@ +#ifndef __INC_LED_SYSDEFS_ARM_D51_H +#define __INC_LED_SYSDEFS_ARM_D51_H + + +#define FASTLED_ARM +// Note this is an M4, not an M0+, but this enables the shared m0clockless.h +#define FASTLED_ARM_M0_PLUS + +#ifndef INTERRUPT_THRESHOLD +#define INTERRUPT_THRESHOLD 1 +#endif + +// Default to allowing interrupts +#ifndef FASTLED_ALLOW_INTERRUPTS +#define FASTLED_ALLOW_INTERRUPTS 0 +#endif + +#if FASTLED_ALLOW_INTERRUPTS == 1 +#define FASTLED_ACCURATE_CLOCK +#endif + +// reusing/abusing cli/sei defs for due +#define cli() __disable_irq(); +#define sei() __enable_irq(); + + +#endif diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/clockless_arm_k20.h b/libraries/FastLED-3.2.9/platforms/arm/k20/clockless_arm_k20.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/clockless_arm_k20.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/clockless_arm_k20.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/clockless_block_arm_k20.h b/libraries/FastLED-3.2.9/platforms/arm/k20/clockless_block_arm_k20.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/clockless_block_arm_k20.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/clockless_block_arm_k20.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/fastled_arm_k20.h b/libraries/FastLED-3.2.9/platforms/arm/k20/fastled_arm_k20.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/fastled_arm_k20.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/fastled_arm_k20.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/fastpin_arm_k20.h b/libraries/FastLED-3.2.9/platforms/arm/k20/fastpin_arm_k20.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/fastpin_arm_k20.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/fastpin_arm_k20.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/fastspi_arm_k20.h b/libraries/FastLED-3.2.9/platforms/arm/k20/fastspi_arm_k20.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/fastspi_arm_k20.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/fastspi_arm_k20.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/led_sysdefs_arm_k20.h b/libraries/FastLED-3.2.9/platforms/arm/k20/led_sysdefs_arm_k20.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/led_sysdefs_arm_k20.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/led_sysdefs_arm_k20.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/octows2811_controller.h b/libraries/FastLED-3.2.9/platforms/arm/k20/octows2811_controller.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/octows2811_controller.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/octows2811_controller.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/smartmatrix_t3.h b/libraries/FastLED-3.2.9/platforms/arm/k20/smartmatrix_t3.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/smartmatrix_t3.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/smartmatrix_t3.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k20/ws2812serial_controller.h b/libraries/FastLED-3.2.9/platforms/arm/k20/ws2812serial_controller.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k20/ws2812serial_controller.h rename to libraries/FastLED-3.2.9/platforms/arm/k20/ws2812serial_controller.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k66/clockless_arm_k66.h b/libraries/FastLED-3.2.9/platforms/arm/k66/clockless_arm_k66.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k66/clockless_arm_k66.h rename to libraries/FastLED-3.2.9/platforms/arm/k66/clockless_arm_k66.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k66/clockless_block_arm_k66.h b/libraries/FastLED-3.2.9/platforms/arm/k66/clockless_block_arm_k66.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k66/clockless_block_arm_k66.h rename to libraries/FastLED-3.2.9/platforms/arm/k66/clockless_block_arm_k66.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k66/fastled_arm_k66.h b/libraries/FastLED-3.2.9/platforms/arm/k66/fastled_arm_k66.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k66/fastled_arm_k66.h rename to libraries/FastLED-3.2.9/platforms/arm/k66/fastled_arm_k66.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k66/fastpin_arm_k66.h b/libraries/FastLED-3.2.9/platforms/arm/k66/fastpin_arm_k66.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k66/fastpin_arm_k66.h rename to libraries/FastLED-3.2.9/platforms/arm/k66/fastpin_arm_k66.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k66/fastspi_arm_k66.h b/libraries/FastLED-3.2.9/platforms/arm/k66/fastspi_arm_k66.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k66/fastspi_arm_k66.h rename to libraries/FastLED-3.2.9/platforms/arm/k66/fastspi_arm_k66.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/k66/led_sysdefs_arm_k66.h b/libraries/FastLED-3.2.9/platforms/arm/k66/led_sysdefs_arm_k66.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/k66/led_sysdefs_arm_k66.h rename to libraries/FastLED-3.2.9/platforms/arm/k66/led_sysdefs_arm_k66.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/kl26/clockless_arm_kl26.h b/libraries/FastLED-3.2.9/platforms/arm/kl26/clockless_arm_kl26.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/kl26/clockless_arm_kl26.h rename to libraries/FastLED-3.2.9/platforms/arm/kl26/clockless_arm_kl26.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/kl26/fastled_arm_kl26.h b/libraries/FastLED-3.2.9/platforms/arm/kl26/fastled_arm_kl26.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/kl26/fastled_arm_kl26.h rename to libraries/FastLED-3.2.9/platforms/arm/kl26/fastled_arm_kl26.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/kl26/fastpin_arm_kl26.h b/libraries/FastLED-3.2.9/platforms/arm/kl26/fastpin_arm_kl26.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/kl26/fastpin_arm_kl26.h rename to libraries/FastLED-3.2.9/platforms/arm/kl26/fastpin_arm_kl26.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/kl26/fastspi_arm_kl26.h b/libraries/FastLED-3.2.9/platforms/arm/kl26/fastspi_arm_kl26.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/kl26/fastspi_arm_kl26.h rename to libraries/FastLED-3.2.9/platforms/arm/kl26/fastspi_arm_kl26.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/kl26/led_sysdefs_arm_kl26.h b/libraries/FastLED-3.2.9/platforms/arm/kl26/led_sysdefs_arm_kl26.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/kl26/led_sysdefs_arm_kl26.h rename to libraries/FastLED-3.2.9/platforms/arm/kl26/led_sysdefs_arm_kl26.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/nrf51/clockless_arm_nrf51.h b/libraries/FastLED-3.2.9/platforms/arm/nrf51/clockless_arm_nrf51.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/nrf51/clockless_arm_nrf51.h rename to libraries/FastLED-3.2.9/platforms/arm/nrf51/clockless_arm_nrf51.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/nrf51/fastled_arm_nrf51.h b/libraries/FastLED-3.2.9/platforms/arm/nrf51/fastled_arm_nrf51.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/nrf51/fastled_arm_nrf51.h rename to libraries/FastLED-3.2.9/platforms/arm/nrf51/fastled_arm_nrf51.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/nrf51/fastpin_arm_nrf51.h b/libraries/FastLED-3.2.9/platforms/arm/nrf51/fastpin_arm_nrf51.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/nrf51/fastpin_arm_nrf51.h rename to libraries/FastLED-3.2.9/platforms/arm/nrf51/fastpin_arm_nrf51.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/nrf51/fastspi_arm_nrf51.h b/libraries/FastLED-3.2.9/platforms/arm/nrf51/fastspi_arm_nrf51.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/nrf51/fastspi_arm_nrf51.h rename to libraries/FastLED-3.2.9/platforms/arm/nrf51/fastspi_arm_nrf51.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/nrf51/led_sysdefs_arm_nrf51.h b/libraries/FastLED-3.2.9/platforms/arm/nrf51/led_sysdefs_arm_nrf51.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/nrf51/led_sysdefs_arm_nrf51.h rename to libraries/FastLED-3.2.9/platforms/arm/nrf51/led_sysdefs_arm_nrf51.h diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/arbiter_nrf52.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/arbiter_nrf52.h new file mode 100644 index 0000000..5a6aa92 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/arbiter_nrf52.h @@ -0,0 +1,115 @@ +#ifndef __INC_ARBITER_NRF52 +#define __INC_ARBITER_NRF52 + +#if defined(NRF52_SERIES) + +#include "led_sysdefs_arm_nrf52.h" + +//FASTLED_NAMESPACE_BEGIN + +typedef void (*FASTLED_NRF52_PWM_INTERRUPT_HANDLER)(); + +// a trick learned from other embedded projects .. +// use the enum as an index to a statically-allocated array +// to store unique information for that instance. +// also provides a count of how many instances were enabled. +// +// See led_sysdefs_arm_nrf52.h for selection.... +// +typedef enum _FASTLED_NRF52_ENABLED_PWM_INSTANCE { +#if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE0) + FASTLED_NRF52_PWM0_INSTANCE_IDX, +#endif +#if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE1) + FASTLED_NRF52_PWM1_INSTANCE_IDX, +#endif +#if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE2) + FASTLED_NRF52_PWM2_INSTANCE_IDX, +#endif +#if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE3) + FASTLED_NRF52_PWM3_INSTANCE_IDX, +#endif + FASTLED_NRF52_PWM_INSTANCE_COUNT +} FASTLED_NRF52_ENABLED_PWM_INSTANCES; + +static_assert(FASTLED_NRF52_PWM_INSTANCE_COUNT > 0, "Instance count must be greater than zero -- define FASTLED_NRF52_ENABLE_PWM_INSTNACE[n] (replace `[n]` with digit)"); + +template +class PWM_Arbiter { + +private: + static_assert(_PWM_ID < 32, "PWM_ID over 31 breaks current arbitration bitmask"); + //const uint32_t _ACQUIRE_MASK = (1u << _PWM_ID) ; + //const uint32_t _CLEAR_MASK = ~((uint32_t)(1u << _PWM_ID)); + static uint32_t s_PwmInUse; + static NRF_PWM_Type * const s_PWM; + static IRQn_Type const s_PWM_IRQ; + static FASTLED_NRF52_PWM_INTERRUPT_HANDLER volatile s_Isr; + +public: + static void isr_handler() { + return s_Isr(); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static bool isAcquired() { + return (0u != (s_PwmInUse & 1u)); // _ACQUIRE_MASK + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void acquire(FASTLED_NRF52_PWM_INTERRUPT_HANDLER isr) { + while (!tryAcquire(isr)); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static bool tryAcquire(FASTLED_NRF52_PWM_INTERRUPT_HANDLER isr) { + uint32_t oldValue = __sync_fetch_and_or(&s_PwmInUse, 1u); // _ACQUIRE_MASK + if (0u == (oldValue & 1u)) { // _ACQUIRE_MASK + s_Isr = isr; + return true; + } + return false; + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void releaseFromIsr() { + uint32_t oldValue = __sync_fetch_and_and(&s_PwmInUse, ~1u); // _CLEAR_MASK + if (0u == (oldValue & 1u)) { // _ACQUIRE_MASK + // TODO: This should never be true... indicates was not held. + // Assert here? + (void)oldValue; + } + return; + } + FASTLED_NRF52_INLINE_ATTRIBUTE static NRF_PWM_Type * getPWM() { + return s_PWM; + } + FASTLED_NRF52_INLINE_ATTRIBUTE static IRQn_Type getIRQn() { return s_PWM_IRQ; } +}; +template NRF_PWM_Type * const PWM_Arbiter<_PWM_ID>::s_PWM = + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE0) + (_PWM_ID == 0 ? NRF_PWM0 : + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE1) + (_PWM_ID == 1 ? NRF_PWM1 : + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE2) + (_PWM_ID == 2 ? NRF_PWM2 : + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE3) + (_PWM_ID == 3 ? NRF_PWM3 : + #endif + (NRF_PWM_Type*)-1 + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE0) + ) + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE1) + ) + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE2) + ) + #endif + #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE3) + ) + #endif + ; +template IRQn_Type const PWM_Arbiter<_PWM_ID>::s_PWM_IRQ = ((IRQn_Type)((uint8_t)((uint32_t)(s_PWM) >> 12))); +template uint32_t PWM_Arbiter<_PWM_ID>::s_PwmInUse = 0; +template FASTLED_NRF52_PWM_INTERRUPT_HANDLER volatile PWM_Arbiter<_PWM_ID>::s_Isr = NULL; + +//FASTLED_NAMESPACE_END + +#endif // NRF52_SERIES +#endif // __INC_ARBITER_NRF52 \ No newline at end of file diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/clockless_arm_nrf52.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/clockless_arm_nrf52.h new file mode 100644 index 0000000..d8a5da9 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/clockless_arm_nrf52.h @@ -0,0 +1,371 @@ +#ifndef __INC_CLOCKLESS_ARM_NRF52 +#define __INC_CLOCKLESS_ARM_NRF52 + +#if defined(NRF52_SERIES) + + +//FASTLED_NAMESPACE_BEGIN + +#define FASTLED_HAS_CLOCKLESS 1 +#define FASTLED_NRF52_MAXIMUM_PIXELS_PER_STRING 144 // TODO: Figure out how to safely let this be calller-defined.... + +// nRF52810 has a single PWM peripheral (PWM0) +// nRF52832 has three PWM peripherals (PWM0, PWM1, PWM2) +// nRF52840 has four PWM peripherals (PWM0, PWM1, PWM2, PWM3) +// NOTE: Update platforms.cpp in root of FastLED library if this changes +#define FASTLED_NRF52_PWM_ID 0 + + +extern uint32_t isrCount; + + +template +class ClocklessController : public CPixelLEDController<_RGB_ORDER> { + static_assert(FASTLED_NRF52_MAXIMUM_PIXELS_PER_STRING > 0, "Maximum string length must be positive value (FASTLED_NRF52_MAXIMUM_PIXELS_PER_STRING)"); + static_assert(_T1 > 0 , "negative values are not allowed"); + static_assert(_T2 > 0 , "negative values are not allowed"); + static_assert(_T3 > 0 , "negative values are not allowed"); + static_assert(_T1 < (0x8000u-2u), "_T1 must fit in 15 bits"); + static_assert(_T2 < (0x8000u-2u), "_T2 must fit in 15 bits"); + static_assert(_T3 < (0x8000u-2u), "_T3 must fit in 15 bits"); + static_assert(_T1 < (0x8000u-2u), "_T0H must fit in 15 bits"); + static_assert(_T1+_T2 < (0x8000u-2u), "_T1H must fit in 15 bits"); + static_assert(_T1+_T2+_T3 < (0x8000u-2u), "_TOP must fit in 15 bits"); + static_assert(_T1+_T2+_T3 <= PWM_COUNTERTOP_COUNTERTOP_Msk, "_TOP too large for peripheral"); + +private: + static const bool _INITIALIZE_PIN_HIGH = (_FLIP ? 1 : 0); + static const uint16_t _POLARITY_BIT = (_FLIP ? 0 : 0x8000); + + static const uint8_t _BITS_PER_PIXEL = (8 + _XTRA0) * 3; // NOTE: 3 means RGB only... + static const uint16_t _PWM_BUFFER_COUNT = (_BITS_PER_PIXEL * FASTLED_NRF52_MAXIMUM_PIXELS_PER_STRING); + static const uint8_t _T0H = ((uint16_t)(_T1 )); + static const uint8_t _T1H = ((uint16_t)(_T1+_T2 )); + static const uint8_t _TOP = ((uint16_t)(_T1+_T2+_T3)); + + // may as well be static, as can only attach one LED string per _DATA_PIN.... + static uint16_t s_SequenceBuffer[_PWM_BUFFER_COUNT]; + static uint16_t s_SequenceBufferValidElements; + static uint32_t s_SequenceBufferInUse; + static CMinWait<_WAIT_TIME_MICROSECONDS> mWait; // ensure data has time to latch + + FASTLED_NRF52_INLINE_ATTRIBUTE static void startPwmPlayback_InitializePinState() { + FastPin<_DATA_PIN>::setOutput(); + if (_INITIALIZE_PIN_HIGH) { + FastPin<_DATA_PIN>::hi(); + } else { + FastPin<_DATA_PIN>::lo(); + } + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void startPwmPlayback_InitializePwmInstance(NRF_PWM_Type * pwm) { + + // Pins must be set before enabling the peripheral + pwm->PSEL.OUT[0] = FastPin<_DATA_PIN>::nrf_pin(); + pwm->PSEL.OUT[1] = NRF_PWM_PIN_NOT_CONNECTED; + pwm->PSEL.OUT[2] = NRF_PWM_PIN_NOT_CONNECTED; + pwm->PSEL.OUT[3] = NRF_PWM_PIN_NOT_CONNECTED; + nrf_pwm_enable(pwm); + nrf_pwm_configure(pwm, NRF_PWM_CLK_16MHz, NRF_PWM_MODE_UP, _TOP); + nrf_pwm_decoder_set(pwm, NRF_PWM_LOAD_COMMON, NRF_PWM_STEP_AUTO); + + // clear any prior shorts / interrupt enable bits + nrf_pwm_shorts_set(pwm, 0); + nrf_pwm_int_set(pwm, 0); + // clear all prior events + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_STOPPED); + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQSTARTED0); + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQSTARTED1); + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0); + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND1); + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_PWMPERIODEND); + nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_LOOPSDONE); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void startPwmPlayback_ConfigurePwmSequence(NRF_PWM_Type * pwm) { + // config is easy, using SEQ0, no loops... + nrf_pwm_sequence_t sequenceConfig; + sequenceConfig.values.p_common = &(s_SequenceBuffer[0]); + sequenceConfig.length = s_SequenceBufferValidElements; + sequenceConfig.repeats = 0; // send the data once, and only once + sequenceConfig.end_delay = 0; // no extra delay at the end of SEQ[0] / SEQ[1] + nrf_pwm_sequence_set(pwm, 0, &sequenceConfig); + nrf_pwm_sequence_set(pwm, 1, &sequenceConfig); + nrf_pwm_loop_set(pwm, 0); + + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void startPwmPlayback_EnableInterruptsAndShortcuts(NRF_PWM_Type * pwm) { + IRQn_Type irqn = PWM_Arbiter::getIRQn(); + // TODO: check API results... + uint32_t result; + + result = sd_nvic_SetPriority(irqn, configMAX_SYSCALL_INTERRUPT_PRIORITY); + (void)result; + result = sd_nvic_EnableIRQ(irqn); + (void)result; + + // shortcuts prevent (up to) 4-cycle delay from interrupt handler to next action + uint32_t shortsToEnable = 0; + shortsToEnable |= NRF_PWM_SHORT_SEQEND0_STOP_MASK; ///< SEQEND[0] --> STOP task. + shortsToEnable |= NRF_PWM_SHORT_SEQEND1_STOP_MASK; ///< SEQEND[1] --> STOP task. + //shortsToEnable |= NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK; ///< LOOPSDONE --> SEQSTART[0] task. + //shortsToEnable |= NRF_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK; ///< LOOPSDONE --> SEQSTART[1] task. + shortsToEnable |= NRF_PWM_SHORT_LOOPSDONE_STOP_MASK; ///< LOOPSDONE --> STOP task. + nrf_pwm_shorts_set(pwm, shortsToEnable); + + // mark which events should cause interrupts... + uint32_t interruptsToEnable = 0; + interruptsToEnable |= NRF_PWM_INT_SEQEND0_MASK; + interruptsToEnable |= NRF_PWM_INT_SEQEND1_MASK; + interruptsToEnable |= NRF_PWM_INT_LOOPSDONE_MASK; + interruptsToEnable |= NRF_PWM_INT_STOPPED_MASK; + nrf_pwm_int_set(pwm, interruptsToEnable); + + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void startPwmPlayback_StartTask(NRF_PWM_Type * pwm) { + nrf_pwm_task_trigger(pwm, NRF_PWM_TASK_SEQSTART0); + } + +public: + static void isr_handler() { + NRF_PWM_Type * pwm = PWM_Arbiter::getPWM(); + IRQn_Type irqn = PWM_Arbiter::getIRQn(); + + // Currently, only use SEQUENCE 0, so only event + // of consequence is LOOPSDONE ... + if (nrf_pwm_event_check(pwm,NRF_PWM_EVENT_STOPPED)) { + nrf_pwm_event_clear(pwm,NRF_PWM_EVENT_STOPPED); + + // mark the sequence as no longer in use -- pointer, comparator, exchange value + __sync_fetch_and_and(&s_SequenceBufferInUse, 0); + // prevent further interrupts from PWM events + nrf_pwm_int_set(pwm, 0); + // disable PWM interrupts - None of the PWM IRQs are shared + // with other peripherals, avoiding complexity of shared IRQs. + sd_nvic_DisableIRQ(irqn); + // disable the PWM instance + nrf_pwm_disable(pwm); + // may take up to 4 cycles for writes to propagate (APB bus @ 16MHz) + asm __volatile__ ( "NOP; NOP; NOP; NOP;" ); + // release the PWM arbiter to be re-used by another LED string + PWM_Arbiter::releaseFromIsr(); + } + } + + + virtual void init() { + FASTLED_NRF52_DEBUGPRINT("Clockless Timings:\n"); + FASTLED_NRF52_DEBUGPRINT(" T0H == %d", _T0H); + FASTLED_NRF52_DEBUGPRINT(" T1H == %d", _T1H); + FASTLED_NRF52_DEBUGPRINT(" TOP == %d\n", _TOP); + } + virtual uint16_t getMaxRefreshRate() const { return 800; } + + virtual void showPixels(PixelController<_RGB_ORDER> & pixels) { + // wait for the only sequence buffer to become available + while (s_SequenceBufferInUse != 0); + prepareSequenceBuffers(pixels); + mWait.wait(); // ensure min time between updates + startPwmPlayback(s_SequenceBufferValidElements); + return; + } + + template + FASTLED_NRF52_INLINE_ATTRIBUTE static void WriteBitToSequence(uint8_t byte, uint16_t * e) { + *e = _POLARITY_BIT | (((byte & (1u << _BIT)) == 0) ? _T0H : _T1H); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void prepareSequenceBuffers(PixelController<_RGB_ORDER> & pixels) { + s_SequenceBufferValidElements = 0; + int32_t remainingSequenceElements = _PWM_BUFFER_COUNT; + uint16_t * e = s_SequenceBuffer; + uint32_t size_needed = pixels.size(); // count of pixels + size_needed *= (8 + _XTRA0); // bits per pixel + size_needed *= 2; // each bit takes two bytes + + if (size_needed > _PWM_BUFFER_COUNT) { + // TODO: assert()? + return; + } + + while (pixels.has(1) && (remainingSequenceElements >= _BITS_PER_PIXEL)) { + uint8_t b0 = pixels.loadAndScale0(); + WriteBitToSequence<7>(b0, e); e++; + WriteBitToSequence<6>(b0, e); e++; + WriteBitToSequence<5>(b0, e); e++; + WriteBitToSequence<4>(b0, e); e++; + WriteBitToSequence<3>(b0, e); e++; + WriteBitToSequence<2>(b0, e); e++; + WriteBitToSequence<1>(b0, e); e++; + WriteBitToSequence<0>(b0, e); e++; + if (_XTRA0 > 0) { + for (int i = 0; i < _XTRA0; i++) { + WriteBitToSequence<0>(0,e); e++; + } + } + uint8_t b1 = pixels.loadAndScale1(); + WriteBitToSequence<7>(b1, e); e++; + WriteBitToSequence<6>(b1, e); e++; + WriteBitToSequence<5>(b1, e); e++; + WriteBitToSequence<4>(b1, e); e++; + WriteBitToSequence<3>(b1, e); e++; + WriteBitToSequence<2>(b1, e); e++; + WriteBitToSequence<1>(b1, e); e++; + WriteBitToSequence<0>(b1, e); e++; + if (_XTRA0 > 0) { + for (int i = 0; i < _XTRA0; i++) { + WriteBitToSequence<0>(0,e); e++; + } + } + uint8_t b2 = pixels.loadAndScale2(); + WriteBitToSequence<7>(b2, e); e++; + WriteBitToSequence<6>(b2, e); e++; + WriteBitToSequence<5>(b2, e); e++; + WriteBitToSequence<4>(b2, e); e++; + WriteBitToSequence<3>(b2, e); e++; + WriteBitToSequence<2>(b2, e); e++; + WriteBitToSequence<1>(b2, e); e++; + WriteBitToSequence<0>(b2, e); e++; + if (_XTRA0 > 0) { + for (int i = 0; i < _XTRA0; i++) { + WriteBitToSequence<0>(0,e); e++; + } + } + + // advance pixel and sequence pointers + s_SequenceBufferValidElements += _BITS_PER_PIXEL; + remainingSequenceElements -= _BITS_PER_PIXEL; + pixels.advanceData(); + pixels.stepDithering(); + } + } + + + FASTLED_NRF52_INLINE_ATTRIBUTE static void startPwmPlayback(uint16_t bytesToSend) { + PWM_Arbiter::acquire(isr_handler); + NRF_PWM_Type * pwm = PWM_Arbiter::getPWM(); + + // mark the sequence as being in-use + __sync_fetch_and_or(&s_SequenceBufferInUse, 1); + + startPwmPlayback_InitializePinState(); + startPwmPlayback_InitializePwmInstance(pwm); + startPwmPlayback_ConfigurePwmSequence(pwm); + startPwmPlayback_EnableInterruptsAndShortcuts(pwm); + startPwmPlayback_StartTask(pwm); + return; + } + + +#if 0 + FASTLED_NRF52_INLINE_ATTRIBUTE static uint16_t* getRawSequenceBuffer() { return s_SequenceBuffer; } + FASTLED_NRF52_INLINE_ATTRIBUTE static uint16_t getRawSequenceBufferSize() { return _PWM_BUFFER_COUNT; } + FASTLED_NRF52_INLINE_ATTRIBUTE static uint16_t getSequenceBufferInUse() { return s_SequenceBufferInUse; } + FASTLED_NRF52_INLINE_ATTRIBUTE static void sendRawSequenceBuffer(uint16_t bytesToSend) { + mWait.wait(); // ensure min time between updates + startPwmPlayback(bytesToSend); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void sendRawBytes(uint8_t * arrayOfBytes, uint16_t bytesToSend) { + // wait for sequence buffer to be available + while (s_SequenceBufferInUse != 0); + + s_SequenceBufferValidElements = 0; + int32_t remainingSequenceElements = _PWM_BUFFER_COUNT; + uint16_t * e = s_SequenceBuffer; + uint8_t * nextByte = arrayOfBytes; + for (uint16_t bytesRemain = bytesToSend; + (remainingSequenceElements >= 8) && (bytesRemain > 0); + bytesRemain--, + remainingSequenceElements -= 8, + s_SequenceBufferValidElements += 8 + ) { + uint8_t b = *nextByte; + WriteBitToSequence<7,false>(b, e); e++; + WriteBitToSequence<6,false>(b, e); e++; + WriteBitToSequence<5,false>(b, e); e++; + WriteBitToSequence<4,false>(b, e); e++; + WriteBitToSequence<3,false>(b, e); e++; + WriteBitToSequence<2,false>(b, e); e++; + WriteBitToSequence<1,false>(b, e); e++; + WriteBitToSequence<0,false>(b, e); e++; + if (_XTRA0 > 0) { + for (int i = 0; i < _XTRA0; i++) { + WriteBitToSequence<0,_FLIP>(0,e); e++; + } + } + } + mWait.wait(); // ensure min time between updates + + startPwmPlayback(s_SequenceBufferValidElements); + } +#endif // 0 + +}; + +template +uint16_t ClocklessController<_DATA_PIN, _T1, _T2, _T3, _RGB_ORDER, _XTRA0, _FLIP, _WAIT_TIME_MICROSECONDS>::s_SequenceBufferValidElements = 0; +template +uint32_t ClocklessController<_DATA_PIN, _T1, _T2, _T3, _RGB_ORDER, _XTRA0, _FLIP, _WAIT_TIME_MICROSECONDS>::s_SequenceBufferInUse = 0; +template +uint16_t ClocklessController<_DATA_PIN, _T1, _T2, _T3, _RGB_ORDER, _XTRA0, _FLIP, _WAIT_TIME_MICROSECONDS>::s_SequenceBuffer[_PWM_BUFFER_COUNT]; +template +CMinWait<_WAIT_TIME_MICROSECONDS> ClocklessController<_DATA_PIN, _T1, _T2, _T3, _RGB_ORDER, _XTRA0, _FLIP, _WAIT_TIME_MICROSECONDS>::mWait; + +/* nrf_pwm solution +// +// When the nRF52 softdevice (e.g., BLE) is enabled, the CPU can be pre-empted +// at any time for radio interrupts. These interrupts cannot be disabled. +// The problem is, even simple BLE advertising interrupts may take **`348μs`** +// (per softdevice 1.40, see http://infocenter.nordicsemi.com/pdf/S140_SDS_v1.3.pdf) +// +// The nRF52 chips have a decent Easy-DMA-enabled PWM peripheral. +// +// The major downside: +// [] The PWM peripheral has a fixed input buffer size at 16 bits per clock cycle. +// (each clockless protocol bit == 2 bytes) +// +// The major upsides include: +// [] Fully asynchronous, freeing CPU for other tasks +// [] Softdevice interrupts do not affect PWM clocked output (reliable clocking) +// +// The initial solution generally does the following for showPixels(): +// [] wait for a sequence buffer to become available +// [] prepare the entire LED string's sequence (see `prepareSequenceBuffers()`) +// [] ensures minimum wait time from prior sequence's end +// +// Options after initial solution working: +// [] + +// TODO: Double-buffers, so one can be doing DMA while the second +// buffer is being prepared. +// TODO: Pool of buffers, so can keep N-1 active in DMA, while +// preparing data in the final buffer? +// Write another class similar to PWM_Arbiter, only for +// tracking use of sequence buffers? +// TODO: Use volatile variable to track buffers that the +// prior DMA operation is finished with, so can fill +// in those buffers with newly-prepared data... +// apis to send the pre-generated buffer. This would be essentially asynchronous, +// and result in efficient run time if the pixels are either (a) static, or +// (b) cycle through a limited number of options whose converted results can +// be cached and re-used. While simple, this method takes lots of extra RAM... +// 16 bits for every full clock (high/low) cycle. +// +// Clockless chips typically send 24 bits (3x 8-bit) per pixel. +// One odd clockless chip sends 36 bits (3x 12-bit) per pixel. +// Each bit requires a 16-bit sequence entry for the PWM peripheral. +// This gives approximately: +// 24 bpp 36 bpp +// ========================================== +// 1 pixel 48 bytes 72 bytes +// 32 pixels 1,536 bytes 2,304 bytes +// 64 pixels 3,072 bytes 4,608 bytes +// +// +// UPDATE: this is the method I'm choosing, to get _SOMETHING_ +// clockless working... 3k RAM for 64 pixels is acceptable +// for a first release, as it allows re-use of FASTLED +// color correction, dithering, etc. .... +*/ + +//FASTLED_NAMESPACE_END + +#endif // NRF52_SERIES +#endif // __INC_CLOCKLESS_ARM_NRF52 \ No newline at end of file diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastled_arm_nrf52.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastled_arm_nrf52.h new file mode 100644 index 0000000..4530030 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastled_arm_nrf52.h @@ -0,0 +1,11 @@ +#ifndef __INC_FASTLED_ARM_NRF52_H +#define __INC_FASTLED_ARM_NRF52_H + +#include "led_sysdefs_arm_nrf52.h" +#include "arbiter_nrf52.h" +#include "fastpin_arm_nrf52.h" +#include "fastspi_arm_nrf52.h" +#include "clockless_arm_nrf52.h" + +#endif // #ifndef __INC_FASTLED_ARM_NRF52_H + diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52.h new file mode 100644 index 0000000..a868466 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52.h @@ -0,0 +1,328 @@ +#ifndef __FASTPIN_ARM_NRF52_H +#define __FASTPIN_ARM_NRF52_H + + +/* +// +// Background: +// =========== +// the nRF52 has more than 32 ports, and thus must support +// two distinct GPIO port registers. +// +// For the nRF52 series, the structure to control the port is +// `NRF_GPIO_Type`, with separate addresses mapped for set, clear, etc. +// The two ports are defined as NRF_P0 and NRF_P1. +// An example declaration for the ports is: +// #define NRF_P0_BASE 0x50000000UL +// #define NRF_P1_BASE 0x50000300UL +// #define NRF_P0 ((NRF_GPIO_Type*)NRF_P0_BASE) +// #define NRF_P1 ((NRF_GPIO_Type*)NRF_P1_BASE) +// +// Therefore, ideally, the _DEFPIN_ARM() macro would simply +// conditionally pass either NRF_P0 or NRF_P1 to the underlying +// FastPin<> template class class. +// +// The "pin" provided to the FastLED<> template (and which +// the _DEFPIN_ARM() macro specializes for valid pins) is NOT +// the microcontroller port.pin, but the Arduino digital pin. +// Some boards have an identity mapping (e.g., nRF52832 Feather) +// but most do not. Therefore, the _DEFPIN_ARM() macro +// must translate the Arduino pin to the mcu port.pin. +// +// +// Difficulties: +// ============= +// The goal is to avoid any such lookups, using compile-time +// optimized functions for speed, in line with FastLED's +// overall design goals. This means constexpr, compile-time +// and aggressive inlining of functions.... +// +// Right away, this precludes the use of g_ADigitalPinMap, +// which is not constexpr, and thus not available for +// preprocessor/compile-time optimizations. Therefore, +// we have to specialize FastPin, given a +// compile-time value for PIN, into at least a PORT and +// a BITMASK for the port. +// +// Arduino compiles using C++11 for at least Feather nRF52840 Express. +// C++11 is very restrictive about template parameters. +// Template parameters can only be: +// 1. a type (as most people expect) +// 2. a template +// 3. a constexpr native integer type +// +// Therefore, attempts to use `NRF_GPIO_Type *` as a +// template parameter will fail.... +// +// Solution: +// ========= +// The solution chosen is to define a unique structure for each port, +// whose SOLE purpose is to have a static inline function that +// returns the `NRF_GPIO_Type *` that is needed. +// +// Thus, while it's illegal to pass `NRF_P0` as a template +// parameter, it's perfectly legal to pass `__generated_struct_NRF_P0`, +// and have the template call a well-known `static inline` function +// that returns `NRF_P0` ... which is itself a compile-time constant. +// +// Note that additional magic can be applied that will automatically +// generate the structures. If you want to add that to this platform, +// check out the KL26 platform files for a starting point. +// +*/ + +// manually define two structures, to avoid fighting with preprocessor macros +struct __generated_struct_NRF_P0 { + FASTLED_NRF52_INLINE_ATTRIBUTE constexpr static NRF_GPIO_Type * r() { + return NRF_P0; + } +}; +struct __generated_struct_NRF_P1 { + FASTLED_NRF52_INLINE_ATTRIBUTE constexpr static NRF_GPIO_Type * r() { + return NRF_P1; + } +}; + + +// The actual class template can then use a typename, for what is essentially a constexpr NRF_GPIO_Type* +template class _ARMPIN { +public: + typedef volatile uint32_t * port_ptr_t; + typedef uint32_t port_t; + + FASTLED_NRF52_INLINE_ATTRIBUTE static void setOutput() { + // OK for this to be more than one instruction, as unusual to quickly switch input/output modes + nrf_gpio_cfg( + nrf_pin(), + NRF_GPIO_PIN_DIR_OUTPUT, // set pin as output + NRF_GPIO_PIN_INPUT_DISCONNECT, // disconnect the input buffering + NRF_GPIO_PIN_NOPULL, // neither pull-up nor pull-down resistors enabled + NRF_GPIO_PIN_H0H1, // high drive mode required for faster speeds + NRF_GPIO_PIN_NOSENSE // pin sense level disabled + ); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void setInput() { + // OK for this to be more than one instruction, as unusual to quickly switch input/output modes + nrf_gpio_cfg( + nrf_pin(), + NRF_GPIO_PIN_DIR_INPUT, // set pin as input + NRF_GPIO_PIN_INPUT_DISCONNECT, // disconnect the input buffering + NRF_GPIO_PIN_NOPULL, // neither pull-up nor pull-down resistors enabled + NRF_GPIO_PIN_H0H1, // high drive mode required for faster speeds + NRF_GPIO_PIN_NOSENSE // pin sense level disabled + ); + } + FASTLED_NRF52_INLINE_ATTRIBUTE static void hi() { _PORT::r()->OUTSET = _MASK; } // sets _MASK in the SET OUTPUT register (output set high) + FASTLED_NRF52_INLINE_ATTRIBUTE static void lo() { _PORT::r()->OUTCLR = _MASK; } // sets _MASK in the CLEAR OUTPUT register (output set low) + FASTLED_NRF52_INLINE_ATTRIBUTE static void toggle() { _PORT::r()->OUT ^= _MASK; } // toggles _MASK bits in the OUTPUT GPIO port directly + FASTLED_NRF52_INLINE_ATTRIBUTE static void strobe() { toggle(); toggle(); } // BUGBUG -- Is this used by FastLED? Without knowing (for example) SPI Speed? + FASTLED_NRF52_INLINE_ATTRIBUTE static port_t hival() { return _PORT::r()->OUT | _MASK; } // sets all _MASK bit(s) in the OUTPUT GPIO port to 1 + FASTLED_NRF52_INLINE_ATTRIBUTE static port_t loval() { return _PORT::r()->OUT & ~_MASK; } // sets all _MASK bit(s) in the OUTPUT GPIO port to 0 + FASTLED_NRF52_INLINE_ATTRIBUTE static port_ptr_t port() { return &(_PORT::r()->OUT); } // gets raw pointer to OUTPUT GPIO port + FASTLED_NRF52_INLINE_ATTRIBUTE static port_ptr_t cport() { return &(_PORT::r()->OUTCLR); } // gets raw pointer to SET DIRECTION GPIO port + FASTLED_NRF52_INLINE_ATTRIBUTE static port_ptr_t sport() { return &(_PORT::r()->OUTSET); } // gets raw pointer to CLEAR DIRECTION GPIO port + FASTLED_NRF52_INLINE_ATTRIBUTE static port_t mask() { return _MASK; } // gets the value of _MASK + FASTLED_NRF52_INLINE_ATTRIBUTE static void hi (register port_ptr_t port) { hi(); } // sets _MASK in the SET OUTPUT register (output set high) + FASTLED_NRF52_INLINE_ATTRIBUTE static void lo (register port_ptr_t port) { lo(); } // sets _MASK in the CLEAR OUTPUT register (output set low) + FASTLED_NRF52_INLINE_ATTRIBUTE static void set(register port_t val ) { _PORT::r()->OUT = val; } // sets entire port's value (optimization used by FastLED) + FASTLED_NRF52_INLINE_ATTRIBUTE static void fastset(register port_ptr_t port, register port_t val) { *port = val; } + constexpr static uint32_t nrf_pin2() { return NRF_GPIO_PIN_MAP(_PORT_NUMBER, _PIN_NUMBER); } + constexpr static bool LowSpeedOnlyRecommended() { + // only allow one function body. + #undef _FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT + + // unique cases for each board / processor package / module? + #if defined(NRF52810_XXAA) && defined(NRF52810_PACKAGE_QFN48) + #if defined(_FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT) + #error "Multiple board match" + #endif + #define _FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT 1 + static_assert(_PORT_NUMBER == 0, "nRF52810 only has one port"); + return ( + (_PIN_NUMBER == 25) || + (_PIN_NUMBER == 26) || + (_PIN_NUMBER == 27) || + (_PIN_NUMBER == 28) || + (_PIN_NUMBER == 29) + ); + #endif + #if defined(NRF52810_XXAA) && defined(NRF52810_PACKAGE_QFN32) + #if defined(_FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT) + #error "Multiple board match" + #endif + #define _FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT 1 + static_assert(_PORT_NUMBER == 0, "nRF52810 only has one port"); + if (_PORT_NUMBER == 0) { + if ( + (_PIN_NUMBER == 26) || + (_PIN_NUMBER == 27) + ) { + return true; + } + } + return false; + #endif + #if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) + #if defined(_FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT) + #error "Multiple board match" + #endif + #define _FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT 1 + static_assert(_PORT_NUMBER == 0, "nRF52832 only has one port"); + // data sheets shows the same pins in both QFN48 and WLCSP package + // are recommended as low-speed only: + return ( + (_PIN_NUMBER == 22) || + (_PIN_NUMBER == 23) || + (_PIN_NUMBER == 24) || + (_PIN_NUMBER == 25) || + (_PIN_NUMBER == 26) || + (_PIN_NUMBER == 27) || + (_PIN_NUMBER == 28) || + (_PIN_NUMBER == 29) || + (_PIN_NUMBER == 30) || + (_PIN_NUMBER == 31) + ); + #endif + #if defined(NRF52840_XXAA) && defined(NRF52840_PACKAGE_aQFN73) + #if defined(_FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT) + #error "Multiple board match" + #endif + #define _FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT 1 + static_assert(_PORT_NUMBER == 0 || _PORT_NUMBER == 1, "nRF52840 only has two ports"); + return + ( + ( + (_PORT_NUMBER == 0) && + ( + (_PIN_NUMBER == 2) || + (_PIN_NUMBER == 3) || + (_PIN_NUMBER == 9) || + (_PIN_NUMBER == 10) || + (_PIN_NUMBER == 11) || + (_PIN_NUMBER == 12) || + (_PIN_NUMBER == 14) || + (_PIN_NUMBER == 28) || + (_PIN_NUMBER == 29) || + (_PIN_NUMBER == 30) || + (_PIN_NUMBER == 31) + ) + ) + || + ( + (_PORT_NUMBER == 1) && + ( + (_PIN_NUMBER == 2) || + (_PIN_NUMBER == 3) || + (_PIN_NUMBER == 4) || + (_PIN_NUMBER == 5) || + (_PIN_NUMBER == 6) || + (_PIN_NUMBER == 7) || + (_PIN_NUMBER == 10) || + (_PIN_NUMBER == 13) || + (_PIN_NUMBER == 15) + ) + ) + ); + #endif + #if false && defined(NRF52840_XXAA) && (defined(NRF52840_PACKAGE_aQFN73) || defined(ARDUINO_NRF52840_FEATHER)) + // Adafruit nRF52840 feather uses RAYTAC MDBT50Q module, which is aQFN73 + // See https://cdn-learn.adafruit.com/assets/assets/000/068/544/original/Raytac_MDBT50Q.pdf + #if defined(_FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT) + #error "Multiple board match" + #endif + #define _FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT 1 + static_assert(_PORT_NUMBER == 0 || _PORT_NUMBER == 1, "nRF52840 only has two ports"); + return + ( + ( + (_PORT_NUMBER == 0) && + ( + (_PIN_NUMBER == 2) || + (_PIN_NUMBER == 3) || + (_PIN_NUMBER == 9) || + (_PIN_NUMBER == 10) || + (_PIN_NUMBER == 28) || + (_PIN_NUMBER == 29) || + (_PIN_NUMBER == 30) || + (_PIN_NUMBER == 31) + ) + ) + || + ( + (_PORT_NUMBER == 1) && + ( + (_PIN_NUMBER == 1) || + (_PIN_NUMBER == 2) || + (_PIN_NUMBER == 3) || + (_PIN_NUMBER == 4) || + (_PIN_NUMBER == 5) || + (_PIN_NUMBER == 6) || + (_PIN_NUMBER == 7) || + (_PIN_NUMBER == 10) || + (_PIN_NUMBER == 11) || + (_PIN_NUMBER == 12) || + (_PIN_NUMBER == 13) || + (_PIN_NUMBER == 14) || + (_PIN_NUMBER == 15) + ) + ) + ); + #endif + #if !defined(_FASTLED_NRF52_LOW_SPEED_ONLY_BOARD_DETECT) + #warning "Unknown board / package, ... caller must pins support high-speed" + return false; // choosing default to be FALSE, to allow users to ATTEMPT to use high-speed on pins where support is not known + #endif + } + // Expose the nrf pin (port/pin combined), port, and pin as properties (e.g., for setting up SPI) + + FASTLED_NRF52_INLINE_ATTRIBUTE static uint32_t nrf_pin() { return NRF_GPIO_PIN_MAP(_PORT_NUMBER, _PIN_NUMBER); } +}; + +// +// BOARD_PIN can be either the pin portion of a port.pin, or the combined NRF_GPIO_PIN_MAP() number. +// For example both the following two defines refer to P1.15 (pin 47) as Arduino pin 3: +// _DEFPIN_ARM(3, 1, 15); +// _DEFPIN_ARM(3, 1, 47); +// +// Similarly, the following defines are all equivalent: +// _DEFPIN_ARM_IDENTITY_P1(47); +// _DEFPIN_ARM(47, 1, 15); +// _DEFPIN_ARM(47, 1, 47); +// + +#define _DEFPIN_ARM(ARDUINO_PIN, BOARD_PORT, BOARD_PIN) \ + template<> class FastPin : \ + public _ARMPIN< \ + 1u << (BOARD_PIN & 31u), \ + __generated_struct_NRF_P ## BOARD_PORT, \ + (BOARD_PIN / 32), \ + BOARD_PIN & 31u \ + > \ + {} + +#define _DEFPIN_ARM_IDENTITY_P0(ARDUINO_PIN) \ + template<> class FastPin : \ + public _ARMPIN< \ + 1u << (ARDUINO_PIN & 31u), \ + __generated_struct_NRF_P0, \ + 0, \ + (ARDUINO_PIN & 31u) + 0 \ + > \ + {} + +#define _DEFPIN_ARM_IDENTITY_P1(ARDUINO_PIN) \ + template<> class FastPin : \ + public _ARMPIN< \ + 1u << (ARDUINO_PIN & 31u), \ + __generated_struct_NRF_P1, \ + 1, \ + (ARDUINO_PIN & 31u) + 32 \ + > \ + {} + +// The actual pin definitions are in a separate header file... +#include "fastpin_arm_nrf52_variants.h" + +#define HAS_HARDWARE_PIN_SUPPORT + +#endif // #ifndef __FASTPIN_ARM_NRF52_H diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52_variants.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52_variants.h new file mode 100644 index 0000000..b3b9ff9 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastpin_arm_nrf52_variants.h @@ -0,0 +1,579 @@ +#ifndef __FASTPIN_ARM_NRF52_VARIANTS_H +#define __FASTPIN_ARM_NRF52_VARIANTS_H + +// use this to determine if found variant or not (avoid multiple boards at once) +#undef __FASTPIN_ARM_NRF52_VARIANT_FOUND + +// Adafruit Bluefruit nRF52832 Feather +// From https://www.adafruit.com/package_adafruit_index.json +#if defined (ARDUINO_NRF52832_FEATHER) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Adafruit Bluefruit nRF52832 Feather is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + _DEFPIN_ARM_IDENTITY_P0( 0); // xtal 1 + _DEFPIN_ARM_IDENTITY_P0( 1); // xtal 2 + _DEFPIN_ARM_IDENTITY_P0( 2); // a0 + _DEFPIN_ARM_IDENTITY_P0( 3); // a1 + _DEFPIN_ARM_IDENTITY_P0( 4); // a2 + _DEFPIN_ARM_IDENTITY_P0( 5); // a3 + _DEFPIN_ARM_IDENTITY_P0( 6); // TXD + _DEFPIN_ARM_IDENTITY_P0( 7); // GPIO #7 + _DEFPIN_ARM_IDENTITY_P0( 8); // RXD + _DEFPIN_ARM_IDENTITY_P0( 9); // NFC1 + _DEFPIN_ARM_IDENTITY_P0(10); // NFC2 + _DEFPIN_ARM_IDENTITY_P0(11); // GPIO #11 + _DEFPIN_ARM_IDENTITY_P0(12); // SCK + _DEFPIN_ARM_IDENTITY_P0(13); // MOSI + _DEFPIN_ARM_IDENTITY_P0(14); // MISO + _DEFPIN_ARM_IDENTITY_P0(15); // GPIO #15 + _DEFPIN_ARM_IDENTITY_P0(16); // GPIO #16 + _DEFPIN_ARM_IDENTITY_P0(17); // LED #1 (red) + _DEFPIN_ARM_IDENTITY_P0(18); // SWO + _DEFPIN_ARM_IDENTITY_P0(19); // LED #2 (blue) + _DEFPIN_ARM_IDENTITY_P0(20); // DFU + // _DEFPIN_ARM_IDENTITY_P0(21); // Reset -- not valid to use for FastLED? + // _DEFPIN_ARM_IDENTITY_P0(22); // Factory Reset -- not vaild to use for FastLED? + // _DEFPIN_ARM_IDENTITY_P0(23); // N/A + // _DEFPIN_ARM_IDENTITY_P0(24); // N/A + _DEFPIN_ARM_IDENTITY_P0(25); // SDA + _DEFPIN_ARM_IDENTITY_P0(26); // SCL + _DEFPIN_ARM_IDENTITY_P0(27); // GPIO #27 + _DEFPIN_ARM_IDENTITY_P0(28); // A4 + _DEFPIN_ARM_IDENTITY_P0(29); // A5 + _DEFPIN_ARM_IDENTITY_P0(30); // A6 + _DEFPIN_ARM_IDENTITY_P0(31); // A7 +#endif // defined (ARDUINO_NRF52832_FEATHER) + +// Adafruit Bluefruit nRF52840 Feather Express +// From https://www.adafruit.com/package_adafruit_index.json +#if defined (ARDUINO_NRF52840_FEATHER) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + + #define MAX_PIN (33u) // 34 if wanting to use NFC1 test point + + // Arduino pins 0..7 + _DEFPIN_ARM( 0, 0, 25); // D0 is P0.25 -- UART TX + //_DEFPIN_ARM( 1, 0, 24); // D1 is P0.24 -- UART RX + _DEFPIN_ARM( 2, 0, 10); // D2 is P0.10 -- NFC2 + _DEFPIN_ARM( 3, 1, 47); // D3 is P1.15 -- PIN_LED1 (red) + _DEFPIN_ARM( 4, 1, 42); // D4 is P1.10 -- PIN_LED2 (blue) + _DEFPIN_ARM( 5, 1, 40); // D5 is P1.08 -- SPI/SS + _DEFPIN_ARM( 6, 0, 7); // D6 is P0.07 + _DEFPIN_ARM( 7, 1, 34); // D7 is P1.02 -- PIN_DFU (Button) + + // Arduino pins 8..15 + _DEFPIN_ARM( 8, 0, 16); // D8 is P0.16 -- PIN_NEOPIXEL + _DEFPIN_ARM( 9, 0, 26); // D9 is P0.26 + _DEFPIN_ARM(10, 0, 27); // D10 is P0.27 + _DEFPIN_ARM(11, 0, 6); // D11 is P0.06 + _DEFPIN_ARM(12, 0, 8); // D12 is P0.08 + _DEFPIN_ARM(13, 1, 41); // D13 is P1.09 + _DEFPIN_ARM(14, 0, 4); // D14 is P0.04 -- A0 + _DEFPIN_ARM(15, 0, 5); // D15 is P0.05 -- A1 + + // Arduino pins 16..23 + _DEFPIN_ARM(16, 0, 30); // D16 is P0.30 -- A2 + _DEFPIN_ARM(17, 0, 28); // D17 is P0.28 -- A3 + _DEFPIN_ARM(18, 0, 2); // D18 is P0.02 -- A4 + _DEFPIN_ARM(19, 0, 3); // D19 is P0.03 -- A5 + //_DEFPIN_ARM(20, 0, 29); // D20 is P0.29 -- A6 -- Connected to battery! + //_DEFPIN_ARM(21, 0, 31); // D21 is P0.31 -- A7 -- AREF + _DEFPIN_ARM(22, 0, 12); // D22 is P0.12 -- SDA + _DEFPIN_ARM(23, 0, 11); // D23 is P0.11 -- SCL + + // Arduino pins 24..31 + _DEFPIN_ARM(24, 0, 15); // D24 is P0.15 -- PIN_SPI_MISO + _DEFPIN_ARM(25, 0, 13); // D25 is P0.13 -- PIN_SPI_MOSI + _DEFPIN_ARM(26, 0, 14); // D26 is P0.14 -- PIN_SPI_SCK + //_DEFPIN_ARM(27, 0, 19); // D27 is P0.19 -- PIN_QSPI_SCK + //_DEFPIN_ARM(28, 0, 20); // D28 is P0.20 -- PIN_QSPI_CS + //_DEFPIN_ARM(29, 0, 17); // D29 is P0.17 -- PIN_QSPI_DATA0 + //_DEFPIN_ARM(30, 0, 22); // D30 is P0.22 -- PIN_QSPI_DATA1 + //_DEFPIN_ARM(31, 0, 23); // D31 is P0.23 -- PIN_QSPI_DATA2 + + // Arduino pins 32..34 + //_DEFPIN_ARM(32, 0, 21); // D32 is P0.21 -- PIN_QSPI_DATA3 + //_DEFPIN_ARM(33, 0, 9); // D33 is NFC1, only accessible via test point +#endif // defined (ARDUINO_NRF52840_FEATHER) + +// Adafruit Bluefruit nRF52840 Metro Express +// From https://www.adafruit.com/package_adafruit_index.json +#if defined (ARDUINO_NRF52840_METRO) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Adafruit Bluefruit nRF52840 Metro Express is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + + _DEFPIN_ARM( 0, 0, 25); // D0 is P0.25 (UART TX) + _DEFPIN_ARM( 1, 0, 24); // D1 is P0.24 (UART RX) + _DEFPIN_ARM( 2, 1, 10); // D2 is P1.10 + _DEFPIN_ARM( 3, 1, 4); // D3 is P1.04 + _DEFPIN_ARM( 4, 1, 11); // D4 is P1.11 + _DEFPIN_ARM( 5, 1, 12); // D5 is P1.12 + _DEFPIN_ARM( 6, 1, 14); // D6 is P1.14 + _DEFPIN_ARM( 7, 0, 26); // D7 is P0.26 + _DEFPIN_ARM( 8, 0, 27); // D8 is P0.27 + _DEFPIN_ARM( 9, 0, 12); // D9 is P0.12 + _DEFPIN_ARM(10, 0, 6); // D10 is P0.06 + _DEFPIN_ARM(11, 0, 8); // D11 is P0.08 + _DEFPIN_ARM(12, 1, 9); // D12 is P1.09 + _DEFPIN_ARM(13, 0, 14); // D13 is P0.14 + _DEFPIN_ARM(14, 0, 4); // D14 is P0.04 (A0) + _DEFPIN_ARM(15, 0, 5); // D15 is P0.05 (A1) + _DEFPIN_ARM(16, 0, 28); // D16 is P0.28 (A2) + _DEFPIN_ARM(17, 0, 30); // D17 is P0.30 (A3) + _DEFPIN_ARM(18, 0, 2); // D18 is P0.02 (A4) + _DEFPIN_ARM(19, 0, 3); // D19 is P0.03 (A5) + _DEFPIN_ARM(20, 0, 29); // D20 is P0.29 (A6, battery) + _DEFPIN_ARM(21, 0, 31); // D21 is P0.31 (A7, ARef) + _DEFPIN_ARM(22, 0, 15); // D22 is P0.15 (SDA) + _DEFPIN_ARM(23, 0, 16); // D23 is P0.16 (SCL) + _DEFPIN_ARM(24, 0, 11); // D24 is P0.11 (SPI MISO) + _DEFPIN_ARM(25, 1, 8); // D25 is P1.08 (SPI MOSI) + _DEFPIN_ARM(26, 0, 7); // D26 is P0.07 (SPI SCK ) + //_DEFPIN_ARM(27, 0, 19); // D27 is P0.19 (QSPI CLK ) + //_DEFPIN_ARM(28, 0, 20); // D28 is P0.20 (QSPI CS ) + //_DEFPIN_ARM(29, 0, 17); // D29 is P0.17 (QSPI Data 0) + //_DEFPIN_ARM(30, 0, 23); // D30 is P0.23 (QSPI Data 1) + //_DEFPIN_ARM(31, 0, 22); // D31 is P0.22 (QSPI Data 2) + //_DEFPIN_ARM(32, 0, 21); // D32 is P0.21 (QSPI Data 3) + _DEFPIN_ARM(33, 1, 13); // D33 is P1.13 LED1 + _DEFPIN_ARM(34, 1, 15); // D34 is P1.15 LED2 + _DEFPIN_ARM(35, 0, 13); // D35 is P0.13 NeoPixel + _DEFPIN_ARM(36, 1, 0); // D36 is P1.02 Switch + _DEFPIN_ARM(37, 1, 0); // D37 is P1.00 SWO/DFU + _DEFPIN_ARM(38, 0, 9); // D38 is P0.09 NFC1 + _DEFPIN_ARM(39, 0, 10); // D39 is P0.10 NFC2 +#endif // defined (ARDUINO_NRF52840_METRO) + +// Adafruit Bluefruit on nRF52840DK PCA10056 +// From https://www.adafruit.com/package_adafruit_index.json +#if defined (ARDUINO_NRF52840_PCA10056) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Adafruit Bluefruit on nRF52840DK PCA10056 is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + + #if defined(USE_ARDUINO_PIN_NUMBERING) + /* pca10056_schematic_and_pcb.pdf + Page 3 shows the Arduino Pin to GPIO Px.xx mapping + */ + _DEFPIN_ARM( 0, 1, 1); // D0 is P1.01 + _DEFPIN_ARM( 1, 1, 2); // D1 is P1.02 + _DEFPIN_ARM( 2, 1, 3); // D2 is P1.03 + _DEFPIN_ARM( 3, 1, 4); // D3 is P1.04 + _DEFPIN_ARM( 4, 1, 5); // D4 is P1.05 + _DEFPIN_ARM( 5, 1, 6); // D5 is P1.06 + _DEFPIN_ARM( 6, 1, 7); // D6 is P1.07 (BUTTON1 option) + _DEFPIN_ARM( 7, 1, 8); // D7 is P1.08 (BUTTON2 option) + _DEFPIN_ARM( 8, 1, 10); // D8 is P1.10 + _DEFPIN_ARM( 9, 1, 11); // D9 is P1.11 + _DEFPIN_ARM(10, 1, 12); // D10 is P1.12 + _DEFPIN_ARM(11, 1, 13); // D11 is P1.13 + _DEFPIN_ARM(12, 1, 14); // D12 is P1.14 + _DEFPIN_ARM(13, 1, 15); // D13 is P1.15 + _DEFPIN_ARM(14, 0, 0); // D14 is P0.00 (if SB4 bridged) + _DEFPIN_ARM(15, 0, 1); // D15 is P0.01 (if SB3 bridged) + _DEFPIN_ARM(16, 0, 5); // D16 is P0.05 (aka AIN3, aka UART RTS) + _DEFPIN_ARM(17, 0, 6); // D17 is P0.06 (UART TxD) + _DEFPIN_ARM(18, 0, 7); // D18 is P0.07 (UART CTS default) + _DEFPIN_ARM(19, 0, 8); // D19 is P0.08 (UART RxD) + _DEFPIN_ARM(20, 0, 9); // D20 is P0.09 (NFC1) + _DEFPIN_ARM(21, 0, 10); // D21 is P0.10 (NFC2) + _DEFPIN_ARM(22, 0, 11); // D22 is P0.11 (TRACEDATA2 / BUTTON1 default) + _DEFPIN_ARM(23, 0, 12); // D23 is P0.12 (TRACEDATA1 / BUTTON2 default) + _DEFPIN_ARM(24, 0, 13); // D24 is P0.13 (LED1) + _DEFPIN_ARM(25, 0, 14); // D25 is P0.14 (LED2) + _DEFPIN_ARM(26, 0, 15); // D26 is P0.15 (LED3) + _DEFPIN_ARM(27, 0, 16); // D27 is P0.16 (LED4) + _DEFPIN_ARM(28, 0, 17); // D28 is P0.17 (QSPI !CS , unless SB13 cut) + // _DEFPIN_ARM(29, 0, 18); // D29 is P0.18 (RESET) + _DEFPIN_ARM(30, 0, 19); // D30 is P0.19 (QSPI CLK , unless SB11 cut) + _DEFPIN_ARM(31, 0, 20); // D31 is P0.20 (QSPI DIO0, unless SB12 cut) + _DEFPIN_ARM(32, 0, 21); // D32 is P0.21 (QSPI DIO1, unless SB14 cut) + _DEFPIN_ARM(33, 0, 22); // D33 is P0.22 (QSPI DIO2, unless SB15 cut) + _DEFPIN_ARM(34, 0, 23); // D34 is P0.23 (QSPI DIO3, unless SB10 cut) + _DEFPIN_ARM(35, 0, 24); // D35 is P0.24 (BUTTON3) + _DEFPIN_ARM(36, 0, 25); // D36 is P0.25 (BUTTON4) + _DEFPIN_ARM(37, 1, 00); // D37 is P1.00 (TRACEDATA0 / SWO) + _DEFPIN_ARM(38, 1, 09); // D38 is P1.09 (TRACEDATA3) + //_DEFPIN_ARM(??, 0, 2); // D?? is P0.02 (AREF, aka AIN0) + //_DEFPIN_ARM(??, 0, 3); // D?? is P0.03 (A0, aka AIN1) + //_DEFPIN_ARM(??, 0, 4); // D?? is P0.04 (A1, aka AIN2, aka UART CTS option) + //_DEFPIN_ARM(??, 0, 28); // D?? is P0.28 (A2, aka AIN4) + //_DEFPIN_ARM(??, 0, 29); // D?? is P0.29 (A3, aka AIN5) + //_DEFPIN_ARM(??, 0, 30); // D?? is P0.30 (A4, aka AIN6) + //_DEFPIN_ARM(??, 0, 31); // D?? is P0.31 (A5, aka AIN7) + + #else + /* 48 pins, defined using natural mapping in Adafruit's variant.cpp (!) */ + _DEFPIN_ARM_IDENTITY_P0( 0); // P0.00 (XL1 .. ensure SB4 bridged, SB2 cut) + _DEFPIN_ARM_IDENTITY_P0( 1); // P0.01 (XL2 .. ensure SB3 bridged, SB1 cut) + _DEFPIN_ARM_IDENTITY_P0( 2); // P0.02 (AIN0) + _DEFPIN_ARM_IDENTITY_P0( 3); // P0.03 (AIN1) + _DEFPIN_ARM_IDENTITY_P0( 4); // P0.04 (AIN2 / UART CTS option) + _DEFPIN_ARM_IDENTITY_P0( 5); // P0.05 (AIN3 / UART RTS) + _DEFPIN_ARM_IDENTITY_P0( 6); // P0.06 (UART TxD) + _DEFPIN_ARM_IDENTITY_P0( 7); // P0.07 (TRACECLK / UART CTS default) + _DEFPIN_ARM_IDENTITY_P0( 8); // P0.08 (UART RxD) + _DEFPIN_ARM_IDENTITY_P0( 9); // P0.09 (NFC1) + _DEFPIN_ARM_IDENTITY_P0(10); // P0.10 (NFC2) + _DEFPIN_ARM_IDENTITY_P0(11); // P0.11 (TRACEDATA2 / BUTTON1 default) + _DEFPIN_ARM_IDENTITY_P0(12); // P0.12 (TRACEDATA1 / BUTTON2 default) + _DEFPIN_ARM_IDENTITY_P0(13); // P0.13 (LED1) + _DEFPIN_ARM_IDENTITY_P0(14); // P0.14 (LED2) + _DEFPIN_ARM_IDENTITY_P0(15); // P0.15 (LED3) + _DEFPIN_ARM_IDENTITY_P0(16); // P0.16 (LED4) + //_DEFPIN_ARM_IDENTITY_P0(17); // P0.17 (QSPI !CS ) + //_DEFPIN_ARM_IDENTITY_P0(18); // P0.18 (RESET) + //_DEFPIN_ARM_IDENTITY_P0(19); // P0.19 (QSPI CLK ) + //_DEFPIN_ARM_IDENTITY_P0(20); // P0.20 (QSPI DIO0) + //_DEFPIN_ARM_IDENTITY_P0(21); // P0.21 (QSPI DIO1) + //_DEFPIN_ARM_IDENTITY_P0(22); // P0.22 (QSPI DIO2) + //_DEFPIN_ARM_IDENTITY_P0(23); // P0.23 (QSPI DIO3) + _DEFPIN_ARM_IDENTITY_P0(24); // P0.24 (BUTTON3) + _DEFPIN_ARM_IDENTITY_P0(25); // P0.25 (BUTTON4) + _DEFPIN_ARM_IDENTITY_P0(26); // P0.26 + _DEFPIN_ARM_IDENTITY_P0(27); // P0.27 + _DEFPIN_ARM_IDENTITY_P0(28); // P0.28 (AIN4) + _DEFPIN_ARM_IDENTITY_P0(29); // P0.29 (AIN5) + _DEFPIN_ARM_IDENTITY_P0(30); // P0.30 (AIN6) + _DEFPIN_ARM_IDENTITY_P0(31); // P0.31 (AIN7) + _DEFPIN_ARM_IDENTITY_P0(32); // P1.00 (SWO / TRACEDATA0) + _DEFPIN_ARM_IDENTITY_P0(33); // P1.01 + _DEFPIN_ARM_IDENTITY_P0(34); // P1.02 + _DEFPIN_ARM_IDENTITY_P0(35); // P1.03 + _DEFPIN_ARM_IDENTITY_P0(36); // P1.04 + _DEFPIN_ARM_IDENTITY_P0(37); // P1.05 + _DEFPIN_ARM_IDENTITY_P0(38); // P1.06 + _DEFPIN_ARM_IDENTITY_P0(39); // P1.07 (BUTTON1 option) + _DEFPIN_ARM_IDENTITY_P0(40); // P1.08 (BUTTON2 option) + _DEFPIN_ARM_IDENTITY_P0(41); // P1.09 (TRACEDATA3) + _DEFPIN_ARM_IDENTITY_P0(42); // P1.10 + _DEFPIN_ARM_IDENTITY_P0(43); // P1.11 + _DEFPIN_ARM_IDENTITY_P0(44); // P1.12 + _DEFPIN_ARM_IDENTITY_P0(45); // P1.13 + _DEFPIN_ARM_IDENTITY_P0(46); // P1.14 + _DEFPIN_ARM_IDENTITY_P0(47); // P1.15 + #endif +#endif // defined (ARDUINO_NRF52840_PCA10056) + +// Electronut labs bluey +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/bluey/variant.cpp +#if defined(ARDUINO_ELECTRONUT_BLUEY) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Electronut labs bluey is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + + _DEFPIN_ARM( 0, 0, 26); // D0 is P0.26 + _DEFPIN_ARM( 1, 0, 27); // D1 is P0.27 + _DEFPIN_ARM( 2, 0, 22); // D2 is P0.22 (SPI SS ) + _DEFPIN_ARM( 3, 0, 23); // D3 is P0.23 (SPI MOSI) + _DEFPIN_ARM( 4, 0, 24); // D4 is P0.24 (SPI MISO, also A3) + _DEFPIN_ARM( 5, 0, 25); // D5 is P0.25 (SPI SCK ) + _DEFPIN_ARM( 6, 0, 16); // D6 is P0.16 (Button) + _DEFPIN_ARM( 7, 0, 19); // D7 is P0.19 (R) + _DEFPIN_ARM( 8, 0, 18); // D8 is P0.18 (G) + _DEFPIN_ARM( 9, 0, 17); // D9 is P0.17 (B) + _DEFPIN_ARM(10, 0, 11); // D10 is P0.11 (SCL) + _DEFPIN_ARM(11, 0, 12); // D11 is P0.12 (DRDYn) + _DEFPIN_ARM(12, 0, 13); // D12 is P0.13 (SDA) + _DEFPIN_ARM(13, 0, 14); // D13 is P0.17 (INT) + _DEFPIN_ARM(14, 0, 15); // D14 is P0.15 (INT1) + _DEFPIN_ARM(15, 0, 20); // D15 is P0.20 (INT2) + _DEFPIN_ARM(16, 0, 2); // D16 is P0.02 (A0) + _DEFPIN_ARM(17, 0, 3); // D17 is P0.03 (A1) + _DEFPIN_ARM(18, 0, 4); // D18 is P0.04 (A2) + _DEFPIN_ARM(19, 0, 24); // D19 is P0.24 (A3, also D4/SPI MISO) -- is this right? + _DEFPIN_ARM(20, 0, 29); // D20 is P0.29 (A4) + _DEFPIN_ARM(21, 0, 30); // D21 is P0.30 (A5) + _DEFPIN_ARM(22, 0, 31); // D22 is P0.31 (A6) + _DEFPIN_ARM(23, 0, 8); // D23 is P0.08 (RX) + _DEFPIN_ARM(24, 0, 6); // D24 is P0.06 (TX) + _DEFPIN_ARM(25, 0, 5); // D25 is P0.05 (RTS) + _DEFPIN_ARM(26, 0, 7); // D26 is P0.07 (CTS) +#endif // defined(ARDUINO_ELECTRONUT_BLUEY) + +// Electronut labs hackaBLE +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/hackaBLE/variant.cpp +#if defined(ARDUINO_ELECTRONUT_HACKABLE) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Electronut labs hackaBLE is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + _DEFPIN_ARM( 0, 0, 14); // D0 is P0.14 (RX) + _DEFPIN_ARM( 1, 0, 13); // D1 is P0.13 (TX) + _DEFPIN_ARM( 2, 0, 12); // D2 is P0.12 + _DEFPIN_ARM( 3, 0, 11); // D3 is P0.11 (SPI MOSI) + _DEFPIN_ARM( 4, 0, 8); // D4 is P0.08 (SPI MISO) + _DEFPIN_ARM( 5, 0, 7); // D5 is P0.07 (SPI SCK ) + _DEFPIN_ARM( 6, 0, 6); // D6 is P0.06 + _DEFPIN_ARM( 7, 0, 27); // D7 is P0.27 + _DEFPIN_ARM( 8, 0, 26); // D8 is P0.26 + _DEFPIN_ARM( 9, 0, 25); // D9 is P0.25 + _DEFPIN_ARM(10, 0, 5); // D10 is P0.05 (A3) + _DEFPIN_ARM(11, 0, 4); // D11 is P0.04 (A2) + _DEFPIN_ARM(12, 0, 3); // D12 is P0.03 (A1) + _DEFPIN_ARM(13, 0, 2); // D13 is P0.02 (A0 / AREF) + _DEFPIN_ARM(14, 0, 23); // D14 is P0.23 + _DEFPIN_ARM(15, 0, 22); // D15 is P0.22 + _DEFPIN_ARM(16, 0, 18); // D16 is P0.18 + _DEFPIN_ARM(17, 0, 16); // D17 is P0.16 + _DEFPIN_ARM(18, 0, 15); // D18 is P0.15 + _DEFPIN_ARM(19, 0, 24); // D19 is P0.24 + _DEFPIN_ARM(20, 0, 28); // D20 is P0.28 (A4) + _DEFPIN_ARM(21, 0, 29); // D21 is P0.29 (A5) + _DEFPIN_ARM(22, 0, 30); // D22 is P0.30 (A6) + _DEFPIN_ARM(23, 0, 31); // D23 is P0.31 (A7) + _DEFPIN_ARM(24, 0, 19); // D24 is P0.19 (RED LED) + _DEFPIN_ARM(25, 0, 20); // D25 is P0.20 (GREEN LED) + _DEFPIN_ARM(26, 0, 17); // D26 is P0.17 (BLUE LED) +#endif // defined(ARDUINO_ELECTRONUT_HACKABLE) + +// Electronut labs hackaBLE_v2 +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/hackaBLE_v2/variant.cpp +// (32 pins, natural mapping) +#if defined(ARDUINO_ELECTRONUT_hackaBLE_v2) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Electronut labs hackaBLE_v2 is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + _DEFPIN_ARM_IDENTITY_P0( 0); // P0.00 + _DEFPIN_ARM_IDENTITY_P0( 1); // P0.01 + _DEFPIN_ARM_IDENTITY_P0( 2); // P0.02 (A0 / SDA / AREF) + _DEFPIN_ARM_IDENTITY_P0( 3); // P0.03 (A1 / SCL ) + _DEFPIN_ARM_IDENTITY_P0( 4); // P0.04 (A2) + _DEFPIN_ARM_IDENTITY_P0( 5); // P0.05 (A3) + _DEFPIN_ARM_IDENTITY_P0( 6); // P0.06 + _DEFPIN_ARM_IDENTITY_P0( 7); // P0.07 (RX) + _DEFPIN_ARM_IDENTITY_P0( 8); // P0.08 (TX) + _DEFPIN_ARM_IDENTITY_P0( 9); // P0.09 + _DEFPIN_ARM_IDENTITY_P0(10); // P0.10 + _DEFPIN_ARM_IDENTITY_P0(11); // P0.11 (SPI MISO) + _DEFPIN_ARM_IDENTITY_P0(12); // P0.12 (SPI MOSI) + _DEFPIN_ARM_IDENTITY_P0(13); // P0.13 (SPI SCK ) + _DEFPIN_ARM_IDENTITY_P0(14); // P0.14 (SPI SS ) + _DEFPIN_ARM_IDENTITY_P0(15); // P0.15 + _DEFPIN_ARM_IDENTITY_P0(16); // P0.16 + _DEFPIN_ARM_IDENTITY_P0(17); // P0.17 (BLUE LED) + _DEFPIN_ARM_IDENTITY_P0(18); // P0.18 + _DEFPIN_ARM_IDENTITY_P0(19); // P0.19 (RED LED) + _DEFPIN_ARM_IDENTITY_P0(20); // P0.20 (GREEN LED) + // _DEFPIN_ARM_IDENTITY_P0(21); // P0.21 (RESET) + _DEFPIN_ARM_IDENTITY_P0(22); // P0.22 + _DEFPIN_ARM_IDENTITY_P0(23); // P0.23 + _DEFPIN_ARM_IDENTITY_P0(24); // P0.24 + _DEFPIN_ARM_IDENTITY_P0(25); // P0.25 + _DEFPIN_ARM_IDENTITY_P0(26); // P0.26 + _DEFPIN_ARM_IDENTITY_P0(27); // P0.27 + _DEFPIN_ARM_IDENTITY_P0(28); // P0.28 (A4) + _DEFPIN_ARM_IDENTITY_P0(29); // P0.29 (A5) + _DEFPIN_ARM_IDENTITY_P0(30); // P0.30 (A6) + _DEFPIN_ARM_IDENTITY_P0(31); // P0.31 (A7) +#endif // defined(ARDUINO_ELECTRONUT_hackaBLE_v2) + +// RedBear Blend 2 +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/RedBear_Blend2/variant.cpp +#if defined(ARDUINO_RB_BLEND_2) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "RedBear Blend 2 is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + _DEFPIN_ARM( 0, 0, 11); // D0 is P0.11 + _DEFPIN_ARM( 1, 0, 12); // D1 is P0.12 + _DEFPIN_ARM( 2, 0, 13); // D2 is P0.13 + _DEFPIN_ARM( 3, 0, 14); // D3 is P0.14 + _DEFPIN_ARM( 4, 0, 15); // D4 is P0.15 + _DEFPIN_ARM( 5, 0, 16); // D5 is P0.16 + _DEFPIN_ARM( 6, 0, 17); // D6 is P0.17 + _DEFPIN_ARM( 7, 0, 18); // D7 is P0.18 + _DEFPIN_ARM( 8, 0, 19); // D8 is P0.19 + _DEFPIN_ARM( 9, 0, 20); // D9 is P0.20 + _DEFPIN_ARM(10, 0, 22); // D10 is P0.22 (SPI SS ) + _DEFPIN_ARM(11, 0, 23); // D11 is P0.23 (SPI MOSI) + _DEFPIN_ARM(12, 0, 24); // D12 is P0.24 (SPI MISO) + _DEFPIN_ARM(13, 0, 25); // D13 is P0.25 (SPI SCK / LED) + _DEFPIN_ARM(14, 0, 3); // D14 is P0.03 (A0) + _DEFPIN_ARM(15, 0, 4); // D15 is P0.04 (A1) + _DEFPIN_ARM(16, 0, 28); // D16 is P0.28 (A2) + _DEFPIN_ARM(17, 0, 29); // D17 is P0.29 (A3) + _DEFPIN_ARM(18, 0, 30); // D18 is P0.30 (A4) + _DEFPIN_ARM(19, 0, 31); // D19 is P0.31 (A5) + _DEFPIN_ARM(20, 0, 26); // D20 is P0.26 (SDA) + _DEFPIN_ARM(21, 0, 27); // D21 is P0.27 (SCL) + _DEFPIN_ARM(22, 0, 8); // D22 is P0.08 (RX) + _DEFPIN_ARM(23, 0, 6); // D23 is P0.06 (TX) + _DEFPIN_ARM(24, 0, 2); // D24 is P0.02 (AREF) +#endif // defined(ARDUINO_RB_BLEND_2) + +// RedBear BLE Nano 2 +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/RedBear_BLENano2/variant.cpp +#if defined(ARDUINO_RB_BLE_NANO_2) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "RedBear BLE Nano 2 is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + _DEFPIN_ARM( 0, 0, 30); // D0 is P0.30 (A0 / RX) + _DEFPIN_ARM( 1, 0, 29); // D1 is P0.29 (A1 / TX) + _DEFPIN_ARM( 2, 0, 28); // D2 is P0.28 (A2 / SDA) + _DEFPIN_ARM( 3, 0, 2); // D3 is P0.02 (A3 / SCL) + _DEFPIN_ARM( 4, 0, 5); // D4 is P0.05 (A4) + _DEFPIN_ARM( 5, 0, 4); // D5 is P0.04 (A5) + _DEFPIN_ARM( 6, 0, 3); // D6 is P0.03 (SPI SS ) + _DEFPIN_ARM( 7, 0, 6); // D7 is P0.06 (SPI MOSI) + _DEFPIN_ARM( 8, 0, 7); // D8 is P0.07 (SPI MISO) + _DEFPIN_ARM( 9, 0, 8); // D9 is P0.08 (SPI SCK ) + // _DEFPIN_ARM(10, 0, 21); // D10 is P0.21 (RESET) + _DEFPIN_ARM(13, 0, 11); // D11 is P0.11 (LED) +#endif // defined(ARDUINO_RB_BLE_NANO_2) + +// Nordic Semiconductor nRF52 DK +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/nRF52DK/variant.cpp +#if defined(ARDUINO_NRF52_DK) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Nordic Semiconductor nRF52 DK is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + _DEFPIN_ARM( 0, 0, 11); // D0 is P0.11 + _DEFPIN_ARM( 1, 0, 12); // D1 is P0.12 + _DEFPIN_ARM( 2, 0, 13); // D2 is P0.13 (BUTTON1) + _DEFPIN_ARM( 3, 0, 14); // D3 is P0.14 (BUTTON2) + _DEFPIN_ARM( 4, 0, 15); // D4 is P0.15 (BUTTON3) + _DEFPIN_ARM( 5, 0, 16); // D5 is P0.16 (BUTTON4) + _DEFPIN_ARM( 6, 0, 17); // D6 is P0.17 (LED1) + _DEFPIN_ARM( 7, 0, 18); // D7 is P0.18 (LED2) + _DEFPIN_ARM( 8, 0, 19); // D8 is P0.19 (LED3) + _DEFPIN_ARM( 9, 0, 20); // D9 is P0.20 (LED4) + _DEFPIN_ARM(10, 0, 22); // D10 is P0.22 (SPI SS ) + _DEFPIN_ARM(11, 0, 23); // D11 is P0.23 (SPI MOSI) + _DEFPIN_ARM(12, 0, 24); // D12 is P0.24 (SPI MISO) + _DEFPIN_ARM(13, 0, 25); // D13 is P0.25 (SPI SCK / LED) + _DEFPIN_ARM(14, 0, 3); // D14 is P0.03 (A0) + _DEFPIN_ARM(15, 0, 4); // D15 is P0.04 (A1) + _DEFPIN_ARM(16, 0, 28); // D16 is P0.28 (A2) + _DEFPIN_ARM(17, 0, 29); // D17 is P0.29 (A3) + _DEFPIN_ARM(18, 0, 30); // D18 is P0.30 (A4) + _DEFPIN_ARM(19, 0, 31); // D19 is P0.31 (A5) + _DEFPIN_ARM(20, 0, 5); // D20 is P0.05 (A6) + _DEFPIN_ARM(21, 0, 2); // D21 is P0.02 (A7 / AREF) + _DEFPIN_ARM(22, 0, 26); // D22 is P0.26 (SDA) + _DEFPIN_ARM(23, 0, 27); // D23 is P0.27 (SCL) + _DEFPIN_ARM(24, 0, 8); // D24 is P0.08 (RX) + _DEFPIN_ARM(25, 0, 6); // D25 is P0.06 (TX) +#endif // defined(ARDUINO_NRF52_DK) + +// Taida Century nRF52 mini board +// https://github.com/sandeepmistry/arduino-nRF5/blob/master/variants/Taida_Century_nRF52_minidev/variant.cpp +#if defined(ARDUINO_STCT_NRF52_minidev) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Taida Century nRF52 mini board is an untested board -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + //_DEFPIN_ARM( 0, 0, 25); // D0 is P0.xx (near radio!) + //_DEFPIN_ARM( 1, 0, 26); // D1 is P0.xx (near radio!) + //_DEFPIN_ARM( 2, 0, 27); // D2 is P0.xx (near radio!) + //_DEFPIN_ARM( 3, 0, 28); // D3 is P0.xx (near radio!) + //_DEFPIN_ARM( 4, 0, 29); // D4 is P0.xx (Not connected, near radio!) + //_DEFPIN_ARM( 5, 0, 30); // D5 is P0.xx (LED1, near radio!) + //_DEFPIN_ARM( 6, 0, 31); // D6 is P0.xx (LED2, near radio!) + _DEFPIN_ARM( 7, 0, 2); // D7 is P0.xx (SDA) + _DEFPIN_ARM( 8, 0, 3); // D8 is P0.xx (SCL) + _DEFPIN_ARM( 9, 0, 4); // D9 is P0.xx (BUTTON1 / NFC1) + _DEFPIN_ARM(10, 0, 5); // D10 is P0.xx + //_DEFPIN_ARM(11, 0, 0); // D11 is P0.xx (Not connected) + //_DEFPIN_ARM(12, 0, 1); // D12 is P0.xx (Not connected) + _DEFPIN_ARM(13, 0, 6); // D13 is P0.xx + _DEFPIN_ARM(14, 0, 7); // D14 is P0.xx + _DEFPIN_ARM(15, 0, 8); // D15 is P0.xx + //_DEFPIN_ARM(16, 0, 9); // D16 is P0.xx (Not connected) + //_DEFPIN_ARM(17, 0, 10); // D17 is P0.xx (NFC2, Not connected) + _DEFPIN_ARM(18, 0, 11); // D18 is P0.xx (RXD) + _DEFPIN_ARM(19, 0, 12); // D19 is P0.xx (TXD) + _DEFPIN_ARM(20, 0, 13); // D20 is P0.xx (SPI SS ) + _DEFPIN_ARM(21, 0, 14); // D21 is P0.xx (SPI MISO) + _DEFPIN_ARM(22, 0, 15); // D22 is P0.xx (SPI MOSI) + _DEFPIN_ARM(23, 0, 16); // D23 is P0.xx (SPI SCK ) + _DEFPIN_ARM(24, 0, 17); // D24 is P0.xx (A0) + _DEFPIN_ARM(25, 0, 18); // D25 is P0.xx (A1) + _DEFPIN_ARM(26, 0, 19); // D26 is P0.xx (A2) + _DEFPIN_ARM(27, 0, 20); // D27 is P0.xx (A3) + //_DEFPIN_ARM(28, 0, 22); // D28 is P0.xx (A4, near radio!) + //_DEFPIN_ARM(29, 0, 23); // D29 is P0.xx (A5, near radio!) + _DEFPIN_ARM(30, 0, 24); // D30 is P0.xx + // _DEFPIN_ARM(31, 0, 21); // D31 is P0.21 (RESET) +#endif // defined(ARDUINO_STCT_NRF52_minidev) + +// Generic nRF52832 +// See https://github.com/sandeepmistry/arduino-nRF5/blob/master/boards.txt +#if defined(ARDUINO_GENERIC) && (\ + defined(NRF52832_XXAA) || defined(NRF52832_XXAB)\ + ) + #if defined(__FASTPIN_ARM_NRF52_VARIANT_FOUND) + #error "Cannot define more than one board at a time" + #else + #define __FASTPIN_ARM_NRF52_VARIANT_FOUND + #endif + #warning "Using `generic` NRF52832 board is an untested configuration -- test and let use know your results via https://github.com/FastLED/FastLED/issues" + + _DEFPIN_ARM_IDENTITY_P0( 0); // P0.00 ( UART RX + _DEFPIN_ARM_IDENTITY_P0( 1); // P0.01 (A0, UART TX) + _DEFPIN_ARM_IDENTITY_P0( 2); // P0.02 (A1) + _DEFPIN_ARM_IDENTITY_P0( 3); // P0.03 (A2) + _DEFPIN_ARM_IDENTITY_P0( 4); // P0.04 (A3) + _DEFPIN_ARM_IDENTITY_P0( 5); // P0.05 (A4) + _DEFPIN_ARM_IDENTITY_P0( 6); // P0.06 (A5) + _DEFPIN_ARM_IDENTITY_P0( 7); // P0.07 + _DEFPIN_ARM_IDENTITY_P0( 8); // P0.08 + _DEFPIN_ARM_IDENTITY_P0( 9); // P0.09 + _DEFPIN_ARM_IDENTITY_P0(10); // P0.10 + _DEFPIN_ARM_IDENTITY_P0(11); // P0.11 + _DEFPIN_ARM_IDENTITY_P0(12); // P0.12 + _DEFPIN_ARM_IDENTITY_P0(13); // P0.13 (LED) + _DEFPIN_ARM_IDENTITY_P0(14); // P0.14 + _DEFPIN_ARM_IDENTITY_P0(15); // P0.15 + _DEFPIN_ARM_IDENTITY_P0(16); // P0.16 + _DEFPIN_ARM_IDENTITY_P0(17); // P0.17 + _DEFPIN_ARM_IDENTITY_P0(18); // P0.18 + _DEFPIN_ARM_IDENTITY_P0(19); // P0.19 + _DEFPIN_ARM_IDENTITY_P0(20); // P0.20 (I2C SDA) + _DEFPIN_ARM_IDENTITY_P0(21); // P0.21 (I2C SCL) + _DEFPIN_ARM_IDENTITY_P0(22); // P0.22 (SPI MISO) + _DEFPIN_ARM_IDENTITY_P0(23); // P0.23 (SPI MOSI) + _DEFPIN_ARM_IDENTITY_P0(24); // P0.24 (SPI SCK ) + _DEFPIN_ARM_IDENTITY_P0(25); // P0.25 (SPI SS ) + _DEFPIN_ARM_IDENTITY_P0(26); // P0.26 + _DEFPIN_ARM_IDENTITY_P0(27); // P0.27 + _DEFPIN_ARM_IDENTITY_P0(28); // P0.28 + _DEFPIN_ARM_IDENTITY_P0(29); // P0.29 + _DEFPIN_ARM_IDENTITY_P0(30); // P0.30 + _DEFPIN_ARM_IDENTITY_P0(31); // P0.31 +#endif // defined(ARDUINO_GENERIC) + + +#endif // __FASTPIN_ARM_NRF52_VARIANTS_H \ No newline at end of file diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastspi_arm_nrf52.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastspi_arm_nrf52.h new file mode 100644 index 0000000..8492282 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/fastspi_arm_nrf52.h @@ -0,0 +1,341 @@ +#ifndef __FASTSPI_ARM_NRF52_H +#define __FASTSPI_ARM_NRF52_H + + +#ifndef FASTLED_FORCE_SOFTWARE_SPI + + #include + + #define FASTLED_ALL_PINS_HARDWARE_SPI + + + // NRF52810 has SPIM0: Frequencies from 125kbps to 8Mbps + // NRF52832 adds SPIM1, SPIM2 (same frequencies) + // NRF52840 adds SPIM3 (same frequencies), adds SPIM3 that can be @ up to 32Mbps frequency(!) + #if !defined(FASTLED_NRF52_SPIM) + #define FASTLED_NRF52_SPIM NRF_SPIM0 + #endif + + /* This class is slightly simpler than fastpin, as it can rely on fastpin + * to handle the mapping to the underlying PN.XX board-level pins... + */ + + /// SPI_CLOCK_DIVIDER is number of CPU clock cycles per SPI transmission bit? + template + class NRF52SPIOutput { + + private: + // static variables -- always using same SPIM instance + static bool s_InUse; + static bool s_NeedToWait; // a data transfer was started, and completion event was not cleared. + + /* + // TODO -- Workaround nRF52840 errata #198, which relates to + // contention between SPIM3 and CPU over AHB. + // The workaround is to ensure the SPIM TX buffer + // is on a different / dedicated RAM block. + // This also avoids AHB contention generally, so + // should be applied to all supported boards. + // + // But... how to allocate m_Buffer[] to be at a + // specific memory range? Also, might need to + // avoid use of single-transaction writeBytes() + // as cannot control where that memory lies.... + */ + static uint8_t s_BufferIndex; + static uint8_t s_Buffer[2][2]; // 2x two-byte buffers, allows one buffer currently being sent, and a second one being prepped to send. + + // This allows saving the configuration of the SPIM instance + // upon select(), and restoring the configuration upon release(). + struct spim_config { + uint32_t inten; + uint32_t shorts; + uint32_t sck_pin; + uint32_t mosi_pin; + uint32_t miso_pin; + uint32_t frequency; + // data pointers, RX/TX counts not saved as would only hide bugs + uint32_t config; // mode & bit order + uint32_t orc; + +#if false // additional configuration to save/restore for SPIM3 + uint32_t csn_pin; + uint32_t csn_polarity; // CSNPOL + uint32_t csn_duration; // IFTIMING.CSNDUR + uint32_t rx_delay; // IFTIMING.RXDELAY + uint32_t dcx_pin; // PSELDCX + uint32_t dcx_config; // DCXCNT +#endif + + } m_SpiSavedConfig; + void saveSpimConfig() { + m_SpiSavedConfig.inten = FASTLED_NRF52_SPIM->INTENSET; + m_SpiSavedConfig.shorts = FASTLED_NRF52_SPIM->SHORTS; + m_SpiSavedConfig.sck_pin = FASTLED_NRF52_SPIM->PSEL.SCK; + m_SpiSavedConfig.mosi_pin = FASTLED_NRF52_SPIM->PSEL.MOSI; + m_SpiSavedConfig.miso_pin = FASTLED_NRF52_SPIM->PSEL.MISO; + m_SpiSavedConfig.frequency = FASTLED_NRF52_SPIM->FREQUENCY; + m_SpiSavedConfig.config = FASTLED_NRF52_SPIM->CONFIG; + m_SpiSavedConfig.orc = FASTLED_NRF52_SPIM->ORC; + +#if false // additional configuration to save/restore for SPIM3 + m_SpiSavedConfig.csn_pin = FASTLED_NRF52_SPIM->PSEL.CSN; + m_SpiSavedConfig.csn_polarity = FASTLED_NRF52_SPIM->CSNPOL; + m_SpiSavedConfig.csn_duration = FASTLED_NRF52_SPIM->IFTIMING.CSNDUR; + m_SpiSavedConfig.dcx_pin = FASTLED_NRF52_SPIM->PSELDCX; + m_SpiSavedConfig.dcx_config = FASTLED_NRF52_SPIM->DCXCNT; +#endif + } + void restoreSpimConfig() { + // 0. ASSERT() the SPIM instance is not enabled + + FASTLED_NRF52_SPIM->INTENCLR = 0xFFFFFFFF; + FASTLED_NRF52_SPIM->INTENSET = m_SpiSavedConfig.inten; + FASTLED_NRF52_SPIM->SHORTS = m_SpiSavedConfig.shorts; + FASTLED_NRF52_SPIM->PSEL.SCK = m_SpiSavedConfig.sck_pin; + FASTLED_NRF52_SPIM->PSEL.MOSI = m_SpiSavedConfig.mosi_pin; + FASTLED_NRF52_SPIM->PSEL.MISO = m_SpiSavedConfig.miso_pin; + FASTLED_NRF52_SPIM->FREQUENCY = m_SpiSavedConfig.frequency; + FASTLED_NRF52_SPIM->CONFIG = m_SpiSavedConfig.config; + FASTLED_NRF52_SPIM->ORC = m_SpiSavedConfig.orc; + +#if false // additional configuration to save/restore for SPIM3 + FASTLED_NRF52_SPIM->PSEL.CSN = m_SpiSavedConfig.csn_pin; + FASTLED_NRF52_SPIM->CSNPOL = m_SpiSavedConfig.csn_polarity; + FASTLED_NRF52_SPIM->IFTIMING.CSNDUR = m_SpiSavedConfig.csn_duration; + FASTLED_NRF52_SPIM->PSELDCX = m_SpiSavedConfig.dcx_pin; + FASTLED_NRF52_SPIM->DCXCNT = m_SpiSavedConfig.dcx_config; +#endif + } + + public: + NRF52SPIOutput() {} + + // Low frequency GPIO is for signals with a frequency up to 10 kHz. Lowest speed SPIM is 125kbps. + static_assert(!FastPin<_DATA_PIN>::LowSpeedOnlyRecommended(), "Invalid (low-speed only) pin specified"); + static_assert(!FastPin<_CLOCK_PIN>::LowSpeedOnlyRecommended(), "Invalid (low-speed only) pin specified"); + + /// initialize the SPI subssytem + void init() { + // 0. ASSERT() the SPIM instance is not enabled / in use + //ASSERT(m_SPIM->ENABLE != (SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos)); + + // 1. set pins to output/H0H1 drive/etc. + FastPin<_DATA_PIN>::setOutput(); + FastPin<_CLOCK_PIN>::setOutput(); + + // 2. Configure SPIMx + nrf_spim_configure( + FASTLED_NRF52_SPIM, + NRF_SPIM_MODE_0, + NRF_SPIM_BIT_ORDER_MSB_FIRST + ); + nrf_spim_frequency_set( + FASTLED_NRF52_SPIM, + NRF_SPIM_FREQ_4M // BUGBUG -- use _SPI_CLOCK_DIVIDER to determine frequency + ); + nrf_spim_pins_set( + FASTLED_NRF52_SPIM, + FastPin<_CLOCK_PIN>::nrf_pin(), + FastPin<_DATA_PIN>::nrf_pin(), + NRF_SPIM_PIN_NOT_CONNECTED + ); + + // 4. Ensure events are cleared + nrf_spim_event_clear(FASTLED_NRF52_SPIM, NRF_SPIM_EVENT_END); + nrf_spim_event_clear(FASTLED_NRF52_SPIM, NRF_SPIM_EVENT_STARTED); + + // 5. Enable the SPIM instance + nrf_spim_enable(FASTLED_NRF52_SPIM); + } + + /// latch the CS select + void select() { + //ASSERT(!s_InUse); + saveSpimConfig(); + s_InUse = true; + init(); + } + + /// release the CS select + void release() { + //ASSERT(s_InUse); + waitFully(); + s_InUse = false; + restoreSpimConfig(); + } + + /// wait until all queued up data has been written + static void waitFully() { + if (!s_NeedToWait) return; + // else, need to wait for END event + while(!FASTLED_NRF52_SPIM->EVENTS_END) {}; + s_NeedToWait = 0; + // only use two events in this code... + nrf_spim_event_clear(FASTLED_NRF52_SPIM, NRF_SPIM_EVENT_END); + nrf_spim_event_clear(FASTLED_NRF52_SPIM, NRF_SPIM_EVENT_STARTED); + return; + } + // wait only until we can add a new transaction into the registers + // (caller must still waitFully() before actually starting this next transaction) + static void wait() { + if (!s_NeedToWait) return; + while (!FASTLED_NRF52_SPIM->EVENTS_STARTED) {}; + // leave the event set here... caller must waitFully() and start next transaction + return; + } + + /// write a byte out via SPI (returns immediately on writing register) + static void writeByte(uint8_t b) { + wait(); + // cannot use pointer to stack, so copy to m_buffer[] + uint8_t i = (s_BufferIndex ? 1u : 0u); + s_BufferIndex = !s_BufferIndex; // 1 <==> 0 swap + + s_Buffer[i][0u] = b; // cannot use the stack location, so copy to a more permanent buffer... + nrf_spim_tx_buffer_set( + FASTLED_NRF52_SPIM, + &(s_Buffer[i][0u]), + 1 + ); + + waitFully(); + nrf_spim_task_trigger( + FASTLED_NRF52_SPIM, + NRF_SPIM_TASK_START + ); + return; + } + + /// write a word out via SPI (returns immediately on writing register) + static void writeWord(uint16_t w) { + wait(); + // cannot use pointer to stack, so copy to m_buffer[] + uint8_t i = (s_BufferIndex ? 1u : 0u); + s_BufferIndex = !s_BufferIndex; // 1 <==> 0 swap + + s_Buffer[i][0u] = (w >> 8u); // cannot use the stack location, so copy to a more permanent buffer... + s_Buffer[i][1u] = (w & 0xFFu); // cannot use the stack location, so copy to a more permanent buffer... + nrf_spim_tx_buffer_set( + FASTLED_NRF52_SPIM, + &(s_Buffer[i][0u]), + 2 + ); + + waitFully(); + nrf_spim_task_trigger( + FASTLED_NRF52_SPIM, + NRF_SPIM_TASK_START + ); + return; + } + + /// A raw set of writing byte values, assumes setup/init/waiting done elsewhere (static for use by adjustment classes) + static void writeBytesValueRaw(uint8_t value, int len) { + while (len--) { writeByte(value); } + } + + /// A full cycle of writing a value for len bytes, including select, release, and waiting + void writeBytesValue(uint8_t value, int len) { + select(); + writeBytesValueRaw(value, len); + waitFully(); + release(); + } + + /// A full cycle of writing a raw block of data out, including select, release, and waiting + void writeBytes(uint8_t *data, int len) { + // This is a special-case, with no adjustment of the bytes... write them directly... + select(); + wait(); + nrf_spim_tx_buffer_set( + FASTLED_NRF52_SPIM, + data, + len + ); + waitFully(); + nrf_spim_task_trigger( + FASTLED_NRF52_SPIM, + NRF_SPIM_TASK_START + ); + waitFully(); + release(); + } + + /// A full cycle of writing a raw block of data out, including select, release, and waiting + template void writeBytes(uint8_t *data, int len) { + uint8_t * end = data + len; + select(); + wait(); + while(data != end) { + writeByte(D::adjust(*data++)); + } + D::postBlock(len); + waitFully(); + release(); + } + /// specialization for DATA_NOP ... + //template void writeBytes(uint8_t * data, int len) { + // writeBytes(data, len); + //} + + /// write a single bit out, which bit from the passed in byte is determined by template parameter + template inline static void writeBit(uint8_t b) { + // SPIM instance must be finished transmitting and then disabled + waitFully(); + nrf_spim_disable(FASTLED_NRF52_SPIM); + // set the data pin to appropriate state + if (b & (1 << BIT)) { + FastPin<_DATA_PIN>::hi(); + } else { + FastPin<_DATA_PIN>::lo(); + } + // delay 1/2 cycle per SPI bit + delaycycles<_SPI_CLOCK_DIVIDER/2>(); + FastPin<_CLOCK_PIN>::toggle(); + delaycycles<_SPI_CLOCK_DIVIDER/2>(); + FastPin<_CLOCK_PIN>::toggle(); + // re-enable the SPIM instance + nrf_spim_enable(FASTLED_NRF52_SPIM); + } + + /// write out pixel data from the given PixelController object, including select, release, and waiting + template void writePixels(PixelController pixels) { + select(); + int len = pixels.mLen; + // TODO: If user indicates a pre-allocated double-buffer, + // then process all the pixels at once into that buffer, + // then use the non-templated WriteBytes(data, len) function + // to write the entire buffer as a single SPI transaction. + while (pixels.has(1)) { + if (FLAGS & FLAG_START_BIT) { + writeBit<0>(1); + } + writeByte(D::adjust(pixels.loadAndScale0())); + writeByte(D::adjust(pixels.loadAndScale1())); + writeByte(D::adjust(pixels.loadAndScale2())); + pixels.advanceData(); + pixels.stepDithering(); + } + D::postBlock(len); + waitFully(); + release(); + } + }; + + // Static member definition and initialization using templates. + // see https://stackoverflow.com/questions/3229883/static-member-initialization-in-a-class-template#answer-3229919 + template + bool NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER>::s_InUse = false; + template + bool NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER>::s_NeedToWait = false; + template + uint8_t NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER>::s_BufferIndex = 0; + template + uint8_t NRF52SPIOutput<_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER>::s_Buffer[2][2] = {{0,0},{0,0}}; + +#endif // #ifndef FASTLED_FORCE_SOFTWARE_SPI + + + +#endif // #ifndef __FASTPIN_ARM_NRF52_H diff --git a/libraries/FastLED-3.2.9/platforms/arm/nrf52/led_sysdefs_arm_nrf52.h b/libraries/FastLED-3.2.9/platforms/arm/nrf52/led_sysdefs_arm_nrf52.h new file mode 100644 index 0000000..440aed9 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/nrf52/led_sysdefs_arm_nrf52.h @@ -0,0 +1,58 @@ +#ifndef __LED_SYSDEFS_ARM_NRF52 +#define __LED_SYSDEFS_ARM_NRF52 + +#define FASTLED_ARM + +#ifndef F_CPU + #define F_CPU 64000000 // the NRF52 series has a 64MHz CPU +#endif + +// even though CPU is at 64MHz, use the 8MHz-defined timings because... +// PWM module runs at 16MHz +// SPI0..2 runs at 8MHz +#define CLOCKLESS_FREQUENCY 16000000 // the NRF52 has EasyDMA for PWM module at 16MHz + +#ifndef F_TIMER + #define F_TIMER 16000000 // the NRF52 timer is 16MHz, even though CPU is 64MHz +#endif + +#if !defined(FASTLED_USE_PROGMEM) + #define FASTLED_USE_PROGMEM 0 // nRF52 series have flat memory model +#endif + +#if !defined(FASTLED_ALLOW_INTERRUPTS) + #define FASTLED_ALLOW_INTERRUPTS 1 +#endif + +// Use PWM instance 0 +// See clockless_arm_nrf52.h and (in root of library) platforms.cpp +#define FASTLED_NRF52_ENABLE_PWM_INSTANCE0 + +#if defined(FASTLED_NRF52_NEVER_INLINE) + #define FASTLED_NRF52_INLINE_ATTRIBUTE __attribute__((always_inline)) inline +#else + #define FASTLED_NRF52_INLINE_ATTRIBUTE __attribute__((always_inline)) inline +#endif + + + +#include +#include // for FastSPI +#include // for Clockless +#include // for Clockless / anything else using interrupts +typedef __I uint32_t RoReg; +typedef __IO uint32_t RwReg; + +#define cli() __disable_irq() +#define sei() __enable_irq() + +#define FASTLED_NRF52_DEBUGPRINT(format, ...) +//#define FASTLED_NRF52_DEBUGPRINT(format, ...)\ +// do {\ +// FastLED_NRF52_DebugPrint(format, ##__VA_ARGS__);\ +// } while(0); + + + + +#endif // __LED_SYSDEFS_ARM_NRF52 diff --git a/libraries/FastLED-3.2.0/platforms/arm/sam/clockless_arm_sam.h b/libraries/FastLED-3.2.9/platforms/arm/sam/clockless_arm_sam.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/sam/clockless_arm_sam.h rename to libraries/FastLED-3.2.9/platforms/arm/sam/clockless_arm_sam.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/sam/clockless_block_arm_sam.h b/libraries/FastLED-3.2.9/platforms/arm/sam/clockless_block_arm_sam.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/sam/clockless_block_arm_sam.h rename to libraries/FastLED-3.2.9/platforms/arm/sam/clockless_block_arm_sam.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/sam/fastled_arm_sam.h b/libraries/FastLED-3.2.9/platforms/arm/sam/fastled_arm_sam.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/sam/fastled_arm_sam.h rename to libraries/FastLED-3.2.9/platforms/arm/sam/fastled_arm_sam.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/sam/fastpin_arm_sam.h b/libraries/FastLED-3.2.9/platforms/arm/sam/fastpin_arm_sam.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/sam/fastpin_arm_sam.h rename to libraries/FastLED-3.2.9/platforms/arm/sam/fastpin_arm_sam.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/sam/fastspi_arm_sam.h b/libraries/FastLED-3.2.9/platforms/arm/sam/fastspi_arm_sam.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/sam/fastspi_arm_sam.h rename to libraries/FastLED-3.2.9/platforms/arm/sam/fastspi_arm_sam.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/sam/led_sysdefs_arm_sam.h b/libraries/FastLED-3.2.9/platforms/arm/sam/led_sysdefs_arm_sam.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/sam/led_sysdefs_arm_sam.h rename to libraries/FastLED-3.2.9/platforms/arm/sam/led_sysdefs_arm_sam.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/stm32/clockless_arm_stm32.h b/libraries/FastLED-3.2.9/platforms/arm/stm32/clockless_arm_stm32.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/stm32/clockless_arm_stm32.h rename to libraries/FastLED-3.2.9/platforms/arm/stm32/clockless_arm_stm32.h diff --git a/libraries/FastLED-3.2.9/platforms/arm/stm32/cm3_regs.h b/libraries/FastLED-3.2.9/platforms/arm/stm32/cm3_regs.h new file mode 100644 index 0000000..f81f24c --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/arm/stm32/cm3_regs.h @@ -0,0 +1,63 @@ +#ifndef __CM3_REGS +#define __CM3_REGS + +#include + +#ifdef __cplusplus + #define __I volatile /*!< Defines 'read only' permissions */ +#else + #define __I volatile const /*!< Defines 'read only' permissions */ +#endif +#define __O volatile /*!< Defines 'write only' permissions */ +#define __IO volatile /*!< Defines 'read / write' permissions */ + + +typedef struct +{ + __IO uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __O uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IO uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IO uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ +} CoreDebug_Type; + +#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ +#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ + +#define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ + +typedef struct +{ + __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + __IO uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ + __IO uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ + __IO uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ + __IO uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ + __IO uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ + __IO uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ + __I uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ + __IO uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ + __IO uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ + __IO uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ + uint32_t RESERVED0[1]; + __IO uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ + __IO uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ + __IO uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ + uint32_t RESERVED1[1]; + __IO uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ + __IO uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ + __IO uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ + uint32_t RESERVED2[1]; + __IO uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ + __IO uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ + __IO uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ +} DWT_Type; + + +#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ +#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ + +#define DWT_CTRL_CYCCNTENA_Pos 0 /*!< DWT CTRL: CYCCNTENA Position */ +#define DWT_CTRL_CYCCNTENA_Msk (0x1UL << DWT_CTRL_CYCCNTENA_Pos) /*!< DWT CTRL: CYCCNTENA Mask */ + +#endif // __CM3_REGS diff --git a/libraries/FastLED-3.2.0/platforms/arm/stm32/fastled_arm_stm32.h b/libraries/FastLED-3.2.9/platforms/arm/stm32/fastled_arm_stm32.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/arm/stm32/fastled_arm_stm32.h rename to libraries/FastLED-3.2.9/platforms/arm/stm32/fastled_arm_stm32.h diff --git a/libraries/FastLED-3.2.0/platforms/arm/stm32/fastpin_arm_stm32.h b/libraries/FastLED-3.2.9/platforms/arm/stm32/fastpin_arm_stm32.h similarity index 71% rename from libraries/FastLED-3.2.0/platforms/arm/stm32/fastpin_arm_stm32.h rename to libraries/FastLED-3.2.9/platforms/arm/stm32/fastpin_arm_stm32.h index 63729bb..57309cd 100644 --- a/libraries/FastLED-3.2.0/platforms/arm/stm32/fastpin_arm_stm32.h +++ b/libraries/FastLED-3.2.9/platforms/arm/stm32/fastpin_arm_stm32.h @@ -55,15 +55,21 @@ public: inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; } }; +#if defined(STM32F10X_MD) + #define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline volatile GPIO_TypeDef * r() { return T; } }; + #define _IO32(L) _RD32(GPIO ## L) +#elif defined(__STM32F1__) + #define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline gpio_reg_map* r() { return T->regs; } }; + #define _IO32(L) _RD32(GPIO ## L) +#else + #error "Platform not supported" +#endif + #define _R(T) struct __gen_struct_ ## T -#define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline volatile GPIO_TypeDef * r() { return T; } }; - -#define _IO32(L) _RD32(GPIO ## L) - #define _DEFPIN_ARM(PIN, BIT, L) template<> class FastPin : public _ARMPIN {}; // Actual pin definitions -#if defined(SPARK) +#if defined(SPARK) // Sparkfun STM32F103 based board _IO32(A); _IO32(B); _IO32(C); _IO32(D); _IO32(E); _IO32(F); _IO32(G); @@ -96,7 +102,54 @@ _DEFPIN_ARM(19, 2, A); #define HAS_HARDWARE_PIN_SUPPORT -#endif +#endif // SPARK + +#if defined(__STM32F1__) // Generic STM32F103 aka "Blue Pill" + +_IO32(A); _IO32(B); _IO32(C); + +#define MAX_PIN 46 + +_DEFPIN_ARM(10, 0, A); // PA0 - PA7 +_DEFPIN_ARM(11, 1, A); +_DEFPIN_ARM(12, 2, A); +_DEFPIN_ARM(13, 3, A); +_DEFPIN_ARM(14, 4, A); +_DEFPIN_ARM(15, 5, A); +_DEFPIN_ARM(16, 6, A); +_DEFPIN_ARM(17, 7, A); +_DEFPIN_ARM(29, 8, A); // PA8 - PA15 +_DEFPIN_ARM(30, 9, A); +_DEFPIN_ARM(31, 10, A); +_DEFPIN_ARM(32, 11, A); +_DEFPIN_ARM(33, 12, A); +_DEFPIN_ARM(34, 13, A); +_DEFPIN_ARM(37, 14, A); +_DEFPIN_ARM(38, 15, A); + +_DEFPIN_ARM(18, 0, B); // PB0 - PB11 +_DEFPIN_ARM(19, 1, B); +_DEFPIN_ARM(20, 2, B); +_DEFPIN_ARM(39, 3, B); +_DEFPIN_ARM(40, 4, B); +_DEFPIN_ARM(41, 5, B); +_DEFPIN_ARM(42, 6, B); +_DEFPIN_ARM(43, 7, B); +_DEFPIN_ARM(45, 8, B); +_DEFPIN_ARM(46, 9, B); +_DEFPIN_ARM(21, 10, B); +_DEFPIN_ARM(22, 11, B); + +_DEFPIN_ARM(2, 13, C); // PC13 - PC15 +_DEFPIN_ARM(3, 14, C); +_DEFPIN_ARM(4, 15, C); + +#define SPI_DATA BOARD_SPI1_MOSI_PIN +#define SPI_CLOCK BOARD_SPI1_SCK_PIN + +#define HAS_HARDWARE_PIN_SUPPORT + +#endif // __STM32F1__ #endif // FASTLED_FORCE_SOFTWARE_PINS diff --git a/libraries/FastLED-3.2.0/platforms/arm/stm32/led_sysdefs_arm_stm32.h b/libraries/FastLED-3.2.9/platforms/arm/stm32/led_sysdefs_arm_stm32.h similarity index 59% rename from libraries/FastLED-3.2.0/platforms/arm/stm32/led_sysdefs_arm_stm32.h rename to libraries/FastLED-3.2.9/platforms/arm/stm32/led_sysdefs_arm_stm32.h index b697324..6b9ce7c 100644 --- a/libraries/FastLED-3.2.0/platforms/arm/stm32/led_sysdefs_arm_stm32.h +++ b/libraries/FastLED-3.2.9/platforms/arm/stm32/led_sysdefs_arm_stm32.h @@ -1,11 +1,28 @@ #ifndef __INC_LED_SYSDEFS_ARM_SAM_H #define __INC_LED_SYSDEFS_ARM_SAM_H -#include +#if defined(STM32F10X_MD) -#define FASTLED_NAMESPACE_BEGIN namespace NSFastLED { -#define FASTLED_NAMESPACE_END } -#define FASTLED_USING_NAMESPACE using namespace NSFastLED; + #include + + #define FASTLED_NAMESPACE_BEGIN namespace NSFastLED { + #define FASTLED_NAMESPACE_END } + #define FASTLED_USING_NAMESPACE using namespace NSFastLED; + + // reusing/abusing cli/sei defs for due + #define cli() __disable_irq(); __disable_fault_irq(); + #define sei() __enable_irq(); __enable_fault_irq(); + +#elif defined (__STM32F1__) + + #include "cm3_regs.h" + + #define cli() nvic_globalirq_disable() + #define sei() nvic_globalirq_enable() + +#else + #error "Platform not supported" +#endif #define FASTLED_ARM @@ -22,10 +39,6 @@ #define FASTLED_ACCURATE_CLOCK #endif -// reusing/abusing cli/sei defs for due -#define cli() __disable_irq(); __disable_fault_irq(); -#define sei() __enable_irq(); __enable_fault_irq(); - // pgmspace definitions #define PROGMEM #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) @@ -42,6 +55,7 @@ typedef volatile uint8_t RwReg; /**< Read-Write 8-bit register (volatile u #define FASTLED_NO_PINMAP -#define F_CPU 72000000 - +#ifndef F_CPU + #define F_CPU 72000000 +#endif #endif diff --git a/libraries/FastLED-3.2.0/platforms/avr/clockless_trinket.h b/libraries/FastLED-3.2.9/platforms/avr/clockless_trinket.h similarity index 88% rename from libraries/FastLED-3.2.0/platforms/avr/clockless_trinket.h rename to libraries/FastLED-3.2.9/platforms/avr/clockless_trinket.h index 0954679..69f33d6 100644 --- a/libraries/FastLED-3.2.0/platforms/avr/clockless_trinket.h +++ b/libraries/FastLED-3.2.9/platforms/avr/clockless_trinket.h @@ -71,9 +71,9 @@ template<> __attribute__((always_inline)) inline void _dc<20>(register uint8_t & #define DINTPIN(T,ADJ,PINADJ) (T-(PINADJ+ADJ)>0) ? _dc(loopvar) : _dc<0>(loopvar); #define DINT(T,ADJ) if(AVR_PIN_CYCLES(DATA_PIN)==1) { DINTPIN(T,ADJ,1) } else { DINTPIN(T,ADJ,2); } -#define D1(ADJ) DINT(T1,ADJ) -#define D2(ADJ) DINT(T2,ADJ) -#define D3(ADJ) DINT(T3,ADJ) +#define _D1(ADJ) DINT(T1,ADJ) +#define _D2(ADJ) DINT(T2,ADJ) +#define _D3(ADJ) DINT(T3,ADJ) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -394,56 +394,56 @@ protected: // Inline scaling - RGB ordering // DNOP - HI1 D1(1) QLO2(b0, 7) LDSCL4(b1,O1) D2(4) LO1 PRESCALEA2(d1) D3(2) - HI1 D1(1) QLO2(b0, 6) PRESCALEB4(d1) D2(4) LO1 SCALE12(b1,0) D3(2) - HI1 D1(1) QLO2(b0, 5) RORSC14(b1,1) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 4) SCROR14(b1,2) D2(4) LO1 SCALE12(b1,3) D3(2) - HI1 D1(1) QLO2(b0, 3) RORSC14(b1,4) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 2) SCROR14(b1,5) D2(4) LO1 SCALE12(b1,6) D3(2) - HI1 D1(1) QLO2(b0, 1) RORSC14(b1,7) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 0) + HI1 _D1(1) QLO2(b0, 7) LDSCL4(b1,O1) _D2(4) LO1 PRESCALEA2(d1) _D3(2) + HI1 _D1(1) QLO2(b0, 6) PRESCALEB4(d1) _D2(4) LO1 SCALE12(b1,0) _D3(2) + HI1 _D1(1) QLO2(b0, 5) RORSC14(b1,1) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 4) SCROR14(b1,2) _D2(4) LO1 SCALE12(b1,3) _D3(2) + HI1 _D1(1) QLO2(b0, 3) RORSC14(b1,4) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 2) SCROR14(b1,5) _D2(4) LO1 SCALE12(b1,6) _D3(2) + HI1 _D1(1) QLO2(b0, 1) RORSC14(b1,7) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 0) switch(XTRA0) { - case 4: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 3: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 2: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 1: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) + case 4: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 3: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 2: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 1: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) } - MOV_ADDDE14(b0,b1,d1,e1) D2(4) LO1 D3(0) + MOV_ADDDE14(b0,b1,d1,e1) _D2(4) LO1 _D3(0) - HI1 D1(1) QLO2(b0, 7) LDSCL4(b1,O2) D2(4) LO1 PRESCALEA2(d2) D3(2) - HI1 D1(1) QLO2(b0, 6) PSBIDATA4(d2) D2(4) LO1 SCALE22(b1,0) D3(2) - HI1 D1(1) QLO2(b0, 5) RORSC24(b1,1) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 4) SCROR24(b1,2) D2(4) LO1 SCALE22(b1,3) D3(2) - HI1 D1(1) QLO2(b0, 3) RORSC24(b1,4) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 2) SCROR24(b1,5) D2(4) LO1 SCALE22(b1,6) D3(2) - HI1 D1(1) QLO2(b0, 1) RORSC24(b1,7) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 0) + HI1 _D1(1) QLO2(b0, 7) LDSCL4(b1,O2) _D2(4) LO1 PRESCALEA2(d2) _D3(2) + HI1 _D1(1) QLO2(b0, 6) PSBIDATA4(d2) _D2(4) LO1 SCALE22(b1,0) _D3(2) + HI1 _D1(1) QLO2(b0, 5) RORSC24(b1,1) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 4) SCROR24(b1,2) _D2(4) LO1 SCALE22(b1,3) _D3(2) + HI1 _D1(1) QLO2(b0, 3) RORSC24(b1,4) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 2) SCROR24(b1,5) _D2(4) LO1 SCALE22(b1,6) _D3(2) + HI1 _D1(1) QLO2(b0, 1) RORSC24(b1,7) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 0) switch(XTRA0) { - case 4: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 3: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 2: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 1: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) + case 4: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 3: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 2: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 1: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) } // Because Prescale on the middle byte also increments the data counter, // we have to do both halves of updating d2 here - negating it (in the // MOV_NEGD24 macro) and then adding E back into it - MOV_NEGD24(b0,b1,d2) D2(4) LO1 ADDDE1(d2,e2) D3(1) - HI1 D1(1) QLO2(b0, 7) LDSCL4(b1,O0) D2(4) LO1 PRESCALEA2(d0) D3(2) - HI1 D1(1) QLO2(b0, 6) PRESCALEB4(d0) D2(4) LO1 SCALE02(b1,0) D3(2) - HI1 D1(1) QLO2(b0, 5) RORSC04(b1,1) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 4) SCROR04(b1,2) D2(4) LO1 SCALE02(b1,3) D3(2) - HI1 D1(1) QLO2(b0, 3) RORSC04(b1,4) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 2) SCROR04(b1,5) D2(4) LO1 SCALE02(b1,6) D3(2) - HI1 D1(1) QLO2(b0, 1) RORSC04(b1,7) D2(4) LO1 RORCLC2(b1) D3(2) - HI1 D1(1) QLO2(b0, 0) + MOV_NEGD24(b0,b1,d2) _D2(4) LO1 ADDDE1(d2,e2) _D3(1) + HI1 _D1(1) QLO2(b0, 7) LDSCL4(b1,O0) _D2(4) LO1 PRESCALEA2(d0) _D3(2) + HI1 _D1(1) QLO2(b0, 6) PRESCALEB4(d0) _D2(4) LO1 SCALE02(b1,0) _D3(2) + HI1 _D1(1) QLO2(b0, 5) RORSC04(b1,1) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 4) SCROR04(b1,2) _D2(4) LO1 SCALE02(b1,3) _D3(2) + HI1 _D1(1) QLO2(b0, 3) RORSC04(b1,4) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 2) SCROR04(b1,5) _D2(4) LO1 SCALE02(b1,6) _D3(2) + HI1 _D1(1) QLO2(b0, 1) RORSC04(b1,7) _D2(4) LO1 RORCLC2(b1) _D3(2) + HI1 _D1(1) QLO2(b0, 0) switch(XTRA0) { - case 4: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 3: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 2: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) - case 1: D2(0) LO1 D3(0) HI1 D1(1) QLO2(b0,0) + case 4: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 3: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 2: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) + case 1: _D2(0) LO1 _D3(0) HI1 _D1(1) QLO2(b0,0) } - MOV_ADDDE04(b0,b1,d0,e0) D2(4) LO1 D3(5) + MOV_ADDDE04(b0,b1,d0,e0) _D2(4) LO1 _D3(5) ENDLOOP5 } DONE; diff --git a/libraries/FastLED-3.2.0/platforms/avr/fastled_avr.h b/libraries/FastLED-3.2.9/platforms/avr/fastled_avr.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/avr/fastled_avr.h rename to libraries/FastLED-3.2.9/platforms/avr/fastled_avr.h diff --git a/libraries/FastLED-3.2.0/platforms/avr/fastpin_avr.h b/libraries/FastLED-3.2.9/platforms/avr/fastpin_avr.h similarity index 96% rename from libraries/FastLED-3.2.0/platforms/avr/fastpin_avr.h rename to libraries/FastLED-3.2.9/platforms/avr/fastpin_avr.h index f3ada40..4e25cf8 100644 --- a/libraries/FastLED-3.2.0/platforms/avr/fastpin_avr.h +++ b/libraries/FastLED-3.2.9/platforms/avr/fastpin_avr.h @@ -51,9 +51,13 @@ typedef volatile uint8_t & reg8_t; #define _IO(L) _RD8(DDR ## L); _RD8(PORT ## L); _RD8(PIN ## L); #define _DEFPIN_AVR(_PIN, MASK, L) template<> class FastPin<_PIN> : public _AVRPIN<_PIN, MASK, _R(PORT ## L), _R(DDR ## L), _R(PIN ## L)> {}; -#if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__) +#if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny25__) _IO(B); +#if defined(__AVR_ATtiny25__) +#pragma message "ATtiny25 has very limited storage. This library could use up to more than 100% of its flash size" +#endif + #define MAX_PIN 5 _DEFPIN_AVR(0, 0x01, B); _DEFPIN_AVR(1, 0x02, B); _DEFPIN_AVR(2, 0x04, B); _DEFPIN_AVR(3, 0x08, B); @@ -80,7 +84,7 @@ _IO(A); _IO(B); _DEFPIN_AVR(0, 0x01, B); _DEFPIN_AVR(1, 0x02, B); _DEFPIN_AVR(2, 0x04, B); _DEFPIN_AVR(3, 0x80, A); _DEFPIN_AVR(4, 0x40, A); _DEFPIN_AVR(5, 0x20, A); -#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) +#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) _IO(A); _IO(B); #define MAX_PIN 10 @@ -158,7 +162,7 @@ _DEFPIN_AVR(16, 0x04, C); _DEFPIN_AVR(17, 0x08, C); _DEFPIN_AVR(18, 0x10, C); _D #define SPI_UART0_CLOCK 12 #endif -#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega8__) +#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega8__) // Accelerated port definitions for arduino avrs _IO(D); _IO(B); _IO(C); @@ -180,7 +184,7 @@ _DEFPIN_AVR(16, 0x04, C); _DEFPIN_AVR(17, 0x08, C); _DEFPIN_AVR(18, 0x10, C); _D #define SPI_UART0_CLOCK 4 #endif -#elif defined(__AVR_ATmega1284P__) +#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__) _IO(A); _IO(B); _IO(C); _IO(D); diff --git a/libraries/FastLED-3.2.0/platforms/avr/fastspi_avr.h b/libraries/FastLED-3.2.9/platforms/avr/fastspi_avr.h similarity index 70% rename from libraries/FastLED-3.2.0/platforms/avr/fastspi_avr.h rename to libraries/FastLED-3.2.9/platforms/avr/fastspi_avr.h index 2ed5bb1..fc14d59 100644 --- a/libraries/FastLED-3.2.0/platforms/avr/fastspi_avr.h +++ b/libraries/FastLED-3.2.9/platforms/avr/fastspi_avr.h @@ -493,6 +493,183 @@ public: release(); } }; +#elif defined(SPSR0) + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Hardware SPI support using SPDR0 registers and friends +// +// Technically speaking, this uses the AVR SPI registers. This will work on the Teensy 3.0 because Paul made a set of compatability +// classes that map the AVR SPI registers to ARM's, however this caps the performance of output. +// +// TODO: implement ARMHardwareSPIOutput +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template +class AVRHardwareSPIOutput { + Selectable *m_pSelect; + bool mWait; +public: + AVRHardwareSPIOutput() { m_pSelect = NULL; mWait = false;} + AVRHardwareSPIOutput(Selectable *pSelect) { m_pSelect = pSelect; } + void setSelect(Selectable *pSelect) { m_pSelect = pSelect; } + + void setSPIRate() { + SPCR0 &= ~ ( (1<= 128) { SPCR0 |= (1<= 64) { SPCR0 |= (1<= 32) { SPCR0 |= (1<= 16) { SPCR0 |= (1<= 8) { SPCR0 |= (1<= 4) { /* do nothing - default rate */ } + else { b2x = true; } + + if(b2x) { SPSR0 |= (1<::setOutput(); + FastPin<_CLOCK_PIN>::setOutput(); +#ifdef SPI_SELECT + // Make sure the slave select line is set to output, or arduino will block us + FastPin::setOutput(); + FastPin::lo(); +#endif + + SPCR0 |= ((1<= 128) { SPCR0 |= (1<= 64) { SPCR0 |= (1<= 32) { SPCR0 |= (1<= 16) { SPCR0 |= (1<= 8) { SPCR0 |= (1<= 4) { /* do nothing - default rate */ } + else { b2x = true; } + + if(b2x) { SPSR0 |= (1<>8); writeByte(w&0xFF); } + + static void writeByte(uint8_t b) __attribute__((always_inline)) { wait(); SPDR0=b; shouldWait(true); } + static void writeBytePostWait(uint8_t b) __attribute__((always_inline)) { SPDR0=b; shouldWait(true); wait(); } + static void writeByteNoWait(uint8_t b) __attribute__((always_inline)) { SPDR0=b; shouldWait(true); } + + template inline static void writeBit(uint8_t b) { + SPCR0 &= ~(1 << SPE); + if(b & (1 << BIT)) { + FastPin<_DATA_PIN>::hi(); + } else { + FastPin<_DATA_PIN>::lo(); + } + + FastPin<_CLOCK_PIN>::hi(); + FastPin<_CLOCK_PIN>::lo(); + SPCR0 |= 1 << SPE; + shouldWait(false); + } + + void enable_pins() { + SPCR0 |= ((1<select(); } + enable_pins(); + setSPIRate(); + } + + void release() { + if(m_pSelect != NULL) { m_pSelect->release(); } + disable_pins(); + } + + static void writeBytesValueRaw(uint8_t value, int len) { + while(len--) { writeByte(value); } + } + + void writeBytesValue(uint8_t value, int len) { + //setSPIRate(); + select(); + while(len--) { + writeByte(value); + } + release(); + } + + // Write a block of n uint8_ts out + template void writeBytes(register uint8_t *data, int len) { + //setSPIRate(); + uint8_t *end = data + len; + select(); + while(data != end) { + // a slight touch of delay here helps optimize the timing of the status register check loop (not used on ARM) + writeByte(D::adjust(*data++)); delaycycles<3>(); + } + release(); + } + + void writeBytes(register uint8_t *data, int len) { writeBytes(data, len); } + + // write a block of uint8_ts out in groups of three. len is the total number of uint8_ts to write out. The template + // parameters indicate how many uint8_ts to skip at the beginning and/or end of each grouping + template void writePixels(PixelController pixels) { + //setSPIRate(); + int len = pixels.mLen; + + select(); + while(pixels.has(1)) { + if(FLAGS & FLAG_START_BIT) { + writeBit<0>(1); + writeBytePostWait(D::adjust(pixels.loadAndScale0())); + writeBytePostWait(D::adjust(pixels.loadAndScale1())); + writeBytePostWait(D::adjust(pixels.loadAndScale2())); + } else { + writeByte(D::adjust(pixels.loadAndScale0())); + writeByte(D::adjust(pixels.loadAndScale1())); + writeByte(D::adjust(pixels.loadAndScale2())); + } + + pixels.advanceData(); + pixels.stepDithering(); + } + D::postBlock(len); + waitFully(); + release(); + } +}; #endif #else diff --git a/libraries/FastLED-3.2.0/platforms/avr/led_sysdefs_avr.h b/libraries/FastLED-3.2.9/platforms/avr/led_sysdefs_avr.h similarity index 92% rename from libraries/FastLED-3.2.0/platforms/avr/led_sysdefs_avr.h rename to libraries/FastLED-3.2.9/platforms/avr/led_sysdefs_avr.h index 27024fe..2d9722d 100644 --- a/libraries/FastLED-3.2.0/platforms/avr/led_sysdefs_avr.h +++ b/libraries/FastLED-3.2.9/platforms/avr/led_sysdefs_avr.h @@ -53,12 +53,12 @@ extern volatile unsigned long timer0_millis; }; // special defs for the tiny environments -#if defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny167__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtinyX41__) +#if defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny167__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtinyX41__) || defined(__AVR_ATtiny841__) || defined(__AVR_ATtiny441__) #define LIB8_ATTINY 1 #define FASTLED_NEEDS_YIELD #endif -#if defined(ARDUINO) && (ARDUINO > 150) && !defined(IS_BEAN) && !defined (ARDUINO_AVR_DIGISPARK) && !defined (LIB8_TINY) +#if defined(ARDUINO) && (ARDUINO > 150) && !defined(IS_BEAN) && !defined (ARDUINO_AVR_DIGISPARK) && !defined (LIB8_TINY) && !defined (ARDUINO_AVR_LARDU_328E) // don't need YIELD defined by the library #else #define FASTLED_NEEDS_YIELD diff --git a/libraries/FastLED-3.2.0/platforms/esp/32/clockless_block_esp32.h b/libraries/FastLED-3.2.9/platforms/esp/32/clockless_block_esp32.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/esp/32/clockless_block_esp32.h rename to libraries/FastLED-3.2.9/platforms/esp/32/clockless_block_esp32.h diff --git a/libraries/FastLED-3.2.0/platforms/esp/32/clockless_esp32.h.orig b/libraries/FastLED-3.2.9/platforms/esp/32/clockless_esp32.h.orig similarity index 100% rename from libraries/FastLED-3.2.0/platforms/esp/32/clockless_esp32.h.orig rename to libraries/FastLED-3.2.9/platforms/esp/32/clockless_esp32.h.orig diff --git a/libraries/FastLED-3.2.9/platforms/esp/32/clockless_i2s_esp32.h b/libraries/FastLED-3.2.9/platforms/esp/32/clockless_i2s_esp32.h new file mode 100644 index 0000000..a4d15ba --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/esp/32/clockless_i2s_esp32.h @@ -0,0 +1,767 @@ +/* + * I2S Driver + * + * Copyright (c) 2019 Yves Bazin + * Copyright (c) 2019 Samuel Z. Guyer + * Derived from lots of code examples from other people. + * + * The I2S implementation can drive up to 24 strips in parallel, but + * with the following limitation: all the strips must have the same + * timing (i.e., they must all use the same chip). + * + * To enable the I2S driver, add the following line *before* including + * FastLED.h (no other changes are necessary): + * + * #define FASTLED_ESP32_I2S true + * + * The overall strategy is to use the parallel mode of the I2S "audio" + * peripheral to send up to 24 bits in parallel to 24 different pins. + * Unlike the RMT peripheral the I2S system cannot send bits of + * different lengths. Instead, we set the I2S data clock fairly high + * and then encode a signal as a series of bits. + * + * For example, with a clock divider of 10 the data clock will be + * 8MHz, so each bit is 125ns. The WS2812 expects a "1" bit to be + * encoded as a HIGH signal for around 875ns, followed by LOW for + * 375ns. Sending the following pattern results in the right shape + * signal: + * + * 1111111000 WS2812 "1" bit encoded as 10 125ns pulses + * + * The I2S peripheral expects the bits for all 24 outputs to be packed + * into a single 32-bit word. The complete signal is a series of these + * 32-bit values -- one for each bit for each strip. The pixel data, + * however, is stored "serially" as a series of RGB values separately + * for each strip. To prepare the data we need to do three things: (1) + * take 1 pixel from each strip, and (2) tranpose the bits so that + * they are in the parallel form, (3) translate each data bit into the + * bit pattern that encodes the signal for that bit. This code is in + * the fillBuffer() method: + * + * 1. Read 1 pixel from each strip into an array; store this data by + * color channel (e.g., all the red bytes, then all the green + * bytes, then all the blue bytes). For three color channels, the + * array is 3 X 24 X 8 bits. + * + * 2. Tranpose the array so that it is 3 X 8 X 24 bits. The hardware + * wants the data in 32-bit chunks, so the actual form is 3 X 8 X + * 32, with the low 8 bits unused. + * + * 3. Take each group of 24 parallel bits and "expand" them into a + * pattern according to the encoding. For example, with a 8MHz + * data clock, each data bit turns into 10 I2s pulses, so 24 + * parallel data bits turn into 10 X 24 pulses. + * + * We send data to the I2S peripheral using the DMA interface. We use + * two DMA buffers, so that we can fill one buffer while the other + * buffer is being sent. Each DMA buffer holds the fully-expanded + * pulse pattern for one pixel on up to 24 strips. The exact amount of + * memory required depends on the number of color channels and the + * number of pulses used to encode each bit. + * + * We get an interrupt each time a buffer is sent; we then fill that + * buffer while the next one is being sent. The DMA interface allows + * us to configure the buffers as a circularly linked list, so that it + * can automatically start on the next buffer. + */ +/* + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#pragma message "NOTE: ESP32 support using I2S parallel driver. All strips must use the same chipset" + +FASTLED_NAMESPACE_BEGIN + +#ifdef __cplusplus +extern "C" { +#endif + +#include "esp_heap_caps.h" +#include "soc/soc.h" +#include "soc/gpio_sig_map.h" +#include "soc/i2s_reg.h" +#include "soc/i2s_struct.h" +#include "soc/io_mux_reg.h" +#include "driver/gpio.h" +#include "driver/periph_ctrl.h" +#include "rom/lldesc.h" +#include "esp_intr.h" +#include "esp_log.h" + +#ifdef __cplusplus +} +#endif + +__attribute__ ((always_inline)) inline static uint32_t __clock_cycles() { + uint32_t cyc; + __asm__ __volatile__ ("rsr %0,ccount":"=a" (cyc)); + return cyc; +} + +#define FASTLED_HAS_CLOCKLESS 1 +#define NUM_COLOR_CHANNELS 3 + +// -- Choose which I2S device to use +#ifndef I2S_DEVICE +#define I2S_DEVICE 0 +#endif + +// -- Max number of controllers we can support +#ifndef FASTLED_I2S_MAX_CONTROLLERS +#define FASTLED_I2S_MAX_CONTROLLERS 24 +#endif + +// -- I2S clock +#define I2S_BASE_CLK (80000000L) +#define I2S_MAX_CLK (20000000L) //more tha a certain speed and the I2s looses some bits +#define I2S_MAX_PULSE_PER_BIT 20 //put it higher to get more accuracy but it could decrease the refresh rate without real improvement +// -- Convert ESP32 cycles back into nanoseconds +#define ESPCLKS_TO_NS(_CLKS) (((long)(_CLKS) * 1000L) / F_CPU_MHZ) + +// -- Array of all controllers +static CLEDController * gControllers[FASTLED_I2S_MAX_CONTROLLERS]; +static int gNumControllers = 0; +static int gNumStarted = 0; + +// -- Global semaphore for the whole show process +// Semaphore is not given until all data has been sent +static xSemaphoreHandle gTX_sem = NULL; + +// -- One-time I2S initialization +static bool gInitialized = false; + +// -- Interrupt handler +static intr_handle_t gI2S_intr_handle = NULL; + +// -- A pointer to the memory-mapped structure: I2S0 or I2S1 +static i2s_dev_t * i2s; + +// -- I2S goes to these pins until we remap them using the GPIO matrix +static int i2s_base_pin_index; + +// --- I2S DMA buffers +struct DMABuffer { + lldesc_t descriptor; + uint8_t * buffer; +}; + +#define NUM_DMA_BUFFERS 2 +static DMABuffer * dmaBuffers[NUM_DMA_BUFFERS]; + +// -- Bit patterns +// For now, we require all strips to be the same chipset, so these +// are global variables. + +static int gPulsesPerBit = 0; +static uint32_t gOneBit[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +static uint32_t gZeroBit[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + +// -- Counters to track progress +static int gCurBuffer = 0; +static bool gDoneFilling = false; +static int ones_for_one; +static int ones_for_zero; + +// -- Temp buffers for pixels and bits being formatted for DMA +static uint8_t gPixelRow[NUM_COLOR_CHANNELS][32]; +static uint8_t gPixelBits[NUM_COLOR_CHANNELS][8][4]; +static int CLOCK_DIVIDER_N; +static int CLOCK_DIVIDER_A; +static int CLOCK_DIVIDER_B; + +template +class ClocklessController : public CPixelLEDController +{ + // -- Store the GPIO pin + gpio_num_t mPin; + + // -- This instantiation forces a check on the pin choice + FastPin mFastPin; + + // -- Save the pixel controller + PixelController * mPixels; + +public: + + void init() + { + i2sInit(); + + // -- Allocate space to save the pixel controller + // during parallel output + mPixels = (PixelController *) malloc(sizeof(PixelController)); + + gControllers[gNumControllers] = this; + int my_index = gNumControllers; + gNumControllers++; + + // -- Set up the pin We have to do two things: configure the + // actual GPIO pin, and route the output from the default + // pin (determined by the I2S device) to the pin we + // want. We compute the default pin using the index of this + // controller in the array. This order is crucial because + // the bits must go into the DMA buffer in the same order. + mPin = gpio_num_t(DATA_PIN); + + PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[DATA_PIN], PIN_FUNC_GPIO); + gpio_set_direction(mPin, (gpio_mode_t)GPIO_MODE_DEF_OUTPUT); + pinMode(mPin,OUTPUT); + gpio_matrix_out(mPin, i2s_base_pin_index + my_index, false, false); + } + + virtual uint16_t getMaxRefreshRate() const { return 400; } + +protected: + + static int pgcd(int smallest,int precision,int a,int b,int c) + { + int pgc_=1; + for( int i=smallest;i>0;i--) + { + + if( a%i<=precision && b%i<=precision && c%i<=precision) + { + pgc_=i; + break; + } + } + return pgc_; + } + + /** Compute pules/bit patterns + * + * This is Yves Bazin's mad code for computing the pulse pattern + * and clock timing given the target signal given by T1, T2, and + * T3. In general, these parameters are interpreted as follows: + * + * a "1" bit is encoded by setting the pin HIGH to T1+T2 ns, then LOW for T3 ns + * a "0" bit is encoded by setting the pin HIGH to T1 ns, then LOW for T2+T3 ns + * + */ + static void initBitPatterns() + { + // Precompute the bit patterns based on the I2S sample rate + // Serial.println("Setting up fastled using I2S"); + + // -- First, convert back to ns from CPU clocks + uint32_t T1ns = ESPCLKS_TO_NS(T1); + uint32_t T2ns = ESPCLKS_TO_NS(T2); + uint32_t T3ns = ESPCLKS_TO_NS(T3); + + // Serial.print("T1 = "); Serial.print(T1); Serial.print(" ns "); Serial.println(T1ns); + // Serial.print("T2 = "); Serial.print(T2); Serial.print(" ns "); Serial.println(T2ns); + // Serial.print("T3 = "); Serial.print(T3); Serial.print(" ns "); Serial.println(T3ns); + + /* + We calculate the best pcgd to the timing + ie + WS2811 77 77 154 => 1 1 2 => nb pulses= 4 + WS2812 60 150 90 => 2 5 3 => nb pulses=10 + */ + int smallest=0; + if (T1>T2) + smallest=T2; + else + smallest=T1; + if(smallest>T3) + smallest=T3; + double freq=(double)1/(double)(T1ns + T2ns + T3ns); + // Serial.printf("chipset frequency:%f Khz\n", 1000000L*freq); + // Serial.printf("smallest %d\n",smallest); + int pgc_=1; + int precision=0; + pgc_=pgcd(smallest,precision,T1,T2,T3); + //Serial.printf("%f\n",I2S_MAX_CLK/(1000000000L*freq)); + while(pgc_==1 || (T1/pgc_ +T2/pgc_ +T3/pgc_)>I2S_MAX_PULSE_PER_BIT) //while(pgc_==1 || (T1/pgc_ +T2/pgc_ +T3/pgc_)>I2S_MAX_CLK/(1000000000L*freq)) + { + precision++; + pgc_=pgcd(smallest,precision,T1,T2,T3); + //Serial.printf("%d %d\n",pgc_,(a+b+c)/pgc_); + } + pgc_=pgcd(smallest,precision,T1,T2,T3); + // Serial.printf("pgcd %d precision:%d\n",pgc_,precision); + // Serial.printf("nb pulse per bit:%d\n",T1/pgc_ +T2/pgc_ +T3/pgc_); + gPulsesPerBit=(int)T1/pgc_ +(int)T2/pgc_ +(int)T3/pgc_; + /* + we calculate the duration of one pulse nd htre base frequency of the led + ie WS2812B F=1/(250+625+375)=800kHz or 1250ns + as we need 10 pulses each pulse is 125ns => frequency 800Khz*10=8MHz + WS2811 T=320+320+641=1281ns qnd we need 4 pulses => pulse duration 320.25ns =>frequency 3.1225605Mhz + + */ + + freq=1000000000L*freq*gPulsesPerBit; + // Serial.printf("needed frequency (nbpiulse per bit)*(chispset frequency):%f Mhz\n",freq/1000000); + + /* + we do calculate the needed N a and b + as f=basefred/(N+b/a); + as a is max 63 the precision for the decimal is 1/63 + + */ + + CLOCK_DIVIDER_N=(int)((double)I2S_BASE_CLK/freq); + double v=I2S_BASE_CLK/freq-CLOCK_DIVIDER_N; + + double prec=(double)1/63; + int a=1; + int b=0; + CLOCK_DIVIDER_A=1; + CLOCK_DIVIDER_B=0; + for(a=1;a<64;a++) + { + for(b=0;bbuffer = (uint8_t *)heap_caps_malloc(bytes, MALLOC_CAP_DMA); + memset(b->buffer, 0, bytes); + + b->descriptor.length = bytes; + b->descriptor.size = bytes; + b->descriptor.owner = 1; + b->descriptor.sosf = 1; + b->descriptor.buf = b->buffer; + b->descriptor.offset = 0; + b->descriptor.empty = 0; + b->descriptor.eof = 1; + b->descriptor.qe.stqe_next = 0; + + return b; + } + + static void i2sInit() + { + // -- Only need to do this once + if (gInitialized) return; + + // -- Construct the bit patterns for ones and zeros + initBitPatterns(); + + // -- Choose whether to use I2S device 0 or device 1 + // Set up the various device-specific parameters + int interruptSource; + if (I2S_DEVICE == 0) { + i2s = &I2S0; + periph_module_enable(PERIPH_I2S0_MODULE); + interruptSource = ETS_I2S0_INTR_SOURCE; + i2s_base_pin_index = I2S0O_DATA_OUT0_IDX; + } else { + i2s = &I2S1; + periph_module_enable(PERIPH_I2S1_MODULE); + interruptSource = ETS_I2S1_INTR_SOURCE; + i2s_base_pin_index = I2S1O_DATA_OUT0_IDX; + } + + // -- Reset everything + i2sReset(); + i2sReset_DMA(); + i2sReset_FIFO(); + + // -- Main configuration + i2s->conf.tx_msb_right = 1; + i2s->conf.tx_mono = 0; + i2s->conf.tx_short_sync = 0; + i2s->conf.tx_msb_shift = 0; + i2s->conf.tx_right_first = 1; // 0;//1; + i2s->conf.tx_slave_mod = 0; + + // -- Set parallel mode + i2s->conf2.val = 0; + i2s->conf2.lcd_en = 1; + i2s->conf2.lcd_tx_wrx2_en = 0; // 0 for 16 or 32 parallel output + i2s->conf2.lcd_tx_sdx2_en = 0; // HN + + // -- Set up the clock rate and sampling + i2s->sample_rate_conf.val = 0; + i2s->sample_rate_conf.tx_bits_mod = 32; // Number of parallel bits/pins + i2s->sample_rate_conf.tx_bck_div_num = 1; + i2s->clkm_conf.val = 0; + i2s->clkm_conf.clka_en = 0; + + // -- Data clock is computed as Base/(div_num + (div_b/div_a)) + // Base is 80Mhz, so 80/(10 + 0/1) = 8Mhz + // One cycle is 125ns + i2s->clkm_conf.clkm_div_a = CLOCK_DIVIDER_A; + i2s->clkm_conf.clkm_div_b = CLOCK_DIVIDER_B; + i2s->clkm_conf.clkm_div_num = CLOCK_DIVIDER_N; + + i2s->fifo_conf.val = 0; + i2s->fifo_conf.tx_fifo_mod_force_en = 1; + i2s->fifo_conf.tx_fifo_mod = 3; // 32-bit single channel data + i2s->fifo_conf.tx_data_num = 32; // fifo length + i2s->fifo_conf.dscr_en = 1; // fifo will use dma + + i2s->conf1.val = 0; + i2s->conf1.tx_stop_en = 0; + i2s->conf1.tx_pcm_bypass = 1; + + i2s->conf_chan.val = 0; + i2s->conf_chan.tx_chan_mod = 1; // Mono mode, with tx_msb_right = 1, everything goes to right-channel + + i2s->timing.val = 0; + + // -- Allocate two DMA buffers + dmaBuffers[0] = allocateDMABuffer(32 * NUM_COLOR_CHANNELS * gPulsesPerBit); + dmaBuffers[1] = allocateDMABuffer(32 * NUM_COLOR_CHANNELS * gPulsesPerBit); + + // -- Arrange them as a circularly linked list + dmaBuffers[0]->descriptor.qe.stqe_next = &(dmaBuffers[1]->descriptor); + dmaBuffers[1]->descriptor.qe.stqe_next = &(dmaBuffers[0]->descriptor); + + // -- Allocate i2s interrupt + SET_PERI_REG_BITS(I2S_INT_ENA_REG(I2S_DEVICE), I2S_OUT_EOF_INT_ENA_V, 1, I2S_OUT_EOF_INT_ENA_S); + esp_err_t e = esp_intr_alloc(interruptSource, 0, // ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_LEVEL3, + &interruptHandler, 0, &gI2S_intr_handle); + + // -- Create a semaphore to block execution until all the controllers are done + if (gTX_sem == NULL) { + gTX_sem = xSemaphoreCreateBinary(); + xSemaphoreGive(gTX_sem); + } + + // Serial.println("Init I2S"); + gInitialized = true; + } + + /** Clear DMA buffer + * + * Yves' clever trick: initialize the bits that we know must be 0 + * or 1 regardless of what bit they encode. + */ + static void empty( uint32_t *buf) + { + for(int i=0;i<8*NUM_COLOR_CHANNELS;i++) + { + int offset=gPulsesPerBit*i; + for(int j=0;j & pixels) + { + if (gNumStarted == 0) { + // -- First controller: make sure everything is set up + xSemaphoreTake(gTX_sem, portMAX_DELAY); + } + + // -- Initialize the local state, save a pointer to the pixel + // data. We need to make a copy because pixels is a local + // variable in the calling function, and this data structure + // needs to outlive this call to showPixels. + (*mPixels) = pixels; + + // -- Keep track of the number of strips we've seen + gNumStarted++; + + // Serial.print("Show pixels "); + // Serial.println(gNumStarted); + + // -- The last call to showPixels is the one responsible for doing + // all of the actual work + if (gNumStarted == gNumControllers) { + empty((uint32_t*)dmaBuffers[0]->buffer); + empty((uint32_t*)dmaBuffers[1]->buffer); + gCurBuffer = 0; + gDoneFilling = false; + + // -- Prefill both buffers + fillBuffer(); + fillBuffer(); + + i2sStart(); + + // -- Wait here while the rest of the data is sent. The interrupt handler + // will keep refilling the DMA buffers until it is all sent; then it + // gives the semaphore back. + xSemaphoreTake(gTX_sem, portMAX_DELAY); + xSemaphoreGive(gTX_sem); + + i2sStop(); + + // -- Reset the counters + gNumStarted = 0; + } + } + + // -- Custom interrupt handler + static IRAM_ATTR void interruptHandler(void *arg) + { + if (i2s->int_st.out_eof) { + i2s->int_clr.val = i2s->int_raw.val; + + if ( ! gDoneFilling) { + fillBuffer(); + } else { + portBASE_TYPE HPTaskAwoken = 0; + xSemaphoreGiveFromISR(gTX_sem, &HPTaskAwoken); + if(HPTaskAwoken == pdTRUE) portYIELD_FROM_ISR(); + } + } + } + + /** Fill DMA buffer + * + * This is where the real work happens: take a row of pixels (one + * from each strip), transpose and encode the bits, and store + * them in the DMA buffer for the I2S peripheral to read. + */ + static void fillBuffer() + { + // -- Alternate between buffers + volatile uint32_t * buf = (uint32_t *) dmaBuffers[gCurBuffer]->buffer; + gCurBuffer = (gCurBuffer + 1) % NUM_DMA_BUFFERS; + + // -- Get the requested pixel from each controller. Store the + // data for each color channel in a separate array. + uint32_t has_data_mask = 0; + for (int i = 0; i < gNumControllers; i++) { + // -- Store the pixels in reverse controller order starting at index 23 + // This causes the bits to come out in the right position after we + // transpose them. + int bit_index = 23-i; + ClocklessController * pController = static_cast(gControllers[i]); + if (pController->mPixels->has(1)) { + gPixelRow[0][bit_index] = pController->mPixels->loadAndScale0(); + gPixelRow[1][bit_index] = pController->mPixels->loadAndScale1(); + gPixelRow[2][bit_index] = pController->mPixels->loadAndScale2(); + pController->mPixels->advanceData(); + pController->mPixels->stepDithering(); + + // -- Record that this controller still has data to send + has_data_mask |= (1 << (i+8)); + } + } + + // -- None of the strips has data? We are done. + if (has_data_mask == 0) { + gDoneFilling = true; + return; + } + + // -- Transpose and encode the pixel data for the DMA buffer + int buf_index = 0; + for (int channel = 0; channel < NUM_COLOR_CHANNELS; channel++) { + + // -- Tranpose each array: all the bit 7's, then all the bit 6's, ... + transpose32(gPixelRow[channel], gPixelBits[channel][0] ); + + //Serial.print("Channel: "); Serial.print(channel); Serial.print(" "); + for (int bitnum = 0; bitnum < 8; bitnum++) { + uint8_t * row = (uint8_t *) (gPixelBits[channel][bitnum]); + uint32_t bit = (row[0] << 24) | (row[1] << 16) | (row[2] << 8) | row[3]; + + /* SZG: More general, but too slow: + for (int pulse_num = 0; pulse_num < gPulsesPerBit; pulse_num++) { + buf[buf_index++] = has_data_mask & ( (bit & gOneBit[pulse_num]) | (~bit & gZeroBit[pulse_num]) ); + } + */ + + // -- Only fill in the pulses that are different between the "0" and "1" encodings + for(int pulse_num = ones_for_zero; pulse_num < ones_for_one; pulse_num++) { + buf[bitnum*gPulsesPerBit+channel*8*gPulsesPerBit+pulse_num] = has_data_mask & bit; + } + } + } + } + + static void transpose32(uint8_t * pixels, uint8_t * bits) + { + transpose8rS32(& pixels[0], 1, 4, & bits[0]); + transpose8rS32(& pixels[8], 1, 4, & bits[1]); + transpose8rS32(& pixels[16], 1, 4, & bits[2]); + //transpose8rS32(& pixels[24], 1, 4, & bits[3]); Can only use 24 bits + } + + /** Transpose 8x8 bit matrix + * From Hacker's Delight + */ + static void transpose8rS32(uint8_t * A, int m, int n, uint8_t * B) + { + uint32_t x, y, t; + + // Load the array and pack it into x and y. + + x = (A[0]<<24) | (A[m]<<16) | (A[2*m]<<8) | A[3*m]; + y = (A[4*m]<<24) | (A[5*m]<<16) | (A[6*m]<<8) | A[7*m]; + + t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7); + t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7); + + t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14); + t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14); + + t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F); + y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F); + x = t; + + B[0]=x>>24; B[n]=x>>16; B[2*n]=x>>8; B[3*n]=x; + B[4*n]=y>>24; B[5*n]=y>>16; B[6*n]=y>>8; B[7*n]=y; + } + + /** Start I2S transmission + */ + static void i2sStart() + { + // esp_intr_disable(gI2S_intr_handle); + // Serial.println("I2S start"); + i2sReset(); + //Serial.println(dmaBuffers[0]->sampleCount()); + i2s->lc_conf.val=I2S_OUT_DATA_BURST_EN | I2S_OUTDSCR_BURST_EN | I2S_OUT_DATA_BURST_EN; + i2s->out_link.addr = (uint32_t) & (dmaBuffers[0]->descriptor); + i2s->out_link.start = 1; + ////vTaskDelay(5); + i2s->int_clr.val = i2s->int_raw.val; + // //vTaskDelay(5); + i2s->int_ena.out_dscr_err = 1; + //enable interrupt + ////vTaskDelay(5); + esp_intr_enable(gI2S_intr_handle); + // //vTaskDelay(5); + i2s->int_ena.val = 0; + i2s->int_ena.out_eof = 1; + + //start transmission + i2s->conf.tx_start = 1; + } + + static void i2sReset() + { + // Serial.println("I2S reset"); + const unsigned long lc_conf_reset_flags = I2S_IN_RST_M | I2S_OUT_RST_M | I2S_AHBM_RST_M | I2S_AHBM_FIFO_RST_M; + i2s->lc_conf.val |= lc_conf_reset_flags; + i2s->lc_conf.val &= ~lc_conf_reset_flags; + + const uint32_t conf_reset_flags = I2S_RX_RESET_M | I2S_RX_FIFO_RESET_M | I2S_TX_RESET_M | I2S_TX_FIFO_RESET_M; + i2s->conf.val |= conf_reset_flags; + i2s->conf.val &= ~conf_reset_flags; + } + + static void i2sReset_DMA() + { + i2s->lc_conf.in_rst=1; i2s->lc_conf.in_rst=0; + i2s->lc_conf.out_rst=1; i2s->lc_conf.out_rst=0; + } + + static void i2sReset_FIFO() + { + i2s->conf.rx_fifo_reset=1; i2s->conf.rx_fifo_reset=0; + i2s->conf.tx_fifo_reset=1; i2s->conf.tx_fifo_reset=0; + } + + static void i2sStop() + { + // Serial.println("I2S stop"); + esp_intr_disable(gI2S_intr_handle); + i2sReset(); + i2s->conf.rx_start = 0; + i2s->conf.tx_start = 0; + } +}; + +FASTLED_NAMESPACE_END diff --git a/libraries/FastLED-3.2.0/platforms/esp/32/clockless_esp32.h b/libraries/FastLED-3.2.9/platforms/esp/32/clockless_rmt_esp32.h similarity index 90% rename from libraries/FastLED-3.2.0/platforms/esp/32/clockless_esp32.h rename to libraries/FastLED-3.2.9/platforms/esp/32/clockless_rmt_esp32.h index 248325a..c9fee8a 100644 --- a/libraries/FastLED-3.2.0/platforms/esp/32/clockless_esp32.h +++ b/libraries/FastLED-3.2.9/platforms/esp/32/clockless_rmt_esp32.h @@ -112,6 +112,7 @@ __attribute__ ((always_inline)) inline static uint32_t __clock_cycles() { } #define FASTLED_HAS_CLOCKLESS 1 +#define NUM_COLOR_CHANNELS 3 // -- Configuration constants #define DIVIDER 2 /* 4, 8 still seem to work, but timings become marginal */ @@ -185,10 +186,9 @@ class ClocklessController : public CPixelLEDController rmt_item32_t mZero; rmt_item32_t mOne; - // -- State information for keeping track of where we are in the pixel data - uint8_t * mPixelData = NULL; - int mSize = 0; - int mCurByte; + // -- Save the pixel controller + PixelController * mPixels; + int mCurColor; uint16_t mCurPulse; // -- Buffer to hold all of the pulses. For the version that uses @@ -200,6 +200,10 @@ public: void init() { + // -- Allocate space to save the pixel controller + // during parallel output + mPixels = (PixelController *) malloc(sizeof(PixelController)); + // -- Precompute rmt items corresponding to a zero bit and a one bit // according to the timing values given in the template instantiation // T1H @@ -288,17 +292,15 @@ protected: xSemaphoreTake(gTX_sem, portMAX_DELAY); } - // -- Initialize the local state, save a pointer to the pixel - // data. We need to make a copy because pixels is a local - // variable in the calling function, and this data structure - // needs to outlive this call to showPixels. - - //if (mPixels != NULL) delete mPixels; - //mPixels = new PixelController(pixels); if (FASTLED_RMT_BUILTIN_DRIVER) convertAllPixelData(pixels); - else - copyPixelData(pixels); + else { + // -- Initialize the local state, save a pointer to the pixel + // data. We need to make a copy because pixels is a local + // variable in the calling function, and this data structure + // needs to outlive this call to showPixels. + (*mPixels) = pixels; + } // -- Keep track of the number of strips we've seen gNumStarted++; @@ -328,33 +330,6 @@ protected: } } - // -- Copy pixel data - // Make a safe copy of the pixel data, so that the FastLED show - // function can continue to the next controller while the RMT - // device starts sending this data asynchronously. - virtual void copyPixelData(PixelController & pixels) - { - // -- Make sure we have a buffer of the right size - // (3 bytes per pixel) - int size_needed = pixels.size() * 3; - if (size_needed > mSize) { - if (mPixelData != NULL) free(mPixelData); - mSize = size_needed; - mPixelData = (uint8_t *) malloc( mSize); - } - - // -- Cycle through the R,G, and B values in the right order, - // storing the resulting raw pixel data in the buffer. - int cur = 0; - while (pixels.has(1)) { - mPixelData[cur++] = pixels.loadAndScale0(); - mPixelData[cur++] = pixels.loadAndScale1(); - mPixelData[cur++] = pixels.loadAndScale2(); - pixels.advanceData(); - pixels.stepDithering(); - } - } - // -- Convert all pixels to RMT pulses // This function is only used when the user chooses to use the // built-in RMT driver, which needs all of the RMT pulses @@ -372,7 +347,7 @@ protected: // -- Cycle through the R,G, and B values in the right order, // storing the pulses in the big buffer mCurPulse = 0; - int cur = 0; + uint32_t byteval; while (pixels.has(1)) { byteval = pixels.loadAndScale0(); @@ -403,7 +378,7 @@ protected: // -- Start up the next controller // This method is static so that it can dispatch to the // appropriate startOnChannel method of the given controller. - static void startNext(int channel) + static void IRAM_ATTR startNext(int channel) { if (gNext < gNumControllers) { ClocklessController * pController = static_cast(gControllers[gNext]); @@ -415,7 +390,7 @@ protected: // -- Start this controller on the given channel // This function just initiates the RMT write; it does not wait // for it to finish. - void startOnChannel(int channel) + void IRAM_ATTR startOnChannel(int channel) { // -- Assign this channel and configure the RMT mRMT_channel = rmt_channel_t(channel); @@ -440,7 +415,7 @@ protected: // -- Initialize the counters that keep track of where we are in // the pixel data. mCurPulse = 0; - mCurByte = 0; + mCurColor = 0; // -- Fill both halves of the buffer fillHalfRMTBuffer(); @@ -487,7 +462,7 @@ protected: // This interrupt handler handles two cases: a controller is // done writing its data, or a controller needs to fill the // next half of the RMT buffer with data. - static IRAM_ATTR void interruptHandler(void *arg) + static void IRAM_ATTR interruptHandler(void *arg) { // -- The basic structure of this code is borrowed from the // interrupt handler in esp-idf/components/driver/rmt.c @@ -519,12 +494,39 @@ protected: } } + uint8_t IRAM_ATTR getNextByte() + { + uint8_t byte; + + // -- Cycle through the color channels + switch (mCurColor) { + case 0: + byte = mPixels->loadAndScale0(); + break; + case 1: + byte = mPixels->loadAndScale1(); + break; + case 2: + byte = mPixels->loadAndScale2(); + mPixels->advanceData(); + mPixels->stepDithering(); + break; + default: + // -- This is bad! + byte = 0; + } + + mCurColor = (mCurColor + 1) % NUM_COLOR_CHANNELS; + + return byte; + } + // -- Fill the RMT buffer // This function fills the next 32 slots in the RMT write // buffer with pixel data. It also handles the case where the // pixel data is exhausted, so we need to fill the RMT buffer // with zeros to signal that it's done. - void fillHalfRMTBuffer() + void IRAM_ATTR fillHalfRMTBuffer() { uint32_t one_val = mOne.val; uint32_t zero_val = mZero.val; @@ -533,9 +535,9 @@ protected: // into RMT pulses that encode the zeros and ones. int pulses = 0; uint32_t byteval; - while (pulses < 32 && mCurByte < mSize) { + while (pulses < 32 && mPixels->has(1)) { // -- Get one byte - byteval = mPixelData[mCurByte++]; + byteval = getNextByte(); byteval <<= 24; // Shift bits out, MSB first, setting RMTMEM.chan[n].data32[x] to the // rmt_item32_t value corresponding to the buffered bit value @@ -550,7 +552,7 @@ protected: // -- When we reach the end of the pixel data, fill the rest of the // RMT buffer with 0's, which signals to the device that we're done. - if (mCurByte == mSize) { + if ( ! mPixels->has(1) ) { while (pulses < 32) { RMTMEM.chan[mRMT_channel].data32[mCurPulse].val = 0; mCurPulse++; diff --git a/libraries/FastLED-3.2.9/platforms/esp/32/fastled_esp32.h b/libraries/FastLED-3.2.9/platforms/esp/32/fastled_esp32.h new file mode 100644 index 0000000..edf27e7 --- /dev/null +++ b/libraries/FastLED-3.2.9/platforms/esp/32/fastled_esp32.h @@ -0,0 +1,11 @@ +#pragma once + +#include "fastpin_esp32.h" + +#ifdef FASTLED_ESP32_I2S +#include "clockless_i2s_esp32.h" +#else +#include "clockless_rmt_esp32.h" +#endif + +// #include "clockless_block_esp32.h" diff --git a/libraries/FastLED-3.2.0/platforms/esp/32/fastpin_esp32.h b/libraries/FastLED-3.2.9/platforms/esp/32/fastpin_esp32.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/esp/32/fastpin_esp32.h rename to libraries/FastLED-3.2.9/platforms/esp/32/fastpin_esp32.h diff --git a/libraries/FastLED-3.2.0/platforms/esp/32/led_sysdefs_esp32.h b/libraries/FastLED-3.2.9/platforms/esp/32/led_sysdefs_esp32.h similarity index 96% rename from libraries/FastLED-3.2.0/platforms/esp/32/led_sysdefs_esp32.h rename to libraries/FastLED-3.2.9/platforms/esp/32/led_sysdefs_esp32.h index 68e7823..5cd374e 100644 --- a/libraries/FastLED-3.2.0/platforms/esp/32/led_sysdefs_esp32.h +++ b/libraries/FastLED-3.2.9/platforms/esp/32/led_sysdefs_esp32.h @@ -12,7 +12,7 @@ typedef volatile uint32_t RoReg; typedef volatile uint32_t RwReg; typedef unsigned long prog_uint32_t; -typedef bool boolean; + // Default to NOT using PROGMEM here #ifndef FASTLED_USE_PROGMEM diff --git a/libraries/FastLED-3.2.0/platforms/esp/8266/clockless_block_esp8266.h b/libraries/FastLED-3.2.9/platforms/esp/8266/clockless_block_esp8266.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/esp/8266/clockless_block_esp8266.h rename to libraries/FastLED-3.2.9/platforms/esp/8266/clockless_block_esp8266.h diff --git a/libraries/FastLED-3.2.0/platforms/esp/8266/clockless_esp8266.h b/libraries/FastLED-3.2.9/platforms/esp/8266/clockless_esp8266.h similarity index 99% rename from libraries/FastLED-3.2.0/platforms/esp/8266/clockless_esp8266.h rename to libraries/FastLED-3.2.9/platforms/esp/8266/clockless_esp8266.h index f799635..83d05b3 100644 --- a/libraries/FastLED-3.2.0/platforms/esp/8266/clockless_esp8266.h +++ b/libraries/FastLED-3.2.9/platforms/esp/8266/clockless_esp8266.h @@ -53,7 +53,7 @@ protected: #define _ESP_ADJ2 (0) template __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & last_mark, register uint32_t b) { - b = ~b; b <<= 24; + b <<= 24; b = ~b; for(register uint32_t i = BITS; i > 0; i--) { while((__clock_cycles() - last_mark) < (T1+T2+T3)); last_mark = __clock_cycles(); diff --git a/libraries/FastLED-3.2.0/platforms/esp/8266/fastled_esp8266.h b/libraries/FastLED-3.2.9/platforms/esp/8266/fastled_esp8266.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/esp/8266/fastled_esp8266.h rename to libraries/FastLED-3.2.9/platforms/esp/8266/fastled_esp8266.h diff --git a/libraries/FastLED-3.2.0/platforms/esp/8266/fastpin_esp8266.h b/libraries/FastLED-3.2.9/platforms/esp/8266/fastpin_esp8266.h similarity index 100% rename from libraries/FastLED-3.2.0/platforms/esp/8266/fastpin_esp8266.h rename to libraries/FastLED-3.2.9/platforms/esp/8266/fastpin_esp8266.h diff --git a/libraries/FastLED-3.2.0/platforms/esp/8266/led_sysdefs_esp8266.h b/libraries/FastLED-3.2.9/platforms/esp/8266/led_sysdefs_esp8266.h similarity index 97% rename from libraries/FastLED-3.2.0/platforms/esp/8266/led_sysdefs_esp8266.h rename to libraries/FastLED-3.2.9/platforms/esp/8266/led_sysdefs_esp8266.h index a3f6ac3..26dffdc 100644 --- a/libraries/FastLED-3.2.0/platforms/esp/8266/led_sysdefs_esp8266.h +++ b/libraries/FastLED-3.2.9/platforms/esp/8266/led_sysdefs_esp8266.h @@ -12,7 +12,7 @@ typedef volatile uint32_t RoReg; typedef volatile uint32_t RwReg; typedef uint32_t prog_uint32_t; -typedef uint8_t boolean; + // Default to NOT using PROGMEM here #ifndef FASTLED_USE_PROGMEM diff --git a/libraries/FastLED-3.2.0/power_mgt.cpp b/libraries/FastLED-3.2.9/power_mgt.cpp similarity index 100% rename from libraries/FastLED-3.2.0/power_mgt.cpp rename to libraries/FastLED-3.2.9/power_mgt.cpp diff --git a/libraries/FastLED-3.2.0/power_mgt.h b/libraries/FastLED-3.2.9/power_mgt.h similarity index 100% rename from libraries/FastLED-3.2.0/power_mgt.h rename to libraries/FastLED-3.2.9/power_mgt.h diff --git a/libraries/FastLED-3.2.0/preview_changes.txt b/libraries/FastLED-3.2.9/preview_changes.txt similarity index 100% rename from libraries/FastLED-3.2.0/preview_changes.txt rename to libraries/FastLED-3.2.9/preview_changes.txt diff --git a/libraries/FastLED-3.2.0/release_notes.md b/libraries/FastLED-3.2.9/release_notes.md similarity index 80% rename from libraries/FastLED-3.2.0/release_notes.md rename to libraries/FastLED-3.2.9/release_notes.md index 69dbd6a..ae9075c 100644 --- a/libraries/FastLED-3.2.0/release_notes.md +++ b/libraries/FastLED-3.2.9/release_notes.md @@ -1,10 +1,54 @@ +FastLED 3.2.9 +============= +* Update ItsyBitsy support +* Remove conflicting types courtesy of an esp8266 framework update +* Fixes to clockless M0 code to allow for more interrupt enabled environments +* ATTiny25 compilation fix +* Some STM32 fixes (the platform still seems unhappy, though) +* NRF52 support +* Updated ESP32 support - supporting up to 24-way parallel output + + + +FastLED 3.2.6 +============= + +* typo fix + +FastLED 3.2.5 +============= + +* Fix for SAMD51 based boards (a SAMD21 optimization broke the D51 builds, now D51 is a separate platform) + +FastLED 3.2.4 +============= + +* fix builds for WAV boards + +FastLED 3.2.2 +============= + +* Perf tweak for SAMD21 +* LPD6803 support +* Add atmega328pb support +* Variety of minor bug/correctness/typo fixes +* Added SM16703, GE8822, GS1903 + +FastLED 3.2.1 +============= +* ATmega644P support +* Adafruit Hallowwing (Thanks to Lady Ada) +* Improved STM 32 support +* Some user contributed cleanups +* ESP32 APA102 output fix + FastLED3.2 ========== * ESP32 support with improved output and parallel output options (thanks Sam Guyer!) * various minor contributed fixes FastLED 3.1.8 -============= +============= * Added support for Adafruit Circuit Playground Express (Thanks to Lady Ada) * Improved support for Adafruit Gemma and Trinket m0 (Thanks to Lady Ada) * Added support for PJRC's WS2812Serial (Thanks to Paul Stoffregen) @@ -37,26 +81,26 @@ FastLED3.1.3 =============== * Add SK6822 timings -* Add ESP8266 support - note, only tested w/the arduino esp8266 build environment +* Add ESP8266 support - note, only tested w/the arduino esp8266 build environment * Improvements to hsv2rgb, palette, and noise performance * Improvements to rgb2hsv accuracy -* Fixed noise discontinuity +* Fixed noise discontinuity * Add wino board support * Fix scale8 (so now, scale8(255,255) == 255, not 254!) -* Add ESP8266 parallel output support +* Add ESP8266 parallel output support FastLED3.1.1 ============ * Enabled RFDuino/nrf51822 hardware SPI support -* Fix edge case bug w/HSV palette blending +* Fix edge case bug w/HSV palette blending * Fix power management issue w/parallel output * Use static_asserts for some more useful compile time errors around bad pins * Roll power management into FastLED.show/delay directly * Support for adafruit pixies on arduino type platforms that have SoftwareSerial * TODO: support hardware serial on platforms that have it available * Add UCS2903 timings -* Preliminary CPixelView/CRGBSet code - more flexible treatment of groups of arrays +* Preliminary CPixelView/CRGBSet code - more flexible treatment of groups of arrays * https://github.com/FastLED/FastLED/wiki/RGBSet-Reference @@ -68,7 +112,7 @@ FastLED3.1.0 * RFDuino/nrf51822 * Spark Core * Major internal code reoganization -* Started doxygen based documentation +* Started doxygen based documentation * Lots of bug/performance fixes * Parallel output on various arm platforms * lots of new stuff @@ -117,7 +161,7 @@ FastLED3.0 * Fixed DMXSERIAL/DMXSIMPLE support * Timing adjustments for existing SPI chipsets * Cleaned up the code layout to make platform support easier -* Many bug fixes +* Many bug fixes * A number of performance/memory improvements * Remove Squant (takes up space!) @@ -127,7 +171,7 @@ FastLED2 ## Full release of the library ## Release Candidate 6 -* Rename library, offically, to FastLED, move to github +* Rename library, offically, to FastLED, move to github * Update keywords with all the new stuffs ## Release Candidate 5 @@ -143,7 +187,7 @@ FastLED2 * Added ability to set pixel color directly from HSV * Added ability to retrieve current random16 seed -## Release Candidate 2 +## Release Candidate 2 * mostly bug fixes * Fix SPI macro definitions for latest teensy3 software update * Teensy 2 compilation fix @@ -156,7 +200,7 @@ FastLED2 * high speed memory management operations * library for interpolation/easing functions * various api changes, addition of clear and showColor functions -* scale value applied to all show methods +* scale value applied to all show methods * bug fixes for SM16716 * performance improvements, lpd8806 exceeds 22Mbit now * hardware def fixes @@ -185,5 +229,3 @@ en if you're using the hardware SPI pins ## Preview 1 * Initial release - - diff --git a/libraries/FastLED-3.2.0/wiring.cpp b/libraries/FastLED-3.2.9/wiring.cpp similarity index 100% rename from libraries/FastLED-3.2.0/wiring.cpp rename to libraries/FastLED-3.2.9/wiring.cpp diff --git a/libraries/ПРОЧТИ МЕНЯ!!!!11111.txt b/libraries/ПРОЧТИ МЕНЯ!!!!11111.txt new file mode 100644 index 0000000..93ef281 --- /dev/null +++ b/libraries/ПРОЧТИ МЕНЯ!!!!11111.txt @@ -0,0 +1,8 @@ +В видео было сказано, что нужно ставить версию ядра 2.5.0, потому что что-то не работало. +Проблема была в библиотеке FastLED, точнее в её версии 3.2.0, которая показана в видео и в инструкции +На данный момент (вечер 15.06.2019) библиотеку FastLED я заменил на версию 3.2.9, которая работает с ядром esp версии 2.5.2 +1. Ставьте ядро ESP (инструменты/Плата/Менеджер плат) версии 2.5.2! +2. Версию FastLED ставим 3.2.9, как в этом архиве +3. Свою версию FastLED НУЖНО УДАЛИТЬ из c/Program Files.... libraries + +Зачем это всё: версия ядра 2.5.2 СТАБИЛЬНЕЕ \ No newline at end of file