adc_demo.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 
  2. /*================================================================
  3. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  4. Quectel Wireless Solutions Proprietary and Confidential.
  5. =================================================================*/
  6. /*=================================================================
  7. EDIT HISTORY FOR MODULE
  8. This section contains comments describing changes made to the module.
  9. Notice that changes are listed in reverse chronological order.
  10. WHEN WHO WHAT, WHERE, WHY
  11. ------------ ------- -------------------------------------------------------------------------------
  12. =================================================================*/
  13. /*===========================================================================
  14. * include files
  15. ===========================================================================*/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "osi_api.h"
  20. #include "ql_log.h"
  21. #include "ql_adc.h"
  22. #include "adc_demo.h"
  23. #include "ql_api_osi.h"
  24. /*===========================================================================
  25. *Definition
  26. ===========================================================================*/
  27. #define QL_ADCDEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
  28. #define QL_ADCDEMO_LOG(msg, ...) QL_LOG(QL_ADCDEMO_LOG_LEVEL, "ql_ADC", msg, ##__VA_ARGS__)
  29. #define QL_ADCDEMO_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_ADCDEMO", msg, ##__VA_ARGS__)
  30. #define QL_ADC_TASK_STACK_SIZE 1024
  31. #define QL_ADC_TASK_PRIO APP_PRIORITY_NORMAL
  32. #define QL_ADC_TASK_EVENT_CNT 5
  33. /*===========================================================================
  34. * Variate
  35. ===========================================================================*/
  36. /*===========================================================================
  37. * Functions
  38. ===========================================================================*/
  39. ql_errcode_adc_e ql_adc_demo_test( void)
  40. {
  41. int adc_value = 0;
  42. ql_adc_get_volt(QL_ADC0_CHANNEL, &adc_value);
  43. QL_ADCDEMO_LOG("ADC[0]: adc_value=[%d]", adc_value );
  44. ql_adc_get_volt(QL_ADC1_CHANNEL, &adc_value);
  45. QL_ADCDEMO_LOG("ADC[1]: adc_value=[%d]", adc_value );
  46. #ifndef QL_APP_PROJECT_DEF_EC800G
  47. #ifndef QL_APP_PROJECT_DEF_EG800G
  48. ql_adc_get_volt(QL_ADC2_CHANNEL, &adc_value);
  49. QL_ADCDEMO_LOG("ADC[2]: adc_value=[%d]", adc_value );
  50. ql_adc_get_volt(QL_ADC3_CHANNEL, &adc_value);
  51. QL_ADCDEMO_LOG("ADC[3]: adc_value=[%d]", adc_value );
  52. #endif
  53. #endif
  54. //obtain raw data in order to improve the speed, customers need to optimize the accuracy themselves
  55. ql_adc_get_volt_raw(QL_ADC0_CHANNEL, QL_ADC_SCALE_0, &adc_value);
  56. QL_ADCDEMO_LOG("RAW ADC[0]: adc_value=[%d]", adc_value );
  57. ql_adc_get_volt_raw(QL_ADC1_CHANNEL, QL_ADC_SCALE_0, &adc_value);
  58. QL_ADCDEMO_LOG("RAW ADC[1]: adc_value=[%d]", adc_value );
  59. #ifndef QL_APP_PROJECT_DEF_EC800G
  60. #ifndef QL_APP_PROJECT_DEF_EG800G
  61. ql_adc_get_volt_raw(QL_ADC2_CHANNEL, QL_ADC_SCALE_0, &adc_value);
  62. QL_ADCDEMO_LOG("RAW ADC[2]: adc_value=[%d]", adc_value );
  63. ql_adc_get_volt_raw(QL_ADC3_CHANNEL, QL_ADC_SCALE_0, &adc_value);
  64. QL_ADCDEMO_LOG("RAW ADC[3]: adc_value=[%d]", adc_value );
  65. #endif
  66. #endif
  67. return 0;
  68. }
  69. static void ql_adc_demo_thread(void *param)
  70. {
  71. ql_rtos_task_sleep_s(1);
  72. /*Show test results*/
  73. ql_adc_demo_test();
  74. ql_rtos_task_delete(NULL);
  75. }
  76. void ql_adc_app_init(void)
  77. {
  78. QlADCStatus err = QL_ADC_SUCCESS;
  79. ql_task_t adc_task = NULL;
  80. err = ql_rtos_task_create(&adc_task, QL_ADC_TASK_STACK_SIZE, QL_ADC_TASK_PRIO, "adc DEMO", ql_adc_demo_thread, NULL, QL_ADC_TASK_EVENT_CNT);
  81. if (err != QL_ADC_SUCCESS)
  82. {
  83. QL_ADCDEMO_LOG("adc demo task created failed");
  84. }
  85. }