drivers: can: mcp2515: use gpio_dt_spec
Use struct gpio_dt_spec to simplify driver implementation. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
b61df8281c
commit
03ab730347
2 changed files with 13 additions and 18 deletions
|
@ -721,7 +721,6 @@ static void mcp2515_recover(const struct device *dev, k_timeout_t timeout)
|
|||
static void mcp2515_handle_interrupts(const struct device *dev)
|
||||
{
|
||||
const struct mcp2515_config *dev_cfg = dev->config;
|
||||
struct mcp2515_data *dev_data = dev->data;
|
||||
int ret;
|
||||
uint8_t canintf;
|
||||
|
||||
|
@ -776,7 +775,7 @@ static void mcp2515_handle_interrupts(const struct device *dev)
|
|||
}
|
||||
|
||||
/* Break from loop if INT pin is inactive */
|
||||
ret = gpio_pin_get(dev_data->int_gpio, dev_cfg->int_pin);
|
||||
ret = gpio_pin_get_dt(&dev_cfg->int_gpio);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Couldn't read INT pin");
|
||||
} else if (ret == 0) {
|
||||
|
@ -864,28 +863,26 @@ static int mcp2515_init(const struct device *dev)
|
|||
}
|
||||
|
||||
/* Initialize interrupt handling */
|
||||
dev_data->int_gpio = device_get_binding(dev_cfg->int_port);
|
||||
if (dev_data->int_gpio == NULL) {
|
||||
LOG_ERR("GPIO port %s not found", dev_cfg->int_port);
|
||||
return -EINVAL;
|
||||
if (!device_is_ready(dev_cfg->int_gpio.port)) {
|
||||
LOG_ERR("Interrupt GPIO port not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (gpio_pin_configure(dev_data->int_gpio, dev_cfg->int_pin,
|
||||
(GPIO_INPUT |
|
||||
DT_INST_GPIO_FLAGS(0, int_gpios)))) {
|
||||
if (gpio_pin_configure_dt(&dev_cfg->int_gpio, GPIO_INPUT)) {
|
||||
LOG_ERR("Unable to configure GPIO pin %u", dev_cfg->int_pin);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
gpio_init_callback(&(dev_data->int_gpio_cb), mcp2515_int_gpio_callback,
|
||||
BIT(dev_cfg->int_pin));
|
||||
BIT(dev_cfg->int_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(dev_data->int_gpio, &(dev_data->int_gpio_cb))) {
|
||||
if (gpio_add_callback(dev_cfg->int_gpio.port,
|
||||
&(dev_data->int_gpio_cb))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (gpio_pin_interrupt_configure(dev_data->int_gpio, dev_cfg->int_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE)) {
|
||||
if (gpio_pin_interrupt_configure_dt(&dev_cfg->int_gpio,
|
||||
GPIO_INT_EDGE_TO_ACTIVE)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -943,8 +940,7 @@ static struct mcp2515_data mcp2515_data_1 = {
|
|||
|
||||
static const struct mcp2515_config mcp2515_config_1 = {
|
||||
.bus = SPI_DT_SPEC_INST_GET(0, SPI_WORD_SET(8), 0),
|
||||
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
||||
.int_port = DT_INST_GPIO_LABEL(0, int_gpios),
|
||||
.int_gpio = GPIO_DT_SPEC_INST_GET(0),
|
||||
.int_thread_stack_size = CONFIG_CAN_MCP2515_INT_THREAD_STACK_SIZE,
|
||||
.int_thread_priority = CONFIG_CAN_MCP2515_INT_THREAD_PRIO,
|
||||
.tq_sjw = DT_INST_PROP(0, sjw),
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#ifndef _MCP2515_H_
|
||||
#define _MCP2515_H_
|
||||
|
||||
#include <drivers/gpio.h>
|
||||
#include <drivers/can.h>
|
||||
|
||||
#define MCP2515_RX_CNT 2
|
||||
|
@ -23,7 +24,6 @@ struct mcp2515_tx_cb {
|
|||
|
||||
struct mcp2515_data {
|
||||
/* interrupt data */
|
||||
const struct device *int_gpio;
|
||||
struct gpio_callback int_gpio_cb;
|
||||
struct k_thread int_thread;
|
||||
k_thread_stack_t *int_thread_stack;
|
||||
|
@ -53,8 +53,7 @@ struct mcp2515_config {
|
|||
struct spi_dt_spec bus;
|
||||
|
||||
/* interrupt configuration */
|
||||
uint8_t int_pin;
|
||||
const char *int_port;
|
||||
struct gpio_dt_spec int_gpio;
|
||||
size_t int_thread_stack_size;
|
||||
int int_thread_priority;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue