Changeset 6a44ee4 in mainline for uspace/srv/hid/input/proto/ps2.c


Ignore:
Timestamp:
2011-07-20T15:26:21Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efcebe1
Parents:
25bef0ff (diff), a701812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/proto/ps2.c

    r25bef0ff r6a44ee4  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup mouse
     29/** @addtogroup mouse_proto
     30 * @ingroup input
    3031 * @{
    3132 */
    3233/**
    3334 * @file
    34  * @brief PS/2 mouse protocol driver.
     35 * @brief PS/2 protocol driver.
    3536 */
    3637
    37 #include <stdio.h>
     38#include <mouse.h>
    3839#include <mouse_port.h>
    39 #include <char_mouse.h>
    4040#include <mouse_proto.h>
    41 
    42 #define BUFSIZE 3
    4341
    4442#define PS2_MOUSE_OUT_INIT  0xf4
    4543#define PS2_MOUSE_ACK       0xfa
     44
     45#define BUFSIZE 3
    4646
    4747typedef struct {
     
    4949                unsigned char data[BUFSIZE];
    5050                struct {
    51                         unsigned leftbtn : 1;
    52                         unsigned rightbtn : 1;
    53                         unsigned middlebtn : 1;
    54                         unsigned isone : 1; /* Always one */
    55                         unsigned xsign : 1;
    56                         unsigned ysign : 1;
    57                         unsigned xovfl : 1;
    58                         unsigned yovfl : 1;
     51                        unsigned int leftbtn : 1;
     52                        unsigned int rightbtn : 1;
     53                        unsigned int middlebtn : 1;
     54                        unsigned int isone : 1; /* Always one */
     55                        unsigned int xsign : 1;
     56                        unsigned int ysign : 1;
     57                        unsigned int xovfl : 1;
     58                        unsigned int yovfl : 1;
    5959                        unsigned char x;
    6060                        unsigned char y;
     
    6464
    6565static ps2packet_t buf;
    66 static int bufpos = 0;
    67 static int leftbtn = 0;
    68 static int rightbtn = 0;
    69 static int middlebtn = 0;
     66static unsigned int bufpos;
     67static unsigned int leftbtn;
     68static unsigned int rightbtn;
     69static unsigned int middlebtn;
    7070
    71 int mouse_proto_init(void)
     71static mouse_dev_t *mouse_dev;
     72
     73static int ps2_proto_init(mouse_dev_t *mdev)
    7274{
    73         mouse_port_write(PS2_MOUSE_OUT_INIT);
     75        mouse_dev = mdev;
     76        bufpos = 0;
     77        leftbtn = 0;
     78        rightbtn = 0;
     79       
     80        mouse_dev->port_ops->write(PS2_MOUSE_OUT_INIT);
    7481        return 0;
    7582}
     
    7986{
    8087        int tmp;
    81 
     88       
    8289        if (!sign)
    8390                return data;
    84 
    85         tmp = ((unsigned char)~data) + 1;
     91       
     92        tmp = ((unsigned char) ~data) + 1;
    8693        return -tmp;
    8794}
    8895
    8996/** Process mouse data */
    90 void mouse_proto_parse_byte(int data)
     97static void ps2_proto_parse(sysarg_t data)
    9198{
    9299        int x, y;
    93 
     100       
    94101        /* Check that we have not lost synchronization */
    95102        if (bufpos == 0 && !(data & 0x8))
    96103                return; /* Synchro lost, ignore byte */
    97 
     104       
    98105        buf.u.data[bufpos++] = data;
    99106        if (bufpos == BUFSIZE) {
    100107                bufpos = 0;
    101 
     108               
    102109                if (buf.u.val.leftbtn ^ leftbtn) {
    103110                        leftbtn = buf.u.val.leftbtn;
    104                         mouse_ev_btn(1, leftbtn);
     111                        mouse_push_event_button(mouse_dev, 1, leftbtn);
    105112                }
    106 
     113               
    107114                if (buf.u.val.rightbtn ^ rightbtn) {
    108115                        rightbtn = buf.u.val.rightbtn;
    109                         mouse_ev_btn(2, rightbtn);
     116                        mouse_push_event_button(mouse_dev, 2, rightbtn);
    110117                }
    111 
     118               
    112119                if (buf.u.val.middlebtn ^ middlebtn) {
    113120                        middlebtn = buf.u.val.middlebtn;
    114                         mouse_ev_btn(3, middlebtn);
     121                        mouse_push_event_button(mouse_dev, 3, middlebtn);
    115122                }
     123               
     124                x = bit9toint(buf.u.val.xsign, buf.u.val.x);
     125                y = -bit9toint(buf.u.val.ysign, buf.u.val.y);
     126               
     127                if (x != 0 || y != 0)
     128                        mouse_push_event_move(mouse_dev, x, y);
     129        }
     130}
    116131
    117                 x =   bit9toint(buf.u.val.xsign, buf.u.val.x);
    118                 y = - bit9toint(buf.u.val.ysign, buf.u.val.y);
    119 
    120                 if (x != 0 || y != 0) {
    121                         mouse_ev_move(x, y);
    122                 }
    123         }
    124 
    125         return;
    126 }
     132mouse_proto_ops_t ps2_proto = {
     133        .parse = ps2_proto_parse,
     134        .init = ps2_proto_init
     135};
    127136
    128137/**
Note: See TracChangeset for help on using the changeset viewer.