Functions

group group_csdadc_functions

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.

The function:

  • verifies input parameters

  • copies the configuration structure to the context structure

  • disconnects all input channels

  • verifies the CSD HW block state

  • locks the CSD HW block

  • writes the default configuration to the CSD HW block

  • configures the CSDADC middleware to the default state.


    /* Captures the CSD HW block and initialize it to the default state. */
    Cy_CSDADC_Init(&CSDADC_csdadc_config, &cy_csdadc_context);

    /* Initializes the CSDADC interrupt */
    Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
    NVIC_ClearPendingIRQ(CSDADC_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CSDADC_ISR_cfg.intrSrc);

    /* Initializes the CSDADC  firmware modules. */
    Cy_CSDADC_Enable(&cy_csdadc_context);
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:
/* CSDADC context declaration */
cy_stc_csdadc_context_t cy_csdadc_context;
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.
Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The function performed successfully.

  • CY_CSDADC_HW_LOCKED - The CSD HW block is already in use by another CSD function. The CSDADC cannot be initialized right now. The user waits until the CSD HW block passes to the idle state.

  • CY_CSDADC_BAD_PARAM - The context pointer is NULL. The function was not performed.

Function Usage

Parameters
  • config: The pointer to the CSDADC configuration structure.

  • 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 CM0+ core:


const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = NvicMux2_IRQn,       /* CM0+ interrupt is NVIC #2 */
    .cm0pSrc = csd_interrupt_IRQn,  /* Source of NVIC #2 is the CSD interrupt */
    .intrPriority = 3u,             /* Interrupt priority is 3 */
};
For CM4 core:

const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn,  /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,             /* Interrupt priority is 7 */
};
The CSDADC interrupt handler is declared by the application program according to the example below:

static void CSDADC_Interrupt(void)
{
    Cy_CSDADC_InterruptHandler(CSDADC_HW, &cy_csdadc_context);
}
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:

  • Capture the CSD HW block and initialize it to the default state.

  • Initialize the CSDADC interrupt.

  • Initialize the CSDADC firmware modules.

This function is called by the application program prior to calling any other function of the middleware. The function:

  • Configures the CSD HW block to perform CSDADC conversions

  • Calibrates the CSDADC for an accurate measurement

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.


    /* Captures the CSD HW block and initialize it to the default state. */
    Cy_CSDADC_Init(&CSDADC_csdadc_config, &cy_csdadc_context);

    /* Initializes the CSDADC interrupt */
    Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
    NVIC_ClearPendingIRQ(CSDADC_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CSDADC_ISR_cfg.intrSrc);

    /* Initializes the CSDADC  firmware modules. */
    Cy_CSDADC_Enable(&cy_csdadc_context);
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:
/* CSDADC context declaration */
cy_stc_csdadc_context_t cy_csdadc_context;
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.
Return

Returns the status of the initialization process. If CY_RET_SUCCESS is not received, some of the initialization fails.

Function Usage

Parameters
  • context: The pointer to the CSDADC context structure.

The CSDADC_ISR_cfg variable should be declared by the application program according to the examples below:

For CM0+ core:


const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = NvicMux2_IRQn,       /* CM0+ interrupt is NVIC #2 */
    .cm0pSrc = csd_interrupt_IRQn,  /* Source of NVIC #2 is the CSD interrupt */
    .intrPriority = 3u,             /* Interrupt priority is 3 */
};
For CM4 core:

const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn,  /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,             /* Interrupt priority is 7 */
};
The CSDADC interrupt handler is declared by the application program according to the example below:

static void CSDADC_Interrupt(void)
{
    Cy_CSDADC_InterruptHandler(CSDADC_HW, &cy_csdadc_context);
}
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. Calling the Cy_CSDADC_Enable() function is not needed a second time. However, to implement the time-multiplexed mode (sharing the CSD HW Block between multiple middleware), the Cy_CSDADC_Save()/Cy_CSDADC_Restore() functions should be used instead of Cy_CSDADC_DeInit()/Cy_CSDADC_Init() functions.

Besides releasing the CSD HW block, this function also configures all input channels to the default state.

Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The function performed successfully.

  • CY_CSDADC_HW_LOCKED - The CSD HW block is busy with ADC conversion. The CSDADC can’t be de-initialized right now. The user should wait until the CSD HW block passes to the idle state or use Cy_CSDADC_StopConvert().

  • CY_CSDADC_BAD_PARAM - A context pointer is equal to NULL. The function was not performed.

Parameters
  • 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:

  • Verifies input parameters. If any of them is equal to NULL, the function does not perform further operations

  • Initializes the CSDADC context structure in the accordance with the specified configuration

  • Initializes the CSD HW block registers with data, passed through the specified configuration

  • Disconnects inputs and sets the CSD HW block to the default state for CSDADC operations

  • Enables CSDADC operations like the Cy_CSDADC_Enable() function. To start a conversion, the user should call the Cy_CSDADC_StartConvert() function.

  • Returns a status code regarding the function execution result

warning

This function must be called only in the CSD HW block idle state. A call of this function during a conversion will yield an unpredictable CSD HW block behavior.

note

This function as the Cy_CSDADC_Enable() function can be called only after the CSDADC middleware initialization. To do this, use the Cy_CSDADC_Init() function and the CSDADC interrupt enabling as it is shown in the code example for the Cy_CSDADC_Enable() function.

Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The function performed successfully.

  • CY_CSDADC_BAD_PARAM - A context pointer or config pointer is equal to NULL. The function was not performed.

Parameters
  • 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.

Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The processing performed successfully.

  • CY_CSDADC_BAD_PARAM - The input parameter is invalid.

Parameters
  • 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.

Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The processing performed successfully.

  • CY_CSDADC_BAD_PARAM - The input parameter is invalid.

Parameters

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 conversion only on the first input channel and does not wait for the conversion to complete. The conversion on subsequent channels are initiated by the interrupt service routine of the CSDADC middleware. Therefore, the Cy_CSDADC_IsEndConversion() function must be used to check the status of conversion 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.

An example of the conversion executing in Single-shot mode:

    uint32_t ch0Result;
    uint32_t ch1Result;
    /* The mask to enable conversion on Channel-0 and Channel-1. */
    uint32_t channelsMask = 0x03u;

    if (CY_CSDADC_SUCCESS == Cy_CSDADC_StartConvert(CY_CSDADC_SINGLE_SHOT, channelsMask, &cy_csdadc_context))
    {
        while (CY_CSDADC_SUCCESS != Cy_CSDADC_IsEndConversion(&cy_csdadc_context))
        {
            /* Waits for the end of conversions. */
        }

        /* Stores the Channel-0 measurement result to the ch0Result variable. */
        ch0Result = Cy_CSDADC_GetResultVoltage(0u, &cy_csdadc_context);
        /* Stores  the Channel-1 measurement result to the ch1Result variable. */
        ch1Result = Cy_CSDADC_GetResultVoltage(1u, &cy_csdadc_context);
    }
An example of the conversion executing in Continuous mode:
    uint32_t ch0Result;
    uint32_t ch1Result;
    /* The mask to enable conversion on Channel-0 and Channel-1. */
    uint32_t channelsMask = 0x03u;

    cy_en_csdadc_status_t retVal;

    uint32_t curConvNumber = 0u;
    uint32_t prevConvNumber = 0u;

    /* Starts conversion in Continuous mode. */
    retVal = Cy_CSDADC_StartConvert(CY_CSDADC_CONTINUOUS, channelsMask, &cy_csdadc_context);

    /*
    * Checks the execution status of the Cy_CSDADC_StartConvert()routine. Handles the failing status
    * if the conversion is not started successfully.
    */
    if (CY_CSDADC_SUCCESS != retVal)
    {
        /* Places the handling code here. */
    }

    for (;;)
    {

        /*
        * Checks if the conversion is completed on all of the configured channels.
        * The Cy_CSDADC_GetConversionStatus() function returns a combination of
        * a conversion number and channel number.
        * Bit[0-26] (CY_CSDADC_COUNTER_CYCLE_MASK) is the current cycle number in
        * Continuous mode. This counter increment indicates that the current
        * conversion is completed on all of the configured channels.
        */
        curConvNumber = Cy_CSDADC_GetConversionStatus(&cy_csdadc_context);
        curConvNumber &= CY_CSDADC_COUNTER_CYCLE_MASK;
        if(curConvNumber != prevConvNumber)
        {
            prevConvNumber = curConvNumber;

            /* Stores the Channel-0 measurement result to the ch0Result variable. */
            ch0Result = Cy_CSDADC_GetResultVoltage(0u, &cy_csdadc_context);
            /* Stores the Channel-1 measurement result to the ch1Result variable. */
            ch1Result = Cy_CSDADC_GetResultVoltage(1u, &cy_csdadc_context);
        }
    }
Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - A conversion is started.

  • CY_CSDADC_HW_BUSY - A conversion is not started. A previously initiated conversion is in progress or the CSD HW block is in use by another application.

  • CY_CSDADC_BAD_PARAM - A conversion is not started. An invalid mode value or chMask is 0 or the context pointer is NULL.

  • CY_CSDADC_NOT_INITIALIZED - CSDADC to be initialized by using the Cy_CSDADC_Init() and Cy_CSDADC_Enable() functions.

Function Usage

Parameters
  • mode: The desired mode of conversion:

    • CY_CSDADC_SINGLE_SHOT - Only one conversion cycle of all chosen channels.

    • CY_CSDADC_CONTINUOUS - Continuous mode.

  • chMask: The bit mask with set bits of specified channels to convert.

  • context: The pointer to the CSDADC middleware context structure.

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 the 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 ignore future conversions in the queue. Or it can be stopped after the current conversion cycle (i.e. one set of conversion on all enabled inputs) is completed and ignore conversion cycles in the queue.

The ADC status should be checked using the Cy_CSDADC_IsEndConversion() function. A new conversion or calibration should be started only if CSDADC is not BUSY.

Return

The function returns the next statuses:

  • CY_CSDADC_SUCCESS - Stop operation successful. The CSDADC conversion is stopped in the case of the immediate stop mode or the stop conversion bit in the CSDADC status byte is set to stop conversions after the current channel or all the enabled channels are completed.

  • CY_CSDADC_BAD_PARAM - An input parameter is bad.

Parameters
  • stopMode: The desired mode of the stop operation. It can be:

    • CY_CSDADC_IMMED_STOP - The CSDADC conversion will be stopped immediately. A last channel conversion may produce an invalid result.

    • CY_CSDADC_CURRENT_CHAN_STOP - The CSDADC conversion will be stopped after the current channel conversion to be completed.

    • CY_CSDADC_ENABLED_CHAN_STOP - The CSDADC conversion will be stopped after all the enabled channels conversions to be completed.

  • 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 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.

An example of the

Cy_CSDADC_IsEndConversion() function usage:
    uint32_t ch0Result;
    uint32_t ch1Result;
    /* The mask to enable conversion on Channel-0 and Channel-1. */
    uint32_t channelsMask = 0x03u;

    if (CY_CSDADC_SUCCESS == Cy_CSDADC_StartConvert(CY_CSDADC_SINGLE_SHOT, channelsMask, &cy_csdadc_context))
    {
        while (CY_CSDADC_SUCCESS != Cy_CSDADC_IsEndConversion(&cy_csdadc_context))
        {
            /* Waits for the end of conversions. */
        }

        /* Stores the Channel-0 measurement result to the ch0Result variable. */
        ch0Result = Cy_CSDADC_GetResultVoltage(0u, &cy_csdadc_context);
        /* Stores  the Channel-1 measurement result to the ch1Result variable. */
        ch1Result = Cy_CSDADC_GetResultVoltage(1u, &cy_csdadc_context);
    }
Return

The function returns the status of the ADC operation.

  • CY_CSDADC_SUCCESS - The ADC is not busy, so a new conversion can be initiated.

  • CY_CSDADC_HW_BUSY - The previously initiated conversion is in progress.

  • CY_CSDADC_OVERFLOW - The most recent conversion caused an overflow. The root cause of the overflow may be the previous calibration values being invalid or VDDA and VDDA configuration setting mismatch. Perform a re-calibration or set the appropriate VDDA value to avoid this error condition.

Function Usage

Parameters
  • context: The pointer to the CSDADC context.

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.

An example of the

Cy_CSDADC_GetConversionStatus() function usage:
    uint32_t ch0Result;
    uint32_t ch1Result;
    /* The mask to enable conversion on Channel-0 and Channel-1. */
    uint32_t channelsMask = 0x03u;

    cy_en_csdadc_status_t retVal;

    uint32_t curConvNumber = 0u;
    uint32_t prevConvNumber = 0u;

    /* Starts conversion in Continuous mode. */
    retVal = Cy_CSDADC_StartConvert(CY_CSDADC_CONTINUOUS, channelsMask, &cy_csdadc_context);

    /*
    * Checks the execution status of the Cy_CSDADC_StartConvert()routine. Handles the failing status
    * if the conversion is not started successfully.
    */
    if (CY_CSDADC_SUCCESS != retVal)
    {
        /* Places the handling code here. */
    }

    for (;;)
    {

        /*
        * Checks if the conversion is completed on all of the configured channels.
        * The Cy_CSDADC_GetConversionStatus() function returns a combination of
        * a conversion number and channel number.
        * Bit[0-26] (CY_CSDADC_COUNTER_CYCLE_MASK) is the current cycle number in
        * Continuous mode. This counter increment indicates that the current
        * conversion is completed on all of the configured channels.
        */
        curConvNumber = Cy_CSDADC_GetConversionStatus(&cy_csdadc_context);
        curConvNumber &= CY_CSDADC_COUNTER_CYCLE_MASK;
        if(curConvNumber != prevConvNumber)
        {
            prevConvNumber = curConvNumber;

            /* Stores the Channel-0 measurement result to the ch0Result variable. */
            ch0Result = Cy_CSDADC_GetResultVoltage(0u, &cy_csdadc_context);
            /* Stores the Channel-1 measurement result to the ch1Result variable. */
            ch1Result = Cy_CSDADC_GetResultVoltage(1u, &cy_csdadc_context);
        }
    }
Return

The function returns a combination of the conversion number and channel number.

  • Bit[0-26] The current cycle number in Continuous mode. In the single shot mode, it is equal to 0u.

  • Bit[27-31] A current input channel number inside the current cycle.

  • If the context parameter is equal to NULL, then the function returns CY_CSDADC_COUNTER_BAD_PARAM.

Function Usage

Parameters
  • context: The pointer to the CSDADC context.

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.

Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The CSD HW block is successfully calibrated for the ADC use.

  • CY_CSDADC_BAD_PARAM - The context pointer is NULL. A calibration has not been executed.

  • CY_CSDADC_HW_BUSY - The CSD HW block is already in use by a previously initialized conversion or other function. A calibration has not been executed.

  • CY_CSDADC_CALIBRATION_FAIL - The operation watchdog is triggered. The calibration was not performed.

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 and an extra delay is required to establish correct operation of the CSD HW block.

Return

The function returns the status of its operation.

  • CY_CSDADC_SUCCESS - The function performed successfully.

  • CY_CSDADC_BAD_PARAM - A context pointer is equal to NULL. The function was not performed.

Parameters
  • 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.

note

After the CPU Deep Sleep transition, the device automatically goes to System Deep Sleep if all conditions are fulfilled: another core is in CPU Deep Sleep, all the peripherals are ready to System Deep Sleep, etc. (see details in the device TRM).

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.

Return

Returns the status cy_en_syspm_status_t of the operation requested by the mode parameter:

  • CY_SYSPM_SUCCESS - CPU / System Deep Sleep power mode can be entered.

  • CY_SYSPM_FAIL - CPU / System Deep Sleep power mode cannot be entered.

Parameters
  • 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.

warning

The function operates only in the idle state of the CSDADC.

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 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:

  • Checks whether CSDADC is in the idle state. If the CSDADC is busy, the function does nothing.

    In the idle state:

    • Releases the CSD HW block

    • Disconnects channel input pins from analog muxbus B and configures them to the default state.

An example of sharing the CSD HW block with the CapSense and CSDADC middleware.

Declares the CapSense_ISR_cfg variable:


const cy_stc_sysint_t CapSense_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,            /* Interrupt priority is 7 */
};
Declares the CSDADC_ISR_cfg variable:

const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn,  /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,             /* Interrupt priority is 7 */
};
Defines the CapSense interrupt handler:

static void CapSense_Interrupt(void)
{
    Cy_CapSense_InterruptHandler(CSDADC_HW, &cy_capsense_context);
}
Defines the CSDADC interrupt handler:

static void CSDADC_Interrupt(void)
{
    Cy_CSDADC_InterruptHandler(CSDADC_HW, &cy_csdadc_context);
}
The part of the main.c FW flow:
    /* ... */

    /* Initializes the CapSense MW. */
    Cy_CapSense_Init(&cy_capsense_context);
    Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_Interrupt);
    NVIC_ClearPendingIRQ(CapSense_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CapSense_ISR_cfg.intrSrc);
    Cy_CapSense_Enable(&cy_capsense_context);
    Cy_CapSense_Save(&cy_capsense_context);

    /* Initializes the CSDADC MW. */
    Cy_CSDADC_Init(&CSDADC_csdadc_config, &cy_csdadc_context);
    Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
    NVIC_ClearPendingIRQ(CSDADC_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CSDADC_ISR_cfg.intrSrc);
    Cy_CSDADC_Enable(&cy_csdadc_context);
    Cy_CSDADC_Save(&cy_csdadc_context);

    for (;;)
    {
        /* Switches to the CapSense MW. */
        Cy_CapSense_Restore(&cy_capsense_context);
        Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_Interrupt);
        /* Does the CapSense sensing operation. */
        Cy_CapSense_Save(&cy_capsense_context);

        /* Switches to the CSDADC MW. */
        Cy_CSDADC_Restore(&cy_csdadc_context);
        Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
        /* Does the CSDADC measurement operation. */
        Cy_CSDADC_Save(&cy_csdadc_context);
    }

    /* ... */
Return

Returns the status of the process. If CY_CSDADC_SUCCESS is not received, the save process fails and a retry may be required.

Function Usage

Parameters
  • context: The pointer to the CSDADC context structure.

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.

An example of sharing the CSD HW block by CapSense and CSDADC middleware:

    /* ... */

    /* Initializes the CapSense MW. */
    Cy_CapSense_Init(&cy_capsense_context);
    Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_Interrupt);
    NVIC_ClearPendingIRQ(CapSense_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CapSense_ISR_cfg.intrSrc);
    Cy_CapSense_Enable(&cy_capsense_context);
    Cy_CapSense_Save(&cy_capsense_context);

    /* Initializes the CSDADC MW. */
    Cy_CSDADC_Init(&CSDADC_csdadc_config, &cy_csdadc_context);
    Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
    NVIC_ClearPendingIRQ(CSDADC_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CSDADC_ISR_cfg.intrSrc);
    Cy_CSDADC_Enable(&cy_csdadc_context);
    Cy_CSDADC_Save(&cy_csdadc_context);

    for (;;)
    {
        /* Switches to the CapSense MW. */
        Cy_CapSense_Restore(&cy_capsense_context);
        Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_Interrupt);
        /* Does the CapSense sensing operation. */
        Cy_CapSense_Save(&cy_capsense_context);

        /* Switches to the CSDADC MW. */
        Cy_CSDADC_Restore(&cy_csdadc_context);
        Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
        /* Does the CSDADC measurement operation. */
        Cy_CSDADC_Save(&cy_csdadc_context);
    }

    /* ... */
Return

Returns the status of the resume process. If CY_CSDADC_SUCCESS is not received, the resume process fails and a retry may be required.

Function Usage

Parameters
  • context: The pointer to the CSDADC middleware context structure.

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.

Return

Specifies the CSDADC input channel code result between 0 and 2^resolution - 1. If a channel number is invalid, CY_CSDADC_MEASUREMENT_FAILED is returned because this function returns a number (not a status).

Parameters
  • 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.

Return

Specifies the CSDADC input channel result in millivolts. If a channel number is invalid or the pointer to the CSDADC context is equal to NULL, CY_CSDADC_MEASUREMENT_FAILED is returned.

Parameters
  • 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 supply voltage (VDDA) of device without need of explicitly connecting VDDA to a GPIO input of ADC. This capability can be used to measure battery voltage and/or change VDDA dependent parameters of the ADC during run-time.

The conversion is initiated only if the CSDADC is in IDLE state and a context parameter is not NULL. This function is blocking function, i.e. waits for ADC conversion to be completed prior to returning to caller.

Return

The function returns measurement result, VDDA in millivolts. If the pointer to the CSDADC context is equal to NULL or ADC is not in IDLE state, CY_CSDADC_MEASUREMENT_FAILED is returned.

Parameters
  • 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 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.

Return

The function returns the result of an analog MuxBusB voltage measuring in millivolts. If the pointer to the CSDADC context is equal to NULL or ADC is not in the idle state, CY_CSDADC_MEASUREMENT_FAILED is returned.

Parameters
  • 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 a 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.

The CSDADC_ISR_cfg variable is declared by the application program according to the examples below:

For CM0+ core:


const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = NvicMux2_IRQn,       /* CM0+ interrupt is NVIC #2 */
    .cm0pSrc = csd_interrupt_IRQn,  /* Source of NVIC #2 is the CSD interrupt */
    .intrPriority = 3u,             /* Interrupt priority is 3 */
};
For CM4 core:

const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn,  /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,             /* Interrupt priority is 7 */
};
The CSDADC interrupt handler should be declared by the application program according to the example below:

static void CSDADC_Interrupt(void)
{
    Cy_CSDADC_InterruptHandler(CSDADC_HW, &cy_csdadc_context);
}
Then, the application program configures and enables the CSD block interrupt between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:

    /* Captures the CSD HW block and initialize it to the default state. */
    Cy_CSDADC_Init(&CSDADC_csdadc_config, &cy_csdadc_context);

    /* Initializes the CSDADC interrupt */
    Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
    NVIC_ClearPendingIRQ(CSDADC_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CSDADC_ISR_cfg.intrSrc);

    /* Initializes the CSDADC  firmware modules. */
    Cy_CSDADC_Enable(&cy_csdadc_context);
An example of sharing the CSD HW block by the CapSense and CSDADC middleware.

Declares the CapSense_ISR_cfg variable:


const cy_stc_sysint_t CapSense_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,            /* Interrupt priority is 7 */
};
Declares the CSDADC_ISR_cfg variable:

const cy_stc_sysint_t CSDADC_ISR_cfg =
{
    .intrSrc = csd_interrupt_IRQn,  /* Interrupt source is the CSD interrupt */
    .intrPriority = 7u,             /* Interrupt priority is 7 */
};
Defines the CapSense interrupt handler:

static void CapSense_Interrupt(void)
{
    Cy_CapSense_InterruptHandler(CSDADC_HW, &cy_capsense_context);
}
Defines the CSDADC interrupt handler:

static void CSDADC_Interrupt(void)
{
    Cy_CSDADC_InterruptHandler(CSDADC_HW, &cy_csdadc_context);
}
The part of the main.c FW flow:
    /* ... */

    /* Initializes the CapSense MW. */
    Cy_CapSense_Init(&cy_capsense_context);
    Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_Interrupt);
    NVIC_ClearPendingIRQ(CapSense_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CapSense_ISR_cfg.intrSrc);
    Cy_CapSense_Enable(&cy_capsense_context);
    Cy_CapSense_Save(&cy_capsense_context);

    /* Initializes the CSDADC MW. */
    Cy_CSDADC_Init(&CSDADC_csdadc_config, &cy_csdadc_context);
    Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
    NVIC_ClearPendingIRQ(CSDADC_ISR_cfg.intrSrc);
    NVIC_EnableIRQ(CSDADC_ISR_cfg.intrSrc);
    Cy_CSDADC_Enable(&cy_csdadc_context);
    Cy_CSDADC_Save(&cy_csdadc_context);

    for (;;)
    {
        /* Switches to the CapSense MW. */
        Cy_CapSense_Restore(&cy_capsense_context);
        Cy_SysInt_Init(&CapSense_ISR_cfg, &CapSense_Interrupt);
        /* Does the CapSense sensing operation. */
        Cy_CapSense_Save(&cy_capsense_context);

        /* Switches to the CSDADC MW. */
        Cy_CSDADC_Restore(&cy_csdadc_context);
        Cy_SysInt_Init(&CSDADC_ISR_cfg, &CSDADC_Interrupt);
        /* Does the CSDADC measurement operation. */
        Cy_CSDADC_Save(&cy_csdadc_context);
    }

    /* ... */
Function Usage

An example of the ISR initialization:

Parameters
  • 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.