aboutsummaryrefslogtreecommitdiff
path: root/hw/thefreeman/avr32dd20-devkit
diff options
context:
space:
mode:
Diffstat (limited to 'hw/thefreeman/avr32dd20-devkit')
-rw-r--r--hw/thefreeman/avr32dd20-devkit/anduril.h1
-rw-r--r--hw/thefreeman/avr32dd20-devkit/hwdef.c19
-rw-r--r--hw/thefreeman/avr32dd20-devkit/hwdef.h27
3 files changed, 40 insertions, 7 deletions
diff --git a/hw/thefreeman/avr32dd20-devkit/anduril.h b/hw/thefreeman/avr32dd20-devkit/anduril.h
index 02d5de3..3152183 100644
--- a/hw/thefreeman/avr32dd20-devkit/anduril.h
+++ b/hw/thefreeman/avr32dd20-devkit/anduril.h
@@ -110,6 +110,7 @@
#define PARTY_STROBE_ONTIME 1 // slow down party strobe
#define STROBE_OFF_LEVEL 1 // keep the regulator chip on between pulses
+#define BLIP_LEVEL 1 // same
// smoother candle mode with bigger oscillations
#define CANDLE_AMPLITUDE 40
diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.c b/hw/thefreeman/avr32dd20-devkit/hwdef.c
index 3e5dd79..5b534d2 100644
--- a/hw/thefreeman/avr32dd20-devkit/hwdef.c
+++ b/hw/thefreeman/avr32dd20-devkit/hwdef.c
@@ -30,6 +30,11 @@ void set_level_zero() {
delay_4ms(IN_NFET_DELAY_TIME/4);
IN_NFET_ENABLE_PORT &= ~(1 << IN_NFET_ENABLE_PIN);
+ #ifdef USE_BST_BYPASS
+ // turn off bypass
+ BST_BYPASS_PORT |= (1 << BST_BYPASS_PIN);
+ #endif
+
// turn off boost last
BST_ENABLE_PORT &= ~(1 << BST_ENABLE_PIN); // BST off
}
@@ -48,6 +53,14 @@ void set_level_main(uint8_t level) {
// BST on first, to give it a few extra microseconds to spin up
BST_ENABLE_PORT |= (1 << BST_ENABLE_PIN);
+ #ifdef USE_BST_BYPASS
+ // turn on bypass in li-ion mode
+ if (voltage > DUAL_VOLTAGE_FLOOR)
+ BST_BYPASS_PORT &= ~(1 << BST_BYPASS_PIN); // low = bypass
+ else // turn off bypass in AA/NiMH mode
+ BST_BYPASS_PORT |= (1 << BST_BYPASS_PIN); // high = boost
+ #endif
+
// pre-load ramp data so it can be assigned faster later
// DAC level register is left-aligned
PWM1_DATATYPE dac_lvl = PWM1_GET(level) << 6;
@@ -106,13 +119,13 @@ bool gradual_tick_main(uint8_t gt) {
uint8_t voltage_raw2cooked(uint16_t measurement) {
// In : 65535 * BATTLVL / 1.024V
- // Out: uint8_t: Vbat * 40
+ // Out: uint8_t: Vbat * 50
// BATTLVL = Vbat * (100.0/(330+100)) = Vbat / 4.3
- // So, Out = In * 4.3 / 1600
+ // So, Out = In * 4.3 / 1280
// (plus a bit of fudging to fix the slope and offset,
// based on measuring actual hardware)
uint8_t result = (uint32_t)(measurement + (65535 * 4 / 1024))
- * 43 / 16128;
+ * 43 / 12880;
return result;
}
diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.h b/hw/thefreeman/avr32dd20-devkit/hwdef.h
index f1b6095..5015c24 100644
--- a/hw/thefreeman/avr32dd20-devkit/hwdef.h
+++ b/hw/thefreeman/avr32dd20-devkit/hwdef.h
@@ -28,6 +28,7 @@
* 18 PA1 G: aux green
* 19 PA2 B: aux blue
* 20 PA3 CH: detect charging
+ * or BBY: boost bypass PFET
*
* BST EN enable the boost regulator and Op-Amp
* DAC sets the current, max current depends on Vset voltage divider and Rsense
@@ -35,6 +36,8 @@
* and low value Rsense (high current range, pin high)
* IN- NFET : pull up after BST enable to eliminate startup flash, pull down otherwise
* CH senses the status of the onboard charger
+ * BBY routes power around the boost converter in li-ion 3V mode
+ * (pin low = bypass, pin high = boost)
* BATT LVL : Vbat * (100.0/(330+100))
* LVB is for OTSM firmware, not used here
*/
@@ -77,6 +80,11 @@ enum CHANNEL_MODES {
#define BST_ENABLE_PIN PIN5_bp
#define BST_ENABLE_PORT PORTD_OUT
+// BST bypass
+#define USE_BST_BYPASS
+#define BST_BYPASS_PIN PIN3_bp
+#define BST_BYPASS_PORT PORTA_OUT
+
// HDR
// turns on HDR FET for the high current range
#define HDR_ENABLE_PIN PIN7_bp
@@ -101,8 +109,8 @@ enum CHANNEL_MODES {
// AVR datasheet table 3.1 I/O Multiplexing, PA6 ADC0 = AIN26
#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is regulated
#define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN26_gc
-#define DUAL_VOLTAGE_FLOOR (4*21) // for AA/14500 boost drivers, don't indicate low voltage if below this level
-#define DUAL_VOLTAGE_LOW_LOW (4*7) // the lower voltage range's danger zone 0.7 volts (NiMH)
+#define DUAL_VOLTAGE_FLOOR (21*dV) // for AA/14500 boost drivers, don't indicate low voltage if below this level
+#define DUAL_VOLTAGE_LOW_LOW ( 7*dV) // the lower voltage range's danger zone 0.7 volts (NiMH)
// don't use the default VDD converter
// convert BATT LVL pin readings to FSM volt units
#undef voltage_raw2cooked
@@ -133,7 +141,9 @@ inline void hwdef_setup() {
VPORTA.DIR = PIN0_bm // R
| PIN1_bm // G
| PIN2_bm // B
- //| PIN3_bm // CH
+ #ifdef USE_BST_BYPASS
+ | PIN3_bm // BBY
+ #endif
| PIN7_bm; // HDR
VPORTD.DIR = PIN5_bm // EN
| PIN6_bm // DAC
@@ -143,7 +153,10 @@ inline void hwdef_setup() {
//PORTA.PIN0CTRL = PORT_PULLUPEN_bm; // R
//PORTA.PIN1CTRL = PORT_PULLUPEN_bm; // G
//PORTA.PIN2CTRL = PORT_PULLUPEN_bm; // B
- //PORTA.PIN3CTRL = PORT_PULLUPEN_bm; // CH
+ #ifdef USE_BST_BYPASS
+ PORTA.PIN3CTRL = PORT_PULLUPEN_bm; // BBY
+ BST_BYPASS_PORT |= (1 << BST_BYPASS_PIN);
+ #endif
PORTA.PIN4CTRL = PORT_PULLUPEN_bm;
PORTA.PIN5CTRL = PORT_PULLUPEN_bm;
//PORTA.PIN6CTRL = PORT_PULLUPEN_bm; // BATT LVL
@@ -177,6 +190,12 @@ inline void hwdef_setup() {
// to generate a zero without spending power on the DAC
// (and do this in set_level_zero() too)
+ // TCA/TCB/TCD aren't being used, so turn them off
+ TCA0.SINGLE.CTRLA = 0;
+ TCB0.CTRLA = 0;
+ TCB1.CTRLA = 0;
+ TCD0.CTRLA = 0;
+
}