1
#ifndef HWDEF_LUME1_FW3X_REVB_H
2
#define HWDEF_LUME1_FW3X_REVB_H
4
/* lume1 Driver Rev B for FW3x driver layout (attiny1634)
5
* www.loneoceans.com/labs/ for more information
7
* Pin / Name / Function in Lume1 Rev B
8
* 1 PA6 Regulated PWM (PWM1B)
9
* 2 PA5 R red aux LED (PWM0B)
10
* 3 PA4 G green aux LED
11
* 4 PA3 B blue aux LED
12
* 5 PA2 e-switch (PCINT2)
20
* 13 PC2 External Thermal Sensor (ADC11)
23
* 16 PB3 FET PWM (PWM1A)
26
* 19 PB0 ADC5 Voltage Battery Sense (2:1 divider)
28
* ADC12 internal thermal sensor (not used for lume1)
30
* Main LED power uses one pin as a global Buck Boost Enable, and
31
* one pin to control the power level via PWM. Another pin is used
41
#define PWM_CHANNELS 2
42
// Added for Lume1 Buck Boost Driver
43
#define PWM_BITS 10 // 0 to 1023 at 3.9 kHz, not 0 to 255 at 15.6 kHz
46
#define SWITCH_PIN PA2 // pin 5
47
#define SWITCH_PCINT PCINT2 // pin 5 pin change interrupt
48
#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0]
49
#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0]
50
#define SWITCH_PORT PINA // PINA or PINB or PINC
52
#define PWM1_PIN PA6 // pin 1, Buck Boost CTRL pin or 7135-eqv PWM
53
#define PWM1_LVL OCR1B // OCR1A is the output compare register for PA6
55
#define PWM2_PIN PB3 // pin 16, FET PWM Pin, but only used as on (1023) or off (0)
56
#define PWM2_LVL OCR1A // OCR1A is the output compare register for PB3
58
// Added for Lume1 Buck Boost Driver
59
#define LED_ENABLE_PIN PA7 // pin 20, BuckBoost Enable
60
#define LED_ENABLE_PORT PORTA // control port for PA7
62
/* // For Jumpers X1 to X4, no SW support yet
63
#define JUMPER1_PIN PA1
64
#define JUMPER2_PIN PA0
65
#define JUMPER3_PIN PC5
66
#define JUMPER4_PIN PC4
70
// average drop across diode on this hardware
71
// not applicable for LUME1 driver
72
#ifndef VOLTAGE_FUDGE_FACTOR
73
#define VOLTAGE_FUDGE_FACTOR 4 // add 0.20V (measured 0.22V)
77
#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
78
#define VOLTAGE_PIN PB0 // Pin 19 PB0 ADC5
79
// pin to ADC mappings are in DS table 19-4
80
#define VOLTAGE_ADC ADC5D // digital input disable pin for PB1
81
// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6
82
#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC5D
83
// DS tables 19-3, 19-4
84
// Bit 7 6 5 4 3 2 1 0
85
// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0
86
// MUX[3:0] = 0, 1, 0, 1 for ADC5 / PB0
88
// REFS[1:0] = 0, 0 for VCC as analog reference at 2.5V
89
// other bits reserved
90
#define ADMUX_VOLTAGE_DIVIDER 0b00000101
91
#define ADC_PRSCL 0x06 // clk/64
93
// Raw ADC readings at 4.4V and 2.2V
94
// calibrate the voltage readout here
95
// estimated / calculated values are:
96
// [(Vbatt)*(R2/(R2+R1)) / 2.5V] * 1023
105
// Default ADMUX_THERM for Temperature is: 0b10001110 in tk-attiny.h
106
// REFS[1:0] as 10 for analog reference at internal 1.1Vref
107
// MUX[3:0] as 1110 for ADC'12' - temperature sensor internal
109
// Modified fsm-adc.c to use different ADMUX and ADC_temperature_handler()
110
// based on USE_EXTERNAL_TEMP_SENSOR
111
// See line 34 and line 209
112
#define USE_EXTERNAL_TEMP_SENSOR
113
#define ADMUX_THERM_EXTERNAL_SENSOR 0b00001011 // VCC reference (2.5V), Channel PC2
114
#define TEMP_CHANNEL 0b00001111
116
// this driver allows for aux LEDs under the optic
117
#define AUXLED_R_PIN PA5 // pin 2
118
#define AUXLED_G_PIN PA4 // pin 3
119
#define AUXLED_B_PIN PA3 // pin 4
120
#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC
121
#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC
122
#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC
124
// with so many pins, doing this all with #ifdefs gets awkward...
125
// ... so just hardcode it in each hwdef file instead
126
// For lume1 driver, no SW support for Auxillary Jumpers X1 to X4 yet!
127
inline void hwdef_setup() {
128
// enable output ports in Data Direction Registers
129
// Buck Boost Enable Pin
130
// DDRA = (1 << LED_ENABLE_PIN);
132
DDRB = (1 << PWM2_PIN);
133
// Main PWM, aux R/G/B
134
DDRA = (1 << PWM1_PIN)
135
| (1 << AUXLED_R_PIN)
136
| (1 << AUXLED_G_PIN)
137
| (1 << AUXLED_B_PIN)
138
| (1 << LED_ENABLE_PIN)
140
//DDRB&=~(1<<VOLTAGE_PIN); // All pins are input by default
141
/* // For Jumpers X1 to X4, no SW support yet
142
DDRA &= (1<<JUMPER1_PIN);
143
DDRA &= (1<<JUMPER2_PIN);
144
DDRC &= (1<<JUMPER3_PIN);
145
DDRC &= (1<<JUMPER4_PIN);
146
PUEA = (1 << JUMPER1_PIN);
147
PUEA = (1 << JUMPER2_PIN);
148
PUEC = (1 << JUMPER3_PIN);
149
PUEC = (1 << JUMPER4_PIN);
152
// configure PWM for 10 bit at 3.9kHz
153
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
154
// pre-scale for timer: N = 1
155
// WGM1[3:0]: 0,0,1,1: PWM, Phase Correct, 10-bit (DS table 12-5)
156
// CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
157
// COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
158
// COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4)
159
TCCR1A = (1<<WGM11) | (1<<WGM10) // 10-bit (TOP=0x03FF) (DS table 12-5)
160
| (1<<COM1A1) | (0<<COM1A0) // PWM 1A Clear OC1A on Compare Match
161
| (1<<COM1B1) | (0<<COM1B0) // PWM 1B Clear OC1B on Compare Match
163
TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
164
| (0<<WGM13) | (0<<WGM12) // PWM, Phase Correct, 10-bit
168
//PORTA = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC?
169
PUEA = (1 << SWITCH_PIN); // pull-up for e-switch
170
SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
173
#define LAYOUT_DEFINED
b'\\ No newline at end of file'