diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 499d2e7..88c93e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,8 @@ concurrency: cancel-in-progress: true env: - ARDUINO_CLI_VERSION: 'latest' - ESP32_CORE_VERSION: 'latest' + ARDUINO_CLI_VERSION: '1.3.0' + ESP32_CORE_VERSION: '3.3.0' jobs: # ============================================================================ @@ -27,6 +27,25 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 + - name: Setup Arduino CLI + uses: arduino/setup-arduino-cli@v1 + with: + version: ${{ env.ARDUINO_CLI_VERSION }} + + - name: Cache Arduino data + uses: actions/cache@v4 + with: + path: | + ~/.arduino15 + key: ${{ runner.os }}-arduino-${{ env.ESP32_CORE_VERSION }}-${{ hashFiles('**/libraries/**') }} + restore-keys: | + ${{ runner.os }}-arduino-${{ env.ESP32_CORE_VERSION }}- + + - name: Install ESP32 core + run: | + arduino-cli core update-index + arduino-cli core install esp32:esp32@${{ env.ESP32_CORE_VERSION }} + - name: Arduino Lint uses: arduino/arduino-lint-action@v1 with: @@ -55,12 +74,28 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Compile Example (${{ matrix.build-flags.name }}) - uses: arduino/compile-sketches@v1 + - name: Setup Arduino CLI + uses: arduino/setup-arduino-cli@v1 with: - fqbn: esp32:esp32:esp32 - libraries: | - - source-path: ${{ github.workspace }} + version: ${{ env.ARDUINO_CLI_VERSION }} + + - name: Cache Arduino data + uses: actions/cache@v4 + with: + path: | + ~/.arduino15 + key: ${{ runner.os }}-arduino-${{ env.ESP32_CORE_VERSION }}-${{ hashFiles('**/libraries/**') }} + restore-keys: | + ${{ runner.os }}-arduino-${{ env.ESP32_CORE_VERSION }}- + + - name: Install ESP32 core + run: | + arduino-cli core update-index + arduino-cli core install esp32:esp32@${{ env.ESP32_CORE_VERSION }} + + - name: Compile Example (${{ matrix.build-flags.name }}) + run: | + arduino-cli compile --fqbn esp32:esp32:esp32 ${{ matrix.example }} # ============================================================================ # Static Code Analysis @@ -74,6 +109,25 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 + - name: Setup Arduino CLI + uses: arduino/setup-arduino-cli@v1 + with: + version: ${{ env.ARDUINO_CLI_VERSION }} + + - name: Cache Arduino data + uses: actions/cache@v4 + with: + path: | + ~/.arduino15 + key: ${{ runner.os }}-arduino-${{ env.ESP32_CORE_VERSION }}-${{ hashFiles('**/libraries/**') }} + restore-keys: | + ${{ runner.os }}-arduino-${{ env.ESP32_CORE_VERSION }}- + + - name: Install ESP32 core + run: | + arduino-cli core update-index + arduino-cli core install esp32:esp32@${{ env.ESP32_CORE_VERSION }} + - name: Install Cppcheck run: sudo apt-get update && sudo apt-get install -y cppcheck diff --git a/.gitignore b/.gitignore index 2704b2d..304b85a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ examples/dshot300/esp32.svd examples/dshot300/debug_custom.json examples/dshot300/debug.svd /build +/.github/chatmodes diff --git a/DShotRMT.cpp b/DShotRMT.cpp index d1f24db..ac34cec 100644 --- a/DShotRMT.cpp +++ b/DShotRMT.cpp @@ -53,7 +53,7 @@ DShotRMT::DShotRMT(uint16_t pin_nr, dshot_mode_t mode, bool is_bidirectional) : } // Setup and configure DShotRMT -bool DShotRMT::begin() +uint16_t DShotRMT::begin() { // Inits TX Channel if (!_initTXChannel()) @@ -320,7 +320,7 @@ uint16_t DShotRMT::_decodeDShotFrame(const rmt_symbol_word_t *symbols) // Decodes each symbol to reconstruct the frame for (size_t i = 0; i < DSHOT_BITS_PER_FRAME; ++i) { - bool bit = symbols[i].duration0 < symbols[i].duration1; + bool bit = symbols[i].duration0 > symbols[i].duration1; received_frame = (received_frame << 1) | bit; } diff --git a/DShotRMT.h b/DShotRMT.h index 3bea80a..01ab298 100644 --- a/DShotRMT.h +++ b/DShotRMT.h @@ -15,20 +15,20 @@ #include // --- DShot Protocol Constants --- -static constexpr auto DSHOT_THROTTLE_FAILSAFE = 0; -static constexpr auto DSHOT_THROTTLE_MIN = 48; -static constexpr auto DSHOT_THROTTLE_MAX = 2047; +constexpr auto DSHOT_THROTTLE_FAILSAFE = 0; +constexpr auto DSHOT_THROTTLE_MIN = 48; +constexpr auto DSHOT_THROTTLE_MAX = 2047; -static constexpr auto DSHOT_BITS_PER_FRAME = 16; -static constexpr auto DSHOT_SWITCH_TIME = 30; // 30us -static constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000; +constexpr auto DSHOT_BITS_PER_FRAME = 16; +constexpr auto DSHOT_SWITCH_TIME = 30; // 30us +constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000; // --- RMT Config Constants --- -static constexpr auto DSHOT_CLOCK_SRC_DEFAULT = RMT_CLK_SRC_DEFAULT; -static constexpr auto DSHOT_RMT_RESOLUTION = 10 * 1000 * 1000; // 10 MHz -static constexpr auto TX_BUFFER_SIZE = DSHOT_BITS_PER_FRAME; -static constexpr auto RX_BUFFER_SIZE = 128; -static constexpr auto DSHOT_SYMBOLS_SIZE = 64; +constexpr auto DSHOT_CLOCK_SRC_DEFAULT = RMT_CLK_SRC_DEFAULT; +constexpr auto DSHOT_RMT_RESOLUTION = 10 * 1000 * 1000; // 10 MHz +constexpr auto TX_BUFFER_SIZE = DSHOT_BITS_PER_FRAME; +constexpr auto RX_BUFFER_SIZE = 128; +constexpr auto DSHOT_SYMBOLS_SIZE = 64; // --- DShot Mode Select --- typedef enum dshot_mode_e @@ -71,7 +71,7 @@ public: DShotRMT(uint16_t pin_nr, dshot_mode_t mode, bool is_bidirectional); // --- Init RMT Module --- - bool begin(); + uint16_t begin(); // Sets the throttle value and transmits [[deprecated("Use sendThrottle() instead")]] diff --git a/examples/dshot300/dshot300.ino b/examples/dshot300/dshot300.ino index fea9183..cc68260 100644 --- a/examples/dshot300/dshot300.ino +++ b/examples/dshot300/dshot300.ino @@ -42,7 +42,7 @@ void setup() USB_SERIAL.printf("CPU Freq = %lu MHz\n", getCpuFrequencyMhz()); USB_SERIAL.printf("XTAL Freq = %lu MHz\n", getXtalFrequencyMhz()); USB_SERIAL.printf("APB Freq = %lu Hz\n", getApbFrequency()); - + USB_SERIAL.println("***********************************"); USB_SERIAL.println(" === DShotRMT Demo started. === "); USB_SERIAL.println("Enter a throttle value (48 – 2047):"); @@ -109,7 +109,7 @@ void print_RMT_packet() USB_SERIAL.print("Current Frame: "); // Print bit by bit - for (auto i = 15; i >= 0; --i) + for (int i = 15; i >= 0; --i) { if ((packet >> i) & 1) {