You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /* Copyright 2015 Jack Humbert
  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 <stdint.h>
  18. #include "quantum.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. void analogReference(uint8_t mode);
  23. int16_t analogReadPin(pin_t pin);
  24. uint8_t pinToMux(pin_t pin);
  25. int16_t adc_read(uint8_t mux);
  26. #ifdef __cplusplus
  27. }
  28. #endif
  29. #define ADC_REF_EXTERNAL 0 // AREF, Internal Vref turned off
  30. #define ADC_REF_POWER _BV(REFS0) // AVCC with external capacitor on AREF pin
  31. #define ADC_REF_INTERNAL (_BV(REFS1) | _BV(REFS0)) // Internal 2.56V Voltage Reference with external capacitor on AREF pin (1.1V for 328P)
  32. // These prescaler values are for high speed mode, ADHSM = 1
  33. #if F_CPU == 16000000L || F_CPU == 12000000L
  34. # define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS1)) // /64
  35. #elif F_CPU == 8000000L
  36. # define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS0)) // /32
  37. #elif F_CPU == 4000000L
  38. # define ADC_PRESCALER (_BV(ADPS2)) // /16
  39. #elif F_CPU == 2000000L
  40. # define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0)) // /8
  41. #elif F_CPU == 1000000L
  42. # define ADC_PRESCALER _BV(ADPS1) // /4
  43. #else
  44. # define ADC_PRESCALER _BV(ADPS0) // /2
  45. #endif