Numworks Epsilon  1.4.1
Graphing Calculator Operating System
usart.h
Go to the documentation of this file.
1 #ifndef REGS_USART_H
2 #define REGS_USART_H
3 
4 #include "register.h"
5 
6 class USART {
7 public:
8  class SR : Register32 {
9  public:
10  REGS_BOOL_FIELD(RXNE, 5);
11  REGS_BOOL_FIELD(TXE, 7);
12  };
13 
14  class DR : Register32 {
15  public:
16  uint16_t get() volatile {
17  return (uint16_t)getBitRange(8, 0);
18  }
19  void set(uint16_t v) volatile {
20  setBitRange(8, 0, v);
21  }
22  };
23 
24  class BRR : Register32 {
25  public:
26  REGS_FIELD(DIV_FRAC, uint8_t, 3, 0);
27  REGS_FIELD(DIV_MANTISSA, uint16_t, 15, 4);
28  };
29 
30  class CR1 : Register32 {
31  public:
32  REGS_BOOL_FIELD(UE, 13);
33  REGS_BOOL_FIELD(TE, 3);
34  REGS_BOOL_FIELD(RE, 2);
35  };
36 
37  constexpr USART(int i) : m_index(i) {}
38  constexpr operator int() const { return m_index; }
39  REGS_REGISTER_AT(SR, 0x00);
40  REGS_REGISTER_AT(DR, 0x04);
41  REGS_REGISTER_AT(BRR, 0x08);
42  REGS_REGISTER_AT(CR1, 0x0C);
43 private:
44  constexpr uint32_t Base() const {
45  return ((uint32_t []){0x40011000, 0x40004400, 0x40004800})[m_index-1];
46  };
47  int m_index;
48 };
49 
50 #endif
Definition: usart.h:8
unsigned short uint16_t
Definition: stdint.h:5
unsigned char uint8_t
Definition: stdint.h:4
REGS_BOOL_FIELD(RXNE, 5)
unsigned int uint32_t
Definition: stdint.h:6
REGS_REGISTER_AT(SR, 0x00)
REGS_FIELD(DIV_FRAC, uint8_t, 3, 0)
Definition: usart.h:6
void setBitRange(uint8_t high, uint8_t low, T value) volatile
Definition: register.h:21
constexpr USART(int i)
Definition: usart.h:37
REGS_BOOL_FIELD(UE, 13)
T getBitRange(uint8_t high, uint8_t low) volatile
Definition: register.h:24