diff --git a/keyboard/fc660c/unimap_emu.c b/keyboard/fc660c/unimap_emu.c
index 50e445997f..9bdfd6c364 100644
--- a/keyboard/fc660c/unimap_emu.c
+++ b/keyboard/fc660c/unimap_emu.c
@@ -54,7 +54,7 @@ const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = {
};
-void hook_layer_change(uint32_t layer_state)
+void hook_layer_change(layer_state_t layer_state)
{
// lights LED on Insert when layer 1 is enabled
if (layer_state & (1L<<1)) {
diff --git a/keyboard/fc660c/unimap_hasu.c b/keyboard/fc660c/unimap_hasu.c
index c7a8700ad9..406aa4aec7 100644
--- a/keyboard/fc660c/unimap_hasu.c
+++ b/keyboard/fc660c/unimap_hasu.c
@@ -73,7 +73,7 @@ const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = {
};
-void hook_layer_change(uint32_t layer_state)
+void hook_layer_change(layer_state_t layer_state)
{
// lights LED on Insert when layer 1 is enabled
if (layer_state & (1L<<1)) {
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 305816d4f0..a6a587fe90 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -35,6 +35,11 @@ along with this program. If not, see .
#include "nodebug.h"
#endif
+#ifndef NO_ACTION_LAYER
+void action_layer_bitop(action_t action, bool pressed);
+void action_layer_bitop(action_t action, bool pressed);
+void action_layer_calc_bits_mask(action_t action, layer_state_t *bits, layer_state_t *mask);
+#endif
void action_exec(keyevent_t event)
{
@@ -214,34 +219,7 @@ void process_action(keyrecord_t *record)
#endif
#ifndef NO_ACTION_LAYER
case ACT_LAYER:
- if (action.layer_bitop.on == 0) {
- /* Default Layer Bitwise Operation */
- if (!event.pressed) {
- uint8_t shift = action.layer_bitop.part*4;
- uint32_t bits = ((uint32_t)action.layer_bitop.bits)< 16 // layer_state is uint32_t
+ return action.layer_bitop.part*4;
+#elif NUM_LAYERS > 8 // unit16_t
+ return (action.layer_bitop.part & 3)*4;
+#else // uint8_t
+ return (action.layer_bitop.part & 1)*4;
+#endif
+}
+
+//outputs bits and mask.
+inline void action_layer_calc_bits_mask(action_t action, layer_state_t *bits, layer_state_t *mask)
+{
+ uint8_t shift = action_layer_shift(action);
+ *bits = ((layer_state_t)action.layer_bitop.bits) << shift;
+ *mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<= 0; i--) {
- if (layers & (1UL<= 0; i--) {
+ if (layers & (ONE<.
#include "keyboard.h"
#include "action.h"
+#ifndef NUM_LAYERS //You can redefine NUM_LAYERS in config.h to improve performance.
+ #define NUM_LAYERS 32
+#endif
+
+#if (NUM_LAYERS <= 8)
+typedef uint8_t layer_state_t;
+#elif (NUM_LAYERS <= 16)
+typedef uint16_t layer_state_t;
+#elif (NUM_LAYERS <= 32)
+typedef uint32_t layer_state_t;
+#else
+//Note we can't have more than 32 layers due to implementation of action_code.action_layer.bitop
+#error "NUM_LAYERS: invalid value"
+#endif
/*
* Default Layer
*/
-extern uint32_t default_layer_state;
+extern layer_state_t default_layer_state;
void default_layer_debug(void);
-void default_layer_set(uint32_t state);
+void default_layer_set(layer_state_t state);
#ifndef NO_ACTION_LAYER
/* bitwise operation */
-void default_layer_or(uint32_t state);
-void default_layer_and(uint32_t state);
-void default_layer_xor(uint32_t state);
+void default_layer_or(layer_state_t state);
+void default_layer_and(layer_state_t state);
+void default_layer_xor(layer_state_t state);
#endif
@@ -41,7 +55,7 @@ void default_layer_xor(uint32_t state);
* Keymap Layer
*/
#ifndef NO_ACTION_LAYER
-extern uint32_t layer_state;
+extern layer_state_t layer_state;
void layer_debug(void);
void layer_clear(void);
void layer_move(uint8_t layer);
@@ -49,9 +63,9 @@ void layer_on(uint8_t layer);
void layer_off(uint8_t layer);
void layer_invert(uint8_t layer);
/* bitwise operation */
-void layer_or(uint32_t state);
-void layer_and(uint32_t state);
-void layer_xor(uint32_t state);
+void layer_or(layer_state_t state);
+void layer_and(layer_state_t state);
+void layer_xor(layer_state_t state);
#endif
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index eb06d7874d..57478944d0 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -104,10 +104,10 @@ void bootmagic(void)
if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
if (default_layer) {
eeconfig_write_default_layer(default_layer);
- default_layer_set((uint32_t)default_layer);
+ default_layer_set((layer_state_t)default_layer);
} else {
default_layer = eeconfig_read_default_layer();
- default_layer_set((uint32_t)default_layer);
+ default_layer_set((layer_state_t)default_layer);
}
}
diff --git a/tmk_core/common/hook.c b/tmk_core/common/hook.c
index 4ed2403cf4..9006ea942a 100644
--- a/tmk_core/common/hook.c
+++ b/tmk_core/common/hook.c
@@ -31,12 +31,12 @@ void hook_matrix_change(keyevent_t event) {
}
__attribute__((weak))
-void hook_default_layer_change(uint32_t default_layer_state) {
+void hook_default_layer_change(layer_state_t default_layer_state) {
(void)default_layer_state;
}
__attribute__((weak))
-void hook_layer_change(uint32_t layer_state) {
+void hook_layer_change(layer_state_t layer_state) {
(void)layer_state;
}
diff --git a/tmk_core/common/hook.h b/tmk_core/common/hook.h
index 56fe567774..df084f5ee9 100644
--- a/tmk_core/common/hook.h
+++ b/tmk_core/common/hook.h
@@ -19,6 +19,7 @@ along with this program. If not, see .
#define _HOOKS_H_
#include "keyboard.h"
+#include "action_layer.h"
#include "led.h"
/* -------------------------------------
@@ -62,11 +63,11 @@ void hook_matrix_change(keyevent_t event);
/* Called on default layer state change event. */
/* Default behaviour: do nothing. */
-void hook_default_layer_change(uint32_t default_layer_state);
+void hook_default_layer_change(layer_state_t default_layer_state);
/* Called on layer state change event. */
/* Default behaviour: do nothing. */
-void hook_layer_change(uint32_t layer_state);
+void hook_layer_change(layer_state_t layer_state);
/* Called on indicator LED update event (when reported from host). */
/* Default behaviour: calls keyboard_set_leds. */
diff --git a/tmk_core/doc/hook.txt b/tmk_core/doc/hook.txt
index 1689034e93..dc274533b4 100644
--- a/tmk_core/doc/hook.txt
+++ b/tmk_core/doc/hook.txt
@@ -14,8 +14,8 @@ Hook function | Timing
`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.
`hook_keyboard_loop(void)` | Continuously, during the main loop, after the matrix is checked.
`hook_matrix_change(keyevent_t event)` | When a matrix state change is detected, before any other actions are processed.
-`hook_layer_change(uint32_t layer_state)` | When any layer is changed.
-`hook_default_layer_change(uint32_t default_layer_state)` | When any default layer is changed.
+`hook_layer_change(layer_state_t layer_state)` | When any layer is changed.
+`hook_default_layer_change(layer_state_t default_layer_state)` | When any default layer is changed.
`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)`
diff --git a/tmk_core/doc/keymap.md b/tmk_core/doc/keymap.md
index dfb80797ae..878f3a2faf 100644
--- a/tmk_core/doc/keymap.md
+++ b/tmk_core/doc/keymap.md
@@ -387,9 +387,9 @@ bs
These parameters works as following code.
- uint32_t layer_state;
+ layer_state_t layer_state;
uint8_t shift = part*4;
- uint32_t mask = (bits&0x10) ? ~((uint32_t)0xf<) {
case BIT_AND:
layer_state = layer_state & (((bits&0xf)<