aboutsummaryrefslogtreecommitdiff
path: root/keyboards/nullbitsco/nibble
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/nullbitsco/nibble')
-rw-r--r--keyboards/nullbitsco/nibble/big_led.c2
-rw-r--r--keyboards/nullbitsco/nibble/big_led.h2
-rw-r--r--keyboards/nullbitsco/nibble/bitc_led.c37
-rw-r--r--keyboards/nullbitsco/nibble/bitc_led.h29
-rw-r--r--keyboards/nullbitsco/nibble/config.h2
-rw-r--r--keyboards/nullbitsco/nibble/keymaps/default/keymap.c2
-rw-r--r--keyboards/nullbitsco/nibble/keymaps/iso/keymap.c2
-rw-r--r--keyboards/nullbitsco/nibble/keymaps/oled/keymap.c2
-rw-r--r--keyboards/nullbitsco/nibble/keymaps/via/keymap.c2
-rw-r--r--keyboards/nullbitsco/nibble/matrix.c2
-rw-r--r--keyboards/nullbitsco/nibble/nibble.c3
-rw-r--r--keyboards/nullbitsco/nibble/nibble.h5
-rw-r--r--keyboards/nullbitsco/nibble/remote_kb.c178
-rw-r--r--keyboards/nullbitsco/nibble/remote_kb.h52
-rw-r--r--keyboards/nullbitsco/nibble/rules.mk4
15 files changed, 14 insertions, 310 deletions
diff --git a/keyboards/nullbitsco/nibble/big_led.c b/keyboards/nullbitsco/nibble/big_led.c
index 9fd06a5de..d66a80815 100644
--- a/keyboards/nullbitsco/nibble/big_led.c
+++ b/keyboards/nullbitsco/nibble/big_led.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/big_led.h b/keyboards/nullbitsco/nibble/big_led.h
index b4b065078..4ebcc35f0 100644
--- a/keyboards/nullbitsco/nibble/big_led.h
+++ b/keyboards/nullbitsco/nibble/big_led.h
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/bitc_led.c b/keyboards/nullbitsco/nibble/bitc_led.c
deleted file mode 100644
index 60ffeea27..000000000
--- a/keyboards/nullbitsco/nibble/bitc_led.c
+++ /dev/null
@@ -1,37 +0,0 @@
1/* Copyright 2020 Jay Greco
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "bitc_led.h"
17
18void set_bitc_LED(uint8_t mode) {
19 switch(mode) {
20 case LED_ON:
21 setPinOutput(PIN_LED);
22 writePin(PIN_LED, GPIO_STATE_HIGH);
23 break;
24
25 case LED_DIM:
26 setPinInput(PIN_LED);
27 break;
28
29 case LED_OFF:
30 setPinOutput(PIN_LED);
31 writePin(PIN_LED, GPIO_STATE_LOW);
32 break;
33
34 default:
35 break;
36 }
37} \ No newline at end of file
diff --git a/keyboards/nullbitsco/nibble/bitc_led.h b/keyboards/nullbitsco/nibble/bitc_led.h
deleted file mode 100644
index b3552a7d1..000000000
--- a/keyboards/nullbitsco/nibble/bitc_led.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/* Copyright 2020 Jay Greco
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18#include "quantum.h"
19
20#define LED_ON 2
21#define LED_DIM 1
22#define LED_OFF 0
23
24#define GPIO_STATE_LOW 0
25#define GPIO_STATE_HIGH 1
26
27#define PIN_LED F0
28
29void set_bitc_LED(uint8_t mode); \ No newline at end of file
diff --git a/keyboards/nullbitsco/nibble/config.h b/keyboards/nullbitsco/nibble/config.h
index 3e0adce45..b88d4bc36 100644
--- a/keyboards/nullbitsco/nibble/config.h
+++ b/keyboards/nullbitsco/nibble/config.h
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/keymaps/default/keymap.c b/keyboards/nullbitsco/nibble/keymaps/default/keymap.c
index beac1c55a..f9fc56e70 100644
--- a/keyboards/nullbitsco/nibble/keymaps/default/keymap.c
+++ b/keyboards/nullbitsco/nibble/keymaps/default/keymap.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/keymaps/iso/keymap.c b/keyboards/nullbitsco/nibble/keymaps/iso/keymap.c
index 270350ca0..0f0ed590a 100644
--- a/keyboards/nullbitsco/nibble/keymaps/iso/keymap.c
+++ b/keyboards/nullbitsco/nibble/keymaps/iso/keymap.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/keymaps/oled/keymap.c b/keyboards/nullbitsco/nibble/keymaps/oled/keymap.c
index 0e0a152ec..14f79f5fb 100644
--- a/keyboards/nullbitsco/nibble/keymaps/oled/keymap.c
+++ b/keyboards/nullbitsco/nibble/keymaps/oled/keymap.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/keymaps/via/keymap.c b/keyboards/nullbitsco/nibble/keymaps/via/keymap.c
index 67a53f241..b1c9242b9 100644
--- a/keyboards/nullbitsco/nibble/keymaps/via/keymap.c
+++ b/keyboards/nullbitsco/nibble/keymaps/via/keymap.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/matrix.c b/keyboards/nullbitsco/nibble/matrix.c
index 8ec9da284..496c5dbe3 100644
--- a/keyboards/nullbitsco/nibble/matrix.c
+++ b/keyboards/nullbitsco/nibble/matrix.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
diff --git a/keyboards/nullbitsco/nibble/nibble.c b/keyboards/nullbitsco/nibble/nibble.c
index 409edd44a..43918c13e 100644
--- a/keyboards/nullbitsco/nibble/nibble.c
+++ b/keyboards/nullbitsco/nibble/nibble.c
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
@@ -14,7 +14,6 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16#include QMK_KEYBOARD_H 16#include QMK_KEYBOARD_H
17#include "bitc_led.h"
18 17
19// Use Bit-C LED to show CAPS LOCK status 18// Use Bit-C LED to show CAPS LOCK status
20bool led_update_kb(led_t led_state) { 19bool led_update_kb(led_t led_state) {
diff --git a/keyboards/nullbitsco/nibble/nibble.h b/keyboards/nullbitsco/nibble/nibble.h
index b974edaba..58ac80445 100644
--- a/keyboards/nullbitsco/nibble/nibble.h
+++ b/keyboards/nullbitsco/nibble/nibble.h
@@ -1,4 +1,4 @@
1/* Copyright 2020 Jay Greco 1/* Copyright 2021 Jay Greco
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,8 @@
18#define ___ KC_NO 18#define ___ KC_NO
19 19
20#include "quantum.h" 20#include "quantum.h"
21#include "remote_kb.h" 21#include "common/remote_kb.h"
22#include "common/bitc_led.h"
22 23
23#define LAYOUT_all( \ 24#define LAYOUT_all( \
24 K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, \ 25 K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, \
diff --git a/keyboards/nullbitsco/nibble/remote_kb.c b/keyboards/nullbitsco/nibble/remote_kb.c
deleted file mode 100644
index 7a914993f..000000000
--- a/keyboards/nullbitsco/nibble/remote_kb.c
+++ /dev/null
@@ -1,178 +0,0 @@
1/* Copyright 2020 Jay Greco
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/*
18Remote keyboard is an experimental feature that allows for connecting another
19keyboard, macropad, numpad, or accessory without requiring an additional USB connection.
20The "remote keyboard" forwards its keystrokes using UART serial over TRRS. Dynamic VUSB
21detect allows the keyboard automatically switch to host or remote mode depending on
22which is connected to the USB port.
23
24Possible functionality includes the ability to send data from the host to the remote using
25a reverse link, allowing for LED sync, configuration, and more data sharing between devices.
26This will require a new communication protocol, as the current one is limited.
27*/
28
29#include "remote_kb.h"
30#include "uart.h"
31
32uint8_t
33 msg[UART_MSG_LEN],
34 msg_idx = 0;
35
36bool
37 is_host = true;
38
39// Private functions
40
41static bool vbus_detect(void) {
42 #if defined(__AVR_ATmega32U4__)
43 //returns true if VBUS is present, false otherwise.
44 USBCON |= (1 << OTGPADE); //enables VBUS pad
45 _delay_us(10);
46 return (USBSTA & (1<<VBUS)); //checks state of VBUS
47 #else
48 #error vbus_detect is not implemented for this architecure!
49 #endif
50}
51
52static uint8_t chksum8(const unsigned char *buf, size_t len) {
53 unsigned int sum;
54 for (sum = 0 ; len != 0 ; len--)
55 sum += *(buf++);
56 return (uint8_t)sum;
57}
58
59static void send_msg(uint16_t keycode, bool pressed) {
60 msg[IDX_PREAMBLE] = UART_PREAMBLE;
61 msg[IDX_KCLSB] = (keycode & 0xFF);
62 msg[IDX_KCMSB] = (keycode >> 8) & 0xFF;
63 msg[IDX_PRESSED] = pressed;
64 msg[IDX_CHECKSUM] = chksum8(msg, UART_MSG_LEN-1);
65
66 for (int i=0; i<UART_MSG_LEN; i++) {
67 uart_putchar(msg[i]);
68 }
69}
70
71static void print_message_buffer(void) {
72 for (int i=0; i<UART_MSG_LEN; i++) {
73 dprintf("msg[%u]: %u\n", i, msg[i]);
74 }
75}
76
77static void process_uart(void) {
78 uint8_t chksum = chksum8(msg, UART_MSG_LEN-1);
79 if (msg[IDX_PREAMBLE] != UART_PREAMBLE || msg[IDX_CHECKSUM] != chksum) {
80 dprintf("UART checksum mismatch!\n");
81 print_message_buffer();
82 dprintf("calc checksum: %u\n", chksum);
83 } else {
84 uint16_t keycode = (uint16_t)msg[IDX_KCLSB] | ((uint16_t)msg[IDX_KCMSB] << 8);
85 bool pressed = (bool)msg[IDX_PRESSED];
86 if (IS_RM_KC(keycode)) {
87 keyrecord_t record;
88 record.event.pressed = pressed;
89 if (pressed) dprintf("Remote macro: press [%u]\n", keycode);
90 else dprintf("Remote macro: release [%u]\n", keycode);
91 process_record_user(keycode, &record);
92 } else {
93 if (pressed) {
94 dprintf("Remote: press [%u]\n", keycode);
95 register_code(keycode);
96 } else {
97 dprintf("Remote: release [%u]\n", keycode);
98 unregister_code(keycode);
99 }
100 }
101 }
102}
103
104static void get_msg(void) {
105 while (uart_available()) {
106 msg[msg_idx] = uart_getchar();
107 dprintf("idx: %u, recv: %u\n", msg_idx, msg[msg_idx]);
108 if (msg_idx == 0 && (msg[msg_idx] != UART_PREAMBLE)) {
109 dprintf("Byte sync error!\n");
110 msg_idx = 0;
111 } else if (msg_idx == (UART_MSG_LEN-1)) {
112 process_uart();
113 msg_idx = 0;
114 } else {
115 msg_idx++;
116 }
117 }
118}
119
120static void handle_host_incoming(void) {
121 get_msg();
122}
123
124static void handle_host_outgoing(void) {
125 // for future reverse link use
126}
127
128static void handle_remote_incoming(void) {
129 // for future reverse link use
130}
131
132static void handle_remote_outgoing(uint16_t keycode, keyrecord_t *record) {
133 if (IS_HID_KC(keycode) || IS_RM_KC(keycode)) {
134 dprintf("Remote: send [%u]\n", keycode);
135 send_msg(keycode, record->event.pressed);
136 }
137}
138
139// Public functions
140
141void matrix_init_remote_kb(void) {
142 uart_init(SERIAL_UART_BAUD);
143 is_host = vbus_detect();
144}
145
146void process_record_remote_kb(uint16_t keycode, keyrecord_t *record) {
147 #if defined (KEYBOARD_HOST)
148 handle_host_outgoing();
149
150 #elif defined(KEYBOARD_REMOTE)
151 handle_remote_outgoing(keycode, record);
152
153 #else //auto check with VBUS
154 if (is_host) {
155 handle_host_outgoing();
156 }
157 else {
158 handle_remote_outgoing(keycode, record);
159 }
160 #endif
161}
162
163void matrix_scan_remote_kb(void) {
164 #if defined(KEYBOARD_HOST)
165 handle_host_incoming();
166
167 #elif defined (KEYBOARD_REMOTE)
168 handle_remote_incoming();
169
170 #else //auto check with VBUS
171 if (is_host) {
172 handle_host_incoming();
173 }
174 else {
175 handle_remote_incoming();
176 }
177 #endif
178}
diff --git a/keyboards/nullbitsco/nibble/remote_kb.h b/keyboards/nullbitsco/nibble/remote_kb.h
deleted file mode 100644
index f4b5c43f5..000000000
--- a/keyboards/nullbitsco/nibble/remote_kb.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/* Copyright 2020 Jay Greco
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18#include "quantum.h"
19
20#define SERIAL_UART_BAUD 153600 //low error rate for 32u4 @ 16MHz
21
22#define UART_PREAMBLE 0x69
23#define UART_MSG_LEN 5
24#define UART_NULL 0
25
26#define IDX_PREAMBLE 0
27#define IDX_KCLSB 1
28#define IDX_KCMSB 2
29#define IDX_PRESSED 3
30#define IDX_CHECKSUM 4
31
32#define IS_HID_KC(x) ((x > 0) && (x < 0xFF))
33#define IS_RM_KC(x) ((x >= RM_BASE) && (x <= 0xFFFF))
34
35#define RM_BASE 0xFFFF-16
36enum remote_macros {
37 RM_1 = RM_BASE,
38 RM_2, RM_3,
39 RM_4, RM_5,
40 RM_6, RM_7,
41 RM_8, RM_9,
42 RM_10, RM_11,
43 RM_12, RM_13,
44 RM_14, RM_15,
45};
46
47
48// Public functions
49void
50 matrix_init_remote_kb(void),
51 process_record_remote_kb(uint16_t keycode, keyrecord_t *record),
52 matrix_scan_remote_kb(void); \ No newline at end of file
diff --git a/keyboards/nullbitsco/nibble/rules.mk b/keyboards/nullbitsco/nibble/rules.mk
index dd4d36c98..ab20cfa24 100644
--- a/keyboards/nullbitsco/nibble/rules.mk
+++ b/keyboards/nullbitsco/nibble/rules.mk
@@ -23,7 +23,7 @@ CUSTOM_MATRIX = lite # Lite custom matrix
23 23
24# Project specific files 24# Project specific files
25SRC += matrix.c \ 25SRC += matrix.c \
26 bitc_led.c \ 26 common/bitc_led.c \
27 big_led.c \ 27 big_led.c \
28 remote_kb.c 28 common/remote_kb.c
29QUANTUM_LIB_SRC += uart.c 29QUANTUM_LIB_SRC += uart.c