Browse Source

HAL_ChibiOS: added palReadLineMode() function

used to change and restore line modes
mission-4.1.18
Andrew Tridgell 6 years ago
parent
commit
a0ed658fcc
  1. 23
      libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c
  2. 10
      libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.h

23
libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c

@ -279,3 +279,26 @@ void peripheral_power_enable(void) @@ -279,3 +279,26 @@ void peripheral_power_enable(void)
#endif
#endif
}
#if defined(STM32F7) || defined(STM32F4)
/*
read mode of a pin. This allows a pin config to be read, changed and
then written back
*/
iomode_t palReadLineMode(ioline_t line)
{
ioportid_t port = PAL_PORT(line);
uint8_t pad = PAL_PAD(line);
iomode_t ret = 0;
ret |= (port->MODER >> (pad*2)) & 0x3;
ret |= ((port->OTYPER >> pad)&1) << 2;
ret |= ((port->OSPEEDR >> (pad*2))&3) << 3;
ret |= ((port->PUPDR >> (pad*2))&3) << 5;
if (pad < 8) {
ret |= ((port->AFRL >> (pad*4))&0xF) << 7;
} else {
ret |= ((port->AFRH >> ((pad-8)*4))&0xF) << 7;
}
return ret;
}
#endif

10
libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.h

@ -69,7 +69,15 @@ void peripheral_power_enable(void); @@ -69,7 +69,15 @@ void peripheral_power_enable(void);
// initialise allocation subsystem
void malloc_init(void);
/*
read mode of a pin. This allows a pin config to be read, changed and
then written back
*/
#if defined(STM32F7) || defined(STM32F4)
iomode_t palReadLineMode(ioline_t line);
#endif
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save