Skip to content

Commit 84f98ae

Browse files
committed
Merge branch 'p8-acc-hfble' into p8b
2 parents a650728 + 7a67517 commit 84f98ae

File tree

16 files changed

+689
-109
lines changed

16 files changed

+689
-109
lines changed

src/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,11 @@ list(APPEND SOURCE_FILES
443443
drivers/DebugPins.cpp
444444
drivers/InternalFlash.cpp
445445
drivers/Hrs3300.cpp
446+
drivers/AccelerationSensor.cpp
446447
drivers/Bma421.cpp
447448
drivers/Bma421_C/bma4.c
448449
drivers/Bma421_C/bma423.c
450+
drivers/SC7A20.cpp
449451
components/battery/BatteryController.cpp
450452
components/ble/BleController.cpp
451453
components/ble/NotificationManager.cpp
@@ -510,9 +512,11 @@ list(APPEND RECOVERY_SOURCE_FILES
510512
drivers/DebugPins.cpp
511513
drivers/InternalFlash.cpp
512514
drivers/Hrs3300.cpp
515+
drivers/AccelerationSensor.cpp
513516
drivers/Bma421.cpp
514517
drivers/Bma421_C/bma4.c
515518
drivers/Bma421_C/bma423.c
519+
drivers/SC7A20.cpp
516520
components/battery/BatteryController.cpp
517521
components/ble/BleController.cpp
518522
components/ble/NotificationManager.cpp
@@ -626,9 +630,12 @@ set(INCLUDE_FILES
626630
drivers/InternalFlash.h
627631
drivers/Hrs3300.h
628632
drivers/PinMap.h
633+
drivers/AccelerationSensor.h
629634
drivers/Bma421.h
630635
drivers/Bma421_C/bma4.c
631636
drivers/Bma421_C/bma423.c
637+
drivers/SC7A20.h
638+
drivers/SC7A20_registers.h
632639
components/battery/BatteryController.h
633640
components/ble/BleController.h
634641
components/ble/NotificationManager.h
@@ -799,27 +806,32 @@ add_definitions(-DTARGET_DEVICE_NAME="${TARGET_DEVICE}")
799806
if(TARGET_DEVICE STREQUAL "PINETIME")
800807
add_definitions(-DDRIVER_PINMAP_PINETIME)
801808
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
809+
add_definitions(-DDRIVER_ACC_BMA421)
802810
add_definitions(-DDRIVER_TOUCH_DYNAMIC)
803811
elseif(TARGET_DEVICE STREQUAL "MOY-TFK5") # P8a
804812
add_definitions(-DDRIVER_PINMAP_P8)
805813
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
814+
add_definitions(-DDRIVER_ACC_BMA421)
806815
add_definitions(-DDRIVER_TOUCH_GESTURE)
807816
elseif(TARGET_DEVICE STREQUAL "MOY-TIN5") # P8a variant 2
808817
add_definitions(-DDRIVER_PINMAP_P8)
809818
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
819+
add_definitions(-DDRIVER_ACC_SC7A20)
810820
add_definitions(-DDRIVER_TOUCH_GESTURE)
811821
elseif(TARGET_DEVICE STREQUAL "MOY-TON5") # P8b
812822
add_definitions(-DDRIVER_PINMAP_P8)
813823
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
814824
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
815825
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
826+
add_definitions(-DDRIVER_ACC_SC7A20)
816827
add_definitions(-DDRIVER_TOUCH_REPORT)
817828
elseif(TARGET_DEVICE STREQUAL "MOY-UNK") # P8b mirrored
818829
add_definitions(-DDRIVER_PINMAP_P8)
819830
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
820831
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
821832
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
822833
add_definitions(-DDRIVER_DISPLAY_MIRROR)
834+
add_definitions(-DDRIVER_ACC_SC7A20)
823835
add_definitions(-DDRIVER_TOUCH_REPORT)
824836
else()
825837
message(FATAL_ERROR "Invalid TARGET_DEVICE")

src/components/ble/MotionService.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,22 @@ void MotionService::OnNewStepCountValue(uint32_t stepCount) {
9090

9191
ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
9292
}
93-
void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
93+
94+
void MotionService::OnNewMotionValues(int16_t* samples, uint16_t samples_length) {
9495
if (!motionValuesNoficationEnabled)
9596
return;
9697

97-
int16_t buffer[3] = {motionController.X(), motionController.Y(), motionController.Z()};
98-
auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t));
98+
if (samples_length > 0 && samples != nullptr) {
99+
auto* om = ble_hs_mbuf_from_flat(samples, samples_length * 3 * sizeof(int16_t));
99100

100-
uint16_t connectionHandle = system.nimble().connHandle();
101+
uint16_t connectionHandle = system.nimble().connHandle();
101102

102-
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
103-
return;
104-
}
103+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
104+
return;
105+
}
105106

106-
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
107+
ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
108+
}
107109
}
108110

109111
void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {

src/components/ble/MotionService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Pinetime {
1818
void Init();
1919
int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
2020
void OnNewStepCountValue(uint32_t stepCount);
21-
void OnNewMotionValues(int16_t x, int16_t y, int16_t z);
21+
void OnNewMotionValues(int16_t* samples, uint16_t samples_length);
2222

2323
void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
2424
void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);

src/components/motion/MotionController.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#include "os/os_cputime.h"
33
using namespace Pinetime::Controllers;
44

5-
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
5+
void MotionController::Update(uint32_t nbSteps, int16_t x, int16_t y, int16_t z, int16_t* samples, uint16_t samples_length) {
66
if (this->nbSteps != nbSteps && service != nullptr) {
77
service->OnNewStepCountValue(nbSteps);
88
}
99

1010
if (service != nullptr && (this->x != x || this->y != y || this->z != z)) {
11-
service->OnNewMotionValues(x, y, z);
11+
service->OnNewMotionValues(samples, samples_length);
1212
}
1313

1414
this->x = x;
@@ -62,26 +62,19 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
6262
lastZForShake = z;
6363
return wake;
6464
}
65+
6566
int32_t MotionController::currentShakeSpeed() {
6667
return accumulatedspeed;
6768
}
6869

6970
void MotionController::IsSensorOk(bool isOk) {
7071
isSensorOk = isOk;
7172
}
72-
void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
73-
switch (types) {
74-
case Drivers::Bma421::DeviceTypes::BMA421:
75-
this->deviceType = DeviceTypes::BMA421;
76-
break;
77-
case Drivers::Bma421::DeviceTypes::BMA425:
78-
this->deviceType = DeviceTypes::BMA425;
79-
break;
80-
default:
81-
this->deviceType = DeviceTypes::Unknown;
82-
break;
83-
}
73+
74+
void MotionController::Init(Pinetime::Drivers::AccelerationDeviceTypes types) {
75+
this->deviceType = types;
8476
}
77+
8578
void MotionController::SetService(Pinetime::Controllers::MotionService* service) {
8679
this->service = service;
8780
}

src/components/motion/MotionController.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ namespace Pinetime {
88
namespace Controllers {
99
class MotionController {
1010
public:
11-
enum class DeviceTypes {
12-
Unknown,
13-
BMA421,
14-
BMA425,
15-
};
16-
17-
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
11+
void Update(uint32_t nbSteps, int16_t x, int16_t y, int16_t z, int16_t* samples, uint16_t samples_length);
1812

1913
int16_t X() const {
2014
return x;
@@ -44,11 +38,11 @@ namespace Pinetime {
4438
return isSensorOk;
4539
}
4640

47-
DeviceTypes DeviceType() const {
41+
Pinetime::Drivers::AccelerationDeviceTypes DeviceType() const {
4842
return deviceType;
4943
}
5044

51-
void Init(Pinetime::Drivers::Bma421::DeviceTypes types);
45+
void Init(Pinetime::Drivers::AccelerationDeviceTypes types);
5246
void SetService(Pinetime::Controllers::MotionService* service);
5347

5448
private:
@@ -59,7 +53,7 @@ namespace Pinetime {
5953
int16_t z;
6054
int16_t lastYForWakeUp = 0;
6155
bool isSensorOk = false;
62-
DeviceTypes deviceType = DeviceTypes::Unknown;
56+
Pinetime::Drivers::AccelerationDeviceTypes deviceType = Pinetime::Drivers::AccelerationDeviceTypes::Unknown;
6357
Pinetime::Controllers::MotionService* service = nullptr;
6458

6559
int16_t lastXForShake = 0;

src/displayapp/screens/SystemInfo.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
using namespace Pinetime::Applications::Screens;
1818

1919
namespace {
20-
const char* ToString(const Pinetime::Controllers::MotionController::DeviceTypes deviceType) {
20+
const char* ToString(const Pinetime::Drivers::AccelerationDeviceTypes deviceType) {
2121
switch (deviceType) {
22-
case Pinetime::Controllers::MotionController::DeviceTypes::BMA421:
22+
case Pinetime::Drivers::AccelerationDeviceTypes::BMA421:
2323
return "BMA421";
24-
case Pinetime::Controllers::MotionController::DeviceTypes::BMA425:
24+
case Pinetime::Drivers::AccelerationDeviceTypes::BMA425:
2525
return "BMA425";
26-
case Pinetime::Controllers::MotionController::DeviceTypes::Unknown:
26+
case Pinetime::Drivers::AccelerationDeviceTypes::SC7A20:
27+
return "SC7A20";
28+
case Pinetime::Drivers::AccelerationDeviceTypes::Unknown:
2729
return "???";
2830
}
2931
return "???";

src/drivers/AccelerationSensor.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "AccelerationSensor.h"
2+
3+
namespace Pinetime {
4+
namespace Drivers {
5+
6+
AccelerationSensor::AccelerationSensor(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster(twiMaster), deviceAddress(twiAddress) {
7+
}
8+
9+
void AccelerationSensor::SoftReset() {
10+
}
11+
12+
void AccelerationSensor::Init() {
13+
}
14+
15+
AccelerationValues AccelerationSensor::Process() {
16+
return {0};
17+
}
18+
19+
void AccelerationSensor::ResetStepCounter() {
20+
}
21+
22+
void AccelerationSensor::Read(uint8_t registerAddress, uint8_t* buffer, size_t size) {
23+
twiMaster.Read(deviceAddress, registerAddress, buffer, size);
24+
}
25+
26+
void AccelerationSensor::Write(uint8_t registerAddress, const uint8_t* data, size_t size) {
27+
twiMaster.Write(deviceAddress, registerAddress, data, size);
28+
}
29+
30+
AccelerationDeviceTypes AccelerationSensor::DeviceType() const {
31+
return deviceType;
32+
}
33+
34+
bool AccelerationSensor::IsInitialized() const {
35+
return isInitialized;
36+
}
37+
38+
}
39+
}

src/drivers/AccelerationSensor.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include "drivers/TwiMaster.h"
4+
5+
namespace Pinetime {
6+
namespace Drivers {
7+
8+
enum class AccelerationDeviceTypes : uint8_t { Unknown, BMA421, BMA425, SC7A20 };
9+
10+
struct AccelerationValues {
11+
uint32_t steps;
12+
int16_t x;
13+
int16_t y;
14+
int16_t z;
15+
int16_t* samples = nullptr;
16+
uint16_t samples_length = 0;
17+
};
18+
19+
class AccelerationSensor {
20+
public:
21+
AccelerationSensor(TwiMaster& twiMaster, uint8_t twiAddress);
22+
AccelerationSensor(const AccelerationSensor&) = delete;
23+
AccelerationSensor& operator=(const AccelerationSensor&) = delete;
24+
AccelerationSensor(AccelerationSensor&&) = delete;
25+
AccelerationSensor& operator=(AccelerationSensor&&) = delete;
26+
27+
virtual void SoftReset();
28+
virtual void Init();
29+
virtual AccelerationValues Process();
30+
virtual void ResetStepCounter();
31+
32+
void Read(uint8_t registerAddress, uint8_t* buffer, size_t size);
33+
void Write(uint8_t registerAddress, const uint8_t* data, size_t size);
34+
35+
bool IsInitialized() const;
36+
AccelerationDeviceTypes DeviceType() const;
37+
38+
protected:
39+
TwiMaster& twiMaster;
40+
uint8_t deviceAddress;
41+
bool isInitialized = false;
42+
AccelerationDeviceTypes deviceType = AccelerationDeviceTypes::Unknown;
43+
int16_t fifo[32][3] = {0};
44+
};
45+
46+
}
47+
}

0 commit comments

Comments
 (0)