Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: typedef'ed uint32_t to layer_state_t #526

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion keyboard/fc660c/unimap_emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion keyboard/fc660c/unimap_hasu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ void process_action(keyrecord_t *record)
/* Default Layer Bitwise Operation */
if (!event.pressed) {
uint8_t shift = action.layer_bitop.part*4;
uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift;
layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0;
switch (action.layer_bitop.op) {
case OP_BIT_AND: default_layer_and(bits | mask); break;
case OP_BIT_OR: default_layer_or(bits | mask); break;
Expand All @@ -232,8 +232,8 @@ void process_action(keyrecord_t *record)
if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
(action.layer_bitop.on & ON_RELEASE)) {
uint8_t shift = action.layer_bitop.part*4;
uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift;
layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0;
switch (action.layer_bitop.op) {
case OP_BIT_AND: layer_and(bits | mask); break;
case OP_BIT_OR: layer_or(bits | mask); break;
Expand Down
24 changes: 12 additions & 12 deletions tmk_core/common/action_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
/*
* Default Layer State
*/
uint32_t default_layer_state = 0;
layer_state_t default_layer_state = 0;

static void default_layer_state_set(uint32_t state)
static void default_layer_state_set(layer_state_t state)
{
debug("default_layer_state: ");
default_layer_debug(); debug(" to ");
Expand All @@ -34,21 +34,21 @@ void default_layer_debug(void)
dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state));
}

void default_layer_set(uint32_t state)
void default_layer_set(layer_state_t state)
{
default_layer_state_set(state);
}

#ifndef NO_ACTION_LAYER
void default_layer_or(uint32_t state)
void default_layer_or(layer_state_t state)
{
default_layer_state_set(default_layer_state | state);
}
void default_layer_and(uint32_t state)
void default_layer_and(layer_state_t state)
{
default_layer_state_set(default_layer_state & state);
}
void default_layer_xor(uint32_t state)
void default_layer_xor(layer_state_t state)
{
default_layer_state_set(default_layer_state ^ state);
}
Expand All @@ -59,9 +59,9 @@ void default_layer_xor(uint32_t state)
/*
* Keymap Layer State
*/
uint32_t layer_state = 0;
layer_state_t layer_state = 0;

static void layer_state_set(uint32_t state)
static void layer_state_set(layer_state_t state)
{
dprint("layer_state: ");
layer_debug(); dprint(" to ");
Expand Down Expand Up @@ -98,15 +98,15 @@ void layer_invert(uint8_t layer)
layer_state_set(layer_state ^ (1UL<<layer));
}

void layer_or(uint32_t state)
void layer_or(layer_state_t state)
{
layer_state_set(layer_state | state);
}
void layer_and(uint32_t state)
void layer_and(layer_state_t state)
{
layer_state_set(layer_state & state);
}
void layer_xor(uint32_t state)
void layer_xor(layer_state_t state)
{
layer_state_set(layer_state ^ state);
}
Expand All @@ -124,7 +124,7 @@ static uint8_t current_layer_for_key(keypos_t key)
{
#ifndef NO_ACTION_LAYER
action_t action = ACTION_TRANSPARENT;
uint32_t layers = layer_state | default_layer_state;
layer_state_t layers = layer_state | default_layer_state;
/* check top layer first */
for (int8_t i = 31; i >= 0; i--) {
if (layers & (1UL<<i)) {
Expand Down
19 changes: 10 additions & 9 deletions tmk_core/common/action_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "keyboard.h"
#include "action.h"

typedef uint32_t layer_state_t;

/*
* 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


/*
* 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);
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


Expand Down
4 changes: 2 additions & 2 deletions tmk_core/common/bootmagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tmk_core/common/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions tmk_core/common/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define _HOOKS_H_

#include "keyboard.h"
#include "action_layer.h"
#include "led.h"

/* -------------------------------------
Expand Down Expand Up @@ -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. */
Expand Down
4 changes: 2 additions & 2 deletions tmk_core/doc/hook.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)`


Expand Down
4 changes: 2 additions & 2 deletions tmk_core/doc/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<<shift) : 0;
layer_state_t mask = (bits&0x10) ? ~((layer_state_t)0xf<<shift) : 0;
switch (<bitop>) {
case BIT_AND:
layer_state = layer_state & (((bits&0xf)<<shift)|mask);
Expand Down