powerpods/main/uart.h

55 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef UART_H
#define UART_H
#include "esp_err.h"
#include "freertos/idf_additions.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define UART_NUM UART_NUM_1
#define UART_BAUD_RATE 921600
// #define UART_TXD_PIN 3
// #define UART_RXD_PIN 2
#define UART_TXD_PIN 2
#define UART_RXD_PIN 3
#define UART_BUF_SIZE 4096
/** Driver RX ring — must hold a full OTA block burst (~20 × ~215 B frames). */
#define UART_DRIVER_RX_BUF_SIZE 16384
#define UART_DRIVER_TX_BUF_SIZE 4096
#define START_MARKER 0xAA
#define STOP_MARKER 0xCC
#define MAX_BUF_SIZE 252
#define MAX_PAYLOAD_SIZE \
MAX_BUF_SIZE - 4 // Buffer overhead, Start, Len, CRC, End
typedef enum {
STATE_START,
STATE_LEN,
STATE_DATA,
STATE_CHECKSUM,
STATE_STOP
} parser_state_t;
typedef struct {
uint8_t payload[MAX_PAYLOAD_SIZE];
uint8_t len;
uint8_t index;
uint8_t checksum;
parser_state_t state;
} uart_packet_t;
typedef struct {
uint8_t cmd;
} uart_command_t;
void init_uart(QueueHandle_t cmd_queue);
void uart_read_task(void *param);
bool parse_uart_byte(uint8_t byte, uart_packet_t *p);
esp_err_t uart_send_framed(const uint8_t *payload, size_t len);
#endif