diff --git a/src/BlheliCmdMap.h b/src/BlheliCmdMap.h index 7192e48..9d261d1 100644 --- a/src/BlheliCmdMap.h +++ b/src/BlheliCmdMap.h @@ -1,30 +1,31 @@ #pragma once -// source: https://github.com/bitdump/BLHeli/blob/master/BLHeli_S%20SiLabs/Dshotprog%20spec%20BLHeli_S.txt +// Source: https://github.com/bitdump/BLHeli/blob/master/BLHeli_S%20SiLabs/Dshotprog%20spec%20BLHeli_S.txt +// Date: 04.07.2021 enum dshot_cmd_t { - DIGITAL_CMD_MOTOR_STOP, // Currently not implemented - DIGITAL_CMD_BEEP1, // Wait at least length of beep (380ms) before next command - DIGITAL_CMD_BEEP2, // Wait at least length of beep (380ms) before next command - DIGITAL_CMD_BEEP3, // Wait at least length of beep (400ms) before next command - DIGITAL_CMD_BEEP4, // Wait at least length of beep (400ms) before next command - DIGITAL_CMD_BEEP5, // Wait at least length of beep (400ms) before next command - DIGITAL_CMD_ESC_INFO, // Wait at least 12ms before next command - DIGITAL_CMD_SPIN_DIRECTION_1, // Currently not implemented - DIGITAL_CMD_SPIN_DIRECTION_2, // Need 6x, no wait required - DIGITAL_CMD_3D_MODE_OFF, // Need 6x, no wait required - DIGITAL_CMD_3D_MODE_ON, // Need 6x, no wait required - DIGITAL_CMD_SETTINGS_REQUEST, // Currently not implemented - DIGITAL_CMD_SAVE_SETTINGS, // Need 6x, wait at least 12ms before next command - DIGITAL_CMD_SPIN_DIRECTION_NORMAL = 20, // Need 6x, no wait required - DIGITAL_CMD_SPIN_DIRECTION_REVERSED, // Need 6x, no wait required - DIGITAL_CMD_LED0_ON, // No wait required - DIGITAL_CMD_LED1_ON, // No wait required - DIGITAL_CMD_LED2_ON, // No wait required - DIGITAL_CMD_LED3_ON, // No wait required - DIGITAL_CMD_LED0_OFF, // No wait required - DIGITAL_CMD_LED1_OFF, // No wait required - DIGITAL_CMD_LED2_OFF, // No wait required - DIGITAL_CMD_LED3_OFF, // No wait required + DSHOT_CMD_MOTOR_STOP, // Currently not implemented - STOP Motors + DSHOT_CMD_BEEP1, // Wait at least length of beep (380ms) before next command + DSHOT_CMD_BEEP2, // Wait at least length of beep (380ms) before next command + DSHOT_CMD_BEEP3, // Wait at least length of beep (400ms) before next command + DSHOT_CMD_BEEP4, // Wait at least length of beep (400ms) before next command + DSHOT_CMD_BEEP5, // Wait at least length of beep (400ms) before next command + DSHOT_CMD_ESC_INFO, // Currently not implemented + DSHOT_CMD_SPIN_DIRECTION_1, // Need 6x, no wait required + DSHOT_CMD_SPIN_DIRECTION_2, // Need 6x, no wait required + DSHOT_CMD_3D_MODE_OFF, // Need 6x, no wait required + DSHOT_CMD_3D_MODE_ON, // Need 6x, no wait required + DSHOT_CMD_SETTINGS_REQUEST, // Currently not implemented + DSHOT_CMD_SAVE_SETTINGS, // Need 6x, wait at least 12ms before next command + DSHOT_CMD_SPIN_DIRECTION_NORMAL, // Need 6x, no wait required + DSHOT_CMD_SPIN_DIRECTION_REVERSED, // Need 6x, no wait required + DSHOT_CMD_LED0_ON, // Currently not implemented + DSHOT_CMD_LED1_ON, // Currently not implemented + DSHOT_CMD_LED2_ON, // Currently not implemented + DSHOT_CMD_LED3_ON, // Currently not implemented + DSHOT_CMD_LED0_OFF, // Currently not implemented + DSHOT_CMD_LED1_OFF, // Currently not implemented + DSHOT_CMD_LED2_OFF, // Currently not implemented + DSHOT_CMD_LED3_OFF, // Currently not implemented DSHOT_CMD_MAX = 47 }; diff --git a/src/DShotRMT.cpp b/src/DShotRMT.cpp index 799aac9..4c12422 100644 --- a/src/DShotRMT.cpp +++ b/src/DShotRMT.cpp @@ -4,10 +4,11 @@ // Author: derdoktor667 // -#include - #include "DShotRMT.h" +DShotRMT* DShotFirst = nullptr; +DShotRMT* DShotNext = nullptr; + DShotRMT::DShotRMT(gpio_num_t gpio, rmt_channel_t rmtChannel) { dshot_config.gpio_num = gpio; dshot_config.pin_num = uint8_t(gpio); @@ -44,7 +45,7 @@ bool DShotRMT::begin(dshot_mode_t dshot_mode, bool is_bidirectional) { dshot_config.mode = dshot_mode; dshot_config.clk_div = DSHOT_CLK_DIVIDER; dshot_config.name_str = dshot_mode_name[dshot_mode]; - dshot_config.is_inverted = is_bidirectional; + dshot_config.bidirectional = is_bidirectional; switch (dshot_config.mode) { case DSHOT150: @@ -119,7 +120,7 @@ void DShotRMT::send_dshot_value(uint16_t throttle_value, telemetric_request_t te throttle_value = DSHOT_THROTTLE_MAX; } - if (dshot_config.is_inverted) { + if (dshot_config.bidirectional) { // ...implement bidirectional mode @@ -132,12 +133,14 @@ void DShotRMT::send_dshot_value(uint16_t throttle_value, telemetric_request_t te } } +// ...get all setup data about current mode dshot_config_t* DShotRMT::get_dshot_info() { return &dshot_config; } -uint8_t DShotRMT::get_dshot_clock_div() { - return dshot_config.clk_div; +// ...get the ABP_Clock Divider for further calculations +uint8_t* DShotRMT::get_dshot_clock_div() { + return &dshot_config.clk_div; } rmt_item32_t* DShotRMT::encode_dshot_to_rmt(uint16_t parsed_packet) { @@ -173,7 +176,7 @@ uint16_t DShotRMT::calc_dshot_chksum(const dshot_packet_t& dshot_packet) { uint16_t packet = DSHOT_NULL_PACKET; uint16_t chksum = DSHOT_NULL_PACKET; - if (dshot_config.is_inverted) { + if (dshot_config.bidirectional) { // ...implement bidirectional mode diff --git a/src/DShotRMT.h b/src/DShotRMT.h index a020530..b421ab5 100644 --- a/src/DShotRMT.h +++ b/src/DShotRMT.h @@ -21,7 +21,7 @@ constexpr auto DSHOT_THROTTLE_MIN = 48; constexpr auto DSHOT_THROTTLE_MAX = 2047; constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000; -constexpr auto DSHOT_PAUSE = 65; // ...21bit is recommended +constexpr auto DSHOT_PAUSE = DSHOT_PACKET_LENGTH * DSHOT_CLK_DIVIDER; // ...21bit is recommended, but to be sure constexpr auto DSHOT_PAUSE_BIDIRECTIONAL = DSHOT_PAUSE; constexpr auto DSHOT_PAUSE_BIT = 16; @@ -37,6 +37,7 @@ typedef enum dshot_mode_e { DSHOT1200 } dshot_mode_t; +// ...to get human readable DShot Mode static const char* const dshot_mode_name[] = { "DSHOT_OFF", "DSHOT150", @@ -61,7 +62,7 @@ typedef struct dshot_packet_s { typedef struct dshot_config_s { dshot_mode_t mode; dshot_name_t name_str; - bool is_inverted; + bool bidirectional; gpio_num_t gpio_num; uint8_t pin_num; rmt_channel_t rmt_channel; @@ -86,7 +87,7 @@ class DShotRMT { void send_dshot_value(uint16_t throttle_value, telemetric_request_t telemetric_request = NO_TELEMETRIC); dshot_config_t* get_dshot_info(); - uint8_t get_dshot_clock_div(); + uint8_t* get_dshot_clock_div(); private: rmt_item32_t dshot_rmt_item[DSHOT_PACKET_LENGTH] = { };