diff options
author | Keith Packard <keithp@keithp.com> | 2018-09-11 00:07:38 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2018-10-13 08:22:50 -0700 |
commit | b7a21bf6a086748b4907c0577eaa114445995783 (patch) | |
tree | 4a91bb4fd0ad23c66520bb3dd01d0207f4f11d17 /src/stm32f4/ao_arch_funcs.h | |
parent | f037d0091a4b31c631d64e71441953eb9b3b21ce (diff) |
altos/stm32f4: Start adding support for STM32F413
Enough to get clocks lit up at least.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/stm32f4/ao_arch_funcs.h')
-rw-r--r-- | src/stm32f4/ao_arch_funcs.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/stm32f4/ao_arch_funcs.h b/src/stm32f4/ao_arch_funcs.h new file mode 100644 index 00000000..252fe77a --- /dev/null +++ b/src/stm32f4/ao_arch_funcs.h @@ -0,0 +1,106 @@ +/* + * Copyright © 2018 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#ifndef _AO_ARCH_FUNCS_H_ +#define _AO_ARCH_FUNCS_H_ + +/* GPIO functions */ + +#define ao_power_register(gpio) +#define ao_power_unregister(gpio) + +static inline void ao_enable_port(struct stm_gpio *port) +{ + if ((port) == &stm_gpioa) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPAEN); + ao_power_register(&ao_power_gpioa); + } else if ((port) == &stm_gpiob) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPBEN); + ao_power_register(&ao_power_gpiob); + } else if ((port) == &stm_gpioc) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPCEN); + ao_power_register(&ao_power_gpioc); + } else if ((port) == &stm_gpiod) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPDEN); + ao_power_register(&ao_power_gpiod); + } else if ((port) == &stm_gpioe) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPEEN); + ao_power_register(&ao_power_gpioe); + } else if ((port) == &stm_gpiof) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPFEN); + ao_power_register(&ao_power_gpiof); + } else if ((port) == &stm_gpiog) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPGEN); + ao_power_register(&ao_power_gpiog); + } else if ((port) == &stm_gpioh) { + stm_rcc.ahb1enr |= (1 << STM_RCC_AHB1ENR_IOPHEN); + ao_power_register(&ao_power_gpioh); + } +} + +static inline void ao_disable_port(struct stm_gpio *port) +{ + if ((port) == &stm_gpioa) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPAEN); + ao_power_unregister(&ao_power_gpioa); + } else if ((port) == &stm_gpiob) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPBEN); + ao_power_unregister(&ao_power_gpiob); + } else if ((port) == &stm_gpioc) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPCEN); + ao_power_unregister(&ao_power_gpioc); + } else if ((port) == &stm_gpiod) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPDEN); + ao_power_unregister(&ao_power_gpiod); + } else if ((port) == &stm_gpioe) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPEEN); + ao_power_unregister(&ao_power_gpioe); + } else if ((port) == &stm_gpiof) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPFEN); + ao_power_unregister(&ao_power_gpiof); + } else if ((port) == &stm_gpiog) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPGEN); + ao_power_unregister(&ao_power_gpiog); + } else if ((port) == &stm_gpioh) { + stm_rcc.ahb1enr &= ~(1 << STM_RCC_AHB1ENR_IOPHEN); + ao_power_unregister(&ao_power_gpioh); + } +} + +#define ao_gpio_set(port, bit, v) stm_gpio_set(port, bit, v) + +#define ao_gpio_get(port, bit) stm_gpio_get(port, bit) + +#define ao_enable_output(port,bit,v) do { \ + ao_enable_port(port); \ + ao_gpio_set(port, bit, v); \ + stm_moder_set(port, bit, STM_MODER_OUTPUT);\ + } while (0) + +#define ao_gpio_set_mode(port,bit,mode) do { \ + if (mode == AO_EXTI_MODE_PULL_UP) \ + stm_pupdr_set(port, bit, STM_PUPDR_PULL_UP); \ + else if (mode == AO_EXTI_MODE_PULL_DOWN) \ + stm_pupdr_set(port, bit, STM_PUPDR_PULL_DOWN); \ + else \ + stm_pupdr_set(port, bit, STM_PUPDR_NONE); \ + } while (0) + +#define ao_enable_input(port,bit,mode) do { \ + ao_enable_port(port); \ + stm_moder_set(port, bit, STM_MODER_INPUT); \ + ao_gpio_set_mode(port, bit, mode); \ + } while (0) + +#endif /* _AO_ARCH_FUNCS_H_ */ |