GPIO in XMC1400 example file

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User16172
Level 1
Level 1
Hi. I am currently studying using the XMC1400.

In the meantime, you will see a code listing the GPIO settings. I know a little bit about what the code does. However, I do not understand why I wrote code this way when I set up a port or device connection.

And where can I find the value of "pin"?

The GPIO setup code is directly below.


void XMC_GPIO_Init(XMC_GPIO_PORT_t *const port, const uint8_t pin, const XMC_GPIO_CONFIG_t *const config)

{

XMC_ASSERT("XMC_GPIO_Init: Invalid port", XMC_GPIO_CHECK_PORT(port));

XMC_ASSERT("XMC_GPIO_Init: Invalid mode", XMC_GPIO_IsModeValid(config->mode));

XMC_ASSERT("XMC_GPIO_Init: Invalid input hysteresis", XMC_GPIO_CHECK_INPUT_HYSTERESIS(config->input_hysteresis));



/* Switch to input */

port->IOCR[pin >> 2U] &= ~(uint32_t)((uint32_t)PORT_IOCR_PC_Msk << (PORT_IOCR_PC_Size * (pin & 0x3U)));



/* HW port control is disabled */

port->HWSEL &= ~(uint32_t)((uint32_t)PORT_HWSEL_Msk << ((uint32_t)pin << 1U));



/* Set input hysteresis */

port->PHCR[(uint32_t)pin >> 3U] &= ~(uint32_t)((uint32_t)PORT_PHCR_Msk << ((uint32_t)PORT_PHCR_Size * ((uint32_t)pin & 0x7U)));

port->PHCR[(uint32_t)pin >> 3U] |= (uint32_t)config->input_hysteresis << ((uint32_t)PORT_PHCR_Size * ((uint32_t)pin & 0x7U));



/* Enable digital input */

if (XMC_GPIO_CHECK_ANALOG_PORT(port))

{

port->PDISC &= ~(uint32_t)((uint32_t)0x1U << pin);

}

/* Set output level */

port->OMR = (uint32_t)config->output_level << pin;



/* Set mode */

port->IOCR[pin >> 2U] |= (uint32_t)config->mode << (PORT_IOCR_PC_Size * (pin & 0x3U));

}
0 Likes
0 Replies