Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial P8 a/b smartwatch support #1050

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

StarGate01
Copy link
Contributor

@StarGate01 StarGate01 commented Mar 25, 2022

Since this PR was too large, it was split smaller, separate PRs. Same-level entries can be merged independent from each other.

#1133 also requires #1145 for the BMA421.

PRs / WIPs in related projects:

This PR extends the existing P8 smartwatch support (eg. from e614af1) to support models of the P8 series: P8a and P8b. This is a feature desired by the community (see #62).

The P8 smartwatches and the Pinetime have a few small differences:

  • Slightly different pins are used
  • Some variants have a SC7A20 acceleration sensor, some have a BMA421 (like the Pinetime)
  • Some variants have a CST716 touch screen sensor, some have a CST816S (like the Pinetime)
  • Some variants have no external low frequency crystal
  • Different SPI flash chips are used (Not relevant as no whitelist is enforced in InfiniTime)

I added support for the SC7A20 sensor based on the work by @hubmartin and @ildar at https://github.com/ildar/InfiniTime/tree/p8 . A CMake variable (DRIVER_ACC) can be used to select which sensor is used at compile time. The acceleration driver code was split into an generic interface definition and two hardware-specific implementations.

In addition, both acceleration drivers now use the internal FIFO buffer of the sensor to read high-frequency data without additional CPU load. This buffer is also made available via the motion data BLE service.

In addition, the touch driver can be configured for the touch sensor chip used, to adjust its logic accordingly. The CST716 does not support an automatic sleep state, and cannot wake from the explicit manual sleep state. On these devices, the touch sensor is kept awake if tap to wake is enabled. The CST816S is not explicitly put to sleep, instead it uses its auto-sleep functionality. On my Pinetime dev kit, I had some issues concerning the initialization of the touch sensor after a reset, so I implemented a small workaround for variants with that issue as well.

The CSTX16 touch sensor series can be used in two modes - reporting mode and gesture mode - which control when and how often an event is reported to the main CPU. The InfiniTime code currently assumes that both the CST816S as well as the CST716 are configured in reporting mode. The CST816S is able to switch at runtime to this mode, which is what the code does. The CST716 can only be configured once in the factory. In my P8b it came in reporting mode, however there are P8a variants with a CST716 stuck in gesture mode. The touch sensor mode can be specified by setting the CMake variable DRIVER_TOUCH.

The Nimble Bluetooth stack has been slightly modified to be compatible with the LFRC clock source calibration (see apache/mynewt-nimble#1207), as well as the power-conserving BLE_LL_RFMGMT_ENABLE_TIME Nimble configuration option (see https://mynewt.apache.org/v1_7_0/network/ble_setup/ble_lp_clock.html#crystal-settle-time-configuration).

A second new CMake option (LF_CLK) can be used to specify which source should be used for the low frequency clock (used for Bluetooth). If the RC source is chosen, the code will periodically recalibrate the internal RC oscillator using the high frequency clock as a reference. And the third new option (TARGET_DEVICE) replaces WATCH_COLMI_P8 to select the pin map.

All these now options are optional and documented in buildAndProgram.md. By default, the regular Pinetime configuration is built. The CMake files were slightly refactored as well, for a better display of the configuration options and better debugging configuration.

A related PR was made to the bootloader: InfiniTimeOrg/pinetime-mcuboot-bootloader#10 .

I realize this is a rather large and broad PR, so please feel free to criticize, and I'll be happy to discuss and incorporate any improvements.

CMakeLists.txt Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
src/components/settings/Settings.cpp Outdated Show resolved Hide resolved
src/main.cpp Outdated Show resolved Hide resolved
@StarGate01
Copy link
Contributor Author

This PR has been rebased onto #1052 , which in turn was rebased onto #1051 . Please review / merge those first.

@hubmartin
Copy link
Contributor

@StarGate01 Thanks for all the awesome work! I'll try that on my P8 soon. I'm glad I could update them after long time.

@StarGate01
Copy link
Contributor Author

@hubmartin Thanks! Let me know how the testing goes, especially if you have a P8a watch (which I can't test on at the moment).

@hubmartin
Copy link
Contributor

Merged all 3 PRs and on PineTime it works absolutely fine. Doesn't break anything. Correct touch driver is detected.

On P8 also no major issues. Tested and works fine:

  • Touch, swipes
  • Tap to wake (wow!)
  • Wake on Raise Wrist
  • Shake wake

Thanks a lot @StarGate01 for your work, my P8 has updated FW after long time.
Don't know which P8 version I have, don't have internal photos, didn't looked at info page before I erased original FW.

https://twitter.com/hubmartin/status/1507463707936370696

image

@StarGate01
Copy link
Contributor Author

StarGate01 commented Mar 25, 2022

Great! Thanks for the shoutout :) Your watch appears to be exactly the same as my P8b (see #62 (comment)). Glad to see the firmware working.

Yea, setting up the SC7A20 to correctly detect tap events was a bit of a challenge, but I am happy it works now.

src/drivers/AccelerationSensor.h Outdated Show resolved Hide resolved
src/drivers/Bma421.cpp Outdated Show resolved Hide resolved
src/drivers/Bma421.h Outdated Show resolved Hide resolved
src/drivers/Cst816s.cpp Show resolved Hide resolved
src/drivers/Cst816s.cpp Outdated Show resolved Hide resolved
src/drivers/Cst816s.h Outdated Show resolved Hide resolved
src/drivers/SC7A20.cpp Show resolved Hide resolved
src/drivers/SC7A20.h Outdated Show resolved Hide resolved
src/drivers/SC7A20.h Outdated Show resolved Hide resolved
@StarGate01 StarGate01 force-pushed the p8b branch 3 times, most recently from d5f85c9 to 4cdc1a7 Compare March 30, 2022 22:31
@StarGate01 StarGate01 requested a review from NeroBurner March 30, 2022 22:42
@StarGate01 StarGate01 changed the title Add initial P8b smartwatch support Add initial P8 a/b smartwatch support Apr 4, 2022
@StarGate01
Copy link
Contributor Author

StarGate01 commented Apr 4, 2022

I added a new CMake configuration option (DRIVER_TOUCH), which is used to control how the CSTx17 touch driver chip is configured. On some models, this configuration is set once in the factory, and cannot be changed or even detected at runtime.
I also released a new build with support for the P8a touch sensor: https://github.com/StarGate01/p8b-infinitime/releases .

@StarGate01 StarGate01 force-pushed the p8b branch 2 times, most recently from 0b86558 to 8b872ea Compare April 6, 2022 20:56
@StarGate01
Copy link
Contributor Author

I have squashed and reordered the commits, and removed the acceleration tap detection functionality, which turned out to be highly unreliable. I hope the commits are now more easily reviewable.

I also edited the PR description above, to reflect the updates to the touch driver compatibility and BLE motion service.

@StarGate01 StarGate01 force-pushed the p8b branch 2 times, most recently from c1666ce to c4fc866 Compare May 10, 2022 15:30
Copy link
Contributor

@Riksu9000 Riksu9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work on porting InfiniTIme to other devices, however I think this PR is still too big even with the two other PRs. It would be a good idea to chop it down further to a PR for each driver for example. Also please follow our coding conventions and avoid creating unnecessary changes for a better chance of this being merged.

src/drivers/Bma421.cpp Outdated Show resolved Hide resolved
src/displayapp/LittleVgl.cpp Outdated Show resolved Hide resolved
src/touchhandler/TouchHandler.cpp Outdated Show resolved Hide resolved
@StarGate01
Copy link
Contributor Author

StarGate01 commented May 10, 2022

@Riksu9000 Thank you for the feedback!

I'll try to split the PR further into chunks, the accelerometer FIFO handling should be easy to separate for example.

Do you prefer to have fewer, larger commits per PR, or more fine-grained ones? Also, should I try to keep the PRs independent from each other, or should I stack/rebase them onto each other? The code is not always able to be cleanly separated.

@Riksu9000
Copy link
Contributor

I don't have a strong preference for the number of commits. Do whatever you think is reasonable. Keeping the PRs independent where possible should be easier and faster to review.

This function sends a tap down and tap up event to LVGL,
despite being called only once.
The P8 smartwatches use the CST716 or CST816S chips in various modes.

The device ID of these chips cannot be used for runtime detection,
because it does not give the hardware revision / firmware configuration.
The AccelerationSensor base class provides a unified interface
to access both the BMA421 as well as the SC7A20 chip.
The FIFO buffer is used as well
The DRIVER_ACC configuration variable can be used to select the
acceleration sensor driver to be used.
The motion BLE service now broadcasts the entire FIFO buffer,
in order to expose a higher frequency measurement.

A high enough MTU has to be negotiated to fit all max. 192 bytes.
The format is backwards-compatible.
@ildar
Copy link

ildar commented May 8, 2024

Hello again, pals.
I see many parts of P8 support were accepted and some obviously not.
What are the clue PRs to push yet? I guess #1130 ?
Is it much work to do yet? (I've been away for some time, didn't trace all the discussions)
@StarGate01, thanks again and again for your efforts.

@StarGate01
Copy link
Contributor Author

I am planning to rebase my PRs on the most recent Infinitime release quite soon, I recently got a P8 watch again.

Most of the yet unmerged PRs were held up by some discussions about implementation details, which should be able to be resolved eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants