UART rework

many possible problems fixed in preparation for thread-safe
This commit is contained in:
me-no-dev
2016-10-14 03:02:40 +03:00
parent 50b060ab32
commit 17c8ceb1b9
4 changed files with 153 additions and 132 deletions

View File

@ -19,10 +19,9 @@
extern "C" {
#endif
#include "esp32-hal.h"
#include "soc/uart_struct.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#define SERIAL_5N1 0x8000010
#define SERIAL_6N1 0x8000014
@ -49,17 +48,8 @@ extern "C" {
#define SERIAL_7O2 0x800003b
#define SERIAL_8O2 0x800003f
typedef struct {
uart_dev_t * dev;
xQueueHandle queue;
uint32_t baud_rate;
uint8_t num;
int8_t rxPin;
int8_t txPin;
bool rxEnabled;
bool txEnabled;
bool inverted;
} uart_t;
struct uart_struct_t;
typedef struct uart_struct_t uart_t;
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted);
void uartEnd(uart_t* uart);
@ -67,8 +57,10 @@ void uartEnd(uart_t* uart);
uint32_t uartAvailable(uart_t* uart);
uint8_t uartRead(uart_t* uart);
uint8_t uartPeek(uart_t* uart);
void uartWrite(uart_t* uart, uint8_t c);
void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len);
void uartFlush(uart_t* uart);
void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);