Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Here is a list of commands and examples for them:
*Command*: `hkey.crt`</br>
*Syntax*: `hkey.crt <bool>`</br>
*Example*: `hkey.crt false`</br>
*Description*: Enables/Disables Continuous Rapid trigger functionality on the specified key(s).
*Description*: Enables/Disables Continuous Rapid Trigger functionality on the specified key(s).

*Command*: `hkey.rtus`</br>
*Syntax*: `hkey.rtus <uint16>`</br>
Expand Down
73 changes: 73 additions & 0 deletions include/config/components/keys.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

#include <stdint.h>

// An enum used to identify the type of key a Key object represents.
enum KeyType
{
// Key objects of this type have been initialized as neither an HEKey or DigitalKey object.
Base,

// A Key object that was initialized as an HEKey object.
HallEffect,

// A Key object that was initialized as a DigitalKey object.
Digital
};


// The base configuration struct for the DigitalKey and HEKey struct, containing the common fields.
struct Key
{
// Used to identify the type of key that a Key object was initialized as (e.g. HEKey or DigitalKey).
KeyType type = KeyType::Base;

// The index of the key. This is hardcoded in the default config and is not changed.
// It does not serve a config purpose but is instead for accessing the index from the DigitalKey object.
uint8_t index;

// The corresponding key sent via HID interface.
char keyChar;

// Bools whether HID commands are sent on the key.
bool hidEnabled;
};

// Configuration for the hall effect keys of the keypad, containing the actuation points, calibration, sensitivities etc. of the key.
struct HEKey : Key
{
// Initialize with the correct type for identifying the type of key that a Key object was initialized as (e.g. HEKey).
HEKey() { type = KeyType::HallEffect; }

// Bool whether rapid trigger is enabled or not.
bool rapidTrigger;

// Bool whether continuous rapid trigger is enabled or not.
bool continuousRapidTrigger;

// The sensitivity of the rapid trigger algorithm when pressing up.
uint16_t rapidTriggerUpSensitivity;

// The sensitivity of the rapid trigger algorithm when pressing down.
uint16_t rapidTriggerDownSensitivity;

// The value below which the key is pressed and rapid trigger is active in rapid trigger mode.
uint16_t lowerHysteresis;

// The value below which the key is no longer pressed and rapid trigger is no longer active in rapid trigger mode.
uint16_t upperHysteresis;

// The value read when the keys are in rest position/all the way down.
uint16_t restPosition;
uint16_t downPosition;
};

// Configuration for the digital keys of the keypad.
struct DigitalKey : Key
{
// Initialize with the correct type for identifying the type of key that a Key object was initialized as (e.g. DigitalKey).
DigitalKey() { type = KeyType::Digital; }

// This struct is empty on purpose. The only purpose it serves is explicitly having
// a type for the digital keys, instead of differentiating between Key and DigitalKey.
};
28 changes: 28 additions & 0 deletions include/config/components/led.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <stdint.h>

// Configuration for the LEDs registered on the hardware.
struct Led
{
// The index of the led. This is hardcoded in the default config and is not changed.
// It does not serve a config purpose but is instead for accessing the index from the Led object.
uint8_t index;

// The RGB color of the led.
uint32_t rgb;
};

// An enum used to identify the type of effect the LEDs have.
enum LedEffectType
{
// The configured RGB colors are shown at the configured brightness statically.
Static,

// The configured RGB color is shown with brightness dependant on how far the furthest key is pressed in.
Analog,

// Last value used to identify the end of the enum. This is necessary to get the amount of elements in the enum.
// e.g. in the serial command, there is a check looking whether the specified value is smaller than this.
MaxValue
};
22 changes: 19 additions & 3 deletions include/config/configuration.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#pragma once

#include "config/keys/he_key.hpp"
#include "config/keys/digital_key.hpp"
#include "config/components/keys.hpp"
#include "config/components/led.hpp"

// Configuration for the LEDs, containing the actual LEDs, brightness, effects, ... of the keypad.
struct LedConfiguration
{
// A list of all LEDs. (rgb, effect, ...)
Led leds[LEDS];

// The brightness of the LEDs. (0-100)
uint8_t brightness;

// The ID of the RGB effect.
LedEffectType effect;
};

// Configuration for the whole firmware, containing the name of the keypad and it's configurations.
struct Configuration
Expand All @@ -18,11 +31,14 @@ struct Configuration
// A list of all digital key configurations. (key char, hid state, ...)
DigitalKey digitalKeys[DIGITAL_KEYS];

// The config for the LEDs on the keypad.
LedConfiguration leds;

// Returns the version constant of the latest Configuration layout.
static uint32_t getVersion()
{
// Version of the configuration in the format YYMMDDhhmm (e.g. 2301030040 for 12:44am on the 3rd january 2023)
int64_t version = 2304281204;
int64_t version = 2306182346;

return version;
}
Expand Down
22 changes: 20 additions & 2 deletions include/config/configuration_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ inline class ConfigurationController
// structs that might get modified on a firmware update and have to be reset back to their default values then later on.
Configuration getDefaultConfig()
{
Configuration config = {
Configuration config =
{
.name = {'m', 'i', 'n', 'i', 'p', 'a', 'd'},
.heKeys = {},
.digitalKeys = {}
.digitalKeys = {},
.leds =
{
.leds = {},
.brightness = 50,
.effect = LedEffectType::Static
}
};

// Populate the hall effect keys array with the correct amount of hall effect keys.
Expand Down Expand Up @@ -69,6 +76,17 @@ inline class ConfigurationController
config.digitalKeys[i].hidEnabled = false;
}

#pragma GCC diagnostic ignored "-Wtype-limits"
for (uint8_t i = 0; i < LEDS; i++)
#pragma GCC diagnostic pop
{
config.leds.leds[i] = Led();
config.leds.leds[i].index = i;

// Set the default RGB for the leds to white (FFFFFF).
config.leds.leds[i].rgb = 0xFFFFFF;
}

return config;
};

Expand Down
14 changes: 0 additions & 14 deletions include/config/keys/digital_key.hpp

This file was deleted.

34 changes: 0 additions & 34 deletions include/config/keys/he_key.hpp

This file was deleted.

21 changes: 0 additions & 21 deletions include/config/keys/key.hpp

This file was deleted.

14 changes: 0 additions & 14 deletions include/config/keys/key_type.hpp

This file was deleted.

11 changes: 6 additions & 5 deletions include/definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
// NOTE: This way, the amount of keys is limited to 26 since the 27th key overlaps with the first analog port, 26.
#define DIGITAL_PIN(index) 0 + DIGITAL_KEYS - index - 1

// The pin the NeoPixel LEDs are chained onto.
#define LED_PIN 20

// The type of LEDs for the Adafruit NeoPixel library.
#define LED_TYPE NEO_GRB + NEO_KHZ800

// Add a compiler error if the firmware is being tried to built with more than the supported 4 keys.
// (only 4 ADC pins available)
#if HE_KEYS > 4
Expand All @@ -71,8 +77,3 @@
#if DIGITAL_KEYS > 26
#error As of right now, the firmware only supports up to 26 digital keys.
#endif

// If the debug flag is not set via compiler parameters, default it to 0 since it's required for if statements.
#ifndef DEV
#define DEV 0
#endif
3 changes: 1 addition & 2 deletions include/handlers/keypad_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ inline class KeypadHandler
digitalKeyStates[i] = DigitalKeyState();
}

void handle();
void loop();
bool outputMode;
HEKeyState heKeyStates[HE_KEYS];
DigitalKeyState digitalKeyStates[DIGITAL_KEYS];

private:

void checkHEKey(const HEKey &key, uint16_t value);
void checkDigitalKey(const DigitalKey &key, bool pressed);
void pressKey(const Key &key);
Expand Down
19 changes: 19 additions & 0 deletions include/handlers/led_handler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <Adafruit_NeoPixel.h>
#include "definitions.hpp"

inline class LEDHandler
{
public:
void setup();
void loop();

private:
void effect_static();
void effect_analog();
void setBrightness(uint8_t value);

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LEDS, LED_PIN, LED_TYPE);

} LEDHandler;
3 changes: 3 additions & 0 deletions include/handlers/serial_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ inline class SerialHandler
void hkey_down(HEKey &key, uint16_t value);
void key_char(Key &key, uint8_t keyChar);
void key_hid(Key &key, bool state);
void leds_btns(uint8_t value);
void leds_efct(uint8_t value);
void led_rgb(Led &led, char hex[7]);
} SerialHandler;
9 changes: 9 additions & 0 deletions include/helpers/color_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <stdint.h>

namespace ColorHelper
{
uint32_t hexToDec(char hex[7]);
void decToHex(uint32_t value, char hex[7]);
}
22 changes: 13 additions & 9 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ board = pico
framework = arduino
check_tool = clangtidy
board_build.core = earlephilhower
board_build.arduino.earlephilhower.usb_manufacturer=Project Minipad
board_build.arduino.earlephilhower.usb_manufacturer = Project Minipad
build_flags = -DUSBD_VID=0x0727 -DUSBD_PID=0x0727 -DHID_POLLING_RATE=1000 -DIGNORE_MULTI_ENDPOINT_PID_MUTATION -Wall -Wextra

[env:minipad-2k-dev]
build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -DDEV=1
board_build.arduino.earlephilhower.usb_product=minipad-2k-dev
build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -DLEDS=6 -DDEV=1
board_build.arduino.earlephilhower.usb_product = minipad-2k-dev
lib_deps = adafruit/Adafruit NeoPixel@^1.11.0

[env:minipad-3k-dev]
build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -DDEV=1
board_build.arduino.earlephilhower.usb_product=minipad-3k-dev
build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -DLEDS=0 -DDEV=1
board_build.arduino.earlephilhower.usb_product = minipad-3k-dev
lib_deps = adafruit/Adafruit NeoPixel@^1.11.0

[env:minipad-2k-prod]
build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0
board_build.arduino.earlephilhower.usb_product=minipad-2k
build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -DLEDS=0 -DDEV=0
board_build.arduino.earlephilhower.usb_product = minipad-2k
lib_deps = adafruit/Adafruit NeoPixel@^1.11.0

[env:minipad-3k-prod]
build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0
board_build.arduino.earlephilhower.usb_product=minipad-3k
build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -DLEDS=0 -DDEV=0
board_build.arduino.earlephilhower.usb_product = minipad-3k
lib_deps = adafruit/Adafruit NeoPixel@^1.11.0
Loading