MAX32665 Peripheral Driver API
Peripheral Driver API for the MAX32665
adc.h
1 
6 /* ****************************************************************************
7  * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  *************************************************************************** */
38 
39 /* Define to prevent redundant inclusion */
40 #ifndef _ADC_H_
41 #define _ADC_H_
42 
43 /* **** Includes **** */
44 #include <stdint.h>
45 #include "adc_regs.h"
46 #include "mcr_regs.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
58 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN0 ((uint32_t)(0x00000000UL))
60 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN1 ((uint32_t)(0x00000001UL))
61 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN2 ((uint32_t)(0x00000002UL))
62 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN3 ((uint32_t)(0x00000003UL))
63 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN4 ((uint32_t)(0x00000004UL))
64 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN5 ((uint32_t)(0x00000005UL))
65 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN6 ((uint32_t)(0x00000006UL))
66 #define MXC_V_ADC_CTRL_ADC_CHSEL_AIN7 ((uint32_t)(0x00000007UL))
67 #define MXC_V_ADC_CTRL_ADC_CHSEL_VCOREA ((uint32_t)(0x00000008UL))
68 #define MXC_V_ADC_CTRL_ADC_CHSEL_VCOREB ((uint32_t)(0x00000009UL))
69 #define MXC_V_ADC_CTRL_ADC_CHSEL_VRXOUT ((uint32_t)(0x0000000AUL))
70 #define MXC_V_ADC_CTRL_ADC_CHSEL_VTXOUT ((uint32_t)(0x0000000BUL))
71 #define MXC_V_ADC_CTRL_ADC_CHSEL_VDDA ((uint32_t)(0x0000000CUL))
72 #define MXC_V_ADC_CTRL_ADC_CHSEL_VDDB ((uint32_t)(0x0000000DUL))
73 #define MXC_V_ADC_CTRL_ADC_CHSEL_VDDI0 ((uint32_t)(0x0000000EUL))
74 #define MXC_V_ADC_CTRL_ADC_CHSEL_VDDI0H ((uint32_t)(0x0000000FUL))
75 #define MXC_V_ADC_CTRL_ADC_CHSEL_VREGI ((uint32_t)(0x00000010UL))
76 
77 
78 /***************************************************************************************************************
79  DATA STRUCTURES FOR ADC INITIALIZATION
80 ***************************************************************************************************************/
85 typedef enum {
87  MXC_ADC_CH_1 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN1,
88  MXC_ADC_CH_2 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN2,
89  MXC_ADC_CH_3 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN3,
90  MXC_ADC_CH_4 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN4,
91  MXC_ADC_CH_5 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN5,
92  MXC_ADC_CH_6 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN6,
93  MXC_ADC_CH_7 = MXC_V_ADC_CTRL_ADC_CHSEL_AIN7,
94  MXC_ADC_CH_VCOREA = MXC_V_ADC_CTRL_ADC_CHSEL_VCOREA,
95  MXC_ADC_CH_VCOREB = MXC_V_ADC_CTRL_ADC_CHSEL_VCOREB,
96  MXC_ADC_CH_VRXOUT = MXC_V_ADC_CTRL_ADC_CHSEL_VRXOUT,
97  MXC_ADC_CH_VTXOUT = MXC_V_ADC_CTRL_ADC_CHSEL_VTXOUT,
98  MXC_ADC_CH_VDDA = MXC_V_ADC_CTRL_ADC_CHSEL_VDDA,
99  MXC_ADC_CH_VDDB = MXC_V_ADC_CTRL_ADC_CHSEL_VDDB,
100  MXC_ADC_CH_VDDIO = MXC_V_ADC_CTRL_ADC_CHSEL_VDDI0,
101  MXC_ADC_CH_VDDIOH = MXC_V_ADC_CTRL_ADC_CHSEL_VDDI0H,
102  MXC_ADC_CH_VREGI = MXC_V_ADC_CTRL_ADC_CHSEL_VREGI,
104 
110 typedef enum {
111  MXC_ADC_MONITOR_0,
112  MXC_ADC_MONITOR_1,
113  MXC_ADC_MONITOR_2,
114  MXC_ADC_MONITOR_3,
116 
122 typedef enum {
131 
136 typedef void (*mxc_adc_complete_cb_t) (void * req, int error);
137 
142 typedef void (*mxc_adc_monitor_cb_t) (void * req, int error);
143 
148 typedef struct {
156 
161 typedef struct {
167 
168 
174 int MXC_ADC_Init (void);
175 
181 int MXC_ADC_Shutdown (void);
182 
188 int MXC_ADC_Busy (void);
189 
195 void MXC_ADC_EnableInt (uint32_t flags);
196 
202 void MXC_ADC_DisableInt (uint32_t flags);
203 
209 int MXC_ADC_GetFlags (void);
210 
216 void MXC_ADC_ClearFlags (uint32_t flags);
217 
225 int MXC_ADC_SetConversionSpeed (uint32_t hz);
226 
233 
239 void MXC_ADC_SetDataAlignment (int msbJustify);
240 
249 
257 
265 
273 void MXC_ADC_SetMonitorHighThreshold (mxc_adc_monitor_t monitor, uint32_t threshold);
274 
283 
291 void MXC_ADC_SetMonitorLowThreshold (mxc_adc_monitor_t monitor, uint32_t threshold);
292 
301 
310 
319 
328 
335 
345 
358 
369 int MXC_ADC_StartConversionDMA (mxc_adc_chsel_t channel, uint16_t *data, void (*callback) (int, int));
370 
377 int MXC_ADC_Handler (void);
378 
389 
400 
407 
416 
423 int MXC_ADC_GetData (uint16_t *outdata);
426 #ifdef __cplusplus
427 }
428 #endif
429 
430 #endif /* _ADC_H_ */
MXC_ADC_CH_7
@ MXC_ADC_CH_7
VDD18 input select.
Definition: adc.h:93
MXC_ADC_SCALE_1
@ MXC_ADC_SCALE_1
ADC Scale by 1x (no scaling)
Definition: adc.h:124
MXC_ADC_EnableInt
void MXC_ADC_EnableInt(uint32_t flags)
Enable specific ADC interrupts.
MXC_ADC_GetMonitorChannel
int MXC_ADC_GetMonitorChannel(mxc_adc_monitor_t monitor)
Get the channel used by a monitor.
MXC_ADC_CH_0
@ MXC_ADC_CH_0
Select Channel 0.
Definition: adc.h:86
MXC_ADC_SCALE_2X
@ MXC_ADC_SCALE_2X
ADC Scale by 2x (this scales ADC Reference by 1/2)
Definition: adc.h:123
MXC_ADC_GetMonitorLowThreshold
int MXC_ADC_GetMonitorLowThreshold(mxc_adc_monitor_t monitor)
Set the low limit for a specific monitor.
MXC_ADC_GetConversionSpeed
int MXC_ADC_GetConversionSpeed(void)
Gets the current ADC conversion speed.
MXC_ADC_EnableMonitor
void MXC_ADC_EnableMonitor(mxc_adc_monitor_t monitor)
Enable channel high/low monitor.
mxc_adc_monitor_req_t::highThreshold
int highThreshold
High Threshold for monitor (RAW ADC counts)
Definition: adc.h:153
MXC_ADC_CH_VRXOUT
@ MXC_ADC_CH_VRXOUT
VRTC divided by 2.
Definition: adc.h:96
MXC_ADC_Handler
int MXC_ADC_Handler(void)
Call this function from the ADC ISR when using Async API functions.
MXC_ADC_GetData
int MXC_ADC_GetData(uint16_t *outdata)
Gets the result from the previous ADC conversion.
MXC_ADC_GetMonitorHighThreshold
int MXC_ADC_GetMonitorHighThreshold(mxc_adc_monitor_t monitor)
Set the high limit for a specific monitor.
MXC_ADC_SCALE_8
@ MXC_ADC_SCALE_8
ADC Scale by 1/8 (this uses 1/4 and an additional 1/2 scaling)
Definition: adc.h:129
MXC_ADC_CH_4
@ MXC_ADC_CH_4
Channel 0 divided by 5.
Definition: adc.h:90
mxc_adc_monitor_cb_t
void(* mxc_adc_monitor_cb_t)(void *req, int error)
Callback used when a monitor detects that a channel has reached a limit.
Definition: adc.h:142
MXC_ADC_ConvertAsync
int MXC_ADC_ConvertAsync(mxc_adc_conversion_req_t req)
Perform a conversion on a specific channel.
mxc_adc_monitor_req_t::channel
mxc_adc_chsel_t channel
Channel to use.
Definition: adc.h:151
MXC_ADC_Shutdown
int MXC_ADC_Shutdown(void)
Shuts down the ADC.
MXC_ADC_DisableInt
void MXC_ADC_DisableInt(uint32_t flags)
Disable specific ADC interrupts.
MXC_ADC_SetExtScale
void MXC_ADC_SetExtScale(mxc_adc_scale_t scale)
Sets the scaling used for conversions on external channels.
mxc_adc_monitor_req_t::callback
mxc_adc_monitor_cb_t callback
Function to call when the channel crosses threshold.
Definition: adc.h:154
MXC_ADC_CH_5
@ MXC_ADC_CH_5
Channel 1 divided by 5.
Definition: adc.h:91
MXC_ADC_Busy
int MXC_ADC_Busy(void)
Checks if the ADC is busy (performing a conversion)
MXC_ADC_MonitorAsync
void MXC_ADC_MonitorAsync(mxc_adc_monitor_req_t req)
Monitor a specific channel for an out of range event.
MXC_ADC_Init
int MXC_ADC_Init(void)
Performs the ADC startup procedure.
MXC_ADC_DisableMonitorAsync
void MXC_ADC_DisableMonitorAsync(mxc_adc_monitor_t monitor)
Disable a callback for a monitor.
MXC_ADC_SCALE_2
@ MXC_ADC_SCALE_2
ADC Scale by 1/2.
Definition: adc.h:125
MXC_ADC_SCALE_3
@ MXC_ADC_SCALE_3
ADC Scale by 1/3.
Definition: adc.h:126
MXC_ADC_CH_1
@ MXC_ADC_CH_1
Select Channel 1.
Definition: adc.h:87
MXC_ADC_StartConversion
int MXC_ADC_StartConversion(mxc_adc_chsel_t channel)
Perform a conversion on a specific channel.
MXC_ADC_Convert
int MXC_ADC_Convert(mxc_adc_conversion_req_t *req)
Perform a conversion on a specific channel.
mxc_adc_monitor_t
mxc_adc_monitor_t
Enumeration type for the ADC Monitors 4 Monitors exist and can be mapped to any ADC channels.
Definition: adc.h:110
mxc_adc_conversion_req_t
Used to set up channel for conversion.
Definition: adc.h:161
MXC_ADC_CH_VCOREA
@ MXC_ADC_CH_VCOREA
VDD12 input select.
Definition: adc.h:94
MXC_V_ADC_CTRL_ADC_CHSEL_AIN0
#define MXC_V_ADC_CTRL_ADC_CHSEL_AIN0
< Macros to select ADC channels
Definition: adc.h:59
mxc_adc_chsel_t
mxc_adc_chsel_t
Enumeration type for the ADC Input Channels.
Definition: adc.h:85
MXC_ADC_SetMonitorLowThreshold
void MXC_ADC_SetMonitorLowThreshold(mxc_adc_monitor_t monitor, uint32_t threshold)
Set the low limit for a specific monitor.
MXC_ADC_SetDataAlignment
void MXC_ADC_SetDataAlignment(int msbJustify)
Set the data alignment.
MXC_ADC_CH_2
@ MXC_ADC_CH_2
Select Channel 2.
Definition: adc.h:88
MXC_ADC_EnableMonitorAsync
void MXC_ADC_EnableMonitorAsync(mxc_adc_monitor_t monitor, mxc_adc_monitor_cb_t callback)
Set a callback to be called when a monitor goes out of range.
mxc_adc_scale_t
mxc_adc_scale_t
Enumeration type for ADC Scale values Internal ADC channels automatically use the most appropriate sc...
Definition: adc.h:122
MXC_ADC_StartConversionAsync
int MXC_ADC_StartConversionAsync(mxc_adc_chsel_t channel, mxc_adc_complete_cb_t callback)
Perform a conversion on a specific channel.
MXC_ADC_CH_3
@ MXC_ADC_CH_3
Select Channel 3.
Definition: adc.h:89
MXC_ADC_Monitor
void MXC_ADC_Monitor(mxc_adc_monitor_req_t req)
Monitor a specific channel for an out of range event.
MXC_ADC_SCALE_4
@ MXC_ADC_SCALE_4
ADC Scale by 1/4.
Definition: adc.h:127
MXC_ADC_ClearFlags
void MXC_ADC_ClearFlags(uint32_t flags)
Performs the ADC startup procedure.
mxc_adc_monitor_req_t
Used to set up a monitor to watch a channel.
Definition: adc.h:148
MXC_ADC_CH_6
@ MXC_ADC_CH_6
VDDB divided by 4.
Definition: adc.h:92
MXC_ADC_GetFlags
int MXC_ADC_GetFlags(void)
Performs the ADC startup procedure.
mxc_adc_monitor_req_t::monitor
mxc_adc_monitor_t monitor
Monitor to use.
Definition: adc.h:149
mxc_adc_monitor_req_t::lowThreshold
int lowThreshold
Low Threshold for monitor (RAW ADC counts)
Definition: adc.h:152
MXC_ADC_DisableMonitor
void MXC_ADC_DisableMonitor(mxc_adc_monitor_t monitor)
Disable channel high/low monitor.
MXC_ADC_SetMonitorChannel
void MXC_ADC_SetMonitorChannel(mxc_adc_monitor_t monitor, mxc_adc_chsel_t channel)
Set a monitor to use a specific channel.
MXC_ADC_StartConversionDMA
int MXC_ADC_StartConversionDMA(mxc_adc_chsel_t channel, uint16_t *data, void(*callback)(int, int))
Perform a conversion on a specific channel.
mxc_adc_monitor_req_t::scale
mxc_adc_scale_t scale
Channel scale to use (if external channel)
Definition: adc.h:150
mxc_adc_complete_cb_t
void(* mxc_adc_complete_cb_t)(void *req, int error)
Callback used when a conversion event is complete.
Definition: adc.h:136
MXC_ADC_CH_VTXOUT
@ MXC_ADC_CH_VTXOUT
TMON input select.
Definition: adc.h:97
mxc_adc_conversion_req_t::rawADCValue
int rawADCValue
Result of the conversion.
Definition: adc.h:164
MXC_ADC_SetMonitorHighThreshold
void MXC_ADC_SetMonitorHighThreshold(mxc_adc_monitor_t monitor, uint32_t threshold)
Set the high limit for a specific monitor.
MXC_ADC_SCALE_6
@ MXC_ADC_SCALE_6
ADC Scale by 1/6 (this uses 1/3 and an additional 1/2 scaling)
Definition: adc.h:128
mxc_adc_conversion_req_t::callback
mxc_adc_complete_cb_t callback
Function to call when callback is complete.
Definition: adc.h:165
MXC_ADC_SetConversionSpeed
int MXC_ADC_SetConversionSpeed(uint32_t hz)
Sets the ADC conversion speed.