2024-05-05 14:36:42 +06:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
2024-08-04 16:12:10 +02:00
|
|
|
* 3M MicroTouch Serial emulation.
|
2024-05-05 14:36:42 +06:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2024-07-22 02:02:41 +01:00
|
|
|
* Authors: Cacodemon345, mourix
|
2024-05-05 14:36:42 +06:00
|
|
|
*
|
|
|
|
|
* Copyright 2024 Cacodemon345
|
|
|
|
|
*/
|
2024-05-04 17:01:29 +06:00
|
|
|
|
2024-06-12 00:24:58 +06:00
|
|
|
/* Reference: https://www.touchwindow.com/mm5/drivers/mtsctlrm.pdf */
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
/* TODO:
|
2024-07-26 01:19:12 +02:00
|
|
|
- Properly implement GP/SP commands (formats are not documented at all, like anywhere; no dumps yet).
|
2024-08-01 22:40:20 +02:00
|
|
|
- Decouple serial packet generation from mouse poll rate.
|
2024-06-12 00:24:58 +06:00
|
|
|
- Dynamic baud rate selection from software following this.
|
2024-07-29 21:51:44 +02:00
|
|
|
- Add additional SMT2/3 formats as we currently only support Tablet, Hex and Dec.
|
2024-09-15 03:13:54 +02:00
|
|
|
- Mode Polled.
|
2024-05-04 17:01:29 +06:00
|
|
|
*/
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <86box/86box.h>
|
|
|
|
|
#include <86box/device.h>
|
|
|
|
|
#include <86box/timer.h>
|
|
|
|
|
#include <86box/mouse.h>
|
|
|
|
|
#include <86box/serial.h>
|
|
|
|
|
#include <86box/plat.h>
|
|
|
|
|
#include <86box/fifo8.h>
|
|
|
|
|
#include <86box/fifo.h>
|
2024-05-05 13:06:35 +06:00
|
|
|
#include <86box/video.h> /* Needed to account for overscan. */
|
2024-05-04 17:01:29 +06:00
|
|
|
|
2024-07-29 20:36:21 +02:00
|
|
|
enum mtouch_formats {
|
2024-07-29 21:01:54 +02:00
|
|
|
FORMAT_DEC = 1,
|
|
|
|
|
FORMAT_HEX = 2,
|
|
|
|
|
FORMAT_RAW = 3,
|
|
|
|
|
FORMAT_TABLET = 4
|
2024-05-04 17:01:29 +06:00
|
|
|
};
|
|
|
|
|
|
2024-08-04 16:12:10 +02:00
|
|
|
enum mtouch_modes {
|
|
|
|
|
MODE_DOWNUP = 1,
|
|
|
|
|
MODE_INACTIVE = 2,
|
|
|
|
|
MODE_POINT = 3,
|
|
|
|
|
MODE_STREAM = 4,
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-29 20:28:20 +02:00
|
|
|
const char* mtouch_identity[] = {
|
|
|
|
|
"A30100", /* SMT2 Serial / SMT3(R)V */
|
2024-07-30 20:09:13 +02:00
|
|
|
"A40100", /* SMT2 PCBus */
|
|
|
|
|
"P50100", /* TouchPen 4(+) */
|
2024-07-29 20:28:20 +02:00
|
|
|
"Q10100", /* SMT3(R) Serial */
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-04 17:01:29 +06:00
|
|
|
typedef struct mouse_microtouch_t {
|
2024-09-15 01:18:37 +02:00
|
|
|
double baud_rate, abs_x, abs_y;
|
2024-08-04 01:04:09 +02:00
|
|
|
int b;
|
|
|
|
|
char cmd[256];
|
|
|
|
|
int cmd_pos;
|
2024-08-04 16:12:10 +02:00
|
|
|
uint8_t format, mode;
|
2024-08-04 01:04:09 +02:00
|
|
|
bool mode_status;
|
|
|
|
|
uint8_t id, cal_cntr, pen_mode;
|
|
|
|
|
bool soh;
|
2024-08-04 14:27:47 +02:00
|
|
|
bool in_reset, reset;
|
2024-08-04 01:04:09 +02:00
|
|
|
serial_t *serial;
|
|
|
|
|
Fifo8 resp;
|
|
|
|
|
pc_timer_t host_to_serial_timer;
|
|
|
|
|
pc_timer_t reset_timer;
|
2024-05-04 17:01:29 +06:00
|
|
|
} mouse_microtouch_t;
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
static mouse_microtouch_t *mtouch_inst = NULL;
|
2024-05-04 17:01:29 +06:00
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void
|
|
|
|
|
microtouch_reset_complete(void *priv)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
2024-05-05 14:55:42 +06:00
|
|
|
mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv;
|
2024-08-02 00:16:49 +02:00
|
|
|
|
2024-09-15 03:13:54 +02:00
|
|
|
mtouch->reset = true;
|
2024-05-05 14:55:42 +06:00
|
|
|
mtouch->in_reset = false;
|
2024-08-04 00:19:40 +02:00
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x30\x0D", 3); /* <SOH>0<CR> */
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void
|
|
|
|
|
microtouch_calibrate_timer(void *priv)
|
2024-05-05 14:25:31 +06:00
|
|
|
{
|
2024-05-05 14:55:42 +06:00
|
|
|
mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv;
|
2024-08-02 00:16:49 +02:00
|
|
|
|
2024-05-05 14:25:31 +06:00
|
|
|
if (!fifo8_num_used(&mtouch->resp)) {
|
|
|
|
|
mtouch->cal_cntr--;
|
2024-08-04 00:19:40 +02:00
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x31\x0D", 3); /* <SOH>1<CR> */
|
2024-05-05 14:25:31 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void
|
|
|
|
|
microtouch_process_commands(mouse_microtouch_t *mtouch)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
|
|
|
|
mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0';
|
2024-08-04 00:19:40 +02:00
|
|
|
pclog("MT Command: %s\n", mtouch->cmd);
|
|
|
|
|
|
2024-08-02 15:09:52 +02:00
|
|
|
if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { /* Calibrate New/Extended */
|
2024-08-02 01:24:00 +02:00
|
|
|
mtouch->cal_cntr = 2;
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
2024-07-29 21:01:54 +02:00
|
|
|
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'D') { /* Format Decimal */
|
2024-08-01 22:40:20 +02:00
|
|
|
mouse_set_sample_rate(106);
|
2024-07-29 21:01:54 +02:00
|
|
|
mtouch->format = FORMAT_DEC;
|
2024-08-04 16:12:10 +02:00
|
|
|
mtouch->mode_status = false;
|
2024-08-02 01:24:00 +02:00
|
|
|
}
|
|
|
|
|
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { /* Finger Only */
|
|
|
|
|
mtouch->pen_mode = 1;
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
2024-07-21 17:52:42 +02:00
|
|
|
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'H') { /* Format Hexadecimal */
|
2024-08-01 22:40:20 +02:00
|
|
|
mouse_set_sample_rate(106);
|
2024-07-29 20:36:21 +02:00
|
|
|
mtouch->format = FORMAT_HEX;
|
2024-08-04 16:12:10 +02:00
|
|
|
mtouch->mode_status = false;
|
2024-08-02 01:24:00 +02:00
|
|
|
}
|
2024-07-21 17:52:42 +02:00
|
|
|
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { /* Format Raw */
|
2024-08-01 22:40:20 +02:00
|
|
|
mouse_set_sample_rate(106);
|
2024-07-29 21:01:54 +02:00
|
|
|
mtouch->format = FORMAT_RAW;
|
2024-08-04 16:12:10 +02:00
|
|
|
mtouch->mode = MODE_INACTIVE;
|
2024-05-05 14:25:31 +06:00
|
|
|
mtouch->cal_cntr = 0;
|
2024-05-05 13:06:35 +06:00
|
|
|
}
|
2024-07-29 21:01:54 +02:00
|
|
|
if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { /* Format Tablet */
|
2024-08-01 22:40:20 +02:00
|
|
|
mouse_set_sample_rate(192);
|
2024-07-29 21:01:54 +02:00
|
|
|
mtouch->format = FORMAT_TABLET;
|
2024-08-02 01:24:00 +02:00
|
|
|
}
|
|
|
|
|
if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Get Parameter Block 1 */
|
2024-08-04 00:19:40 +02:00
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x41\x0D", 3); /* <SOH>A<CR> */
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", 26);
|
2024-05-05 13:06:35 +06:00
|
|
|
}
|
2024-08-04 16:12:10 +02:00
|
|
|
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'D' && mtouch->cmd[2] == 'U') { /* Mode Down/Up */
|
|
|
|
|
mtouch->mode = MODE_DOWNUP;
|
|
|
|
|
}
|
|
|
|
|
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'I') { /* Mode Inactive */
|
|
|
|
|
mtouch->mode = MODE_INACTIVE;
|
|
|
|
|
}
|
|
|
|
|
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'P') { /* Mode Point */
|
|
|
|
|
mtouch->mode = MODE_POINT;
|
|
|
|
|
}
|
2024-08-01 22:40:20 +02:00
|
|
|
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'T') { /* Mode Status */
|
2024-08-02 00:16:49 +02:00
|
|
|
mtouch->mode_status = true;
|
2024-08-02 01:24:00 +02:00
|
|
|
}
|
2024-08-04 16:12:10 +02:00
|
|
|
if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { /* Mode Stream */
|
|
|
|
|
mtouch->mode = MODE_STREAM;
|
|
|
|
|
}
|
2024-08-02 01:24:00 +02:00
|
|
|
if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { /* Output Identity */
|
2024-08-04 00:19:40 +02:00
|
|
|
fifo8_push(&mtouch->resp, 0x01);
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) mtouch_identity[mtouch->id], 6);
|
|
|
|
|
fifo8_push(&mtouch->resp, 0x0D);
|
|
|
|
|
return;
|
2024-08-02 01:24:00 +02:00
|
|
|
}
|
2024-08-04 14:27:47 +02:00
|
|
|
if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'S') { /* Output Status */
|
|
|
|
|
if (mtouch->reset) {
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x40\x60\x0D", 4);
|
|
|
|
|
} else {
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x40\x40\x0D", 4);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-02 01:24:00 +02:00
|
|
|
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 */
|
|
|
|
|
}
|
2024-08-04 16:12:10 +02:00
|
|
|
if (mtouch->cmd[0] == 'R') { /* Reset */
|
2024-05-04 17:01:29 +06:00
|
|
|
mtouch->in_reset = true;
|
2024-05-05 14:36:42 +06:00
|
|
|
mtouch->cal_cntr = 0;
|
2024-05-07 15:49:28 +06:00
|
|
|
mtouch->pen_mode = 3;
|
2024-07-29 21:01:54 +02:00
|
|
|
|
2024-08-04 16:12:10 +02:00
|
|
|
if (mtouch->cmd[0] == 'D') { /* Restore Defaults */
|
|
|
|
|
mtouch->mode = MODE_STREAM;
|
|
|
|
|
mtouch->mode_status = false;
|
|
|
|
|
|
|
|
|
|
if (mtouch->id < 2) {
|
|
|
|
|
mouse_set_sample_rate(106);
|
|
|
|
|
mtouch->format = FORMAT_DEC;
|
|
|
|
|
} else {
|
|
|
|
|
mouse_set_sample_rate(192);
|
|
|
|
|
mtouch->format = FORMAT_TABLET;
|
|
|
|
|
}
|
2024-08-01 22:40:20 +02:00
|
|
|
}
|
2024-07-29 21:01:54 +02:00
|
|
|
|
2024-05-04 17:01:29 +06:00
|
|
|
timer_on_auto(&mtouch->reset_timer, 500. * 1000.);
|
2024-08-04 00:19:40 +02:00
|
|
|
return;
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
2024-08-02 01:24:00 +02:00
|
|
|
if (mtouch->cmd[0] == 'S' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { /* Set Parameter Block 1 */
|
2024-08-04 00:19:40 +02:00
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x41\x0D", 3); /* <SOH>A<CR> */
|
|
|
|
|
return;
|
2024-05-05 14:25:31 +06:00
|
|
|
}
|
2024-08-02 15:09:52 +02:00
|
|
|
if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { /* Unit Type */
|
2024-08-04 00:19:40 +02:00
|
|
|
fifo8_push(&mtouch->resp, 0x01);
|
|
|
|
|
|
|
|
|
|
if (mtouch->id == 2) {
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "TP****00", 8);
|
|
|
|
|
} else {
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "QM****00", 8);
|
|
|
|
|
}
|
|
|
|
|
fifo8_push(&mtouch->resp, 0x0D);
|
|
|
|
|
return;
|
2024-07-26 02:11:21 +02:00
|
|
|
}
|
2024-08-04 00:19:40 +02:00
|
|
|
|
|
|
|
|
fifo8_push_all(&mtouch->resp, (uint8_t *) "\x01\x30\x0D", 3); /* <SOH>0<CR> */
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void
|
|
|
|
|
mtouch_write_to_host(void *priv)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
2024-05-05 14:55:42 +06:00
|
|
|
mouse_microtouch_t *dev = (mouse_microtouch_t *) priv;
|
2024-05-04 17:01:29 +06:00
|
|
|
if ((dev->serial->type >= SERIAL_16550) && dev->serial->fifo_enabled) {
|
|
|
|
|
if (fifo_get_full(dev->serial->rcvr_fifo)) {
|
|
|
|
|
goto no_write_to_machine;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (dev->serial->lsr & 1) {
|
|
|
|
|
goto no_write_to_machine;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-26 02:11:21 +02:00
|
|
|
if (dev->in_reset) {
|
2024-05-04 17:01:29 +06:00
|
|
|
goto no_write_to_machine;
|
2024-07-26 02:11:21 +02:00
|
|
|
}
|
2024-05-04 17:01:29 +06:00
|
|
|
if (fifo8_num_used(&dev->resp)) {
|
|
|
|
|
serial_write_fifo(dev->serial, fifo8_pop(&dev->resp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
no_write_to_machine:
|
2024-08-02 15:09:52 +02:00
|
|
|
timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double) dev->baud_rate) * (double) (1 + 8 + 1));
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void
|
|
|
|
|
mtouch_write(serial_t *serial, void *priv, uint8_t data)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
2024-05-05 14:55:42 +06:00
|
|
|
mouse_microtouch_t *dev = (mouse_microtouch_t *) priv;
|
|
|
|
|
if (data == '\x1') {
|
2024-05-04 17:01:29 +06:00
|
|
|
dev->soh = 1;
|
|
|
|
|
} else if (dev->soh) {
|
|
|
|
|
if (data != '\r') {
|
|
|
|
|
dev->cmd[dev->cmd_pos++] = data;
|
|
|
|
|
} else {
|
2024-07-27 20:14:22 +02:00
|
|
|
dev->soh = 0;
|
2024-08-04 00:19:40 +02:00
|
|
|
|
|
|
|
|
if (!dev->cmd_pos) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev->cmd[dev->cmd_pos++] = data;
|
|
|
|
|
dev->cmd_pos = 0;
|
2024-05-04 17:01:29 +06:00
|
|
|
microtouch_process_commands(dev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
mtouch_poll(void *priv)
|
|
|
|
|
{
|
2024-05-05 14:55:42 +06:00
|
|
|
mouse_microtouch_t *dev = (mouse_microtouch_t *) priv;
|
2024-07-21 01:03:55 +02:00
|
|
|
double abs_x;
|
|
|
|
|
double abs_y;
|
|
|
|
|
int b = mouse_get_buttons_ex();
|
2024-09-15 01:18:37 +02:00
|
|
|
char buffer[10];
|
2024-08-02 00:16:49 +02:00
|
|
|
|
2024-09-15 01:56:45 +02:00
|
|
|
if (fifo8_num_free(&dev->resp) <= 256 - 10 || dev->mode == MODE_INACTIVE) {
|
|
|
|
|
return 0;
|
2024-09-15 03:13:54 +02:00
|
|
|
}
|
2024-09-15 01:56:45 +02:00
|
|
|
|
|
|
|
|
if (dev->cal_cntr || (!b && !dev->b)) { /* Calibration or no buttonpress */
|
|
|
|
|
if (!b && dev->b) {
|
|
|
|
|
microtouch_calibrate_timer(dev);
|
|
|
|
|
}
|
|
|
|
|
dev->b = b; /* Save buttonpress */
|
|
|
|
|
return 0;
|
2024-09-15 03:13:54 +02:00
|
|
|
}
|
2024-09-15 01:56:45 +02:00
|
|
|
|
2024-07-21 01:03:55 +02:00
|
|
|
mouse_get_abs_coords(&abs_x, &abs_y);
|
|
|
|
|
|
|
|
|
|
if (enable_overscan) {
|
|
|
|
|
int index = mouse_tablet_in_proximity - 1;
|
2024-08-02 00:16:49 +02:00
|
|
|
if (mouse_tablet_in_proximity == -1) {
|
2024-07-21 01:03:55 +02:00
|
|
|
mouse_tablet_in_proximity = 0;
|
2024-08-02 00:16:49 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-21 01:03:55 +02:00
|
|
|
abs_x *= monitors[index].mon_unscaled_size_x - 1;
|
|
|
|
|
abs_y *= monitors[index].mon_efscrnsz_y - 1;
|
2024-08-02 00:16:49 +02:00
|
|
|
|
2024-07-21 01:03:55 +02:00
|
|
|
if (abs_x <= (monitors[index].mon_overscan_x / 2.)) {
|
|
|
|
|
abs_x = (monitors[index].mon_overscan_x / 2.);
|
|
|
|
|
}
|
|
|
|
|
if (abs_y <= (monitors[index].mon_overscan_y / 2.)) {
|
|
|
|
|
abs_y = (monitors[index].mon_overscan_y / 2.);
|
|
|
|
|
}
|
|
|
|
|
abs_x -= (monitors[index].mon_overscan_x / 2.);
|
|
|
|
|
abs_y -= (monitors[index].mon_overscan_y / 2.);
|
|
|
|
|
abs_x = abs_x / (double) monitors[index].mon_xsize;
|
|
|
|
|
abs_y = abs_y / (double) monitors[index].mon_ysize;
|
|
|
|
|
}
|
2024-07-26 02:11:21 +02:00
|
|
|
|
2024-09-15 01:56:45 +02:00
|
|
|
if (abs_x >= 1.0) abs_x = 1.0;
|
|
|
|
|
if (abs_y >= 1.0) abs_y = 1.0;
|
|
|
|
|
if (abs_x <= 0.0) abs_x = 0.0;
|
|
|
|
|
if (abs_y <= 0.0) abs_y = 0.0;
|
2024-07-29 21:01:54 +02:00
|
|
|
|
2024-09-15 01:18:37 +02:00
|
|
|
if (dev->format == FORMAT_DEC || dev->format == FORMAT_HEX) {
|
|
|
|
|
if (b) {
|
2024-09-15 03:13:54 +02:00
|
|
|
if (!dev->b) { /* Touchdown (MS, MP, MDU) */
|
2024-09-15 01:18:37 +02:00
|
|
|
fifo8_push(&dev->resp, (dev->mode_status) ? 0x19 : 0x01);
|
|
|
|
|
if (dev->format == FORMAT_DEC){
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%03d,%03d\r", (uint16_t)(999 * abs_x), (uint16_t)(999 * (1 - abs_y)));
|
|
|
|
|
} else if (dev->format == FORMAT_HEX) {
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%03X,%03X\r", (uint16_t)(1023 * abs_x), (uint16_t)(1023 * (1 - abs_y)));
|
|
|
|
|
}
|
2024-08-02 00:16:49 +02:00
|
|
|
fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer));
|
2024-09-15 03:13:54 +02:00
|
|
|
} else if (dev->mode == MODE_STREAM){ /* Touch Continuation (MS) */
|
2024-09-15 01:18:37 +02:00
|
|
|
fifo8_push(&dev->resp, (dev->mode_status) ? 0x1c : 0x01);
|
|
|
|
|
if (dev->format == FORMAT_DEC){
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%03d,%03d\r", (uint16_t)(999 * abs_x), (uint16_t)(999 * (1 - abs_y)));
|
|
|
|
|
} else if (dev->format == FORMAT_HEX) {
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%03X,%03X\r", (uint16_t)(1023 * abs_x), (uint16_t)(1023 * (1 - abs_y)));
|
2024-08-02 00:16:49 +02:00
|
|
|
}
|
|
|
|
|
fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer));
|
2024-07-29 21:01:54 +02:00
|
|
|
}
|
2024-09-15 03:13:54 +02:00
|
|
|
} else if (dev->b && dev->mode != MODE_POINT) { /* Touch Liftoff (MS, MDU) */
|
2024-09-15 01:18:37 +02:00
|
|
|
fifo8_push(&dev->resp, (dev->mode_status) ? 0x18 : 0x01);
|
|
|
|
|
if (dev->format == FORMAT_DEC) {
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%03d,%03d\r", (uint16_t)(999 * dev->abs_x), (uint16_t)(999 * (1 - dev->abs_y)));
|
|
|
|
|
} else if (dev->format == FORMAT_HEX) {
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%03X,%03X\r", (uint16_t)(1023 * dev->abs_x), (uint16_t)(1023 * (1 - dev->abs_y)));
|
2024-08-02 00:16:49 +02:00
|
|
|
}
|
|
|
|
|
fifo8_push_all(&dev->resp, (uint8_t *)buffer, strlen(buffer));
|
2024-07-29 21:01:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 01:56:45 +02:00
|
|
|
if (dev->format == FORMAT_TABLET) {
|
2024-07-26 01:19:12 +02:00
|
|
|
if (b) { /* Touchdown/Continuation */
|
2024-05-20 13:05:35 +06:00
|
|
|
fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode == 2) ? ((1 << 5) | ((b & 3))) : 0));
|
2024-09-15 01:18:37 +02:00
|
|
|
fifo8_push(&dev->resp, (uint16_t)(16383 * abs_x) & 0b1111111);
|
|
|
|
|
fifo8_push(&dev->resp, ((uint16_t)(16383 * abs_x) >> 7) & 0b1111111);
|
|
|
|
|
fifo8_push(&dev->resp, (uint16_t)(16383 * (1 - abs_y)) & 0b1111111);
|
|
|
|
|
fifo8_push(&dev->resp, ((uint16_t)(16383 * (1 - abs_y)) >> 7) & 0b1111111);
|
2024-07-26 01:19:12 +02:00
|
|
|
} else if (dev->b) { /* Liftoff */
|
2024-05-20 13:05:35 +06:00
|
|
|
fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0));
|
2024-09-15 01:18:37 +02:00
|
|
|
fifo8_push(&dev->resp, (uint16_t)(16383 * dev->abs_x) & 0b1111111);
|
|
|
|
|
fifo8_push(&dev->resp, ((uint16_t)(16383 * dev->abs_x) >> 7) & 0b1111111);
|
|
|
|
|
fifo8_push(&dev->resp, (uint16_t)(16383 * (1 - dev->abs_y))& 0b1111111);
|
|
|
|
|
fifo8_push(&dev->resp, ((uint16_t)(16383 * (1 - dev->abs_y)) >> 7) & 0b1111111);
|
2024-05-04 17:01:29 +06:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-21 17:52:42 +02:00
|
|
|
|
2024-08-04 01:04:09 +02:00
|
|
|
/* Save old states*/
|
2024-09-15 01:18:37 +02:00
|
|
|
dev->abs_x = abs_x;
|
|
|
|
|
dev->abs_y = abs_y;
|
2024-09-15 03:13:54 +02:00
|
|
|
dev->b = b;
|
2024-05-04 17:01:29 +06:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
static void
|
|
|
|
|
mtouch_poll_global(void)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
|
|
|
|
mtouch_poll(mtouch_inst);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void *
|
|
|
|
|
mtouch_init(const device_t *info)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
|
|
|
|
mouse_microtouch_t *dev = calloc(1, sizeof(mouse_microtouch_t));
|
2024-08-02 00:16:49 +02:00
|
|
|
|
2024-05-04 17:01:29 +06:00
|
|
|
dev->serial = serial_attach(device_get_config_int("port"), NULL, mtouch_write, dev);
|
2024-06-12 00:24:58 +06:00
|
|
|
dev->baud_rate = device_get_config_int("baudrate");
|
2024-08-01 20:47:15 +02:00
|
|
|
serial_set_cts(dev->serial, 1);
|
|
|
|
|
serial_set_dsr(dev->serial, 1);
|
|
|
|
|
serial_set_dcd(dev->serial, 1);
|
|
|
|
|
|
2024-08-01 22:40:20 +02:00
|
|
|
fifo8_create(&dev->resp, 256);
|
2024-05-04 17:01:29 +06:00
|
|
|
timer_add(&dev->host_to_serial_timer, mtouch_write_to_host, dev, 0);
|
|
|
|
|
timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0);
|
2024-06-12 00:24:58 +06:00
|
|
|
timer_on_auto(&dev->host_to_serial_timer, (1000000. / dev->baud_rate) * 10);
|
2024-07-29 20:28:20 +02:00
|
|
|
dev->id = device_get_config_int("identity");
|
2024-08-02 00:16:49 +02:00
|
|
|
dev->pen_mode = 3;
|
2024-08-04 16:12:10 +02:00
|
|
|
dev->mode = MODE_STREAM;
|
2024-07-29 21:01:54 +02:00
|
|
|
|
2024-08-01 22:40:20 +02:00
|
|
|
if (dev->id < 2) { /* legacy controllers */
|
2024-07-29 21:01:54 +02:00
|
|
|
dev->format = FORMAT_DEC;
|
2024-08-01 22:40:20 +02:00
|
|
|
mouse_set_sample_rate(106);
|
2024-09-15 01:56:45 +02:00
|
|
|
} else {
|
2024-07-29 21:01:54 +02:00
|
|
|
dev->format = FORMAT_TABLET;
|
2024-08-01 22:40:20 +02:00
|
|
|
mouse_set_sample_rate(192);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 20:12:10 +02:00
|
|
|
mouse_input_mode = device_get_config_int("crosshair") + 1;
|
2024-05-04 17:01:29 +06:00
|
|
|
mouse_set_buttons(2);
|
|
|
|
|
mouse_set_poll_ex(mtouch_poll_global);
|
|
|
|
|
mtouch_inst = dev;
|
2024-08-02 15:09:52 +02:00
|
|
|
|
2024-05-04 17:01:29 +06:00
|
|
|
return dev;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 14:55:42 +06:00
|
|
|
void
|
|
|
|
|
mtouch_close(void *priv)
|
2024-05-04 17:01:29 +06:00
|
|
|
{
|
|
|
|
|
mouse_microtouch_t *dev = (mouse_microtouch_t *) priv;
|
|
|
|
|
|
|
|
|
|
fifo8_destroy(&dev->resp);
|
|
|
|
|
/* Detach serial port from the mouse. */
|
2024-09-15 01:56:45 +02:00
|
|
|
if (dev && dev->serial && dev->serial->sd) {
|
2024-05-04 17:01:29 +06:00
|
|
|
memset(dev->serial->sd, 0, sizeof(serial_device_t));
|
2024-09-15 01:56:45 +02:00
|
|
|
}
|
2024-08-02 15:09:52 +02:00
|
|
|
|
2024-05-04 17:01:29 +06:00
|
|
|
free(dev);
|
|
|
|
|
mtouch_inst = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const device_config_t mtouch_config[] = {
|
|
|
|
|
// clang-format off
|
|
|
|
|
{
|
|
|
|
|
.name = "port",
|
|
|
|
|
.description = "Serial Port",
|
|
|
|
|
.type = CONFIG_SELECTION,
|
|
|
|
|
.default_string = "",
|
|
|
|
|
.default_int = 0,
|
|
|
|
|
.file_filter = "",
|
|
|
|
|
.spinner = { 0 },
|
|
|
|
|
.selection = {
|
|
|
|
|
{ .description = "COM1", .value = 0 },
|
|
|
|
|
{ .description = "COM2", .value = 1 },
|
|
|
|
|
{ .description = "COM3", .value = 2 },
|
|
|
|
|
{ .description = "COM4", .value = 3 },
|
|
|
|
|
{ .description = "" }
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-06-12 00:24:58 +06:00
|
|
|
{
|
|
|
|
|
.name = "baudrate",
|
|
|
|
|
.description = "Baud Rate",
|
|
|
|
|
.type = CONFIG_SELECTION,
|
|
|
|
|
.default_string = "",
|
|
|
|
|
.default_int = 9600,
|
|
|
|
|
.file_filter = NULL,
|
|
|
|
|
.spinner = { 0 },
|
|
|
|
|
.selection = {
|
|
|
|
|
{ .description = "19200", .value = 19200 },
|
|
|
|
|
{ .description = "9600", .value = 9600 },
|
|
|
|
|
{ .description = "4800", .value = 4800 },
|
|
|
|
|
{ .description = "2400", .value = 2400 },
|
|
|
|
|
{ .description = "1200", .value = 1200 }
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-07-29 20:28:20 +02:00
|
|
|
{
|
|
|
|
|
.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 }
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-07-26 20:12:10 +02:00
|
|
|
{
|
|
|
|
|
.name = "crosshair",
|
|
|
|
|
.description = "Show Crosshair",
|
|
|
|
|
.type = CONFIG_BINARY,
|
|
|
|
|
.default_string = "",
|
|
|
|
|
.default_int = 1
|
|
|
|
|
},
|
2024-05-04 17:01:29 +06:00
|
|
|
{ .name = "", .description = "", .type = CONFIG_END }
|
|
|
|
|
// clang-format on
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const device_t mouse_mtouch_device = {
|
2024-07-22 02:02:41 +01:00
|
|
|
.name = "3M MicroTouch (Serial)",
|
2024-05-04 17:01:29 +06:00
|
|
|
.internal_name = "microtouch_touchpen",
|
|
|
|
|
.flags = DEVICE_COM,
|
|
|
|
|
.local = 0,
|
|
|
|
|
.init = mtouch_init,
|
|
|
|
|
.close = mtouch_close,
|
|
|
|
|
.reset = NULL,
|
|
|
|
|
{ .poll = mtouch_poll },
|
|
|
|
|
.speed_changed = NULL,
|
|
|
|
|
.force_redraw = NULL,
|
|
|
|
|
.config = mtouch_config
|
|
|
|
|
};
|