chore: clang-format the codebase.

* Use the LLVM style
* Override indent width (8) and column limit (100)
* Fixes #142.
This commit is contained in:
Pete Johanson
2020-09-13 22:53:24 -04:00
parent 296a89ce63
commit 191a2d755a
51 changed files with 2171 additions and 2547 deletions

View File

@@ -10,41 +10,27 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/hid.h>
static struct zmk_hid_keypad_report kp_report = {
.report_id = 1,
.body = {
.modifiers = 0,
.keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}};
.report_id = 1, .body = {.modifiers = 0, .keys = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}};
static struct zmk_hid_consumer_report consumer_report = {
.report_id = 2,
.body = {
.keys = {0,0,0,0,0,0}}};
static struct zmk_hid_consumer_report consumer_report = {.report_id = 2,
.body = {.keys = {0, 0, 0, 0, 0, 0}}};
#define _TOGGLE_MOD(mod, state) \
if (modifier > MOD_RGUI) \
{ \
return -EINVAL; \
} \
WRITE_BIT(kp_report.body.modifiers, mod, state); \
#define _TOGGLE_MOD(mod, state) \
if (modifier > MOD_RGUI) { \
return -EINVAL; \
} \
WRITE_BIT(kp_report.body.modifiers, mod, state); \
return 0;
int zmk_hid_register_mod(zmk_mod modifier)
{
_TOGGLE_MOD(modifier, true);
}
int zmk_hid_unregister_mod(zmk_mod modifier)
{
_TOGGLE_MOD(modifier, false);
}
int zmk_hid_register_mod(zmk_mod modifier) { _TOGGLE_MOD(modifier, true); }
int zmk_hid_unregister_mod(zmk_mod modifier) { _TOGGLE_MOD(modifier, false); }
int zmk_hid_register_mods(zmk_mod_flags modifiers)
{
int zmk_hid_register_mods(zmk_mod_flags modifiers) {
kp_report.body.modifiers |= modifiers;
return 0;
}
int zmk_hid_unregister_mods(zmk_mod_flags modifiers)
{
int zmk_hid_unregister_mods(zmk_mod_flags modifiers) {
kp_report.body.modifiers &= ~modifiers;
return 0;
}
@@ -67,28 +53,21 @@ int zmk_hid_unregister_mods(zmk_mod_flags modifiers)
#define TOGGLE_KEY(code, val) WRITE_BIT(kp_report.body.keys[code / 8], code % 8, val)
#define TOGGLE_CONSUMER(match, val) \
for (int idx = 0; idx < MAX_KEYS; idx++) \
{ \
if (consumer_report.body.keys[idx] != match) \
{ \
continue; \
} \
consumer_report.body.keys[idx] = val; \
break; \
#define TOGGLE_CONSUMER(match, val) \
for (int idx = 0; idx < MAX_KEYS; idx++) { \
if (consumer_report.body.keys[idx] != match) { \
continue; \
} \
consumer_report.body.keys[idx] = val; \
break; \
}
int zmk_hid_keypad_press(zmk_key code)
{
if (code >= LCTL && code <= RGUI)
{
int zmk_hid_keypad_press(zmk_key code) {
if (code >= LCTL && code <= RGUI) {
return zmk_hid_register_mod(code - LCTL);
}
if (code > ZMK_HID_MAX_KEYCODE)
{
if (code > ZMK_HID_MAX_KEYCODE) {
return -EINVAL;
}
@@ -99,15 +78,12 @@ int zmk_hid_keypad_press(zmk_key code)
return 0;
};
int zmk_hid_keypad_release(zmk_key code)
{
if (code >= LCTL && code <= RGUI)
{
int zmk_hid_keypad_release(zmk_key code) {
if (code >= LCTL && code <= RGUI) {
return zmk_hid_unregister_mod(code - LCTL);
}
if (code > ZMK_HID_MAX_KEYCODE)
{
if (code > ZMK_HID_MAX_KEYCODE) {
return -EINVAL;
}
@@ -118,25 +94,20 @@ int zmk_hid_keypad_release(zmk_key code)
return 0;
};
int zmk_hid_consumer_press(zmk_key code)
{
int zmk_hid_consumer_press(zmk_key code) {
TOGGLE_CONSUMER(0U, code);
return 0;
};
int zmk_hid_consumer_release(zmk_key code)
{
int zmk_hid_consumer_release(zmk_key code) {
TOGGLE_CONSUMER(code, 0U);
return 0;
};
struct zmk_hid_keypad_report *zmk_hid_get_keypad_report()
{
struct zmk_hid_keypad_report *zmk_hid_get_keypad_report() {
return &kp_report;
}
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report()
{
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report() {
return &consumer_report;
}