carol: add touch dll functions

This commit is contained in:
2023-05-31 04:54:38 -04:00
parent 02201dfba5
commit 4c67843f08
7 changed files with 152 additions and 5 deletions

View File

@ -27,6 +27,12 @@ const struct dll_bind_sym carol_dll_syms[] = {
}, {
.sym = "carol_io_controlbd_init",
.off = offsetof(struct carol_dll, controlbd_init),
}, {
.sym = "carol_io_touch_start",
.off = offsetof(struct carol_dll, touch_start),
}, {
.sym = "carol_io_touch_stop",
.off = offsetof(struct carol_dll, touch_stop),
}
};

View File

@ -12,6 +12,8 @@ struct carol_dll {
HRESULT (*touch_init)();
HRESULT (*ledbd_init)();
HRESULT (*controlbd_init)();
void (*touch_start)(carol_io_touch_callback_t callback);
void (*touch_stop)();
};
struct carol_dll_config {

View File

@ -18,3 +18,5 @@ EXPORTS
carol_io_touch_init
carol_io_ledbd_init
carol_io_controlbd_init
carol_io_touch_start
carol_io_touch_stop

View File

@ -32,12 +32,17 @@ static HRESULT touch_frame_decode(struct touch_req *dest, struct iobuf *iobuf);
static HRESULT handle_touch_ack_cmd(const struct touch_req *req);
static HRESULT handle_touch_name_cmd(const struct touch_req *req);
static HRESULT handle_touch_id_cmd(const struct touch_req *req);
static void touch_scan_auto(const bool is_pressed, const uint32_t mouse_x, const uint32_t mouse_y);
static CRITICAL_SECTION touch_lock;
static struct uart touch_uart;
static uint8_t touch_written_bytes[520];
static uint8_t touch_readable_bytes[520];
static uint8_t touch_written_bytes[528];
static uint8_t touch_readable_bytes[528];
static bool should_stream = false;
static bool last_pressed;
static uint16_t last_x;
static uint16_t last_y;
HRESULT touch_hook_init(const struct touch_config *cfg)
{
@ -118,13 +123,13 @@ static HRESULT touch_handle_irp_locked(struct irp *irp)
}
else if (!strcmp("OI", (char *)req.cmd)) {
hr = handle_touch_id_cmd(&req);
should_stream = true; // possibly send stuff after we get this?
//carol_dll.touch_start(touch_scan_auto);
}
else if (!strcmp("NM", (char *)req.cmd)) {
hr = handle_touch_name_cmd(&req);
}
else if (!strcmp("R", (char *)req.cmd)) {
should_stream = false;
carol_dll.touch_stop();
dprintf("Touch: Reset\n");
hr = handle_touch_ack_cmd(&req);
}
@ -154,6 +159,58 @@ static HRESULT handle_touch_id_cmd(const struct touch_req *req)
return iobuf_write(&touch_uart.readable, "\001EX1234\015", 8);
}
static void touch_scan_auto(const bool is_pressed, const uint32_t mouse_x, const uint32_t mouse_y)
{
struct touch_auto_resp resp;
uint16_t tmp_x;
uint16_t tmp_y;
bool flg = false;
memset(&resp, 0, sizeof(resp));
resp.rep_id = 0x17;
resp.touches[0].status = 0x04;
resp.count = 1;
if (is_pressed) {
resp.touches[0].status = 0x07;
resp.touches[0].touch_id = 1;
tmp_x = mouse_x & 0x7FFF;
tmp_y = mouse_y & 0x7FFF;
// flip
resp.touches[0].x = (tmp_x << 8) | (tmp_x >> 8);
resp.touches[0].y = (tmp_y << 8) | (tmp_y >> 8);
flg = resp.touches[0].x != last_x || resp.touches[0].y != last_y;
#if 1
if (flg)
dprintf("Touch: Mouse down! x %04X y: %04X\n", resp.touches[0].x, resp.touches[0].y);
#endif
last_x = resp.touches[0].x;
last_y = resp.touches[0].y;
} else if (last_pressed) {
resp.touches[0].x = last_x;
resp.touches[0].y = last_y;
}
last_pressed = is_pressed;
EnterCriticalSection(&touch_lock);
iobuf_write(&touch_uart.readable, &resp, sizeof(resp));
LeaveCriticalSection(&touch_lock);
#if 1
//if (flg) {
dprintf("Touch: RX Buffer: (pos %08x)\n", (uint32_t)touch_uart.readable.pos);
dump_iobuf(&touch_uart.readable);
//}
#endif
}
/* Decodes the response into a struct that's easier to work with. */
static HRESULT touch_frame_decode(struct touch_req *dest, struct iobuf *iobuf)
{

View File

@ -4,6 +4,8 @@
#include <stdbool.h>
#include <stdint.h>
#pragma pack(push, 1)
struct touch_config {
bool enable;
};
@ -16,4 +18,21 @@ struct touch_req {
size_t data_len; // length of data
};
struct touch_report {
uint8_t status;
uint8_t touch_id;
uint16_t x;
uint16_t y;
};
struct touch_auto_resp {
uint8_t rep_id;
struct touch_report touches[10];
uint8_t count;
uint16_t scan_time;
//uint8_t padding[456];
};
#pragma pack(pop)
HRESULT touch_hook_init(const struct touch_config *cfg);