aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsatt99 <39004890+satt99@users.noreply.github.com>2018-12-31 01:34:06 +0900
committerDrashna Jaelre <drashna@live.com>2018-12-30 08:34:06 -0800
commit46b4b4407ff6e23d0799b0f902e61f1fe3645a9a (patch)
treede3fe1ee10e65c08549cc20230f9f822954a8fee
parentc2390bf32156884d6825686c7f13f9c621bab366 (diff)
downloadqmk_firmware-46b4b4407ff6e23d0799b0f902e61f1fe3645a9a.tar.gz
qmk_firmware-46b4b4407ff6e23d0799b0f902e61f1fe3645a9a.zip
Comet46 add support for OLED (#4745)
* Add OLED support for Comet46 * fix length of char "name" of keylogger.c * update ssd1306 * fix rules.mk * update led-receiver keymap * Update OLED related code * add mod_state_reader & modify led_state_reader * Update OLED related files * Update kemaps * Update readme * change default-oled-display to default * Add OSM compatibility to mod_state_reader * Code formatting * Use PROGMEM to store code_to_name * Clean up satt keymap * Rename default-led keymap to defult-rgbled
-rw-r--r--keyboards/comet46/comet46.c8
-rw-r--r--keyboards/comet46/comet46.h40
-rw-r--r--keyboards/comet46/config.h12
-rw-r--r--keyboards/comet46/i2c.c162
-rw-r--r--keyboards/comet46/i2c.h49
-rw-r--r--keyboards/comet46/keymaps/default-rgbled/keymap.c226
-rw-r--r--keyboards/comet46/keymaps/default-rgbled/readme.md3
-rw-r--r--keyboards/comet46/keymaps/default/config.h31
-rw-r--r--keyboards/comet46/keymaps/default/keymap.c189
-rw-r--r--keyboards/comet46/keymaps/default/readme.md3
-rw-r--r--keyboards/comet46/keymaps/default/rules.mk5
-rw-r--r--keyboards/comet46/keymaps/satt/action_pseudo_lut.c212
-rw-r--r--keyboards/comet46/keymaps/satt/config.h34
-rw-r--r--keyboards/comet46/keymaps/satt/keymap.c256
-rw-r--r--keyboards/comet46/keymaps/satt/keymap_jis2us.h46
-rw-r--r--keyboards/comet46/keymaps/satt/rules.mk29
-rw-r--r--keyboards/comet46/lib/glcdfont.c148
-rw-r--r--keyboards/comet46/lib/host_led_state_reader.c15
-rw-r--r--keyboards/comet46/lib/keylogger.c294
-rw-r--r--keyboards/comet46/lib/modifier_state_reader.c18
-rw-r--r--keyboards/comet46/readme.md5
-rw-r--r--keyboards/comet46/rules.mk16
-rw-r--r--keyboards/comet46/ssd1306.c344
-rw-r--r--keyboards/comet46/ssd1306.h91
24 files changed, 1906 insertions, 330 deletions
diff --git a/keyboards/comet46/comet46.c b/keyboards/comet46/comet46.c
index 20dcfab83..0710b8e33 100644
--- a/keyboards/comet46/comet46.c
+++ b/keyboards/comet46/comet46.c
@@ -4,19 +4,11 @@ void uart_init(void) {
4 SERIAL_UART_INIT(); 4 SERIAL_UART_INIT();
5} 5}
6 6
7void led_init(void) {
8 DDRD |= (1<<1);
9 PORTD |= (1<<1);
10 DDRF |= (1<<4) | (1<<5);
11 PORTF |= (1<<4) | (1<<5);
12}
13
14void matrix_init_kb(void) { 7void matrix_init_kb(void) {
15 // put your keyboard start-up code here 8 // put your keyboard start-up code here
16 // runs once when the firmware starts up 9 // runs once when the firmware starts up
17 matrix_init_user(); 10 matrix_init_user();
18 uart_init(); 11 uart_init();
19 led_init();
20} 12}
21 13
22void matrix_scan_kb(void) { 14void matrix_scan_kb(void) {
diff --git a/keyboards/comet46/comet46.h b/keyboards/comet46/comet46.h
index 7d6d6d513..07dad0a00 100644
--- a/keyboards/comet46/comet46.h
+++ b/keyboards/comet46/comet46.h
@@ -6,46 +6,6 @@
6#include "backlight.h" 6#include "backlight.h"
7#include <stddef.h> 7#include <stddef.h>
8 8
9#define red_led_off PORTF |= (1<<5)
10#define red_led_on PORTF &= ~(1<<5)
11#define blu_led_off PORTF |= (1<<4)
12#define blu_led_on PORTF &= ~(1<<4)
13#define grn_led_off PORTD |= (1<<1)
14#define grn_led_on PORTD &= ~(1<<1)
15
16#define set_led_off red_led_off; grn_led_off; blu_led_off
17#define set_led_red red_led_on; grn_led_off; blu_led_off
18#define set_led_blue red_led_off; grn_led_off; blu_led_on
19#define set_led_green red_led_off; grn_led_on; blu_led_off
20#define set_led_yellow red_led_on; grn_led_on; blu_led_off
21#define set_led_magenta red_led_on; grn_led_off; blu_led_on
22#define set_led_cyan red_led_off; grn_led_on; blu_led_on
23#define set_led_white red_led_on; grn_led_on; blu_led_on
24
25/*
26#define LED_B 5
27#define LED_R 6
28#define LED_G 7
29
30#define all_leds_off PORTF &= ~(1<<LED_B) & ~(1<<LED_R) & ~(1<<LED_G)
31
32#define red_led_on PORTF |= (1<<LED_R)
33#define red_led_off PORTF &= ~(1<<LED_R)
34#define grn_led_on PORTF |= (1<<LED_G)
35#define grn_led_off PORTF &= ~(1<<LED_G)
36#define blu_led_on PORTF |= (1<<LED_B)
37#define blu_led_off PORTF &= ~(1<<LED_B)
38
39#define set_led_off PORTF &= ~(1<<LED_B) & ~(1<<LED_R) & ~(1<<LED_G)
40#define set_led_red PORTF = PORTF & ~(1<<LED_B) & ~(1<<LED_G) | (1<<LED_R)
41#define set_led_blue PORTF = PORTF & ~(1<<LED_G) & ~(1<<LED_R) | (1<<LED_B)
42#define set_led_green PORTF = PORTF & ~(1<<LED_B) & ~(1<<LED_R) | (1<<LED_G)
43#define set_led_yellow PORTF = PORTF & ~(1<<LED_B) | (1<<LED_R) | (1<<LED_G)
44#define set_led_magenta PORTF = PORTF & ~(1<<LED_G) | (1<<LED_R) | (1<<LED_B)
45#define set_led_cyan PORTF = PORTF & ~(1<<LED_R) | (1<<LED_B) | (1<<LED_G)
46#define set_led_white PORTF |= (1<<LED_B) | (1<<LED_R) | (1<<LED_G)
47*/
48
49// This a shortcut to help you visually see your layout. 9// This a shortcut to help you visually see your layout.
50// The first section contains all of the arguements 10// The first section contains all of the arguements
51// The second converts the arguments into a two-dimensional array 11// The second converts the arguments into a two-dimensional array
diff --git a/keyboards/comet46/config.h b/keyboards/comet46/config.h
index 2421f5341..c43f13a50 100644
--- a/keyboards/comet46/config.h
+++ b/keyboards/comet46/config.h
@@ -41,12 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
41 41
42#define ONESHOT_TIMEOUT 500 42#define ONESHOT_TIMEOUT 500
43 43
44
45/* key combination for command */
46#define IS_COMMAND() ( \
47 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
48)
49
50/* 44/*
51 * Feature disable options 45 * Feature disable options
52 * These options are also useful to firmware size reduction. 46 * These options are also useful to firmware size reduction.
@@ -65,6 +59,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
65//#define NO_ACTION_MACRO 59//#define NO_ACTION_MACRO
66//#define NO_ACTION_FUNCTION 60//#define NO_ACTION_FUNCTION
67 61
62// Define masks for modifiers
63#define MODS_SHIFT_MASK (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT))
64#define MODS_CTRL_MASK (MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTRL))
65#define MODS_ALT_MASK (MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT))
66#define MODS_GUI_MASK (MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))
67
68//UART settings for communication with the RF microcontroller 68//UART settings for communication with the RF microcontroller
69#define SERIAL_UART_BAUD 1000000 69#define SERIAL_UART_BAUD 1000000
70#define SERIAL_UART_DATA UDR1 70#define SERIAL_UART_DATA UDR1
diff --git a/keyboards/comet46/i2c.c b/keyboards/comet46/i2c.c
new file mode 100644
index 000000000..4bee5c639
--- /dev/null
+++ b/keyboards/comet46/i2c.c
@@ -0,0 +1,162 @@
1#include <util/twi.h>
2#include <avr/io.h>
3#include <stdlib.h>
4#include <avr/interrupt.h>
5#include <util/twi.h>
6#include <stdbool.h>
7#include "i2c.h"
8
9#ifdef USE_I2C
10
11// Limits the amount of we wait for any one i2c transaction.
12// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
13// 9 bits, a single transaction will take around 90μs to complete.
14//
15// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit
16// poll loop takes at least 8 clock cycles to execute
17#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8
18
19#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE)
20
21volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
22
23static volatile uint8_t slave_buffer_pos;
24static volatile bool slave_has_register_set = false;
25
26// Wait for an i2c operation to finish
27inline static
28void i2c_delay(void) {
29 uint16_t lim = 0;
30 while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT)
31 lim++;
32
33 // easier way, but will wait slightly longer
34 // _delay_us(100);
35}
36
37// Setup twi to run at 100kHz or 400kHz (see ./i2c.h SCL_CLOCK)
38void i2c_master_init(void) {
39 // no prescaler
40 TWSR = 0;
41 // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.
42 // Check datasheets for more info.
43 TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
44}
45
46// Start a transaction with the given i2c slave address. The direction of the
47// transfer is set with I2C_READ and I2C_WRITE.
48// returns: 0 => success
49// 1 => error
50uint8_t i2c_master_start(uint8_t address) {
51 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA);
52
53 i2c_delay();
54
55 // check that we started successfully
56 if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START))
57 return 1;
58
59 TWDR = address;
60 TWCR = (1<<TWINT) | (1<<TWEN);
61
62 i2c_delay();
63
64 if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) )
65 return 1; // slave did not acknowledge
66 else
67 return 0; // success
68}
69
70
71// Finish the i2c transaction.
72void i2c_master_stop(void) {
73 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
74
75 uint16_t lim = 0;
76 while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT)
77 lim++;
78}
79
80// Write one byte to the i2c slave.
81// returns 0 => slave ACK
82// 1 => slave NACK
83uint8_t i2c_master_write(uint8_t data) {
84 TWDR = data;
85 TWCR = (1<<TWINT) | (1<<TWEN);
86
87 i2c_delay();
88
89 // check if the slave acknowledged us
90 return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1;
91}
92
93// Read one byte from the i2c slave. If ack=1 the slave is acknowledged,
94// if ack=0 the acknowledge bit is not set.
95// returns: byte read from i2c device
96uint8_t i2c_master_read(int ack) {
97 TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA);
98
99 i2c_delay();
100 return TWDR;
101}
102
103void i2c_reset_state(void) {
104 TWCR = 0;
105}
106
107void i2c_slave_init(uint8_t address) {
108 TWAR = address << 0; // slave i2c address
109 // TWEN - twi enable
110 // TWEA - enable address acknowledgement
111 // TWINT - twi interrupt flag
112 // TWIE - enable the twi interrupt
113 TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN);
114}
115
116ISR(TWI_vect);
117
118ISR(TWI_vect) {
119 uint8_t ack = 1;
120 switch(TW_STATUS) {
121 case TW_SR_SLA_ACK:
122 // this device has been addressed as a slave receiver
123 slave_has_register_set = false;
124 break;
125
126 case TW_SR_DATA_ACK:
127 // this device has received data as a slave receiver
128 // The first byte that we receive in this transaction sets the location
129 // of the read/write location of the slaves memory that it exposes over
130 // i2c. After that, bytes will be written at slave_buffer_pos, incrementing
131 // slave_buffer_pos after each write.
132 if(!slave_has_register_set) {
133 slave_buffer_pos = TWDR;
134 // don't acknowledge the master if this memory loctaion is out of bounds
135 if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) {
136 ack = 0;
137 slave_buffer_pos = 0;
138 }
139 slave_has_register_set = true;
140 } else {
141 i2c_slave_buffer[slave_buffer_pos] = TWDR;
142 BUFFER_POS_INC();
143 }
144 break;
145
146 case TW_ST_SLA_ACK:
147 case TW_ST_DATA_ACK:
148 // master has addressed this device as a slave transmitter and is
149 // requesting data.
150 TWDR = i2c_slave_buffer[slave_buffer_pos];
151 BUFFER_POS_INC();
152 break;
153
154 case TW_BUS_ERROR: // something went wrong, reset twi state
155 TWCR = 0;
156 default:
157 break;
158 }
159 // Reset everything, so we are ready for the next TWI interrupt
160 TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
161}
162#endif
diff --git a/keyboards/comet46/i2c.h b/keyboards/comet46/i2c.h
new file mode 100644
index 000000000..47cf6bd1b
--- /dev/null
+++ b/keyboards/comet46/i2c.h
@@ -0,0 +1,49 @@
1#ifndef I2C_H
2#define I2C_H
3
4#include <stdint.h>
5
6#ifndef F_CPU
7#define F_CPU 16000000UL
8#endif
9
10#define I2C_READ 1
11#define I2C_WRITE 0
12
13#define I2C_ACK 1
14#define I2C_NACK 0
15
16#define SLAVE_BUFFER_SIZE 0x10
17
18// i2c SCL clock frequency 400kHz
19#define SCL_CLOCK 400000L
20
21extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
22
23void i2c_master_init(void);
24uint8_t i2c_master_start(uint8_t address);
25void i2c_master_stop(void);
26uint8_t i2c_master_write(uint8_t data);
27uint8_t i2c_master_read(int);
28void i2c_reset_state(void);
29void i2c_slave_init(uint8_t address);
30
31
32static inline unsigned char i2c_start_read(unsigned char addr) {
33 return i2c_master_start((addr << 1) | I2C_READ);
34}
35
36static inline unsigned char i2c_start_write(unsigned char addr) {
37 return i2c_master_start((addr << 1) | I2C_WRITE);
38}
39
40// from SSD1306 scrips
41extern unsigned char i2c_rep_start(unsigned char addr);
42extern void i2c_start_wait(unsigned char addr);
43extern unsigned char i2c_readAck(void);
44extern unsigned char i2c_readNak(void);
45extern unsigned char i2c_read(unsigned char ack);
46
47#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
48
49#endif
diff --git a/keyboards/comet46/keymaps/default-rgbled/keymap.c b/keyboards/comet46/keymaps/default-rgbled/keymap.c
new file mode 100644
index 000000000..d446d50d0
--- /dev/null
+++ b/keyboards/comet46/keymaps/default-rgbled/keymap.c
@@ -0,0 +1,226 @@
1// this is the style you want to emulate.
2// This is the canonical layout file for the Quantum project. If you want to add another keyboard,
3
4#include QMK_KEYBOARD_H
5
6// Each layer gets a name for readability, which is then used in the keymap matrix below.
7// The underscores don't mean anything - you can have a layer called STUFF or any other name.
8// Layer names don't all need to be of the same length, obviously, and you can also skip them
9// entirely and just use numbers.
10enum comet46_layers
11{
12 _QWERTY,
13 _COLEMAK,
14 _DVORAK,
15 _LOWER,
16 _RAISE,
17 _ADJUST,
18};
19
20enum custom_keycodes {
21 QWERTY = SAFE_RANGE,
22 COLEMAK,
23 DVORAK,
24 LOWER,
25 RAISE,
26};
27
28// Fillers to make layering more clear
29#define _______ KC_TRNS
30#define XXXXXXX KC_NO
31#define LOWER MO(_LOWER)
32#define RAISE MO(_RAISE)
33
34const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
35
36 /* Qwerty
37 * ,-----------------------------------------+ +-----------------------------------------.
38 * | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp |
39 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
40 * | Ctl | A | S | D | F | G | Esc | | Del | H | J | K | L | ; | " |
41 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
42 * | Shift| Z | X | C | V | B | { | | } | N | M | , | . | / | Shift|
43 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
44 * | GUI | Lower| Space| | Enter| Raise| Alt |
45 * +--------------------/ \--------------------+
46 */
47 [_QWERTY] = LAYOUT(
48 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
49 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_ESC, KC_DEL, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
50 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LCBR, KC_RCBR, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
51 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT
52 ),
53
54 /* Colemak
55 * ,-----------------------------------------+ +-----------------------------------------.
56 * | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp |
57 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
58 * | Ctl | A | R | S | T | D | Esc | | Del | H | N | E | I | O | " |
59 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
60 * | Shift| Z | X | C | V | B | { | | } | K | M | , | . | / | Shift|
61 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
62 * | GUI | Lower| Space| | Enter| Raise| Alt |
63 * +--------------------/ \--------------------+
64 */
65 [_COLEMAK] = LAYOUT(
66 KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
67 KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_ESC, KC_DEL, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
68 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LCBR, KC_RCBR, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
69 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT
70 ),
71
72 /* Dvorak
73 * ,-----------------------------------------+ +-----------------------------------------.
74 * | Tab | " | , | . | P | Y | | F | G | C | R | L | Bksp |
75 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
76 * | Ctl | A | O | E | U | I | Esc | | Del | D | H | T | N | S | / |
77 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
78 * | Shift| ; | Q | J | K | X | { | | } | B | M | W | V | Z | Shift|
79 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
80 * | GUI | Lower| Space| | Enter| Raise| Alt |
81 * +--------------------/ \--------------------+
82 */
83 [_DVORAK] = LAYOUT(
84 KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC,
85 KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_ESC, KC_DEL, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH,
86 KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_LCBR, KC_RCBR, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_RSFT,
87 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT
88 ),
89
90 /* Lower
91 * ,-----------------------------------------+ +-----------------------------------------.
92 * | | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
93 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
94 * | | | | | | | | | ` | \ | - | = | [ | ] | |
95 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
96 * | | | | | | | | | ~ | | | _ | + | { | } | |
97 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
98 * | | | | | | | |
99 * +--------------------/ \--------------------+
100 */
101 [_LOWER] = LAYOUT(
102 _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
103 _______, _______, _______, _______, _______, _______, _______, KC_GRV, KC_BSLS, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, _______,
104 _______, _______, _______, _______, _______, _______, _______, KC_TILD, KC_PIPE, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, _______,
105 _______, _______, _______, _______, _______, _______
106 ),
107
108 /* Raise
109 * ,-----------------------------------------+ +-----------------------------------------.
110 * | | 1 | 2 | 3 | 4 | 5 | | | | | | | |
111 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
112 * | | F1 | F2 | F3 | F4 | F5 | F6 | | | Left | Down | Up |Right | End | |
113 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
114 * | | F7 | F8 | F9 | F10 | F11 | F12 | | Home | | PgDn | PgUp | | | |
115 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
116 * | | | | | | | |
117 * +--------------------/ \--------------------+
118 */
119 [_RAISE] = LAYOUT(
120 _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
121 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_END, _______,
122 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, XXXXXXX, KC_PGDN, KC_PGUP, XXXXXXX, XXXXXXX, _______,
123 _______, _______, _______, _______, _______, _______
124 ),
125
126 /* Adjust
127 * ,-----------------------------------------+ +-----------------------------------------.
128 * | | | | | | | | | | | | | |
129 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
130 * | | | | | | |Qwerty| |Colemk| | | | | | |
131 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
132 * | | | | | | |Reset | |Dvorak| | | | | | |
133 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
134 * | | | | | | | |
135 * +--------------------/ \--------------------+
136 */
137 [_ADJUST] = LAYOUT(
138 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
139 _______, _______, _______, _______, _______, _______, QWERTY, COLEMAK, _______, _______, _______, _______, _______, _______,
140 _______, _______, _______, _______, _______, _______, RESET, DVORAK, _______, _______, _______, _______, _______, _______,
141 _______, _______, _______, _______, _______, _______
142 )
143};
144
145
146uint32_t layer_state_set_user(uint32_t state) {
147 return update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
148}
149
150// settings for LED on receiver
151void led_init(void) {
152 DDRD |= (1<<1);
153 PORTD |= (1<<1);
154 DDRF |= (1<<4) | (1<<5);
155 PORTF |= (1<<4) | (1<<5);
156}
157
158#define red_led_off PORTF |= (1<<5)
159#define red_led_on PORTF &= ~(1<<5)
160#define blu_led_off PORTF |= (1<<4)
161#define blu_led_on PORTF &= ~(1<<4)
162#define grn_led_off PORTD |= (1<<1)
163#define grn_led_on PORTD &= ~(1<<1)
164
165#define set_led_off red_led_off; grn_led_off; blu_led_off
166#define set_led_red red_led_on; grn_led_off; blu_led_off
167#define set_led_blue red_led_off; grn_led_off; blu_led_on
168#define set_led_green red_led_off; grn_led_on; blu_led_off
169#define set_led_yellow red_led_on; grn_led_on; blu_led_off
170#define set_led_magenta red_led_on; grn_led_off; blu_led_on
171#define set_led_cyan red_led_off; grn_led_on; blu_led_on
172#define set_led_white red_led_on; grn_led_on; blu_led_on
173
174void matrix_init_user(void) {
175 led_init();
176}
177
178void matrix_scan_user(void) {
179 uint8_t layer = biton32(layer_state);
180 uint8_t default_layer = biton32(eeconfig_read_default_layer());
181 switch (layer) {
182 case _LOWER:
183 set_led_red;
184 break;
185 case _RAISE:
186 set_led_blue;
187 break;
188 case _ADJUST:
189 set_led_magenta;
190 break;
191 default:
192 switch (default_layer) {
193 case _COLEMAK:
194 set_led_white;
195 break;
196 case _DVORAK:
197 set_led_yellow;
198 break;
199 default:
200 set_led_green;
201 break;
202 }
203 break;
204 }
205};
206
207bool process_record_user(uint16_t keycode, keyrecord_t *record) {
208 switch (keycode) {
209 case QWERTY:
210 if (record->event.pressed) {
211 set_single_persistent_default_layer(_QWERTY);
212 }
213 break;
214 case COLEMAK:
215 if (record->event.pressed) {
216 set_single_persistent_default_layer(_COLEMAK);
217 }
218 break;
219 case DVORAK:
220 if (record->event.pressed) {
221 set_single_persistent_default_layer(_DVORAK);
222 }
223 break;
224 }
225 return true;
226}
diff --git a/keyboards/comet46/keymaps/default-rgbled/readme.md b/keyboards/comet46/keymaps/default-rgbled/readme.md
new file mode 100644
index 000000000..40cc74433
--- /dev/null
+++ b/keyboards/comet46/keymaps/default-rgbled/readme.md
@@ -0,0 +1,3 @@
1## default-led
2
3A keymap that is compatible with mitosis-type receivers, which use RGB LED for layer indication.
diff --git a/keyboards/comet46/keymaps/default/config.h b/keyboards/comet46/keymaps/default/config.h
new file mode 100644
index 000000000..7873cf5a7
--- /dev/null
+++ b/keyboards/comet46/keymaps/default/config.h
@@ -0,0 +1,31 @@
1/*
2This is the c configuration file for the keymap
3
4Copyright 2012 Jun Wako <wakojun@gmail.com>
5Copyright 2015 Jack Humbert
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef CONFIG_USER_H
22#define CONFIG_USER_H
23
24// #include "../../config.h"
25
26/* Use I2C or Serial */
27
28#define USE_I2C
29#define SSD1306OLED
30
31#endif
diff --git a/keyboards/comet46/keymaps/default/keymap.c b/keyboards/comet46/keymaps/default/keymap.c
index b03ece4e9..c87492e4b 100644
--- a/keyboards/comet46/keymaps/default/keymap.c
+++ b/keyboards/comet46/keymaps/default/keymap.c
@@ -2,6 +2,10 @@
2// This is the canonical layout file for the Quantum project. If you want to add another keyboard, 2// This is the canonical layout file for the Quantum project. If you want to add another keyboard,
3 3
4#include QMK_KEYBOARD_H 4#include QMK_KEYBOARD_H
5#ifdef SSD1306OLED
6 #include "ssd1306.h"
7#endif
8
5 9
6// Each layer gets a name for readability, which is then used in the keymap matrix below. 10// Each layer gets a name for readability, which is then used in the keymap matrix below.
7// The underscores don't mean anything - you can have a layer called STUFF or any other name. 11// The underscores don't mean anything - you can have a layer called STUFF or any other name.
@@ -9,13 +13,18 @@
9// entirely and just use numbers. 13// entirely and just use numbers.
10enum comet46_layers 14enum comet46_layers
11{ 15{
12 _QWERTY, 16 _QWERTY,
13 _LOWER, 17 _COLEMAK,
14 _RAISE, 18 _DVORAK,
19 _LOWER,
20 _RAISE,
21 _ADJUST,
15}; 22};
16 23
17enum custom_keycodes { 24enum custom_keycodes {
18 QWERTY = SAFE_RANGE, 25 QWERTY = SAFE_RANGE,
26 COLEMAK,
27 DVORAK,
19 LOWER, 28 LOWER,
20 RAISE, 29 RAISE,
21}; 30};
@@ -46,6 +55,42 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
46 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT 55 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT
47 ), 56 ),
48 57
58 /* Colemak
59 * ,-----------------------------------------+ +-----------------------------------------.
60 * | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp |
61 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
62 * | Ctl | A | R | S | T | D | Esc | | Del | H | N | E | I | O | " |
63 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
64 * | Shift| Z | X | C | V | B | { | | } | K | M | , | . | / | Shift|
65 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
66 * | GUI | Lower| Space| | Enter| Raise| Alt |
67 * +--------------------/ \--------------------+
68 */
69 [_COLEMAK] = LAYOUT(
70 KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
71 KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_ESC, KC_DEL, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
72 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LCBR, KC_RCBR, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
73 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT
74 ),
75
76 /* Dvorak
77 * ,-----------------------------------------+ +-----------------------------------------.
78 * | Tab | " | , | . | P | Y | | F | G | C | R | L | Bksp |
79 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
80 * | Ctl | A | O | E | U | I | Esc | | Del | D | H | T | N | S | / |
81 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
82 * | Shift| ; | Q | J | K | X | { | | } | B | M | W | V | Z | Shift|
83 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
84 * | GUI | Lower| Space| | Enter| Raise| Alt |
85 * +--------------------/ \--------------------+
86 */
87 [_DVORAK] = LAYOUT(
88 KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC,
89 KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_ESC, KC_DEL, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH,
90 KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_LCBR, KC_RCBR, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_RSFT,
91 KC_LGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LALT
92 ),
93
49 /* Lower 94 /* Lower
50 * ,-----------------------------------------+ +-----------------------------------------. 95 * ,-----------------------------------------+ +-----------------------------------------.
51 * | | ! | @ | # | $ | % | | ^ | & | * | ( | ) | | 96 * | | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
@@ -70,7 +115,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
70 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------| 115 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
71 * | | F1 | F2 | F3 | F4 | F5 | F6 | | | Left | Down | Up |Right | End | | 116 * | | F1 | F2 | F3 | F4 | F5 | F6 | | | Left | Down | Up |Right | End | |
72 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------| 117 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
73 * | | F7 | F8 | F9 | F10 | F11 | F12 | | Home | | | | | | | 118 * | | F7 | F8 | F9 | F10 | F11 | F12 | | Home | | PgDn | PgUp | | | |
74 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------| 119 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
75 * | | | | | | | | 120 * | | | | | | | |
76 * +--------------------/ \--------------------+ 121 * +--------------------/ \--------------------+
@@ -78,26 +123,134 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
78 [_RAISE] = LAYOUT( 123 [_RAISE] = LAYOUT(
79 _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______, 124 _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
80 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_END, _______, 125 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_END, _______,
81 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, 126 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, XXXXXXX, KC_PGDN, KC_PGUP, XXXXXXX, XXXXXXX, _______,
127 _______, _______, _______, _______, _______, _______
128 ),
129
130 /* Adjust
131 * ,-----------------------------------------+ +-----------------------------------------.
132 * | | | | | | | | | | | | | |
133 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
134 * | | | | | | |Qwerty| |Colemk| | | | | | |
135 * |------+------+------+------+------+------+------+ +------+------+------+------+------+------+------|
136 * | | | | | | |Reset | |Dvorak| | | | | | |
137 * |------+------+------+------+------+------+------+ +------+------+------+------+------+-------------|
138 * | | | | | | | |
139 * +--------------------/ \--------------------+
140 */
141 [_ADJUST] = LAYOUT(
142 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
143 _______, _______, _______, _______, _______, _______, QWERTY, COLEMAK, _______, _______, _______, _______, _______, _______,
144 _______, _______, _______, _______, _______, _______, RESET, DVORAK, _______, _______, _______, _______, _______, _______,
82 _______, _______, _______, _______, _______, _______ 145 _______, _______, _______, _______, _______, _______
83 ) 146 )
84}; 147};
85 148
86 149
150uint32_t layer_state_set_user(uint32_t state) {
151 return update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
152}
153
154//SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
155#ifdef SSD1306OLED
156
157// You need to add source files to SRC in rules.mk when using OLED display functions
158void set_keylog(uint16_t keycode);
159const char *read_keylog(void);
160const char *read_modifier_state(void);
161const char *read_host_led_state(void);
162
163void matrix_init_user(void) {
164 iota_gfx_init(false); // turns on the display
165}
166
87void matrix_scan_user(void) { 167void matrix_scan_user(void) {
88 uint8_t layer = biton32(layer_state); 168 iota_gfx_task(); // this is what updates the display continuously
89 switch (layer) { 169}
90 case _QWERTY: 170
91 set_led_green; 171void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
92 break; 172 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
93 case _RAISE: 173 memcpy(dest->display, source->display, sizeof(dest->display));
94 set_led_blue; 174 dest->dirty = true;
95 break; 175 }
96 case _LOWER: 176}
97 set_led_red; 177
98 break; 178void render_status(struct CharacterMatrix *matrix) {
179 // Layer state
180 char layer_str[22];
181 matrix_write(matrix, "Layer: ");
182 uint8_t layer = biton32(layer_state);
183 uint8_t default_layer = biton32(eeconfig_read_default_layer());
184 switch (layer) {
185 case _QWERTY:
186 switch (default_layer) {
187 case _QWERTY:
188 snprintf(layer_str, sizeof(layer_str), "Qwerty");
189 break;
190 case _COLEMAK:
191 snprintf(layer_str, sizeof(layer_str), "Colemak");
192 break;
193 case _DVORAK:
194 snprintf(layer_str, sizeof(layer_str), "Dvorak");
195 break;
99 default: 196 default:
100 set_led_green; 197 snprintf(layer_str, sizeof(layer_str), "Undef-%d", default_layer);
101 break; 198 break;
199 }
200 break;
201 case _RAISE:
202 snprintf(layer_str, sizeof(layer_str), "Raise");
203 break;
204 case _LOWER:
205 snprintf(layer_str, sizeof(layer_str), "Lower");
206 break;
207 case _ADJUST:
208 snprintf(layer_str, sizeof(layer_str), "Adjust");
209 break;
210 default:
211 snprintf(layer_str, sizeof(layer_str), "Undef-%d", layer);
212 }
213 matrix_write_ln(matrix, layer_str);
214 // Last entered keycode
215 matrix_write_ln(matrix, read_keylog());
216 // Modifier state
217 matrix_write_ln(matrix, read_modifier_state());
218 // Host Keyboard LED Status
219 matrix_write(matrix, read_host_led_state());
220}
221
222
223void iota_gfx_task_user(void) {
224 struct CharacterMatrix matrix;
225 matrix_clear(&matrix);
226 render_status(&matrix);
227 matrix_update(&display, &matrix);
228}
229
230#endif//SSD1306OLED
231
232bool process_record_user(uint16_t keycode, keyrecord_t *record) {
233 #ifdef SSD1306OLED
234 if (record->event.pressed) {
235 set_keylog(keycode);
102 } 236 }
237 #endif
238 switch (keycode) {
239 case QWERTY:
240 if (record->event.pressed) {
241 set_single_persistent_default_layer(_QWERTY);
242 }
243 break;
244 case COLEMAK:
245 if (record->event.pressed) {
246 set_single_persistent_default_layer(_COLEMAK);
247 }
248 break;
249 case DVORAK:
250 if (record->event.pressed) {
251 set_single_persistent_default_layer(_DVORAK);
252 }
253 break;
254 }
255 return true;
103} 256}
diff --git a/keyboards/comet46/keymaps/default/readme.md b/keyboards/comet46/keymaps/default/readme.md
new file mode 100644
index 000000000..b0085d2a6
--- /dev/null
+++ b/keyboards/comet46/keymaps/default/readme.md
@@ -0,0 +1,3 @@
1## default-oled-display
2
3A keymap that is compatible with receivers with an OLED display.
diff --git a/keyboards/comet46/keymaps/default/rules.mk b/keyboards/comet46/keymaps/default/rules.mk
new file mode 100644
index 000000000..3fa01f96a
--- /dev/null
+++ b/keyboards/comet46/keymaps/default/rules.mk
@@ -0,0 +1,5 @@
1# If you want to change display settings of the OLED, you need to change the following lines
2SRC += ./lib/glcdfont.c \
3 ./lib/keylogger.c \
4 ./lib/modifier_state_reader.c \
5 ./lib/host_led_state_reader.c
diff --git a/keyboards/comet46/keymaps/satt/action_pseudo_lut.c b/keyboards/comet46/keymaps/satt/action_pseudo_lut.c
index 5664d4d2a..0ac713359 100644
--- a/keyboards/comet46/keymaps/satt/action_pseudo_lut.c
+++ b/keyboards/comet46/keymaps/satt/action_pseudo_lut.c
@@ -10,133 +10,133 @@ static uint8_t send_key_shift_bit[SHIFT_BIT_SIZE];
10 * Memo: Using other layer keymap to get keycode 10 * Memo: Using other layer keymap to get keycode
11 */ 11 */
12void action_pseudo_lut(keyrecord_t *record, uint8_t base_keymap_id, const uint16_t (*keymap)[2]) { 12void action_pseudo_lut(keyrecord_t *record, uint8_t base_keymap_id, const uint16_t (*keymap)[2]) {
13 uint8_t prev_shift; 13 uint8_t prev_shift;
14 uint16_t keycode; 14 uint16_t keycode;
15 uint16_t pseudo_keycode; 15 uint16_t pseudo_keycode;
16 16
17 /* get keycode from keymap you specified */ 17 /* get keycode from keymap you specified */
18 keycode = keymap_key_to_keycode(base_keymap_id, record->event.key); 18 keycode = keymap_key_to_keycode(base_keymap_id, record->event.key);
19 19
20 prev_shift = keyboard_report->mods & (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)); 20 prev_shift = keyboard_report->mods & (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT));
21 21
22 if (record->event.pressed) { 22 if (record->event.pressed) {
23 /* when magic commands entered, keycode does not converted */ 23 /* when magic commands entered, keycode does not converted */
24 if (IS_COMMAND()) { 24 if (IS_COMMAND()) {
25 if (prev_shift) { 25 if (prev_shift) {
26 add_shift_bit(keycode); 26 add_shift_bit(keycode);
27 } 27 }
28 register_code(keycode); 28 register_code(keycode);
29 return; 29 return;
30 } 30 }
31 31
32 if (prev_shift) { 32 if (prev_shift) {
33 pseudo_keycode = convert_keycode(keymap, keycode, true); 33 pseudo_keycode = convert_keycode(keymap, keycode, true);
34 dprintf("pressed: %02X, converted: %04X\n", keycode, pseudo_keycode); 34 dprintf("pressed: %02X, converted: %04X\n", keycode, pseudo_keycode);
35 add_shift_bit(keycode); 35 add_shift_bit(keycode);
36 36
37 if (IS_LSFT(pseudo_keycode)) { 37 if (IS_LSFT(pseudo_keycode)) {
38 register_code(QK_LSFT ^ pseudo_keycode); 38 register_code(QK_LSFT ^ pseudo_keycode);
39 } else { 39 } else {
40 /* delete shift mod temporarily */ 40 /* delete shift mod temporarily */
41 del_mods(prev_shift); 41 del_mods(prev_shift);
42 send_keyboard_report(); 42 send_keyboard_report();
43 register_code(pseudo_keycode); 43 register_code(pseudo_keycode);
44 add_mods(prev_shift); 44 add_mods(prev_shift);
45 send_keyboard_report(); 45 send_keyboard_report();
46 } 46 }
47 } else { 47 } else {
48 pseudo_keycode = convert_keycode(keymap, keycode, false); 48 pseudo_keycode = convert_keycode(keymap, keycode, false);
49 dprintf("pressed: %02X, converted: %04X\n", keycode, pseudo_keycode); 49 dprintf("pressed: %02X, converted: %04X\n", keycode, pseudo_keycode);
50 50
51 if (IS_LSFT(pseudo_keycode)) { 51 if (IS_LSFT(pseudo_keycode)) {
52 add_weak_mods(MOD_BIT(KC_LSFT)); 52 add_weak_mods(MOD_BIT(KC_LSFT));
53 send_keyboard_report(); 53 send_keyboard_report();
54 register_code(QK_LSFT ^ pseudo_keycode); 54 register_code(QK_LSFT ^ pseudo_keycode);
55 /* on Windows, prevent key repeat to avoid unintended output */ 55 /* on Windows, prevent key repeat to avoid unintended output */
56 unregister_code(QK_LSFT ^ pseudo_keycode); 56 unregister_code(QK_LSFT ^ pseudo_keycode);
57 del_weak_mods(MOD_BIT(KC_LSFT)); 57 del_weak_mods(MOD_BIT(KC_LSFT));
58 send_keyboard_report(); 58 send_keyboard_report();
59 } else { 59 } else {
60 register_code(pseudo_keycode); 60 register_code(pseudo_keycode);
61 } 61 }
62 } 62 }
63 } else {
64 if (get_shift_bit(keycode)) {
65 del_shift_bit(keycode);
66 pseudo_keycode = convert_keycode(keymap, keycode, true);
63 } else { 67 } else {
64 if (get_shift_bit(keycode)) { 68 pseudo_keycode = convert_keycode(keymap, keycode, false);
65 del_shift_bit(keycode); 69 }
66 pseudo_keycode = convert_keycode(keymap, keycode, true); 70 dprintf("released: %02X, converted: %04X\n", keycode, pseudo_keycode);
67 } else {
68 pseudo_keycode = convert_keycode(keymap, keycode, false);
69 }
70 dprintf("released: %02X, converted: %04X\n", keycode, pseudo_keycode);
71 71
72 if (IS_LSFT(pseudo_keycode)) { 72 if (IS_LSFT(pseudo_keycode)) {
73 unregister_code(QK_LSFT ^ pseudo_keycode); 73 unregister_code(QK_LSFT ^ pseudo_keycode);
74 } else { 74 } else {
75 unregister_code(pseudo_keycode); 75 unregister_code(pseudo_keycode);
76 }
77 } 76 }
77 }
78} 78}
79 79
80uint16_t convert_keycode(const uint16_t (*keymap)[2], uint16_t keycode, bool shift_modded) 80uint16_t convert_keycode(const uint16_t (*keymap)[2], uint16_t keycode, bool shift_modded)
81{ 81{
82 uint16_t pseudo_keycode; 82 uint16_t pseudo_keycode;
83 83
84 switch (keycode) { 84 switch (keycode) {
85 case KC_A ... KC_CAPSLOCK: 85 case KC_A ... KC_CAPSLOCK:
86#if defined(__AVR__) 86 #if defined(__AVR__)
87 if (shift_modded) { 87 if (shift_modded) {
88 pseudo_keycode = pgm_read_word(&keymap[keycode][1]); 88 pseudo_keycode = pgm_read_word(&keymap[keycode][1]);
89 } else { 89 } else {
90 pseudo_keycode = pgm_read_word(&keymap[keycode][0]); 90 pseudo_keycode = pgm_read_word(&keymap[keycode][0]);
91 } 91 }
92#else 92 #else
93 if (shift_modded) { 93 if (shift_modded) {
94 pseudo_keycode = keymap[keycode][1]; 94 pseudo_keycode = keymap[keycode][1];
95 } else { 95 } else {
96 pseudo_keycode = keymap[keycode][0]; 96 pseudo_keycode = keymap[keycode][0];
97 } 97 }
98#endif 98 #endif
99 /* if undefined, use got keycode as it is */ 99 /* if undefined, use got keycode as it is */
100 if (pseudo_keycode == 0x00) { 100 if (pseudo_keycode == 0x00) {
101 if (shift_modded) { 101 if (shift_modded) {
102 pseudo_keycode = S(keycode); 102 pseudo_keycode = S(keycode);
103 } else { 103 } else {
104 pseudo_keycode = keycode; 104 pseudo_keycode = keycode;
105 } 105 }
106 } 106 }
107 break; 107 break;
108 default: 108 default:
109 if (shift_modded) { 109 if (shift_modded) {
110 pseudo_keycode = S(keycode); 110 pseudo_keycode = S(keycode);
111 } else { 111 } else {
112 pseudo_keycode = keycode; 112 pseudo_keycode = keycode;
113 } 113 }
114 break; 114 break;
115 } 115 }
116 return pseudo_keycode; 116 return pseudo_keycode;
117} 117}
118 118
119uint8_t get_shift_bit(uint16_t keycode) { 119uint8_t get_shift_bit(uint16_t keycode) {
120 if ((keycode >> 3) < SHIFT_BIT_SIZE) { 120 if ((keycode >> 3) < SHIFT_BIT_SIZE) {
121 return send_key_shift_bit[keycode >> 3] & (1 << (keycode & 7)); 121 return send_key_shift_bit[keycode >> 3] & (1 << (keycode & 7));
122 } else { 122 } else {
123 dprintf("get_shift_bit: Can't get shift bit. keycode: %02X\n", keycode); 123 dprintf("get_shift_bit: Can't get shift bit. keycode: %02X\n", keycode);
124 return 0; 124 return 0;
125 } 125 }
126} 126}
127 127
128void add_shift_bit(uint16_t keycode) { 128void add_shift_bit(uint16_t keycode) {
129 if ((keycode >> 3) < SHIFT_BIT_SIZE) { 129 if ((keycode >> 3) < SHIFT_BIT_SIZE) {
130 send_key_shift_bit[keycode >> 3] |= (1 << (keycode & 7)); 130 send_key_shift_bit[keycode >> 3] |= (1 << (keycode & 7));
131 } else { 131 } else {
132 dprintf("add_shift_bit: Can't add shift bit. keycode: %02X\n", keycode); 132 dprintf("add_shift_bit: Can't add shift bit. keycode: %02X\n", keycode);
133 } 133 }
134} 134}
135 135
136void del_shift_bit(uint16_t keycode) { 136void del_shift_bit(uint16_t keycode) {
137 if ((keycode >> 3) < SHIFT_BIT_SIZE) { 137 if ((keycode >> 3) < SHIFT_BIT_SIZE) {
138 send_key_shift_bit[keycode >> 3] &= ~(1 << (keycode & 7)); 138 send_key_shift_bit[keycode >> 3] &= ~(1 << (keycode & 7));
139 } else { 139 } else {
140 dprintf("del_shift_bit: Can't delete shift bit. keycode: %02X\n", keycode); 140 dprintf("del_shift_bit: Can't delete shift bit. keycode: %02X\n", keycode);
141 } 141 }
142} 142}
diff --git a/keyboards/comet46/keymaps/satt/config.h b/keyboards/comet46/keymaps/satt/config.h
new file mode 100644
index 000000000..c99de2cf8
--- /dev/null
+++ b/keyboards/comet46/keymaps/satt/config.h
@@ -0,0 +1,34 @@
1/*
2This is the c configuration file for the keymap
3
4Copyright 2012 Jun Wako <wakojun@gmail.com>
5Copyright 2015 Jack Humbert
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef CONFIG_USER_H
22#define CONFIG_USER_H
23
24/* key combination for command */
25#define IS_COMMAND() ( \
26 keyboard_report->mods == (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)) \
27)
28
29/* Use I2C or Serial */
30
31#define USE_I2C
32#define SSD1306OLED
33
34#endif
diff --git a/keyboards/comet46/keymaps/satt/keymap.c b/keyboards/comet46/keymaps/satt/keymap.c
index 7e728e5d0..eec40eff4 100644
--- a/keyboards/comet46/keymaps/satt/keymap.c
+++ b/keyboards/comet46/keymaps/satt/keymap.c
@@ -4,64 +4,96 @@
4#include QMK_KEYBOARD_H 4#include QMK_KEYBOARD_H
5#include "keymap_jis2us.h" 5#include "keymap_jis2us.h"
6#include "action_pseudo_lut.h" 6#include "action_pseudo_lut.h"
7#include "keymap_jp.h"
8#ifdef SSD1306OLED
9 #include "ssd1306.h"
10#endif
7 11
8// Each layer gets a name for readability, which is then used in the keymap matrix below. 12// Each layer gets a name for readability, which is then used in the keymap matrix below.
9// The underscores don't mean anything - you can have a layer called STUFF or any other name. 13// The underscores don't mean anything - you can have a layer called STUFF or any other name.
10// Layer names don't all need to be of the same length, obviously, and you can also skip them 14// Layer names don't all need to be of the same length, obviously, and you can also skip them
11// entirely and just use numbers. 15// entirely and just use numbers.
12enum comet46_layers { 16enum comet46_layers {
13 _QWERTY, 17 _QWERTY,
14 _LOWER, 18 _LOWER,
15 _RAISE, 19 _RAISE,
16 _PSEUDO_US, 20 _PSEUDO_US,
17 _PSEUDO_US_LOWER, 21 _PSEUDO_US_LOWER,
18 _PSEUDO_US_RAISE, 22 _PSEUDO_US_RAISE,
19 _ADJUST 23 _ADJUST
20}; 24};
21 25
22enum custom_keycodes { 26enum custom_keycodes {
23 QWERTY = SAFE_RANGE, 27 QWERTY = SAFE_RANGE,
24 PSEUDO_US, 28 PSEUDO_US,
29 JIS2US,
25}; 30};
26 31
27#define KC_LWR MO(_LOWER) 32// JIS keycodes
28#define KC_RSE MO(_RAISE) 33#define KC_JZHT JP_ZHTG // hankaku/zenkaku|kanzi
34#define KC_JCIR JP_CIRC // ^, ~
35#define KC_JAT JP_AT // @, `
36#define KC_JLBR JP_LBRC // [, {
37#define KC_JCOL JP_COLN // :, *
38#define KC_JRBR JP_RBRC // ], }
39#define KC_JBSL JP_BSLS // \, _
40#define KC_JMHE JP_MHEN // muhenkan
41#define KC_JHEN JP_HENK // henkan
42#define KC_JKAN JP_KANA // katakana/hiragana|ro-mazi
43#define KC_JMKA JP_MKANA //kana on MacOSX
44#define KC_JMEI JP_MEISU //eisu on MacOSX
45#define KC_JAMP JP_AMPR // &
46#define KC_JQUO JP_QUOT // '
47#define KC_JLPR JP_LPRN // (
48#define KC_JRPR JP_RPRN // )
49#define KC_JEQL JP_EQL // =
50#define KC_JTIL JP_TILD // ~
51#define KC_JPIP JP_PIPE // |
52#define KC_JGRV JP_GRV // `
53#define KC_JLCB JP_LCBR // {
54#define KC_JPLU JP_PLUS // +
55#define KC_JAST JP_ASTR // *
56#define KC_JRCB JP_RCBR // }
57#define KC_JUND JP_UNDS // _
58
59// Layer related keycodes
60#define KC_LWR MO(_LOWER)
61#define KC_RSE MO(_RAISE)
29#define KC_P_LW MO(_PSEUDO_US_LOWER) 62#define KC_P_LW MO(_PSEUDO_US_LOWER)
30#define KC_P_RS MO(_PSEUDO_US_RAISE) 63#define KC_P_RS MO(_PSEUDO_US_RAISE)
31#define KC_QWRT QWERTY 64#define KC_QWRT QWERTY
32#define KC_P_US PSEUDO_US 65#define KC_P_US PSEUDO_US
66#define KC_J2US JIS2US
67
68// Special keycodes
33#define KC_SPCT CTL_T(KC_SPC) 69#define KC_SPCT CTL_T(KC_SPC)
34#define KC_ENSF SFT_T(KC_ENT) 70#define KC_ENSF SFT_T(KC_ENT)
35#define KC_SFTA SFT_T(KC_A) 71#define KC_CAEC MT(MOD_LCTL | MOD_LALT, KC_ESC)
36#define KC_CTSF S(KC_LCTL) 72#define KC_CSTB C_S_T(KC_TAB)
37#define KC_IMON ALT_T(KC_F13) 73#define KC_IMON ALT_T(KC_F13)
38#define KC_IMOF GUI_T(KC_F14) 74#define KC_IMOF GUI_T(KC_F14)
39#define KC_SRO S(KC_RO)
40#define KC_SYEN S(KC_JYEN)
41#define KC_CAD LCA(KC_DEL) 75#define KC_CAD LCA(KC_DEL)
42#define KC_RST RESET 76#define KC_RST RESET
43 77
44#define LONGPRESS_DELAY 150
45
46// Fillers to make layering more clear 78// Fillers to make layering more clear
47#define KC_ KC_TRNS 79#define KC_ KC_TRNS
48#define KC_XXXX KC_NO 80#define KC_XXXX KC_NO
49 81
50const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 82const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
51 83
52 [_QWERTY] = LAYOUT_kc( 84 [_QWERTY] = LAYOUT_kc(
53 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 85 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
54 ESC , Q , W , E , R , T , Y , U , I , O , P ,DEL , 86 CAEC, Q , W , E , R , T , Y , U , I , O , P ,DEL ,
55 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 87 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
56 TAB ,SFTA, S , D , F , G ,LPRN, RPRN, H , J , K , L ,SCLN,BSPC, 88 CSTB, A , S , D , F , G ,LPRN, RPRN, H , J , K , L ,SCLN,BSPC,
57 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 89 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
58 CTSF, Z , X , C , V , B ,LBRC, RBRC, N , M ,COMM,DOT ,SLSH,QUOT, 90 LSFT, Z , X , C , V , B ,LBRC, RBRC, N , M ,COMM,DOT ,SLSH,QUOT,
59 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 91 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
60 IMOF,LWR ,SPCT, ENSF,RSE ,IMON 92 IMOF,LWR ,SPCT, ENSF,RSE ,IMON
61 // +----+----+---/ \---+----+----+ 93 // +----+----+---/ \---+----+----+
62 ), 94 ),
63 95
64 [_LOWER] = LAYOUT_kc( 96 [_LOWER] = LAYOUT_kc(
65 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 97 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
66 ,EXLM, AT ,HASH,DLR ,PERC, CIRC,AMPR,ASTR,LPRN,RPRN, , 98 ,EXLM, AT ,HASH,DLR ,PERC, CIRC,AMPR,ASTR,LPRN,RPRN, ,
67 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 99 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
@@ -69,60 +101,60 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
69 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 101 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
70 , F7 , F8 , F9 , F10, F11, F12, TILD,PIPE,UNDS,PLUS,LCBR,RCBR, , 102 , F7 , F8 , F9 , F10, F11, F12, TILD,PIPE,UNDS,PLUS,LCBR,RCBR, ,
71 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 103 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
72 , , , , , 104 , , , , ,
73 // +----+----+---/ \---+----+----+ 105 // +----+----+---/ \---+----+----+
74 ), 106 ),
75 107
76 [_RAISE] = LAYOUT_kc( 108 [_RAISE] = LAYOUT_kc(
77 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 109 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
78 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , , 110 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , ,
79 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 111 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
80 , , , , , , , XXXX,LEFT,DOWN, UP ,RGHT,END , , 112 , , , , , , , XXXX,LEFT,DOWN, UP ,RGHT,END , ,
81 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 113 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
82 , , , , , , , HOME,XXXX,XXXX,XXXX,XXXX,XXXX, , 114 , , , , , , , HOME,XXXX,PGDN,PGUP,XXXX,XXXX, ,
83 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 115 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
84 , , , , , 116 , , , , ,
85 // +----+----+---/ \---+----+----+ 117 // +----+----+---/ \---+----+----+
86 ), 118 ),
87 119
88 [_PSEUDO_US] = LAYOUT_kc( 120 [_PSEUDO_US] = LAYOUT_kc(
89 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 121 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
90 ESC , Q , W , E , R , T , Y , U , I , O , P ,DEL , 122 CAEC, Q , W , E , R , T , Y , U , I , O , P ,DEL ,
91 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 123 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
92 TAB ,SFTA, S , D , F , G ,ASTR, LPRN, H , J , K , L ,FN0 ,BSPC, 124 CSTB, A , S , D , F , G ,JLPR, JRPR, H , J , K , L ,J2US,BSPC,
93 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 125 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
94 CTSF, Z , X , C , V , B ,FN0 , FN0 , N , M ,COMM,DOT ,SLSH,FN0 , 126 LSFT, Z , X , C , V , B ,J2US, J2US, N , M ,COMM,DOT ,SLSH,J2US,
95 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 127 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
96 IMOF,P_LW,SPCT, ENSF,P_RS,IMON 128 IMOF,P_LW,SPCT, ENSF,P_RS,IMON
97 // +----+----+---/ \---+----+----+ 129 // +----+----+---/ \---+----+----+
98 ), 130 ),
99 131
100 132
101 [_PSEUDO_US_LOWER] = LAYOUT_kc( 133 [_PSEUDO_US_LOWER] = LAYOUT_kc(
102 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 134 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
103 ,EXLM,LBRC,HASH,DLR ,PERC, EQL ,CIRC, DQT,ASTR,LPRN, , 135 ,EXLM,JAT ,HASH,DLR ,PERC, JCIR,JAMP,JAST,JLPR,JRPR, ,
104 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 136 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
105 , F1 , F2 , F3 , F4 , F5 , F6 , LCBR,JYEN,MINS,UNDS,RBRC,BSLS, , 137 , F1 , F2 , F3 , F4 , F5 , F6 , JGRV,JBSL,MINS,JEQL,JLBR,JRBR, ,
106 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 138 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
107 , F7 , F8 , F9 , F10, F11, F12, PLUS,SYEN,SRO ,COLN,RCBR,PIPE, , 139 , F7 , F8 , F9 , F10, F11, F12, JTIL,JPIP,JUND,JPLU,JLCB,JRCB, ,
108 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 140 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
109 , , , , , 141 , , , , ,
110 // +----+----+---/ \---+----+----+ 142 // +----+----+---/ \---+----+----+
111 ), 143 ),
112 144
113 [_PSEUDO_US_RAISE] = LAYOUT_kc( 145 [_PSEUDO_US_RAISE] = LAYOUT_kc(
114 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 146 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
115 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , , 147 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , ,
116 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 148 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
117 , , , , , , GRV, XXXX,LEFT,DOWN, UP ,RGHT,END , , 149 , , , , , ,JZHT, XXXX,LEFT,DOWN, UP ,RGHT,END , ,
118 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 150 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
119 , , , , , , , HOME,XXXX,XXXX,XXXX,XXXX,XXXX, , 151 , , , , , , , HOME,XXXX,PGDN,PGUP,XXXX,XXXX, ,
120 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 152 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
121 , , , , , 153 , , , , ,
122 // +----+----+---/ \---+----+----+ 154 // +----+----+---/ \---+----+----+
123 ), 155 ),
124 156
125 [_ADJUST] = LAYOUT_kc( 157 [_ADJUST] = LAYOUT_kc(
126 //,----+----+----+----+----+----+ +----+----+----+----+----+----. 158 //,----+----+----+----+----+----+ +----+----+----+----+----+----.
127 , , , , , , , , , , , , 159 , , , , , , , , , , , ,
128 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----| 160 //|----+----+----+----+----+----+----+ +----+----+----+----+----+----+----|
@@ -130,90 +162,130 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
130 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 162 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
131 , , , , , ,RST , P_US, , , , , , , 163 , , , , , ,RST , P_US, , , , , , ,
132 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| 164 //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
133 , , , , , 165 , , , , ,
134 // +----+----+---/ \---+----+----+ 166 // +----+----+---/ \---+----+----+
135 ) 167 )
136 168
137}; 169};
138 170
171uint32_t layer_state_set_user(uint32_t state) {
172 switch (biton32(state)) {
173 case _PSEUDO_US_LOWER:
174 case _PSEUDO_US_RAISE:
175 return update_tri_layer_state(state, _PSEUDO_US_RAISE, _PSEUDO_US_LOWER, _ADJUST);
176 break;
177 default:
178 return update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
179 break;
180 }
181}
139 182
140/* 183//SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
141 * user defined action function 184#ifdef SSD1306OLED
142 */
143enum function_id {
144 PSEUDO_US_FUNCTION,
145};
146 185
147void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { 186// You need to add source files to SRC in rules.mk when using OLED display functions
148 switch (id) 187void set_keylog(uint16_t keycode);
149 { 188const char *read_keylog(void);
150 case PSEUDO_US_FUNCTION: 189const char *read_modifier_state(void);
151 action_pseudo_lut(record, _QWERTY, keymap_jis2us); 190const char *read_host_led_state(void);
152 break;
153 }
154}
155 191
156/* 192void matrix_init_user(void) {
157 * Fn action definition 193 iota_gfx_init(false); // turns on the display
158 */ 194}
159const uint16_t PROGMEM fn_actions[] = {
160 [0] = ACTION_FUNCTION(PSEUDO_US_FUNCTION),
161};
162 195
163void matrix_scan_user(void) { 196void matrix_scan_user(void) {
164 uint8_t layer = biton32(layer_state); 197 iota_gfx_task(); // this is what updates the display continuously
198}
199
200void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
201 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
202 memcpy(dest->display, source->display, sizeof(dest->display));
203 dest->dirty = true;
204 }
205}
206
207void render_status(struct CharacterMatrix *matrix) {
208 // Layer state
209 char layer_str[22];
210 matrix_write(matrix, "Layer: ");
211 uint8_t layer = biton32(layer_state);
212 uint8_t default_layer = biton32(eeconfig_read_default_layer());
165 switch (layer) { 213 switch (layer) {
166 case _LOWER: 214 case _QWERTY:
167 set_led_red; 215 switch (default_layer) {
168 break; 216 case _QWERTY:
217 snprintf(layer_str, sizeof(layer_str), "Qwerty");
218 break;
219 case _PSEUDO_US:
220 snprintf(layer_str, sizeof(layer_str), "Psuedo_US");
221 break;
222 default:
223 snprintf(layer_str, sizeof(layer_str), "Undef-%d", default_layer);
224 break;
225 }
226 break;
169 case _RAISE: 227 case _RAISE:
170 set_led_blue; 228 snprintf(layer_str, sizeof(layer_str), "Raise");
171 break; 229 break;
172 case _PSEUDO_US_LOWER: 230 case _LOWER:
173 set_led_yellow; 231 snprintf(layer_str, sizeof(layer_str), "Lower");
174 break; 232 break;
175 case _PSEUDO_US_RAISE: 233 case _PSEUDO_US_RAISE:
176 set_led_cyan; 234 snprintf(layer_str, sizeof(layer_str), "P_US_Raise");
177 break; 235 break;
236 case _PSEUDO_US_LOWER:
237 snprintf(layer_str, sizeof(layer_str), "P_US_Lower");
238 break;
178 case _ADJUST: 239 case _ADJUST:
179 set_led_magenta; 240 snprintf(layer_str, sizeof(layer_str), "Adjust");
180 break; 241 break;
181 default: 242 default:
182 set_led_green; 243 snprintf(layer_str, sizeof(layer_str), "Undef-%d", layer);
183 break;
184 } 244 }
185}; 245 matrix_write_ln(matrix, layer_str);
246 // Last entered keycode
247 matrix_write_ln(matrix, read_keylog());
248 // Modifier state
249 matrix_write_ln(matrix, read_modifier_state());
250 // Host Keyboard LED Status
251 matrix_write(matrix, read_host_led_state());
252}
186 253
187uint32_t layer_state_set_user(uint32_t state) { 254void iota_gfx_task_user(void) {
188 switch (biton32(state)) { 255 struct CharacterMatrix matrix;
189 case _PSEUDO_US: 256
190 return update_tri_layer_state(state, _PSEUDO_US_RAISE, _PSEUDO_US_LOWER, _ADJUST); 257#if DEBUG_TO_SCREEN
191 break; 258 if (debug_enable) {
192 case _PSEUDO_US_LOWER: 259 return;
193 return update_tri_layer_state(state, _PSEUDO_US_RAISE, _PSEUDO_US_LOWER, _ADJUST);
194 break;
195 case _PSEUDO_US_RAISE:
196 return update_tri_layer_state(state, _PSEUDO_US_RAISE, _PSEUDO_US_LOWER, _ADJUST);
197 break;
198 default:
199 return update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
200 break;
201 } 260 }
261#endif
262
263 matrix_clear(&matrix);
264 render_status(&matrix);
265 matrix_update(&display, &matrix);
202} 266}
203 267
268#endif//SSD1306OLED
269
204bool process_record_user(uint16_t keycode, keyrecord_t *record) { 270bool process_record_user(uint16_t keycode, keyrecord_t *record) {
271 #ifdef SSD1306OLED
272 if (record->event.pressed) {
273 set_keylog(keycode);
274 }
275 #endif
205 switch (keycode) { 276 switch (keycode) {
206 case QWERTY: 277 case QWERTY:
207 if (record->event.pressed) { 278 if (record->event.pressed) {
208 set_single_persistent_default_layer(_QWERTY); 279 set_single_persistent_default_layer(_QWERTY);
209 } 280 }
210 return false;
211 break; 281 break;
212 case PSEUDO_US: 282 case PSEUDO_US:
213 if (record->event.pressed) { 283 if (record->event.pressed) {
214 set_single_persistent_default_layer(_PSEUDO_US); 284 set_single_persistent_default_layer(_PSEUDO_US);
215 } 285 }
216 return false; 286 break;
287 case JIS2US:
288 action_pseudo_lut(record, _QWERTY, keymap_jis2us);
217 break; 289 break;
218 } 290 }
219 return true; 291 return true;
diff --git a/keyboards/comet46/keymaps/satt/keymap_jis2us.h b/keyboards/comet46/keymaps/satt/keymap_jis2us.h
index cf2bd4f0e..e32a0579a 100644
--- a/keyboards/comet46/keymaps/satt/keymap_jis2us.h
+++ b/keyboards/comet46/keymaps/satt/keymap_jis2us.h
@@ -3,30 +3,30 @@
3 3
4/* keymap for convert from JIS to US */ 4/* keymap for convert from JIS to US */
5const uint16_t PROGMEM keymap_jis2us[][2] = { 5const uint16_t PROGMEM keymap_jis2us[][2] = {
6 [KC_A ... KC_CAPS] = { 0x00, 0x00 }, /* default value */ 6 [KC_A ... KC_CAPS] = { 0x00, 0x00 }, /* default value */
7 7
8 [KC_1] = { KC_1, KC_EXLM }, /* 1 and ! -> 1 and ! */ 8 [KC_1] = { KC_1, KC_EXLM }, /* 1 and ! -> 1 and ! */
9 [KC_2] = { KC_2, KC_LBRC }, /* 2 and " -> 2 and @ */ 9 [KC_2] = { KC_2, KC_LBRC }, /* 2 and " -> 2 and @ */
10 [KC_3] = { KC_3, KC_HASH }, /* 3 and # -> 3 and # */ 10 [KC_3] = { KC_3, KC_HASH }, /* 3 and # -> 3 and # */
11 [KC_4] = { KC_4, KC_DLR }, /* 4 and $ -> 4 and $ */ 11 [KC_4] = { KC_4, KC_DLR }, /* 4 and $ -> 4 and $ */
12 [KC_5] = { KC_5, KC_PERC }, /* 5 and % -> 5 and % */ 12 [KC_5] = { KC_5, KC_PERC }, /* 5 and % -> 5 and % */
13 [KC_6] = { KC_6, KC_EQL }, /* 6 and & -> 6 and ^ */ 13 [KC_6] = { KC_6, KC_EQL }, /* 6 and & -> 6 and ^ */
14 [KC_7] = { KC_7, KC_CIRC }, /* 7 and ' -> 7 and & */ 14 [KC_7] = { KC_7, KC_CIRC }, /* 7 and ' -> 7 and & */
15 [KC_8] = { KC_8, KC_DQT }, /* 8 and ( -> 8 and * */ 15 [KC_8] = { KC_8, KC_DQT }, /* 8 and ( -> 8 and * */
16 [KC_9] = { KC_9, KC_ASTR }, /* 9 and ) -> 9 and ( */ 16 [KC_9] = { KC_9, KC_ASTR }, /* 9 and ) -> 9 and ( */
17 [KC_0] = { KC_0, KC_LPRN }, /* 0 and (no assign) -> 0 and ) */ 17 [KC_0] = { KC_0, KC_LPRN }, /* 0 and (no assign) -> 0 and ) */
18 [KC_MINS] = { KC_MINS, S(KC_RO) }, /* - and = -> - and _ */ 18 [KC_MINS] = { KC_MINS, S(KC_RO) }, /* - and = -> - and _ */
19 [KC_EQL] = { KC_UNDS, KC_COLN }, /* ^ and ~ -> = and + */ 19 [KC_EQL] = { KC_UNDS, KC_COLN }, /* ^ and ~ -> = and + */
20 [KC_LBRC] = { KC_RBRC, KC_RCBR }, /* @ and ` -> [ and { */ 20 [KC_LBRC] = { KC_RBRC, KC_RCBR }, /* @ and ` -> [ and { */
21 [KC_RBRC] = { KC_BSLS, KC_PIPE }, /* [ and { -> ] and } */ 21 [KC_RBRC] = { KC_BSLS, KC_PIPE }, /* [ and { -> ] and } */
22 [KC_BSLS] = { KC_JYEN, S(KC_JYEN) }, /* ] and } -> / and | */ 22 [KC_BSLS] = { KC_JYEN, S(KC_JYEN) }, /* ] and } -> / and | */
23 [KC_NUHS] = { KC_NUHS, S(KC_NUHS) }, /* (no assign) */ 23 [KC_NUHS] = { KC_NUHS, S(KC_NUHS) }, /* (no assign) */
24 [KC_SCLN] = { KC_SCLN, KC_QUOT }, /* ; and + -> ; and : */ 24 [KC_SCLN] = { KC_SCLN, KC_QUOT }, /* ; and + -> ; and : */
25 [KC_QUOT] = { KC_AMPR, KC_AT }, /* : and * -> ' and " */ 25 [KC_QUOT] = { KC_AMPR, KC_AT }, /* : and * -> ' and " */
26 [KC_GRV] = { KC_LCBR, KC_PLUS }, /* (no assign) -> ` and ~ */ 26 [KC_GRV] = { KC_LCBR, KC_PLUS }, /* (no assign) -> ` and ~ */
27 [KC_COMM] = { KC_COMM, KC_LT }, /* , and < -> , and < */ 27 [KC_COMM] = { KC_COMM, KC_LT }, /* , and < -> , and < */
28 [KC_DOT] = { KC_DOT, KC_GT }, /* . and > -> . and > */ 28 [KC_DOT] = { KC_DOT, KC_GT }, /* . and > -> . and > */
29 [KC_SLSH] = { KC_SLSH, KC_QUES }, /* / and ? -> / and ? */ 29 [KC_SLSH] = { KC_SLSH, KC_QUES }, /* / and ? -> / and ? */
30}; 30};
31 31
32#endif 32#endif
diff --git a/keyboards/comet46/keymaps/satt/rules.mk b/keyboards/comet46/keymaps/satt/rules.mk
index dc4355c78..5839b778b 100644
--- a/keyboards/comet46/keymaps/satt/rules.mk
+++ b/keyboards/comet46/keymaps/satt/rules.mk
@@ -1,26 +1,7 @@
1SRC += action_pseudo_lut.c 1SRC += action_pseudo_lut.c
2 2
3# Build Options 3# If you want to change display settings of the OLED, you need to change the following lines
4# change to "no" to disable the options, or define them in the Makefile in 4SRC += ./lib/glcdfont.c \
5# the appropriate keymap folder that will get included automatically 5 ./lib/keylogger.c \
6# 6 ./lib/modifier_state_reader.c \
7BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) 7 ./lib/host_led_state_reader.c
8MOUSEKEY_ENABLE = no # Mouse keys(+4700)
9EXTRAKEY_ENABLE = no # Audio control and System control(+450)
10CONSOLE_ENABLE = no # Console for debug(+400)
11COMMAND_ENABLE = no # Commands for debug and configuration
12NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
13BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
14MIDI_ENABLE = no # MIDI controls
15AUDIO_ENABLE = no # Audio output on port C6
16UNICODE_ENABLE = no # Unicode
17BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
18RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight.
19ONEHAND_ENABLE = no # Enable one-hand typing
20
21# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
22SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
23
24ifndef QUANTUM_DIR
25 include ../../../../Makefile
26endif
diff --git a/keyboards/comet46/lib/glcdfont.c b/keyboards/comet46/lib/glcdfont.c
new file mode 100644
index 000000000..e912d2233
--- /dev/null
+++ b/keyboards/comet46/lib/glcdfont.c
@@ -0,0 +1,148 @@
1// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
2// See gfxfont.h for newer custom bitmap font info.
3
4#ifndef FONT5X7_H
5#define FONT5X7_H
6
7#ifdef __AVR__
8 #include <avr/io.h>
9 #include <avr/pgmspace.h>
10#elif defined(ESP8266)
11 #include <pgmspace.h>
12#else
13 #define PROGMEM
14#endif
15
16// Standard ASCII 5x7 font
17
18const unsigned char font[] PROGMEM = {
19 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00,
21 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00,
22 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00,
23 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00,
24 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00,
25 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00,
26 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00,
27 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00,
28 0x00, 0x18, 0x24, 0x18, 0x00, 0x00,
29 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00,
30 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00,
31 0x26, 0x29, 0x79, 0x29, 0x26, 0x00,
32 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00,
33 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00,
34 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00,
35 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00,
36 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00,
37 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00,
38 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00,
39 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00,
40 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00,
41 0x60, 0x60, 0x60, 0x60, 0x60, 0x00,
42 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00,
43 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00,
44 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00,
45 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00,
46 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00,
47 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00,
48 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00,
49 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00,
50 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00,
53 0x00, 0x07, 0x00, 0x07, 0x00, 0x00,
54 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00,
55 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00,
56 0x23, 0x13, 0x08, 0x64, 0x62, 0x00,
57 0x36, 0x49, 0x56, 0x20, 0x50, 0x00,
58 0x00, 0x08, 0x07, 0x03, 0x00, 0x00,
59 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00,
60 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00,
61 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00,
62 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00,
63 0x00, 0x80, 0x70, 0x30, 0x00, 0x00,
64 0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
65 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,
66 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
67 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00,
68 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00,
69 0x72, 0x49, 0x49, 0x49, 0x46, 0x00,
70 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00,
71 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00,
72 0x27, 0x45, 0x45, 0x45, 0x39, 0x00,
73 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00,
74 0x41, 0x21, 0x11, 0x09, 0x07, 0x00,
75 0x36, 0x49, 0x49, 0x49, 0x36, 0x00,
76 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00,
77 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
78 0x00, 0x40, 0x34, 0x00, 0x00, 0x00,
79 0x00, 0x08, 0x14, 0x22, 0x41, 0x00,
80 0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
81 0x00, 0x41, 0x22, 0x14, 0x08, 0x00,
82 0x02, 0x01, 0x59, 0x09, 0x06, 0x00,
83 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00,
84 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00,
85 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00,
86 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00,
87 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00,
88 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00,
89 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00,
90 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00,
91 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00,
92 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00,
93 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00,
94 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00,
95 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00,
96 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00,
97 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00,
98 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00,
99 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00,
100 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00,
101 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00,
102 0x26, 0x49, 0x49, 0x49, 0x32, 0x00,
103 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00,
104 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00,
105 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00,
106 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00,
107 0x63, 0x14, 0x08, 0x14, 0x63, 0x00,
108 0x03, 0x04, 0x78, 0x04, 0x03, 0x00,
109 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00,
110 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00,
111 0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
112 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00,
113 0x04, 0x02, 0x01, 0x02, 0x04, 0x00,
114 0x40, 0x40, 0x40, 0x40, 0x40, 0x00,
115 0x00, 0x03, 0x07, 0x08, 0x00, 0x00,
116 0x20, 0x54, 0x54, 0x78, 0x40, 0x00,
117 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00,
118 0x38, 0x44, 0x44, 0x44, 0x28, 0x00,
119 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00,
120 0x38, 0x54, 0x54, 0x54, 0x18, 0x00,
121 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00,
122 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00,
123 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00,
124 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00,
125 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00,
126 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00,
127 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00,
128 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00,
129 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00,
130 0x38, 0x44, 0x44, 0x44, 0x38, 0x00,
131 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00,
132 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00,
133 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00,
134 0x48, 0x54, 0x54, 0x54, 0x24, 0x00,
135 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00,
136 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00,
137 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00,
138 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00,
139 0x44, 0x28, 0x10, 0x28, 0x44, 0x00,
140 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00,
141 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00,
142 0x00, 0x08, 0x36, 0x41, 0x00, 0x00,
143 0x00, 0x00, 0x77, 0x00, 0x00, 0x00,
144 0x00, 0x41, 0x36, 0x08, 0x00, 0x00,
145 0x02, 0x01, 0x02, 0x04, 0x02, 0x00,
146 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00
147};
148#endif // FONT5X7_H
diff --git a/keyboards/comet46/lib/host_led_state_reader.c b/keyboards/comet46/lib/host_led_state_reader.c
new file mode 100644
index 000000000..864b1e244
--- /dev/null
+++ b/keyboards/comet46/lib/host_led_state_reader.c
@@ -0,0 +1,15 @@
1#include <stdio.h>
2#include "comet46.h"
3
4char host_led_state_str[22];
5
6const char *read_host_led_state(void) {
7 uint8_t leds = host_keyboard_leds();
8
9 snprintf(host_led_state_str, sizeof(host_led_state_str), "Lock: %s%s%s",
10 (leds & (1 << USB_LED_CAPS_LOCK)) ? "CAPL " : "",
11 (leds & (1 << USB_LED_SCROLL_LOCK)) ? "SCRL " : "",
12 (leds & (1 << USB_LED_NUM_LOCK)) ? "NUML" : "");
13
14 return host_led_state_str;
15}
diff --git a/keyboards/comet46/lib/keylogger.c b/keyboards/comet46/lib/keylogger.c
new file mode 100644
index 000000000..184f60109
--- /dev/null
+++ b/keyboards/comet46/lib/keylogger.c
@@ -0,0 +1,294 @@
1#include <stdio.h>
2
3#ifdef __AVR__
4 #include <avr/io.h>
5 #include <avr/pgmspace.h>
6#else
7 #define PROGMEM
8#endif
9
10#define NUM_USB_HID_KEYCODES 255
11#define LEN_KEYCODE_STR 4
12
13char keylog[22] = {"KC: ID: "};
14
15// Quick and dirty way to display USB HID keycodes used in QMK
16// USB HID keycodes from 0x0000 to 0x00FF are stored in a 4x256+1 length char
17const char code_to_name[] PROGMEM = {
18 "NO " //0x00
19 "TRNS"
20 "? "
21 "? "
22 "A "
23 "B "
24 "C "
25 "D "
26 "E "
27 "F "
28 "G "
29 "H "
30 "I "
31 "J "
32 "K "
33 "L "
34 "M " //0x10
35 "N "
36 "O "
37 "P "
38 "Q "
39 "R "
40 "S "
41 "T "
42 "U "
43 "V "
44 "W "
45 "X "
46 "Y "
47 "Z "
48 "1 "
49 "2 "
50 "3 " //0x20
51 "4 "
52 "5 "
53 "6 "
54 "7 "
55 "8 "
56 "9 "
57 "0 "
58 "ENT "
59 "ESC "
60 "BSPC"
61 "TAB "
62 "SPC "
63 "MINS"
64 "EQL "
65 "LBRC"
66 "RBRC" //0x30
67 "BSLS"
68 "NUHS"
69 "SCLN"
70 "QUOT"
71 "GRV "
72 "COMM"
73 "DOT "
74 "SLSH"
75 "CAPS"
76 "F1 "
77 "F2 "
78 "F3 "
79 "F4 "
80 "F5 "
81 "F6 "
82 "F7 " //0x40
83 "F8 "
84 "F9 "
85 "F10 "
86 "F11 "
87 "F12 "
88 "PSCR"
89 "SLCK"
90 "PAUS"
91 "INS "
92 "HOME"
93 "PGUP"
94 "DEL "
95 "END "
96 "PGDN"
97 "RGHT"
98 "LEFT" //0x50
99 "DOWN"
100 "UP "
101 "NLCK"
102 "PSLS"
103 "PAST"
104 "PMNS"
105 "PPLS"
106 "PENT"
107 "P1 "
108 "P2 "
109 "P3 "
110 "P4 "
111 "P5 "
112 "P6 "
113 "P7 "
114 "P8 " //0x60
115 "P9 "
116 "P0 "
117 "PDOT"
118 "NUBS"
119 "APP "
120 "POW "
121 "PEQL"
122 "F13 "
123 "F14 "
124 "F15 "
125 "F16 "
126 "F17 "
127 "F18 "
128 "F19 "
129 "F20 "
130 "F21 " //0x70
131 "F22 "
132 "F23 "
133 "F24 "
134 "EXEC"
135 "HELP"
136 "MENU"
137 "SLCT"
138 "STOP"
139 "AGIN"
140 "UNDO"
141 "CUT "
142 "COPY"
143 "PSTE"
144 "FIND"
145 "_MUT"
146 "_VUP" //0x80
147 "_VDN"
148 "LCAP"
149 "LNUM"
150 "LSCR"
151 "PCMM"
152 "PEQA"
153 "INT1"
154 "INT2"
155 "INT3"
156 "INT4"
157 "INT5"
158 "INT6"
159 "INT7"
160 "INT8"
161 "INT9"
162 "LAN1" //0x90
163 "LAN2"
164 "LAN3"
165 "LAN4"
166 "LAN5"
167 "LAN6"
168 "LAN7"
169 "LAN8"
170 "LAN9"
171 "ERAS"
172 "SYSR"
173 "CNCL"
174 "CLR "
175 "PRIR"
176 "RTRN"
177 "SEP "
178 "OUT " //0xA0
179 "OPER"
180 "CLRA"
181 "CSEL"
182 "ESEL"
183 "PWR " //0xA5
184 "SLEP"
185 "WAKE"
186 "MUTE"
187 "VOLU"
188 "VOLD"
189 "MNXT"
190 "MPRV"
191 "MSTP"
192 "MPLY"
193 "MSEL"
194 "EJCT" //0xB0
195 "MAIL"
196 "CALC"
197 "MYCM"
198 "WSCH"
199 "WHOM"
200 "WBAK"
201 "WFWD"
202 "WSTP"
203 "WREF"
204 "WFAV"
205 "MFFD"
206 "MRWD"
207 "BRIU"
208 "BRID"
209 "? "
210 "FN0 " //0xC0
211 "FN1 "
212 "FN2 "
213 "FN3 "
214 "FN4 "
215 "FN5 "
216 "FN6 "
217 "FN7 "
218 "FN8 "
219 "FN9 "
220 "FN10"
221 "FN11"
222 "FN12"
223 "FN13"
224 "FN14"
225 "FN15"
226 "FN16" //0xD0
227 "FN17"
228 "FN18"
229 "FN19"
230 "FN20"
231 "FN21"
232 "FN22"
233 "FN23"
234 "FN24"
235 "FN25"
236 "FN26"
237 "FN27"
238 "FN28"
239 "FN29"
240 "FN30"
241 "FN31"
242 "LCTL" //0xE0
243 "LSFT"
244 "LALT"
245 "LGUI"
246 "RCTL"
247 "RSFT"
248 "RALT"
249 "RGUI"
250 "? "
251 "? "
252 "? "
253 "? "
254 "? "
255 "? "
256 "? "
257 "? "
258 "MS_U" //0xF0
259 "MS_D"
260 "MS_L"
261 "MS_R"
262 "BTN1"
263 "BTN2"
264 "BTN3"
265 "BTN4"
266 "BTN5"
267 "WH_U"
268 "WH_D"
269 "WH_L"
270 "WH_R"
271 "ACL0"
272 "ACL1"
273 "ACL2"
274};
275
276void set_keylog(uint16_t keycode)
277{
278 char name[LEN_KEYCODE_STR+1] = "? ";
279
280 if (keycode <= NUM_USB_HID_KEYCODES) {
281 for (uint8_t k = 0; k < LEN_KEYCODE_STR; k++) {
282 name[k] = pgm_read_byte_near(code_to_name + keycode * LEN_KEYCODE_STR + k);
283 }
284 } else if (keycode > NUM_USB_HID_KEYCODES) {
285 snprintf(name, sizeof(name), "QMK ");
286 }
287
288 // update keylog
289 snprintf(keylog, sizeof(keylog), "KC: %s ID: %d", name, keycode);
290}
291
292const char *read_keylog(void) {
293 return keylog;
294}
diff --git a/keyboards/comet46/lib/modifier_state_reader.c b/keyboards/comet46/lib/modifier_state_reader.c
new file mode 100644
index 000000000..518eef92a
--- /dev/null
+++ b/keyboards/comet46/lib/modifier_state_reader.c
@@ -0,0 +1,18 @@
1#include <stdio.h>
2#include "comet46.h"
3
4char modifier_state_str[22];
5
6const char *read_modifier_state(void) {
7 uint8_t modifiers = get_mods();
8 uint8_t one_shot = get_oneshot_mods();
9
10 snprintf(modifier_state_str, sizeof(modifier_state_str), "Mod: %s%s%s%s",
11 (modifiers & MODS_CTRL_MASK || one_shot & MODS_CTRL_MASK) ? "CTL " : "",
12 (modifiers & MODS_GUI_MASK || one_shot & MODS_GUI_MASK) ? "GUI " : "",
13 (modifiers & MODS_ALT_MASK || one_shot & MODS_ALT_MASK) ? "ALT " : "",
14 (modifiers & MODS_SHIFT_MASK || one_shot & MODS_SHIFT_MASK) ? "SFT" : ""
15 );
16
17 return modifier_state_str;
18}
diff --git a/keyboards/comet46/readme.md b/keyboards/comet46/readme.md
index 8df27183d..3db64d291 100644
--- a/keyboards/comet46/readme.md
+++ b/keyboards/comet46/readme.md
@@ -1,6 +1,6 @@
1# Comet46 1# Comet46
2 2
3![Comet46](https://user-images.githubusercontent.com/39004890/42418180-d5bb188c-82d5-11e8-99fa-65020ce5ac5d.jpg) 3![Comet46](https://user-images.githubusercontent.com/39004890/50396817-a1660600-07af-11e9-8611-3156c635db43.jpg)
4 4
5A split wireless 40% column-staggered keyboard 5A split wireless 40% column-staggered keyboard
6 6
@@ -13,4 +13,5 @@ Make example for this keyboard (after setting up your build environment):
13 13
14 make comet46:default 14 make comet46:default
15 15
16See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information. 16See [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.
17
diff --git a/keyboards/comet46/rules.mk b/keyboards/comet46/rules.mk
index 648b8b200..897cc9b8c 100644
--- a/keyboards/comet46/rules.mk
+++ b/keyboards/comet46/rules.mk
@@ -1,12 +1,8 @@
1
2OPT_DEFS += -DCOMET46_ORTHO_===PROMICRO
3COMET46_UPLOAD_COMMAND = while [ ! -r $(USB) ]; do sleep 1; done; \
4 avrdude -p $(MCU) -c avr109 -U flash:w:$(TARGET).hex -P $(USB)
5
6# # project specific files 1# # project specific files
7SRC = matrix.c 2SRC += matrix.c \
8 3 i2c.c \
9 4 ssd1306.c
5
10# MCU name 6# MCU name
11#MCU = at90usb1287 7#MCU = at90usb1287
12MCU = atmega32u4 8MCU = atmega32u4
@@ -24,8 +20,6 @@ MCU = atmega32u4
24# software delays. 20# software delays.
25F_CPU = 16000000 21F_CPU = 16000000
26 22
27
28#
29# LUFA specific 23# LUFA specific
30# 24#
31# Target architecture (see library "Board Types" documentation). 25# Target architecture (see library "Board Types" documentation).
@@ -48,7 +42,7 @@ F_USB = $(F_CPU)
48# This definition is optional, and if your keyboard supports multiple bootloaders of 42# This definition is optional, and if your keyboard supports multiple bootloaders of
49# different sizes, comment this out, and the correct address will be loaded 43# different sizes, comment this out, and the correct address will be loaded
50# automatically (+60). See bootloader.mk for all options. 44# automatically (+60). See bootloader.mk for all options.
51BOOTLOADER = caterina 45# BOOTLOADER = caterina
52 46
53# Interrupt driven control endpoint task(+60) 47# Interrupt driven control endpoint task(+60)
54OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT 48OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
diff --git a/keyboards/comet46/ssd1306.c b/keyboards/comet46/ssd1306.c
new file mode 100644
index 000000000..4330c8497
--- /dev/null
+++ b/keyboards/comet46/ssd1306.c
@@ -0,0 +1,344 @@
1#ifdef SSD1306OLED
2
3#include "ssd1306.h"
4#include "i2c.h"
5#include <string.h>
6#include "print.h"
7#ifdef ADAFRUIT_BLE_ENABLE
8#include "adafruit_ble.h"
9#endif
10#ifdef PROTOCOL_LUFA
11#include "lufa.h"
12#endif
13#include "sendchar.h"
14#include "timer.h"
15
16static const unsigned char font[] PROGMEM;
17
18// Set this to 1 to help diagnose early startup problems
19// when testing power-on with ble. Turn it off otherwise,
20// as the latency of printing most of the debug info messes
21// with the matrix scan, causing keys to drop.
22#define DEBUG_TO_SCREEN 0
23
24//static uint16_t last_battery_update;
25//static uint32_t vbat;
26//#define BatteryUpdateInterval 10000 /* milliseconds */
27
28// 'last_flush' is declared as uint16_t,
29// so this must be less than 65535
30#define ScreenOffInterval 60000 /* milliseconds */
31#if DEBUG_TO_SCREEN
32static uint8_t displaying;
33#endif
34static uint16_t last_flush;
35
36static bool force_dirty = true;
37
38// Write command sequence.
39// Returns true on success.
40static inline bool _send_cmd1(uint8_t cmd) {
41 bool res = false;
42
43 if (i2c_start_write(SSD1306_ADDRESS)) {
44 xprintf("failed to start write to %d\n", SSD1306_ADDRESS);
45 goto done;
46 }
47
48 if (i2c_master_write(0x0 /* command byte follows */)) {
49 print("failed to write control byte\n");
50
51 goto done;
52 }
53
54 if (i2c_master_write(cmd)) {
55 xprintf("failed to write command %d\n", cmd);
56 goto done;
57 }
58 res = true;
59done:
60 i2c_master_stop();
61 return res;
62}
63
64// Write 2-byte command sequence.
65// Returns true on success
66static inline bool _send_cmd2(uint8_t cmd, uint8_t opr) {
67 if (!_send_cmd1(cmd)) {
68 return false;
69 }
70 return _send_cmd1(opr);
71}
72
73// Write 3-byte command sequence.
74// Returns true on success
75static inline bool _send_cmd3(uint8_t cmd, uint8_t opr1, uint8_t opr2) {
76 if (!_send_cmd1(cmd)) {
77 return false;
78 }
79 if (!_send_cmd1(opr1)) {
80 return false;
81 }
82 return _send_cmd1(opr2);
83}
84
85#define send_cmd1(c) if (!_send_cmd1(c)) {goto done;}
86#define send_cmd2(c,o) if (!_send_cmd2(c,o)) {goto done;}
87#define send_cmd3(c,o1,o2) if (!_send_cmd3(c,o1,o2)) {goto done;}
88
89static void clear_display(void) {
90 matrix_clear(&display);
91
92 // Clear all of the display bits (there can be random noise
93 // in the RAM on startup)
94 send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1);
95 send_cmd3(ColumnAddr, 0, DisplayWidth - 1);
96
97 if (i2c_start_write(SSD1306_ADDRESS)) {
98 goto done;
99 }
100 if (i2c_master_write(0x40)) {
101 // Data mode
102 goto done;
103 }
104 for (uint8_t row = 0; row < MatrixRows; ++row) {
105 for (uint8_t col = 0; col < DisplayWidth; ++col) {
106 i2c_master_write(0);
107 }
108 }
109
110 display.dirty = false;
111
112done:
113 i2c_master_stop();
114}
115
116#if DEBUG_TO_SCREEN
117#undef sendchar
118static int8_t capture_sendchar(uint8_t c) {
119 sendchar(c);
120 iota_gfx_write_char(c);
121
122 if (!displaying) {
123 iota_gfx_flush();
124 }
125 return 0;
126}
127#endif
128
129bool iota_gfx_init(bool rotate) {
130 bool success = false;
131
132 i2c_master_init();
133 send_cmd1(DisplayOff);
134 send_cmd2(SetDisplayClockDiv, 0x80);
135 send_cmd2(SetMultiPlex, DisplayHeight - 1);
136
137 send_cmd2(SetDisplayOffset, 0);
138
139
140 send_cmd1(SetStartLine | 0x0);
141 send_cmd2(SetChargePump, 0x14 /* Enable */);
142 send_cmd2(SetMemoryMode, 0 /* horizontal addressing */);
143
144 if(rotate){
145 // the following Flip the display orientation 180 degrees
146 send_cmd1(SegRemap);
147 send_cmd1(ComScanInc);
148 }else{
149 // Flips the display orientation 0 degrees
150 send_cmd1(SegRemap | 0x1);
151 send_cmd1(ComScanDec);
152 }
153
154 send_cmd2(SetComPins, 0x2);
155 send_cmd2(SetContrast, 0x8f);
156 send_cmd2(SetPreCharge, 0xf1);
157 send_cmd2(SetVComDetect, 0x40);
158 send_cmd1(DisplayAllOnResume);
159 send_cmd1(NormalDisplay);
160 send_cmd1(DeActivateScroll);
161 send_cmd1(DisplayOn);
162
163 send_cmd2(SetContrast, 0); // Dim
164
165 clear_display();
166
167 success = true;
168
169 iota_gfx_flush();
170
171#if DEBUG_TO_SCREEN
172 print_set_sendchar(capture_sendchar);
173#endif
174
175done:
176 return success;
177}
178
179bool iota_gfx_off(void) {
180 bool success = false;
181
182 send_cmd1(DisplayOff);
183 success = true;
184
185done:
186 return success;
187}
188
189bool iota_gfx_on(void) {
190 bool success = false;
191
192 send_cmd1(DisplayOn);
193 success = true;
194
195done:
196 return success;
197}
198
199void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c) {
200 *matrix->cursor = c;
201 ++matrix->cursor;
202
203 if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) {
204 // We went off the end; scroll the display upwards by one line
205 memmove(&matrix->display[0], &matrix->display[1],
206 MatrixCols * (MatrixRows - 1));
207 matrix->cursor = &matrix->display[MatrixRows - 1][0];
208 memset(matrix->cursor, ' ', MatrixCols);
209 }
210}
211
212void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c) {
213 matrix->dirty = true;
214
215 if (c == '\n') {
216 // Clear to end of line from the cursor and then move to the
217 // start of the next line
218 uint8_t cursor_col = (matrix->cursor - &matrix->display[0][0]) % MatrixCols;
219
220 while (cursor_col++ < MatrixCols) {
221 matrix_write_char_inner(matrix, ' ');
222 }
223 return;
224 }
225
226 matrix_write_char_inner(matrix, c);
227}
228
229void iota_gfx_write_char(uint8_t c) {
230 matrix_write_char(&display, c);
231}
232
233void matrix_write(struct CharacterMatrix *matrix, const char *data) {
234 const char *end = data + strlen(data);
235 while (data < end) {
236 matrix_write_char(matrix, *data);
237 ++data;
238 }
239}
240
241void matrix_write_ln(struct CharacterMatrix *matrix, const char *data) {
242 char data_ln[strlen(data)+2];
243 snprintf(data_ln, sizeof(data_ln), "%s\n", data);
244 matrix_write(matrix, data_ln);
245}
246
247void iota_gfx_write(const char *data) {
248 matrix_write(&display, data);
249}
250
251void matrix_write_P(struct CharacterMatrix *matrix, const char *data) {
252 while (true) {
253 uint8_t c = pgm_read_byte(data);
254 if (c == 0) {
255 return;
256 }
257 matrix_write_char(matrix, c);
258 ++data;
259 }
260}
261
262void iota_gfx_write_P(const char *data) {
263 matrix_write_P(&display, data);
264}
265
266void matrix_clear(struct CharacterMatrix *matrix) {
267 memset(matrix->display, ' ', sizeof(matrix->display));
268 matrix->cursor = &matrix->display[0][0];
269 matrix->dirty = true;
270}
271
272void iota_gfx_clear_screen(void) {
273 matrix_clear(&display);
274}
275
276void matrix_render(struct CharacterMatrix *matrix) {
277 last_flush = timer_read();
278 iota_gfx_on();
279#if DEBUG_TO_SCREEN
280 ++displaying;
281#endif
282
283 // Move to the home position
284 send_cmd3(PageAddr, 0, MatrixRows - 1);
285 send_cmd3(ColumnAddr, 0, (MatrixCols * FontWidth) - 1);
286
287 if (i2c_start_write(SSD1306_ADDRESS)) {
288 goto done;
289 }
290 if (i2c_master_write(0x40)) {
291 // Data mode
292 goto done;
293 }
294
295 for (uint8_t row = 0; row < MatrixRows; ++row) {
296 for (uint8_t col = 0; col < MatrixCols; ++col) {
297 const uint8_t *glyph = font + (matrix->display[row][col] * FontWidth);
298
299 for (uint8_t glyphCol = 0; glyphCol < FontWidth; ++glyphCol) {
300 uint8_t colBits = pgm_read_byte(glyph + glyphCol);
301 i2c_master_write(colBits);
302 }
303
304 // 1 column of space between chars (it's not included in the glyph)
305 //i2c_master_write(0);
306 }
307 }
308
309 matrix->dirty = false;
310
311done:
312 i2c_master_stop();
313#if DEBUG_TO_SCREEN
314 --displaying;
315#endif
316}
317
318void iota_gfx_flush(void) {
319 matrix_render(&display);
320}
321
322__attribute__ ((weak))
323void iota_gfx_task_user(void) {
324}
325
326void iota_gfx_task(void) {
327 iota_gfx_task_user();
328
329 if (display.dirty|| force_dirty) {
330 iota_gfx_flush();
331 force_dirty = false;
332 }
333
334 if (timer_elapsed(last_flush) > ScreenOffInterval) {
335 iota_gfx_off();
336 }
337}
338
339bool process_record_gfx(uint16_t keycode, keyrecord_t *record) {
340 force_dirty = true;
341 return true;
342}
343
344#endif
diff --git a/keyboards/comet46/ssd1306.h b/keyboards/comet46/ssd1306.h
new file mode 100644
index 000000000..ea8c92328
--- /dev/null
+++ b/keyboards/comet46/ssd1306.h
@@ -0,0 +1,91 @@
1#pragma once
2
3#include <stdbool.h>
4#include <stdio.h>
5#include "pincontrol.h"
6#include "action.h"
7
8enum ssd1306_cmds {
9 DisplayOff = 0xAE,
10 DisplayOn = 0xAF,
11
12 SetContrast = 0x81,
13 DisplayAllOnResume = 0xA4,
14
15 DisplayAllOn = 0xA5,
16 NormalDisplay = 0xA6,
17 InvertDisplay = 0xA7,
18 SetDisplayOffset = 0xD3,
19 SetComPins = 0xda,
20 SetVComDetect = 0xdb,
21 SetDisplayClockDiv = 0xD5,
22 SetPreCharge = 0xd9,
23 SetMultiPlex = 0xa8,
24 SetLowColumn = 0x00,
25 SetHighColumn = 0x10,
26 SetStartLine = 0x40,
27
28 SetMemoryMode = 0x20,
29 ColumnAddr = 0x21,
30 PageAddr = 0x22,
31
32 ComScanInc = 0xc0,
33 ComScanDec = 0xc8,
34 SegRemap = 0xa0,
35 SetChargePump = 0x8d,
36 ExternalVcc = 0x01,
37 SwitchCapVcc = 0x02,
38
39 ActivateScroll = 0x2f,
40 DeActivateScroll = 0x2e,
41 SetVerticalScrollArea = 0xa3,
42 RightHorizontalScroll = 0x26,
43 LeftHorizontalScroll = 0x27,
44 VerticalAndRightHorizontalScroll = 0x29,
45 VerticalAndLeftHorizontalScroll = 0x2a,
46};
47
48// Controls the SSD1306 128x32 OLED display via i2c
49
50#ifndef SSD1306_ADDRESS
51#define SSD1306_ADDRESS 0x3C
52#endif
53
54#define DisplayHeight 32
55#define DisplayWidth 128
56
57#define FontHeight 8
58#define FontWidth 6
59
60#define MatrixRows (DisplayHeight / FontHeight)
61#define MatrixCols (DisplayWidth / FontWidth)
62
63struct CharacterMatrix {
64 uint8_t display[MatrixRows][MatrixCols];
65 uint8_t *cursor;
66 bool dirty;
67};
68
69struct CharacterMatrix display;
70
71bool iota_gfx_init(bool rotate);
72void iota_gfx_task(void);
73bool iota_gfx_off(void);
74bool iota_gfx_on(void);
75void iota_gfx_flush(void);
76void iota_gfx_write_char(uint8_t c);
77void iota_gfx_write(const char *data);
78void iota_gfx_write_P(const char *data);
79void iota_gfx_clear_screen(void);
80
81void iota_gfx_task_user(void);
82
83void matrix_clear(struct CharacterMatrix *matrix);
84void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c);
85void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c);
86void matrix_write(struct CharacterMatrix *matrix, const char *data);
87void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
88void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
89void matrix_render(struct CharacterMatrix *matrix);
90
91bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file