aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/gpio.h
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-03-24 17:27:38 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-03-24 17:31:47 -0400
commit63ea7464925b8cbeb8623d08a2bde0b1d2044047 (patch)
treec1e0291202084d8d8011b0b66715a711108cbef4 /libmaple/gpio.h
parentbc246609ccd44601a0564fea8da407cc500ad471 (diff)
downloadlibrambutan-63ea7464925b8cbeb8623d08a2bde0b1d2044047.tar.gz
librambutan-63ea7464925b8cbeb8623d08a2bde0b1d2044047.zip
Adding /wirish/boards/ for easier porting; shrank PIN_MAPs.
/wirish/boards/ contains xxx.h and xxx.cpp (for xxx=maple, maple_native, maple_mini, maple_RET6). The headers contain the board-specific #defines that used to live in boards.h (except BOARD_INIT, which was removed). The CPP files contain the PIN_MAP definitions that used to live in boards.cpp, and a proper boardInit() function to replace the old BOARD_INIT macro. This will make it easier to add new boards in the future. struct PinMapping was renamed struct stm32_pin_info, and was moved into a new wirish_types.h. Its external interrupt field was moved into struct gpio_dev, which saves memory by storing an afio_exti_port per port, rather than one per pin. Also rearranged the stm32_pin_info fields to improve packing. Maple's PIN_MAP is now down to below 500 bytes.
Diffstat (limited to 'libmaple/gpio.h')
-rw-r--r--libmaple/gpio.h59
1 files changed, 35 insertions, 24 deletions
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 {