Skip to content

Commit

Permalink
[Keyboard] Work Louder board fixup (qmk#14247)
Browse files Browse the repository at this point in the history
* [Keyboard] Add some last minute tweaks to Work board

* Additional fixes

* Fix rgb pin

* Fix ws2812 hackery

* additional led tweaks

* Add indicator LEDs

* fix bootmagic settings

* Fix up RGB stuff

* Limit power draw for entire board

* fixup lights and such

* change LED order on loop

* Fix indicators if via is not enabled

* Enable Sleep for rgb matrix

* Even more LED tweaks

* Final tweaks?

* Tweak keycodes
  • Loading branch information
drashna authored and Billy Bryant committed Sep 29, 2021
1 parent cadad22 commit d9e9a96
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 112 deletions.
35 changes: 20 additions & 15 deletions keyboards/work_louder/loop/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT_ID 0x1DF8
#define DEVICE_VER 0x0001
#define MANUFACTURER Work Louder
#define PRODUCT loop
#define PRODUCT Loop Pad

/* key matrix size */
#define MATRIX_ROWS 2
Expand All @@ -40,7 +40,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
*
*/
#define MATRIX_ROW_PINS { F5 }
#define MATRIX_ROW_PINS \
{ F5, NO_PIN }
#define MATRIX_COL_PINS { B3, B2, B1, D6, D7, B4, B5, B6, C6, C7, F7, F6 }
#define UNUSED_PINS

Expand All @@ -63,20 +64,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//# define RGBLIGHT_HUE_STEP 8
//# define RGBLIGHT_SAT_STEP 8
//# define RGBLIGHT_VAL_STEP 8
//# define RGBLIGHT_LIMIT_VAL 255 /* The maximum brightness level */
# define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */
/*== all animations enable ==*/
# define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_LIMIT_VAL 120 /* The maximum brightness level */
#define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */
/*== or choose animations ==*/
//# define RGBLIGHT_EFFECT_BREATHING
//# define RGBLIGHT_EFFECT_RAINBOW_MOOD
//# define RGBLIGHT_EFFECT_RAINBOW_SWIRL
//# define RGBLIGHT_EFFECT_SNAKE
//# define RGBLIGHT_EFFECT_KNIGHT
//# define RGBLIGHT_EFFECT_CHRISTMAS
//# define RGBLIGHT_EFFECT_STATIC_GRADIENT
//# define RGBLIGHT_EFFECT_RGB_TEST
//# define RGBLIGHT_EFFECT_ALTERNATING
#define RGBLIGHT_EFFECT_BREATHING
#define RGBLIGHT_EFFECT_RAINBOW_MOOD
#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
#define RGBLIGHT_EFFECT_SNAKE
#define RGBLIGHT_EFFECT_KNIGHT
#define RGBLIGHT_EFFECT_CHRISTMAS
#define RGBLIGHT_EFFECT_STATIC_GRADIENT
#define RGBLIGHT_EFFECT_RGB_TEST
#define RGBLIGHT_EFFECT_TWINKLE

#define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_LIGHT
#define RGBLIGHT_DEFAULT_HUE 36
/*== customize breathing effect ==*/
/*==== (DEFAULT) use fixed table instead of exp() and sin() ====*/
//# define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256(default) or 128 or 64
Expand All @@ -87,7 +89,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#define RGB_DI_PIN F1
#define DRIVER_LED_TOTAL 9
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 120
#define RGB_MATRIX_DISABLE_KEYCODES
#define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT // Sets the default mode, if none has been set
#define RGB_DISABLE_WHEN_USB_SUSPENDED

/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCE 5
Expand Down
4 changes: 2 additions & 2 deletions keyboards/work_louder/loop/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
#include QMK_KEYBOARD_H

// clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Base */
[0] = LAYOUT_via(
KC_MUTE, KC_MPLY, R_M_TOG, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, MO(1),
KC_VOLD, KC_VOLD, KC_MPRV, KC_MNXT, R_M_MOD, R_M_RMOD
KC_VOLU, KC_VOLD, KC_MNXT, KC_MPRV, R_M_MOD, R_M_RMOD
),
[1] = LAYOUT_via(
RESET, _______, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, MO(2), _______,
Expand Down
5 changes: 3 additions & 2 deletions keyboards/work_louder/loop/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
#endif

#ifdef RGB_MATRIX_ENABLE
// clang-format off
led_config_t g_led_config = {
{
{ NO_LED, NO_LED, NO_LED, 8, 7, 6, 5, 4, 3, 2, 1, 0 }
}, {
{ 36, 32 }, { 55, 32 }, { 74, 32 }, { 93, 32 }, { 112, 32 }, { 131, 32 }, { 150, 32 }, { 169, 32 }, { 188, 32 }
{188, 32}, {169, 32}, {150, 32}, {131, 32}, {112, 32}, {93, 32}, {74, 32}, {55, 32}, {36, 32}
}, {
4, 4, 4, 4, 4, 4, 4, 4, 4
}
};

// clang-format on
#endif
78 changes: 42 additions & 36 deletions keyboards/work_louder/nano/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT_ID 0xE6EF
#define DEVICE_VER 0x0001
#define MANUFACTURER Work Louder
#define PRODUCT nano
#define PRODUCT Nano Pad

/* key matrix size */
#define MATRIX_ROWS 1
#ifdef VIA_ENABLE
# define MATRIX_COLS 5
#else
# define MATRIX_COLS 3
#endif
#define MATRIX_ROWS 1
#define MATRIX_COLS 5

/*
* Keyboard Matrix Assignments
Expand All @@ -44,13 +40,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
*
*/
#define MATRIX_ROW_PINS { F7 }
#define MATRIX_COL_PINS { B5, B6, C6 }
#define UNUSED_PINS
#define MATRIX_ROW_PINS \
{ F7 }
#define MATRIX_COL_PINS \
{ B5, B6, C6, NO_PIN, NO_PIN }

/* COL2ROW, ROW2COL */
#define DIODE_DIRECTION COL2ROW

#define DIODE_DIRECTION COL2ROW

//#define LED_NUM_LOCK_PIN B0
//#define LED_CAPS_LOCK_PIN B1
Expand All @@ -62,25 +58,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define BACKLIGHT_LEVELS 3
//#define BACKLIGHT_BREATHING

#define RGBLIGHT_DI_PIN C7
# define RGBLED_NUM 6
#define RGBLIGHT_DI_PIN C7
#define RGBLED_NUM 6
//# define RGBLIGHT_HUE_STEP 8
//# define RGBLIGHT_SAT_STEP 8
//# define RGBLIGHT_VAL_STEP 8
//# define RGBLIGHT_LIMIT_VAL 255 /* The maximum brightness level */
# define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */
/*== all animations enable ==*/
# define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_LIMIT_VAL 120 /* The maximum brightness level */
#define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */
/*== or choose animations ==*/
//# define RGBLIGHT_EFFECT_BREATHING
//# define RGBLIGHT_EFFECT_RAINBOW_MOOD
//# define RGBLIGHT_EFFECT_RAINBOW_SWIRL
//# define RGBLIGHT_EFFECT_SNAKE
//# define RGBLIGHT_EFFECT_KNIGHT
//# define RGBLIGHT_EFFECT_CHRISTMAS
//# define RGBLIGHT_EFFECT_STATIC_GRADIENT
//# define RGBLIGHT_EFFECT_RGB_TEST
//# define RGBLIGHT_EFFECT_ALTERNATING
#define RGBLIGHT_EFFECT_BREATHING
#define RGBLIGHT_EFFECT_RAINBOW_MOOD
#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
#define RGBLIGHT_EFFECT_SNAKE
#define RGBLIGHT_EFFECT_KNIGHT
#define RGBLIGHT_EFFECT_CHRISTMAS
#define RGBLIGHT_EFFECT_STATIC_GRADIENT
#define RGBLIGHT_EFFECT_RGB_TEST
#define RGBLIGHT_EFFECT_TWINKLE
#define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_LIGHT
#define RGBLIGHT_DEFAULT_HUE 170

/*== customize breathing effect ==*/
/*==== (DEFAULT) use fixed table instead of exp() and sin() ====*/
//# define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256(default) or 128 or 64
Expand All @@ -89,9 +86,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//# define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255
//#endif

#define RGB_DI_PIN F6
#define DRIVER_LED_TOTAL 2
#define RGB_DI_PIN F6
#define DRIVER_LED_TOTAL 2
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 120
#define RGB_MATRIX_DISABLE_KEYCODES
#define RGB_DISABLE_WHEN_USB_SUSPENDED

/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCE 5
Expand Down Expand Up @@ -151,14 +150,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define NO_ACTION_FUNCTION

/* Bootmagic Lite key configuration */
#define BOOTMAGIC_LITE_ROW 0
#define BOOTMAGIC_LITE_COLUMN 3

#define BOOTMAGIC_LITE_ROW 0
#define BOOTMAGIC_LITE_COLUMN 2

#define ENCODERS_PAD_A { D7 }
#define ENCODERS_PAD_B { B4 }
#define ENCODERS_PAD_A \
{ D7 }
#define ENCODERS_PAD_B \
{ B4 }

#define ENCODERS 1

#define ENCODERS_CW_KEY { { 3, 0 } }
#define ENCODERS_CCW_KEY { { 4, 0 } }
#define ENCODERS_CW_KEY \
{ \
{ 3, 0 } \
}
#define ENCODERS_CCW_KEY \
{ \
{ 4, 0 } \
}
157 changes: 152 additions & 5 deletions keyboards/work_louder/rgb_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,160 @@
#include QMK_KEYBOARD_H
#include "rgb_functions.h"

#if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_EANBLE)
# undef RGB_DI_PIN
# define RGBLIGHT_DI_PIN
# include "ws2812.c"
#ifdef RGBLIGHT_ENABLE
# include "ws2812.h"
# include <avr/interrupt.h>
# include <avr/io.h>
# include <util/delay.h>

# define pinmask(pin) (_BV((pin)&0xF))

/*
* Forward declare internal functions
*
* The functions take a byte-array and send to the data output as WS2812 bitstream.
* The length is the number of bytes to send - three per LED.
*/

static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi);

/*
This routine writes an array of bytes with RGB values to the Dataout pin
using the fast 800kHz clockless WS2811/2812 protocol.
*/

// Timing in ns
# define w_zeropulse 350
# define w_onepulse 900
# define w_totalperiod 1250

// Fixed cycles used by the inner loop
# define w_fixedlow 2
# define w_fixedhigh 4
# define w_fixedtotal 8

// Insert NOPs to match the timing, if possible
# define w_zerocycles (((F_CPU / 1000) * w_zeropulse) / 1000000)
# define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000)
# define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000)

// w1_nops - nops between rising edge and falling edge - low
# if w_zerocycles >= w_fixedlow
# define w1_nops (w_zerocycles - w_fixedlow)
# else
# define w1_nops 0
# endif

// w2_nops - nops between fe low and fe high
# if w_onecycles >= (w_fixedhigh + w1_nops)
# define w2_nops (w_onecycles - w_fixedhigh - w1_nops)
# else
# define w2_nops 0
# endif

// w3_nops - nops to complete loop
# if w_totalcycles >= (w_fixedtotal + w1_nops + w2_nops)
# define w3_nops (w_totalcycles - w_fixedtotal - w1_nops - w2_nops)
# else
# define w3_nops 0
# endif

// The only critical timing parameter is the minimum pulse length of the "0"
// Warn or throw error if this timing can not be met with current F_CPU settings.
# define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000)
# if w_lowtime > 550
# error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?"
# elif w_lowtime > 450
# warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)."
# warning "Please consider a higher clockspeed, if possible"
# endif

# define w_nop1 "nop \n\t"
# define w_nop2 "rjmp .+0 \n\t"
# define w_nop4 w_nop2 w_nop2
# define w_nop8 w_nop4 w_nop4
# define w_nop16 w_nop8 w_nop8

static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi) {
uint8_t curbyte, ctr, sreg_prev;

sreg_prev = SREG;
cli();

while (datlen--) {
curbyte = (*data++);

asm volatile(" ldi %0,8 \n\t"
"loop%=: \n\t"
" out %2,%3 \n\t" // '1' [01] '0' [01] - re
# if (w1_nops & 1)
w_nop1
# endif
# if (w1_nops & 2)
w_nop2
# endif
# if (w1_nops & 4)
w_nop4
# endif
# if (w1_nops & 8)
w_nop8
# endif
# if (w1_nops & 16)
w_nop16
# endif
" sbrs %1,7 \n\t" // '1' [03] '0' [02]
" out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low
" lsl %1 \n\t" // '1' [04] '0' [04]
# if (w2_nops & 1)
w_nop1
# endif
# if (w2_nops & 2)
w_nop2
# endif
# if (w2_nops & 4)
w_nop4
# endif
# if (w2_nops & 8)
w_nop8
# endif
# if (w2_nops & 16)
w_nop16
# endif
" out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high
# if (w3_nops & 1)
w_nop1
# endif
# if (w3_nops & 2)
w_nop2
# endif
# if (w3_nops & 4)
w_nop4
# endif
# if (w3_nops & 8)
w_nop8
# endif
# if (w3_nops & 16)
w_nop16
# endif

" dec %0 \n\t" // '1' [+2] '0' [+2]
" brne loop%=\n\t" // '1' [+3] '0' [+4]
: "=&d"(ctr)
: "r"(curbyte), "I"(_SFR_IO_ADDR(PORTx_ADDRESS(RGBLIGHT_DI_PIN))), "r"(maskhi), "r"(masklo));
}

SREG = sreg_prev;
}

void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) {
ws2812_setleds(start_led, num_leds);
DDRx_ADDRESS(RGBLIGHT_DI_PIN) |= pinmask(RGBLIGHT_DI_PIN);

uint8_t masklo = ~(pinmask(RGBLIGHT_DI_PIN)) & PORTx_ADDRESS(RGBLIGHT_DI_PIN);
uint8_t maskhi = pinmask(RGBLIGHT_DI_PIN) | PORTx_ADDRESS(RGBLIGHT_DI_PIN);

ws2812_sendarray_mask((uint8_t *)start_led, num_leds * sizeof(LED_TYPE), masklo, maskhi);

_delay_us(WS2812_TRST_US);
}
#endif

Expand Down
Loading

0 comments on commit d9e9a96

Please sign in to comment.