43 lines
870 B
C
43 lines
870 B
C
#ifndef UART_H
|
|
#define UART_H
|
|
|
|
#include "freertos/idf_additions.h"
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#define UART_NUM UART_NUM_1
|
|
#define UART_BUF_SIZE 256
|
|
#define UART_TXD_PIN 2
|
|
#define UART_RXD_PIN 3
|
|
|
|
#define START_MARKER 0xAA
|
|
#define STOP_MARKER 0xCC
|
|
#define MAX_BUF_SIZE 256
|
|
#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);
|
|
|
|
#endif
|