Fix/projectkb/alice/right spacebar layout size from 2.25 to 2.7… (#6984)
[jackhill/qmk/firmware.git] / drivers / avr / analog.h
CommitLineData
23839b8c 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
f7bca5c4
JH
17#ifndef _analog_h_included__
18#define _analog_h_included__
19
20#include <stdint.h>
21
fa71c4c9 22#ifdef __cplusplus
23extern "C" {
24#endif
b624f32f 25void analogReference(uint8_t mode);
f7bca5c4
JH
26int16_t analogRead(uint8_t pin);
27int16_t adc_read(uint8_t mux);
fa71c4c9 28#ifdef __cplusplus
29}
30#endif
f7bca5c4 31
b624f32f 32#define ADC_REF_POWER (1 << REFS0)
33#define ADC_REF_INTERNAL ((1 << REFS1) | (1 << REFS0))
34#define ADC_REF_EXTERNAL (0)
f7bca5c4
JH
35
36// These prescaler values are for high speed mode, ADHSM = 1
37#if F_CPU == 16000000L
b624f32f 38# define ADC_PRESCALER ((1 << ADPS2) | (1 << ADPS1))
f7bca5c4 39#elif F_CPU == 8000000L
b624f32f 40# define ADC_PRESCALER ((1 << ADPS2) | (1 << ADPS0))
f7bca5c4 41#elif F_CPU == 4000000L
b624f32f 42# define ADC_PRESCALER ((1 << ADPS2))
f7bca5c4 43#elif F_CPU == 2000000L
b624f32f 44# define ADC_PRESCALER ((1 << ADPS1) | (1 << ADPS0))
f7bca5c4 45#elif F_CPU == 1000000L
b624f32f 46# define ADC_PRESCALER ((1 << ADPS1))
f7bca5c4 47#else
b624f32f 48# define ADC_PRESCALER ((1 << ADPS0))
f7bca5c4
JH
49#endif
50
51// some avr-libc versions do not properly define ADHSM
52#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
b624f32f 53# if !defined(ADHSM)
54# define ADHSM (7)
55# endif
f7bca5c4
JH
56#endif
57
58#endif