36
36
* not to change brightness.
42
39
#define ATTINY 1634
43
40
#include <avr/io.h>
45
#define PWM_CHANNELS 1
46
#define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz
43
#define HWDEF_C_FILE hwdef-noctigon-k1.c
46
// allow using aux LEDs as extra channel modes
47
#include "chan-rgbaux.h"
52
#define NUM_CHANNEL_MODES (1 + NUM_RGB_AUX_CHANNEL_MODES)
58
#define DEFAULT_CHANNEL_MODE CM_MAIN
60
// right-most bit first, modes are in fedcba9876543210 order
61
#define CHANNEL_MODES_ENABLED 0b0000000000000001
63
//#define USE_CHANNEL_MODE_ARGS
64
//#define CHANNEL_MODE_ARGS 0,0,0,0,0,0,0,0
67
#define PWM_CHANNELS 1 // old, remove this
69
#define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz
70
#define PWM_GET PWM_GET16
71
#define PWM_DATATYPE uint16_t // is used for PWM_TOPS (which goes way over 255)
72
#define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255
73
#define PWM1_DATATYPE uint16_t // linear ramp
75
#define PWM_TOP ICR1 // holds the TOP value for variable-resolution PWM
76
#define PWM_TOP_INIT 1023 // highest value used in top half of ramp
77
#define PWM_CNT TCNT1 // for dynamic PWM, reset phase
80
#define CH1_PIN PB3 // pin 16, Opamp reference
81
#define CH1_PWM OCR1A // OCR1A is the output compare register for PB3
82
#define CH1_ENABLE_PIN PB0 // pin 19, Opamp power
83
#define CH1_ENABLE_PORT PORTB // control port for PB0
49
86
#define SWITCH_PIN PA7 // pin 20
50
87
#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt
51
88
#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0]
52
89
#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0]
53
90
#define SWITCH_PORT PINA // PINA or PINB or PINC
55
#define PWM1_PIN PB3 // pin 16, Opamp reference
56
#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3
58
#define LED_ENABLE_PIN PB0 // pin 19, Opamp power
59
#define LED_ENABLE_PORT PORTB // control port for PB0
91
#define SWITCH_PUE PUEA // pullup group A
92
#define PCINT_vect PCINT0_vect // ISR for PCINT[7:0]
62
95
#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
78
111
// Raw ADC readings at 4.4V and 2.2V
79
112
// calibrate the voltage readout here
80
113
// estimated / calculated values are:
81
// (voltage - D1) * (R2/(R2+R1) * 256 / 1.1)
114
// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1)
82
115
// D1, R1, R2 = 0, 330, 100
84
117
//#define ADC_44 981 // raw value at 4.40V
97
130
#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC
98
131
#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC
100
// with so many pins, doing this all with #ifdefs gets awkward...
101
// ... so just hardcode it in each hwdef file instead
102
134
inline void hwdef_setup() {
103
// enable output ports
104
// Opamp level and Opamp on/off
105
DDRB = (1 << PWM1_PIN)
106
| (1 << LED_ENABLE_PIN);
108
DDRA = (1 << AUXLED_R_PIN)
109
| (1 << AUXLED_G_PIN)
110
| (1 << AUXLED_B_PIN)
114
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
115
// pre-scale for timer: N = 1
116
// WGM1[3:0]: 0,0,1,1: PWM, Phase Correct, 10-bit (DS table 12-5)
117
// CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
118
// COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
119
// COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4)
120
TCCR1A = (1<<WGM11) | (1<<WGM10) // 10-bit (TOP=0x03FF) (DS table 12-5)
121
| (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
122
| (0<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
124
TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
125
| (0<<WGM13) | (0<<WGM12) // phase-correct PWM (DS table 12-5)
129
//PORTA = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC?
130
PUEA = (1 << SWITCH_PIN); // pull-up for e-switch
131
SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
135
// enable output ports
136
// Opamp level and Opamp on/off
137
DDRB = (1 << CH1_PIN)
138
| (1 << CH1_ENABLE_PIN);
140
DDRA = (1 << AUXLED_R_PIN)
141
| (1 << AUXLED_G_PIN)
142
| (1 << AUXLED_B_PIN)
146
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
147
// pre-scale for timer: N = 1
148
// WGM1[3:0]: 0,0,1,1: PWM, Phase Correct, 10-bit (DS table 12-5)
149
// CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
150
// COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
151
// COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4)
152
TCCR1A = (1<<WGM11) | (1<<WGM10) // 10-bit (TOP=0x03FF) (DS table 12-5)
153
| (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
154
| (0<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
156
TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
157
| (0<<WGM13) | (0<<WGM12) // phase-correct PWM (DS table 12-5)
160
// set PWM resolution
161
//PWM_TOP = PWM_TOP_INIT;
164
SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch
165
SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
134
169
#define LAYOUT_DEFINED