/********************** 头文件 *************************/ #include "bsp_time.h" /********************** 变量区 *************************/ const nrf_drv_timer_t TIMER_INT = NRF_DRV_TIMER_INSTANCE(0); const uint32_t time_ms = 10; //Time(in miliseconds) between consecutive compare events. static uint32_t time_ticks; extern uint16_t s_press_buf[3]; extern uint8_t s_press_dex; extern uint16_t s_press; int16_t gyro[3]; int16_t accel[3]; uint16_t h_press; /********************** 函数声明区 *************************/ extern void process_motion(void); void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context) { switch (event_type) { case NRF_TIMER_EVENT_COMPARE0: send_to_phone_process(); gpio_mt_process(); // printf("H"); if(mpu6050_get_reg_data(gyro,accel)==0){ //读取 IMU 值 h_press = (uint16_t)(ReadPressure()>>8); //读取气压计值 主机 // s_press = s_press_buf[s_press_dex]; //读取气压计值 从机 // if(s_press_dex>0) s_press_dex--; //按顺序对位 process_motion(); // sen_data_to_host(); ReadPressure_Pre(); //准备下一次读取 nrf_gpio_pin_toggle(LED); } default: //Do nothing. break; } } void time_init(void) { uint32_t err_code; //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other. nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; err_code = nrf_drv_timer_init(&TIMER_INT, &timer_cfg, timer_led_event_handler); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_INT, time_ms); nrf_drv_timer_extended_compare( &TIMER_INT, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrf_drv_timer_enable(&TIMER_INT); }