1
#ifndef HWDEF_WURKKOS_TS25_T1616_H
2
#define HWDEF_WURKKOS_TS25_T1616_H
4
/* BLF Q8 driver layout using the Attiny1616
8
* PWM FET: PB0 (TCA0 WO0)
9
* PWM 1x7135: PB1 (TCA0 WO1)
18
#define LAYOUT_DEFINED
26
#define PWM_CHANNELS 2
32
#define SWITCH_PIN PIN5_bp
33
#define SWITCH_PORT VPORTA.IN
34
#define SWITCH_ISC_REG PORTA.PIN2CTRL
35
#define SWITCH_VECT PORTA_PORT_vect
36
#define SWITCH_INTFLG VPORTA.INTFLAGS
42
#define PWM1_PIN PB1 //
43
#define PWM1_LVL TCA0.SINGLE.CMP1BUF // CMP1 is the output compare register for PB1
48
#define PWM2_PIN PB0 //
49
#define PWM2_LVL TCA0.SINGLE.CMP0BUF // CMP0 is the output compare register for PB0
52
// PWM parameters of both channels are tied together because they share a counter
53
#define PWM1_TOP TCA0.SINGLE.PERBUF // holds the TOP value for for variable-resolution PWM
54
// not necessary when double-buffered "BUF" registers are used
55
#define PWM1_CNT TCA0.SINGLE.CNT // for resetting phase after each TOP adjustment
56
#define PWM1_PHASE_RESET_OFF // force reset while shutting off
57
#define PWM1_PHASE_RESET_ON // force reset while turning on
59
// average drop across diode on this hardware
60
#ifndef VOLTAGE_FUDGE_FACTOR
61
#define VOLTAGE_FUDGE_FACTOR 7 // add 0.35V
65
// this driver allows for aux LEDs under the optic
66
#define AUXLED_B_PIN PIN1_bp // pin 1
67
#define AUXLED_R_PIN PIN2_bp // pin 2
68
#define AUXLED_G_PIN PIN3_bp // pin 3
69
#define AUXLED_RGB_PORT PORTC // PORTA or PORTB or PORTC
72
// with so many pins, doing this all with #ifdefs gets awkward...
73
// ... so just hardcode it in each hwdef file instead
74
inline void hwdef_setup() {
76
// set up the system clock to run at 10 MHz instead of the default 3.33 MHz
77
_PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm );
80
VPORTB.DIR = PIN0_bm | PIN1_bm; // Outputs: PWMs
81
VPORTC.DIR = PIN1_bm | PIN2_bm | PIN3_bm;
83
// enable pullups on the unused pins to reduce power
84
PORTA.PIN0CTRL = PORT_PULLUPEN_bm;
85
PORTA.PIN1CTRL = PORT_PULLUPEN_bm;
86
PORTA.PIN2CTRL = PORT_PULLUPEN_bm;
87
PORTA.PIN3CTRL = PORT_PULLUPEN_bm;
88
PORTA.PIN4CTRL = PORT_PULLUPEN_bm;
89
PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // eSwitch
90
PORTA.PIN6CTRL = PORT_PULLUPEN_bm;
91
PORTA.PIN7CTRL = PORT_PULLUPEN_bm;
93
//PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // FET channel
94
//PORTB.PIN1CTRL = PORT_PULLUPEN_bm; // 7135 channel
95
PORTB.PIN2CTRL = PORT_PULLUPEN_bm;
96
PORTB.PIN3CTRL = PORT_PULLUPEN_bm;
97
PORTB.PIN4CTRL = PORT_PULLUPEN_bm;
98
PORTB.PIN5CTRL = PORT_PULLUPEN_bm;
100
PORTC.PIN0CTRL = PORT_PULLUPEN_bm;
101
//PORTC.PIN1CTRL = PORT_PULLUPEN_bm; // RGB Aux
102
//PORTC.PIN2CTRL = PORT_PULLUPEN_bm; // RGB Aux
103
//PORTC.PIN3CTRL = PORT_PULLUPEN_bm; // RGB Aux
106
// https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf
107
// PB0 is TCA0:WO0, use TCA_SINGLE_CMP0EN_bm
108
// PB1 is TCA0:WO1, use TCA_SINGLE_CMP1EN_bm
109
// PB2 is TCA0:WO2, use TCA_SINGLE_CMP2EN_bm
110
// For Fast (Single Slope) PWM use TCA_SINGLE_WGMODE_SINGLESLOPE_gc
111
// For Phase Correct (Dual Slope) PWM use TCA_SINGLE_WGMODE_DSBOTTOM_gc
112
// See the manual for other pins, clocks, configs, portmux, etc
113
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc;
115
TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm;