diff --git a/boards/arm/96b_carbon/96b_carbon.dts b/boards/arm/96b_carbon/96b_carbon.dts index d1c0eb15070..f1e41cf4025 100644 --- a/boards/arm/96b_carbon/96b_carbon.dts +++ b/boards/arm/96b_carbon/96b_carbon.dts @@ -84,8 +84,8 @@ bt-hci@0 { compatible = "zephyr,bt-hci-spi"; reg = <0>; - reset-gpios = <&gpiob 4 0>; - irq-gpios = <&gpiob 1 0>; + reset-gpios = <&gpiob 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + irq-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>; spi-max-frequency = <2000000>; label = "BT_HCI"; }; diff --git a/boards/arm/disco_l475_iot1/disco_l475_iot1.dts b/boards/arm/disco_l475_iot1/disco_l475_iot1.dts index a431c9c996d..c978796e709 100644 --- a/boards/arm/disco_l475_iot1/disco_l475_iot1.dts +++ b/boards/arm/disco_l475_iot1/disco_l475_iot1.dts @@ -117,13 +117,14 @@ &spi3 { status = "okay"; - cs-gpios = <&gpiod 13 0>, <&gpioe 0 GPIO_ACTIVE_HIGH>; + cs-gpios = <&gpiod 13 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>, + <&gpioe 0 GPIO_ACTIVE_HIGH>; spbtle-rf@0 { compatible = "zephyr,bt-hci-spi"; reg = <0>; - reset-gpios = <&gpioa 8 0>; - irq-gpios = <&gpioe 6 0>; + reset-gpios = <&gpioa 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + irq-gpios = <&gpioe 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; spi-max-frequency = <2000000>; label = "SPBTLE-RF"; }; diff --git a/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay b/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay index 366ba7d93bb..ee89b406713 100644 --- a/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay +++ b/boards/shields/x_nucleo_idb05a1/x_nucleo_idb05a1.overlay @@ -5,13 +5,13 @@ */ &arduino_spi { - cs-gpios = <&arduino_header 16 0>; /* D10 */ + cs-gpios = <&arduino_header 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; /* D10 */ spbtle-rf@0 { compatible = "zephyr,bt-hci-spi"; reg = <0>; - reset-gpios = <&arduino_header 13 0>; /* D7 */ - irq-gpios = <&arduino_header 0 0>; /* A0 */ + reset-gpios = <&arduino_header 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* D7 */ + irq-gpios = <&arduino_header 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; /* A0 */ spi-max-frequency = <2000000>; label = "SPBTLE-RF"; }; diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 8e99fc9880f..c2c53efae9c 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -46,9 +46,12 @@ #define CMD_OCF 2 #define GPIO_IRQ_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_IRQ_GPIOS_PIN +#define GPIO_IRQ_FLAGS DT_INST_0_ZEPHYR_BT_HCI_SPI_IRQ_GPIOS_FLAGS #define GPIO_RESET_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_RESET_GPIOS_PIN +#define GPIO_RESET_FLAGS DT_INST_0_ZEPHYR_BT_HCI_SPI_RESET_GPIOS_FLAGS #ifdef DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN #define GPIO_CS_PIN DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN +#define GPIO_CS_FLAGS DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_FLAGS #endif /* DT_INST_0_ZEPHYR_BT_HCI_SPI_CS_GPIOS_PIN */ /* Max SPI buffer length for transceive operations. @@ -201,22 +204,23 @@ static int configure_cs(void) return -EIO; } + /* Configure pin as output and set to active */ gpio_pin_configure(cs_dev, GPIO_CS_PIN, - GPIO_DIR_OUT | GPIO_PUD_PULL_UP); - gpio_pin_write(cs_dev, GPIO_CS_PIN, 1); + GPIO_OUTPUT_ACTIVE | GPIO_CS_FLAGS); + return 0; } static void kick_cs(void) { - gpio_pin_write(cs_dev, GPIO_CS_PIN, 1); - gpio_pin_write(cs_dev, GPIO_CS_PIN, 0); + gpio_pin_set(cs_dev, GPIO_CS_PIN, 1); + gpio_pin_set(cs_dev, GPIO_CS_PIN, 0); } static void release_cs(void) { - gpio_pin_write(cs_dev, GPIO_CS_PIN, 1); + gpio_pin_set(cs_dev, GPIO_CS_PIN, 1); } static bool irq_pin_high(void) @@ -480,16 +484,11 @@ static int bt_spi_open(void) { /* Configure RST pin and hold BLE in Reset */ gpio_pin_configure(rst_dev, GPIO_RESET_PIN, - GPIO_DIR_OUT | GPIO_PUD_PULL_UP); - gpio_pin_write(rst_dev, GPIO_RESET_PIN, 0); + GPIO_OUTPUT_ACTIVE | GPIO_RESET_FLAGS); /* Configure IRQ pin and the IRQ call-back/handler */ gpio_pin_configure(irq_dev, GPIO_IRQ_PIN, -#if defined(CONFIG_BT_SPI_BLUENRG) - GPIO_PUD_PULL_DOWN | -#endif - GPIO_DIR_IN | GPIO_INT | - GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH); + GPIO_INPUT | GPIO_IRQ_FLAGS); gpio_init_callback(&gpio_cb, bt_spi_isr, BIT(GPIO_IRQ_PIN)); @@ -497,9 +496,8 @@ static int bt_spi_open(void) return -EINVAL; } - if (gpio_pin_enable_callback(irq_dev, GPIO_IRQ_PIN)) { - return -EINVAL; - } + gpio_pin_interrupt_configure(irq_dev, GPIO_IRQ_PIN, + GPIO_INT_EDGE_TO_ACTIVE); /* Start RX thread */ k_thread_create(&spi_rx_thread_data, spi_rx_stack, @@ -509,7 +507,7 @@ static int bt_spi_open(void) 0, K_NO_WAIT); /* Take BLE out of reset */ - gpio_pin_write(rst_dev, GPIO_RESET_PIN, 1); + gpio_pin_set(rst_dev, GPIO_RESET_PIN, 0); /* Device will let us know when it's ready */ k_sem_take(&sem_initialised, K_FOREVER);