Project

General

Profile

Revision 39

fixed frozen keyboard

View differences:

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

  
82
int (kbd_issue_cmd)(uint8_t cmd){
82
int (kbc_read_cmd)(uint8_t *cmd){
83
    if(kbc_issue_cmd(READ_KBC_CMD)) return 1;
84
    if(kbc_read_byte(cmd)) return 1;
85
    return 0;
86
}
87

  
88
int (kbc_change_cmd)(uint8_t cmd){
89
    if(kbc_issue_cmd(WRITE_KBC_CMD)) return 1;
90
    if(sys_outb(KBC_CMD_ARG, cmd)) return 1;
91
    return 0;
92
}
93

  
94
int (kbc_issue_cmd)(uint8_t cmd){
83 95
    uint8_t stat;
84
    for(int i = 0; i < 10; ++i){
96
    while(1){
85 97
        if(util_sys_inb(STATUS_REG, &stat)) return 1;
86 98
        if((stat&IN_BUF_FULL) == 0){
87 99
            if(sys_outb(KBC_CMD, cmd)) return 1;
......
92 104
    return 1;
93 105
}
94 106

  
95
int (kbd_read_byte)(uint8_t *byte){
107
int (kbc_read_byte)(uint8_t *byte){
96 108
    uint8_t stat;
97 109
    while(true){
98 110
        if(util_sys_inb(STATUS_REG, &stat)) return 1;
......
104 116
        tickdelay(micros_to_ticks(DELAY));
105 117
    }
106 118
}
107

  
108
int (kbd_read_cmd)(uint8_t *cmd){
109
    if(kbd_issue_cmd(0x20)) return 1;
110
    if(kbd_read_byte(cmd)) return 1;
111
    return 0;
112
}
lab3/kbc.h
41 41
#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
42 42
#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
43 43

  
44
/* Command byte masks */
45
#define INT_KBD         BIT(0)
46
#define INT_MOU         BIT(1)
47
#define DIS_KBD         BIT(4)
48
#define DIS_MOU         BIT(5)
49

  
44 50
#endif
lab3/kbc_func.h
44 44
 */
45 45
int (kbd_poll)(uint8_t bytes[], uint8_t *size);
46 46

  
47
int (kbd_issue_cmd)(uint8_t cmd);
47
/**
48
 * @brief High-level function that reads the command byte of the KBC
49
 * @param cmd Pointer to variable where command byte read from KBC will be stored
50
 * @return 0 if operation was successful, 1 otherwise
51
 */
52
int (kbc_read_cmd)(uint8_t *cmd);
48 53

  
49 54
/**
55
 * @brief High-level function that changes the command byte of the KBC
56
 * @param cmd New value for command byte of KBC
57
 * @return 0 if operation was successful, 1 otherwise
58
 */
59
int (kbc_change_cmd)(uint8_t cmd);
60

  
61
/**
62
 * @brief Low-level function to issue a command to keyboard
63
 * @param cmd command to be issued
64
 * @return 0 if operation was successful, 1 otherwise
65
 */
66
int (kbc_issue_cmd)(uint8_t cmd);
67

  
68
/**
50 69
 * @brief Low-level function for reading byte from keyboard
51 70
 * Low-level function for reading byte from keyboard. Waits until output buffer
52 71
 * is full
53 72
 * @param value Pointer to variable where byte read from keyboard will be stored
54 73
 * @return 0 if operation was successful, 1 otherwise
55 74
 */
56
int (kbd_read_byte)(uint8_t *byte);
75
int (kbc_read_byte)(uint8_t *byte);
57 76

  
58
int (kbd_read_cmd)(uint8_t *cmd);
59 77

  
60 78
#endif
lab3/lab3.c
98 98
    }while(!(size == 1 && c[0] == ESC_BREAK_CODE));
99 99

  
100 100
    uint8_t cmd = 0;
101
    if(kbd_read_cmd(&cmd)) return 1;
102
    printf("%x\n", cmd);
101
    if(kbc_read_cmd(&cmd)) return 1;
102
    cmd = (cmd | INT_KBD) & (~DIS_KBD);
103 103

  
104
    if(kbc_change_cmd(cmd)) return 1;
105

  
104 106
    return 0;
105 107
}
106 108

  

Also available in: Unified diff