#pragma once #include #if defined(__USART_BUFFER__) // buffer based i/o #else #include #endif #include #include #define USART_5BIT 0x0100 #define USART_6BIT 0x0200 #define USART_7BIT 0x0400 #define USART_8BIT 0x0800 #define USART_PAR_E 0x1000 #define USART_PAR_O 0x2000 #define USART_STOP2 0x4000 #define USART_MODE_TX (1<<0) #define USART_MODE_RX (1<<1) typedef struct __io_usart usart_t; struct __io_usart { int (*configure) (usart_t *usart,uint32_t baud,uint32_t config); int (*mode_set) (usart_t *usart,uint16_t mode); int (*mode_clear) (usart_t *usart,uint16_t mode); #if defined(__USART_BUFFER__) // buffer based i/o buffer_t tx, rx; #else // fifo based i/o #define usart_fifo_t fifo64_t #define usart_fifo_read f64_read #define usart_fifo_write f64_write usart_fifo_t tx, rx; #endif uint8_t driverdata[0]; }; usart_t* usart_device_get(int usart); int usart_configure (uint8_t usart,uint32_t baud,uint32_t config); int usart_options (uint8_t usart,uint8_t options); #define usart_tx_str(u,t) usart_tx(u,t,strlen(t)) #if defined(__USART_BUFFER__) int usart_tx (uint8_t usart,void *data,int size); int usart_tx_done (uint8_t usart); int usart_rx (uint8_t usart,void *data,int size); int usart_rx_done (uint8_t usart); #else int usart_read (uint8_t usart); int usart_write (uint8_t usart,int ch); int usart_tx (uint8_t usart,char *b,int size); #endif