Make Uart driver universal
This commit is contained in:
@@ -18,57 +18,55 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stm32/stm32f4xx.h>
|
||||
#include <stm-periph/dma-ring-buffer.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef UART_UART_H_
|
||||
#define UART_UART_H_
|
||||
|
||||
#define UART_RECEIVE_DMA_STREAM DMA2_Stream5
|
||||
struct stm_uart {
|
||||
USART_TypeDef *uart_dev;
|
||||
uint32_t brr_val;
|
||||
uint8_t base_dma_num;
|
||||
DMA_Stream_TypeDef *dma_tx_stream;
|
||||
uint8_t dma_tx_trigger_channel;
|
||||
DMA_Stream_TypeDef *dma_rx_stream;
|
||||
uint8_t dma_rx_trigger_channel;
|
||||
char *dma_rx_buff;
|
||||
char *dma_tx_buff;
|
||||
size_t rx_buff_count;
|
||||
size_t tx_buff_count;
|
||||
volatile uint32_t *rcc_reg;
|
||||
uint8_t rcc_bit_no;
|
||||
struct dma_ring_buffer_to_mem rx_ring_buff;
|
||||
struct dma_ring_buffer_to_periph tx_ring_buff;
|
||||
uint8_t tx : 1;
|
||||
uint8_t rx : 1;
|
||||
};
|
||||
|
||||
#define UART_SEND_DMA_STREAM DMA2_Stream7
|
||||
int uart_init(struct stm_uart *uart);
|
||||
|
||||
#define UART_PERIPH USART1
|
||||
#define UART_RCC_MASK RCC_APB2ENR_USART1EN
|
||||
void uart_disable(struct stm_uart *uart);
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
void uart_send_char(struct stm_uart *uart, char c);
|
||||
|
||||
#define UART_PORT GPIOA
|
||||
#define UART_PORT_RCC_MASK RCC_AHB1ENR_GPIOAEN
|
||||
#define UART_RX_PIN 10
|
||||
#define UART_TX_PIN 9
|
||||
#define UART_RX_PIN_ALTFUNC 7
|
||||
#define UART_TX_PIN_ALTFUNC 7
|
||||
#else
|
||||
void uart_send_array(struct stm_uart *uart, const char *data, uint32_t len);
|
||||
|
||||
#endif
|
||||
void uart_send_string(struct stm_uart *uart, const char *string);
|
||||
|
||||
/* UART_DIV is 45.5625 => 115200 @ 84 MHz */
|
||||
#define UART_DIV_FRACTION 9U /* Equals 9/16 = 0.5625 */
|
||||
#define UART_DIV_MANTISSA 45U /* Equals 45 */
|
||||
void uart_send_array_with_dma(struct stm_uart *uart, const char *data, uint32_t len);
|
||||
|
||||
#define UART_BRR_REG_VALUE ((UART_DIV_MANTISSA<<4) | UART_DIV_FRACTION);
|
||||
void uart_send_string_with_dma(struct stm_uart *uart, const char *string);
|
||||
|
||||
void initUART();
|
||||
void sendChar(char c);
|
||||
void sendString(char* s, int count);
|
||||
int uart_receive_data_with_dma(struct stm_uart *uart, const char **data, size_t *len);
|
||||
|
||||
char uart_get_char(struct stm_uart *uart);
|
||||
|
||||
void uart_init_with_dma();
|
||||
int uart_check_rx_avail(struct stm_uart *uart);
|
||||
|
||||
void uart_disable();
|
||||
|
||||
void uart_send_char(char c);
|
||||
|
||||
void uart_send_array(const char *data, uint32_t len);
|
||||
|
||||
void uart_send_string(const char *string);
|
||||
|
||||
void uart_send_array_with_dma(const char *data, uint32_t len);
|
||||
|
||||
void uart_send_string_with_dma(const char *string);
|
||||
|
||||
int uart_receive_data_with_dma(const char **data, size_t *len);
|
||||
void uart_tx_dma_complete_int_callback(struct stm_uart *uart);
|
||||
|
||||
|
||||
#endif /* UART_UART_H_ */
|
||||
|
Reference in New Issue
Block a user