diff --git a/DShotRMT.cpp b/DShotRMT.cpp index 5aba4a2..45a7b5f 100644 --- a/DShotRMT.cpp +++ b/DShotRMT.cpp @@ -65,7 +65,6 @@ bool DShotRMT::begin() // bool DShotRMT::setThrottle(uint16_t throttle) { - // DShot Frame Container dshot_packet_t packet = {}; @@ -80,6 +79,23 @@ bool DShotRMT::setThrottle(uint16_t throttle) } } +// +bool DShotRMT::sendDShotCommand(uint16_t command) +{ + // DShot Frame Container + dshot_packet_t packet = {}; + + // Create DShot packet + packet.throttle_value = constrain(command, DSHOT_CMD_MOTOR_STOP, DSHOT_CMD_MAX); + packet.telemetric_request = _is_bidirectional; + packet.checksum = _calculateCRC(packet); + + if (!_sendDShotFrame(packet)) + { + return DSHOT_ERROR; + } +} + // uint32_t DShotRMT::getERPM() { diff --git a/DShotRMT.h b/DShotRMT.h index 1cdfa5e..f9f10d8 100644 --- a/DShotRMT.h +++ b/DShotRMT.h @@ -13,6 +13,7 @@ #include #include #include +#include static constexpr bool DSHOT_OK = 0; static constexpr bool DSHOT_ERROR = 1; diff --git a/examples/dshot300/dshot300.ino b/examples/dshot300/dshot300.ino index 1753da0..a6c38d3 100644 --- a/examples/dshot300/dshot300.ino +++ b/examples/dshot300/dshot300.ino @@ -10,18 +10,18 @@ #include // USB serial port settings -constexpr auto &USB_SERIAL = Serial0; -constexpr uint32_t USB_SERIAL_BAUD = 115200; +static constexpr auto &USB_SERIAL = Serial0; +static constexpr uint32_t USB_SERIAL_BAUD = 115200; // Motor configuration -constexpr gpio_num_t MOTOR01_PIN = GPIO_NUM_17; -constexpr dshot_mode_t DSHOT_MODE = DSHOT300; +static constexpr gpio_num_t MOTOR01_PIN = PIN_UART2_RX; +static constexpr dshot_mode_t DSHOT_MODE = DSHOT300; // BiDirectional DShot Support (default: false) -constexpr bool IS_BIDIRECTIONAL = false; +static constexpr bool IS_BIDIRECTIONAL = false; // Motor magnet count for RPM calculation -constexpr uint8_t MOTOR01_MAGNET_COUNT = 14; +static constexpr uint8_t MOTOR01_MAGNET_COUNT = 14; // Setup Motor Pin, DShot Mode and optional BiDirectional Support DShotRMT motor01(MOTOR01_PIN, DSHOT_MODE, IS_BIDIRECTIONAL); diff --git a/hw_defaults.h b/hw_defaults.h new file mode 100644 index 0000000..02457bb --- /dev/null +++ b/hw_defaults.h @@ -0,0 +1,36 @@ +/** + * @file hw_defaults.h + * @brief Some Shortcuts + * @author Wastl Kraus + * @date 2025-08-02 + * @license MIT + */ + +#ifdef ESP32 +// USB-Serial (UART0): GPIO1/3 in use by default + +// Serial1 +constexpr auto PIN_UART1_TX = GPIO_NUM_13; +constexpr auto PIN_UART1_RX = GPIO_NUM_14; + +// Serial2 +constexpr auto PIN_UART2_TX = GPIO_NUM_16; +constexpr auto PIN_UART2_RX = GPIO_NUM_17; + +// SPI (VSPI) +constexpr auto PIN_SPI_SCLK = GPIO_NUM_18; +constexpr auto PIN_SPI_MISO = GPIO_NUM_19; +constexpr auto PIN_SPI_MOSI = GPIO_NUM_23; +constexpr auto PIN_SPI_SS = GPIO_NUM_5; + +// I2C (Wire) +constexpr auto PIN_I2C_SDA = GPIO_NUM_21; +constexpr auto PIN_I2C_SCL = GPIO_NUM_22; + +// RMT (5 Channels) +constexpr auto PIN_RMT_CH0 = GPIO_NUM_25; +constexpr auto PIN_RMT_CH1 = GPIO_NUM_26; +constexpr auto PIN_RMT_CH2 = GPIO_NUM_27; +constexpr auto PIN_RMT_CH3 = GPIO_NUM_32; +constexpr auto PIN_RMT_CH4 = GPIO_NUM_33; +#endif // ESP32