analog.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright 2019 Drew Mills
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "quantum.h"
  18. #include "ch.h"
  19. #include <hal.h>
  20. #if !defined(STM32F0XX) && !defined(STM32F3XX)
  21. #error "Only STM23F0 and STM32F3 devices have ADC support in QMK at this time."
  22. #endif
  23. #if !HAL_USE_ADC
  24. #error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC."
  25. #endif
  26. #if !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4
  27. #error "You need to set one of the 'STM32_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC."
  28. #endif
  29. #if STM32_ADC_DUAL_MODE
  30. #error "STM32 ADC Dual Mode is not supported at this time."
  31. #endif
  32. #if STM32_ADCV3_OVERSAMPLING
  33. #error "STM32 ADCV3 Oversampling is not supported at this time."
  34. #endif
  35. typedef struct {
  36. pin_t pin;
  37. uint8_t adc;
  38. } pin_and_adc;
  39. #define PIN_AND_ADC(p,a) (pin_and_adc){p,a}
  40. // analogReference has been left un-defined for ARM devices.
  41. // void analogReference(uint8_t mode);
  42. adcsample_t analogReadPin(pin_t pin);
  43. adcsample_t analogReadPinAdc(pin_t pin, uint8_t adc);
  44. pin_and_adc pinToMux(pin_t pin);
  45. adcsample_t adc_read(pin_and_adc mux);