~toykeeper/flashlight-firmware/lume1

« back to all changes in this revision

Viewing changes to ToyKeeper/hwdef-fw3x-lume1.h

  • Committer: Selene Scriven
  • Date: 2020-09-02 22:57:30 UTC
  • Revision ID: bzr@toykeeper.net-20200902225730-osm3hshgyzx1ywsv
imported cfg and hwdef files for lume1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef HWDEF_LUME1_FW3X_REVB_H
 
2
#define HWDEF_LUME1_FW3X_REVB_H
 
3
 
 
4
/* lume1 Driver Rev B for FW3x driver layout (attiny1634)
 
5
 * www.loneoceans.com/labs/ for more information
 
6
 *
 
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) 
 
13
 *   6    PA1   Jumper 1
 
14
 *   7    PA0   Jumper 2 
 
15
 *   8    GND   GND
 
16
 *   9    VCC   VCC
 
17
 *  10    PC5   Jumper 3
 
18
 *  11    PC4   Jumper 4
 
19
 *  12    PC3   RESET
 
20
 *  13    PC2   External Thermal Sensor (ADC11)
 
21
 *  14    PC1   SCK
 
22
 *  15    PC0   N/C
 
23
 *  16    PB3   FET PWM (PWM1A)
 
24
 *  17    PB2   MISO
 
25
 *  18    PB1   MOSI
 
26
 *  19    PB0   ADC5 Voltage Battery Sense (2:1 divider)
 
27
 *  20    PA7   BB_Enable
 
28
 *                              ADC12   internal thermal sensor (not used for lume1)
 
29
 *
 
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
 
32
 * for FET control. 
 
33
 */
 
34
 
 
35
#ifdef ATTINY
 
36
#undef ATTINY
 
37
#endif
 
38
#define ATTINY 1634
 
39
#include <avr/io.h>
 
40
 
 
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
 
44
#define PWM_TOP 1023
 
45
 
 
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
 
51
 
 
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
 
54
 
 
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
 
57
 
 
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
 
61
 
 
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
 
67
*/
 
68
 
 
69
/*
 
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)
 
74
#endif
 
75
*/
 
76
 
 
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
 
87
// divided by ...
 
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
 
92
 
 
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
 
97
// R1 = R2 = 100kR
 
98
#ifndef ADC_44
 
99
#define ADC_44 900
 
100
#endif
 
101
#ifndef ADC_22
 
102
#define ADC_22 450
 
103
#endif
 
104
 
 
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
 
108
 
 
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
 
115
 
 
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
 
123
 
 
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);
 
131
  // FET PWM 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)
 
139
       ;
 
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); 
 
150
  */
 
151
 
 
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
 
162
          ;
 
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
 
165
          ;
 
166
 
 
167
  // set up e-switch
 
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
 
171
}
 
172
 
 
173
#define LAYOUT_DEFINED
 
174
 
 
175
#endif
 
 
b'\\ No newline at end of file'