From 559c636765b66300ab186b1e617c85facd604c6b Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sat, 13 May 2017 03:45:35 +0200 Subject: [PATCH] Use available info from register rather than shift and mask in gpio_read() Comments updates in gpio/pio code --- core/pio.c | 5 +++-- drivers/gpio.c | 3 +-- include/drivers/gpio.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/pio.c b/core/pio.c index a1ffd11..77b8ee8 100644 --- a/core/pio.c +++ b/core/pio.c @@ -99,7 +99,7 @@ static void config_pio_safe(const struct pio* pp, const struct pin_matrix_entry* if (pp->pin >= PORT0_NB_PINS) { return; } - /* Movable (offset0 & 0x80) or Fixed pin function */ + /* Movable and GPIO have (offset0 & 0x80) */ if (pp->offset0 & 0x80) { /* Disable fixed pin functions for this pin */ if ((pp->offset0 & 0x7F) <= 31) { @@ -108,7 +108,7 @@ static void config_pio_safe(const struct pio* pp, const struct pin_matrix_entry* if (pp->offset1 <= 31) { matrix->pin_enable[0] |= (1 << pp->offset1); } - /* Assign the function to the pin if not a GPIO or fixed pin function */ + /* Assign the function to the pin if not a GPIO */ if ((me != NULL) && (me->reg_offset < LPC_MATRIX_NB_PIN_ASSIGN)) { matrix->pin_assign[me->reg_offset] &= ~(0xFF << me->bit_shift); matrix->pin_assign[me->reg_offset] |= (pp->pin << me->bit_shift); @@ -117,6 +117,7 @@ static void config_pio_safe(const struct pio* pp, const struct pin_matrix_entry* handle = pio_regs_handles_port0[pp->pin]; *handle = mode; } else { + /* Fixed pin function */ /* Maybe disable the other fixed pin entry ? */ if (pp->offset1 <= 31) { matrix->pin_enable[0] |= (1 << pp->offset1); diff --git a/drivers/gpio.c b/drivers/gpio.c index 1a10b4c..8a95bd2 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -84,11 +84,10 @@ int set_gpio_callback(void (*callback) (uint32_t), const struct pio* gpio, uint8 struct lpc_sys_config* sys_conf = LPC_SYS_CONFIG; uint32_t irq = 0; - /* Register the callback */ if (gpio->pin >= PORT0_NB_PINS) return -EINVAL; - /* Get the next available interrupt */ + /* Get the next available interrupt and register the callback if empty slot found. */ for (irq = 0; irq < NB_PININT_INTERRUPTS; irq++) { if (gpio_callbacks[irq] == NULL) { gpio_callbacks[irq] = callback; diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 27ceff4..c69448a 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -130,7 +130,7 @@ void gpio_off(void); 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)); + return (gpio_port->bval[gpio.pin]); } -- 2.43.0