diff options
| author | Your Name <you@example.com> | 2026-05-18 22:44:37 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-18 22:44:37 +0530 |
| commit | f2c4b15c72a2fa89caed5d8a11a4ea9832c48be6 (patch) | |
| tree | 4cfaa400b1bddcd6cff2a5e53f3789256c40700d /tests/unit/test_touch.c | |
| parent | 7820837d79ebc8e00221b5206bdd8e3ca0ae4c15 (diff) | |
feat: add AXS15231B touch driver with coordinate parsing tests
Diffstat (limited to 'tests/unit/test_touch.c')
| -rw-r--r-- | tests/unit/test_touch.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/unit/test_touch.c b/tests/unit/test_touch.c new file mode 100644 index 0000000..13f04b5 --- /dev/null +++ b/tests/unit/test_touch.c | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | #include "test_framework.h" | ||
| 2 | #include "../../main/touch.h" | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(void) | ||
| 6 | { | ||
| 7 | touch_point_t pt; | ||
| 8 | uint8_t data[8]; | ||
| 9 | |||
| 10 | printf("=== test_touch ===\n"); | ||
| 11 | |||
| 12 | memset(data, 0, sizeof(data)); | ||
| 13 | touch_parse_raw(data, &pt); | ||
| 14 | ASSERT(!pt.touched, "All-zero data = no touch"); | ||
| 15 | |||
| 16 | data[0] = 1; | ||
| 17 | data[1] = 1; | ||
| 18 | data[2] = 0; | ||
| 19 | data[3] = 0; | ||
| 20 | touch_parse_raw(data, &pt); | ||
| 21 | ASSERT(!pt.touched, "data[0]=1 = no touch (gesture byte nonzero)"); | ||
| 22 | |||
| 23 | data[0] = 0; | ||
| 24 | data[1] = 0; | ||
| 25 | touch_parse_raw(data, &pt); | ||
| 26 | ASSERT(!pt.touched, "data[1]=0 = no touch (touch count zero)"); | ||
| 27 | |||
| 28 | data[0] = 0; | ||
| 29 | data[1] = 1; | ||
| 30 | data[2] = 0x00; | ||
| 31 | data[3] = 0x64; | ||
| 32 | data[4] = 0x00; | ||
| 33 | data[5] = 0xC8; | ||
| 34 | data[6] = 0; | ||
| 35 | data[7] = 0; | ||
| 36 | touch_parse_raw(data, &pt); | ||
| 37 | ASSERT(pt.touched, "Valid touch: touched=true"); | ||
| 38 | ASSERT_EQ_INT(100, (int)pt.x, "Valid touch: x=100"); | ||
| 39 | ASSERT_EQ_INT(200, (int)pt.y, "Valid touch: y=200"); | ||
| 40 | |||
| 41 | data[0] = 0; | ||
| 42 | data[1] = 1; | ||
| 43 | data[2] = 0x0F; | ||
| 44 | data[3] = 0xFF; | ||
| 45 | data[4] = 0x0F; | ||
| 46 | data[5] = 0xFF; | ||
| 47 | touch_parse_raw(data, &pt); | ||
| 48 | ASSERT(pt.touched, "Max raw coords: touched=true"); | ||
| 49 | ASSERT_EQ_INT(TOUCH_MAX_X, (int)pt.x, "Max raw coords clamped to 319"); | ||
| 50 | ASSERT_EQ_INT(TOUCH_MAX_Y, (int)pt.y, "Max raw coords clamped to 479"); | ||
| 51 | |||
| 52 | data[0] = 0; | ||
| 53 | data[1] = 1; | ||
| 54 | data[2] = 0x05; | ||
| 55 | data[3] = 0x00; | ||
| 56 | data[4] = 0x08; | ||
| 57 | data[5] = 0x00; | ||
| 58 | touch_parse_raw(data, &pt); | ||
| 59 | ASSERT(pt.touched, "12-bit coords: touched=true"); | ||
| 60 | ASSERT_EQ_INT(TOUCH_MAX_X, (int)pt.x, "12-bit x: (0x05 << 8) | 0x00 = 1280, clamped to 319"); | ||
| 61 | |||
| 62 | data[0] = 0; | ||
| 63 | data[1] = 2; | ||
| 64 | touch_parse_raw(data, &pt); | ||
| 65 | ASSERT(!pt.touched, "data[1]=2 = too many touches, reject"); | ||
| 66 | |||
| 67 | touch_parse_raw(NULL, &pt); | ||
| 68 | ASSERT(!pt.touched, "NULL data = no touch"); | ||
| 69 | |||
| 70 | data[0] = 0; | ||
| 71 | data[1] = 1; | ||
| 72 | data[2] = 0x00; | ||
| 73 | data[3] = 0x00; | ||
| 74 | data[4] = 0x00; | ||
| 75 | data[5] = 0x00; | ||
| 76 | touch_parse_raw(data, &pt); | ||
| 77 | ASSERT(pt.touched, "Origin (0,0): touched=true"); | ||
| 78 | ASSERT_EQ_INT(0, (int)pt.x, "Origin: x=0"); | ||
| 79 | ASSERT_EQ_INT(0, (int)pt.y, "Origin: y=0"); | ||
| 80 | |||
| 81 | data[0] = 0; | ||
| 82 | data[1] = 1; | ||
| 83 | data[2] = 0x01; | ||
| 84 | data[3] = 0x3F; | ||
| 85 | data[4] = 0x01; | ||
| 86 | data[5] = 0xDF; | ||
| 87 | touch_parse_raw(data, &pt); | ||
| 88 | ASSERT(pt.touched, "Mid-screen: touched=true"); | ||
| 89 | ASSERT_EQ_INT(319, (int)pt.x, "Mid-screen: x=0x13F=319"); | ||
| 90 | ASSERT_EQ_INT(479, (int)pt.y, "Mid-screen: y=0x1DF=479"); | ||
| 91 | |||
| 92 | TEST_SUMMARY(); | ||
| 93 | } | ||