[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
This commit is contained in:
parent
caefb1c61e
commit
cb2f2fd258
33 changed files with 192 additions and 202 deletions
|
@ -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).
|
||||
*/
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -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"
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
|
@ -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]);
|
||||
|
@ -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
|
|
@ -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,
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue