Fix RIP bugs, add in UART

This commit is contained in:
Johnathon Slightham
2026-03-31 14:26:37 -04:00
committed by Johnathon Slightham
parent d4602012f1
commit 548e8db484
26 changed files with 704 additions and 434 deletions

View File

@@ -9,8 +9,11 @@
#include "driver/rmt_tx.h"
#include "driver/rmt_rx.h"
#include "soc/gpio_num.h"
#include "IPhysicalLayer.h"
#ifndef MAX_CHANNELS
#define MAX_CHANNELS 4
#endif
#define RMT_SYMBOL_BLOCK_SIZE 48
#define RECEIVE_BUFFER_SIZE 1024 //this is some value (we should probably set it to some packet size that we predetermine in some custom protocol:tm:)
@@ -74,12 +77,12 @@ typedef struct _rmt_channel{
* @author Justin Chow
*
*/
class RMTManager{
class RMTManager : public IPhysicalLayer {
public:
RMTManager(uint8_t num_channels);
~RMTManager();
esp_err_t send(uint8_t* data, size_t size, rmt_transmit_config_t* config, uint8_t channel_num); //temp function to send some string data
esp_err_t receive(uint8_t* recv_buf, size_t size, size_t* output_size, uint8_t channel_num);
~RMTManager() override;
esp_err_t send(uint8_t* data, size_t size, void* config, uint8_t channel_num) override;
esp_err_t receive(uint8_t* recv_buf, size_t size, size_t* output_size, uint8_t channel_num) override;
static size_t encoder_callback(const void* data, size_t data_size, size_t symbols_written,
size_t symbols_free, rmt_symbol_word_t* symbols, bool* done, void* arg);
@@ -87,9 +90,9 @@ class RMTManager{
static bool rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *edata, void *user_data);
static bool rmt_tx_done_callback(rmt_channel_handle_t channel, const rmt_tx_done_event_data_t *edata, void *user_data);
esp_err_t start_receiving(uint8_t channel_num);
esp_err_t start_receiving(uint8_t channel_num) override;
esp_err_t wait_until_send_complete(uint8_t channel_num);
esp_err_t wait_until_send_complete(uint8_t channel_num) override;
private:
uint8_t num_channels; //number of channels initalized
@@ -107,21 +110,21 @@ class RMTManager{
// rmt_channel_handle_t tx_chan;
const gpio_num_t tx_gpio[MAX_CHANNELS] = {GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_11, GPIO_NUM_13}; //using pins 4,5,11,13 for channels 0,1,2,3 respectively for tx
const gpio_num_t tx_gpio[MAX_CHANNELS] = {GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_11, GPIO_NUM_13};
QueueHandle_t memory_to_free;
//=====================RX=====================
rmt_channel_handle_t rx_chan;
const gpio_num_t rx_gpio[MAX_CHANNELS] = {GPIO_NUM_3, GPIO_NUM_6, GPIO_NUM_12, GPIO_NUM_14}; //using pins 3,6,12,14 for channels 0,1,2,3 respectively for rx
const gpio_num_t rx_gpio[MAX_CHANNELS] = {GPIO_NUM_3, GPIO_NUM_6, GPIO_NUM_12, GPIO_NUM_14};
//rx_receive_config
rmt_receive_config_t receive_config = {
.signal_range_min_ns = 200,
.signal_range_max_ns = 200 * 1000,
.flags = {
.en_partial_rx = true
.en_partial_rx = false // frames are max 121B = ~968 symbols, well within the 1024-symbol buffer
}
};
@@ -135,22 +138,21 @@ typedef struct _gpio_channel_pair {
static const GPIO_Channel_Pair gpio_channel_pairs[MAX_CHANNELS] = {
{
.tx_pin = GPIO_NUM_1,
.tx_pin = GPIO_NUM_4,
.rx_pin = GPIO_NUM_3
},
{
.tx_pin = GPIO_NUM_5,
.rx_pin = GPIO_NUM_6
},
{
.tx_pin = GPIO_NUM_11,
.rx_pin = GPIO_NUM_12
},
{
.tx_pin = GPIO_NUM_2,
.rx_pin = GPIO_NUM_13
},
{
.tx_pin = GPIO_NUM_3,
.rx_pin = GPIO_NUM_14
},
{
.tx_pin = GPIO_NUM_4,
.rx_pin = GPIO_NUM_15
.rx_pin = GPIO_NUM_14
}
}; //todo: use these pairs directly instead of the two arrays in the class definition above
// but ensure to update them first!!!
#endif //RMT_COMMUNICATIONS