Project

General

Profile

Revision 36

implemented keyboard polling

View differences:

lab3/kbc.c
62 62
    if (increment) return ++counter;
63 63
    return counter;
64 64
}
65

  
66
int (kbd_poll)(uint8_t bytes[], uint8_t *size){
67
    if(bytes == NULL || size == NULL) return 1;
68
    uint8_t c;
69
    if(kbd_read_byte(&c)) return 1;
70
    if(c == TWO_BYTE_CODE){
71
        if(kbd_read_byte(&bytes[0])) return 1;
72
        bytes[1] = c;
73
        *size = 2;
74
    }else{
75
        bytes[1] = 0;
76
        bytes[0] = c;
77
        *size = 1;
78
    }
79
    return 0;
80
}
81

  
82
int (kbd_read_byte)(uint8_t *value){
83
    uint8_t stat;
84
    while(1){
85
        if(util_sys_inb(STATUS_REG, &stat)) return 1;
86
        if((stat&OUT_BUF_FUL) && ((stat&AUX_MOUSE)^AUX_MOUSE)){
87
            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return 1;
88
            else return util_sys_inb(OUTPUT_BUF, value);
89
        }
90
        tickdelay(micros_to_ticks(DELAY));
91
    }
92
}
lab3/kbc.h
6 6
#define KBC_IRQ     1 /* @brief KBC Controller IRQ Line */
7 7

  
8 8
/* Delay for KBC */
9
#define DELAY   20000 /* @brief KBC Response Delay */
9
#define DELAY   50000 /* @brief KBC Response Delay */
10 10

  
11 11
/* I/O Ports Addresses */
12 12

  
lab3/kbc_func.h
34 34
 */
35 35
uint32_t (sys_inb_counter)(int get_increment);
36 36

  
37
/**
38
 * @brief High-level function that polls keyboard for scancode
39
 * High-level function that polls keyboard for scancode of up to 2 bytes. If
40
 * scancode has only 1 byte, the second byte is set to 0x00.
41
 * @param bytes Array of at least 2 bytes to store scancode
42
 * @param size Size of scancode in bytes
43
 * @return 0 if operation was successful, 1 otherwise
44
 */
45
int (kbd_poll)(uint8_t bytes[], uint8_t *size);
46

  
47
/**
48
 * @brief Low-level function for reading byte from keyboard
49
 * Low-level function for reading byte from keyboard. Waits until output buffer
50
 * is full
51
 * @param value Pointer to variable where byte read from keyboard will be stored
52
 * @return 0 if operation was successful, 1 otherwise
53
 */
54
int (kbd_read_byte)(uint8_t *value);
55

  
37 56
#endif
lab3/lab3.c
90 90
}
91 91

  
92 92
int(kbd_test_poll)() {
93
  /* To be completed by the students */
94
  printf("%s is not yet implemented!\n", __func__);
95

  
96
  return 1;
93
    uint8_t c[2]; uint8_t size;
94
    do{
95
        if(kbd_poll(c, &size)) return 1;
96
        if(kbd_print_scancode((~c[0])&BREAK_CODE_BIT, size, c)) return 1;
97
    }while(!(size == 1 && c[0] == ESC_BREAK_CODE));
98
    return 0;
97 99
}
98 100

  
99 101
int(kbd_test_timed_scan)(uint8_t n) {

Also available in: Unified diff