1 /*
2  * Copyright (c) 2023 Ambiq Micro Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @brief Header file of Ambiq Apollox Blue SoC extended driver
9  * for SPI based HCI.
10  */
11 #ifndef ZEPHYR_DRIVERS_BLUETOOTH_HCI_APOLLOX_BLUE_H_
12 #define ZEPHYR_DRIVERS_BLUETOOTH_HCI_APOLLOX_BLUE_H_
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /**
19  * @typedef bt_spi_transceive_fun
20  * @brief SPI transceive function for Bluetooth packet.
21  *
22  * @param tx Pointer of transmission packet.
23  * @param tx_len Length of transmission packet.
24  * @param rx Pointer of reception packet.
25  * @param rx_len Length of reception packet.
26  *
27  * @return 0 on success or negative error number on failure.
28  */
29 typedef int (*bt_spi_transceive_fun)(void *tx, uint32_t tx_len, void *rx, uint32_t rx_len);
30 
31 /**
32  * @typedef spi_transmit_fun
33  * @brief Define the SPI transmission function.
34  *
35  * @param data Pointer of transmission packet.
36  * @param len Length of transmission packet.
37  *
38  * @return 0 on success or negative error number on failure.
39  */
40 typedef int (*spi_transmit_fun)(uint8_t *data, uint16_t len);
41 
42 /**
43  * @brief Initialize the required devices for HCI driver.
44  *
45  * The devices mainly include the required gpio (e.g. reset-gpios,
46  * irq-gpios).
47  *
48  * @return 0 on success or negative error number on failure.
49  */
50 int bt_apollo_dev_init(void);
51 
52 /**
53  * @brief Send the packets to BLE controller from host via SPI.
54  *
55  * @param data Pointer of transmission packet.
56  * @param len  Length of transmission packet.
57  * @param transceive SPI transceive function for Bluetooth packet.
58  *
59  * @return 0 on success or negative error number on failure.
60  */
61 int bt_apollo_spi_send(uint8_t *data, uint16_t len, bt_spi_transceive_fun transceive);
62 
63 /**
64  * @brief Receive the packets sent from BLE controller to host via SPI.
65  *
66  * @param data Pointer of reception packet.
67  * @param len  Pointer of reception packet length.
68  * @param transceive  SPI transceive function for Bluetooth packet.
69  *
70  * @return 0 on success or negative error number on failure.
71  */
72 int bt_apollo_spi_rcv(uint8_t *data, uint16_t *len, bt_spi_transceive_fun transceive);
73 
74 /**
75  * @brief Initialize the BLE controller.
76  *
77  * This step may do the necessary handshaking with the controller before
78  * @param transmit SPI transmit function
79  *
80  * @return 0 on success or negative error number on failure.
81  */
82 int bt_apollo_controller_init(spi_transmit_fun transmit);
83 
84 /**
85  * @brief Vendor specific setup before general HCI command sequence for
86  * Bluetooth application.
87  *
88  * @return 0 on success or negative error number on failure.
89  */
90 int bt_apollo_vnd_setup(void);
91 
92 /**
93  * @brief Check if vendor specific receiving handling is ongoing.
94  *
95  * @param data Pointer of received packet.
96  *
97  * @return true indicates if vendor specific receiving handling is ongoing.
98  */
99 bool bt_apollo_vnd_rcv_ongoing(uint8_t *data, uint16_t len);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif /* ZEPHYR_DRIVERS_BLUETOOTH_HCI_APOLLOX_BLUE_H_ */
106