Skip to content

Commit

Permalink
[Keyboard] Small Refactor of Duck boards (qmk#5521)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* include the correct library
  • Loading branch information
mechmerlin authored and drashna committed Apr 3, 2019
1 parent caefb1c commit cb2f2fd
Show file tree
Hide file tree
Showing 33 changed files with 192 additions and 202 deletions.
7 changes: 7 additions & 0 deletions keyboards/duck/duck_led/duck_led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <avr/io.h>
#include "duck_led.h"
#include "quantum.h"

void show(void) {
wait_us((RES / 1000UL) + 1);
}
16 changes: 16 additions & 0 deletions keyboards/duck/duck_led/duck_led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#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)

enum Device {
Device_PCBRGB,
Device_STATUSLED
};

void show(void);

1 change: 0 additions & 1 deletion keyboards/duck/eagle_viper/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ Newest version is the [Eagle/Viper V2](http://duck0113.tistory.com/127)
Make example for this keyboard (after setting up your build environment):

make duck/eagle_viper/v2:default

8 changes: 5 additions & 3 deletions keyboards/duck/eagle_viper/v2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONFIG_H
#define CONFIG_H
#pragma once

#include "config_common.h"

Expand Down Expand Up @@ -44,6 +43,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGB_DI_PIN D6
#define RGBLED_NUM 17

/* Set to top left most key */
#define BOOTMAGIC_LITE_ROW 4
#define BOOTMAGIC_LITE_COLUMN 10

#define TAPPING_TERM 200

#endif
23 changes: 8 additions & 15 deletions keyboards/duck/eagle_viper/v2/indicator_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#include <util/delay.h>
#include "indicator_leds.h"

#define RES 6000
#include "duck_led/duck_led.h"

#define LED_T1H 600
#define LED_T1L 650
#define LED_T0H 250
#define LED_T0L 1000

#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 (
Expand Down Expand Up @@ -66,14 +60,12 @@ void send_bit_d4(bool bitVal) {
}
}

void show(void) {
_delay_us((RES / 1000UL) + 1);
}

void send_value(uint8_t byte) {
void send_value(uint8_t byte, enum Device device) {
for(uint8_t b = 0; b < 8; b++) {
send_bit_d4(byte & 0b10000000);
byte <<= 1;
if(device == Device_STATUSLED) {
send_bit_d4(byte & 0b10000000);
byte <<= 1;
}
}
}

Expand All @@ -83,7 +75,8 @@ void indicator_leds_set(bool leds[8]) {

cli();
for(led_cnt = 0; led_cnt < 8; led_cnt++)
send_value(leds[led_cnt] ? 255 : 0);
send_value(leds[led_cnt] ? 255 : 0, Device_STATUSLED);
sei();
show();
}

1 change: 0 additions & 1 deletion keyboards/duck/eagle_viper/v2/indicator_leds.h
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
void indicator_leds_set(bool leds[8]);
void show(void);
3 changes: 3 additions & 0 deletions keyboards/duck/eagle_viper/v2/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ uint8_t matrix_scan(void) {
bool curr_bit = rows & (1<<row);
if (prev_bit != curr_bit) {
matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
if (debouncing) {
dprint("bounce!: "); dprintf("%02X", debouncing); dprintln();
}
debouncing = DEBOUNCING_DELAY;
}
}
Expand Down
2 changes: 2 additions & 0 deletions keyboards/duck/eagle_viper/v2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Make example for this keyboard (after setting up your build environment):

make eagle_viper/v2:default

**Reset Key:** To put the Eagle/Viper V2 into reset, hold caps lock key (`K2A`) while plugging in.

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.

## Hardware Notes
Expand Down
28 changes: 14 additions & 14 deletions keyboards/duck/eagle_viper/v2/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
# Build Options
# change yes to no to disable
#
BOOTMAGIC_ENABLE ?= no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE ?= no # Mouse keys(+4700)
EXTRAKEY_ENABLE ?= yes # Audio control and System control(+450)
CONSOLE_ENABLE ?= no # Console for debug(+400)
COMMAND_ENABLE ?= yes # Commands for debug and configuration
BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE ?= yes # USB Nkey Rollover
BACKLIGHT_ENABLE ?= yes # Enable keyboard backlight functionality on B7 by default
MIDI_ENABLE ?= no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE ?= no # Unicode
BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE ?= no # Audio output on port C6
FAUXCLICKY_ENABLE ?= no # Use buzzer to emulate clicky switches
NKRO_ENABLE = yes # USB Nkey Rollover
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality on B7 by default
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
RGBLIGHT_ENABLE = yes

CUSTOM_MATRIX = yes
SRC += indicator_leds.c \
matrix.c
matrix.c duck_led/duck_led.c
4 changes: 1 addition & 3 deletions keyboards/duck/eagle_viper/v2/v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef V2_H
#define V2_H
#pragma once

#include "quantum.h"

Expand Down Expand Up @@ -78,4 +77,3 @@

#define LAYOUT_eagle LAYOUT_60_ansi

#endif
4 changes: 4 additions & 0 deletions keyboards/duck/jetfire/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* 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).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#include <util/delay.h>
#include <stdint.h>
#include "backlight_led.h"
#include "indicator_leds.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)
#define LED_T1H 900
#define LED_T1L 600
#define LED_T0H 400
#define LED_T0L 900

void send_bit_d4(bool bitVal)
{
Expand All @@ -48,8 +40,8 @@ void send_bit_d4(bool bitVal)
::
[port] "I" (_SFR_IO_ADDR(PORTD)),
[bit] "I" (4),
[onCycles] "I" (NS_TO_CYCLES(T1H) - 2),
[offCycles] "I" (NS_TO_CYCLES(T1L) - 2));
[onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2),
[offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2));
} else {
asm volatile (
"sbi %[port], %[bit] \n\t"
Expand All @@ -63,8 +55,8 @@ void send_bit_d4(bool bitVal)
::
[port] "I" (_SFR_IO_ADDR(PORTD)),
[bit] "I" (4),
[onCycles] "I" (NS_TO_CYCLES(T0H) - 2),
[offCycles] "I" (NS_TO_CYCLES(T0L) - 2));
[onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2),
[offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2));
}
}

Expand All @@ -83,8 +75,8 @@ void send_bit_d6(bool bitVal)
::
[port] "I" (_SFR_IO_ADDR(PORTD)),
[bit] "I" (6),
[onCycles] "I" (NS_TO_CYCLES(T1H) - 2),
[offCycles] "I" (NS_TO_CYCLES(T1L) - 2));
[onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2),
[offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2));
} else {
asm volatile (
"sbi %[port], %[bit] \n\t"
Expand All @@ -98,20 +90,15 @@ void send_bit_d6(bool bitVal)
::
[port] "I" (_SFR_IO_ADDR(PORTD)),
[bit] "I" (6),
[onCycles] "I" (NS_TO_CYCLES(T0H) - 2),
[offCycles] "I" (NS_TO_CYCLES(T0L) - 2));
[onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2),
[offCycles] "I" (NS_TO_CYCLES(LED_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) {
if(device == Device_STATUSLED) {
send_bit_d4(byte & 0b10000000);
}
if(device == Device_PCBRGB) {
Expand All @@ -123,7 +110,7 @@ void send_value(uint8_t byte, enum Device device)

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(g, device);
send_value(b, device);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef BACKLIGHT_LED_H
#define BACKLIGHT_LED_H
#pragma once

enum Device {
Device_PCBRGB,
Device_STATELED
};
#include "duck_led/duck_led.h"

void backlight_init_ports(void);
void backlight_set_state(bool cfg[7]);
Expand All @@ -13,6 +9,3 @@ 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
10 changes: 5 additions & 5 deletions keyboards/duck/jetfire/jetfire.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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,
Expand Down Expand Up @@ -137,15 +137,15 @@ void backlight_update_state()
send_color(backlight_state_led & (1<<STATE_LED_SCROLL_LOCK) ? 255 : 0,
backlight_state_led & (1<<STATE_LED_CAPS_LOCK) ? 255 : 0,
backlight_state_led & (1<<STATE_LED_NUM_LOCK) ? 255 : 0,
Device_STATELED);
Device_STATUSLED);
send_color(backlight_state_led & (1<<STATE_LED_LAYER_1) ? 255 : 0,
backlight_state_led & (1<<STATE_LED_LAYER_2) ? 255 : 0,
backlight_state_led & (1<<STATE_LED_LAYER_0) ? 255 : 0,
Device_STATELED);
Device_STATUSLED);
send_color(backlight_state_led & (1<<STATE_LED_LAYER_4) ? 255 : 0,
backlight_state_led & (1<<STATE_LED_LAYER_3) ? 255 : 0,
0,
Device_STATELED);
Device_STATUSLED);
sei();
show();
}
Expand Down
4 changes: 1 addition & 3 deletions keyboards/duck/jetfire/jetfire.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JETFIRE_H
#define JETFIRE_H
#pragma once

#include "quantum.h"

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion keyboards/duck/jetfire/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
6 changes: 3 additions & 3 deletions keyboards/duck/jetfire/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
8 changes: 5 additions & 3 deletions keyboards/duck/lightsaver/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONFIG_H
#define CONFIG_H
#pragma once

#include "config_common.h"

Expand Down Expand Up @@ -44,6 +43,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGB_DI_PIN D6
#define RGBLED_NUM 17

/* Set to top left most key */
#define BOOTMAGIC_LITE_ROW 5
#define BOOTMAGIC_LITE_COLUMN 10

#define TAPPING_TERM 200

#endif
Loading

0 comments on commit cb2f2fd

Please sign in to comment.