/* * comport.h * * Created on: Feb 15, 2023 * Author: Think */ #ifndef INC_COMPORT_H_ #define INC_COMPORT_H_ /* Library includes. */ #include "stm32l4xx_hal.h" /* Demo application includes. */ #include #include "usart.h" #include "ringbuf.h" #define COMM_RXBUFSIZE 1024 typedef struct comport_s { int fd; /* compatible with Linux API */ char devname[32]; /* UART device name */ UART_HandleTypeDef *huart; /* STM32 UART Handler */ uint8_t *rxch; /* receive data in interrupt handler */ ring_buffer_t rb; /* receive data ring buffer */ } comport_t; comport_t *comport_init(UART_HandleTypeDef *huart, uint8_t *rxch, uint8_t *rxbuf, size_t size); comport_t *comport_open(UART_HandleTypeDef *huart); void comport_flush(comport_t *comport); extern int comport_send(comport_t *comport, char *data, int bytes); extern int comport_recv(comport_t *comport, char *buf, int size, uint32_t timeout); extern void comport_term(comport_t *comport); extern comport_t *rs485_open(UART_HandleTypeDef *huart); extern int rs485_send(comport_t *comport, char *data, int bytes); extern int rs485_recv(comport_t *comport, char *buf, int size, uint32_t timeout); extern void rs485_term(comport_t *comport); #endif /* INC_WIRED_H_ */