Skip to content

Commit b2f7f25

Browse files
committed
Merge branch 'p8-acc' into p8b
2 parents 11a5d41 + 9751693 commit b2f7f25

File tree

15 files changed

+673
-90
lines changed

15 files changed

+673
-90
lines changed

doc/buildAndProgram.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CMake configures the project according to variables you specify the command line
3939
**GDB_CLIENT_BIN_PATH**|Path to arm-none-eabi-gdb executable. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_BIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gdb`
4040
**GDB_CLIENT_TARGET_REMOTE**|Target remote connection string. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_TARGET_REMOTE=/dev/ttyACM0`
4141
**BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1`
42-
**TARGET_DEVICE**|Target device, used for the pin map and the low frequency clock source, and the touch driver behavior. Allowed: `PINETIME, MOY-TFK5, MOY-TIN5,MOY-TON5, MOY-UNK`|`-DTARGET_DEVICE=PINETIME` (Default)
42+
**TARGET_DEVICE**|Target device, used for the pin map and the low frequency clock source, the touch driver behavior, and the acceleration driver selection. Allowed: `PINETIME, MOY-TFK5, MOY-TIN5,MOY-TON5, MOY-UNK`|`-DTARGET_DEVICE=PINETIME` (Default)
4343
4444
####(**) Note about **CMAKE_BUILD_TYPE**:
4545
By default, this variable is set to *Release*. It compiles the code with size and speed optimizations. We use this value for all the binaries we publish when we [release](https://github.com/InfiniTimeOrg/InfiniTime/releases) new versions of InfiniTime.

src/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,11 @@ list(APPEND SOURCE_FILES
438438
drivers/DebugPins.cpp
439439
drivers/InternalFlash.cpp
440440
drivers/Hrs3300.cpp
441+
drivers/AccelerationSensor.cpp
441442
drivers/Bma421.cpp
442443
drivers/Bma421_C/bma4.c
443444
drivers/Bma421_C/bma423.c
445+
drivers/SC7A20.cpp
444446
components/battery/BatteryController.cpp
445447
components/ble/BleController.cpp
446448
components/ble/NotificationManager.cpp
@@ -505,9 +507,11 @@ list(APPEND RECOVERY_SOURCE_FILES
505507
drivers/DebugPins.cpp
506508
drivers/InternalFlash.cpp
507509
drivers/Hrs3300.cpp
510+
drivers/AccelerationSensor.cpp
508511
drivers/Bma421.cpp
509512
drivers/Bma421_C/bma4.c
510513
drivers/Bma421_C/bma423.c
514+
drivers/SC7A20.cpp
511515
components/battery/BatteryController.cpp
512516
components/ble/BleController.cpp
513517
components/ble/NotificationManager.cpp
@@ -618,9 +622,12 @@ set(INCLUDE_FILES
618622
drivers/InternalFlash.h
619623
drivers/Hrs3300.h
620624
drivers/PinMap.h
625+
drivers/AccelerationSensor.h
621626
drivers/Bma421.h
622627
drivers/Bma421_C/bma4.c
623628
drivers/Bma421_C/bma423.c
629+
drivers/SC7A20.h
630+
drivers/SC7A20_registers.h
624631
components/battery/BatteryController.h
625632
components/ble/BleController.h
626633
components/ble/NotificationManager.h
@@ -791,26 +798,31 @@ if(TARGET_DEVICE STREQUAL "PINETIME")
791798
add_definitions(-DDRIVER_PINMAP_PINETIME)
792799
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
793800
add_definitions(-DDRIVER_TOUCH_DYNAMIC)
801+
add_definitions(-DDRIVER_ACC_BMA421)
794802
elseif(TARGET_DEVICE STREQUAL "MOY-TFK5") # P8a
795803
add_definitions(-DDRIVER_PINMAP_P8)
796804
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
797805
add_definitions(-DDRIVER_TOUCH_GESTURE)
806+
add_definitions(-DDRIVER_ACC_BMA421)
798807
elseif(TARGET_DEVICE STREQUAL "MOY-TIN5") # P8a variant 2
799808
add_definitions(-DDRIVER_PINMAP_P8)
800809
add_definitions(-DCLOCK_CONFIG_LF_SRC=1) # XTAL
801810
add_definitions(-DDRIVER_TOUCH_GESTURE)
811+
add_definitions(-DDRIVER_ACC_SC7A20)
802812
elseif(TARGET_DEVICE STREQUAL "MOY-TON5") # P8b
803813
add_definitions(-DDRIVER_PINMAP_P8)
804814
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
805815
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
806816
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
807817
add_definitions(-DDRIVER_TOUCH_REPORT)
818+
add_definitions(-DDRIVER_ACC_SC7A20)
808819
elseif(TARGET_DEVICE STREQUAL "MOY-UNK") # P8b mirrored
809820
add_definitions(-DDRIVER_PINMAP_P8)
810821
add_definitions(-DCLOCK_CONFIG_LF_SRC=0) # RC
811822
add_definitions(-DMYNEWT_VAL_BLE_LL_SCA=500)
812823
add_definitions(-DCLOCK_CONFIG_LF_CAL_ENABLED=1)
813824
add_definitions(-DDRIVER_TOUCH_REPORT)
825+
add_definitions(-DDRIVER_ACC_SC7A20)
814826
else()
815827
message(FATAL_ERROR "Invalid TARGET_DEVICE")
816828
endif()

src/components/motion/MotionController.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ namespace Pinetime {
88
namespace Controllers {
99
class MotionController {
1010
public:
11-
enum class DeviceTypes {
12-
Unknown,
13-
BMA421,
14-
BMA425,
15-
};
16-
1711
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
1812

1913
int16_t X() const {
@@ -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
@@ -16,13 +16,15 @@
1616
using namespace Pinetime::Applications::Screens;
1717

1818
namespace {
19-
const char* ToString(const Pinetime::Controllers::MotionController::DeviceTypes deviceType) {
19+
const char* ToString(const Pinetime::Drivers::AccelerationDeviceTypes deviceType) {
2020
switch (deviceType) {
21-
case Pinetime::Controllers::MotionController::DeviceTypes::BMA421:
21+
case Pinetime::Drivers::AccelerationDeviceTypes::BMA421:
2222
return "BMA421";
23-
case Pinetime::Controllers::MotionController::DeviceTypes::BMA425:
23+
case Pinetime::Drivers::AccelerationDeviceTypes::BMA425:
2424
return "BMA425";
25-
case Pinetime::Controllers::MotionController::DeviceTypes::Unknown:
25+
case Pinetime::Drivers::AccelerationDeviceTypes::SC7A20:
26+
return "SC7A20";
27+
case Pinetime::Drivers::AccelerationDeviceTypes::Unknown:
2628
return "???";
2729
}
2830
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+
}

src/drivers/Bma421.cpp

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#include "drivers/Bma421.h"
2-
#include <libraries/delay/nrf_delay.h>
3-
#include <libraries/log/nrf_log.h>
42
#include "drivers/TwiMaster.h"
53
#include <drivers/Bma421_C/bma423.h>
4+
#include <libraries/delay/nrf_delay.h>
65

76
using namespace Pinetime::Drivers;
8-
97
namespace {
108
int8_t user_i2c_read(uint8_t reg_addr, uint8_t* reg_data, uint32_t length, void* intf_ptr) {
119
auto bma421 = static_cast<Bma421*>(intf_ptr);
@@ -24,7 +22,7 @@ namespace {
2422
}
2523
}
2624

27-
Bma421::Bma421(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, deviceAddress {twiAddress} {
25+
Bma421::Bma421(TwiMaster& twiMaster, uint8_t twiAddress) : AccelerationSensor(twiMaster, twiAddress) {
2826
bma.intf = BMA4_I2C_INTF;
2927
bma.bus_read = user_i2c_read;
3028
bma.bus_write = user_i2c_write;
@@ -47,13 +45,13 @@ void Bma421::Init() {
4745
// Identify chip by ID. The driver code has been modified to handle BMA421 as BMA423
4846
switch (bma.chip_id) {
4947
case BMA423_CHIP_ID:
50-
deviceType = DeviceTypes::BMA421;
48+
deviceType = AccelerationDeviceTypes::BMA421;
5149
break;
5250
case BMA425_CHIP_ID:
53-
deviceType = DeviceTypes::BMA425;
51+
deviceType = AccelerationDeviceTypes::BMA425;
5452
break;
5553
default:
56-
deviceType = DeviceTypes::Unknown;
54+
deviceType = AccelerationDeviceTypes::Unknown;
5755
break;
5856
}
5957

@@ -66,11 +64,9 @@ void Bma421::Init() {
6664
ret = bma423_feature_enable(BMA423_STEP_CNTR, 1, &bma);
6765
if (ret != BMA4_OK)
6866
return;
69-
7067
ret = bma423_step_detector_enable(0, &bma);
7168
if (ret != BMA4_OK)
7269
return;
73-
7470
ret = bma4_set_accel_enable(1, &bma);
7571
if (ret != BMA4_OK)
7672
return;
@@ -94,24 +90,11 @@ void Bma421::Init() {
9490
if (ret != BMA4_OK)
9591
return;
9692

97-
isOk = true;
98-
}
99-
100-
void Bma421::Reset() {
101-
uint8_t data = 0xb6;
102-
twiMaster.Write(deviceAddress, 0x7E, &data, 1);
93+
isInitialized = true;
10394
}
10495

105-
void Bma421::Read(uint8_t registerAddress, uint8_t* buffer, size_t size) {
106-
twiMaster.Read(deviceAddress, registerAddress, buffer, size);
107-
}
108-
109-
void Bma421::Write(uint8_t registerAddress, const uint8_t* data, size_t size) {
110-
twiMaster.Write(deviceAddress, registerAddress, data, size);
111-
}
112-
113-
Bma421::Values Bma421::Process() {
114-
if (not isOk)
96+
AccelerationValues Bma421::Process() {
97+
if (!isInitialized)
11598
return {};
11699

117100
// Dump entire FIFO into buffer
@@ -146,11 +129,7 @@ Bma421::Values Bma421::Process() {
146129
for (uint8_t j = 0; j < 3; j++)
147130
avgs[j] /= length;
148131

149-
return {steps, avgs[0], avgs[1], avgs[2]};
150-
}
151-
152-
bool Bma421::IsOk() const {
153-
return isOk;
132+
return {steps, avgs[0], avgs[1], avgs[2], (int16_t*) fifo, length};
154133
}
155134

156135
void Bma421::ResetStepCounter() {
@@ -164,6 +143,3 @@ void Bma421::SoftReset() {
164143
nrf_delay_ms(1);
165144
}
166145
}
167-
Bma421::DeviceTypes Bma421::DeviceType() const {
168-
return deviceType;
169-
}

0 commit comments

Comments
 (0)