aboutsummaryrefslogtreecommitdiff
path: root/keyboard/hhkb_rn42
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-09-20 06:12:49 +0900
committertmk <nobody@nowhere>2014-09-20 06:12:49 +0900
commit2015027da325e9f9b602af1f36ceeeebbcd6c78d (patch)
tree65e9f6606bf256ce260475aff1ea4eb0c3ba901b /keyboard/hhkb_rn42
parentd8dd18b4217ce56ee3248e3b09598196e0b6731c (diff)
downloadqmk_firmware-2015027da325e9f9b602af1f36ceeeebbcd6c78d.tar.gz
qmk_firmware-2015027da325e9f9b602af1f36ceeeebbcd6c78d.zip
Add FET swtich for battery ADC
Diffstat (limited to 'keyboard/hhkb_rn42')
-rw-r--r--keyboard/hhkb_rn42/MEMO.txt7
-rw-r--r--keyboard/hhkb_rn42/rn42/battery.c12
2 files changed, 19 insertions, 0 deletions
diff --git a/keyboard/hhkb_rn42/MEMO.txt b/keyboard/hhkb_rn42/MEMO.txt
index 11f64b8c4..2f61574c3 100644
--- a/keyboard/hhkb_rn42/MEMO.txt
+++ b/keyboard/hhkb_rn42/MEMO.txt
@@ -15,12 +15,19 @@ Power saving:
15- deep sleep MCU and BT module(keyboard is not used for long time) 15- deep sleep MCU and BT module(keyboard is not used for long time)
16- deep sleep MCU and turn off BT module(keyboard is not used and not connected) 16- deep sleep MCU and turn off BT module(keyboard is not used and not connected)
17- Battery ADC; switching, high resistance 17- Battery ADC; switching, high resistance
18 - switching gnd end of divider with PF4
19 - high resistor 100K/1M?
20 capacitor 10nF
21 http://www.eevblog.com/forum/beginners/measuring-battery-voltage-without-consuming-current/
18 22
19Improving: 23Improving:
20- BT LED; connecting, linked, sleeping, deep sleeping 24- BT LED; connecting, linked, sleeping, deep sleeping
21- Battry LED; blink(using timer?) 25- Battry LED; blink(using timer?)
22- move rn42 to protocol directory when it becomes reusable stack 26- move rn42 to protocol directory when it becomes reusable stack
23- LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256). 27- LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256).
28- ADC resolution
29 AVR120
30 AVR32138
24 31
25Testing: 32Testing:
26- Factroy reset doesn't work; need to **test again** 10K pull-up is too high? 33- Factroy reset doesn't work; need to **test again** 10K pull-up is too high?
diff --git a/keyboard/hhkb_rn42/rn42/battery.c b/keyboard/hhkb_rn42/rn42/battery.c
index c6988fe33..0320e1baf 100644
--- a/keyboard/hhkb_rn42/rn42/battery.c
+++ b/keyboard/hhkb_rn42/rn42/battery.c
@@ -21,6 +21,10 @@ void battery_init(void)
21 ADMUX = (1<<REFS1) | (1<<REFS0); 21 ADMUX = (1<<REFS1) | (1<<REFS0);
22 ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); 22 ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
23 ADCSRA |= (1<<ADEN); 23 ADCSRA |= (1<<ADEN);
24
25 // ADC disable voltate divider(PF4)
26 DDRF |= (1<<4);
27 PORTF &= ~(1<<4);
24} 28}
25 29
26// Indicator for battery 30// Indicator for battery
@@ -79,6 +83,10 @@ bool battery_charging(void)
79// Returns voltage in mV 83// Returns voltage in mV
80uint16_t battery_voltage(void) 84uint16_t battery_voltage(void)
81{ 85{
86 // ADC disable voltate divider(PF4)
87 DDRF |= (1<<4);
88 PORTF |= (1<<4);
89
82 volatile uint16_t bat; 90 volatile uint16_t bat;
83 //ADCSRA |= (1<<ADEN); 91 //ADCSRA |= (1<<ADEN);
84 92
@@ -98,6 +106,10 @@ uint16_t battery_voltage(void)
98 106
99 //ADCSRA &= ~(1<<ADEN); 107 //ADCSRA &= ~(1<<ADEN);
100 108
109 // ADC disable voltate divider(PF4)
110 DDRF |= (1<<4);
111 PORTF &= ~(1<<4);
112
101 return (bat - BATTERY_ADC_OFFSET) * BATTERY_ADC_RESOLUTION; 113 return (bat - BATTERY_ADC_OFFSET) * BATTERY_ADC_RESOLUTION;
102} 114}
103 115