Skip to content
Permalink
Browse files

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 <carles.cufi@nordicsemi.no>
  • Loading branch information...
carlescufi committed Apr 18, 2019
1 parent 43b00ef commit bca3deb1e7352f3d4813b0f0c2c9212d909709fb
@@ -2,4 +2,5 @@

zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_sources_ifdef(CONFIG_BT_H4 nrf51_pm.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
@@ -12,47 +12,35 @@

#include <errno.h>

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_nrf51_pm
#include "common/log.h"

#define NBLE_SWDIO_PIN 6
#define NBLE_RESET_PIN NBLE_SWDIO_PIN
#define NBLE_BTWAKE_PIN 5

static struct device *nrf51_gpio;

int nrf51_wakeup(void)
static int nrf51_wakeup(void)
{
return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 1);
}

int nrf51_allow_sleep(void)
{
return gpio_pin_write(nrf51_gpio, NBLE_BTWAKE_PIN, 0);
}

int nrf51_init(struct device *dev)
int bt_hci_transport_setup(struct device *dev)
{
u8_t c;
int ret;

nrf51_gpio = device_get_binding("GPIO_0");
if (!nrf51_gpio) {
BT_ERR("Cannot find GPIO_0");
return -ENODEV;
}

ret = gpio_pin_configure(nrf51_gpio, NBLE_RESET_PIN, GPIO_DIR_OUT);
if (ret) {
BT_ERR("Error configuring pin %d", NBLE_RESET_PIN);
return -ENODEV;
}

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

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

ret = gpio_pin_write(nrf51_gpio, NBLE_RESET_PIN, 1);
if (ret) {
BT_ERR("Error pin write %d", NBLE_RESET_PIN);
return -EINVAL;
}

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

ret = gpio_pin_configure(nrf51_gpio, NBLE_BTWAKE_PIN, GPIO_DIR_OUT);
if (ret) {
BT_ERR("Error configuring pin %d", NBLE_BTWAKE_PIN);
return -ENODEV;
}

@@ -2,4 +2,3 @@

zephyr_include_directories(${ZEPHYR_BASE}/subsys/bluetooth)
add_subdirectory(hci)
zephyr_sources_ifdef(CONFIG_BT_NRF51_PM nrf51_pm.c)
@@ -24,13 +24,6 @@ if BT_CUSTOM
# Insert here any custom (non-HCI) offload drives
endif

config BT_NRF51_PM
bool "nRF51 Power Management [EXPERIMENTAL]"
depends on BT_H4
help
Power Management support for Nordic BLE nRF51 chip. Allows to enable,
disable the chip and handle wakeups.

endmenu

endif # BT && ! BT_CTLR
@@ -28,10 +28,6 @@

#include "../util.h"

#if defined(CONFIG_BT_NRF51_PM)
#include "../nrf51_pm.h"
#endif

#define H4_NONE 0x00
#define H4_CMD 0x01
#define H4_ACL 0x02
@@ -423,20 +419,31 @@ static int h4_send(struct net_buf *buf)
return 0;
}

/** Setup the HCI transport, which usually means to reset the Bluetooth IC
*
* @param dev The device structure for the bus connecting to the IC
*
* @return 0 on success, negative error value on failure
*/
int __weak bt_hci_transport_setup(struct device *dev)
{
h4_discard(h4_dev, 32);
return 0;
}

static int h4_open(void)
{
int ret;

BT_DBG("");

uart_irq_rx_disable(h4_dev);
uart_irq_tx_disable(h4_dev);

#if defined(CONFIG_BT_NRF51_PM)
if (nrf51_init(h4_dev) < 0) {
ret = bt_hci_transport_setup(h4_dev);
if (ret < 0) {
return -EIO;
}
#else
h4_discard(h4_dev, 32);
#endif

uart_irq_callback_set(h4_dev, bt_uart_isr);

This file was deleted.

@@ -20,6 +20,7 @@
#include <stdbool.h>
#include <net/buf.h>
#include <bluetooth/buf.h>
#include <device.h>

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

/**
* @brief Setup the HCI transport, which usually means to reset the
* Bluetooth IC.
*
* @note A weak version of this function is included in the H4 driver, so
* defining it is optional per board.
*
* @param dev The device structure for the bus connecting to the IC
*
* @return 0 on success, negative error value on failure
*/
int bt_hci_transport_setup(struct device *dev);

#ifdef __cplusplus
}
#endif
@@ -9,4 +9,3 @@ CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_GPIO=y
CONFIG_BT_WAIT_NOP=y
CONFIG_BT_NRF51_PM=y

0 comments on commit bca3deb

Please sign in to comment.
You can’t perform that action at this time.