From: Nathael Pajani Date: Mon, 5 Sep 2016 10:03:49 +0000 (+0200) Subject: Add gpio_read() helper X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=247a4d051725e37cd4e1bc02aa8451160a84870a;p=soft%2Flpc82x%2Fcore Add gpio_read() helper --- diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 65cbbf3..143607c 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -35,6 +35,41 @@ #include "core/pio.h" +/***************************************************************************** */ +/* General Purpose Input/Output */ +/***************************************************************************** */ +/* General Purpose Input/Output (GPIO) */ +struct lpc_gpio +{ + volatile uint8_t bval[32]; /* 0x0000 - 0x001C : Pin value of each pin on a byte for quick access */ + uint32_t reserved_0[1016]; + volatile uint32_t wval[32]; /* 0x1000 - 0x1074 : Pin value of each pin on a 32bits word for quick access */ + uint32_t reserved_1[992]; + volatile uint32_t data_dir; /* 0x2000 : Data direction Register (R/W) */ + uint32_t reserved_2[31]; + volatile uint32_t mask; /* 0x2080 : Pin mask, affects data, out, set, clear and invert */ + uint32_t reserved_3[31]; + volatile uint32_t val; /* 0x2100 : Port data Register (R/W) */ + uint32_t reserved_4[31]; + volatile uint32_t mval; /* 0x2180 : Port masked data Register (R/W) */ + uint32_t reserved_5[31]; + volatile uint32_t set; /* 0x2200 : Port output set Register (-/W) */ + uint32_t reserved_6[31]; + volatile uint32_t clear; /* 0x2280 : Port output clear Register (-/W) */ + uint32_t reserved_7[31]; + volatile uint32_t toggle; /* 0x2300 : Port output invert Register (-/W) */ + uint32_t reserved_8[31]; + volatile uint32_t dir_set; /* 0x2380 : Port direction set (set as output) Register (-/W) */ + uint32_t reserved_9[31]; + volatile uint32_t dir_clear; /* 0x2400 : Port direction clear (set as input) Register (-/W) */ + uint32_t reserved_10[31]; + volatile uint32_t dir_toggle; /* 0x2480 : Port direction toggle Register (-/W) */ +}; +#define LPC_GPIO_0 ((struct lpc_gpio *) LPC_GPIO_BASE) +#define LPC_GPIO_REGS(x) ((struct lpc_gpio *) (LPC_GPIO_BASE)) + + + /***************************************************************************** */ /* Public access to GPIO setup */ @@ -98,6 +133,12 @@ void gpio_off(void); gpio_port->toggle = (1 << gpio.pin);\ } +static inline uint32_t gpio_read(const struct pio gpio) +{ + struct lpc_gpio* gpio_port = LPC_GPIO_REGS(0); + return (gpio_port->val & (1 << gpio.pin)); +} + /* GPIO Configuration * This function calls the config_pio() function for the gpio with the given @@ -109,43 +150,6 @@ void config_gpio(const struct pio* gpio, uint32_t mode, uint8_t dir, uint8_t ini -/***************************************************************************** */ -/* General Purpose Input/Output */ -/***************************************************************************** */ -/* General Purpose Input/Output (GPIO) */ -struct lpc_gpio -{ - volatile uint8_t bval[32]; /* 0x0000 - 0x001C : Pin value of each pin on a byte for quick access */ - uint32_t reserved_0[1016]; - volatile uint32_t wval[32]; /* 0x1000 - 0x1074 : Pin value of each pin on a 32bits word for quick access */ - uint32_t reserved_1[992]; - volatile uint32_t data_dir; /* 0x2000 : Data direction Register (R/W) */ - uint32_t reserved_2[31]; - volatile uint32_t mask; /* 0x2080 : Pin mask, affects data, out, set, clear and invert */ - uint32_t reserved_3[31]; - volatile uint32_t val; /* 0x2100 : Port data Register (R/W) */ - uint32_t reserved_4[31]; - volatile uint32_t mval; /* 0x2180 : Port masked data Register (R/W) */ - uint32_t reserved_5[31]; - volatile uint32_t set; /* 0x2200 : Port output set Register (-/W) */ - uint32_t reserved_6[31]; - volatile uint32_t clear; /* 0x2280 : Port output clear Register (-/W) */ - uint32_t reserved_7[31]; - volatile uint32_t toggle; /* 0x2300 : Port output invert Register (-/W) */ - uint32_t reserved_8[31]; - volatile uint32_t dir_set; /* 0x2380 : Port direction set (set as output) Register (-/W) */ - uint32_t reserved_9[31]; - volatile uint32_t dir_clear; /* 0x2400 : Port direction clear (set as input) Register (-/W) */ - uint32_t reserved_10[31]; - volatile uint32_t dir_toggle; /* 0x2480 : Port direction toggle Register (-/W) */ -}; -#define LPC_GPIO_0 ((struct lpc_gpio *) LPC_GPIO_BASE) -#define LPC_GPIO_REGS(x) ((struct lpc_gpio *) (LPC_GPIO_BASE)) - - - - - /***************************************************************************** */ /* Pin interrupts and patern interrupts */ /***************************************************************************** */