Skip to content

Commit

Permalink
Merge branch 'master' of github.com:UltimateHackingKeyboard/firmware
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
kareltucek committed Oct 26, 2019
2 parents c380246 + 9177c14 commit f1286e7
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 79 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to the [UHK Versioning](VERSIONING.md) conventions.

## [8.6.0] - 2018-08-23

Device Protocol: 4.5.0 | Module Protocol: 4.**1.0** | User Config: 4.1.**1** | Hardware Config: 1.0.0

- Make the config parser accept mouse button 4 to 8. `USERCONFIG:PATCH`
- Implement API for modules to send pointer movements to the master. `MODULEPROTOCOL:MINOR`
- Fix empty macro playback.

## [8.5.4] - 2018-01-05

Device Protocol: 4.5.0 | Module Protocol: 4.0.0 | User Config: 4.1.0 | Hardware Config: 1.0.0
Expand Down
4 changes: 4 additions & 0 deletions cla/cla-1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ IF THE DISCLAIMER AND DAMAGE WAIVER MENTIONED IN SECTION 4. AND SECTION 5. CANNO

I have read this Agreement, and fully agree to it by signing it with my GitHub username:

- @eltang
- @kareltucek
- @Lauszus
- @mondalaci
- @santiagogf89
- @tastyger
- @xdever
- @stephengroat
- @ert78gb
49 changes: 19 additions & 30 deletions keycluster/src/blackberry_trackball.c
Original file line number Diff line number Diff line change
@@ -1,61 +1,50 @@
#include "fsl_gpio.h"
#include "fsl_port.h"
#include "blackberry_trackball.h"
#include "test_led.h"

pointer_delta_t BlackBerryTrackball_PointerDelta;

void BlackberryTrackball_Init(void)
{
CLOCK_EnableClock(BLACKBERRY_TRACKBALL_LEFT_CLOCK);
PORT_SetPinMux(BLACKBERRY_TRACKBALL_LEFT_PORT, BLACKBERRY_TRACKBALL_LEFT_PIN, kPORT_MuxAsGpio);
PORT_SetPinInterruptConfig(BLACKBERRY_TRACKBALL_LEFT_PORT, BLACKBERRY_TRACKBALL_LEFT_PIN, kPORT_InterruptEitherEdge);
NVIC_EnableIRQ(BLACKBERRY_TRACKBALL_LEFT_IRQ);

CLOCK_EnableClock(BLACKBERRY_TRACKBALL_RIGHT_CLOCK);
PORT_SetPinMux(BLACKBERRY_TRACKBALL_RIGHT_PORT, BLACKBERRY_TRACKBALL_RIGHT_PIN, kPORT_MuxAsGpio);
PORT_SetPinInterruptConfig(BLACKBERRY_TRACKBALL_RIGHT_PORT, BLACKBERRY_TRACKBALL_RIGHT_PIN, kPORT_InterruptEitherEdge);
NVIC_EnableIRQ(BLACKBERRY_TRACKBALL_RIGHT_IRQ);

CLOCK_EnableClock(BLACKBERRY_TRACKBALL_UP_CLOCK);
PORT_SetPinMux(BLACKBERRY_TRACKBALL_UP_PORT, BLACKBERRY_TRACKBALL_UP_PIN, kPORT_MuxAsGpio);
PORT_SetPinInterruptConfig(BLACKBERRY_TRACKBALL_UP_PORT, BLACKBERRY_TRACKBALL_UP_PIN, kPORT_InterruptEitherEdge);
NVIC_EnableIRQ(BLACKBERRY_TRACKBALL_UP_IRQ);

CLOCK_EnableClock(BLACKBERRY_TRACKBALL_DOWN_CLOCK);
PORT_SetPinMux(BLACKBERRY_TRACKBALL_DOWN_PORT, BLACKBERRY_TRACKBALL_DOWN_PIN, kPORT_MuxAsGpio);
PORT_SetPinInterruptConfig(BLACKBERRY_TRACKBALL_DOWN_PORT, BLACKBERRY_TRACKBALL_DOWN_PIN, kPORT_InterruptEitherEdge);
NVIC_EnableIRQ(BLACKBERRY_TRACKBALL_DOWN_IRQ);
}

void handleTrackball(void)
{
if (PORT_GetPinsInterruptFlags(BLACKBERRY_TRACKBALL_LEFT_PORT) & (1 << BLACKBERRY_TRACKBALL_LEFT_PIN)) {
BlackBerryTrackball_PointerDelta.x++;
GPIO_ClearPinsInterruptFlags(BLACKBERRY_TRACKBALL_LEFT_GPIO, 1U << BLACKBERRY_TRACKBALL_LEFT_PIN);
}
bool oldLeft, oldRight, oldUp, oldDown;

if (PORT_GetPinsInterruptFlags(BLACKBERRY_TRACKBALL_RIGHT_PORT) & (1 << BLACKBERRY_TRACKBALL_RIGHT_PIN)) {
void BlackberryTrackball_Update(void)
{
uint8_t newLeft = GPIO_ReadPinInput(BLACKBERRY_TRACKBALL_LEFT_GPIO, BLACKBERRY_TRACKBALL_LEFT_PIN);
if (oldLeft != newLeft) {
BlackBerryTrackball_PointerDelta.x--;
GPIO_ClearPinsInterruptFlags(BLACKBERRY_TRACKBALL_RIGHT_GPIO, 1U << BLACKBERRY_TRACKBALL_RIGHT_PIN);
oldLeft = newLeft;
}

if (PORT_GetPinsInterruptFlags(BLACKBERRY_TRACKBALL_UP_PORT) & (1 << BLACKBERRY_TRACKBALL_UP_PIN)) {
BlackBerryTrackball_PointerDelta.y++;
GPIO_ClearPinsInterruptFlags(BLACKBERRY_TRACKBALL_UP_GPIO, 1U << BLACKBERRY_TRACKBALL_UP_PIN);
uint8_t newRight = GPIO_ReadPinInput(BLACKBERRY_TRACKBALL_RIGHT_GPIO, BLACKBERRY_TRACKBALL_RIGHT_PIN);
if (oldRight != newRight) {
BlackBerryTrackball_PointerDelta.x++;
oldRight = newRight;
}

if (PORT_GetPinsInterruptFlags(BLACKBERRY_TRACKBALL_DOWN_PORT) & (1 << BLACKBERRY_TRACKBALL_DOWN_PIN)) {
uint8_t newUp = GPIO_ReadPinInput(BLACKBERRY_TRACKBALL_UP_GPIO, BLACKBERRY_TRACKBALL_UP_PIN);
if (oldUp != newUp) {
BlackBerryTrackball_PointerDelta.y--;
GPIO_ClearPinsInterruptFlags(BLACKBERRY_TRACKBALL_DOWN_GPIO, 1U << BLACKBERRY_TRACKBALL_DOWN_PIN);
oldUp = newUp;
}
}

void BLACKBERRY_TRACKBALL_IRQ_HANDLER1(void)
{
handleTrackball();
}

void BLACKBERRY_TRACKBALL_IRQ_HANDLER2(void)
{
handleTrackball();
uint8_t newDown = GPIO_ReadPinInput(BLACKBERRY_TRACKBALL_DOWN_GPIO, BLACKBERRY_TRACKBALL_DOWN_PIN);
if (oldDown != newDown) {
BlackBerryTrackball_PointerDelta.y++;
oldDown = newDown;
}
}
21 changes: 10 additions & 11 deletions keycluster/src/blackberry_trackball.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@
// Includes:

#include "slave_protocol.h"
#include "fsl_port.h"

// Macros:

#define BLACKBERRY_TRACKBALL_LEFT_PORT PORTB
#define BLACKBERRY_TRACKBALL_LEFT_GPIO GPIOB
#define BLACKBERRY_TRACKBALL_LEFT_IRQ PORTB_IRQn
#define BLACKBERRY_TRACKBALL_LEFT_CLOCK kCLOCK_PortB
#define BLACKBERRY_TRACKBALL_LEFT_PIN 0
#define BLACKBERRY_TRACKBALL_LEFT_PIN 13

#define BLACKBERRY_TRACKBALL_RIGHT_PORT PORTB
#define BLACKBERRY_TRACKBALL_RIGHT_GPIO GPIOB
#define BLACKBERRY_TRACKBALL_RIGHT_IRQ PORTB_IRQn
#define BLACKBERRY_TRACKBALL_RIGHT_CLOCK kCLOCK_PortB
#define BLACKBERRY_TRACKBALL_RIGHT_PIN 2
#define BLACKBERRY_TRACKBALL_RIGHT_PIN 6

#define BLACKBERRY_TRACKBALL_UP_PORT PORTA
#define BLACKBERRY_TRACKBALL_UP_GPIO GPIOA
#define BLACKBERRY_TRACKBALL_UP_IRQ PORTA_IRQn
#define BLACKBERRY_TRACKBALL_UP_CLOCK kCLOCK_PortA
#define BLACKBERRY_TRACKBALL_UP_PIN 12
#define BLACKBERRY_TRACKBALL_UP_PIN 3

#define BLACKBERRY_TRACKBALL_DOWN_PORT PORTB
#define BLACKBERRY_TRACKBALL_DOWN_GPIO GPIOB
#define BLACKBERRY_TRACKBALL_DOWN_IRQ PORTB_IRQn
#define BLACKBERRY_TRACKBALL_DOWN_CLOCK kCLOCK_PortB
#define BLACKBERRY_TRACKBALL_DOWN_PIN 6

#define BLACKBERRY_TRACKBALL_IRQ_HANDLER1 PORTA_IRQHandler
#define BLACKBERRY_TRACKBALL_IRQ_HANDLER2 PORTB_IRQHandler
#define BLACKBERRY_TRACKBALL_DOWN_PORT PORTA
#define BLACKBERRY_TRACKBALL_DOWN_GPIO GPIOA
#define BLACKBERRY_TRACKBALL_DOWN_IRQ PORTA_IRQn
#define BLACKBERRY_TRACKBALL_DOWN_CLOCK kCLOCK_PortA
#define BLACKBERRY_TRACKBALL_DOWN_PIN 4

// Variables:

Expand All @@ -41,5 +39,6 @@
// Functions:

void BlackberryTrackball_Init(void);
void BlackberryTrackball_Update(void);

#endif
2 changes: 1 addition & 1 deletion keycluster/src/key_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

void KEY_SCANNER_HANDLER(void)
{
KeyMatrix_ScanRow(&keyMatrix);
KeyVector_Scan(&keyVector);
RunWatchdog();
LPTMR_ClearStatusFlags(KEY_SCANNER_LPTMR_BASEADDR, kLPTMR_TimerCompareFlag);
}
Expand Down
2 changes: 1 addition & 1 deletion keycluster/src/key_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define KEY_SCANNER_LPTMR_IRQ_ID LPTMR0_IRQn
#define KEY_SCANNER_HANDLER LPTMR0_IRQHandler

#define KEY_SCANNER_INTERVAL_USEC (1000 / KEYBOARD_MATRIX_ROWS_NUM)
#define KEY_SCANNER_INTERVAL_USEC (1000 / KEYBOARD_VECTOR_ITEMS_NUM)

// Functions:

Expand Down
23 changes: 12 additions & 11 deletions keycluster/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@
#include <stdio.h>
#include "key_scanner.h"
#include "module.h"
#include "blackberry_trackball.h"

DEFINE_BOOTLOADER_CONFIG_AREA(I2C_ADDRESS_MODULE_BOOTLOADER)

key_matrix_t keyMatrix = {
.colNum = KEYBOARD_MATRIX_COLS_NUM,
.rowNum = KEYBOARD_MATRIX_ROWS_NUM,
.cols = (key_matrix_pin_t[]) {
{PORTB, GPIOB, kCLOCK_PortB, 11},
{PORTA, GPIOA, kCLOCK_PortA, 6},
key_vector_t keyVector = {
.itemNum = KEYBOARD_VECTOR_ITEMS_NUM,
.items = (key_vector_pin_t[]) {
{PORTB, GPIOB, kCLOCK_PortB, 10}, // top key
{PORTA, GPIOA, kCLOCK_PortA, 6}, // left key
{PORTB, GPIOB, kCLOCK_PortB, 2}, // right key
{PORTA, GPIOA, kCLOCK_PortA, 5}, // left microswitch
{PORTB, GPIOB, kCLOCK_PortB, 7}, // trackball microswitch
{PORTA, GPIOA, kCLOCK_PortA, 8}, // right microswitch
},
.rows = (key_matrix_pin_t[]) {
{PORTB, GPIOB, kCLOCK_PortB, 7},
{PORTB, GPIOB, kCLOCK_PortB, 10},
}
};

int main(void)
{
InitClock();
InitPeripherals();
KeyMatrix_Init(&keyMatrix);
KeyVector_Init(&keyVector);
InitKeyScanner();

while (1) {
BlackberryTrackball_Update();
__WFI();
}
}
7 changes: 3 additions & 4 deletions keycluster/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

// Includes:

#include "key_matrix.h"
#include "key_vector.h"

// Macros:

#define KEYBOARD_MATRIX_COLS_NUM 2
#define KEYBOARD_MATRIX_ROWS_NUM 2
#define KEYBOARD_VECTOR_ITEMS_NUM 6

// Variables:

extern key_matrix_t keyMatrix;
extern key_vector_t keyVector;

#endif
2 changes: 1 addition & 1 deletion keycluster/src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define I2C_ADDRESS_MODULE_BOOTLOADER I2C_ADDRESS_LEFT_MODULE_BOOTLOADER
#define MODULE_PROTOCOL_VERSION 1
#define MODULE_ID ModuleId_KeyClusterLeft
#define MODULE_KEY_COUNT (KEYBOARD_MATRIX_ROWS_NUM * KEYBOARD_MATRIX_COLS_NUM)
#define MODULE_KEY_COUNT KEYBOARD_VECTOR_ITEMS_NUM
#define MODULE_POINTER_COUNT 1

#endif
5 changes: 1 addition & 4 deletions keycluster/src/slave_protocol_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,14 @@ void SlaveTxHandler(void)
break;
}
case SlaveCommand_RequestKeyStates:
BoolBytesToBits(keyMatrix.keyStates, TxMessage.data, MODULE_KEY_COUNT);
BoolBytesToBits(keyVector.keyStates, TxMessage.data, MODULE_KEY_COUNT);
uint8_t messageLength = BOOL_BYTES_TO_BITS_COUNT(MODULE_KEY_COUNT);
if (MODULE_POINTER_COUNT) {
pointer_delta_t *pointerDelta = (pointer_delta_t*)(TxMessage.data + messageLength);
pointerDelta->x = BlackBerryTrackball_PointerDelta.x;
pointerDelta->y = BlackBerryTrackball_PointerDelta.y;
BlackBerryTrackball_PointerDelta.x = 0;
BlackBerryTrackball_PointerDelta.y = 0;
if (keyMatrix.keyStates[0]) {
pointerDelta->x = 1;
}
messageLength += sizeof(pointer_delta_t);
}
TxMessage.length = messageLength;
Expand Down
2 changes: 1 addition & 1 deletion keycluster/src/test_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define TEST_LED_GPIO GPIOB
#define TEST_LED_PORT PORTB
#define TEST_LED_CLOCK kCLOCK_PortB
#define TEST_LED_PIN 13
#define TEST_LED_PIN 1

static inline void TestLed_On(void)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/agent
Submodule agent updated 123 files
4 changes: 3 additions & 1 deletion right/src/config_parser/parse_keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
SerializedMouseAction_ScrollRight,
SerializedMouseAction_Accelerate,
SerializedMouseAction_Decelerate,
SerializedMouseAction_Last = SerializedMouseAction_Decelerate,
SerializedMouseAction_Button_4,
SerializedMouseAction_Button_5,
SerializedMouseAction_Button_6,
SerializedMouseAction_Button_7,
SerializedMouseAction_Button_8,
SerializedMouseAction_Last = SerializedMouseAction_Button_8,
} serialized_mouse_action_t;

// Functions:
Expand Down
9 changes: 8 additions & 1 deletion right/src/slave_drivers/uhk_module_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,12 @@ void UhkModuleSlaveDriver_Disconnect(uint8_t uhkModuleDriverId)
if (uhkModuleDriverId == SlaveId_LeftKeyboardHalf) {
Slaves[SlaveId_LeftLedDriver].isConnected = false;
}
UhkModuleStates[uhkModuleDriverId].moduleId = 0;

uhk_module_state_t *uhkModuleState = UhkModuleStates + uhkModuleDriverId;
uhkModuleState->moduleId = 0;
uint8_t slotId = UhkModuleSlaveDriver_DriverIdToSlotId(uhkModuleDriverId);

if (IS_VALID_MODULE_SLOT(slotId)) {
memset(KeyStates[slotId], 0, MAX_KEY_COUNT_PER_MODULE * sizeof(key_state_t));
}
}
2 changes: 2 additions & 0 deletions right/src/slave_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ uhk_slave_t Slaves[] = {
{
.init = UhkModuleSlaveDriver_Init,
.update = UhkModuleSlaveDriver_Update,
.disconnect = UhkModuleSlaveDriver_Disconnect,
.perDriverId = UhkModuleDriverId_LeftModule,
},
{
.init = UhkModuleSlaveDriver_Init,
.update = UhkModuleSlaveDriver_Update,
.disconnect = UhkModuleSlaveDriver_Disconnect,
.perDriverId = UhkModuleDriverId_RightModule,
},
{
Expand Down
10 changes: 5 additions & 5 deletions scripts/make-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ const package = JSON.parse(fs.readFileSync(`${__dirname}/package.json`));
const version = package.firmwareVersion;
const releaseName = `uhk-firmware-${version}`;
const releaseDir = `${__dirname}/${releaseName}`;
const modulesDir = `${releaseDir}/modules`;
const releaseFile = `${__dirname}/${releaseName}.tar.bz2`;
const leftFirmwareFile = `${__dirname}/../left/build_make/uhk_left.bin`;
const usbDir = `${__dirname}/../lib/agent/packages/usb`;
const agentDir = `${__dirname}/../lib/agent`;

const deviceSourceFirmwares = package.devices.map(device => `${__dirname}/../${device.source}`);
const moduleSourceFirmwares = package.modules.map(module => `${__dirname}/../${module.source}`);
Expand All @@ -23,14 +21,16 @@ rm('-rf', releaseDir, releaseFile, deviceSourceFirmwares, moduleSourceFirmwares)
exec(`cd ${__dirname}/../left; make clean; make -j8`);
exec(`cd ${__dirname}/../right; make clean; make -j8`);

exec(`git pull origin master; git checkout master`, { cwd: agentDir });
exec(`npm ci`, { cwd: agentDir });

for (const device of package.devices) {
const deviceDir = `${releaseDir}/devices/${device.name}`;
const deviceSource = `${__dirname}/../${device.source}`;
mkdir('-p', deviceDir);
chmod(644, deviceSource);
cp(deviceSource, `${deviceDir}/firmware.hex`);
exec(`cd ${usbDir}; git pull origin master; git checkout master`);
exec(`${usbDir}/user-config-json-to-bin.ts ${deviceDir}/config.bin`);
exec(`npm run convert-user-config-to-bin -- ${deviceDir}/config.bin`, { cwd: agentDir });
}

for (const module of package.modules) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"commander": "^2.11.0",
"shelljs": "^0.7.8"
},
"firmwareVersion": "8.5.4",
"firmwareVersion": "8.6.0",
"deviceProtocolVersion": "4.5.0",
"moduleProtocolVersion": "4.0.0",
"userConfigVersion": "4.1.0",
"moduleProtocolVersion": "4.1.0",
"userConfigVersion": "4.1.1",
"hardwareConfigVersion": "1.0.0",
"devices": [
{
Expand Down
20 changes: 20 additions & 0 deletions shared/key_vector.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "fsl_gpio.h"
#include "key_vector.h"

void KeyVector_Init(key_vector_t *keyVector)
{
for (key_vector_pin_t *item = keyVector->items; item < keyVector->items + keyVector->itemNum; item++) {
CLOCK_EnableClock(item->clock);
PORT_SetPinConfig(item->port, item->pin,
&(port_pin_config_t){.pullSelect=kPORT_PullUp, .mux=kPORT_MuxAsGpio});
GPIO_PinInit(item->gpio, item->pin, &(gpio_pin_config_t){kGPIO_DigitalInput});
}
}

void KeyVector_Scan(key_vector_t *keyVector)
{
uint8_t *keyState = keyVector->keyStates;
for (key_vector_pin_t *item = keyVector->items; item < keyVector->items + keyVector->itemNum; item++) {
*(keyState++) = !GPIO_ReadPinInput(item->gpio, item->pin);
}
}
Loading

0 comments on commit f1286e7

Please sign in to comment.