MAX78002 Peripheral Driver API
Peripheral Driver API for the MAX78002
adc.h
1
6/******************************************************************************
7 *
8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9 * Analog Devices, Inc.),
10 * Copyright (C) 2023-2024 Analog Devices, Inc.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 ******************************************************************************/
25
26/* Define to prevent redundant inclusion */
27#ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_ADC_H_
28#define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_ADC_H_
29
30/* **** Includes **** */
31#include <stdint.h>
32#include "adc_regs.h"
33#include "mcr_regs.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
46/* MAX78002 Specific TODO */
47#define MAX_ADC_SLOT_NUM 20
48#define MAX_ADC_FIFO_LEN 16
49#define MAX_ADC_RES_DIV_CH 8
50
51/***************************************************************************************************************
52 DATA STRUCTURES FOR ADC INITIALIZATION
53***************************************************************************************************************/
54
59typedef enum {
78
79// AI87-TODO: Github comment the below enum out - ?
84typedef enum {
92
96typedef enum {
97 MXC_ADC_COMP_0 = 1,
98 MXC_ADC_COMP_1 = 2,
99 // MXC_ADC_COMP_HYST_0 = 1 << MXC_F_MCR_AINCOMP_AINCOMPHYST_POS, //Refer to the V HYST specification in the data sheet electrical characteristics
100 // // for the values corresponding to this field value.
101 // MXC_ADC_COMP_HYST_1 = 2 << MXC_F_MCR_AINCOMP_AINCOMPHYST_POS, //Refer to the V HYST specification in the data sheet electrical characteristics
102 // for the values corresponding to this field value.
104
108typedef enum {
115
119typedef enum {
125
129typedef enum {
133
137typedef enum {
141
145typedef enum {
155
159typedef enum {
163
167typedef enum {
174
178typedef enum {
183
188typedef enum {
194
198typedef enum {
203
207typedef enum {
211
213typedef void (*mxc_adc_complete_cb_t)(void *req, int error);
214
218typedef struct {
223 uint32_t trackCount;
224 uint32_t idleCount;
226
230typedef struct {
235
239typedef struct {
247 uint8_t num_slots;
248 int8_t dma_channel;
250
257
264
270void MXC_ADC_EnableInt(uint32_t flags);
271
277void MXC_ADC_DisableInt(uint32_t flags);
278
285
291void MXC_ADC_ClearFlags(uint32_t flags);
292
300
311int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);
312
327 void (*callback)(int, int));
328
336
345
354
366
375
384
393
401int MXC_ADC_GetData(int *outdata);
402
411
420int MXC_ADC_SlotConfiguration(mxc_adc_slot_req_t *req, uint32_t slot_length);
421
428
435
442
449
455uint16_t MXC_ADC_FIFO_Level(void);
456
463
471int MXC_ADC_FIFO_Threshold_Config(uint32_t fifo_threshold);
472
481
488
497
506
515
524
535int MXC_ConvertTemperature_ToK(uint16_t tempSensor_Readout, mxc_adc_refsel_t ref, float ext_ref,
536 float *temp_k);
537
548int MXC_ConvertTemperature_ToC(uint16_t tempSensor_Readout, mxc_adc_refsel_t ref, float ext_ref,
549 float *temp);
550
561int MXC_ConvertTemperature_ToF(uint16_t tempSensor_Readout, mxc_adc_refsel_t ref, float ext_ref,
562 float *temp);
563
572
575#ifdef __cplusplus
576}
577#endif
578
579#endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_ADC_H_
Registers, Bit Masks and Bit Positions for the ADC Peripheral Module.
#define MXC_S_ADC_CTRL1_AVG_AVG8
Definition: adc_regs.h:196
#define MXC_S_ADC_CTRL1_AVG_AVG32
Definition: adc_regs.h:200
#define MXC_S_ADC_CTRL1_AVG_AVG4
Definition: adc_regs.h:194
#define MXC_S_ADC_CTRL1_AVG_AVG1
Definition: adc_regs.h:190
#define MXC_S_ADC_CTRL1_AVG_AVG16
Definition: adc_regs.h:198
#define MXC_S_ADC_CTRL1_AVG_AVG2
Definition: adc_regs.h:192
#define MXC_V_MCR_ADCCFG2_CH0_DIV2_5K
Definition: mcr_regs.h:299
#define MXC_V_MCR_ADCCFG2_CH0_DIV2_50K
Definition: mcr_regs.h:301
#define MXC_V_MCR_ADCCFG2_CH0_DIV1
Definition: mcr_regs.h:297
mxc_adc_div_lpmode_t lpmode_divder
Divide by 2 control in lpmode.
Definition: adc.h:246
mxc_adc_trig_sel_t hwTrig
HW Trigger Source.
Definition: adc.h:242
uint8_t fifo_threshold
FIFO Threshold Configuration.
Definition: adc.h:244
mxc_adc_chsel_t channel
channel select
Definition: adc.h:231
mxc_adc_divsel_t div
Analog input divider.
Definition: adc.h:232
uint32_t trackCount
Sample Clock High time.
Definition: adc.h:223
mxc_adc_clock_t clock
clock to use
Definition: adc.h:219
mxc_adc_avg_t avg_number
no of samples to average
Definition: adc.h:245
mxc_adc_trig_mode_t trig
trigger mode
Definition: adc.h:241
mxc_adc_dynamic_pullup_t pullup_dyn
Dynamic Pullup.
Definition: adc.h:233
uint32_t idleCount
Sample Clock Low time.
Definition: adc.h:224
mxc_adc_refsel_t ref
ADC reference voltage.
Definition: adc.h:222
mxc_adc_calibration_t cal
skip calibration
Definition: adc.h:221
mxc_adc_clkdiv_t clkdiv
clock divider
Definition: adc.h:220
int8_t dma_channel
The channel to use for DMA-enabled transactions.
Definition: adc.h:248
mxc_adc_conversion_mode_t mode
conversion mode
Definition: adc.h:240
mxc_adc_fifodataformat_t fifo_format
FIFO Data Format.
Definition: adc.h:243
uint8_t num_slots
num of slots in the sequence
Definition: adc.h:247
int MXC_ADC_Configuration(mxc_adc_conversion_req_t *req)
Configures the ADC.
int MXC_ADC_DynamicModeEn(mxc_adc_chsel_t ch)
Enables the ADC Dynamic Power-Up Mode.
mxc_adc_avg_t
Enumeration type for the number of samples to average.
Definition: adc.h:84
mxc_adc_calibration_t
Calibration settings.
Definition: adc.h:129
int MXC_ADC_StartConversion(void)
Initiate configured ADC conversion.
void MXC_ADC_ClearFlags(uint32_t flags)
Performs the ADC startup procedure.
int MXC_ADC_InputDividerSelect(mxc_adc_chsel_t ch, mxc_adc_divsel_t div, mxc_adc_dynamic_pullup_t lpEn)
Selects the analog input divider.
mxc_adc_dynamic_pullup_t
Dynamic Divider pullup control.
Definition: adc.h:207
mxc_adc_trig_sel_t
Hardware trigger select options.
Definition: adc.h:145
int MXC_ConvertTemperature_ToK(uint16_t tempSensor_Readout, mxc_adc_refsel_t ref, float ext_ref, float *temp_k)
Calculates temperature (in K) from ADC readout.
int MXC_ADC_FIFO_Threshold_Config(uint32_t fifo_threshold)
Configures the ADC FIFO threshold register.
mxc_adc_trig_mode_t
trigger mode settings
Definition: adc.h:137
int MXC_ADC_ComparatorHysteresisDis(mxc_adc_comp_t comp)
Disable comparator hysteresis.
int MXC_ADC_AverageConfig(mxc_adc_avg_t avg_number)
Configures number of sample average in the sequence for each channel.
int MXC_ADC_GetData(int *outdata)
Gets the ADC readout after the ADC conversion.
void MXC_ADC_Clear_ChannelSelect(void)
Clear all channel select registers.
mxc_adc_clkdiv_t
Enumeration type for ADC clock divider.
Definition: adc.h:108
int MXC_ADC_DynamicModeDis(mxc_adc_chsel_t ch)
Disables the ADC Dynamic Power-Up Mode.
void MXC_ADC_EnableConversion(void)
Enables the ADC converter.
int MXC_ConvertTemperature_ToC(uint16_t tempSensor_Readout, mxc_adc_refsel_t ref, float ext_ref, float *temp)
Calculates temperature (in C) from ADC readout.
int MXC_ADC_ReferenceSelect(mxc_adc_refsel_t ref)
Selects the desired reference voltage for the ADC.
void MAX_ADC_Flush_FIFO(void)
Flushes the ADC FIFO.
void MXC_ADC_SetConversionDelay(int delay)
Set Sample Delay before Continuous Mode Conversion Restart.
int MXC_ADC_SlotConfiguration(mxc_adc_slot_req_t *req, uint32_t slot_length)
Configures ADC slot and channel registers.
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback)
Perform a conversion on a specific channel.
mxc_adc_chsel_t
Enumeration type for the ADC Input Channels.
Definition: adc.h:59
int MXC_ADC_Init(mxc_adc_req_t *req)
Performs the ADC startup procedure.
mxc_adc_div_lpmode_t
Divide by 2 control in low power mode.
Definition: adc.h:188
void MXC_ADC_EnableInt(uint32_t flags)
Enable specific ADC interrupts.
uint16_t MXC_ADC_FIFO_Level(void)
Provides the ADC FIFO level.
mxc_adc_conversion_mode_t
trigger mode settings
Definition: adc.h:159
mxc_adc_refsel_t
Reference voltage select type.
Definition: adc.h:178
mxc_adc_comp_t
Definition: adc.h:96
int MXC_ADC_SlotsConfig(mxc_adc_conversion_req_t *req)
Configures number of slots for ADC sequence.
void MXC_ADC_TS_SelectEnable(void)
Enables the temperature sensor.
int MXC_ADC_GetFlags(void)
Performs the ADC startup procedure.
int MXC_ADC_StartConversionDMA(mxc_adc_conversion_req_t *req, int *data, void(*callback)(int, int))
Perform a conversion on a specific channel using a DMA transfer. DMA channel must be acquired using M...
void MXC_ADC_TS_SelectDisable(void)
Disables the temperature sensor.
mxc_adc_divsel_t
Analog input divider select.
Definition: adc.h:167
void MXC_ADC_TriggerConfig(mxc_adc_conversion_req_t *req)
Configures ADC Trigger to initiate ADC conversion.
int MXC_ConvertTemperature_ToF(uint16_t tempSensor_Readout, mxc_adc_refsel_t ref, float ext_ref, float *temp)
Calculates temperature (in F) from ADC readout.
int MXC_ADC_ComparatorHysteresisEn(mxc_adc_comp_t comp)
Enable comparator hysteresis.
void MXC_ADC_DisableConversion(void)
Disables the ADC converter.
mxc_adc_clock_t
Clock settings.
Definition: adc.h:119
int MXC_ADC_LowPowerModeDividerSelect(mxc_adc_div_lpmode_t div_lpmode)
Configures Divider (0-12 channel) in the low power mode.
int MXC_ADC_Handler(void)
Call this function from the ADC ISR when using Async API functions.
void MXC_ADC_DisableInt(uint32_t flags)
Disable specific ADC interrupts.
int MXC_ADC_Shutdown(void)
Shuts down the ADC.
mxc_adc_fifodataformat_t
Data FIFO data format.
Definition: adc.h:198
void MXC_ADC_ConversionModeConfig(mxc_adc_conversion_req_t *req)
Configures ADC Conversion Mode: Single vs Continuous Conversion.
@ MXC_ADC_AVG_32
Select Channel 5.
Definition: adc.h:90
@ MXC_ADC_AVG_1
Select Channel 0.
Definition: adc.h:85
@ MXC_ADC_AVG_8
Select Channel 3.
Definition: adc.h:88
@ MXC_ADC_AVG_16
Select Channel 4.
Definition: adc.h:89
@ MXC_ADC_AVG_2
Select Channel 1.
Definition: adc.h:86
@ MXC_ADC_AVG_4
Select Channel 2.
Definition: adc.h:87
@ MXC_ADC_SKIP_CAL
Skip calibration on power-up.
Definition: adc.h:130
@ MXC_ADC_EN_CAL
Calibrate on power-up.
Definition: adc.h:131
@ MXC_ADC_PY_DN_DISABLE
Disable Dynamic Divider Pullup.
Definition: adc.h:208
@ MXC_ADC_PY_DN_ENABLE
Enable Dynamic Divider Pullup.
Definition: adc.h:209
@ MXC_ADC_TRIG_SEL_P1_13
GPIO Port 1, Pin 13.
Definition: adc.h:151
@ MXC_ADC_TRIG_SEL_TMR2
Timer 2 Out Rising Edge.
Definition: adc.h:148
@ MXC_ADC_TRIG_SEL_TEMP_SENS
Temperature Sensor Ready.
Definition: adc.h:153
@ MXC_ADC_TRIG_SEL_TMR1
Timer 1 Out Rising Edge.
Definition: adc.h:147
@ MXC_ADC_TRIG_SEL_P1_14
GPIO Port 1, Pin 14.
Definition: adc.h:152
@ MXC_ADC_TRIG_SEL_TMR3
Timer 3 Out Rising Edge.
Definition: adc.h:149
@ MXC_ADC_TRIG_SEL_P1_12
GPIO Port 1, Pin 12.
Definition: adc.h:150
@ MXC_ADC_TRIG_SEL_TMR0
Timer 0 Out Rising edge.
Definition: adc.h:146
@ MXC_ADC_TRIG_SOFTWARE
Software Trigger.
Definition: adc.h:138
@ MXC_ADC_TRIG_HARDWARE
Hardware Trigger.
Definition: adc.h:139
@ MXC_ADC_CLKDIV_16
ADC Scale by 1/16.
Definition: adc.h:112
@ MXC_ADC_CLKDIV_8
ADC Scale by 1/8.
Definition: adc.h:111
@ MXC_ADC_CLKDIV_4
ADC Scale by 1/4.
Definition: adc.h:110
@ MXC_ADC_CLKDIV_2
ADC Scale by 1/2.
Definition: adc.h:109
@ MXC_ADC_CLKDIV_1
ADC Scale by 1x (no scaling)
Definition: adc.h:113
@ MXC_ADC_CH_VLDO_2P5_DIV4
Select Channel 10, VLDO_2P5DIV4.
Definition: adc.h:70
@ MXC_ADC_CH_VCOREA
Select Channel 8, VCOREA.
Definition: adc.h:68
@ MXC_ADC_CH_6
Select Channel 6.
Definition: adc.h:66
@ MXC_ADC_CH_3
Select Channel 3.
Definition: adc.h:63
@ MXC_ADC_CH_0
Select Channel 0.
Definition: adc.h:60
@ MXC_ADC_CH_VDDA_DIV2
Select Channel 12, VDDA_DIV2.
Definition: adc.h:72
@ MXC_ADC_CH_VCOREB
Select Channel 9, VCOREB.
Definition: adc.h:69
@ MXC_ADC_CH_1
Select Channel 1.
Definition: adc.h:61
@ MXC_ADC_CH_7
Select Channel 7.
Definition: adc.h:67
@ MXC_ADC_CH_VBB_DIV4
Select Channel 14, VBB_DIV4.
Definition: adc.h:74
@ MXC_ADC_CH_5
Select Channel 5.
Definition: adc.h:65
@ MXC_ADC_CH_2
Select Channel 2.
Definition: adc.h:62
@ MXC_ADC_CH_VDDB_DIV4
Select Channel 14, VDDB_DIV4.
Definition: adc.h:75
@ MXC_ADC_CH_VSS
Select Channel 16, VSS.
Definition: adc.h:76
@ MXC_ADC_CH_VLDO_0P9
Select Channel 11, VLDO_0P9.
Definition: adc.h:71
@ MXC_ADC_CH_4
Select Channel 4.
Definition: adc.h:64
@ MXC_ADC_CH_TEMP_SENSOR
Select Channel 13, VDDA_DIV2.
Definition: adc.h:73
@ MXC_ADC_DIV_2_5K_50K_ENABLE
2.5K and 50K divide by 2 enable in lpmode
Definition: adc.h:189
@ MXC_ADC_DIV_2_5K_50K_DISABLE
2.5K and 50K divide by 2 disable in lpmode
Definition: adc.h:192
@ MXC_ADC_DIV_2_5K_DISABLE
2.5K disable and 50K divide by 2 enable in lpmode
Definition: adc.h:190
@ MXC_ADC_DIV_50K_DISABLE
2.5K enable and 50K divide by 2 disable in lpmode
Definition: adc.h:191
@ MXC_ADC_CONTINUOUS_CONV
Hardware Trigger.
Definition: adc.h:161
@ MXC_ADC_ATOMIC_CONV
Software Trigger.
Definition: adc.h:160
@ MXC_ADC_REF_EXT
Use external reference voltage source.
Definition: adc.h:179
@ MXC_ADC_REF_INT_1V25
Use internal 1.25V source.
Definition: adc.h:180
@ MXC_ADC_REF_INT_2V048
Use internal 2.048V souce.
Definition: adc.h:181
@ MXC_ADC_DIV1
No input divider.
Definition: adc.h:168
@ MXC_ADC_DIV2_5K
Divide analog input by two with 5K resistor.
Definition: adc.h:169
@ MXC_ADC_DIV2_50K
Divide analog input by two with 50K resistor.
Definition: adc.h:171
@ MXC_ADC_CLK_HCLK
HCLK CLock.
Definition: adc.h:120
@ MXC_ADC_CLK_IBRO
IBRO Clock.
Definition: adc.h:122
@ MXC_ADC_CLK_EXT
External Clock.
Definition: adc.h:121
@ MXC_ADC_CLK_ERFO
ERFO Clock.
Definition: adc.h:123
@ MXC_ADC_DATA_STATUS
Data(12-bit) plus Status.
Definition: adc.h:199
@ MXC_ADC_DATA
Data(12-bit) only.
Definition: adc.h:200
@ MXC_ADC_RAW_DATA
18-bit raw data
Definition: adc.h:201
ADC Conversion Settings.
Definition: adc.h:239
ADC Settings.
Definition: adc.h:218
ADC Slot Settings.
Definition: adc.h:230
Registers, Bit Masks and Bit Positions for the MCR Peripheral Module.