单导联心电记录仪
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
4.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "board.h"
  2. #include "app_timer.h"
  3. #include "nrf_gpio.h"
  4. #include "sys.h"
  5. /*******************************************************************************
  6. * DEBUG_LIGHT *
  7. *******************************************************************************/
  8. APP_TIMER_DEF(m_debug_light_tmr);
  9. static int32_t m_debug_light_io_index;
  10. static void debug_light_tmr_cb_handler(void* p_context) {
  11. static bool state = false;
  12. if (state) {
  13. nrf_gpio_pin_set(m_debug_light_io_index);
  14. } else {
  15. nrf_gpio_pin_clear(m_debug_light_io_index);
  16. }
  17. state = !state;
  18. }
  19. void debug_light_init(int io_index) {
  20. m_debug_light_io_index = io_index;
  21. nrf_gpio_cfg(m_debug_light_io_index, //
  22. NRF_GPIO_PIN_DIR_OUTPUT, //
  23. NRF_GPIO_PIN_INPUT_DISCONNECT, //
  24. NRF_GPIO_PIN_PULLUP, //
  25. NRF_GPIO_PIN_S0S1, //
  26. NRF_GPIO_PIN_NOSENSE);
  27. ret_code_t err_code;
  28. err_code = app_timer_create(&m_debug_light_tmr, APP_TIMER_MODE_REPEATED, debug_light_tmr_cb_handler);
  29. APP_ERROR_CHECK(err_code);
  30. app_timer_start(m_debug_light_tmr, APP_TIMER_TICKS(100), NULL);
  31. }
  32. /*******************************************************************************
  33. * zbsp_enter_sleep *
  34. *******************************************************************************/
  35. APP_TIMER_DEF(enter_sleep_mode_tmr);
  36. static int32_t m_wakeup_io_index;
  37. static bool m_wakeup_io_mirror;
  38. static void enter_sleep_tmr_cb(void* p_context) {
  39. ZLOGI("enter sleep mode, wakeup io index: %d", m_wakeup_io_index);
  40. if (m_wakeup_io_mirror) {
  41. nrf_gpio_cfg_sense_input(m_wakeup_io_index, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
  42. nrf_gpio_cfg_sense_set(m_wakeup_io_index, NRF_GPIO_PIN_SENSE_LOW);
  43. } else {
  44. nrf_gpio_cfg_sense_input(m_wakeup_io_index, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_HIGH);
  45. nrf_gpio_cfg_sense_set(m_wakeup_io_index, NRF_GPIO_PIN_SENSE_HIGH);
  46. }
  47. // Go to system-off mode (this function will not return; wakeup will cause a reset).
  48. ret_code_t err_code;
  49. err_code = sd_power_system_off();
  50. if(err_code != NRF_SUCCESS) {
  51. ZLOGE("sd_power_system_off err_code: %x", err_code);
  52. }
  53. }
  54. void zbsp_enter_sleep(int32_t after_ms, int32_t wakeup_io_index, bool mirror) {
  55. m_wakeup_io_index = wakeup_io_index;
  56. m_wakeup_io_mirror = mirror;
  57. ret_code_t err_code;
  58. APP_ERROR_CHECK(app_timer_create(&enter_sleep_mode_tmr, APP_TIMER_MODE_SINGLE_SHOT, enter_sleep_tmr_cb));
  59. APP_ERROR_CHECK(app_timer_start(enter_sleep_mode_tmr, APP_TIMER_TICKS(after_ms), NULL));
  60. ZLOGI("enter sleep mode after %d ms", after_ms);
  61. }
  62. /*******************************************************************************
  63. * gpio_io_state_monitor *
  64. *******************************************************************************/
  65. APP_TIMER_DEF(gpio_io_state_monitor_tmr);
  66. static uint8_t* m_io_index;
  67. static int32_t m_nio;
  68. static void gpio_io_state_monitor_tmr_cb(void* p_context) {
  69. // ioindex:state ioindex:state ioindex:state
  70. if (m_nio == 1) {
  71. ZLOGI("iostate %d:%d ", m_io_index[0], nrf_gpio_pin_read(m_io_index[0]));
  72. } else if (m_nio == 2) {
  73. ZLOGI("iostate %d:%d %d:%d", m_io_index[0], nrf_gpio_pin_read(m_io_index[0]), //
  74. m_io_index[1], nrf_gpio_pin_read(m_io_index[1]));
  75. } else if (m_nio >= 3) {
  76. ZLOGI("iostate %d:%d %d:%d %d:%d", m_io_index[0], nrf_gpio_pin_read(m_io_index[0]), //
  77. m_io_index[1], nrf_gpio_pin_read(m_io_index[1]), //
  78. m_io_index[2], nrf_gpio_pin_read(m_io_index[2]));
  79. }
  80. }
  81. void zbsp_gpio_state_monitor_without_initio(int dumpstate_period, uint8_t* io_index, int32_t nio) {
  82. m_io_index = io_index;
  83. m_nio = nio;
  84. APP_ERROR_CHECK(app_timer_create(&gpio_io_state_monitor_tmr, APP_TIMER_MODE_REPEATED, gpio_io_state_monitor_tmr_cb));
  85. APP_ERROR_CHECK(app_timer_start(gpio_io_state_monitor_tmr, APP_TIMER_TICKS(dumpstate_period), NULL));
  86. }
  87. void zbsp_gpio_state_monitor(int dumpstate_period, uint8_t* io_index, int32_t nio) {
  88. m_io_index = io_index;
  89. m_nio = nio;
  90. for (int i = 0; i < nio; i++) {
  91. nrf_gpio_cfg_input(io_index[i], NRF_GPIO_PIN_PULLUP);
  92. }
  93. zbsp_gpio_state_monitor_without_initio(dumpstate_period, io_index, nio);
  94. }
  95. void board_init() {}