From: Nathael Pajani Date: Sun, 22 Feb 2015 01:50:14 +0000 (+0100) Subject: Add some gpio helper functions. Note that these are not very effective unless the... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=2d435467cae4356843c00d97e6f48d6b95086c11;p=soft%2Flpc122x%2Fcore Add some gpio helper functions. Note that these are not very effective unless the compiler does some optimisations when called multiple times from the same function. --- diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 5e2d1a5..6d14312 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -60,6 +60,31 @@ void remove_gpio_callback(const struct pio* gpio); void gpio_on(void); void gpio_off(void); +#define gpio_dir_in(gpio) \ +{ \ + struct lpc_gpio* gpio_port = LPC_GPIO_REGS(gpio.port); \ + gpio_port->data_dir &= ~(1 << gpio->pin);\ +} + +#define gpio_dir_out(gpio) \ +{ \ + struct lpc_gpio* gpio_port = LPC_GPIO_REGS(gpio.port); \ + gpio_port->data_dir |= (1 << gpio->pin);\ +} + + +#define gpio_set(gpio) \ +{ \ + struct lpc_gpio* gpio_port = LPC_GPIO_REGS(gpio.port); \ + gpio_port->set = (1 << gpio->pin);\ +} + +#define gpio_clear(gpio) \ +{ \ + struct lpc_gpio* gpio_port = LPC_GPIO_REGS(gpio.port); \ + gpio_port->clear = (1 << gpio.pin);\ +} + /* GPIO Configuration * This function calls the config_pio() function for the gpio with the given