Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Keyboard] Add support for jj4x4 numpad/macropad by Kprepublic (#5016)
* added keyboard jj4x4, a shorter version of the jj40 * removed useless file * edited jj4x4 readme.md * optimized array size in jj4x4 config.h, removed reference to jj40 layouts from rules.mk * removed custom matrix for this ps2avrgb board, refactored column and row pins
- Loading branch information
Showing
15 changed files
with
1,325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# jj4x4 | ||
|
||
![jj4x4](https://cdn.shopify.com/s/files/1/2711/4238/products/JJ4x4case-1_1024x1024.jpg?v=1532325339) | ||
|
||
A 4x4 keypad kit made and KPRepublic on AliExpress. This is a chopped off version of the jj40 with rearranged keys. | ||
|
||
Keyboard Maintainer: [QMK Community](https://github.com/qmk) | ||
Hardware Supported: Atmega32A | ||
Hardware Availability: [AliExpress](https://www.aliexpress.com/item/jj4x4-jj4X4-16-keys-Custom-Mechanical-Keyboard-PCB-programmed-numpad-layouts-bface-firmware-with-rgb-bottom/32901955446.html?spm=2114.search0104.3.7.3ebf431ae1d9ic&ws_ab_test=searchweb0_0,searchweb201602_4_10065_10130_10068_10547_319_317_10548_10545_10696_453_10084_454_10083_433_10618_431_10307_537_536_10902_10059_10884_10887_321_322_10103,searchweb201603_6,ppcSwitch_0&algo_expid=9d1891dd-80af-4793-a889-5a62e1fdfdd8-1&algo_pvid=9d1891dd-80af-4793-a889-5a62e1fdfdd8&transAbTest=ae803_5) | ||
|
||
Make example for this keyboard (after setting up your build environment): | ||
|
||
make jj4x4:default:program | ||
|
||
See [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) then the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. | ||
|
||
Note that this is a complete replacement for the firmware, so you won't be | ||
using Bootmapper Client to change any keyboard settings, since not all the | ||
USB report options are supported. | ||
|
||
In addition you may need the AVR toolchain and `bootloadHID` ([GitHub repo](https://github.com/whiteneon/bootloadHID)) for flashing: | ||
|
||
For macOS: | ||
``` | ||
$ brew cask install crosspack-avr | ||
$ brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb | ||
``` | ||
|
||
For Linux: | ||
``` | ||
$ sudo apt install libusb-dev | ||
$ wget https://www.obdev.at/downloads/vusb/bootloadHID.2012-12-08.tar.gz | ||
$ tar -xzf bootloadHID.2012-12-08.tar.gz | ||
$ cd bootloadHID.2012-12-08/commandline | ||
$ make | ||
$ sudo cp bootloadHID /usr/bin | ||
``` | ||
|
||
In order to use the `./program` script, which can reboot the board into | ||
the bootloader, you'll need Python 2 with PyUSB installed: | ||
|
||
``` | ||
$ pip install pyusb | ||
``` | ||
|
||
If you prefer (or are having issues with a `program` flash), you can just build it (`make jj40:<keymap-name>` and flash the firmware (`.hex` file) directly with | ||
`bootloadHID` if you boot the board while holding down `8` (second from top, second from left, with usb plug is at the top) to keep it | ||
in the bootloader: | ||
|
||
``` | ||
$ make jj40 | ||
$ bootloadHID -r jj4x4_default.hex | ||
``` | ||
|
||
For Windows 10: | ||
Windows sometimes doesn't recognize the jj4x4. The easiest way of flashing a new layout is probably using [HIDBootFlash](http://vusb.wikidot.com/project:hidbootflash). | ||
1. Go to Windows Device Manager and find the keyboard (plug it in while holding down `8` (second from top, second from left, with usb plug is at the top)). It can be found under Human Interface Devices or under Keyboards. | ||
2. Go to properties and the Details tab to find the hardware ID. You want the VID and the PID (code after the underscore). Plug them into HIDBootFlash and hit Find Device. | ||
3. Use `make jj4x4:<keymap-name>` to generate the .hex file in the qmk basis folder. Select the .hex file in HIDBootFlash and press Flash Device. | ||
|
||
|
||
## Troubleshooting | ||
|
||
1. Try plugging the board in while pressing `8` (usb plug at top, second from top, second from left). This will force it | ||
to boot only the bootloader without loading the firmware. Once this is | ||
done, just reflash the board with the original firmware. | ||
2. Sometimes USB hubs can act weird, so try connecting the board directly | ||
to your computer or plugging/unplugging the USB hub. | ||
3. If you get an error such as "Resource Unavailable" when attemting to flash | ||
on Linux, you may want to compile and run `tools/usb_detach.c`. See `tools/README.md` | ||
for more info. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/** | ||
* Backlighting code for PS2AVRGB boards (ATMEGA32A) | ||
* Kenneth A. (github.com/krusli | krusli.me) | ||
*/ | ||
|
||
#include "backlight.h" | ||
#include "quantum.h" | ||
|
||
#include <avr/pgmspace.h> | ||
#include <avr/interrupt.h> | ||
|
||
#include "backlight_custom.h" | ||
#include "breathing_custom.h" | ||
|
||
// DEBUG | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
// Port D: digital pins of the AVR chipset | ||
#define NUMLOCK_PORT (1 << 0) // D0 | ||
#define CAPSLOCK_PORT (1 << 1) // D1 | ||
#define BACKLIGHT_PORT (1 << 4) // D4 | ||
#define SCROLLLOCK_PORT (1 << 6) // D6 | ||
|
||
#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. | ||
__attribute__ ((weak)) | ||
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; | ||
} | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <avr/pgmspace.h> | ||
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 |
Oops, something went wrong.