This can be done by modifying the GPIO_PRTx_PC , HSIOM_PORT_SELx and GPIO_PRTx_PCx registers accordingly.
When a pin is configured as CapSense button, the pin is set to the following:
1. Drive mode -> Analog High -Z
2. HSIOM -.> CapSense sensor CSD
3. Input buffer forcefully disabled by writing '1' in the GPIO_PRTx_PCx register
CapSense_ScanAllWidgets() takes care of setting this register every time a sensor is scanned. Therefore calling CapSense_ScanAllWidgets() after modifying the registers (to serve as input or output pin) will be overwritten by CapSense_ScanAllWidgets().
To modify the CapSense pin to act as digital input pin do the following:
1. Make sure that there is no active scan. Modify the registers only when there is no scan happening.
2. Modify the drive mode to Digital HI Z/ Resitive pull down/ resistive pull up using GPIO_PRTx_PC register.
3. Change the HSIOM using HSIOM_PORT_SELx register depending on your requirement
4. Make sure the input buffer is not disabled using GPIO_PRTx_PC2 register.
5. Read the status of the pin using CYREG_GPIO_PRTx_PS register
These 3 registers needs to be modified according to whether you want them to be input pin/ output pin/ analog pin.
Please refer to the architecture TRM and register TRM for more details on when to set what.
Below is a sample code to convert capsense pin to digital input pin:
//Pin P2.7 is used here
#define PIN_NUM (7u)
#define PIN_MASK (1u << PIN_NUM )
#define DRIVE_MODE_SHIFT (3u)
#define DIGITAL_HIZ (1u)
#define HSIOM_SHIFT (4u)
#define HSIOM_MODE_GPIO (0u)
#define PC2_SHIFT (1u)
/*Change the drive mode to Digital HIZ*/ //Or what you need
regVal = CY_GET_REG32(CYREG_GPIO_PRT2_PC);
regVal = ((regVal &(~(7u << PIN_NUM * DRIVE_MODE_SHIFT))) | (DIGITAL_HIZ << PIN_NUM * DRIVE_MODE_SHIFT));
/*Change the HSIOM */
regVal = CY_GET_REG32(CYREG_HSIOM_PORT_SEL2);
regVal = ((regVal &(~(15u << PIN_NUM * HSIOM_SHIFT))) | (HSIOM_MODE_GPIO << PIN_NUM * HSIOM_SHIFT));
/*Change PC2 to enable input buffer*/
regVal = CY_GET_REG32(CYREG_GPIO_PRT2_PC2);
regVal = ((regVal &(~(1u << PIN_NUM * PC2_SHIFT))) | (0u << PIN_NUM * PC2_SHIFT));
I've also attached a sample code that swtich between CapSense sensor and input sensor based on a button press in 4100 S device.
Please let us know your observation.
Design02.cyprj.Archive01.zip 545.8 K
I'm able to configure the pins as a resistive pull-ups like I would like through code. However, It doesn't work after I do CapSense_Start(). Would there be a difference in how this is done between a 4100S and a 4200M device?