Changes in uspace/srv/hid/isdv4_tablet/isdv4.c [582a0b8:f300523] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/isdv4_tablet/isdv4.c
r582a0b8 rf300523 27 27 */ 28 28 29 #include < char_dev_iface.h>29 #include <async.h> 30 30 #include <errno.h> 31 #include <io/chardev.h> 32 #include <mem.h> 33 #include <stdbool.h> 34 #include <stdint.h> 31 35 #include <stdlib.h> 32 #include <mem.h>33 #include <thread.h>34 36 35 37 #include "isdv4.h" … … 296 298 bool reading = true; 297 299 while (reading) { 298 ssize_t read = char_dev_read(state->sess, state->buf + state->buf_end, 299 state->buf_size - state->buf_end); 300 if (read < 0) 300 size_t nread; 301 int rc; 302 303 rc = chardev_read(state->chardev, state->buf + state->buf_end, 304 state->buf_size - state->buf_end, &nread); 305 if (rc != EOK && nread == 0) 301 306 return EIO; 302 state->buf_end += read;307 state->buf_end += nread; 303 308 304 309 size_t i = 0; … … 355 360 return EOK; 356 361 } 357 static bool write_command(async_sess_t *sess, uint8_t command) 358 { 359 return char_dev_write(sess, &command, 1) == 1; 362 363 static bool write_command(chardev_t *chardev, uint8_t command) 364 { 365 int rc; 366 size_t nwr; 367 368 rc = chardev_write(chardev, &command, 1, &nwr); 369 return rc == EOK; 360 370 } 361 371 … … 363 373 isdv4_event_fn event_fn) 364 374 { 375 chardev_t *chardev; 376 int rc; 377 378 rc = chardev_open(sess, &chardev); 379 if (rc != EOK) 380 return rc; 381 365 382 memset(state, 0, sizeof(isdv4_state_t)); 383 366 384 state->sess = sess; 385 state->chardev = chardev; 386 367 387 state->buf = malloc(BUF_SIZE); 368 if (state->buf == NULL) 388 if (state->buf == NULL) { 389 chardev_close(chardev); 369 390 return ENOMEM; 391 } 392 370 393 state->buf_size = BUF_SIZE; 371 394 state->emit_event_fn = event_fn; … … 375 398 int isdv4_init_tablet(isdv4_state_t *state) 376 399 { 377 if (!write_command(state-> sess, CMD_STOP))400 if (!write_command(state->chardev, CMD_STOP)) 378 401 return EIO; 379 402 380 thread_usleep(250000); /* 250 ms */403 async_usleep(250000); /* 250 ms */ 381 404 382 405 // FIXME: Read all possible garbage before sending commands 383 if (!write_command(state-> sess, CMD_QUERY_STYLUS))406 if (!write_command(state->chardev, CMD_QUERY_STYLUS)) 384 407 return EIO; 385 408 … … 388 411 return rc; 389 412 390 if (!write_command(state-> sess, CMD_QUERY_TOUCH))413 if (!write_command(state->chardev, CMD_QUERY_TOUCH)) 391 414 return EIO; 392 415 … … 395 418 return rc; 396 419 397 if (!write_command(state-> sess, CMD_START))420 if (!write_command(state->chardev, CMD_START)) 398 421 return EIO; 399 422
Note:
See TracChangeset
for help on using the changeset viewer.