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.

122 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 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 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 year ago
1 year ago
1 year ago
  1. #pragma once
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <time.h>
  5. //
  6. #include "app_scheduler.h"
  7. #include "app_timer.h"
  8. #include "app_uart.h"
  9. #include "app_util_platform.h"
  10. #include "ble_advdata.h"
  11. #include "ble_advertising.h"
  12. #include "ble_conn_params.h"
  13. #include "ble_hci.h"
  14. #include "ble_nus.h"
  15. #include "bsp_btn_ble.h"
  16. #include "diskio_blkdev.h"
  17. #include "ff.h"
  18. #include "nordic_common.h"
  19. #include "nrf.h"
  20. #include "nrf_ble_gatt.h"
  21. #include "nrf_ble_qwr.h"
  22. #include "nrf_block_dev_sdc.h"
  23. #include "nrf_delay.h"
  24. #include "nrf_drv_pwm.h"
  25. #include "nrf_drv_saadc.h"
  26. #include "nrf_drv_spi.h"
  27. #include "nrf_drv_twi.h"
  28. #include "nrf_drv_wdt.h"
  29. #include "nrf_gpio.h"
  30. #include "nrf_log.h"
  31. #include "nrf_log_ctrl.h"
  32. #include "nrf_log_default_backends.h"
  33. #include "nrf_pwr_mgmt.h"
  34. #include "nrf_sdh.h"
  35. #include "nrf_sdh_ble.h"
  36. #include "nrf_sdh_soc.h"
  37. //
  38. #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
  39. // #define ZNORDIC_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE) APP_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE)
  40. /*******************************************************************************
  41. * UTILS *
  42. *******************************************************************************/
  43. typedef struct tm ztm_t;
  44. void wd_init();
  45. void wd_feed();
  46. void znordic_init();
  47. void znordic_init_without_wd();
  48. void znordic_loop();
  49. void znrf_gpio_cfg_output(uint32_t pin_number, nrf_gpio_pin_pull_t pull);
  50. int16_t znrf_adc_channel_read_val(uint16_t channel);
  51. bool znordic_rtc_has_setted();
  52. void znordic_rtc_settime_s(uint32_t timestamp_s);
  53. uint32_t znordic_rtc_gettime_s(void);
  54. uint32_t znordic_getpower_on_s(void); // �����ϵ�ʱ��
  55. uint32_t znordic_getpower_on_ms(void); // ������125ms
  56. uint32_t znordic_haspassed_ms(uint32_t last);
  57. void znordic_rtc_gettime(ztm_t* now);
  58. void znordic_rtc_settime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec);
  59. void znordic_force_flush_log();
  60. const char* fmt(const char* fmt, ...);
  61. const char* hex2str(const uint8_t* data, uint16_t len);
  62. void nrf_log_backend_uart_tx_raw(char const* p_buffer, size_t len);
  63. /*******************************************************************************
  64. * LOG *
  65. *******************************************************************************/
  66. #define ZLOGI(...) NRF_LOG_INFO(__VA_ARGS__)
  67. #define ZLOGE(...) ZLOGE_BLOCK(__VA_ARGS__)
  68. #define ZLOGW(...) NRF_LOG_WARNING(__VA_ARGS__)
  69. #define ZLOGD(...) NRF_LOG_DEBUG(__VA_ARGS__)
  70. #define ZLOG_FLUSH() \
  71. { znordic_force_flush_log(); }
  72. #define ZLOGI_BLOCK(...) \
  73. { \
  74. NRF_LOG_INFO(__VA_ARGS__); \
  75. znordic_force_flush_log(); \
  76. }
  77. #define ZLOGE_BLOCK(...) \
  78. { \
  79. NRF_LOG_ERROR(__VA_ARGS__); \
  80. znordic_force_flush_log(); \
  81. }
  82. #define ZLOGW_BLOCK(...) \
  83. { \
  84. NRF_LOG_WARNING(__VA_ARGS__); \
  85. znordic_force_flush_log(); \
  86. }
  87. #define ZLOGD_BLOCK(...) \
  88. { \
  89. NRF_LOG_DEBUG(__VA_ARGS__); \
  90. znordic_force_flush_log(); \
  91. }
  92. #define ZARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
  93. #define ZPIN(port, num) NRF_GPIO_PIN_MAP(port, num)
  94. #define ZERROR_CHECK(err_code) \
  95. do { \
  96. const uint32_t _zecode = (err_code); \
  97. if (_zecode != NRF_SUCCESS) { \
  98. ZLOGE_BLOCK("%s:%d ZERROR_CHECK(%s) fail:%d", __FILE__, __LINE__, #err_code, _zecode); \
  99. APP_ERROR_CHECK(_zecode); \
  100. } \
  101. } while (0)
  102. #define ZASSERT(expr) \
  103. do { \
  104. if (!(expr)) { \
  105. ZLOGE_BLOCK("%s:%d ZASSERT(%s) fail", __FILE__, __LINE__, #expr); \
  106. APP_ERROR_CHECK_BOOL(false); \
  107. } \
  108. } while (0)