summaryrefslogtreecommitdiff
path: root/keyboards/matrix/m20add/m20add.c
diff options
context:
space:
mode:
authoryulei <yuleiz@gmail.com>2020-08-23 04:45:06 +0800
committerGitHub <noreply@github.com>2020-08-22 13:45:06 -0700
commitac3dfa742a92de541f86846b94269aab87d55d3c (patch)
treea14cd8d42a963e8aa2e50b214e57f89973f9ea8e /keyboards/matrix/m20add/m20add.c
parente02f4798f97f7432e8df55846f8eb496b6ac45d1 (diff)
[Keyboard] added matrix 8xv2.0 additional (#9470)
* added matrix 8xv2.0 additional keyboard * Apply suggestions from code review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * add copyright and speed up the matrix scanning * Update keyboards/matrix/m20add/rules.mk Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'keyboards/matrix/m20add/m20add.c')
-rw-r--r--keyboards/matrix/m20add/m20add.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/keyboards/matrix/m20add/m20add.c b/keyboards/matrix/m20add/m20add.c
new file mode 100644
index 0000000000..b38dad27cd
--- /dev/null
+++ b/keyboards/matrix/m20add/m20add.c
@@ -0,0 +1,80 @@
+/**
+ * m20add.c
+ */
+
+#include "m20add.h"
+#include "tca6424.h"
+#include "rgb_ring.h"
+#include "i2c_master.h"
+
+void set_pin(uint16_t pin)
+{
+ uint8_t data = tca6424_read_port(GET_PORT(pin));
+ data |= ( 1 << GET_PIN(pin));
+ tca6424_write_port(GET_PORT(pin), data);
+}
+
+void clear_pin(uint16_t pin)
+{
+ uint8_t data = tca6424_read_port(GET_PORT(pin));
+ data &= ~( 1 << GET_PIN(pin));
+ tca6424_write_port(GET_PORT(pin), data);
+}
+
+uint8_t read_pin(uint16_t pin)
+{
+ uint8_t data = tca6424_read_port(GET_PORT(pin));
+ return (data & (1<<GET_PIN(pin))) ? 1 : 0;
+}
+
+void matrix_init_kb(void) {
+#ifdef RGBLIGHT_ENABLE
+ rgb_ring_init();
+#endif
+ matrix_init_user();
+}
+
+void matrix_scan_kb(void) {
+#ifdef RGBLIGHT_ENABLE
+ rgb_ring_task();
+#endif
+ matrix_scan_user();
+}
+
+static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);
+static uint16_t scroll_lock_pin = DEF_PIN(TCA6424_PORT0, 1);
+
+bool led_update_kb(led_t led_state) {
+ bool res = led_update_user(led_state);
+ if (res) {
+ led_state.caps_lock ? set_pin(caps_lock_pin) : clear_pin(caps_lock_pin);
+ led_state.scroll_lock ? set_pin(scroll_lock_pin) : clear_pin(scroll_lock_pin);
+ }
+ return res;
+}
+
+// override the default implementation to avoid re-initialization
+void i2c_init(void)
+{
+ static bool initialized = false;
+ if (initialized) {
+ return;
+ } else {
+ initialized = true;
+ }
+
+ // Try releasing special pins for a short time
+ palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
+ palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
+
+ chThdSleepMilliseconds(10);
+ palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
+ palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
+}
+
+#define REBOOT_MAGIC 0x41544B42
+void shutdown_user(void)
+{
+ // set the magic number for resetting to the bootloader
+ *(uint32_t *)(&(RTCD1.rtc->BKP0R)) = REBOOT_MAGIC;
+}