Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 5d50c419 in mainline for uspace/drv/hid/ps2mouse/ps2mouse.c


Ignore:
Timestamp:
2017-11-19T21:14:19Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
c657bd7
Parents:
75fcf9b
Message:

Chardev API should separate error code from number of bytes transferred. This is cleaner, allows the code to be more independent of Exxx sign and allows for partial success (some bytes successfully transferred and then an error occurred.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/hid/ps2mouse/ps2mouse.c

    r75fcf9b r5d50c419  
    7575        uint8_t value = (value_); \
    7676        uint8_t data = 0; \
    77         const ssize_t size = chardev_read((mouse)->chardev, &data, 1); \
    78         if (size != 1) { \
    79                 ddf_msg(LVL_ERROR, "Failed reading byte: %zd)", size);\
    80                 return size < 0 ? size : EIO; \
     77        size_t nread; \
     78        const int rc = chardev_read((mouse)->chardev, &data, 1, &nread); \
     79        if (rc != EOK) { \
     80                ddf_msg(LVL_ERROR, "Failed reading byte: %d", rc);\
     81                return rc; \
    8182        } \
    8283        if (data != value) { \
     
    9192        uint8_t value = (value_); \
    9293        uint8_t data = (value); \
    93         const ssize_t size = chardev_write((mouse)->chardev, &data, 1); \
    94         if (size < 0 ) { \
    95                 ddf_msg(LVL_ERROR, "Failed writing byte: %hhx", value); \
    96                 return size; \
     94        size_t nwr; \
     95        const int rc = chardev_write((mouse)->chardev, &data, 1, &nwr); \
     96        if (rc != EOK) { \
     97                ddf_msg(LVL_ERROR, "Failed writing byte: %d", rc); \
     98                return rc; \
    9799        } \
    98100} while (0)
     
    172174        /* Enable mouse data reporting. */
    173175        uint8_t report = PS2_MOUSE_ENABLE_DATA_REPORT;
    174         ssize_t size = chardev_write(mouse->chardev, &report, 1);
    175         if (size != 1) {
     176        size_t nwr;
     177        rc = chardev_write(mouse->chardev, &report, 1, &nwr);
     178        if (rc != EOK) {
    176179                ddf_msg(LVL_ERROR, "Failed to enable data reporting.");
    177180                rc = EIO;
     
    179182        }
    180183
    181         size = chardev_read(mouse->chardev, &report, 1);
    182         if (size != 1 || report != PS2_MOUSE_ACK) {
     184        size_t nread;
     185        rc = chardev_read(mouse->chardev, &report, 1, &nread);
     186        if (rc != EOK || report != PS2_MOUSE_ACK) {
    183187                ddf_msg(LVL_ERROR, "Failed to confirm data reporting: %hhx.",
    184188                    report);
     
    215219{
    216220        ps2_mouse_t *mouse = (ps2_mouse_t *) arg;
     221        size_t nread;
     222        int rc;
    217223
    218224        bool buttons[PS2_BUTTON_COUNT] = {};
    219225        while (1) {
    220226                uint8_t packet[PS2_BUFSIZE] = {};
    221                 const ssize_t size =
    222                     chardev_read(mouse->chardev, packet, PS2_BUFSIZE);
    223 
    224                 if (size != PS2_BUFSIZE) {
    225                         ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", size);
     227                rc = chardev_read(mouse->chardev, packet, PS2_BUFSIZE, &nread);
     228                if (rc != EOK || nread != PS2_BUFSIZE) {
     229                        ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", nread);
    226230                        continue;
    227231                }
     232
    228233                ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx.",
    229234                    packet[0], packet[1], packet[2]);
     
    269274{
    270275        ps2_mouse_t *mouse = (ps2_mouse_t *) arg;
     276        size_t nread;
     277        int rc;
    271278
    272279        bool buttons[INTELLIMOUSE_BUTTON_COUNT] = {};
    273280        while (1) {
    274281                uint8_t packet[INTELLIMOUSE_BUFSIZE] = {};
    275                 const ssize_t size = chardev_read(
    276                     mouse->chardev, packet, INTELLIMOUSE_BUFSIZE);
    277 
    278                 if (size != INTELLIMOUSE_BUFSIZE) {
    279                         ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", size);
     282                rc = chardev_read(mouse->chardev, packet, INTELLIMOUSE_BUFSIZE,
     283                    &nread);
     284                if (rc != EOK || nread != INTELLIMOUSE_BUFSIZE) {
     285                        ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", nread);
    280286                        continue;
    281287                }
Note: See TracChangeset for help on using the changeset viewer.