Trident IoT SDK
Loading...
Searching...
No Matches
T32CZ20_adc.h
Go to the documentation of this file.
1
13
14#ifndef T32CZ20_ADC_H_
15#define T32CZ20_ADC_H_
16
17#include "tr_hal_platform.h"
18
24
25#define TR_HAL_NUM_ADC 7
26
43
44#define MAX_ADC_CHANNEL_ID ADC_CHANNEL_6_ID
45#define TR_HAL_ADC_CHANNEL_NONE 0xFF
46
52#define TR_HAL_ADC_AIO0 21
53#define TR_HAL_ADC_AIO1 22
54#define TR_HAL_ADC_AIO2 23
55// pin 24 = AIO3 is not available
56#define TR_HAL_ADC_AIO4 28
57#define TR_HAL_ADC_AIO5 29
58#define TR_HAL_ADC_AIO6 30
59#define TR_HAL_ADC_AIO7 31
60
61#define ADC_VALID_PIN_CHOICE1 TR_HAL_ADC_AIO0
62#define ADC_VALID_PIN_CHOICE2 TR_HAL_ADC_AIO1
63#define ADC_VALID_PIN_CHOICE3 TR_HAL_ADC_AIO2
64#define ADC_VALID_PIN_CHOICE4 TR_HAL_ADC_AIO4
65#define ADC_VALID_PIN_CHOICE5 TR_HAL_ADC_AIO5
66#define ADC_VALID_PIN_CHOICE6 TR_HAL_ADC_AIO6
67#define ADC_VALID_PIN_CHOICE7 TR_HAL_ADC_AIO7
68
69#define DEFAULT_ADC_PIN ADC_VALID_PIN_CHOICE1
70
71// these are used to enable the AIO in the analog settings register
72#define TR_ADC_ENABLE_AIO0 0x01UL
73#define TR_ADC_ENABLE_AIO1 0x02UL
74#define TR_ADC_ENABLE_AIO2 0x04UL
75// AIO3 is not available
76#define TR_ADC_ENABLE_AIO4 0x10UL
77#define TR_ADC_ENABLE_AIO5 0x20UL
78#define TR_ADC_ENABLE_AIO6 0x40UL
79#define TR_ADC_ENABLE_AIO7 0x80UL
80
81
90#ifdef SADC_SECURE_EN
91 #define CHIP_MEMORY_MAP_ADC_BASE (0x5002F000UL)
92 #define CHIP_MEMORY_MAP_AUX_COMPARATOR_BASE (0x5001E000UL)
93#else
94 #define CHIP_MEMORY_MAP_ADC_BASE (0x4002F000UL)
95 #define CHIP_MEMORY_MAP_AUX_COMPARATOR_BASE (0x4001E000UL)
96#endif // SADC_SECURE_EN
97
98
104typedef struct
105{
106 __IO uint32_t ch_x_config; // 0x00
107 __IO uint32_t ch_x_burst; // 0x04
108 __IO uint32_t ch_x_threshholds; // 0x08
109 __IO uint32_t ch_x_reserved; // 0x0C
111
112
118{
120 {
121 uint32_t AUX_ADC_DEBUG : 1;
122 uint32_t AUX_ADC_MODE : 1;
123 uint32_t AUX_ADC_OUTPUTSTB : 1;
124 uint32_t AUX_ADC_OSPN : 1;
125 uint32_t AUX_ADC_CLK_SEL : 2;
126 uint32_t AUX_ADC_MCAP : 2;
127 uint32_t AUX_ADC_MDLY : 2;
128 uint32_t AUX_ADC_SEL_DUTY : 2;
129 uint32_t AUX_ADC_OS : 2;
130 uint32_t RESERVED1 : 2;
131 uint32_t AUX_ADC_BR : 4;
132 uint32_t AUX_ADC_PW : 3;
133 uint32_t RESERVED2 : 1;
134 uint32_t AUX_ADC_STB_BIT : 3;
135 uint32_t RESERVED3 : 1;
136 uint32_t AUX_PW : 3;
137 uint32_t RESERVED4 : 1;
138
140 uint32_t reg;
142
143typedef union tr_sadc_ana_set1_s
144{
145 struct tr_sadc_ana_set1_b
146 {
147 uint32_t AUX_VGA_CMSEL : 4;
148 uint32_t AUX_VGA_COMP : 2;
149 uint32_t AUX_VGA_SIN : 2;
150
151 uint32_t AUX_VGA_LOUT : 1;
152 uint32_t AUX_VGA_SW_VDD : 1;
153 uint32_t AUX_VGA_VLDO : 2;
154 uint32_t AUX_VGA_ACM : 4;
155
156 uint32_t AUX_VGA_PW : 6;
157 uint32_t AUX_DC_ADJ : 2;
158
159 uint32_t AUX_TEST_MODE : 1;
160 uint32_t CFG_EN_CLKAUX : 1;
162 uint32_t RESERVED1 : 5;
163
164 } bit;
165 uint32_t reg;
167
168
169
173typedef struct
174{
175 // enable, reset, and start control register
176 __IO uint32_t control_enable; // 0x00
177 __IO uint32_t control_reset; // 0x04
178 __IO uint32_t control_start; // 0x08
179
180 // settings
181 __IO uint32_t clock_settings; // 0x0C
182 __IO uint32_t oversample_settings; // 0x10
183
184 // reserved
185 __IO uint32_t reserved1[3]; // 0x14, 0x18, 0x1C
186
187 // there are 10 channels: 0 to 9
188 // each channel has 3 register fields, plus one reserved
189 // rather than have 40 fields for these, these are setup as an array
190 // for simpler code
191 //
192 // here is an example of CH 0 and CH 1 if we were doing individual fields:
193 // CH 0: configurations, burst mode, and monitor threshhold
194 // __IO uint32_t ch_0_config; // 0x20
195 // __IO uint32_t ch_0_burst; // 0x24
196 // __IO uint32_t ch_0_threshholds; // 0x28
197 // __IO uint32_t ch_0_reserved; // 0x2C
198
199 // CH 1: configurations, burst mode, and monitor threshhold
200 // __IO uint32_t ch_1_config; // 0x30
201 // __IO uint32_t ch_1_burst; // 0x34
202 // __IO uint32_t ch_1_threshholds; // 0x38
203 // __IO uint32_t ch_1_reserved; // 0x3C
204
205 // each of the 10 channels has 4 registers = 40 total
206 // CH 0: configurations (0x20), burst mode (0x24), and threshholds (0x28), rsvd (0x2C)
207 // CH 1: configurations (0x30), burst mode (0x34), and threshholds (0x38), rsvd (0x3C)
208 // CH 2: configurations (0x40), burst mode (0x44), and threshholds (0x48), rsvd (0x4C)
209 // CH 3: configurations (0x50), burst mode (0x54), and threshholds (0x58), rsvd (0x5C)
210 // CH 4: configurations (0x60), burst mode (0x64), and threshholds (0x68), rsvd (0x6C)
211 // CH 5: configurations (0x70), burst mode (0x74), and threshholds (0x78), rsvd (0x7C)
212 // CH 6: configurations (0x80), burst mode (0x84), and threshholds (0x88), rsvd (0x8C)
213 // CH 7: configurations (0x90), burst mode (0x94), and threshholds (0x98), rsvd (0x9C)
214 // CH 8: configurations (0xA0), burst mode (0xA4), and threshholds (0xA8), rsvd (0xAC)
215 // CH 9: configurations (0xB0), burst mode (0xB4), and threshholds (0xB8), rsvd (0xBC)
216
217 // here are the 10 channels, CHAN_SETTINGS_T is 4 x uint32_t
218 __IO CHAN_SETTINGS_T ch_x_setting[9]; // 0x20 - 0xAC
219
220 __IO uint32_t reserved2[3]; // 0xB0, 0xB4, 0xB8
221
222 // analog AUX ADC settings
223 // unfortunately the first one overlaps with the reserved field of the prior channel
224 // we could pull that channel from the array but that makes everything harder.
225 // so we just #define analog_settings0 to the right address below. Right after these
226 // 2 fields we have a MASSIVE gap. so we weren't short on space.
229
230 // reserved
231 __IO uint32_t reserved3[15]; // 0xC4 - 0xFC
232
233 // DMA: start, reset, buffer size, buffer addr
234 __IO uint32_t enable_dma; // 0x100
235 __IO uint32_t reset_dma; // 0x104
236 __IO uint32_t dma_buffer_size; // 0x108
237 __IO uint32_t dma_buffer_addr; // 0x10C
238 __IO uint32_t dma_settings; // 0x110
239 __IO uint32_t dma_next_ptr_addr; // 0x114
240 __IO uint32_t dma_status; // 0x118
241 __IO uint32_t dma_reserved2; // 0x11C
242
243 // interrupts
244 __IO uint32_t interrupt_clear; // 0x120
245 // note that this register is opposite of most interrupt_enable registers:
246 // 0 means enable and 1 means disable
247 __IO uint32_t interrupt_enable; // 0x124
248 __IO uint32_t interrupt_status; // 0x128
249
250 // result
251 __IO uint32_t result_oversample; // 0x12C
252 __IO uint32_t result_digital; // 0x130
253 __IO uint32_t result_analog; // 0x134
254
256
257
262{
264 {
265 uint32_t COMP_SELREF : 1;
266 uint32_t COMP_SELINPUT : 1;
267 uint32_t COMP_PW : 2;
268 uint32_t COMP_SELHYS : 2;
269 uint32_t COMP_SWDIV : 1;
270 uint32_t COMP_PSRR : 1;
271 uint32_t COMP_VSEL : 4;
272 uint32_t COMP_REFSEL : 4;
273 uint32_t COMP_CHSEL : 4;
274 uint32_t COMP_TC : 1;
275 uint32_t RESERVED1 : 3;
276 uint32_t COMP_EN_START : 2;
277 uint32_t RESERVED2 : 6;
279 uint32_t reg;
281
282
287typedef struct
288{
290 __IO uint32_t AUXCOMP_DIG_CTRL0; // 0x04
291 __IO uint32_t AUXCOMP_DIG_CTRL1; // 0x04
292 __IO uint32_t AUXCOMP_DIG_CTRL2; // 0x04
293
295
296
297// *****************************************************************
298// these defines help when dealing with the CONTROL ENABLE register (0x00)
299
300#define ADC_REG_ENABLE_ADC_DISABLE 0x000
301#define ADC_REG_ENABLE_ADC_ENABLE 0x001
302
303// undocumented
304#define ADC_REG_ENABLE_VGA_ENABLE 0x02
305#define ADC_REG_ENABLE_LDO_ENABLE 0x04
306
307// bits 8-9 (undocumented -- same as CM11)
308#define ADC_REG_ENABLE_CLK_FREE 0x100
309
310// *****************************************************************
311// these defines help when dealing with the CONTROL RESET register (0x04)
312
313#define ADC_REG_RESET_ADC 0x001
314#define ADC_REG_RESET_FIFO 0x100
315
316// *****************************************************************
317// these defines help when dealing with the CONTROL START register (0x08)
318
319#define ADC_REG_START_ADC 0x01
320
321// *****************************************************************
322// these defines help when dealing with the CLOCK SETTINGS register (0x0C)
323
324// bit 0 = sample rate mode
325#define ADC_REG_TIMER_RATE_DEPENDS_ON_SOFTWARE 0x00
326#define ADC_REG_TIMER_RATE_DEPENDS_ON_TIMER 0x01
327// bit 1 = timer clock source
328#define ADC_REG_TIMER_USE_SYSTEM_CLOCK 0x00
329#define ADC_REG_TIMER_USE_SLOW_CLOCK 0x02
330// bit 2 = clock phase
331#define ADC_REG_TIMER_RISING_EDGE 0x00
332#define ADC_REG_TIMER_FALLING_EDGE 0x04
333// bit 3 to 6 = debug selection
334#define ADC_REG_TIMER_DEBUG_MASK 0x78
335
336// bit 16 to 31 (high 2 bytes) = timer clock divider
337#define ADC_REG_TIMER_CLOCK_DIV_MASK 0xFFFF0000
338#define ADC_REG_TIMER_CLOCK_DIV_SHIFT 16
339// one is added to the value given before being used to divide the clock
340// smallest value is 2 which would be a clk div of 3
341// largest value is 65535 which would be a clk div of 65536
342#define TR_HAL_ADC_MAX_CLOCK_DIVISOR 65536
343#define TR_HAL_ADC_MIN_CLOCK_DIVISOR 3
344
345// *****************************************************************
346// these defines help when dealing with the OVERSAMPLE SETTINGS register (0x10)
347
348// bit 0 to 3 = output resolution (chip default 2)
349#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_8_BIT 0x00
350#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_10_BIT 0x01
351#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_12_BIT 0x02
352#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_14_BIT 0x03
353
354// bits 4 to 7 = channel select
355#define ADC_REG_SAMPLE_SELECT_CHANNEL_0 0x00
356#define ADC_REG_SAMPLE_SELECT_CHANNEL_1 0x10
357#define ADC_REG_SAMPLE_SELECT_CHANNEL_2 0x20
358#define ADC_REG_SAMPLE_SELECT_CHANNEL_3 0x30
359#define ADC_REG_SAMPLE_SELECT_CHANNEL_4 0x40
360#define ADC_REG_SAMPLE_SELECT_CHANNEL_5 0x50
361#define ADC_REG_SAMPLE_SELECT_CHANNEL_6 0x60
362#define ADC_REG_SAMPLE_SELECT_CHANNEL_7 0x70
363#define ADC_REG_SAMPLE_SELECT_CHANNEL_8 0x80
364#define ADC_REG_SAMPLE_SELECT_CHANNEL_9 0x90
365
366// bits 8 to 11 = oversample rate
380
381// bits 12-15 are for testing
382#define ADC_REG_SAMPLE_VALUE_BYPASS 0x1000
383#define ADC_REG_SAMPLE_MSB_BIT_INVERSION 0x2000
384#define ADC_REG_SAMPLE_ENABLE_MANUAL_MODE1 0x4000
385#define ADC_REG_SAMPLE_ENABLE_MANUAL_MODE2 0x8000
386
387// undocumented = in order to make ADC single shot work
388// need to enable ADC_REG_SAMPLE_ENABLE_MANUAL_MODE1
389// and ADC_REG_SAMPLE_ENABLE_MANUAL_MODE2, which
390// gives a value of 0xC000
391
392// bits 16 to 27 = ADC adjuts value, used for calibration
393#define ADC_REG_SAMPLE_CALIBRATION_MASK 0x0FFF0000
394
395// *****************************************************************
396// these defines help when dealing with the CH_X_CONFIG register (0x20, 0x30, 0x40...)
397
398// 4 bits (0 to 3) of the P-channel
399#define ADC_CONFIG_REG_P_CHANNEL_AIN_0 0x00000000
400#define ADC_CONFIG_REG_P_CHANNEL_AIN_1 0x00000001
401#define ADC_CONFIG_REG_P_CHANNEL_AIN_2 0x00000002
402#define ADC_CONFIG_REG_P_CHANNEL_AIN_3 0x00000003
403#define ADC_CONFIG_REG_P_CHANNEL_AIN_4 0x00000004
404#define ADC_CONFIG_REG_P_CHANNEL_AIN_5 0x00000005
405#define ADC_CONFIG_REG_P_CHANNEL_AIN_6 0x00000006
406#define ADC_CONFIG_REG_P_CHANNEL_AIN_7 0x00000007
407#define ADC_CONFIG_REG_P_CHANNEL_TEMP_SENSOR 0x00000008
408#define ADC_CONFIG_REG_P_CHANNEL_BATT_VOLT 0x0000000A
409#define ADC_CONFIG_REG_P_CHANNEL_NONE 0x0000000F
410
411// 4 bits (4 to 7) of the N-channel
412#define ADC_CONFIG_REG_N_CHANNEL_AIN_0 0x00000000
413#define ADC_CONFIG_REG_N_CHANNEL_AIN_1 0x00000010
414#define ADC_CONFIG_REG_N_CHANNEL_AIN_2 0x00000020
415#define ADC_CONFIG_REG_N_CHANNEL_AIN_3 0x00000030
416#define ADC_CONFIG_REG_N_CHANNEL_AIN_4 0x00000040
417#define ADC_CONFIG_REG_N_CHANNEL_AIN_5 0x00000050
418#define ADC_CONFIG_REG_N_CHANNEL_AIN_6 0x00000060
419#define ADC_CONFIG_REG_N_CHANNEL_AIN_7 0x00000070
420#define ADC_CONFIG_REG_N_CHANNEL_TEMP_SENSOR 0x00000080
421#define ADC_CONFIG_REG_N_CHANNEL_BATT_VOLT 0x000000A0
422#define ADC_CONFIG_REG_N_CHANNEL_NONE 0x000000F0
423
424// 6 bits of VGA gain (8 to 13)
425//
426// upper 2 bits get multiplied by 6 dB
427// max value of 3 -> 3 x 6 = 18
428//
429// lower 4 bits get multiplied by 3 dB
430// max value of 15 -> 15 x 3 = 45
431//
432// so max value is 45 + 18 = 63
433#define ADC_CONFIG_REG_MAX_GAIN_SETTING 63
434
435// default is 0x14 = 0b010100
436// upper 2 bits = 01 = 1 -> 1 x 6 dB = 6 dB
437// lower 4 bits = 0100 = 4 -> 4 x 3 dB = 12 dB
438// -> 6 dB + 12 dB = 18 dB
439#define ADC_CONFIG_REG_DEFAULT_GAIN 0x00001400
440
441// 2 bits of channel select (14 to 15)
442#define ADC_CONFIG_REG_SELECT_REF_IN 0x00004000
443
444// 8 bits of PULL (16 to 19)
445#define ADC_CONFIG_REG_P_CHAN_PULL_NONE 0x00000000
446#define ADC_CONFIG_REG_N_CHAN_PULL_NONE 0x00000000
447#define ADC_CONFIG_REG_P_CHAN_PULL_HIGH 0x00010000
448#define ADC_CONFIG_REG_P_CHAN_PULL_LOW 0x00020000
449#define ADC_CONFIG_REG_N_CHAN_PULL_HIGH 0x00040000
450#define ADC_CONFIG_REG_N_CHAN_PULL_LOW 0x00080000
451#define ADC_CONFIG_REG_P_CHAN_TO_VDD 0x00100000
452#define ADC_CONFIG_REG_P_CHAN_TO_GND 0x00200000
453#define ADC_CONFIG_REG_N_CHAN_TO_VDD 0x00400000
454#define ADC_CONFIG_REG_N_CHAN_TO_GND 0x00800000
455
456#define ADC_CONFIG_REG_P_CHAN_VCM_VOLTAGE 0x00030000
457#define ADC_CONFIG_REG_N_CHAN_VCM_VOLTAGE 0x000C0000
458
459#define ADC_CONFIG_REG_PULL_NONE 0x00000000
460#define ADC_CONFIG_REG_PULL_VCM_MODE 0x000F0000
461
462// 20 to 23 reserved
463
464// 3 bits of result aquisition time (24 to 26)
465#define ADC_CONFIG_REG_AQUISITION_TIME_0p3_uS 0x00000000
466#define ADC_CONFIG_REG_AQUISITION_TIME_1_uS 0x01000000
467#define ADC_CONFIG_REG_AQUISITION_TIME_2_uS 0x02000000
468#define ADC_CONFIG_REG_AQUISITION_TIME_3_uS 0x03000000
469#define ADC_CONFIG_REG_AQUISITION_TIME_4_uS 0x04000000
470#define ADC_CONFIG_REG_AQUISITION_TIME_8_uS 0x05000000
471#define ADC_CONFIG_REG_AQUISITION_TIME_12_uS 0x06000000
472#define ADC_CONFIG_REG_AQUISITION_TIME_16_uS 0x07000000
473
474// 3 bits of end delay time (28 to 30)
475#define ADC_CONFIG_REG_END_DELAY_TIME_0p3_uS 0x00000000
476#define ADC_CONFIG_REG_END_DELAY_TIME_1_uS 0x10000000
477#define ADC_CONFIG_REG_END_DELAY_TIME_2_uS 0x20000000
478#define ADC_CONFIG_REG_END_DELAY_TIME_3_uS 0x30000000
479#define ADC_CONFIG_REG_END_DELAY_TIME_4_uS 0x40000000
480#define ADC_CONFIG_REG_END_DELAY_TIME_8_uS 0x50000000
481#define ADC_CONFIG_REG_END_DELAY_TIME_12_uS 0x60000000
482#define ADC_CONFIG_REG_END_DELAY_TIME_16_uS 0x70000000
483
484// use this when uninit a channel
485#define ADC_CONFIG_REG_CLEAR_VALUE 0x240000FF
486
487
488// *****************************************************************
489// these defines help when dealing with the CH_X_BURST register (0x24, 0x34, 0x44...)
490#define ADC_BURST_REG_DISABLE_BURST 0x00000000
491#define ADC_BURST_REG_ENABLE_BURST 0x80000000
492
493// *****************************************************************
494// these defines help when dealing with the CH_X_THRESHHOLD register (0x28, 0x38, 0x48...)
495// this register is 14 bits of low threshhold (bits 0-13)
496// and then 14 buts of high threshhold (bits 16-29)
497// basically the low 2 bytes is low TH and high 2 bytes is high TH but only uses 14 bits
498
499#define ADC_THRESHHOLD_LOW_DEFAULT 0x00000000
500#define ADC_THRESHHOLD_HIGH_DEFAULT 0x3FFF0000
501
502// *****************************************************************
503// these defines help when dealing with the ENABLE DMA register (0x100)
504#define ADC_ENDMA_REG_ENABLE_DMA 0x01
505
506// *****************************************************************
507// these defines help when dealing with the RESET DMA register (0x104)
508#define ADC_ENDMA_REG_RESET_DMA 0x01
509
510// *****************************************************************
511// these defines help when dealing with the DMA SETTINGS register (0x110)
512
513// bit 0
514#define ADC_DMASET_REG_LOAD_ADDR_ON_DMA_START 0x00
515#define ADC_DMASET_REG_LOAD_ADDR_ON_DMA_RESET 0x01
516
517// bit 4,5
518#define ADC_DMASET_REG_4_BYTE_FORMAT 0x00
519#define ADC_DMASET_REG_2_BYTE_FORMAT 0x10
520#define ADC_DMASET_REG_1_BYTE_FORMAT 0x20
521
522// *****************************************************************
523// these defines help when dealing with the INTERRUPT registers (0x120, 0x124, 0x128)
524#define TR_HAL_ADC_INTERRUPT_DMA 0x0000001
525#define TR_HAL_ADC_INTERRUPT_DONE 0x0000004
526#define TR_HAL_ADC_INTERRUPT_VALID 0x0000008
527#define TR_HAL_ADC_INTERRUPT_MODE_DONE 0x0000010
528#define TR_HAL_ADC_INTERRUPT_CHAN_0 0x0040000
529#define TR_HAL_ADC_INTERRUPT_CHAN_1 0x0080000
530#define TR_HAL_ADC_INTERRUPT_CHAN_2 0x0100000
531#define TR_HAL_ADC_INTERRUPT_CHAN_3 0x0200000
532#define TR_HAL_ADC_INTERRUPT_CHAN_4 0x0400000
533#define TR_HAL_ADC_INTERRUPT_CHAN_5 0x0800000
534#define TR_HAL_ADC_INTERRUPT_CHAN_6 0x1000000
535#define TR_HAL_ADC_INTERRUPT_CHAN_7 0x2000000
536
537#define TR_HAL_ADC_INTERRUPT_LOW_THRESH 0x0003FF00
538#define TR_HAL_ADC_INTERRUPT_HIGH_THRESH 0x0FFC0000
539
540#define TR_HAL_ADC_INTERRUPT_ALL 0x0FFFFF1D
541#define TR_HAL_ADC_INTERRUPT_BASE 0x0000001D
542
543// these are the events that can come back to the callback
544#define TR_HAL_ADC_EVENT_CH_0_RESULT 0x001
545#define TR_HAL_ADC_EVENT_CH_1_RESULT 0x002
546#define TR_HAL_ADC_EVENT_CH_2_RESULT 0x004
547#define TR_HAL_ADC_EVENT_CH_3_RESULT 0x008
548#define TR_HAL_ADC_EVENT_CH_4_RESULT 0x010
549#define TR_HAL_ADC_EVENT_CH_5_RESULT 0x020
550#define TR_HAL_ADC_EVENT_CH_6_RESULT 0x040
551#define TR_HAL_ADC_EVENT_CH_7_RESULT 0x080
552#define TR_HAL_ADC_EVENT_ALL_CH_DONE 0x100
553#define TR_HAL_ADC_EVENT_DMA 0x200
554
555
556// *****************************************************************
557// these defines help when dealing with the RESULT OVERSAMPLE register (0x12C)
558#define TR_HAL_ADC_R0_RESULT_MASK 0x00003FFF
559
560
561// *****************************************************************
562// these defines help when dealing with the RESULT DIGITAL and RESULT ANALOG register (0x130, 0x134)
563#define TR_HAL_ADC_R1_RESULT_MASK 0x00000FFF
564#define TR_HAL_ADC_R2_RESULT_MASK 0x00000FFF
565
566
567// *****************************************************************
568// this orients the ADC REGISTERS struct with the correct address
569// so referencing a field will now read/write the correct ADC
570// register chip address
571#define ADC_REGISTERS ((ADC_REGISTERS_T *) CHIP_MEMORY_MAP_ADC_BASE)
572
573
574// *****************************************************************
575// this orients the AUX COMP REGISTERS struct with the correct address
576// so referencing a field will now read/write the correct register
577// chip address
578#define AUX_COMP_REGISTERS ((AUX_COMPARATOR_REGISTERS_T *) CHIP_MEMORY_MAP_AUX_COMPARATOR_BASE)
579
580
584typedef void (*tr_hal_adc_event_callback_t) (uint32_t raw_result,
585 uint32_t converted_result,
586 uint32_t event_bitmask,
587 uint32_t int_status);
588
589
600
601
613
614
618#define TR_HAL_ADC_DEFAULT_GAIN 6
619
620
633
634
638#define TR_HAL_ADC_THRESH_LOW_DEFAULT 0x0000
639#define TR_HAL_ADC_THRESH_HIGH_DEFAULT 0x0003
640
641
651
668
669
674typedef struct
675{
676 // pin(s) to use for the ADC
677 // use both pin P (positive) and pin N (negative) when using a differential signal
678 // use just pin P when using a single ended signal
679 tr_hal_gpio_pin_t adc_pin_p;
680 tr_hal_gpio_pin_t adc_pin_n;
681
682 // mode: one-shot, timer, or scan
684
685 // start immediately or not?
686 bool start_now;
687
688 // resolution (8-bit, 10-bit, 12-bit, 14-bit)
689 tr_hal_adc_resolution_t resolution;
690
691 // VGA gain, this must be in increments of 3 dB
692 uint16_t vga_gain_in_dB;
693
694 // pull
695 tr_hal_adc_pull_mode_t pin_p_pull_mode;
696 tr_hal_adc_pull_mode_t pin_n_pull_mode;
697
698 // aquisition time and end delay time
699 tr_hal_time_t aquisition_time;
700 tr_hal_time_t end_delay_time;
701
702 // clock select and clock divider
703 tr_hal_adc_clock_t clock_to_use;
704 uint32_t clock_divider;
705
706 // enable burst
707 bool enable_burst_mode;
708
709 // oversample setting
710 tr_hal_adc_oversample_t oversample;
711
712 // threshhold: high and low (for scan mode)
713 uint16_t threshhold_low;
714 uint16_t threshhold_high;
715
716 // interrupts
717 bool interrupt_enabled;
718 tr_hal_int_pri_t interrupt_priority;
719
720 // event callback from HAL to App when a reading is ready
721 // if the app doesn't want this, then set it to NULL
722 tr_hal_adc_event_callback_t event_handler_fx;
723
724 // these are for doing conversion of an ADC reading to uV
725 // the values could be pulled from NV from cal values
726 // or set constant if there isn't enough flux
727 bool enable_microvolt_conversion;
728 uint32_t min_expected_adc_reading;
729 uint32_t max_expected_adc_reading;
730 uint32_t min_microvolt_value;
731 uint32_t max_microvolt_value;
732
734
735
741#define DEFAULT_ADC_SINGLE_ENDED_CONFIG \
742 { \
743 .adc_pin_p = (tr_hal_gpio_pin_t) { DEFAULT_ADC_PIN }, \
744 .adc_pin_n = (tr_hal_gpio_pin_t) { TR_HAL_PIN_NOT_SET }, \
745 .mode = TR_HAL_ADC_MODE_ONE_SHOT, \
746 .start_now = false, \
747 .resolution = TR_HAL_ADC_MODE_RESOLUTION_12_BIT, \
748 .vga_gain_in_dB = TR_HAL_ADC_DEFAULT_GAIN, \
749 .pin_p_pull_mode = TR_HAL_ADC_PULL_NOT_USED, \
750 .pin_n_pull_mode = TR_HAL_ADC_PULL_NOT_USED, \
751 .aquisition_time = TR_HAL_ADC_TIME_4, \
752 .end_delay_time = TR_HAL_ADC_TIME_2, \
753 .clock_to_use = ADC_REG_TIMER_USE_SYSTEM_CLOCK, \
754 .clock_divider = 4, \
755 .enable_burst_mode = true, \
756 .oversample = TR_HAL_ADC_REG_SAMPLE_NO_OVERSAMPLE, \
757 .threshhold_low = TR_HAL_ADC_THRESH_LOW_DEFAULT, \
758 .threshhold_high = TR_HAL_ADC_THRESH_HIGH_DEFAULT, \
759 .interrupt_enabled = false, \
760 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
761 .event_handler_fx = NULL, \
762 .enable_microvolt_conversion = true, \
763 .min_expected_adc_reading = 3900, \
764 .max_expected_adc_reading = 10000, \
765 .min_microvolt_value = 0, \
766 .max_microvolt_value = 3300000, \
767 }
768
769
773
774
775#endif // T32CZ20_ADC_H_
tr_hal_int_pri_t
values and a range checking function for setting the interrupt priority in the Trident HAL APIs
Definition tr_hal_platform.h:34
This file contains the CHIP SPECIFIC types and defines for the T32CZ20.
tr_hal_adc_clock_t
Definition T32CM11_adc.h:508
#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_12_BIT
Definition T32CM11_adc.h:252
#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_8_BIT
Definition T32CM11_adc.h:250
#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_14_BIT
Definition T32CM11_adc.h:253
void(* tr_hal_adc_event_callback_t)(uint32_t raw_result, uint32_t converted_result, uint32_t event_bitmask, uint32_t int_status)
Definition T32CM11_adc.h:447
tr_hal_adc_mode_t
Definition T32CM11_adc.h:457
tr_hal_adc_channel_id_t
Definition T32CM11_adc.h:33
tr_hal_adc_resolution_t
Definition T32CM11_adc.h:469
#define ADC_REG_SAMPLE_OUTPUT_RESOLUTION_10_BIT
Definition T32CM11_adc.h:251
union tr_sadc_ana_set1_s tr_sadc_ana_set1_t
tr_hal_adc_oversample_t
Definition T32CM11_adc.h:269
tr_hal_time_t
Definition T32CM11_adc.h:520
tr_hal_adc_pull_mode_t
Definition T32CM11_adc.h:488
@ TR_HAL_ADC_USE_SYSTEM_CLOCK
Definition T32CM11_adc.h:509
@ TR_HAL_ADC_USE_SLOW_CLOCK
Definition T32CM11_adc.h:510
@ TR_HAL_ADC_MODE_TIMER
Definition T32CM11_adc.h:459
@ TR_HAL_ADC_MODE_SCAN
Definition T32CM11_adc.h:460
@ TR_HAL_ADC_MODE_ONE_SHOT
Definition T32CM11_adc.h:458
@ ADC_CHANNEL_0_ID
Definition T32CM11_adc.h:34
@ ADC_CHANNEL_1_ID
Definition T32CM11_adc.h:35
@ ADC_CHANNEL_2_ID
Definition T32CM11_adc.h:36
@ ADC_CHANNEL_3_ID
Definition T32CM11_adc.h:37
@ TR_HAL_ADC_MODE_RESOLUTION_12_BIT
Definition T32CM11_adc.h:472
@ TR_HAL_ADC_MODE_RESOLUTION_10_BIT
Definition T32CM11_adc.h:471
@ TR_HAL_ADC_MODE_RESOLUTION_8_BIT
Definition T32CM11_adc.h:470
@ TR_HAL_ADC_MODE_RESOLUTION_14_BIT
Definition T32CM11_adc.h:473
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_128
Definition T32CM11_adc.h:277
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_8
Definition T32CM11_adc.h:273
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_16
Definition T32CM11_adc.h:274
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_256
Definition T32CM11_adc.h:278
@ TR_HAL_ADC_REG_SAMPLE_NO_OVERSAMPLE
Definition T32CM11_adc.h:270
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_4
Definition T32CM11_adc.h:272
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_32
Definition T32CM11_adc.h:275
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_2
Definition T32CM11_adc.h:271
@ TR_HAL_ADC_REG_SAMPLE_OVERSAMPLE_64
Definition T32CM11_adc.h:276
@ TR_HAL_ADC_TIME_16
Definition T32CM11_adc.h:528
@ TR_HAL_ADC_TIME_3
Definition T32CM11_adc.h:524
@ TR_HAL_ADC_TIME_2
Definition T32CM11_adc.h:523
@ TR_HAL_ADC_TIME_4
Definition T32CM11_adc.h:525
@ TR_HAL_ADC_TIME_1
Definition T32CM11_adc.h:522
@ TR_HAL_ADC_TIME_12
Definition T32CM11_adc.h:527
@ TR_HAL_ADC_TIME_8
Definition T32CM11_adc.h:526
@ TR_HAL_ADC_TIME_HALF
Definition T32CM11_adc.h:521
@ TR_HAL_ADC_PULL_LOW
Definition T32CM11_adc.h:489
@ TR_HAL_ADC_PULL_NOT_USED
Definition T32CM11_adc.h:492
@ TR_HAL_ADC_PULL_HIGH
Definition T32CM11_adc.h:490
union tr_sadc_ana_set0_s tr_sadc_ana_set0_t
union tr_aux_comp_ana_ctl_s tr_aux_comp_ana_ctl_t
union tr_sadc_ana_set1_s tr_sadc_ana_set1_t
@ ADC_CHANNEL_5_ID
Definition T32CZ20_adc.h:39
@ ADC_CHANNEL_6_ID
Definition T32CZ20_adc.h:40
@ ADC_CHANNEL_4_ID
Definition T32CZ20_adc.h:38
@ TR_HAL_ADC_PULL_TO_GND
Definition T32CZ20_adc.h:629
@ TR_HAL_ADC_PULL_TO_VCC
Definition T32CZ20_adc.h:628
the struct we use so we can address registers using field names
Definition T32CM11_adc.h:122
__IO uint32_t dma_next_ptr_addr
Definition T32CM11_adc.h:185
__IO uint32_t interrupt_enable
Definition T32CM11_adc.h:191
__IO uint32_t result_oversample
Definition T32CM11_adc.h:195
__IO uint32_t dma_reserved2
Definition T32CM11_adc.h:187
__IO tr_sadc_ana_set1_t analog_settings1
Definition T32CM11_adc.h:174
__IO uint32_t dma_buffer_addr
Definition T32CM11_adc.h:183
__IO uint32_t reserved3[15]
Definition T32CZ20_adc.h:231
__IO uint32_t reset_dma
Definition T32CM11_adc.h:181
__IO uint32_t interrupt_status
Definition T32CM11_adc.h:192
__IO uint32_t dma_settings
Definition T32CZ20_adc.h:238
__IO uint32_t dma_buffer_size
Definition T32CM11_adc.h:182
__IO uint32_t dma_status
Definition T32CM11_adc.h:186
__IO uint32_t interrupt_clear
Definition T32CM11_adc.h:190
__IO uint32_t result_digital
Definition T32CM11_adc.h:196
__IO uint32_t result_analog
Definition T32CM11_adc.h:197
__IO uint32_t enable_dma
Definition T32CM11_adc.h:180
__IO tr_sadc_ana_set0_t analog_settings0
Definition T32CZ20_adc.h:227
Definition T32CZ20_adc.h:288
__IO uint32_t AUXCOMP_DIG_CTRL1
Definition T32CZ20_adc.h:291
__IO uint32_t AUXCOMP_DIG_CTRL2
Definition T32CZ20_adc.h:292
__IO tr_aux_comp_ana_ctl_t COMP_ANA_CTRL
Definition T32CZ20_adc.h:289
__IO uint32_t AUXCOMP_DIG_CTRL0
Definition T32CZ20_adc.h:290
Definition T32CM11_adc.h:86
uint32_t COMP_VSEL
Definition T32CZ20_adc.h:271
uint32_t COMP_PW
Definition T32CZ20_adc.h:267
uint32_t RESERVED1
Definition T32CZ20_adc.h:275
uint32_t COMP_TC
Definition T32CZ20_adc.h:274
uint32_t COMP_CHSEL
Definition T32CZ20_adc.h:273
uint32_t COMP_SELREF
Definition T32CZ20_adc.h:265
uint32_t COMP_SELHYS
Definition T32CZ20_adc.h:268
uint32_t COMP_EN_START
Definition T32CZ20_adc.h:276
uint32_t COMP_REFSEL
Definition T32CZ20_adc.h:272
uint32_t COMP_SELINPUT
Definition T32CZ20_adc.h:266
uint32_t RESERVED2
Definition T32CZ20_adc.h:277
uint32_t COMP_PSRR
Definition T32CZ20_adc.h:270
uint32_t COMP_SWDIV
Definition T32CZ20_adc.h:269
Definition T32CM11_adc.h:538
pin type
Definition tr_hal_platform.h:23
Definition T32CZ20_adc.h:120
uint32_t RESERVED1
Definition T32CZ20_adc.h:130
uint32_t AUX_ADC_PW
Definition T32CZ20_adc.h:132
uint32_t AUX_ADC_CLK_SEL
Definition T32CZ20_adc.h:125
uint32_t AUX_ADC_MODE
Definition T32CZ20_adc.h:122
uint32_t AUX_ADC_OUTPUTSTB
Definition T32CZ20_adc.h:123
uint32_t AUX_ADC_DEBUG
Definition T32CZ20_adc.h:121
uint32_t RESERVED4
Definition T32CZ20_adc.h:137
uint32_t AUX_ADC_OSPN
Definition T32CZ20_adc.h:124
uint32_t AUX_ADC_MDLY
Definition T32CZ20_adc.h:127
uint32_t AUX_ADC_STB_BIT
Definition T32CZ20_adc.h:134
uint32_t RESERVED3
Definition T32CZ20_adc.h:135
uint32_t AUX_ADC_SEL_DUTY
Definition T32CZ20_adc.h:128
uint32_t AUX_ADC_BR
Definition T32CZ20_adc.h:131
uint32_t AUX_ADC_MCAP
Definition T32CZ20_adc.h:126
uint32_t AUX_ADC_OS
Definition T32CZ20_adc.h:129
uint32_t RESERVED2
Definition T32CZ20_adc.h:133
uint32_t AUX_PW
Definition T32CZ20_adc.h:136
Definition T32CM11_adc.h:101
uint32_t AUX_VGA_CMSEL
Definition T32CZ20_adc.h:147
uint32_t AUX_VGA_TEST_AIO_EN
Definition T32CZ20_adc.h:161
uint32_t AUX_VGA_PW
Definition T32CZ20_adc.h:156
uint32_t AUX_TEST_MODE
Definition T32CZ20_adc.h:159
uint32_t AUX_VGA_LOUT
Definition T32CZ20_adc.h:151
uint32_t AUX_DC_ADJ
Definition T32CZ20_adc.h:157
uint32_t AUX_VGA_SW_VDD
Definition T32CZ20_adc.h:152
uint32_t AUX_VGA_ACM
Definition T32CZ20_adc.h:154
uint32_t CFG_EN_CLKAUX
Definition T32CM11_adc.h:111
uint32_t RESERVED1
Definition T32CM11_adc.h:108
uint32_t AUX_VGA_SIN
Definition T32CZ20_adc.h:149
uint32_t AUX_VGA_COMP
Definition T32CZ20_adc.h:148
uint32_t AUX_VGA_VLDO
Definition T32CZ20_adc.h:153
Definition T32CZ20_adc.h:262
uint32_t reg
Definition T32CZ20_adc.h:279
struct tr_aux_comp_ana_ctl_s::tr_aux_comp_ana_ctl_b bit
Definition T32CZ20_adc.h:118
struct tr_sadc_ana_set0_s::tr_sadc_ana_set0_b bit
uint32_t reg
Definition T32CZ20_adc.h:140
Definition T32CM11_adc.h:99
uint32_t reg
Definition T32CM11_adc.h:114
struct tr_sadc_ana_set1_s::tr_sadc_ana_set1_b bit