hal_qma.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. static QMA_ACC_ODR_e NowQmafreq = QMA_ACC_ODR_OFF;
  11. static QMA_ACC_ODR_e ReqQmafreq = QMA_ACC_ODR_OFF;
  12. /*API --------------------------------------------------------------*/
  13. QmaFrequency hal_get_QmaFrequency(void){
  14. QmaFrequency freq;
  15. if(QMA_ACC_ODR_OFF == NowQmafreq) freq = QMA_OFF;
  16. else if(QMA_ACC_ODR_12HZ5 == NowQmafreq) freq = QMA_12_5HZ;
  17. else if(QMA_ACC_ODR_104HZ == NowQmafreq) freq = QMA_104HZ;
  18. return freq;
  19. }
  20. void hal_qma_setFrequency(QmaFrequency freq){
  21. QMA_ACC_ODR_e mIFREQ = QMA_ACC_ODR_OFF;
  22. if(QMA_OFF == freq) mIFREQ = QMA_ACC_ODR_OFF;
  23. else if(QMA_12_5HZ == freq) mIFREQ = QMA_ACC_ODR_12HZ5;
  24. else if(QMA_104HZ == freq)mIFREQ = QMA_ACC_ODR_104HZ;
  25. else return;
  26. if(NowQmafreq == mIFREQ)return ;
  27. ReqQmafreq = mIFREQ;
  28. QmaSetFlag =1;
  29. }
  30. static void hal_qma_Porcess(void)
  31. {
  32. static uint8_t state=0;
  33. switch(state){
  34. case 0:
  35. if(1 == QmaSetFlag){
  36. drv_qma_power_off();
  37. if(QMA_ACC_ODR_OFF == ReqQmafreq){
  38. QmaSetFlag =0;
  39. NowQmafreq = ReqQmafreq;
  40. }
  41. else state =1;
  42. }
  43. break;
  44. case 1:
  45. if(0 == drv_qma_power_on()){
  46. state =2;
  47. }
  48. else{
  49. Except_TxError(EXCEPT_QMA7981,"QMA7981 set fail");
  50. DEBUG_LOG("qma7981 config FAIL !\r\n");
  51. state =1;
  52. }
  53. break;
  54. case 2:
  55. if(0 == drv_qma_set_acc_odr(ReqQmafreq)){
  56. DEBUG_LOG("qma7981 config success !\r\n");
  57. Except_TxError(EXCEPT_QMA7981,"QMA7981 set ok");
  58. NowQmafreq = ReqQmafreq;
  59. QmaSetFlag =0;
  60. }else{
  61. DEBUG_LOG("qma7981 config FAIL !\r\n");
  62. Except_TxError(EXCEPT_QMA7981,"QMA7981 set fail");
  63. }
  64. state =0;
  65. break;
  66. default:state =0;break;
  67. }
  68. }
  69. int hal_qma_Init(void)
  70. {
  71. int ret = -1;
  72. ret = drv_qma_Init();
  73. Process_Start(100,"qma_err",hal_qma_Porcess);
  74. // nrf_delay_ms(20);
  75. // ret += drv_qma_set_acc_odr(QMA_ACC_ODR_12HZ5);
  76. // if(ret < 0)ret = drv_qma_set_acc_odr(QMA_ACC_ODR_12HZ5);//再配置一次
  77. drv_qma_power_off();
  78. ReqQmafreq = QMA_ACC_ODR_OFF;
  79. NowQmafreq = QMA_ACC_ODR_OFF;
  80. return ret;
  81. }