diff options
| -rw-r--r-- | os/drivers/pinctrl/pinctrl.h | 6 | ||||
| -rw-r--r-- | os/drivers/pinctrl/stm32f769_pinctrl.c | 94 | ||||
| -rw-r--r-- | os/drivers/pinctrl/stm32f769_pinctrl.h | 53 |
3 files changed, 153 insertions, 0 deletions
diff --git a/os/drivers/pinctrl/pinctrl.h b/os/drivers/pinctrl/pinctrl.h new file mode 100644 index 00000000..a23b5b19 --- /dev/null +++ b/os/drivers/pinctrl/pinctrl.h @@ -0,0 +1,6 @@ +#ifndef __PINCTRL_H__ +#define __PINCTRL_H__ + +void pinctrl_configure_pin(uint32_t pin); + +#endif/*__PINCTRL_H__*/ diff --git a/os/drivers/pinctrl/stm32f769_pinctrl.c b/os/drivers/pinctrl/stm32f769_pinctrl.c new file mode 100644 index 00000000..ce45ec17 --- /dev/null +++ b/os/drivers/pinctrl/stm32f769_pinctrl.c @@ -0,0 +1,94 @@ +#include <drivers/clock/stm32f769_clocks.h> +#include <drivers/clock/stm32f769_clock_control.h> +#include <drivers/gpio/stm32f769_gpio.h> + +static const GPIO_TypeDef *stm32f769_port_addrs[] = { + GPIOA, + GPIOB, + GPIOC, + GPIOD, + GPIOE, + GPIOF, + GPIOG, + GPIOH, + GPIOI, + GPIOJ, + GPIOK, +}; + +static const uint16_t stm32f769_port_clkids[] = { + STM32F769_CLOCK_GPIOA, + STM32F769_CLOCK_GPIOB, + STM32F769_CLOCK_GPIOC, + STM32F769_CLOCK_GPIOD, + STM32F769_CLOCK_GPIOE, + STM32F769_CLOCK_GPIOF, + STM32F769_CLOCK_GPIOG, + STM32F769_CLOCK_GPIOH, + STM32F769_CLOCK_GPIOI, + STM32F769_CLOCK_GPIOJ, + STM32F769_CLOCK_GPIOK, +}; + +static GPIO_TypeDef *stm32f769_get_port(unsigned int port_idx) { + GPIO_TypeDef *p = stm32f769_port_addrs[port_idx]; + return p; +} + +static uint16_t stm32f769_get_port_clkid(unsigned int port_idx) { + return stm32f769_port_clkids[port_idx]; +} + +void stm32f769_pinctrl_configure_pin(uint32_t pin) +{ + uint8_t port_idx; + uint32_t port; + uint32_t pin_num; + uint32_t af; + uint32_t dir; + uint16_t clkid; + //uint16_t strength; + + port_idx = STM32F769_PORT_GET(pin); + GPIO_TypeDef *p = stm32f769_get_port(port_idx); + + clkid = stm32f769_get_port_clkid(port_idx); + + pin_num = STM32F769_PIN_GET(pin); + af = STM32F769_AF_GET(pin); + dir = STM32F769_DIR_GET(pin); + + clock_control_mik32_on(clkid); + + uint32_t pupd; + uint32_t ds; + uint32_t cfg; + uint32_t dirin; + uint32_t dirout; + + pupd = MIK32_PAD_PUPD(port); + cfg = MIK32_PAD_CFG(port); + ds = MIK32_PAD_DS(port); + dirin = MIK32_GPIO_DIRIN(port); + dirout = MIK32_GPIO_DIROUT(port); + + if (af != STM32F769_ANALOG) { + stm32f769_gpio_configure_af(NULL, pin, pin); + } else { + // set mode ANALOG + stm32f769_gpio_configure_analog(NULL, pin, pin); + } +} + +/* int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, */ +/* uintptr_t reg) */ +/* { */ +/* ARG_UNUSED(reg); */ + +/* for (uint8_t i = 0U; i < pin_cnt; i++) { */ +/* pinctrl_configure_pin(pins[i]); */ +/* } */ + +/* return 0; */ +/* } */ + diff --git a/os/drivers/pinctrl/stm32f769_pinctrl.h b/os/drivers/pinctrl/stm32f769_pinctrl.h new file mode 100644 index 00000000..489faa68 --- /dev/null +++ b/os/drivers/pinctrl/stm32f769_pinctrl.h @@ -0,0 +1,53 @@ +#ifndef __DT_BINDINGS_PINCTRL_STM32F769_AF_H__ +#define __DT_BINDINGS_PINCTRL_STM32F769_AF_H__ + +#define STM32F769_AF0 0U +#define STM32F769_AF1 1U +#define STM32F769_AF2 2U +#define STM32F769_AF3 3U +#define STM32F769_AF4 4U +#define STM32F769_AF5 5U +#define STM32F769_AF6 6U +#define STM32F769_AF7 7U +#define STM32F769_AF8 8U +#define STM32F769_AF9 9U +#define STM32F769_AF10 10U +#define STM32F769_AF11 11U +#define STM32F769_AF12 12U +#define STM32F769_AF13 13U +#define STM32F769_AF14 14U +#define STM32F769_AF15 15U +#define STM32F769_ANALOG 16U + +#define STM32F769_PORT_MSK 0xFU +#define STM32F769_PORT_POS 0U +#define STM32F769_PIN_MSK 0xFU +#define STM32F769_PIN_POS 4U +#define STM32F769_AF_MSK 0xFU +#define STM32F769_AF_POS 8U + +#define STM32F769_PORT_GET(pinmux) \ + (((pinmux) >> STM32F769_PORT_POS) & STM32F769_PORT_MSK) + +#define STM32F769_PIN_GET(pinmux) \ + (((pinmux) >> STM32F769_PIN_POS) & STM32F769_PIN_MSK) + +#define STM32F769_AF_GET(pinmux) \ + (((pinmux) >> STM32F769_AF_POS) & STM32F769_AF_MSK) + +/** + * - 0..3: port + * - 4..7: pin + * - 8..13: af + * + * port: Port ('A'..'K') + * pin: Pin (0..15) + * af: Alternate function (ANALOG, AFx, x=0..15) + */ + +#define STM32F769_PINMUX_AF(port, pin, af) \ + ((((port) & STM32F769_PORT_MSK) << STM32F769_PORT_POS) | \ + (((pin) & STM32F769_PIN_MSK) << STM32F769_PIN_POS) | \ + (((STM32F769_ ## af) & STM32F769_AF_MSK) << STM32F769_AF_POS)) + +#endif/*__DT_BINDINGS_PINCTRL_STM32F769_AF_H_ */ |
