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.

462 lines
14 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 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "basic/zble_module.h"
  2. #include "basic/zdatachannel_service.h"
  3. #include "znordic.h"
  4. //
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. //
  10. #include "app_uart.h"
  11. #include "basic/ssd1306/driver_ssd1306_basic.h"
  12. #include "one_conduction/one_conduction_board.h"
  13. #include "three_lead\three_lead_board.h"
  14. #if defined(UART_PRESENT)
  15. #include "nrf_uart.h"
  16. #endif
  17. #if defined(UARTE_PRESENT)
  18. #include "nrf_uarte.h"
  19. #endif
  20. #if 0
  21. static void test_tx_timer_cb(void* p_context) {
  22. static uint32_t data;
  23. data++;
  24. ZLOGI("tim cb %d", data);
  25. // ThreeLeadECG_sdcard_connect2_ext_usb_sdcard_driver_ic_reset();
  26. }
  27. extern uint32_t g_nrf_log_tx_pin;
  28. APP_TIMER_DEF(m_test_tx_timer);
  29. void main() {
  30. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  31. ThreeLeadECG_beep_init();
  32. ThreeLeadECG_sdcard_base_init();
  33. znordic_init();
  34. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  35. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  36. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(3000), NULL));
  37. znordic_loop();
  38. }
  39. #endif
  40. // EEPROM_TEST
  41. #if 0
  42. static void test_tx_timer_cb(void* p_context) {
  43. static uint32_t data;
  44. data++;
  45. // ZLOGI("test_tx_timer_cb %d", data);
  46. static uint8_t eepromw_test_data[256];
  47. static uint8_t eepromw_rx_data[256];
  48. for (size_t i = 0; i < 256; i++) {
  49. eepromw_test_data[i] = i;
  50. }
  51. // SingleLeadECG_eeprom_write(0, eepromw_test_data, 256);
  52. SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  53. // for (size_t i = 0; i < 256; i++) {
  54. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  55. // NRF_LOG_INTERNAL_FLUSH();
  56. // }
  57. }
  58. extern uint32_t g_nrf_log_tx_pin;
  59. APP_TIMER_DEF(m_test_tx_timer);
  60. void main() {
  61. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  62. znordic_init();
  63. // SingleLeadECG_beep_init();
  64. // SingleLeadECG_beep_set_state(false);
  65. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  66. NRF_LOG_INTERNAL_FLUSH();
  67. SingleLeadECG_eeprom_init();
  68. // nrf_delay_ms(20);
  69. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  70. // for (size_t i = 0; i < 256; i++) {
  71. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  72. // NRF_LOG_INTERNAL_FLUSH();
  73. // }
  74. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  75. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  76. znordic_loop();
  77. }
  78. #endif
  79. /*******************************************************************************
  80. * +LED测试 *
  81. *******************************************************************************/
  82. #if 0
  83. static void test_tx_timer_cb(void* p_context) {
  84. static uint32_t data;
  85. data++;
  86. ZLOGI("test_tx_timer_cb %d", data);
  87. SingleLeadECG_led_green_set_state(data % 2 == 0);
  88. SingleLeadECG_led_blue_set_state(data % 3 == 0);
  89. }
  90. extern uint32_t g_nrf_log_tx_pin;
  91. APP_TIMER_DEF(m_test_tx_timer);
  92. void main() {
  93. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  94. znordic_init();
  95. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  96. NRF_LOG_INTERNAL_FLUSH();
  97. SingleLeadECG_screen_init();
  98. ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0);
  99. ssd1306_basic_display_on();
  100. ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  101. ssd1306_basic_string(0, 16, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  102. ssd1306_basic_string(0, 32, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  103. ssd1306_basic_string(0, 48, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  104. SingleLeadECG_led_init();
  105. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  106. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  107. znordic_loop();
  108. }
  109. #endif
  110. /*******************************************************************************
  111. * ECG *
  112. *******************************************************************************/
  113. #if 0
  114. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  115. #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
  116. uint32_t err_code;
  117. app_uart_comm_params_t const comm_params = //
  118. {
  119. .rx_pin_no = UART_PIN_DISCONNECTED,
  120. .tx_pin_no = 41,
  121. .rts_pin_no = UART_PIN_DISCONNECTED,
  122. .cts_pin_no = UART_PIN_DISCONNECTED,
  123. .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
  124. .use_parity = false,
  125. .baud_rate = NRF_UARTE_BAUDRATE_921600,
  126. };
  127. void uart_error_handle(app_uart_evt_t* p_event) {}
  128. void uartinit() {
  129. APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  130. APP_ERROR_CHECK(err_code);
  131. }
  132. void zchip_log(const char* fmt, ...) {
  133. static char tx[256] = {0};
  134. va_list args;
  135. va_start(args, fmt);
  136. vsprintf(tx, fmt, args);
  137. for (size_t i = 0; i < strlen(tx); i++) {
  138. app_uart_put(tx[i]);
  139. }
  140. va_end(args);
  141. }
  142. static void test_tx_timer_cb(void* p_context) {
  143. static uint32_t data;
  144. data++;
  145. // SingleLeadECG_ecg_nlod_get_connected_state();
  146. // SingleLeadECG_ecg_plod_get_connected_state();
  147. // SingleLeadECG_ecg_plod_get_ecg_val();
  148. // ZLOGI("%d nlod %d plod %d ecg:%d", data, SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  149. // ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  150. zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  151. // app_uart_put('c');
  152. // app_uart_put('c');
  153. // app_uart_put('c');
  154. // app_uart_put('c');
  155. // app_uart_put('c');
  156. // NRF_LOG_INFO("......");
  157. }
  158. extern uint32_t g_nrf_log_tx_pin;
  159. APP_TIMER_DEF(m_test_tx_timer);
  160. void main() {
  161. // g_nrf_log_tx_pin = 41;
  162. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  163. znordic_init();
  164. SingleLeadECG_adc_module_init();
  165. uartinit();
  166. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  167. NRF_LOG_INTERNAL_FLUSH();
  168. SingleLeadECG_ecg_init();
  169. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  170. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  171. znordic_loop();
  172. }
  173. #endif
  174. /*******************************************************************************
  175. * *
  176. *******************************************************************************/
  177. #if 0
  178. extern uint32_t g_nrf_log_tx_pin;
  179. APP_TIMER_DEF(m_test_tx_timer);
  180. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  181. static const char* hex2str(const uint8_t* data, int32_t len) {
  182. static char rx[64] = {0};
  183. memset(rx, 0, sizeof(rx));
  184. for (int32_t i = 0; i < len; i++) {
  185. sprintf(rx + i * 2, "%02X", data[i]);
  186. }
  187. return rx;
  188. }
  189. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  190. /**
  191. * @brief
  192. */
  193. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  194. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  195. }
  196. }
  197. static void on_service_init(void) {
  198. /**
  199. * @brief
  200. */
  201. ZLOGI("init zdatachannel service");
  202. zdatachannel_init_t zdatachannle_init;
  203. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  204. zdatachannle_init.data_handler = zdatachannel_data_handler;
  205. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  206. }
  207. void main() {
  208. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  209. ThreeLeadECG_sdcard_base_init();
  210. znordic_init(0, 20);
  211. NRF_LOG_INFO("compile time :%s", __TIME__);
  212. NRF_LOG_INFO("Version :%d", VERSION);
  213. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  214. static zble_module_cfg_t cfg = //
  215. {
  216. .deviceName = BLE_NAME,
  217. .on_service_init = on_service_init,
  218. };
  219. zble_module_init(&cfg);
  220. zble_module_start_adv();
  221. znordic_loop();
  222. }
  223. #endif
  224. #if 0
  225. /*******************************************************************************
  226. * ADCTEST *
  227. *******************************************************************************/
  228. static void test_tx_timer_cb(void* p_context) {
  229. static uint32_t data;
  230. data++;
  231. // ZLOGI("test_tx_timer_cb %d", data);
  232. static uint8_t eepromw_test_data[256];
  233. static uint8_t eepromw_rx_data[256];
  234. for (size_t i = 0; i < 256; i++) {
  235. eepromw_test_data[i] = i;
  236. }
  237. int16_t adc = SingleLeadECG_battery_get_adc_val();
  238. int16_t mv = adc * 1.0 / 4096 * 3.6 * 1000 / 2.0 * 3;
  239. ZLOGI("battery:%d", mv);
  240. }
  241. extern uint32_t g_nrf_log_tx_pin;
  242. APP_TIMER_DEF(m_test_tx_timer);
  243. void main() {
  244. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  245. znordic_init();
  246. SingleLeadECG_adc_module_init();
  247. SingleLeadECG_battery_init();
  248. // SingleLeadECG_beep_init();
  249. // SingleLeadECG_beep_set_state(false);
  250. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  251. NRF_LOG_INTERNAL_FLUSH();
  252. // nrf_delay_ms(20);
  253. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  254. // for (size_t i = 0; i < 256; i++) {
  255. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  256. // NRF_LOG_INTERNAL_FLUSH();
  257. // }
  258. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  259. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  260. znordic_loop();
  261. }
  262. #endif
  263. #if 0
  264. /*******************************************************************************
  265. * 3-ADS1293- *
  266. *******************************************************************************/
  267. static void test_tx_timer_cb(void* p_context) {
  268. static uint32_t data;
  269. data++;
  270. ZLOGI("tim cb %d :%d %d", data, ThreeLeadECG_ready_pin_state_get(), ThreeLeadECG_LineInputDet_get_state());
  271. // ThreeLeadECG_sdcard_connect2_ext_usb_sdcard_driver_ic_reset();
  272. }
  273. extern uint32_t g_nrf_log_tx_pin;
  274. APP_TIMER_DEF(m_test_tx_timer);
  275. void main() {
  276. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  277. // ThreeLeadECG_sdcard_base_init();
  278. znordic_init();
  279. ThreeLeadECG_ecg_init();
  280. ThreeLeadECG_LineInputDet_init();
  281. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  282. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  283. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(3000), NULL));
  284. znordic_loop();
  285. }
  286. #endif
  287. #if 0
  288. /*******************************************************************************
  289. * 3-led测试 *
  290. *******************************************************************************/
  291. static void test_tx_timer_cb(void* p_context) {
  292. static uint32_t data;
  293. data++;
  294. ZLOGI("test_tx_timer_cb %d", data);
  295. ThreeLeadECG_led_green_set_state(data % 2 == 0);
  296. }
  297. extern uint32_t g_nrf_log_tx_pin;
  298. APP_TIMER_DEF(m_test_tx_timer);
  299. void main() {
  300. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  301. znordic_init();
  302. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  303. NRF_LOG_INTERNAL_FLUSH();
  304. ThreeLeadECG_led_init();
  305. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  306. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  307. znordic_loop();
  308. }
  309. #endif
  310. #if 0
  311. /*******************************************************************************
  312. * 3- *
  313. *******************************************************************************/
  314. static void test_tx_timer_cb(void* p_context) {
  315. static uint32_t data;
  316. data++;
  317. int16_t mv = ThreeLeadECG_battery_get_adc_val() * 1.0 / 4096 * 3.3 * 1000 / 2.0 * 3;
  318. ZLOGI("battery:%d", mv);
  319. }
  320. extern uint32_t g_nrf_log_tx_pin;
  321. APP_TIMER_DEF(m_test_tx_timer);
  322. void main() {
  323. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  324. znordic_init();
  325. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  326. NRF_LOG_INTERNAL_FLUSH();
  327. ThreeLeadECG_adc_module_init();
  328. ThreeLeadECG_battery_init();
  329. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  330. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  331. znordic_loop();
  332. }
  333. #endif
  334. #if 1
  335. /*******************************************************************************
  336. * 3-flash测试 *
  337. *******************************************************************************/
  338. static void test_tx_timer_cb(void* p_context) {
  339. static uint32_t data;
  340. data++;
  341. }
  342. extern uint32_t g_nrf_log_tx_pin;
  343. APP_TIMER_DEF(m_test_tx_timer);
  344. void main() {
  345. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  346. znordic_init();
  347. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  348. NRF_LOG_INTERNAL_FLUSH();
  349. ThreeLeadECG_sdcard_base_init();
  350. ThreeLeadECG_sdcard_mount();
  351. ThreeLeadECG_sdcard_umount();
  352. ThreeLeadECG_sdcard_mount();
  353. ThreeLeadECG_sdcard_umount();
  354. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  355. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  356. znordic_loop();
  357. }
  358. #endif
  359. #if 0
  360. /*******************************************************************************
  361. * 3-flash测试 *
  362. *******************************************************************************/
  363. static void test_tx_timer_cb(void* p_context) {
  364. static uint32_t data;
  365. data++;
  366. ZLOGI("button %d", ThreeLeadECG_button_get_state());
  367. }
  368. extern uint32_t g_nrf_log_tx_pin;
  369. APP_TIMER_DEF(m_test_tx_timer);
  370. void main() {
  371. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  372. znordic_init();
  373. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  374. NRF_LOG_INTERNAL_FLUSH();
  375. ThreeLeadECG_button_init();
  376. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  377. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(300), NULL));
  378. znordic_loop();
  379. }
  380. #endif