Author Topic: Ergodox LED modification  (Read 7998 times)

0 Members and 1 Guest are viewing this topic.

Offline thisMoment

  • Thread Starter
  • Posts: 6
Ergodox LED modification
« on: Sun, 18 August 2013, 23:54:42 »

I've placed my order for an Ergdox kit and I have an idea concerning the LEDs.

I have no need for capslock/numlock/etc LEDs, so what I would like to do is use the 3 LEDs that come with the kit as indicators for what layer is currently in use. With 3 LEDs working as a binary counter I can represent 8 layers, which is more than enough I think.

I took a look at the firmware on Github and it seems like it should be possible, but it'll take some digging around to get it to work right. So far the thing I understand the least is how to find the LEDs and make them operate completely independently from the buttons they happen to be under. I've never done anything with C, but this program is pretty small, so I'm not too worried.

Anyone have any feedback on this idea? Has anyone done it before? Does this functionality already exists in some form?

Offline meiosis

  • * Esteemed Elder
  • Posts: 1281
  • Location: 408
  • Time
Re: Ergodox LED modification
« Reply #1 on: Mon, 19 August 2013, 05:00:57 »
I like the way you think. No homo.

It should be possible, but to represent each layer might be a bit more difficult than it looks initially.

But yeah it should definitely be possible... Might take a while
Keyboards:
Filco Majestouch 2 - Sakura Edition [MX Blue]
Filco Majestouch 2 - Lotus Edition [MX Brown]
Realforce 23ub - Modded with 55g Domes.
Aripeko TKL

Offline Larken

  • Posts: 624
Re: Ergodox LED modification
« Reply #2 on: Mon, 19 August 2013, 05:49:24 »
sordna did something along the line, only that the led will light up whenever he's no longer in the main layer. I imagine what you intend to do would be pretty similar. his post,  quoted from the ergodox thread.

Good question about the firmware. Yep, the default layout would probably have the key assignments mirrored! So you'd need to do build a mirrored layout on the configurator so it works properly on the ergodox. Unless you hack the main firmware to do it for you.
BTW both your links are the same, pointing to massdrop's configurator.

Firmware is very hackable, I now made the teensy LED light up whenever I am not in the main layer, it's super useful, and shows very nicely through the acrylic case! Code patch below, includes the buzzer stuff.

Code: [Select]
diff -upr ../src/keyboard/ergodox/controller/teensy-2-0--led.h src/keyboard/ergodox/controller/teensy-2-0--led.h
--- ../src/keyboard/ergodox/controller/teensy-2-0--led.h 2013-04-01 15:06:12.000000000 -0700
+++ src/keyboard/ergodox/controller/teensy-2-0--led.h 2013-04-05 21:52:11.000000000 -0700
@@ -30,17 +30,29 @@
  #define _kb_led_3_set(n)         (OCR1C = (uint8_t)(n))
  #define _kb_led_3_set_percent(n) (OCR1C = (uint8_t)((n) * 0xFF))
 
+ #define _kb_led_4_on()           (PORTD |=  (1<<5))
+ #define _kb_led_4_off()          (PORTD &= ~(1<<5))
+ #define _kb_led_5_on()           (PORTD |=  (1<<4))
+ #define _kb_led_5_off()          (PORTD &= ~(1<<4))
+ #define _kb_led_6_on()           (PORTD |=  (1<<6))
+ #define _kb_led_6_off()          (PORTD &= ~(1<<6))
 
  #define _kb_led_all_on() do { \
  _kb_led_1_on(); \
  _kb_led_2_on(); \
  _kb_led_3_on(); \
+ _kb_led_4_on(); \
+ _kb_led_5_on(); \
+ _kb_led_6_on(); \
  } while(0)
 
  #define _kb_led_all_off() do { \
  _kb_led_1_off(); \
  _kb_led_2_off(); \
  _kb_led_3_off(); \
+ _kb_led_4_off(); \
+ _kb_led_5_off(); \
+ _kb_led_6_off(); \
  } while(0)
 
  #define _kb_led_all_set(n) do { \
diff -upr ../src/main.c src/main.c
--- ../src/main.c 2013-04-01 15:06:12.000000000 -0700
+++ src/main.c 2013-04-05 21:54:38.000000000 -0700
@@ -24,6 +24,7 @@
 
 // ----------------------------------------------------------------------------
 
+uint8_t       layers_head = 0;
 static bool _main_kb_is_pressed[KB_ROWS][KB_COLUMNS];
 bool (*main_kb_is_pressed)[KB_ROWS][KB_COLUMNS] = &_main_kb_is_pressed;
 
@@ -50,6 +51,17 @@ bool    main_arg_was_pressed;
 int main(void) {
  kb_init();  // does controller initialization too
 
+ // set internal pull-up off for both pins
+ PORTD &= ~(1<<4);
+ PORTD &= ~(1<<5);
+ PORTD &= ~(1<<6);
+
+ // set the pins as output
+ // (because we cleared the applicable PORT bits above, the pins will now be driving low)
+ DDRD |= (1<<4);
+ DDRD |= (1<<5);
+ DDRD |= (1<<6);
+
  kb_led_state_power_on();
 
  usb_init();
@@ -63,6 +75,7 @@ int main(void) {
  bool (*temp)[KB_ROWS][KB_COLUMNS] = main_kb_was_pressed;
  main_kb_was_pressed = main_kb_is_pressed;
  main_kb_is_pressed = temp;
+ _kb_led_4_off(); // buzzer off
 
  kb_update_matrix(*main_kb_is_pressed);
 
@@ -82,15 +95,23 @@ int main(void) {
  #define is_pressed   main_arg_is_pressed
  #define was_pressed  main_arg_was_pressed
  for (row=0; row<KB_ROWS; row++) {
+ if (layers_head != 0)
+ _kb_led_6_on(); // layer led on
+ else
+ _kb_led_6_off(); // layer led off
+
  for (col=0; col<KB_COLUMNS; col++) {
  is_pressed = (*main_kb_is_pressed)[row][col];
  was_pressed = (*main_kb_was_pressed)[row][col];
 
  if (is_pressed != was_pressed) {
  if (is_pressed) {
+         _kb_led_4_on(); // buzzer on
+         _kb_led_5_on(); // key led on
  layer = main_layers_peek(0);
  main_layers_pressed[row][col] = layer;
  } else {
+ _kb_led_5_off(); // key led off
  layer = main_layers_pressed[row][col];
  }
 
@@ -175,7 +197,6 @@ struct layers {
 // ----------------------------------------------------------------------------
 
 struct layers layers[MAX_ACTIVE_LAYERS];
-uint8_t       layers_head = 0;
 uint8_t       layers_ids_in_use[MAX_ACTIVE_LAYERS] = {true};
 
 /*
diff -upr ../src/makefile-options src/makefile-options
--- ../src/makefile-options 2013-04-01 15:06:12.000000000 -0700
+++ src/makefile-options 2013-04-03 16:54:14.000000000 -0700
@@ -9,7 +9,7 @@
 
 TARGET   := firmware  # the name we want for our program binary
 KEYBOARD := ergodox   # keyboard model; see "src/keyboard" for what's available
-LAYOUT   := default-kinesis-mod  # keyboard layout
+LAYOUT   := default--layout  # keyboard layout
  # see "src/keyboard/*/layout" for what's
  # available
 

And here are the changes just for the layer indicator by itself, which doesn't need any hardware mod. Just download the source from massdrop's layer configurator, and make the changes by hand or apply the patch with: patch -p0 < filename.patch

Code: [Select]
--- ../src/keyboard/ergodox/controller/teensy-2-0--led.h 2013-04-01 15:06:12.000000000 -0700
+++ keyboard/ergodox/controller/teensy-2-0--led.h 2013-04-05 21:52:11.000000000 -0700
@@ -30,17 +30,21 @@
  #define _kb_led_3_set(n)         (OCR1C = (uint8_t)(n))
  #define _kb_led_3_set_percent(n) (OCR1C = (uint8_t)((n) * 0xFF))
 
+ #define _kb_led_6_on()           (PORTD |=  (1<<6))
+ #define _kb_led_6_off()          (PORTD &= ~(1<<6))
 
  #define _kb_led_all_on() do { \
  _kb_led_1_on(); \
  _kb_led_2_on(); \
  _kb_led_3_on(); \
+ _kb_led_6_on(); \
  } while(0)
 
  #define _kb_led_all_off() do { \
  _kb_led_1_off(); \
  _kb_led_2_off(); \
  _kb_led_3_off(); \
+ _kb_led_6_off(); \
  } while(0)
 
  #define _kb_led_all_set(n) do { \
--- ../src/main.c 2013-04-01 15:06:12.000000000 -0700
+++ main.c 2013-04-05 21:54:38.000000000 -0700
@@ -24,6 +24,7 @@
 
 // ----------------------------------------------------------------------------
 
+uint8_t       layers_head = 0;
 static bool _main_kb_is_pressed[KB_ROWS][KB_COLUMNS];
 bool (*main_kb_is_pressed)[KB_ROWS][KB_COLUMNS] = &_main_kb_is_pressed;
 
@@ -50,6 +51,9 @@ bool    main_arg_was_pressed;
 int main(void) {
  kb_init();  // does controller initialization too
 
+ PORTD &= ~(1<<6);
+ DDRD |= (1<<6);
+
  kb_led_state_power_on();
 
  usb_init();
@@ -82,6 +95,11 @@ int main(void) {
  #define is_pressed   main_arg_is_pressed
  #define was_pressed  main_arg_was_pressed
  for (row=0; row<KB_ROWS; row++) {
+ if (layers_head != 0)
+ _kb_led_6_on(); // layer led on
+ else
+ _kb_led_6_off(); // layer led off
+
  for (col=0; col<KB_COLUMNS; col++) {
  is_pressed = (*main_kb_is_pressed)[row][col];
  was_pressed = (*main_kb_was_pressed)[row][col];
@@ -175,7 +197,6 @@ struct layers {
 // ----------------------------------------------------------------------------
 
 struct layers layers[MAX_ACTIVE_LAYERS];
-uint8_t       layers_head = 0;
 uint8_t       layers_ids_in_use[MAX_ACTIVE_LAYERS] = {true};
 
 /*
--- ../src/makefile-options 2013-04-01 15:06:12.000000000 -0700
+++ makefile-options 2013-04-03 16:54:14.000000000 -0700
@@ -9,7 +9,7 @@
 
 TARGET   := firmware  # the name we want for our program binary
 KEYBOARD := ergodox   # keyboard model; see "src/keyboard" for what's available
-LAYOUT   := default-kinesis-mod  # keyboard layout
+LAYOUT   := default--layout  # keyboard layout
  # see "src/keyboard/*/layout" for what's
  # available
 

If you try it let me know how it worked for you!
| Ergodox #1 | Ergodox #2 |


Filco Majestouch Brown | Ducky 1087 Brown | Cherry G80-3494 Reds | Unicomp Ultra Classics | Cherry G80-8113 Clears |

Offline tp4tissue

  • * Destiny Supporter
  • Posts: 13565
  • Location: Official Geekhack Public Defender..
  • OmniExpert of: Rice, Top-Ramen, Ergodox, n Females
Re: Ergodox LED modification
« Reply #3 on: Mon, 19 August 2013, 05:58:37 »
Indicator lights are not very useful.

I have the escape key top left set to return to default layer.

This is faster than Looking down at lights.


Just like how no one ever looks at the capslock light or insert light or numlock light.

Because you never LOOK at the board BEFORE you make the typing error.


Once you've made the typing error, you already know the board is in the wrong Layer..


Just hit escape to return to default layer.  there is no need to LOOK DOWN.. :p

Offline kurplop

  • THE HERO WE DON'T DESERVE
  • Posts: 992
Re: Ergodox LED modification
« Reply #4 on: Mon, 19 August 2013, 08:45:03 »
I never thought of that of that. Good point tp4tissue. Now I won't feel like I'm missing something.

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: Ergodox LED modification
« Reply #5 on: Mon, 19 August 2013, 10:01:48 »
That sounds like a lot of presses on the L0 key ...

If you don't want that, then ... well... a light is cool. It would also be cool to have a latching switch.

Offline tp4tissue

  • * Destiny Supporter
  • Posts: 13565
  • Location: Official Geekhack Public Defender..
  • OmniExpert of: Rice, Top-Ramen, Ergodox, n Females
Re: Ergodox LED modification
« Reply #6 on: Mon, 19 August 2013, 13:01:43 »
That sounds like a lot of presses on the L0 key ...

If you don't want that, then ... well... a light is cool. It would also be cool to have a latching switch.

Hey man, I agree you can certainly find better Use for those indicator lights..

But as to the Indicator of "What"...   that is the issue we should iron out.


I think it would be nice as an aesthetic light show.

perhaps, make it do Hello world in binary when You plug in the USB cord.

Or, use an led to light up every time you type a letter

Or, use an led to mirror the network/ harddrive access leds, the same ones on your mobo..

^^ this part would be quite the challenge :D

Offline Thimplum

  • * Esteemed Elder
  • Posts: 1101
  • Master of all Ponies
Re: Ergodox LED modification
« Reply #7 on: Mon, 19 August 2013, 16:24:12 »
Wait, there's another GB already?!?
TP4 FOR ADMIN 2013

Offline SpAmRaY

  • NOT a Moderator
  • * Certified Spammer
  • Posts: 14667
  • Location: ¯\(°_o)/¯
  • because reasons.......
Re: Ergodox LED modification
« Reply #8 on: Mon, 19 August 2013, 16:28:43 »

Offline MOZ

  • KING OF THE NEWBIES
  • * Maker
  • Posts: 3981
  • Location: Jo'burg
  • Busy making stuff
Re: Ergodox LED modification
« Reply #9 on: Tue, 20 August 2013, 02:05:06 »
Indicator lights are not very useful.

I have the escape key top left set to return to default layer.

This is faster than Looking down at lights.


Just like how no one ever looks at the capslock light or insert light or numlock light.

Because you never LOOK at the board BEFORE you make the typing error.


Once you've made the typing error, you already know the board is in the wrong Layer..


Just hit escape to return to default layer.  there is no need to LOOK DOWN.. :p

For once I agree with tp4.

And thimplum, they've already reached the lowest price point.

Offline thisMoment

  • Thread Starter
  • Posts: 6
Re: Ergodox LED modification
« Reply #10 on: Tue, 20 August 2013, 04:49:51 »
Good point about looking down, I just assumed it would be hard to manage what layer I am on if I have several. I guess in practice I probably won't need that many.

I'd still like something to do with the 3 LEDs though. Maybe I can have a layer for gaming and have WASD light up when I'm on that layer (or the equivalent of WASD). If I had more LEDs I could do cool stuff with the whole keyboard. Like maybe a wave of light up/down only when I push/pop. It would be less about functionality at that point and more about making something pretty.

Maybe I'll think of some useful thing to do and buy enough LEDs for the whole board. Does anyone have any pictures of what the Ergodox kit looks like with LEDs? I'd be interested to see what it looks like to have backlights and solid keycaps but a clear acrylic case.

Edit: Thanks for finding that Larken, It looks like it will be pretty helpful.
« Last Edit: Tue, 20 August 2013, 04:53:13 by thisMoment »

Offline Larken

  • Posts: 624
Re: Ergodox LED modification
« Reply #11 on: Tue, 20 August 2013, 05:31:43 »
in all honestly, I never did use the code I quoted for my own keyboard either, as I didn't really need leds to tell me which layer I'm on.

the default ergodox pcb does not accept leds, save for the three indicator leds on the right side. if you want to have a backlight board, you'll need to redesign the pcb from scratch, or do some rather drastic drilling and wiring.

for a backlight board in the fashion of the ergodox, check out the ergogp board that is still under development in the making stuff section.
| Ergodox #1 | Ergodox #2 |


Filco Majestouch Brown | Ducky 1087 Brown | Cherry G80-3494 Reds | Unicomp Ultra Classics | Cherry G80-8113 Clears |

Offline tp4tissue

  • * Destiny Supporter
  • Posts: 13565
  • Location: Official Geekhack Public Defender..
  • OmniExpert of: Rice, Top-Ramen, Ergodox, n Females
Re: Ergodox LED modification
« Reply #12 on: Tue, 20 August 2013, 12:33:21 »
in all honestly, I never did use the code I quoted for my own keyboard either, as I didn't really need leds to tell me which layer I'm on.

the default ergodox pcb does not accept leds, save for the three indicator leds on the right side. if you want to have a backlight board, you'll need to redesign the pcb from scratch, or do some rather drastic drilling and wiring.

for a backlight board in the fashion of the ergodox, check out the ergogp board that is still under development in the making stuff section.

I have a drill press :D