Numworks Epsilon  1.4.1
Graphing Calculator Operating System
tim.h
Go to the documentation of this file.
1 #ifndef REGS_TIM_H
2 #define REGS_TIM_H
3 
4 #include "register.h"
5 
6 class TIM {
7 public:
8  class CR1 : Register16 {
9  public:
10  REGS_BOOL_FIELD(CEN, 0);
11  REGS_BOOL_FIELD(ARPE, 7);
12  };
13 
14  class CCMR : Register64 {
15  /* We're declaring CCMR as a 64 bits register. CCMR doesn't exsist per se,
16  * it is in fact the consolidation of CCMR1 and CCMR2. Both are 16 bits
17  * registers, so one could expect the consolidation to be 32 bits. However,
18  * both CCMR1 and CCMR2 live on 32-bits boundaries, so the consolidation has
19  * to be 64 bits wide, even though we'll only use 32 bits out of 64. */
20  public:
21  enum class CC1S : uint8_t {
22  OUTPUT = 0,
23  INPUT_TI2 = 1,
24  INPUT_TI1 = 2,
25  INPUT_TRC = 3
26  };
27  enum class OCM : uint8_t {
28  Frozen = 0,
29  ActiveOnMatch = 1,
30  InactiveOnMatch = 2,
31  Toggle = 3,
32  ForceInactive = 4,
33  ForceActive = 5,
34  PWM1 = 6,
35  PWM2 = 7
36  };
37  typedef OCM OC1M;
38  typedef OCM OC2M;
39  typedef OCM OC3M;
40  typedef OCM OC4M;
41  REGS_BOOL_FIELD(OC1PE, 3);
42  REGS_TYPE_FIELD(OC1M, 6, 4);
43  REGS_BOOL_FIELD(OC2PE, 11);
44  REGS_TYPE_FIELD(OC2M, 14, 12);
45  REGS_BOOL_FIELD(OC3PE, 35);
46  REGS_TYPE_FIELD(OC3M, 38, 36);
47  REGS_BOOL_FIELD(OC4PE, 43);
48  REGS_TYPE_FIELD(OC4M, 46, 44);
49  };
50 
51  class CCER : Register16 {
52  public:
53  REGS_BOOL_FIELD(CC1E, 0);
54  REGS_BOOL_FIELD(CC2E, 4);
55  REGS_BOOL_FIELD(CC3E, 8);
56  REGS_BOOL_FIELD(CC4E, 12);
57  };
58 
59  class BDTR : Register16 {
60  public:
61  REGS_BOOL_FIELD(MOE, 15);
62  };
63 
64  class PSC : public Register16 {};
65  class ARR : public Register16 {};
66  class CCR1 : public Register16 {};
67  class CCR2 : public Register16 {};
68  class CCR3 : public Register16 {};
69  class CCR4 : public Register16 {};
70 
71  constexpr TIM(int i) : m_index(i) {}
72  REGS_REGISTER_AT(CR1, 0x0);
73  REGS_REGISTER_AT(CCMR, 0x18);
74  REGS_REGISTER_AT(CCER, 0x20);
75  REGS_REGISTER_AT(PSC, 0x28);
76  REGS_REGISTER_AT(ARR, 0x2C);
77  REGS_REGISTER_AT(CCR1, 0x34);
78  REGS_REGISTER_AT(CCR2, 0x38);
79  REGS_REGISTER_AT(CCR3, 0x3C);
80  REGS_REGISTER_AT(CCR4, 0x40);
81  REGS_REGISTER_AT(BDTR, 0x44);
82 private:
83  constexpr uint32_t Base() const {
84  return (m_index == 1 ? 0x40010000 : 0x40000000 + 0x400*(m_index-2));
85  };
86  int m_index;
87 };
88 
89 constexpr TIM TIM1(1);
90 constexpr TIM TIM3(3);
91 
92 #endif
OCM OC4M
Definition: tim.h:40
Definition: tim.h:6
Definition: tim.h:59
Definition: tim.h:66
Definition: tim.h:69
#define x0
Definition: b_tgamma.c:86
OCM OC2M
Definition: tim.h:38
constexpr TIM(int i)
Definition: tim.h:71
constexpr TIM TIM3(3)
Definition: tim.h:67
unsigned char uint8_t
Definition: stdint.h:4
REGS_TYPE_FIELD(OC1M, 6, 4)
Definition: tim.h:64
Definition: tim.h:8
REGS_BOOL_FIELD(MOE, 15)
REGS_BOOL_FIELD(CEN, 0)
unsigned int uint32_t
Definition: stdint.h:6
CC1S
Definition: tim.h:21
Definition: tim.h:51
Definition: tim.h:14
REGS_BOOL_FIELD(CC1E, 0)
REGS_REGISTER_AT(CR1, 0x0)
constexpr TIM TIM1(1)
Definition: tim.h:65
REGS_BOOL_FIELD(OC1PE, 3)
OCM OC3M
Definition: tim.h:39
Definition: tim.h:68
OCM OC1M
Definition: tim.h:37
OCM
Definition: tim.h:27