From 2162a849bbacb1d6c1cf4c4f199c318896eefe39 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 14 Oct 2020 21:50:16 -0600 Subject: configured K9.3 hwdef --- hwdef-Noctigon_K9.3.h | 82 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/hwdef-Noctigon_K9.3.h b/hwdef-Noctigon_K9.3.h index feb49e6..15f93cb 100644 --- a/hwdef-Noctigon_K9.3.h +++ b/hwdef-Noctigon_K9.3.h @@ -1,16 +1,16 @@ -#ifndef HWDEF_NOCTIGON_KR4_H -#define HWDEF_NOCTIGON_KR4_H +#ifndef HWDEF_NOCTIGON_K93_H +#define HWDEF_NOCTIGON_K93_H -/* Noctigon KR4 / D4V2.5 driver layout (attiny1634) +/* Noctigon K9.3 driver layout (attiny1634) * * Pin / Name / Function - * 1 PA6 FET PWM (direct drive) (PWM1B) + * 1 PA6 2nd LED PWM (linear) (PWM1B) * 2 PA5 R: red aux LED (PWM0B) * 3 PA4 G: green aux LED * 4 PA3 B: blue aux LED - * 5 PA2 button LED (D4V2.5 only) - * 6 PA1 (none) - * 7 PA0 (none) + * 5 PA2 button LED + * 6 PA1 Opamp 2 enable (2nd LEDs) + * 7 PA0 Opamp 1 enable (main LEDs) * 8 GND GND * 9 VCC VCC * 10 PC5 (none) @@ -18,12 +18,12 @@ * 12 PC3 RESET * 13 PC2 (none) * 14 PC1 SCK - * 15 PC0 (none) PWM0A + * 15 PC0 main LED PWM (FET) (PWM0A) * 16 PB3 main LED PWM (linear) (PWM1A) - * 17 PB2 MISO / e-switch (PCINT10) + * 17 PB2 MISO * 18 PB1 MOSI / battery voltage (ADC6) - * 19 PB0 Opamp power - * 20 PA7 (none) + * 19 PB0 (none) + * 20 PA7 e-switch (PCINT7) * ADC12 thermal sensor * * Main LED power uses one pin to turn the Opamp on/off, @@ -40,30 +40,31 @@ #define ATTINY 1634 #include -#define PWM_CHANNELS 2 +#define PWM_CHANNELS 2 // 3 actually, but only 2 for main LEDs #define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz #define PWM_TOP 1023 -#define SWITCH_PIN PB2 // pin 17 -#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt -#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] -#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] -#define SWITCH_PORT PINB // PINA or PINB or PINC -#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] - -// the button tends to short out the voltage divider, -// so ignore voltage while the button is being held -//#define NO_LVP_WHILE_BUTTON_PRESSED - +#define SWITCH_PIN PA7 // pin 20 +#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt +#define SWITCH_PCIE PCIE0 // PCIE1 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK1 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC +#define PCINT_vect PCINT0_vect // ISR for PCINT[7:0] #define PWM1_PIN PB3 // pin 16, Opamp reference #define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 -#define PWM2_PIN PA6 // pin 1, DD FET PWM -#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 +#define PWM2_PIN PC0 // pin 15, DD FET PWM +#define PWM2_LVL OCR0A // OCR0A is the output compare register for PC0 + +#define PWM3_PIN PA6 // pin 1, 2nd LED Opamp reference +#define PWM3_LVL OCR1B // OCR1B is the output compare register for PA6 -#define LED_ENABLE_PIN PB0 // pin 19, Opamp power -#define LED_ENABLE_PORT PORTB // control port for PB0 +#define LED_ENABLE_PIN PA0 // pin 7, Opamp power +#define LED_ENABLE_PORT PORTA // control port for PA0 + +#define LED2_ENABLE_PIN PA1 // pin 6, Opamp power +#define LED2_ENABLE_PORT PORTA // control port for PA1 #define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened @@ -113,20 +114,21 @@ // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { // enable output ports - // Opamp level and Opamp on/off - DDRB = (1 << PWM1_PIN) - | (1 << LED_ENABLE_PIN); - // DD FET PWM, aux R/G/B, button LED - DDRA = (1 << PWM2_PIN) + DDRC = (1 << PWM2_PIN); + DDRB = (1 << PWM1_PIN); + DDRA = (1 << PWM3_PIN) | (1 << AUXLED_R_PIN) | (1 << AUXLED_G_PIN) | (1 << AUXLED_B_PIN) | (1 << BUTTON_LED_PIN) + | (1 << LED_ENABLE_PIN); + | (1 << LED2_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]: 0,0,1,1: PWM, Phase Correct, 10-bit (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) @@ -139,9 +141,21 @@ inline void hwdef_setup() { | (0<