From 6d4bd6d6f8d63129b5660ee8523974452caf3154 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Sat, 27 Jul 2024 20:14:22 +0200 Subject: [PATCH 1/8] Megatouch MAXX WIP - Fix soh bug to only proces full commands, - Print unhandled commands too, - Temporarily change identity to SMT3. --- src/device/mouse_microtouch_touchscreen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 385dcef74..87ddf6728 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -108,7 +108,7 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) } if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { /* Output Identity */ fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "P50200\r", sizeof("P50200\r") - 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "A30600\r", sizeof("A30600\r") - 1); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ mtouch->mode = MODE_TABLET; @@ -176,8 +176,10 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); } - if (fifo8_num_used(&mtouch->resp) != fifo_used) { - pclog("Command received: %s\n", mtouch->cmd); + if (fifo8_num_used(&mtouch->resp) != fifo_used || mtouch->in_reset) { + pclog("Command handled: %s\n", mtouch->cmd); + } else { + pclog("Command ignored: %s\n", mtouch->cmd); } } @@ -216,6 +218,7 @@ mtouch_write(serial_t *serial, void *priv, uint8_t data) dev->cmd[dev->cmd_pos++] = data; } else { dev->cmd[dev->cmd_pos++] = data; + dev->soh = 0; microtouch_process_commands(dev); } } From 51cd31b8855f029acebd5eb9d2a2907f93c3ffc0 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Mon, 29 Jul 2024 18:54:06 +0200 Subject: [PATCH 2/8] Use wrapper function for Microtouch replies --- src/device/mouse_microtouch_touchscreen.c | 67 ++++++++++------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 87ddf6728..74ace2653 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -61,14 +61,21 @@ typedef struct mouse_microtouch_t { static mouse_microtouch_t *mtouch_inst = NULL; +void +mt_fifo8_puts(Fifo8 *fifo, const uint8_t *data) +{ + fifo8_push(fifo, 1); + fifo8_push_all(fifo, data, strlen(data)); + fifo8_push(fifo, '\r'); +} + void microtouch_reset_complete(void *priv) { mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv; mtouch->in_reset = false; - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } void @@ -78,8 +85,7 @@ microtouch_calibrate_timer(void *priv) if (!fifo8_num_used(&mtouch->resp)) { mtouch->cal_cntr--; - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); + mt_fifo8_puts(&mtouch->resp, "1"); } } @@ -94,42 +100,34 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) mtouch->cmd[i] = toupper(mtouch->cmd[i]); } if (mtouch->cmd[0] == 'Z') { /* Null */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { /* Finger Only */ mtouch->pen_mode = 1; - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { /* Unit Type */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "TP****00\r", sizeof("TP****00\r") - 1); + mt_fifo8_puts(&mtouch->resp, "TP****00"); } if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { /* Output Identity */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "A30600\r", sizeof("A30600\r") - 1); + mt_fifo8_puts(&mtouch->resp, "A30600"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ mtouch->mode = MODE_TABLET; - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */ /* Do not reset Mode Status for now as Photo Play 2000 relies on it */ mtouch->mode = MODE_HEX; - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *)"0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { /* Format Raw */ mtouch->mode = MODE_RAW; mtouch->cal_cntr = 0; - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { /* Mode Stream */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'R') { /* Reset */ mtouch->in_reset = true; @@ -139,42 +137,33 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) timer_on_auto(&mtouch->reset_timer, 500. * 1000.); } if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { /* Autobaud Enable/Disable */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'N' && mtouch->cmd[1] == 'M') { /* ?? */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); + mt_fifo8_puts(&mtouch->resp, "1"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'Q') { /* ?? */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); + mt_fifo8_puts(&mtouch->resp, "1"); } if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'F') { /* ?? */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); + mt_fifo8_puts(&mtouch->resp, "1"); } if (mtouch->cmd[0] == 'P') { if (mtouch->cmd[1] == 'F') mtouch->pen_mode = 3; /* Pen or Finger */ else if (mtouch->cmd[1] == 'O') mtouch->pen_mode = 2; /* Pen Only */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0");; } if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { /* Calibrate New/Extended */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "0"); mtouch->cal_cntr = 2; } if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Get Parameter Block 1 */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", sizeof("0000000000000000000000000\r") - 1); - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + mt_fifo8_puts(&mtouch->resp, "A"); + mt_fifo8_puts(&mtouch->resp, "0000000000000000000000000"); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'S' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Set Parameter Block 1 */ - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); + mt_fifo8_puts(&mtouch->resp, "A"); } if (fifo8_num_used(&mtouch->resp) != fifo_used || mtouch->in_reset) { pclog("Command handled: %s\n", mtouch->cmd); From 2616c66854bfe9054083f32d43466416ee0da7c3 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Mon, 29 Jul 2024 20:28:20 +0200 Subject: [PATCH 3/8] Add controller identity menu option --- src/device/mouse_microtouch_touchscreen.c | 43 +++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 74ace2653..c727f11a2 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -44,13 +44,20 @@ enum mtouch_modes { MODE_HEX = 3 }; +const char* mtouch_identity[] = { + "A30100", /* SMT2 Serial / SMT3(R)V */ + "A40100", /* PC Bus SMT2 */ + "P50100", /* TouchPen 4 (+) */ + "Q10100", /* SMT3(R) Serial */ +}; + typedef struct mouse_microtouch_t { double baud_rate; int b; char cmd[512]; int cmd_pos; int mode; - uint8_t cal_cntr, pen_mode; + uint8_t id, cal_cntr, pen_mode; bool soh; bool in_reset; serial_t *serial; @@ -64,9 +71,9 @@ static mouse_microtouch_t *mtouch_inst = NULL; void mt_fifo8_puts(Fifo8 *fifo, const uint8_t *data) { - fifo8_push(fifo, 1); - fifo8_push_all(fifo, data, strlen(data)); - fifo8_push(fifo, '\r'); + fifo8_push(fifo, 1); + fifo8_push_all(fifo, data, strlen(data)); + fifo8_push(fifo, '\r'); } void @@ -100,17 +107,17 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) mtouch->cmd[i] = toupper(mtouch->cmd[i]); } if (mtouch->cmd[0] == 'Z') { /* Null */ - mt_fifo8_puts(&mtouch->resp, "0"); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { /* Finger Only */ mtouch->pen_mode = 1; - mt_fifo8_puts(&mtouch->resp, "0"); + mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { /* Unit Type */ - mt_fifo8_puts(&mtouch->resp, "TP****00"); + mt_fifo8_puts(&mtouch->resp, "TP****00"); } if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { /* Output Identity */ - mt_fifo8_puts(&mtouch->resp, "A30600"); + mt_fifo8_puts(&mtouch->resp, mtouch_identity[mtouch->id]); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ mtouch->mode = MODE_TABLET; @@ -158,8 +165,8 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) mtouch->cal_cntr = 2; } if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Get Parameter Block 1 */ - mt_fifo8_puts(&mtouch->resp, "A"); - mt_fifo8_puts(&mtouch->resp, "0000000000000000000000000"); + mt_fifo8_puts(&mtouch->resp, "A"); + mt_fifo8_puts(&mtouch->resp, "0000000000000000000000000"); mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'S' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Set Parameter Block 1 */ @@ -331,6 +338,7 @@ mtouch_init(const device_t *info) timer_add(&dev->host_to_serial_timer, mtouch_write_to_host, dev, 0); timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); timer_on_auto(&dev->host_to_serial_timer, (1000000. / dev->baud_rate) * 10); + dev->id = device_get_config_int("identity"); dev->mode = MODE_TABLET; dev->pen_mode = 3; mouse_input_mode = device_get_config_int("crosshair") + 1; @@ -390,6 +398,21 @@ static const device_config_t mtouch_config[] = { { .description = "1200", .value = 1200 } } }, + { + .name = "identity", + .description = "Controller", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "A3 - SMT2 Serial / SMT3(R)V", .value = 0 }, + { .description = "A4 - SMT2 PCBus", .value = 1 }, + { .description = "P5 - TouchPen 4(+)", .value = 2 }, + { .description = "Q1 - SMT3(R) Serial", .value = 3 } + } + }, { .name = "crosshair", .description = "Show Crosshair", From 37538fd932fe1a34b0d4c4635e09c239c2b49701 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Mon, 29 Jul 2024 20:36:21 +0200 Subject: [PATCH 4/8] Correct MT format variables, to not confuse them with MT modes --- src/device/mouse_microtouch_touchscreen.c | 27 +++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index c727f11a2..7a7683b3e 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -38,10 +38,10 @@ #include <86box/fifo.h> #include <86box/video.h> /* Needed to account for overscan. */ -enum mtouch_modes { - MODE_RAW = 1, - MODE_TABLET = 2, - MODE_HEX = 3 +enum mtouch_formats { + FORMAT_RAW = 1, + FORMAT_TABLET = 2, + FORMAT_HEX = 3 }; const char* mtouch_identity[] = { @@ -56,7 +56,7 @@ typedef struct mouse_microtouch_t { int b; char cmd[512]; int cmd_pos; - int mode; + int format; uint8_t id, cal_cntr, pen_mode; bool soh; bool in_reset; @@ -120,16 +120,15 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) mt_fifo8_puts(&mtouch->resp, mtouch_identity[mtouch->id]); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ - mtouch->mode = MODE_TABLET; + mtouch->format = FORMAT_TABLET; mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */ - /* Do not reset Mode Status for now as Photo Play 2000 relies on it */ - mtouch->mode = MODE_HEX; + mtouch->format = FORMAT_HEX; mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { /* Format Raw */ - mtouch->mode = MODE_RAW; + mtouch->format = FORMAT_RAW; mtouch->cal_cntr = 0; mt_fifo8_puts(&mtouch->resp, "0"); } @@ -138,7 +137,7 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) } if (mtouch->cmd[0] == 'R') { /* Reset */ mtouch->in_reset = true; - mtouch->mode = MODE_TABLET; + mtouch->format = FORMAT_TABLET; mtouch->cal_cntr = 0; mtouch->pen_mode = 3; timer_on_auto(&mtouch->reset_timer, 500. * 1000.); @@ -225,7 +224,7 @@ mtouch_poll(void *priv) { mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; - if (fifo8_num_free(&dev->resp) <= 10 || dev->mode == MODE_RAW) { + if (fifo8_num_free(&dev->resp) <= 10 || dev->format == FORMAT_RAW) { return 0; } @@ -276,7 +275,7 @@ mtouch_poll(void *priv) return 0; } - if (dev->mode == MODE_TABLET) { + if (dev->format == FORMAT_TABLET) { abs_x_int = abs_x * 16383; abs_y_int = 16383 - abs_y * 16383; @@ -300,7 +299,7 @@ mtouch_poll(void *priv) } } - if (dev->mode == MODE_HEX) { + if (dev->format == FORMAT_HEX) { abs_x_int = abs_x * 1023; abs_y_int = 1023 - (abs_y * 1023); char buffer[10]; @@ -339,7 +338,7 @@ mtouch_init(const device_t *info) timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); timer_on_auto(&dev->host_to_serial_timer, (1000000. / dev->baud_rate) * 10); dev->id = device_get_config_int("identity"); - dev->mode = MODE_TABLET; + dev->format = FORMAT_TABLET; dev->pen_mode = 3; mouse_input_mode = device_get_config_int("crosshair") + 1; mouse_set_buttons(2); From 1eb24bf69b75c4c18cd97c98879eec30574b7528 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Mon, 29 Jul 2024 21:01:54 +0200 Subject: [PATCH 5/8] Add Format Decimal and make it default for legacy controller modes --- src/device/mouse_microtouch_touchscreen.c | 88 +++++++++++++++-------- 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 7a7683b3e..e4f3c7e7b 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -39,9 +39,10 @@ #include <86box/video.h> /* Needed to account for overscan. */ enum mtouch_formats { - FORMAT_RAW = 1, - FORMAT_TABLET = 2, - FORMAT_HEX = 3 + FORMAT_DEC = 1, + FORMAT_HEX = 2, + FORMAT_RAW = 3, + FORMAT_TABLET = 4 }; const char* mtouch_identity[] = { @@ -119,8 +120,8 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { /* Output Identity */ mt_fifo8_puts(&mtouch->resp, mtouch_identity[mtouch->id]); } - if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ - mtouch->format = FORMAT_TABLET; + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'D') { /* Format Decimal */ + mtouch->format = FORMAT_DEC; mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */ @@ -128,18 +129,27 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { /* Format Raw */ - mtouch->format = FORMAT_RAW; + mtouch->format = FORMAT_RAW; mtouch->cal_cntr = 0; mt_fifo8_puts(&mtouch->resp, "0"); } + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */ + mtouch->format = FORMAT_TABLET; + mt_fifo8_puts(&mtouch->resp, "0"); + } if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { /* Mode Stream */ mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'R') { /* Reset */ mtouch->in_reset = true; - mtouch->format = FORMAT_TABLET; mtouch->cal_cntr = 0; mtouch->pen_mode = 3; + + if (mtouch->id < 2) + mtouch->format = FORMAT_DEC; + else + mtouch->format = FORMAT_TABLET; + timer_on_auto(&mtouch->reset_timer, 500. * 1000.); } if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { /* Autobaud Enable/Disable */ @@ -274,8 +284,42 @@ mtouch_poll(void *priv) dev->b = b; /* Save lack of buttonpress */ return 0; } - - if (dev->format == FORMAT_TABLET) { + + if (dev->format == FORMAT_DEC) { + abs_x_int = abs_x * 999; + abs_y_int = 999 - (abs_y * 999); + char buffer[10]; + + if (b) { + if (!dev->b) { /* Touchdown */ + snprintf(buffer, sizeof(buffer), "\x19%03d,%03d\r", abs_x_int, abs_y_int); + } else { /* Touch Continuation */ + snprintf(buffer, sizeof(buffer), "\x1c%03d,%03d\r", abs_x_int, abs_y_int); + } + } else if (dev->b) { /* Liftoff */ + snprintf(buffer, sizeof(buffer), "\x18%03d,%03d\r", abs_x_int, abs_y_int); + } + fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer)); + } + + else if (dev->format == FORMAT_HEX) { + abs_x_int = abs_x * 1023; + abs_y_int = 1023 - (abs_y * 1023); + char buffer[10]; + + if (b) { + if (!dev->b) { /* Touchdown */ + snprintf(buffer, sizeof(buffer), "\x19%03X,%03X\r", abs_x_int, abs_y_int); + } else { /* Touch Continuation */ + snprintf(buffer, sizeof(buffer), "\x1c%03X,%03X\r", abs_x_int, abs_y_int); + } + } else if (dev->b) { /* Liftoff */ + snprintf(buffer, sizeof(buffer), "\x18%03X,%03X\r", abs_x_int, abs_y_int); + } + fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer)); + } + + else if (dev->format == FORMAT_TABLET) { abs_x_int = abs_x * 16383; abs_y_int = 16383 - abs_y * 16383; @@ -299,23 +343,6 @@ mtouch_poll(void *priv) } } - if (dev->format == FORMAT_HEX) { - abs_x_int = abs_x * 1023; - abs_y_int = 1023 - (abs_y * 1023); - char buffer[10]; - - if (b) { - if (!dev->b) { /* Touchdown */ - snprintf(buffer, sizeof(buffer), "\x19%03X,%03X\r", abs_x_int, abs_y_int); - } else { /* Touch Continuation */ - snprintf(buffer, sizeof(buffer), "\x1c%03X,%03X\r", abs_x_int, abs_y_int); - } - } else if (dev->b) { /* Liftoff */ - snprintf(buffer, sizeof(buffer), "\x18%03X,%03X\r", abs_x_int, abs_y_int); - } - fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer)); - } - dev->b = b; /* Save buttonpress */ return 0; } @@ -338,8 +365,13 @@ mtouch_init(const device_t *info) timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); timer_on_auto(&dev->host_to_serial_timer, (1000000. / dev->baud_rate) * 10); dev->id = device_get_config_int("identity"); - dev->format = FORMAT_TABLET; - dev->pen_mode = 3; + dev->pen_mode = 3; + + if (dev->id < 2) /* legacy controllers */ + dev->format = FORMAT_DEC; + else + dev->format = FORMAT_TABLET; + mouse_input_mode = device_get_config_int("crosshair") + 1; mouse_set_buttons(2); mouse_set_poll_ex(mtouch_poll_global); From 066bd35f1aa4fc77285631b5f19841433445fdca Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Mon, 29 Jul 2024 21:31:36 +0200 Subject: [PATCH 6/8] Optimize Format Tablet Remove touchdown packet from Format tablet liftoff. Does not cause issues for windows 95 or DOS. --- src/device/mouse_microtouch_touchscreen.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index e4f3c7e7b..598764415 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -330,11 +330,6 @@ mtouch_poll(void *priv) fifo8_push(&dev->resp, abs_y_int & 0b1111111); fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); } else if (dev->b) { /* Liftoff */ - fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0)); - fifo8_push(&dev->resp, abs_x_int & 0b1111111); - fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); - fifo8_push(&dev->resp, abs_y_int & 0b1111111); - fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); From 796e7bbe1925485da538a92473664fcc38866989 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Mon, 29 Jul 2024 21:51:44 +0200 Subject: [PATCH 7/8] Update TODO --- src/device/mouse_microtouch_touchscreen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 598764415..23f582237 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -20,7 +20,8 @@ /* TODO: - Properly implement GP/SP commands (formats are not documented at all, like anywhere; no dumps yet). - Dynamic baud rate selection from software following this. - - Add additional SMT2/3 commands plus config option for controller type. + - Add additional SMT2/3 formats as we currently only support Tablet, Hex and Dec. + - Add additional SMT2/3 modes as we currently hardcode Mode Stream + Mode Status. */ #include #include From fcec4a40f91aefeca2a4a1b9c550532120910589 Mon Sep 17 00:00:00 2001 From: Jos van Mourik Date: Tue, 30 Jul 2024 20:09:13 +0200 Subject: [PATCH 8/8] Cleanup/bugfix --- src/device/mouse_microtouch_touchscreen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 23f582237..b05e82054 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -48,8 +48,8 @@ enum mtouch_formats { const char* mtouch_identity[] = { "A30100", /* SMT2 Serial / SMT3(R)V */ - "A40100", /* PC Bus SMT2 */ - "P50100", /* TouchPen 4 (+) */ + "A40100", /* SMT2 PCBus */ + "P50100", /* TouchPen 4(+) */ "Q10100", /* SMT3(R) Serial */ }; @@ -176,7 +176,7 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) } if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Get Parameter Block 1 */ mt_fifo8_puts(&mtouch->resp, "A"); - mt_fifo8_puts(&mtouch->resp, "0000000000000000000000000"); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", sizeof("0000000000000000000000000\r") - 1); mt_fifo8_puts(&mtouch->resp, "0"); } if (mtouch->cmd[0] == 'S' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Set Parameter Block 1 */ @@ -282,7 +282,7 @@ mtouch_poll(void *priv) if (!b && dev->b) { microtouch_calibrate_timer(dev); } - dev->b = b; /* Save lack of buttonpress */ + dev->b = b; /* Save buttonpress */ return 0; }