mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
decrease freq resolution for rmt to hopefully make it more reliable
This commit is contained in:
@@ -33,12 +33,21 @@ typedef struct {
|
||||
size_t byte_index; //which byte is currently being encoded when transmitting
|
||||
uint8_t bit_index; //which bit in the `byte_index` is currently being encoded (into high/low waveforms)
|
||||
size_t num_symbols; //temp
|
||||
#ifdef NRZ_INVERTED
|
||||
bool current_level;
|
||||
uint8_t zero_count;
|
||||
#endif //NRZ_INVERTED
|
||||
} rmt_encoder_context_t;
|
||||
|
||||
//will need to keep the data alive until it has been transmitted (not working or being used atm)
|
||||
struct TxCallbackContext{
|
||||
SemaphoreHandle_t tx_done_sem;
|
||||
QueueHandle_t transmit_queue;
|
||||
rmt_encoder_context_t* tx_context;
|
||||
QueueHandle_t free_mem_queue;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t* data;
|
||||
size_t length;
|
||||
} TxBuffer;
|
||||
|
||||
typedef struct _rmt_channel{
|
||||
//TX
|
||||
uint8_t tx_gpio;
|
||||
@@ -47,6 +56,7 @@ typedef struct _rmt_channel{
|
||||
QueueHandle_t tx_queue;
|
||||
rmt_encoder_handle_t encoder; //encoder config
|
||||
rmt_encoder_context_t encoder_context;
|
||||
TxCallbackContext tx_context;
|
||||
|
||||
//RX
|
||||
uint8_t rx_gpio;
|
||||
@@ -85,6 +95,8 @@ class RMTManager{
|
||||
esp_err_t init_rx_channel();
|
||||
int decode_symbols(rmt_symbol_word_t* symbols, size_t num, rmt_symbol_word_t* decoded, size_t output_num);
|
||||
int convert_symbols_to_char(rmt_symbol_word_t* symbols, size_t num, uint8_t* string, size_t output_num);
|
||||
|
||||
[[noreturn]] static void freeMemory(void* args);
|
||||
|
||||
rmt_channel channels[MAX_CHANNELS] = {0};
|
||||
//=====================TX=====================
|
||||
@@ -102,7 +114,7 @@ class RMTManager{
|
||||
//will be used to temporarily hold the bits that are being wait to be sent -- not working
|
||||
// QueueHandle_t transmit_queue = NULL;
|
||||
|
||||
// TxCallbackContext tx_context;
|
||||
QueueHandle_t memory_to_free;
|
||||
|
||||
//=====================RX=====================
|
||||
rmt_channel_handle_t rx_chan;
|
||||
@@ -124,19 +136,6 @@ class RMTManager{
|
||||
// bool ready_to_receive = false;
|
||||
};
|
||||
|
||||
//will need to keep the data alive until it has been transmitted (not working or being used atm)
|
||||
|
||||
struct TxCallbackContext{
|
||||
SemaphoreHandle_t tx_done_sem;
|
||||
QueueHandle_t transmit_queue;
|
||||
rmt_encoder_context_t* tx_context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* data;
|
||||
size_t length;
|
||||
} TxBuffer;
|
||||
|
||||
typedef struct _gpio_channel_pair {
|
||||
gpio_num_t tx_pin;
|
||||
gpio_num_t rx_pin;
|
||||
|
||||
@@ -2,43 +2,11 @@
|
||||
|
||||
#include "driver/rmt_tx.h"
|
||||
|
||||
// #ifdef MANCHESTER_40
|
||||
// #define RMT_RESOLUTION_HZ 40 * 1000 * 1000 // 40MHz resolution
|
||||
// #define RMT_DURATION_SYMBOL 10 //0.25 us bit duration
|
||||
// #elif NRZ_INVERTED
|
||||
// #ifdef NRZ_INVERTED_40_HZ
|
||||
// #define RMT_RESOLUTION_HZ 40 * 1000 * 1000 // 40MHz resolution
|
||||
// #else
|
||||
// #define RMT_RESOLUTION_HZ 20 * 1000 * 1000 // 20MHz resolution
|
||||
// #endif //NRZ_INVERTED_40_HZ
|
||||
// #ifdef NRZ_INVERTED_10
|
||||
// #define RMT_DURATION_SYMBOL 10 //0.5us bit duration
|
||||
// #elif NRZ_INVERTED_20
|
||||
// #define RMT_DURATION_SYMBOL 5 //0.25 us bit duration
|
||||
// #elif NRZ_INVERTED_2
|
||||
// #define RMT_DURATION_SYMBOL 2 //0.1 us bit duration
|
||||
// #else
|
||||
// #define RMT_DURATION_SYMBOL 20 //1us bit duration
|
||||
// #endif //NRZ_INVERTED_10
|
||||
// #else
|
||||
// #define RMT_RESOLUTION_HZ 1 * 1000 * 1000 // 1MHz resolution
|
||||
// #define RMT_DURATION_SYMBOL 10
|
||||
// #endif //MANCHESTER_40
|
||||
|
||||
// #define NRZ_INVERTED //using NRZ_I
|
||||
#define RMT_RESOLUTION_HZ 40 * 1000 * 1000 // 40MHz resolution
|
||||
#define RMT_DURATION_SYMBOL 12 //0.6us
|
||||
|
||||
|
||||
// #define RMT_DURATION_SYMBOL ((RMT_RESOLUTION_HZ * 3) / 1000000) // duration time for a symbol - this is 3us
|
||||
#define RMT_RESOLUTION_HZ 3 * 1000 * 1000 // 3MHz resolution
|
||||
#define RMT_DURATION_SYMBOL 1 //0.667us
|
||||
|
||||
#define RMT_DURATION_MAX (2 * RMT_DURATION_SYMBOL)
|
||||
|
||||
// #define RMT_TX_GPIO GPIO_NUM_1 //RMT will use GPIO pin 1 to transmit (on one channel)
|
||||
|
||||
// #define RMT_RX_GPIO GPIO_NUM_12 // RMT will use GPIO pin 12 to receive (on one channel)
|
||||
|
||||
#ifndef NRZ_INVERTED
|
||||
//MANCHESTER ENCODING (ETHERNET STANDARD)
|
||||
|
||||
/**
|
||||
@@ -62,60 +30,6 @@ static const rmt_symbol_word_t RMT_SYMBOL_ZERO = {
|
||||
.duration1 = RMT_DURATION_SYMBOL,
|
||||
.level1 = 1,
|
||||
};
|
||||
#else
|
||||
|
||||
//Non-Return-to-Zero Inverted (NRZ-I)
|
||||
|
||||
#define CONSEC_ZERO_THRESHOLD 3 //max number of consecutive zeros before adding a bit 1
|
||||
|
||||
// Logic 1 inverts the current voltage state
|
||||
|
||||
/**
|
||||
* @brief This struct represents a 1 symbol being transmitted over RMT. This will create a falling edge (low for `RMT_DURATION_SYMBOL` and high for `RMT_DURATION_SYMBOL`)
|
||||
*
|
||||
*/
|
||||
static const rmt_symbol_word_t RMT_SYMBOL_ONE_FALLING = {
|
||||
.duration0 = RMT_DURATION_SYMBOL,
|
||||
.level0 = 1,
|
||||
.duration1 = RMT_DURATION_SYMBOL,
|
||||
.level1 = 0,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This struct represents a 1 symbol being transmitted over RMT. This will create a rising edge (low for `RMT_DURATION_SYMBOL` and high for `RMT_DURATION_SYMBOL`)
|
||||
*
|
||||
*/
|
||||
static const rmt_symbol_word_t RMT_SYMBOL_ONE_RISING = {
|
||||
.duration0 = RMT_DURATION_SYMBOL,
|
||||
.level0 = 0,
|
||||
.duration1 = RMT_DURATION_SYMBOL,
|
||||
.level1 = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This struct will represent a bit 0. In NRZ-I, this represents a no change in the voltage
|
||||
*
|
||||
*/
|
||||
static const rmt_symbol_word_t RMT_SYMBOL_ZERO_HIGH = {
|
||||
.duration0 = RMT_DURATION_SYMBOL,
|
||||
.level0 = 1,
|
||||
.duration1 = RMT_DURATION_SYMBOL,
|
||||
.level1 = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This struct will represent a bit 0. In NRZ-I, this represents a no change in the voltage
|
||||
*
|
||||
*/
|
||||
static const rmt_symbol_word_t RMT_SYMBOL_ZERO_LOW = {
|
||||
.duration0 = RMT_DURATION_SYMBOL,
|
||||
.level0 = 0,
|
||||
.duration1 = RMT_DURATION_SYMBOL,
|
||||
.level1 = 0,
|
||||
};
|
||||
|
||||
|
||||
#endif //NRZ_INVERTED
|
||||
|
||||
//not used at the moment
|
||||
|
||||
|
||||
Reference in New Issue
Block a user