aboutsummaryrefslogtreecommitdiff
path: root/hwdef-emisar-2ch.h
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-29 01:19:42 -0600
committerSelene ToyKeeper2023-04-29 01:19:42 -0600
commit9765caab66ab628d763a5148efde80b3c3930b31 (patch)
tree5ec21fdf9a521b0d72820540e81263efc3028da3 /hwdef-emisar-2ch.h
parentjust a todo note for later (diff)
downloadanduril-9765caab66ab628d763a5148efde80b3c3930b31.tar.gz
anduril-9765caab66ab628d763a5148efde80b3c3930b31.tar.bz2
anduril-9765caab66ab628d763a5148efde80b3c3930b31.zip
Noctigon KR4: updated to use new channel system
(also tweaked D4v2 build to match KR4 as much as possible) (also added Extended Simple UI to Hank's config)
Diffstat (limited to '')
-rw-r--r--hwdef-emisar-2ch.h115
1 files changed, 57 insertions, 58 deletions
diff --git a/hwdef-emisar-2ch.h b/hwdef-emisar-2ch.h
index 8b0ffc0..9d1b185 100644
--- a/hwdef-emisar-2ch.h
+++ b/hwdef-emisar-2ch.h
@@ -28,11 +28,12 @@
* ADC12 thermal sensor
*/
-#define HWDEF_C_FILE hwdef-emisar-2ch.c
-
#define ATTINY 1634
#include <avr/io.h>
+#define HWDEF_C_FILE hwdef-emisar-2ch.c
+
+#define USE_CHANNEL_MODES
// channel modes:
// * 0. channel 1 only
// * 1. channel 2 only
@@ -48,11 +49,10 @@
#define CHANNEL_MODES_ENABLED 0b00011111
#define CHANNEL_HAS_ARGS 0b00011000
+#define USE_CHANNEL_MODE_ARGS
// _, _, _, 128=middle CCT, 0=warm-to-cool
#define CHANNEL_MODE_ARGS 0,0,0,128,0
-#define USE_CHANNEL_MODES
-#define USE_CHANNEL_MODE_ARGS
#define SET_LEVEL_MODES set_level_ch1, \
set_level_ch2, \
set_level_both, \
@@ -70,7 +70,7 @@
#define PWM_CHANNELS 1 // old, remove this
-#define PWM_BITS 16 // 0 to 16383 at variable Hz, not 0 to 255 at 16 kHz
+#define PWM_BITS 16 // 0 to 16383 at variable Hz, not 0 to 255 at 16 kHz
#define PWM_GET PWM_GET16
#define PWM_DATATYPE uint16_t
#define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255
@@ -80,7 +80,7 @@
// PWM parameters of both channels are tied together because they share a counter
#define PWM_TOP ICR1 // holds the TOP value for for variable-resolution PWM
-#define PWM_TOP_INIT 511
+#define PWM_TOP_INIT 511 // highest value used in top half of ramp
#define PWM_CNT TCNT1 // for dynamic PWM, reset phase
#define CH1_PIN PB3 // pin 16, Opamp reference
@@ -96,7 +96,7 @@
//#define CH3_PIN PC0 // pin 15, DD FET PWM
//#define CH3_LVL OCR0A // OCR0A is the output compare register for PC0
-
+// e-switch
#ifndef SWITCH_PIN
#define SWITCH_PIN PA7 // pin 20
#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt
@@ -164,59 +164,58 @@ bool gradual_tick_blend(uint8_t gt);
bool gradual_tick_auto(uint8_t gt);
-// with so many pins, doing this all with #ifdefs gets awkward...
-// ... so just hardcode it in each hwdef file instead
inline void hwdef_setup() {
- // enable output ports
- //DDRC = (1 << CH3_PIN);
- DDRB = (1 << CH1_PIN);
- DDRA = (1 << CH2_PIN)
- | (1 << AUXLED_R_PIN)
- | (1 << AUXLED_G_PIN)
- | (1 << AUXLED_B_PIN)
- | (1 << BUTTON_LED_PIN)
- | (1 << CH1_ENABLE_PIN)
- | (1 << CH2_ENABLE_PIN)
- ;
-
- // configure PWM
- // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
- // pre-scale for timer: N = 1
- // Linear opamp PWM for both main and 2nd LEDs (10-bit)
- // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5)
- // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
- // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
- // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4)
- TCCR1A = (1<<WGM11) | (0<<WGM10) // adjustable PWM (TOP=ICR1) (DS table 12-5)
- | (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
- | (1<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
- ;
- TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
- | (1<<WGM13) | (0<<WGM12) // phase-correct adjustable PWM (DS table 12-5)
- ;
-
- // unused on this driver
- // FET PWM (8-bit; this channel can't do 10-bit)
- // WGM0[2:0]: 0,0,1: PWM, Phase Correct, 8-bit (DS table 11-8)
- // CS0[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 11-9)
- // COM0A[1:0]: 1,0: PWM OC0A in the normal direction (DS table 11-4)
- // COM0B[1:0]: 1,0: PWM OC0B in the normal direction (DS table 11-7)
- //TCCR0A = (0<<WGM01) | (1<<WGM00) // 8-bit (TOP=0xFF) (DS table 11-8)
- // | (1<<COM0A1) | (0<<COM0A0) // PWM 0A in normal direction (DS table 11-4)
- // //| (1<<COM0B1) | (0<<COM0B0) // PWM 0B in normal direction (DS table 11-7)
- // ;
- //TCCR0B = (0<<CS02) | (0<<CS01) | (1<<CS00) // clk/1 (no prescaling) (DS table 11-9)
- // | (0<<WGM02) // phase-correct PWM (DS table 11-8)
- // ;
- //CH3_LVL = 0; // ensure this channel is off, if it exists
-
- // set PWM resolution
- PWM_TOP = PWM_TOP_INIT;
-
- // set up e-switch
- SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch
- SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
+ // enable output ports
+ //DDRC = (1 << CH3_PIN);
+ DDRB = (1 << CH1_PIN);
+ DDRA = (1 << CH2_PIN)
+ | (1 << AUXLED_R_PIN)
+ | (1 << AUXLED_G_PIN)
+ | (1 << AUXLED_B_PIN)
+ | (1 << BUTTON_LED_PIN)
+ | (1 << CH1_ENABLE_PIN)
+ | (1 << CH2_ENABLE_PIN)
+ ;
+
+ // configure PWM
+ // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
+ // pre-scale for timer: N = 1
+ // Linear opamp PWM for both main and 2nd LEDs (10-bit)
+ // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5)
+ // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
+ // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
+ // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4)
+ TCCR1A = (1<<WGM11) | (0<<WGM10) // adjustable PWM (TOP=ICR1) (DS table 12-5)
+ | (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
+ | (1<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
+ ;
+ TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
+ | (1<<WGM13) | (0<<WGM12) // phase-correct adjustable PWM (DS table 12-5)
+ ;
+
+ // unused on this driver
+ // FET PWM (8-bit; this channel can't do 10-bit)
+ // WGM0[2:0]: 0,0,1: PWM, Phase Correct, 8-bit (DS table 11-8)
+ // CS0[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 11-9)
+ // COM0A[1:0]: 1,0: PWM OC0A in the normal direction (DS table 11-4)
+ // COM0B[1:0]: 1,0: PWM OC0B in the normal direction (DS table 11-7)
+ //TCCR0A = (0<<WGM01) | (1<<WGM00) // 8-bit (TOP=0xFF) (DS table 11-8)
+ // | (1<<COM0A1) | (0<<COM0A0) // PWM 0A in normal direction (DS table 11-4)
+ // //| (1<<COM0B1) | (0<<COM0B0) // PWM 0B in normal direction (DS table 11-7)
+ // ;
+ //TCCR0B = (0<<CS02) | (0<<CS01) | (1<<CS00) // clk/1 (no prescaling) (DS table 11-9)
+ // | (0<<WGM02) // phase-correct PWM (DS table 11-8)
+ // ;
+ //CH3_LVL = 0; // ensure this channel is off, if it exists
+
+ // set PWM resolution
+ PWM_TOP = PWM_TOP_INIT;
+
+ // set up e-switch
+ SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch
+ SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
}
+
#define LAYOUT_DEFINED