diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
| commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
| tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/api.c | |
| parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
| download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip | |
clang-format changes
Diffstat (limited to 'quantum/api.c')
| -rw-r--r-- | quantum/api.c | 115 |
1 files changed, 51 insertions, 64 deletions
diff --git a/quantum/api.c b/quantum/api.c index 233f99636..168574458 100644 --- a/quantum/api.c +++ b/quantum/api.c | |||
| @@ -17,40 +17,28 @@ | |||
| 17 | #include "api.h" | 17 | #include "api.h" |
| 18 | #include "quantum.h" | 18 | #include "quantum.h" |
| 19 | 19 | ||
| 20 | void dword_to_bytes(uint32_t dword, uint8_t * bytes) { | 20 | void dword_to_bytes(uint32_t dword, uint8_t* bytes) { |
| 21 | bytes[0] = (dword >> 24) & 0xFF; | 21 | bytes[0] = (dword >> 24) & 0xFF; |
| 22 | bytes[1] = (dword >> 16) & 0xFF; | 22 | bytes[1] = (dword >> 16) & 0xFF; |
| 23 | bytes[2] = (dword >> 8) & 0xFF; | 23 | bytes[2] = (dword >> 8) & 0xFF; |
| 24 | bytes[3] = (dword >> 0) & 0xFF; | 24 | bytes[3] = (dword >> 0) & 0xFF; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index) { | 27 | uint32_t bytes_to_dword(uint8_t* bytes, uint8_t index) { return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3]; } |
| 28 | return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3]; | ||
| 29 | } | ||
| 30 | 28 | ||
| 31 | __attribute__ ((weak)) | 29 | __attribute__((weak)) bool process_api_quantum(uint8_t length, uint8_t* data) { return process_api_keyboard(length, data); } |
| 32 | bool process_api_quantum(uint8_t length, uint8_t * data) { | ||
| 33 | return process_api_keyboard(length, data); | ||
| 34 | } | ||
| 35 | 30 | ||
| 36 | __attribute__ ((weak)) | 31 | __attribute__((weak)) bool process_api_keyboard(uint8_t length, uint8_t* data) { return process_api_user(length, data); } |
| 37 | bool process_api_keyboard(uint8_t length, uint8_t * data) { | ||
| 38 | return process_api_user(length, data); | ||
| 39 | } | ||
| 40 | 32 | ||
| 41 | __attribute__ ((weak)) | 33 | __attribute__((weak)) bool process_api_user(uint8_t length, uint8_t* data) { return true; } |
| 42 | bool process_api_user(uint8_t length, uint8_t * data) { | ||
| 43 | return true; | ||
| 44 | } | ||
| 45 | 34 | ||
| 46 | void process_api(uint16_t length, uint8_t * data) { | 35 | void process_api(uint16_t length, uint8_t* data) { |
| 47 | // SEND_STRING("\nRX: "); | 36 | // SEND_STRING("\nRX: "); |
| 48 | // for (uint8_t i = 0; i < length; i++) { | 37 | // for (uint8_t i = 0; i < length; i++) { |
| 49 | // send_byte(data[i]); | 38 | // send_byte(data[i]); |
| 50 | // SEND_STRING(" "); | 39 | // SEND_STRING(" "); |
| 51 | // } | 40 | // } |
| 52 | if (!process_api_quantum(length, data)) | 41 | if (!process_api_quantum(length, data)) return; |
| 53 | return; | ||
| 54 | 42 | ||
| 55 | switch (data[0]) { | 43 | switch (data[0]) { |
| 56 | case MT_SET_DATA: | 44 | case MT_SET_DATA: |
| @@ -65,10 +53,10 @@ void process_api(uint16_t length, uint8_t * data) { | |||
| 65 | break; | 53 | break; |
| 66 | } | 54 | } |
| 67 | case DT_RGBLIGHT: { | 55 | case DT_RGBLIGHT: { |
| 68 | #ifdef RGBLIGHT_ENABLE | 56 | #ifdef RGBLIGHT_ENABLE |
| 69 | uint32_t rgblight = bytes_to_dword(data, 2); | 57 | uint32_t rgblight = bytes_to_dword(data, 2); |
| 70 | eeconfig_update_rgblight(rgblight); | 58 | eeconfig_update_rgblight(rgblight); |
| 71 | #endif | 59 | #endif |
| 72 | break; | 60 | break; |
| 73 | } | 61 | } |
| 74 | } | 62 | } |
| @@ -79,12 +67,12 @@ void process_api(uint16_t length, uint8_t * data) { | |||
| 79 | break; | 67 | break; |
| 80 | } | 68 | } |
| 81 | case DT_DEBUG: { | 69 | case DT_DEBUG: { |
| 82 | uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) }; | 70 | uint8_t debug_bytes[1] = {eeprom_read_byte(EECONFIG_DEBUG)}; |
| 83 | MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1); | 71 | MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1); |
| 84 | break; | 72 | break; |
| 85 | } | 73 | } |
| 86 | case DT_DEFAULT_LAYER: { | 74 | case DT_DEFAULT_LAYER: { |
| 87 | uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) }; | 75 | uint8_t default_bytes[1] = {eeprom_read_byte(EECONFIG_DEFAULT_LAYER)}; |
| 88 | MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1); | 76 | MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1); |
| 89 | break; | 77 | break; |
| 90 | } | 78 | } |
| @@ -95,35 +83,35 @@ void process_api(uint16_t length, uint8_t * data) { | |||
| 95 | break; | 83 | break; |
| 96 | } | 84 | } |
| 97 | case DT_AUDIO: { | 85 | case DT_AUDIO: { |
| 98 | #ifdef AUDIO_ENABLE | 86 | #ifdef AUDIO_ENABLE |
| 99 | uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) }; | 87 | uint8_t audio_bytes[1] = {eeprom_read_byte(EECONFIG_AUDIO)}; |
| 100 | MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1); | 88 | MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1); |
| 101 | #else | 89 | #else |
| 102 | MT_GET_DATA_ACK(DT_AUDIO, NULL, 0); | 90 | MT_GET_DATA_ACK(DT_AUDIO, NULL, 0); |
| 103 | #endif | 91 | #endif |
| 104 | break; | 92 | break; |
| 105 | } | 93 | } |
| 106 | case DT_BACKLIGHT: { | 94 | case DT_BACKLIGHT: { |
| 107 | #ifdef BACKLIGHT_ENABLE | 95 | #ifdef BACKLIGHT_ENABLE |
| 108 | uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) }; | 96 | uint8_t backlight_bytes[1] = {eeprom_read_byte(EECONFIG_BACKLIGHT)}; |
| 109 | MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1); | 97 | MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1); |
| 110 | #else | 98 | #else |
| 111 | MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0); | 99 | MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0); |
| 112 | #endif | 100 | #endif |
| 113 | break; | 101 | break; |
| 114 | } | 102 | } |
| 115 | case DT_RGBLIGHT: { | 103 | case DT_RGBLIGHT: { |
| 116 | #ifdef RGBLIGHT_ENABLE | 104 | #ifdef RGBLIGHT_ENABLE |
| 117 | uint8_t rgblight_bytes[4]; | 105 | uint8_t rgblight_bytes[4]; |
| 118 | dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes); | 106 | dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes); |
| 119 | MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4); | 107 | MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4); |
| 120 | #else | 108 | #else |
| 121 | MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0); | 109 | MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0); |
| 122 | #endif | 110 | #endif |
| 123 | break; | 111 | break; |
| 124 | } | 112 | } |
| 125 | case DT_KEYMAP_OPTIONS: { | 113 | case DT_KEYMAP_OPTIONS: { |
| 126 | uint8_t keymap_bytes[1] = { eeconfig_read_keymap() }; | 114 | uint8_t keymap_bytes[1] = {eeconfig_read_keymap()}; |
| 127 | MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1); | 115 | MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1); |
| 128 | break; | 116 | break; |
| 129 | } | 117 | } |
| @@ -172,24 +160,23 @@ void process_api(uint16_t length, uint8_t * data) { | |||
| 172 | break; | 160 | break; |
| 173 | case MT_TYPE_ERROR: | 161 | case MT_TYPE_ERROR: |
| 174 | break; | 162 | break; |
| 175 | default: ; // command not recognised | 163 | default:; // command not recognised |
| 176 | SEND_BYTES(MT_TYPE_ERROR, DT_NONE, data, length); | 164 | SEND_BYTES(MT_TYPE_ERROR, DT_NONE, data, length); |
| 177 | break; | 165 | break; |
| 178 | 166 | ||
| 179 | // #ifdef RGBLIGHT_ENABLE | 167 | // #ifdef RGBLIGHT_ENABLE |
| 180 | // case 0x27: ; // RGB LED functions | 168 | // case 0x27: ; // RGB LED functions |
| 181 | // switch (*data++) { | 169 | // switch (*data++) { |
| 182 | // case 0x00: ; // Update HSV | 170 | // case 0x00: ; // Update HSV |
| 183 | // rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]); | 171 | // rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]); |
| 184 | // break; | 172 | // break; |
| 185 | // case 0x01: ; // Update RGB | 173 | // case 0x01: ; // Update RGB |
| 186 | // break; | 174 | // break; |
| 187 | // case 0x02: ; // Update mode | 175 | // case 0x02: ; // Update mode |
| 188 | // rgblight_mode(data[0]); | 176 | // rgblight_mode(data[0]); |
| 189 | // break; | 177 | // break; |
| 190 | // } | 178 | // } |
| 191 | // break; | 179 | // break; |
| 192 | // #endif | 180 | // #endif |
| 193 | } | 181 | } |
| 194 | |||
| 195 | } | 182 | } |
