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