Merge branch 'master' into direct

This commit is contained in:
hathach committed 2023-11-30 12:16:58 +07:00
commit ea3dd125f0
53 files changed
+50785 -51451

No files matched your search

+3
View File
@@ -3,3 +3,6 @@ contact_links:
- name: Adafruit Support Forum
url: https://forums.adafruit.com
about: If you have other questions or need help, post it here.
- name: Discussion
url: https://github.com/adafruit/Adafruit_nRF52_Arduino/discussions
about: If you have other questions or need help, post it here.
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -13,32 +13,34 @@
*********************************************************************/
#include <bluefruit.h>
// Beacon uses the Manufacturer Specific Data field in the advertising
// packet, which means you must provide a valid Manufacturer ID. Update
// Beacon uses the Manufacturer Specific Data field in the advertising packet,
// which means you must provide a valid Manufacturer ID. Update
// the field below to an appropriate value. For a list of valid IDs see:
// https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
// 0x004C is Apple
// 0x0822 is Adafruit
// 0x0059 is Nordic
// - 0x004C is Apple
// - 0x0822 is Adafruit
// - 0x0059 is Nordic
// For testing with this sketch, you can use nRF Beacon app
// - on Android you may need change the MANUFACTURER_ID to Nordic
// - on iOS you may need to change the MANUFACTURER_ID to Apple.
// You will also need to "Add Other Beacon, then enter Major, Minor that you set in the sketch
#define MANUFACTURER_ID 0x0059
// "nRF Connect" app can be used to detect beacon
uint8_t beaconUuid[16] =
{
uint8_t beaconUuid[16] = {
0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0
};
// A valid Beacon packet consists of the following information:
// UUID, Major, Minor, RSSI @ 1M
BLEBeacon beacon(beaconUuid, 0x0102, 0x0304, -54);
BLEBeacon beacon(beaconUuid, 1, 2, -54);
void setup()
{
void setup() {
Serial.begin(115200);
// Uncomment to blocking wait for Serial connection
// while ( !Serial ) delay(10);
// while ( !Serial ) delay(10);
Serial.println("Bluefruit52 Beacon Example");
Serial.println("--------------------------\n");
@@ -55,7 +57,10 @@ void setup()
// Setup the advertising packet
startAdv();
Serial.println("Broadcasting beacon, open your beacon app to test");
Serial.printf("Broadcasting beacon with MANUFACTURER_ID = 0x%04X\n", MANUFACTURER_ID);
Serial.println("open your beacon app to test such as: nRF Beacon");
Serial.println("- on Android you may need to change the MANUFACTURER_ID to 0x0059");
Serial.println("- on iOS you may need to change the MANUFACTURER_ID to 0x004C");
// Suspend Loop() to save power, since we didn't have any code there
suspendLoop();
@@ -78,17 +83,16 @@ void startAdv(void)
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* Apple Beacon specs
* - Type: Non connectable, undirected
* - Type: Non-connectable, scannable, undirected
* - Fixed interval: 100 ms -> fast = slow = 100 ms
*/
//Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_ADV_NONCONN_IND);
Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED);
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(160, 160); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
void loop() {
// loop is already suspended, CPU will not run loop() at all
}
@@ -41,7 +41,10 @@
#include "bonding.h"
#include "bluefruit.h"
using namespace Adafruit_LittleFS_Namespace;
enum {
FO_READ = Adafruit_LittleFS_Namespace::FILE_O_READ,
FO_WRITE = Adafruit_LittleFS_Namespace::FILE_O_WRITE,
};
#define BOND_DEBUG 1
@@ -68,7 +71,7 @@ static void get_fname (char* fname, uint8_t role, uint8_t const mac[6])
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
static bool bdata_skip_field(File* file)
static bool bdata_skip_field(Adafruit_LittleFS_Namespace::File* file)
{
int len = file->read();
VERIFY(len > 0);
@@ -77,7 +80,7 @@ static bool bdata_skip_field(File* file)
return true;
}
static void bdata_write(File* file, void const* buffer, uint16_t bufsize)
static void bdata_write(Adafruit_LittleFS_Namespace::File* file, void const* buffer, uint16_t bufsize)
{
file->write( (uint8_t) bufsize );
file->write( (uint8_t const*) buffer, bufsize);
@@ -106,7 +109,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t con
// delete if file already exists
if ( InternalFS.exists(filename) ) InternalFS.remove(filename);
File file(filename, FILE_O_WRITE, InternalFS);
Adafruit_LittleFS_Namespace::File file(filename, FO_WRITE, InternalFS);
VERIFY(file,);
//------------- save keys -------------//
@@ -150,8 +153,8 @@ bool bond_load_keys(uint8_t role, ble_gap_addr_t* addr, bond_keys_t* bkeys)
char filename[BOND_FNAME_LEN];
get_fname(filename, role, addr->addr);
File file(InternalFS);
if( file.open(filename, FILE_O_READ) )
Adafruit_LittleFS_Namespace::File file(InternalFS);
if( file.open(filename, FO_READ) )
{
int keylen = file.read();
if ( keylen > 0 )
@@ -172,10 +175,10 @@ bool bond_load_keys(uint8_t role, ble_gap_addr_t* addr, bond_keys_t* bkeys)
// Resolvable address, we have to go through the whole list to perform IRK Address matching
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
File dir(dpath, FILE_O_READ, InternalFS);
File file(InternalFS);
Adafruit_LittleFS_Namespace::File dir(dpath, FO_READ, InternalFS);
Adafruit_LittleFS_Namespace::File file(InternalFS);
while ( !ret && (file = dir.openNextFile(FILE_O_READ)) )
while ( !ret && (file = dir.openNextFile(FO_READ)) )
{
int keylen = file.read();
if ( keylen == sizeof(bond_keys_t) )
@@ -217,7 +220,7 @@ static void bond_save_cccd_dfr (uint8_t role, uint16_t conn_hdl, ble_gap_addr_t
char filename[BOND_FNAME_LEN];
get_fname(filename, role, id_addr->addr);
File file(filename, FILE_O_WRITE, InternalFS);
Adafruit_LittleFS_Namespace::File file(filename, FO_WRITE, InternalFS);
VERIFY(file,);
file.seek(0); // write mode start at the end, seek to beginning
@@ -266,7 +269,7 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, ble_gap_addr_t const* id_ad
char filename[BOND_FNAME_LEN];
get_fname(filename, role, id_addr->addr);
File file(filename, FILE_O_READ, InternalFS);
Adafruit_LittleFS_Namespace::File file(filename, FO_READ, InternalFS);
if ( file )
{
bdata_skip_field(&file); // skip key
@@ -298,10 +301,10 @@ void bond_print_list(uint8_t role)
{
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
File dir(dpath, FILE_O_READ, InternalFS);
File file(InternalFS);
Adafruit_LittleFS_Namespace::File dir(dpath, FO_READ, InternalFS);
Adafruit_LittleFS_Namespace::File file(InternalFS);
while ( (file = dir.openNextFile(FILE_O_READ)) )
while ( (file = dir.openNextFile(FO_READ)) )
{
if ( !file.isDirectory() && bdata_skip_field(&file) ) // skip key
{
+3 -3
View File
@@ -120,14 +120,14 @@ void SwRotaryEncoder::clearAbs(void)
void SwRotaryEncoder::_irq_handler(void)
{
uint32_t val = NRF_GPIO->IN;
uint8_t bita = bitRead(val, _pina);
uint8_t bita = digitalRead(_pina);
uint8_t bitb = digitalRead(_pinb);
if ( bita != _a_last)
{
int32_t step;
if ( bita != bitRead(val, _pinb) )
if ( bita != bitb )
{
step = 1;
}else
+1 -1
View File
@@ -146,7 +146,7 @@ tools.nrfutil.upload.pattern="{cmd}" {upload.verbose} dfu serial -pkg "{build.pa
# ---------------------------------------------------
# Bootloader version
tools.bootburn.bootloader.file={runtime.platform.path}/bootloader/{build.variant}/{build.variant}_bootloader-0.6.2_{build.sd_name}_{build.sd_version}
tools.bootburn.bootloader.file={runtime.platform.path}/bootloader/{build.variant}/{build.variant}_bootloader-0.8.0_{build.sd_name}_{build.sd_version}
tools.bootburn.bootloader.params.verbose=
tools.bootburn.bootloader.params.quiet=
+31 -21
View File
@@ -1,7 +1,6 @@
import os
import shutil
import urllib.request
import zipfile
from multiprocessing import Pool
# Get all variants
all_variant = []
@@ -11,7 +10,7 @@ for entry in os.scandir("variants"):
all_variant.sort()
# Detect version in platform.txt
version = '';
version = ''
with open('platform.txt') as pf:
platform_txt = pf.read()
e = '{build.variant}_bootloader-'
@@ -19,25 +18,36 @@ with open('platform.txt') as pf:
v2 = platform_txt.index('_', v1)
version = platform_txt[v1:v2]
print('version {}'.format(version))
print(f'version {version}')
for variant in all_variant:
# Download a variant's bootloader
def download_variant(variant):
# Download from bootloader release
name = '{}_bootloader-{}.zip'.format(variant, version)
url = 'https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases/download/{}/{}'.format(version, name)
print("Downloading", name)
urllib.request.urlretrieve(url, name)
# remove existing bootloader
shutil.rmtree('bootloader/{}'.format(variant), ignore_errors=True)
# unzip
with zipfile.ZipFile(name, "r") as zip_ref:
zip_ref.extractall("bootloader/{}".format(variant))
# Remove update.uf2 for 832
sd_version = '6.1.1'
sd_name = 's140'
if variant == 'feather_nrf52832':
os.remove("bootloader/{}/update-{}_nosd.uf2".format(variant, name[:-4]))
sd_name = 's132'
# remove zip file
os.remove(name)
f_zip = f'{variant}_bootloader-{version}_{sd_name}_{sd_version}.zip'
f_hex = f'{variant}_bootloader-{version}_{sd_name}_{sd_version}.hex'
f_uf2 = f'update-{variant}_bootloader-{version}_nosd.uf2'
url_prefix = f'https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases/download/{version}/'
# remove existing bootloader files
for item in os.listdir(f'bootloader/{variant}'):
os.remove(os.path.join(f'bootloader/{variant}', item))
print(f"Downloading {f_zip}")
urllib.request.urlretrieve(url_prefix + f_zip, f'bootloader/{variant}/{f_zip}')
print(f"Downloading {f_hex}")
urllib.request.urlretrieve(url_prefix + f_hex, f'bootloader/{variant}/{f_hex}')
if sd_name != 's132':
print(f"Downloading {f_uf2}")
urllib.request.urlretrieve(url_prefix + f_uf2, f'bootloader/{variant}/{f_uf2}')
if __name__ == "__main__":
with Pool() as p:
p.map(download_variant, all_variant)