summaryrefslogtreecommitdiffstats
path: root/keyboards
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards')
-rw-r--r--keyboards/keychron/k3_pro/config.h5
-rw-r--r--keyboards/keychron/k3_pro/halconf.h1
-rw-r--r--keyboards/keychron/k3_pro/matrix.c27
-rw-r--r--keyboards/keychron/k3_pro/mcuconf.h3
4 files changed, 33 insertions, 3 deletions
diff --git a/keyboards/keychron/k3_pro/config.h b/keyboards/keychron/k3_pro/config.h
index 733ad5a3b8..c31f3cc18b 100644
--- a/keyboards/keychron/k3_pro/config.h
+++ b/keyboards/keychron/k3_pro/config.h
@@ -29,6 +29,9 @@
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION ROW2COL
+/* Use SPI to drive 74HC595 shift register */
+#define DRIVE_SHRIFT_REGISTER_WITH_SPI
+
/* Turn off effects when suspended */
#define RGB_DISABLE_WHEN_USB_SUSPENDED
#define LED_DISABLE_WHEN_USB_SUSPENDED
@@ -41,7 +44,7 @@
{ A8 }
/* Caps lock LED Pin */
-#define LED_CAPS_LOCK_PIN A7
+#define LED_CAPS_LOCK_PIN A0
#define LED_PIN_ON_STATE 1
#ifdef KC_BLUETOOTH_ENABLE
diff --git a/keyboards/keychron/k3_pro/halconf.h b/keyboards/keychron/k3_pro/halconf.h
index 577334a345..128ff72492 100644
--- a/keyboards/keychron/k3_pro/halconf.h
+++ b/keyboards/keychron/k3_pro/halconf.h
@@ -17,6 +17,7 @@
#pragma once
#define HAL_USE_I2C TRUE
+#define HAL_USE_SPI TRUE
#ifdef KC_BLUETOOTH_ENABLE
# define PAL_USE_CALLBACKS TRUE
diff --git a/keyboards/keychron/k3_pro/matrix.c b/keyboards/keychron/k3_pro/matrix.c
index 9e81ee6722..a601c6c4e4 100644
--- a/keyboards/keychron/k3_pro/matrix.c
+++ b/keyboards/keychron/k3_pro/matrix.c
@@ -32,7 +32,24 @@ static inline void HC595_delay(uint16_t n) {
}
}
+#ifdef DRIVE_SHRIFT_REGISTER_WITH_SPI
+// clang-format off
+const SPIConfig hs_spicfg = {
+ .circular = false,
+ .slave = false,
+ .data_cb = NULL,
+ .error_cb = NULL,
+ .ssport = PAL_PORT(HC595_STCP),
+ .sspad = PAL_PAD(HC595_STCP),
+ .cr1 = SPI_CR1_BR_1,
+ .cr2 = SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 | SPI_CR2_SSOE | SPI_CR2_NSSP
+};
+// clang-format on
+#endif
static void HC595_output(uint16_t data) {
+#ifdef DRIVE_SHRIFT_REGISTER_WITH_SPI
+ spiSend(&SPID1, 1, &data);
+#else
uint8_t i;
uint8_t n = 1;
@@ -56,6 +73,7 @@ static void HC595_output(uint16_t data) {
writePinLow(HC595_STCP);
HC595_delay(n);
writePinHigh(HC595_STCP);
+#endif
}
static inline void setPinOutput_writeLow(pin_t pin) {
@@ -147,11 +165,16 @@ void matrix_init_custom(void) {
setPinInputHigh_atomic(row_pins[x]);
}
}
-
+#ifdef DRIVE_SHRIFT_REGISTER_WITH_SPI
+ palSetPadMode(PAL_PORT(HC595_SHCP), PAL_PAD(HC595_SHCP), PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); /* SCK */
+ palSetPadMode(PAL_PORT(HC595_DS), PAL_PAD(HC595_DS), PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); /* MOSI*/
+ palSetPadMode(PAL_PORT(HC595_STCP), PAL_PAD(HC595_STCP), PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); /* CS*/
+ spiStart(&SPID1, &hs_spicfg);
+#else
setPinOutput(HC595_DS);
setPinOutput(HC595_STCP);
setPinOutput(HC595_SHCP);
-
+#endif
unselect_cols();
}
diff --git a/keyboards/keychron/k3_pro/mcuconf.h b/keyboards/keychron/k3_pro/mcuconf.h
index 4dae767a44..2e17094d3b 100644
--- a/keyboards/keychron/k3_pro/mcuconf.h
+++ b/keyboards/keychron/k3_pro/mcuconf.h
@@ -30,6 +30,9 @@
#undef STM32_I2C_USE_I2C1
#define STM32_I2C_USE_I2C1 TRUE
+#undef STM32_SPI_USE_SPI1
+#define STM32_SPI_USE_SPI1 TRUE
+
#ifdef KC_BLUETOOTH_ENABLE
# undef STM32_SERIAL_USE_USART2
# define STM32_SERIAL_USE_USART2 TRUE