Numworks Epsilon  1.4.1
Graphing Calculator Operating System
adc.h
Go to the documentation of this file.
1 #ifndef REGS_ADC_H
2 #define REGS_ADC_H
3 
4 #include "register.h"
5 
6 class ADC {
7 public:
8  class SR : Register32 {
9  public:
10  REGS_BOOL_FIELD(EOC, 1);
11  };
12 
13  class CR1 : Register32 {
14  public:
15  };
16 
17  class CR2 : Register32 {
18  public:
19  REGS_BOOL_FIELD(ADON, 0);
20  REGS_BOOL_FIELD(SWSTART, 30);
21  };
22 
23  class SMPR : Register64 {
24  /* The SMPR register doesn't exist per-se in the documentation. It is the
25  * consolidation of SMPR1 and SMPR2 which are two 32-bit registers. */
26  public:
27  enum class SamplingTime {
28  Cycles3 = 0,
29  Cycles15 = 1,
30  Cycles28 = 2,
31  Cycles56 = 3,
32  Cycles84 = 4,
33  Cycles112 = 5,
34  Cycles144 = 6,
35  Cycles480 = 7
36  };
38  return (SamplingTime)getBitRange(3*channel+2, 3*channel);
39  }
40  void setSamplingTime(int channel, SamplingTime t) volatile {
41  setBitRange(3*channel+2, 3*channel, (uint64_t)t);
42  }
43  };
44 
45  class SQR1 : Register32 {
46  public:
47  REGS_FIELD(L, uint8_t, 23, 20);
48  };
49 
50  class SQR3 : Register32 {
51  public:
52  REGS_FIELD(SQ1, uint8_t, 4, 0);
53  };
54 
55  class DR : public Register16 {
56  };
57 
58  constexpr ADC() {};
59  REGS_REGISTER_AT(SR, 0x0);
60  REGS_REGISTER_AT(CR2, 0x08);
61  REGS_REGISTER_AT(SMPR, 0x0C);
62  REGS_REGISTER_AT(SQR1, 0x2C);
63  REGS_REGISTER_AT(SQR3, 0x34);
64  REGS_REGISTER_AT(DR, 0x4C);
65 private:
66  constexpr uint32_t Base() const {
67  return 0x40012000;
68  };
69 };
70 
71 constexpr ADC ADC;
72 
73 #endif
constexpr ADC ADC
Definition: adc.h:71
Definition: adc.h:13
REGS_REGISTER_AT(SR, 0x0)
#define x0
Definition: b_tgamma.c:86
Definition: adc.h:6
unsigned char uint8_t
Definition: stdint.h:4
REGS_FIELD(L, uint8_t, 23, 20)
REGS_BOOL_FIELD(ADON, 0)
REGS_FIELD(SQ1, uint8_t, 4, 0)
Definition: adc.h:17
Definition: adc.h:55
Definition: adc.h:8
unsigned int uint32_t
Definition: stdint.h:6
unsigned long long uint64_t
Definition: stdint.h:7
Definition: adc.h:45
REGS_BOOL_FIELD(EOC, 1)
Definition: adc.h:50
SamplingTime
Definition: adc.h:27
Definition: adc.h:23
constexpr ADC()
Definition: adc.h:58
void setBitRange(uint8_t high, uint8_t low, T value) volatile
Definition: register.h:21
SamplingTime getSamplingTime(int channel)
Definition: adc.h:37
void setSamplingTime(int channel, SamplingTime t) volatile
Definition: adc.h:40
T getBitRange(uint8_t high, uint8_t low) volatile
Definition: register.h:24