diff options
-rw-r--r-- | drivers/issi/is31fl3218.c | 102 | ||||
-rw-r--r-- | drivers/issi/is31fl3218.h (renamed from keyboards/rama/m6_a/keymaps/default/config.h) | 16 | ||||
-rw-r--r-- | keyboards/rama/m6_a/config.h | 24 | ||||
-rw-r--r-- | keyboards/rama/m6_a/keymaps/default/keymap.c | 316 | ||||
-rw-r--r-- | keyboards/rama/m6_a/m6_a.c | 31 | ||||
-rw-r--r-- | keyboards/rama/m6_a/readme.md | 2 | ||||
-rw-r--r-- | keyboards/rama/m6_a/rules.mk | 44 | ||||
-rw-r--r-- | keyboards/rama/m6_b/config.h | 129 | ||||
-rw-r--r-- | keyboards/rama/m6_b/info.json | 19 | ||||
-rw-r--r-- | keyboards/rama/m6_b/keymaps/default/keymap.c | 16 | ||||
-rw-r--r-- | keyboards/rama/m6_b/m6_b.c | 230 | ||||
-rw-r--r-- | keyboards/rama/m6_b/m6_b.h | 28 | ||||
-rw-r--r-- | keyboards/rama/m6_b/m6_b_api.h | 39 | ||||
-rw-r--r-- | keyboards/rama/m6_b/readme.md | 15 | ||||
-rw-r--r-- | keyboards/rama/m6_b/rgb_backlight.c | 139 | ||||
-rw-r--r-- | keyboards/rama/m6_b/rgb_backlight.h | 34 | ||||
-rw-r--r-- | keyboards/rama/m6_b/rules.mk | 77 | ||||
-rw-r--r-- | quantum/dynamic_keymap.c | 2 |
18 files changed, 885 insertions, 378 deletions
diff --git a/drivers/issi/is31fl3218.c b/drivers/issi/is31fl3218.c new file mode 100644 index 0000000000..db44f72564 --- /dev/null +++ b/drivers/issi/is31fl3218.c @@ -0,0 +1,102 @@ +/* Copyright 2018 Jason Williams (Wilba) + * + * 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 "is31fl3218.h" +#include "i2c_master.h" + +// This is the full 8-bit address +#define ISSI_ADDRESS 0b10101000 + +// These are the register addresses +#define ISSI_REG_SHUTDOWN 0x00 +#define ISSI_REG_PWM 0x01 +#define ISSI_REG_CONTROL 0x13 +#define ISSI_REG_UPDATE 0x16 +#define ISSI_REG_RESET 0x17 + +// Default timeout if no I2C response +#define ISSI_TIMEOUT 100 + +// Reusable buffer for transfers +uint8_t g_twi_transfer_buffer[20]; + +// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining. +// If used as RGB LED driver, LEDs are assigned RGB,RGB,RGB,RGB,RGB,RGB +uint8_t g_pwm_buffer[18]; +bool g_pwm_buffer_update_required = false; + +void IS31FL3218_write_register( uint8_t reg, uint8_t data ) +{ + g_twi_transfer_buffer[0] = reg; + g_twi_transfer_buffer[1] = data; + i2c_transmit( ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); +} + +void IS31FL3218_write_pwm_buffer( uint8_t *pwm_buffer ) +{ + g_twi_transfer_buffer[0] = ISSI_REG_PWM; + for ( int i=0; i<18; i++ ) { + g_twi_transfer_buffer[1+i] = pwm_buffer[i]; + } + + i2c_transmit( ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT); +} + +void IS31FL3218_init(void) +{ + // In case we ever want to reinitialize (?) + IS31FL3218_write_register( ISSI_REG_RESET, 0x00 ); + + // Turn off software shutdown + IS31FL3218_write_register( ISSI_REG_SHUTDOWN, 0x01 ); + + // Set all PWM values to zero + for ( uint8_t i = 0; i < 18; i++ ) { + IS31FL3218_write_register( ISSI_REG_PWM+i, 0x00 ); + } + + // Enable all channels + for ( uint8_t i = 0; i < 3; i++ ) { + IS31FL3218_write_register( ISSI_REG_CONTROL+i, 0b00111111 ); + } + + // Load PWM registers and LED Control register data + IS31FL3218_write_register( ISSI_REG_UPDATE, 0x01 ); +} + +void IS31FL3218_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) +{ + g_pwm_buffer[index * 3 + 0] = red; + g_pwm_buffer[index * 3 + 1] = green; + g_pwm_buffer[index * 3 + 2] = blue; + g_pwm_buffer_update_required = true; +} + +void IS31FL3218_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) +{ + for ( int i = 0; i < 6; i++ ) { + IS31FL3218_set_color( i, red, green, blue ); + } +} + +void IS31FL3218_update_pwm_buffers(void) +{ + if ( g_pwm_buffer_update_required ) { + IS31FL3218_write_pwm_buffer( g_pwm_buffer ); + // Load PWM registers and LED Control register data + IS31FL3218_write_register( ISSI_REG_UPDATE, 0x01 ); + } + g_pwm_buffer_update_required = false; +} diff --git a/keyboards/rama/m6_a/keymaps/default/config.h b/drivers/issi/is31fl3218.h index d150575c1a..2d24e51463 100644 --- a/keyboards/rama/m6_a/keymaps/default/config.h +++ b/drivers/issi/is31fl3218.h @@ -1,4 +1,4 @@ -/* Copyright 2018 Wilba +/* Copyright 2018 Jason Williams (Wilba) * * 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 @@ -13,12 +13,12 @@ * 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 -#ifndef CONFIG_USER_H -#define CONFIG_USER_H +#include <stdint.h> +#include <stdbool.h> -#include "../../config.h" - -// place overrides here - -#endif +void IS31FL3218_init(void); +void IS31FL3218_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); +void IS31FL3218_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); +void IS31FL3218_update_pwm_buffers(void); diff --git a/keyboards/rama/m6_a/config.h b/keyboards/rama/m6_a/config.h index 0c5355f4a8..8d77f5339d 100644 --- a/keyboards/rama/m6_a/config.h +++ b/keyboards/rama/m6_a/config.h @@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef CONFIG_H -#define CONFIG_H +#pragma once #include "config_common.h" @@ -187,4 +186,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 -#endif +#define RGB_BACKLIGHT_ENABLED 0 + +#define DYNAMIC_KEYMAP_LAYER_COUNT 4 + + +// EEPROM usage + +// TODO: refactor with new user EEPROM code (coming soon) +#define EEPROM_MAGIC 0x451F +#define EEPROM_MAGIC_ADDR 32 +// Bump this every time we change what we store +// This will automatically reset the EEPROM with defaults +// and avoid loading invalid data from the EEPROM +#define EEPROM_VERSION 0x07 +#define EEPROM_VERSION_ADDR 34 + +// Backlight config starts after EEPROM version +#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 +// Dynamic keymap starts after backlight config (35+37) +#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 diff --git a/keyboards/rama/m6_a/keymaps/default/keymap.c b/keyboards/rama/m6_a/keymaps/default/keymap.c index 6b15f3cd10..7a408fa8aa 100644 --- a/keyboards/rama/m6_a/keymaps/default/keymap.c +++ b/keyboards/rama/m6_a/keymaps/default/keymap.c @@ -3,322 +3,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { LAYOUT( - TO(1), KC_A, KC_B, KC_C, KC_D, KC_E), + KC_1, KC_2, KC_3, KC_4, KC_5, KC_6), LAYOUT( - TO(2), KC_F, KC_G, KC_H, KC_I, KC_J), + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO), LAYOUT( - TO(3), KC_K, KC_L, KC_M, KC_N, KC_O), + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO), LAYOUT( - TO(4), KC_P, KC_Q, KC_R, KC_S, KC_T), + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO) }; - LAYOUT( - TO(5), KC_U, KC_V, KC_W, KC_X, KC_Y), - - LAYOUT( - TO(0), KC_Z, KC_1, KC_2, KC_3, KC_4)}; - -const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) -{ - //keyevent_t event = record->event; - - switch (id) - { - case 0: - if (record->event.pressed) - { - return MACRO(T(T), T(G), T(L), T(H), T(F), T(ENT), END); - } - break; - case 1: - if (record->event.pressed) - { - return MACRO(T(T), T(G), T(G), T(ENT), END); - } - break; - case 2: - if (record->event.pressed) - { - return MACRO(D(NO), T(L), U(NO), END); - } - break; - case 3: - if (record->event.pressed) - { - return MACRO(D(LCTL), T(Z), U(LCTL), END); - } - break; - case 4: - if (record->event.pressed) - { - return MACRO(D(LCTL), D(LSFT), T(Z), U(LSFT), U(LCTL), END); - } - break; - case 5: - if (record->event.pressed) - { - return MACRO(D(LCTL), T(X), U(LCTL), END); - } - break; - case 6: - if (record->event.pressed) - { - return MACRO(D(LCTL), T(C), U(LCTL), END); - } - break; - case 7: - if (record->event.pressed) - { - return MACRO(D(LCTL), T(V), U(LCTL), END); - } - break; - } - return MACRO_NONE; -} - -// M6-A LEDs are connected to D6, B6, F5, B4, C7, F7 -// This is 1-based because I copied it from Knops code. -void set_switch_led(int ledId, bool state) -{ - if (state) - { - switch (ledId) - { - case 1: - PORTD |= (1 << 6); - break; - case 2: - PORTB |= (1 << 6); - break; - case 3: - PORTF |= (1 << 5); - break; - case 4: - PORTB |= (1 << 4); - break; - case 5: - PORTC |= (1 << 7); - break; - case 6: - PORTF |= (1 << 7); - break; - } - } - else - { - switch (ledId) - { - case 1: - PORTD &= ~(1 << 6); - break; - case 2: - PORTB &= ~(1 << 6); - break; - case 3: - PORTF &= ~(1 << 5); - break; - case 4: - PORTB &= ~(1 << 4); - break; - case 5: - PORTC &= ~(1 << 7); - break; - case 6: - PORTF &= ~(1 << 7); - break; - } - } -} - -void set_layer_led(int layerId) -{ - // UNUSED -} - -void led_set_layer(int layer); - -void matrix_init_user(void) -{ - led_init_ports(); - led_set_layer(0); -} - -void matrix_scan_user(void) -{ -} - -// M6-A LEDs are connected to D6, B6, F5, B4, C7, F7 -void led_init_ports() -{ - // Switch #1 - DDRD |= (1 << 6); - PORTD &= ~(1 << 6); - - // Switch #2 - DDRB |= (1 << 6); - PORTB &= ~(1 << 6); - - // Switch #3 - DDRF |= (1 << 5); - PORTF &= ~(1 << 5); - - // Switch #4 - DDRB |= (1 << 4); - PORTB &= ~(1 << 4); - - // Switch #5 - DDRC |= (1 << 7); - PORTC &= ~(1 << 7); - - // Switch #6 - DDRF |= (1 << 7); - PORTF &= ~(1 << 7); -} - -void led_set_user(uint8_t usb_led) -{ - - if (usb_led & (1 << USB_LED_NUM_LOCK)) - { - } - else - { - } - - if (usb_led & (1 << USB_LED_CAPS_LOCK)) - { - } - else - { - } - - if (usb_led & (1 << USB_LED_SCROLL_LOCK)) - { - } - else - { - } - - if (usb_led & (1 << USB_LED_COMPOSE)) - { - } - else - { - } - - if (usb_led & (1 << USB_LED_KANA)) - { - } - else - { - } -} - -void led_set_layer(int layer) -{ - switch (layer) - { - case 0: - set_switch_led(1, true); - set_switch_led(2, false); - set_switch_led(3, false); - set_switch_led(4, false); - set_switch_led(5, false); - set_switch_led(6, false); - break; - case 1: - set_switch_led(1, false); - set_switch_led(2, true); - set_switch_led(3, false); - set_switch_led(4, false); - set_switch_led(5, false); - set_switch_led(6, false); - break; - case 2: - set_switch_led(1, false); - set_switch_led(2, false); - set_switch_led(3, true); - set_switch_led(4, false); - set_switch_led(5, false); - set_switch_led(6, false); - break; - case 3: - set_switch_led(1, false); - set_switch_led(2, false); - set_switch_led(3, false); - set_switch_led(4, true); - set_switch_led(5, false); - set_switch_led(6, false); - break; - case 4: - set_switch_led(1, false); - set_switch_led(2, false); - set_switch_led(3, false); - set_switch_led(4, false); - set_switch_led(5, true); - set_switch_led(6, false); - break; - case 5: - set_switch_led(1, false); - set_switch_led(2, false); - set_switch_led(3, false); - set_switch_led(4, false); - set_switch_led(5, false); - set_switch_led(6, true); - break; - default: - set_switch_led(1, true); - set_switch_led(2, true); - set_switch_led(3, true); - set_switch_led(4, true); - set_switch_led(5, true); - set_switch_led(6, true); - break; - } -} - -bool process_record_user(uint16_t keycode, keyrecord_t *record) -{ - switch (keycode) - { - case TO(0): - if (record->event.pressed) - { - led_set_layer(0); - } - break; - case TO(1): - if (record->event.pressed) - { - led_set_layer(1); - } - break; - case TO(2): - if (record->event.pressed) - { - led_set_layer(2); - } - break; - case TO(3): - if (record->event.pressed) - { - led_set_layer(3); - } - break; - case TO(4): - if (record->event.pressed) - { - led_set_layer(4); - } - break; - case TO(5): - if (record->event.pressed) - { - led_set_layer(5); - } - break; - } - return true; -} diff --git a/keyboards/rama/m6_a/m6_a.c b/keyboards/rama/m6_a/m6_a.c index 1c84ea2b83..fa19003600 100644 --- a/keyboards/rama/m6_a/m6_a.c +++ b/keyboards/rama/m6_a/m6_a.c @@ -1,4 +1,4 @@ -/* Copyright 2018 Wilba +/* Copyright 2018 Jason Williams (Wilba) * * 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 @@ -13,32 +13,3 @@ * 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 "m6_a.h" -/* -void matrix_init_kb(void) { - // put your keyboard start-up code here - // runs once when the firmware starts up - - matrix_init_user(); -} - -void matrix_scan_kb(void) { - // put your looping keyboard code here - // runs every cycle (a lot) - - matrix_scan_user(); -} - -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 - - return process_record_user(keycode, record); -} - -void led_set_kb(uint8_t usb_led) { - // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here - - led_set_user(usb_led); -} -*/ diff --git a/keyboards/rama/m6_a/readme.md b/keyboards/rama/m6_a/readme.md index 5dd2b92e19..ceaf6a88de 100644 --- a/keyboards/rama/m6_a/readme.md +++ b/keyboards/rama/m6_a/readme.md @@ -12,4 +12,4 @@ Make example for this keyboard (after setting up your build environment): make rama/m6_a:default -See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information.
\ No newline at end of file +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
\ No newline at end of file diff --git a/keyboards/rama/m6_a/rules.mk b/keyboards/rama/m6_a/rules.mk index ca2a2a5f80..ed85ac36d0 100644 --- a/keyboards/rama/m6_a/rules.mk +++ b/keyboards/rama/m6_a/rules.mk @@ -1,5 +1,7 @@ +# project specific files +SRC = keyboards/rama/m6_b/m6_b.c + # MCU name -#MCU = at90usb1286 MCU = atmega32u4 # Processor frequency. @@ -38,31 +40,27 @@ F_USB = $(F_CPU) # Interrupt driven control endpoint task(+60) OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT - -# Boot Section Size in *bytes* -# Teensy halfKay 512 -# Teensy++ halfKay 1024 -# Atmel DFU loader 4096 -# LUFA bootloader 4096 -# USBaspLoader 2048 -OPT_DEFS += -DBOOTLOADER_SIZE=4096 - +# Boot Section +BOOTLOADER = atmel-dfu # Build Options # change yes to no to disable # -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 ?= yes # Console for debug(+400) -COMMAND_ENABLE ?= yes # Commands for debug and configuration +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = no # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = no # Console for debug(+400) +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 +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 ?= no # USB Nkey Rollover -BACKLIGHT_ENABLE ?= no # Enable keyboard backlight functionality on B7 by default -MIDI_ENABLE ?= no # MIDI support (+2400 to 4200, depending on config) -UNICODE_ENABLE ?= no # Unicode -BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID -AUDIO_ENABLE ?= no # Audio output on port C6 -FAUXCLICKY_ENABLE ?= no # Use buzzer to emulate clicky switches +NKRO_ENABLE = yes # USB Nkey Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default +MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +AUDIO_ENABLE = no # Audio output on port C6 +FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches + +RAW_ENABLE = yes +DYNAMIC_KEYMAP_ENABLE = yes
\ No newline at end of file diff --git a/keyboards/rama/m6_b/config.h b/keyboards/rama/m6_b/config.h new file mode 100644 index 0000000000..1adaad3f9e --- /dev/null +++ b/keyboards/rama/m6_b/config.h @@ -0,0 +1,129 @@ +/* Copyright 2018 Jason Williams (Wilba) + * + * 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" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0x5241 // "RW" +#define PRODUCT_ID 0x006B // 6-B +#define DEVICE_VER 0x0001 +#define MANUFACTURER RAMA.WORKS +#define PRODUCT RAMA M6-B +#define DESCRIPTION RAMA M6-B Macropad + +/* key matrix size */ +#define MATRIX_ROWS 1 +#define MATRIX_COLS 6 + +/* + * Keyboard Matrix Assignments + * + * Change this to how you wired your keyboard + * COLS: AVR pins used for columns, left to right + * ROWS: AVR pins used for rows, top to bottom + * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) + * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) + * +*/ +#define MATRIX_ROW_PINS { E6 } +#define MATRIX_COL_PINS { D4, B5, F4, D7, C6, F6 } +#define UNUSED_PINS + +/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */ +#define DIODE_DIRECTION COL2ROW + +// #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 DEBOUNCING_DELAY 5 + +/* define if matrix has ghost (lacks anti-ghosting diodes) */ +//#define MATRIX_HAS_GHOST + +/* number of backlight levels */ + +/* 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 + +/* If defined, GRAVE_ESC will always act as ESC when CTRL is held. + * This is userful for the Windows task manager shortcut (ctrl+shift+esc). + */ +// #define GRAVE_ESC_CTRL_OVERRIDE + +/* + * Force NKRO + * + * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved + * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the + * makefile for this to work.) + * + * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N) + * until the next keyboard reset. + * + * NKRO may prevent your keystrokes from being detected in the BIOS, but it is + * fully operational during normal computer usage. + * + * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N) + * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by + * bootmagic, NKRO mode will always be enabled until it is toggled again during a + * power-up. + * + */ +//#define FORCE_NKRO + +/* + * Magic Key Options + * + * Magic keys are hotkey commands that allow control over firmware functions of + * the keyboard. They are best used in combination with the HID Listen program, + * found here: https://www.pjrc.com/teensy/hid_listen.html + * + * The options below allow the magic key functionality to be changed. This is + * useful if your keyboard/keypad is missing keys and you want magic key support. + * + */ + +/* key combination for magic key command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +#define RGB_BACKLIGHT_ENABLED 1 + +#define DYNAMIC_KEYMAP_LAYER_COUNT 4 + + +// EEPROM usage + +// TODO: refactor with new user EEPROM code (coming soon) +#define EEPROM_MAGIC 0x451F +#define EEPROM_MAGIC_ADDR 32 +// Bump this every time we change what we store +// This will automatically reset the EEPROM with defaults +// and avoid loading invalid data from the EEPROM +#define EEPROM_VERSION 0x07 +#define EEPROM_VERSION_ADDR 34 + +// Backlight config starts after EEPROM version +#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35 +// Dynamic keymap starts after backlight config (35+37) +#define DYNAMIC_KEYMAP_EEPROM_ADDR 72 diff --git a/keyboards/rama/m6_b/info.json b/keyboards/rama/m6_b/info.json new file mode 100644 index 0000000000..c88a3cc618 --- /dev/null +++ b/keyboards/rama/m6_b/info.json @@ -0,0 +1,19 @@ +{ + "keyboard_name": "m6-b", + "url": "", + "maintainer": "qmk", + "width": 3, + "height": 2, + "layouts": { + "LAYOUT": { + "layout": [ + { "x": 0, "y": 0 }, + { "x": 1, "y": 0 }, + { "x": 2, "y": 0 }, + { "x": 0, "y": 1 }, + { "x": 1, "y": 1 }, + { "x": 2, "y": 1 } + ] + } + } +} diff --git a/keyboards/rama/m6_b/keymaps/default/keymap.c b/keyboards/rama/m6_b/keymaps/default/keymap.c new file mode 100644 index 0000000000..7a408fa8aa --- /dev/null +++ b/keyboards/rama/m6_b/keymaps/default/keymap.c @@ -0,0 +1,16 @@ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + LAYOUT( + KC_1, KC_2, KC_3, KC_4, KC_5, KC_6), + + LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO), + + LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO), + + LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO) }; + diff --git a/keyboards/rama/m6_b/m6_b.c b/keyboards/rama/m6_b/m6_b.c new file mode 100644 index 0000000000..e7cd2f6287 --- /dev/null +++ b/keyboards/rama/m6_b/m6_b.c @@ -0,0 +1,230 @@ +/* Copyright 2018 Jason Williams (Wilba) + * + * 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 "m6_b.h" +#include "m6_b_api.h" + +// Check that no backlight functions are called +#if RGB_BACKLIGHT_ENABLED +#include "rgb_backlight.h" +#endif // RGB_BACKLIGHT_ENABLED + +#include "raw_hid.h" +#include "dynamic_keymap.h" +#include "timer.h" +#include "tmk_core/common/eeprom.h" + +bool eeprom_is_valid(void) +{ + return (eeprom_read_word(((void*)EEPROM_MAGIC_ADDR)) == EEPROM_MAGIC && + eeprom_read_byte(((void*)EEPROM_VERSION_ADDR)) == EEPROM_VERSION); +} + +void eeprom_set_valid(bool valid) +{ + eeprom_update_word(((void*)EEPROM_MAGIC_ADDR), valid ? EEPROM_MAGIC : 0xFFFF); + eeprom_update_byte(((void*)EEPROM_VERSION_ADDR), valid ? EEPROM_VERSION : 0xFF); +} + +void eeprom_reset(void) +{ + // Set the keyboard-specific EEPROM state as invalid. + eeprom_set_valid(false); + // Set the TMK/QMK EEPROM state as invalid. + eeconfig_disable(); +} + +#ifdef RAW_ENABLE + +void raw_hid_receive( uint8_t *data, uint8_t length ) +{ + uint8_t *command_id = &(data[0]); + uint8_t *command_data = &(data[1]); + switch ( *command_id ) + { + case id_get_protocol_version: + { + command_data[0] = PROTOCOL_VERSION >> 8; + command_data[1] = PROTOCOL_VERSION & 0xFF; + break; + } + case id_get_keyboard_value: + { + if ( command_data[0] == id_uptime ) + { + uint32_t value = timer_read32(); + command_data[1] = (value >> 24 ) & 0xFF; + command_data[2] = (value >> 16 ) & 0xFF; + command_data[3] = (value >> 8 ) & 0xFF; + command_data[4] = value & 0xFF; + } + else + { + *command_id = id_unhandled; + } + break; + } +#ifdef DYNAMIC_KEYMAP_ENABLE + case id_dynamic_keymap_get_keycode: + { + uint16_t keycode = dynamic_keymap_get_keycode( command_data[0], command_data[1], command_data[2] ); + command_data[3] = keycode >> 8; + command_data[4] = keycode & 0xFF; + break; + } + case id_dynamic_keymap_set_keycode: + { + dynamic_keymap_set_keycode( command_data[0], command_data[1], command_data[2], ( command_data[3] << 8 ) | command_data[4] ); + break; + } + case id_dynamic_keymap_reset: + { + dynamic_keymap_reset(); + break; + } +#endif // DYNAMIC_KEYMAP_ENABLE +#if RGB_BACKLIGHT_ENABLED + case id_backlight_config_set_value: + { + //backlight_config_set_value(command_data); + break; + } + case id_backlight_config_get_value: + { + //backlight_config_get_value(command_data); + break; + } + case id_backlight_config_save: + { + //backlight_config_save(); + break; + } +#endif // RGB_BACKLIGHT_ENABLED + case id_eeprom_reset: + { + eeprom_reset(); + break; + } + case id_bootloader_jump: + { + // Need to send data back before the jump + // Informs host that the command is handled + raw_hid_send( data, length ); + // Give host time to read it + wait_ms(100); + bootloader_jump(); + break; + } + default: + { + // Unhandled message. + *command_id = id_unhandled; + break; + } + } + + // Return same buffer with values changed + raw_hid_send( data, length ); + +} + +#endif + +void main_init(void) +{ + // If the EEPROM has the magic, the data is good. + // OK to load from EEPROM. + if (eeprom_is_valid()) { +#if RGB_BACKLIGHT_ENABLED + //backlight_config_load(); +#endif // RGB_BACKLIGHT_ENABLED + } else { +#if RGB_BACKLIGHT_ENABLED + // If the EEPROM has not been saved before, or is out of date, + // save the default values to the EEPROM. Default values + // come from construction of the zeal_backlight_config instance. + //backlight_config_save(); +#endif // RGB_BACKLIGHT_ENABLED +#ifdef DYNAMIC_KEYMAP_ENABLE + // This resets the keymaps in EEPROM to what is in flash. + dynamic_keymap_reset(); +#endif + // Save the magic number last, in case saving was interrupted + eeprom_set_valid(true); + } +#if RGB_BACKLIGHT_ENABLED + // Initialize LED drivers for backlight. + backlight_init_drivers(); + + backlight_timer_init(); + backlight_timer_enable(); +#endif // RGB_BACKLIGHT_ENABLED +} + +void bootmagic_lite(void) +{ + // The lite version of TMK's bootmagic. + // 100% less potential for accidentally making the + // keyboard do stupid things. + + // We need multiple scans because debouncing can't be turned off. + matrix_scan(); + wait_ms(DEBOUNCING_DELAY); + wait_ms(DEBOUNCING_DELAY); + matrix_scan(); + + // If the Esc (matrix 0,0) is held down on power up, + // reset the EEPROM valid state and jump to bootloader. + if ( matrix_get_row(0) & (1<<0) ) { + eeprom_reset(); + bootloader_jump(); + } +} + +void matrix_init_kb(void) { + bootmagic_lite(); + main_init(); + matrix_init_user(); +} + +void matrix_scan_kb(void) { +#if RGB_BACKLIGHT_ENABLED + // This only updates the LED driver buffers if something has changed. + backlight_update_pwm_buffers(); +#endif // BACKLIGHT_ENABLED + matrix_scan_user(); +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + return process_record_user(keycode, record); +} + +void led_set_kb(uint8_t usb_led) { + led_set_user(usb_led); +} + +void suspend_power_down_kb(void) +{ +#if RGB_BACKLIGHT_ENABLED + //backlight_set_suspend_state(true); +#endif // BACKLIGHT_ENABLED +} + +void suspend_wakeup_init_kb(void) +{ +#if RGB_BACKLIGHT_ENABLED + //backlight_set_suspend_state(false); +#endif // BACKLIGHT_ENABLED |