otg.h
4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef REGS_OTG_H
#define REGS_OTG_H
#include "register.h"
class OTG {
public:
class GAHBCFG : public Register32 {
public:
REGS_BOOL_FIELD(GINTMSK, 0);
};
class GUSBCFG : public Register32 {
public:
REGS_BOOL_FIELD(PHYSEL, 6);
REGS_FIELD(TRDT, uint8_t, 13, 10);
REGS_BOOL_FIELD(FDMOD, 30);
};
class GRSTCTL : public Register32 {
public:
REGS_BOOL_FIELD(CSRST, 0);
REGS_BOOL_FIELD(RXFFLSH, 4);
REGS_BOOL_FIELD(TXFFLSH, 5);
REGS_FIELD(TXFNUM, uint8_t, 10, 6);
REGS_BOOL_FIELD(AHBIDL, 31);
};
class GINTSTS : public Register32 {
public:
using Register32::Register32;
REGS_BOOL_FIELD(MMIS, 1);
REGS_BOOL_FIELD(SOF, 3);
REGS_BOOL_FIELD(RXFLVL, 4);
REGS_BOOL_FIELD(USBSUSP, 11);
REGS_BOOL_FIELD(USBRST, 12);
REGS_BOOL_FIELD(ENUMDNE, 13);
REGS_BOOL_FIELD(IEPINT, 18);
REGS_BOOL_FIELD(WKUPINT, 31);
};
class GINTMSK : public Register32 {
public:
using Register32::Register32;
REGS_BOOL_FIELD(RXFLVLM, 4);
REGS_BOOL_FIELD(USBSUSPM, 11);
REGS_BOOL_FIELD(USBRST, 12);
REGS_BOOL_FIELD(ENUMDNEM, 13);
REGS_BOOL_FIELD(IEPINT, 18);
REGS_BOOL_FIELD(WUIM, 31);
};
class GRXSTSP : public Register32 {
public:
using Register32::Register32;
enum class PKTSTS {
GlobalOutNAK = 1,
OutReceived = 2,
OutTransferCompleted = 3, // After each Out Transaction
SetupTransactionCompleted = 4, // Supposed to be after each SETUP transaction
SetupReceived = 6
};
REGS_FIELD(EPNUM, uint8_t, 3, 0);
REGS_FIELD(BCNT, uint16_t, 14, 4);
PKTSTS getPKTSTS() volatile { return (PKTSTS)getBitRange(20, 17); }
};
class GRXFSIZ : public Register32 {
public:
REGS_FIELD(RXFD, uint16_t, 15, 0);
};
class DIEPTXF0 : public Register32 {
public:
REGS_FIELD(TX0FSA, uint16_t, 15, 0);
REGS_FIELD(TX0FD, uint16_t, 31, 16);
};
class GCCFG : public Register32 {
public:
REGS_BOOL_FIELD(PWRDWN, 16);
REGS_BOOL_FIELD(VBDEN, 21);
};
class DCFG : public Register32 {
public:
enum class DSPD {
FullSpeed = 3,
};
void setDSPD(DSPD s) volatile { setBitRange(1, 0, (uint8_t)s); }
REGS_FIELD(DAD, uint8_t, 10, 4);
};
class DCTL : public Register32 {
public:
REGS_BOOL_FIELD(SDIS, 1);
};
class DIEPMSK : public Register32 {
public:
REGS_BOOL_FIELD(XFRCM, 0);
};
class DAINTMSK : public Register32 {
public:
REGS_FIELD(IEPM, uint16_t, 15, 0);
REGS_FIELD(OEPM, uint16_t, 31, 16);
};
class DIEPCTL0 : public Register32 {
public:
enum class MPSIZ {
Size64 = 0,
Size32 = 1,
Size16 = 2,
Size8 = 3
};
using Register32::Register32;
void setMPSIZ(MPSIZ s) volatile { setBitRange(1, 0, (uint8_t)s); }
REGS_BOOL_FIELD(STALL, 21);
REGS_FIELD(TXFNUM, uint8_t, 25, 22);
REGS_BOOL_FIELD(CNAK, 26);
REGS_BOOL_FIELD(SNAK, 27);
REGS_BOOL_FIELD(EPENA, 31);
};
class DOEPCTL0 : public Register32 {
public:
REGS_BOOL_FIELD(CNAK, 26);
REGS_BOOL_FIELD(SNAK, 27);
REGS_BOOL_FIELD(EPENA, 31);
};
class DIEPINT : public Register32 {
public:
REGS_BOOL_FIELD(XFRC, 0);
REGS_BOOL_FIELD(INEPNE, 6);
};
class DIEPTSIZ0 : public Register32 {
public:
using Register32::Register32;
REGS_FIELD(XFRSIZ, uint8_t, 6, 0);
REGS_FIELD(PKTCNT, uint8_t, 20, 19);
};
class DOEPTSIZ0 : public Register32 {
public:
using Register32::Register32;
REGS_FIELD(XFRSIZ, uint8_t, 6, 0);
REGS_BOOL_FIELD(PKTCNT, 19);
REGS_FIELD(STUPCNT, uint8_t, 30, 29);
};
class PCGCCTL : public Register32 {
public:
REGS_BOOL_FIELD(STPPCLK, 0);
REGS_BOOL_FIELD(GATEHCLK, 1);
};
class DFIFO0 : public Register32 {
};
constexpr OTG() {};
REGS_REGISTER_AT(GAHBCFG, 0x008);
REGS_REGISTER_AT(GUSBCFG, 0x00C);
REGS_REGISTER_AT(GRSTCTL, 0x010);
REGS_REGISTER_AT(GINTSTS, 0x014);
REGS_REGISTER_AT(GINTMSK, 0x018);
REGS_REGISTER_AT(GRXSTSP, 0x020);
REGS_REGISTER_AT(GRXFSIZ, 0x024);
REGS_REGISTER_AT(DIEPTXF0, 0x28);
REGS_REGISTER_AT(GCCFG, 0x038);
REGS_REGISTER_AT(DCFG, 0x800);
REGS_REGISTER_AT(DCTL, 0x804);
REGS_REGISTER_AT(DIEPMSK, 0x810);
REGS_REGISTER_AT(DAINTMSK, 0x81C);
REGS_REGISTER_AT(DIEPCTL0, 0x900);
REGS_REGISTER_AT(DIEPTSIZ0, 0x910);
REGS_REGISTER_AT(DOEPCTL0, 0xB00);
REGS_REGISTER_AT(DOEPTSIZ0, 0xB10);
REGS_REGISTER_AT(PCGCCTL, 0xE00);
REGS_REGISTER_AT(DFIFO0, 0x1000);
constexpr volatile DIEPINT * DIEPINT(int i) const {
return (class DIEPINT *)(Base() + 0x908 + i*0x20);
}
private:
constexpr uint32_t Base() const {
return 0x50000000;
}
};
constexpr OTG OTG;
#endif