Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[keyboard] Add Phantagom numpads #18493

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a6e8dd2
initial commit for phantagom numpads
dkruyt Sep 26, 2022
9708839
Merge branch 'qmk:master' into phantagom-pads
dkruyt Sep 26, 2022
e74cfe5
remove keymap from json
dkruyt Sep 26, 2022
219b2b1
linting fixes
dkruyt Sep 26, 2022
9f4e4db
Update keyboards/phantagom/oled_mpad/config.h
dkruyt Sep 27, 2022
353923f
Update keyboards/phantagom/oled_mpad/keymaps/default/keymap.c
dkruyt Sep 27, 2022
b8c025f
Update keyboards/phantagom/oled_mpad/keymaps/default/keymap.c
dkruyt Sep 27, 2022
bf78313
Update keyboards/phantagom/oled_mpad/keymaps/default/keymap.c
dkruyt Sep 27, 2022
fc78835
Update keyboards/phantagom/oled_mpad/keymaps/default/keymap.c
dkruyt Sep 27, 2022
4fb53dc
cleanup rules
dkruyt Sep 27, 2022
e601a61
license
dkruyt Sep 27, 2022
6b954a9
remove device info
dkruyt Sep 27, 2022
98e295c
fixes for get_u16_str and revert to update_kb, user compiles but does…
dkruyt Sep 27, 2022
126d7b8
Merge branch 'qmk:master' into phantagom-pads
dkruyt Oct 26, 2022
a46e62b
led_update_kb -> led_update_user
dkruyt Oct 26, 2022
406c959
remove default address
dkruyt Oct 26, 2022
b40080c
changed to led_update_ports and enabled scroll lock
dkruyt Oct 26, 2022
e9df87b
Merge branch 'qmk:master' into phantagom-pads
dkruyt Nov 13, 2022
aabfdea
fix: mousekey doesn't work with trackpoint (#18474)
klesh Nov 13, 2022
5de4a9d
Cleanup. (#19061)
tzarc Nov 13, 2022
836d38d
Fixup day_off (#19067)
waffle87 Nov 13, 2022
2e05067
Bastard Keyboards: upstream recent changes (#18903)
0xcharly Nov 15, 2022
9acc8ab
[Keyboard] change BT LEDs so no longer hard coded in Anne Pro (#18934)
SgoSkz Nov 15, 2022
4980717
[Keyboard] Add Constellation Rev3 (#18868)
Xelus22 Nov 15, 2022
89d0681
Fix typo (#19035)
kosorin Nov 15, 2022
9c154e2
keyboards/anavi: Add ANAVI Knob 1 (#18623)
leon-anavi Nov 15, 2022
181d7f7
Planck unicode rune layout (#18674)
trguhq Nov 15, 2022
6827099
Personal keymap updates (#18763)
bghull Nov 15, 2022
1bba49f
[Docs] Note default value for TAP_CODE_DELAY (#19078)
filterpaper Nov 15, 2022
805ea91
Specify `DEFAULT_FOLDER` for `v2/splinky` (#19093)
0xcharly Nov 16, 2022
74920ab
Use `keyboard_pre_init_kb(void)` at keyboard level (#19091)
0xcharly Nov 16, 2022
b04b2f1
Disable onekey console by default (#19104)
zvecr Nov 18, 2022
3956101
Merge branch 'qmk:master' into phantagom-pads
dkruyt Nov 18, 2022
6ddb020
Update keyboards/phantagom/rgb_npad/info.json
dkruyt Nov 20, 2022
93bc065
Update keyboards/phantagom/rgb_npad/info.json
dkruyt Nov 20, 2022
94092a0
Update keyboards/phantagom/rgb_npad/info.json
dkruyt Nov 20, 2022
477eb40
rehosted on imgur
dkruyt Nov 20, 2022
a4e8ad0
rehosted on imgur
dkruyt Nov 20, 2022
8710c16
Merge branch 'qmk:master' into phantagom-pads
dkruyt Nov 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions keyboards/phantagom/oled_mpad/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2022 <dennis@kruyt.org>

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

#include "config_common.h"

#define VENDOR_ID 0xF8E8
#define PRODUCT_ID 0x0001
#define DEVICE_VER 0x0003
#define MANUFACTURER phantagom
#define PRODUCT mega numpad with oled and extra function rows
dkruyt marked this conversation as resolved.
Show resolved Hide resolved

#define TAPPING_TERM 400

/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 5

// ROWS: Top to bottom, COLS: Left to right

#define MATRIX_ROW_PINS { GP23, GP22, GP21, GP20, GP19, GP18 }
#define MATRIX_COL_PINS { GP17, GP16, GP15 , GP14, GP11 }

/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW

/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5

/* 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_LED GP4
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT 500U
/* #define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_LED_MASK 0U */

#define BOOTMAGIC_LITE_ROW 1
#define BOOTMAGIC_LITE_COLUMN 0

#define I2C_DRIVER I2CD1
#define OLED_DISPLAY_128X64
#define OLED_DISPLAY_ADDRESS 0x3c
dkruyt marked this conversation as resolved.
Show resolved Hide resolved
#define I2C1_SDA_PIN GP12
#define I2C1_SCL_PIN GP13
53 changes: 53 additions & 0 deletions keyboards/phantagom/oled_mpad/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "oled_mpad",
"keyboard_name": "oled_mpad",
"manufacturer": "Phantagom",
"vendorId": "0xF8E8",
"productId": "0x0001",
"matrix": { "rows": 6, "cols": 5 },
"url": "",
"lighting": "qmk_rgblight",
Comment on lines +2 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"name": "oled_mpad",
"keyboard_name": "oled_mpad",
"manufacturer": "Phantagom",
"vendorId": "0xF8E8",
"productId": "0x0001",
"matrix": { "rows": 6, "cols": 5 },
"url": "",
"lighting": "qmk_rgblight",
"keyboard_name": "oled_mpad",
"manufacturer": "Phantagom",

"maintainer": "Phantagom",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"maintainer": "Phantagom",
"maintainer": "Phantagom",
"processor": "RP2040",
"bootloader": "rp2040",

"usb": {
"vid": "0xF8E8",
"pid": "0x0001",
"device_version": "0.0.3"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
},
},
"indicators": {
"caps_lock": "GP5",
"num_lock": "GP4",
"scroll_lock": "GP6",
"on_state": 0
},

"layouts": {
"LAYOUT_numpad_6x5": {
"layout": [
{"x": 1, "y": 0},
{"x": 2, "y": 0},
{"x": 3, "y": 0},
{"x": 4, "y": 0},

{"x": 0, "y": 1},
{"x": 1, "y": 1},
{"x": 2, "y": 1},
{"x": 3, "y": 1},
{"x": 4, "y": 1},

{"x": 0, "y": 2},
{"x": 1, "y": 2},
{"x": 2, "y": 2},
{"x": 3, "y": 2},
{"x": 4, "y": 2, "h": 2},

{"x": 0, "y": 3},
{"x": 1, "y": 3},
{"x": 2, "y": 3},
{"x": 3, "y": 3},

{"x": 0, "y": 4},
{"x": 1, "y": 4},
{"x": 2, "y": 4},
{"x": 3, "y": 4},
{"x": 4, "y": 4, "h": 2},

{"x": 0, "y": 5},
{"x": 1, "y": 5, "w": 2},
{"x": 3, "y": 5}
]
}
}
}
181 changes: 181 additions & 0 deletions keyboards/phantagom/oled_mpad/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#include QMK_KEYBOARD_H
dkruyt marked this conversation as resolved.
Show resolved Hide resolved

enum Layer {
_NUMPAD = 0, // Standard QWERTY layer
_MOUSE, // Function key layer
_NAV,
};
#define _NP _NUMPAD
#define _MS _MOUSE
#define _NV _NAV

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/*
* ,-------------------.
* | Fx | Fx | Fx | Fx |
* |----|----|----|----|
* | NL | / | * | - |
* |----|----|----|----|
* | 7 | 8 | 9 | |
* |----|----|----| + |
* | 4 | 5 | 6 | |
* |----|----|----|----|
* | 1 | 2 | 3 | |
* |----|----|----| En |
* | 0 | . | |
* `-------------------'
*/

[_NUMPAD] = LAYOUT_numpad_6x5(
MO(_MS), KC_MUTE, KC_VOLD, KC_VOLU,
KC_PSCR, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
TO(_NP), KC_P7, KC_P8, KC_P9,
TO(_MS), KC_P4, KC_P5, KC_P6, KC_PPLS,
TO(_NV), KC_P1, KC_P2, KC_P3,
KC_A, KC_P0, KC_PDOT, KC_PENT
),

[_MOUSE] = LAYOUT_numpad_6x5(
_______, KC_MUTE, KC_VOLD, KC_VOLU,
KC_PSCR, KC_NUM, KC_BTN1, KC_BTN2, KC_BTN3,
TO(_NP), KC_P7, KC_MS_U, KC_P9,
TO(_MS), KC_MS_L, KC_P5, KC_MS_R, KC_PPLS,
TO(_NV), KC_P1, KC_MS_D, KC_P3,
KC_A, KC_P0, KC_PDOT, KC_PENT
),

[_NAV] = LAYOUT_numpad_6x5(
MO(_MS), KC_MUTE, KC_VOLD, KC_VOLU,
KC_PSCR, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
TO(_NP), KC_HOME, KC_UP, KC_PGUP,
TO(_MS), KC_LEFT, _______, KC_RIGHT, KC_PPLS,
TO(_NV), KC_END, KC_DOWN, KC_PGDOWN,
KC_A, KC_INS, KC_DEL, KC_PENT
),
};

void matrix_init_kb(void) {
dkruyt marked this conversation as resolved.
Show resolved Hide resolved
// set CapsLock LED to output and low
setPinOutput(GP4);
writePinLow(GP4);
// set NumLock LED to output and low
setPinOutput(GP5);
writePinLow(GP5);
// set ScrollLock LED to output and low
setPinOutput(GP6);
writePinLow(GP6);
}

bool led_update_kb(led_t led_state) {
dkruyt marked this conversation as resolved.
Show resolved Hide resolved
bool res = led_update_user(led_state);
if(res) {
writePin(GP4, led_state.num_lock);
writePin(GP5, led_state.caps_lock);
//writePin(B2, led_state.scroll_lock);
}
return res;
}

static unsigned int type_count = 0 ;
dkruyt marked this conversation as resolved.
Show resolved Hide resolved
void count_type ( void ) {
type_count++;
}

// Function to be called when the key is pressed/released
// If the function itself is not added, add each function, if it is, add only in `#ifdef OLED_ENABLE`
bool process_record_user ( uint16_t keycode, keyrecord_t *record) {
#ifdef OLED_ENABLE
if (record->event.pressed) {
count_type ();
}
#endif
return true ;
}

void oled_write_type_count ( void ) {
static char type_count_str[ 7 ];
oled_write_P ( PSTR ( "Type count: " ), false );
itoa (type_count, type_count_str, 10 );
oled_write_ln (type_count_str, false );
dkruyt marked this conversation as resolved.
Show resolved Hide resolved
}

// Layer state
void oled_write_layer_state ( void ) {
// Host Keyboard Layer Status
oled_write_P(PSTR("Layer: "), false);

switch (get_highest_layer(layer_state)) {
case _NUMPAD:
oled_write_P(PSTR("Numpad\n"), false);
break;
case _MOUSE:
oled_write_P(PSTR("Mouse\n"), false);
break;
case _NAV:
oled_write_P(PSTR("Navigation\n"), false);
break;
default:
// Or use the write_ln shortcut over adding '\n' to the end of your string
oled_write_ln_P(PSTR("Undefined\n"), false);
}
}

// State of NumLock/CapsLock/ScrollLock
void oled_write_host_led_state ( void ) {
const led_t led_state = host_keyboard_led_state ();
oled_write_P ( PSTR ( "NL:" ), false );
oled_write_P (led_state.num_lock ? PSTR ( "on" ) : PSTR ( "- " ), false );
oled_write_P ( PSTR ( " CL:" ), false );
oled_write_P (led_state.caps_lock ? PSTR ( "on" ) :PSTR ( "- " ), false );
oled_write_P ( PSTR ( " SL:" ), false );
oled_write_ln_P (led_state.scroll_lock ? PSTR ( "on\n" ) : PSTR ( "-\n" ), false );
}

// Uptime
// write given digit, with leading zero if digit < 10
void oled_write_2digit(unsigned int digit) {
static char buf[6];
itoa(digit, buf, 10);
if (digit < 10) {
oled_write_char('0', false);
}
oled_write(buf, false);
}

Comment on lines +146 to +154
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_u8_str and get_u16_str will do this, and without using itoa, which can be expensive, size wise.

if neither of these work, then you could simply use get_numeric_str instead.

All of these are in quantum.c, and available anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what you mean, but not how to solve it, not a C programmer :( but learning a lot ;)

Copy link
Member

@drashna drashna Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only wanted 2 digits:

const char *oled_write_2digit(uint8_t curr_num, char curr_pad) {
    static char    buf[3]   = {0};
    static uint8_t last_num = 0xFF;
    static char    last_pad = '\0';
    if (last_num == curr_num && last_pad == curr_pad) {
        return buf;
    }
    last_num = curr_num;
    last_pad = curr_pad;
    return get_numeric_str(buf, sizeof(buf), curr_num, curr_pad);
}

and oled_write_2digits(uptime, '0') would print out what you want.

I'm not sure of the compile size difference compared with itoa, but may be worth testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way I am getting extra leading 0, that I don't want, it's a uptime clock.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oled_write_2digits(uptime, ' ') would fix that.

void oled_write_uptime(void) {
static uint32_t uptime_s;
uptime_s = timer_read32() / 1000;
oled_write_P(PSTR("Uptime "), false);
// hour
oled_write_2digit((uptime_s / 3600) % 60);
oled_write_char(':', false);
// minutes
oled_write_2digit((uptime_s / 60) % 60);
oled_write_char(':', false);
// seconds
oled_write_2digit(uptime_s % 60);
oled_write_char('\n', false);
}

void oled_render_logo(void) {
static const char PROGMEM crkbd_logo[] = {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
0};
oled_write_P(crkbd_logo, false);
}

#ifdef OLED_ENABLE
bool oled_task_user(void) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could all of this be moved to oled_mpad.c, and use the oled_task_kb function?


oled_render_logo();
oled_write_host_led_state ();
oled_write_layer_state ();
oled_write_type_count ();
oled_write_uptime ();
return false;
}
#endif


24 changes: 24 additions & 0 deletions keyboards/phantagom/oled_mpad/keymaps/default/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MCU name
dkruyt marked this conversation as resolved.
Show resolved Hide resolved
MCU = RP2040
# Bootloader selection
BOOTLOADER = rp2040
# Build Options
# change yes to no to disable
#
BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite
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
NKRO_ENABLE = yes # Enable N-Key Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
AUDIO_ENABLE = no # Audio output
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
WPM_ENABLE = yes
OLED_ENABLE = yes
OLED_DRIVER = SSD1306

OPT_DEFS += -DHAL_USE_I2C=TRUE

LAYOUTS = numpad_6x5
Loading