diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-09-18 23:00:27 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-09-18 23:00:45 +0200 |
commit | ff979a918dad00eeb0f1f66034c347feedc2ec02 (patch) | |
tree | 748efe954129ad40fec8071bf599c2e21c12df15 /include | |
parent | 4f6973b8500418abf83c2377d09396b8588f7746 (diff) |
lora32u4ii: Add ADC driver
Diffstat (limited to 'include')
-rw-r--r-- | include/arch/lora32u4ii/driver/adc.h | 18 | ||||
-rw-r--r-- | include/arch/lora32u4ii/driver/gpio.h | 11 |
2 files changed, 28 insertions, 1 deletions
diff --git a/include/arch/lora32u4ii/driver/adc.h b/include/arch/lora32u4ii/driver/adc.h new file mode 100644 index 0000000..5f9189a --- /dev/null +++ b/include/arch/lora32u4ii/driver/adc.h @@ -0,0 +1,18 @@ +#ifndef ADC_H +#define ADC_H + +class AVRADC { + private: + AVRADC(AVRADC const ©); + + public: + AVRADC() {} + + int16_t getTemp_mdegC(int16_t offset = 205); + uint16_t getVCC_mV(); + uint16_t getVBat_mV(bool controlCharger); +}; + +extern AVRADC adc; + +#endif diff --git a/include/arch/lora32u4ii/driver/gpio.h b/include/arch/lora32u4ii/driver/gpio.h index ba044d0..61dc867 100644 --- a/include/arch/lora32u4ii/driver/gpio.h +++ b/include/arch/lora32u4ii/driver/gpio.h @@ -3,6 +3,14 @@ #include <avr/io.h> +/* + * lora32u4ii v1.3 pin map: + * + * PB0 -> Charger and Vbat/2 measurement voltage divider enable + * PB5 -> User LED + * PB5 <- Vbat/2 + */ + class GPIO { private: GPIO(const GPIO ©); @@ -40,7 +48,8 @@ class GPIO { }; inline void setup() { - DDRB = _BV(PB5); + // PB5 is both output (user LED) and input (Vbat/2 to ADC). + // Leave it as input by default. } inline volatile uint8_t * pinToPort(uint8_t pin) { if (pin <= pb7) { |