37
37
* Some models also have a direct-drive FET for turbo.
43
40
#define ATTINY 1634
44
41
#include <avr/io.h>
46
#define PWM_CHANNELS 2 // override this for the no-FET version
47
#define PWM_BITS 16 // data type needs 16 bits, not 8
48
#define PWM_TOP 255 // highest value used in top half of ramp
49
#define USE_DYN_PWM // dynamic frequency and speed
44
#define HWDEF_C_FILE hwdef-noctigon-kr4.c
47
// allow using aux LEDs as extra channel modes
48
#include "chan-rgbaux.h"
51
// * 0. linear + DD FET stacked
53
#define NUM_CHANNEL_MODES (1 + NUM_RGB_AUX_CHANNEL_MODES)
59
#define DEFAULT_CHANNEL_MODE CM_MAIN
61
// right-most bit first, modes are in fedcba9876543210 order
62
#define CHANNEL_MODES_ENABLED 0b0000000000000001
64
//#define USE_CHANNEL_MODE_ARGS
65
//#define CHANNEL_MODE_ARGS 0,0,0,0,0,0,0,0
68
#define PWM_CHANNELS 2 // old, remove this
70
#define PWM_BITS 16 // dynamic 16-bit, but never goes over 255
71
#define PWM_GET PWM_GET8
72
#define PWM_DATATYPE uint16_t // is used for PWM_TOPS (which goes way over 255)
73
#define PWM_DATATYPE2 uint16_t // only needs 32-bit if ramp values go over 255
74
#define PWM1_DATATYPE uint8_t // linear ramp
75
#define PWM2_DATATYPE uint8_t // DD FET ramp
77
// PWM parameters of both channels are tied together because they share a counter
78
#define PWM_TOP ICR1 // holds the TOP value for variable-resolution PWM
79
#define PWM_TOP_INIT 255 // highest value used in top half of ramp
80
#define PWM_CNT TCNT1 // for dynamic PWM, reset phase
83
#define CH1_PIN PB3 // pin 16, Opamp reference
84
#define CH1_PWM OCR1A // OCR1A is the output compare register for PB3
85
#define CH1_ENABLE_PIN PB0 // pin 19, Opamp power
86
#define CH1_ENABLE_PORT PORTB // control port for PB0
89
#define CH2_PIN PA6 // pin 1, DD FET PWM
90
#define CH2_PWM OCR1B // OCR1B is the output compare register for PA6
51
93
#define SWITCH_PIN PA7 // pin 20
52
94
#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt
53
95
#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0]
54
96
#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0]
55
97
#define SWITCH_PORT PINA // PINA or PINB or PINC
57
#define PWM1_PIN PB3 // pin 16, Opamp reference
58
#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3
59
#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase
60
#define PWM1_PHASE_RESET_OFF // force reset while shutting off
61
#define PWM1_PHASE_RESET_ON // force reset while turning on
62
#define PWM1_PHASE_SYNC // manual sync while changing level
64
#define PWM2_PIN PA6 // pin 1, DD FET PWM
65
#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6
67
// PWM parameters of both channels are tied together because they share a counter
68
#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM
70
#define LED_ENABLE_PIN PB0 // pin 19, Opamp power
71
#define LED_ENABLE_PORT PORTB // control port for PB0
98
#define SWITCH_PUE PUEA // pullup group A
99
#define PCINT_vect PCINT0_vect // ISR for PCINT[7:0]
74
102
#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
114
142
#define BUTTON_LED_DDR DDRA // for all "PA" pins
115
143
#define BUTTON_LED_PUE PUEA // for all "PA" pins
117
// with so many pins, doing this all with #ifdefs gets awkward...
118
// ... so just hardcode it in each hwdef file instead
119
145
inline void hwdef_setup() {
120
// enable output ports
121
// Opamp level and Opamp on/off
122
DDRB = (1 << PWM1_PIN)
123
| (1 << LED_ENABLE_PIN);
124
// DD FET PWM, aux R/G/B, button LED
125
DDRA = (1 << PWM2_PIN)
126
| (1 << AUXLED_R_PIN)
127
| (1 << AUXLED_G_PIN)
128
| (1 << AUXLED_B_PIN)
129
| (1 << BUTTON_LED_PIN)
133
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
134
// pre-scale for timer: N = 1
135
// WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5)
136
// CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
137
// COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
138
// COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4)
139
TCCR1A = (1<<WGM11) | (0<<WGM10) // adjustable PWM (TOP=ICR1) (DS table 12-5)
140
| (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
141
| (1<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
143
TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
144
| (1<<WGM13) | (0<<WGM12) // phase-correct adjustable PWM (DS table 12-5)
147
// set PWM resolution
151
//PORTA = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC?
152
PUEA = (1 << SWITCH_PIN); // pull-up for e-switch
153
SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
146
// enable output ports
147
// Opamp level and Opamp on/off
148
DDRB = (1 << CH1_PIN)
149
| (1 << CH1_ENABLE_PIN);
150
// DD FET PWM, aux R/G/B, button LED
151
DDRA = (1 << CH2_PIN)
152
| (1 << AUXLED_R_PIN)
153
| (1 << AUXLED_G_PIN)
154
| (1 << AUXLED_B_PIN)
155
| (1 << BUTTON_LED_PIN)
159
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
160
// pre-scale for timer: N = 1
161
// WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5)
162
// CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
163
// COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
164
// COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4)
165
TCCR1A = (1<<WGM11) | (0<<WGM10) // adjustable PWM (TOP=ICR1) (DS table 12-5)
166
| (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
167
| (1<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
169
TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
170
| (1<<WGM13) | (0<<WGM12) // phase-correct adjustable PWM (DS table 12-5)
173
// set PWM resolution
174
PWM_TOP = PWM_TOP_INIT;
177
SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch
178
SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
156
182
#define LAYOUT_DEFINED