Browse Source

Refactor 40percentclub/ut47 (#25571)

Joel Challis 11 months ago
parent
commit
319da7bfdb

+ 0 - 32
keyboards/40percentclub/ut47/config.h

@@ -1,32 +0,0 @@
-/*
-Copyright 2018 Carlos Filoteo
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#pragma once
-
-
-/* key matrix size */
-#define MATRIX_ROWS 4
-#define MATRIX_COLS 12
-
-#define MATRIX_ROW_PINS { D1, D0, D4, C6 }
-#define MATRIX_COL_PINS { D7, E6, B4, B5, B6, B2, B3, B1, F7, F6, F5, F4 }
-
-/* COL2ROW, ROW2COL*/
-#define DIODE_DIRECTION COL2ROW
-
-/* Enable GNAP matrix serial output */
-#define GNAP_ENABLE

+ 9 - 0
keyboards/40percentclub/ut47/keyboard.json

@@ -22,6 +22,15 @@
       "resync": true
     }
   },
+  "diode_direction": "COL2ROW",
+  "matrix_pins": {
+    "cols": ["D7", "E6", "B4", "B5", "B6", "B2", "B3", "B1", "F7", "F6", "F5", "F4"],
+    "rows": ["D1", "D0", "D4", "C6"]
+  },
+  "keycodes": [
+    {"key": "LED_TOG"},
+    {"key": "LED_CHG"}
+  ],
   "layouts": {
     "LAYOUT": {
       "layout": [

+ 2 - 52
keyboards/40percentclub/ut47/keymaps/default/keymap.c

@@ -1,31 +1,10 @@
-/* Copyright 2018 Carlos Filoteo
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
+// Copyright 2018 Carlos Filoteo
+// SPDX-License-Identifier: GPL-2.0-or-later
 #include QMK_KEYBOARD_H
-#ifdef LED_ENABLE
-  #include "uart.h"
-#endif
 
 #define LT3_TAB LT(3, KC_TAB)
 #define MT_RSFT_ENT MT(MOD_RSFT, KC_ENT)
 
-enum custom_keycodes {
-    LED_TOG = SAFE_RANGE,
-    LED_CHG
-};
-
 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 
   /* Base Layer
@@ -104,32 +83,3 @@ LAYOUT( /* Tab */
   _______, _______, _______, _______, _______,     _______,      _______, MS_LEFT, MS_DOWN, MS_UP,   MS_RGHT
 ),
 };
-
-//LED keymap functions
- #ifdef LED_ENABLE
-void led_chmode(void) {
-  uart_write(0x65);
-}
-
-void led_toggle(void) {
-  uart_write(0x64);
-}
-
-bool process_record_user(uint16_t keycode, keyrecord_t *record) {
-  if (record->event.pressed) {
-    switch(keycode) {
-      case LED_TOG:
-        #ifdef LED_ENABLE
-        led_toggle();
-        #endif
-        return false;
-      case LED_CHG:
-        #ifdef LED_ENABLE
-        led_chmode();
-        #endif
-        return false;
-    }
-  }
-  return true;
-};
-#endif

+ 2 - 18
keyboards/40percentclub/ut47/keymaps/rgb/config.h

@@ -1,23 +1,7 @@
-/* Copyright 2018 Carlos Filoteo
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
+// Copyright 2018 Carlos Filoteo
+// SPDX-License-Identifier: GPL-2.0-or-later
 #pragma once
 
-
-// place overrides here
 #define RGBLIGHT_EFFECT_BREATHING
 #define RGBLIGHT_EFFECT_RAINBOW_MOOD
 #define RGBLIGHT_EFFECT_RAINBOW_SWIRL

+ 2 - 52
keyboards/40percentclub/ut47/keymaps/rgb/keymap.c

@@ -1,31 +1,10 @@
-/* Copyright 2018 Carlos Filoteo
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
+// Copyright 2018 Carlos Filoteo
+// SPDX-License-Identifier: GPL-2.0-or-later
 #include QMK_KEYBOARD_H
-#ifdef LED_ENABLE
-  #include "uart.h"
-#endif
 
 #define LT3_TAB LT(3, KC_TAB)
 #define MT_RSFT_ENT MT(MOD_RSFT, KC_ENT)
 
-enum custom_keycodes {
-    LED_TOG = SAFE_RANGE,
-    LED_CHG
-};
-
 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 
 LAYOUT(
@@ -56,32 +35,3 @@ LAYOUT( /* Tab */
   _______, _______, _______, _______, _______,     _______,      _______, MS_LEFT, MS_DOWN, MS_UP,   MS_RGHT
 ),
 };
-
-//LED keymap functions
- #ifdef LED_ENABLE
-void led_chmode(void) {
-  uart_write(0x65);
-}
-
-void led_toggle(void) {
-  uart_write(0x64);
-}
-
-bool process_record_user(uint16_t keycode, keyrecord_t *record) {
-  if (record->event.pressed) {
-    switch(keycode) {
-      case LED_TOG:
-        #ifdef LED_ENABLE
-        led_toggle();
-        #endif
-        return false;
-      case LED_CHG:
-        #ifdef LED_ENABLE
-        led_chmode();
-        #endif
-        return false;
-    }
-  }
-  return true;
-};
-#endif

+ 0 - 39
keyboards/40percentclub/ut47/led.c

@@ -1,39 +0,0 @@
-/*
-Copyright 2012 Jun Wako <wakojun@gmail.com>
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#include <avr/io.h>
-#include <stdint.h>
-#include "led.h"
-
-bool led_update_kb(led_t led_state)
-{
-    bool res = led_update_user(led_state);
-    if (res) {
-        if (led_state.caps_lock) {
-            // output low
-            gpio_set_pin_output(B0);
-            gpio_write_pin_low(B0);
-            gpio_set_pin_output(D5);
-            gpio_write_pin_low(D5);
-        } else {
-            // Hi-Z
-            gpio_set_pin_input(B0);
-            gpio_set_pin_input(D5);
-        }
-    }
-    return false;
-}

+ 44 - 0
keyboards/40percentclub/ut47/led_controls.c

@@ -0,0 +1,44 @@
+// Copyright 2018 Carlos Filoteo
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include QMK_KEYBOARD_H
+#include "uart.h"
+
+bool led_update_kb(led_t led_state) {
+    bool res = led_update_user(led_state);
+    if (res) {
+        if (led_state.caps_lock) {
+            // output low
+            gpio_set_pin_output(B0);
+            gpio_write_pin_low(B0);
+            gpio_set_pin_output(D5);
+            gpio_write_pin_low(D5);
+        } else {
+            // Hi-Z
+            gpio_set_pin_input(B0);
+            gpio_set_pin_input(D5);
+        }
+    }
+    return false;
+}
+
+void keyboard_post_init_kb(void) {
+    uart_init(9600);
+
+    keyboard_post_init_user();
+}
+
+bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
+    if (record->event.pressed) {
+        uart_write((record->event.key.row * 16) + record->event.key.col);
+
+        switch (keycode) {
+            case LED_TOG:
+                uart_write(0x64);
+                return false;
+            case LED_CHG:
+                uart_write(0x65);
+                return false;
+        }
+    }
+    return process_record_user(keycode, record);
+}

+ 0 - 0
keyboards/40percentclub/ut47/LED_controls.ino → keyboards/40percentclub/ut47/led_controls.ino


+ 0 - 194
keyboards/40percentclub/ut47/matrix.c

@@ -1,194 +0,0 @@
-/*
-Copyright 2018 Carlos Filoteo
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-/*
- * scan matrix
- */
-#include <stdint.h>
-#include <stdbool.h>
-#include <avr/io.h>
-#include <util/delay.h>
-#include "print.h"
-#include "debug.h"
-#include "util.h"
-#include "matrix.h"
-
-#ifndef DEBOUNCE
-#   define DEBOUNCE	5
-#endif
-static uint8_t debouncing = DEBOUNCE;
-
-/* matrix state(1:on, 0:off) */
-static matrix_row_t matrix[MATRIX_ROWS];
-static matrix_row_t matrix_debouncing[MATRIX_ROWS];
-
-static matrix_row_t read_cols(void);
-static void init_cols(void);
-static void unselect_rows(void);
-static void select_row(uint8_t row);
-
-
-inline
-uint8_t matrix_rows(void)
-{
-    return MATRIX_ROWS;
-}
-
-inline
-uint8_t matrix_cols(void)
-{
-    return MATRIX_COLS;
-}
-
-void matrix_init(void)
-{
-    // initialize row and col
-    unselect_rows();
-    init_cols();
-
-    // initialize matrix state: all keys off
-    for (uint8_t i=0; i < MATRIX_ROWS; i++) {
-        matrix[i] = 0;
-        matrix_debouncing[i] = 0;
-    }
-}
-
-uint8_t matrix_scan(void)
-{
-    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
-        select_row(i);
-        _delay_us(30);  // without this wait read unstable value.
-        matrix_row_t cols = read_cols();
-        if (matrix_debouncing[i] != cols) {
-            matrix_debouncing[i] = cols;
-            if (debouncing) {
-                dprintf("bounce!: %02X\n", debouncing);
-            }
-            debouncing = DEBOUNCE;
-        }
-        unselect_rows();
-    }
-
-    if (debouncing) {
-        if (--debouncing) {
-            _delay_ms(1);
-        } else {
-            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
-                matrix[i] = matrix_debouncing[i];
-            }
-        }
-    }
-
-    return 1;
-}
-
-inline
-bool matrix_is_on(uint8_t row, uint8_t col)
-{
-    return (matrix[row] & ((matrix_row_t)1<<col));
-}
-
-inline
-matrix_row_t matrix_get_row(uint8_t row)
-{
-    return matrix[row];
-}
-
-void matrix_print(void)
-{
-    print("\nr/c 0123456789ABCDEF\n");
-    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
-        print_hex8(row); print(": ");
-        print_bin_reverse16(matrix_get_row(row));
-        print("\n");
-    }
-}
-
-/* Column pin configuration
- * col: 0   1   2   3   4   5   6   7   8   9   10  11
- * pin: D7  E6  B4  B5  B6  B2  B3  B1  F7  F6  F5  F4
- */
-
-static void  init_cols(void)
-{
-    // Input with pull-up(DDR:0, PORT:1)
-    gpio_set_pin_input_high(F4);
-    gpio_set_pin_input_high(F5);
-    gpio_set_pin_input_high(F6);
-    gpio_set_pin_input_high(F7);
-    gpio_set_pin_input_high(E6);
-    gpio_set_pin_input_high(D7);
-    gpio_set_pin_input_high(B1);
-    gpio_set_pin_input_high(B2);
-    gpio_set_pin_input_high(B3);
-    gpio_set_pin_input_high(B4);
-    gpio_set_pin_input_high(B5);
-    gpio_set_pin_input_high(B6);
-}
-
-static matrix_row_t read_cols(void)
-{
-    return (PIND&(1<<7) ? 0 : (1<<0)) |
-           (PINE&(1<<6) ? 0 : (1<<1)) |
-           (PINB&(1<<4) ? 0 : (1<<2)) |
-           (PINB&(1<<5) ? 0 : (1<<3)) |
-           (PINB&(1<<6) ? 0 : (1<<4)) |
-           (PINB&(1<<2) ? 0 : (1<<5)) |
-           (PINB&(1<<3) ? 0 : (1<<6)) |
-           (PINB&(1<<1) ? 0 : (1<<7)) |
-           (PINF&(1<<7) ? 0 : (1<<8)) |
-           (PINF&(1<<6) ? 0 : (1<<9)) |
-           (PINF&(1<<5) ? 0 : (1<<10)) |
-           (PINF&(1<<4) ? 0 : (1<<11));
-}
-
-/* Row pin configuration
- * row: 0   1   2   3
- * pin: D1  D0  D4  C6
- */
-
-static void unselect_rows(void)
-{
-    // Hi-Z(DDR:0, PORT:0) to unselect
-    gpio_set_pin_input(C6);
-    gpio_set_pin_input(D0);
-    gpio_set_pin_input(D1);
-    gpio_set_pin_input(D4);
-}
-
-static void select_row(uint8_t row)
-{
-    // Output low(DDR:1, PORT:0) to select
-    switch (row) {
-        case 0:
-            gpio_set_pin_output(D1);
-            gpio_write_pin_low(D1);
-            break;
-        case 1:
-            gpio_set_pin_output(D0);
-            gpio_write_pin_low(D0);
-            break;
-        case 2:
-            gpio_set_pin_output(D4);
-            gpio_write_pin_low(D4);
-            break;
-        case 3:
-            gpio_set_pin_output(C6);
-            gpio_write_pin_low(C6);
-            break;
-    }
-}

+ 3 - 2
keyboards/40percentclub/ut47/post_rules.mk

@@ -1,4 +1,5 @@
 ifeq ($(strip $(LED_ENABLE)), yes)
-  OPT_DEFS += -DLED_ENABLE
-  SRC += led.c
+    OPT_DEFS += -DLED_ENABLE
+    SRC += led_controls.c
+    UART_DRIVER_REQUIRED = yes
 endif

+ 4 - 5
keyboards/40percentclub/ut47/readme.md

@@ -1,13 +1,12 @@
 # ut47
 
 ![ut47](https://i.imgur.com/ZDKZQaj.jpg)
-===
 
 Somewhere between ortholinear and standard offset. Created to have all the same functions on a Planck in a keyboard but with a more conventional keyboard row stagger.
 
-Keyboard Maintainer: [filoxo](https://github.com/filoxo), [network_operations]  
-Hardware Supported: [PCB design](http://www.40percent.club/2016/10/gnap-20-plateless.html), Arduino Pro Micro  
-Hardware Availability: [How to order](http://www.40percent.club/2017/03/ordering-pcb.html)
+* Keyboard Maintainer: [filoxo](https://github.com/filoxo), [network_operations]
+* Hardware Supported: [PCB design](http://www.40percent.club/2016/10/gnap-20-plateless.html), Arduino Pro Micro
+* Hardware Availability: [How to order](http://www.40percent.club/2017/03/ordering-pcb.html)
 
 ### Instructions
 
@@ -21,7 +20,7 @@ To enable the UT47 LEDs (dual controller), run this for the main controller:
 
 Or you can add `LED_ENABLE = yes` to *rules.mk*
 
-And then flash [LED_controls.ino](LED_controls.ino) to the second controller using [Arduino IDE](https://www.arduino.cc/en/Main/Software) or similar. NOTE: Arduino IDE will require importing additional libraries to compile.
+And then flash [led_controls.ino](led_controls.ino) to the second controller using [Arduino IDE](https://www.arduino.cc/en/Main/Software) or similar. NOTE: Arduino IDE will require importing additional libraries to compile.
 
 <small>The reason this is an "opt-in" feature is to prevent sending serial communication over the pin, in case it ends up being used for something else (like RGB underglow).</small>
 

+ 0 - 3
keyboards/40percentclub/ut47/rules.mk

@@ -1,3 +0,0 @@
-CUSTOM_MATRIX = yes
-SRC += matrix.c
-UART_DRIVER_REQUIRED = yes

+ 0 - 36
keyboards/40percentclub/ut47/ut47.c

@@ -1,36 +0,0 @@
-/* Copyright 2018 Carlos Filoteo
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-#include "quantum.h"
-#ifdef LED_ENABLE
-  #include "uart.h"
-
-void matrix_init_kb(void) {
-  uart_init(9600);
-
-  matrix_init_user();
-}
-#endif
-
-bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
-	// put your per-action keyboard code here
-	// runs for every action, just before processing by the firmware
-  if (record->event.pressed) {
-    #ifdef LED_ENABLE
-      uart_write((record->event.key.row*16)+record->event.key.col);
-    #endif
-  }
-	return process_record_user(keycode, record);
-}