37
37
#include "shared-bindings/microcontroller/ResetReason.h"
38
38
#include "shared-module/storage/__init__.h"
39
39
40
- #include "bluetooth/ble_drv.h"
41
-
42
40
#include "common-hal/_bleio/__init__.h"
43
41
44
42
#include "supervisor/shared/status_leds.h"
48
46
49
47
#if CIRCUITPY_BLE_FILE_SERVICE
50
48
#include "supervisor/shared/bluetooth/file_transfer.h"
49
+ #include "bluetooth/ble_drv.h"
51
50
#endif
52
51
53
52
#if CIRCUITPY_SERIAL_BLE
54
53
#include "supervisor/shared/bluetooth/serial.h"
54
+ #include "bluetooth/ble_drv.h"
55
55
#endif
56
56
57
57
// This standard advertisement advertises the CircuitPython editing service and a CIRCUITPY short name.
@@ -75,18 +75,21 @@ const uint8_t public_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags
75
75
const uint8_t private_advertising_data [] = { 0x02 , 0x01 , 0x06 , // 0-2 Flags
76
76
0x02 , 0x0a , 0x00 // 3-5 TX power level 0
77
77
};
78
- // This scan response advertises the full CIRCUITPYXXXX device name.
78
+ // This scan response advertises the full CIRCPYXXXX device name.
79
79
uint8_t circuitpython_scan_response_data [] = {
80
- 0x0e , 0x09 , 0x43 , 0x49 , 0x52 , 0x43 , 0x55 , 0x49 , 0x54 , 0x50 , 0x59 , 0x00 , 0x00 , 0x00 , 0x00 ,
80
+ 0x0a , 0x09 , 0x43 , 0x49 , 0x52 , 0x50 , 0x59 , 0x00 , 0x00 , 0x00 , 0x00 ,
81
81
#if CIRCUITPY_SERIAL_BLE
82
- 0x06 , 0x10 , 0x9e , 0xca , 0xdc , 0x24 , 0x0e , 0xe5 , 0xa9 , 0xe0 , 0x93 , 0xf3 , 0xa3 , 0xb5 , 0x00 , 0x00 , 0x40 , 0x6e ,
82
+ 0x11 , 0x06 , 0x9e , 0xca , 0xdc , 0x24 , 0x0e , 0xe5 , 0xa9 , 0xe0 , 0x93 , 0xf3 , 0xa3 , 0xb5 , 0x01 , 0x00 , 0x40 , 0x6e ,
83
83
#endif
84
84
};
85
85
86
86
bool boot_in_discovery_mode = false;
87
87
bool advertising = false;
88
88
89
89
STATIC void supervisor_bluetooth_start_advertising (void ) {
90
+ // #if !CIRCUITPY_BLE_FILE_SERVICE && !CIRCUITPY_SERIAL_BLE
91
+ // return;
92
+ // #else
90
93
bool is_connected = common_hal_bleio_adapter_get_connected (& common_hal_bleio_adapter_obj );
91
94
if (is_connected ) {
92
95
return ;
@@ -95,7 +98,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
95
98
#if CIRCUITPY_USB
96
99
// Don't advertise when we have USB instead of BLE.
97
100
if (!bonded && !boot_in_discovery_mode ) {
98
- // mp_printf(&mp_plat_print, "skipping advertising\n");
101
+ mp_printf (& mp_plat_print , "skipping advertising\n" );
99
102
return ;
100
103
}
101
104
#endif
@@ -109,6 +112,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
109
112
// Advertise with less power when doing so publicly to reduce who can hear us. This will make it
110
113
// harder for someone with bad intentions to pair from a distance.
111
114
if (!bonded ) {
115
+ mp_printf (& mp_plat_print , "public advertising\n" );
112
116
tx_power = -40 ;
113
117
adv = public_advertising_data ;
114
118
adv_len = sizeof (public_advertising_data );
@@ -126,6 +130,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
126
130
scan_response_len ,
127
131
tx_power ,
128
132
NULL );
133
+ mp_printf (& mp_plat_print , "advert %d\n" , status );
129
134
// This may fail if we are already advertising.
130
135
advertising = status == NRF_SUCCESS ;
131
136
}
@@ -139,20 +144,22 @@ void supervisor_bluetooth_init(void) {
139
144
if ((reset_state & BLE_DISCOVERY_DATA_GUARD_MASK ) == BLE_DISCOVERY_DATA_GUARD ) {
140
145
ble_mode = (reset_state & ~BLE_DISCOVERY_DATA_GUARD_MASK ) >> 8 ;
141
146
}
142
- const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason ();
147
+ // const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
143
148
boot_in_discovery_mode = false;
144
- if (reset_reason != RESET_REASON_POWER_ON &&
145
- reset_reason != RESET_REASON_RESET_PIN &&
146
- reset_reason != RESET_REASON_UNKNOWN &&
147
- reset_reason != RESET_REASON_SOFTWARE ) {
148
- return ;
149
- }
149
+ // if (reset_reason != RESET_REASON_POWER_ON &&
150
+ // reset_reason != RESET_REASON_RESET_PIN &&
151
+ // reset_reason != RESET_REASON_UNKNOWN &&
152
+ // reset_reason != RESET_REASON_SOFTWARE) {
153
+ // return;
154
+ // }
150
155
151
156
if (ble_mode == 0 ) {
152
157
port_set_saved_word (BLE_DISCOVERY_DATA_GUARD | (0x01 << 8 ));
153
158
}
154
159
// Wait for a while to allow for reset.
155
160
161
+ ble_mode = 1 ;
162
+
156
163
#ifdef CIRCUITPY_BOOT_BUTTON
157
164
digitalio_digitalinout_obj_t boot_button ;
158
165
common_hal_digitalio_digitalinout_construct (& boot_button , CIRCUITPY_BOOT_BUTTON );
0 commit comments