Changeset 74017ce in mainline for uspace/srv/hid/isdv4_tablet/isdv4.c


Ignore:
Timestamp:
2017-11-22T17:36:54Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a6065c
Parents:
c4c6025
git-author:
Jiri Svoboda <jiri@…> (2017-11-22 15:53:34)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-22 17:36:54)
Message:

Convert char_dev_iface users to chardev.

File:
1 edited

Legend:

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

    rc4c6025 r74017ce  
    2727 */
    2828
    29 #include <char_dev_iface.h>
    3029#include <errno.h>
     30#include <io/chardev.h>
     31#include <mem.h>
    3132#include <stdbool.h>
    3233#include <stdint.h>
    3334#include <stdlib.h>
    34 #include <mem.h>
    3535#include <thread.h>
    3636
     
    298298        bool reading = true;
    299299        while (reading) {
    300                 ssize_t read = char_dev_read(state->sess, state->buf + state->buf_end,
    301                     state->buf_size - state->buf_end);
    302                 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)
    303306                        return EIO;
    304                 state->buf_end += read;
     307                state->buf_end += nread;
    305308
    306309                size_t i = 0;
     
    357360        return EOK;
    358361}
    359 static bool write_command(async_sess_t *sess, uint8_t command)
    360 {
    361         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;
    362370}
    363371
     
    365373    isdv4_event_fn event_fn)
    366374{
     375        chardev_t *chardev;
     376        int rc;
     377
     378        rc = chardev_open(sess, &chardev);
     379        if (rc != EOK)
     380                return rc;
     381
    367382        memset(state, 0, sizeof(isdv4_state_t));
     383
    368384        state->sess = sess;
     385        state->chardev = chardev;
     386
    369387        state->buf = malloc(BUF_SIZE);
    370         if (state->buf == NULL)
     388        if (state->buf == NULL) {
     389                chardev_close(chardev);
    371390                return ENOMEM;
     391        }
     392
    372393        state->buf_size = BUF_SIZE;
    373394        state->emit_event_fn = event_fn;
     
    377398int isdv4_init_tablet(isdv4_state_t *state)
    378399{
    379         if (!write_command(state->sess, CMD_STOP))
     400        if (!write_command(state->chardev, CMD_STOP))
    380401                return EIO;
    381402
     
    383404
    384405        // FIXME: Read all possible garbage before sending commands
    385         if (!write_command(state->sess, CMD_QUERY_STYLUS))
     406        if (!write_command(state->chardev, CMD_QUERY_STYLUS))
    386407                return EIO;
    387408
     
    390411                return rc;
    391412
    392         if (!write_command(state->sess, CMD_QUERY_TOUCH))
     413        if (!write_command(state->chardev, CMD_QUERY_TOUCH))
    393414                return EIO;
    394415
     
    397418                return rc;
    398419
    399         if (!write_command(state->sess, CMD_START))
     420        if (!write_command(state->chardev, CMD_START))
    400421                return EIO;
    401422
Note: See TracChangeset for help on using the changeset viewer.