1
#ifndef HWDEF_BLF_LANTERN_T1616_H
2
#define HWDEF_BLF_LANTERN_T1616_H
4
/* BLF LT1 driver layout using the Attiny1616
9
* PWM FET: PB0 (TCA0 WO0)
10
* PWM 1x7135: PB1 (TCA0 WO1)
16
#define LAYOUT_DEFINED
24
#define PWM_CHANNELS 1
27
#define SWITCH_PIN PIN5_bp
28
#define SWITCH_PORT VPORTA.IN
29
#define SWITCH_ISC_REG PORTA.PIN2CTRL
30
#define SWITCH_VECT PORTA_PORT_vect
31
#define SWITCH_INTFLG VPORTA.INTFLAGS
35
// usually PWM1_LVL would be a hardware register, but we need to abstract
36
// it out to a soft brightness value, in order to handle tint ramping
37
// (this allows smooth thermal regulation to work, and makes things
38
// otherwise simpler and easier)
43
#define PWM1_PIN PB1 //
44
#define TINT1_LVL TCA0.SINGLE.CMP1 // CMP1 is the output compare register for PB1
49
#define PWM2_PIN PB0 //
50
#define TINT2_LVL TCA0.SINGLE.CMP0 // CMP0 is the output compare register for PB0
53
// average drop across diode on this hardware
54
#ifndef VOLTAGE_FUDGE_FACTOR
55
#define VOLTAGE_FUDGE_FACTOR 7 // add 0.35V
61
#define AUXLED_PIN PIN5_bp
62
#define AUXLED_PORT PORTB
66
// with so many pins, doing this all with #ifdefs gets awkward...
67
// ... so just hardcode it in each hwdef file instead
68
inline void hwdef_setup() {
70
// set up the system clock to run at 5 MHz instead of the default 3.33 MHz
71
_PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm );
74
VPORTB.DIR = PIN0_bm | PIN1_bm | PIN5_bm; // Outputs: Aux LED and PWMs
77
// enable pullups on the unused pins to reduce power
78
PORTA.PIN0CTRL = PORT_PULLUPEN_bm;
79
PORTA.PIN1CTRL = PORT_PULLUPEN_bm;
80
PORTA.PIN2CTRL = PORT_PULLUPEN_bm;
81
PORTA.PIN3CTRL = PORT_PULLUPEN_bm;
82
PORTA.PIN4CTRL = PORT_PULLUPEN_bm;
83
PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // eSwitch
84
PORTA.PIN6CTRL = PORT_PULLUPEN_bm;
85
PORTA.PIN7CTRL = PORT_PULLUPEN_bm;
87
//PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // cold tint channel
88
//PORTB.PIN1CTRL = PORT_PULLUPEN_bm; // warm tint channel
89
PORTB.PIN2CTRL = PORT_PULLUPEN_bm;
90
PORTB.PIN3CTRL = PORT_PULLUPEN_bm;
91
PORTB.PIN4CTRL = PORT_PULLUPEN_bm;
92
//PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Aux LED
94
PORTC.PIN0CTRL = PORT_PULLUPEN_bm;
95
PORTC.PIN1CTRL = PORT_PULLUPEN_bm;
96
PORTC.PIN2CTRL = PORT_PULLUPEN_bm;
97
PORTC.PIN3CTRL = PORT_PULLUPEN_bm;
100
// TODO: add references to MCU documentation
101
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc;
102
TCA0.SINGLE.PER = 255;
103
TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm;