Skip to content

Commit

Permalink
Merge branch 'avoid-slave-side-encoder-setup' into variants
Browse files Browse the repository at this point in the history
  • Loading branch information
yahiro07 committed Dec 3, 2024
2 parents 6e14dda + 3897a5d commit 977f335
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
14 changes: 7 additions & 7 deletions firmware/src/modules/km0/wrapper/splitKeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static uint8_t sw_txbuf[SingleWireMaxPacketSize] = { 0 };
static uint8_t sw_rxbuf[SingleWireMaxPacketSize] = { 0 };

bool isRightHand = false;
void (*boardConfigCallback)(int8_t side) = NULL;
void (*boardConfigCallback)(int8_t side, bool isMaster) = NULL;

int8_t configuredBoardSide = -1;

Expand All @@ -97,12 +97,12 @@ static void taskForEach100ms(void (*taskFunc)(uint32_t)) {

//-------------------------------------------------------

static void setBoardSide(int8_t side) {
static void setBoardSide(int8_t side, bool isMaster) {
if (side != configuredBoardSide) {
isRightHand = side == 1;
printf("board side: %s\n", isRightHand ? "RIGHT" : "LEFT");
if (boardConfigCallback) {
boardConfigCallback(side);
boardConfigCallback(side, isMaster);
}
configuredBoardSide = side;
}
Expand Down Expand Up @@ -254,7 +254,7 @@ static void master_handleMasterParameterChanged(uint8_t eventType, uint8_t param
enqueueMasterStatePacket(SplitOp_MasterParameterChanged, parameterIndex, value);
}
if (pi == SystemParameter_MasterSide) {
setBoardSide(value);
setBoardSide(value, true);
}
}

Expand All @@ -264,7 +264,7 @@ static void master_handleMasterKeySlotStateChanged(uint8_t slotIndex, bool isDow

static void master_setupBoard() {
uint8_t side = configManager_readParameter(SystemParameter_MasterSide);
setBoardSide(side);
setBoardSide(side, true);
}

static void master_ledTask(uint32_t step) {
Expand Down Expand Up @@ -424,7 +424,7 @@ static void slave_consumeMasterStatePackets() {
if (parameterIndex == SystemParameter_MasterSide) {
uint8_t masterSide = value;
uint8_t slaveSide = (masterSide == 0) ? 1 : 0;
setBoardSide(slaveSide);
setBoardSide(slaveSide, false);
}
}
}
Expand Down Expand Up @@ -609,7 +609,7 @@ void splitKeyboard_setNumScanSlots(uint8_t _numScanSlotsLeft, uint8_t _numScanSl
numScanSlotBytesRight = (numScanSlotsRight + 7) / 8;
}

void splitKeyboard_setBoardConfigCallback(void (*callback)(int8_t side)) {
void splitKeyboard_setBoardConfigCallback(void (*callback)(int8_t side, bool isMaster)) {
boardConfigCallback = callback;
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/src/modules/km0/wrapper/splitKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "km0/types.h"

void splitKeyboard_setNumScanSlots(uint8_t numScanSlotsLeft, uint8_t numScanSlotsRight);
void splitKeyboard_setBoardConfigCallback(void (*callback)(int8_t side));
void splitKeyboard_setBoardConfigCallback(void (*callback)(int8_t side, bool isMaster));
void splitKeyboard_start();
18 changes: 13 additions & 5 deletions firmware/src/projects/standard/common/main_split.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ KermiteKeyboardDefinitionData defs = {
static EncoderConfig encoderConfigs[1] = { { .pinA = 0, .pinB = 0, .scanIndexBase = 0 } };
static EncoderConfig encoderConfigsR[1] = { { .pinA = 0, .pinB = 0, .scanIndexBase = 0 } };

static void setupBoard(int8_t side) {
static void setupBoard(int8_t side, bool isMaster) {

uint8_t *pins = defs.keyScannerPins;

Expand Down Expand Up @@ -139,17 +139,25 @@ static void setupBoard(int8_t side) {
config->pinA = encoderPins[0];
config->pinB = encoderPins[1];
config->scanIndexBase = scanIndexBaseL;
keyScanner_encoders_initialize(1, encoderConfigs);
keyboardMain_useKeyScanner(keyScanner_encoders_update);
if (isMaster) {
keyScanner_encoders_initialize(1, encoderConfigs);
keyboardMain_useKeyScanner(keyScanner_encoders_update);
} else {
//encoders are not supported in slave side
}
scanIndexBaseL += 2;
}
if (side == 1 && defs.numEncoderRight == 1) {
EncoderConfig *config = &encoderConfigsR[0];
config->pinA = encoderPinsR[0];
config->pinB = encoderPinsR[1];
config->scanIndexBase = scanIndexBaseR;
keyScanner_encoders_initialize(1, encoderConfigs);
keyboardMain_useKeyScanner(keyScanner_encoders_update);
if (isMaster) {
keyScanner_encoders_initialize(1, encoderConfigs);
keyboardMain_useKeyScanner(keyScanner_encoders_update);
} else {
//encoders are not supported in slave side
}
scanIndexBaseR += 2;
}
}
Expand Down

0 comments on commit 977f335

Please sign in to comment.