From b36a1ef61baf857281f124e27e7d0faefb49ad13 Mon Sep 17 00:00:00 2001 From: Harshit Goel Date: Sat, 2 Jun 2018 00:37:49 +0530 Subject: [PATCH] YMD96 complete QMK port (#3105) * readded code for YMD96 full working * added jj50 layout back --- keyboards/ymd96/README.md | 2 + keyboards/ymd96/backlight.c | 213 ++++++++++++++++++++++ keyboards/ymd96/backlight_custom.h | 15 ++ keyboards/ymd96/breathing_custom.h | 140 ++++++++++++++ keyboards/ymd96/config.h | 30 ++- keyboards/ymd96/keymaps/default/keymap.c | 2 + keyboards/ymd96/keymaps/hgoel89/config.h | 9 + keyboards/ymd96/keymaps/hgoel89/keymap.c | 67 +++++++ keyboards/ymd96/keymaps/hgoel89/readme.md | 2 + keyboards/ymd96/keymaps/hgoel89/rules.mk | 1 + keyboards/ymd96/matrix.c | 28 ++- keyboards/ymd96/rules.mk | 24 ++- keyboards/ymd96/tools/README.md | 16 ++ keyboards/ymd96/tools/usb_detach.c | 33 ++++ keyboards/ymd96/usbconfig.h | 3 +- keyboards/ymd96/ymd96.c | 74 ++++++-- keyboards/ymd96/ymd96.h | 34 ++-- 17 files changed, 650 insertions(+), 43 deletions(-) create mode 100644 keyboards/ymd96/backlight.c create mode 100644 keyboards/ymd96/backlight_custom.h create mode 100644 keyboards/ymd96/breathing_custom.h create mode 100644 keyboards/ymd96/keymaps/hgoel89/config.h create mode 100644 keyboards/ymd96/keymaps/hgoel89/keymap.c create mode 100644 keyboards/ymd96/keymaps/hgoel89/readme.md create mode 100644 keyboards/ymd96/keymaps/hgoel89/rules.mk create mode 100644 keyboards/ymd96/tools/README.md create mode 100644 keyboards/ymd96/tools/usb_detach.c diff --git a/keyboards/ymd96/README.md b/keyboards/ymd96/README.md index 5de5062ecd..7a950223b6 100644 --- a/keyboards/ymd96/README.md +++ b/keyboards/ymd96/README.md @@ -17,6 +17,8 @@ Keyboard maintainer: [Andrew](https://github.com/sparkyman215) Hardware Supported: YMD96 with the ATmega32a chip. Hardware Availability: The GB was run June 2017, [in this thread](https://www.reddit.com/r/mechmarket/comments/6hu3yx/vendor_ymd96_gb_is_now_live_68_an_universal_and/). The vendor has stated that they plan on selling more rounds. +A very big thanks to @krusli for making the RGB underglow, Backlight, CapsLock and NumLock LEDs working correctly. + ## Finding your specific matrix This firmware was modified from [ps2avrGB](https://github.com/qmk/qmk_firmware/tree/master/keyboards/ps2avrGB), also found on this qmk repo, to work with the YMD96 keyboard. However, I only have one board to test with, which might have a different layout than yours. To get qmk working with your specific layout, you'll need to follow these steps: diff --git a/keyboards/ymd96/backlight.c b/keyboards/ymd96/backlight.c new file mode 100644 index 0000000000..36c5563875 --- /dev/null +++ b/keyboards/ymd96/backlight.c @@ -0,0 +1,213 @@ +/** + * Backlighting code for PS2AVRGB boards (ATMEGA32A) + * Kenneth A. (github.com/krusli | krusli.me) + */ + +#include "backlight.h" +#include "quantum.h" + +#include +#include + +#include "backlight_custom.h" +#include "breathing_custom.h" + +// DEBUG +#include +#include + +// Port D: digital pins of the AVR chipset +#define NUMLOCK_PORT (1 << 0) // 0th pin of Port D (digital) +#define CAPSLOCK_PORT (1 << 1) // 1st pin +#define BACKLIGHT_PORT (1 << 4) // 4th pin +//#define SCROLLLOCK_PORT (1 << 6) // 6th pin + +#define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 +#define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default + +#define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask + +#define PWM_MAX 0xFF +#define TIMER_TOP 255 // 8 bit PWM + +extern backlight_config_t backlight_config; + +/** + * References + * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation + * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b + * Timers: http://www.avrbeginners.net/architecture/timers/timers.html + * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/ + * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware + */ + +// @Override +// turn LEDs on and off depending on USB caps/num/scroll lock states. +void led_set_user(uint8_t usb_led) { + if (usb_led & (1 << USB_LED_NUM_LOCK)) { + // turn on + DDRD |= NUMLOCK_PORT; + PORTD |= NUMLOCK_PORT; + } else { + // turn off + DDRD &= ~NUMLOCK_PORT; + PORTD &= ~NUMLOCK_PORT; + } + + if (usb_led & (1 << USB_LED_CAPS_LOCK)) { + DDRD |= CAPSLOCK_PORT; + PORTD |= CAPSLOCK_PORT; + } else { + DDRD &= ~CAPSLOCK_PORT; + PORTD &= ~CAPSLOCK_PORT; + } + + /* YMD96 does not have scroll lock led + if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { + DDRD |= SCROLLLOCK_PORT; + PORTD |= SCROLLLOCK_PORT; + } else { + DDRD &= ~SCROLLLOCK_PORT; + PORTD &= ~SCROLLLOCK_PORT; + }*/ +} + +#ifdef BACKLIGHT_ENABLE + +// sets up Timer 1 for 8-bit PWM +void timer1PWMSetup(void) { // NOTE ONLY CALL THIS ONCE + // default 8 bit mode + TCCR1A &= ~(1 << 1); // cbi(TCCR1A,PWM11); <- set PWM11 bit to HIGH + TCCR1A |= (1 << 0); // sbi(TCCR1A,PWM10); <- set PWM10 bit to LOW + + // clear output compare value A + // outb(OCR1AH, 0); + // outb(OCR1AL, 0); + + // clear output comparator registers for B + OCR1BH = 0; // outb(OCR1BH, 0); + OCR1BL = 0; // outb(OCR1BL, 0); +} + +bool is_init = false; +void timer1Init(void) { + // timer1SetPrescaler(TIMER1PRESCALE) + // set to DIV/64 + (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER1PRESCALE; + + // reset TCNT1 + TCNT1H = 0; // outb(TCNT1H, 0); + TCNT1L = 0; // outb(TCNT1L, 0); + + // TOIE1: Timer Overflow Interrupt Enable (Timer 1); + TIMSK |= _BV(TOIE1); // sbi(TIMSK, TOIE1); + + is_init = true; +} + +void timer1UnInit(void) { + // set prescaler back to NONE + (TCCR1B) = ((TCCR1B) & ~TIMER_PRESCALE_MASK) | 0x00; // TIMERRTC_CLK_STOP + + // disable timer overflow interrupt + TIMSK &= ~_BV(TOIE1); // overflow bit? + + setPWM(0); + + is_init = false; +} + + +// handle TCNT1 overflow +//! Interrupt handler for tcnt1 overflow interrupt +ISR(TIMER1_OVF_vect, ISR_NOBLOCK) +{ + // sei(); + // handle breathing here + #ifdef BACKLIGHT_BREATHING + if (is_breathing()) { + custom_breathing_handler(); + } + #endif + + // TODO call user defined function +} + +// enable timer 1 PWM +// timer1PWMBOn() +void timer1PWMBEnable(void) { + // turn on channel B (OC1B) PWM output + // set OC1B as non-inverted PWM + TCCR1A |= _BV(COM1B1); + TCCR1A &= ~_BV(COM1B0); +} + +// disable timer 1 PWM +// timer1PWMBOff() +void timer1PWMBDisable(void) { + TCCR1A &= ~_BV(COM1B1); + TCCR1A &= ~_BV(COM1B0); +} + +void enableBacklight(void) { + DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output + PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high +} + +void disableBacklight(void) { + // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input + PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low +} + +void startPWM(void) { + timer1Init(); + timer1PWMBEnable(); + enableBacklight(); +} + +void stopPWM(void) { + timer1UnInit(); + disableBacklight(); + timer1PWMBDisable(); +} + +void b_led_init_ports(void) { + /* turn backlight on/off depending on user preference */ + #if BACKLIGHT_ON_STATE == 0 + // DDRx register: sets the direction of Port D + // DDRD &= ~BACKLIGHT_PORT; // set digital pin 4 as input + PORTD &= ~BACKLIGHT_PORT; // set digital pin 4 to low + #else + DDRD |= BACKLIGHT_PORT; // set digital pin 4 as output + PORTD |= BACKLIGHT_PORT; // set digital pin 4 to high + #endif + + timer1PWMSetup(); + startPWM(); + + #ifdef BACKLIGHT_BREATHING + breathing_enable(); + #endif +} + +void b_led_set(uint8_t level) { + if (level > BACKLIGHT_LEVELS) { + level = BACKLIGHT_LEVELS; + } + + setPWM((int)(TIMER_TOP * (float) level / BACKLIGHT_LEVELS)); +} + +// called every matrix scan +void b_led_task(void) { + // do nothing for now +} + +void setPWM(uint16_t xValue) { + if (xValue > TIMER_TOP) { + xValue = TIMER_TOP; + } + OCR1B = xValue; // timer1PWMBSet(xValue); +} + +#endif // BACKLIGHT_ENABLE diff --git a/keyboards/ymd96/backlight_custom.h b/keyboards/ymd96/backlight_custom.h new file mode 100644 index 0000000000..7210be840e --- /dev/null +++ b/keyboards/ymd96/backlight_custom.h @@ -0,0 +1,15 @@ +/** + * Backlighting code for PS2AVRGB boards (ATMEGA32A) + * Kenneth A. (github.com/krusli | krusli.me) + */ + +#ifndef BACKLIGHT_CUSTOM_H +#define BACKLIGHT_CUSTOM_H + +#include +void b_led_init_ports(void); +void b_led_set(uint8_t level); +void b_led_task(void); +void setPWM(uint16_t xValue); + +#endif // BACKLIGHT_CUSTOM_H diff --git a/keyboards/ymd96/breathing_custom.h b/keyboards/ymd96/breathing_custom.h new file mode 100644 index 0000000000..71416b1b45 --- /dev/null +++ b/keyboards/ymd96/breathing_custom.h @@ -0,0 +1,140 @@ +/** + * Breathing effect code for PS2AVRGB boards (ATMEGA32A) + * Works in conjunction with `backlight.c`. + * + * Code adapted from `quantum.c` to register with the existing TIMER1 overflow + * handler in `backlight.c` instead of setting up its own timer. + * Kenneth A. (github.com/krusli | krusli.me) + */ + +#ifdef BACKLIGHT_ENABLE +#ifdef BACKLIGHT_BREATHING + +#include "backlight_custom.h" + +#ifndef BREATHING_PERIOD +#define BREATHING_PERIOD 6 +#endif + +#define breathing_min() do {breathing_counter = 0;} while (0) +#define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) + +// TODO make this share code with quantum.c + +#define BREATHING_NO_HALT 0 +#define BREATHING_HALT_OFF 1 +#define BREATHING_HALT_ON 2 +#define BREATHING_STEPS 128 + +static uint8_t breathing_period = BREATHING_PERIOD; +static uint8_t breathing_halt = BREATHING_NO_HALT; +static uint16_t breathing_counter = 0; + +static bool breathing = false; + +bool is_breathing(void) { + return breathing; +} + +// See http://jared.geek.nz/2013/feb/linear-led-pwm +static uint16_t cie_lightness(uint16_t v) { + if (v <= 5243) // if below 8% of max + return v / 9; // same as dividing by 900% + else { + uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare + // to get a useful result with integer division, we shift left in the expression above + // and revert what we've done again after squaring. + y = y * y * y >> 8; + if (y > 0xFFFFUL) // prevent overflow + return 0xFFFFU; + else + return (uint16_t) y; + } +} + +void breathing_enable(void) { + breathing = true; + breathing_counter = 0; + breathing_halt = BREATHING_NO_HALT; + // interrupt already registered +} + +void breathing_pulse(void) { + if (get_backlight_level() == 0) + breathing_min(); + else + breathing_max(); + breathing_halt = BREATHING_HALT_ON; + // breathing_interrupt_enable(); + breathing = true; +} + +void breathing_disable(void) { + breathing = false; + // backlight_set(get_backlight_level()); + b_led_set(get_backlight_level()); // custom implementation of backlight_set() +} + +void breathing_self_disable(void) +{ + if (get_backlight_level() == 0) + breathing_halt = BREATHING_HALT_OFF; + else + breathing_halt = BREATHING_HALT_ON; +} + +void breathing_toggle(void) { + if (is_breathing()) + breathing_disable(); + else + breathing_enable(); +} + +void breathing_period_set(uint8_t value) +{ + if (!value) + value = 1; + breathing_period = value; +} + +void breathing_period_default(void) { + breathing_period_set(BREATHING_PERIOD); +} + +void breathing_period_inc(void) +{ + breathing_period_set(breathing_period+1); +} + +void breathing_period_dec(void) +{ + breathing_period_set(breathing_period-1); +} + +/* To generate breathing curve in python: + * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] + */ +static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +// Use this before the cie_lightness function. +static inline uint16_t scale_backlight(uint16_t v) { + return v / BACKLIGHT_LEVELS * get_backlight_level(); +} + +void custom_breathing_handler(void) { + uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; + // resetting after one period to prevent ugly reset at overflow. + breathing_counter = (breathing_counter + 1) % (breathing_period * 244); + uint8_t index = breathing_counter / interval % BREATHING_STEPS; + + if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) || + ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1))) + { + // breathing_interrupt_disable(); + } + + setPWM(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U))); +} + +#endif // BACKLIGHT_BREATHING +#endif // BACKLIGHT_ENABLE diff --git a/keyboards/ymd96/config.h b/keyboards/ymd96/config.h index 8a0668ac98..3122c694eb 100644 --- a/keyboards/ymd96/config.h +++ b/keyboards/ymd96/config.h @@ -1,7 +1,7 @@ /* Base Copyright 2017 Luiz Ribeiro Modified 2017 Andrew Novak - +Modified 2018 Harshit Goel 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 @@ -16,6 +16,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "config_common.h" + #ifndef CONFIG_H #define CONFIG_H @@ -29,15 +31,29 @@ along with this program. If not, see . /* matrix size */ #define MATRIX_ROWS 8 #define MATRIX_COLS 15 -#define DIODE_DIRECTION ROW2COL +//#define DIODE_DIRECTION ROW2COL -#define RGB_DI_PIN C4 -#define RGBLED_NUM 18 -#define RGBLIGHT_ANIMATIONS -#define RGBLIGHT_VAL_STEP 20 +//#define RGB_DI_PIN C4 +/* COL2ROW or ROW2COL */ +#define DIODE_DIRECTION COL2ROW + +#define BACKLIGHT_LEVELS 12 +// #define BACKLIGHT_BREATHING // works, but BL_TOGG might not work + +#define TAPPING_TOGGLE 3 #define NO_UART 1 -#define BOOTLOADHID_BOOTLOADER 1 + +/* RGB underglow */ +// The RGB_DI_PIN value seems to be shared between all PS2AVRGB boards. +// The same pin is used on the JJ40, at least. +#define RGBLED_NUM 18 +#define RGB_DI_PIN E2 // NOTE: for PS2AVRGB boards, underglow commands are sent via I2C to 0xB0. +#define RGBLIGHT_ANIMATIONS +/*#define RGBLIGHT_VAL_STEP 20 + +#define NO_UART 1 +#define BOOTLOADHID_BOOTLOADER 1*/ /* key combination for command */ #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) diff --git a/keyboards/ymd96/keymaps/default/keymap.c b/keyboards/ymd96/keymaps/default/keymap.c index 1ca3d22a34..9d0a8261dc 100644 --- a/keyboards/ymd96/keymaps/default/keymap.c +++ b/keyboards/ymd96/keymaps/default/keymap.c @@ -24,6 +24,8 @@ along with this program. If not, see . #define _DEFLT 0 #define _RAISE 1 +#define KEYMAP KEYMAP_DEFAULT + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Layer 0, default layer diff --git a/keyboards/ymd96/keymaps/hgoel89/config.h b/keyboards/ymd96/keymaps/hgoel89/config.h new file mode 100644 index 0000000000..52aaa8f24d --- /dev/null +++ b/keyboards/ymd96/keymaps/hgoel89/config.h @@ -0,0 +1,9 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +#define PREVENT_STUCK_MODIFIERS +#define TAPPING_TERM 300 + +#endif diff --git a/keyboards/ymd96/keymaps/hgoel89/keymap.c b/keyboards/ymd96/keymaps/hgoel89/keymap.c new file mode 100644 index 0000000000..81addf69f4 --- /dev/null +++ b/keyboards/ymd96/keymaps/hgoel89/keymap.c @@ -0,0 +1,67 @@ +#include "ymd96.h" +#include "action_layer.h" + +/* +#define _QWERTY 0 +#define _LOWER 1 +#define _RAISE 2*/ +/* +enum custom_keycodes { + QWERTY = SAFE_RANGE, + LOWER, + RAISE, +};*/ + +void matrix_scan_user(void) { + // runs at every matrix scan. +} + +enum { + TD_H_E = 0 +}; + +qk_tap_dance_action_t tap_dance_actions[] = { + [TD_H_E] = ACTION_TAP_DANCE_DOUBLE(KC_HOME, KC_END) +}; +#define ______ KC_TRNS +#define _DEFLT 0 +#define _RAISE 1 + +#define KEYMAP KEYMAP_CUSTOM + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* Layer 0, default layer + * | Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |Print | Home | End |Insert|Delete| PgUp | 19 keys + * | ~` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BkSpc |NumLck| / | * | PgDn | 18 keys + * | Tab | Q | W | E | R | T | Y | U | I | O | P | { | } | \ | 7 | 8 | 9 | - | 18 keys + * | Caps | A | S | D | F | G | H | J | K | L | ; | ' | Return | 4 | 5 | 6 | + | 17 keys + * | LShft | Z | X | C | V | B | N | M | , | . | / | RShft | 1 | 2 | 3 | En | 16 keys + * | Ctrl | Win | Alt | Space | Fn | Win | Left | Down | Up | Right| 0 | . | | 12 keys + */ + + [_DEFLT] = KEYMAP( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_HOME, KC_END, KC_INSERT, KC_DELETE, KC_PGUP, \ + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_NUMLOCK, KC_KP_SLASH, KC_KP_ASTERISK, KC_PMNS, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_P7, KC_P8, KC_P9, KC_NO, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6, KC_PPLS, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, KC_P1, KC_P2, KC_P3, KC_PENT, \ + KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RGUI , KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, MO(_RAISE), KC_P0, KC_PDOT \ + ), + /* Layer 1, raise layer + * | | | | | | | | | | | | | | | | | | | | + * | | | | | | | | | | | | | | | | | | | + * | | |rgb_up|rgb_dn|rgb_mo| | | | | | F22 | F23 | F24 | | | | | | + * | | | | | | | | | | | | | | | | | | + * | | | | | | | | | VolDn| VolUp| Mute | Play/Pause | | | | | + * | | | | | | |MPrev | | | MNext| | | | + */ + [_RAISE] = KEYMAP( + RESET,RGB_TOG, BL_TOGG, BL_STEP, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, \ + ______, BL_INC, BL_DEC, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, \ + ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, KC_F22, KC_F23, KC_F24, ______, ______, ______, ______, ______, \ + ______, RGB_HUI, RGB_SAI, RGB_VAI, RGB_MODE_FORWARD , ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, ______, \ + ______, RGB_HUD, RGB_SAD, RGB_VAD, ______, ______, ______, ______, KC_VOLD,KC_VOLU, KC_MUTE, KC_MPLY, ______, ______, ______, ______, \ + ______, ______, BL_OFF, BL_ON, ______, ______, ______, ______, ______, ______, ______, ______ \ + ) +}; diff --git a/keyboards/ymd96/keymaps/hgoel89/readme.md b/keyboards/ymd96/keymaps/hgoel89/readme.md new file mode 100644 index 0000000000..05488df990 --- /dev/null +++ b/keyboards/ymd96/keymaps/hgoel89/readme.md @@ -0,0 +1,2 @@ +# Harshit +Modified the layout according to me. Full 2u NumPad 0, 5 * 1u modifiers on right of space. Split right shift. \ No newline at end of file diff --git a/keyboards/ymd96/keymaps/hgoel89/rules.mk b/keyboards/ymd96/keymaps/hgoel89/rules.mk new file mode 100644 index 0000000000..e5ddcae8d9 --- /dev/null +++ b/keyboards/ymd96/keymaps/hgoel89/rules.mk @@ -0,0 +1 @@ +TAP_DANCE_ENABLE = yes diff --git a/keyboards/ymd96/matrix.c b/keyboards/ymd96/matrix.c index 140026013f..f2ecf4d33c 100644 --- a/keyboards/ymd96/matrix.c +++ b/keyboards/ymd96/matrix.c @@ -29,6 +29,9 @@ static uint8_t debouncing = DEBOUNCE; static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +void matrix_set_row_status(uint8_t row); +uint8_t bit_reverse(uint8_t x); + void matrix_init(void) { // all outputs for rows high DDRB = 0xFF; @@ -47,18 +50,20 @@ void matrix_init(void) { matrix[row] = 0x00; matrix_debouncing[row] = 0x00; } -} +/*} + matrix_init_quantum(); // missing from original port by Luiz void matrix_set_row_status(uint8_t row) { DDRB = (1 << row); PORTB = ~(1 << row); -} +}*/ -uint8_t bit_reverse(uint8_t x) { + +/*uint8_t bit_reverse(uint8_t x) { x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); - return x; + return x;*/ } uint8_t matrix_scan(void) { @@ -93,11 +98,24 @@ uint8_t matrix_scan(void) { } } - matrix_scan_user(); + matrix_scan_quantum(); // also missing in original PS2AVRGB implementation return 1; } +// declarations +void matrix_set_row_status(uint8_t row) { + DDRB = (1 << row); + PORTB = ~(1 << row); +} + +uint8_t bit_reverse(uint8_t x) { + x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); + x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); + x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); + return x; +} + inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } diff --git a/keyboards/ymd96/rules.mk b/keyboards/ymd96/rules.mk index c7c12dcf17..42b3d11551 100644 --- a/keyboards/ymd96/rules.mk +++ b/keyboards/ymd96/rules.mk @@ -26,25 +26,33 @@ F_CPU = 12000000 # Bootloader # This definition is optional, and if your keyboard supports multiple bootloaders of -# different sizes, comment this out, and the correct address will be loaded +# different sizes, comment this out, and the correct address will be loaded # automatically (+60). See bootloader.mk for all options. -BOOTLOADER = atmel-dfu +BOOTLOADER = bootloadHID # build options -BOOTMAGIC_ENABLE = yes -MOUSEKEY_ENABLE = yes +BOOTMAGIC_ENABLE = no +MOUSEKEY_ENABLE = no EXTRAKEY_ENABLE = yes -CONSOLE_ENABLE = yes +CONSOLE_ENABLE = no COMMAND_ENABLE = yes -BACKLIGHT_ENABLE = no + +BACKLIGHT_ENABLE = yes +BACKLIGHT_CUSTOM_DRIVER = yes + RGBLIGHT_ENABLE = yes RGBLIGHT_CUSTOM_DRIVER = yes +KEY_LOCK_ENABLE = yes + +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend + OPT_DEFS = -DDEBUG_LEVEL=0 # custom matrix setup CUSTOM_MATRIX = yes -SRC = matrix.c i2c.c +SRC = matrix.c i2c.c backlight.c # programming options -PROGRAM_CMD = ./keyboards/ps2avrGB/program $(TARGET).hex +PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex diff --git a/keyboards/ymd96/tools/README.md b/keyboards/ymd96/tools/README.md new file mode 100644 index 0000000000..081984ed44 --- /dev/null +++ b/keyboards/ymd96/tools/README.md @@ -0,0 +1,16 @@ +# JJ40 Tools + +## usb_detach.c + +When trying to flash on Linux, you may encounter a "Resource Unavailable" error. This means that Linux's HID driver has taken exclusive control of the keyboard, and the program script can't flash it. +This program can force Linux to give up a device, so that the programming script can reset it. + +### To compile: +``` +gcc usb_detach.c -o usb_detach +``` + +### To run: +1. Use `lsusb` to discover the Bus and Device numbers for your keyboard. +2. Run the program: `sudo ./usb_detach /dev/bus/usb//`. +3. Build and program the firmware as normal. diff --git a/keyboards/ymd96/tools/usb_detach.c b/keyboards/ymd96/tools/usb_detach.c new file mode 100644 index 0000000000..c21e47a7a4 --- /dev/null +++ b/keyboards/ymd96/tools/usb_detach.c @@ -0,0 +1,33 @@ +/* Found at https://www.linuxquestions.org/questions/linux-hardware-18/how-to-unclaim-usb-device-558138/#post3406986 */ +#include +#include +#include +#include +#include +#include + +int main(int argc, char**argv) +{ + struct usbdevfs_ioctl command; + int ret; + int fd; + int i; + if (argc>1) { + fd = open(argv[1],O_RDWR); + if (fd<1){ + perror("unable to open file"); + return 1; + } + for (i=0;i<255;i++){ // hack: should fetch how many interface there is. + command.ifno = i; + command.ioctl_code = USBDEVFS_DISCONNECT; + command.data = NULL; + ret = ioctl(fd, USBDEVFS_IOCTL, &command); + if(ret!=-1) + printf("un claimed interface %d %d\n",i,ret); + } + } else { + printf ("usage: %s /dev/bus/usb/BUS/DEVICE\n",argv[0]); + printf("Release all interfaces of this usb device for usage in virtualisation\n"); + } +} \ No newline at end of file diff --git a/keyboards/ymd96/usbconfig.h b/keyboards/ymd96/usbconfig.h index d2d848fcdc..50fe4ed113 100644 --- a/keyboards/ymd96/usbconfig.h +++ b/keyboards/ymd96/usbconfig.h @@ -118,7 +118,8 @@ section at the end of this file). /* Define this to 1 if the device has its own power supply. Set it to 0 if the * device is powered from the USB bus. */ -#define USB_CFG_MAX_BUS_POWER 500 +// max power draw with maxed white underglow measured at 120 mA (peaks) +#define USB_CFG_MAX_BUS_POWER 100 /* Set this variable to the maximum USB bus power consumption of your device. * The value is in milliamperes. [It will be divided by two since USB * communicates power requirements in units of 2 mA.] diff --git a/keyboards/ymd96/ymd96.c b/keyboards/ymd96/ymd96.c index fa786dc3cd..b0bf6128fa 100644 --- a/keyboards/ymd96/ymd96.c +++ b/keyboards/ymd96/ymd96.c @@ -1,5 +1,6 @@ /* Copyright 2017 Luiz Ribeiro +Modified 2018 Kenneth A. 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 @@ -16,30 +17,81 @@ along with this program. If not, see . */ #include "ymd96.h" -#include "rgblight.h" #include #include "action_layer.h" -#include "i2c.h" #include "quantum.h" +#include "i2c.h" + +#include "backlight.h" +#include "backlight_custom.h" + +// for keyboard subdirectory level init functions +// @Override +void matrix_init_kb(void) { + // call user level keymaps, if any + matrix_init_user(); +} + +#ifdef BACKLIGHT_ENABLE +/// Overrides functions in `quantum.c` +void backlight_init_ports(void) { + b_led_init_ports(); +} + +void backlight_task(void) { + b_led_task(); +} + +void backlight_set(uint8_t level) { + b_led_set(level); +} +#endif + +#ifdef RGBLIGHT_ENABLE extern rgblight_config_t rgblight_config; +// custom RGB driver void rgblight_set(void) { - if (!rgblight_config.enable) { - for (uint8_t i = 0; i < RGBLED_NUM; i++) { - led[i].r = 0; - led[i].g = 0; - led[i].b = 0; - } + if (!rgblight_config.enable) { + for (uint8_t i=0; i Modified 2017 Andrew Novak - +Modified 2018 harshit goel 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 @@ -19,11 +19,14 @@ along with this program. If not, see . #ifndef KEYMAP_COMMON_H #define KEYMAP_COMMON_H +#include "quantum.h" #include "quantum_keycodes.h" #include "keycode.h" #include "action.h" -#define KEYMAP( \ +void matrix_init_user(void); // TODO port this to other PS2AVRGB boards + +#define KEYMAP_DEFAULT( \ K500, K502, K503, K504, K505, K600, K610, K710, K700, K511, K512, K513, K514, K113, K214, K013, K706, K709, K708, \ K400, K401, K402, K403, K404, K405, K601, K611, K711, K701, K410, K411, K412, K414, K406, K407, K408, K409, \ K300, K301, K302, K303, K304, K305, K602, K612, K712, K702, K310, K311, K312, K313, K306, K307, K308, K309, \ @@ -41,6 +44,24 @@ along with this program. If not, see . { K700, K701, K702, K703, K704, K705, K706, KC_NO, K708, K709, K710, K711, K712, K713, K714 } \ } +#define KEYMAP_CUSTOM( \ + K500, K502, K503, K504, K505, K600, K610, K710, K700, K511, K512, K513, K514, K113, K214, K013, K706, K709, K708, \ + K400, K401, K402, K403, K404, K405, K601, K611, K711, K701, K410, K411, K412, K414, K406, K407, K408, K409, \ + K300, K301, K302, K303, K304, K305, K602, K612, K712, K702, K310, K311, K312, K313, K306, K307, K308, K309, \ + K200, K201, K202, K203, K204, K205, K603, K613, K713, K703, K210, K211, K213, K206, K207, K208, K209, \ + K100, K101, K102, K103, K104, K105, K604, K614, K714, K704, K110, K111, K106, K107, K108, K009, \ + K000, K001, K002, K605, K705, K010, K011, K606, K607, KC_NO, K006, K008 \ +) { \ + { K000, K001, K002, KC_NO, KC_NO, KC_NO, K006, KC_NO, K008, K009, K010, K011, KC_NO, K013, KC_NO, }, \ + { K100, K101, K102, K103, K104, K105, K106, K107, K108, KC_NO, K110, K111, KC_NO, K113, KC_NO, }, \ + { K200, K201, K202, K203, K204, K205, K206, K207, K208, K209, K210, K211, KC_NO, K213, K214, }, \ + { K300, K301, K302, K303, K304, K305, K306, K307, K308, K309, K310, K311, K312, K313, KC_NO, }, \ + { K400, K401, K402, K403, K404, K405, K406, K407, K408, K409, K410, K411, K412, KC_NO, K414, }, \ + { K500, KC_NO, K502, K503, K504, K505, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, K511, K512, K513, K514, }, \ + { K600, K601, K602, K603, K604, K605, K606, K607, KC_NO, KC_NO, K610, K611, K612, K613, K614, }, \ + { K700, K701, K702, K703, K704, K705, K706, KC_NO, K708, K709, K710, K711, K712, K713, K714 } \ +} + #define LAYOUT_jj50( \ K011, K010, K009, K008, K004, K005, K006, K007, K003, K002, K201, K000, \ K111, K110, K109, K108, K104, K105, K106, K107, K103, K102, K001, K100, \ @@ -57,12 +78,3 @@ K411, K410, K409, K408, K404, K405, K406, K407, K403, K402, K401, K400 \ #endif - - - - - - - - -