Skip to content

Commit

Permalink
Reverted qmk#16394, added rp2040 example, bug fixes from rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
zykrah committed Jul 2, 2022
1 parent d84168c commit c3353bd
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 88 deletions.
29 changes: 29 additions & 0 deletions keyboards/vial_example/vial_rp2040/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

/* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x0000
#define DEVICE_VER 0x0001
#define MANUFACTURER Vial
#define PRODUCT RP2040 example

/* key matrix size */
#define MATRIX_ROWS 2
#define MATRIX_COLS 2

#define MATRIX_ROW_PINS { 0, 1 }
#define MATRIX_COL_PINS { 2, 3 }

#define DIODE_DIRECTION COL2ROW

/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE

#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT 500U

// #define TAPPING_TERM_PER_KEY
15 changes: 15 additions & 0 deletions keyboards/vial_example/vial_rp2040/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_1, KC_2,
KC_3, KC_4
),

[1] = LAYOUT(
KC_A, KC_B,
KC_C, KC_D
)
};
7 changes: 7 additions & 0 deletions keyboards/vial_example/vial_rp2040/keymaps/vial/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

#define VIAL_KEYBOARD_UID {0x03, 0x35, 0x69, 0xE1, 0x5C, 0x42, 0xD9, 0x5E}
#define VIAL_UNLOCK_COMBO_ROWS {0, 1}
#define VIAL_UNLOCK_COMBO_COLS {0, 1}
25 changes: 25 additions & 0 deletions keyboards/vial_example/vial_rp2040/keymaps/vial/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_1, KC_2,
KC_3, KC_4
),

[1] = LAYOUT(
KC_A, KC_B,
KC_C, KC_D
),

[2] = LAYOUT(
KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS
),

[3] = LAYOUT(
KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS
)
};
4 changes: 4 additions & 0 deletions keyboards/vial_example/vial_rp2040/keymaps/vial/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
# DYNAMIC_TAPPING_TERM_ENABLE = no
VIAL_TAP_DANCE_ENABLE = no
20 changes: 20 additions & 0 deletions keyboards/vial_example/vial_rp2040/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# MCU name
MCU = RP2040
BOOTLOADER = rp2040

# Build Options
# change yes to no to disable
#
BOOTMAGIC_ENABLE = yes
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
COMMAND_ENABLE = no # Commands for debug and configuration
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE = yes # USB Nkey Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
BLUETOOTH_ENABLE = no # Enable Bluetooth
AUDIO_ENABLE = no # Audio output
3 changes: 3 additions & 0 deletions keyboards/vial_example/vial_rp2040/vial_rp2040.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include "vial_rp2040.h"
13 changes: 13 additions & 0 deletions keyboards/vial_example/vial_rp2040/vial_rp2040.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

#include "quantum.h"

#define LAYOUT( \
K00, K01, \
K10, K11 \
) { \
{ K00, K01 }, \
{ K10, K11 } \
}
2 changes: 1 addition & 1 deletion quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void action_exec(keyevent_t event) {
clear_oneshot_swaphands();
}
# endif
}
# endif
}
#endif

Expand Down
28 changes: 16 additions & 12 deletions quantum/dynamic_keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#include "via.h" // for default VIA_EEPROM_ADDR_END
#include <string.h>

<<<<<<< HEAD
#ifdef VIAL_ENABLE
#include "vial.h"
=======
#endif

#ifdef ENCODER_ENABLE
# include "encoder.h"
#else
Expand All @@ -34,7 +34,6 @@

#ifndef DYNAMIC_KEYMAP_LAYER_COUNT
# define DYNAMIC_KEYMAP_LAYER_COUNT 4
>>>>>>> 5d67c4d908 (Fix missing definition for non-encoder case. (#16593))
#endif

#ifndef DYNAMIC_KEYMAP_MACRO_COUNT
Expand Down Expand Up @@ -70,6 +69,11 @@
# endif
#endif

// Dynamic encoders starts after dynamic keymaps
#ifndef DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR
# define DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2))
#endif

// Dynamic macro starts after dynamic encoders, but only when using ENCODER_MAP
#ifdef ENCODER_MAP_ENABLE
# ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
Expand Down Expand Up @@ -127,6 +131,7 @@
// Dynamic macro
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (VIAL_KEY_OVERRIDE_EEPROM_ADDR + VIAL_KEY_OVERRIDE_SIZE)
#endif

// Sanity check that dynamic keymaps fit in available EEPROM
// If there's not 100 bytes available for macros, then something is wrong.
Expand Down Expand Up @@ -163,7 +168,7 @@ void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint
if (layer >= DYNAMIC_KEYMAP_LAYER_COUNT || row >= MATRIX_ROWS || column >= MATRIX_COLS) return;

#ifdef VIAL_ENABLE
if (keycode == RESET && !vial_unlocked)
if (keycode == QK_BOOT && !vial_unlocked)
return;
#endif

Expand All @@ -173,7 +178,6 @@ void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint
eeprom_update_byte(address + 1, (uint8_t)(keycode & 0xFF));
}

=======
#ifdef ENCODER_MAP_ENABLE
void *dynamic_keymap_encoder_to_eeprom_address(uint8_t layer, uint8_t encoder_id) {
return ((void *)DYNAMIC_KEYMAP_ENCODER_EEPROM_ADDR) + (layer * NUM_ENCODERS * 2 * 2) + (encoder_id * 2 * 2);
Expand Down Expand Up @@ -283,7 +287,7 @@ int dynamic_keymap_set_key_override(uint8_t index, const vial_key_override_entry

void dynamic_keymap_reset(void) {
#ifdef VIAL_ENABLE
/* temporarily unlock the keyboard so we can set hardcoded RESET keycode */
/* temporarily unlock the keyboard so we can set hardcoded QK_BOOT keycode */
int vial_unlocked_prev = vial_unlocked;
vial_unlocked = 1;
#endif
Expand All @@ -310,7 +314,7 @@ void dynamic_keymap_reset(void) {
#endif

#ifdef VIAL_TAP_DANCE_ENABLE
vial_tap_dance_entry_t td = { KC_NO, KC_NO, KC_NO, KC_NO, TAPPING_TERM };
vial_tap_dance_entry_t td = { KC_NO, KC_NO, KC_NO, KC_NO };
for (size_t i = 0; i < VIAL_TAP_DANCE_ENTRIES; ++i) {
dynamic_keymap_set_tap_dance(i, &td);
}
Expand Down Expand Up @@ -362,7 +366,7 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
return;

#ifndef VIAL_INSECURE
/* Check whether it is trying to send a RESET keycode; only allow setting these if unlocked */
/* Check whether it is trying to send a QK_BOOT keycode; only allow setting these if unlocked */
if (!vial_unlocked) {
/* how much of the input array we'll have to check in the loop */
uint16_t chk_offset = 0;
Expand All @@ -371,7 +375,7 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
/* initial byte misaligned -- this means the first keycode will be a combination of existing and new data */
if (offset % 2 != 0) {
uint16_t kc = (eeprom_read_byte((uint8_t*)target - 1) << 8) | data[0];
if (kc == RESET)
if (kc == QK_BOOT)
data[0] = 0xFF;

/* no longer have to check the first byte */
Expand All @@ -381,17 +385,17 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
/* final byte misaligned -- this means the last keycode will be a combination of new and existing data */
if ((offset + size) % 2 != 0) {
uint16_t kc = (data[size - 1] << 8) | eeprom_read_byte((uint8_t*)target + size);
if (kc == RESET)
if (kc == QK_BOOT)
data[size - 1] = 0xFF;

/* no longer have to check the last byte */
chk_sz -= 1;
}

/* check the entire array, replace any instances of RESET with invalid keycode 0xFFFF */
/* check the entire array, replace any instances of QK_BOOT with invalid keycode 0xFFFF */
for (uint16_t i = chk_offset; i < chk_sz; i += 2) {
uint16_t kc = (data[i] << 8) | data[i + 1];
if (kc == RESET) {
if (kc == QK_BOOT) {
data[i] = 0xFF;
data[i + 1] = 0xFF;
}
Expand Down
Loading

0 comments on commit c3353bd

Please sign in to comment.