385
void Input_Pin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) { uint32_t position = 0; uint32_t register_offset; volatile uint32_t *config_register; uint32_t temp; while (GPIO_Pin) { if (GPIO_Pin & 0x01) { register_offset = (position < 8) ? 0 : 1; config_register = &GPIOx->CRL + register_offset; temp = *config_register; temp &= ~(0x0F << ((position & 0x07) * 4)); temp |= (0x04 << ((position & 0x07) * 4)); // Input floating *config_register = temp; } position++; GPIO_Pin >>= 1; } } void Output_Pin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) { uint32_t position = 0; uint32_t register_offset; volatile uint32_t *config_register; uint32_t temp; while (GPIO_Pin) { if (GPIO_Pin & 0x01) { register_offset = (position < 8) ? 0 : 1; config_register = &GPIOx->CRL + register_offset; temp = *config_register; temp &= ~(0x0F << ((position & 0x07) * 4)); temp |= (0x01 << ((position & 0x07) * 4)); // Output push-pull *config_register = temp; } position++; GPIO_Pin >>= 1; } }