MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / GPIO_PinModeSet

Function GPIO_PinModeSet

bsp/efm32/Libraries/emlib/src/em_gpio.c:224–269  ·  view source on GitHub ↗

/ * @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

Source from the content-addressed store, hash-verified

222 * corresponding DOUT bit unchanged.
223 ******************************************************************************/
224void 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/***************************************************************************//**

Callers 15

drv_usart.cFile · 0.85
efm_hw_eth_initFunction · 0.85
efm32_spiLcd_initFunction · 0.85
efm32_hw_keys_initFunction · 0.85
efm_spiFlash_initFunction · 0.85
efm_spiSd_initFunction · 0.85
rt_hw_iic_unit_initFunction · 0.85
rt_hw_leuart_unit_initFunction · 0.85
rt_hw_led_initFunction · 0.85
efm_accel_initFunction · 0.85
DVK_EBI_initFunction · 0.85
DVK_EBI_disableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected