This section describes the CSDADC Function Prototypes.
Functions | |
cy_en_csdadc_status_t | Cy_CSDADC_Init (const cy_stc_csdadc_config_t *config, cy_stc_csdadc_context_t *context) |
Captures the CSD HW block and configures it to the default state, is called by the application program prior to calling any other function of the middleware. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_Enable (cy_stc_csdadc_context_t *context) |
Initializes the CSDADC firmware modules. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_DeInit (cy_stc_csdadc_context_t *context) |
Stops the middleware operation and releases the CSD HW block. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_WriteConfig (const cy_stc_csdadc_config_t *config, cy_stc_csdadc_context_t *context) |
Updates the CSDADC middleware with the desired configuration. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_RegisterCallback (cy_csdadc_callback_t callbackFunction, cy_stc_csdadc_context_t *context) |
Registers a callback function, which notifies that a callback event occurred in the CSDADC middleware. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_UnRegisterCallback (cy_stc_csdadc_context_t *context) |
This function unregisters the CSDADC middleware callback. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_StartConvert (cy_en_csdadc_conversion_mode_t mode, uint32_t chMask, cy_stc_csdadc_context_t *context) |
Initiates an analog-to-digital conversion. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_StopConvert (cy_en_csdadc_stop_mode_t stopMode, cy_stc_csdadc_context_t *context) |
The function stops conversions in Continuous mode. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_IsEndConversion (const cy_stc_csdadc_context_t *context) |
The function returns the status of the CSDADC's operation. More... | |
uint32_t | Cy_CSDADC_GetConversionStatus (const cy_stc_csdadc_context_t *context) |
The function returns a current CSDADC conversion status. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_Calibrate (cy_stc_csdadc_context_t *context) |
Performs calibration of the CSDADC. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_Wakeup (const cy_stc_csdadc_context_t *context) |
Resumes the middleware after CPU / System Deep Sleep. More... | |
cy_en_syspm_status_t | Cy_CSDADC_DeepSleepCallback (cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode) |
Handles CPU active to CPU / System Deep Sleep power mode transitions for the CSDADC middleware. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_Save (cy_stc_csdadc_context_t *context) |
Saves the state of the CSDADC MW so the functionality can be restored using the Cy_CSDACD_Restore() function. More... | |
cy_en_csdadc_status_t | Cy_CSDADC_Restore (cy_stc_csdadc_context_t *context) |
Resumes the middleware operation if the Cy_CSDADC_Save() function was called previously. More... | |
uint32_t | Cy_CSDADC_GetResult (uint32_t chId, const cy_stc_csdadc_context_t *context) |
Returns the most recent result of a specified channel as an ADC code. More... | |
uint32_t | Cy_CSDADC_GetResultVoltage (uint32_t chId, const cy_stc_csdadc_context_t *context) |
Returns the the most recent result of a specified channel in millivolts. More... | |
uint32_t | Cy_CSDADC_MeasureVdda (cy_stc_csdadc_context_t *context) |
The function measures a VDDA voltage and returns the result in millivolts. More... | |
uint32_t | Cy_CSDADC_MeasureAMuxB (cy_stc_csdadc_context_t *context) |
The function measures an AMUX-B voltage and returns the result in millivolts. More... | |
void | Cy_CSDADC_InterruptHandler (const CSD_Type *base, void *CSDADC_Context) |
Implements the interrupt service routine for the CSDADC middleware. More... | |
cy_en_csdadc_status_t Cy_CSDADC_Init | ( | const cy_stc_csdadc_config_t * | config, |
cy_stc_csdadc_context_t * | context | ||
) |
Captures the CSD HW block and configures it to the default state, is called by the application program prior to calling any other function of the middleware.
The function:
config | The pointer to the CSDADC configuration structure. |
context | The pointer to the CSDADC context structure. |
The 'cy_csdadc_context' variable used as the parameter of the Cy_CSDADC_Init() and Cy_CSDADC_Enable() functions is declared on the application layer according to the example below:
The 'CSD_csdadc_config' variable used as the parameter of the Cy_CSDADC_Init() function is declared in the cycfg_capsense.h file if the Device Configurator tool is used. Refer to the Configuration Considerations section for details. The 'CSDADC_csdadc_config' variable is declared and initialized on the application layer if the third party IDE is used for development.
The CSDADC_ISR_cfg variable is declared by the application program according to the examples below:
For PSoC™ 4 devices:
For CM0+ core of PSoC™ 6 devices:
For CM4 core of PSoC™ 6 devices:
The CSDADC interrupt handler is declared by the application program according to the example below:
The CSDADC_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer is in the cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name is specified, the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
cy_en_csdadc_status_t Cy_CSDADC_Enable | ( | cy_stc_csdadc_context_t * | context | ) |
Initializes the CSDADC firmware modules.
The Cy_CSDADC_Init() function is to be called and the CSD HW block interrupt is to be configured prior to calling this function. The following steps are performed for proper CSDADC initialization:
This function is called by the application program prior to calling any other function of the middleware. The function:
Any subsequent call of this function repeats an initialization process except for the data structure initialization. Therefore, changing the middleware configuration from the application program is possible. Do this by writing registers to the data structure and calling this function again. This is also done inside the Cy_CSDACD_WriteConfig() function, when configuration must be updated.
context | The pointer to the CSDADC context structure. |
The 'cy_csdadc_context' variable used as the parameter of the Cy_CSDADC_Init() and Cy_CSDADC_Enable() functions is declared on the application layer according to the examples below:
The 'CSD_csdadc_config' variable used as the parameter of the Cy_CSDADC_Init() function is declared in the cycfg_capsense.h file if the Device Configurator tool is used. Refer to the Configuration Considerations section for details.
The CSDADC_ISR_cfg variable should be declared by the application program according to the examples below:
For PSoC™ 4 devices:
For CM0+ core of PSoC™ 6 devices:
For CM4 core of PSoC™ 6 devices:
The CSDADC interrupt handler is declared by the application program according to the example below:
The CSDADC_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer is in the cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name specified, the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
cy_en_csdadc_status_t Cy_CSDADC_DeInit | ( | cy_stc_csdadc_context_t * | context | ) |
Stops the middleware operation and releases the CSD HW block.
No input voltage conversion can be executed when the middleware is stopped. This function should be called only when no conversion is in progress. I.e. Cy_CSDADC_IsEndConversion() returns a non-busy status.
After it is stopped, the CSD HW block may be reconfigured by the application program or other middleware for any other use.
When the middleware operation is stopped by the Cy_CSDADC_DeInit() function, a subsequent call of the Cy_CSDADC_Init() function repeats the initialization process. The second calling the Cy_CSDADC_Enable() function is not needed. However, to implement Time-multiplexed mode (sharing the CSD HW Block between multiple middleware), use the Cy_CSDADC_Save()/Cy_CSDADC_Restore() functions instead of the Cy_CSDADC_DeInit()/Cy_CSDADC_Init() functions.
Besides releasing the CSD HW block, this function also configures all input channels to the default state.
context | The pointer to the CSDADC context structure. |
cy_en_csdadc_status_t Cy_CSDADC_WriteConfig | ( | const cy_stc_csdadc_config_t * | config, |
cy_stc_csdadc_context_t * | context | ||
) |
Updates the CSDADC middleware with the desired configuration.
This function sets the desired CSDADC middleware configuration. The function performs the following:
config | The pointer to the CSDADC configuration structure. |
context | The pointer to the CSDADC context structure. |
cy_en_csdadc_status_t Cy_CSDADC_RegisterCallback | ( | cy_csdadc_callback_t | callbackFunction, |
cy_stc_csdadc_context_t * | context | ||
) |
Registers a callback function, which notifies that a callback event occurred in the CSDADC middleware.
callbackFunction | The pointer to the callback function. |
context | The pointer to the CSDADC context structure cy_stc_csdadc_context_t. |
cy_en_csdadc_status_t Cy_CSDADC_UnRegisterCallback | ( | cy_stc_csdadc_context_t * | context | ) |
This function unregisters the CSDADC middleware callback.
context | The pointer to the CSDADC context structure cy_stc_csdadc_context_t. |
cy_en_csdadc_status_t Cy_CSDADC_StartConvert | ( | cy_en_csdadc_conversion_mode_t | mode, |
uint32_t | chMask, | ||
cy_stc_csdadc_context_t * | context | ||
) |
Initiates an analog-to-digital conversion.
Initializes the CSD HW block to perform an analog-to-digital conversion on input channels specified by chMask. This is a non-blocking function. It initiates a conversion only on the first input channel and does not wait for the conversion to complete. A conversion on subsequent channels is initiated by the interrupt service routine of the CSDADC middleware. Therefore, the Cy_CSDADC_IsEndConversion() function must be used to check the conversion status to ensure the previously initiated conversion is complete prior to initiating other tasks. These include: reading the ADC result, initiation of a new conversion on the same or a different channel, or calibration or stopping a CSDADC conversion.
In Single-shot mode, the CSDADC middleware performs one conversion on all channels specified by the chMask argument and stops. The Cy_CSDADC_IsEndConversion() function returns the CY_CSDADC_SUCCESS status after conversion on all channels completes. Otherwise, it returns the CY_CSDADC_HW_BUSY state. To get information on the latest conversion, use the Cy_CSDADC_GetConversionStatus() function.
In Continuous mode, this function continuously initiates conversions on channels specified by chMask (i.e. once a conversion is completed on all channels specified by chMask, the CSDADC MW initiates a next set of conversions). The Cy_CSDADC_IsEndConversion() function always returns the CY_CSDADC_HW_BUSY status. To get information on the latest conversion, use the Cy_CSDADC_GetConversionStatus() functions.
mode | The desired mode of conversion:
|
chMask | The bit mask with set bits of specified channels to convert. |
context | The pointer to the CSDADC middleware context structure. |
An example of the conversion executing in Single-shot mode:
An example of the conversion executing in Continuous mode:
cy_en_csdadc_status_t Cy_CSDADC_StopConvert | ( | cy_en_csdadc_stop_mode_t | stopMode, |
cy_stc_csdadc_context_t * | context | ||
) |
The function stops conversions in Continuous mode.
This function can be used to stop CSDADC conversions in Continuous mode. The ADC can be stopped instantly by ignoring current and all future conversions in the queue. Or it can be stopped after the current conversion on an input channel is completed but future conversions in the queue are ignored. Or it can be stopped after the current conversion cycle (i.e. one set of conversion on all enabled inputs) is completed and conversion cycles in the queue are ignored.
Check the ADC status using the Cy_CSDADC_IsEndConversion() function. Start a new conversion or calibration only if the CSDADC is not busy.
stopMode | The desired mode of the stop operation. It can be:
|
context | The pointer to the CSDADC middleware context structure. |
cy_en_csdadc_status_t Cy_CSDADC_IsEndConversion | ( | const cy_stc_csdadc_context_t * | context | ) |
The function returns the status of the CSDADC's operation.
This function is used to ensure that the CSDADC is in the idle state prior to initiating a conversion, calibration, or configuration change. Initiating any ADC operation while the CSDADC is in the busy state may produce unexpected results from the ADC.
context | The pointer to the CSDADC context. |
An example of the Cy_CSDADC_IsEndConversion() function usage:
uint32_t Cy_CSDADC_GetConversionStatus | ( | const cy_stc_csdadc_context_t * | context | ) |
The function returns a current CSDADC conversion status.
In Continuous mode, this function returns a combination of the current channel number and current cycle number. This function can be used to identify whether a cycle of conversion completed or identify the latest input where the conversion completed so a result can be read. In Single-shot mode, only the latest input where a conversion completed is returned. A conversion cycle number is incremented by the CSDADC after each cycle of conversion completes. A channel number is assigned to each input channel. A new start-conversion request resets the conversion cycle number to zero and the channel number to the first enabled channel in the chMask parameter.
context | The pointer to the CSDADC context. |
An example of the Cy_CSDADC_GetConversionStatus() function usage:
cy_en_csdadc_status_t Cy_CSDADC_Calibrate | ( | cy_stc_csdadc_context_t * | context | ) |
Performs calibration of the CSDADC.
Executes calibration for the CSDADC to identify optimal CSD HW block configuration to produce accurate results. The configuration parameters are dependent on VDDA, VREF, IDAC, and PERI_CLK tolerances, and hence run calibrations periodically (for example every 10 seconds) to compensate for variation in the above mentioned parameters.
context | The pointer to the CSDADC context structure. |
cy_en_csdadc_status_t Cy_CSDADC_Wakeup | ( | const cy_stc_csdadc_context_t * | context | ) |
Resumes the middleware after CPU / System Deep Sleep.
This function is used to resume the middleware operation after exiting CPU / System Deep Sleep. After the CSD HW block has been powered off, an extra delay is required to establish the correct operation of the CSD HW block.
context | The pointer to the CSDADC context structure. |
cy_en_syspm_status_t Cy_CSDADC_DeepSleepCallback | ( | cy_stc_syspm_callback_params_t * | callbackParams, |
cy_en_syspm_callback_mode_t | mode | ||
) |
Handles CPU active to CPU / System Deep Sleep power mode transitions for the CSDADC middleware.
Do not call this function directly from the application program. Instead, use Cy_SysPm_CpuEnterDeepSleep() for CPU active to CPU / System Deep Sleep power mode transitions.
For proper operation of the CSDADC middleware during CPU active to CPU / System Deep Sleep mode transitions, a callback to this function is registered using the Cy_SysPm_RegisterCallback() function with the CY_SYSPM_DEEPSLEEP type. After the callback is registered, this function is called by the Cy_SysPm_CpuEnterDeepSleep() function to prepare the middleware to the device power mode transition.
When this function is called with CY_SYSPM_CHECK_READY as the input, this function returns CY_SYSPM_SUCCESS if no conversion is in progress. Otherwise, CY_SYSPM_FAIL is returned. If the CY_SYSPM_FAIL status is returned, a device cannot change the power mode without completing the current conversion because a transition to CPU / System Deep Sleep during the conversion can disrupt the middleware operation.
For details of the SysPm types and macros, refer to the SysPm section of the PDL documentation PDL API Reference.
callbackParams | Refer to the description of the cy_stc_syspm_callback_params_t type in the Peripheral Driver Library documentation. |
mode | Specifies mode cy_en_syspm_callback_mode_t. |
cy_en_csdadc_status_t Cy_CSDADC_Save | ( | cy_stc_csdadc_context_t * | context | ) |
Saves the state of the CSDADC MW so the functionality can be restored using the Cy_CSDACD_Restore() function.
This function, along with the Cy_CSDACD_Restore() function, is specifically designed for ease of use and supports time multiplexing of the CSD HW block among multiple middleware. When the CSD HW block is shared by two or more middleware, this function can be used to save the current state of the CSD HW block and the CSDADC middleware prior to releasing the CSD HW block for use by other middleware.
This function performs the same tasks as the Cy_CSDADC_DeInit() function and is kept for the API consistency among middleware. Use the Cy_CSDADC_Save()/Cy_CSDADC_Restore() functions to implement Time-multiplexed mode instead of the Cy_CSSADC_DeInit()/Cy_CSDADC_Init() functions for further compatibility. This function:
context | The pointer to the CSDADC context structure. |
An example of sharing the CSD HW block with the CAPSENSE™ and CSDADC middleware.
The CapSense_ISR_cfg variable is declared by the application program according to the examples below:
For PSoC™ 4 devices:
For CM0+ core of PSoC™ 6 devices:
For CM4 core of PSoC™ 6 devices:
The CSDADC_ISR_cfg variable is declared by the application program according to the examples below:
For PSoC™ 4 devices:
For CM0+ core of PSoC™ 6 devices:
For CM4 core of PSoC™ 6 devices:
Defines the CAPSENSE™ interrupt handler:
Defines the CSDADC interrupt handler:
The part of the main.c FW flow:
cy_en_csdadc_status_t Cy_CSDADC_Restore | ( | cy_stc_csdadc_context_t * | context | ) |
Resumes the middleware operation if the Cy_CSDADC_Save() function was called previously.
This function, along with the Cy_CSDADC_Save() function, is specifically designed for ease of use and supports time multiplexing of the CSD HW block among multiple middleware. When the CSD HW block is shared by two or more middleware, this function can be used to restore the previous state of the CSD HW block and CSDADC middleware saved using the Cy_CSDACD_Save() function. This function performs a sub-set of initialization tasks and is used into the Cy_CSDADC_Init() function.
context | The pointer to the CSDADC middleware context structure. |
An example of sharing the CSD HW block by CAPSENSE™ and CSDADC middleware:
uint32_t Cy_CSDADC_GetResult | ( | uint32_t | chId, |
const cy_stc_csdadc_context_t * | context | ||
) |
Returns the most recent result of a specified channel as an ADC code.
The function neither initiates a conversion nor converts the ADC result in millivolts. Instead, it returns the most recent conversion result on specified input as an ADC code. The valid range for result is from 0 to 2^ CSDADCresolution - 1.
chId | An ID of the input channel to read the most recent result. Acceptable values are between 0 and (chNum - 1). |
context | The pointer to the CSDADC context structure. |
uint32_t Cy_CSDADC_GetResultVoltage | ( | uint32_t | chId, |
const cy_stc_csdadc_context_t * | context | ||
) |
Returns the the most recent result of a specified channel in millivolts.
The function does not initiate a conversion. Instead, it returns the most recent conversion result on specified input in millivolts.
chId | An ID of the input channel to read the most recent result. Acceptable values are between 0 and (chNum - 1). |
context | The pointer to the CSDADC context structure. |
uint32_t Cy_CSDADC_MeasureVdda | ( | cy_stc_csdadc_context_t * | context | ) |
The function measures a VDDA voltage and returns the result in millivolts.
This function measures the device supply voltage (VDDA) without the need of explicitly connecting VDDA to a GPIO input of ADC. This capability can be used to measure the battery voltage and/or change VDDA-dependent parameters of the ADC during run-time.
The conversion is initiated only if the CSDADC is in the IDLE state and the context parameter is not NULL. This function is a blocking function, i.e. waits for ADC conversion to be completed prior to returning to caller.
context | The pointer to the CSDADC middleware context structure. |
uint32_t Cy_CSDADC_MeasureAMuxB | ( | cy_stc_csdadc_context_t * | context | ) |
The function measures an AMUX-B voltage and returns the result in millivolts.
This function measures a voltage on AMUX-B without the need for explicitly connecting a GPIO input to the CSDADC. This capability can be used to measure an internal voltage connectable to AMUX-B. It is the responsibility of the application program to establish connection between a voltage source and AMUX-B prior to initiating a conversion with this function.
context | The pointer to the CSDADC middleware context structure. |
void Cy_CSDADC_InterruptHandler | ( | const CSD_Type * | base, |
void * | CSDADC_Context | ||
) |
Implements the interrupt service routine for the CSDADC middleware.
The CSD HW block generates an interrupt at the end of every conversion or a calculation phase. The CSDADC middleware uses this interrupt to implement the non-blocking conversion method, in which only the first conversion is initiated by the application program and subsequent conversions are initiated in the interrupt service routine as soon as the current one is completed. The above stated interrupt service routine is implemented as a part of the CSDADC middleware.
The CSDADC middleware does not initialize or modify the priority of interrupts. For the middleware operation, the application program must configure the CSD interrupt and assign the interrupt vector to the Cy_CSDACD_InterruptHandler() function. If the CSD HW block is shared by more than one middleware, the CSD interrupt vector is initialized to the interrupt handler function of the middleware that is active in the application program.
base | The pointer to the base register address of the CSD HW block. A macro for the pointer can be found in cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name is specified, the default name is used csd_<Block_Number>_csd_<Block_Number>_HW. |
CSDADC_Context | The pointer to the CSDADC context structure. |
The CSDADC_ISR_cfg variable is declared by the application program according to the examples below:
For PSoC™ 4 devices:
For CM0+ core of PSoC™ 6 devices:
For CM4 core of PSoC™ 6 devices:
The CSDADC interrupt handler should be declared by the application program according to the example below:
Then, the application program configures and enables the CSD block interrupt between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions: