Skip to content

Commit 0ca106d

Browse files
committed
Fix code and table in hook.txt
1 parent 714d418 commit 0ca106d

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

doc/hook.txt

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ Hooks allow you to execute custom code at certain predefined points in the firmw
44

55
The following hooks are available available:
66

7-
Hook function | Called in file | Timing
8-
---|---|---
9-
`hook_keyboard_start(void)` | *protocol/\<protocol>.c* | Early in the boot process, before the matrix is initialized and before a connection is made with the host. Thus, this hook has access to very few parameters, but it is a good place to define any custom parameters needed by other early processes.
10-
`hook_keyboard_init(void)` | *protocol/\<protocol>.c* | Near the end of the boot process, after Boot Magic has run and LEDs have been initialized.
11-
`hook_bootmagic(void)` | *common/bootmagic.c* | During the Boot Magic window, after EEPROM and Bootloader checks are made, but before any other built-in Boot Magic checks are made.
12-
`hook_usb_suspend(void)` | *protocol/\<protocol>.c* | When the device enters USB suspend state. *Default action:* enable LED breathing.
13-
`hook_usb_wakeup(void)` | *protocol/\<protocol>.c* | When the device wakes up from USB suspend state. *Default action:* disable LED breathing.
14-
`hook_suspend_loop(void)` | *protocol/\<protocol>.c* | Continuously, while the device is in USB suspend state. *Default action:* power down and periodically check the matrix, causing wakeup if needed.
15-
`hook_keyboard_loop(void)` | *common/keyboard.c* | Continuously, during the main loop, after the matrix is checked. Note that the protocol and interrupt configuration may affect the timing. If you need precise timing, use one of the `hook_interval_*` functions listed below.
16-
`hook_matrix_change(keyevent_t event)` | *common/action.c* | When a keypress event is detected, before any other actions are processed.
17-
`hook_layer_state_change(uint32_t layer_state)` | *common/action_layer.c* | When any layer is turned on or off. `layer_state` is a 32-bit integer containing the 0/1 state of all 32 layers, one bit per layer (see [keymap documentation](tmk_core/doc/keymap.md)).
18-
`hook_default_layer_state_change(uint32_t default_layer_state)` | *common/action_layer.c* | When the default layer is changed. `default_layer_state` is a 32-bit integer with a single bit set to 1 indicating the default layer (see [keymap documentation](tmk_core/doc/keymap.md)).
19-
`hook_leds_change(uint8_t led_status)` | *common/keyboard.c* | Whenever a change in the LED status is performed. *Default action:* call `keyboard_set_leds(led_status)`
7+
Hook function | Timing
8+
--------------------------------|-----------------------------------------------
9+
`hook_early_init(void)` | Early in the boot process, before the matrix is initialized and before a connection is made with the host. Thus, this hook has access to very few parameters, but it is a good place to define any custom parameters needed by other early processes.
10+
`hook_late_init(void)` | Near the end of the boot process, after Boot Magic has run and LEDs have been initialized.
11+
`hook_bootmagic(void)` | During the Boot Magic window, after EEPROM and Bootloader checks are made, but before any other built-in Boot Magic checks are made.
12+
`hook_usb_wakeup(void)` | When the device wakes up from USB suspend state.
13+
`hook_usb_suspend_entry(void)` | When the device enters USB suspend state.
14+
`hook_usb_suspend_loop(void)` | Continuously, while the device is in USB suspend state. *Default action:* power down and periodically check the matrix, causing wakeup if needed.
15+
`hook_keyboard_loop(void)` | Continuously, during the main loop, after the matrix is checked.
16+
`hook_matrix_change(keyevent_t event)` | When a matrix state change is detected, before any other actions are processed.
17+
`hook_layer_change(uint32_t layer_state)` | When any layer is changed.
18+
`hook_default_layer_change(uint32_t default_layer_state)` | When any default layer is changed.
19+
`hook_keyboard_leds_change(uint8_t led_status)` | Whenever a change in the LED status is performed. *Default action:* call `keyboard_set_leds(led_status)`
20+
21+
22+
23+
2024

2125
### Hooks Examples
2226

@@ -27,7 +31,7 @@ You can try these out by copying the code to your keymap file, or any .c file in
2731
```C
2832
#include "action_layer.h"
2933

30-
void hook_keyboard_init(void)
34+
void hook_late_init(void)
3135
{
3236
layer_on(5);
3337
print("Layer 5 enabled!");
@@ -56,7 +60,7 @@ void hook_keyboard_loop(void)
5660
if (my_led_status)
5761
{
5862
// LED is on, so let's turn it off
59-
led_set(host_keyboard_leds() & (0<<USB_LED_CAPS_LOCK));
63+
led_set(host_keyboard_leds() & ~(1<<USB_LED_CAPS_LOCK));
6064
my_led_status = 0;
6165
}
6266
else
@@ -71,7 +75,7 @@ void hook_keyboard_loop(void)
7175

7276
#### Flash the Caps Lock LED for 20ms on every keypress
7377
```C
74-
#include "timer.h"
78+
include "timer.h"
7579
#include "led.h"
7680

7781
bool my_led_status = 0;
@@ -83,13 +87,7 @@ void hook_matrix_change(keyevent_t event)
8387
if (event.pressed)
8488
{
8589
// check the current LED status and reverse it
86-
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))
87-
{
88-
led_set(host_keyboard_leds() & (0<<USB_LED_CAPS_LOCK));
89-
}
90-
else {
91-
led_set(host_keyboard_leds() | (1<<USB_LED_CAPS_LOCK));
92-
}
90+
led_set(host_keyboard_leds() ^ (1<<USB_LED_CAPS_LOCK));
9391

9492
my_led_status = 1;
9593
my_led_timer = timer_read();
@@ -101,12 +99,13 @@ void hook_keyboard_loop(void)
10199
if (my_led_status)
102100
{
103101
// check if we've reached 20 milliseconds yet...
104-
if (timer_elapsed(my_led_timer) > 20)
102+
if (timer_elapsed(my_led_timer) > 50)
105103
{
106-
keyboard_set_leds(host_keyboard_leds());
104+
led_set(host_keyboard_leds());
107105

108106
my_led_status = 0;
109107
}
110108
}
111109
}
110+
112111
```

0 commit comments

Comments
 (0)