Skip to content

Commit

Permalink
Merge branch 'variants'
Browse files Browse the repository at this point in the history
  • Loading branch information
yahiro07 committed Mar 10, 2024
2 parents 09b16c4 + e66cb27 commit 12f520c
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 21 deletions.
3 changes: 2 additions & 1 deletion firmware/docs/storage_format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BB BB ...: チャンクのボディデータ, LL LL で規定されるサイズ
storageSystemParametersRevision: U8;
softwareStorageFomartRevision: U8;
};
systemParameters: Chunk<0xaa30, 10> & {
systemParameters: Chunk<0xaa30, 11> & {
emitRealtimeEvents: U8;
keyHoldLedOutput: U8;
heartBeatLedOutput: U8;
Expand All @@ -36,6 +36,7 @@ BB BB ...: チャンクのボディデータ, LL LL で規定されるサイズ
glowColor: U8;
glowBrightness: U8;
glowPattern: U8;
debounceWaitMs: U8;
};
customParameters: Chunk<0xaa40, "KM0_KEYBOARD__NUM_CUSTOM_PARAMETERS"> & {};
profileData: Chunk<0xaa70> & {
Expand Down
4 changes: 3 additions & 1 deletion firmware/src/modules/km0/kernel/commandDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "km0/types.h"

#define NumSystemParameters 10
#define NumSystemParameters 11

enum {
SystemParameter_EmitRealtimeEvents = 0,
Expand All @@ -15,6 +15,7 @@ enum {
SystemParameter_GlowColor, //0-12
SystemParameter_GlowBrightness, //0-255
SystemParameter_GlowPattern, //0-10(仮)
SystemParameter_DebounceWaitMs, //0-250
};
typedef struct {
uint8_t emitRealtimeEvents;
Expand All @@ -27,6 +28,7 @@ typedef struct {
uint8_t glowColor;
uint8_t glowBrightness;
uint8_t glowPattern;
uint8_t debounceWaitMs;
} T_SystemParametersSet;

enum {
Expand Down
4 changes: 3 additions & 1 deletion firmware/src/modules/km0/kernel/configManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static const T_SystemParametersSet systemParametersDefault = {
.glowColor = 0,
.glowBrightness = 20,
.glowPattern = 0,
.debounceWaitMs = 0,
};

static T_SystemParametersSet systemParameterMaxValues = {
Expand All @@ -56,6 +57,7 @@ static T_SystemParametersSet systemParameterMaxValues = {
.glowColor = 255,
.glowBrightness = 255,
.glowPattern = 255,
.debounceWaitMs = 200,
};

static void notifyParameterChanged(uint8_t eventType, uint8_t parameterIndex, uint8_t value) {
Expand Down Expand Up @@ -113,7 +115,7 @@ uint16_t configManager_getParameterExposeFlags() {
return parameterExposeFlags;
}

void configManager_setParameterExposeFlagsForBoardLeds(){
void configManager_setParameterExposeFlagsForBoardLeds() {
configManager_setParameterExposeFlag(SystemParameter_HeartbeatLed);
configManager_setParameterExposeFlag(SystemParameter_KeyHoldIndicatorLed);
}
Expand Down
32 changes: 29 additions & 3 deletions firmware/src/modules/km0/kernel/keyboardMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ scanSlotFlags, nextScanSlotFlags
前半に左手側,後半に右手側のキー状態を持つ
*/
static uint8_t scanSlotFlags[NumScanSlotBytes] = { 0 };
static uint8_t intermediateScanSlotFlags[NumScanSlotBytes] = { 0 };
static uint8_t inputScanSlotFlags[NumScanSlotBytes] = { 0 };

static uint8_t debouncingTickCounter[NumScanSlots] = { 0 };

static uint16_t localLayerFlags = 0;
static uint8_t localHidReport[8] = { 0 };

Expand Down Expand Up @@ -350,10 +353,32 @@ static void onPhysicalKeyStateChanged(uint8_t scanIndex, bool isDown) {
//----------------------------------------------------------------------

//キー状態更新処理
static void processKeyStatesUpdate() {
static void processKeyStatesUpdate(uint8_t elapsed) {
uint8_t debouncingWaitMs = configManager_readParameter(SystemParameter_DebounceWaitMs);
if (debouncingWaitMs > 0) {
for (uint8_t i = 0; i < NumScanSlots; i++) {
uint8_t curr = utils_readArrayedBitFlagsBit(intermediateScanSlotFlags, i);
uint8_t next = utils_readArrayedBitFlagsBit(inputScanSlotFlags, i);

if (debouncingTickCounter[i] == 0) {
} else if (debouncingTickCounter[i] < elapsed) {
debouncingTickCounter[i] = 0;
} else {
debouncingTickCounter[i] -= elapsed;
}

if (next != curr && debouncingTickCounter[i] == 0) {
utils_writeArrayedBitFlagsBit(intermediateScanSlotFlags, i, next);
debouncingTickCounter[i] = debouncingWaitMs;
}
}
} else {
utils_copyBytes(intermediateScanSlotFlags, inputScanSlotFlags, NumScanSlotBytes);
}

for (uint8_t i = 0; i < NumScanSlots; i++) {
uint8_t curr = utils_readArrayedBitFlagsBit(scanSlotFlags, i);
uint8_t next = utils_readArrayedBitFlagsBit(inputScanSlotFlags, i);
uint8_t next = utils_readArrayedBitFlagsBit(intermediateScanSlotFlags, i);
if (!curr && next) {
onPhysicalKeyStateChanged(i, true);
}
Expand Down Expand Up @@ -416,6 +441,7 @@ void keyboardMain_initialize() {
configManager_setParameterExposeFlag(SystemParameter_EmitRealtimeEvents);
configManager_setParameterExposeFlag(SystemParameter_SystemLayout);
configManager_setParameterExposeFlag(SystemParameter_WiringMode);
configManager_setParameterExposeFlag(SystemParameter_DebounceWaitMs);
dataMemory_initialize();
dataStorage_initialize();
configManager_addParameterChangeListener(parameterValueHandler);
Expand Down Expand Up @@ -447,7 +473,7 @@ void keyboardMain_processKeyInputUpdate() {
uint32_t tickMs = system_getSystemTimeMs();
uint32_t elapsed = utils_clamp(tickMs - prevTickMs, 0, 100);

processKeyStatesUpdate();
processKeyStatesUpdate(elapsed);
keyboardCoreLogic_processTicker(elapsed);
processKeyboardCoreLogicOutput();

Expand Down
2 changes: 1 addition & 1 deletion firmware/src/modules/km0/kernel/versionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define Kermite_ConfigStorageFormatRevision 6
#define Kermite_RawHidMessageProtocolRevision 5
#define Kermite_ProfileBinaryFormatRevision 5
#define Kermite_ConfigParametersRevision 5
#define Kermite_ConfigParametersRevision 6

#define Kermite_Project_ReleaseBuildRevision EXTR_KERMITE_PROJECT_RELEASE_BUILD_REVISION
#define Kermite_Project_VariationName EXTR_KERMITE_VARIATION_NAME
Expand Down
15 changes: 15 additions & 0 deletions firmware/src/projects/proto/astelia/rp/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#define KERMITE_FIRMWARE_ID "9CJAA4"
#define KERMITE_KEYBOARD_NAME "astelia"

#define KS_NUM_SCAN_SLOTS 48

#define KS_NUM_COLUMNS 6
#define KS_NUM_ROWS 8

#define KS_COLUMN_PINS \
{ GP5, GP4, GP26, GP27, GP28, GP29 }

#define KS_ROW_PINS \
{ GP6, GP7, GP8, GP9, GP22, GP20, GP23, GP21 }
6 changes: 6 additions & 0 deletions firmware/src/projects/proto/astelia/rp/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TARGET_MCU = rp2040
TARGET_STENCIL = stencil_default

KL_USE_GENERAL_KEYBOARD = 1
KL_USE_BOARD_LEDS_PROMICRO_RP = 1
KL_USE_KEY_MATRIX = 1
1 change: 1 addition & 0 deletions software/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ tsconfig.tsbuildinfo

/public/debug_local_firmwares/

.env

3 changes: 2 additions & 1 deletion software/src/shared/defs/commandDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const NumSystemParameters = 10;
export const NumSystemParameters = 11;

export const enum SystemParameter {
EmitRealtimeEvents = 0,
Expand All @@ -11,6 +11,7 @@ export const enum SystemParameter {
GlowColor,
GlowBrightness,
GlowPattern,
DebounceWaitMs,
}

export type SystemAction =
Expand Down
18 changes: 15 additions & 3 deletions software/src/shared/defs/customErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type IAppErrorsSource = {
FailedToLoadRemoteResource: { url: string };
// [key: string]: { [key in string]?: string };
InvalidLocalFileExtension: { fileName: string };
IncompatibleFirmwareVersion: {};
};

type IErrorType = keyof IAppErrorsSource;
Expand All @@ -28,6 +29,7 @@ const errorTextMapEN: { [key in IErrorType]: string } = {
InvalidProfileFileSchema: `Invalid schema for file.`,
FailedToLoadRemoteResource: `Failed to fetch remote resource.`,
InvalidLocalFileExtension: `Invalid file extension.`,
IncompatibleFirmwareVersion: `Incompatible firmware version. Please update the firmware.`,
};

const errorTextMapJP: { [key in IErrorType]: string } = {
Expand All @@ -42,6 +44,7 @@ const errorTextMapJP: { [key in IErrorType]: string } = {
InvalidProfileFileSchema: `プロファイルファイルの形式が不正です。`,
FailedToLoadRemoteResource: `リソースの取得に失敗しました。`,
InvalidLocalFileExtension: `ファイルの拡張子が不正です。`,
IncompatibleFirmwareVersion: `ファームウェアのバージョンに互換性がありません。\n最新のファームウェアに更新してください。`,
};

const fieldNameDictionaryJP: { [key: string]: string } = {
Expand All @@ -57,6 +60,7 @@ export type IAppErrorData<T extends keyof IAppErrorsSource> =
type: T;
params: IAppErrorsSource[T];
stack: string;
messageOverride?: string;
}
| {
isAppError: false;
Expand All @@ -67,12 +71,19 @@ export class AppError<T extends keyof IAppErrorsSource> extends Error {
type: T;
params: IAppErrorsSource[T];
originalError: any;
messageOverride?: string;

constructor(type: T, params: IAppErrorsSource[T], original?: any) {
constructor(
type: T,
params: IAppErrorsSource[T],
original?: any,
messageOverride?: string,
) {
super(original?.message || type);
this.type = type;
this.params = params;
this.originalError = original;
this.messageOverride = messageOverride;
}
}

Expand Down Expand Up @@ -107,6 +118,7 @@ export function getAppErrorData(
type: error.type,
params: error.params,
stack: makeCompactStackTrace(error),
messageOverride: error.messageOverride,
};
} else {
return {
Expand All @@ -118,7 +130,7 @@ export function getAppErrorData(

export function makeDisplayErrorMessage(errorData: IAppErrorData<any>) {
if (errorData.isAppError) {
const { type, params, stack } = errorData;
const { type, params, stack, messageOverride } = errorData;
const headline = errorTextMapJP[type as IErrorType] || type; // TODO: 多言語対応
const paramsLines = Object.keys(params)
.map(
Expand All @@ -128,7 +140,7 @@ export function makeDisplayErrorMessage(errorData: IAppErrorData<any>) {
return `${headline}${paramsLines ? '\n' + paramsLines : ''}
詳細:
${stack}
${messageOverride ?? stack}
`;
} else {
return errorData.stack;
Expand Down
23 changes: 22 additions & 1 deletion software/src/shared/defs/customParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ export type ICustomParameterSpec_Select = {
defaultValue: number;
};

export type ICustomParameterSpec_NumberEdit = {
type: 'numberEdit';
slotIndex: number;
label: string;
minValue: number;
maxValue: number;
defaultValue: number;
unit: string;
};

export type ICustomParameterSpec =
| ICustomParameterSpec_Toggle
| ICustomParameterSpec_Linear
| ICustomParameterSpec_Select;
| ICustomParameterSpec_Select
| ICustomParameterSpec_NumberEdit;

export const SystemParameterDefinitions: ICustomParameterSpec[] = [
{
Expand Down Expand Up @@ -107,6 +118,15 @@ export const SystemParameterDefinitions: ICustomParameterSpec[] = [
defaultValue: 0,
maxValue: 255, // read from firmware
},
{
slotIndex: 10,
type: 'numberEdit',
label: 'Debouncing Wait',
minValue: 0,
maxValue: 200,
defaultValue: 0,
unit: 'ms',
},
];

export function getSystemParameterDefinitionBySystemParameterKey(
Expand All @@ -123,6 +143,7 @@ export function getSystemParameterDefinitionBySystemParameterKey(
'glowColor',
'glowBrightness',
'glowPattern',
'debounceWaitMs',
];
const index = keys.indexOf(systemParameterKey);
if (index >= 0) {
Expand Down
3 changes: 2 additions & 1 deletion software/src/shared/defs/versionDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export const ProfileBinaryFormatRevision = 5;
// 210706, 3, emitKeyStrokeを削除
// 210706, 4, systemLayoutをUS:0,JIS:1に戻す
// 210712, 5, glowDirectionとglowSpeedを削除
export const ConfigParametersRevision = 5;
// 240310, 6, debouncingWaitMsを追加
export const ConfigParametersRevision = 6;
2 changes: 1 addition & 1 deletion software/src/shell/base/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const processEnv = (import.meta as any).env as IProcessEnv;
// console.log({ processEnv });

export const appConfig = {
applicationVersion: 'v240207',
applicationVersion: 'v240310',
isDevelopment: processEnv.DEV,
// isDevelopment: location.host === 'localhost',
// applicationVersion: app.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AppError,
ConfigParametersRevision,
ConfigStorageFormatRevision,
delayMs,
Expand All @@ -21,8 +22,11 @@ function checkRevisionValue(
softwareValue: number,
) {
if (firmwareValue !== softwareValue) {
throw new Error(
`incompatible ${label} (software:${softwareValue}, firmware:${firmwareValue})`,
throw new AppError(
'IncompatibleFirmwareVersion',
{},
{},
`Incompatible ${label} (software:${softwareValue}, firmware:${firmwareValue})`,
);
}
}
Expand Down
Loading

0 comments on commit 12f520c

Please sign in to comment.