hal_qma.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*Includes ----------------------------------------------*/
  2. #include "tool.h"
  3. #include "bsp_time.h"
  4. #include "nrf_delay.h"
  5. #include "bll_imu.h"
  6. #include "hal_qma.h"
  7. #include "exception.h"
  8. #include "system.h"
  9. static uint8_t QmaSetFlag =0;//Qma配置成功标志位
  10. /*API --------------------------------------------------------------*/
  11. static void hal_qma_Porcess(void)
  12. {
  13. static uint8_t state=0;
  14. switch(state){
  15. case 0:
  16. if(0 == QmaSetFlag){
  17. drv_qma_power_off();
  18. state =1;
  19. }
  20. break;
  21. case 1:
  22. if(0 == drv_qma_power_on()){
  23. state =2;
  24. }
  25. else{
  26. Except_TxError(EXCEPT_QMA7981,"QMA7981 set fail");
  27. DEBUG_LOG("qma7981 config FAIL !\r\n");
  28. state =1;
  29. }
  30. break;
  31. case 2:
  32. if(0 == drv_qma_set_acc_odr(QMA_ACC_ODR_12HZ5)){
  33. QmaSetFlag =1;
  34. DEBUG_LOG("qma7981 config success !\r\n");
  35. Except_TxError(EXCEPT_QMA7981,"QMA7981 set ok");
  36. }else{
  37. DEBUG_LOG("qma7981 config FAIL !\r\n");
  38. Except_TxError(EXCEPT_QMA7981,"QMA7981 set fail");
  39. }
  40. state =0;
  41. break;
  42. default:state =0;break;
  43. }
  44. }
  45. uint8_t hal_qma_get_state(void){
  46. return QmaSetFlag;
  47. }
  48. int hal_qma_Init(void)
  49. {
  50. int ret = -1;
  51. ret = drv_qma_Init();
  52. nrf_delay_ms(20);
  53. ret += drv_qma_set_acc_odr(QMA_ACC_ODR_12HZ5);
  54. if(ret < 0)ret = drv_qma_set_acc_odr(QMA_ACC_ODR_12HZ5);//再配置一次
  55. Process_Start(1000,"hal_qma_err_Porcess",hal_qma_Porcess);
  56. if(ret == 0){
  57. QmaSetFlag =1;
  58. DEBUG_LOG("qma7981 config success !\r\n");
  59. }
  60. else{
  61. QmaSetFlag = 0;
  62. DEBUG_LOG("qma7981 config error:%d !\r\n",ret);
  63. }
  64. ret = ret < 0 ? -1 : 0;
  65. return ret;
  66. }