diff options
Diffstat (limited to 'libmaple')
-rw-r--r-- | libmaple/gpio.c | 35 | ||||
-rw-r--r-- | libmaple/gpio.h | 59 |
2 files changed, 56 insertions, 38 deletions
diff --git a/libmaple/gpio.c b/libmaple/gpio.c index 18b856b..5484e21 100644 --- a/libmaple/gpio.c +++ b/libmaple/gpio.c @@ -34,45 +34,52 @@ */ gpio_dev gpioa = { - .regs = GPIOA_BASE, - .clk_id = RCC_GPIOA + .regs = GPIOA_BASE, + .clk_id = RCC_GPIOA, + .exti_port = AFIO_EXTI_PA, }; gpio_dev* const GPIOA = &gpioa; gpio_dev gpiob = { - .regs = GPIOB_BASE, - .clk_id = RCC_GPIOB + .regs = GPIOB_BASE, + .clk_id = RCC_GPIOB, + .exti_port = AFIO_EXTI_PB, }; gpio_dev* const GPIOB = &gpiob; gpio_dev gpioc = { - .regs = GPIOC_BASE, - .clk_id = RCC_GPIOC + .regs = GPIOC_BASE, + .clk_id = RCC_GPIOC, + .exti_port = AFIO_EXTI_PC, }; gpio_dev* const GPIOC = &gpioc; gpio_dev gpiod = { - .regs = GPIOD_BASE, - .clk_id = RCC_GPIOD + .regs = GPIOD_BASE, + .clk_id = RCC_GPIOD, + .exti_port = AFIO_EXTI_PD, }; gpio_dev* const GPIOD = &gpiod; #ifdef STM32_HIGH_DENSITY gpio_dev gpioe = { - .regs = GPIOE_BASE, - .clk_id = RCC_GPIOE + .regs = GPIOE_BASE, + .clk_id = RCC_GPIOE, + .exti_port = AFIO_EXTI_PE, }; gpio_dev* const GPIOE = &gpioe; gpio_dev gpiof = { - .regs = GPIOF_BASE, - .clk_id = RCC_GPIOF + .regs = GPIOF_BASE, + .clk_id = RCC_GPIOF, + .exti_port = AFIO_EXTI_PF, }; gpio_dev* const GPIOF = &gpiof; gpio_dev gpiog = { - .regs = GPIOG_BASE, - .clk_id = RCC_GPIOG + .regs = GPIOG_BASE, + .clk_id = RCC_GPIOG, + .exti_port = AFIO_EXTI_PG, }; gpio_dev* const GPIOG = &gpiog; #endif diff --git a/libmaple/gpio.h b/libmaple/gpio.h index a8a4985..63ba0d5 100644 --- a/libmaple/gpio.h +++ b/libmaple/gpio.h @@ -47,19 +47,37 @@ extern "C"{ /** GPIO register map type */ typedef struct gpio_reg_map { - __io uint32 CRL; ///< Port configuration register low - __io uint32 CRH; ///< Port configuration register high - __io uint32 IDR; ///< Port input data register - __io uint32 ODR; ///< Port output data register - __io uint32 BSRR; ///< Port bit set/reset register - __io uint32 BRR; ///< Port bit reset register - __io uint32 LCKR; ///< Port configuration lock register + __io uint32 CRL; /**< Port configuration register low */ + __io uint32 CRH; /**< Port configuration register high */ + __io uint32 IDR; /**< Port input data register */ + __io uint32 ODR; /**< Port output data register */ + __io uint32 BSRR; /**< Port bit set/reset register */ + __io uint32 BRR; /**< Port bit reset register */ + __io uint32 LCKR; /**< Port configuration lock register */ } gpio_reg_map; + +/** + * External interrupt line port selector. Used to determine which + * GPIO port to map an external interrupt line onto. */ +/* (See AFIO sections, below) */ +typedef enum { + AFIO_EXTI_PA, /**< Use PAx pin. */ + AFIO_EXTI_PB, /**< Use PBx pin. */ + AFIO_EXTI_PC, /**< Use PCx pin. */ + AFIO_EXTI_PD, /**< Use PDx pin. */ +#ifdef STM32_HIGH_DENSITY + AFIO_EXTI_PE, /**< Use PEx pin. */ + AFIO_EXTI_PF, /**< Use PFx pin. */ + AFIO_EXTI_PG, /**< Use PGx pin. */ +#endif +} afio_exti_port; + /** GPIO device type */ typedef struct gpio_dev { - gpio_reg_map *regs; ///< Register map - rcc_clk_id clk_id; ///< RCC clock information + gpio_reg_map *regs; /**< Register map */ + rcc_clk_id clk_id; /**< RCC clock information */ + afio_exti_port exti_port; /**< AFIO external interrupt port value */ } gpio_dev; extern gpio_dev gpioa; @@ -145,6 +163,14 @@ void gpio_init_all(void); void gpio_set_mode(gpio_dev *dev, uint8 pin, gpio_pin_mode mode); /** + * @brief Get a GPIO port's corresponding afio_exti_port. + * @param dev GPIO device whose afio_exti_port to return. + */ +static inline afio_exti_port gpio_exti_port(gpio_dev *dev) { + return dev->exti_port; +} + +/** * Set or reset a GPIO pin. * * Pin must have previously been configured to output mode. @@ -260,21 +286,6 @@ typedef struct afio_reg_map { /* External interrupt configuration registers */ /** - * External interrupt line port selector. Used to determine which - * GPIO port to map an external interrupt line onto. */ -typedef enum { - AFIO_EXTI_PA, /**< Use PAx pin. */ - AFIO_EXTI_PB, /**< Use PBx pin. */ - AFIO_EXTI_PC, /**< Use PCx pin. */ - AFIO_EXTI_PD, /**< Use PDx pin. */ -#ifdef STM32_HIGH_DENSITY - AFIO_EXTI_PE, /**< Use PEx pin. */ - AFIO_EXTI_PF, /**< Use PFx pin. */ - AFIO_EXTI_PG, /**< Use PGx pin. */ -#endif -} afio_exti_port; - -/** * External interrupt line numbers. */ typedef enum { |