summaryrefslogtreecommitdiff
path: root/quantum/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/encoder')
-rw-r--r--quantum/encoder/tests/config_encoder_common.h6
-rw-r--r--quantum/encoder/tests/config_mock.h3
-rw-r--r--quantum/encoder/tests/config_mock_split_left_eq_right.h3
-rw-r--r--quantum/encoder/tests/config_mock_split_left_gt_right.h3
-rw-r--r--quantum/encoder/tests/config_mock_split_left_lt_right.h3
-rw-r--r--quantum/encoder/tests/config_mock_split_no_left.h3
-rw-r--r--quantum/encoder/tests/config_mock_split_no_right.h3
-rw-r--r--quantum/encoder/tests/config_mock_split_role.h3
-rw-r--r--quantum/encoder/tests/encoder_tests.cpp2
-rw-r--r--quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp91
-rw-r--r--quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp89
-rw-r--r--quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp89
-rw-r--r--quantum/encoder/tests/encoder_tests_split_no_left.cpp69
-rw-r--r--quantum/encoder/tests/encoder_tests_split_no_right.cpp66
-rw-r--r--quantum/encoder/tests/encoder_tests_split_role.cpp8
-rw-r--r--quantum/encoder/tests/mock_split.c4
-rw-r--r--quantum/encoder/tests/mock_split.h3
-rw-r--r--quantum/encoder/tests/rules.mk7
18 files changed, 329 insertions, 126 deletions
diff --git a/quantum/encoder/tests/config_encoder_common.h b/quantum/encoder/tests/config_encoder_common.h
new file mode 100644
index 0000000000..6b3b20182b
--- /dev/null
+++ b/quantum/encoder/tests/config_encoder_common.h
@@ -0,0 +1,6 @@
+// Copyright 2023 Nick Brassel (@tzarc)
+// SPDX-License-Identifier: GPL-2.0-or-later
+#pragma once
+
+// Override the one in quantum/util because it doesn't like working on x64 builds.
+#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0]))
diff --git a/quantum/encoder/tests/config_mock.h b/quantum/encoder/tests/config_mock.h
index 703dcaf103..9eb59ddc88 100644
--- a/quantum/encoder/tests/config_mock.h
+++ b/quantum/encoder/tests/config_mock.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/config_mock_split_left_eq_right.h b/quantum/encoder/tests/config_mock_split_left_eq_right.h
index c80ac4d519..ea795657ef 100644
--- a/quantum/encoder/tests/config_mock_split_left_eq_right.h
+++ b/quantum/encoder/tests/config_mock_split_left_eq_right.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/config_mock_split_left_gt_right.h b/quantum/encoder/tests/config_mock_split_left_gt_right.h
index 91d5f3d605..abcfe03918 100644
--- a/quantum/encoder/tests/config_mock_split_left_gt_right.h
+++ b/quantum/encoder/tests/config_mock_split_left_gt_right.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/config_mock_split_left_lt_right.h b/quantum/encoder/tests/config_mock_split_left_lt_right.h
index 4108a184a6..075c774b0d 100644
--- a/quantum/encoder/tests/config_mock_split_left_lt_right.h
+++ b/quantum/encoder/tests/config_mock_split_left_lt_right.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/config_mock_split_no_left.h b/quantum/encoder/tests/config_mock_split_no_left.h
index 9db7fa7e41..dfd8358929 100644
--- a/quantum/encoder/tests/config_mock_split_no_left.h
+++ b/quantum/encoder/tests/config_mock_split_no_left.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/config_mock_split_no_right.h b/quantum/encoder/tests/config_mock_split_no_right.h
index 14f18015e6..5683eade8c 100644
--- a/quantum/encoder/tests/config_mock_split_no_right.h
+++ b/quantum/encoder/tests/config_mock_split_no_right.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/config_mock_split_role.h b/quantum/encoder/tests/config_mock_split_role.h
index c80ac4d519..ea795657ef 100644
--- a/quantum/encoder/tests/config_mock_split_role.h
+++ b/quantum/encoder/tests/config_mock_split_role.h
@@ -1,6 +1,7 @@
-// Copyright 2022 Nick Brassel (@tzarc)
+// Copyright 2022-2023 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
+#include "config_encoder_common.h"
#define MATRIX_ROWS 1
#define MATRIX_COLS 1
diff --git a/quantum/encoder/tests/encoder_tests.cpp b/quantum/encoder/tests/encoder_tests.cpp
index b7c18aeec0..499e413aed 100644
--- a/quantum/encoder/tests/encoder_tests.cpp
+++ b/quantum/encoder/tests/encoder_tests.cpp
@@ -41,7 +41,7 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderTest : public ::testing::Test {};
diff --git a/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp b/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp
index 916e47b185..7d6b3e30e6 100644
--- a/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp
+++ b/quantum/encoder/tests/encoder_tests_split_left_eq_right.cpp
@@ -33,22 +33,29 @@ struct update {
uint8_t updates_array_idx = 0;
update updates[32];
+bool isMaster;
bool isLeftHand;
+extern "C" {
+bool is_keyboard_master(void) {
+ return isMaster;
+}
+
bool encoder_update_kb(uint8_t index, bool clockwise) {
- if (!isLeftHand) {
+ if (!is_keyboard_master()) {
// this method has no effect on slave half
- printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC");
+ printf("ignoring update on slave (%d,%s)\n", index, clockwise ? "CW" : "CC");
return true;
}
updates[updates_array_idx % 32] = {index, clockwise};
updates_array_idx++;
return true;
}
+};
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderSplitTestLeftEqRight : public ::testing::Test {
@@ -63,6 +70,7 @@ class EncoderSplitTestLeftEqRight : public ::testing::Test {
};
TEST_F(EncoderSplitTestLeftEqRight, TestInitLeft) {
+ isMaster = true;
isLeftHand = true;
encoder_init();
EXPECT_EQ(pinIsInputHigh[0], true);
@@ -77,6 +85,7 @@ TEST_F(EncoderSplitTestLeftEqRight, TestInitLeft) {
}
TEST_F(EncoderSplitTestLeftEqRight, TestInitRight) {
+ isMaster = true;
isLeftHand = false;
encoder_init();
EXPECT_EQ(pinIsInputHigh[0], false);
@@ -90,7 +99,8 @@ TEST_F(EncoderSplitTestLeftEqRight, TestInitRight) {
EXPECT_EQ(updates_array_idx, 0); // no updates received
}
-TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseLeft) {
+TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseLeftMaster) {
+ isMaster = true;
isLeftHand = true;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -102,9 +112,19 @@ TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseLeft) {
EXPECT_EQ(updates_array_idx, 1); // one update received
EXPECT_EQ(updates[0].index, 0);
EXPECT_EQ(updates[0].clockwise, true);
+
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseRightSent) {
+TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseRightMaster) {
+ isMaster = true;
isLeftHand = false;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -113,23 +133,60 @@ TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseRightSent) {
setAndRead(6, true);
setAndRead(7, true);
- uint8_t slave_state[32] = {0};
- encoder_state_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 1); // one update received
+ EXPECT_EQ(updates[0].index, 3);
+ EXPECT_EQ(updates[0].clockwise, true);
- EXPECT_EQ(slave_state[0], 0);
- EXPECT_EQ(slave_state[1], 0xFF);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestLeftEqRight, TestMultipleEncodersRightReceived) {
+TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseLeftSlave) {
+ isMaster = false;
isLeftHand = true;
encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(0, false);
+ setAndRead(1, false);
+ setAndRead(0, true);
+ setAndRead(1, true);
- uint8_t slave_state[32] = {1, 0xFF}; // First right encoder is CCW, Second right encoder CW
- encoder_update_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
- EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side
- EXPECT_EQ(updates[0].index, 2);
- EXPECT_EQ(updates[0].clockwise, false);
- EXPECT_EQ(updates[1].index, 3);
- EXPECT_EQ(updates[1].clockwise, true);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
+}
+
+TEST_F(EncoderSplitTestLeftEqRight, TestOneClockwiseRightSlave) {
+ isMaster = false;
+ isLeftHand = false;
+ encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(6, false);
+ setAndRead(7, false);
+ setAndRead(6, true);
+ setAndRead(7, true);
+
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
+
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
}
diff --git a/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp b/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp
index 7b64bb2981..2beb4e3972 100644
--- a/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp
+++ b/quantum/encoder/tests/encoder_tests_split_left_gt_right.cpp
@@ -33,22 +33,29 @@ struct update {
uint8_t updates_array_idx = 0;
update updates[32];
+bool isMaster;
bool isLeftHand;
+extern "C" {
+bool is_keyboard_master(void) {
+ return isMaster;
+}
+
bool encoder_update_kb(uint8_t index, bool clockwise) {
- if (!isLeftHand) {
+ if (!is_keyboard_master()) {
// this method has no effect on slave half
- printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC");
+ printf("ignoring update on slave (%d,%s)\n", index, clockwise ? "CW" : "CC");
return true;
}
updates[updates_array_idx % 32] = {index, clockwise};
updates_array_idx++;
return true;
}
+};
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderSplitTestLeftGreaterThanRight : public ::testing::Test {
@@ -94,7 +101,8 @@ TEST_F(EncoderSplitTestLeftGreaterThanRight, TestInitRight) {
EXPECT_EQ(updates_array_idx, 0); // no updates received
}
-TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseLeft) {
+TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseLeftMaster) {
+ isMaster = true;
isLeftHand = true;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -106,9 +114,19 @@ TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseLeft) {
EXPECT_EQ(updates_array_idx, 1); // one update received
EXPECT_EQ(updates[0].index, 0);
EXPECT_EQ(updates[0].clockwise, true);
+
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseRightSent) {
+TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseRightMaster) {
+ isMaster = true;
isLeftHand = false;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -117,23 +135,60 @@ TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseRightSent) {
setAndRead(6, true);
setAndRead(7, true);
- uint8_t slave_state[32] = {0};
- encoder_state_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 1); // one update received
+ EXPECT_EQ(updates[0].index, 3);
+ EXPECT_EQ(updates[0].clockwise, true);
- EXPECT_EQ(slave_state[0], 0xFF);
- EXPECT_EQ(slave_state[1], 0);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestLeftGreaterThanRight, TestMultipleEncodersRightReceived) {
+TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseLeftSlave) {
+ isMaster = false;
isLeftHand = true;
encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(0, false);
+ setAndRead(1, false);
+ setAndRead(0, true);
+ setAndRead(1, true);
- uint8_t slave_state[32] = {1, 0xFF}; // First right encoder is CCW, Second right encoder no change, third right encoder CW
- encoder_update_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
- EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side
- EXPECT_EQ(updates[0].index, 3);
- EXPECT_EQ(updates[0].clockwise, false);
- EXPECT_EQ(updates[1].index, 4);
- EXPECT_EQ(updates[1].clockwise, true);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
+}
+
+TEST_F(EncoderSplitTestLeftGreaterThanRight, TestOneClockwiseRightSlave) {
+ isMaster = false;
+ isLeftHand = false;
+ encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(6, false);
+ setAndRead(7, false);
+ setAndRead(6, true);
+ setAndRead(7, true);
+
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
+
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
}
diff --git a/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp b/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp
index a6519c5762..5612f8b658 100644
--- a/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp
+++ b/quantum/encoder/tests/encoder_tests_split_left_lt_right.cpp
@@ -33,22 +33,29 @@ struct update {
uint8_t updates_array_idx = 0;
update updates[32];
+bool isMaster;
bool isLeftHand;
+extern "C" {
+bool is_keyboard_master(void) {
+ return isMaster;
+}
+
bool encoder_update_kb(uint8_t index, bool clockwise) {
- if (!isLeftHand) {
+ if (!is_keyboard_master()) {
// this method has no effect on slave half
- printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC");
+ printf("ignoring update on slave (%d,%s)\n", index, clockwise ? "CW" : "CC");
return true;
}
updates[updates_array_idx % 32] = {index, clockwise};
updates_array_idx++;
return true;
}
+};
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderSplitTestLeftLessThanRight : public ::testing::Test {
@@ -94,7 +101,8 @@ TEST_F(EncoderSplitTestLeftLessThanRight, TestInitRight) {
EXPECT_EQ(updates_array_idx, 0); // no updates received
}
-TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseLeft) {
+TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseLeftMaster) {
+ isMaster = true;
isLeftHand = true;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -106,9 +114,19 @@ TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseLeft) {
EXPECT_EQ(updates_array_idx, 1); // one update received
EXPECT_EQ(updates[0].index, 0);
EXPECT_EQ(updates[0].clockwise, true);
+
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseRightSent) {
+TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseRightMaster) {
+ isMaster = true;
isLeftHand = false;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -117,23 +135,60 @@ TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseRightSent) {
setAndRead(6, true);
setAndRead(7, true);
- uint8_t slave_state[32] = {0};
- encoder_state_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 1); // one update received
+ EXPECT_EQ(updates[0].index, 3);
+ EXPECT_EQ(updates[0].clockwise, true);
- EXPECT_EQ(slave_state[0], 0);
- EXPECT_EQ(slave_state[1], 0xFF);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestLeftLessThanRight, TestMultipleEncodersRightReceived) {
+TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseLeftSlave) {
+ isMaster = false;
isLeftHand = true;
encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(0, false);
+ setAndRead(1, false);
+ setAndRead(0, true);
+ setAndRead(1, true);
- uint8_t slave_state[32] = {1, 0, 0xFF}; // First right encoder is CCW, Second right encoder no change, third right encoder CW
- encoder_update_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
- EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side
- EXPECT_EQ(updates[0].index, 2);
- EXPECT_EQ(updates[0].clockwise, false);
- EXPECT_EQ(updates[1].index, 4);
- EXPECT_EQ(updates[1].clockwise, true);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
+}
+
+TEST_F(EncoderSplitTestLeftLessThanRight, TestOneClockwiseRightSlave) {
+ isMaster = false;
+ isLeftHand = false;
+ encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(6, false);
+ setAndRead(7, false);
+ setAndRead(6, true);
+ setAndRead(7, true);
+
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
+
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
}
diff --git a/quantum/encoder/tests/encoder_tests_split_no_left.cpp b/quantum/encoder/tests/encoder_tests_split_no_left.cpp
index b6b2d7e2d1..980e4074ff 100644
--- a/quantum/encoder/tests/encoder_tests_split_no_left.cpp
+++ b/quantum/encoder/tests/encoder_tests_split_no_left.cpp
@@ -33,22 +33,29 @@ struct update {
uint8_t updates_array_idx = 0;
update updates[32];
+bool isMaster;
bool isLeftHand;
+extern "C" {
+bool is_keyboard_master(void) {
+ return isMaster;
+}
+
bool encoder_update_kb(uint8_t index, bool clockwise) {
- if (!isLeftHand) {
+ if (!is_keyboard_master()) {
// this method has no effect on slave half
- printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC");
+ printf("ignoring update on slave (%d,%s)\n", index, clockwise ? "CW" : "CC");
return true;
}
updates[updates_array_idx % 32] = {index, clockwise};
updates_array_idx++;
return true;
}
+};
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderSplitTestNoLeft : public ::testing::Test {
@@ -82,19 +89,8 @@ TEST_F(EncoderSplitTestNoLeft, TestInitRight) {
EXPECT_EQ(updates_array_idx, 0); // no updates received
}
-TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseLeft) {
- isLeftHand = true;
- encoder_init();
- // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
- setAndRead(0, false);
- setAndRead(1, false);
- setAndRead(0, true);
- setAndRead(1, true);
-
- EXPECT_EQ(updates_array_idx, 0); // no updates received
-}
-
-TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseRightSent) {
+TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseLeftMaster) {
+ isMaster = true;
isLeftHand = false;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
@@ -103,23 +99,38 @@ TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseRightSent) {
setAndRead(2, true);
setAndRead(3, true);
- uint8_t slave_state[32] = {0};
- encoder_state_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 1); // one update received
+ EXPECT_EQ(updates[0].index, 1);
+ EXPECT_EQ(updates[0].clockwise, true);
- EXPECT_EQ(slave_state[0], 0);
- EXPECT_EQ(slave_state[1], 0xFF);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestNoLeft, TestMultipleEncodersRightReceived) {
- isLeftHand = true;
+TEST_F(EncoderSplitTestNoLeft, TestOneClockwiseRightSlave) {
+ isMaster = false;
+ isLeftHand = false;
encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(2, false);
+ setAndRead(3, false);
+ setAndRead(2, true);
+ setAndRead(3, true);
- uint8_t slave_state[32] = {1, 0xFF}; // First right encoder is CCW, Second right encoder no change, third right encoder CW
- encoder_update_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
- EXPECT_EQ(updates_array_idx, 2); // two updates received, one for each changed item on the right side
- EXPECT_EQ(updates[0].index, 0);
- EXPECT_EQ(updates[0].clockwise, false);
- EXPECT_EQ(updates[1].index, 1);
- EXPECT_EQ(updates[1].clockwise, true);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
}
diff --git a/quantum/encoder/tests/encoder_tests_split_no_right.cpp b/quantum/encoder/tests/encoder_tests_split_no_right.cpp
index fa0a7c18a8..d39659853b 100644
--- a/quantum/encoder/tests/encoder_tests_split_no_right.cpp
+++ b/quantum/encoder/tests/encoder_tests_split_no_right.cpp
@@ -33,22 +33,29 @@ struct update {
uint8_t updates_array_idx = 0;
update updates[32];
+bool isMaster;
bool isLeftHand;
+extern "C" {
+bool is_keyboard_master(void) {
+ return isMaster;
+}
+
bool encoder_update_kb(uint8_t index, bool clockwise) {
- if (!isLeftHand) {
+ if (!is_keyboard_master()) {
// this method has no effect on slave half
- printf("ignoring update on right hand (%d,%s)\n", index, clockwise ? "CW" : "CC");
+ printf("ignoring update on slave (%d,%s)\n", index, clockwise ? "CW" : "CC");
return true;
}
updates[updates_array_idx % 32] = {index, clockwise};
updates_array_idx++;
return true;
}
+};
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderSplitTestNoRight : public ::testing::Test {
@@ -82,37 +89,48 @@ TEST_F(EncoderSplitTestNoRight, TestInitRight) {
EXPECT_EQ(updates_array_idx, 0); // no updates received
}
-TEST_F(EncoderSplitTestNoRight, TestOneClockwiseLeft) {
+TEST_F(EncoderSplitTestNoRight, TestOneClockwiseLeftMaster) {
+ isMaster = true;
isLeftHand = true;
encoder_init();
// send 4 pulses. with resolution 4, that's one step and we should get 1 update.
- setAndRead(0, false);
- setAndRead(1, false);
- setAndRead(0, true);
- setAndRead(1, true);
+ setAndRead(2, false);
+ setAndRead(3, false);
+ setAndRead(2, true);
+ setAndRead(3, true);
- EXPECT_EQ(updates_array_idx, 1); // one updates received
- EXPECT_EQ(updates[0].index, 0);
+ EXPECT_EQ(updates_array_idx, 1); // one update received
+ EXPECT_EQ(updates[0].index, 1);
EXPECT_EQ(updates[0].clockwise, true);
-}
-TEST_F(EncoderSplitTestNoRight, TestOneClockwiseRightSent) {
- isLeftHand = false;
- encoder_init();
-
- uint8_t slave_state[32] = {0xAA, 0xAA};
- encoder_state_raw(slave_state);
-
- EXPECT_EQ(slave_state[0], 0xAA);
- EXPECT_EQ(slave_state[1], 0xAA);
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 0); // No events should be queued on master
}
-TEST_F(EncoderSplitTestNoRight, TestMultipleEncodersRightReceived) {
+TEST_F(EncoderSplitTestNoRight, TestOneClockwiseRightSlave) {
+ isMaster = false;
isLeftHand = true;
encoder_init();
+ // send 4 pulses. with resolution 4, that's one step and we should get 1 update.
+ setAndRead(2, false);
+ setAndRead(3, false);
+ setAndRead(2, true);
+ setAndRead(3, true);
- uint8_t slave_state[32] = {1, 0xFF}; // These values would trigger updates if there were encoders on the other side
- encoder_update_raw(slave_state);
+ EXPECT_EQ(updates_array_idx, 0); // no updates received
- EXPECT_EQ(updates_array_idx, 0); // no updates received -- no right-hand encoders
+ int events_queued = 0;
+ encoder_events_t events;
+ encoder_retrieve_events(&events);
+ while (events.tail != events.head) {
+ events.tail = (events.tail + 1) % MAX_QUEUED_ENCODER_EVENTS;
+ ++events_queued;
+ }
+ EXPECT_EQ(events_queued, 1); // One event should be queued on slave
}
diff --git a/quantum/encoder/tests/encoder_tests_split_role.cpp b/quantum/encoder/tests/encoder_tests_split_role.cpp
index 0ab7bfc2a7..b588af8c70 100644
--- a/quantum/encoder/tests/encoder_tests_split_role.cpp
+++ b/quantum/encoder/tests/encoder_tests_split_role.cpp
@@ -50,7 +50,7 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
bool setAndRead(pin_t pin, bool val) {
setPin(pin, val);
- return encoder_read();
+ return encoder_task();
}
class EncoderSplitTestRole : public ::testing::Test {
@@ -87,9 +87,6 @@ TEST_F(EncoderSplitTestRole, TestPrimaryRight) {
setAndRead(6, true);
setAndRead(7, true);
- uint8_t slave_state[32] = {0};
- encoder_state_raw(slave_state);
-
EXPECT_EQ(num_updates, 1); // one update received
}
@@ -116,8 +113,5 @@ TEST_F(EncoderSplitTestRole, TestNotPrimaryRight) {
setAndRead(6, true);
setAndRead(7, true);
- uint8_t slave_state[32] = {0};
- encoder_state_raw(slave_state);
-
EXPECT_EQ(num_updates, 0); // zero updates received
}
diff --git a/quantum/encoder/tests/mock_split.c b/quantum/encoder/tests/mock_split.c
index f024c2058d..fb5f074fbb 100644
--- a/quantum/encoder/tests/mock_split.c
+++ b/quantum/encoder/tests/mock_split.c
@@ -36,7 +36,3 @@ bool setPin(pin_t pin, bool val) {
}
void last_encoder_activity_trigger(void) {}
-
-__attribute__((weak)) bool is_keyboard_master(void) {
- return true;
-}
diff --git a/quantum/encoder/tests/mock_split.h b/quantum/encoder/tests/mock_split.h
index 8b4a141078..0d108afa6e 100644
--- a/quantum/encoder/tests/mock_split.h
+++ b/quantum/encoder/tests/mock_split.h
@@ -22,9 +22,6 @@
#define SPLIT_KEYBOARD
typedef uint8_t pin_t;
-void encoder_state_raw(uint8_t* slave_state);
-void encoder_update_raw(uint8_t* slave_state);
-
extern bool pins[];
extern bool pinIsInputHigh[];
diff --git a/quantum/encoder/tests/rules.mk b/quantum/encoder/tests/rules.mk
index d01c1c66ee..eb6106039e 100644
--- a/quantum/encoder/tests/rules.mk
+++ b/quantum/encoder/tests/rules.mk
@@ -3,6 +3,7 @@ encoder_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock.h
encoder_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests.cpp \
$(QUANTUM_PATH)/encoder.c
@@ -13,6 +14,7 @@ encoder_split_left_eq_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_
encoder_split_left_eq_right_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock_split.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests_split_left_eq_right.cpp \
$(QUANTUM_PATH)/encoder.c
@@ -23,6 +25,7 @@ encoder_split_left_gt_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_
encoder_split_left_gt_right_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock_split.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests_split_left_gt_right.cpp \
$(QUANTUM_PATH)/encoder.c
@@ -33,6 +36,7 @@ encoder_split_left_lt_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_
encoder_split_left_lt_right_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock_split.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests_split_left_lt_right.cpp \
$(QUANTUM_PATH)/encoder.c
@@ -43,6 +47,7 @@ encoder_split_no_left_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_
encoder_split_no_left_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock_split.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests_split_no_left.cpp \
$(QUANTUM_PATH)/encoder.c
@@ -53,6 +58,7 @@ encoder_split_no_right_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split
encoder_split_no_right_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock_split.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests_split_no_right.cpp \
$(QUANTUM_PATH)/encoder.c
@@ -63,6 +69,7 @@ encoder_split_role_CONFIG := $(QUANTUM_PATH)/encoder/tests/config_mock_split_rol
encoder_split_role_SRC := \
platforms/test/timer.c \
+ drivers/encoder/encoder_quadrature.c \
$(QUANTUM_PATH)/encoder/tests/mock_split.c \
$(QUANTUM_PATH)/encoder/tests/encoder_tests_split_role.cpp \
$(QUANTUM_PATH)/encoder.c