aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/model01/config.h3
-rw-r--r--keyboards/model01/keymaps/default/keymap.c57
-rw-r--r--keyboards/model01/leds.c144
-rw-r--r--keyboards/model01/leds.h9
-rw-r--r--keyboards/model01/rules.mk4
-rw-r--r--quantum/rgb_matrix.c1
6 files changed, 182 insertions, 36 deletions
diff --git a/keyboards/model01/config.h b/keyboards/model01/config.h
index 796653f45..167310731 100644
--- a/keyboards/model01/config.h
+++ b/keyboards/model01/config.h
@@ -33,3 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33 33
34/* The scanners already debounce for us */ 34/* The scanners already debounce for us */
35#define DEBOUNCING_DELAY 0 35#define DEBOUNCING_DELAY 0
36
37/* RGB matrix constants */
38#define DRIVER_LED_TOTAL 64
diff --git a/keyboards/model01/keymaps/default/keymap.c b/keyboards/model01/keymaps/default/keymap.c
index cdc050cd9..a6e5303fe 100644
--- a/keyboards/model01/keymaps/default/keymap.c
+++ b/keyboards/model01/keymaps/default/keymap.c
@@ -26,7 +26,7 @@ enum {
26const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 26const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
27[DEF] = LAYOUT( 27[DEF] = LAYOUT(
28 RESET , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , TG(NUM), 28 RESET , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , TG(NUM),
29 KC_GRV , KC_Q , KC_W , KC_E , KC_R , KC_T , _______, _______, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_EQL , 29 KC_GRV , KC_Q , KC_W , KC_E , KC_R , KC_T , RGB_MOD, _______, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_EQL ,
30 KC_PGUP, KC_A , KC_S , KC_D , KC_F , KC_G , KC_TAB , KC_ENT , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, 30 KC_PGUP, KC_A , KC_S , KC_D , KC_F , KC_G , KC_TAB , KC_ENT , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT,
31 KC_PGDN, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_ESC , _______, KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_MINS, 31 KC_PGDN, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_ESC , _______, KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_MINS,
32 KC_LCTL, KC_RCTL, 32 KC_LCTL, KC_RCTL,
@@ -48,7 +48,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
48 ), 48 ),
49[FUN] = LAYOUT( 49[FUN] = LAYOUT(
50 _______, KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , 50 _______, KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 ,
51 KC_TAB , _______, KC_MS_U, _______, KC_BTN3, _______, _______, KC_MPRV, KC_MNXT, KC_LCBR, KC_RCBR, KC_LBRC, KC_RBRC, KC_F12 , 51 KC_TAB , _______, KC_MS_U, _______, KC_BTN3, _______, RGB_TOG, KC_MPRV, KC_MNXT, KC_LCBR, KC_RCBR, KC_LBRC, KC_RBRC, KC_F12 ,
52 KC_HOME, KC_MS_L, KC_MS_D, KC_MS_R, KC_BTN1, _______, _______, KC_MPLY, KC_LEFT, KC_DOWN, KC_UP , KC_RGHT, _______, _______, 52 KC_HOME, KC_MS_L, KC_MS_D, KC_MS_R, KC_BTN1, _______, _______, KC_MPLY, KC_LEFT, KC_DOWN, KC_UP , KC_RGHT, _______, _______,
53 KC_END , KC_PSCR, KC_INS , _______, KC_BTN2, _______, _______, _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, KC_BSLS, KC_PIPE, 53 KC_END , KC_PSCR, KC_INS , _______, KC_BTN2, _______, _______, _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, KC_BSLS, KC_PIPE,
54 _______, _______, 54 _______, _______,
@@ -73,21 +73,52 @@ LAYOUT(
73 ) 73 )
74*/ 74*/
75 75
76static void set_numpad_colours(int on, void (*write)(int, uint8_t, uint8_t, uint8_t)) {
77 if (!on) {
78 for (int i=44; i<=60; i++)
79 write(i, 0, 0, 0);
80 write(63, 0, 0, 0);
81 return;
82 }
83
84 /* main number keys */
85 for (int i=44; i<=47; i++)
86 write(i, 255, 0, 0);
87 for (int i=49; i<=54; i++)
88 write(i, 255, 0, 0);
89
90 /* accessory keys */
91 write(48, 128, 128, 0);
92 for (int i=55; i<=59; i++)
93 write(i, 128, 128, 0);
94
95 // enter
96 write(63, 0, 128, 0);
97
98 // num key
99 write(60, 128, 0, 128);
100}
101
102#ifdef RGB_MATRIX_ENABLE
103/* the RGB matrix effects will overwrite the numpad indicator.
104 * this handy mechanism allows to override the matrix effects.
105 */
106void rgb_matrix_indicators_user(void) {
107 if (layer_state & (1<<NUM)) {
108 set_numpad_colours(1, &rgb_matrix_set_color);
109 }
110}
111#else /* no RGB matrix support */
112
76uint32_t layer_state_set_user(uint32_t state) { 113uint32_t layer_state_set_user(uint32_t state) {
77 switch (biton32(state)) { 114 if (state & (1<<NUM)) {
78 case DEF: 115 set_numpad_colours(1, &set_led_to);
79 set_all_leds_to(0,0,0); 116 } else {
80 break; 117 set_numpad_colours(0, &set_led_to);
81 case NUM:
82 /* highlight the numpad keys when numlock is on */
83 for (int i=44; i<=60; i++) {
84 set_led_to(i, 128,0,0);
85 }
86 set_led_to(63, 128, 0, 0);
87 break;
88 } 118 }
89 119
90 return state; 120 return state;
91} 121}
122#endif
92 123
93/* vim: set ts=2 sw=2 et: */ 124/* vim: set ts=2 sw=2 et: */
diff --git a/keyboards/model01/leds.c b/keyboards/model01/leds.c
index b80a749a7..7a62c7424 100644
--- a/keyboards/model01/leds.c
+++ b/keyboards/model01/leds.c
@@ -16,42 +16,154 @@
16#include <quantum.h> 16#include <quantum.h>
17#include <i2c_master.h> 17#include <i2c_master.h>
18#include <led_tables.h> 18#include <led_tables.h>
19#include <rgb_matrix.h>
20#include <string.h>
19#include "model01.h" 21#include "model01.h"
20 22
21#define I2C_TIMEOUT 1000 23#define I2C_TIMEOUT 1000
22 24
23#define LINCOR(i) pgm_read_byte(&CIE1931_CURVE[i]) 25void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
24
25int set_all_leds_to_raw(uint8_t r, uint8_t g, uint8_t b) {
26 uint8_t buf[] = { 26 uint8_t buf[] = {
27 TWI_CMD_LED_SET_ALL_TO, 27 TWI_CMD_LED_SET_ALL_TO,
28 b, g, r 28 b, g, r
29 }; 29 };
30 int ret = 0; 30 i2c_transmit(I2C_ADDR(LEFT), buf, sizeof(buf), I2C_TIMEOUT);
31 ret |= i2c_transmit(I2C_ADDR(LEFT), buf, sizeof(buf), I2C_TIMEOUT); 31 i2c_transmit(I2C_ADDR(RIGHT), buf, sizeof(buf), I2C_TIMEOUT);
32 ret |= i2c_transmit(I2C_ADDR(RIGHT), buf, sizeof(buf), I2C_TIMEOUT);
33 _delay_us(10); 32 _delay_us(10);
34 return ret;
35}
36
37int set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
38 return set_all_leds_to_raw(LINCOR(r), LINCOR(g), LINCOR(b));
39} 33}
40 34
41int set_led_to_raw(uint8_t led, uint8_t r, uint8_t g, uint8_t b) { 35void set_led_to(int led, uint8_t r, uint8_t g, uint8_t b) {
42 uint8_t buf[] = { 36 uint8_t buf[] = {
43 TWI_CMD_LED_SET_ONE_TO, 37 TWI_CMD_LED_SET_ONE_TO,
44 led & 0x1f, 38 led & 0x1f,
45 b, g, r 39 b, g, r
46 }; 40 };
47 int hand = (led >= 32) ? RIGHT : LEFT; 41 int hand = (led >= 32) ? RIGHT : LEFT;
48 int ret = i2c_transmit(I2C_ADDR(hand), buf, sizeof(buf), I2C_TIMEOUT); 42 i2c_transmit(I2C_ADDR(hand), buf, sizeof(buf), I2C_TIMEOUT);
49 _delay_us(10); 43 _delay_us(10);
50 return ret;
51} 44}
52 45
53int set_led_to(uint8_t led, uint8_t r, uint8_t g, uint8_t b) { 46#ifdef RGB_MATRIX_ENABLE
54 return set_led_to_raw(led, LINCOR(r), LINCOR(g), LINCOR(b)); 47
48__attribute__ ((weak))
49const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
50 {{0x73}, { 3, 35}, 0},
51 {{0x72}, { 0, 26}, 0},
52 {{0x71}, { 0, 17}, 0},
53 {{0x70}, { 0, 6}, 0},
54 {{0x60}, { 14, 5}, 0},
55 {{0x61}, { 15, 16}, 0},
56 {{0x62}, { 16, 25}, 0},
57 {{0x63}, { 17, 34}, 0},
58 {{0x53}, { 31, 29}, 0},
59 {{0x52}, { 31, 19}, 0},
60 {{0x51}, { 30, 11}, 0},
61 {{0x50}, { 30, 1}, 0},
62 {{0x40}, { 45, 0}, 0},
63 {{0x41}, { 45, 8}, 0},
64 {{0x42}, { 46, 17}, 0},
65 {{0x43}, { 46, 27}, 0},
66 {{0x33}, { 60, 27}, 0},
67 {{0x32}, { 60, 18}, 0},
68 {{0x31}, { 60, 9}, 0},
69 {{0x30}, { 60, 0}, 0},
70 {{0x20}, { 74, 2}, 0},
71 {{0x21}, { 74, 11}, 0},
72 {{0x22}, { 75, 20}, 0},
73 {{0x23}, { 74, 28}, 0},
74 {{0x12}, { 89, 30}, 0},
75 {{0x11}, { 89, 19}, 0},
76 {{0x10}, { 89, 7}, 0},
77 {{0x00}, { 70, 38}, 1},
78 {{0x01}, { 82, 41}, 1},
79 {{0x02}, { 93, 45}, 1},
80 {{0x03}, {104, 50}, 1},
81 {{0x13}, { 74, 64}, 1},
82 {{0x67}, {149, 64}, 1},
83 {{0x77}, {119, 50}, 1},
84 {{0x76}, {130, 45}, 1},
85 {{0x75}, {141, 41}, 1},
86 {{0x74}, {153, 38}, 1},
87 {{0x64}, {134, 7}, 0},
88 {{0x65}, {134, 19}, 0},
89 {{0x66}, {134, 30}, 0},
90 {{0x57}, {149, 28}, 0},
91 {{0x56}, {148, 20}, 0},
92 {{0x55}, {149, 11}, 0},
93 {{0x54}, {149, 2}, 0},
94 {{0x44}, {163, 0}, 0},
95 {{0x45}, {163, 9}, 0},
96 {{0x46}, {163, 18}, 0},
97 {{0x47}, {163, 27}, 0},
98 {{0x37}, {177, 27}, 0},
99 {{0x36}, {177, 17}, 0},
100 {{0x35}, {178, 8}, 0},
101 {{0x34}, {178, 0}, 0},
102 {{0x24}, {193, 1}, 0},
103 {{0x25}, {193, 11}, 0},
104 {{0x26}, {192, 19}, 0},
105 {{0x27}, {192, 29}, 0},
106 {{0x17}, {206, 34}, 0},
107 {{0x16}, {207, 25}, 0},
108 {{0x15}, {208, 16}, 0},
109 {{0x14}, {209, 5}, 0},
110 {{0x04}, {224, 6}, 0},
111 {{0x05}, {223, 17}, 0},
112 {{0x06}, {223, 26}, 0},
113 {{0x07}, {220, 35}, 0},
114};
115
116static struct {
117 uint8_t b;
118 uint8_t g;
119 uint8_t r;
120} __attribute__((packed)) led_state[64];
121
122static void set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
123 led_state[index].r = r;
124 led_state[index].g = g;
125 led_state[index].b = b;
126}
127
128static void set_color_all(uint8_t r, uint8_t g, uint8_t b) {
129 for (int i=0; i<DRIVER_LED_TOTAL; i++)
130 set_color(i, r, g, b);
55} 131}
56 132
133static void init(void) {
134 // Enable high current pathway to LEDs - this does violate the USB spec though! (1.6 amps...)
135 DDRE |= _BV(6);
136 PORTE &= ~_BV(6);
137
138 // Overcurrent check input
139 DDRB &= ~_BV(4);
140 PORTB &= ~_BV(4);
141}
142
143static void flush(void) {
144 uint8_t *bank_data = (uint8_t*)&led_state[0];
145 uint8_t command[1 + 8*3];
146 for (int hand=0; hand<2; hand++) {
147 int addr = I2C_ADDR(hand);
148
149 for (int bank=0; bank<4; bank++) {
150 command[0] = TWI_CMD_LED_BASE + bank;
151 memcpy(&command[1], bank_data, 8*3);
152 i2c_transmit(addr, command, sizeof(command), I2C_TIMEOUT);
153 _delay_us(100);
154
155 bank_data += 8*3;
156 }
157 }
158}
159
160const rgb_matrix_driver_t rgb_matrix_driver = {
161 .init = init,
162 .flush = flush,
163 .set_color = set_color,
164 .set_color_all = set_color_all
165};
166
167#endif
168
57/* vim: set ts=2 sw=2 et: */ 169/* vim: set ts=2 sw=2 et: */
diff --git a/keyboards/model01/leds.h b/keyboards/model01/leds.h
index 0aac781dd..405bdf328 100644
--- a/keyboards/model01/leds.h
+++ b/keyboards/model01/leds.h
@@ -16,10 +16,7 @@
16#pragma once 16#pragma once
17 17
18#include <quantum.h> 18#include <quantum.h>
19#include <rgb_matrix.h>
19 20
20int set_all_leds_to(uint8_t r, uint8_t g, uint8_t b); 21void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b);
21int set_led_to(uint8_t led, uint8_t r, uint8_t g, uint8_t b); 22void set_led_to(int led, uint8_t r, uint8_t g, uint8_t b);
22
23/* Raw (gamma uncorrected) LED values */
24int set_all_leds_to_raw(uint8_t r, uint8_t g, uint8_t b);
25int set_led_to_raw(uint8_t led, uint8_t r, uint8_t g, uint8_t b);
diff --git a/keyboards/model01/rules.mk b/keyboards/model01/rules.mk
index cab7065ff..49ab981d1 100644
--- a/keyboards/model01/rules.mk
+++ b/keyboards/model01/rules.mk
@@ -59,4 +59,6 @@ MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
59UNICODE_ENABLE = no # Unicode 59UNICODE_ENABLE = no # Unicode
60 60
61CUSTOM_MATRIX = yes 61CUSTOM_MATRIX = yes
62CIE1931_CURVE = yes 62
63# You can set RGB_MATRIX_ENABLE = no in your rules.mk to disable this and save the Flash
64RGB_MATRIX_ENABLE = custom # Enable RGB matrix effects (+10000).
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 807e4d62d..b282284a1 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -21,6 +21,7 @@
21#include "progmem.h" 21#include "progmem.h"
22#include "config.h" 22#include "config.h"
23#include "eeprom.h" 23#include "eeprom.h"
24#include <string.h>
24#include <math.h> 25#include <math.h>
25 26
26rgb_config_t rgb_matrix_config; 27rgb_config_t rgb_matrix_config;