diff options
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/api.c | 178 | ||||
| -rw-r--r-- | quantum/api.h | 59 | ||||
| -rw-r--r-- | quantum/api/api_sysex.c | 29 | ||||
| -rw-r--r-- | quantum/api/api_sysex.h | 10 | ||||
| -rw-r--r-- | quantum/config_common.h | 101 | ||||
| -rw-r--r-- | quantum/keymap.h | 4 | ||||
| -rwxr-xr-x | quantum/light_ws2812.c | 151 | ||||
| -rwxr-xr-x | quantum/light_ws2812.h | 21 | ||||
| -rw-r--r-- | quantum/process_keycode/process_printer.c | 254 | ||||
| -rw-r--r-- | quantum/process_keycode/process_printer.h | 8 | ||||
| -rw-r--r-- | quantum/process_keycode/process_printer_bb.c | 260 | ||||
| -rw-r--r-- | quantum/quantum.c | 48 | ||||
| -rw-r--r-- | quantum/quantum.h | 11 | ||||
| -rw-r--r-- | quantum/rgblight.c | 139 | ||||
| -rw-r--r-- | quantum/rgblight.h | 13 |
15 files changed, 1171 insertions, 115 deletions
diff --git a/quantum/api.c b/quantum/api.c new file mode 100644 index 000000000..4ca3b9676 --- /dev/null +++ b/quantum/api.c | |||
| @@ -0,0 +1,178 @@ | |||
| 1 | #include "api.h" | ||
| 2 | #include "quantum.h" | ||
| 3 | |||
| 4 | void dword_to_bytes(uint32_t dword, uint8_t * bytes) { | ||
| 5 | bytes[0] = (dword >> 24) & 0xFF; | ||
| 6 | bytes[1] = (dword >> 16) & 0xFF; | ||
| 7 | bytes[2] = (dword >> 8) & 0xFF; | ||
| 8 | bytes[3] = (dword >> 0) & 0xFF; | ||
| 9 | } | ||
| 10 | |||
| 11 | uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index) { | ||
| 12 | return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3]; | ||
| 13 | } | ||
| 14 | |||
| 15 | __attribute__ ((weak)) | ||
| 16 | bool process_api_quantum(uint8_t length, uint8_t * data) { | ||
| 17 | return process_api_keyboard(length, data); | ||
| 18 | } | ||
| 19 | |||
| 20 | __attribute__ ((weak)) | ||
| 21 | bool process_api_keyboard(uint8_t length, uint8_t * data) { | ||
| 22 | return process_api_user(length, data); | ||
| 23 | } | ||
| 24 | |||
| 25 | __attribute__ ((weak)) | ||
| 26 | bool process_api_user(uint8_t length, uint8_t * data) { | ||
| 27 | return true; | ||
| 28 | } | ||
| 29 | |||
| 30 | void process_api(uint16_t length, uint8_t * data) { | ||
| 31 | // SEND_STRING("\nRX: "); | ||
| 32 | // for (uint8_t i = 0; i < length; i++) { | ||
| 33 | // send_byte(data[i]); | ||
| 34 | // SEND_STRING(" "); | ||
| 35 | // } | ||
| 36 | if (!process_api_quantum(length, data)) | ||
| 37 | return; | ||
| 38 | |||
| 39 | switch (data[0]) { | ||
| 40 | case MT_SET_DATA: | ||
| 41 | switch (data[1]) { | ||
| 42 | case DT_DEFAULT_LAYER: { | ||
| 43 | eeconfig_update_default_layer(data[2]); | ||
| 44 | default_layer_set((uint32_t)(data[2])); | ||
| 45 | break; | ||
| 46 | } | ||
| 47 | case DT_KEYMAP_OPTIONS: { | ||
| 48 | eeconfig_update_keymap(data[2]); | ||
| 49 | break; | ||
| 50 | } | ||
| 51 | case DT_RGBLIGHT: { | ||
| 52 | #ifdef RGBLIGHT_ENABLE | ||
| 53 | uint32_t rgblight = bytes_to_dword(data, 2); | ||
| 54 | rgblight_update_dword(rgblight); | ||
| 55 | #endif | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | case MT_GET_DATA: | ||
| 60 | switch (data[1]) { | ||
| 61 | case DT_HANDSHAKE: { | ||
| 62 | MT_GET_DATA_ACK(DT_HANDSHAKE, NULL, 0); | ||
| 63 | break; | ||
| 64 | } | ||
| 65 | case DT_DEBUG: { | ||
| 66 | uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) }; | ||
| 67 | MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1); | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | case DT_DEFAULT_LAYER: { | ||
| 71 | uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) }; | ||
| 72 | MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1); | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | case DT_CURRENT_LAYER: { | ||
| 76 | uint8_t layer_state_bytes[4]; | ||
| 77 | dword_to_bytes(layer_state, layer_state_bytes); | ||
| 78 | MT_GET_DATA_ACK(DT_CURRENT_LAYER, layer_state_bytes, 4); | ||
| 79 | break; | ||
| 80 | } | ||
| 81 | case DT_AUDIO: { | ||
| 82 | #ifdef AUDIO_ENABLE | ||
| 83 | uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) }; | ||
| 84 | MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1); | ||
| 85 | #else | ||
| 86 | MT_GET_DATA_ACK(DT_AUDIO, NULL, 0); | ||
| 87 | #endif | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | case DT_BACKLIGHT: { | ||
| 91 | #ifdef BACKLIGHT_ENABLE | ||
| 92 | uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) }; | ||
| 93 | MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1); | ||
| 94 | #else | ||
| 95 | MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0); | ||
| 96 | #endif | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | case DT_RGBLIGHT: { | ||
| 100 | #ifdef RGBLIGHT_ENABLE | ||
| 101 | uint8_t rgblight_bytes[4]; | ||
| 102 | dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes); | ||
| 103 | MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4); | ||
| 104 | #else | ||
| 105 | MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0); | ||
| 106 | #endif | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | case DT_KEYMAP_OPTIONS: { | ||
| 110 | uint8_t keymap_bytes[1] = { eeconfig_read_keymap() }; | ||
| 111 | MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1); | ||
| 112 | break; | ||
| 113 | } | ||
| 114 | case DT_KEYMAP_SIZE: { | ||
| 115 | uint8_t keymap_size[2] = {MATRIX_ROWS, MATRIX_COLS}; | ||
| 116 | MT_GET_DATA_ACK(DT_KEYMAP_SIZE, keymap_size, 2); | ||
| 117 | break; | ||
| 118 | } | ||
| 119 | case DT_KEYMAP: { | ||
| 120 | uint8_t keymap_data[MATRIX_ROWS * MATRIX_COLS * 4 + 3]; | ||
| 121 | keymap_data[0] = data[2]; | ||
| 122 | keymap_data[1] = MATRIX_ROWS; | ||
| 123 | keymap_data[2] = MATRIX_COLS; | ||
| 124 | for (int i = 0; i < MATRIX_ROWS; i++) { | ||
| 125 | for (int j = 0; j < MATRIX_COLS; j++) { | ||
| 126 | keymap_data[3 + (i*MATRIX_COLS*2) + (j*2)] = pgm_read_word(&keymaps[data[2]][i][j]) >> 8; | ||
| 127 | keymap_data[3 + (i*MATRIX_COLS*2) + (j*2) + 1] = pgm_read_word(&keymaps[data[2]][i][j]) & 0xFF; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, MATRIX_ROWS * MATRIX_COLS * 4 + 3); | ||
| 131 | // uint8_t keymap_data[5]; | ||
| 132 | // keymap_data[0] = data[2]; | ||
| 133 | // keymap_data[1] = data[3]; | ||
| 134 | // keymap_data[2] = data[4]; | ||
| 135 | // keymap_data[3] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) >> 8; | ||
| 136 | // keymap_data[4] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) & 0xFF; | ||
| 137 | |||
| 138 | // MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, 5); | ||
| 139 | break; | ||
| 140 | } | ||
| 141 | default: | ||
| 142 | break; | ||
| 143 | } | ||
| 144 | break; | ||
| 145 | case MT_SET_DATA_ACK: | ||
| 146 | case MT_GET_DATA_ACK: | ||
| 147 | break; | ||
| 148 | case MT_SEND_DATA: | ||
| 149 | break; | ||
| 150 | case MT_SEND_DATA_ACK: | ||
| 151 | break; | ||
| 152 | case MT_EXE_ACTION: | ||
| 153 | break; | ||
| 154 | case MT_EXE_ACTION_ACK: | ||
| 155 | break; | ||
| 156 | case MT_TYPE_ERROR: | ||
| 157 | break; | ||
| 158 | default: ; // command not recognised | ||
| 159 | SEND_BYTES(MT_TYPE_ERROR, DT_NONE, data, length); | ||
| 160 | break; | ||
| 161 | |||
| 162 | // #ifdef RGBLIGHT_ENABLE | ||
| 163 | // case 0x27: ; // RGB LED functions | ||
| 164 | // switch (*data++) { | ||
| 165 | // case 0x00: ; // Update HSV | ||
| 166 | // rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]); | ||
| 167 | // break; | ||
| 168 | // case 0x01: ; // Update RGB | ||
| 169 | // break; | ||
| 170 | // case 0x02: ; // Update mode | ||
| 171 | // rgblight_mode(data[0]); | ||
| 172 | // break; | ||
| 173 | // } | ||
| 174 | // break; | ||
| 175 | // #endif | ||
| 176 | } | ||
| 177 | |||
| 178 | } \ No newline at end of file | ||
diff --git a/quantum/api.h b/quantum/api.h new file mode 100644 index 000000000..00dcdb895 --- /dev/null +++ b/quantum/api.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #ifndef _API_H_ | ||
| 2 | #define _API_H_ | ||
| 3 | |||
| 4 | #include "lufa.h" | ||
| 5 | |||
| 6 | enum MESSAGE_TYPE { | ||
| 7 | MT_GET_DATA = 0x10, // Get data from keyboard | ||
| 8 | MT_GET_DATA_ACK = 0x11, // returned data to process (ACK) | ||
| 9 | MT_SET_DATA = 0x20, // Set data on keyboard | ||
| 10 | MT_SET_DATA_ACK = 0x21, // returned data to confirm (ACK) | ||
| 11 | MT_SEND_DATA = 0x30, // Sending data/action from keyboard | ||
| 12 | MT_SEND_DATA_ACK = 0x31, // returned data/action confirmation (ACK) | ||
| 13 | MT_EXE_ACTION = 0x40, // executing actions on keyboard | ||
| 14 | MT_EXE_ACTION_ACK =0x41, // return confirmation/value (ACK) | ||
| 15 | MT_TYPE_ERROR = 0x80 // type not recofgnised (ACK) | ||
| 16 | }; | ||
| 17 | |||
| 18 | enum DATA_TYPE { | ||
| 19 | DT_NONE = 0x00, | ||
| 20 | DT_HANDSHAKE, | ||
| 21 | DT_DEFAULT_LAYER, | ||
| 22 | DT_CURRENT_LAYER, | ||
| 23 | DT_KEYMAP_OPTIONS, | ||
| 24 | DT_BACKLIGHT, | ||
| 25 | DT_RGBLIGHT, | ||
| 26 | DT_UNICODE, | ||
| 27 | DT_DEBUG, | ||
| 28 | DT_AUDIO, | ||
| 29 | DT_QUANTUM_ACTION, | ||
| 30 | DT_KEYBOARD_ACTION, | ||
| 31 | DT_USER_ACTION, | ||
| 32 | DT_KEYMAP_SIZE, | ||
| 33 | DT_KEYMAP | ||
| 34 | }; | ||
| 35 | |||
| 36 | void dword_to_bytes(uint32_t dword, uint8_t * bytes); | ||
| 37 | uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index); | ||
| 38 | |||
| 39 | #define MT_GET_DATA(data_type, data, length) SEND_BYTES(MT_GET_DATA, data_type, data, length) | ||
| 40 | #define MT_GET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_GET_DATA_ACK, data_type, data, length) | ||
| 41 | #define MT_SET_DATA(data_type, data, length) SEND_BYTES(MT_SET_DATA, data_type, data, length) | ||
| 42 | #define MT_SET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_SET_DATA_ACK, data_type, data, length) | ||
| 43 | #define MT_SEND_DATA(data_type, data, length) SEND_BYTES(MT_SEND_DATA, data_type, data, length) | ||
| 44 | #define MT_SEND_DATA_ACK(data_type, data, length) SEND_BYTES(MT_SEND_DATA_ACK, data_type, data, length) | ||
| 45 | #define MT_EXE_ACTION(data_type, data, length) SEND_BYTES(MT_EXE_ACTION, data_type, data, length) | ||
| 46 | #define MT_EXE_ACTION_ACK(data_type, data, length) SEND_BYTES(MT_EXE_ACTION_ACK, data_type, data, length) | ||
| 47 | |||
| 48 | void process_api(uint16_t length, uint8_t * data); | ||
| 49 | |||
| 50 | __attribute__ ((weak)) | ||
| 51 | bool process_api_quantum(uint8_t length, uint8_t * data); | ||
| 52 | |||
| 53 | __attribute__ ((weak)) | ||
| 54 | bool process_api_keyboard(uint8_t length, uint8_t * data); | ||
| 55 | |||
| 56 | __attribute__ ((weak)) | ||
| 57 | bool process_api_user(uint8_t length, uint8_t * data); | ||
| 58 | |||
| 59 | #endif \ No newline at end of file | ||
diff --git a/quantum/api/api_sysex.c b/quantum/api/api_sysex.c new file mode 100644 index 000000000..a4a554e76 --- /dev/null +++ b/quantum/api/api_sysex.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #include "api_sysex.h" | ||
| 2 | |||
| 3 | void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length) { | ||
| 4 | // SEND_STRING("\nTX: "); | ||
| 5 | // for (uint8_t i = 0; i < length; i++) { | ||
| 6 | // send_byte(bytes[i]); | ||
| 7 | // SEND_STRING(" "); | ||
| 8 | // } | ||
| 9 | uint8_t * precode = malloc(sizeof(uint8_t) * (length + 2)); | ||
| 10 | precode[0] = message_type; | ||
| 11 | precode[1] = data_type; | ||
| 12 | memcpy(precode + 2, bytes, length); | ||
| 13 | uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 2))); | ||
| 14 | uint16_t encoded_length = sysex_encode(encoded, precode, length + 2); | ||
| 15 | uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5)); | ||
| 16 | array[0] = 0xF0; | ||
| 17 | array[1] = 0x00; | ||
| 18 | array[2] = 0x00; | ||
| 19 | array[3] = 0x00; | ||
| 20 | array[encoded_length + 4] = 0xF7; | ||
| 21 | memcpy(array + 4, encoded, encoded_length); | ||
| 22 | midi_send_array(&midi_device, encoded_length + 5, array); | ||
| 23 | |||
| 24 | // SEND_STRING("\nTD: "); | ||
| 25 | // for (uint8_t i = 0; i < encoded_length + 5; i++) { | ||
| 26 | // send_byte(array[i]); | ||
| 27 | // SEND_STRING(" "); | ||
| 28 | // } | ||
| 29 | } \ No newline at end of file | ||
diff --git a/quantum/api/api_sysex.h b/quantum/api/api_sysex.h new file mode 100644 index 000000000..b947b60e5 --- /dev/null +++ b/quantum/api/api_sysex.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef _API_SYSEX_H_ | ||
| 2 | #define _API_SYSEX_H_ | ||
| 3 | |||
| 4 | #include "api.h" | ||
| 5 | |||
| 6 | void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length); | ||
| 7 | |||
| 8 | #define SEND_BYTES(mt, dt, b, l) send_bytes_sysex(mt, dt, b, l) | ||
| 9 | |||
| 10 | #endif \ No newline at end of file | ||
diff --git a/quantum/config_common.h b/quantum/config_common.h index 4d3939dae..17c11faeb 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h | |||
| @@ -5,55 +5,56 @@ | |||
| 5 | #define COL2ROW 0 | 5 | #define COL2ROW 0 |
| 6 | #define ROW2COL 1 | 6 | #define ROW2COL 1 |
| 7 | /* I/O pins */ | 7 | /* I/O pins */ |
| 8 | #define B0 0x30 | 8 | #ifndef F0 |
| 9 | #define B1 0x31 | 9 | #define B0 0x30 |
| 10 | #define B2 0x32 | 10 | #define B1 0x31 |
| 11 | #define B3 0x33 | 11 | #define B2 0x32 |
| 12 | #define B4 0x34 | 12 | #define B3 0x33 |
| 13 | #define B5 0x35 | 13 | #define B4 0x34 |
| 14 | #define B6 0x36 | 14 | #define B5 0x35 |
| 15 | #define B7 0x37 | 15 | #define B6 0x36 |
| 16 | #define C0 0x60 | 16 | #define B7 0x37 |
| 17 | #define C1 0x61 | 17 | #define C0 0x60 |
| 18 | #define C2 0x62 | 18 | #define C1 0x61 |
| 19 | #define C3 0x63 | 19 | #define C2 0x62 |
| 20 | #define C4 0x64 | 20 | #define C3 0x63 |
| 21 | #define C5 0x65 | 21 | #define C4 0x64 |
| 22 | #define C6 0x66 | 22 | #define C5 0x65 |
| 23 | #define C7 0x67 | 23 | #define C6 0x66 |
| 24 | #define D0 0x90 | 24 | #define C7 0x67 |
| 25 | #define D1 0x91 | 25 | #define D0 0x90 |
| 26 | #define D2 0x92 | 26 | #define D1 0x91 |
| 27 | #define D3 0x93 | 27 | #define D2 0x92 |
| 28 | #define D4 0x94 | 28 | #define D3 0x93 |
| 29 | #define D5 0x95 | 29 | #define D4 0x94 |
| 30 | #define D6 0x96 | 30 | #define D5 0x95 |
| 31 | #define D7 0x97 | 31 | #define D6 0x96 |
| 32 | #define E0 0xC0 | 32 | #define D7 0x97 |
| 33 | #define E1 0xC1 | 33 | #define E0 0xC0 |
| 34 | #define E2 0xC2 | 34 | #define E1 0xC1 |
| 35 | #define E3 0xC3 | 35 | #define E2 0xC2 |
| 36 | #define E4 0xC4 | 36 | #define E3 0xC3 |
| 37 | #define E5 0xC5 | 37 | #define E4 0xC4 |
| 38 | #define E6 0xC6 | 38 | #define E5 0xC5 |
| 39 | #define E7 0xC7 | 39 | #define E6 0xC6 |
| 40 | #define F0 0xF0 | 40 | #define E7 0xC7 |
| 41 | #define F1 0xF1 | 41 | #define F0 0xF0 |
| 42 | #define F2 0xF2 | 42 | #define F1 0xF1 |
| 43 | #define F3 0xF3 | 43 | #define F2 0xF2 |
| 44 | #define F4 0xF4 | 44 | #define F3 0xF3 |
| 45 | #define F5 0xF5 | 45 | #define F4 0xF4 |
| 46 | #define F6 0xF6 | 46 | #define F5 0xF5 |
| 47 | #define F7 0xF7 | 47 | #define F6 0xF6 |
| 48 | #define A0 0x00 | 48 | #define F7 0xF7 |
| 49 | #define A1 0x01 | 49 | #define A0 0x00 |
| 50 | #define A2 0x02 | 50 | #define A1 0x01 |
| 51 | #define A3 0x03 | 51 | #define A2 0x02 |
| 52 | #define A4 0x04 | 52 | #define A3 0x03 |
| 53 | #define A5 0x05 | 53 | #define A4 0x04 |
| 54 | #define A6 0x06 | 54 | #define A5 0x05 |
| 55 | #define A7 0x07 | 55 | #define A6 0x06 |
| 56 | 56 | #define A7 0x07 | |
| 57 | #endif | ||
| 57 | 58 | ||
| 58 | /* USART configuration */ | 59 | /* USART configuration */ |
| 59 | #ifdef BLUETOOTH_ENABLE | 60 | #ifdef BLUETOOTH_ENABLE |
| @@ -79,4 +80,4 @@ | |||
| 79 | # endif | 80 | # endif |
| 80 | #endif | 81 | #endif |
| 81 | 82 | ||
| 82 | #endif \ No newline at end of file | 83 | #endif |
diff --git a/quantum/keymap.h b/quantum/keymap.h index a01bbfbd1..ae56d16c7 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h | |||
| @@ -178,6 +178,10 @@ enum quantum_keycodes { | |||
| 178 | // Right shift, close paren | 178 | // Right shift, close paren |
| 179 | KC_RSPC, | 179 | KC_RSPC, |
| 180 | 180 | ||
| 181 | // Printing | ||
| 182 | PRINT_ON, | ||
| 183 | PRINT_OFF, | ||
| 184 | |||
| 181 | // always leave at the end | 185 | // always leave at the end |
| 182 | SAFE_RANGE | 186 | SAFE_RANGE |
| 183 | }; | 187 | }; |
diff --git a/quantum/light_ws2812.c b/quantum/light_ws2812.c index 401845e85..a883b1388 100755 --- a/quantum/light_ws2812.c +++ b/quantum/light_ws2812.c | |||
| @@ -16,14 +16,128 @@ | |||
| 16 | #include <util/delay.h> | 16 | #include <util/delay.h> |
| 17 | #include "debug.h" | 17 | #include "debug.h" |
| 18 | 18 | ||
| 19 | #ifdef RGBW_BB_TWI | ||
| 20 | |||
| 21 | // Port for the I2C | ||
| 22 | #define I2C_DDR DDRD | ||
| 23 | #define I2C_PIN PIND | ||
| 24 | #define I2C_PORT PORTD | ||
| 25 | |||
| 26 | // Pins to be used in the bit banging | ||
| 27 | #define I2C_CLK 0 | ||
| 28 | #define I2C_DAT 1 | ||
| 29 | |||
| 30 | #define I2C_DATA_HI()\ | ||
| 31 | I2C_DDR &= ~ (1 << I2C_DAT);\ | ||
| 32 | I2C_PORT |= (1 << I2C_DAT); | ||
| 33 | #define I2C_DATA_LO()\ | ||
| 34 | I2C_DDR |= (1 << I2C_DAT);\ | ||
| 35 | I2C_PORT &= ~ (1 << I2C_DAT); | ||
| 36 | |||
| 37 | #define I2C_CLOCK_HI()\ | ||
| 38 | I2C_DDR &= ~ (1 << I2C_CLK);\ | ||
| 39 | I2C_PORT |= (1 << I2C_CLK); | ||
| 40 | #define I2C_CLOCK_LO()\ | ||
| 41 | I2C_DDR |= (1 << I2C_CLK);\ | ||
| 42 | I2C_PORT &= ~ (1 << I2C_CLK); | ||
| 43 | |||
| 44 | #define I2C_DELAY 1 | ||
| 45 | |||
| 46 | void I2C_WriteBit(unsigned char c) | ||
| 47 | { | ||
| 48 | if (c > 0) | ||
| 49 | { | ||
| 50 | I2C_DATA_HI(); | ||
| 51 | } | ||
| 52 | else | ||
| 53 | { | ||
| 54 | I2C_DATA_LO(); | ||
| 55 | } | ||
| 56 | |||
| 57 | I2C_CLOCK_HI(); | ||
| 58 | _delay_us(I2C_DELAY); | ||
| 59 | |||
| 60 | I2C_CLOCK_LO(); | ||
| 61 | _delay_us(I2C_DELAY); | ||
| 62 | |||
| 63 | if (c > 0) | ||
| 64 | { | ||
| 65 | I2C_DATA_LO(); | ||
| 66 | } | ||
| 67 | |||
| 68 | _delay_us(I2C_DELAY); | ||
| 69 | } | ||
| 70 | |||
| 71 | // Inits bitbanging port, must be called before using the functions below | ||
| 72 | // | ||
| 73 | void I2C_Init() | ||
| 74 | { | ||
| 75 | I2C_PORT &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK)); | ||
| 76 | |||
| 77 | I2C_CLOCK_HI(); | ||
| 78 | I2C_DATA_HI(); | ||
| 79 | |||
| 80 | _delay_us(I2C_DELAY); | ||
| 81 | } | ||
| 82 | |||
| 83 | // Send a START Condition | ||
| 84 | // | ||
| 85 | void I2C_Start() | ||
| 86 | { | ||
| 87 | // set both to high at the same time | ||
| 88 | I2C_DDR &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK)); | ||
| 89 | _delay_us(I2C_DELAY); | ||
| 90 | |||
| 91 | I2C_DATA_LO(); | ||
| 92 | _delay_us(I2C_DELAY); | ||
| 93 | |||
| 94 | I2C_CLOCK_LO(); | ||
| 95 | _delay_us(I2C_DELAY); | ||
| 96 | } | ||
| 97 | |||
| 98 | // Send a STOP Condition | ||
| 99 | // | ||
| 100 | void I2C_Stop() | ||
| 101 | { | ||
| 102 | I2C_CLOCK_HI(); | ||
| 103 | _delay_us(I2C_DELAY); | ||
| 104 | |||
| 105 | I2C_DATA_HI(); | ||
| 106 | _delay_us(I2C_DELAY); | ||
| 107 | } | ||
| 108 | |||
| 109 | // write a byte to the I2C slave device | ||
| 110 | // | ||
| 111 | unsigned char I2C_Write(unsigned char c) | ||
| 112 | { | ||
| 113 | for (char i = 0; i < 8; i++) | ||
| 114 | { | ||
| 115 | I2C_WriteBit(c & 128); | ||
| 116 | |||
| 117 | c <<= 1; | ||
| 118 | } | ||
| 119 | |||
| 120 | |||
| 121 | I2C_WriteBit(0); | ||
| 122 | _delay_us(I2C_DELAY); | ||
| 123 | _delay_us(I2C_DELAY); | ||
| 124 | |||
| 125 | // _delay_us(I2C_DELAY); | ||
| 126 | //return I2C_ReadBit(); | ||
| 127 | return 0; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | #endif | ||
| 132 | |||
| 19 | // Setleds for standard RGB | 133 | // Setleds for standard RGB |
| 20 | void inline ws2812_setleds(struct cRGB *ledarray, uint16_t leds) | 134 | void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) |
| 21 | { | 135 | { |
| 22 | // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin)); | 136 | // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin)); |
| 23 | ws2812_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF)); | 137 | ws2812_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF)); |
| 24 | } | 138 | } |
| 25 | 139 | ||
| 26 | void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pinmask) | 140 | void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) |
| 27 | { | 141 | { |
| 28 | // ws2812_DDRREG |= pinmask; // Enable DDR | 142 | // ws2812_DDRREG |= pinmask; // Enable DDR |
| 29 | // new universal format (DDR) | 143 | // new universal format (DDR) |
| @@ -34,14 +148,41 @@ void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pin | |||
| 34 | } | 148 | } |
| 35 | 149 | ||
| 36 | // Setleds for SK6812RGBW | 150 | // Setleds for SK6812RGBW |
| 37 | void inline ws2812_setleds_rgbw(struct cRGBW *ledarray, uint16_t leds) | 151 | void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) |
| 38 | { | 152 | { |
| 153 | |||
| 154 | #ifdef RGBW_BB_TWI | ||
| 155 | uint8_t sreg_prev, twcr_prev; | ||
| 156 | sreg_prev=SREG; | ||
| 157 | twcr_prev=TWCR; | ||
| 158 | cli(); | ||
| 159 | TWCR &= ~(1<<TWEN); | ||
| 160 | I2C_Init(); | ||
| 161 | I2C_Start(); | ||
| 162 | I2C_Write(0x84); | ||
| 163 | uint16_t datlen = leds<<2; | ||
| 164 | uint8_t curbyte; | ||
| 165 | uint8_t * data = (uint8_t*)ledarray; | ||
| 166 | while (datlen--) { | ||
| 167 | curbyte=*data++; | ||
| 168 | I2C_Write(curbyte); | ||
| 169 | } | ||
| 170 | I2C_Stop(); | ||
| 171 | SREG=sreg_prev; | ||
| 172 | TWCR=twcr_prev; | ||
| 173 | #endif | ||
| 174 | |||
| 175 | |||
| 39 | // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR | 176 | // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR |
| 40 | // new universal format (DDR) | 177 | // new universal format (DDR) |
| 41 | _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF); | 178 | _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF); |
| 42 | 179 | ||
| 43 | ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(RGB_DI_PIN & 0xF)); | 180 | ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(RGB_DI_PIN & 0xF)); |
| 44 | _delay_us(80); | 181 | |
| 182 | |||
| 183 | #ifndef RGBW_BB_TWI | ||
| 184 | _delay_us(80); | ||
| 185 | #endif | ||
| 45 | } | 186 | } |
| 46 | 187 | ||
| 47 | void ws2812_sendarray(uint8_t *data,uint16_t datlen) | 188 | void ws2812_sendarray(uint8_t *data,uint16_t datlen) |
| @@ -123,7 +264,7 @@ void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi) | |||
| 123 | cli(); | 264 | cli(); |
| 124 | 265 | ||
| 125 | while (datlen--) { | 266 | while (datlen--) { |
| 126 | curbyte=*data++; | 267 | curbyte=(*data++); |
| 127 | 268 | ||
| 128 | asm volatile( | 269 | asm volatile( |
| 129 | " ldi %0,8 \n\t" | 270 | " ldi %0,8 \n\t" |
diff --git a/quantum/light_ws2812.h b/quantum/light_ws2812.h index 54eef22d9..9498e550e 100755 --- a/quantum/light_ws2812.h +++ b/quantum/light_ws2812.h | |||
| @@ -16,6 +16,21 @@ | |||
| 16 | #include <avr/io.h> | 16 | #include <avr/io.h> |
| 17 | #include <avr/interrupt.h> | 17 | #include <avr/interrupt.h> |
| 18 | //#include "ws2812_config.h" | 18 | //#include "ws2812_config.h" |
| 19 | //#include "i2cmaster.h" | ||
| 20 | |||
| 21 | #define LIGHT_I2C 1 | ||
| 22 | #define LIGHT_I2C_ADDR 0x84 | ||
| 23 | #define LIGHT_I2C_ADDR_WRITE ( (LIGHT_I2C_ADDR<<1) | I2C_WRITE ) | ||
| 24 | #define LIGHT_I2C_ADDR_READ ( (LIGHT_I2C_ADDR<<1) | I2C_READ ) | ||
| 25 | |||
| 26 | #define RGBW 1 | ||
| 27 | |||
| 28 | #ifdef RGBW | ||
| 29 | #define LED_TYPE struct cRGBW | ||
| 30 | #else | ||
| 31 | #define LED_TYPE struct cRGB | ||
| 32 | #endif | ||
| 33 | |||
| 19 | 34 | ||
| 20 | /* | 35 | /* |
| 21 | * Structure of the LED array | 36 | * Structure of the LED array |
| @@ -42,9 +57,9 @@ struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;}; | |||
| 42 | * - Wait 50�s to reset the LEDs | 57 | * - Wait 50�s to reset the LEDs |
| 43 | */ | 58 | */ |
| 44 | 59 | ||
| 45 | void ws2812_setleds (struct cRGB *ledarray, uint16_t number_of_leds); | 60 | void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds); |
| 46 | void ws2812_setleds_pin (struct cRGB *ledarray, uint16_t number_of_leds,uint8_t pinmask); | 61 | void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask); |
| 47 | void ws2812_setleds_rgbw(struct cRGBW *ledarray, uint16_t number_of_leds); | 62 | void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); |
| 48 | 63 | ||
| 49 | /* | 64 | /* |
| 50 | * Old interface / Internal functions | 65 | * Old interface / Internal functions |
diff --git a/quantum/process_keycode/process_printer.c b/quantum/process_keycode/process_printer.c new file mode 100644 index 000000000..2e11dd366 --- /dev/null +++ b/quantum/process_keycode/process_printer.c | |||
| @@ -0,0 +1,254 @@ | |||
| 1 | #include "process_printer.h" | ||
| 2 | #include "action_util.h" | ||
| 3 | |||
| 4 | bool printing_enabled = false; | ||
| 5 | uint8_t character_shift = 0; | ||
| 6 | |||
| 7 | void enabled_printing() { | ||
| 8 | printing_enabled = true; | ||
| 9 | serial_init(); | ||
| 10 | } | ||
| 11 | |||
| 12 | void disable_printing() { | ||
| 13 | printing_enabled = false; | ||
| 14 | } | ||
| 15 | |||
| 16 | uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; | ||
| 17 | |||
| 18 | // uint8_t keycode_to_ascii[0xFF][2]; | ||
| 19 | |||
| 20 | // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; | ||
| 21 | |||
| 22 | void print_char(char c) { | ||
| 23 | USB_Disable(); | ||
| 24 | serial_send(c); | ||
| 25 | USB_Init(); | ||
| 26 | } | ||
| 27 | |||
| 28 | void print_box_string(uint8_t text[]) { | ||
| 29 | uint8_t len = strlen(text); | ||
| 30 | uint8_t out[len * 3 + 8]; | ||
| 31 | out[0] = 0xDA; | ||
| 32 | for (uint8_t i = 0; i < len; i++) { | ||
| 33 | out[i+1] = 0xC4; | ||
| 34 | } | ||
| 35 | out[len + 1] = 0xBF; | ||
| 36 | out[len + 2] = '\n'; | ||
| 37 | |||
| 38 | out[len + 3] = 0xB3; | ||
| 39 | for (uint8_t i = 0; i < len; i++) { | ||
| 40 | out[len + 4 + i] = text[i]; | ||
| 41 | } | ||
| 42 | out[len * 2 + 4] = 0xB3; | ||
| 43 | out[len * 2 + 5] = '\n'; | ||
| 44 | |||
| 45 | |||
| 46 | out[len * 2 + 6] = 0xC0; | ||
| 47 | for (uint8_t i = 0; i < len; i++) { | ||
| 48 | out[len * 2 + 7 + i] = 0xC4; | ||
| 49 | } | ||
| 50 | out[len * 3 + 7] = 0xD9; | ||
| 51 | out[len * 3 + 8] = '\n'; | ||
| 52 | |||
| 53 | print_string(out); | ||
| 54 | } | ||
| 55 | |||
| 56 | void print_string(char c[]) { | ||
| 57 | for(uint8_t i = 0; i < strlen(c); i++) | ||
| 58 | print_char(c[i]); | ||
| 59 | } | ||
| 60 | |||
| 61 | bool process_printer(uint16_t keycode, keyrecord_t *record) { | ||
| 62 | if (keycode == PRINT_ON) { | ||
| 63 | enabled_printing(); | ||
| 64 | return false; | ||
| 65 | } | ||
| 66 | if (keycode == PRINT_OFF) { | ||
| 67 | disable_printing(); | ||
| 68 | return false; | ||
| 69 | } | ||
| 70 | |||
| 71 | if (printing_enabled) { | ||
| 72 | switch(keycode) { | ||
| 73 | case KC_EXLM ... KC_RPRN: | ||
| 74 | case KC_UNDS: | ||
| 75 | case KC_PLUS: | ||
| 76 | case KC_LCBR: | ||
| 77 | case KC_RCBR: | ||
| 78 | case KC_PIPE: | ||
| 79 | case KC_TILD: | ||
| 80 | keycode &= 0xFF; | ||
| 81 | case KC_LSFT: | ||
| 82 | case KC_RSFT: | ||
| 83 | if (record->event.pressed) { | ||
| 84 | character_shift++; | ||
| 85 | } else { | ||
| 86 | character_shift--; | ||
| 87 | } | ||
| 88 | return false; | ||
| 89 | break; | ||
| 90 | } | ||
| 91 | |||
| 92 | switch(keycode) { | ||
| 93 | case KC_F1: | ||
| 94 | if (record->event.pressed) { | ||
| 95 | print_box_string("This is a line of text!"); | ||
| 96 | } | ||
| 97 | return false; | ||
| 98 | case KC_ESC: | ||
| 99 | if (record->event.pressed) { | ||
| 100 | print_char(0x1B); | ||
| 101 | } | ||
| 102 | return false; | ||
| 103 | break; | ||
| 104 | case KC_SPC: | ||
| 105 | if (record->event.pressed) { | ||
| 106 | print_char(0x20); | ||
| 107 | } | ||
| 108 | return false; | ||
| 109 | break; | ||
| 110 | case KC_A ... KC_Z: | ||
| 111 | if (record->event.pressed) { | ||
| 112 | if (character_shift) { | ||
| 113 | print_char(0x41 + (keycode - KC_A)); | ||
| 114 | } else { | ||
| 115 | print_char(0x61 + (keycode - KC_A)); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | return false; | ||
| 119 | break; | ||
| 120 | case KC_1 ... KC_0: | ||
| 121 | if (record->event.pressed) { | ||
| 122 | if (character_shift) { | ||
| 123 | print_char(shifted_numbers[keycode - KC_1]); | ||
| 124 | } else { | ||
| 125 | print_char(0x30 + ((keycode - KC_1 + 1) % 10)); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | return false; | ||
| 129 | break; | ||
| 130 | case KC_ENT: | ||
| 131 | if (record->event.pressed) { | ||
| 132 | if (character_shift) { | ||
| 133 | print_char(0x0C); | ||
| 134 | } else { | ||
| 135 | print_char(0x0A); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | return false; | ||
| 139 | break; | ||
| 140 | case KC_BSPC: | ||
| 141 | if (record->event.pressed) { | ||
| 142 | if (character_shift) { | ||
| 143 | print_char(0x18); | ||
| 144 | } else { | ||
| 145 | print_char(0x1A); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | return false; | ||
| 149 | break; | ||
| 150 | case KC_DOT: | ||
| 151 | if (record->event.pressed) { | ||
| 152 | if (character_shift) { | ||
| 153 | print_char(0x3E); | ||
| 154 | } else { | ||
| 155 | print_char(0x2E); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | return false; | ||
| 159 | break; | ||
| 160 | case KC_COMM: | ||
| 161 | if (record->event.pressed) { | ||
| 162 | if (character_shift) { | ||
| 163 | print_char(0x3C); | ||
| 164 | } else { | ||
| 165 | print_char(0x2C); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | return false; | ||
| 169 | break; | ||
| 170 | case KC_SLSH: | ||
| 171 | if (record->event.pressed) { | ||
| 172 | if (character_shift) { | ||
| 173 | print_char(0x3F); | ||
| 174 | } else { | ||
| 175 | print_char(0x2F); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | return false; | ||
| 179 | break; | ||
| 180 | case KC_QUOT: | ||
| 181 | if (record->event.pressed) { | ||
| 182 | if (character_shift) { | ||
| 183 | print_char(0x22); | ||
| 184 | } else { | ||
| 185 | print_char(0x27); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | return false; | ||
| 189 | break; | ||
| 190 | case KC_GRV: | ||
| 191 | if (record->event.pressed) { | ||
| 192 | if (character_shift) { | ||
| 193 | print_char(0x7E); | ||
| 194 | } else { | ||
| 195 | print_char(0x60); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | return false; | ||
| 199 | break; | ||
| 200 | case KC_MINS: | ||
| 201 | if (record->event.pressed) { | ||
| 202 | if (character_shift) { | ||
| 203 | print_char(0x5F); | ||
| 204 | } else { | ||
| 205 | print_char(0x2D); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | return false; | ||
| 209 | break; | ||
| 210 | case KC_EQL: | ||
| 211 | if (record->event.pressed) { | ||
| 212 | if (character_shift) { | ||
| 213 | print_char(0x2B); | ||
| 214 | } else { | ||
| 215 | print_char(0x3D); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | return false; | ||
| 219 | break; | ||
| 220 | case KC_LBRC: | ||
| 221 | if (record->event.pressed) { | ||
| 222 | if (character_shift) { | ||
| 223 | print_char(0x7B); | ||
| 224 | } else { | ||
| 225 | print_char(0x5B); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | return false; | ||
| 229 | break; | ||
| 230 | case KC_RBRC: | ||
| 231 | if (record->event.pressed) { | ||
| 232 | if (character_shift) { | ||
| 233 | print_char(0x7D); | ||
| 234 | } else { | ||
| 235 | print_char(0x5D); | ||
| 236 | } | ||
| 237 | } | ||
| 238 | return false; | ||
| 239 | break; | ||
| 240 | case KC_BSLS: | ||
| 241 | if (record->event.pressed) { | ||
| 242 | if (character_shift) { | ||
| 243 | print_char(0x7C); | ||
| 244 | } else { | ||
| 245 | print_char(0x5C); | ||
| 246 | } | ||
| 247 | } | ||
| 248 | return false; | ||
| 249 | break; | ||
| 250 | } | ||
| 251 | } | ||
| 252 | return true; | ||
| 253 | |||
| 254 | } \ No newline at end of file | ||
diff --git a/quantum/process_keycode/process_printer.h b/quantum/process_keycode/process_printer.h new file mode 100644 index 000000000..fdd36d75a --- /dev/null +++ b/quantum/process_keycode/process_printer.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #ifndef PROCESS_PRINTER_H | ||
| 2 | #define PROCESS_PRINTER_H | ||
| 3 | |||
| 4 | #include "quantum.h" | ||
| 5 | |||
| 6 | #include "protocol/serial.h" | ||
| 7 | |||
| 8 | #endif \ No newline at end of file | ||
diff --git a/quantum/process_keycode/process_printer_bb.c b/quantum/process_keycode/process_printer_bb.c new file mode 100644 index 000000000..1924d0377 --- /dev/null +++ b/quantum/process_keycode/process_printer_bb.c | |||
| @@ -0,0 +1,260 @@ | |||
| 1 | #include "process_printer.h" | ||
| 2 | #include "action_util.h" | ||
| 3 | |||
| 4 | bool printing_enabled = false; | ||
| 5 | uint8_t character_shift = 0; | ||
| 6 | |||
| 7 | #define SERIAL_PIN_DDR DDRD | ||
| 8 | #define SERIAL_PIN_PORT PORTD | ||
| 9 | #define SERIAL_PIN_MASK _BV(PD3) | ||
| 10 | #define SERIAL_DELAY 52 | ||
| 11 | |||
| 12 | inline static | ||
| 13 | void serial_delay(void) { | ||
| 14 | _delay_us(SERIAL_DELAY); | ||
| 15 | } | ||
| 16 | |||
| 17 | inline static | ||
| 18 | void serial_high(void) { | ||
| 19 | SERIAL_PIN_PORT |= SERIAL_PIN_MASK; | ||
| 20 | } | ||
| 21 | |||
| 22 | inline static | ||
| 23 | void serial_low(void) { | ||
| 24 | SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; | ||
| 25 | } | ||
| 26 | |||
| 27 | inline static | ||
| 28 | void serial_output(void) { | ||
| 29 | SERIAL_PIN_DDR |= SERIAL_PIN_MASK; | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | void enabled_printing() { | ||
| 34 | printing_enabled = true; | ||
| 35 | serial_output(); | ||
| 36 | serial_high(); | ||
| 37 | } | ||
| 38 | |||
| 39 | void disable_printing() { | ||
| 40 | printing_enabled = false; | ||
| 41 | } | ||
| 42 | |||
| 43 | uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; | ||
| 44 | |||
| 45 | // uint8_t keycode_to_ascii[0xFF][2]; | ||
| 46 | |||
| 47 | // keycode_to_ascii[KC_MINS] = {0x2D, 0x5F}; | ||
| 48 | |||
| 49 | void print_char(char c) { | ||
| 50 | uint8_t b = 8; | ||
| 51 | serial_output(); | ||
| 52 | while( b-- ) { | ||
| 53 | if(c & (1 << b)) { | ||
| 54 | serial_high(); | ||
| 55 | } else { | ||
| 56 | serial_low(); | ||
| 57 | } | ||
| 58 | serial_delay(); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | void print_string(char c[]) { | ||
| 63 | for(uint8_t i = 0; i < strlen(c); i++) | ||
| 64 | print_char(c[i]); | ||
| 65 | } | ||
| 66 | |||
| 67 | bool process_printer(uint16_t keycode, keyrecord_t *record) { | ||
| 68 | if (keycode == PRINT_ON) { | ||
| 69 | enabled_printing(); | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | if (keycode == PRINT_OFF) { | ||
| 73 | disable_printing(); | ||
| 74 | return false; | ||
| 75 | } | ||
| 76 | |||
| 77 | if (printing_enabled) { | ||
| 78 | switch(keycode) { | ||
| 79 | case KC_EXLM ... KC_RPRN: | ||
| 80 | case KC_UNDS: | ||
| 81 | case KC_PLUS: | ||
| 82 | case KC_LCBR: | ||
| 83 | case KC_RCBR: | ||
| 84 | case KC_PIPE: | ||
| 85 | case KC_TILD: | ||
| 86 | keycode &= 0xFF; | ||
| 87 | case KC_LSFT: | ||
| 88 | case KC_RSFT: | ||
| 89 | if (record->event.pressed) { | ||
| 90 | character_shift++; | ||
| 91 | } else { | ||
| 92 | character_shift--; | ||
| 93 | } | ||
| 94 | return false; | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | |||
| 98 | switch(keycode) { | ||
| 99 | case KC_F1: | ||
| 100 | if (record->event.pressed) { | ||
| 101 | print_string("This is a line of text!\n\n\n"); | ||
| 102 | } | ||
| 103 | return false; | ||
| 104 | case KC_ESC: | ||
| 105 | if (record->event.pressed) { | ||
| 106 | print_char(0x1B); | ||
| 107 | } | ||
| 108 | return false; | ||
| 109 | break; | ||
| 110 | case KC_SPC: | ||
| 111 | if (record->event.pressed) { | ||
| 112 | print_char(0x20); | ||
| 113 | } | ||
| 114 | return false; | ||
| 115 | break; | ||
| 116 | case KC_A ... KC_Z: | ||
| 117 | if (record->event.pressed) { | ||
| 118 | if (character_shift) { | ||
| 119 | print_char(0x41 + (keycode - KC_A)); | ||
| 120 | } else { | ||
| 121 | print_char(0x61 + (keycode - KC_A)); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | return false; | ||
| 125 | break; | ||
| 126 | case KC_1 ... KC_0: | ||
| 127 | if (record->event.pressed) { | ||
| 128 | if (character_shift) { | ||
| 129 | print_char(shifted_numbers[keycode - KC_1]); | ||
| 130 | } else { | ||
| 131 | print_char(0x30 + ((keycode - KC_1 + 1) % 10)); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | return false; | ||
| 135 | break; | ||
| 136 | case KC_ENT: | ||
| 137 | if (record->event.pressed) { | ||
| 138 | if (character_shift) { | ||
| 139 | print_char(0x0C); | ||
| 140 | } else { | ||
| 141 | print_char(0x0A); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | return false; | ||
| 145 | break; | ||
| 146 | case KC_BSPC: | ||
| 147 | if (record->event.pressed) { | ||
| 148 | if (character_shift) { | ||
| 149 | print_char(0x18); | ||
| 150 | } else { | ||
| 151 | print_char(0x1A); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | return false; | ||
| 155 | break; | ||
| 156 | case KC_DOT: | ||
| 157 | if (record->event.pressed) { | ||
| 158 | if (character_shift) { | ||
| 159 | print_char(0x3E); | ||
| 160 | } else { | ||
| 161 | print_char(0x2E); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | return false; | ||
| 165 | break; | ||
| 166 | case KC_COMM: | ||
| 167 | if (record->event.pressed) { | ||
| 168 | if (character_shift) { | ||
| 169 | print_char(0x3C); | ||
| 170 | } else { | ||
| 171 | print_char(0x2C); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | return false; | ||
| 175 | break; | ||
| 176 | case KC_SLSH: | ||
| 177 | if (record->event.pressed) { | ||
| 178 | if (character_shift) { | ||
| 179 | print_char(0x3F); | ||
| 180 | } else { | ||
| 181 | print_char(0x2F); | ||
| 182 | } | ||
| 183 | } | ||
| 184 | return false; | ||
| 185 | break; | ||
| 186 | case KC_QUOT: | ||
| 187 | if (record->event.pressed) { | ||
| 188 | if (character_shift) { | ||
| 189 | print_char(0x22); | ||
| 190 | } else { | ||
| 191 | print_char(0x27); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | return false; | ||
| 195 | break; | ||
| 196 | case KC_GRV: | ||
| 197 | if (record->event.pressed) { | ||
| 198 | if (character_shift) { | ||
| 199 | print_char(0x7E); | ||
| 200 | } else { | ||
| 201 | print_char(0x60); | ||
| 202 | } | ||
| 203 | } | ||
| 204 | return false; | ||
| 205 | break; | ||
| 206 | case KC_MINS: | ||
| 207 | if (record->event.pressed) { | ||
| 208 | if (character_shift) { | ||
| 209 | print_char(0x5F); | ||
| 210 | } else { | ||
| 211 | print_char(0x2D); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | return false; | ||
| 215 | break; | ||
| 216 | case KC_EQL: | ||
| 217 | if (record->event.pressed) { | ||
| 218 | if (character_shift) { | ||
| 219 | print_char(0x2B); | ||
| 220 | } else { | ||
| 221 | print_char(0x3D); | ||
| 222 | } | ||
| 223 | } | ||
| 224 | return false; | ||
| 225 | break; | ||
| 226 | case KC_LBRC: | ||
| 227 | if (record->event.pressed) { | ||
| 228 | if (character_shift) { | ||
| 229 | print_char(0x7B); | ||
| 230 | } else { | ||
| 231 | print_char(0x5B); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | return false; | ||
| 235 | break; | ||
| 236 | case KC_RBRC: | ||
| 237 | if (record->event.pressed) { | ||
| 238 | if (character_shift) { | ||
| 239 | print_char(0x7D); | ||
| 240 | } else { | ||
| 241 | print_char(0x5D); | ||
| 242 | } | ||
| 243 | } | ||
| 244 | return false; | ||
| 245 | break; | ||
| 246 | case KC_BSLS: | ||
| 247 | if (record->event.pressed) { | ||
| 248 | if (character_shift) { | ||
| 249 | print_char(0x7C); | ||
| 250 | } else { | ||
| 251 | print_char(0x5C); | ||
| 252 | } | ||
| 253 | } | ||
| 254 | return false; | ||
| 255 | break; | ||
| 256 | } | ||
| 257 | } | ||
| 258 | return true; | ||
| 259 | |||
| 260 | } \ No newline at end of file | ||
diff --git a/quantum/quantum.c b/quantum/quantum.c index b5e2d60b9..f653564a6 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -134,6 +134,9 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 134 | #ifdef UCIS_ENABLE | 134 | #ifdef UCIS_ENABLE |
| 135 | process_ucis(keycode, record) && | 135 | process_ucis(keycode, record) && |
| 136 | #endif | 136 | #endif |
| 137 | #ifdef PRINTING_ENABLE | ||
| 138 | process_printer(keycode, record) && | ||
| 139 | #endif | ||
| 137 | #ifdef UNICODEMAP_ENABLE | 140 | #ifdef UNICODEMAP_ENABLE |
| 138 | process_unicode_map(keycode, record) && | 141 | process_unicode_map(keycode, record) && |
| 139 | #endif | 142 | #endif |
| @@ -806,6 +809,51 @@ void backlight_set(uint8_t level) | |||
| 806 | #endif // backlight | 809 | #endif // backlight |
| 807 | 810 | ||
| 808 | 811 | ||
| 812 | // Functions for spitting out values | ||
| 813 | // | ||
| 814 | |||
| 815 | void send_dword(uint32_t number) { // this might not actually work | ||
| 816 | uint16_t word = (number >> 16); | ||
| 817 | send_word(word); | ||
| 818 | send_word(number & 0xFFFFUL); | ||
| 819 | } | ||
| 820 | |||
| 821 | void send_word(uint16_t number) { | ||
| 822 | uint8_t byte = number >> 8; | ||
| 823 | send_byte(byte); | ||
| 824 | send_byte(number & 0xFF); | ||
| 825 | } | ||
| 826 | |||
| 827 | void send_byte(uint8_t number) { | ||
| 828 | uint8_t nibble = number >> 4; | ||
| 829 | send_nibble(nibble); | ||
| 830 | send_nibble(number & 0xF); | ||
| 831 | } | ||
| 832 | |||
| 833 | void send_nibble(uint8_t number) { | ||
| 834 | switch (number) { | ||
| 835 | case 0: | ||
| 836 | register_code(KC_0); | ||
| 837 | unregister_code(KC_0); | ||
| 838 | break; | ||
| 839 | case 1 ... 9: | ||
| 840 | register_code(KC_1 + (number - 1)); | ||
| 841 | unregister_code(KC_1 + (number - 1)); | ||
| 842 | break; | ||
| 843 | case 0xA ... 0xF: | ||
| 844 | register_code(KC_A + (number - 0xA)); | ||
| 845 | unregister_code(KC_A + (number - 0xA)); | ||
| 846 | break; | ||
| 847 | } | ||
| 848 | } | ||
| 849 | |||
| 850 | void api_send_unicode(uint32_t unicode) { | ||
| 851 | #ifdef API_ENABLE | ||
| 852 | uint8_t chunk[4]; | ||
| 853 | dword_to_bytes(unicode, chunk); | ||
| 854 | MT_SEND_DATA(DT_UNICODE, chunk, 5); | ||
| 855 | #endif | ||
| 856 | } | ||
| 809 | 857 | ||
| 810 | __attribute__ ((weak)) | 858 | __attribute__ ((weak)) |
| 811 | void led_set_user(uint8_t usb_led) { | 859 | void led_set_user(uint8_t usb_led) { |
diff --git a/quantum/quantum.h b/quantum/quantum.h index 0c6046649..e6adf974a 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -59,6 +59,10 @@ extern uint32_t default_layer_state; | |||
| 59 | 59 | ||
| 60 | #include "process_tap_dance.h" | 60 | #include "process_tap_dance.h" |
| 61 | 61 | ||
| 62 | #ifdef PRINTING_ENABLE | ||
| 63 | #include "process_printer.h" | ||
| 64 | #endif | ||
| 65 | |||
| 62 | #define SEND_STRING(str) send_string(PSTR(str)) | 66 | #define SEND_STRING(str) send_string(PSTR(str)) |
| 63 | void send_string(const char *str); | 67 | void send_string(const char *str); |
| 64 | 68 | ||
| @@ -106,8 +110,15 @@ void breathing_speed_dec(uint8_t value); | |||
| 106 | #endif | 110 | #endif |
| 107 | 111 | ||
| 108 | #endif | 112 | #endif |
| 113 | void send_dword(uint32_t number); | ||
| 114 | void send_word(uint16_t number); | ||
| 115 | void send_byte(uint8_t number); | ||
| 116 | void send_nibble(uint8_t number); | ||
| 117 | |||
| 109 | 118 | ||
| 110 | void led_set_user(uint8_t usb_led); | 119 | void led_set_user(uint8_t usb_led); |
| 111 | void led_set_kb(uint8_t usb_led); | 120 | void led_set_kb(uint8_t usb_led); |
| 112 | 121 | ||
| 122 | void api_send_unicode(uint32_t unicode); | ||
| 123 | |||
| 113 | #endif | 124 | #endif |
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index d550c5866..bb03d6e91 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -69,11 +69,12 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20}; | |||
| 69 | 69 | ||
| 70 | rgblight_config_t rgblight_config; | 70 | rgblight_config_t rgblight_config; |
| 71 | rgblight_config_t inmem_config; | 71 | rgblight_config_t inmem_config; |
| 72 | struct cRGB led[RGBLED_NUM]; | ||
| 73 | uint8_t rgblight_inited = 0; | ||
| 74 | 72 | ||
| 73 | LED_TYPE led[RGBLED_NUM]; | ||
| 74 | uint8_t rgblight_inited = 0; | ||
| 75 | bool rgblight_timer_enabled = false; | ||
| 75 | 76 | ||
| 76 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { | 77 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { |
| 77 | uint8_t r = 0, g = 0, b = 0, base, color; | 78 | uint8_t r = 0, g = 0, b = 0, base, color; |
| 78 | 79 | ||
| 79 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. | 80 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. |
| @@ -124,7 +125,7 @@ void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { | |||
| 124 | setrgb(r, g, b, led1); | 125 | setrgb(r, g, b, led1); |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1) { | 128 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { |
| 128 | (*led1).r = r; | 129 | (*led1).r = r; |
| 129 | (*led1).g = g; | 130 | (*led1).g = g; |
| 130 | (*led1).b = b; | 131 | (*led1).b = b; |
| @@ -141,9 +142,9 @@ void eeconfig_update_rgblight_default(void) { | |||
| 141 | dprintf("eeconfig_update_rgblight_default\n"); | 142 | dprintf("eeconfig_update_rgblight_default\n"); |
| 142 | rgblight_config.enable = 1; | 143 | rgblight_config.enable = 1; |
| 143 | rgblight_config.mode = 1; | 144 | rgblight_config.mode = 1; |
| 144 | rgblight_config.hue = 200; | 145 | rgblight_config.hue = 0; |
| 145 | rgblight_config.sat = 204; | 146 | rgblight_config.sat = 255; |
| 146 | rgblight_config.val = 204; | 147 | rgblight_config.val = 255; |
| 147 | eeconfig_update_rgblight(rgblight_config.raw); | 148 | eeconfig_update_rgblight(rgblight_config.raw); |
| 148 | } | 149 | } |
| 149 | void eeconfig_debug_rgblight(void) { | 150 | void eeconfig_debug_rgblight(void) { |
| @@ -173,7 +174,7 @@ void rgblight_init(void) { | |||
| 173 | } | 174 | } |
| 174 | eeconfig_debug_rgblight(); // display current eeprom values | 175 | eeconfig_debug_rgblight(); // display current eeprom values |
| 175 | 176 | ||
| 176 | #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) | 177 | #ifdef RGBLIGHT_ANIMATIONS |
| 177 | rgblight_timer_init(); // setup the timer | 178 | rgblight_timer_init(); // setup the timer |
| 178 | #endif | 179 | #endif |
| 179 | 180 | ||
| @@ -182,6 +183,19 @@ void rgblight_init(void) { | |||
| 182 | } | 183 | } |
| 183 | } | 184 | } |
| 184 | 185 | ||
| 186 | void rgblight_update_dword(uint32_t dword) { | ||
| 187 | rgblight_config.raw = dword; | ||
| 188 | eeconfig_update_rgblight(rgblight_config.raw); | ||
| 189 | if (rgblight_config.enable) | ||
| 190 | rgblight_mode(rgblight_config.mode); | ||
| 191 | else { | ||
| 192 | #ifdef RGBLIGHT_ANIMATIONS | ||
| 193 | rgblight_timer_disable(); | ||
| 194 | #endif | ||
| 195 | rgblight_set(); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 185 | void rgblight_increase(void) { | 199 | void rgblight_increase(void) { |
| 186 | uint8_t mode = 0; | 200 | uint8_t mode = 0; |
| 187 | if (rgblight_config.mode < RGBLIGHT_MODES) { | 201 | if (rgblight_config.mode < RGBLIGHT_MODES) { |
| @@ -220,7 +234,7 @@ void rgblight_mode(uint8_t mode) { | |||
| 220 | eeconfig_update_rgblight(rgblight_config.raw); | 234 | eeconfig_update_rgblight(rgblight_config.raw); |
| 221 | xprintf("rgblight mode: %u\n", rgblight_config.mode); | 235 | xprintf("rgblight mode: %u\n", rgblight_config.mode); |
| 222 | if (rgblight_config.mode == 1) { | 236 | if (rgblight_config.mode == 1) { |
| 223 | #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) | 237 | #ifdef RGBLIGHT_ANIMATIONS |
| 224 | rgblight_timer_disable(); | 238 | rgblight_timer_disable(); |
| 225 | #endif | 239 | #endif |
| 226 | } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) { | 240 | } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) { |
| @@ -230,7 +244,7 @@ void rgblight_mode(uint8_t mode) { | |||
| 230 | // MODE 15-20, snake | 244 | // MODE 15-20, snake |
| 231 | // MODE 21-23, knight | 245 | // MODE 21-23, knight |
| 232 | 246 | ||
| 233 | #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) | 247 | #ifdef RGBLIGHT_ANIMATIONS |
| 234 | rgblight_timer_enable(); | 248 | rgblight_timer_enable(); |
| 235 | #endif | 249 | #endif |
| 236 | } | 250 | } |
| @@ -244,7 +258,7 @@ void rgblight_toggle(void) { | |||
| 244 | if (rgblight_config.enable) { | 258 | if (rgblight_config.enable) { |
| 245 | rgblight_mode(rgblight_config.mode); | 259 | rgblight_mode(rgblight_config.mode); |
| 246 | } else { | 260 | } else { |
| 247 | #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) | 261 | #ifdef RGBLIGHT_ANIMATIONS |
| 248 | rgblight_timer_disable(); | 262 | rgblight_timer_disable(); |
| 249 | #endif | 263 | #endif |
| 250 | _delay_ms(50); | 264 | _delay_ms(50); |
| @@ -252,6 +266,13 @@ void rgblight_toggle(void) { | |||
| 252 | } | 266 | } |
| 253 | } | 267 | } |
| 254 | 268 | ||
| 269 | void rgblight_enable(void) { | ||
| 270 | rgblight_config.enable = 1; | ||
| 271 | eeconfig_update_rgblight(rgblight_config.raw); | ||
| 272 | xprintf("rgblight enable: rgblight_config.enable = %u\n", rgblight_config.enable); | ||
| 273 | rgblight_mode(rgblight_config.mode); | ||
| 274 | } | ||
| 275 | |||
| 255 | 276 | ||
| 256 | void rgblight_increase_hue(void) { | 277 | void rgblight_increase_hue(void) { |
| 257 | uint16_t hue; | 278 | uint16_t hue; |
| @@ -307,7 +328,7 @@ void rgblight_decrease_val(void) { | |||
| 307 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | 328 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { |
| 308 | inmem_config.raw = rgblight_config.raw; | 329 | inmem_config.raw = rgblight_config.raw; |
| 309 | if (rgblight_config.enable) { | 330 | if (rgblight_config.enable) { |
| 310 | struct cRGB tmp_led; | 331 | LED_TYPE tmp_led; |
| 311 | sethsv(hue, sat, val, &tmp_led); | 332 | sethsv(hue, sat, val, &tmp_led); |
| 312 | inmem_config.hue = hue; | 333 | inmem_config.hue = hue; |
| 313 | inmem_config.sat = sat; | 334 | inmem_config.sat = sat; |
| @@ -351,66 +372,78 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { | |||
| 351 | 372 | ||
| 352 | void rgblight_set(void) { | 373 | void rgblight_set(void) { |
| 353 | if (rgblight_config.enable) { | 374 | if (rgblight_config.enable) { |
| 354 | ws2812_setleds(led, RGBLED_NUM); | 375 | #ifdef RGBW |
| 376 | ws2812_setleds_rgbw(led, RGBLED_NUM); | ||
| 377 | #else | ||
| 378 | ws2812_setleds(led, RGBLED_NUM); | ||
| 379 | #endif | ||
| 355 | } else { | 380 | } else { |
| 356 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 381 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 357 | led[i].r = 0; | 382 | led[i].r = 0; |
| 358 | led[i].g = 0; | 383 | led[i].g = 0; |
| 359 | led[i].b = 0; | 384 | led[i].b = 0; |
| 360 | } | 385 | } |
| 361 | ws2812_setleds(led, RGBLED_NUM); | 386 | #ifdef RGBW |
| 387 | ws2812_setleds_rgbw(led, RGBLED_NUM); | ||
| 388 | #else | ||
| 389 | ws2812_setleds(led, RGBLED_NUM); | ||
| 390 | #endif | ||
| 362 | } | 391 | } |
| 363 | } | 392 | } |
| 364 | 393 | ||
| 365 | #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) | 394 | #ifdef RGBLIGHT_ANIMATIONS |
| 366 | 395 | ||
| 367 | // Animation timer -- AVR Timer3 | 396 | // Animation timer -- AVR Timer3 |
| 368 | void rgblight_timer_init(void) { | 397 | void rgblight_timer_init(void) { |
| 369 | static uint8_t rgblight_timer_is_init = 0; | 398 | // static uint8_t rgblight_timer_is_init = 0; |
| 370 | if (rgblight_timer_is_init) { | 399 | // if (rgblight_timer_is_init) { |
| 371 | return; | 400 | // return; |
| 372 | } | 401 | // } |
| 373 | rgblight_timer_is_init = 1; | 402 | // rgblight_timer_is_init = 1; |
| 374 | /* Timer 3 setup */ | 403 | // /* Timer 3 setup */ |
| 375 | TCCR3B = _BV(WGM32) //CTC mode OCR3A as TOP | 404 | // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP |
| 376 | | _BV(CS30); //Clock selelct: clk/1 | 405 | // | _BV(CS30); // Clock selelct: clk/1 |
| 377 | /* Set TOP value */ | 406 | // /* Set TOP value */ |
| 378 | uint8_t sreg = SREG; | 407 | // uint8_t sreg = SREG; |
| 379 | cli(); | 408 | // cli(); |
| 380 | OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; | 409 | // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; |
| 381 | OCR3AL = RGBLED_TIMER_TOP & 0xff; | 410 | // OCR3AL = RGBLED_TIMER_TOP & 0xff; |
| 382 | SREG = sreg; | 411 | // SREG = sreg; |
| 412 | |||
| 413 | rgblight_timer_enabled = true; | ||
| 383 | } | 414 | } |
| 384 | void rgblight_timer_enable(void) { | 415 | void rgblight_timer_enable(void) { |
| 385 | TIMSK3 |= _BV(OCIE3A); | 416 | rgblight_timer_enabled = true; |
| 386 | dprintf("TIMER3 enabled.\n"); | 417 | dprintf("TIMER3 enabled.\n"); |
| 387 | } | 418 | } |
| 388 | void rgblight_timer_disable(void) { | 419 | void rgblight_timer_disable(void) { |
| 389 | TIMSK3 &= ~_BV(OCIE3A); | 420 | rgblight_timer_enabled = false; |
| 390 | dprintf("TIMER3 disabled.\n"); | 421 | dprintf("TIMER3 disabled.\n"); |
| 391 | } | 422 | } |
| 392 | void rgblight_timer_toggle(void) { | 423 | void rgblight_timer_toggle(void) { |
| 393 | TIMSK3 ^= _BV(OCIE3A); | 424 | rgblight_timer_enabled ^= rgblight_timer_enabled; |
| 394 | dprintf("TIMER3 toggled.\n"); | 425 | dprintf("TIMER3 toggled.\n"); |
| 395 | } | 426 | } |
| 396 | 427 | ||
| 397 | ISR(TIMER3_COMPA_vect) { | 428 | void rgblight_task(void) { |
| 398 | // mode = 1, static light, do nothing here | 429 | if (rgblight_timer_enabled) { |
| 399 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { | 430 | // mode = 1, static light, do nothing here |
| 400 | // mode = 2 to 5, breathing mode | 431 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { |
| 401 | rgblight_effect_breathing(rgblight_config.mode - 2); | 432 | // mode = 2 to 5, breathing mode |
| 402 | } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) { | 433 | rgblight_effect_breathing(rgblight_config.mode - 2); |
| 403 | // mode = 6 to 8, rainbow mood mod | 434 | } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) { |
| 404 | rgblight_effect_rainbow_mood(rgblight_config.mode - 6); | 435 | // mode = 6 to 8, rainbow mood mod |
| 405 | } else if (rgblight_config.mode >= 9 && rgblight_config.mode <= 14) { | 436 | rgblight_effect_rainbow_mood(rgblight_config.mode - 6); |
| 406 | // mode = 9 to 14, rainbow swirl mode | 437 | } else if (rgblight_config.mode >= 9 && rgblight_config.mode <= 14) { |
| 407 | rgblight_effect_rainbow_swirl(rgblight_config.mode - 9); | 438 | // mode = 9 to 14, rainbow swirl mode |
| 408 | } else if (rgblight_config.mode >= 15 && rgblight_config.mode <= 20) { | 439 | rgblight_effect_rainbow_swirl(rgblight_config.mode - 9); |
| 409 | // mode = 15 to 20, snake mode | 440 | } else if (rgblight_config.mode >= 15 && rgblight_config.mode <= 20) { |
| 410 | rgblight_effect_snake(rgblight_config.mode - 15); | 441 | // mode = 15 to 20, snake mode |
| 411 | } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) { | 442 | rgblight_effect_snake(rgblight_config.mode - 15); |
| 412 | // mode = 21 to 23, knight mode | 443 | } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) { |
| 413 | rgblight_effect_knight(rgblight_config.mode - 21); | 444 | // mode = 21 to 23, knight mode |
| 445 | rgblight_effect_knight(rgblight_config.mode - 21); | ||
| 446 | } | ||
| 414 | } | 447 | } |
| 415 | } | 448 | } |
| 416 | 449 | ||
| @@ -449,7 +482,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { | |||
| 449 | last_timer = timer_read(); | 482 | last_timer = timer_read(); |
| 450 | for (i = 0; i < RGBLED_NUM; i++) { | 483 | for (i = 0; i < RGBLED_NUM; i++) { |
| 451 | hue = (360 / RGBLED_NUM * i + current_hue) % 360; | 484 | hue = (360 / RGBLED_NUM * i + current_hue) % 360; |
| 452 | sethsv(hue, rgblight_config.sat, rgblight_config.val, &led[i]); | 485 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); |
| 453 | } | 486 | } |
| 454 | rgblight_set(); | 487 | rgblight_set(); |
| 455 | 488 | ||
| @@ -486,7 +519,7 @@ void rgblight_effect_snake(uint8_t interval) { | |||
| 486 | k = k + RGBLED_NUM; | 519 | k = k + RGBLED_NUM; |
| 487 | } | 520 | } |
| 488 | if (i == k) { | 521 | if (i == k) { |
| 489 | sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), &led[i]); | 522 | sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), (LED_TYPE *)&led[i]); |
| 490 | } | 523 | } |
| 491 | } | 524 | } |
| 492 | } | 525 | } |
| @@ -506,7 +539,7 @@ void rgblight_effect_knight(uint8_t interval) { | |||
| 506 | static uint16_t last_timer = 0; | 539 | static uint16_t last_timer = 0; |
| 507 | uint8_t i, j, cur; | 540 | uint8_t i, j, cur; |
| 508 | int8_t k; | 541 | int8_t k; |
| 509 | struct cRGB preled[RGBLED_NUM]; | 542 | LED_TYPE preled[RGBLED_NUM]; |
| 510 | static int8_t increment = -1; | 543 | static int8_t increment = -1; |
| 511 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { | 544 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { |
| 512 | return; | 545 | return; |
| @@ -525,7 +558,7 @@ void rgblight_effect_knight(uint8_t interval) { | |||
| 525 | k = RGBLED_NUM - 1; | 558 | k = RGBLED_NUM - 1; |
| 526 | } | 559 | } |
| 527 | if (i == k) { | 560 | if (i == k) { |
| 528 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, &preled[i]); | 561 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&preled[i]); |
| 529 | } | 562 | } |
| 530 | } | 563 | } |
| 531 | } | 564 | } |
diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 17f04ffcf..28a410e48 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | #ifndef RGBLIGHT_H | 1 | #ifndef RGBLIGHT_H |
| 2 | #define RGBLIGHT_H | 2 | #define RGBLIGHT_H |
| 3 | 3 | ||
| 4 | 4 | #ifdef RGBLIGHT_ANIMATIONS | |
| 5 | #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER) | ||
| 6 | #define RGBLIGHT_MODES 23 | 5 | #define RGBLIGHT_MODES 23 |
| 7 | #else | 6 | #else |
| 8 | #define RGBLIGHT_MODES 1 | 7 | #define RGBLIGHT_MODES 1 |
| @@ -34,6 +33,7 @@ | |||
| 34 | #endif | 33 | #endif |
| 35 | 34 | ||
| 36 | #define RGBLED_TIMER_TOP F_CPU/(256*64) | 35 | #define RGBLED_TIMER_TOP F_CPU/(256*64) |
| 36 | // #define RGBLED_TIMER_TOP 0xFF10 | ||
| 37 | 37 | ||
| 38 | #include <stdint.h> | 38 | #include <stdint.h> |
| 39 | #include <stdbool.h> | 39 | #include <stdbool.h> |
| @@ -61,9 +61,11 @@ void rgblight_init(void); | |||
| 61 | void rgblight_increase(void); | 61 | void rgblight_increase(void); |
| 62 | void rgblight_decrease(void); | 62 | void rgblight_decrease(void); |
| 63 | void rgblight_toggle(void); | 63 | void rgblight_toggle(void); |
| 64 | void rgblight_enable(void); | ||
| 64 | void rgblight_step(void); | 65 | void rgblight_step(void); |
| 65 | void rgblight_mode(uint8_t mode); | 66 | void rgblight_mode(uint8_t mode); |
| 66 | void rgblight_set(void); | 67 | void rgblight_set(void); |
| 68 | void rgblight_update_dword(uint32_t dword); | ||
| 67 | void rgblight_increase_hue(void); | 69 | void rgblight_increase_hue(void); |
| 68 | void rgblight_decrease_hue(void); | 70 | void rgblight_decrease_hue(void); |
| 69 | void rgblight_increase_sat(void); | 71 | void rgblight_increase_sat(void); |
| @@ -78,10 +80,13 @@ void eeconfig_update_rgblight(uint32_t val); | |||
| 78 | void eeconfig_update_rgblight_default(void); | 80 | void eeconfig_update_rgblight_default(void); |
| 79 | void eeconfig_debug_rgblight(void); | 81 | void eeconfig_debug_rgblight(void); |
| 80 | 82 | ||
| 81 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1); | 83 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); |
| 82 | void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1); | 84 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); |
| 83 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); | 85 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); |
| 84 | 86 | ||
| 87 | |||
| 88 | void rgblight_task(void); | ||
| 89 | |||
| 85 | void rgblight_timer_init(void); | 90 | void rgblight_timer_init(void); |
| 86 | void rgblight_timer_enable(void); | 91 | void rgblight_timer_enable(void); |
| 87 | void rgblight_timer_disable(void); | 92 | void rgblight_timer_disable(void); |
