1 /*
2  * Copyright (c) 2022 Chipsea Technologies (Shenzhen) Corp., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef MODEL_SENSOR_DRIVER_CHIPSET_PPG_PPG_CS1262_H
10 #define MODEL_SENSOR_DRIVER_CHIPSET_PPG_PPG_CS1262_H
11 
12 #include "ppg_cs1262_spi.h"
13 #include "hdf_device_desc.h"
14 /****************************************** DEFINE ******************************************/
15 #ifdef __LITEOS__
16 #define HEART_REG_TAB    "/etc/cs1262_default.bin"
17 #else
18 #define HEART_REG_TAB    "/system/etc/ppgconfig/cs1262_default.bin"
19 #endif
20 #define CS1262_MAX_FIFO_READ_NUM 800
21 #define CS1262_DEVICE_ID   0x1262
22 #define CS1262_MODULE_VER 1
23 /******************************************* ENUM ********************************************/
24 typedef enum {
25     CS1262_REG_LOCK = 0,
26     CS1262_REG_UNLOCK,
27 } Cs1262LockStatus;
28 /***************************************** TYPEDEF ******************************************/
29 // tab regs num
30 #define SYS_REGS_NUM      6
31 #define TL_REGS_NUM       40
32 #define TX_REGS_NUM       15
33 #define RX_REGS_NUM       77
34 #define TE_REGS_NUM       38
35 #define WEAR_REGS_NUM     25
36 #define FIFO_REGS_NUM     10
37 #define FIFO_WRITE_OFFSET 1
38 
39 typedef struct {
40     uint16_t startMagic;
41     uint16_t clock;
42     uint16_t tlTab[TL_REGS_NUM];
43     uint16_t txTab[TX_REGS_NUM];
44     uint16_t rxTab[RX_REGS_NUM];
45     uint16_t teTab[TE_REGS_NUM];
46     uint16_t wearTab[WEAR_REGS_NUM];
47     uint16_t fifoTab[FIFO_REGS_NUM];
48     uint16_t checksum;
49 } Cs1262RegConfigTab;
50 
51 enum PpgMode {
52     NONE_MODE = 0,
53     DEFAULT_MODE,
54     HEART_RATE_MODE = DEFAULT_MODE,
55     REG_MODE_MAX,
56 };
57 
58 struct Cs1262DrvData {
59     struct IDeviceIoService ioService;
60     struct HdfDeviceObject *device;
61     struct PpgCfgData *ppgCfg;
62     enum PpgMode regMode;
63 };
64 
65 struct PpgModeTab {
66     enum PpgMode mode;
67     Cs1262RegConfigTab *regTab;
68 };
69 
70 int32_t Cs1262Loadfw(enum PpgMode mode, Cs1262RegConfigTab **configTab);
71 
72 #endif  // MODEL_SENSOR_DRIVER_CHIPSET_PPG_PPG_CS1262_H
73