Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/isdv4_tablet/isdv4.c

    r582a0b8 rf300523  
    2727 */
    2828
    29 #include <char_dev_iface.h>
     29#include <async.h>
    3030#include <errno.h>
     31#include <io/chardev.h>
     32#include <mem.h>
     33#include <stdbool.h>
     34#include <stdint.h>
    3135#include <stdlib.h>
    32 #include <mem.h>
    33 #include <thread.h>
    3436
    3537#include "isdv4.h"
     
    296298        bool reading = true;
    297299        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)
    301306                        return EIO;
    302                 state->buf_end += read;
     307                state->buf_end += nread;
    303308
    304309                size_t i = 0;
     
    355360        return EOK;
    356361}
    357 static bool write_command(async_sess_t *sess, uint8_t command)
    358 {
    359         return char_dev_write(sess, &command, 1) == 1;
     362
     363static 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;
    360370}
    361371
     
    363373    isdv4_event_fn event_fn)
    364374{
     375        chardev_t *chardev;
     376        int rc;
     377
     378        rc = chardev_open(sess, &chardev);
     379        if (rc != EOK)
     380                return rc;
     381
    365382        memset(state, 0, sizeof(isdv4_state_t));
     383
    366384        state->sess = sess;
     385        state->chardev = chardev;
     386
    367387        state->buf = malloc(BUF_SIZE);
    368         if (state->buf == NULL)
     388        if (state->buf == NULL) {
     389                chardev_close(chardev);
    369390                return ENOMEM;
     391        }
     392
    370393        state->buf_size = BUF_SIZE;
    371394        state->emit_event_fn = event_fn;
     
    375398int isdv4_init_tablet(isdv4_state_t *state)
    376399{
    377         if (!write_command(state->sess, CMD_STOP))
     400        if (!write_command(state->chardev, CMD_STOP))
    378401                return EIO;
    379402
    380         thread_usleep(250000); /* 250 ms */
     403        async_usleep(250000); /* 250 ms */
    381404
    382405        // 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))
    384407                return EIO;
    385408
     
    388411                return rc;
    389412
    390         if (!write_command(state->sess, CMD_QUERY_TOUCH))
     413        if (!write_command(state->chardev, CMD_QUERY_TOUCH))
    391414                return EIO;
    392415
     
    395418                return rc;
    396419
    397         if (!write_command(state->sess, CMD_START))
     420        if (!write_command(state->chardev, CMD_START))
    398421                return EIO;
    399422
Note: See TracChangeset for help on using the changeset viewer.