W800_Smart_Watch/README.md
Th3maz1ng 4fd86d28ff Updated README.md
Detailed the battery saving mode
2025-02-12 08:30:41 +01:00

386 lines
20 KiB
Markdown

# W800_Smart_Watch
![](http://82.64.196.164/images/git/W800_watch_header.png)
## Why this project :
I was interested in working on a bigger project with more challenges and which could be useful.
I am also quite unhappy with the smartwatches that are on the market (expensive, no access to the firmware, data collection and privacy issues), that's why I decided to try doing my own that I can fully customize. This is going to be a long adventure with a lot of discoveries along the way :).
I also wanted to test this W800 SOC more deeply and see what it could do and I think it is a perfect fit for the project.
So let's go !
# Update : the release firmware is stable and usable for everyday use.
## A Smart Watch project using the Chinese W800 SOC.
The W800 is a pretty interesting chip with impressive characteristics for its price (around 1$) :
### Core :
* 32bit XT804 CPU
* 240 MHz max clock
### Memory :
* 2 MB on chip flash
* 288 KB RAM, ~130 KB available to the user
### Wireless connectivity :
* Bluetooth EDR(Classic) and BLE 4.2
* WiFi 2.4Ghz 802.11 b/g/n
### SDK & OS
* FreeRTOS v10.4.1
* BLE stack : NimBLE
* TCP IP stack : lwip v2.1.3
## W800 Smart Watch V1 specifications :
#### Sensors :
* A magnetometer (QMC5883L) used by the compass app for example
* An accelerometer (BMA456) to get wrist tilt detection (to wake the screen up), step counts, activity detection (standing, walking and running) and more.
* A pressure and temperature sensor (BMP280) used by the altimeter app for example.
* A heart rate sensor (MAX30102).
#### Screen and Actuators :
* A 1.28 inch touch screen is being used on the watch (GC9A01 screen controller).
* A vibration motor to notify the user of events.
* No physical buttons as everything can be done using the graphical interface.
#### Connectivity :
* The watch has BLE (4.2) connectivity which is used to connect to a phone using the GadgetBridge app (**use version 0.73.0, commit : 4f3472565**) to :
* Control music playback
* Find my phone feature
* Report its battery level
* Report step counts - **to implement**
* Display received text messages, emails and calls - **to implement**
* Show the weather forecast for the next 6 hours or so - **to implement**
* WiFi is also available but not used yet because I didn't find any good use case for it. It is also quite power hungry.
#### Battery and Battery life:
* The battery currently used in this version of the watch is a 6mm x 25mm x 35mm (602535) single cell 600 mAh lipo battery (had one laying around).
* Using the current battery, expected battery life is :
* ~ 5 days in sleep mode.
* ~ 9 hours when continuously connected to BLE with the phone (I may be able to slightly improve power consumption in BLE mode - working on it).
#### Casing size, Weight and Docking station :
* The case of the watch is 3D printed and the STL design files are available [here](design/FreeCad/stl)
* The size of the watch's case is as follow :
![](http://82.64.196.164/images/git/W800_casing_size.png)
* The thickness of the watch will be reworked in the next version of the casing, the goal is to shave 3 to 4 mm off to reach 12 to 13 mm.
* The watch weighs around 50 grams with the 600 mAh battery and the straps attached to it.
* It also has a docking station designed for it which is used to :
* Recharge the W800 Smart Watch by simply putting the watch on it. The connection between the docking and the watch is done through a magnetic 4 pin connector.
* Flash a new firmware to the watch. No extra programming hardware is required, only the docking is needed.
![](http://82.64.196.164/images/git/W800_docking.png)
## Getting started :
### So, you'd like to try this project yourself ?
### Here are the steps to follow, in order to build the firmware and flash the board :
#### **On Windows :**
1) Start by cloning this repository.
**Put it in a path that doesn't contain any spaces** ie : "C:\Users\Bob\Desktop\projects" for example.
2) Once cloning is done, you will need to install the [MSYS2](https://www.msys2.org/) tool/environment. This tool is needed to compile the project using **Make**.
3) Open a terminal by clicking on the **MSYS2** icon and execute the following commands to prepare the environment :
1) Update packages :
```bash
pacman -Syu
```
2) Install make :
```bash
pacman -S msys/make
```
3) Install automake :
```bash
pacman -S msys/automake
```
4) Install autoconf :
```bash
pacman -S msys/autoconf
```
5) Install gcc :
```bash
pacman -S msys/gcc
```
6) Install git :
```bash
pacman -S msys/git
```
7) Install utils needed for menuconfig :
```bash
pacman -S msys/ncurses-devel
pacman -S msys/gettext-devel
```
4) You now, need to download the toolchain required to compile and link the app [here](http://82.157.145.101/download/toolkits/winnermicro/w806/csky-elfabiv2-tools-mingw-minilibc-20210423.tar.gz) and extract it somewhere you remember on your hardrive.
5) Now, go back to the MSYS terminal window and move to the **src/W800_SDK_v1.00.10/** directory which is located in the cloned repository, using the **cd** command.
6) Then, execute the **make menuconfig** command, this should greet you with a crude configuration window.
Move to the **Toolchain Configuration -->** option using the arrows and hit enter.
Using the same controls, move to the **toolchain path** and **set the location** to where you extracted the toolchain in step 4.
7) To be able to flash the board, you will also need to set the used com port in the **Download Configuration --->** option.
**TIPS : set the download rate to : 2000000**, this should speed up the flashing process.
8) Now save your configuration and exit.
9) Finally, type :
```bash
#This will remove all builded object to start from a clean environment (Needed only once)
make distclean
#This will only compile the library part of the firmware
make lib
#This will compile the actual firmware using the libraries and produce the .bin file
make
#This will flash the board using the previously generated .bin file
make down
#This will do both previous commands in one (build and flash)
make flash
```
## Regenerating LVGL builtin fonts (to add special characters for example) :
### If you need to modify the font by changing the default one or need to add missing characters or symbols, you'll have to install a few tools :
#### **On Windows** (every thing is done in Windows 10's Linux console) :
1) Check that python3 is installed and available :
```bash
python3 -V
#If python3 is not installed, do it with :
sudo apt install python3
```
2) You will need to install or update nodejs (**version v14+ required**) as it is used to generate the fonts :
```bash
node -v
#If nodejs is not installed, first install NVM (Node Version Manager) :
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
```
3) Don't forget to reload you .bashrc file, as it was modified by the NVM install script, using :
```bash
source ~/.bashrc
```
These lines were added at the end of your .bashrc file automatically :
```bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
```
4) Now that NVM is installed and accessible, install node :
```bash
#Then using NVM, install node, let's say version 16 :
nvm install 16
#Check the installed version number :
node -v
#My output is : v16.20.2
```
5) Then having node installed, install the **[lv_font_conv](https://github.com/lvgl/lv_font_conv)** utility :
```bash
sudo npm install lv_font_conv -g
#If the lv_font_conv module is successfully installed, you should be able to check its verrsion :
lv_font_conv -v
#My output is : 1.5.2
```
6) Finally, using the command line terminal, you need to move to the ***src/W800_SDK_v1.00.10/lvlg/lvgl_v8.3/scripts/built_in_font*** folder and execute, using
python3, the **built_in_font_gen.py** script :
```bash
#Here are some font regeneration examples using the tool :
python3 built_in_font_gen.py -s 14 --bpp 4 --font Montserrat-Medium.ttf -r 0x20-0x7F,0xB0,0x2022,0xC0,0xC4,0xC7,0xC8,0xC9,0xCA,0xCB,0xCE,0xD4,0xD6,0xD9,0xDB,0xDC,0xDF,0xE0,0xE2,0xE4,0xE7-0xEB,0xEE,0xEF,0xF6,0xFB,0xFC,0x153 -o lv_font_montserrat_14.c
python3 built_in_font_gen.py -s 16 --bpp 4 --font Montserrat-Medium.ttf -r 0x20-0x7F,0xB0,0x2022,0xC0,0xC4,0xC7,0xC8,0xC9,0xCA,0xCB,0xCE,0xD4,0xD6,0xD9,0xDB,0xDC,0xDF,0xE0,0xE2,0xE4,0xE7-0xEB,0xEE,0xEF,0xF6,0xFB,0xFC,0x153 -o lv_font_montserrat_16.c
python3 built_in_font_gen.py -s 24 --bpp 4 --font Montserrat-Medium.ttf -r 0x20-0x7F,0xB0,0x2022,0xC0,0xC4,0xC7,0xC8,0xC9,0xCA,0xCB,0xCE,0xD4,0xD6,0xD9,0xDB,0xDC,0xDF,0xE0,0xE2,0xE4,0xE7-0xEB,0xEE,0xEF,0xF6,0xFB,0xFC,0x153 -o lv_font_montserrat_24.c
python3 built_in_font_gen.py -s 28 --bpp 4 --font Montserrat-Medium.ttf -r 0x20-0x7F,0xB0,0x2022,0xC0,0xC4,0xC7,0xC8,0xC9,0xCA,0xCB,0xCE,0xD4,0xD6,0xD9,0xDB,0xDC,0xDF,0xE0,0xE2,0xE4,0xE7-0xEB,0xEE,0xEF,0xF6,0xFB,0xFC,0x153 -o lv_font_montserrat_28.c
python3 built_in_font_gen.py -s 30 --bpp 4 --font Montserrat-Medium.ttf -r 0x20-0x7F,0xB0,0x2022,0xC0,0xC4,0xC7,0xC8,0xC9,0xCA,0xCB,0xCE,0xD4,0xD6,0xD9,0xDB,0xDC,0xDF,0xE0,0xE2,0xE4,0xE7-0xEB,0xEE,0xEF,0xF6,0xFB,0xFC,0x153 -o lv_font_montserrat_30.c
```
7) Once done, the new generated fonts file will be in the same folder (***src/W800_SDK_v1.00.10/lvlg/lvgl_v8.3/scripts/built_in_font***) named **lv_font_'font name'_'size'.c**
like lv_font_monserrat_14.c, happy fonting !!!
## Sensors and I2C addresses :
* Accelerometer : **BMA456** I2C addr : 0x18 or 0x19 7 bit address.
* Magnetometer : **QMC5883L** I2C addr : 0x0D 7 bit address.
* Pressure/Temperature sensor : **BMP280** I2C addr : 0x76 or 0x77 7 bit address.
* Heart Rate and SpO2 sensor : **Max30102** I2C addr : 0x57 7 bit address.
## Power source :
* A single ~ 600 mAh cell lipo battery.
* A charge/discharge controller stage :
* TP4056
* DW01A + 8205A
## Screen + touch element :
* [Screen with touch](https://fr.aliexpress.com/item/1005004887834918.html?spm=a2g0o.order_list.order_list_main.22.340a5e5bX8WCb0&gatewayAdapt=glo2fra) : GC9A01 with touch panel. It uses the required 4 line Serial Interface.
* Touch element i2c addr : 0x15, CST816D I2C touch driver.
## Programming and charging :
* The smart watch programming and charging is done through the same USB port
using a magnetic 4 pin plug.
## MCU Pin assignement table :
| Pin Number | Pin Name | Type | Function | Pull UP/DOWN| Connected to | Comment |
|------------|----------|------|----------|-------------|--------------|---------|
|1|PB_20|I/O|**UART0_RX**/PWM1/UART1_CTS/I²C_SCL|U/D|**USB/Serial TX flash pin**||
|2|PB_19|I/O|**UART0_TX**/PWM0/UART1_RTS/**I²C_SDA**|U/D|**USB/Serial RX flash pin** and **BMA456, Touch Panel, HMC5883L and BMP280 SDA pins**||
|3|WAKEUP|I|**External Wake Up Pin**|D|**BMA456 IRQ 1 line** and **Touch Panel IRQ line** through NAND Gate|The chip is waken up when the pin is HIGH|
|4|RESET|I|Reset Pin|D|**Micro switch** and **USB/Serial RTS pin**||
|5|XTAL_OUT|O|External crystal output||||
|6|XTAL_IN|I|External crystal input||||
|7|AVDD3V3|P|Chip power supply, 3.3V||||
|8|ANT|I/O|RF Antenna||||
|9|AVDD3V3|P|Chip power supply, 3.3V||||
|10|AVDD3V3|P|Chip power supply, 3.3V|||
|11|AVDD3V3_AUX|P|Chip power supply, 3.3V||||
|12|TEST|I|Test function configuration pin||||
|13|BOOTMODE|**I/O**|BOOTMODE and I²S_MCLK/LSPI_CS/PWM2/I²S_DO|U/D|**Touch Panel Reset line**||
|14|PA_1|I/O|JTAG_CK/**I²C_SCL**/PWM3/I²S_LRCK/ADC0|U/D|**BMA456, Touch Panel, HMC5883L and BMP280 SCL pins**||
|15|PA_4|I/O|JTAG_SWO/I²C_SDA/PWM4/I²S_BCK/**ADC1**|U/D|**Battery resistor voltage divider output**||
|16|PA_7|I/O|**PWM4**/LSPI_MOSI/I²S_MCK/I²S_DI/Touch0|U/D|**LCD backlight N-MOSFET driver**||
|17|VDD3V3IO|P|IO power supply, 3.3V||||
|18|PB_0|I/O|**PWM0**/LSPI_MISO/UART3_TX/PSRAM_CK/Touch3|U/D|**Vibration motor control pin**||
|19|PB_1|**I/O**|PWM1/LSPI_CK/UART3_RX/PSRAM_CS/Touch4|U/D|**Touch Panel IRQ line**||
|20|PB_2|I/O|PWM2/LSPI_CK/**UART2_TX**/PSRAM_D0/Touch5|U/D|**Debug UART serial output**||
|21|PB_3|**I/O**|PWM3/LSPI_MISO/UART2_RX/PSRAM_D1/Touch6|U/D|**TP4056A Charging Signal**||
|22|PB_4|**I/O**|LSPI_CS/UART2_RTS/UART4_TX/PSRAM_D2/Touch7|U/D|**TP4056A Charged Signal**||
|23|PB_5|**I/O**|LSPI_MOSI/UART2_CTS/UART4_RX/PSRAM_D3/Touch8|U/D|**Battery resistor voltage divider enable**||
|24|VDD3V3IO|P|IO power supply, 3.3V||||
|25|CAP|I|External capacitor, 4.7µF||||
|26|PB_6|I/O|UART1_TX/**MMC_CLK**/HSPI_CK/SDIO_CK/Touch9|U/D|**LCD Serial Clock Pin**||
|27|PB_7|I/O|UART1_RX/**MMC_CMD**/HSPI_INT/SDIO_CMD/Touch10|U/D|**LCD Serial Data Pin**||
|28|PB_8|**I/O**|I²S_BCK/MMC_D0/PWM_BREAK/SDIO_D0/Touch11|U/D|**LCD Data or Command Selection Pin**||
|29|PB_9|**I/O**|I²S_LRCK/MMC_D1/HSPI_CS/SDIO_D1/Touch12|U/D|**LCD Reset Pin**||
|30|PB_10|**I/O**|I²S_DI/MMC_D2/HSPI_DI/SDIO_D2|U/D|**LCD Chip Select Pin**||
|31|VDD3V3IO|P|IO power supply, 3.3V||||
|32|PB_11|**I/O**|I²S_DO/MMC_D3/HSPI_DO/SDIO_D3|U/D|**BMA456 IRQ 2 line**||
|33|GND|P|Ground (Central Pad)||||
## What is done/working so far - HARDWARE :
* Schematic :
* First version of the schematic is done an available [here](design/Kicad/W800_Smart_Watch/W800_Smart_Watch.pdf).
* 2 layer PCB version 1.0 design is done based on the schematic. It has a 38 mm diameter size.
* Wake up interrupts handling :
* Wrist tilt MCU wake up working
* LCD touch wake up
* MCU sleep feature :
* Sleep and Standby modes working but implemented in a crude way.
Can and should be improved.
* PIFA antenna tested, performance isn't the best but it is working well for what it will be used for (BLE).
## What is done/working so far - SOFTWARE :
* LVGL 8.3.3 running on the SOC using DMA.
* Supported LCD drivers :
* ILI9341 in 4-line serial mode (8 bits) with D/C pin
* ST7789 in 4-line serial mode (8 bits) with D/C pin
* GC9A01 in 4-line serial mode (8 bits) with D/C pin <-- **this one is used**.
* Supported LCD touch screen :
* CST816D I2C capacitive touch ic.
* Six screens designed and working with LVGL :
* An analog watch face based on a existing casio watch.
* An analog watch face having a carbon fiber vibe.
* A circular menu screen with icons.
* A setting screen allowing to tune the smart watch :
* Time and date settings
* Display settings
* Notifications settings
* Connectivity settings for BLE
* Language settings (French, German and English available)
* System information page
* A compass application using the QMC5883L.
* An altimeter app.
* A music player app (working with GadgetBridge).
* A find my phone screen which makes the device ring and vibrate (must be connected to the watch using BLE through the GadgetBridge app).
* Debug UART on PB_2 (**output only**)
* Sensors/Actuators :
* QMC5883L driver working
* BMA456 driver working
* BMP280 driver working (temperature + pressure + altitude)
* MAX30102 driver working
* Battery voltage sense using ADC is working
* Vibration motor controlled by PWM working
* Update the W800 SDK from version 1.00.08 to version 1.00.10 released in January of 2023.
* Added **multi-language** support to the UI, still some translations to do though.
* Step counter using the BMA456 is working and steps are displayed on the watch face.
## **To Do list :**
* Write the notification app listing all the received notification to be able to read them again or delete them if wanted.
* Write a flash light app which sets the screen brightness to its maximum and
sets a white background, be able to make it also flash with a red background.
* Add a quick access drawer (like on android) to :
* turn bluetooth on and off faster
* enable or disable the watch wrist tilt wakeup
* open the flash light app
* access the battery charge/discharge history app (to be written)
* more if some ideas pop
* Update the compass algorithm to also use the Z axis and not having to hold the watch flat.
* Update the settings app to include a sensor category where calibration can be done for the magnetometer as well as for the temperature sensor to get more accurate temperature when the watch is worn.
* Update the GadgetBridge parser to work with the latest version of GadgetBridge.
* Write an algorithm to get the heart rate measurements and a way to make them periodically and displays it in a dedicated app and on the watch face.
* Display the weather forecast on the watch face using icons (Data coming from GadgetBridge).
* Finish to translate all texts in the 3 supported languages (French, German and English).
* Design a digital watch face with a light memory footprint to be able to choose a watch face kind (analog or digital) at run time.
* Improve the step counting mechanism (reset step count every midnight).
* Write an app to track step counts made every day (on a week for example with a graph).
* Write an alarm app which set an RTC alarm to vibrate the watch.
* Write a timer app with countdown and lap functionality.
* Implement a battery saving mode activated on low batterie (ie <= 10 %).
* This mode would :
* turn bluetooth off.
* set the screen brightness to 50 %.
* throttle the MCU frequency down to 80 or 40 Mhz.
## Done List :
* Two analog watch faces available (which can be selected at compile time using the **app_config.h** header file).
* A circular menu screen.
* Total number of steps on the watch face.
* A music player (works with GadgetBridge).
* A compass app with temperature reading.
* An altimeter app.
* The find my phone app (works with GadgetBridge).
* A setting app to set :
* Time and date
* Display settings
* Notification settings
* Connectivity (BLE)
* Language
* About section
* Vibration on the watch works and is configurable.
* Wrist tilt to wake the watch up.
* Receive phone notifications on the watch (works with GadgetBridge).
* Smooth screen changes with transitions.
* Adaptative dynamic MCU clock speed to save power or have better visual performance.
* Battery discharging, charging and charged status on the watch face.
* Improve the received notification design (colour and layout) as well as the AM or PM time when hour format is set to 12H.
* Call the GadgetBridge parser close notification when notification is closed.
## Achieved power consumption recap:
(Need to work on sleep current :-( )
| Mode | Current draw | Estimated battery life (600 mAh lipo) |
|--------------------------|--------------------------|---------------------------------------|
|Active (80MHz clk)<br>(No BLE / No WiFi / Screen on) |~54.51 mA | ~11 hours |
|Active (160MHz clk)<br>(No BLE / No WiFi / Screen on)|~64.7 mA | ~9 hours |
|Sleep (Clock is OFF / No BLE) |~3.97 mA | ~6 days |
|Sleep (40MHz clk / With BLE) |~49.20 mA | ~12 hours |
|Standby (Not available) |~1.8 mA |~13 days and 15 hours |
## Some screenshots of the achieved visuals currently running on the watch using lvgl :
![](http://82.64.196.164/images/git/watch_graphics.png)
## Here is a preview of what the PCB should look like :
### The front :
![](http://82.64.196.164/images/git/rendering_front.png)
### The back :
![](http://82.64.196.164/images/git/rendering_back.png)
## Update 21/03/2023 : PCBs were received from JLCPCB and this what they look like :
![](http://82.64.196.164/images/git/W800_pcb_1.png)
![](http://82.64.196.164/images/git/W800_pcb_2.png)
## And the watch running :
![](http://82.64.196.164/images/git/W800_running.png)
### **Everything works :**
* BMA456 ✓
* BMP280 ✓
* QMC5883L ✓
* MAX30102 ✓
* Screen + touch panel ✓
* CH340E for chip programming ✓
* Vibration motor ✓
* Charge IC ✓
### **Known issues :**
* DW01A chip not driving the double N mosfet as expected (when plugging a battery, the watch doesn't start without beeing plugged into the charger at least once).
Thought it might be a capacitor value issue, replaced C12 with a 82nf and 68nf caps, but it did not solve the problem :(.
**TLDR : after installing the battery, the watch might need to be plugged to it's charger at least once to start up**
## If you are interested in the project or if you just want to say hi, you can contact me at the email address : bugreport[at]laposte.net .