Subversion Repositories HelenOS-historic

Rev

Rev 1759 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1759 Rev 1780
Line 82... Line 82...
82
/**
82
/**
83
 * These codes read from i8042 data register are silently ignored.
83
 * These codes read from i8042 data register are silently ignored.
84
 */
84
 */
85
#define IGNORE_CODE 0x7f
85
#define IGNORE_CODE 0x7f
86
 
86
 
87
static void key_released(__u8 sc);
87
static void key_released(uint8_t sc);
88
static void key_pressed(__u8 sc);
88
static void key_pressed(uint8_t sc);
89
static char key_read(chardev_t *d);
89
static char key_read(chardev_t *d);
90
 
90
 
91
#define PRESSED_SHIFT       (1<<0)
91
#define PRESSED_SHIFT       (1<<0)
92
#define PRESSED_CAPSLOCK    (1<<1)
92
#define PRESSED_CAPSLOCK    (1<<1)
93
#define LOCKED_CAPSLOCK     (1<<0)
93
#define LOCKED_CAPSLOCK     (1<<0)
94
 
94
 
95
#define ACTIVE_READ_BUFF_SIZE 16    /* Must be power of 2 */
95
#define ACTIVE_READ_BUFF_SIZE 16    /* Must be power of 2 */
96
 
96
 
97
static __u8 active_read_buff[ACTIVE_READ_BUFF_SIZE];
97
static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
98
 
98
 
99
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
99
SPINLOCK_INITIALIZE(keylock);       /**< keylock protects keyflags and lockflags. */
100
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
100
static volatile int keyflags;       /**< Tracking of multiple keypresses. */
101
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
101
static volatile int lockflags;      /**< Tracking of multiple keys lockings. */
102
 
102
 
Line 320... Line 320...
320
 * @param n Interrupt vector.
320
 * @param n Interrupt vector.
321
 * @param istate Interrupted state.
321
 * @param istate Interrupted state.
322
 */
322
 */
323
void i8042_interrupt(int n, istate_t *istate)
323
void i8042_interrupt(int n, istate_t *istate)
324
{
324
{
325
    __u8 x;
325
    uint8_t x;
326
    __u8 status;
326
    uint8_t status;
327
 
327
 
328
    while (((status=i8042_status_read()) & i8042_BUFFER_FULL_MASK)) {
328
    while (((status=i8042_status_read()) & i8042_BUFFER_FULL_MASK)) {
329
        x = i8042_data_read();
329
        x = i8042_data_read();
330
 
330
 
331
        if ((status & i8042_MOUSE_DATA))
331
        if ((status & i8042_MOUSE_DATA))
Line 348... Line 348...
348
 
348
 
349
/** Process release of key.
349
/** Process release of key.
350
 *
350
 *
351
 * @param sc Scancode of the key being released.
351
 * @param sc Scancode of the key being released.
352
 */
352
 */
353
void key_released(__u8 sc)
353
void key_released(uint8_t sc)
354
{
354
{
355
    spinlock_lock(&keylock);
355
    spinlock_lock(&keylock);
356
    switch (sc) {
356
    switch (sc) {
357
        case SC_LSHIFT:
357
        case SC_LSHIFT:
358
        case SC_RSHIFT:
358
        case SC_RSHIFT:
Line 373... Line 373...
373
 
373
 
374
/** Process keypress.
374
/** Process keypress.
375
 *
375
 *
376
 * @param sc Scancode of the key being pressed.
376
 * @param sc Scancode of the key being pressed.
377
 */
377
 */
378
void key_pressed(__u8 sc)
378
void key_pressed(uint8_t sc)
379
{
379
{
380
    char *map = sc_primary_map;
380
    char *map = sc_primary_map;
381
    char ascii = sc_primary_map[sc];
381
    char ascii = sc_primary_map[sc];
382
    bool shift, capslock;
382
    bool shift, capslock;
383
    bool letter = false;
383
    bool letter = false;
Line 451... Line 451...
451
/* Called from getc(). */
451
/* Called from getc(). */
452
void i8042_suspend(chardev_t *d)
452
void i8042_suspend(chardev_t *d)
453
{
453
{
454
}
454
}
455
 
455
 
456
static __u8 active_read_buff_read(void)
456
static uint8_t active_read_buff_read(void)
457
{
457
{
458
    static int i=0;
458
    static int i=0;
459
    i &= (ACTIVE_READ_BUFF_SIZE-1);
459
    i &= (ACTIVE_READ_BUFF_SIZE-1);
460
    if(!active_read_buff[i]) {
460
    if(!active_read_buff[i]) {
461
        return 0;
461
        return 0;
462
    }
462
    }
463
    return active_read_buff[i++];
463
    return active_read_buff[i++];
464
}
464
}
465
 
465
 
466
static void active_read_buff_write(__u8 ch)
466
static void active_read_buff_write(uint8_t ch)
467
{
467
{
468
    static int i=0;
468
    static int i=0;
469
    active_read_buff[i] = ch;
469
    active_read_buff[i] = ch;
470
    i++;
470
    i++;
471
    i &= (ACTIVE_READ_BUFF_SIZE-1);
471
    i &= (ACTIVE_READ_BUFF_SIZE-1);
472
    active_read_buff[i]=0;
472
    active_read_buff[i]=0;
473
}
473
}
474
 
474
 
475
 
475
 
476
static void active_read_key_pressed(__u8 sc)
476
static void active_read_key_pressed(uint8_t sc)
477
{
477
{
478
    char *map = sc_primary_map;
478
    char *map = sc_primary_map;
479
    char ascii = sc_primary_map[sc];
479
    char ascii = sc_primary_map[sc];
480
    bool shift, capslock;
480
    bool shift, capslock;
481
    bool letter = false;
481
    bool letter = false;
Line 545... Line 545...
545
static char key_read(chardev_t *d)
545
static char key_read(chardev_t *d)
546
{
546
{
547
    char ch;   
547
    char ch;   
548
 
548
 
549
    while(!(ch = active_read_buff_read())) {
549
    while(!(ch = active_read_buff_read())) {
550
        __u8 x;
550
        uint8_t x;
551
        while (!(i8042_status_read() & i8042_BUFFER_FULL_MASK))
551
        while (!(i8042_status_read() & i8042_BUFFER_FULL_MASK))
552
            ;
552
            ;
553
        x = i8042_data_read();
553
        x = i8042_data_read();
554
        if (x != IGNORE_CODE) {
554
        if (x != IGNORE_CODE) {
555
            if (x & KEY_RELEASE)
555
            if (x & KEY_RELEASE)
Line 565... Line 565...
565
 *
565
 *
566
 * This function can be used to implement keyboard polling.
566
 * This function can be used to implement keyboard polling.
567
 */
567
 */
568
void i8042_poll(void)
568
void i8042_poll(void)
569
{
569
{
570
    __u8 x;
570
    uint8_t x;
571
 
571
 
572
    while (((x = i8042_status_read() & i8042_BUFFER_FULL_MASK))) {
572
    while (((x = i8042_status_read() & i8042_BUFFER_FULL_MASK))) {
573
        x = i8042_data_read();
573
        x = i8042_data_read();
574
        if (x != IGNORE_CODE) {
574
        if (x != IGNORE_CODE) {
575
            if (x & KEY_RELEASE)
575
            if (x & KEY_RELEASE)