]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
add initial support for left leds on an ergodox ez
authorDon Armstrong <don@donarmstrong.com>
Mon, 1 May 2017 03:47:40 +0000 (20:47 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 22 Oct 2017 19:43:56 +0000 (12:43 -0700)
keyboards/ergodox/keymaps/don/Makefile
keyboards/ergodox/keymaps/don/keymap.c
keyboards/ergodox_ez/ergodox_ez.c
keyboards/ergodox_ez/ergodox_ez.h

index cae19a6f4b0601d849021f55d527fad84c70191d..14b5afbde92c8961a137948e51f6577a121fa23f 100644 (file)
@@ -15,9 +15,13 @@ UNICODE_ENABLE = yes         # Unicode
 BLUETOOTH_ENABLE = no       # Enable Bluetooth with the Adafruit EZ-Key HID
 RGBLIGHT_ENABLE = no        # Enable WS2812 RGB underlight.  Do not enable this with audio at the same time.
 SLEEP_LED_ENABLE = no       # Breathing sleep LED during USB suspend
+ifeq ($(SUBPROJECT_DIR),'infinity')
 VISUALIZER_ENABLE = yes
 LCD_BACKLIGHT_ENABLE = yes
 LCD_ENABLE = yes
+else
+OPT_DEFS+= -DLEFT_LEDS
+endif
 
 dfu-util: $(BUILD_DIR)/$(TARGET).bin sizeafter
        while true; do \
index 21e71a4cecc729095af2a892930a5a4db0e76100..39da4d6c2de5644440f97f77b793f58ad93fb845 100644 (file)
@@ -206,3 +206,43 @@ void matrix_init_user(void) {
 void matrix_scan_user(void) {
 
 };
+
+// if this is my ergodox ez, I have left LEDs.
+#ifdef LEFT_LEDS
+
+extern bool ergodox_left_led_1;
+extern bool ergodox_left_led_2;
+extern bool ergodox_left_led_3;
+
+
+uint8_t ergodox_left_leds_update(void) {
+    if (mcp23018_status) { // if there was an error
+        return mcp23018_status;
+    }
+#define LEFT_LED_1_SHIFT        7       // in MCP23018 port B
+#define LEFT_LED_2_SHIFT        6       // in MCP23018 port B
+#define LEFT_LED_3_SHIFT        7       // in MCP23018 port A
+
+    // set logical value (doesn't matter on inputs)
+    // - unused  : hi-Z : 1
+    // - input   : hi-Z : 1
+    // - driving : hi-Z : 1
+    mcp23018_status = i2c_start(I2C_ADDR_WRITE);
+    if (mcp23018_status) goto out;
+    mcp23018_status = i2c_write(OLATA);
+    if (mcp23018_status) goto out;
+    mcp23018_status = i2c_write(0b11111111
+                                & ~(ergodox_left_led_3<<LEFT_LED_3_SHIFT)
+                                );
+    if (mcp23018_status) goto out;
+    mcp23018_status = i2c_write(0b11111111
+                                & ~(ergodox_left_led_2<<LEFT_LED_2_SHIFT)
+                                & ~(ergodox_left_led_1<<LEFT_LED_1_SHIFT)
+                                );
+    if (mcp23018_status) goto out;
+
+ out:
+    i2c_stop();
+    return mcp23018_status;
+}
+#endif
index 3609f6f81042f6aa4bfa2b3233bd316f4f616dc9..8337db666597469f0a0311edca7c435da882fea1 100644 (file)
@@ -61,11 +61,46 @@ void ergodox_blink_all_leds(void)
     _delay_ms(50);
     ergodox_right_led_3_on();
     _delay_ms(50);
+#ifdef LEFT_LEDS
+    ergodox_left_led_1_on();
+    _delay_ms(50);
+    if (!mcp23018_status) {
+      mcp23018_status = ergodox_left_leds_update();
+    }
+    ergodox_left_led_2_on();
+    _delay_ms(50);
+    if (!mcp23018_status) {
+      mcp23018_status = ergodox_left_leds_update();
+    }
+    ergodox_left_led_3_on();
+    _delay_ms(50);
+    if (!mcp23018_status) {
+      mcp23018_status = ergodox_left_leds_update();
+    }
+#endif
     ergodox_right_led_1_off();
     _delay_ms(50);
     ergodox_right_led_2_off();
     _delay_ms(50);
     ergodox_right_led_3_off();
+#ifdef LEFT_LEDS
+    _delay_ms(50);
+    ergodox_left_led_1_off();
+    if (!mcp23018_status) {
+      mcp23018_status = ergodox_left_leds_update();
+    }
+    _delay_ms(50);
+    ergodox_left_led_2_off();
+    if (!mcp23018_status) {
+      mcp23018_status = ergodox_left_leds_update();
+    }
+    _delay_ms(50);
+    ergodox_left_led_3_off();
+    if (!mcp23018_status) {
+      mcp23018_status = ergodox_left_leds_update();
+    }
+#endif
+    
     //ergodox_led_all_on();
     //_delay_ms(333);
     ergodox_led_all_off();
@@ -107,6 +142,10 @@ uint8_t init_mcp23018(void) {
 out:
     i2c_stop();
 
+#ifdef LEFT_LEDS
+    if (!mcp23018_status) mcp23018_status = ergodox_left_leds_update();
+#endif // LEFT_LEDS
+
     // SREG=sreg_prev;
 
     return mcp23018_status;
index 1f8d597519486aea670c9210c19de3c461cbd253..a6890a70c53d152bc0c322de42f933910bf9f572 100644 (file)
@@ -46,12 +46,31 @@ inline void ergodox_right_led_2_off(void)   { DDRB &= ~(1<<6); PORTB &= ~(1<<6);
 inline void ergodox_right_led_3_off(void)   { DDRB &= ~(1<<7); PORTB &= ~(1<<7); }
 inline void ergodox_right_led_off(uint8_t led) { DDRB &= ~(1<<(led+4)); PORTB &= ~(1<<(led+4)); }
 
+#ifdef LEFT_LEDS
+bool ergodox_left_led_1;
+bool ergodox_left_led_2;
+bool ergodox_left_led_3;
+
+inline void ergodox_left_led_1_on(void)    { ergodox_left_led_1 = 1; }
+inline void ergodox_left_led_2_on(void)    { ergodox_left_led_2 = 1; }
+inline void ergodox_left_led_3_on(void)    { ergodox_left_led_3 = 1; }
+
+inline void ergodox_left_led_1_off(void)    { ergodox_left_led_1 = 0; }
+inline void ergodox_left_led_2_off(void)    { ergodox_left_led_2 = 0; }
+inline void ergodox_left_led_3_off(void)    { ergodox_left_led_3 = 0; }
+#endif // LEFT_LEDS
+
 inline void ergodox_led_all_on(void)
 {
     ergodox_board_led_on();
     ergodox_right_led_1_on();
     ergodox_right_led_2_on();
     ergodox_right_led_3_on();
+#ifdef LEFT_LEDS
+    ergodox_left_led_1_on();
+    ergodox_left_led_2_on();
+    ergodox_left_led_3_on();
+#endif // LEFT_LEDS
 }
 
 inline void ergodox_led_all_off(void)
@@ -60,6 +79,11 @@ inline void ergodox_led_all_off(void)
     ergodox_right_led_1_off();
     ergodox_right_led_2_off();
     ergodox_right_led_3_off();
+#ifdef LEFT_LEDS
+    ergodox_left_led_1_off();
+    ergodox_left_led_2_off();
+    ergodox_left_led_3_off();
+#endif // LEFT_LEDS
 }
 
 inline void ergodox_right_led_1_set(uint8_t n)    { OCR1A = n; }