tsc2005.c
来自「xen虚拟机源代码安装包」· C语言 代码 · 共 594 行 · 第 1/2 页
C
594 行
s->enabled = 0; s->busy = 0; s->nextprecision = 0; s->nextfunction = 0; s->timing[0] = 0; s->timing[1] = 0; s->irq = 0; s->dav = 0; s->reset = 0; s->pdst = 1; s->pnd0 = 0; s->function = -1; s->temp_thr[0] = 0x000; s->temp_thr[1] = 0xfff; s->aux_thr[0] = 0x000; s->aux_thr[1] = 0xfff; tsc2005_pin_update(s);}uint8_t tsc2005_txrx_word(void *opaque, uint8_t value){ struct tsc2005_state_s *s = opaque; uint32_t ret = 0; switch (s->state ++) { case 0: if (value & 0x80) { /* Command */ if (value & (1 << 1)) tsc2005_reset(s); else { s->nextfunction = (value >> 3) & 0xf; s->nextprecision = (value >> 2) & 1; if (s->enabled != !(value & 1)) { s->enabled = !(value & 1); fprintf(stderr, "%s: touchscreen sense %sabled\n", __FUNCTION__, s->enabled ? "en" : "dis"); if (s->busy && !s->enabled) qemu_del_timer(s->timer); s->busy &= s->enabled; } tsc2005_pin_update(s); } s->state = 0; } else if (value) { /* Data transfer */ s->reg = (value >> 3) & 0xf; s->pnd0 = (value >> 1) & 1; s->command = value & 1; if (s->command) { /* Read */ s->data = tsc2005_read(s, s->reg); tsc2005_pin_update(s); } else s->data = 0; } else s->state = 0; break; case 1: if (s->command) ret = (s->data >> 8) & 0xff; else s->data |= value << 8; break; case 2: if (s->command) ret = s->data & 0xff; else { s->data |= value; tsc2005_write(s, s->reg, s->data); tsc2005_pin_update(s); } s->state = 0; break; } return ret;}uint32_t tsc2005_txrx(void *opaque, uint32_t value, int len){ uint32_t ret = 0; len &= ~7; while (len > 0) { len -= 8; ret |= tsc2005_txrx_word(opaque, (value >> len) & 0xff) << len; } return ret;}static void tsc2005_timer_tick(void *opaque){ struct tsc2005_state_s *s = opaque; /* Timer ticked -- a set of conversions has been finished. */ if (!s->busy) return; s->busy = 0; s->dav |= mode_regs[s->function]; s->function = -1; tsc2005_pin_update(s);}static void tsc2005_touchscreen_event(void *opaque, int x, int y, int z, int buttons_state){ struct tsc2005_state_s *s = opaque; int p = s->pressure; if (buttons_state) { s->x = x; s->y = y; } s->pressure = !!buttons_state; /* * Note: We would get better responsiveness in the guest by * signaling TS events immediately, but for now we simulate * the first conversion delay for sake of correctness. */ if (p != s->pressure) tsc2005_pin_update(s);}static void tsc2005_save(QEMUFile *f, void *opaque){ struct tsc2005_state_s *s = (struct tsc2005_state_s *) opaque; int i; qemu_put_be16(f, s->x); qemu_put_be16(f, s->y); qemu_put_byte(f, s->pressure); qemu_put_byte(f, s->state); qemu_put_byte(f, s->reg); qemu_put_byte(f, s->command); qemu_put_byte(f, s->irq); qemu_put_be16s(f, &s->dav); qemu_put_be16s(f, &s->data); qemu_put_timer(f, s->timer); qemu_put_byte(f, s->enabled); qemu_put_byte(f, s->host_mode); qemu_put_byte(f, s->function); qemu_put_byte(f, s->nextfunction); qemu_put_byte(f, s->precision); qemu_put_byte(f, s->nextprecision); qemu_put_be16(f, s->filter); qemu_put_byte(f, s->pin_func); qemu_put_be16(f, s->timing[0]); qemu_put_be16(f, s->timing[1]); qemu_put_be16s(f, &s->temp_thr[0]); qemu_put_be16s(f, &s->temp_thr[1]); qemu_put_be16s(f, &s->aux_thr[0]); qemu_put_be16s(f, &s->aux_thr[1]); qemu_put_be32(f, s->noise); qemu_put_byte(f, s->reset); qemu_put_byte(f, s->pdst); qemu_put_byte(f, s->pnd0); for (i = 0; i < 8; i ++) qemu_put_be32(f, s->tr[i]);}static int tsc2005_load(QEMUFile *f, void *opaque, int version_id){ struct tsc2005_state_s *s = (struct tsc2005_state_s *) opaque; int i; s->x = qemu_get_be16(f); s->y = qemu_get_be16(f); s->pressure = qemu_get_byte(f); s->state = qemu_get_byte(f); s->reg = qemu_get_byte(f); s->command = qemu_get_byte(f); s->irq = qemu_get_byte(f); qemu_get_be16s(f, &s->dav); qemu_get_be16s(f, &s->data); qemu_get_timer(f, s->timer); s->enabled = qemu_get_byte(f); s->host_mode = qemu_get_byte(f); s->function = qemu_get_byte(f); s->nextfunction = qemu_get_byte(f); s->precision = qemu_get_byte(f); s->nextprecision = qemu_get_byte(f); s->filter = qemu_get_be16(f); s->pin_func = qemu_get_byte(f); s->timing[0] = qemu_get_be16(f); s->timing[1] = qemu_get_be16(f); qemu_get_be16s(f, &s->temp_thr[0]); qemu_get_be16s(f, &s->temp_thr[1]); qemu_get_be16s(f, &s->aux_thr[0]); qemu_get_be16s(f, &s->aux_thr[1]); s->noise = qemu_get_be32(f); s->reset = qemu_get_byte(f); s->pdst = qemu_get_byte(f); s->pnd0 = qemu_get_byte(f); for (i = 0; i < 8; i ++) s->tr[i] = qemu_get_be32(f); s->busy = qemu_timer_pending(s->timer); tsc2005_pin_update(s); return 0;}static int tsc2005_iid = 0;void *tsc2005_init(qemu_irq pintdav){ struct tsc2005_state_s *s; s = (struct tsc2005_state_s *) qemu_mallocz(sizeof(struct tsc2005_state_s)); s->x = 400; s->y = 240; s->pressure = 0; s->precision = s->nextprecision = 0; s->timer = qemu_new_timer(vm_clock, tsc2005_timer_tick, s); s->pint = pintdav; s->model = 0x2005; s->tr[0] = 0; s->tr[1] = 1; s->tr[2] = 1; s->tr[3] = 0; s->tr[4] = 1; s->tr[5] = 0; s->tr[6] = 1; s->tr[7] = 0; tsc2005_reset(s); qemu_add_mouse_event_handler(tsc2005_touchscreen_event, s, 1, "QEMU TSC2005-driven Touchscreen"); qemu_register_reset((void *) tsc2005_reset, s); register_savevm("tsc2005", tsc2005_iid ++, 0, tsc2005_save, tsc2005_load, s); return s;}/* * Use tslib generated calibration data to generate ADC input values * from the touchscreen. Assuming 12-bit precision was used during * tslib calibration. */void tsc2005_set_transform(void *opaque, struct mouse_transform_info_s *info){ struct tsc2005_state_s *s = (struct tsc2005_state_s *) opaque; /* This version assumes touchscreen X & Y axis are parallel or * perpendicular to LCD's X & Y axis in some way. */ if (abs(info->a[0]) > abs(info->a[1])) { s->tr[0] = 0; s->tr[1] = -info->a[6] * info->x; s->tr[2] = info->a[0]; s->tr[3] = -info->a[2] / info->a[0]; s->tr[4] = info->a[6] * info->y; s->tr[5] = 0; s->tr[6] = info->a[4]; s->tr[7] = -info->a[5] / info->a[4]; } else { s->tr[0] = info->a[6] * info->y; s->tr[1] = 0; s->tr[2] = info->a[1]; s->tr[3] = -info->a[2] / info->a[1]; s->tr[4] = 0; s->tr[5] = -info->a[6] * info->x; s->tr[6] = info->a[3]; s->tr[7] = -info->a[5] / info->a[3]; } s->tr[0] >>= 11; s->tr[1] >>= 11; s->tr[3] <<= 4; s->tr[4] >>= 11; s->tr[5] >>= 11; s->tr[7] <<= 4;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?