Skip to content

Commit a5ab282

Browse files
committed
use zephyr include files; wip: compiles
1 parent 11cb3e3 commit a5ab282

File tree

16 files changed

+5005
-753
lines changed

16 files changed

+5005
-753
lines changed

devices/ble_hci/common-hal/_bleio/Adapter.c

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <stdio.h>
3232
#include <string.h>
3333

34-
#include "hci.h"
34+
#include "hci_api.h"
3535

3636
#include "py/gc.h"
3737
#include "py/mphal.h"
@@ -179,13 +179,10 @@ char default_ble_name[] = { 'C', 'I', 'R', 'C', 'U', 'I', 'T', 'P', 'Y', 0, 0, 0
179179
// common_hal_bleio_adapter_set_name(self, (char*) default_ble_name);
180180
// }
181181

182-
void common_hal_bleio_adapter_hci_init(bleio_adapter_obj_t *self, const mcu_pin_obj_t *tx, const mcu_pin_obj_t *rx, const mcu_pin_obj_t *rts, const mcu_pin_obj_t *cts, uint32_t baudrate, uint32_t buffer_size) {
183-
self->tx_pin = tx;
184-
self->rx_pin = rx;
182+
void common_hal_bleio_adapter_hci_init(bleio_adapter_obj_t *self, busio_uart_obj_t *uart, const mcu_pin_obj_t *rts, const mcu_pin_obj_t *cts) {
183+
self->hci_uart = uart;
185184
self->rts_pin = rts;
186185
self->cts_pin = cts;
187-
self->baudrate = baudrate;
188-
self->buffer_size = buffer_size;
189186
self->enabled = false;
190187
}
191188

@@ -198,34 +195,15 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
198195
}
199196

200197
if (enabled) {
201-
common_hal_busio_uart_construct(
202-
&self->hci_uart,
203-
self->tx_pin, // tx pin
204-
self->rx_pin, // rx pin
205-
NULL, // rts pin
206-
NULL, // cts pin
207-
NULL, // rs485 dir pin
208-
false, // rs485 invert
209-
0, // timeout
210-
self->baudrate, // baudrate
211-
8, // nbits
212-
PARITY_NONE, // parity
213-
1, // stop bits
214-
self->buffer_size, // buffer size
215-
NULL, // buffer
216-
false // sigint_enabled
217-
);
218198
common_hal_digitalio_digitalinout_construct(&self->rts_digitalinout, self->rts_pin);
219199
common_hal_digitalio_digitalinout_construct(&self->cts_digitalinout, self->cts_pin);
220200

221201
hci_init(self);
222202
} else {
223-
common_hal_busio_uart_deinit(&self->hci_uart);
224203
common_hal_digitalio_digitalinout_deinit(&self->rts_digitalinout);
225204
common_hal_digitalio_digitalinout_deinit(&self->cts_digitalinout);
226205
}
227206

228-
229207
//FIX enable/disable HCI adapter, but don't reset it, since we don't know how.
230208
self->enabled = enabled;
231209
}
@@ -235,35 +213,22 @@ bool common_hal_bleio_adapter_get_enabled(bleio_adapter_obj_t *self) {
235213
}
236214

237215
bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *self) {
238-
common_hal_bleio_adapter_set_enabled(self, true);
239-
240-
uint8_t addr[6];
241-
hci_readBdAddr(addr);
216+
bt_addr_le_t addr;
217+
hci_read_bd_addr(&addr.a);
242218

243219
bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t);
244220
address->base.type = &bleio_address_type;
245221

246-
// 0 is the type designating a public address.
247-
common_hal_bleio_address_construct(address, addr, 0);
222+
common_hal_bleio_address_construct(address, addr.a.val, addr.type);
248223
return address;
249224
}
250225

251226
mp_obj_str_t* common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
252-
uint16_t len = 0;
253-
// sd_ble_gap_device_name_get(NULL, &len);
254-
uint8_t buf[len];
255-
// uint32_t err_code = sd_ble_gap_device_name_get(buf, &len);
256-
// if (err_code != NRF_SUCCESS) {
257-
// return NULL;
258-
// }
259-
return mp_obj_new_str((char*) buf, len);
227+
return self->name;
260228
}
261229

262230
void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char* name) {
263-
// ble_gap_conn_sec_mode_t sec;
264-
// sec.lv = 0;
265-
// sec.sm = 0;
266-
// sd_ble_gap_device_name_set(&sec, (const uint8_t*) name, strlen(name));
231+
self->name = mp_obj_new_str(name, strlen(name));
267232
}
268233

269234
// STATIC bool scan_on_ble_evt(ble_evt_t *ble_evt, void *scan_results_in) {

devices/ble_hci/common-hal/_bleio/Adapter.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ typedef struct {
5252
bleio_scanresults_obj_t* scan_results;
5353
mp_obj_t name;
5454
mp_obj_tuple_t *connection_objs;
55-
const mcu_pin_obj_t* tx_pin;
56-
const mcu_pin_obj_t* rx_pin;
55+
busio_uart_obj_t* hci_uart;
5756
const mcu_pin_obj_t* rts_pin;
5857
const mcu_pin_obj_t* cts_pin;
59-
uint32_t baudrate;
60-
uint16_t buffer_size;
61-
busio_uart_obj_t hci_uart;
6258
digitalio_digitalinout_obj_t rts_digitalinout;
6359
digitalio_digitalinout_obj_t cts_digitalinout;
6460
bool enabled;

0 commit comments

Comments
 (0)