/ * @brief * Set the mode for a GPIO pin. * * @param[in] port * The GPIO port to access. * * @param[in] pin * The pin number in the port. * * @param[in] mode * The desired pin mode. * * @param[in] out * Value to set for pin in DOUT register. The DOUT setting is important for * even some input mode configurations, determining pull-up/down direction. * Notice that this p
| 222 | * corresponding DOUT bit unchanged. |
| 223 | ******************************************************************************/ |
| 224 | void GPIO_PinModeSet(GPIO_Port_TypeDef port, |
| 225 | unsigned int pin, |
| 226 | GPIO_Mode_TypeDef mode, |
| 227 | unsigned int out) |
| 228 | { |
| 229 | EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_PIN_VALID(pin)); |
| 230 | |
| 231 | /* If disabling pin, do not modify DOUT in order to reduce chance for */ |
| 232 | /* glitch/spike (may not be sufficient precaution in all use cases) */ |
| 233 | if (mode != gpioModeDisabled) |
| 234 | { |
| 235 | if (out) |
| 236 | { |
| 237 | GPIO->P[port].DOUTSET = 1 << pin; |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | GPIO->P[port].DOUTCLR = 1 << pin; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* There are two registers controlling the pins for each port. The MODEL |
| 246 | * register controls pins 0-7 and MODEH controls pins 8-15. */ |
| 247 | if (pin < 8) |
| 248 | { |
| 249 | GPIO->P[port].MODEL = (GPIO->P[port].MODEL & ~(0xF << (pin * 4))) | |
| 250 | (mode << (pin * 4)); |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | GPIO->P[port].MODEH = (GPIO->P[port].MODEH & ~(0xF << ((pin - 8) * 4))) | |
| 255 | (mode << ((pin - 8) * 4)); |
| 256 | } |
| 257 | |
| 258 | if (mode == gpioModeDisabled) |
| 259 | { |
| 260 | if (out) |
| 261 | { |
| 262 | GPIO->P[port].DOUTSET = 1 << pin; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | GPIO->P[port].DOUTCLR = 1 << pin; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | |
| 272 | /***************************************************************************//** |
no outgoing calls
no test coverage detected