mp_flipper_modflipperzero_adc.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <furi_hal.h>
  2. #include <mp_flipper_modflipperzero.h>
  3. #include <mp_flipper_runtime.h>
  4. #include "mp_flipper_context.h"
  5. inline static FuriHalAdcChannel decode_pin_to_adc_channel(uint8_t pin) {
  6. switch(pin) {
  7. case MP_FLIPPER_GPIO_PIN_PC0:
  8. return FuriHalAdcChannel1;
  9. case MP_FLIPPER_GPIO_PIN_PC1:
  10. return FuriHalAdcChannel2;
  11. case MP_FLIPPER_GPIO_PIN_PC3:
  12. return FuriHalAdcChannel4;
  13. case MP_FLIPPER_GPIO_PIN_PA4:
  14. return FuriHalAdcChannel9;
  15. case MP_FLIPPER_GPIO_PIN_PA6:
  16. return FuriHalAdcChannel11;
  17. case MP_FLIPPER_GPIO_PIN_PA7:
  18. return FuriHalAdcChannel12;
  19. default:
  20. return FuriHalAdcChannelNone;
  21. }
  22. }
  23. inline uint16_t mp_flipper_adc_read_pin(uint8_t raw_pin) {
  24. mp_flipper_context_t* ctx = mp_flipper_context;
  25. furi_check(ctx->adc_handle, "missing ADC handle");
  26. FuriHalAdcChannel channel = decode_pin_to_adc_channel(raw_pin);
  27. return furi_hal_adc_read(ctx->adc_handle, channel);
  28. }
  29. inline float mp_flipper_adc_convert_to_voltage(uint16_t value) {
  30. mp_flipper_context_t* ctx = mp_flipper_context;
  31. furi_check(ctx->adc_handle, "missing ADC handle");
  32. return furi_hal_adc_convert_to_voltage(ctx->adc_handle, value);
  33. }