aboutsummaryrefslogtreecommitdiff
path: root/usart/include
diff options
context:
space:
mode:
Diffstat (limited to 'usart/include')
-rw-r--r--usart/include/common.h12
-rw-r--r--usart/include/usart.h39
2 files changed, 46 insertions, 5 deletions
diff --git a/usart/include/common.h b/usart/include/common.h
index d88d82d..9d5c7cd 100644
--- a/usart/include/common.h
+++ b/usart/include/common.h
@@ -1,6 +1,8 @@
#ifndef COMMON__H
#define COMMON__H
+#include <stdint.h>
+
/* Define __IO to be volatile if it's not already. */
#ifndef __IO
#define __IO volatile
@@ -15,4 +17,14 @@
#define PACKED __attribute__((packed))
#define BIT(n) (1 << (n))
+#define RESERVED_CONCAT_IMPL(x, y) x ## y
+#define RESERVED_MACRO_CONCAT(x, y) RESERVED_CONCAT_IMPL(x, y)
+#define RESERVED(n) \
+ bits_t RESERVED_MACRO_CONCAT(_r, __COUNTER__) :n
+
+#define RESERVE(type) \
+ __IO type RESERVED_MACRO_CONCAT(_r, __COUNTER__)
+
+typedef uint32_t bits_t;
+
#endif /* COMMON_H */
diff --git a/usart/include/usart.h b/usart/include/usart.h
index ebc5458..257aab6 100644
--- a/usart/include/usart.h
+++ b/usart/include/usart.h
@@ -18,7 +18,33 @@ typedef enum {
typedef struct {
/* USART configuration registers 0x04 - 0x0c. */
- uint32_t c_r1;
+ union {
+ uint32_t c_r1;
+ struct {
+ bits_t ue:1; /* UART enable */
+ bits_t uesm:1; /* UART enabled in stop mode. */
+ bits_t re:1; /* reciever enabled. */
+ bits_t te:1; /* transmitter enabled. */
+ bits_t idleie:1; /* Idle interrupt enabled. */
+ bits_t rxneie:1; /* RXNEIE RXNE interrupt enable. */
+ bits_t tcie:1;
+ bits_t txeie:1;
+ bits_t peie:1;
+ bits_t ps:1;
+ bits_t pce:1;
+ bits_t wake:1;
+ bits_t m0:1;
+ bits_t mme:1;
+ bits_t cmie:1;
+ bits_t over8:1;
+ bits_t dedt:4;
+ bits_t deat:4;
+ bits_t rtoie:1;
+ bits_t eobie:1;
+ bits_t m1:1;
+ bits_t reserved:3;
+ } PACKED c1_bf;
+ };
uint32_t c_r2;
uint32_t c_r3;
@@ -73,10 +99,9 @@ typedef enum {
} usart_parity_t;
typedef enum {
- USART_ENABLE_TX_RX = 0x0d, /* 0b1101 */
- USART_ENABLE_TX = 0x09, /* 0b1001 */
- USART_ENABLE_RX = 0x05, /* 0b0101 */
- USART_ENABLE_DISABLED = 0x00, /* 0b0000 */
+ USART_ENABLE_TX = 0x02,
+ USART_ENABLE_RX = 0x01,
+ USART_ENABLE_DISABLED = 0x00,
} usart_enable_t;
void usart_set_parity(__IO usart_t* usart, usart_parity_t parity);
@@ -97,6 +122,10 @@ void set_usart2_clock_src(__IO rcc_t* rcc, usart_clk_src_t usart_clk_src);
void set_usart2_clock_enabled(__IO rcc_t* rcc, bool enable);
+void usart_transmit_bytes(
+ __IO usart_t* usart, const uint8_t* bytes, uint32_t n);
+
+void usart_transmit_str(__IO usart_t* usart, const char* str);
#endif /* H__USART_ */