aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed M Lin <tedmlin@gmail.com>2020-02-06 20:53:43 -0500
committerGitHub <noreply@github.com>2020-02-07 12:53:43 +1100
commitd84eb14b3a8516c2a16b69d09dc31e3a9f21122b (patch)
tree1b931c131e0a297aa13733b900c9b933954e0260
parentfe814be287bc0591df87549ea6233eae2177e062 (diff)
downloadqmk_firmware-d84eb14b3a8516c2a16b69d09dc31e3a9f21122b.tar.gz
qmk_firmware-d84eb14b3a8516c2a16b69d09dc31e3a9f21122b.zip
Use function for KEYCODE2 routines instead of macro. (#8101)
* Option to use function for KEYCODE2 routines. Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions, defaulting to using the macros. The function form allows the compiler to optimize the switch statement itself, over the macro nested ternaries. To enable this feature, #define USE_KEYCODE2_FUNCTION. Testing against a random selection of avr-based keyboards, this increased available flash by ~500 bytes. For arm-based keyboards, the available flash increased by ~400 bytes. * Replace macro with function entirely. As zvecr states, go bold and just commit to using the function instead of the macro. * Reformat whitespace now that functional review is done Verified against clang-format output.
-rw-r--r--tmk_core/common/report.h67
1 files changed, 64 insertions, 3 deletions
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index 2a9dad881..ecd5da89a 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -167,11 +167,72 @@ typedef struct {
167} __attribute__((packed)) report_mouse_t; 167} __attribute__((packed)) report_mouse_t;
168 168
169/* keycode to system usage */ 169/* keycode to system usage */
170#define KEYCODE2SYSTEM(key) (key == KC_SYSTEM_POWER ? SYSTEM_POWER_DOWN : (key == KC_SYSTEM_SLEEP ? SYSTEM_SLEEP : (key == KC_SYSTEM_WAKE ? SYSTEM_WAKE_UP : 0))) 170static inline uint16_t KEYCODE2SYSTEM(uint8_t key) {
171 switch (key) {
172 case KC_SYSTEM_POWER:
173 return SYSTEM_POWER_DOWN;
174 case KC_SYSTEM_SLEEP:
175 return SYSTEM_SLEEP;
176 case KC_SYSTEM_WAKE:
177 return SYSTEM_WAKE_UP;
178 default:
179 return 0;
180 }
181}
171 182
172/* keycode to consumer usage */ 183/* keycode to consumer usage */
173#define KEYCODE2CONSUMER(key) \ 184static inline uint16_t KEYCODE2CONSUMER(uint8_t key) {
174 (key == KC_AUDIO_MUTE ? AUDIO_MUTE : (key == KC_AUDIO_VOL_UP ? AUDIO_VOL_UP : (key == KC_AUDIO_VOL_DOWN ? AUDIO_VOL_DOWN : (key == KC_MEDIA_NEXT_TRACK ? TRANSPORT_NEXT_TRACK : (key == KC_MEDIA_PREV_TRACK ? TRANSPORT_PREV_TRACK : (key == KC_MEDIA_FAST_FORWARD ? TRANSPORT_FAST_FORWARD : (key == KC_MEDIA_REWIND ? TRANSPORT_REWIND : (key == KC_MEDIA_STOP ? TRANSPORT_STOP : (key == KC_MEDIA_EJECT ? TRANSPORT_STOP_EJECT : (key == KC_MEDIA_PLAY_PAUSE ? TRANSPORT_PLAY_PAUSE : (key == KC_MEDIA_SELECT ? AL_CC_CONFIG : (key == KC_MAIL ? AL_EMAIL : (key == KC_CALCULATOR ? AL_CALCULATOR : (key == KC_MY_COMPUTER ? AL_LOCAL_BROWSER : (key == KC_WWW_SEARCH ? AC_SEARCH : (key == KC_WWW_HOME ? AC_HOME : (key == KC_WWW_BACK ? AC_BACK : (key == KC_WWW_FORWARD ? AC_FORWARD : (key == KC_WWW_STOP ? AC_STOP : (key == KC_WWW_REFRESH ? AC_REFRESH : (key == KC_BRIGHTNESS_UP ? BRIGHTNESS_UP : (key == KC_BRIGHTNESS_DOWN ? BRIGHTNESS_DOWN : (key == KC_WWW_FAVORITES ? AC_BOOKMARKS : 0))))))))))))))))))))))) 185 switch (key) {
186 case KC_AUDIO_MUTE:
187 return AUDIO_MUTE;
188 case KC_AUDIO_VOL_UP:
189 return AUDIO_VOL_UP;
190 case KC_AUDIO_VOL_DOWN:
191 return AUDIO_VOL_DOWN;
192 case KC_MEDIA_NEXT_TRACK:
193 return TRANSPORT_NEXT_TRACK;
194 case KC_MEDIA_PREV_TRACK:
195 return TRANSPORT_PREV_TRACK;
196 case KC_MEDIA_FAST_FORWARD:
197 return TRANSPORT_FAST_FORWARD;
198 case KC_MEDIA_REWIND:
199 return TRANSPORT_REWIND;
200 case KC_MEDIA_STOP:
201 return TRANSPORT_STOP;
202 case KC_MEDIA_EJECT:
203 return TRANSPORT_STOP_EJECT;
204 case KC_MEDIA_PLAY_PAUSE:
205 return TRANSPORT_PLAY_PAUSE;
206 case KC_MEDIA_SELECT:
207 return AL_CC_CONFIG;
208 case KC_MAIL:
209 return AL_EMAIL;
210 case KC_CALCULATOR:
211 return AL_CALCULATOR;
212 case KC_MY_COMPUTER:
213 return AL_LOCAL_BROWSER;
214 case KC_WWW_SEARCH:
215 return AC_SEARCH;
216 case KC_WWW_HOME:
217 return AC_HOME;
218 case KC_WWW_BACK:
219 return AC_BACK;
220 case KC_WWW_FORWARD:
221 return AC_FORWARD;
222 case KC_WWW_STOP:
223 return AC_STOP;
224 case KC_WWW_REFRESH:
225 return AC_REFRESH;
226 case KC_BRIGHTNESS_UP:
227 return BRIGHTNESS_UP;
228 case KC_BRIGHTNESS_DOWN:
229 return BRIGHTNESS_DOWN;
230 case KC_WWW_FAVORITES:
231 return AC_BOOKMARKS;
232 default:
233 return 0;
234 }
235}
175 236
176uint8_t has_anykey(report_keyboard_t* keyboard_report); 237uint8_t has_anykey(report_keyboard_t* keyboard_report);
177uint8_t get_first_key(report_keyboard_t* keyboard_report); 238uint8_t get_first_key(report_keyboard_t* keyboard_report);