libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
uart.h
Go to the documentation of this file.
1/*
2TODO
3- Overflow handling, etc. for Rx Queue.
4*/
5
6#pragma once
7#ifndef DSY_UART_H
8#define DSY_UART_H
9#include "daisy_core.h"
10
11#if !UNIT_TEST
12#include "util/hal_map.h"
13#endif
14
15namespace daisy
16{
27{
28 public:
29 struct Config
30 {
31 enum class Peripheral
32 {
33 USART_1,
34 USART_2,
35 USART_3,
36 UART_4,
37 UART_5,
38 USART_6,
39 UART_7,
40 UART_8,
42 };
43
44 enum class StopBits
45 {
47 BITS_1,
49 BITS_2,
50 };
51
52 enum class Parity
53 {
54 NONE,
55 EVEN,
56 ODD,
57 };
58
59 enum class Mode
60 {
61 RX,
62 TX,
63 TX_RX,
64 };
65
66 enum class WordLength
67 {
68 BITS_7,
69 BITS_8,
70 BITS_9,
71 };
72
73 struct
74 {
80 {
81 // user must init periph, pin_config, and mode
85 baudrate = 31250;
86 }
87
94 };
95
96
97 UartHandler() : pimpl_(nullptr) {}
98 UartHandler(const UartHandler& other) = default;
100
102 enum class Result
103 {
104 OK,
105 ERR
106 };
107
108 enum class DmaDirection
109 {
110 RX,
111 TX
112 };
113
116
118 const Config& GetConfig() const;
119
121 typedef void (*StartCallbackFunctionPtr)(void* context);
123 typedef void (*EndCallbackFunctionPtr)(void* context, Result result);
124
137 size_t size,
138 void* context,
139 Result result);
140
148
155 Result
157
169 size_t size,
172 void* callback_context);
173
185 size_t size,
188 void* callback_context);
189
205 size_t size,
207 void* callback_context);
208
211
213 bool IsListening() const;
214
217
219 int PollReceive(uint8_t* buff, size_t size, uint32_t timeout);
220
223
224 class Impl;
226 private:
227 Impl* pimpl_;
228};
229
230extern "C"
231{
234};
235
237} // namespace daisy
238
239#endif
Definition leddriver.h:33
Definition uart.h:27
void(* EndCallbackFunctionPtr)(void *context, Result result)
Definition uart.h:123
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result DmaTransmit(uint8_t *buff, size_t size, UartHandler::StartCallbackFunctionPtr start_callback, UartHandler::EndCallbackFunctionPtr end_callback, void *callback_context)
bool IsListening() const
Result DmaListenStart(uint8_t *buff, size_t size, CircularRxCallbackFunctionPtr cb, void *callback_context)
const Config & GetConfig() const
UartHandler(const UartHandler &other)=default
void(* StartCallbackFunctionPtr)(void *context)
Definition uart.h:121
Result PollTx(uint8_t *buff, size_t size)
void(* CircularRxCallbackFunctionPtr)(uint8_t *data, size_t size, void *context, Result result)
Definition uart.h:136
int PollReceive(uint8_t *buff, size_t size, uint32_t timeout)
Result Init(const Config &config)
Result BlockingReceive(uint8_t *buffer, uint16_t size, uint32_t timeout=100)
Result DmaListenStop()
Result
Definition uart.h:103
UartHandler()
Definition uart.h:97
DmaDirection
Definition uart.h:109
UartHandler & operator=(const UartHandler &other)=default
Result DmaReceive(uint8_t *buff, size_t size, UartHandler::StartCallbackFunctionPtr start_callback, UartHandler::EndCallbackFunctionPtr end_callback, void *callback_context)
void dsy_uart_global_init()
Hardware defines and helpers for daisy field platform.
Definition index.h:2
representation of hardware port/pin combination
Definition daisy_core.h:193
Definition uart.h:30
Pin rx
Definition uart.h:76
Pin tx
Definition uart.h:75
StopBits
Definition uart.h:45
Mode mode
Definition uart.h:91
StopBits stopbits
Definition uart.h:89
WordLength wordlength
Definition uart.h:92
Peripheral periph
Definition uart.h:88
Parity
Definition uart.h:53
struct daisy::UartHandler::Config::@20 pin_config
Config()
Definition uart.h:79
uint32_t baudrate
Definition uart.h:93
WordLength
Definition uart.h:67
Parity parity
Definition uart.h:90
Peripheral
Definition uart.h:32
Mode
Definition uart.h:60