Skip to content

Commit 86d5732

Browse files
JF002Gitea
authored andcommitted
Merge branch 'develop' of JF/PineTime into master
2 parents a91c68c + 6e1bd11 commit 86d5732

96 files changed

Lines changed: 2697 additions & 183 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ I've tested this project on the actual PineTime hardware.
2929
* SPI (DMA & IRQ based) LCD driver;
3030
* BLE advertising, connection and bonding;
3131
* BLE CTS client (retrieves the time from the connected device if it implements a CTS server);
32-
* Push button to go to disable screen (and go to low power mode) / enable screen (and wake-up);
32+
* Push button to go to disable screen (and go to low power mode) / enable screen (and wake-up) and UI navigation
3333
* Touch panel support;
34-
* Basic user interface via display, touchpanel and push button.
35-
* Digital watch face and 4 demo applications (spinning meter, analog gauche, push button and message box);
34+
* Rich user interface (using [LittleVGL](https://littlevgl.com/)) via display, touchpanel and push button.
35+
* Digital watch face and 4 demo applications (spinning meter, analog gauche, push button and message box);
36+
* Watchdog (automatic reset in case of firmware crash) and reset support (push and hold the button for 7 - 10s);
37+
* BLE Notification support (still Work-In-Progress, [companion app](https://github.com/JF002/gobbledegook) needed).
38+
39+
## Documentation
40+
41+
* [BLE implementation and API](./doc/ble.md)
3642

3743
## Stub using NRF52-DK
3844
![Pinetime stub](./images/pinetimestub1.jpg "PinetimeStub")
@@ -206,6 +212,7 @@ $ JLinkRTTClient
206212
At runtime, BLE advertising is started. You can then use a smartphone or computer to connect and bond to your Pinetime.
207213
As soon as a device is bonded, Pinetime will look for a **CTS** server (**C**urrent **T**ime **S**ervice) on the connected device.
208214

215+
### Using Android and NRFConnect
209216
Here is how to do it with an Android smartphone running NRFConnect:
210217

211218
* Build and program the firmware on the Pinetime
@@ -217,4 +224,33 @@ Here is how to do it with an Android smartphone running NRFConnect:
217224
* Go back to the main screen and scan for BLE devices. A device called "PineTime" should appear
218225
* Tap the button "Connect" next to the PineTime device. It should connect to the PineTime and switch to a new tab.
219226
* On this tab, on the top right, there is a 3 dots button. Tap on it and select Bond. The bonding process begins, and if it is sucessful, the PineTime should update its time and display it on the screen.
220-
227+
228+
### Using Linux and bluetoothctl
229+
* Ensure that your bluetooth controller is enabled and working fine. I've tested this on a x86 Debian computer and on a RaspberryPi 3.
230+
* Run bluetoothctl as root : `sudo bluetoothctl`
231+
* Enter the following commands:
232+
* `scan on` and wait for you Pinetime to be detected. Note the BLE MAC address
233+
* `scan off'
234+
* `trust <MAC ADDRESS>`
235+
* `pair <MAC ADDRESS>`
236+
* Wait for some time, and the connection should be established.
237+
238+
**NOTE : ** The commands above establish a BLE connection between your PC, but the time synchronization and notifications won't work because there is not CTS or ANS server running. I'm currently working on an application that'll provide both of these servers.
239+
240+
### Troubleshooting
241+
If the connection cannot be established, or the time synchronization does not work, try the following steps.
242+
243+
On Android:
244+
* Disable and re-enable your bluetooth device
245+
* In NRFConnect, in the device tab corresponding to your pinetime, tap on the menu on the top left of the screen and select "Delete bond information".
246+
* Then re-try to bond/connect.
247+
248+
On Linux:
249+
* Reset the bluetooth device : `sudo hciconfig hci0 reset`
250+
* Restart the Bluetooth service : `sudo systemctl restart bluetooth.service`
251+
* In bluetootctl:
252+
* `remove <MAC ADDRESS>`
253+
* `trust <MAC ADDRESS>`
254+
* `pair <MAC ADDRESS>`
255+
256+
Note that the current firmware only advertise for the first 3 minutes. If you cannot connect after more than 3 minutes, try resetting the device (push the button and hold it for 7-10 seconds).

cmake-nRF5x/CMake_nRF5x.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ macro(nRF5x_setup)
260260
list(APPEND SDK_SOURCE_FILES
261261
"${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c"
262262
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_cts_c/ble_cts_c.c"
263-
"${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c"
263+
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_ans_c/ble_ans_c.c"
264+
# "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c"
264265
)
265266

266267
#BLE S132

doc/ble.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Bluetooth Low-Energy :
2+
## Introduction
3+
This page describes the BLE implementation and API built in this firmware.
4+
5+
**Note** : I'm a beginner in BLE related technologies and the information of this document reflect my current knowledge and understanding of the BLE stack. These informations might be erroneous or incomplete. Feel free to submit a PR if you think you can improve these.
6+
7+
## BLE Connection
8+
When starting the firmware start a BLE advertising : it send small messages that can be received by any *central* device in range. This allows the device to announce its presence to other devices.
9+
10+
A companion application (running on a PC, RasberryPi, smartphone) which received this avertising packet can request a connection to the device. This connection procedure allows the 2 devices to negociate communication parameters, security keys,...
11+
12+
When the connection is established, the pinetime will try to discover services running on the companion application. For now **CTS** (**C**urrent **T**ime **S**ervice) and **ANS** (**A**lert **N**otification **S**ervice) are supported.
13+
14+
If **CTS** is detected, it'll request the current time to the companion application. If **ANS** is detected, it will listen to new notifications coming from the companion application.
15+
16+
![BLE connection sequence diagram](ble/connection_sequence.png "BLE connection sequence diagram")
17+
18+
## BLE services
19+
[List of standard BLE services](https://www.bluetooth.com/specifications/gatt/services/)
20+
21+
### CTS
22+
[Current Time Service](https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org.bluetooth.service.alert_notification.xml)
23+
24+
### ANS
25+
[Alert Notification Service](https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org.bluetooth.service.current_time.xml)
26+
27+
![ANS sequence diagram](./ble/ans_sequence.png "ANS sequence diagram")

doc/ble/ans_sequence.png

35.7 KB
Loading

doc/ble/ans_sequence.puml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@startuml
2+
group Get configuration from server
3+
Pinetime -> CompanionApp : Read request (Supported 'new' notification categories - 0x2A47)
4+
CompanionApp --> Pinetime: Response (0xff = all categories)
5+
6+
Pinetime -> CompanionApp : Read request (Supported 'unread' notification categories - 0x2A48)
7+
CompanionApp --> Pinetime: Response (0xff = all categories)
8+
end
9+
10+
group Configure the server
11+
Pinetime -> CompanionApp : Configure 'new' notifications categories : Accept all (Write [0, 0xFF] to Control Point - 0x2A44)
12+
activate CompanionApp
13+
deactivate CompanionApp
14+
Pinetime -> CompanionApp : Configure 'unread' notifications categories : Accept all (Write [1, 0xFF] to Control Point - 0x2A44)
15+
activate CompanionApp
16+
deactivate CompanionApp
17+
end
18+
19+
group Server sends a notification
20+
CompanionApp -> Pinetime : Notify new_alert (0x2A46)
21+
activate Pinetime
22+
note over Pinetime
23+
Pinetime FW handles the
24+
notification (display on UI)
25+
end note
26+
deactivate Pinetime
27+
end
28+
29+
@enduml

doc/ble/connection_sequence.png

17.5 KB
Loading

doc/ble/connection_sequence.puml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@startuml
2+
Pinetime --> CompanionApp: Start advertising
3+
4+
group BLE Connection
5+
CompanionApp -> Pinetime: Connection request
6+
CompanionApp <-> Pinetime: Connection parameters negociation, security procedure,...
7+
end
8+
9+
group Service Discovery
10+
CompanionApp <-> Pinetime: Discover service 0x1805 (CTS)
11+
CompanionApp <-> Pinetime: Discover service 0x1811 (ANS)
12+
end
13+
14+
@enduml

0 commit comments

Comments
 (0)