Switch Control Functions

group group_ctb_functions_switches

This set of functions is for controlling routing switches.

Functions

void Cy_CTB_SetAnalogSwitch(CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_ctb_switch_state_t state)

Provide firmware control of the CTB switches.

Each call to this function can open a set of switches or close a set of switches in one register.

    /* Scenario: OA0 has been configured as an opamp with 10x output drive using the 
     * pre-defined Cy_CTB_Fast_Opamp0_Opamp10x configuration. The 10x output has
     * a dedicated connection to Pin 9.2.
     * 
     * Call SetAnalogSwitch to route the non-inverting input of OA0 to Pin 9.0
     * and the inverting input to Pin 9.1.
     *
     * Note that the CTB port may vary based on device. */
    
    /* Select OA0 switch register. */
    cy_en_ctb_switch_register_sel_t switchSelect = CY_CTB_SWITCH_OA0_SW;

    /* Select two switches for Pin 0 and Pin 1 of the CTB port. */
    uint32_t switchMask = CY_CTB_SW_OA0_POS_PIN0_MASK | CY_CTB_SW_OA0_NEG_PIN1_MASK;

    /* Set the state of the switches to closed */
    cy_en_ctb_switch_state_t state = CY_CTB_SWITCH_CLOSE;

    Cy_CTB_SetAnalogSwitch(CTBM0, switchSelect, switchMask, state);
Return

None

Function Usage

Parameters

uint32_t Cy_CTB_GetAnalogSwitch(const CTBM_Type *base, cy_en_ctb_switch_register_sel_t switchSelect)

Return the open or closed state of the specified analog switch.

    /* Scenario: Query if the positive terminal of Opamp0 is connected to P9.0 or not. */
    uint32_t switchMask;
    
    switchMask = Cy_CTB_GetAnalogSwitch(CTBM0, CY_CTB_SWITCH_OA0_SW);
    
    if ((uint32_t) CY_CTB_SW_OA0_POS_PIN0_MASK == (switchMask & ((uint32_t) CY_CTB_SW_OA0_POS_PIN0_MASK)))
    {
        /* The positive terminal of OA0 is connected to P9.0. */
    }
Return

The state of the switches in the provided register. Compare this value to the switch masks in the following enums: cy_en_ctb_oa0_switches_t, cy_en_ctb_oa1_switches_t, and cy_en_ctb_ctd_switches_t.

Function Usage

Parameters

__STATIC_INLINE void Cy_CTB_OpenAllSwitches (CTBM_Type *base)

Open all the switches and disable all hardware (SAR Sequencer and DSI) control of the switches.

Primarily used as a quick method of re-configuring all analog connections that are sparsely closed.

    /* Scenario: Reset all the switches to destroy all previous connections. */
    
    Cy_CTB_OpenAllSwitches(CTBM0);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_CTB_EnableSarSeqCtrl (CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask)

Enable SAR sequencer control of specified switch(es).

This allows the SAR ADC to use routes through the CTB when configuring its channels.

There are three switches in the CTB that can be enabled by the SAR sequencer.

  • D51: This switch connects the negative input of Opamp0 to the SARBUS0

  • D52: This switch connects the positive input of Opamp1 to the SARBUS0

  • D62: This switch connects the positive input of Opamp1 to the SARBUS1

    /* Scenario: The SAR ADC has been configured to sample the opamp outputs.
     * Enable SAR sequencer control of all three switches in the CTB. */
    
    Cy_CTB_EnableSarSeqCtrl(CTBM0, CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • switchMask: The switch or switches in which to enable SAR sequencer control. Use an enumerated value from cy_en_ctb_switch_sar_seq_t.

__STATIC_INLINE void Cy_CTB_DisableSarSeqCtrl (CTBM_Type *base, cy_en_ctb_switch_sar_seq_t switchMask)

Disable SAR sequencer control of specified switch(es).

    /* Scenario: The SAR ADC no longer needs to sample the opamp outputs.
     * Disable SAR sequencer control of all three switches in the CTB. */
    
    Cy_CTB_DisableSarSeqCtrl(CTBM0, CY_CTB_SW_SEQ_CTRL_D51_D52_D62_MASK);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • switchMask: The switch or switches in which to disable SAR sequencer control. Use an enumerated value from cy_en_ctb_switch_sar_seq_t.