Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mcp2515@0 {
compatible = "microchip,mcp2515";
spi-max-frequency = <1000000>;
int-gpios = <&arduino_header 8 0>; /* D2 */
int-gpios = <&arduino_header 8 GPIO_ACTIVE_LOW>; /* D2 */
status = "okay";
label = "CAN_1";
reg = <0x0>;
Expand Down
2 changes: 1 addition & 1 deletion boards/shields/link_board_can/link_board_can.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
mcp2515@0 {
compatible = "microchip,mcp2515";
spi-max-frequency = <1000000>;
int-gpios = <&gpio1 7 GPIO_INT_ACTIVE_LOW>;
int-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
status = "okay";
label = "CAN_1";
reg = <0>;
Expand Down
18 changes: 9 additions & 9 deletions drivers/can/can_mcp2515.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,10 @@ static void mcp2515_handle_interrupts(struct device *dev)
{
const struct mcp2515_config *dev_cfg = DEV_CFG(dev);
struct mcp2515_data *dev_data = DEV_DATA(dev);
u32_t pin;
int ret;
u8_t canintf;

/* Loop until INT pin is high (all interrupt flags handled) */
/* Loop until INT pin is inactive (all interrupt flags handled) */
while (1) {
ret = mcp2515_cmd_read_reg(dev, MCP2515_ADDR_CANINTF,
&canintf, 1);
Expand Down Expand Up @@ -693,11 +692,11 @@ static void mcp2515_handle_interrupts(struct device *dev)
canintf, ~canintf);
}

/* Break from loop if INT pin is no longer low */
ret = gpio_pin_read(dev_data->int_gpio, dev_cfg->int_pin, &pin);
if (ret != 0) {
/* Break from loop if INT pin is inactive */
ret = gpio_pin_get(dev_data->int_gpio, dev_cfg->int_pin);
if (ret < 0) {
LOG_ERR("Couldn't read INT pin");
} else if (pin != 0) {
} else if (ret == 0) {
/* All interrupt flags handled */
break;
}
Expand Down Expand Up @@ -790,8 +789,8 @@ static int mcp2515_init(struct device *dev)
}

if (gpio_pin_configure(dev_data->int_gpio, dev_cfg->int_pin,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE
| GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE))) {
(GPIO_INPUT |
DT_INST_0_MICROCHIP_MCP2515_INT_GPIOS_FLAGS))) {
LOG_ERR("Unable to configure GPIO pin %u", dev_cfg->int_pin);
return -EINVAL;
}
Expand All @@ -803,7 +802,8 @@ static int mcp2515_init(struct device *dev)
return -EINVAL;
}

if (gpio_pin_enable_callback(dev_data->int_gpio, dev_cfg->int_pin)) {
if (gpio_pin_interrupt_configure(dev_data->int_gpio, dev_cfg->int_pin,
GPIO_INT_EDGE_TO_ACTIVE)) {
return -EINVAL;
}

Expand Down
6 changes: 6 additions & 0 deletions dts/bindings/can/microchip,mcp2515.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ properties:
int-gpios:
type: phandle-array
required: true
description: >
Interrupt pin.

This pin signals active low when produced by the controller. The
property value should ensure the flags properly describe the signal
that is presented to the driver.
reg:
type: array
required: true
6 changes: 3 additions & 3 deletions samples/drivers/CAN/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ void change_led(struct zcan_frame *msg, void *led_dev_param)

switch (msg->data[0]) {
case SET_LED:
gpio_pin_write(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 1);
gpio_pin_set(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 1);
break;
case RESET_LED:
gpio_pin_write(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 0);
gpio_pin_set(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 0);
break;
}
#else
Expand Down Expand Up @@ -220,7 +220,7 @@ void main(void)
}

ret = gpio_pin_configure(led_gpio_dev, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_DIR_OUT);
GPIO_OUTPUT_HIGH | DT_ALIAS_LED0_GPIOS_FLAGS);
if (ret < 0) {
printk("Error setting LED pin to output mode [%d]", ret);
}
Expand Down