Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
fa96588
Apps branch for experimentation
microbit-matt-hillsdon Dec 22, 2025
163073e
Fix packaging issues
microbit-matt-hillsdon Jan 8, 2026
37e521e
More packaging fixes
microbit-matt-hillsdon Jan 8, 2026
a842639
Fix web scenarios
microbit-matt-hillsdon Jan 8, 2026
ce98672
Initializing is a pre-connect not pre-flash stage
microbit-matt-hillsdon Jan 9, 2026
af4bdd8
Breaking: Model the disconnect for hidden tabs explicitly (#72)
microbit-matt-hillsdon Jan 14, 2026
e9cb85c
Rename for clarity
microbit-matt-hillsdon Jan 16, 2026
d366e59
Fix pause state during flash issue
microbit-matt-hillsdon Jan 16, 2026
90a9e79
Breaking: Move to a dynamic model of permission checks (#73)
microbit-matt-hillsdon Jan 16, 2026
55e26b8
Send previous status in connection events (#74)
microbit-matt-hillsdon Jan 19, 2026
65549d9
Attempt connection multiple times, retrieve latest services before st…
microbit-grace Jan 21, 2026
2ada7cd
Discover services right after connecting (#78)
microbit-grace Jan 21, 2026
c375a2c
Wait for disconnect after partial flashing success (#80)
microbit-matt-hillsdon Jan 22, 2026
41865e2
Fix name filter issue (#82)
microbit-matt-hillsdon Jan 23, 2026
cc516fb
Add ability to abort connect, new error type, and progress stages (#84)
microbit-matt-hillsdon Jan 29, 2026
802344e
Remove auto reconnect, `ConnectionStatus.Reconnecting`, and discardin…
microbit-grace Feb 5, 2026
742b8dc
Optimise BLE partial flashing and support V1 thin hex files (#86)
microbit-matt-hillsdon Feb 6, 2026
39e4a26
Add `deviceBondState` option to Bluetooth connection and remove specu…
microbit-grace Feb 9, 2026
8c8751f
Move demo to a separate app from the package (#88)
microbit-matt-hillsdon Feb 11, 2026
42bd15a
Add capacitor demo app to monorepo and build all workspaces in CI (#89)
microbit-matt-hillsdon Feb 11, 2026
0dc9655
Wait for post partial flash disconnect in connect (#91)
microbit-grace Feb 13, 2026
6661729
Skip partial flash when application hash already matches device (#92)
microbit-matt-hillsdon Feb 16, 2026
f7834dd
Move Capacitor packages to peer dependencies (#94)
microbit-matt-hillsdon Feb 16, 2026
92c9d63
Current hex files
microbit-matt-hillsdon Feb 27, 2026
a5ffd18
Add AGENTS/CLAUDE.md
microbit-matt-hillsdon Feb 27, 2026
9ae27f6
Fix iOS DFU with open-link security firmware (#99)
microbit-matt-hillsdon Feb 27, 2026
144524b
Fix flashing over a program without partial flashing service (#98)
microbit-grace Feb 27, 2026
271d01f
Fall back to DFU characteristics for iOS pairing trigger (#100)
microbit-matt-hillsdon Feb 27, 2026
1bb1064
Skip partial flash if we get zero hash value (#101)
microbit-matt-hillsdon Mar 2, 2026
dec7b81
Sync after build for capacitor demo
microbit-matt-hillsdon Mar 2, 2026
ab9ca11
Update known issues; updated Podfile.lock
microbit-matt-hillsdon Mar 2, 2026
4efefdf
Allow cap sync to fail in CI.
microbit-matt-hillsdon Mar 2, 2026
170d820
Reinstate "uBit" BLE name prefix support (#95)
microbit-matt-hillsdon Mar 2, 2026
f81a087
Add missing V2 init packet hash (#93)
microbit-matt-hillsdon Mar 2, 2026
74091d8
Breaking: reorganize for better tree shaking (#96)
microbit-matt-hillsdon Mar 2, 2026
fc07daa
Make the pause behavior optional (#102)
microbit-matt-hillsdon Mar 2, 2026
eb212cc
Attempt a workaround for the bad response issue (#77)
microbit-matt-hillsdon Mar 3, 2026
c56c4ae
Remove serial event state that's available from super class (#56)
microbit-matt-hillsdon Mar 3, 2026
d8d62cf
Use DAPLink vendor command for serial (#103)
microbit-matt-hillsdon Mar 3, 2026
1dcfac9
Breaking: Switch to throwing DeviceError when not connected
microbit-matt-hillsdon Mar 3, 2026
62d98e7
Breaking: Replace EventTarget with custom typed event system
microbit-matt-hillsdon Mar 3, 2026
8289c97
Move flash event to DeviceConnectionEventMap and dispatch from Bluetooth
microbit-matt-hillsdon Mar 3, 2026
4f5514e
Document post-flash connection state differences
microbit-matt-hillsdon Mar 3, 2026
985d343
Breaking: Move serialWrite from DeviceConnection to USB-specific inte…
microbit-matt-hillsdon Mar 3, 2026
52a9458
Merge pull request #104 from microbit-foundation/throw-not-connected
microbit-matt-hillsdon Mar 3, 2026
df2a97c
Document radio bridge as experimental / limited
microbit-matt-hillsdon Mar 3, 2026
775a3f2
Merge pull request #105 from microbit-foundation/drop-event-target
microbit-matt-hillsdon Mar 3, 2026
0ec8881
Merge pull request #106 from microbit-foundation/document-post-connec…
microbit-matt-hillsdon Mar 3, 2026
cb5df72
Merge pull request #107 from microbit-foundation/no-serial-for-bluetooth
microbit-matt-hillsdon Mar 3, 2026
dca3fd7
Merge pull request #108 from microbit-foundation/tidy-radio-bridge
microbit-matt-hillsdon Mar 3, 2026
9829707
Inline CMSIS-DAP protocol handling, removing dapjs dependency
microbit-matt-hillsdon Mar 3, 2026
94b76d8
Improve serial data handling around flash
microbit-matt-hillsdon Mar 4, 2026
3596992
Fix partial flash retry by reinitializing SWD.
microbit-matt-hillsdon Mar 5, 2026
8c4ffa9
Error handling and logging review
microbit-matt-hillsdon Mar 5, 2026
dd0007d
Reorg the USB code including a layer split for the cmsis-dap code
microbit-matt-hillsdon Mar 5, 2026
c53d8c2
Deduplicate ABORT_ALL constant between cmsis-dap and arm-debug
microbit-matt-hillsdon Mar 5, 2026
a722189
Simplify device wrapper and clarify naming across USB and Bluetooth
microbit-matt-hillsdon Mar 5, 2026
4cf0934
Add test coverage extracting interfaces to support this
microbit-matt-hillsdon Mar 5, 2026
9c48307
Simplify the error handler
microbit-matt-hillsdon Mar 5, 2026
d239473
Saturate DAPLink CDC buffers before flash to prevent serial data loss
microbit-matt-hillsdon Mar 6, 2026
bcc6a86
Add a human-in-the-loop hardware test runner
microbit-matt-hillsdon Mar 6, 2026
55c1844
Merge pull request #110 from microbit-foundation/own-dap
microbit-matt-hillsdon Mar 6, 2026
e6efec5
Move DAPLink vendor commands and FICR constants to where they're used…
microbit-matt-hillsdon Mar 6, 2026
7eab3cc
Breaking: Reorganize into directory-based entrypoints
microbit-matt-hillsdon Mar 6, 2026
676d921
Rename DAPOperation to match the rest
microbit-matt-hillsdon Mar 6, 2026
cffcb03
Remove ChromeOS 105 WebUSB workaround
microbit-matt-hillsdon Mar 6, 2026
709e9eb
Breaking: Replace enums with as-const objects and union types
microbit-matt-hillsdon Mar 6, 2026
e037c2b
Breaking: Clean up public API surface
microbit-matt-hillsdon Mar 6, 2026
dbd14c2
Update README for recent API changes
microbit-matt-hillsdon Mar 6, 2026
129e9d9
Simplify code example
microbit-matt-hillsdon Mar 6, 2026
edc7274
Suppress serialreset when pausing USB connection on tab switch
microbit-matt-hillsdon Mar 6, 2026
64b165f
Fix UICR not updated during WebUSB partial flashing (#113)
microbit-matt-hillsdon Mar 7, 2026
0f8637b
Don't trigger knock-on errors in the tests
microbit-matt-hillsdon Mar 7, 2026
ab8c2b3
Merge branch 'apps' of github.com:microbit-foundation/microbit-connec…
microbit-matt-hillsdon Mar 9, 2026
e1d71c3
Add basic SSL so I can test cross platform
microbit-matt-hillsdon Mar 11, 2026
392686a
Breaking: rationalise DeviceErrorCode values and error handling (#114)
microbit-matt-hillsdon Mar 13, 2026
fcfded5
Merge the demo apps; rethink listener types
microbit-matt-hillsdon Mar 13, 2026
892d0de
Fix/test radio bridge
microbit-matt-hillsdon Mar 13, 2026
32819fc
Improve pain points in the demo: LED types, type narrowing
microbit-matt-hillsdon Mar 13, 2026
45166c6
Fix up references to old demo name
microbit-matt-hillsdon Mar 13, 2026
b61ae74
Audit fix
microbit-matt-hillsdon Mar 13, 2026
1bbab0b
Align radio bridge error handling
microbit-matt-hillsdon Mar 13, 2026
c982f7d
Renames for clarity
microbit-matt-hillsdon Mar 13, 2026
69d7ce7
Missing app files
microbit-matt-hillsdon Mar 14, 2026
281889f
Remove team info from demo
microbit-matt-hillsdon Mar 14, 2026
5635105
Merge pull request #115 from microbit-foundation/demo-apps
microbit-matt-hillsdon Mar 14, 2026
4a432d1
Fix TypeDoc entry points to match reorganized source structure (#116)
microbit-matt-hillsdon Mar 14, 2026
ef9a8f7
Simplify overloads for buttons
microbit-matt-hillsdon Mar 14, 2026
e5c6eae
Fall back to skipping hash when crypto.subtle is unavailable (#117)
microbit-matt-hillsdon Mar 17, 2026
a69b660
Add temperature, pin services (#122)
microbit-matt-hillsdon Mar 24, 2026
12ea250
Add event service for gestures, button/logo actions, and raw message …
microbit-matt-hillsdon Mar 27, 2026
b4bcc50
Migration notes (#125)
microbit-matt-hillsdon Apr 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ jobs:
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- uses: actions/setup-node@v4
with:
node-version: "24.x"
cache: npm
- run: npm ci
- name: Build docs
run: npm run docs
run: npm run docs -w @microbit/microbit-connection
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./docs/build
path: ./packages/microbit-connection/docs/build

deploy:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
if: false
permissions:
pages: write
id-token: write
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: 'https://registry.npmjs.org'
node-version: "24.x"
registry-url: "https://registry.npmjs.org"
cache: npm
- uses: microbit-foundation/npm-package-versioner-action@v1
with:
working-directory: packages/microbit-connection
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: npm run ci
- run: npm publish
- run: npm publish -w @microbit/microbit-connection --tag apps
if: github.event_name == 'release' && github.event.action == 'created'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ docs/build
*.sln
*.sw?

/build
build
*.tgz

# Hex files copied from top-level hex-files/ into app public dirs
apps/*/public/hex-files
27 changes: 0 additions & 27 deletions .npmignore

This file was deleted.

65 changes: 65 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# microbit-connection

TypeScript library for connecting to BBC micro:bit devices via USB and Bluetooth (BLE), including partial and full (DFU) flashing. Published as `@microbit/microbit-connection` on NPM. This branch is based off the "apps" branch where we've added Capacitor support for use in a mobile app and are making various other breaking changes that will end up as a v1.0.0 when the app is stable.

## Monorepo structure

npm workspaces monorepo:

- **`packages/microbit-connection/`** — The library. Dual ESM + CJS build.
- **`apps/demo/`** — Vite + React demo app with Capacitor support for mobile.
- **`third-party/`** — Vendored dependencies (patched dapjs).

## Commands

```
npm run build:lib # Build the library (ESM + CJS)
npm run build # Build everything (lib + demo)
npm run dev # Run demo app dev server
npm test # Run tests (vitest)
npm run format # Prettier format
npm run format:check # Prettier check
npm run docs # Generate TypeDoc docs
```

From the library package directory (`packages/microbit-connection/`):

- `npx vitest run` — Run tests once
- `npx vitest` — Run tests in watch mode

## Key source areas

The library source is in `packages/microbit-connection/src/`:

- **Connection types**: `usb.ts` (WebUSB), `bluetooth.ts` (Web Bluetooth), `usb-radio-bridge.ts` (radio bridge via USB)
- **Flashing**: `flashing/` directory — `flashing-partial.ts` (partial flash over BLE/USB), `flashing-full.ts` (full flash), `nordic-dfu.ts` (DFU via Capacitor plugin), `flashing-v1.ts` (V1-specific)
- **BLE services**: `accelerometer-service.ts`, `button-service.ts`, `uart-service.ts`, `led-service.ts`, `magnetometer-service.ts`, `dfu-service.ts`, `partial-flashing-service.ts`, `device-information-service.ts`
- **Shared**: `device.ts` (core types/interfaces), `events.ts` (typed event target), `bluetooth-profile.ts` (UUIDs), `board-id.ts`

## Architecture notes

- Factory functions (`createWebUSBConnection`, `createWebBluetoothConnection`, `createRadioBridgeConnection`) are the public API entry points
- Capacitor platform support: native BLE via `@capacitor-community/bluetooth-le`, native DFU via `@microbit/capacitor-community-nordic-dfu` (from `../nordic-dfu/`). These are peer dependencies.
- `Capacitor.isNativePlatform()` is used to branch between web and native code paths.

## Related projects

Note: these paths rely on an {org}/{repo} scheme for checkouts that might not hold for all developers. If projects are not available then ask the user.

### Capacitor plugins

- **`../nordic-dfu/`** — Capacitor plugin wrapping the Nordic DFU libraries (iOS: iOSDFULibrary, Android: Android-DFU-Library). The iOS plugin code (`ios/Plugin/Plugin.swift`) configures the DFU initiator.

### Native apps (reference implementations)

- **`../microbit-ios/`** — The official micro:bit iOS app. Its DFU flow in `Source/irmLink.m` (lines ~3810-3885) is the reference for how DFU should work on iOS. The bundled `Pods/iOSDFULibrary/` contains the iOS DFU library source, useful for understanding scan/reconnect behaviour.
- **`../microbit-android/`** — The official micro:bit Android app. Its DFU setup in `app/src/main/java/.../ProjectActivity.java` is the reference for Android DFU options.

### Firmware and bootloader

- **`../v2-bootloader/`** — micro:bit V2 bootloader. Key files:
- `bootloader/microbit/config/sdk_config.h` — build config (`NRF_DFU_BLE_REQUIRES_BONDS`, `NRF_DFU_BLE_ADV_NAME`)
- `nRF5SDK_mods/components/libraries/bootloader/ble_dfu/nrf_dfu_ble.c` — BLE transport with micro:bit-specific runtime patches (peer data validation, write permission downgrade, advertising name handling)
- `bootloader/main.c` — DFU observer and LED display symbols
- **`../../lancaster-university/codal-microbit-v2/`** — micro:bit V2 runtime (CODAL). BLE stack configuration in `source/bluetooth/MicroBitBLEManager.cpp`.
- **`../../lancaster-university/microbit-dal/`** — micro:bit V1 runtime (DAL).
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
Loading
Loading