From 9662961f19e4210ac5bb3ea0cf8e99d2a6be5574 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sun, 4 Apr 2021 10:08:42 +0700 Subject: [PATCH] [Keyboard] Add PWM support on Redragon K552-Old (Sonix SN32F248) (#16) * Update PWM for old Redragon K552 * No longer needed that rules --- keyboards/ajazz/ak33/rev1/rules.mk | 4 +- keyboards/redragon/k552/rev1/CT16.h | 259 ++++++ keyboards/redragon/k552/rev1/CT32.h | 82 +- keyboards/redragon/k552/rev1/config.h | 5 - keyboards/redragon/k552/rev1/config_led.h | 7 +- .../k552/rev1/keymaps/default/keymap.c | 28 +- keyboards/redragon/k552/rev1/led_matrix.c | 7 +- keyboards/redragon/k552/rev1/matrix.c | 755 ++++++++++-------- keyboards/redragon/k552/rev1/matrix_2.c | 377 --------- keyboards/redragon/k552/rev1/matrix_base.c | 255 ------ keyboards/redragon/k552/rev1/rules.mk | 4 +- 11 files changed, 720 insertions(+), 1063 deletions(-) create mode 100644 keyboards/redragon/k552/rev1/CT16.h delete mode 100644 keyboards/redragon/k552/rev1/matrix_2.c delete mode 100644 keyboards/redragon/k552/rev1/matrix_base.c diff --git a/keyboards/ajazz/ak33/rev1/rules.mk b/keyboards/ajazz/ak33/rev1/rules.mk index 43ec7d6d3243..56bdbca6f785 100644 --- a/keyboards/ajazz/ak33/rev1/rules.mk +++ b/keyboards/ajazz/ak33/rev1/rules.mk @@ -59,6 +59,4 @@ CUSTOM_MATRIX = yes # Custom RGB matrix handling RGB_MATRIX_ENABLE = yes -RGB_MATRIX_DRIVER = custom - -ALLOW_WARNINGS = yes \ No newline at end of file +RGB_MATRIX_DRIVER = custom \ No newline at end of file diff --git a/keyboards/redragon/k552/rev1/CT16.h b/keyboards/redragon/k552/rev1/CT16.h new file mode 100644 index 000000000000..9f2e4bf00219 --- /dev/null +++ b/keyboards/redragon/k552/rev1/CT16.h @@ -0,0 +1,259 @@ +#ifndef __SN32F240_CT16_H +#define __SN32F240_CT16_H + + +/*_____ I N C L U D E S ____________________________________________________*/ + +/*_____ D E F I N I T I O N S ______________________________________________*/ +/* +Base Address: 0x4000 0000 (CT16B0) + 0x4000 2000 (CT16B1) + 0x4000 4000 (CT16B2) +*/ + +/* CT16Bn Timer Control register (0x00) */ +#define CT16_CEN_DIS 0 //[0:0] CT16Bn enable bit +#define CT16_CEN_EN 1 +#define mskCT16_CEN_DIS (CT16_CEN_DIS<<0) +#define mskCT16_CEN_EN (CT16_CEN_EN<<0) + +#define CT16_CRST 1 //[1:1] CT16Bn counter reset bit +#define mskCT16_CRST (CT16_CRST<<1) + + //[6:4] CT16Bn counting mode selection +#define CT16_CM_EDGE_UP 0 //Edge-aligned Up-counting mode +#define CT16_CM_EDGE_DOWN 1 //Edge-aligned Down-counting mode +#define CT16_CM_CENTER_UP 2 //Center-aligned mode 1. Match interrupt is set during up-counting period +#define CT16_CM_CENTER_DOWN 4 //Center-aligned mode 2. Match interrupt is set during down-counting period +#define CT16_CM_CENTER_BOTH 6 //Center-aligned mode 3. Match interrupt is set during both up and down period. +#define mskCT16_CM_EDGE_UP (CT16_CM_EDGE_UP<<4) +#define mskCT16_CM_EDGE_DOWN (CT16_CM_EDGE_DOWN<<4) +#define mskCT16_CM_CENTER_UP (CT16_CM_CENTER_UP<<4) +#define mskCT16_CM_CENTER_DOWN (CT16_CM_CENTER_DOWN<<4) +#define mskCT16_CM_CENTER_BOTH (CT16_CM_CENTER_BOTH<<4) + +/* CT16Bn Count Control register (0x10) */ + //[1:0] Count/Timer Mode selection. +#define CT16_CTM_TIMER 0 //Timer mode: Every rising PCLK edge. +#define CT16_CTM_CNTER_RISING 1 //Counter mode: TC increments on rising edge of CAP input. +#define CT16_CTM_CNTER_FALLING 2 //Counter mode: TC increments on falling edge of CAP input. +#define CT16_CTM_CNTER_BOTH 3 //Counter mode: TC increments on both edge of CAP input. +#define mskCT16_CTM_TIMER (CT16_CTM_TIMER<<0) +#define mskCT16_CTM_CNTER_RISING (CT16_CTM_CNTER_RISING<<0) +#define mskCT16_CTM_CNTER_FALLING (CT16_CTM_CNTER_FALLING<<0) +#define mskCT16_CTM_CNTER_BOTH (CT16_CTM_CNTER_BOTH<<0) + +#define CT16_CIS 0 //[3:2] Count Input Select +#define mskCT16_CIS (CT16_CIS<<2) + +/* CT16Bn Match Control register (0x14) */ +#define CT16_MR0IE_EN 1 //[0:0] Enable MR0 match interrupt +#define CT16_MR0IE_DIS 0 +#define mskCT16_MR0IE_EN (CT16_MR0IE_EN<<0) +#define mskCT16_MR0IE_DIS (CT16_MR0IE_DIS<<0) + +#define CT16_MR0RST_EN 1 //[1:1] Enable reset TC when MR0 matches TC. +#define CT16_MR0RST_DIS 0 +#define mskCT16_MR0RST_EN (CT16_MR0RST_EN<<1) +#define mskCT16_MR0RST_DIS (CT16_MR0RST_DIS<<1) + +#define CT16_MR0STOP_EN 1 //[2:2] Enable stop TC and clear CEN when MR0 matches TC. +#define CT16_MR0STOP_DIS 0 +#define mskCT16_MR0STOP_EN (CT16_MR0STOP_EN<<2) +#define mskCT16_MR0STOP_DIS (CT16_MR0STOP_DIS<<2) + +#define CT16_MR1IE_EN 1 //[3:3] Enable MR1 match interrupt +#define CT16_MR1IE_DIS 0 +#define mskCT16_MR1IE_EN (CT16_MR1IE_EN<<3) +#define mskCT16_MR1IE_DIS (CT16_MR1IE_DIS<<3) + +#define CT16_MR1RST_EN 1 //[4:4] Enable reset TC when MR1 matches TC. +#define CT16_MR1RST_DIS 0 +#define mskCT16_MR1RST_EN (CT16_MR1RST_EN<<4) +#define mskCT16_MR1RST_DIS (CT16_MR1RST_DIS<<4) + +#define CT16_MR1STOP_EN 1 //[5:5] Enable stop TC and clear CEN when MR1 matches TC. +#define CT16_MR1STOP_DIS 0 +#define mskCT16_MR1STOP_EN (CT16_MR1STOP_EN<<5) +#define mskCT16_MR1STOP_DIS (CT16_MR1STOP_DIS<<5) + +#define CT16_MR2IE_EN 1 //[6:6] Enable MR2 match interrupt +#define CT16_MR2IE_DIS 0 +#define mskCT16_MR2IE_EN (CT16_MR2IE_EN<<6) +#define mskCT16_MR2IE_DIS (CT16_MR2IE_DIS<<6) + +#define CT16_MR2RST_EN 1 //[7:7] Enable reset TC when MR2 matches TC. +#define CT16_MR2RST_DIS 0 +#define mskCT16_MR2RST_EN (CT16_MR2RST_EN<<7) +#define mskCT16_MR2RST_DIS (CT16_MR2RST_DIS<<7) + +#define CT16_MR2STOP_EN 1 //[8:8] Enable stop TC and clear CEN when MR2 matches TC. +#define CT16_MR2STOP_DIS 0 +#define mskCT16_MR2STOP_EN (CT16_MR2STOP_EN<<8) +#define mskCT16_MR2STOP_DIS (CT16_MR2STOP_DIS<<8) + +#define CT16_MR3IE_EN 1 //[9:9] Enable MR3 match interrupt +#define CT16_MR3IE_DIS 0 +#define mskCT16_MR3IE_EN (CT16_MR3IE_EN<<9) +#define mskCT16_MR3IE_DIS (CT16_MR3IE_DIS<<9) + +#define CT16_MR3RST_EN 1 //[10:10] Enable reset TC when MR3 matches TC. +#define CT16_MR3RST_DIS 0 +#define mskCT16_MR3RST_EN (CT16_MR3RST_EN<<10) +#define mskCT16_MR3RST_DIS (CT16_MR3RST_DIS<<10) + +#define CT16_MR3STOP_EN 1 //[11:11] Enable stop TC and clear CEN when MR3 matches TC. +#define CT16_MR3STOP_DIS 0 +#define mskCT16_MR3STOP_EN (CT16_MR3STOP_EN<<11) +#define mskCT16_MR3STOP_DIS (CT16_MR3STOP_DIS<<11) + +/* CT16Bn Capture Control register (0x28) */ +#define CT16_CAP0RE_EN 1 //[0:0] Enable CAP0 capture on rising edge. +#define CT16_CAP0RE_DIS 0 +#define mskCT16_CAP0RE_EN (CT16_CAP0RE_EN<<0) +#define mskCT16_CAP0RE_DIS (CT16_CAP0RE_DIS<<0) + +#define CT16_CAP0FE_EN 1 //[1:1] Enable CAP0 capture on fallng edge. +#define CT16_CAP0FE_DIS 0 +#define mskCT16_CAP0FE_EN (CT16_CAP0FE_EN<<1) +#define mskCT16_CAP0FE_DIS (CT16_CAP0FE_DIS<<1) + +#define CT16_CAP0IE_EN 1 //[2:2] Enable CAP0 interrupt. +#define CT16_CAP0IE_DIS 0 +#define mskCT16_CAP0IE_EN (CT16_CAP0IE_EN<<2) +#define mskCT16_CAP0IE_DIS (CT16_CAP0IE_DIS<<2) + +#define CT16_CAP0EN_EN 1 //[3:3] Enable CAP0 function. +#define CT16_CAP0EN_DIS 0 +#define mskCT16_CAP0EN_EN (CT16_CAP0EN_EN<<3) +#define mskCT16_CAP0EN_DIS (CT16_CAP0EN_DIS<<3) + +/* CT16Bn External Match register (0x30) */ +#define CT16_EM0 1 //[0:0] CT16Bn PWM0 drive state +#define mskCT16_EM0 (CT16_EM0<<0) +#define CT16_EM1 1 //[1:1] CT16Bn PWM1 drive state +#define mskCT16_EM1 (CT16_EM1<<1) +#define CT16_EM2 1 //[2:2] CT16Bn PWM2 drive state +#define mskCT16_EM2 (CT16_EM2<<2) + + + //[5:4] CT16Bn PWM0 functionality +#define CT16_EMC0_DO_NOTHING 0 //Do nothing. +#define CT16_EMC0_LOW 1 //CT16Bn PWM0 pin is low. +#define CT16_EMC0_HIGH 2 //CT16Bn PWM0 pin is high. +#define CT16_EMC0_TOGGLE 3 //Toggle CT16Bn PWM0 pin. +#define mskCT16_EMC0_DO_NOTHING (CT16_EMC0_LOW<<4) +#define mskCT16_EMC0_LOW (CT16_EMC0_LOW<<4) +#define mskCT16_EMC0_HIGH (CT16_EMC0_HIGH<<4) +#define mskCT16_EMC0_TOGGLE (CT16_EMC0_TOGGLE<<4) + + //[7:6] CT16Bn PWM1 functionality +#define CT16_EMC1_DO_NOTHING 0 //Do nothing. +#define CT16_EMC1_LOW 1 //CT16Bn PWM1 pin is low. +#define CT16_EMC1_HIGH 2 //CT16Bn PWM1 pin is high. +#define CT16_EMC1_TOGGLE 3 //Toggle CT16Bn PWM1 pin. +#define mskCT16_EMC1_DO_NOTHING (CT16_EMC1_LOW<<6) +#define mskCT16_EMC1_LOW (CT16_EMC1_LOW<<6) +#define mskCT16_EMC1_HIGH (CT16_EMC1_HIGH<<6) +#define mskCT16_EMC1_TOGGLE (CT16_EMC1_TOGGLE<<6) + + //[9:8] CT16Bn PWM2 functionality +#define CT16_EMC2_DO_NOTHING 0 //Do nothing. +#define CT16_EMC2_LOW 1 //CT16Bn PWM2 pin is low. +#define CT16_EMC2_HIGH 2 //CT16Bn PWM2 pin is high. +#define CT16_EMC2_TOGGLE 3 //Toggle CT16Bn PWM2 pin. +#define mskCT16_EMC2_DO_NOTHING (CT16_EMC2_LOW<<8) +#define mskCT16_EMC2_LOW (CT16_EMC2_LOW<<8) +#define mskCT16_EMC2_HIGH (CT16_EMC2_HIGH<<8) +#define mskCT16_EMC2_TOGGLE (CT16_EMC2_TOGGLE<<8) + + +/* CT16Bn PWM Control register (0x34) */ + //[0:0] CT16Bn PWM0 enable. +#define CT16_PWM0EN_EN 1 // CT16Bn PWM0 is enabled for PWM mode. +#define CT16_PWM0EN_EM0 0 // CT16Bn PWM0 is controlled by EM0. +#define mskCT16_PWM0EN_EN (CT16_PWM0EN_EN<<0) +#define mskCT16_PWM0EN_EM0 (CT16_PWM0EN_EM0<<0) + + //[1:1] CT16Bn PWM1 enable. +#define CT16_PWM1EN_EN 1 // CT16Bn PWM1 is enabled for PWM mode. +#define CT16_PWM1EN_EM1 0 // CT16Bn PWM1 is controlled by EM1. +#define mskCT16_PWM1EN_EN (CT16_PWM1EN_EN<<1) +#define mskCT16_PWM1EN_EM1 (CT16_PWM1EN_EM1<<1) + + //[2:2] CT16Bn PWM2 enable. +#define CT16_PWM2EN_EN 1 // CT16Bn PWM2 is enabled for PWM mode. +#define CT16_PWM2EN_EM2 0 // CT16Bn PWM2 is controlled by EM2. +#define mskCT16_PWM2EN_EN (CT16_PWM2EN_EN<<2) +#define mskCT16_PWM2EN_EM2 (CT16_PWM2EN_EM2<<2) + + //[5:4] CT16Bn PWM0 output mode. +#define CT16_PWM0MODE_1 0 // PWM mode 1. +#define CT16_PWM0MODE_2 1 // PWM mode 2. +#define CT16_PWM0MODE_FORCE_0 2 // Force 0. +#define CT16_PWM0MODE_FORCE_1 3 // Force 1. +#define mskCT16_PWM0MODE_1 (CT16_PWM0MODE_1<<4) +#define mskCT16_PWM0MODE_2 (CT16_PWM0MODE_2<<4) +#define mskCT16_PWM0MODE_FORCE_0 (CT16_PWM0MODE_FORCE_0<<4) +#define mskCT16_PWM0MODE_FORCE_1 (CT16_PWM0MODE_FORCE_1<<4) + + //[7:6] CT16Bn PWM1 output mode. +#define CT16_PWM1MODE_1 0 // PWM mode 1. +#define CT16_PWM1MODE_2 1 // PWM mode 2. +#define CT16_PWM1MODE_FORCE_0 2 // Force 0. +#define CT16_PWM1MODE_FORCE_1 3 // Force 1. +#define mskCT16_PWM1MODE_1 (CT16_PWM1MODE_1<<6) +#define mskCT16_PWM1MODE_2 (CT16_PWM1MODE_2<<6) +#define mskCT16_PWM1MODE_FORCE_0 (CT16_PWM1MODE_FORCE_0<<6) +#define mskCT16_PWM1MODE_FORCE_1 (CT16_PWM1MODE_FORCE_1<<6) + + //[9:8] CT16Bn PWM2 output mode. +#define CT16_PWM2MODE_1 0 // PWM mode 1. +#define CT16_PWM2MODE_2 1 // PWM mode 2. +#define CT16_PWM2MODE_FORCE_0 2 // Force 0. +#define CT16_PWM2MODE_FORCE_1 3 // Force 1. +#define mskCT16_PWM2MODE_1 (CT16_PWM2MODE_1<<8) +#define mskCT16_PWM2MODE_2 (CT16_PWM2MODE_2<<8) +#define mskCT16_PWM2MODE_FORCE_0 (CT16_PWM2MODE_FORCE_0<<8) +#define mskCT16_PWM2MODE_FORCE_1 (CT16_PWM2MODE_FORCE_1<<8) + + //[20:20] CT16Bn PWM0 IO selection. +#define CT16_PWM0IOEN_EN 1 // PWM 0 pin acts as match output. +#define CT16_PWM0IOEN_DIS 0 // PWM 0 pin acts as GPIO. +#define mskCT16_PWM0IOEN_EN (CT16_PWM0IOEN_EN<<20) +#define mskCT16_PWM0IOEN_DIS (CT16_PWM0IOEN_DIS<<20) + + //[21:21] CT16Bn PWM1 IO selection. +#define CT16_PWM1IOEN_EN 1 // PWM 1 pin acts as match output. +#define CT16_PWM1IOEN_DIS 0 // PWM 1 pin acts as GPIO. +#define mskCT16_PWM1IOEN_EN (CT16_PWM1IOEN_EN<<21) +#define mskCT16_PWM1IOEN_DIS (CT16_PWM1IOEN_DIS<<21) + + //[22:22] CT16Bn PWM2 IO selection. +#define CT16_PWM2IOEN_EN 1 // PWM 2 pin acts as match output. +#define CT16_PWM2IOEN_DIS 0 // PWM 2 pin acts as GPIO. +#define mskCT16_PWM2IOEN_EN (CT16_PWM2IOEN_EN<<22) +#define mskCT16_PWM2IOEN_DIS (CT16_PWM2IOEN_DIS<<22) + + +/* CT16Bn Timer Raw Interrupt Status register (0x38) */ +/* CT16Bn Timer Interrupt Clear register (0x3C) */ +/* The bitmask usage of iwCT16Bn_IrqEvent is the same with CT16Bn_RIS*/ +#define mskCT16_MR0IF (0x1<<0) //[0:0] Interrupt flag for match channel 0 +#define mskCT16_MR0IC mskCT16_MR0IF +#define mskCT16_MR1IF (0x1<<1) //[1:1] Interrupt flag for match channel 1 +#define mskCT16_MR1IC mskCT16_MR1IF +#define mskCT16_MR2IF (0x1<<2) //[2:2] Interrupt flag for match channel 2 +#define mskCT16_MR2IC mskCT16_MR2IF +#define mskCT16_MR3IF (0x1<<3) //[3:3] Interrupt flag for match channel 3 +#define mskCT16_MR3IC mskCT16_MR3IF +#define mskCT16_CAP0IF (0x1<<4) //[4:4] Interrupt flag for capture channel 0 +#define mskCT16_CAP0IC mskCT16_CAP0IF + +/*_____ M A C R O S ________________________________________________________*/ + + +/*_____ D E C L A R A T I O N S ____________________________________________*/ + +#endif /*__SN32F240_CT16_H*/ + diff --git a/keyboards/redragon/k552/rev1/CT32.h b/keyboards/redragon/k552/rev1/CT32.h index 84e9a8e5aadc..48e2de98a36b 100644 --- a/keyboards/redragon/k552/rev1/CT32.h +++ b/keyboards/redragon/k552/rev1/CT32.h @@ -9,7 +9,7 @@ Base Address: 0x4000 6000 (CT32B0) 0x4000 8000 (CT32B1) 0x4000 A000 (CT32B2) -*/ +*/ /* CT32Bn Timer Control register (0x00) */ #define CT32_CEN_DIS 0 //[0:0] CT32Bn enable bit @@ -18,17 +18,17 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_CEN_EN (CT32_CEN_EN<<0) #define CT32_CRST 1 //[1:1] CT32Bn counter reset bit -#define mskCT32_CRST (CT32_CRST<<1) +#define mskCT32_CRST (CT32_CRST<<1) - //[6:4] CT32Bn counting mode selection + //[6:4] CT32Bn counting mode selection #define CT32_CM_EDGE_UP 0 //Edge-aligned Up-counting mode #define CT32_CM_EDGE_DOWN 1 //Edge-aligned Down-counting mode #define CT32_CM_CENTER_UP 2 //Center-aligned mode 1. Match interrupt is set during up-counting period #define CT32_CM_CENTER_DOWN 4 //Center-aligned mode 2. Match interrupt is set during down-counting period #define CT32_CM_CENTER_BOTH 6 //Center-aligned mode 3. Match interrupt is set during both up and down period. -#define mskCT32_CM_EDGE_UP (CT32_CM_EDGE_UP<<4) -#define mskCT32_CM_EDGE_DOWN (CT32_CM_EDGE_DOWN<<4) -#define mskCT32_CM_CENTER_UP (CT32_CM_CENTER_UP<<4) +#define mskCT32_CM_EDGE_UP (CT32_CM_EDGE_UP<<4) +#define mskCT32_CM_EDGE_DOWN (CT32_CM_EDGE_DOWN<<4) +#define mskCT32_CM_CENTER_UP (CT32_CM_CENTER_UP<<4) #define mskCT32_CM_CENTER_DOWN (CT32_CM_CENTER_DOWN<<4) #define mskCT32_CM_CENTER_BOTH (CT32_CM_CENTER_BOTH<<4) @@ -38,27 +38,27 @@ Base Address: 0x4000 6000 (CT32B0) #define CT32_CTM_CNTER_RISING 1 //Counter mode: TC increments on rising edge of CAP input. #define CT32_CTM_CNTER_FALLING 2 //Counter mode: TC increments on falling edge of CAP input. #define CT32_CTM_CNTER_BOTH 3 //Counter mode: TC increments on both edge of CAP input. -#define mskCT32_CTM_TIMER (CT32_CTM_TIMER<<0) -#define mskCT32_CTM_CNTER_RISING (CT32_CTM_CNTER_RISING<<0) -#define mskCT32_CTM_CNTER_FALLING (CT32_CTM_CNTER_FALLING<<0) -#define mskCT32_CTM_CNTER_BOTH (CT32_CTM_CNTER_BOTH<<0) +#define mskCT32_CTM_TIMER (CT32_CTM_TIMER<<0) +#define mskCT32_CTM_CNTER_RISING (CT32_CTM_CNTER_RISING<<0) +#define mskCT32_CTM_CNTER_FALLING (CT32_CTM_CNTER_FALLING<<0) +#define mskCT32_CTM_CNTER_BOTH (CT32_CTM_CNTER_BOTH<<0) #define CT32_CIS 0 //[3:2] Count Input Select #define mskCT32_CIS (CT32_CIS<<2) /* CT32Bn Match Control register (0x14) */ #define CT32_MR0IE_EN 1 //[0:0] Enable MR0 match interrupt -#define CT32_MR0IE_DIS 0 +#define CT32_MR0IE_DIS 0 #define mskCT32_MR0IE_EN (CT32_MR0IE_EN<<0) #define mskCT32_MR0IE_DIS (CT32_MR0IE_DIS<<0) #define CT32_MR0RST_EN 1 //[1:1] Enable reset TC when MR0 matches TC. -#define CT32_MR0RST_DIS 0 +#define CT32_MR0RST_DIS 0 #define mskCT32_MR0RST_EN (CT32_MR0RST_EN<<1) #define mskCT32_MR0RST_DIS (CT32_MR0RST_DIS<<1) #define CT32_MR0STOP_EN 1 //[2:2] Enable stop TC and clear CEN when MR0 matches TC. -#define CT32_MR0STOP_DIS 0 +#define CT32_MR0STOP_DIS 0 #define mskCT32_MR0STOP_EN (CT32_MR0STOP_EN<<2) #define mskCT32_MR0STOP_DIS (CT32_MR0STOP_DIS<<2) @@ -68,17 +68,17 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_MR1IE_DIS (CT32_MR1IE_DIS<<3) #define CT32_MR1RST_EN 1 //[4:4] Enable reset TC when MR1 matches TC. -#define CT32_MR1RST_DIS 0 +#define CT32_MR1RST_DIS 0 #define mskCT32_MR1RST_EN (CT32_MR1RST_EN<<4) #define mskCT32_MR1RST_DIS (CT32_MR1RST_DIS<<4) #define CT32_MR1STOP_EN 1 //[5:5] Enable stop TC and clear CEN when MR1 matches TC. -#define CT32_MR1STOP_DIS 0 +#define CT32_MR1STOP_DIS 0 #define mskCT32_MR1STOP_EN (CT32_MR1STOP_EN<<5) #define mskCT32_MR1STOP_DIS (CT32_MR1STOP_DIS<<5) #define CT32_MR2IE_EN 1 //[6:6] Enable MR2 match interrupt -#define CT32_MR2IE_DIS 0 +#define CT32_MR2IE_DIS 0 #define mskCT32_MR2IE_EN (CT32_MR2IE_EN<<6) #define mskCT32_MR2IE_DIS (CT32_MR2IE_DIS<<6) @@ -88,7 +88,7 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_MR2RST_DIS (CT32_MR2RST_DIS<<7) #define CT32_MR2STOP_EN 1 //[8:8] Enable stop TC and clear CEN when MR2 matches TC. -#define CT32_MR2STOP_DIS 0 +#define CT32_MR2STOP_DIS 0 #define mskCT32_MR2STOP_EN (CT32_MR2STOP_EN<<8) #define mskCT32_MR2STOP_DIS (CT32_MR2STOP_DIS<<8) @@ -98,33 +98,33 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_MR3IE_DIS (CT32_MR3IE_DIS<<9) #define CT32_MR3RST_EN 1 //[10:10] Enable reset TC when MR3 matches TC. -#define CT32_MR3RST_DIS 0 +#define CT32_MR3RST_DIS 0 #define mskCT32_MR3RST_EN (CT32_MR3RST_EN<<10) #define mskCT32_MR3RST_DIS (CT32_MR3RST_DIS<<10) #define CT32_MR3STOP_EN 1 //[11:11] Enable stop TC and clear CEN when MR3 matches TC. -#define CT32_MR3STOP_DIS 0 +#define CT32_MR3STOP_DIS 0 #define mskCT32_MR3STOP_EN (CT32_MR3STOP_EN<<11) #define mskCT32_MR3STOP_DIS (CT32_MR3STOP_DIS<<11) /* CT32Bn Capture Control register (0x28) */ #define CT32_CAP0RE_EN 1 //[0:0] Enable CAP0 capture on rising edge. -#define CT32_CAP0RE_DIS 0 +#define CT32_CAP0RE_DIS 0 #define mskCT32_CAP0RE_EN (CT32_CAP0RE_EN<<0) #define mskCT32_CAP0RE_DIS (CT32_CAP0RE_DIS<<0) #define CT32_CAP0FE_EN 1 //[1:1] Enable CAP0 capture on fallng edge. -#define CT32_CAP0FE_DIS 0 +#define CT32_CAP0FE_DIS 0 #define mskCT32_CAP0FE_EN (CT32_CAP0FE_EN<<1) #define mskCT32_CAP0FE_DIS (CT32_CAP0FE_DIS<<1) #define CT32_CAP0IE_EN 1 //[2:2] Enable CAP0 interrupt. -#define CT32_CAP0IE_DIS 0 +#define CT32_CAP0IE_DIS 0 #define mskCT32_CAP0IE_EN (CT32_CAP0IE_EN<<2) #define mskCT32_CAP0IE_DIS (CT32_CAP0IE_DIS<<2) #define CT32_CAP0EN_EN 1 //[3:3] Enable CAP0 function. -#define CT32_CAP0EN_DIS 0 +#define CT32_CAP0EN_DIS 0 #define mskCT32_CAP0EN_EN (CT32_CAP0EN_EN<<3) #define mskCT32_CAP0EN_DIS (CT32_CAP0EN_DIS<<3) @@ -135,7 +135,7 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_EM1 (CT32_EM1<<1) #define CT32_EM2 1 //[2:2] CT32Bn PWM2 drive state #define mskCT32_EM2 (CT32_EM2<<2) -#define CT32_EM3 1 //[3:3] CT32Bn PWM3 drive state +#define CT32_EM3 1 //[3:3] CT32Bn PWM3 drive state #define mskCT32_EM3 (CT32_EM3<<3) //[5:4] CT32Bn PWM0 functionality @@ -180,31 +180,31 @@ Base Address: 0x4000 6000 (CT32B0) /* CT32Bn PWM Control register (0x34) */ //[0:0] CT32Bn PWM0 enable. -#define CT32_PWM0EN_EN 1 // CT32Bn PWM0 is enabled for PWM mode. +#define CT32_PWM0EN_EN 1 // CT32Bn PWM0 is enabled for PWM mode. #define CT32_PWM0EN_EM0 0 // CT32Bn PWM0 is controlled by EM0. #define mskCT32_PWM0EN_EN (CT32_PWM0EN_EN<<0) #define mskCT32_PWM0EN_EM0 (CT32_PWM0EN_EM0<<0) //[1:1] CT32Bn PWM1 enable. -#define CT32_PWM1EN_EN 1 // CT32Bn PWM1 is enabled for PWM mode. +#define CT32_PWM1EN_EN 1 // CT32Bn PWM1 is enabled for PWM mode. #define CT32_PWM1EN_EM1 0 // CT32Bn PWM1 is controlled by EM1. #define mskCT32_PWM1EN_EN (CT32_PWM1EN_EN<<1) #define mskCT32_PWM1EN_EM1 (CT32_PWM1EN_EM1<<1) //[2:2] CT32Bn PWM2 enable. -#define CT32_PWM2EN_EN 1 // CT32Bn PWM2 is enabled for PWM mode. +#define CT32_PWM2EN_EN 1 // CT32Bn PWM2 is enabled for PWM mode. #define CT32_PWM2EN_EM2 0 // CT32Bn PWM2 is controlled by EM2. #define mskCT32_PWM2EN_EN (CT32_PWM2EN_EN<<2) #define mskCT32_PWM2EN_EM2 (CT32_PWM2EN_EM2<<2) //[3:3] CT32Bn PWM3 enable. -#define CT32_PWM3EN_EN 1 // CT32Bn PWM3 is enabled for PWM mode. +#define CT32_PWM3EN_EN 1 // CT32Bn PWM3 is enabled for PWM mode. #define CT32_PWM3EN_EM3 0 // CT32Bn PWM3 is controlled by EM3. #define mskCT32_PWM3EN_EN (CT32_PWM3EN_EN<<3) #define mskCT32_PWM3EN_EM3 (CT32_PWM3EN_EM3<<3) //[5:4] CT32Bn PWM0 output mode. -#define CT32_PWM0MODE_1 0 // PWM mode 1. +#define CT32_PWM0MODE_1 0 // PWM mode 1. #define CT32_PWM0MODE_2 1 // PWM mode 2. #define CT32_PWM0MODE_FORCE_0 2 // Force 0. #define CT32_PWM0MODE_FORCE_1 3 // Force 1. @@ -214,7 +214,7 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_PWM0MODE_FORCE_1 (CT32_PWM0MODE_FORCE_1<<4) //[7:6] CT32Bn PWM1 output mode. -#define CT32_PWM1MODE_1 0 // PWM mode 1. +#define CT32_PWM1MODE_1 0 // PWM mode 1. #define CT32_PWM1MODE_2 1 // PWM mode 2. #define CT32_PWM1MODE_FORCE_0 2 // Force 0. #define CT32_PWM1MODE_FORCE_1 3 // Force 1. @@ -224,7 +224,7 @@ Base Address: 0x4000 6000 (CT32B0) #define mskCT32_PWM1MODE_FORCE_1 (CT32_PWM1MODE_FORCE_1<<6) //[9:8] CT32Bn PWM2 output mode. -#define CT32_PWM2MODE_1 0 // PWM mode 1. +#define CT32_PWM2MODE_1 0 // PWM mode 1. #define CT32_PWM2MODE_2 1 // PWM mode 2. #define CT32_PWM2MODE_FORCE_0 2 // Force 0. #define CT32_PWM2MODE_FORCE_1 3 // Force 1. @@ -235,25 +235,25 @@ Base Address: 0x4000 6000 (CT32B0) //[20:20] CT32Bn PWM0 IO selection. #define CT32_PWM0IOEN_EN 1 // PWM 0 pin acts as match output. -#define CT32_PWM0IOEN_DIS 0 // PWM 0 pin acts as GPIO. +#define CT32_PWM0IOEN_DIS 0 // PWM 0 pin acts as GPIO. #define mskCT32_PWM0IOEN_EN (CT32_PWM0IOEN_EN<<20) #define mskCT32_PWM0IOEN_DIS (CT32_PWM0IOEN_DIS<<20) //[21:21] CT32Bn PWM1 IO selection. #define CT32_PWM1IOEN_EN 1 // PWM 1 pin acts as match output. -#define CT32_PWM1IOEN_DIS 0 // PWM 1 pin acts as GPIO. +#define CT32_PWM1IOEN_DIS 0 // PWM 1 pin acts as GPIO. #define mskCT32_PWM1IOEN_EN (CT32_PWM1IOEN_EN<<21) #define mskCT32_PWM1IOEN_DIS (CT32_PWM1IOEN_DIS<<21) //[22:22] CT32Bn PWM2 IO selection. #define CT32_PWM2IOEN_EN 1 // PWM 2 pin acts as match output. -#define CT32_PWM2IOEN_DIS 0 // PWM 2 pin acts as GPIO. +#define CT32_PWM2IOEN_DIS 0 // PWM 2 pin acts as GPIO. #define mskCT32_PWM2IOEN_EN (CT32_PWM2IOEN_EN<<22) #define mskCT32_PWM2IOEN_DIS (CT32_PWM2IOEN_DIS<<22) //[23:23] CT32Bn PWM3 IO selection. -#define CT32_PWM3IOEN_EN 0 // PWM 3 pin acts as match output. -#define CT32_PWM3IOEN_DIS 0 // PWM 3 pin acts as GPIO. +#define CT32_PWM3IOEN_EN 1 // PWM 3 pin acts as match output. +#define CT32_PWM3IOEN_DIS 0 // PWM 3 pin acts as GPIO. #define mskCT32_PWM3IOEN_EN (CT32_PWM3IOEN_EN<<23) #define mskCT32_PWM3IOEN_DIS (CT32_PWM3IOEN_DIS<<23) @@ -261,15 +261,15 @@ Base Address: 0x4000 6000 (CT32B0) /* CT32Bn Timer Interrupt Clear register (0x3C) */ /* The bitmask usage of iwCT32Bn_IrqEvent is the same with CT32Bn_RIS*/ #define mskCT32_MR0IF (0x1<<0) //[0:0] Interrupt flag for match channel 0 -#define mskCT32_MR0IC mskCT32_MR0IF +#define mskCT32_MR0IC mskCT32_MR0IF #define mskCT32_MR1IF (0x1<<1) //[1:1] Interrupt flag for match channel 1 -#define mskCT32_MR1IC mskCT32_MR1IF +#define mskCT32_MR1IC mskCT32_MR1IF #define mskCT32_MR2IF (0x1<<2) //[2:2] Interrupt flag for match channel 2 -#define mskCT32_MR2IC mskCT32_MR2IF +#define mskCT32_MR2IC mskCT32_MR2IF #define mskCT32_MR3IF (0x1<<3) //[3:3] Interrupt flag for match channel 3 -#define mskCT32_MR3IC mskCT32_MR3IF +#define mskCT32_MR3IC mskCT32_MR3IF #define mskCT32_CAP0IF (0x1<<4) //[4:4] Interrupt flag for capture channel 0 -#define mskCT32_CAP0IC mskCT32_CAP0IF +#define mskCT32_CAP0IC mskCT32_CAP0IF /*_____ M A C R O S ________________________________________________________*/ diff --git a/keyboards/redragon/k552/rev1/config.h b/keyboards/redragon/k552/rev1/config.h index 4196a4b130eb..300a0e051774 100644 --- a/keyboards/redragon/k552/rev1/config.h +++ b/keyboards/redragon/k552/rev1/config.h @@ -45,11 +45,6 @@ #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, A14, A15, B0, B1, B2, B3, B4, B10, B11 } #define MATRIX_ROW_PINS { D15, D14, D13, D12, D11, D10 } -#define LED_PIN_ON_STATE 0 -//#define LED_NUM_LOCK_PIN D5 -#define LED_CAPS_LOCK_PIN D6 -#define LED_SCROLL_LOCK_PIN D7 - /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ #define DEBOUNCE 5 diff --git a/keyboards/redragon/k552/rev1/config_led.h b/keyboards/redragon/k552/rev1/config_led.h index 92d97cf204d0..0c87a61e5438 100644 --- a/keyboards/redragon/k552/rev1/config_led.h +++ b/keyboards/redragon/k552/rev1/config_led.h @@ -24,9 +24,12 @@ along with this program. If not, see . #define LED_MATRIX_ROW_CHANNELS 3 #define LED_MATRIX_ROWS_HW (LED_MATRIX_ROWS * LED_MATRIX_ROW_CHANNELS) #define LED_MATRIX_ROW_PINS { C0, C3, C1, C4, C15, C14, C5, C7, C6, C8, C10, C9, D0, B6, D1, B7, D3, D2 } -//#define LED_MATRIX_ROW_PINS { P2.0, P2.3, P2.1, P2.4, P2.15, P2.14, P2.5, P2.7, P2.6, P2.8, P2.10, P2.9, P3.0, P1.6, P3.1, P1.7, P3.3, P3.2 } #define LED_MATRIX_COLS 17 #define LED_MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, A14, A15, B0, B1, B2, B3, B4, B10, B11 } -#define DRIVER_LED_TOTAL (6*17) \ No newline at end of file +#define DRIVER_LED_TOTAL (6*17) + +#define LED_CAPS_LOCK_PIN D6 +#define LED_SCROLL_LOCK_PIN D7 +#define LED_PIN_ON_STATE 0 \ No newline at end of file diff --git a/keyboards/redragon/k552/rev1/keymaps/default/keymap.c b/keyboards/redragon/k552/rev1/keymaps/default/keymap.c index 502261f3a2f9..2fd572cc8b57 100644 --- a/keyboards/redragon/k552/rev1/keymaps/default/keymap.c +++ b/keyboards/redragon/k552/rev1/keymaps/default/keymap.c @@ -116,7 +116,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐ │   │   │   │   │   │   │   │   │   │   │   │     │     │Vai│ ├────┬───┴┬──┴─┬─┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ - │ │GAME│ │                  │ │ Fn │ │ │ │Hud│Vad│Hui│ + │ │GAME│ │                  │ │ Fn │ │ │ │Hui│Vad│Hud│ └────┴────┴────┴────────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ */ /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */ @@ -125,7 +125,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX}, { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX}, { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, RGB_VAI, XXX}, - { XXX, GAME, XXX, XXX, XXX, MO(_FL), XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, RGB_HUD, RGB_VAD, RGB_HUI} + { XXX, GAME, XXX, XXX, XXX, MO(_FL), XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, RGB_HUI, RGB_VAD, RGB_HUD} }, /* @@ -141,7 +141,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐ │   │   │   │   │   │   │   │   │   │   │   │     │     │Vai│ ├────┬───┴┬──┴─┬─┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ - │ │BASE│ │                  │ │ Fn │ │ │ │Hud│Vad│Hui│ + │ │BASE│ │                  │ │ Fn │ │ │ │Hui│Vad│Hud│ └────┴────┴────┴────────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ */ /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */ @@ -150,28 +150,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX}, { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX}, { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, RGB_VAI, XXX}, - { XXX, BASE, XXX, XXX, XXX, MO(_CL), XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, RGB_HUD, RGB_VAD, RGB_HUI} + { XXX, BASE, XXX, XXX, XXX, MO(_CL), XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, RGB_HUI, RGB_VAD, RGB_HUD} } }; -// Taken from 'g_led_config' in config_led.c -#define CAPS_LOCK_LED_ID 34 -#define SCROLL_LOCK_LED_ID 15 - -void rgb_matrix_indicators_user(void) { - if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) { - rgb_matrix_set_color(CAPS_LOCK_LED_ID, 0xFF, 0x00, 0x00); - } else { - rgb_matrix_set_color(CAPS_LOCK_LED_ID, 0x00, 0x00, 0x00); - } - - if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) { - rgb_matrix_set_color(SCROLL_LOCK_LED_ID, 0xFF, 0x00, 0x00); - } else { - rgb_matrix_set_color(SCROLL_LOCK_LED_ID, 0x00, 0x00, 0x00); - } -} - bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case BASE: @@ -190,4 +172,4 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; } return true; -} +} \ No newline at end of file diff --git a/keyboards/redragon/k552/rev1/led_matrix.c b/keyboards/redragon/k552/rev1/led_matrix.c index 7bfdd99bde80..28e77320fbdd 100644 --- a/keyboards/redragon/k552/rev1/led_matrix.c +++ b/keyboards/redragon/k552/rev1/led_matrix.c @@ -62,4 +62,9 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .flush = flush, .set_color = set_color, .set_color_all = set_color_all, -}; \ No newline at end of file +}; + +void led_set(uint8_t usb_led) { + writePin(LED_CAPS_LOCK_PIN, !IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)); + writePin(LED_SCROLL_LOCK_PIN, !IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)); +} \ No newline at end of file diff --git a/keyboards/redragon/k552/rev1/matrix.c b/keyboards/redragon/k552/rev1/matrix.c index 30c0d0960767..c9881f7ea420 100644 --- a/keyboards/redragon/k552/rev1/matrix.c +++ b/keyboards/redragon/k552/rev1/matrix.c @@ -42,9 +42,7 @@ matrix_row_t last_matrix[MATRIX_ROWS] = {0}; // raw values matrix_row_t matrix[MATRIX_ROWS]; //debounced values static bool matrix_changed = false; -static uint8_t current_col = 0; -//static uint8_t current_row = 0; -static uint8_t current_led_row =0; +static uint8_t current_row = 0; extern volatile LED_TYPE led_state[DRIVER_LED_TOTAL]; @@ -60,50 +58,24 @@ inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } void matrix_print(void) {} -static void select_col(uint8_t col) { - setPinOutput(col_pins[col]); - writePinLow(col_pins[col]); -} - -static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } +static void init_pins(void) { -static void unselect_cols(void) { - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); + // Unselect ROWs + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + setPinInput(row_pins[x]); + writePinHigh(row_pins[x]); } -} -//static void init_pins(void) { -// -// // Unselect ROWs -// for (uint8_t x = 0; x < MATRIX_ROWS; x++) { -// setPinOutput(row_pins[x]); -// writePinHigh(row_pins[x]); -// } -// -// // Unselect COLs -// for (uint8_t x = 0; x < MATRIX_COLS; x++) { -// setPinInput(col_pins[x]); -// writePinHigh(col_pins[x]); -// } -// -//// for (uint8_t x = 0; x < LED_MATRIX_ROWS_HW; x++) { -//// setPinOutput(led_row_pins[x]); -//// writePinHigh(led_row_pins[x]); -//// } -//} - - -static void init_pins(void) { - unselect_cols(); - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); + // Unselect COLs + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + setPinOutput(col_pins[x]); + writePinHigh(col_pins[x]); } - for (uint8_t x = 0; x < LED_MATRIX_ROWS_HW; x++) { + for (uint8_t x = 0; x < LED_MATRIX_ROWS_HW; x++) { setPinOutput(led_row_pins[x]); writePinHigh(led_row_pins[x]); - } + } } void matrix_init(void) { @@ -122,127 +94,175 @@ void matrix_init(void) { debounce_init(MATRIX_ROWS); - while (0) - { - - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - // Turn COL On - setPinOutput(col_pins[x]); - writePinLow(col_pins[x]); -// chThdSleepMilliseconds(100); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) { - - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - - chThdSleepMilliseconds(10); - - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - -// chThdSleepMilliseconds(100); - } - // Turn COL Off - setPinInput(col_pins[x]); - writePinHigh(col_pins[x]); -// chThdSleepMilliseconds(100); - } - } - matrix_init_quantum(); - // Enable Timer Clock -// SN_SYS1->AHBCLKEN_b.CT16B1CLKEN = 1; + // Enable Timer Clocks + SN_SYS1->AHBCLKEN_b.CT16B0CLKEN = 1; + SN_SYS1->AHBCLKEN_b.CT16B1CLKEN = 1; + SN_SYS1->AHBCLKEN_b.CT16B2CLKEN = 1; SN_SYS1->AHBCLKEN_b.CT32B0CLKEN = 1; - - // PFPA - Map most PWM outputs to their PWM A pins - SN_PFPA->CT32B0 = 0x410; -// SN_PFPA->CT16B1 = 0x00006660; - -// // Enable PWM function, IOs and select the PWM modes -// // Enable PWM0-PWM3, PWM8-23 -// SN_CT32B0->EM = (mskCT32_EMC2_TOGGLE); -// SN_CT16B1->PWMCTRL = (mskCT16_PWM0EN_EN \ -// |mskCT16_PWM1EN_EN \ -// |mskCT16_PWM2EN_EN ); \ -// |mskCT16_PWM8EN_EN \ -// |mskCT16_PWM9EN_EN \ -// |mskCT16_PWM10EN_EN \ -// |mskCT16_PWM11EN_EN \ -// |mskCT16_PWM12EN_EN \ -// |mskCT16_PWM13EN_EN \ -// |mskCT16_PWM14EN_EN \ -// |mskCT16_PWM15EN_EN \ -// |mskCT16_PWM16EN_EN \ -// |mskCT16_PWM17EN_EN \ -// |mskCT16_PWM18EN_EN \ -// |mskCT16_PWM19EN_EN \ -// |mskCT16_PWM20EN_EN \ -// |mskCT16_PWM21EN_EN \ -// |mskCT16_PWM22EN_EN \ -// |mskCT16_PWM23EN_EN); -// -// // Enable PWM0-PWM3, PWM8-PWM23 IO - SN_CT32B0->PWMCTRL = - (mskCT32_PWM0EN_EN|mskCT32_PWM0MODE_1|mskCT32_PWM0IOEN_EN - |mskCT32_PWM1EN_EN|mskCT32_PWM1MODE_1|mskCT32_PWM1IOEN_EN - |mskCT32_PWM2EN_EN|mskCT32_PWM2MODE_1|mskCT32_PWM2IOEN_EN); -// SN_CT16B1->PWMCTRL |= (mskCT16_PWM0IOEN_EN \ -// |mskCT16_PWM1IOEN_EN \ -// |mskCT16_PWM2IOEN_EN ); \ -// |mskCT16_PWM8IOEN_EN \ -// |mskCT16_PWM9IOEN_EN \ -// |mskCT16_PWM1IO0EN_EN \ -// |mskCT16_PWM1IO1EN_EN \ -// |mskCT16_PWM1IO2EN_EN \ -// |mskCT16_PWM1IO3EN_EN \ -// |mskCT16_PWM1IO4EN_EN \ -// |mskCT16_PWM1IO5EN_EN \ -// |mskCT16_PWM1IO6EN_EN \ -// |mskCT16_PWM1IO7EN_EN \ -// |mskCT16_PWM1IO8EN_EN \ -// |mskCT16_PWM1IO9EN_EN \ -// |mskCT16_PWM2IO0EN_EN \ -// |mskCT16_PWM2IO1EN_EN \ -// |mskCT16_PWM2IO2EN_EN \ -// |mskCT16_PWM2IO3EN_EN); - - // Set match interrupts and TC rest - SN_CT32B0->MCTRL = (mskCT32_MR3IE_EN|mskCT32_MR3RST_EN); + SN_SYS1->AHBCLKEN_b.CT32B1CLKEN = 1; + SN_SYS1->AHBCLKEN_b.CT32B2CLKEN = 1; + + // Set Timer Clock Prescalers + SN_SYS1->APBCP0_b.CT16B0PRE = 0x00; + SN_SYS1->APBCP0_b.CT16B1PRE = 0x00; + SN_SYS1->APBCP1_b.CT16B2PRE = 0x00; + SN_SYS1->APBCP0_b.CT32B0PRE = 0x00; + SN_SYS1->APBCP0_b.CT32B1PRE = 0x00; + SN_SYS1->APBCP0_b.CT32B2PRE = 0x00; + + // PFPA Timer Mapping + // CT16B0 PWM0 P0.0 Col 0 + // PWM1 P0.1 Col 1 + // CT16B1 PWM1 P1.3 Col 13 + // PWM2 P0.15 Col 9 + // CT16B2 PWM0 P0.2 Col 2 + // PWM1 P1.4 Col 14 + // PWM2 P1.0 Col 10 + // CT32B0 PWM0 P0.4 Col 4 + // PWM1 P1.11 Col 16 + // PWM3 P1.2 Col 12 + // CT32B1 PWM1 P1.10 Col 15 + // PWM2 P0.5 Col 5 + // PWM3 P0.7 Col 7 + // CT32B2 PWM0 P1.1 Col 11 + // PWM1 P0.14 Col 8 + // PWM2 P0.3 Col 3 + // PWM3 P0.6 Col 6 + SN_PFPA->CT16B0 = 0x00000; + SN_PFPA->CT16B1 = 0x02330; + SN_PFPA->CT16B2 = 0x02010; + SN_PFPA->CT32B0 = 0x00410; + SN_PFPA->CT32B1 = 0x21300; + SN_PFPA->CT32B2 = 0x00030; + + // Set match interrupts and TC reset for CT16B0, which is used to generate interrupt + SN_CT16B0->MCTRL = (mskCT16_MR3IE_EN|mskCT16_MR3STOP_EN); // COL match register - SN_CT32B0->MR3 = 0xFF; + SN_CT16B0->MR3 = 0xFF; + + // Set prescale value + SN_CT16B0->PRE = 0x30; + SN_CT16B1->PRE = 0x30; + SN_CT16B2->PRE = 0x30; + SN_CT32B0->PRE = 0x30; + SN_CT32B1->PRE = 0x30; + SN_CT32B2->PRE = 0x30; + + // Enable PWM on all timers + SN_CT16B0->PWMCTRL = + (mskCT16_PWM0EN_EN \ + |mskCT16_PWM1EN_EN); + SN_CT16B1->PWMCTRL = + (mskCT16_PWM1EN_EN \ + |mskCT16_PWM2EN_EN); + SN_CT16B2->PWMCTRL = + (mskCT16_PWM0EN_EN \ + |mskCT16_PWM1EN_EN \ + |mskCT16_PWM2EN_EN); + SN_CT32B0->PWMCTRL = + (mskCT32_PWM0EN_EN \ + |mskCT32_PWM1EN_EN \ + |mskCT32_PWM3EN_EN); + SN_CT32B1->PWMCTRL = + (mskCT32_PWM1EN_EN \ + |mskCT32_PWM2EN_EN \ + |mskCT32_PWM3EN_EN); + SN_CT32B2->PWMCTRL = + (mskCT32_PWM0EN_EN \ + |mskCT32_PWM1EN_EN \ + |mskCT32_PWM2EN_EN \ + |mskCT32_PWM3EN_EN); + + // Enable IO + SN_CT16B0->PWMCTRL |= + (mskCT16_PWM0IOEN_EN \ + |mskCT16_PWM1IOEN_EN); + SN_CT16B1->PWMCTRL |= + (mskCT16_PWM1IOEN_EN \ + |mskCT16_PWM2IOEN_EN); + SN_CT16B2->PWMCTRL |= + (mskCT16_PWM0IOEN_EN \ + |mskCT16_PWM1IOEN_EN \ + |mskCT16_PWM2IOEN_EN); + SN_CT32B0->PWMCTRL |= + (mskCT32_PWM0IOEN_EN \ + |mskCT32_PWM1IOEN_EN \ + |mskCT32_PWM3IOEN_EN); + SN_CT32B1->PWMCTRL |= + (mskCT32_PWM1IOEN_EN \ + |mskCT32_PWM2IOEN_EN \ + |mskCT32_PWM3IOEN_EN); + SN_CT32B2->PWMCTRL |= + (mskCT32_PWM0IOEN_EN \ + |mskCT32_PWM1IOEN_EN \ + |mskCT32_PWM2IOEN_EN \ + |mskCT32_PWM3IOEN_EN); + + // Clear match registers + SN_CT16B0->MR0 = 0x0; + SN_CT16B0->MR1 = 0x0; + SN_CT16B0->MR2 = 0x0; + SN_CT16B1->MR0 = 0x0; + SN_CT16B1->MR1 = 0x0; + SN_CT16B1->MR2 = 0x0; + SN_CT16B1->MR3 = 0x0; + SN_CT16B2->MR0 = 0x0; + SN_CT16B2->MR1 = 0x0; + SN_CT16B2->MR2 = 0x0; + SN_CT16B2->MR3 = 0x0; SN_CT32B0->MR0 = 0x0; SN_CT32B0->MR1 = 0x0; SN_CT32B0->MR2 = 0x0; - - // Set prescale value - SN_CT32B0->PRE = 0x30; - - //Set CT16B1 as the up-counting mode. - SN_CT32B0->TMRCTRL = (mskCT32_CRST|mskCT32_CM_EDGE_UP); + SN_CT32B0->MR3 = 0x0; + SN_CT32B1->MR0 = 0x0; + SN_CT32B1->MR1 = 0x0; + SN_CT32B1->MR2 = 0x0; + SN_CT32B1->MR3 = 0x0; + SN_CT32B2->MR0 = 0x0; + SN_CT32B2->MR1 = 0x0; + SN_CT32B2->MR2 = 0x0; + SN_CT32B2->MR3 = 0x0; + + //Set timers to the up-counting mode. + SN_CT16B0->TMRCTRL = (mskCT16_CRST); + SN_CT16B1->TMRCTRL = (mskCT16_CRST); + SN_CT16B2->TMRCTRL = (mskCT16_CRST); + SN_CT32B0->TMRCTRL = (mskCT32_CRST); + SN_CT32B1->TMRCTRL = (mskCT32_CRST); + SN_CT32B2->TMRCTRL = (mskCT32_CRST); // Wait until timer reset done. - while (SN_CT32B0->TMRCTRL & mskCT32_CRST); - - // Let TC start counting. + while( (SN_CT16B0->TMRCTRL & mskCT16_CRST) + || (SN_CT16B1->TMRCTRL & mskCT16_CRST) + || (SN_CT16B2->TMRCTRL & mskCT16_CRST) + || (SN_CT32B0->TMRCTRL & mskCT32_CRST) + || (SN_CT32B1->TMRCTRL & mskCT32_CRST) + || (SN_CT32B2->TMRCTRL & mskCT32_CRST)); + + // Let TC start counting. Start CT16B0 last because it generates our interrupt + SN_CT16B1->TMRCTRL |= mskCT16_CEN_EN; + SN_CT16B2->TMRCTRL |= mskCT16_CEN_EN; SN_CT32B0->TMRCTRL |= mskCT32_CEN_EN; + SN_CT32B1->TMRCTRL |= mskCT32_CEN_EN; + SN_CT32B2->TMRCTRL |= mskCT32_CEN_EN; + SN_CT16B0->TMRCTRL |= mskCT16_CEN_EN; - NVIC_ClearPendingIRQ(CT32B0_IRQn); - nvicEnableVector(CT32B0_IRQn, 0); + NVIC_ClearPendingIRQ(CT16B0_IRQn); + nvicEnableVector(CT16B0_IRQn, 0); } uint8_t matrix_scan(void) { - matrix_changed = false; - for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { - // Determine if the matrix changed state - if ((last_matrix[row_index] != raw_matrix[row_index])) { - matrix_changed = true; - last_matrix[row_index] = raw_matrix[row_index]; + matrix_changed = false; + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Determine if the matrix changed state + if ((last_matrix[row_index] != raw_matrix[row_index])) { + matrix_changed = true; + last_matrix[row_index] = raw_matrix[row_index]; + } } } @@ -259,237 +279,266 @@ uint8_t hw_row_to_matrix_row[18] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 * * @isr */ -OSAL_IRQ_HANDLER(SN32_CT32B0_HANDLER) { +OSAL_IRQ_HANDLER(SN32_CT16B0_HANDLER) { chSysDisable(); - - OSAL_IRQ_PROLOGUE(); - // Disable PWM outputs on column pins -// SN_CT16B1->PWMCTRL &= ~(mskCT16_PWM0IOEN_DIS| mskCT16_PWM1IOEN_DIS| mskCT16_PWM2IOEN_DIS); + OSAL_IRQ_PROLOGUE(); + // Disable PWM outputs on column pins + SN_CT16B0->PWMCTRL = 0; + SN_CT16B1->PWMCTRL = 0; + SN_CT16B2->PWMCTRL = 0; SN_CT32B0->PWMCTRL = 0; + SN_CT32B1->PWMCTRL = 0; + SN_CT32B2->PWMCTRL = 0; - SN_CT32B0->IC = mskCT32_MR3IC; // Clear match interrupt status - SN_CT32B0->TMRCTRL = CT32_CRST; - -// // Turn the selected LED row off -// writePinLow(led_row_pins[current_led_row]); - - // Enable current matrix row - select_col(current_col); + SN_CT16B0->IC = mskCT16_MR3IC; // Clear match interrupt status + // Turn the selected row off + writePinLow(led_row_pins[current_row]); // Read the key matrix - for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { - // Check row pin state - if (readPin(row_pins[row_index]) == 0) { - // Pin LO, set col bit - raw_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); - } else { - // Pin HI, clear col bit - raw_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + // Enable the column + writePinLow(col_pins[col_index]); + + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Check row pin state + if (readPin(row_pins[row_index]) == 0) { + // Pin LO, set col bit + raw_matrix[row_index] |= (MATRIX_ROW_SHIFTER << col_index); + } else { + // Pin HI, clear col bit + raw_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << col_index); + } } - } - // Disable current matrix row - unselect_col(current_col); + // Disable the column + for (uint8_t delay_idx = 0; delay_idx < 20; delay_idx++) + { + writePinHigh(col_pins[col_index]); + } + } // Turn the next row on -// current_led_row = (current_led_row + 1) % LED_MATRIX_ROWS_HW; + current_row = (current_row + 1) % LED_MATRIX_ROWS_HW; -// current_col = (current_col + 1) % MATRIX_COLS; - - uint8_t row_idx = hw_row_to_matrix_row[current_led_row]; + uint8_t row_idx = hw_row_to_matrix_row[current_row]; uint16_t row_ofst = row_ofsts[row_idx]; + //Set timers to the up-counting mode. + SN_CT16B0->TMRCTRL = (mskCT16_CRST); + SN_CT16B1->TMRCTRL = (mskCT16_CRST); + SN_CT16B2->TMRCTRL = (mskCT16_CRST); + SN_CT32B0->TMRCTRL = (mskCT32_CRST); + SN_CT32B1->TMRCTRL = (mskCT32_CRST); + SN_CT32B2->TMRCTRL = (mskCT32_CRST); + + // Wait until timer reset done. + while( (SN_CT16B0->TMRCTRL & mskCT16_CRST) + || (SN_CT16B1->TMRCTRL & mskCT16_CRST) + || (SN_CT16B2->TMRCTRL & mskCT16_CRST) + || (SN_CT32B0->TMRCTRL & mskCT32_CRST) + || (SN_CT32B1->TMRCTRL & mskCT32_CRST) + || (SN_CT32B2->TMRCTRL & mskCT32_CRST)); + + if (current_row % 3 == 0) + { + SN_CT16B0->MR0 = led_state[row_ofst + 0 ].r; + SN_CT16B0->MR1 = led_state[row_ofst + 1 ].r; + SN_CT16B2->MR0 = led_state[row_ofst + 2 ].r; + SN_CT32B2->MR2 = led_state[row_ofst + 3 ].r; + SN_CT32B0->MR0 = led_state[row_ofst + 4 ].r; + SN_CT32B1->MR2 = led_state[row_ofst + 5 ].r; + SN_CT32B2->MR3 = led_state[row_ofst + 6 ].r; + SN_CT32B1->MR3 = led_state[row_ofst + 7 ].r; + SN_CT32B2->MR1 = led_state[row_ofst + 8 ].r; + SN_CT16B1->MR2 = led_state[row_ofst + 9 ].r; + SN_CT16B2->MR2 = led_state[row_ofst + 10].r; + SN_CT32B2->MR0 = led_state[row_ofst + 11].r; + SN_CT32B0->MR3 = led_state[row_ofst + 12].r; + SN_CT16B1->MR1 = led_state[row_ofst + 13].r; + SN_CT16B2->MR1 = led_state[row_ofst + 14].r; + SN_CT32B1->MR1 = led_state[row_ofst + 15].r; + SN_CT32B0->MR1 = led_state[row_ofst + 16].r; + } + + if (current_row % 3 == 1) + { + SN_CT16B0->MR0 = led_state[row_ofst + 0 ].g; + SN_CT16B0->MR1 = led_state[row_ofst + 1 ].g; + SN_CT16B2->MR0 = led_state[row_ofst + 2 ].g; + SN_CT32B2->MR2 = led_state[row_ofst + 3 ].g; + SN_CT32B0->MR0 = led_state[row_ofst + 4 ].g; + SN_CT32B1->MR2 = led_state[row_ofst + 5 ].g; + SN_CT32B2->MR3 = led_state[row_ofst + 6 ].g; + SN_CT32B1->MR3 = led_state[row_ofst + 7 ].g; + SN_CT32B2->MR1 = led_state[row_ofst + 8 ].g; + SN_CT16B1->MR2 = led_state[row_ofst + 9 ].g; + SN_CT16B2->MR2 = led_state[row_ofst + 10].g; + SN_CT32B2->MR0 = led_state[row_ofst + 11].g; + SN_CT32B0->MR3 = led_state[row_ofst + 12].g; + SN_CT16B1->MR1 = led_state[row_ofst + 13].g; + SN_CT16B2->MR1 = led_state[row_ofst + 14].g; + SN_CT32B1->MR1 = led_state[row_ofst + 15].g; + SN_CT32B0->MR1 = led_state[row_ofst + 16].g; + } + + if (current_row % 3 == 2) + { + SN_CT16B0->MR0 = led_state[row_ofst + 0 ].b; + SN_CT16B0->MR1 = led_state[row_ofst + 1 ].b; + SN_CT16B2->MR0 = led_state[row_ofst + 2 ].b; + SN_CT32B2->MR2 = led_state[row_ofst + 3 ].b; + SN_CT32B0->MR0 = led_state[row_ofst + 4 ].b; + SN_CT32B1->MR2 = led_state[row_ofst + 5 ].b; + SN_CT32B2->MR3 = led_state[row_ofst + 6 ].b; + SN_CT32B1->MR3 = led_state[row_ofst + 7 ].b; + SN_CT32B2->MR1 = led_state[row_ofst + 8 ].b; + SN_CT16B1->MR2 = led_state[row_ofst + 9 ].b; + SN_CT16B2->MR2 = led_state[row_ofst + 10].b; + SN_CT32B2->MR0 = led_state[row_ofst + 11].b; + SN_CT32B0->MR3 = led_state[row_ofst + 12].b; + SN_CT16B1->MR1 = led_state[row_ofst + 13].b; + SN_CT16B2->MR1 = led_state[row_ofst + 14].b; + SN_CT32B1->MR1 = led_state[row_ofst + 15].b; + SN_CT32B0->MR1 = led_state[row_ofst + 16].b; + } + + // Enable PWM on all timers + if(SN_CT16B0->MR0 > 0) + { + SN_CT16B0->PWMCTRL |= + (mskCT16_PWM0EN_EN \ + |mskCT16_PWM0IOEN_EN); + } + if(SN_CT16B0->MR1 > 0) + { + SN_CT16B0->PWMCTRL |= + (mskCT16_PWM1EN_EN \ + |mskCT16_PWM1IOEN_EN); + } + if(SN_CT16B2->MR0 > 0) + { + SN_CT16B2->PWMCTRL |= + (mskCT16_PWM0EN_EN \ + |mskCT16_PWM0IOEN_EN); + } + if(SN_CT32B2->MR2 > 0) + { + SN_CT32B2->PWMCTRL |= + (mskCT32_PWM2EN_EN \ + |mskCT32_PWM2IOEN_EN); + } + if(SN_CT32B0->MR0 > 0) + { + SN_CT32B0->PWMCTRL |= + (mskCT32_PWM0EN_EN \ + |mskCT32_PWM0IOEN_EN); + } + if(SN_CT32B1->MR2 > 0) + { + SN_CT32B1->PWMCTRL |= + (mskCT32_PWM2EN_EN \ + |mskCT32_PWM2IOEN_EN); + } + if(SN_CT32B2->MR3 > 0) + { + SN_CT32B2->PWMCTRL |= + (mskCT32_PWM3EN_EN \ + |mskCT32_PWM3IOEN_EN); + } + if(SN_CT32B1->MR3 > 0) + { + SN_CT32B1->PWMCTRL |= + (mskCT32_PWM3EN_EN \ + |mskCT32_PWM3IOEN_EN); + } + if(SN_CT32B2->MR1 > 0) + { + SN_CT32B2->PWMCTRL |= + (mskCT32_PWM1EN_EN \ + |mskCT32_PWM1IOEN_EN); + } + if(SN_CT16B1->MR2 > 0) + { + SN_CT16B1->PWMCTRL |= + (mskCT16_PWM2EN_EN \ + |mskCT16_PWM2IOEN_EN); + } + if(SN_CT16B2->MR2 > 0) + { + SN_CT16B2->PWMCTRL |= + (mskCT16_PWM2EN_EN \ + |mskCT16_PWM2IOEN_EN); + } + if(SN_CT32B2->MR0 > 0) + { + SN_CT32B2->PWMCTRL |= + (mskCT32_PWM0EN_EN \ + |mskCT32_PWM0IOEN_EN); + } + if(SN_CT32B0->MR3 > 0) + { + SN_CT32B0->PWMCTRL |= + (mskCT32_PWM3EN_EN \ + |mskCT32_PWM3IOEN_EN); + } + if(SN_CT16B1->MR1 > 0) + { + SN_CT16B1->PWMCTRL |= + (mskCT16_PWM1EN_EN \ + |mskCT16_PWM1IOEN_EN); + } + if(SN_CT16B2->MR1 > 0) + { + SN_CT16B2->PWMCTRL |= + (mskCT16_PWM1EN_EN \ + |mskCT16_PWM1IOEN_EN); + } + if(SN_CT32B1->MR1 > 0) + { + SN_CT32B1->PWMCTRL |= + (mskCT32_PWM1EN_EN \ + |mskCT32_PWM1IOEN_EN); + } + if(SN_CT32B0->MR1 > 0) + { + SN_CT32B0->PWMCTRL |= + (mskCT32_PWM1EN_EN \ + |mskCT32_PWM1IOEN_EN); + } -// for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { -// // Turn COL On -// setPinOutput(col_pins[col_index]); -// writePinLow(col_pins[col_index]); - // chThdSleepMilliseconds(10); -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y += 3) { -// // On -// // setPinInput(led_row_pins[y]); -// setPinOutput(led_row_pins[y]); -// setPinOutput(led_row_pins[y+1]); -// setPinOutput(led_row_pins[y+2]); -// writePin(led_row_pins[y], (led_state[current_col * 17 + y / 3].r) > 127); -// writePin(led_row_pins[y+1], 0); -// writePin(led_row_pins[y+2], 0); -//// chThdSleepMilliseconds(5); -// -// // } -// // -// // ; -// // -// // chThdSleepMilliseconds(100); -// // -// // for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) -// // { -// // Off -// // setPinOutput(led_row_pins[y]); -// // writePinLow(led_row_pins[y]); -// // chThdSleepMilliseconds(1000); -// } - - // Turn COL Off -// setPinInput(col_pins[col_index]); -// writePinHigh(col_pins[col_index]); - // chThdSleepMilliseconds(10); -// } - select_col(current_col); - - // for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y += 3) { - writePin(led_row_pins[0], led_state[current_col + 0 * 17].r > 127); -// SN_CT32B0->MR2 = led_state[current_col + 0 * 17].r | 1; - writePin(led_row_pins[1], led_state[current_col + 0 * 17].b > 127); - writePin(led_row_pins[2], led_state[current_col + 0 * 17].g > 127); - - writePin(led_row_pins[3], led_state[current_col + 1 * 17].r > 127); - writePin(led_row_pins[4], led_state[current_col + 1 * 17].b > 127); - // SN_CT32B0->MR0 = led_state[current_col + 1 * 17].g | 1; - writePin(led_row_pins[5], led_state[current_col + 1 * 17].g > 127); - // SN_CT32B0->MR2 = led_state[current_col + 1 * 17].b | 1; - - writePin(led_row_pins[6], led_state[current_col + 2 * 17].r > 127); - writePin(led_row_pins[7], led_state[current_col + 2 * 17].b > 127); - writePin(led_row_pins[8], led_state[current_col + 2 * 17].g > 127); - - writePin(led_row_pins[9], led_state[current_col + 3 * 17].r > 127); - writePin(led_row_pins[10], led_state[current_col + 3 * 17].b > 127); - writePin(led_row_pins[11], led_state[current_col + 3 * 17].g > 127); - - writePin(led_row_pins[12], led_state[current_col + 4 * 17].r > 127); - writePin(led_row_pins[13], led_state[current_col + 4 * 17].b > 127); - writePin(led_row_pins[14], led_state[current_col + 4 * 17].g > 127); - - writePin(led_row_pins[15], led_state[current_col + 5 * 17].r > 127); - writePin(led_row_pins[16], led_state[current_col + 5 * 17].b > 127); -// SN_CT32B0->MR2 = led_state[current_col + 5 * 17].g | 1; - writePin(led_row_pins[17], led_state[current_col + 5 * 17].g > 127); - // } - - unselect_col(current_col); - - current_col = (current_col + 1) % MATRIX_COLS; - - - // for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) { -// if (current_led_row % 3 == 0) { -//// SN_CT16B1->MR8 = led_state[row_ofst + 0].b | 1; -//// SN_CT16B1->MR9 = led_state[row_ofst + 1].b | 1; -//// SN_CT16B1->MR10 = led_state[row_ofst + 2].b | 1; -//// SN_CT16B1->MR11 = led_state[row_ofst + 3].b | 1; -//// SN_CT16B1->MR12 = led_state[row_ofst + 4].b | 1; -//// SN_CT16B1->MR13 = led_state[row_ofst + 5].b | 1; -//// SN_CT16B1->MR14 = led_state[row_ofst + 6].b | 1; -//// SN_CT16B1->MR15 = led_state[row_ofst + 7].b | 1; -//// SN_CT16B1->MR16 = led_state[row_ofst + 8].b | 1; -//// SN_CT16B1->MR17 = led_state[row_ofst + 9].b | 1; -//// SN_CT16B1->MR18 = led_state[row_ofst + 10].b | 1; -//// SN_CT16B1->MR19 = led_state[row_ofst + 11].b | 1; -//// SN_CT16B1->MR20 = led_state[row_ofst + 12].b | 1; -//// SN_CT16B1->MR21 = led_state[row_ofst + 13].b | 1; -//// SN_CT16B1->MR22 = led_state[row_ofst + 14].b | 1; -//// SN_CT16B1->MR23 = led_state[row_ofst + 15].b | 1; -// SN_CT32B0->MR0 = led_state[row_ofst + 16].b | 1; -// SN_CT32B0->MR1 = led_state[row_ofst + 17].b | 1; -// SN_CT32B0->MR2 = led_state[row_ofst + 18].b | 1; -// } -// -// if (current_led_row % 3 == 1) { -//// SN_CT16B1->MR8 = led_state[row_ofst + 0].g | 1; -//// SN_CT16B1->MR9 = led_state[row_ofst + 1].g | 1; -//// SN_CT16B1->MR10 = led_state[row_ofst + 2].g | 1; -//// SN_CT16B1->MR11 = led_state[row_ofst + 3].g | 1; -//// SN_CT16B1->MR12 = led_state[row_ofst + 4].g | 1; -//// SN_CT16B1->MR13 = led_state[row_ofst + 5].g | 1; -//// SN_CT16B1->MR14 = led_state[row_ofst + 6].g | 1; -//// SN_CT16B1->MR15 = led_state[row_ofst + 7].g | 1; -//// SN_CT16B1->MR16 = led_state[row_ofst + 8].g | 1; -//// SN_CT16B1->MR17 = led_state[row_ofst + 9].g | 1; -//// SN_CT16B1->MR18 = led_state[row_ofst + 10].g | 1; -//// SN_CT16B1->MR19 = led_state[row_ofst + 11].g | 1; -//// SN_CT16B1->MR20 = led_state[row_ofst + 12].g | 1; -//// SN_CT16B1->MR21 = led_state[row_ofst + 13].g | 1; -//// SN_CT16B1->MR22 = led_state[row_ofst + 14].g | 1; -//// SN_CT16B1->MR23 = led_state[row_ofst + 15].g | 1; -// SN_CT32B0->MR0 = led_state[row_ofst + 16].g | 1; -// SN_CT32B0->MR1 = led_state[row_ofst + 17].g | 1; -// SN_CT32B0->MR2 = led_state[row_ofst + 18].g | 1; -// } -// if (current_led_row % 3 == 2) { -//// SN_CT16B1->MR8 = led_state[row_ofst + 0].r | 1; -//// SN_CT16B1->MR9 = led_state[row_ofst + 1].r | 1; -//// SN_CT16B1->MR10 = led_state[row_ofst + 2].r | 1; -//// SN_CT16B1->MR11 = led_state[row_ofst + 3].r | 1; -//// SN_CT16B1->MR12 = led_state[row_ofst + 4].r | 1; -//// SN_CT16B1->MR13 = led_state[row_ofst + 5].r | 1; -//// SN_CT16B1->MR14 = led_state[row_ofst + 6].r | 1; -//// SN_CT16B1->MR15 = led_state[row_ofst + 7].r | 1; -//// SN_CT16B1->MR16 = led_state[row_ofst + 8].r | 1; -//// SN_CT16B1->MR17 = led_state[row_ofst + 9].r | 1; -//// SN_CT16B1->MR18 = led_state[row_ofst + 10].r | 1; -//// SN_CT16B1->MR19 = led_state[row_ofst + 11].r | 1; -//// SN_CT16B1->MR20 = led_state[row_ofst + 12].r | 1; -//// SN_CT16B1->MR21 = led_state[row_ofst + 13].r | 1; -//// SN_CT16B1->MR22 = led_state[row_ofst + 14].r | 1; -//// SN_CT16B1->MR23 = led_state[row_ofst + 15].r | 1; -// SN_CT32B0->MR0 = led_state[row_ofst + 16].r | 1; -// SN_CT32B0->MR1 = led_state[row_ofst + 17].r | 1; -// SN_CT32B0->MR2 = led_state[row_ofst + 18].r | 1; -// } -// } -// -// // Enable PWM outputs on column pins -// SN_CT32B0->PWMCTRL |= mskCT32_PWM0IOEN_EN | mskCT32_PWM1IOEN_EN | mskCT32_PWM2IOEN_EN; - SN_CT32B0->PWMCTRL = - (mskCT32_PWM0EN_EN|mskCT32_PWM0MODE_1|mskCT32_PWM0IOEN_EN - |mskCT32_PWM1EN_EN|mskCT32_PWM1MODE_1|mskCT32_PWM1IOEN_EN - |mskCT32_PWM2EN_EN|mskCT32_PWM2MODE_1|mskCT32_PWM2IOEN_EN); - -// SN_CT16B1->PWMIOENB = (mskCT16_PWM0EN_EN \ -// |mskCT16_PWM1EN_EN \ -// |mskCT16_PWM2EN_EN ); \ -// |mskCT16_PWM8EN_EN \ -// |mskCT16_PWM9EN_EN \ -// |mskCT16_PWM10EN_EN \ -// |mskCT16_PWM11EN_EN \ -// |mskCT16_PWM12EN_EN \ -// |mskCT16_PWM13EN_EN \ -// |mskCT16_PWM14EN_EN \ -// |mskCT16_PWM15EN_EN \ -// |mskCT16_PWM16EN_EN \ -// |mskCT16_PWM17EN_EN \ -// |mskCT16_PWM18EN_EN \ -// |mskCT16_PWM19EN_EN \ -// |mskCT16_PWM20EN_EN \ -// |mskCT16_PWM21EN_EN \ -// |mskCT16_PWM22EN_EN \ -// |mskCT16_PWM23EN_EN); - - // Set match interrupts and TC rest - SN_CT32B0->MCTRL = (mskCT32_MR3IE_EN|mskCT32_MR3RST_EN); + // Set match interrupts and TC rest for CT16B0, which is used to generate interrupt + SN_CT16B0->MCTRL = (mskCT16_MR3IE_EN|mskCT16_MR3STOP_EN); // COL match register - SN_CT32B0->MR3 = 0xFF; - SN_CT32B0->MR0 = 0x0; - SN_CT32B0->MR1 = 0x0; - SN_CT32B0->MR2 = 0x0; - - // Set prescale value + SN_CT16B0->MR3 = 0xFF; + + // Set prescale value + SN_CT16B0->PRE = 0x30; + SN_CT16B1->PRE = 0x30; + SN_CT16B2->PRE = 0x30; SN_CT32B0->PRE = 0x30; + SN_CT32B1->PRE = 0x30; + SN_CT32B2->PRE = 0x30; + + writePinHigh(led_row_pins[current_row]); -// writePinHigh(led_row_pins[current_led_row]); + // Let TC start counting. Start CT16B0 last because it generates our interrupt + SN_CT16B1->TMRCTRL |= mskCT16_CEN_EN; + SN_CT16B2->TMRCTRL |= mskCT16_CEN_EN; + SN_CT32B0->TMRCTRL |= mskCT32_CEN_EN; + SN_CT32B1->TMRCTRL |= mskCT32_CEN_EN; + SN_CT32B2->TMRCTRL |= mskCT32_CEN_EN; + SN_CT16B0->TMRCTRL |= mskCT16_CEN_EN; + + chSysEnable(); - chSysEnable(); - OSAL_IRQ_EPILOGUE(); } void HardFault_Handler(void) { NVIC_SystemReset(); -} \ No newline at end of file +} diff --git a/keyboards/redragon/k552/rev1/matrix_2.c b/keyboards/redragon/k552/rev1/matrix_2.c deleted file mode 100644 index 590d233166dd..000000000000 --- a/keyboards/redragon/k552/rev1/matrix_2.c +++ /dev/null @@ -1,377 +0,0 @@ -#include -/* - * Copyright 2011 Jun Wako - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Ported to QMK by Stephen Peery - */ - -#include -#include -#include -#include "ch.h" -#include "hal.h" - -#include "wait.h" -#include "util.h" -#include "matrix.h" -#include "debounce.h" -#include "quantum.h" -#include "color.h" - -static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -static const pin_t led_row_pins[LED_MATRIX_ROWS_HW] = LED_MATRIX_ROW_PINS; -static uint16_t row_ofsts[LED_MATRIX_ROWS]; - -matrix_row_t raw_matrix[MATRIX_ROWS]; //raw values -matrix_row_t last_matrix[MATRIX_ROWS] = {0}; // raw values -matrix_row_t matrix[MATRIX_ROWS]; //debounced values - -static bool matrix_changed = false; -static uint8_t current_row = 0; - -extern volatile LED_TYPE led_state[DRIVER_LED_TOTAL]; - -__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } - -__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } - -__attribute__((weak)) void matrix_init_user(void) {} - -__attribute__((weak)) void matrix_scan_user(void) {} - -__WEAK inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } - -__WEAK void matrix_print(void) {} - - -_Noreturn void color_loop(void); - -static void select_col (uint8_t col) -{ - setPinInput(col_pins[col]); - writePinHigh(col_pins[col]); -} - -static void unselect_col (uint8_t col) -{ - setPinOutput(col_pins[col]); - writePinLow(col_pins[col]); -} - -static void select_row (uint8_t row) -{ - setPinOutput(row_pins[row]); - writePinLow(row_pins[row]); -} - -static void unselect_row (uint8_t row) -{ - setPinInputHigh(row_pins[row]); -} - -static void unselect_rows (void) -{ - for (uint8_t x = 0; x < MATRIX_ROWS; x++) - { - unselect_row(x); - } -} - -static void init_pins(void) { - - // Unselect ROWs - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInput(row_pins[x]); - writePinHigh(row_pins[x]); - } - - // Unselect COLs - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinOutput(col_pins[x]); - writePinHigh(col_pins[x]); - } - - for (uint8_t x = 0; x < LED_MATRIX_ROWS_HW; x++) { - setPinOutput(led_row_pins[x]); - writePinHigh(led_row_pins[x]); - } -} - -static bool read_cols_on_row (matrix_row_t current_matrix[], uint8_t current_row) -{ - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[current_row]; - - // Clear data in matrix row - current_matrix[current_row] = 0; - - // Select row and wait for row selecton to stabilize - select_row(current_row); - wait_us(30); - - // For each col... - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) - { - // Set pin to input - select_col(col_index); - - // Select the col pin to read (active low) - uint8_t pin_state = readPin(col_pins[col_index]); - - // Set pin to output - unselect_col(col_index); - - // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - - // Unselect row - unselect_row(current_row); - - return last_row_value != current_matrix[current_row]; -} - -void matrix_init (void) -{ - // initialize key pins - init_pins(); - - // initialize matrix state: all keys off - for (uint8_t i = 0; i < MATRIX_ROWS; i++) - { - raw_matrix[i] = 0; - matrix[i] = 0; - } - - debounce_init(MATRIX_ROWS); - - color_loop(); - - matrix_init_quantum(); -} - -#if 1 -uint8_t matrix_scan(void) { - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { - // Determine if the matrix changed state - if ((last_matrix[row_index] != raw_matrix[row_index])) { - matrix_changed = true; - last_matrix[row_index] = raw_matrix[row_index]; - } - } - } - - debounce(raw_matrix, matrix, MATRIX_ROWS, matrix_changed); - - matrix_scan_quantum(); - - return matrix_changed; -} - -#else -uint8_t matrix_scan (void) -{ - bool changed = false; - - volatile uint32_t col_index = 1; - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - } - - while (1) - { - for (uint32_t x = 0; x < sizeof(col_pins) / sizeof(col_pins[0]); x++) - { - setPinOutput(col_pins[x]); - writePinLow(col_pins[x]); - - // writePinHigh(col_pins[x]); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - } - - // for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - // { - //// On - //// setPinInput(led_row_pins[y]); - // setPinOutput(led_row_pins[y]); - // writePinHigh(led_row_pins[y]); - // } - - chThdSleepMilliseconds(1); - setPinInput(col_pins[x]); - - // setPinInput(col_pins[col_index]); - } - } - - chThdSleepMilliseconds(5000); - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - } - - // for (uint8_t x = 0; x < MATRIX_COLS; x++) - while (1) - { - for (uint32_t x = 0; x < sizeof(col_pins) / col_pins[0]; x++) - { - setPinOutput(col_pins[x]); - writePinLow(col_pins[x]); - - // setPinInput(col_pins[col_index]); - } - - // Turn COL On -// writePinHigh(col_pins[col_index]); -// chThdSleepMilliseconds(10); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - chThdSleepMilliseconds(100); - - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - } - - for (uint8_t y = 0; y < LED_MATRIX_ROWS; y++) - { - } - - // Turn COL Off - // setPinInput(col_pins[col_index]); - - // writePinHigh(col_pins[col_index]); - chThdSleepMilliseconds(10); - } - - //// Set row, read cols - // for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) - // { - // changed |= read_cols_on_row(raw_matrix, current_row); - // } - - // debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - - // matrix_scan_quantum(); - - return (uint8_t) changed; -} - -#endif - -_Noreturn void color_loop (void) -{ -// volatile uint32_t col_index = 1; -// uint32_t pins[] = { C0, C1, C3, C4, C14, C15, C5, C6, C7, C8, C9, C10, D0, D1, D2, D3, D4, D5 }; -// setPinInputHigh(C2); -// -// uint8_t y = 0; -// -// for (uint32_t i = 0; i < sizeof(pins); i++) -// { -// // On -// // setPinInput(pins[y]); -// setPinOutput(pins[i]); -// writePinLow(pins[i]); -// chThdSleepMilliseconds(200); -// } -// -// while (y < sizeof(pins)) -// { -// setPinOutput(pins[y]); -// do -// { -// writePinHigh(pins[y]); -// chThdSleepMilliseconds(1000); -// writePinLow(pins[y]); -// chThdSleepMilliseconds(1000); -// } while(readPin(C2)); -// y++; -// } - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); - chThdSleepMilliseconds(200); - } -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) -// { -// // On -// // setPinInput(led_row_pins[y]); -//// setPinOutput(led_row_pins[y]); -// writePinHigh(led_row_pins[y]); -// chThdSleepMilliseconds(1000); -// writePinLow(led_row_pins[y]); -// chThdSleepMilliseconds(1000); -// } - -// while (1); - - while (1) - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) - { - // Turn COL On - setPinOutput(col_pins[col_index]); - writePinLow(col_pins[col_index]); - chThdSleepMilliseconds(10); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y++) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - chThdSleepMilliseconds(500); -// } -// -// ; -// -// chThdSleepMilliseconds(100); -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) -// { - // Off - // setPinOutput(led_row_pins[y]); - writePinLow(led_row_pins[y]); -// chThdSleepMilliseconds(1000); - } - - // Turn COL Off - setPinInput(col_pins[col_index]); - writePinHigh(col_pins[col_index]); - chThdSleepMilliseconds(10); - } -} \ No newline at end of file diff --git a/keyboards/redragon/k552/rev1/matrix_base.c b/keyboards/redragon/k552/rev1/matrix_base.c deleted file mode 100644 index 3c17faf2df63..000000000000 --- a/keyboards/redragon/k552/rev1/matrix_base.c +++ /dev/null @@ -1,255 +0,0 @@ -/* -Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#include -#include -#include "util.h" -#include "matrix.h" -#include "debounce.h" -#include "quantum.h" - -#ifdef DIRECT_PINS -static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) -static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -static const pin_t led_row_pins[LED_MATRIX_ROWS_HW] = LED_MATRIX_ROW_PINS; -#endif - -/* matrix state(1:on, 0:off) */ -extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values - -// matrix code - -#ifdef DIRECT_PINS - -static void init_pins(void) { - for (int row = 0; row < MATRIX_ROWS; row++) { - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = direct_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); - } - } - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - // Start with a clear matrix row - matrix_row_t current_row_value = 0; - - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - pin_t pin = direct_pins[current_row][col_index]; - if (pin != NO_PIN) { - current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - } - - // If the row has changed, store the row and return the changed flag. - if (current_matrix[current_row] != current_row_value) { - current_matrix[current_row] = current_row_value; - return true; - } - return false; -} - -#elif defined(DIODE_DIRECTION) -# if (DIODE_DIRECTION == COL2ROW) - -static void select_row(uint8_t row) { - setPinOutput(row_pins[row]); - writePinLow(row_pins[row]); -} - -static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); } - -static void unselect_rows(void) { - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); - } -} - -static void init_pins(void) { - unselect_rows(); - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); - } -} - -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - // Start with a clear matrix row - matrix_row_t current_row_value = 0; - - // Select row and wait for row selecton to stabilize - select_row(current_row); - matrix_io_delay(); - - // For each col... - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - // Select the col pin to read (active low) - uint8_t pin_state = readPin(col_pins[col_index]); - - // Populate the matrix row with the state of the col pin - current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); - } - - // Unselect row - unselect_row(current_row); - - // If the row has changed, store the row and return the changed flag. - if (current_matrix[current_row] != current_row_value) { - current_matrix[current_row] = current_row_value; - return true; - } - return false; -} - -# elif (DIODE_DIRECTION == ROW2COL) - -static void select_col(uint8_t col) { - setPinOutput(col_pins[col]); - writePinLow(col_pins[col]); -} - -static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } - -static void unselect_cols(void) { - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); - } -} - -static void init_pins(void) { - unselect_cols(); - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); - } -} - -static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { - bool matrix_changed = false; - - // Select col and wait for col selecton to stabilize - select_col(current_col); - matrix_io_delay(); - - // For each row... - for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { - // Store last value of row prior to reading - matrix_row_t last_row_value = current_matrix[row_index]; - matrix_row_t current_row_value = last_row_value; - - // Check row pin state - if (readPin(row_pins[row_index]) == 0) { - // Pin LO, set col bit - current_row_value |= (MATRIX_ROW_SHIFTER << current_col); - } else { - // Pin HI, clear col bit - current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); - } - - // Determine if the matrix changed state - if ((last_row_value != current_row_value)) { - matrix_changed |= true; - current_matrix[row_index] = current_row_value; - } - } - - // Unselect col - unselect_col(current_col); - - return matrix_changed; -} - -# else -# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! -# endif -#else -# error DIODE_DIRECTION is not defined! -#endif - -void matrix_init(void) { - // initialize key pins - init_pins(); - - // initialize matrix state: all keys off - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - raw_matrix[i] = 0; - matrix[i] = 0; - } - - debounce_init(MATRIX_ROWS); - - { - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) - { - // Turn COL On - setPinOutput(col_pins[col_index]); - writePinLow(col_pins[col_index]); -// chThdSleepMilliseconds(10); - - for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) - { - // On - // setPinInput(led_row_pins[y]); - setPinOutput(led_row_pins[y]); - writePinHigh(led_row_pins[y]); - chThdSleepMilliseconds(5); -// } -// -// ; -// -// chThdSleepMilliseconds(100); -// -// for (uint8_t y = 0; y < LED_MATRIX_ROWS_HW; y+=3) -// { - // Off - // setPinOutput(led_row_pins[y]); -// writePinLow(led_row_pins[y]); -// chThdSleepMilliseconds(1000); - } - - // Turn COL Off - setPinInput(col_pins[col_index]); - writePinHigh(col_pins[col_index]); -// chThdSleepMilliseconds(10); - } - } - - matrix_init_quantum(); -} - -uint8_t matrix_scan(void) { - bool changed = false; - -#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) - // Set row, read cols - for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { - changed |= read_cols_on_row(raw_matrix, current_row); - } -#elif (DIODE_DIRECTION == ROW2COL) - // Set col, read rows - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - changed |= read_rows_on_col(raw_matrix, current_col); - } -#endif - - debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - - matrix_scan_quantum(); - return (uint8_t)changed; -} \ No newline at end of file diff --git a/keyboards/redragon/k552/rev1/rules.mk b/keyboards/redragon/k552/rev1/rules.mk index 43ec7d6d3243..56bdbca6f785 100644 --- a/keyboards/redragon/k552/rev1/rules.mk +++ b/keyboards/redragon/k552/rev1/rules.mk @@ -59,6 +59,4 @@ CUSTOM_MATRIX = yes # Custom RGB matrix handling RGB_MATRIX_ENABLE = yes -RGB_MATRIX_DRIVER = custom - -ALLOW_WARNINGS = yes \ No newline at end of file +RGB_MATRIX_DRIVER = custom \ No newline at end of file