// Emisar 2-channel-plus-FET-joined-into-1-channel // Copyright (C) 2024 Selene ToyKeeper // SPDX-License-Identifier: GPL-3.0-or-later #pragma once /* * Pin / Name / Function * 1 PA6 ch2 LED PWM (linear) (PWM1B) (unused) * 2 PA5 R: red aux LED (PWM0B) * 3 PA4 G: green aux LED * 4 PA3 B: blue aux LED * 5 PA2 button LED * 6 PA1 Opamp 2 enable (channel 2 LEDs) (unused) * 7 PA0 Opamp 1 enable (channel 1 LEDs) * 8 GND GND * 9 VCC VCC * 10 PC5 (none) * 11 PC4 (none) * 12 PC3 RESET * 13 PC2 (none) * 14 PC1 SCK * 15 PC0 ch1 LED PWM (FET) (PWM0A, 8-bit) * 16 PB3 ch1 LED PWM (linear) (PWM1A) * 17 PB2 MISO * 18 PB1 MOSI / battery voltage (ADC6) * 19 PB0 (none) * 20 PA7 e-switch (PCINT7) * ADC12 thermal sensor * * This is used for lights with only 1 set of main LEDs, when using the * 2-channel driver internally. This allows the D4S to have a lighted button. * Hank typically connects only linear ch1 and sometimes the DD FET * to the main LEDs, leaving linear ch2 completely unused. Support is * included in an extra channel mode in case modders decide to use it. * It can raise the maximum regulated level. */ #define HWDEF_C hank/emisar-2ch/fet/joined/hwdef.c // allow using aux LEDs as extra channel modes #include "fsm/chan-rgbaux.h" // channel modes: // * 0. linear (ch1) only // * 1. linear (ch1) + DD FET <-- Hank's primary config, as far as I can tell // x 2. linear (both) + DD FET (not used) #define NUM_CHANNEL_MODES (2 + NUM_RGB_AUX_CHANNEL_MODES) enum channel_modes_e { CM_CH1 = 0, CM_CH1_FET, // <-- default //CM_BOTH_FET, RGB_AUX_ENUMS }; // right-most bit first, modes are in fedcba9876543210 order #define CHANNEL_MODES_ENABLED 0b0000000000000010 //#define USE_CHANNEL_MODE_ARGS // _, _, _, 128=middle CCT, 0=warm-to-cool //#define CHANNEL_MODE_ARGS 0,0,0,RGB_AUX_CM_ARGS #define PWM_CHANNELS 3 // old, remove this #define PWM_BITS 16 // 0 to 32640 (0 to 255 PWM + 0 to 127 DSM) #define PWM_GET PWM_GET16 #define PWM_DATATYPE uint16_t // linear-only ramp #define PWM1_DATATYPE uint16_t #define PWM1_GET(l) PWM_GET16(pwm1_levels, l) // linear part of linear+FET ramp #define PWM2_DATATYPE uint16_t #define PWM2_GET(l) PWM_GET16(pwm2_levels, l) // DD FET part of linear+FET ramp #define PWM3_DATATYPE uint8_t #define PWM3_GET(l) PWM_GET8(pwm3_levels, l) // 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 255 #define PWM_CNT TCNT1 // for checking / resetting phase // (max is (255 << 7), because it's 8-bit PWM plus 7 bits of DSM) #define DSM_TOP (255<<7) // 15-bit resolution leaves 1 bit for carry // timer interrupt for DSM #define DSM_vect TIMER1_OVF_vect #define DSM_INTCTRL TIMSK #define DSM_OVF_bm (1<