...restructure for rework
This commit is contained in:
parent
85814f39be
commit
873b228d59
|
|
@ -1,3 +1,5 @@
|
||||||
|
.vs
|
||||||
|
.vscode
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
|
|
@ -12,4 +14,4 @@
|
||||||
*.vsix
|
*.vsix
|
||||||
|
|
||||||
# Caching ESP32 Builds
|
# Caching ESP32 Builds
|
||||||
buildCache/*
|
buildCache
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Source: https://github.com/bitdump/BLHeli/blob/master/BLHeli_S%20SiLabs/Dshotprog%20spec%20BLHeli_S.txt
|
|
||||||
// Date: 04.07.2021
|
|
||||||
|
|
||||||
enum dshot_cmd_t
|
|
||||||
{
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
@ -33,7 +33,7 @@ DShotRMT::~DShotRMT()
|
||||||
rmt_driver_uninstall(dshot_config.rmt_channel);
|
rmt_driver_uninstall(dshot_config.rmt_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
DShotRMT::DShotRMT(DShotRMT const &)
|
DShotRMT::DShotRMT(DShotRMT const&)
|
||||||
{
|
{
|
||||||
// ...write me
|
// ...write me
|
||||||
}
|
}
|
||||||
|
|
@ -133,18 +133,18 @@ void DShotRMT::send_dshot_value(uint16_t throttle_value, telemetric_request_t te
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...get all setup data about current mode
|
// ...get all setup data about current mode
|
||||||
dshot_config_t *DShotRMT::get_dshot_info()
|
dshot_config_t* DShotRMT::get_dshot_info()
|
||||||
{
|
{
|
||||||
return &dshot_config;
|
return &dshot_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...get the ABP_Clock Divider for further calculations
|
// ...get the ABP_Clock Divider for further calculations
|
||||||
uint8_t *DShotRMT::get_dshot_clock_div()
|
uint8_t* DShotRMT::get_dshot_clock_div()
|
||||||
{
|
{
|
||||||
return &dshot_config.clk_div;
|
return &dshot_config.clk_div;
|
||||||
}
|
}
|
||||||
|
|
||||||
rmt_item32_t *DShotRMT::encode_dshot_to_rmt(uint16_t parsed_packet)
|
rmt_item32_t* DShotRMT::encode_dshot_to_rmt(uint16_t parsed_packet)
|
||||||
{
|
{
|
||||||
// ...is bidirecional mode activated
|
// ...is bidirecional mode activated
|
||||||
if (dshot_config.bidirectional)
|
if (dshot_config.bidirectional)
|
||||||
|
|
@ -212,7 +212,7 @@ rmt_item32_t *DShotRMT::encode_dshot_to_rmt(uint16_t parsed_packet)
|
||||||
|
|
||||||
// ...just returns the checksum
|
// ...just returns the checksum
|
||||||
// DOES NOT APPEND CHECKSUM!!!
|
// DOES NOT APPEND CHECKSUM!!!
|
||||||
uint16_t DShotRMT::calc_dshot_chksum(const dshot_packet_t &dshot_packet)
|
uint16_t DShotRMT::calc_dshot_chksum(const dshot_packet_t& dshot_packet)
|
||||||
{
|
{
|
||||||
// ...start with two emprty "container"
|
// ...start with two emprty "container"
|
||||||
uint16_t packet = DSHOT_NULL_PACKET;
|
uint16_t packet = DSHOT_NULL_PACKET;
|
||||||
|
|
@ -235,7 +235,7 @@ uint16_t DShotRMT::calc_dshot_chksum(const dshot_packet_t &dshot_packet)
|
||||||
return chksum;
|
return chksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t DShotRMT::prepare_rmt_data(const dshot_packet_t &dshot_packet)
|
uint16_t DShotRMT::prepare_rmt_data(const dshot_packet_t& dshot_packet)
|
||||||
{
|
{
|
||||||
uint16_t prepared_to_encode = DSHOT_NULL_PACKET;
|
uint16_t prepared_to_encode = DSHOT_NULL_PACKET;
|
||||||
uint16_t chksum = calc_dshot_chksum(dshot_packet);
|
uint16_t chksum = calc_dshot_chksum(dshot_packet);
|
||||||
|
|
@ -248,7 +248,7 @@ uint16_t DShotRMT::prepare_rmt_data(const dshot_packet_t &dshot_packet)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...finally output using ESP32 RMT
|
// ...finally output using ESP32 RMT
|
||||||
void DShotRMT::output_rmt_data(const dshot_packet_t &dshot_packet)
|
void DShotRMT::output_rmt_data(const dshot_packet_t& dshot_packet)
|
||||||
{
|
{
|
||||||
encode_dshot_to_rmt(prepare_rmt_data(dshot_packet));
|
encode_dshot_to_rmt(prepare_rmt_data(dshot_packet));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,16 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BlheliCmdMap.h"
|
#ifndef _DSHOTRMT_h
|
||||||
#include <Arduino.h>
|
#define _DSHOTRMT_h
|
||||||
|
|
||||||
// ...utilizing the IR Module library for generating the DShot signal
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
|
#include "arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ...utilizing the RMT Module library for generating the DShot signal
|
||||||
#include <driver/rmt.h>
|
#include <driver/rmt.h>
|
||||||
|
|
||||||
constexpr auto DSHOT_CLK_DIVIDER = 8; // ...slow down RMT clock to 0.1 microseconds / 100 nanoseconds per cycle
|
constexpr auto DSHOT_CLK_DIVIDER = 8; // ...slow down RMT clock to 0.1 microseconds / 100 nanoseconds per cycle
|
||||||
|
|
@ -36,12 +42,12 @@ typedef enum dshot_mode_e
|
||||||
} dshot_mode_t;
|
} dshot_mode_t;
|
||||||
|
|
||||||
// ...to get human readable DShot Mode
|
// ...to get human readable DShot Mode
|
||||||
static const char *const dshot_mode_name[] = {
|
static const char* const dshot_mode_name[] = {
|
||||||
"DSHOT_OFF",
|
"DSHOT_OFF",
|
||||||
"DSHOT150",
|
"DSHOT150",
|
||||||
"DSHOT300",
|
"DSHOT300",
|
||||||
"DSHOT600",
|
"DSHOT600",
|
||||||
"DSHOT1200"};
|
"DSHOT1200" };
|
||||||
|
|
||||||
typedef String dshot_name_t;
|
typedef String dshot_name_t;
|
||||||
|
|
||||||
|
|
@ -86,27 +92,29 @@ typedef struct dshot_config_s
|
||||||
|
|
||||||
class DShotRMT
|
class DShotRMT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DShotRMT(gpio_num_t gpio, rmt_channel_t rmtChannel);
|
DShotRMT(gpio_num_t gpio, rmt_channel_t rmtChannel);
|
||||||
DShotRMT(uint8_t pin, uint8_t channel);
|
DShotRMT(uint8_t pin, uint8_t channel);
|
||||||
~DShotRMT();
|
~DShotRMT();
|
||||||
DShotRMT(DShotRMT const &);
|
DShotRMT(DShotRMT const&);
|
||||||
|
|
||||||
// ...safety first ...no parameters, no DShot
|
// ...safety first ...no parameters, no DShot
|
||||||
bool begin(dshot_mode_t dshot_mode = DSHOT_OFF, bool is_bidirectional = false);
|
bool begin(dshot_mode_t dshot_mode = DSHOT_OFF, bool is_bidirectional = false);
|
||||||
void send_dshot_value(uint16_t throttle_value, telemetric_request_t telemetric_request = NO_TELEMETRIC);
|
void send_dshot_value(uint16_t throttle_value, telemetric_request_t telemetric_request = NO_TELEMETRIC);
|
||||||
|
|
||||||
dshot_config_t *get_dshot_info();
|
dshot_config_t* get_dshot_info();
|
||||||
uint8_t *get_dshot_clock_div();
|
uint8_t* get_dshot_clock_div();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rmt_item32_t dshot_tx_rmt_item[DSHOT_PACKET_LENGTH];
|
rmt_item32_t dshot_tx_rmt_item[DSHOT_PACKET_LENGTH];
|
||||||
rmt_config_t dshot_tx_rmt_config;
|
rmt_config_t dshot_tx_rmt_config;
|
||||||
dshot_config_t dshot_config;
|
dshot_config_t dshot_config;
|
||||||
|
|
||||||
rmt_item32_t *encode_dshot_to_rmt(uint16_t parsed_packet);
|
rmt_item32_t* encode_dshot_to_rmt(uint16_t parsed_packet);
|
||||||
uint16_t calc_dshot_chksum(const dshot_packet_t &dshot_packet);
|
uint16_t calc_dshot_chksum(const dshot_packet_t& dshot_packet);
|
||||||
uint16_t prepare_rmt_data(const dshot_packet_t &dshot_packet);
|
uint16_t prepare_rmt_data(const dshot_packet_t& dshot_packet);
|
||||||
|
|
||||||
void output_rmt_data(const dshot_packet_t &dshot_packet);
|
void output_rmt_data(const dshot_packet_t& dshot_packet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue