#pragma once #include #include #include #define SERIAL_5BIT 0x0100 #define SERIAL_6BIT 0x0200 #define SERIAL_7BIT 0x0400 #define SERIAL_8BIT 0x0800 #define SERIAL_PAR_E 0x1000 #define SERIAL_PAR_O 0x2000 #define SERIAL_STOP2 0x4000 struct avr_serial; typedef struct avr_serial avrSerial; typedef void (*serial_cb_rx)(void *arg,uint8_t ch); /** * @class avr_serial * @author Harald Wolff * @date * @file serial.h * @brief Structure for serial device */ struct avr_serial { avrSerial* next; uint8_t (*init)(avrSerial* serial,uint32_t baudrate,uint32_t config); // Setup Port void (*notify)(avrSerial* serial); // Notify of new byte to send in fifo_tx void (*flush)(avrSerial *serial); // Warten bis alle Zeichen gesendet wurden /* void (*tx)(avrSerial* serial,uint8_t byte); uint16_t (*rx)(avrSerial* serial); */ FIFO* fifo_tx; FIFO* fifo_rx; void* driver; }; extern avrSerial* _serial_head; void serial_register(avrSerial* serial); void usart_register(void); uint8_t serial_init(avrSerial* serial,uint32_t baudrate,uint32_t config); void serial_tx_byte(avrSerial* serial,uint8_t byte); void serial_tx_string(avrSerial* serial,char* string); void serial_tx(avrSerial* serial,uint8_t* data,uint8_t len); void serial_flush(avrSerial *serial); uint16_t serial_rx_byte(avrSerial* serial); uint16_t serial_rx_line(avrSerial* serial,char* buffer,uint8_t maxlen); uint16_t serial_rx(avrSerial* serial,uint8_t* buffer,uint8_t len); uint16_t serial_poll_byte(avrSerial* serial); uint16_t serial_rxready(avrSerial* serial); avrSerial* serial_get(uint8_t no); avrSerial* serial_null(void); FILE* serial_build_stream(avrSerial* serial); void serial_set_blocking(avrSerial *serial,uint8_t blocking); void serial_set_timeout(avrSerial *serial,uint16_t timeout);