Skip to content

Commit bca3deb

Browse files
committed
drivers: Bluetooth: Generalize IC-specific setup hook
In order to generalize the currently specialized nRF51 IC setup hook, make the following changes: - Generalize the hook to bt_ic_setup() - Use a weak NOP version by default - Move the currently existing one to the board folder Signed-off-by: Carles Cufi <[email protected]>
1 parent 43b00ef commit bca3deb

File tree

8 files changed

+33
-46
lines changed

8 files changed

+33
-46
lines changed

boards/x86/arduino_101/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
zephyr_library()
44
zephyr_library_sources(pinmux.c)
5+
zephyr_library_sources_ifdef(CONFIG_BT_H4 nrf51_pm.c)
56
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)

drivers/bluetooth/nrf51_pm.c renamed to boards/x86/arduino_101/nrf51_pm.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,35 @@
1212

1313
#include <errno.h>
1414

15-
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
16-
#define LOG_MODULE_NAME bt_nrf51_pm
17-
#include "common/log.h"
18-
1915
#define NBLE_SWDIO_PIN 6
2016
#define NBLE_RESET_PIN NBLE_SWDIO_PIN
2117
#define NBLE_BTWAKE_PIN 5
2218

2319
static struct device *nrf51_gpio;
2420

25-
int nrf51_wakeup(void)
21+
static int nrf51_wakeup(void)
2622
{
2723
return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 1);
2824
}
2925

30-
int nrf51_allow_sleep(void)
31-
{
32-
return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 0);
33-
}
34-
35-
int nrf51_init(struct device *dev)
26+
int bt_hci_transport_setup(struct device *dev)
3627
{
3728
u8_t c;
3829
int ret;
3930

4031
nrf51_gpio = device_get_binding("GPIO_0");
4132
if (!nrf51_gpio) {
42-
BT_ERR("Cannot find GPIO_0");
4333
return -ENODEV;
4434
}
4535

4636
ret = gpio_pin_configure(nrf51_gpio, NBLE_RESET_PIN, GPIO_DIR_OUT);
4737
if (ret) {
48-
BT_ERR("Error configuring pin %d", NBLE_RESET_PIN);
4938
return -ENODEV;
5039
}
5140

5241
/* Reset hold time is 0.2us (normal) or 100us (SWD debug) */
5342
ret = gpio_pin_write(nrf51_gpio, NBLE_RESET_PIN, 0);
5443
if (ret) {
55-
BT_ERR("Error pin write %d", NBLE_RESET_PIN);
5644
return -EINVAL;
5745
}
5846

@@ -74,20 +62,17 @@ int nrf51_init(struct device *dev)
7462

7563
ret = gpio_pin_write(nrf51_gpio, NBLE_RESET_PIN, 1);
7664
if (ret) {
77-
BT_ERR("Error pin write %d", NBLE_RESET_PIN);
7865
return -EINVAL;
7966
}
8067

8168
/* Set back GPIO to input to avoid interfering with external debugger */
8269
ret = gpio_pin_configure(nrf51_gpio, NBLE_RESET_PIN, GPIO_DIR_IN);
8370
if (ret) {
84-
BT_ERR("Error configuring pin %d", NBLE_RESET_PIN);
8571
return -ENODEV;
8672
}
8773

8874
ret = gpio_pin_configure(nrf51_gpio, NBLE_BTWAKE_PIN, GPIO_DIR_OUT);
8975
if (ret) {
90-
BT_ERR("Error configuring pin %d", NBLE_BTWAKE_PIN);
9176
return -ENODEV;
9277
}
9378

drivers/bluetooth/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
zephyr_include_directories(${ZEPHYR_BASE}/subsys/bluetooth)
44
add_subdirectory(hci)
5-
zephyr_sources_ifdef(CONFIG_BT_NRF51_PM nrf51_pm.c)

drivers/bluetooth/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ if BT_CUSTOM
2424
# Insert here any custom (non-HCI) offload drives
2525
endif
2626

27-
config BT_NRF51_PM
28-
bool "nRF51 Power Management [EXPERIMENTAL]"
29-
depends on BT_H4
30-
help
31-
Power Management support for Nordic BLE nRF51 chip. Allows to enable,
32-
disable the chip and handle wakeups.
33-
3427
endmenu
3528

3629
endif # BT && ! BT_CTLR

drivers/bluetooth/hci/h4.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
#include "../util.h"
3030

31-
#if defined(CONFIG_BT_NRF51_PM)
32-
#include "../nrf51_pm.h"
33-
#endif
34-
3531
#define H4_NONE 0x00
3632
#define H4_CMD 0x01
3733
#define H4_ACL 0x02
@@ -423,20 +419,31 @@ static int h4_send(struct net_buf *buf)
423419
return 0;
424420
}
425421

422+
/** Setup the HCI transport, which usually means to reset the Bluetooth IC
423+
*
424+
* @param dev The device structure for the bus connecting to the IC
425+
*
426+
* @return 0 on success, negative error value on failure
427+
*/
428+
int __weak bt_hci_transport_setup(struct device *dev)
429+
{
430+
h4_discard(h4_dev, 32);
431+
return 0;
432+
}
433+
426434
static int h4_open(void)
427435
{
436+
int ret;
437+
428438
BT_DBG("");
429439

430440
uart_irq_rx_disable(h4_dev);
431441
uart_irq_tx_disable(h4_dev);
432442

433-
#if defined(CONFIG_BT_NRF51_PM)
434-
if (nrf51_init(h4_dev) < 0) {
443+
ret = bt_hci_transport_setup(h4_dev);
444+
if (ret < 0) {
435445
return -EIO;
436446
}
437-
#else
438-
h4_discard(h4_dev, 32);
439-
#endif
440447

441448
uart_irq_callback_set(h4_dev, bt_uart_isr);
442449

drivers/bluetooth/nrf51_pm.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

include/drivers/bluetooth/hci_driver.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdbool.h>
2121
#include <net/buf.h>
2222
#include <bluetooth/buf.h>
23+
#include <device.h>
2324

2425
#ifdef __cplusplus
2526
extern "C" {
@@ -167,6 +168,19 @@ struct bt_hci_driver {
167168
*/
168169
int bt_hci_driver_register(const struct bt_hci_driver *drv);
169170

171+
/**
172+
* @brief Setup the HCI transport, which usually means to reset the
173+
* Bluetooth IC.
174+
*
175+
* @note A weak version of this function is included in the H4 driver, so
176+
* defining it is optional per board.
177+
*
178+
* @param dev The device structure for the bus connecting to the IC
179+
*
180+
* @return 0 on success, negative error value on failure
181+
*/
182+
int bt_hci_transport_setup(struct device *dev);
183+
170184
#ifdef __cplusplus
171185
}
172186
#endif

samples/boards/arduino_101/environmental_sensing/ap/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ CONFIG_BT=y
99
CONFIG_BT_PERIPHERAL=y
1010
CONFIG_GPIO=y
1111
CONFIG_BT_WAIT_NOP=y
12-
CONFIG_BT_NRF51_PM=y

0 commit comments

Comments
 (0)