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:
parent
bc60506d3e
commit
975d92c038
1 changed files with 32 additions and 0 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue