bsp_time.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /********************** 头文件 *************************/
  2. #include "bsp_time.h"
  3. /********************** 变量区 *************************/
  4. const nrf_drv_timer_t TIMER_INT = NRF_DRV_TIMER_INSTANCE(0);
  5. const uint32_t time_ms = 10; //Time(in miliseconds) between consecutive compare events.
  6. static uint32_t time_ticks;
  7. extern uint16_t s_press_buf[3];
  8. extern uint8_t s_press_dex;
  9. extern uint16_t s_press;
  10. int16_t gyro[3];
  11. int16_t accel[3];
  12. uint16_t h_press;
  13. /********************** 函数声明区 *************************/
  14. extern void process_motion(void);
  15. void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
  16. {
  17. switch (event_type)
  18. {
  19. case NRF_TIMER_EVENT_COMPARE0:
  20. send_to_phone_process();
  21. gpio_mt_process();
  22. // printf("H");
  23. if(mpu6050_get_reg_data(gyro,accel)==0){ //读取 IMU 值
  24. h_press = (uint16_t)(ReadPressure()>>8); //读取气压计值 主机
  25. // s_press = s_press_buf[s_press_dex]; //读取气压计值 从机
  26. // if(s_press_dex>0) s_press_dex--; //按顺序对位
  27. process_motion();
  28. // sen_data_to_host();
  29. ReadPressure_Pre(); //准备下一次读取
  30. nrf_gpio_pin_toggle(LED);
  31. }
  32. default:
  33. //Do nothing.
  34. break;
  35. }
  36. }
  37. void time_init(void)
  38. {
  39. uint32_t err_code;
  40. //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
  41. nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
  42. err_code = nrf_drv_timer_init(&TIMER_INT, &timer_cfg, timer_led_event_handler);
  43. APP_ERROR_CHECK(err_code);
  44. time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_INT, time_ms);
  45. nrf_drv_timer_extended_compare(
  46. &TIMER_INT, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
  47. nrf_drv_timer_enable(&TIMER_INT);
  48. }