hr_algo.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*******************************************************************************
  2. * @file hr_algo.h
  3. * @author MEMS Application Team
  4. * @version V1.0
  5. * @date 2021-5-25
  6. * @brief hr algorithm api
  7. *******************************************************************************/
  8. #ifndef _HR_ALGO_H
  9. #define _HR_ALGO_H
  10. /******************************************************************************/
  11. //includes
  12. /******************************************************************************/
  13. #include <stdint.h>
  14. #include <stdarg.h>
  15. /******************************************************************************/
  16. //constants
  17. /******************************************************************************/
  18. /* run mode */
  19. typedef enum {
  20. HB = 0,
  21. SPO2,
  22. HRV,
  23. } hr_mode_e;
  24. /* wear status */
  25. typedef enum {
  26. WEAR = 0,
  27. UNWEAR,
  28. } hr_wear_e;
  29. /******************************************************************************/
  30. //typedef
  31. /******************************************************************************/
  32. #ifdef __CC_ARM /* ARM Compiler */
  33. #pragma anon_unions
  34. #endif
  35. /* hr result handler */
  36. typedef void (*wear_handler_t)(uint8_t wearing_state);
  37. typedef void (*hb_handler_t)(uint8_t hb_val, uint8_t hb_lvl_val, uint16_t rr_val);
  38. typedef void (*spo2_handler_t)(uint8_t spo2_val, uint8_t spo2_lvl_val, uint8_t hb_val,
  39. uint8_t hb_lvl_val, uint16_t rr_val[4], uint8_t rr_lvl_val, uint8_t rr_cnt, uint16_t spo2_r_val);
  40. typedef void (*hrv_handler_t)(uint16_t *rr_val_arr, uint8_t rr_val_cnt, uint8_t rr_lvl);
  41. /* os api */
  42. typedef struct {
  43. /* Printf */
  44. int (*dbgOutput)(const char *fmt, ...);
  45. /* I2C write func */
  46. int (*i2c_write)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len);
  47. /* I2C read func */
  48. int (*i2c_read)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len);
  49. /* User handler */
  50. wear_handler_t wear_handler;
  51. hb_handler_t hb_handler;
  52. spo2_handler_t spo2_handler;
  53. hrv_handler_t hrv_handler;
  54. } hr_os_api_t;
  55. /* Hr algo api */
  56. typedef struct {
  57. /* Init hr algo */
  58. int (*init)(const hr_os_api_t *api);
  59. /* Get os api */
  60. hr_os_api_t* (*get_os_api)(void);
  61. /* Set os api */
  62. int (*set_os_api)(const hr_os_api_t *api);
  63. /* Start hr sensor */
  64. int (*start)(int mode);
  65. /* Stop hr sensor */
  66. int (*stop)(void);
  67. /* Process data through call-back handler */
  68. int (*process)(void);
  69. } hr_algo_api_t;
  70. /******************************************************************************/
  71. //function
  72. /******************************************************************************/
  73. /* Init sensor algo */
  74. extern int hr_algo_init(const hr_os_api_t *api);
  75. /* Get os api */
  76. extern hr_os_api_t* hr_algo_get_os_api(void);
  77. /* Set os api */
  78. extern int hr_algo_set_os_api(const hr_os_api_t *api);
  79. /* Start hr sensor */
  80. extern int hr_algo_start(int mode);
  81. /* Stop hr sensor */
  82. extern int hr_algo_stop(void);
  83. /* Process data through call-back handler */
  84. extern int hr_algo_process(void);
  85. /******************************************************************************/
  86. //api
  87. /******************************************************************************/
  88. /* sensor algo api */
  89. extern char __hr_algo_start[];
  90. extern char __hr_algo_end[];
  91. #define __hr_algo_size (__hr_algo_end - __hr_algo_start)
  92. #define p_hr_algo_api ((const hr_algo_api_t*)__hr_algo_start)
  93. #endif /* _HR_ALGO_H */