~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to ToyKeeper/hwdef-Wurkkos_TS25.h

  • Committer: Gabriel Hart
  • Date: 2022-11-14 21:12:58 UTC
  • Revision ID: gabe@ghart.com-20221114211258-l9gp5vtd1q3czygo
Adding Wurkkos TS25 hwdef file, I missed that when adding the TS25 model on 2022-08-17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef HWDEF_WURKKOS_TS25_T1616_H
 
2
#define HWDEF_WURKKOS_TS25_T1616_H
 
3
 
 
4
/* BLF Q8 driver layout using the Attiny1616
 
5
 
 
6
Driver pinout:
 
7
 * eSwitch:    PA5
 
8
 * PWM FET:    PB0 (TCA0 WO0)
 
9
 * PWM 1x7135: PB1 (TCA0 WO1)
 
10
 * Voltage:    VCC
 
11
 * Aux Blue:   PC1
 
12
 * Aux Red:    PC2
 
13
 * Aux Green:  PC3
 
14
 
 
15
*/
 
16
 
 
17
 
 
18
#define LAYOUT_DEFINED
 
19
 
 
20
#ifdef ATTINY
 
21
#undef ATTINY
 
22
#endif
 
23
#define ATTINY 1616
 
24
#include <avr/io.h>
 
25
 
 
26
#define PWM_CHANNELS 2
 
27
#define PWM_BITS 16
 
28
#define PWM_TOP 255
 
29
#define USE_DYN_PWM
 
30
 
 
31
#ifndef SWITCH_PIN
 
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
 
37
#endif
 
38
 
 
39
 
 
40
// 7135 channel
 
41
#ifndef PWM1_PIN
 
42
#define PWM1_PIN PB1               //
 
43
#define PWM1_LVL TCA0.SINGLE.CMP1BUF  // CMP1 is the output compare register for PB1
 
44
#endif
 
45
 
 
46
// FET channel
 
47
#ifndef PWM2_PIN
 
48
#define PWM2_PIN PB0               //
 
49
#define PWM2_LVL TCA0.SINGLE.CMP0BUF  // CMP0 is the output compare register for PB0
 
50
#endif
 
51
 
 
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
 
58
 
 
59
// average drop across diode on this hardware
 
60
#ifndef VOLTAGE_FUDGE_FACTOR
 
61
#define VOLTAGE_FUDGE_FACTOR 7  // add 0.35V
 
62
#endif
 
63
 
 
64
 
 
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
 
70
 
 
71
 
 
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() {
 
75
 
 
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 );
 
78
 
 
79
    //VPORTA.DIR = ...;
 
80
    VPORTB.DIR = PIN0_bm | PIN1_bm;  // Outputs: PWMs
 
81
    VPORTC.DIR = PIN1_bm | PIN2_bm | PIN3_bm;
 
82
 
 
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;
 
92
 
 
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;
 
99
 
 
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
 
104
 
 
105
    // set up the PWM
 
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;
 
114
    PWM1_TOP = PWM_TOP;
 
115
    TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm;
 
116
}
 
117
 
 
118
 
 
119
#endif