From cb2f2fd258011e6637ed182f484a4317ac510db8 Mon Sep 17 00:00:00 2001 From: MechMerlin <30334081+mechmerlin@users.noreply.github.com> Date: Wed, 3 Apr 2019 10:17:25 -0700 Subject: [Keyboard] Small Refactor of Duck boards (#5521) * first [ass at pulling out common duck library functions * use new library in jetfire * use new library in duck lightsaver * use new library in octagon v2 * put Device into the library * refactor send_value * refactor send_value and send_color * use pragma once * use pragma once * use pragma once * use pragma once * rename backlight_led to indicator_leds to match with other duck boards * rename enum * make #define names consistent * rename ducklib to duck_led * update rules.mk ?= to = * put rgb in the correct order * add debounce debugging printouts * turn on bootmagic lite and set it to the top left most key commonly programmed as Escape * add reset key documentation * fix that typo * Update keyboards/duck/duck_led/duck_led.c Co-Authored-By: mechmerlin <30334081+mechmerlin@users.noreply.github.com> * include the correct library --- keyboards/duck/jetfire/backlight_led.c | 129 -------------------------------- keyboards/duck/jetfire/backlight_led.h | 18 ----- keyboards/duck/jetfire/config.h | 4 + keyboards/duck/jetfire/indicator_leds.c | 116 ++++++++++++++++++++++++++++ keyboards/duck/jetfire/indicator_leds.h | 11 +++ keyboards/duck/jetfire/jetfire.c | 10 +-- keyboards/duck/jetfire/jetfire.h | 4 +- keyboards/duck/jetfire/readme.md | 2 +- keyboards/duck/jetfire/rules.mk | 6 +- 9 files changed, 141 insertions(+), 159 deletions(-) delete mode 100644 keyboards/duck/jetfire/backlight_led.c delete mode 100644 keyboards/duck/jetfire/backlight_led.h create mode 100644 keyboards/duck/jetfire/indicator_leds.c create mode 100644 keyboards/duck/jetfire/indicator_leds.h (limited to 'keyboards/duck/jetfire') diff --git a/keyboards/duck/jetfire/backlight_led.c b/keyboards/duck/jetfire/backlight_led.c deleted file mode 100644 index 7e9dca6e9f..0000000000 --- a/keyboards/duck/jetfire/backlight_led.c +++ /dev/null @@ -1,129 +0,0 @@ -/* -Copyright 2016 Ralf Schmitt -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 -(at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include -#include "backlight_led.h" -#include "quantum.h" -// #include "led.h" - - -#define T1H 900 -#define T1L 600 -#define T0H 400 -#define T0L 900 -#define RES 6000 - -#define NS_PER_SEC (1000000000L) -#define CYCLES_PER_SEC (F_CPU) -#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC) -#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE) - -void send_bit_d4(bool bitVal) -{ - if(bitVal) { - asm volatile ( - "sbi %[port], %[bit] \n\t" - ".rept %[onCycles] \n\t" - "nop \n\t" - ".endr \n\t" - "cbi %[port], %[bit] \n\t" - ".rept %[offCycles] \n\t" - "nop \n\t" - ".endr \n\t" - :: - [port] "I" (_SFR_IO_ADDR(PORTD)), - [bit] "I" (4), - [onCycles] "I" (NS_TO_CYCLES(T1H) - 2), - [offCycles] "I" (NS_TO_CYCLES(T1L) - 2)); - } else { - asm volatile ( - "sbi %[port], %[bit] \n\t" - ".rept %[onCycles] \n\t" - "nop \n\t" - ".endr \n\t" - "cbi %[port], %[bit] \n\t" - ".rept %[offCycles] \n\t" - "nop \n\t" - ".endr \n\t" - :: - [port] "I" (_SFR_IO_ADDR(PORTD)), - [bit] "I" (4), - [onCycles] "I" (NS_TO_CYCLES(T0H) - 2), - [offCycles] "I" (NS_TO_CYCLES(T0L) - 2)); - } -} - -void send_bit_d6(bool bitVal) -{ - if(bitVal) { - asm volatile ( - "sbi %[port], %[bit] \n\t" - ".rept %[onCycles] \n\t" - "nop \n\t" - ".endr \n\t" - "cbi %[port], %[bit] \n\t" - ".rept %[offCycles] \n\t" - "nop \n\t" - ".endr \n\t" - :: - [port] "I" (_SFR_IO_ADDR(PORTD)), - [bit] "I" (6), - [onCycles] "I" (NS_TO_CYCLES(T1H) - 2), - [offCycles] "I" (NS_TO_CYCLES(T1L) - 2)); - } else { - asm volatile ( - "sbi %[port], %[bit] \n\t" - ".rept %[onCycles] \n\t" - "nop \n\t" - ".endr \n\t" - "cbi %[port], %[bit] \n\t" - ".rept %[offCycles] \n\t" - "nop \n\t" - ".endr \n\t" - :: - [port] "I" (_SFR_IO_ADDR(PORTD)), - [bit] "I" (6), - [onCycles] "I" (NS_TO_CYCLES(T0H) - 2), - [offCycles] "I" (NS_TO_CYCLES(T0L) - 2)); - } -} - -void show(void) -{ - _delay_us((RES / 1000UL) + 1); -} - -void send_value(uint8_t byte, enum Device device) -{ - for(uint8_t b = 0; b < 8; b++) { - if(device == Device_STATELED) { - send_bit_d4(byte & 0b10000000); - } - if(device == Device_PCBRGB) { - send_bit_d6(byte & 0b10000000); - } - byte <<= 1; - } -} - -void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device) -{ - send_value(g, device); - send_value(r, device); - send_value(b, device); -} diff --git a/keyboards/duck/jetfire/backlight_led.h b/keyboards/duck/jetfire/backlight_led.h deleted file mode 100644 index 36d8d9aa9b..0000000000 --- a/keyboards/duck/jetfire/backlight_led.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef BACKLIGHT_LED_H -#define BACKLIGHT_LED_H - -enum Device { - Device_PCBRGB, - Device_STATELED -}; - -void backlight_init_ports(void); -void backlight_set_state(bool cfg[7]); -void backlight_update_state(void); -void backlight_toggle_rgb(bool enabled); -void backlight_set_rgb(uint8_t cfg[17][3]); -void backlight_set(uint8_t level); -void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device); -void show(void); - -#endif diff --git a/keyboards/duck/jetfire/config.h b/keyboards/duck/jetfire/config.h index 4bc535b192..774e284918 100644 --- a/keyboards/duck/jetfire/config.h +++ b/keyboards/duck/jetfire/config.h @@ -48,6 +48,10 @@ along with this program. If not, see . /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ #define DEBOUNCING_DELAY 5 +/* Set to top left most key */ +#define BOOTMAGIC_LITE_ROW 5 +#define BOOTMAGIC_LITE_COLUMN 10 + /* If defined, GRAVE_ESC will always act as ESC when CTRL is held. * This is userful for the Windows task manager shortcut (ctrl+shift+esc). */ diff --git a/keyboards/duck/jetfire/indicator_leds.c b/keyboards/duck/jetfire/indicator_leds.c new file mode 100644 index 0000000000..7dbdb1ff79 --- /dev/null +++ b/keyboards/duck/jetfire/indicator_leds.c @@ -0,0 +1,116 @@ +/* +Copyright 2016 Ralf Schmitt +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 +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include +#include "indicator_leds.h" +#include "quantum.h" + +#define LED_T1H 900 +#define LED_T1L 600 +#define LED_T0H 400 +#define LED_T0L 900 + +void send_bit_d4(bool bitVal) +{ + if(bitVal) { + asm volatile ( + "sbi %[port], %[bit] \n\t" + ".rept %[onCycles] \n\t" + "nop \n\t" + ".endr \n\t" + "cbi %[port], %[bit] \n\t" + ".rept %[offCycles] \n\t" + "nop \n\t" + ".endr \n\t" + :: + [port] "I" (_SFR_IO_ADDR(PORTD)), + [bit] "I" (4), + [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2), + [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2)); + } else { + asm volatile ( + "sbi %[port], %[bit] \n\t" + ".rept %[onCycles] \n\t" + "nop \n\t" + ".endr \n\t" + "cbi %[port], %[bit] \n\t" + ".rept %[offCycles] \n\t" + "nop \n\t" + ".endr \n\t" + :: + [port] "I" (_SFR_IO_ADDR(PORTD)), + [bit] "I" (4), + [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2), + [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2)); + } +} + +void send_bit_d6(bool bitVal) +{ + if(bitVal) { + asm volatile ( + "sbi %[port], %[bit] \n\t" + ".rept %[onCycles] \n\t" + "nop \n\t" + ".endr \n\t" + "cbi %[port], %[bit] \n\t" + ".rept %[offCycles] \n\t" + "nop \n\t" + ".endr \n\t" + :: + [port] "I" (_SFR_IO_ADDR(PORTD)), + [bit] "I" (6), + [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2), + [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2)); + } else { + asm volatile ( + "sbi %[port], %[bit] \n\t" + ".rept %[onCycles] \n\t" + "nop \n\t" + ".endr \n\t" + "cbi %[port], %[bit] \n\t" + ".rept %[offCycles] \n\t" + "nop \n\t" + ".endr \n\t" + :: + [port] "I" (_SFR_IO_ADDR(PORTD)), + [bit] "I" (6), + [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2), + [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2)); + } +} + +void send_value(uint8_t byte, enum Device device) +{ + for(uint8_t b = 0; b < 8; b++) { + if(device == Device_STATUSLED) { + send_bit_d4(byte & 0b10000000); + } + if(device == Device_PCBRGB) { + send_bit_d6(byte & 0b10000000); + } + byte <<= 1; + } +} + +void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device) +{ + send_value(r, device); + send_value(g, device); + send_value(b, device); +} diff --git a/keyboards/duck/jetfire/indicator_leds.h b/keyboards/duck/jetfire/indicator_leds.h new file mode 100644 index 0000000000..695e1db6d4 --- /dev/null +++ b/keyboards/duck/jetfire/indicator_leds.h @@ -0,0 +1,11 @@ +#pragma once + +#include "duck_led/duck_led.h" + +void backlight_init_ports(void); +void backlight_set_state(bool cfg[7]); +void backlight_update_state(void); +void backlight_toggle_rgb(bool enabled); +void backlight_set_rgb(uint8_t cfg[17][3]); +void backlight_set(uint8_t level); +void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device); diff --git a/keyboards/duck/jetfire/jetfire.c b/keyboards/duck/jetfire/jetfire.c index 81bdb95ba1..0662489c6f 100644 --- a/keyboards/duck/jetfire/jetfire.c +++ b/keyboards/duck/jetfire/jetfire.c @@ -14,9 +14,9 @@ * along with this program. If not, see . */ #include "jetfire.h" -#include "backlight_led.h" +#include "indicator_leds.h" -enum backlight_level { +enum BACKLIGHT_AREAS { BACKLIGHT_ALPHA = 0b0000001, BACKLIGHT_MOD = 0b0000010, BACKLIGHT_FROW = 0b0000100, @@ -137,15 +137,15 @@ void backlight_update_state() send_color(backlight_state_led & (1<. */ -#ifndef JETFIRE_H -#define JETFIRE_H +#pragma once #include "quantum.h" @@ -57,4 +56,3 @@ { K0A, K0B, K0C, KC_NO,KC_NO,KC_NO,KC_NO,KC_NO, K0I, KC_NO,KC_NO,KC_NO, K0M, K0N, K0O, K0P, K0Q, K0R, K0S, KC_NO } \ } -#endif diff --git a/keyboards/duck/jetfire/readme.md b/keyboards/duck/jetfire/readme.md index 34b351a726..8de2f5ced6 100644 --- a/keyboards/duck/jetfire/readme.md +++ b/keyboards/duck/jetfire/readme.md @@ -9,7 +9,7 @@ Keyboard Maintainer: [MechMerlin](https://github.com/mechmerlin) Hardware Supported: Duck Jetfire PCB Hardware Availability: [Geekhack GB](https://geekhack.org/index.php?topic=92708.0) -To get into bootloader mode, hold the top top most key above the 2 navigation keys while connecting the USB cable. +**Reset Key:** To put the Jetfire into reset, hold top most key above the 2 navigation keys (`K5P`) while plugging in. Make example for this keyboard (after setting up your build environment): diff --git a/keyboards/duck/jetfire/rules.mk b/keyboards/duck/jetfire/rules.mk index 8e05516df3..c708593293 100644 --- a/keyboards/duck/jetfire/rules.mk +++ b/keyboards/duck/jetfire/rules.mk @@ -51,7 +51,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096 # Build Options # change yes to no to disable # -BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = no # Mouse keys(+4700) EXTRAKEY_ENABLE = no # Audio control and System control(+450) CONSOLE_ENABLE = yes # Console for debug(+400) @@ -70,5 +70,5 @@ FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400) CUSTOM_MATRIX = yes -SRC += backlight_led.c \ - matrix.c +SRC += indicator_leds.c \ + matrix.c duck_led/duck_led.c -- cgit v1.2.1