summaryrefslogtreecommitdiff
path: root/src/Components
diff options
context:
space:
mode:
Diffstat (limited to 'src/Components')
-rw-r--r--src/Components/Ble/AlertNotificationClient.cpp2
-rw-r--r--src/Components/Ble/AlertNotificationService.cpp9
-rw-r--r--src/Components/Ble/CurrentTimeService.cpp5
-rw-r--r--src/Components/Ble/DeviceInformationService.cpp11
-rw-r--r--src/Components/Ble/DeviceInformationService.h21
-rw-r--r--src/Components/Ble/DfuService.cpp4
-rw-r--r--src/Components/Ble/MusicService.cpp129
-rw-r--r--src/Components/Ble/MusicService.h92
-rw-r--r--src/Components/Ble/NimbleController.cpp22
-rw-r--r--src/Components/Ble/NimbleController.h12
-rw-r--r--src/Components/FirmwareValidator/FirmwareValidator.cpp20
-rw-r--r--src/Components/FirmwareValidator/FirmwareValidator.h18
12 files changed, 317 insertions, 28 deletions
diff --git a/src/Components/Ble/AlertNotificationClient.cpp b/src/Components/Ble/AlertNotificationClient.cpp
index b65e019..3e4b495 100644
--- a/src/Components/Ble/AlertNotificationClient.cpp
+++ b/src/Components/Ble/AlertNotificationClient.cpp
@@ -116,7 +116,7 @@ void AlertNotificationClient::OnNotification(ble_gap_event *event) {
char *s = (char *) &data[3];
auto messageSize = min(maxMessageSize, (bufferSize-3));
- for (int i = 0; i < messageSize-1; i++) {
+ for (uint i = 0; i < messageSize-1; i++) {
if (s[i] == 0x00) {
s[i] = 0x0A;
}
diff --git a/src/Components/Ble/AlertNotificationService.cpp b/src/Components/Ble/AlertNotificationService.cpp
index 0faa17c..ce2f7dd 100644
--- a/src/Components/Ble/AlertNotificationService.cpp
+++ b/src/Components/Ble/AlertNotificationService.cpp
@@ -26,8 +26,8 @@ void AlertNotificationService::Init() {
ASSERT(res == 0);
}
-AlertNotificationService::AlertNotificationService ( Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NotificationManager& notificationManager ) : m_systemTask{systemTask}, m_notificationManager{notificationManager},
- characteristicDefinition{
+AlertNotificationService::AlertNotificationService ( System::SystemTask& systemTask, NotificationManager& notificationManager )
+ : characteristicDefinition{
{
.uuid = (ble_uuid_t *) &ansCharUuid,
.access_cb = AlertNotificationCallback,
@@ -48,8 +48,7 @@ AlertNotificationService::AlertNotificationService ( Pinetime::System::SystemTas
{
0
},
- }
-{
+ }, m_systemTask{systemTask}, m_notificationManager{notificationManager} {
}
int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle,
@@ -67,7 +66,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
char *s = (char *) &data[3];
auto messageSize = min(maxMessageSize, (bufferSize-3));
- for (int i = 0; i < messageSize-1; i++) {
+ for (uint i = 0; i < messageSize-1; i++) {
if (s[i] == 0x00) {
s[i] = 0x0A;
}
diff --git a/src/Components/Ble/CurrentTimeService.cpp b/src/Components/Ble/CurrentTimeService.cpp
index 80ad9c2..3a6264e 100644
--- a/src/Components/Ble/CurrentTimeService.cpp
+++ b/src/Components/Ble/CurrentTimeService.cpp
@@ -57,7 +57,7 @@ int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handl
return 0;
}
-CurrentTimeService::CurrentTimeService(DateTime &dateTimeController) : m_dateTimeController{dateTimeController},
+CurrentTimeService::CurrentTimeService(DateTime &dateTimeController) :
characteristicDefinition{
{
.uuid = (ble_uuid_t *) &ctChrUuid,
@@ -80,8 +80,7 @@ CurrentTimeService::CurrentTimeService(DateTime &dateTimeController) : m_dateTim
{
0
},
- }
- {
+ }, m_dateTimeController{dateTimeController} {
}
diff --git a/src/Components/Ble/DeviceInformationService.cpp b/src/Components/Ble/DeviceInformationService.cpp
index c1d5554..406db1c 100644
--- a/src/Components/Ble/DeviceInformationService.cpp
+++ b/src/Components/Ble/DeviceInformationService.cpp
@@ -8,6 +8,8 @@ constexpr ble_uuid16_t DeviceInformationService::serialNumberUuid;
constexpr ble_uuid16_t DeviceInformationService::fwRevisionUuid;
constexpr ble_uuid16_t DeviceInformationService::deviceInfoUuid;
constexpr ble_uuid16_t DeviceInformationService::hwRevisionUuid;
+constexpr ble_uuid16_t DeviceInformationService::swRevisionUuid;
+
int DeviceInformationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
auto deviceInformationService = static_cast<DeviceInformationService*>(arg);
@@ -44,6 +46,9 @@ int DeviceInformationService::OnDeviceInfoRequested(uint16_t conn_handle, uint16
case hwRevisionId:
str = hwRevision;
break;
+ case swRevisionId:
+ str = swRevision;
+ break;
default:
return BLE_ATT_ERR_UNLIKELY;
}
@@ -85,6 +90,12 @@ DeviceInformationService::DeviceInformationService() :
.flags = BLE_GATT_CHR_F_READ,
},
{
+ .uuid = (ble_uuid_t *) &swRevisionUuid,
+ .access_cb = DeviceInformationCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_READ,
+ },
+ {
0
}
},
diff --git a/src/Components/Ble/DeviceInformationService.h b/src/Components/Ble/DeviceInformationService.h
index d768da8..25ab840 100644
--- a/src/Components/Ble/DeviceInformationService.h
+++ b/src/Components/Ble/DeviceInformationService.h
@@ -3,6 +3,7 @@
#include <array>
#include <host/ble_gap.h>
+#include <Version.h>
namespace Pinetime {
namespace Controllers {
@@ -21,12 +22,15 @@ namespace Pinetime {
static constexpr uint16_t serialNumberId {0x2a25};
static constexpr uint16_t fwRevisionId {0x2a26};
static constexpr uint16_t hwRevisionId {0x2a27};
+ static constexpr uint16_t swRevisionId {0x2a28};
+
+ static constexpr const char* manufacturerName = "PINE64";
+ static constexpr const char* modelNumber = "PineTime";
+ static constexpr const char* hwRevision = "1.0.0";
+ static constexpr const char* serialNumber = "0";
+ static constexpr const char* fwRevision = Version::VersionString();
+ static constexpr const char* swRevision = "InfiniTime";
- static constexpr char* manufacturerName = "Codingfield";
- static constexpr char* modelNumber = "1";
- static constexpr char* serialNumber = "9.8.7.6.5.4";
- static constexpr char* fwRevision = "0.7.0";
- static constexpr char* hwRevision = "1.0.0";
static constexpr ble_uuid16_t deviceInfoUuid {
.u { .type = BLE_UUID_TYPE_16 },
@@ -58,7 +62,12 @@ namespace Pinetime {
.value = hwRevisionId
};
- struct ble_gatt_chr_def characteristicDefinition[6];
+ static constexpr ble_uuid16_t swRevisionUuid {
+ .u {.type = BLE_UUID_TYPE_16},
+ .value = swRevisionId
+ };
+
+ struct ble_gatt_chr_def characteristicDefinition[7];
struct ble_gatt_svc_def serviceDefinition[2];
diff --git a/src/Components/Ble/DfuService.cpp b/src/Components/Ble/DfuService.cpp
index c6d8493..fcbefdd 100644
--- a/src/Components/Ble/DfuService.cpp
+++ b/src/Components/Ble/DfuService.cpp
@@ -394,14 +394,14 @@ void DfuService::DfuImage::WriteMagicNumber() {
}
void DfuService::DfuImage::Erase() {
- for (int erased = 0; erased < maxSize; erased += 0x1000) {
+ for (size_t erased = 0; erased < maxSize; erased += 0x1000) {
spiNorFlash.SectorErase(writeOffset + erased);
}
}
bool DfuService::DfuImage::Validate() {
uint32_t chunkSize = 200;
- int currentOffset = 0;
+ size_t currentOffset = 0;
uint16_t crc = 0;
bool first = true;
diff --git a/src/Components/Ble/MusicService.cpp b/src/Components/Ble/MusicService.cpp
new file mode 100644
index 0000000..b5fa535
--- /dev/null
+++ b/src/Components/Ble/MusicService.cpp
@@ -0,0 +1,129 @@
+#include <SystemTask/SystemTask.h>
+#include "MusicService.h"
+
+int MSCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
+ auto musicService = static_cast<Pinetime::Controllers::MusicService*>(arg);
+ return musicService->OnCommand(conn_handle, attr_handle, ctxt);
+}
+
+Pinetime::Controllers::MusicService::MusicService(Pinetime::System::SystemTask &system) : m_system(system)
+{
+ msUuid.value[11] = msId[0];
+ msUuid.value[12] = msId[1];
+ msEventCharUuid.value[11] = msEventCharId[0];
+ msEventCharUuid.value[12] = msEventCharId[1];
+ msStatusCharUuid.value[11] = msStatusCharId[0];
+ msStatusCharUuid.value[12] = msStatusCharId[1];
+ msTrackCharUuid.value[11] = msTrackCharId[0];
+ msTrackCharUuid.value[12] = msTrackCharId[1];
+ msArtistCharUuid.value[11] = msArtistCharId[0];
+ msArtistCharUuid.value[12] = msArtistCharId[1];
+ msAlbumCharUuid.value[11] = msAlbumCharId[0];
+ msAlbumCharUuid.value[12] = msAlbumCharId[1];
+
+ characteristicDefinition[0] = { .uuid = (ble_uuid_t*)(&msEventCharUuid),
+ .access_cb = MSCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_NOTIFY,
+ .val_handle = &m_eventHandle
+ };
+ characteristicDefinition[1] = { .uuid = (ble_uuid_t*)(&msStatusCharUuid),
+ .access_cb = MSCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
+ };
+ characteristicDefinition[2] = { .uuid = (ble_uuid_t*)(&msTrackCharUuid),
+ .access_cb = MSCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
+ };
+ characteristicDefinition[3] = { .uuid = (ble_uuid_t*)(&msArtistCharUuid),
+ .access_cb = MSCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
+ };
+ characteristicDefinition[4] = { .uuid = (ble_uuid_t*)(&msAlbumCharUuid),
+ .access_cb = MSCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
+ };
+ characteristicDefinition[5] = {0};
+
+ serviceDefinition[0] = {
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid = (ble_uuid_t *) &msUuid,
+ .characteristics = characteristicDefinition
+ };
+ serviceDefinition[1] = {0};
+
+ m_artist = "Waiting for";
+ m_album = "";
+ m_track = "track information...";
+}
+
+void Pinetime::Controllers::MusicService::Init()
+{
+ int res = 0;
+ res = ble_gatts_count_cfg(serviceDefinition);
+ ASSERT(res == 0);
+
+ res = ble_gatts_add_svcs(serviceDefinition);
+ ASSERT(res == 0);
+}
+
+int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt) {
+
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
+ uint8_t data[notifSize + 1];
+ data[notifSize] = '\0';
+ os_mbuf_copydata(ctxt->om, 0, notifSize, data);
+ char *s = (char *) &data[0];
+ NRF_LOG_INFO("DATA : %s", s);
+ if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *)&msArtistCharUuid) == 0) {
+ m_artist = s;
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *)&msTrackCharUuid) == 0) {
+ m_track = s;
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *)&msAlbumCharUuid) == 0) {
+ m_album = s;
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t *)&msStatusCharUuid) == 0) {
+ m_status = s[0];
+ }
+ }
+ return 0;
+}
+
+std::string Pinetime::Controllers::MusicService::album()
+{
+ return m_album;
+}
+
+std::string Pinetime::Controllers::MusicService::artist()
+{
+ return m_artist;
+}
+
+std::string Pinetime::Controllers::MusicService::track()
+{
+ return m_track;
+}
+
+unsigned char Pinetime::Controllers::MusicService::status()
+{
+ return m_status;
+}
+
+void Pinetime::Controllers::MusicService::event(char event)
+{
+ auto *om = ble_hs_mbuf_from_flat(&event, 1);
+
+ uint16_t connectionHandle = m_system.nimble().connHandle();
+
+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
+ return;
+ }
+
+ ble_gattc_notify_custom(connectionHandle, m_eventHandle, om);
+}
+
diff --git a/src/Components/Ble/MusicService.h b/src/Components/Ble/MusicService.h
new file mode 100644
index 0000000..ab6db57
--- /dev/null
+++ b/src/Components/Ble/MusicService.h
@@ -0,0 +1,92 @@
+#pragma once
+
+#include <cstdint>
+#include <array>
+#include <host/ble_gap.h>
+#include <host/ble_uuid.h>
+#include <string>
+
+//c7e50000-78fc-48fe-8e23-43b37a1942d0
+#define MUSIC_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0xe5, 0xc7}
+
+namespace Pinetime {
+ namespace System {
+ class SystemTask;
+ }
+ namespace Controllers {
+
+ class MusicService {
+ public:
+ MusicService(Pinetime::System::SystemTask &system);
+ void Init();
+ int OnCommand(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt);
+
+ std::string artist();
+ std::string track();
+ std::string album();
+ unsigned char status();
+
+ void event(char event);
+
+ static const char EVENT_MUSIC_OPEN = 0xe0;
+ static const char EVENT_MUSIC_PLAY = 0x00;
+ static const char EVENT_MUSIC_PAUSE = 0x01;
+ static const char EVENT_MUSIC_NEXT = 0x03;
+ static const char EVENT_MUSIC_PREV = 0x04;
+ static const char EVENT_MUSIC_VOLUP = 0x05;
+ static const char EVENT_MUSIC_VOLDOWN = 0x06;
+ static const char STATUS_MUSIC_PAUSED = 0x00;
+ static const char STATUS_MUSIC_PLAYING = 0x01;
+
+ private:
+ static constexpr uint8_t msId[2] = {0x00, 0x01};
+ static constexpr uint8_t msEventCharId[2] = {0x00, 0x02};
+ static constexpr uint8_t msStatusCharId[2] = {0x00, 0x03};
+ static constexpr uint8_t msArtistCharId[2] = {0x00, 0x04};
+ static constexpr uint8_t msTrackCharId[2] = {0x00, 0x05};
+ static constexpr uint8_t msAlbumCharId[2] = {0x00, 0x06};
+
+ ble_uuid128_t msUuid {
+ .u = { .type = BLE_UUID_TYPE_128 },
+ .value = MUSIC_SERVICE_UUID_BASE
+ };
+
+ ble_uuid128_t msEventCharUuid {
+ .u = { .type = BLE_UUID_TYPE_128 },
+ .value = MUSIC_SERVICE_UUID_BASE
+ };
+ ble_uuid128_t msStatusCharUuid {
+ .u = { .type = BLE_UUID_TYPE_128 },
+ .value = MUSIC_SERVICE_UUID_BASE
+ };
+ ble_uuid128_t msArtistCharUuid {
+ .u = { .type = BLE_UUID_TYPE_128 },
+ .value = MUSIC_SERVICE_UUID_BASE
+ };
+ ble_uuid128_t msTrackCharUuid {
+ .u = { .type = BLE_UUID_TYPE_128 },
+ .value = MUSIC_SERVICE_UUID_BASE
+ };
+ ble_uuid128_t msAlbumCharUuid {
+ .u = { .type = BLE_UUID_TYPE_128 },
+ .value = MUSIC_SERVICE_UUID_BASE
+ };
+
+ struct ble_gatt_chr_def characteristicDefinition[6];
+ struct ble_gatt_svc_def serviceDefinition[2];
+
+ uint16_t m_eventHandle;
+
+ std::string m_artist;
+ std::string m_album;
+ std::string m_track;
+
+ unsigned char m_status;
+
+ Pinetime::System::SystemTask& m_system;
+
+ };
+ }
+}
+
diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp
index 561dbce..7dde9d0 100644
--- a/src/Components/Ble/NimbleController.cpp
+++ b/src/Components/Ble/NimbleController.cpp
@@ -6,6 +6,7 @@
#include <hal/nrf_rtc.h>
#include "NimbleController.h"
+#include "MusicService.h"
#include <services/gatt/ble_svc_gatt.h>
#include <services/gap/ble_svc_gap.h>
#include <host/util/util.h>
@@ -35,7 +36,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
currentTimeClient{dateTimeController},
anService{systemTask, notificationManager},
alertNotificationClient{systemTask, notificationManager},
- currentTimeService{dateTimeController} {
+ currentTimeService{dateTimeController},
+ musicService{systemTask} {
}
@@ -80,6 +82,7 @@ void NimbleController::Init() {
deviceInformationService.Init();
currentTimeClient.Init();
currentTimeService.Init();
+ musicService.Init();
anService.Init();
@@ -104,7 +107,7 @@ void NimbleController::Init() {
void NimbleController::StartAdvertising() {
if(ble_gap_adv_active()) return;
- ble_svc_gap_device_name_set("Pinetime-JF");
+ ble_svc_gap_device_name_set(deviceName);
/* set adv parameters */
struct ble_gap_adv_params adv_params;
@@ -132,18 +135,17 @@ void NimbleController::StartAdvertising() {
fields.uuids128_is_complete = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
- rsp_fields.name = (uint8_t *)"Pinetime-JF";
- rsp_fields.name_len = strlen("Pinetime-JF");
+ rsp_fields.name = (uint8_t *)deviceName;
+ rsp_fields.name_len = strlen(deviceName);
rsp_fields.name_is_complete = 1;
- int res;
- res = ble_gap_adv_set_fields(&fields);
+ ble_gap_adv_set_fields(&fields);
// ASSERT(res == 0); // TODO this one sometimes fails with error 22 (notsync)
- res = ble_gap_adv_rsp_set_fields(&rsp_fields);
+ ble_gap_adv_rsp_set_fields(&rsp_fields);
// ASSERT(res == 0);
- res = ble_gap_adv_start(addrType, NULL, 180000,
+ ble_gap_adv_start(addrType, NULL, 180000,
&adv_params, GAPEventCallback, this);
// ASSERT(res == 0);// TODO I've disabled these ASSERT as they sometime asserts and reset the mcu.
// For now, the advertising is restarted as soon as it ends. There may be a race condition
@@ -326,5 +328,7 @@ void NimbleController::StartDiscovery() {
}
-
+uint16_t NimbleController::connHandle() {
+ return connectionHandle;
+}
diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h
index cf50d78..50b8b0b 100644
--- a/src/Components/Ble/NimbleController.h
+++ b/src/Components/Ble/NimbleController.h
@@ -7,6 +7,7 @@
#include "CurrentTimeClient.h"
#include "DfuService.h"
#include "CurrentTimeService.h"
+#include "MusicService.h"
#include <host/ble_gap.h>
namespace Pinetime {
@@ -15,6 +16,7 @@ namespace Pinetime {
}
namespace Controllers {
class DateTime;
+
class NimbleController {
public:
@@ -35,8 +37,13 @@ namespace Pinetime {
uint16_t characteristicValueHandle, const ble_gatt_dsc *descriptor);
void StartDiscovery();
+
+ Pinetime::Controllers::MusicService& music() {return musicService;};
+
+ uint16_t connHandle();
+
private:
- static constexpr char* deviceName = "Pinetime-JF";
+ static constexpr const char* deviceName = "InfiniTime";
Pinetime::System::SystemTask& systemTask;
Pinetime::Controllers::Ble& bleController;
DateTime& dateTimeController;
@@ -49,9 +56,10 @@ namespace Pinetime {
AlertNotificationService anService;
AlertNotificationClient alertNotificationClient;
CurrentTimeService currentTimeService;
+ MusicService musicService;
uint8_t addrType; // 1 = Random, 0 = PUBLIC
- uint16_t connectionHandle;
+ uint16_t connectionHandle = 0;
ble_uuid128_t dfuServiceUuid {
.u { .type = BLE_UUID_TYPE_128},
diff --git a/src/Components/FirmwareValidator/FirmwareValidator.cpp b/src/Components/FirmwareValidator/FirmwareValidator.cpp
new file mode 100644
index 0000000..244d5c0
--- /dev/null
+++ b/src/Components/FirmwareValidator/FirmwareValidator.cpp
@@ -0,0 +1,20 @@
+#include <drivers/InternalFlash.h>
+#include <hal/nrf_rtc.h>
+
+#include "FirmwareValidator.h"
+
+using namespace Pinetime::Controllers;
+
+bool FirmwareValidator::IsValidated() const {
+ auto* imageOkPtr = reinterpret_cast<uint32_t *>(validBitAdress);
+ return (*imageOkPtr) == validBitValue;
+}
+
+void FirmwareValidator::Validate() {
+ if(!IsValidated())
+ Pinetime::Drivers::InternalFlash::WriteWord(validBitAdress, validBitValue);
+}
+
+void FirmwareValidator::Reset() {
+ NVIC_SystemReset();
+}
diff --git a/src/Components/FirmwareValidator/FirmwareValidator.h b/src/Components/FirmwareValidator/FirmwareValidator.h
new file mode 100644
index 0000000..aa576d8
--- /dev/null
+++ b/src/Components/FirmwareValidator/FirmwareValidator.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <cstdint>
+
+namespace Pinetime {
+ namespace Controllers {
+ class FirmwareValidator {
+ public:
+ void Validate();
+ bool IsValidated() const;
+
+ void Reset();
+ private:
+ static constexpr uint32_t validBitAdress {0x7BFE8};
+ static constexpr uint32_t validBitValue {1};
+ };
+ }
+}