...start again

This commit is contained in:
Wastl Kraus 2024-02-11 10:44:56 +01:00
parent a669eb3759
commit 7d64234471
2 changed files with 82 additions and 23 deletions

View File

@ -32,6 +32,19 @@ DShotRMT::DShotRMT(uint8_t pin, uint8_t channel)
buildTxRmtItem(DSHOT_NULL_PACKET);
}
// ...simplest but only for testing
DShotRMT::DShotRMT(uint8_t pin)
{
// Initialize the dshot_config structure with the arguments passed to the constructor
dshot_config.gpio_num = static_cast<gpio_num_t>(pin);
dshot_config.pin_num = pin;
dshot_config.rmt_channel = static_cast<rmt_channel_t>(RMT_CHANNEL_MAX -1);
dshot_config.mem_block_num = RMT_CHANNEL_MAX - 1;
// Create an empty packet using the DSHOT_NULL_PACKET and the buildTxRmtItem function
buildTxRmtItem(DSHOT_NULL_PACKET);
}
DShotRMT::~DShotRMT()
{
// Uninstall the RMT driver

View File

@ -67,6 +67,17 @@ typedef struct eRPM_packet_s
uint8_t checksum : 4;
} eRPM_packet_t;
// return states of the RPM getting function
typedef enum dshot_erpm_exit_mode_e
{
DECODE_SUCCESS = 0,
ERR_EMPTY_QUEUE,
ERR_NO_PACKETS,
ERR_CHECKSUM_FAIL,
ERR_BIDIRECTION_DISABLED,
} dshot_erpm_exit_mode_t;
// Structure for all settings for the DShot mode
typedef struct dshot_config_s
{
@ -88,32 +99,66 @@ typedef struct dshot_config_s
// The official DShot Commands
typedef enum dshot_cmd_e
{
DSHOT_CMD_MOTOR_STOP = 0, // 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_MOTOR_STOP = 0, // 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_36, // Not yet assigned
DSHOT_CMD_37, // Not yet assigned
DSHOT_CMD_38, // Not yet assigned
DSHOT_CMD_39, // Not yet assigned
DSHOT_CMD_40, // Not yet assigned
DSHOT_CMD_41, // Not yet assigned
DSHOT_CMD_SIGNAL_LINE_TEMPERATURE_TELEMETRY, // No wait required
DSHOT_CMD_SIGNAL_LINE_VOLTAGE_TELEMETRY, // No wait required
DSHOT_CMD_SIGNAL_LINE_CURRENT_TELEMETRY, // No wait required
DSHOT_CMD_SIGNAL_LINE_CONSUMPTION_TELEMETRY, // No wait required
DSHOT_CMD_SIGNAL_LINE_ERPM_TELEMETRY, // No wait required
DSHOT_CMD_SIGNAL_LINE_ERPM_PERIOD_TELEMETRY, // No wait required (also command 47)
DSHOT_CMD_MAX = 47
} dshot_cmd_t;
// ...Mapping for GCR
static const unsigned char GCR_encode[16] =
{
0x19, 0x1B, 0x12, 0x13,
0x1D, 0x15, 0x16, 0x17,
0x1A, 0x09, 0x0A, 0x0B,
0x1E, 0x0D, 0x0E, 0x0F};
// ...shifting 5 bits > 4 bits (0xff => invalid)
static const unsigned char GCR_decode[32] =
{
0xFF, 0xFF, 0xFF, 0xFF, // 0 - 3
0xFF, 0xFF, 0xFF, 0xFF, // 4 - 7
0xFF, 9, 10, 11, // 8 - 11
0xFF, 13, 14, 15, // 12 - 15
0xFF, 0xFF, 2, 3, // 16 - 19
0xFF, 5, 6, 7, // 20 - 23
0xFF, 0, 8, 1, // 24 - 27
0xFF, 4, 12, 0xFF, // 28 - 31
};
// The main DShotRMT class
class DShotRMT
{
@ -121,6 +166,7 @@ public:
// Constructor for the DShotRMT class
DShotRMT(gpio_num_t gpio, rmt_channel_t rmtChannel);
DShotRMT(uint8_t pin, uint8_t channel);
DShotRMT(uint8_t pin);
// Destructor for the DShotRMT class
~DShotRMT();