From 31782fa961a2c2b4e414e96c6aee6e905997ce5f Mon Sep 17 00:00:00 2001 From: skullY Date: Sun, 23 Apr 2017 13:53:47 -0700 Subject: [PATCH] Save at a working point --- keyboards/simontester/config.h | 16 +++--- .../simontester/keymaps/default/Makefile | 37 ------------- .../simontester/keymaps/default/config.h | 24 --------- .../simontester/keymaps/default/keymap.c | 39 +++++++++++++- keyboards/simontester/led.c | 35 ++++++++++++- keyboards/simontester/matrix.c | 52 ++++++++++++------- keyboards/simontester/rules.mk | 3 ++ keyboards/simontester/simontester.h | 7 ++- tmk_core/protocol/chibios/usb_main.c | 10 ++++ 9 files changed, 130 insertions(+), 93 deletions(-) delete mode 100644 keyboards/simontester/keymaps/default/Makefile delete mode 100644 keyboards/simontester/keymaps/default/config.h diff --git a/keyboards/simontester/config.h b/keyboards/simontester/config.h index 86f160039f..ec48d9ee8b 100644 --- a/keyboards/simontester/config.h +++ b/keyboards/simontester/config.h @@ -27,7 +27,7 @@ #define MANUFACTURER "Clueboard" #define USBSTR_MANUFACTURER 'C', '\x00', 'l', '\x00', 'u', '\x00', 'e', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00' #define PRODUCT "Simon Tester" -#define USBSTR_PRODUCT 'S', '\x00', 'i', '\x00', 'm', '\x00', 'o', '\x00', 'n', '\x00' +#define USBSTR_PRODUCT 'S', '\x00', 'i', '\x00', 'm', '\x00', 'o', '\x00', 'n', '\x00', ' ', '\x00', 'T', '\x00', 'e', '\x00', 's', '\x00', 't', '\x00', 'e', '\x00', 'r', '\x00' #define DESCRIPTION A switch tester that plays Simon /* key matrix size */ @@ -53,12 +53,6 @@ /* COL2ROW, ROW2COL, or CUSTOM_MATRIX */ #define DIODE_DIRECTION CUSTOM_MATRIX -/* backlight control */ -// #define BACKLIGHT_PIN B7 -// #define BACKLIGHT_BREATHING -// #define BACKLIGHT_LEVELS 3 - - /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ #define DEBOUNCE 6 @@ -134,4 +128,12 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 +/* Remap PA11->PA9 and PA12->PA10 on STM32 devices that require it. + * + * The following MCU's are known to require this: + * + * STM32F042x6 + */ +#define STM32_REMAP_PINS + #endif diff --git a/keyboards/simontester/keymaps/default/Makefile b/keyboards/simontester/keymaps/default/Makefile deleted file mode 100644 index b8879076bd..0000000000 --- a/keyboards/simontester/keymaps/default/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2013 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 . - - -# QMK Build Options -# change to "no" to disable the options, or define them in the Makefile in -# the appropriate keymap folder that will get included automatically -# -BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) -MOUSEKEY_ENABLE = yes # Mouse keys(+4700) -EXTRAKEY_ENABLE = yes # Audio control and System control(+450) -CONSOLE_ENABLE = no # Console for debug(+400) -COMMAND_ENABLE = yes # Commands for debug and configuration -NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality -MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) -AUDIO_ENABLE = no # Audio output on port C6 -UNICODE_ENABLE = no # Unicode -BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID -RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. -SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend - -ifndef QUANTUM_DIR - include ../../../../Makefile -endif diff --git a/keyboards/simontester/keymaps/default/config.h b/keyboards/simontester/keymaps/default/config.h deleted file mode 100644 index f52a97bbc8..0000000000 --- a/keyboards/simontester/keymaps/default/config.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2017 REPLACE_WITH_YOUR_NAME - * - * 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 . - */ - -#ifndef CONFIG_USER_H -#define CONFIG_USER_H - -#include "../../config.h" - -// place overrides here - -#endif diff --git a/keyboards/simontester/keymaps/default/keymap.c b/keyboards/simontester/keymaps/default/keymap.c index 5c6c6bef8b..f6b754e248 100644 --- a/keyboards/simontester/keymaps/default/keymap.c +++ b/keyboards/simontester/keymaps/default/keymap.c @@ -17,7 +17,42 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = KEYMAP( - KC_1, KC_2, \ - KC_3, KC_4 \ + KC_1, F(2), \ + F(0), F(1) \ ), }; + +void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { + static bool backlight; + + switch (id) { + case 0: + palSetPad(GPIOA, 6); + palSetPad(GPIOA, 3); + palSetPad(GPIOA, 15); + palSetPad(GPIOB, 5); + backlight = false; + break; + case 1: + palClearPad(GPIOA, 6); + palClearPad(GPIOA, 3); + palClearPad(GPIOA, 15); + palClearPad(GPIOB, 5); + backlight = true; + break; + case 2: + if (backlight) { + palSetPad(GPIOA, 6); + palSetPad(GPIOA, 3); + palSetPad(GPIOA, 15); + palSetPad(GPIOB, 5); + backlight = false; + } else { + palClearPad(GPIOA, 6); + palClearPad(GPIOA, 3); + palClearPad(GPIOA, 15); + palClearPad(GPIOB, 5); + backlight = true; + } + } +} diff --git a/keyboards/simontester/led.c b/keyboards/simontester/led.c index 0d2b38c388..cce90ea627 100644 --- a/keyboards/simontester/led.c +++ b/keyboards/simontester/led.c @@ -16,9 +16,40 @@ */ #include "hal.h" - +#include "backlight.h" #include "led.h" +#include "print.h" +void backlight_init_ports(void) { + print("backlight_init_ports()\n"); +/* + palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); -void led_set(uint8_t usb_led) { + // Set them high to turn off the LEDs + palClearPad(GPIOA, 6); + //palSetPad(GPIOA, 6); + palSetPad(GPIOA, 3); + palSetPad(GPIOA, 15); + palSetPad(GPIOB, 5); +*/ +} + +void backlight_set(uint8_t level) { + printf("backlight_set(%d)\n", level); +/* + if (level == 0) { + palSetPad(GPIOA, 6); + palSetPad(GPIOA, 3); + palSetPad(GPIOA, 15); + palSetPad(GPIOB, 5); + } else { + palClearPad(GPIOA, 6); + palClearPad(GPIOA, 3); + palClearPad(GPIOA, 15); + palClearPad(GPIOB, 5); + } +*/ } diff --git a/keyboards/simontester/matrix.c b/keyboards/simontester/matrix.c index 49aa50b460..9989e2a39d 100644 --- a/keyboards/simontester/matrix.c +++ b/keyboards/simontester/matrix.c @@ -5,6 +5,7 @@ #include "timer.h" #include "wait.h" #include "print.h" +#include "backlight.h" #include "matrix.h" @@ -25,44 +26,55 @@ static uint16_t debouncing_time = 0; void matrix_init(void) { -//debug_matrix = true; + //debug_matrix = true; + /* Column(sense) */ palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOB, 7, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 6, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOB, 3, PAL_MODE_INPUT_PULLDOWN); /* Row(strobe) */ palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL); - palSetPad(GPIOA, 7); // Only one row, so leave it in strobe state all the time + palSetPad(GPIOA, 7); // Only one row, so leave it in strobe state all the time. // I did it this way so hardware hackers would have another // pin to play with. memset(matrix, 0, MATRIX_ROWS); memset(matrix_debouncing, 0, MATRIX_ROWS); + + /* Setup the backlight */ +/* + palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); + + // Set them high to turn off the LEDs + palSetPad(GPIOA, 6); + palSetPad(GPIOA, 3); + palSetPad(GPIOA, 15); + palSetPad(GPIOB, 5); +*/ } uint8_t matrix_scan(void) { - for (int row = 0; row < MATRIX_ROWS; row++) { - matrix_row_t data = 0; - - // read col data: { PA5, PA4, PB6, PB3 } - data = (palReadPad(GPIOA, 5) | - palReadPad(GPIOA, 4) | - palReadPad(GPIOB, 6) | - palReadPad(GPIOB, 3)); - - if (matrix_debouncing[row] != data) { - matrix_debouncing[row] = data; - debouncing = true; - debouncing_time = timer_read(); - } + matrix_row_t data = 0; + + // read col data: { PA5, PA4, PB6, PB3 } + data = (palReadPad(GPIOA, 5) | + (palReadPad(GPIOA, 4) << 1) | + (palReadPad(GPIOB, 6) << 2) | + (palReadPad(GPIOB, 3) << 3)); + + if (matrix_debouncing[0] != data) { + matrix_debouncing[0] = data; + debouncing = true; + debouncing_time = timer_read(); } if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { - for (int row = 0; row < MATRIX_ROWS; row++) { - matrix[row] = matrix_debouncing[row]; - } + matrix[0] = matrix_debouncing[0]; debouncing = false; } return 1; diff --git a/keyboards/simontester/rules.mk b/keyboards/simontester/rules.mk index 05342ba649..c8a43a90e9 100644 --- a/keyboards/simontester/rules.mk +++ b/keyboards/simontester/rules.mk @@ -33,6 +33,9 @@ ARMV = 6 #OPT_DEFS = -DCORTEX_VTOR_INIT=0x00001000 OPT_DEFS = +# Options to pass to dfu-util when flashing +DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000 + # Build Options # comment out to disable the options. # diff --git a/keyboards/simontester/simontester.h b/keyboards/simontester/simontester.h index ae4ea7d707..33aa44969e 100644 --- a/keyboards/simontester/simontester.h +++ b/keyboards/simontester/simontester.h @@ -21,6 +21,11 @@ // This a shortcut to help you visually see your layout. // The first section contains all of the arguments // The second converts the arguments into a two-dimensional array -#define KEYMAP(k00, k01, k02, k03) { { k00, k03, k01, k02, }, } +#define KEYMAP(\ + k00, k03, \ + k01, k02 \ +) { { \ + k00, k01, k02, k03, \ +}, } #endif diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index d0c72c46c7..79f4b5c115 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -1026,6 +1026,16 @@ void init_usb_driver(USBDriver *usbp) { obqObjectInit(&console_buf_queue, console_queue_buffer, CONSOLE_EPSIZE, CONSOLE_QUEUE_CAPACITY, console_queue_onotify, (void*)usbp); chVTObjectInit(&console_flush_timer); #endif +#ifdef STM32_REMAP_PINS + /* Remap PA11->PA9 and PA12->PA10 on STM32 devices that require it. + * + * The following MCU's are known to require this: + * + * STM32F042x6 + */ + RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN; + SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP; +#endif } /*