12
12
struct NimBLE : ~ Copyable {
13
13
14
14
init ( ) throws ( ESPError) {
15
- //esp_nimble_hci_init()
16
- try nvs_flash_init ( ) . throwsESPError ( )
17
- print ( " nvs_flash_init() " )
18
- try nimble_port_init ( ) . throwsESPError ( )
19
- print ( " nimble_port_init() " )
20
- //var options = esp_bt_controller_config_t()
21
- //try esp_bt_controller_init(&options).throwsESPError()
22
- //print("esp_bt_controller_init()")
23
- //try esp_bt_controller_enable(ESP_BT_MODE_BLE).throwsESPError()
24
- // print("esp_bt_controller_enable()")
15
+ try nvs_flash_init ( ) . throwsESPError ( )
16
+ try nimble_port_init ( ) . throwsESPError ( )
25
17
nimble_port_freertos_init ( nimble_host_task)
26
18
}
27
-
19
+
28
20
deinit {
29
- //esp_nimble_hci_deinit ()
21
+ nimble_port_freertos_deinit ( )
30
22
}
31
23
32
24
var gap = GAP ( )
25
+
26
+ var hostController = HostController ( )
33
27
}
34
28
35
29
@_silgen_name ( " nvs_flash_init " )
@@ -42,10 +36,10 @@ internal func nimble_port_init() -> Int32
42
36
internal func nimble_port_run( ) -> Int32
43
37
44
38
@_silgen_name ( " nimble_port_freertos_init " )
45
- internal func nimble_port_freertos_init( _ function: ( UnsafeMutableRawPointer ) -> ( ) ) -> Int32
39
+ internal func nimble_port_freertos_init( _ function: ( UnsafeMutableRawPointer ) -> ( ) )
46
40
47
41
@_silgen_name ( " nimble_port_freertos_deinit " )
48
- internal func nimble_port_freertos_deinit( ) -> Int32
42
+ internal func nimble_port_freertos_deinit( )
49
43
50
44
internal func nimble_host_task( _ parameters: UnsafeMutableRawPointer ) {
51
45
print ( " BLE Host Task Started " )
@@ -103,4 +97,19 @@ public struct GAP: ~Copyable {
103
97
104
98
internal func _gap_callback( event: UnsafeMutablePointer < ble_gap_event > ? , context: UnsafeMutableRawPointer ? ) -> Int32 {
105
99
return 0
100
+ }
101
+
102
+ public struct HostController : ~ Copyable {
103
+
104
+ func address(
105
+ type: LowEnergyAddressType = . public
106
+ ) throws ( NimBLEError) -> BluetoothAddress {
107
+ var address = BluetoothAddress . zero
108
+ try withUnsafeMutablePointer ( to: & address) {
109
+ $0. withMemoryRebound ( to: UInt8 . self, capacity: 6 ) {
110
+ ble_hs_id_copy_addr ( type. rawValue, $0, nil )
111
+ }
112
+ } . throwsError ( )
113
+ return address
114
+ }
106
115
}
0 commit comments