Skip to content

Commit 9d7955b

Browse files
JF002Gitea
authored andcommitted
Merge branch 'develop' of JF/PineTime into master
2 parents f534fb0 + 324c7da commit 9d7955b

33 files changed

+959
-506
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(pinetime VERSION 0.12.1 LANGUAGES C CXX ASM)
2+
project(pinetime VERSION 0.13.0 LANGUAGES C CXX ASM)
33

44
set(NRF_TARGET "nrf52")
55

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RUN apt-get update -qq \
2121
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/*;
2222

2323
RUN pip3 install adafruit-nrfutil
24+
RUN pip3 install -Iv cryptography==3.3
2425

2526
# build.sh knows how to compile
2627
COPY build.sh /opt/

src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ set(SDK_SOURCE_FILES
3636
# Base SDK
3737
"${NRF5_SDK_PATH}/components/boards/boards.c"
3838
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.c"
39+
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.h"
3940
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_clock.c"
4041
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_gpiote.c"
4142
"${NRF5_SDK_PATH}/modules/nrfx/soc/nrfx_atomic.c"
4243
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_saadc.c"
44+
"${NRF5_SDK_PATH}/components/libraries/timer/app_timer.h"
4345

4446
# FreeRTOS
4547
${NRF5_SDK_PATH}/external/freertos/source/croutine.c
@@ -426,7 +428,6 @@ list(APPEND SOURCE_FILES
426428
displayapp/screens/InfiniPaint.cpp
427429
displayapp/screens/Paddle.cpp
428430
displayapp/screens/DropDownDemo.cpp
429-
displayapp/screens/Modal.cpp
430431
displayapp/screens/BatteryIcon.cpp
431432
displayapp/screens/BleIcon.cpp
432433
displayapp/screens/NotificationIcon.cpp
@@ -469,6 +470,7 @@ list(APPEND SOURCE_FILES
469470
components/ble/ServiceDiscovery.cpp
470471
components/ble/HeartRateService.cpp
471472
components/firmwarevalidator/FirmwareValidator.cpp
473+
components/motor/MotorController.cpp
472474
drivers/Cst816s.cpp
473475
FreeRTOS/port.c
474476
FreeRTOS/port_cmsis_systick.c
@@ -520,7 +522,6 @@ set(INCLUDE_FILES
520522
displayapp/screens/InfiniPaint.h
521523
displayapp/screens/Paddle.h
522524
displayapp/screens/DropDownDemo.h
523-
displayapp/screens/Modal.h
524525
displayapp/screens/BatteryIcon.h
525526
displayapp/screens/BleIcon.h
526527
displayapp/screens/NotificationIcon.h
@@ -579,6 +580,7 @@ set(INCLUDE_FILES
579580
components/heartrate/Biquad.h
580581
components/heartrate/Ptagc.h
581582
components/heartrate/HeartRateController.h
583+
components/motor/MotorController.h
582584
)
583585

584586
include_directories(

src/FreeRTOS/port_cmsis.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,24 @@ static void vPortEnableVFP( void )
354354
configASSERT( NVIC_GetPriorityGrouping() <= ulMaxPRIGROUPValue );
355355
}
356356

357+
uint32_t ulSetInterruptMaskFromISR( void )
358+
{
359+
__asm volatile (
360+
" mrs r0, PRIMASK \n"
361+
" cpsid i \n"
362+
" bx lr "
363+
::: "memory"
364+
);
365+
}
366+
/*-----------------------------------------------------------*/
367+
368+
void vClearInterruptMaskFromISR( __attribute__( ( unused ) ) uint32_t ulMask )
369+
{
370+
__asm volatile (
371+
" msr PRIMASK, r0 \n"
372+
" bx lr "
373+
::: "memory"
374+
);
375+
}
376+
357377
#endif /* configASSERT_DEFINED */

src/FreeRTOS/portmacro_cmsis.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ typedef unsigned long UBaseType_t;
104104
/* Critical section management. */
105105
extern void vPortEnterCritical( void );
106106
extern void vPortExitCritical( void );
107-
#define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
108-
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
107+
extern uint32_t ulSetInterruptMaskFromISR( void ) __attribute__( ( naked ) );
108+
extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__( ( naked ) );
109+
#define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR()
110+
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vClearInterruptMaskFromISR( x )
109111
#define portDISABLE_INTERRUPTS() __asm volatile ( " cpsid i " ::: "memory" )
110112
#define portENABLE_INTERRUPTS() __asm volatile ( " cpsie i " ::: "memory" )
111113
#define portENTER_CRITICAL() vPortEnterCritical()

src/components/ble/AlertNotificationClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ namespace Pinetime {
8383
bool isDescriptorFound = false;
8484
};
8585
}
86-
}
86+
}

src/components/ble/AlertNotificationService.cpp

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using namespace Pinetime::Controllers;
99

1010
constexpr ble_uuid16_t AlertNotificationService::ansUuid;
1111
constexpr ble_uuid16_t AlertNotificationService::ansCharUuid;
12+
constexpr ble_uuid128_t AlertNotificationService::notificationEventUuid;
1213

1314

1415
int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
@@ -33,6 +34,13 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT
3334
.arg = this,
3435
.flags = BLE_GATT_CHR_F_WRITE
3536
},
37+
{
38+
.uuid = (ble_uuid_t *) &notificationEventUuid,
39+
.access_cb = AlertNotificationCallback,
40+
.arg = this,
41+
.flags = BLE_GATT_CHR_F_NOTIFY,
42+
.val_handle = &eventHandle
43+
},
3644
{
3745
0
3846
}
@@ -61,14 +69,65 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
6169
const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om);
6270
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
6371
auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
72+
Categories category;
6473

6574
NotificationManager::Notification notif;
6675
os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
76+
os_mbuf_copydata(ctxt->om, 0, 1, &category);
6777
notif.message[messageSize-1] = '\0';
68-
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
69-
notificationManager.Push(std::move(notif));
7078

71-
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
79+
// TODO convert all ANS categories to NotificationController categories
80+
switch(category) {
81+
case Categories::Call:
82+
notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall;
83+
break;
84+
default:
85+
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
86+
break;
87+
}
88+
89+
auto event = Pinetime::System::SystemTask::Messages::OnNewNotification;
90+
notificationManager.Push(std::move(notif));
91+
systemTask.PushMessage(event);
7292
}
7393
return 0;
7494
}
95+
96+
void AlertNotificationService::AcceptIncomingCall() {
97+
auto response = IncomingCallResponses::Answer;
98+
auto *om = ble_hs_mbuf_from_flat(&response, 1);
99+
100+
uint16_t connectionHandle = systemTask.nimble().connHandle();
101+
102+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
103+
return;
104+
}
105+
106+
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
107+
}
108+
109+
void AlertNotificationService::RejectIncomingCall() {
110+
auto response = IncomingCallResponses::Reject;
111+
auto *om = ble_hs_mbuf_from_flat(&response, 1);
112+
113+
uint16_t connectionHandle = systemTask.nimble().connHandle();
114+
115+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
116+
return;
117+
}
118+
119+
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
120+
}
121+
122+
void AlertNotificationService::MuteIncomingCall() {
123+
auto response = IncomingCallResponses::Mute;
124+
auto *om = ble_hs_mbuf_from_flat(&response, 1);
125+
126+
uint16_t connectionHandle = systemTask.nimble().connHandle();
127+
128+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
129+
return;
130+
}
131+
132+
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
133+
}

src/components/ble/AlertNotificationService.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#undef max
88
#undef min
99

10+
//00020001-78fc-48fe-8e23-433b3a1942d0
11+
#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x01, 0x00, 0x02, 0x00}
12+
1013
namespace Pinetime {
1114

1215
namespace System {
@@ -24,8 +27,31 @@ namespace Pinetime {
2427
int OnAlert(uint16_t conn_handle, uint16_t attr_handle,
2528
struct ble_gatt_access_ctxt *ctxt);
2629

30+
void AcceptIncomingCall();
31+
void RejectIncomingCall();
32+
void MuteIncomingCall();
33+
34+
enum class IncomingCallResponses : uint8_t {
35+
Reject = 0x00,
36+
Answer = 0x01,
37+
Mute = 0x02
38+
};
2739

2840
private:
41+
enum class Categories : uint8_t {
42+
SimpleAlert = 0x00,
43+
Email = 0x01,
44+
News = 0x02,
45+
Call = 0x03,
46+
MissedCall = 0x04,
47+
MmsSms = 0x05,
48+
VoiceMail = 0x06,
49+
Schedule = 0x07,
50+
HighPrioritizedAlert = 0x08,
51+
InstantMessage = 0x09,
52+
All = 0xff
53+
};
54+
2955
static constexpr uint16_t ansId {0x1811};
3056
static constexpr uint16_t ansCharId {0x2a46};
3157

@@ -39,11 +65,18 @@ namespace Pinetime {
3965
.value = ansCharId
4066
};
4167

42-
struct ble_gatt_chr_def characteristicDefinition[2];
68+
static constexpr ble_uuid128_t notificationEventUuid {
69+
.u { .type = BLE_UUID_TYPE_128 },
70+
.value = NOTIFICATION_EVENT_SERVICE_UUID_BASE
71+
};
72+
73+
struct ble_gatt_chr_def characteristicDefinition[3];
4374
struct ble_gatt_svc_def serviceDefinition[2];
4475

4576
Pinetime::System::SystemTask &systemTask;
4677
NotificationManager &notificationManager;
78+
79+
uint16_t eventHandle;
4780
};
4881
}
4982
}

src/components/ble/HeartRateService.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ void HeartRateService::Init() {
5757
int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle,
5858
ble_gatt_access_ctxt *context) {
5959
if(attributeHandle == heartRateMeasurementHandle) {
60-
NRF_LOG_INFO("BATTERY : handle = %d", heartRateMeasurementHandle);
61-
static uint8_t batteryValue = heartRateController.HeartRate();
62-
60+
NRF_LOG_INFO("HEARTRATE : handle = %d", heartRateMeasurementHandle);
6361
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
6462

6563
int res = os_mbuf_append(context->om, buffer, 2);

src/components/ble/NimbleController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
3838
navService{systemTask},
3939
batteryInformationService{batteryController},
4040
immediateAlertService{systemTask, notificationManager},
41-
serviceDiscovery({&currentTimeClient, &alertNotificationClient}),
42-
heartRateService{systemTask, heartRateController} {
41+
heartRateService{systemTask, heartRateController},
42+
serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {
4343
}
4444

4545
int GAPEventCallback(struct ble_gap_event *event, void *arg) {

0 commit comments

Comments
 (0)