soc: nrf5x: Add support to read and write to gpios

Change-Id: I9bded784c8e635a271b88a551b65b7268ea7e2d3
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
This commit is contained in:
Amit Kucheria 2016-07-19 17:36:44 +05:30 committed by Inaky Perez-Gonzalez
commit 975d92c038

View file

@ -154,6 +154,36 @@ static int gpio_nrf5_config(struct device *dev,
return 0;
}
static int gpio_nrf5_read(struct device *dev,
int access_op, uint32_t pin, uint32_t *value)
{
volatile struct _gpio *gpio = GPIO_STRUCT(dev);
if (access_op == GPIO_ACCESS_BY_PIN) {
*value = gpio->IN & BIT(pin);
} else { /* GPIO_ACCESS_BY_PORT */
return -ENOTSUP;
}
return 0;
}
static int gpio_nrf5_write(struct device *dev,
int access_op, uint32_t pin, uint32_t value)
{
volatile struct _gpio *gpio = GPIO_STRUCT(dev);
if (access_op == GPIO_ACCESS_BY_PIN) {
if (value) { /* 1 */
gpio->OUTSET |= BIT(pin);
} else { /* 0 */
gpio->OUTCLR |= BIT(pin);
}
} else { /* GPIO_ACCESS_BY_PORT */
return -ENOTSUP;
}
return 0;
}
/**
* @brief Handler for port interrupts
* @param dev Pointer to device structure for driver instance
@ -166,6 +196,8 @@ static void gpio_nrf5_port_isr(void *dev)
static struct gpio_driver_api gpio_nrf5_drv_api_funcs = {
.config = gpio_nrf5_config,
.read = gpio_nrf5_read,
.write = gpio_nrf5_write,
};
/* Initialization for GPIO Port 0 */