Changeset c657bd7 in mainline for uspace/drv/hid/ps2mouse/ps2mouse.c


Ignore:
Timestamp:
2017-11-20T10:06:59Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
19ea61d
Parents:
5d50c419
git-author:
Jiri Svoboda <jiri@…> (2017-11-19 22:05:26)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-20 10:06:59)
Message:

Less is sometimes more. Need chardev_read to be able to return less bytes than requested if less is available. Otherwise cannot read variable-sized packets except yte-by-byte.

File:
1 edited

Legend:

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

    r5d50c419 rc657bd7  
    212212}
    213213
     214/** Read fixed-size mouse packet.
     215 *
     216 * Continue reading until entire packet is received.
     217 *
     218 * @param mouse Mouse device
     219 * @param pbuf Buffer for storing packet
     220 * @param psize Packet size
     221 *
     222 * @return EOK on success or non-zero error code
     223 */
     224static int ps2_mouse_read_packet(ps2_mouse_t *mouse, void *pbuf, size_t psize)
     225{
     226        int rc;
     227        size_t pos;
     228        size_t nread;
     229
     230        pos = 0;
     231        while (pos < psize) {
     232                rc = chardev_read(mouse->chardev, pbuf + pos, psize - pos,
     233                    &nread);
     234                if (rc != EOK) {
     235                        ddf_msg(LVL_WARN, "Error reading packet.");
     236                        return rc;
     237                }
     238
     239                pos += nread;
     240        }
     241
     242        return EOK;
     243}
     244
    214245/** Get data and parse ps2 protocol packets.
    215246 * @param arg Pointer to ps2_mouse_t structure.
     
    219250{
    220251        ps2_mouse_t *mouse = (ps2_mouse_t *) arg;
    221         size_t nread;
    222252        int rc;
    223253
     
    225255        while (1) {
    226256                uint8_t packet[PS2_BUFSIZE] = {};
    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);
     257                rc = ps2_mouse_read_packet(mouse, packet, PS2_BUFSIZE);
     258                if (rc != EOK)
    230259                        continue;
    231                 }
    232260
    233261                ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx.",
     
    274302{
    275303        ps2_mouse_t *mouse = (ps2_mouse_t *) arg;
    276         size_t nread;
    277304        int rc;
    278305
     
    280307        while (1) {
    281308                uint8_t packet[INTELLIMOUSE_BUFSIZE] = {};
    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);
     309                rc = ps2_mouse_read_packet(mouse, packet, INTELLIMOUSE_BUFSIZE);
     310                if (rc != EOK)
    286311                        continue;
    287                 }
     312
    288313                ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx:%hhx.",
    289314                    packet[0], packet[1], packet[2], packet[3]);
Note: See TracChangeset for help on using the changeset viewer.