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.

123 lines
3.1 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. #if 1
  2. #include "board.h"
  3. #include "diskio_blkdev.h"
  4. #include "ff.h"
  5. #include "nrf_block_dev_sdc.h"
  6. #include "nrf_delay.h"
  7. #include "project_cfg.h"
  8. #include "sys.h"
  9. #include "version.h"
  10. #include "zble_module.h"
  11. #include "zdatachannel_service.h"
  12. #include "diskio_blkdev.h"
  13. #if 0
  14. void qingfengboard_test(void) {
  15. // 测试LED
  16. debug_light_init(15);
  17. // 测试BUTTON
  18. // static uint8_t io_index[] = {ZPIN(0, 5), ZPIN(1, 9)};
  19. // zbsp_gpio_state_monitor(1000, (uint8_t*)io_index, ZARRAY_SIZE(io_index));
  20. // 测试睡眠唤醒
  21. zbsp_enter_sleep(3000, 5, true);
  22. }
  23. #endif
  24. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  25. APP_TIMER_DEF(m_test_tx_timer);
  26. static const char* hex2str(const uint8_t* data, int32_t len) {
  27. static char rx[64] = {0};
  28. memset(rx, 0, sizeof(rx));
  29. for (int32_t i = 0; i < len; i++) {
  30. sprintf(rx + i * 2, "%02X", data[i]);
  31. }
  32. return rx;
  33. }
  34. void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  35. /**
  36. * @brief
  37. */
  38. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  39. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  40. }
  41. }
  42. static void ble_evt_handler(ble_evt_t const* p_ble_evt, void* p_context) {
  43. switch (p_ble_evt->header.evt_id) {
  44. case BLE_GAP_EVT_CONNECTED:
  45. ZLOGI("Connected");
  46. break;
  47. case BLE_GAP_EVT_DISCONNECTED:
  48. ZLOGI("Disconnected");
  49. // zble_module_start_adv();
  50. break;
  51. }
  52. }
  53. void on_service_init(void) {
  54. /**
  55. * @brief
  56. */
  57. ZLOGI("init zdatachannel service");
  58. zdatachannel_init_t zdatachannle_init;
  59. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  60. zdatachannle_init.data_handler = zdatachannel_data_handler;
  61. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  62. }
  63. static void test_tx_timer_cb(void* p_context) {
  64. // static uint32_t data;
  65. // uint16_t txlen = 4;
  66. // data++;
  67. // zdatachannel_data_send((uint8_t*)&data, &txlen);
  68. // ZLOGI("adc channel %d %d", adc_module_heart_elect_channel_read_val(), adc_module_battery_channel_read_val());
  69. ZLOGI("test_tx_timer_cb");
  70. NVIC_SystemReset();
  71. // board_spi_transfer_test();
  72. // uint8_t data[] = {0xAA, 0xBB};
  73. // board_i2c_write(0x3C, data, 2);
  74. // fatfs_test_write();
  75. }
  76. static void board_init() {
  77. // adc_module_init();
  78. // adc_module_battery_channel_init(NRF_SAADC_INPUT_VDD);
  79. // adc_module_heart_elect_channel_init(NRF_SAADC_INPUT_AIN2);
  80. // board_spi_init();
  81. // board_i2c_init();
  82. }
  83. int main(void) {
  84. zsys_init();
  85. NRF_LOG_INFO("compile time :%s", __TIME__);
  86. NRF_LOG_INFO("Version :%d", VERSION);
  87. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  88. static zble_module_cfg_t cfg = //
  89. {
  90. .deviceName = "iflytop_test_ble",
  91. .on_service_init = on_service_init,
  92. };
  93. zble_module_init(&cfg);
  94. board_init();
  95. // fatfs_init();
  96. NRF_SDH_BLE_OBSERVER(m_ble_observer, 3, ble_evt_handler, NULL);
  97. // ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  98. // ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  99. // pwm_trigger();
  100. // wd_init();
  101. zble_module_start_adv();
  102. zsys_loop();
  103. }
  104. #endif