1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2019 Jim Mussared
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 #ifndef MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H
28 #define MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H
29 
30 #include "extmod/modbluetooth.h"
31 
32 #define MP_BLUETOOTH_NIMBLE_MAX_SERVICES (8)
33 
34 typedef struct _mp_bluetooth_nimble_root_pointers_t {
35     // Characteristic (and descriptor) value storage.
36     mp_gatts_db_t gatts_db;
37 
38     // Pending service definitions.
39     size_t n_services;
40     struct ble_gatt_svc_def *services[MP_BLUETOOTH_NIMBLE_MAX_SERVICES];
41 
42     #if MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS
43     // L2CAP channels.
44     struct _mp_bluetooth_nimble_l2cap_channel_t *l2cap_chan;
45     bool l2cap_listening;
46     #endif
47 } mp_bluetooth_nimble_root_pointers_t;
48 
49 enum {
50     MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF,
51     MP_BLUETOOTH_NIMBLE_BLE_STATE_STARTING,
52     MP_BLUETOOTH_NIMBLE_BLE_STATE_WAITING_FOR_SYNC,
53     MP_BLUETOOTH_NIMBLE_BLE_STATE_ACTIVE,
54     MP_BLUETOOTH_NIMBLE_BLE_STATE_STOPPING,
55 };
56 
57 extern volatile int mp_bluetooth_nimble_ble_state;
58 
59 // --- Optionally provided by the MicroPython port. ---------------------------
60 // (default implementations provided by modbluetooth_nimble.c)
61 
62 // Tell the port to init the UART and start the HCI controller.
63 void mp_bluetooth_nimble_port_hci_init(void);
64 
65 // Tell the port to deinit the UART and shutdown the HCI controller.
66 void mp_bluetooth_nimble_port_hci_deinit(void);
67 
68 // Tell the port to run its background task (i.e. poll the UART and pump events).
69 void mp_bluetooth_nimble_port_start(void);
70 
71 // Tell the port to stop its background task.
72 void mp_bluetooth_nimble_port_shutdown(void);
73 
74 // --- Called by the HCI UART layer to let us know when packets have been sent.
75 void mp_bluetooth_nimble_sent_hci_packet(void);
76 
77 
78 #endif // MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H
79