luat_adc_air101.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "luat_adc.h"
  2. #include "luat_base.h"
  3. #include "wm_adc.h"
  4. #include "wm_gpio_afsel.h"
  5. #include "wm_include.h"
  6. // 0,1 标准ADC
  7. // 3 - 内部温度传感
  8. int luat_adc_open(int ch, void *args)
  9. {
  10. switch (ch)
  11. {
  12. case 0:
  13. wm_adc_config(ch);
  14. break;
  15. case 1:
  16. wm_adc_config(ch);
  17. break;
  18. // #ifdef AIR103
  19. case 2:
  20. wm_adc_config(ch);
  21. break;
  22. case 3:
  23. wm_adc_config(ch);
  24. break;
  25. // #endif
  26. case 10:
  27. case LUAT_ADC_CH_CPU:
  28. return 0; // 温度传感器
  29. case 11:
  30. case LUAT_ADC_CH_VBAT:
  31. return 0; // VBAT电压
  32. default:
  33. return 1;
  34. }
  35. return 0;
  36. }
  37. int luat_adc_read(int ch, int *val, int *val2)
  38. {
  39. int voltage = 0;
  40. switch (ch)
  41. {
  42. case 0:
  43. voltage = adc_get_inputVolt(ch, val);
  44. break;
  45. case 1:
  46. voltage = adc_get_inputVolt(ch, val);
  47. break;
  48. case 2:
  49. voltage = adc_get_inputVolt(ch, val);
  50. break;
  51. case 3:
  52. voltage = adc_get_inputVolt(ch, val);
  53. break;
  54. case LUAT_ADC_CH_CPU:
  55. voltage = adc_temp();
  56. *val = voltage;
  57. *val2 = voltage;
  58. return 0;
  59. case LUAT_ADC_CH_VBAT:
  60. voltage = adc_get_interVolt();
  61. *val = voltage;
  62. *val2 = voltage;
  63. return 0;
  64. default:
  65. return 1;
  66. }
  67. *val2 = voltage;
  68. return 0;
  69. }
  70. int luat_adc_close(int ch)
  71. {
  72. switch (ch)
  73. {
  74. case 0:
  75. tls_io_cfg_set(WM_IO_PA_01, WM_IO_OPTION5);
  76. break;
  77. case 1:
  78. tls_io_cfg_set(WM_IO_PA_04, WM_IO_OPTION5);
  79. break;
  80. // #ifdef AIR103
  81. case 2:
  82. tls_io_cfg_set(WM_IO_PA_03, WM_IO_OPTION5);
  83. break;
  84. case 3:
  85. tls_io_cfg_set(WM_IO_PA_02, WM_IO_OPTION5);
  86. break;
  87. // #endif
  88. case LUAT_ADC_CH_CPU:
  89. break; // 温度
  90. case LUAT_ADC_CH_VBAT:
  91. break; // 内部电压
  92. default:
  93. return 1;
  94. }
  95. return 0;
  96. }
  97. int luat_adc_global_config(int tp, int val) {
  98. return 0;
  99. }