aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-10-29 04:27:28 -0600
committerSelene ToyKeeper2023-10-29 04:27:28 -0600
commit842cfe6ab5ff989cf876688196b4e11898e2db88 (patch)
tree591e9521d57fc657b42ce8c2d940734e712f5b86 /hw
parentconverted noctigon-k1-sbt90 to new API and switched to dynamic PWM (diff)
downloadanduril-842cfe6ab5ff989cf876688196b4e11898e2db88.tar.gz
anduril-842cfe6ab5ff989cf876688196b4e11898e2db88.tar.bz2
anduril-842cfe6ab5ff989cf876688196b4e11898e2db88.zip
fixed blf-lt1-t1616, after testing on actual hardware
(its DSM interrupt wasn't working at all, and it needed a few other tweaks)
Diffstat (limited to '')
-rw-r--r--hwdef-blf-lt1-t1616.c8
-rw-r--r--hwdef-blf-lt1-t1616.h8
-rw-r--r--hwdef-sofirn-lt1s-pro.h5
3 files changed, 14 insertions, 7 deletions
diff --git a/hwdef-blf-lt1-t1616.c b/hwdef-blf-lt1-t1616.c
index 48a401d..9d268a4 100644
--- a/hwdef-blf-lt1-t1616.c
+++ b/hwdef-blf-lt1-t1616.c
@@ -54,7 +54,7 @@ Channel channels[] = {
void set_level_zero() {
// disable timer overflow interrupt
// (helps improve button press handling from Off state)
- DSM_INTCTRL &= ~DSM_OVF_bm;
+ DSM_INTCTRL = 0;
// turn off all LEDs
ch1_dsm_lvl = 0;
@@ -77,7 +77,7 @@ void set_hw_levels(PWM_DATATYPE ch1, PWM_DATATYPE ch2) {
CH2_PWM = ch2_pwm = ch2 >> 7;
// enable timer overflow interrupt so DSM can work
- DSM_INTCTRL |= DSM_OVF_bm;
+ DSM_INTCTRL = DSM_OVF_bm;
// reset phase when turning on
if (! was_on) PWM_CNT = 0;
@@ -107,6 +107,10 @@ ISR(DSM_vect) {
ch2_dsm += (ch2_dsm_lvl & 0x007f);
ch2_pwm = (ch2_dsm_lvl >> 7) + (ch2_dsm > 0x7f);
ch2_dsm &= 0x7f;
+
+ // clear the interrupt flag to indicate it was handled
+ // as per: https://onlinedocs.microchip.com/pr/GUID-C37FFBA8-82C6-4339-A2B1-ABD9A0F6C162-en-US-8/index.html?GUID-C2A2BEFD-158F-413D-B9D4-0F0556AA79BD
+ DSM_INTFLAGS = DSM_OVF_bm;
}
diff --git a/hwdef-blf-lt1-t1616.h b/hwdef-blf-lt1-t1616.h
index cc6d065..a28ee0f 100644
--- a/hwdef-blf-lt1-t1616.h
+++ b/hwdef-blf-lt1-t1616.h
@@ -65,19 +65,20 @@ enum channel_modes_e {
// timer interrupt for DSM
#define DSM_vect TCA0_OVF_vect
#define DSM_INTCTRL TCA0.SINGLE.INTCTRL
+#define DSM_INTFLAGS TCA0.SINGLE.INTFLAGS
#define DSM_OVF_bm TCA_SINGLE_OVF_bm
// warm LEDs
uint16_t ch1_dsm_lvl;
uint8_t ch1_pwm, ch1_dsm;
#define CH1_PIN PB1
-#define CH1_PWM TCA0.SINGLE.CMP1 // CMP1 is the output compare register for PB1
+#define CH1_PWM TCA0.SINGLE.CMP1BUF // CMP1 is the output compare register for PB1
// cold LEDs
uint16_t ch2_dsm_lvl;
uint8_t ch2_pwm, ch2_dsm;
#define CH2_PIN PB0
-#define CH2_PWM TCA0.SINGLE.CMP0 // CMP0 is the output compare register for PB0
+#define CH2_PWM TCA0.SINGLE.CMP0BUF // CMP0 is the output compare register for PB0
// lighted button
#define AUXLED_PIN PIN5_bp
@@ -106,6 +107,7 @@ inline void hwdef_setup() {
// Outputs
VPORTB.DIR = PIN0_bm // cool white
| PIN1_bm // warm white
+ // | PIN2_bm // for testing on LT1S Pro, disable red channel
| PIN5_bm; // aux LED
//VPORTC.DIR = ...;
@@ -121,7 +123,7 @@ inline void hwdef_setup() {
//PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // cold tint channel
//PORTB.PIN1CTRL = PORT_PULLUPEN_bm; // warm tint channel
- PORTB.PIN2CTRL = PORT_PULLUPEN_bm;
+ PORTB.PIN2CTRL = PORT_PULLUPEN_bm; // comment out for testing on LT1S Pro
PORTB.PIN3CTRL = PORT_PULLUPEN_bm;
PORTB.PIN4CTRL = PORT_PULLUPEN_bm;
//PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Aux LED
diff --git a/hwdef-sofirn-lt1s-pro.h b/hwdef-sofirn-lt1s-pro.h
index 97de7d7..ae6b3bf 100644
--- a/hwdef-sofirn-lt1s-pro.h
+++ b/hwdef-sofirn-lt1s-pro.h
@@ -96,10 +96,11 @@ enum channel_modes_e {
inline void hwdef_setup() {
// set up the system clock to run at 10 MHz instead of the default 3.33 MHz
- _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm );
+ _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB,
+ CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm );
//VPORTA.DIR = ...;
- // Outputs:
+ // Outputs
VPORTB.DIR = PIN0_bm // warm white
| PIN1_bm // cool white
| PIN2_bm // red
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.