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
11 changes: 11 additions & 0 deletions boards/ambiq/apollo3_evb/apollo3_evb-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,15 @@
ambiq,iom-num = <6>;
};
};

bleif_default: bleif_default{
group1 {
pinmux = <BLEIF_SCK_P30>,
<BLEIF_MISO_P31>,
<BLEIF_MOSI_P32>,
<BLEIF_CSN_P33>,
<BLEIF_STATUS_P35>,
<BLEIF_IRQ_P41>;
};
};
};
6 changes: 6 additions & 0 deletions boards/ambiq/apollo3_evb/apollo3_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
};
};

&bleif {
pinctrl-0 = <&bleif_default>;
pinctrl-names = "default";
status = "okay";
};

&uart0 {
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
Expand Down
11 changes: 11 additions & 0 deletions boards/ambiq/apollo3p_evb/apollo3p_evb-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,15 @@
ambiq,iom-num = <2>;
};
};

bleif_default: bleif_default{
group1 {
pinmux = <BLEIF_SCK_P30>,
<BLEIF_MISO_P31>,
<BLEIF_MOSI_P32>,
<BLEIF_CSN_P33>,
<BLEIF_STATUS_P35>,
<BLEIF_IRQ_P41>;
};
};
};
6 changes: 6 additions & 0 deletions boards/ambiq/apollo3p_evb/apollo3p_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
};
};

&bleif {
pinctrl-0 = <&bleif_default>;
pinctrl-names = "default";
status = "okay";
};

&uart0 {
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
Expand Down
4 changes: 2 additions & 2 deletions drivers/bluetooth/hci/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ config BT_NO_DRIVER
config BT_AMBIQ_HCI
bool "AMBIQ BT HCI driver"
select SPI
select GPIO
select CLOCK_CONTROL
select GPIO if SOC_SERIES_APOLLO4X
select CLOCK_CONTROL if SOC_SERIES_APOLLO4X
select BT_HCI_SETUP
help
Supports Ambiq Bluetooth SoC using SPI as the communication protocol.
Expand Down
80 changes: 73 additions & 7 deletions drivers/bluetooth/hci/apollox_blue.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ LOG_MODULE_REGISTER(bt_apollox_driver);
#include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/clock_control/clock_control_ambiq.h>

#include <am_mcu_apollo.h>
#include "apollox_blue.h"
#if (CONFIG_SOC_SERIES_APOLLO4X)
#include "am_devices_cooper.h"
#elif (CONFIG_SOC_SERIES_APOLLO3X)
#include "am_apollo3_bt_support.h"
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

#define HCI_SPI_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(ambiq_bt_hci_spi)
#define SPI_DEV_NODE DT_BUS(HCI_SPI_NODE)
Expand All @@ -44,6 +49,7 @@ LOG_MODULE_REGISTER(bt_apollox_driver);

#define SPI_MAX_RX_MSG_LEN 258

#if (CONFIG_SOC_SERIES_APOLLO4X)
static const struct gpio_dt_spec irq_gpio = GPIO_DT_SPEC_GET(HCI_SPI_NODE, irq_gpios);
static const struct gpio_dt_spec rst_gpio = GPIO_DT_SPEC_GET(HCI_SPI_NODE, reset_gpios);
static const struct gpio_dt_spec cs_gpio = GPIO_DT_SPEC_GET(SPI_DEV_NODE, cs_gpios);
Expand All @@ -54,10 +60,19 @@ static struct gpio_callback clkreq_gpio_cb;

static const struct device *clk32m_dev = DEVICE_DT_GET(CLK_32M_NODE);
static const struct device *clk32k_dev = DEVICE_DT_GET(CLK_32K_NODE);
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

extern void bt_packet_irq_isr(const struct device *unused1, struct gpio_callback *unused2,
uint32_t unused3);

void bt_apollo_rcv_isr_preprocess(void)
{
#if (CONFIG_SOC_SERIES_APOLLO3X)
am_apollo3_bt_isr_pre();
#endif /* CONFIG_SOC_SERIES_APOLLO3X */
}

#if (CONFIG_SOC_SERIES_APOLLO4X)
static bool irq_pin_state(void)
{
int pin_state;
Expand Down Expand Up @@ -117,10 +132,13 @@ static void bt_apollo_controller_reset(void)
/* Give the controller some time to boot */
k_sleep(K_MSEC(500));
}
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

int bt_apollo_spi_send(uint8_t *data, uint16_t len, bt_spi_transceive_fun transceive)
{
int ret;
int ret = -ENOTSUP;

#if (CONFIG_SOC_SERIES_APOLLO4X)
uint8_t command[1] = {SPI_WRITE};
uint8_t response[2] = {0, 0};
uint16_t fail_count = 0;
Expand All @@ -139,29 +157,51 @@ int bt_apollo_spi_send(uint8_t *data, uint16_t len, bt_spi_transceive_fun transc
break;
}
} while (fail_count++ < SPI_WRITE_TIMEOUT);
#elif (CONFIG_SOC_SERIES_APOLLO3X)
ret = transceive(data, len, NULL, 0);
if ((ret) && (ret != AM_HAL_BLE_STATUS_SPI_NOT_READY)) {
LOG_ERR("SPI write error %d", ret);
}
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

return ret;
}

int bt_apollo_spi_rcv(uint8_t *data, uint16_t *len, bt_spi_transceive_fun transceive)
{
int ret;
uint8_t command[1] = {SPI_READ};
int ret = -ENOTSUP;
uint8_t response[2] = {0, 0};
uint16_t read_size = 0;

do {
#if (CONFIG_SOC_SERIES_APOLLO4X)
/* Skip if the IRQ pin is not in high state */
if (!irq_pin_state()) {
ret = -1;
break;
}

/* Check the available packet bytes */
uint8_t command[1] = {SPI_READ};
ret = transceive(command, 1, response, 2);
if (ret) {
break;
}
#elif (CONFIG_SOC_SERIES_APOLLO3X)
/* Skip if the IRQ bit is not set */
if (!BLEIFn(0)->BSTATUS_b.BLEIRQ) {
ret = -1;
break;
}

/* Check the available packet bytes */
ret = transceive(NULL, 0, response, 2);
if (ret) {
break;
}
#else
break;
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

/* Check if the read size is acceptable */
read_size = (uint16_t)(response[0] | response[1] << 8);
Expand All @@ -186,6 +226,7 @@ int bt_apollo_spi_rcv(uint8_t *data, uint16_t *len, bt_spi_transceive_fun transc

bool bt_apollo_vnd_rcv_ongoing(uint8_t *data, uint16_t len)
{
#if (CONFIG_SOC_SERIES_APOLLO4X)
/* The vendor specific handshake command/response is incompatible with
* standard Bluetooth HCI format, need to handle the received packets
* specifically.
Expand All @@ -196,14 +237,18 @@ bool bt_apollo_vnd_rcv_ongoing(uint8_t *data, uint16_t len)
} else {
return false;
}
#else
return false;
#endif /* CONFIG_SOC_SERIES_APOLLO4X */
}

int bt_hci_transport_setup(const struct device *dev)
{
ARG_UNUSED(dev);

int ret;
int ret = 0;

#if (CONFIG_SOC_SERIES_APOLLO4X)
/* Configure the XO32MHz and XO32kHz clocks.*/
clock_control_configure(clk32k_dev, NULL, NULL);
clock_control_configure(clk32m_dev, NULL, NULL);
Expand Down Expand Up @@ -256,13 +301,18 @@ int bt_hci_transport_setup(const struct device *dev)

/* Configure the interrupt edge for IRQ pin */
gpio_pin_interrupt_configure_dt(&irq_gpio, GPIO_INT_EDGE_RISING);
#elif (CONFIG_SOC_SERIES_APOLLO3X)
IRQ_CONNECT(DT_IRQN(SPI_DEV_NODE), DT_IRQ(SPI_DEV_NODE, priority), bt_packet_irq_isr, 0, 0);
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

return 0;
return ret;
}

int bt_apollo_controller_init(spi_transmit_fun transmit)
{
int ret;
int ret = 0;

#if (CONFIG_SOC_SERIES_APOLLO4X)
am_devices_cooper_callback_t cb = {
.write = transmit,
.reset = bt_apollo_controller_reset,
Expand All @@ -277,10 +327,21 @@ int bt_apollo_controller_init(spi_transmit_fun transmit)
am_devices_cooper_set_initialize_state(AM_DEVICES_COOPER_STATE_INITIALIZE_FAIL);
LOG_ERR("BT controller initialization fail");
}
#elif (CONFIG_SOC_SERIES_APOLLO3X)
ret = am_apollo3_bt_controller_init();
if (ret == AM_HAL_STATUS_SUCCESS) {
LOG_INF("BT controller initialized");
} else {
LOG_ERR("BT controller initialization fail");
}

irq_enable(DT_IRQN(SPI_DEV_NODE));
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

return ret;
}

#if (CONFIG_SOC_SERIES_APOLLO4X)
static int bt_apollo_set_nvds(void)
{
int ret;
Expand Down Expand Up @@ -334,19 +395,23 @@ static int bt_apollo_set_nvds(void)

return ret;
}
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

int bt_apollo_vnd_setup(void)
{
int ret;
int ret = 0;

#if (CONFIG_SOC_SERIES_APOLLO4X)
/* Set the NVDS parameters to BLE controller */
ret = bt_apollo_set_nvds();
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

return ret;
}

int bt_apollo_dev_init(void)
{
#if (CONFIG_SOC_SERIES_APOLLO4X)
if (!gpio_is_ready_dt(&irq_gpio)) {
LOG_ERR("IRQ GPIO device not ready");
return -ENODEV;
Expand All @@ -361,6 +426,7 @@ int bt_apollo_dev_init(void)
LOG_ERR("CLKREQ GPIO device not ready");
return -ENODEV;
}
#endif /* CONFIG_SOC_SERIES_APOLLO4X */

return 0;
}
6 changes: 6 additions & 0 deletions drivers/bluetooth/hci/apollox_blue.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ int bt_apollo_vnd_setup(void);
*/
bool bt_apollo_vnd_rcv_ongoing(uint8_t *data, uint16_t len);

/**
* @brief Do the specific preprocessing in HCI packet receiving ISR if needed,
* for example, clear the interrupt status.
*/
void bt_apollo_rcv_isr_preprocess(void);

#ifdef __cplusplus
}
#endif
Expand Down
Loading