/* * This file is part of the flashrom project. * * Copyright 2021 Google LLC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include "lifecycle.h" static void probe_chip(const struct programmer_entry *prog, struct flashrom_programmer *flashprog, const char *const chip_name) { struct flashrom_flashctx *flashctx; printf("Testing flashrom_flash_probe for programmer=%s, chip=%s ... \n", prog->name, chip_name); assert_int_equal(0, flashrom_flash_probe(&flashctx, flashprog, chip_name)); printf("... flashrom_flash_probe for programmer=%s successful\n", prog->name); flashrom_flash_release(flashctx); /* cleanup */ } static void run_lifecycle(void **state, const struct io_mock *io, const struct programmer_entry *prog, const char *param, const char *const chip_name, void (*action)(const struct programmer_entry *prog, struct flashrom_programmer *flashprog, const char *const chip_name)) { (void) state; /* unused */ io_mock_register(io); struct flashrom_programmer *flashprog; char *param_dup = param ? strdup(param) : NULL; printf("Testing flashrom_programmer_init for programmer=%s ...\n", prog->name); assert_int_equal(0, flashrom_programmer_init(&flashprog, prog->name, param_dup)); printf("... flashrom_programmer_init for programmer=%s successful\n", prog->name); if (action) action(prog, flashprog, chip_name); printf("Testing flashrom_programmer_shutdown for programmer=%s ...\n", prog->name); assert_int_equal(0, flashrom_programmer_shutdown(flashprog)); printf("... flashrom_programmer_shutdown for programmer=%s successful\n", prog->name); free(param_dup); io_mock_register(NULL); } void run_basic_lifecycle(void **state, const struct io_mock *io, const struct programmer_entry *prog, const char *param) { /* Basic lifecycle only does init and shutdown, * so neither chip name nor action is needed. */ run_lifecycle(state, io, prog, param, NULL /* chip_name */, NULL /* action */); } void run_probe_lifecycle(void **state, const struct io_mock *io, const struct programmer_entry *prog, const char *param, const char *const chip_name) { /* Each probe lifecycle should run independently, without cache. */ clear_spi_id_cache(); run_lifecycle(state, io, prog, param, chip_name, &probe_chip); } void run_init_error_path(void **state, const struct io_mock *io, const struct programmer_entry *prog, const char *param, const int error_code) { (void) state; /* unused */ io_mock_register(io); struct flashrom_programmer *flashprog; char *param_dup = strdup(param); printf("Testing init error path for programmer=%s with params: %s ...\n", prog->name, param_dup); assert_int_equal(error_code, flashrom_programmer_init(&flashprog, prog->name, param_dup)); printf("... init failed with error code %i as expected\n", error_code); /* * `flashrom_programmer_shutdown` runs only registered shutdown functions, which means * if nothing has been registered then nothing runs. * Since this is testing error path on initialisation and error can happen at different * phases of init, we don't know whether shutdown function has already been registered * or not yet. Running `flashrom_programmer_shutdown` covers both situations. */ printf("Running programmer shutdown in case anything got registered...\n"); assert_int_equal(0, flashrom_programmer_shutdown(flashprog)); printf("... completed\n"); free(param_dup); io_mock_register(NULL); } href='#n25'>25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
# Advanced Keycodes
Your keymap can include keycodes that are more advanced than normal, for example keys that switch layers or send modifiers when held, but send regular keycodes when tapped. This page documents the functions that are available to you.
## Assigning Custom Names
People often define custom names using `#define`. For example:
```c
#define FN_CAPS LT(_FL, KC_CAPSLOCK)
#define ALT_TAB LALT(KC_TAB)
```
This will allow you to use `FN_CAPS` and `ALT_TAB` in your keymap, keeping it more readable.
## Caveats
Currently, `LT()` and `MT()` are limited to the [Basic Keycode set](keycodes_basic.md), meaning you can't use keycodes like `LCTL()`, `KC_TILD`, or anything greater than `0xFF`. Modifiers specified as part of a Layer Tap or Mod Tap's keycode will be ignored. If you need to apply modifiers to your tapped keycode, [Tap Dance](https://github.com/qmk/qmk_firmware/blob/master/docs/feature_tap_dance.md#example-5-using-tap-dance-for-advanced-mod-tap-and-layer-tap-keys) can be used to accomplish this.
Additionally, if at least one right-handed modifier is specified in a Mod Tap or Layer Tap, it will cause all modifiers specified to become right-handed, so it is not possible to mix and match the two.
# Switching and Toggling Layers
These functions allow you to activate layers in various ways. Note that layers are not generally independent layouts -- multiple layers can be activated at once, and it's typical for layers to use `KC_TRNS` to allow keypresses to pass through to lower layers. For a detailed explanation of layers, see [Keymap Overview](keymap.md#keymap-and-layers). When using momentary layer switching with MO(), LM(), TT(), or LT(), make sure to leave the key on the above layers transparent or it may not work as intended.
* `DF(layer)` - switches the default layer. The default layer is the always-active base layer that other layers stack on top of. See below for more about the default layer. This might be used to switch from QWERTY to Dvorak layout. (Note that this is a temporary switch that only persists until the keyboard loses power. To modify the default layer in a persistent way requires deeper customization, such as calling the `set_single_persistent_default_layer` function inside of [process_record_user](custom_quantum_functions.md#programming-the-behavior-of-any-keycode).)