ergodox-firmware/src/lib/key-functions.c

122 lines
3.3 KiB
C
Raw Normal View History

/* ----------------------------------------------------------------------------
* key functions: code
*
* These functions may do.. pretty much anything rational that thay like. If
* they want keycodes to be sent to the host in an aggrate report, they're
* responsible for modifying the appropriate report variables.
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#include "lib-other/pjrc/usb_keyboard/usb_keyboard.h"
#include "lib/data-types.h"
2012-05-14 03:06:17 +02:00
#include "lib/usb/usage-page/keyboard.h"
#include "keyboard.h"
#include "key-functions.h"
2012-04-28 00:39:26 +02:00
2012-04-12 06:05:45 +02:00
void kbfun_press(
2012-04-29 09:17:17 +02:00
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
2012-04-25 08:49:17 +02:00
// no-op
2012-04-29 09:17:17 +02:00
if (keycode == 0)
2012-04-25 08:49:17 +02:00
return;
// modifier keys
2012-04-29 09:17:17 +02:00
switch (keycode) {
case KEY_LeftControl: keyboard_modifier_keys |= (1<<0);
return;
case KEY_LeftShift: keyboard_modifier_keys |= (1<<1);
return;
case KEY_LeftAlt: keyboard_modifier_keys |= (1<<2);
return;
case KEY_LeftGUI: keyboard_modifier_keys |= (1<<3);
return;
case KEY_RightControl: keyboard_modifier_keys |= (1<<4);
return;
case KEY_RightShift: keyboard_modifier_keys |= (1<<5);
return;
case KEY_RightAlt: keyboard_modifier_keys |= (1<<6);
return;
case KEY_RightGUI: keyboard_modifier_keys |= (1<<7);
return;
}
// all others
for (uint8_t i=0; i<6; i++)
if (keyboard_keys[i] == 0) {
2012-04-29 09:17:17 +02:00
keyboard_keys[i] = keycode;
break;
}
}
void kbfun_release(
2012-04-29 09:17:17 +02:00
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
2012-04-25 08:49:17 +02:00
// no-op
2012-04-29 09:17:17 +02:00
if (keycode == 0)
2012-04-25 08:49:17 +02:00
return;
// modifier keys
2012-04-29 09:17:17 +02:00
switch (keycode) {
case KEY_LeftControl: keyboard_modifier_keys &= ~(1<<0);
return;
case KEY_LeftShift: keyboard_modifier_keys &= ~(1<<1);
return;
case KEY_LeftAlt: keyboard_modifier_keys &= ~(1<<2);
return;
case KEY_LeftGUI: keyboard_modifier_keys &= ~(1<<3);
return;
case KEY_RightControl: keyboard_modifier_keys &= ~(1<<4);
return;
case KEY_RightShift: keyboard_modifier_keys &= ~(1<<5);
return;
case KEY_RightAlt: keyboard_modifier_keys &= ~(1<<6);
return;
case KEY_RightGUI: keyboard_modifier_keys &= ~(1<<7);
return;
}
// all others
for (uint8_t i=0; i<6; i++)
2012-04-29 09:17:17 +02:00
if (keyboard_keys[i] == keycode) {
keyboard_keys[i] = 0;
break;
}
}
// TODO:
// - allocate 10 layers, by default (overrideable in the map specific .h)
// - implement having different keys using different layers
// - implement two shifts => capslock
// - implement layer lock key combos (make a function to switch to a specific
// layer)
void kbfun_layer_inc(
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
if (*current_layer < (KB_LAYERS-1))
(*current_layer)++;
// else do nothing
}
void kbfun_layer_dec(
uint8_t keycode, uint8_t * current_layer,
uint8_t * row, uint8_t * col ) {
if (*current_layer > 0)
(*current_layer)--;
// else do nothing
}
// ----------------------------------------------------------------------------