X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Macro%2FPartialMap%2Fkll.h;h=e5e964f0e2460f14720f54901a984c328875b522;hb=5f262ea4b68a07e9b94ce0a49c0f7196e5f32b3b;hp=1d3f70b50222fee7fe2f781ef5f771584ed6602c;hpb=c7934c7224b5289f443b50a0428559f52f986635;p=kiibohd-controller.git
diff --git a/Macro/PartialMap/kll.h b/Macro/PartialMap/kll.h
index 1d3f70b..e5e964f 100644
--- a/Macro/PartialMap/kll.h
+++ b/Macro/PartialMap/kll.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 by Jacob Alexander
+/* Copyright (C) 2014-2015 by Jacob Alexander
*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,11 +14,13 @@
* along with this file. If not, see .
*/
-#ifndef __kll_h
-#define __kll_h
+#pragma once
// ----- Includes -----
+// KLL Generated Defines
+#include
+
// Project Includes
#include
#include
@@ -36,18 +38,26 @@
// It is possible to change the maximum state and indexing positions of the state machine.
// This usually affects the SRAM usage quite a bit, so it can be used to fit the code on smaller uCs
// Or to allow for nearly infinite states.
-// TODO Make selectable from layout variable
-//typedef uint32_t var_uint_t;
+#if StateWordSize_define == 32
+typedef uint32_t var_uint_t;
+#elif StateWordSize_define == 16
typedef uint16_t var_uint_t;
-//typedef uint8_t var_uint_t;
+#elif StateWordSize_define == 8
+typedef uint8_t var_uint_t;
+#else
+#error "Invalid StateWordSize, possible values: 32, 16 and 8."
+#endif
// - NOTE -
// Native pointer length
// This needs to be defined per microcontroller
// e.g. mk20s -> 32 bit
// atmega -> 16 bit
+#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
typedef uint32_t nat_ptr_t;
-//typedef uint16_t nat_ptr_t;
+#elif defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
+typedef uint16_t nat_ptr_t;
+#endif
@@ -55,23 +65,28 @@ typedef uint32_t nat_ptr_t;
// -- Result Macro
// Defines the sequence of combinations to as the Result of Trigger Macro
+// For RAM optimization reasons, ResultMacro has been split into ResultMacro and ResultMacroRecord structures
//
// Capability + args per USB send
// Default Args (always sent): key state/analog of last key
// Combo Length of 0 signifies end of sequence
//
-// ResultMacro.guide -> [|||||...||...|0]
-// ResultMacro.pos ->
-// ResultMacro.state ->
-// ResultMacro.stateType ->
+// ResultMacro.guide -> [|||||...||...|0]
+//
+// ResultMacroRecord.pos ->
+// ResultMacroRecord.state ->
+// ResultMacroRecord.stateType ->
// ResultMacro struct, one is created per ResultMacro, no duplicates
typedef struct ResultMacro {
const uint8_t *guide;
+} ResultMacro;
+
+typedef struct ResultMacroRecord {
var_uint_t pos;
uint8_t state;
uint8_t stateType;
-} ResultMacro;
+} ResultMacroRecord;
// Guide, key element
#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
@@ -84,6 +99,7 @@ typedef struct ResultGuide {
// -- Trigger Macro
// Defines the sequence of combinations to Trigger a Result Macro
+// For RAM optimization reasons TriggerMacro has been split into TriggerMacro and TriggerMacroRecord
// Key Types:
// * 0x00 Normal (Press/Hold/Release)
// * 0x01 LED State (On/Off)
@@ -102,8 +118,9 @@ typedef struct ResultGuide {
//
// TriggerMacro.guide -> [|||...|||...|0]
// TriggerMacro.result ->
-// TriggerMacro.pos ->
-// TriggerMacro.state ->
+//
+// TriggerMacroRecord.pos ->
+// TriggerMacroRecord.state ->
// TriggerMacro states
typedef enum TriggerMacroState {
@@ -115,10 +132,13 @@ typedef enum TriggerMacroState {
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
typedef struct TriggerMacro {
const uint8_t *guide;
- var_uint_t result;
+ const var_uint_t result;
+} TriggerMacro;
+
+typedef struct TriggerMacroRecord {
var_uint_t pos;
TriggerMacroState state;
-} TriggerMacro;
+} TriggerMacroRecord;
// Guide, key element
#define TriggerGuideSize sizeof( TriggerGuide )
@@ -134,8 +154,8 @@ typedef struct TriggerGuide {
// Capability
typedef struct Capability {
- void *func;
- uint8_t argCount;
+ const void *func;
+ const uint8_t argCount;
} Capability;
// Total Number of Capabilities
@@ -152,7 +172,7 @@ typedef struct Capability {
// * index - Result Macro index number
// Must be used after Guide_RM
#define Guide_RM( index ) const uint8_t rm##index##_guide[]
-#define Define_RM( index ) { rm##index##_guide, 0, 0, 0 }
+#define Define_RM( index ) { rm##index##_guide }
// -- Result Macro List
@@ -172,7 +192,7 @@ typedef struct Capability {
// * index - Trigger Macro index number
// * result - Result Macro index number which is triggered by this Trigger Macro
#define Guide_TM( index ) const uint8_t tm##index##_guide[]
-#define Define_TM( index, result ) { tm##index##_guide, result, 0, TriggerMacro_Waiting }
+#define Define_TM( index, result ) { tm##index##_guide, result }
// -- Trigger Macro List
@@ -202,33 +222,32 @@ typedef struct Capability {
// * Shift - 0x01
// * Latch - 0x02
// * Lock - 0x04
+// Layer states are stored in the LayerState array
//
// Except for Off, all states an exist simultaneously for each layer
// For example:
// state -> 0x04 + 0x01 = 0x05 (Shift + Lock), which is effectively Off (0x00)
//
-// Max defines the maximum number of keys in the map, maximum of 0xFF
+// First defines the first used scan code (most keyboards start at 0, some start higher e.g. 0x40)
// - Compiler calculates this
//
+// Last defines the last scan code used (helps reduce RAM usage)
+//
// The name is defined for cli debugging purposes (Null terminated string)
typedef struct Layer {
const nat_ptr_t **triggerMap;
const char *name;
- const uint8_t max;
- uint8_t state;
+ const uint8_t first;
+ const uint8_t last;
} Layer;
-
-// Layer_IN( map, name );
-// * map - Trigger map
-// * name - Name of the trigger map
-#define Layer_IN( map, name ) { map, name, sizeof( map ) / 4 - 1, 0 }
+// Layer_IN( map, name, first );
+// * map - Trigger map
+// * name - Name of the trigger map
+// * first - First scan code used (most keyboards start at 0, some start higher e.g. 0x40)
+#define Layer_IN( map, name, first ) { map, name, first, sizeof( map ) / sizeof( nat_ptr_t ) - 1 + first }
// Total number of layers
#define LayerNum sizeof( LayerIndex ) / sizeof( Layer )
-
-
-#endif // __kll_h
-