This commit is contained in:
Scott Shawcroft 2021-06-29 11:54:15 -07:00
parent b36858daa0
commit f2ef586331
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
5 changed files with 12 additions and 20 deletions

View File

@ -38,8 +38,6 @@
#include "py/misc.h"
#include "py/mpstate.h"
// #include "supervisor/shared/bluetooth.h"
nrf_nvic_state_t nrf_nvic_state = { 0 };
// Flag indicating progress of internal flash operation.

View File

@ -311,7 +311,6 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
// Did an sd_ble_gatts_sys_attr_set() with the stored sys_attr values.
// Indicate ATTR table change because we may have reloaded since the peer last
// connected.
mp_printf(&mp_plat_print, "restore sys attrs\n");
sd_ble_gatts_service_changed(self->conn_handle, 0xC, 0xFFFF);
} else {
// No matching bonding found, so use fresh system attributes.

View File

@ -153,7 +153,6 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
char_md.p_char_user_desc = (const uint8_t *)user_description;
char_md.char_user_desc_max_size = strlen(user_description);
char_md.char_user_desc_size = strlen(user_description);
mp_printf(&mp_plat_print, "user description %s\n", user_description);
}
bleio_attribute_gatts_set_security_mode(&char_attr_md.read_perm, characteristic->read_perm);

View File

@ -87,9 +87,9 @@ bool boot_in_discovery_mode = false;
bool advertising = false;
STATIC void supervisor_bluetooth_start_advertising(void) {
// #if !CIRCUITPY_BLE_FILE_SERVICE && !CIRCUITPY_SERIAL_BLE
// return;
// #else
#if !CIRCUITPY_BLE_FILE_SERVICE && !CIRCUITPY_SERIAL_BLE
return;
#else
bool is_connected = common_hal_bleio_adapter_get_connected(&common_hal_bleio_adapter_obj);
if (is_connected) {
return;
@ -98,7 +98,6 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
#if CIRCUITPY_USB
// Don't advertise when we have USB instead of BLE.
if (!bonded && !boot_in_discovery_mode) {
mp_printf(&mp_plat_print, "skipping advertising\n");
return;
}
#endif
@ -112,7 +111,6 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
// Advertise with less power when doing so publicly to reduce who can hear us. This will make it
// harder for someone with bad intentions to pair from a distance.
if (!bonded) {
mp_printf(&mp_plat_print, "public advertising\n");
tx_power = -40;
adv = public_advertising_data;
adv_len = sizeof(public_advertising_data);
@ -130,9 +128,9 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
scan_response_len,
tx_power,
NULL);
mp_printf(&mp_plat_print, "advert %d\n", status);
// This may fail if we are already advertising.
advertising = status == NRF_SUCCESS;
#endif
}
#define BLE_DISCOVERY_DATA_GUARD 0xbb0000bb
@ -144,22 +142,20 @@ void supervisor_bluetooth_init(void) {
if ((reset_state & BLE_DISCOVERY_DATA_GUARD_MASK) == BLE_DISCOVERY_DATA_GUARD) {
ble_mode = (reset_state & ~BLE_DISCOVERY_DATA_GUARD_MASK) >> 8;
}
// const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
boot_in_discovery_mode = false;
// if (reset_reason != RESET_REASON_POWER_ON &&
// reset_reason != RESET_REASON_RESET_PIN &&
// reset_reason != RESET_REASON_UNKNOWN &&
// reset_reason != RESET_REASON_SOFTWARE) {
// return;
// }
if (reset_reason != RESET_REASON_POWER_ON &&
reset_reason != RESET_REASON_RESET_PIN &&
reset_reason != RESET_REASON_UNKNOWN &&
reset_reason != RESET_REASON_SOFTWARE) {
return;
}
if (ble_mode == 0) {
port_set_saved_word(BLE_DISCOVERY_DATA_GUARD | (0x01 << 8));
}
// Wait for a while to allow for reset.
ble_mode = 1;
#ifdef CIRCUITPY_BOOT_BUTTON
digitalio_digitalinout_obj_t boot_button;
common_hal_digitalio_digitalinout_construct(&boot_button, CIRCUITPY_BOOT_BUTTON);

View File

@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal