1
+ /* Formula Slug - Sam Ritzo */
2
+
3
+ #pragma once
4
+
5
+ class LTC68xxCommandCode {
6
+ public:
7
+ virtual uint16_t toValue () const = 0;
8
+
9
+ enum class MD : uint8_t {
10
+ // ADCOPT = 0
11
+ kMD_422Hz = 0b00
12
+ kMD_27kHz = 0b01 , // Fast
13
+ kMD_7kHz = 0b10 , // Normal
14
+ kMD_26Hz = 0b11 , // Filtered
15
+ // ADCOPT = 1
16
+ kMD_1kHz = 0b00 ,
17
+ kMD_14kHz = 0b01 ,
18
+ kMD_3kHz = 0b10 ,
19
+ kMD_2kHz = 0b11 ,
20
+ };
21
+
22
+ enum class DCP : uint8_t {
23
+ kDCP_Forbid = 0b0 ,
24
+ kDCP_Permit = 0b1 ,
25
+ };
26
+
27
+ enum class CH : uint8_t {
28
+ kCH_All = 0b000 ,
29
+ kCH_1_7 = 0b001 ,
30
+ kCH_2_8 = 0b010 ,
31
+ kCH_3_9 = 0b011 ,
32
+ kCH_4_10 = 0b100 ,
33
+ kCH_5_11 = 0b101 ,
34
+ kCH_6_12 = 0x110 ,
35
+ };
36
+
37
+ enum class PUP : uint8_t {
38
+ kPUP_PullDown = 0b0 ,
39
+ kPUP_PullUp = 0b1 ,
40
+ };
41
+
42
+ enum class ST : uint8_t {
43
+ kST_1 = 0b01 ,
44
+ kST_2 = 0b10 ,
45
+ };
46
+
47
+ enum class CHG : uint8_t {
48
+ kCHG_All = 0b000 ,
49
+ kCHG_GPIO1 = 0b001 ,
50
+ kCHG_GPIO2 = 0b010 ,
51
+ kCHG_GPIO3 = 0b011 ,
52
+ kCHG_GPIO4 = 0b100 ,
53
+ kCHG_GPIO5 = 0b101 ,
54
+ kCHG_2ndRef = 0x110 ,
55
+ };
56
+
57
+ enum class CHST : uint8_t {
58
+ kCHST_All = 0b000 ,
59
+ kCHST_SC = 0b001 ,
60
+ kCHST_ITMP = 0b010 ,
61
+ kCHST_VA = 0b011 ,
62
+ kCHST_VD = 0b100 ,
63
+ };
64
+ }
65
+
66
+
67
+ // Write Configuration Register Group A
68
+ class WRCFGA : public LTC68xxCommandCode {
69
+ uint16_t toValue () const { return 0b00000000001 ; }
70
+ }
71
+
72
+ // Write Configuration Register Group B
73
+ class WRCFGB : public LTC68xxCommandCode {
74
+ uint16_t toValue () const { return 0b00000100100 ; }
75
+ }
76
+
77
+ // Read Configuration Register Group A
78
+ class RDCFGA : public LTC68xxCommandCode {
79
+ uint16_t toValue () const { return 0b00000000010 ; }
80
+ }
81
+
82
+ // Read Configuration Register Group B
83
+ class RDCFGB : public LTC68xxCommandCode {
84
+ uint16_t toValue () const { return 0b00000100110 ; }
85
+ }
86
+
87
+ // Read Cell Voltage Register Group A
88
+ class RDCVA : public LTC68xxCommandCode {
89
+ uint16_t toValue () const { return 0b00000000100 ; }
90
+ }
91
+
92
+ // Read Cell Voltage Register Group B
93
+ class RDCVB : public LTC68xxCommandCode {
94
+ uint16_t toValue () const { return 0b00000000110 ; }
95
+ }
96
+
97
+ // Read Cell Voltage Register Group C
98
+ class RDCVC : public LTC68xxCommandCode {
99
+ uint16_t toValue () const { return 0b00000001000 ; }
100
+ }
101
+
102
+ // Read Cell Voltage Register Group D
103
+ class RDCVD : public LTC68xxCommandCode {
104
+ uint16_t toValue () const { return 0b00000001010 ; }
105
+ }
106
+
107
+ // Read Cell Voltage Register Group E
108
+ class RDCVE : public LTC68xxCommandCode {
109
+ uint16_t toValue () const { return 0b00000001001 ; }
110
+ }
111
+
112
+ // Read Cell Voltage Register Group F
113
+ class RDCVF : public LTC68xxCommandCode {
114
+ uint16_t toValue () const { return 0b00000001011 ; }
115
+ }
116
+
117
+ // Read Auxiliary Register Group A
118
+ class RDAUXA : public LTC68xxCommandCode {
119
+ uint16_t toValue () const { return 0b00000001100 ; }
120
+ }
121
+
122
+ // Read Auxiliary Register Group B
123
+ class RDAUXB : public LTC68xxCommandCode {
124
+ uint16_t toValue () const { return 0b00000001110 ; }
125
+ }
126
+
127
+ // Read Auxiliary Register Group C
128
+ class RDAUXC : public LTC68xxCommandCode {
129
+ uint16_t toValue () const { return 0b00000001101 ; }
130
+ }
131
+
132
+ // Read Auxiliary Register Group D
133
+ class RDAUXD : public LTC68xxCommandCode {
134
+ uint16_t toValue () const { return 0b00000001111 ; }
135
+ }
136
+
137
+ // Read Status Register Group A
138
+ class RDSTATA : public LTC68xxCommandCode {
139
+ uint16_t toValue () const { return 0b00000010000 ; }
140
+ }
141
+
142
+ // Read Status Register Group B
143
+ class RDSTATB : public LTC68xxCommandCode {
144
+ uint16_t toValue () const { return 0b00000010010 ; }
145
+ }
146
+
147
+ // Write S Control Register Group
148
+ class WRSCTRL : public LTC68xxCommandCode {
149
+ uint16_t toValue () const { return 0b00000010100 ; }
150
+ }
151
+
152
+ // Write PWM Register Group
153
+ class WRPWM : public LTC68xxCommandCode {
154
+ uint16_t toValue () const { return 0b00000100000 ; }
155
+ }
156
+
157
+ // Write PWM/S Control Register Group B
158
+ class WRPSB : public LTC68xxCommandCode {
159
+ uint16_t toValue () const { return 0b00000011100 ; }
160
+ }
161
+
162
+ // Read S Control Register Group
163
+ class RDSCTRL : public LTC68xxCommandCode {
164
+ uint16_t toValue () const { return 0b00000010110 ; }
165
+ }
166
+
167
+ // Read PWM Register Group
168
+ class RDPWM : public LTC68xxCommandCode {
169
+ uint16_t toValue () const { return 0b00000100010 ; }
170
+ }
171
+
172
+ // Read PWM/S Control Register Group B
173
+ class RDPSB : public LTC68xxCommandCode {
174
+ uint16_t toValue () const { return 0b00000011110 ; }
175
+ }
176
+
177
+ // Start S Control Pulsing and Poll Status
178
+ class STSCTRL : public LTC68xxCommandCode {
179
+ uint16_t toValue () const { return 0b00000011001 ; }
180
+ }
181
+
182
+ // Clear S Control Register Group
183
+ class CLRSCTRL : public LTC68xxCommandCode {
184
+ uint16_t toValue () const { return 0b00000011000 ; }
185
+ }
186
+
187
+ // Start Cell Voltage ADC Conversion and Poll Status
188
+ class ADCV : public LTC68xxCommandCode {
189
+ public:
190
+ ADCV (MD md, DCP dcp, CH ch) {}
191
+ // 0 1 MD[1:0] 1 1 DCP 0 CH[2:0]
192
+ uint16_t toValue () const {
193
+ return 0b01001100000 |
194
+ ((uint8_t ) md & 0b011 ) << 7 |
195
+ ((uint8_t ) dcp & 0b001 ) << 4 |
196
+ ((uint8_t ) ch & 0b111 ) << 0
197
+ }
198
+ }
199
+
200
+ // Start Open Wire ADC Conversion and Poll Status
201
+ class ADOW : public LTC68xxCommandCode {
202
+ public:
203
+ ADOW (MD md, PUP pup, DCP dcp, CH ch) {}
204
+ // 0 1 MD[1:0] PUP 1 DCP 1 CH[2:0]
205
+ uint16_t toValue () const {
206
+ return 0b01000101000 |
207
+ ((uint8_t ) md & 0b011 ) << 7 |
208
+ ((uint8_t ) pup & 0b001 ) << 6 |
209
+ ((uint8_t ) dcp & 0b001 ) << 4 |
210
+ ((uint8_t ) ch & 0b111 ) << 0
211
+ }
212
+ }
213
+
214
+ // Start Self Test Cell Voltage Conversion and Poll Status
215
+ class CVST : public LTC68xxCommandCode {
216
+ public:
217
+ CVST (MD md, ST st) {}
218
+ // 0 1 MD[1:0] ST[1:0] 0 0 1 1 1
219
+ uint16_t toValue () const {
220
+ return 0b01000000111 |
221
+ ((uint8_t ) md & 0b011 ) << 7 |
222
+ ((uint8_t ) st & 0b011 ) << 5
223
+ }
224
+ }
225
+
226
+ // Start Overlap Measurement of Cell 7 Voltage
227
+ class ADOL : public LTC68xxCommandCode {
228
+ public:
229
+ ADOL (MD md, DCP dcp) {}
230
+ // 0 1 MD[1:0] 0 0 DCP 0 0 0 1
231
+ uint16_t toValue () const {
232
+ return 0b01000000001 |
233
+ ((uint8_t ) md & 0b011 ) << 7 |
234
+ ((uint8_t ) dcp & 0b001 ) << 4
235
+ }
236
+ }
237
+
238
+ // Start GPIOs ADC Conversion and Poll Status
239
+ class ADAX : public LTC68xxCommandCode {
240
+ public:
241
+ ADAX (MD md, CHG chg) {}
242
+ // 1 0 MD[1:0] 1 1 0 0 CHG[2:0]
243
+ uint16_t toValue () const {
244
+ return 0b10001100000 |
245
+ ((uint8_t ) md & 0b011 ) << 7 |
246
+ ((uint8_t ) chg & 0b111 ) << 0
247
+ }
248
+ }
249
+
250
+ // Start GPIOs ADC Conversion With Digital Redundancy and Poll Status
251
+ class ADAXD : public LTC68xxCommandCode {
252
+ public:
253
+ ADAXD (MD md, CHG chg) {}
254
+ // 1 0 MD[1:0] 0 0 0 0 CHG[2:0]
255
+ uint16_t toValue () const {
256
+ return 0b10000000000 |
257
+ ((uint8_t ) md & 0b011 ) << 7 |
258
+ ((uint8_t ) chg & 0b111 ) << 0
259
+ }
260
+ }
261
+
262
+ // Start Self Test GPIOs Conversion and Poll Status
263
+ class AXST : public LTC68xxCommandCode {
264
+ public:
265
+ AXST (MD md, ST st) {}
266
+ // 1 0 MD[1:0] ST[1:0] 0 0 1 1 1
267
+ uint16_t toValue () const {
268
+ return 0b10000000111 |
269
+ ((uint8_t ) md & 0b011 ) << 7 |
270
+ ((uint8_t ) st & 0b011 ) << 5
271
+ }
272
+ }
273
+
274
+ // Start Status Group ADC Conversion and Poll Status
275
+ class ADSTAT : public LTC68xxCommandCode {
276
+ public:
277
+ ADSTAT (MD md, CHST chst) {}
278
+ // 1 0 MD[1:0] 1 1 0 1 CHST[2:0]
279
+ uint16_t toValue () const {
280
+ return 0b10001101000 |
281
+ ((uint8_t ) md & 0b011 ) << 7 |
282
+ ((uint8_t ) chst & 0b111 ) << 0
283
+ }
284
+ }
285
+
286
+ // Start Status Group ADC Conversion With Digital Redundancy and Poll Status
287
+ class ADSTATD : public LTC68xxCommandCode {
288
+ public:
289
+ ADSTATD (MD md, CHST chst) {}
290
+ // 1 0 MD[1:0] 0 0 0 1 CHST[2:0]
291
+ uint16_t toValue () const {
292
+ return 0b10000001000 |
293
+ ((uint8_t ) md & 0b011 ) << 7 |
294
+ ((uint8_t ) chst & 0b111 ) << 0
295
+ }
296
+ }
297
+
298
+ // Start Self Test Status Group Conversion and Poll Status
299
+ class STATST : public LTC68xxCommandCode {
300
+ public:
301
+ STATST (MD md, ST st) {}
302
+ // 1 0 MD[1:0] ST[1:0] 0 1 1 1 1
303
+ uint16_t toValue () const {
304
+ return 0b10000001111 |
305
+ ((uint8_t ) md & 0b011 ) << 7 |
306
+ ((uint8_t ) st & 0b011 ) << 5
307
+ }
308
+ }
309
+
310
+ // Start Combined Cell Voltage and GPIO1, GPIO2 Conversion and Poll Status
311
+ class ADCVAX : public LTC68xxCommandCode {
312
+ public:
313
+ ADCVAX (MD md, DCP dcp) {}
314
+ // 1 0 MD[1:0] 1 1 DCP 1 1 1 1
315
+ uint16_t toValue () const {
316
+ return 0b10001101111 |
317
+ ((uint8_t ) md & 0b011 ) << 7 |
318
+ ((uint8_t ) dcp & 0b001 ) << 4
319
+ }
320
+ }
321
+
322
+ // Start Combined Cell Voltage and SC Conversion and Poll Status
323
+ class ADCVSC : public LTC68xxCommandCode {
324
+ public:
325
+ ADCVSC (MD md, DCP dcp) {}
326
+ // 1 0 MD[1:0] 1 1 DCP 0 1 1 1
327
+ uint16_t toValue () const {
328
+ return 0b10001100111 |
329
+ ((uint8_t ) md & 0b011 ) << 7 |
330
+ ((uint8_t ) dcp & 0b001 ) << 4
331
+ }
332
+ }
333
+
334
+ // Clear Cell Voltage Register Groups
335
+ class CLRCELL : public LTC68xxCommandCode {
336
+ uint16_t toValue () const { return 0b11100010001 ; }
337
+ }
338
+
339
+ // Clear Auxiliary Register Groups
340
+ class CLRAUX : public LTC68xxCommandCode {
341
+ uint16_t toValue () const { return 0b11100010010 ; }
342
+ }
343
+
344
+ // Clear Status Register Groups
345
+ class CLRSTAT : public LTC68xxCommandCode {
346
+ uint16_t toValue () const { return 0b11100010011 ; }
347
+ }
348
+
349
+ // Poll ADC Conversion Status
350
+ class PLADC : public LTC68xxCommandCode {
351
+ uint16_t toValue () const { return 0b11100010100 ; }
352
+ }
353
+
354
+ // Diagnose MUX and Poll Status
355
+ class DIAGN : public LTC68xxCommandCode {
356
+ uint16_t toValue () const { return 0b11100010101 ; }
357
+ }
358
+
359
+ // Write COMM Register Group
360
+ class WRCOMM : public LTC68xxCommandCode {
361
+ uint16_t toValue () const { return 0b11100100001 ; }
362
+ }
363
+
364
+ // Read COMM Register Group
365
+ class RDCOMM : public LTC68xxCommandCode {
366
+ uint16_t toValue () const { return 0b11100100010 ; }
367
+ }
368
+
369
+ // Start I2C /SPI Communication
370
+ class STCOMM : public LTC68xxCommandCode {
371
+ uint16_t toValue () const { return 0b11100100011 ; }
372
+ }
0 commit comments