From 0106de508a513541c768b521f3e212b7158d65f9 Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Sat, 5 Oct 2024 10:51:33 +0800 Subject: [PATCH] Update Adafruit_NeoPixel to solve core 3.0.5 runtime error --- .../.github/ISSUE_TEMPLATE.md | 46 ---- .../.github/PULL_REQUEST_TEMPLATE.md | 26 -- .../.github/workflows/githubci.yml | 29 -- libdeps/Adafruit NeoPixel/.gitignore | 4 - libdeps/Adafruit NeoPixel/.piopm | 1 - .../RGBWstrandtest/.esp8266.test.skip | 0 .../RGBWstrandtest/.trinket.test.skip | 0 .../StrandtestArduinoBLE/.none.test.only | 0 .../.none.test.only | 0 .../examples/StrandtestBLE/.none.test.only | 0 .../StrandtestBLE_nodelay/.none.test.only | 1 - .../examples/buttoncycler/.esp8266.test.skip | 0 .../examples/simple/.esp8266.test.skip | 0 .../simple_new_operator/.esp8266.test.skip | 0 .../examples/strandtest/.esp8266.test.skip | 0 .../strandtest_nodelay/.esp8266.test.skip | 1 - .../strandtest_wheel/.esp8266.test.skip | 0 .../Adafruit_NeoPixel.cpp | 258 +++++++++++++++++- .../Adafruit_NeoPixel.h | 2 +- .../CONTRIBUTING.md | 0 .../COPYING | 0 .../README.md | 0 .../esp.c | 50 +++- .../esp8266.c | 0 .../RGBWstrandtest/RGBWstrandtest.ino | 0 .../StrandtestArduinoBLE.ino | 0 .../StrandtestArduinoBLECallback.ino | 0 .../examples/StrandtestBLE/BLESerial.cpp | 0 .../examples/StrandtestBLE/BLESerial.h | 0 .../examples/StrandtestBLE/StrandtestBLE.ino | 0 .../StrandtestBLE_nodelay/BLESerial.cpp | 0 .../StrandtestBLE_nodelay/BLESerial.h | 0 .../StrandtestBLE_nodelay.ino | 0 .../examples/buttoncycler/buttoncycler.ino | 0 .../examples/simple/simple.ino | 0 .../simple_new_operator.ino | 0 .../examples/strandtest/strandtest.ino | 0 .../strandtest_nodelay/strandtest_nodelay.ino | 54 ++-- .../strandtest_wheel/strandtest_wheel.ino | 0 .../kendyte_k210.c | 0 .../keywords.txt | 0 .../library.properties | 2 +- .../rp2040_pio.h | 0 43 files changed, 337 insertions(+), 137 deletions(-) delete mode 100644 libdeps/Adafruit NeoPixel/.github/ISSUE_TEMPLATE.md delete mode 100644 libdeps/Adafruit NeoPixel/.github/PULL_REQUEST_TEMPLATE.md delete mode 100644 libdeps/Adafruit NeoPixel/.github/workflows/githubci.yml delete mode 100644 libdeps/Adafruit NeoPixel/.gitignore delete mode 100644 libdeps/Adafruit NeoPixel/.piopm delete mode 100644 libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/.trinket.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLE/.none.test.only delete mode 100644 libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only delete mode 100644 libdeps/Adafruit NeoPixel/examples/StrandtestBLE/.none.test.only delete mode 100644 libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only delete mode 100644 libdeps/Adafruit NeoPixel/examples/buttoncycler/.esp8266.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/simple/.esp8266.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/simple_new_operator/.esp8266.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/strandtest/.esp8266.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip delete mode 100644 libdeps/Adafruit NeoPixel/examples/strandtest_wheel/.esp8266.test.skip rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/Adafruit_NeoPixel.cpp (93%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/Adafruit_NeoPixel.h (99%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/CONTRIBUTING.md (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/COPYING (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/README.md (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/esp.c (85%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/esp8266.c (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/RGBWstrandtest/RGBWstrandtest.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestBLE/BLESerial.cpp (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestBLE/BLESerial.h (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestBLE/StrandtestBLE.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestBLE_nodelay/BLESerial.cpp (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestBLE_nodelay/BLESerial.h (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/buttoncycler/buttoncycler.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/simple/simple.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/simple_new_operator/simple_new_operator.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/strandtest/strandtest.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/strandtest_nodelay/strandtest_nodelay.ino (85%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/examples/strandtest_wheel/strandtest_wheel.ino (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/kendyte_k210.c (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/keywords.txt (100%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/library.properties (95%) rename libdeps/{Adafruit NeoPixel => Adafruit_NeoPixel}/rp2040_pio.h (100%) diff --git a/libdeps/Adafruit NeoPixel/.github/ISSUE_TEMPLATE.md b/libdeps/Adafruit NeoPixel/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index f0e2614..0000000 --- a/libdeps/Adafruit NeoPixel/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,46 +0,0 @@ -Thank you for opening an issue on an Adafruit Arduino library repository. To -improve the speed of resolution please review the following guidelines and -common troubleshooting steps below before creating the issue: - -- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use - the forums at http://forums.adafruit.com to ask questions and troubleshoot why - something isn't working as expected. In many cases the problem is a common issue - that you will more quickly receive help from the forum community. GitHub issues - are meant for known defects in the code. If you don't know if there is a defect - in the code then start with troubleshooting on the forum first. - -- **If following a tutorial or guide be sure you didn't miss a step.** Carefully - check all of the steps and commands to run have been followed. Consult the - forum if you're unsure or have questions about steps in a guide/tutorial. - -- **For Arduino projects check these very common issues to ensure they don't apply**: - - - For uploading sketches or communicating with the board make sure you're using - a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes - very hard to tell the difference between a data and charge cable! Try using the - cable with other devices or swapping to another cable to confirm it is not - the problem. - - - **Be sure you are supplying adequate power to the board.** Check the specs of - your board and plug in an external power supply. In many cases just - plugging a board into your computer is not enough to power it and other - peripherals. - - - **Double check all soldering joints and connections.** Flakey connections - cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. - - - **Ensure you are using an official Arduino or Adafruit board.** We can't - guarantee a clone board will have the same functionality and work as expected - with this code and don't support them. - -If you're sure this issue is a defect in the code and checked the steps above -please fill in the following fields to provide enough troubleshooting information. -You may delete the guideline and text above to just leave the following details: - -- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** - -- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO - VERSION HERE** - -- List the steps to reproduce the problem below (if possible attach a sketch or - copy the sketch code in too): **LIST REPRO STEPS BELOW** diff --git a/libdeps/Adafruit NeoPixel/.github/PULL_REQUEST_TEMPLATE.md b/libdeps/Adafruit NeoPixel/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7b641eb..0000000 --- a/libdeps/Adafruit NeoPixel/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,26 +0,0 @@ -Thank you for creating a pull request to contribute to Adafruit's GitHub code! -Before you open the request please review the following guidelines and tips to -help it be more easily integrated: - -- **Describe the scope of your change--i.e. what the change does and what parts - of the code were modified.** This will help us understand any risks of integrating - the code. - -- **Describe any known limitations with your change.** For example if the change - doesn't apply to a supported platform of the library please mention it. - -- **Please run any tests or examples that can exercise your modified code.** We - strive to not break users of the code and running tests/examples helps with this - process. - -Thank you again for contributing! We will try to test and integrate the change -as soon as we can, but be aware we have many GitHub repositories to manage and -can't immediately respond to every request. There is no need to bump or check in -on a pull request (it will clutter the discussion of the request). - -Also don't be worried if the request is closed or not integrated--sometimes the -priorities of Adafruit's GitHub code (education, ease of use) might not match the -priorities of the pull request. Don't fret, the open source community thrives on -forks and GitHub makes it easy to keep your changes in a forked repo. - -After reviewing the guidelines above you can delete this text from the pull request. diff --git a/libdeps/Adafruit NeoPixel/.github/workflows/githubci.yml b/libdeps/Adafruit NeoPixel/.github/workflows/githubci.yml deleted file mode 100644 index 2ff3d65..0000000 --- a/libdeps/Adafruit NeoPixel/.github/workflows/githubci.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Arduino Library CI - -on: [pull_request, push, repository_dispatch] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - uses: actions/checkout@v2 - - uses: actions/checkout@v2 - with: - repository: adafruit/ci-arduino - path: ci - - - name: pre-install - run: bash ci/actions_install.sh - - - name: test platforms - run: python3 ci/build_platform.py main_platforms - - - name: doxygen - env: - GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} - PRETTYNAME : "Adafruit NeoPixel Library" - run: bash ci/doxy_gen_and_deploy.sh diff --git a/libdeps/Adafruit NeoPixel/.gitignore b/libdeps/Adafruit NeoPixel/.gitignore deleted file mode 100644 index c2a26c0..0000000 --- a/libdeps/Adafruit NeoPixel/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Our handy .gitignore for automation ease -Doxyfile* -doxygen_sqlite3.db -html diff --git a/libdeps/Adafruit NeoPixel/.piopm b/libdeps/Adafruit NeoPixel/.piopm deleted file mode 100644 index 53719f4..0000000 --- a/libdeps/Adafruit NeoPixel/.piopm +++ /dev/null @@ -1 +0,0 @@ -{"type": "library", "name": "Adafruit NeoPixel", "version": "1.11.0", "spec": {"owner": "adafruit", "id": 28, "name": "Adafruit NeoPixel", "requirements": null, "uri": null}} \ No newline at end of file diff --git a/libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/.trinket.test.skip b/libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/.trinket.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLE/.none.test.only b/libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLE/.none.test.only deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only b/libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE/.none.test.only b/libdeps/Adafruit NeoPixel/examples/StrandtestBLE/.none.test.only deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only b/libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only deleted file mode 100644 index 8b13789..0000000 --- a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only +++ /dev/null @@ -1 +0,0 @@ - diff --git a/libdeps/Adafruit NeoPixel/examples/buttoncycler/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/buttoncycler/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/simple/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/simple/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/simple_new_operator/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/simple_new_operator/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/strandtest/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/strandtest/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip deleted file mode 100644 index 8b13789..0000000 --- a/libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip +++ /dev/null @@ -1 +0,0 @@ - diff --git a/libdeps/Adafruit NeoPixel/examples/strandtest_wheel/.esp8266.test.skip b/libdeps/Adafruit NeoPixel/examples/strandtest_wheel/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/libdeps/Adafruit NeoPixel/Adafruit_NeoPixel.cpp b/libdeps/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp similarity index 93% rename from libdeps/Adafruit NeoPixel/Adafruit_NeoPixel.cpp rename to libdeps/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp index 12e4761..0c3cb9b 100644 --- a/libdeps/Adafruit NeoPixel/Adafruit_NeoPixel.cpp +++ b/libdeps/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp @@ -224,7 +224,162 @@ void Adafruit_NeoPixel::rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBy // Bits for transmission must be shifted to top 8 bits pio_sm_put_blocking(pio, sm, ((uint32_t)*pixels++)<< 24); } +#elif defined(ARDUINO_ARCH_CH32) +// F_CPU is defined to SystemCoreClock (not constant number) +#if SYSCLK_FREQ_144MHz_HSE == 144000000 || SYSCLK_FREQ_HSE == 144000000 || \ + SYSCLK_FREQ_144MHz_HSI == 144000000 || SYSCLK_FREQ_HSI == 144000000 +#define CH32_F_CPU 144000000 + +#elif SYSCLK_FREQ_120MHz_HSE == 120000000 || SYSCLK_FREQ_HSE == 120000000 || \ + SYSCLK_FREQ_120MHz_HSI == 120000000 || SYSCLK_FREQ_HSI == 120000000 +#define CH32_F_CPU 120000000 + +#elif SYSCLK_FREQ_96MHz_HSE == 96000000 || SYSCLK_FREQ_HSE == 96000000 || \ + SYSCLK_FREQ_96MHz_HSI == 96000000 || SYSCLK_FREQ_HSI == 96000000 +#define CH32_F_CPU 96000000 + +#elif SYSCLK_FREQ_72MHz_HSE == 72000000 || SYSCLK_FREQ_HSE == 72000000 || \ + SYSCLK_FREQ_72MHz_HSI == 72000000 || SYSCLK_FREQ_HSI == 72000000 +#define CH32_F_CPU 72000000 + +#elif SYSCLK_FREQ_56MHz_HSE == 56000000 || SYSCLK_FREQ_HSE == 56000000 || \ + SYSCLK_FREQ_56MHz_HSI == 56000000 || SYSCLK_FREQ_HSI == 56000000 +#define CH32_F_CPU 56000000 + +#elif SYSCLK_FREQ_48MHz_HSE == 48000000 || SYSCLK_FREQ_HSE == 48000000 || \ + SYSCLK_FREQ_48MHz_HSI == 48000000 || SYSCLK_FREQ_HSI == 48000000 +#define CH32_F_CPU 48000000 + +#endif + +static void ch32Show(GPIO_TypeDef* ch_port, uint32_t ch_pin, uint8_t* pixels, uint32_t numBytes, bool is800KHz) { + // not support 400khz + if (!is800KHz) return; + + volatile uint32_t* set = &ch_port->BSHR; + volatile uint32_t* clr = &ch_port->BCR; + + uint8_t* ptr = pixels; + uint8_t* end = ptr + numBytes; + uint8_t p = *ptr++; + uint8_t bitMask = 0x80; + + // NVIC_DisableIRQ(SysTicK_IRQn); + + while (1) { + if (p & bitMask) { // ONE + // High 800ns + *set = ch_pin; + __asm volatile ("nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop;" +#if CH32_F_CPU >= 72000000 + "nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 96000000 + "nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 120000000 + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 144000000 + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif + ); + + // Low 450ns + *clr = ch_pin; + __asm volatile ("nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop;" +#if CH32_F_CPU >= 72000000 + "nop; nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 96000000 + "nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 120000000 + "nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 144000000 + "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" +#endif + ); + } else { // ZERO + // High 400ns + *set = ch_pin; + __asm volatile ("nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop;" +#if CH32_F_CPU >= 72000000 + "nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 96000000 + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 120000000 + "nop; nop; nop; " + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 144000000 + "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" +#endif + ); + + // Low 850ns + *clr = ch_pin; + __asm volatile ("nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop;" +#if CH32_F_CPU >= 72000000 + "nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 96000000 + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 120000000 + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop;" +#endif +#if CH32_F_CPU >= 144000000 + "nop; nop; nop; nop;" + "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" +#endif + ); + } + + if (bitMask >>= 1) { + // Move on to the next pixel + asm("nop;"); + } + else { + if (ptr >= end) { + break; + } + p = *ptr++; + bitMask = 0x80; + } + } + + // NVIC_EnableIRQ(SysTicK_IRQn); +} #endif #if defined(ESP8266) @@ -282,8 +437,8 @@ void Adafruit_NeoPixel::show(void) { // state, computes 'pin high' and 'pin low' values, and writes these back // to the PORT register as needed. - // NRF52 may use PWM + DMA (if available), may not need to disable interrupt - // ESP32 may not disable interrupts because espShow() uses RMT which tries to acquire locks + // NRF52 may use PWM + DMA (if available), may not need to disable interrupt + // ESP32 may not disable interrupts because espShow() uses RMT which tries to acquire locks #if !(defined(NRF52) || defined(NRF52_SERIES) || defined(ESP32)) noInterrupts(); // Need 100% focus on instruction timing #endif @@ -2256,7 +2411,7 @@ void Adafruit_NeoPixel::show(void) { #elif defined(__SAMD21E17A__) || defined(__SAMD21G18A__) || \ defined(__SAMD21E18A__) || defined(__SAMD21J18A__) || \ - defined (__SAMD11C14A__) + defined(__SAMD11C14A__) || defined(__SAMD21G17A__) // Arduino Zero, Gemma/Trinket M0, SODAQ Autonomo // and others // Tried this with a timer/counter, couldn't quite get adequate @@ -2914,7 +3069,89 @@ if(is800KHz) { ; // Wait for last bit TC_Stop(TC1, 0); -#endif // end Due + +// RENESAS including UNO R4 +#elif defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_RENESAS_UNO) || defined(ARDUINO_ARCH_RENESAS_PORTENTA) + +// Definition for a single channel clockless controller for RA4M1 (Cortex M4) +// 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 F_CPU 48000000 +#define CYCLES_800_T0H (F_CPU / 4000000) +#define CYCLES_800_T1H (F_CPU / 1250000) +#define CYCLES_800 (F_CPU / 800000) +#define CYCLES_400_T0H (F_CPU / 2000000) +#define CYCLES_400_T1H (F_CPU / 833333) +#define CYCLES_400 (F_CPU / 400000) + + uint8_t *p = pixels, *end = p + numBytes, pix, mask; + + bsp_io_port_pin_t io_pin = g_pin_cfg[pin].pin; + #define PIN_IO_PORT_ADDR(pn) (R_PORT0 + ((uint32_t) (R_PORT1 - R_PORT0) * ((pn) >> 8u))) + + volatile uint16_t *set = &(PIN_IO_PORT_ADDR(io_pin)->POSR); + volatile uint16_t *clr = &(PIN_IO_PORT_ADDR(io_pin)->PORR); + uint16_t msk = (1U << (io_pin & 0xFF)); + + uint32_t cyc; + + ARM_DEMCR |= ARM_DEMCR_TRCENA; + ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; + +#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled + if (is800KHz) { +#endif + cyc = ARM_DWT_CYCCNT + CYCLES_800; + while (p < end) { + pix = *p++; + for (mask = 0x80; mask; mask >>= 1) { + while (ARM_DWT_CYCCNT - cyc < CYCLES_800) + ; + cyc = ARM_DWT_CYCCNT; + *set = msk; + if (pix & mask) { + while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T1H) + ; + } else { + while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T0H) + ; + } + *clr = msk; + } + } + while (ARM_DWT_CYCCNT - cyc < CYCLES_800) + ; +#if defined(NEO_KHZ400) + } else { // 400 kHz bitstream + cyc = ARM_DWT_CYCCNT + CYCLES_400; + while (p < end) { + pix = *p++; + for (mask = 0x80; mask; mask >>= 1) { + while (ARM_DWT_CYCCNT - cyc < CYCLES_400) + ; + cyc = ARM_DWT_CYCCNT; + *set = msk; + if (pix & mask) { + while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T1H) + ; + } else { + while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T0H) + ; + } + *clr = msk; + } + } + while (ARM_DWT_CYCCNT - cyc < CYCLES_400) + ; + } +#endif // NEO_KHZ400 + +#endif // ARM // END ARM ---------------------------------------------------------------- @@ -3026,6 +3263,8 @@ if(is800KHz) { } } +#elif defined(ARDUINO_ARCH_CH32) + ch32Show(gpioPort, gpioPin, pixels, numBytes, is800KHz); #else #error Architecture not supported #endif @@ -3059,6 +3298,15 @@ void Adafruit_NeoPixel::setPin(int16_t p) { #if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) gpioPort = digitalPinToPort(p); gpioPin = STM_LL_GPIO_PIN(digitalPinToPinName(p)); +#elif defined(ARDUINO_ARCH_CH32) + PinName const pin_name = digitalPinToPinName(pin); + gpioPort = get_GPIO_Port(CH_PORT(pin_name)); + gpioPin = CH_GPIO_PIN(pin_name); + #if defined (CH32V20x_D6) + if (gpioPort == GPIOC && ((*(volatile uint32_t*)0x40022030) & 0x0F000000) == 0) { + gpioPin = gpioPin >> 13; + } + #endif #endif } @@ -3471,4 +3719,4 @@ neoPixelType Adafruit_NeoPixel::str2order(const char *v) { } if (w < 0) w = r; // If 'w' not specified, duplicate r bits return (w << 6) | (r << 4) | ((g & 3) << 2) | (b & 3); -} +} diff --git a/libdeps/Adafruit NeoPixel/Adafruit_NeoPixel.h b/libdeps/Adafruit_NeoPixel/Adafruit_NeoPixel.h similarity index 99% rename from libdeps/Adafruit NeoPixel/Adafruit_NeoPixel.h rename to libdeps/Adafruit_NeoPixel/Adafruit_NeoPixel.h index ba022f6..18fabbf 100644 --- a/libdeps/Adafruit NeoPixel/Adafruit_NeoPixel.h +++ b/libdeps/Adafruit_NeoPixel/Adafruit_NeoPixel.h @@ -398,7 +398,7 @@ class Adafruit_NeoPixel { volatile uint8_t *port; ///< Output PORT register uint8_t pinMask; ///< Output PORT bitmask #endif -#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) +#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) || defined(ARDUINO_ARCH_CH32) GPIO_TypeDef *gpioPort; ///< Output GPIO PORT uint32_t gpioPin; ///< Output GPIO PIN #endif diff --git a/libdeps/Adafruit NeoPixel/CONTRIBUTING.md b/libdeps/Adafruit_NeoPixel/CONTRIBUTING.md similarity index 100% rename from libdeps/Adafruit NeoPixel/CONTRIBUTING.md rename to libdeps/Adafruit_NeoPixel/CONTRIBUTING.md diff --git a/libdeps/Adafruit NeoPixel/COPYING b/libdeps/Adafruit_NeoPixel/COPYING similarity index 100% rename from libdeps/Adafruit NeoPixel/COPYING rename to libdeps/Adafruit_NeoPixel/COPYING diff --git a/libdeps/Adafruit NeoPixel/README.md b/libdeps/Adafruit_NeoPixel/README.md similarity index 100% rename from libdeps/Adafruit NeoPixel/README.md rename to libdeps/Adafruit_NeoPixel/README.md diff --git a/libdeps/Adafruit NeoPixel/esp.c b/libdeps/Adafruit_NeoPixel/esp.c similarity index 85% rename from libdeps/Adafruit NeoPixel/esp.c rename to libdeps/Adafruit_NeoPixel/esp.c index c480a20..eed9f8e 100644 --- a/libdeps/Adafruit NeoPixel/esp.c +++ b/libdeps/Adafruit_NeoPixel/esp.c @@ -20,14 +20,57 @@ #if defined(ESP32) #include -#include "driver/rmt.h" #if defined(ESP_IDF_VERSION) #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) #define HAS_ESP_IDF_4 #endif +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) +#define HAS_ESP_IDF_5 +#endif #endif + + +#ifdef HAS_ESP_IDF_5 + +void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { + rmt_data_t led_data[numBytes * 8]; + + if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { + log_e("Failed to init RMT TX mode on pin %d", pin); + return; + } + + int i=0; + for (int b=0; b < numBytes; b++) { + for (int bit=0; bit<8; bit++){ + if ( pixels[b] & (1<<(7-bit)) ) { + led_data[i].level0 = 1; + led_data[i].duration0 = 8; + led_data[i].level1 = 0; + led_data[i].duration1 = 4; + } else { + led_data[i].level0 = 1; + led_data[i].duration0 = 4; + led_data[i].level1 = 0; + led_data[i].duration1 = 8; + } + i++; + } + } + + //pinMode(pin, OUTPUT); // don't do this, will cause the rmt to disable! + rmtWrite(pin, led_data, numBytes * 8, RMT_WAIT_FOR_EVER); +} + + + +#else + +#include "driver/rmt.h" + + // This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered // to work with the Arduino version of the ESP-IDF (3.2) @@ -175,4 +218,7 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) gpio_set_direction(pin, GPIO_MODE_OUTPUT); } -#endif +#endif // ifndef IDF5 + + +#endif // ifdef(ESP32) diff --git a/libdeps/Adafruit NeoPixel/esp8266.c b/libdeps/Adafruit_NeoPixel/esp8266.c similarity index 100% rename from libdeps/Adafruit NeoPixel/esp8266.c rename to libdeps/Adafruit_NeoPixel/esp8266.c diff --git a/libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino b/libdeps/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino rename to libdeps/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino b/libdeps/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino rename to libdeps/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino b/libdeps/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino rename to libdeps/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE/BLESerial.cpp b/libdeps/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestBLE/BLESerial.cpp rename to libdeps/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE/BLESerial.h b/libdeps/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestBLE/BLESerial.h rename to libdeps/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino b/libdeps/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino rename to libdeps/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp b/libdeps/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp rename to libdeps/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h b/libdeps/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h rename to libdeps/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h diff --git a/libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino b/libdeps/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino rename to libdeps/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino diff --git a/libdeps/Adafruit NeoPixel/examples/buttoncycler/buttoncycler.ino b/libdeps/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/buttoncycler/buttoncycler.ino rename to libdeps/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino diff --git a/libdeps/Adafruit NeoPixel/examples/simple/simple.ino b/libdeps/Adafruit_NeoPixel/examples/simple/simple.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/simple/simple.ino rename to libdeps/Adafruit_NeoPixel/examples/simple/simple.ino diff --git a/libdeps/Adafruit NeoPixel/examples/simple_new_operator/simple_new_operator.ino b/libdeps/Adafruit_NeoPixel/examples/simple_new_operator/simple_new_operator.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/simple_new_operator/simple_new_operator.ino rename to libdeps/Adafruit_NeoPixel/examples/simple_new_operator/simple_new_operator.ino diff --git a/libdeps/Adafruit NeoPixel/examples/strandtest/strandtest.ino b/libdeps/Adafruit_NeoPixel/examples/strandtest/strandtest.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/strandtest/strandtest.ino rename to libdeps/Adafruit_NeoPixel/examples/strandtest/strandtest.ino diff --git a/libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino b/libdeps/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino similarity index 85% rename from libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino rename to libdeps/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino index 9c392e2..1fb8888 100644 --- a/libdeps/Adafruit NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino +++ b/libdeps/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino @@ -42,10 +42,11 @@ unsigned long pixelPrevious = 0; // Previous Pixel Millis unsigned long patternPrevious = 0; // Previous Pattern Millis int patternCurrent = 0; // Current Pattern Number int patternInterval = 5000; // Pattern Interval (ms) +bool patternComplete = false; + int pixelInterval = 50; // Pixel Interval (ms) int pixelQueue = 0; // Pattern Pixel Queue int pixelCycle = 0; // Pattern Pixel Cycle -uint16_t pixelCurrent = 0; // Pattern Current Pixel Number uint16_t pixelNumber = LED_COUNT; // Total Number of Pixels // setup() function -- runs once at startup -------------------------------- @@ -65,13 +66,14 @@ void setup() { // loop() function -- runs repeatedly as long as board is on --------------- void loop() { unsigned long currentMillis = millis(); // Update current time - if((currentMillis - patternPrevious) >= patternInterval) { // Check for expired time + if( patternComplete || (currentMillis - patternPrevious) >= patternInterval) { // Check for expired time + patternComplete = false; patternPrevious = currentMillis; patternCurrent++; // Advance to next pattern if(patternCurrent >= 7) patternCurrent = 0; } - + if(currentMillis - pixelPrevious >= pixelInterval) { // Check for expired time pixelPrevious = currentMillis; // Run current frame switch (patternCurrent) { @@ -111,31 +113,43 @@ void loop() { // strip.Color(red, green, blue) as shown in the loop() function above), // and a delay time (in milliseconds) between pixels. void colorWipe(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - pixelCurrent++; // Advance current pixel - if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED - pixelCurrent = 0; + static uint16_t current_pixel = 0; + pixelInterval = wait; // Update delay time + strip.setPixelColor(current_pixel++, color); // Set pixel's color (in RAM) + strip.show(); // Update strip to match + if(current_pixel >= pixelNumber) { // Loop the pattern from the first LED + current_pixel = 0; + patternComplete = true; + } } // Theater-marquee-style chasing lights. Pass in a color (32-bit value, // a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) // between frames. void theaterChase(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i = 0; i < pixelNumber; i++) { - strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM) + static uint32_t loop_count = 0; + static uint16_t current_pixel = 0; + + pixelInterval = wait; // Update delay time + + strip.clear(); + + for(int c=current_pixel; c < pixelNumber; c += 3) { + strip.setPixelColor(c, color); } - strip.show(); // Update strip to match - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM) + strip.show(); + + current_pixel++; + if (current_pixel >= 3) { + current_pixel = 0; + loop_count++; + } + + if (loop_count >= 10) { + current_pixel = 0; + loop_count = 0; + patternComplete = true; } - pixelQueue++; // Advance current pixel - if(pixelQueue >= 3) - pixelQueue = 0; // Loop the pattern from the first LED } // Rainbow cycle along whole strip. Pass delay time (in ms) between frames. diff --git a/libdeps/Adafruit NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino b/libdeps/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino similarity index 100% rename from libdeps/Adafruit NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino rename to libdeps/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino diff --git a/libdeps/Adafruit NeoPixel/kendyte_k210.c b/libdeps/Adafruit_NeoPixel/kendyte_k210.c similarity index 100% rename from libdeps/Adafruit NeoPixel/kendyte_k210.c rename to libdeps/Adafruit_NeoPixel/kendyte_k210.c diff --git a/libdeps/Adafruit NeoPixel/keywords.txt b/libdeps/Adafruit_NeoPixel/keywords.txt similarity index 100% rename from libdeps/Adafruit NeoPixel/keywords.txt rename to libdeps/Adafruit_NeoPixel/keywords.txt diff --git a/libdeps/Adafruit NeoPixel/library.properties b/libdeps/Adafruit_NeoPixel/library.properties similarity index 95% rename from libdeps/Adafruit NeoPixel/library.properties rename to libdeps/Adafruit_NeoPixel/library.properties index cec3e14..7c80a96 100644 --- a/libdeps/Adafruit NeoPixel/library.properties +++ b/libdeps/Adafruit_NeoPixel/library.properties @@ -1,5 +1,5 @@ name=Adafruit NeoPixel -version=1.11.0 +version=1.12.3 author=Adafruit maintainer=Adafruit sentence=Arduino library for controlling single-wire-based LED pixels and strip. diff --git a/libdeps/Adafruit NeoPixel/rp2040_pio.h b/libdeps/Adafruit_NeoPixel/rp2040_pio.h similarity index 100% rename from libdeps/Adafruit NeoPixel/rp2040_pio.h rename to libdeps/Adafruit_NeoPixel/rp2040_pio.h