luat_adc_air101.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. case 2:
  19. wm_adc_config(ch);
  20. break;
  21. case 3:
  22. wm_adc_config(ch);
  23. break;
  24. case 10:
  25. case LUAT_ADC_CH_CPU:
  26. return 0; // 温度传感器
  27. case 11:
  28. case LUAT_ADC_CH_VBAT:
  29. return 0; // VBAT电压
  30. default:
  31. return 1;
  32. }
  33. return 0;
  34. }
  35. int luat_adc_read(int ch, int *val, int *val2)
  36. {
  37. int voltage = 0;
  38. switch (ch)
  39. {
  40. case 0:
  41. voltage = adc_get_inputVolt(ch, val);
  42. break;
  43. case 1:
  44. voltage = adc_get_inputVolt(ch, val);
  45. break;
  46. case 2:
  47. voltage = adc_get_inputVolt(ch, val);
  48. break;
  49. case 3:
  50. voltage = adc_get_inputVolt(ch, val);
  51. break;
  52. case LUAT_ADC_CH_CPU:
  53. voltage = adc_temp();
  54. *val = voltage;
  55. *val2 = voltage;
  56. return 0;
  57. case LUAT_ADC_CH_VBAT:
  58. voltage = adc_get_interVolt();
  59. *val = voltage;
  60. *val2 = voltage;
  61. return 0;
  62. default:
  63. return 1;
  64. }
  65. *val2 = voltage;
  66. return 0;
  67. }
  68. int luat_adc_close(int ch)
  69. {
  70. switch (ch)
  71. {
  72. case 0:
  73. tls_io_cfg_set(WM_IO_PA_01, WM_IO_OPTION5);
  74. break;
  75. case 1:
  76. tls_io_cfg_set(WM_IO_PA_04, WM_IO_OPTION5);
  77. break;
  78. case 2:
  79. tls_io_cfg_set(WM_IO_PA_03, WM_IO_OPTION5);
  80. break;
  81. case 3:
  82. tls_io_cfg_set(WM_IO_PA_02, WM_IO_OPTION5);
  83. break;
  84. case LUAT_ADC_CH_CPU:
  85. break; // 温度
  86. case LUAT_ADC_CH_VBAT:
  87. break; // 内部电压
  88. default:
  89. return 1;
  90. }
  91. return 0;
  92. }
  93. int luat_adc_global_config(int tp, int val) {
  94. return 0;
  95. }