usr.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #include "usr.h"
  2. #include "system.h"
  3. #include "bsp_time.h"
  4. #include "nrf_delay.h"
  5. //Add your code here...
  6. #include "twi_master.h"
  7. #include "hal_ser_imu_mode_manage.h"
  8. #include "hal_ble_client.h"
  9. #include "hal_ble_host.h"
  10. #include "hal_mt.h"
  11. #include "hal_battery.h"
  12. #include "hal_led.h"
  13. #include "app_overturn.h"
  14. #include "app_charge.h"
  15. #include "app_power.h"
  16. #include "app_client.h"
  17. #include "app_host.h"
  18. #include "app_flash.h"
  19. #include "app_step.h"
  20. #include "app_game.h"
  21. #include "hal_ble_uart0.h"
  22. #include "app_config.h"
  23. #include "app_ota.h"
  24. #include "app_connect_manage.h"
  25. #include "app_organ.h"
  26. #include "ble_comm.h"
  27. #include "ble_gap.h"
  28. #include "exception.h"
  29. #include "bsp_pwm.h"
  30. #include "bsp_wdt.h"
  31. #include "bsp_adc.h"
  32. #include "tool.h"
  33. #include "app_ImuCalibration.h"
  34. #include "hal_wearshoes.h"
  35. #include "app_math.h"
  36. #include "app_losspack.h"
  37. #include "app_pair.h"
  38. #include "app_switchimu.h"
  39. #include "app_self_checking.h"
  40. #include "exception.h"
  41. #include "tool.h"
  42. #include "app_data_transfer.h"
  43. #include "hal_scan_manage.h"
  44. #include "app_safe.h"
  45. #include "hal_detect_left_right.h"
  46. #include "nrf_drv_gpiote.h"
  47. #include "fml_single_line_simplex.h"
  48. void USR_SetName(void)
  49. {
  50. char buf[16];
  51. memset(buf,0,16);
  52. if(mFlash.isHost){ //
  53. #if BleNameHoldOn_ENANBLE
  54. slave_set_adv_name((char *) LEFT_NAME,sizeof(LEFT_NAME));
  55. SEGGER_RTT_printf(0,"scanName(%d):%s\n",sizeof(RIGHT_NAME),RIGHT_NAME);
  56. host_set_scan_name((char *)RIGHT_NAME,sizeof(RIGHT_NAME));
  57. #else
  58. if(mFlash.mClient.isConfig=='C'){ //
  59. sprintf(buf,"%02X%02X%02X%02X%02X%02X",mFlash.macHost[0],mFlash.macHost[1],mFlash.macHost[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  60. SEGGER_RTT_printf(0,"scanName(%d):%s\n",strlen(buf),buf);
  61. host_set_scan_name(buf,strlen(buf));
  62. }
  63. #endif
  64. }else{ //
  65. #if BleNameHoldOn_ENANBLE
  66. slave_set_adv_name((char *)RIGHT_NAME,sizeof(RIGHT_NAME));
  67. SEGGER_RTT_printf(0,"AdvName(%d):%s\n",sizeof(RIGHT_NAME),RIGHT_NAME);
  68. host_set_scan_name((char *)LAST_NAME,sizeof(LAST_NAME));
  69. #else
  70. if(mFlash.mClient.isConfig=='C'){ //
  71. sprintf(buf,"%02X%02X%02X%02X%02X%02X",mFlash.macHost[0],mFlash.macHost[1],mFlash.macHost[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  72. SEGGER_RTT_printf(0,"advName(%d):%s\n",strlen(buf),buf);
  73. slave_set_adv_name(buf,strlen(buf));
  74. }
  75. host_set_scan_name((char *)"12321321312",sizeof("12321321312"));
  76. #endif
  77. }
  78. }
  79. __weak void usr1_Init(void)
  80. {
  81. USR_SetName();
  82. slave_init(BLE_Client_Push);
  83. host_init(BLE_Host_Push);
  84. }
  85. void PRE_Init(void)
  86. {
  87. // watchdog_init();
  88. // feed_watchdog();
  89. nrf_gpio_cfg_input(21,NRF_GPIO_PIN_PULLUP);//3?¦Ì?¨°y??¨¦?¨¤-
  90. PWR_Init();
  91. LED_Init();
  92. // MT_Init();
  93. Flash_Initialize();
  94. Exception_Init();
  95. usr1_Init();
  96. // nrf_gpio_cfg(
  97. // PIN_CHARGING,
  98. // NRF_GPIO_PIN_DIR_OUTPUT,
  99. // NRF_GPIO_PIN_INPUT_CONNECT,
  100. // NRF_GPIO_PIN_NOPULL,
  101. // NRF_GPIO_PIN_D0H1,
  102. // NRF_GPIO_PIN_NOSENSE);
  103. //
  104. // nrf_gpio_cfg_watcher(PIN_CHARGING);
  105. // while(1)
  106. // {
  107. // nrf_gpio_pin_set(PIN_CHARGING);
  108. // nrf_delay_ms(100);
  109. // nrf_gpio_pin_clear(PIN_CHARGING);
  110. // nrf_delay_ms(100);
  111. // }
  112. fml_single_line_simplex_Init();
  113. char value = 0;
  114. int len = 0;
  115. char receive[100];
  116. while(1)
  117. {
  118. // CHECK_TIMECONSUMING_START;
  119. // fml_single_line_simplex_transfer(&value,1);
  120. // CHECK_TIMECONSUMING_END;
  121. // value++;
  122. // SEGGER_RTT_printf(0,"value:%d\n",value);
  123. len = fml_single_line_simplex_receive(receive, 1) ;
  124. for(int i=0; i < len; i++)
  125. {
  126. SEGGER_RTT_printf(0,"drv_single_line_simplex_receive:%d\n",receive[i]);
  127. }
  128. // WS2812_DisplayDot(COLOR_BLUE);
  129. // led_play();
  130. }
  131. }
  132. void USR_Init(void)
  133. {
  134. //Add your code here...
  135. TIME_Init();
  136. hal_ser_imu_mode_manage_Init();
  137. ADC_Initialize();
  138. hal_battery_init();
  139. BLE_Client_Initialize();
  140. BLE_Host_Initialize();
  141. hal_wearshoes_Init();
  142. hal_ble_scan_Init();
  143. hal_detect_left_right_Init();
  144. //APP
  145. app_client_Initialize();
  146. app_host_Initialize();
  147. app_overturn_Init();
  148. app_charge_Init();
  149. app_step_Init();
  150. app_game_Init();
  151. app_math_Init();
  152. app_ota_Init();
  153. app_connect_manage_Init();
  154. app_switchimu_Init();
  155. app_data_transfer_Init();
  156. app_safe_Init();
  157. #if LOSSPACK_ENANBLE
  158. app_losspack_Init();
  159. #endif
  160. #if !BleNameHoldOn_ENANBLE
  161. app_pair_Init();
  162. #endif
  163. app_self_checking_Init();
  164. Tool_Init();
  165. }