Index: lab4/mouse_func.c
===================================================================
--- lab4/mouse_func.c	(revision 57)
+++ lab4/mouse_func.c	(nonexistent)
@@ -1,59 +0,0 @@
-#include "mouse_func.h"
-#include "errors.h"
-#include "kbc.h"
-#include "mouse.h"
-
-#include <lcom/lcf.h>
-
-int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
-    if (interrupt_id == NULL) return NULL_PTR;
-    *interrupt_id = interrupt_bit;
-    if (sys_irqsetpolicy(MOUSE_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
-    return SUCCESS;
-}
-
-int got_error_mouse_ih = 0;
-uint8_t packet[3];
-int counter = 0;
-
-void (mouse_ih)(void) {
-    uint8_t status = 0;
-    got_error_mouse_ih = 0;
-
-    if (util_sys_inb(STATUS_REG, &status)) {
-        got_error_mouse_ih = 1;
-        return;
-    }
-
-    if (status & (TIME_OUT_REC | PARITY_ERROR)) {
-        got_error_mouse_ih = 1;
-        return;
-    }
-
-    uint8_t byte = 0;
-
-    if (util_sys_inb(OUTPUT_BUF, &byte)) {
-        got_error_mouse_ih = 1;
-        return;
-    }
-
-    if(counter >= 3) counter = 0;
-    packet[counter] = byte;
-    counter++;
-
-}
-
-struct packet (mouse_parse_packet)(const uint8_t *packet_bytes){
-    struct packet pp;
-    pp.bytes[0] = packet_bytes[0];
-    pp.bytes[1] = packet_bytes[1];
-    pp.bytes[2] = packet_bytes[2];
-    pp.rb       = pp.bytes[0] & RIGHT_BUTTON;
-    pp.mb       = pp.bytes[0] & MIDDLE_BUTTON;
-    pp.lb       = pp.bytes[0] & LEFT_BUTTON;
-    pp.delta_x  = pp.bytes[1];
-    pp.delta_y  = pp.bytes[2];
-    pp.x_ov     = pp.bytes[0] & X_OVERFLOW;
-    pp.y_ov     = pp.bytes[0] & Y_OVERFLOW;
-    return pp;
-}

Property changes on: lab4/mouse_func.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: lab4/mouse_func.h
===================================================================
--- lab4/mouse_func.h	(revision 57)
+++ lab4/mouse_func.h	(nonexistent)
@@ -1,17 +0,0 @@
-#ifndef _MOUSE_FUNC_H_
-#define _MOUSE_FUNC_H_
-
-#include <stdint.h>
-
-/**
- * @brief Subscribes Mouse Interrupts and disables Minix Default IH
- * @param interrupt_bit Bit of Interrupt Vector that will be set when Mouse Interrupt is pending
- * @param interrupt_id Mouse Interrupt ID to specify the Mouse Interrupt in other calls
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- * @see {_ERRORS_H_::errors}
- */
-int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
-
-struct packet (mouse_parse_packet)(const uint8_t *packet_bytes);
-
-#endif /* end of include guard: _MOUSE_FUNC_H_ */

Property changes on: lab4/mouse_func.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: lab4/Makefile
===================================================================
--- lab4/Makefile	(revision 57)
+++ lab4/Makefile	(revision 58)
@@ -2,7 +2,7 @@
 PROG=lab4
 
 # source code files to be compiled
-SRCS = lab4.c mouse_func.c utils.c kbc_func.c
+SRCS = lab4.c mouse.c utils.c kbc.c kbd.c
 
 # additional compilation flags
 # "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set
Index: lab4/kbc.h
===================================================================
--- lab4/kbc.h	(revision 57)
+++ lab4/kbc.h	(revision 58)
@@ -1,56 +1,80 @@
-#ifndef _KBC_H_
-#define _KBC_H_
+#ifndef _KBC_FUNC_H_
+#define _KBC_FUNC_H_
 
-/* KBC IRQ Line */
+#include <stdint.h>
 
-#define KBC_IRQ     1   /* @brief KBC Controller IRQ Line */
-#define MOUSE_IRQ   12  /* @brief Mouse IRQ Line */
+#define GET         0 /* @brief Argument to get counter without incrementing */
+#define INCREMENT   1 /* @brief Argument for incrementing counter */
 
-/* Delay for KBC */
-#define DELAY           20000 /* @brief KBC Response Delay */
-#define KBC_NUM_TRIES   10    /* @brief Number of tries to issue command before timeout */
+/**
+ * @brief Subscribes KBC Interrupts and disables Minix Default Keyboard IH
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when KBC Interrupt is pending
+ * @param interrupt_id KBC Interrupt ID to specify the KBC Interrupt in other calls
+ * @return Whether operation was sucessful or not
+ */
+int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
 
-/* I/O Ports Addresses */
+/**
+ * @brief Unsubcribes Interrupts
+ * @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
+ * @see subscribe_kbc_interrupt, subscribe_timer_interrupt
+ * @return Whether operation was sucessful or not
+ */
+int (unsubscribe_interrupt)(int *interrupt_id);
 
-#define KBC_CMD     0x64 /* @brief Address to send commands to KBC */
-#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */
-#define STATUS_REG  0x64 /* @brief KBC Status Register address */
+/**
+ * @brief KBC Interrupt Handler
+ */
+void (kbc_ih)(void);
 
-#define OUTPUT_BUF  0x60 /* @brief Address of Output Buffer of KBC */
+/**
+ * @brief High-level function that polls keyboard for scancode
+ * High-level function that polls keyboard for scancode of up to 2 bytes. If
+ * scancode has only 1 byte, the second byte is set to 0x00.
+ * @param bytes Array of at least 2 bytes to store scancode
+ * @param size Size of scancode in bytes
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbd_poll)(uint8_t bytes[], uint8_t *size);
 
-/* KBC Commands */
-#define READ_KBC_CMD    0x20 /* @brief Read KBC Command Byte */
-#define WRITE_KBC_CMD   0x60 /* @brief Write KBC Command Byte */
-#define KBC_SELF_TEST   0xAA /* @brief KBC Diagnostic Tests */
-#define KBC_INT_TEST    0xAB /* @brief Tests Keyboard Clock and Data lines */
-#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */
-#define KBC_INT_ENABLE  0xAE /* @brief Enable KBC Interface */
-#define MOUSE_DISABLE   0xA7 /* @brief Disable Mouse */
-#define MOUSE_ENABLE    0xA8 /* @brief Enable Mouse */
-#define MOUSE_INT_TEST  0xA9 /* @brief Tests Mouse data line */
-#define MOUSE_WRITE_B   0xD4 /* @brief Write a byte directly to the mouse */
+/**
+ * @brief High-level function that reads the command byte of the KBC
+ * @param cmd Pointer to variable where command byte read from KBC will be stored
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_read_cmd)(uint8_t *cmd);
 
-/* Status Byte Masking */
+/**
+ * @brief High-level function that changes the command byte of the KBC
+ * @param cmd New value for command byte of KBC
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_change_cmd)(uint8_t cmd);
 
-#define OUT_BUF_FUL     BIT(0) /* @brief Output Buffer State */
-#define IN_BUF_FULL     BIT(1) /* @brief Input Buffer State */
-#define SYS_FLAG        BIT(2) /* @brief System Flag */
-#define DATA_CMD_WRITE  BIT(3) /* @brief Identifier of type of byte in input buffer */
-#define INH_FLAG        BIT(4) /* @brief Keyboard inihibited */
-#define AUX_MOUSE       BIT(5) /* @brief Mouse Data */
-#define TIME_OUT_REC    BIT(6) /* @brief Time Out Error - Invalid Data */
-#define PARITY_ERROR    BIT(7) /* @brief Parity Error - Invalid Data */
+/**
+ * @brief High-level function that restores KBC to normal state
+ * High-level function that restores KBC to normal state, because lcf_start
+ * changes the command byte of KBC. If this function is not used, there is a
+ * chance that the keyboard and keyboard interrupts remain disabled.
+ * @return 1 if operation was successful, 1 otherwise
+ */
+int (kbc_restore_kbd)();
 
-/* Scancode Constants */
+/**
+ * @brief Low-level function to issue a command to keyboard
+ * @param cmd command to be issued
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_issue_cmd)(uint8_t cmd);
 
-#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
-#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
-#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
+/**
+ * @brief Low-level function for reading byte from keyboard
+ * Low-level function for reading byte from keyboard. Waits until output buffer
+ * is full
+ * @param value Pointer to variable where byte read from keyboard will be stored
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_read_byte)(uint8_t *byte);
 
-/* Command byte masks */
-#define INT_KBD         BIT(0)  /* @brief Enable Keyboard Interrupts */
-#define INT_MOU         BIT(1)  /* @brief Enable Mouse Interrupts */
-#define DIS_KBD         BIT(4)  /* @brief Disable Keyboard */
-#define DIS_MOU         BIT(5)  /* @brief Disable Mouse */
 
 #endif
Index: lab4/lab4.c
===================================================================
--- lab4/lab4.c	(revision 57)
+++ lab4/lab4.c	(revision 58)
@@ -3,8 +3,8 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include "mouse_func.h"
-#include "kbc_func.h"
+#include "mouse.h"
+#include "kbc.h"
 
 int main(int argc, char *argv[]) {
   // sets the language of LCF messages (can be either EN-US or PT-PT)
@@ -63,13 +63,6 @@
                             cnt_now++;
                             if(cnt == cnt_now) good = 0;
                         }
-                        /*
-                        if (!(two_byte_scancode || got_error)) { // finished processing a scancode
-                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
-                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
-                        } else { break; }
-                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
-                        */
                     }
                     break;
                 default:
@@ -81,8 +74,9 @@
     }
 
     if (unsubscribe_interrupt(&mouse_id)) return 1;
-    if(kbc_restore_kbd()) return 1;
 
+    if(mouse_set_data_report(false)) return 1;
+
     return 0;
 }
 
Index: lab4/mouse.h
===================================================================
--- lab4/mouse.h	(revision 57)
+++ lab4/mouse.h	(revision 58)
@@ -1,37 +1,19 @@
-#ifndef _MOUSE_H_
-#define _MOUSE_H_
+#ifndef _MOUSE_FUNC_H_
+#define _MOUSE_FUNC_H_
 
-/* Mouse Data Packet */
-// Byte 0 - Button States
-#define LEFT_BUTTON     BIT(0) /* @brief Left button click event*/
-#define RIGHT_BUTTON    BIT(1) /* @brief Right button click event */
-#define MIDDLE_BUTTON   BIT(2) /* @brief Middle button click event */
-#define FIRST_BYTE_ID   BIT(3) /* @brief Identifier of first byte of packet CAREFUL: Not 100% accurate */
-#define MSB_X_DELTA     BIT(4) /* @brief Most significant bit of X delta */
-#define MSB_Y_DELTA     BIT(5) /* @brief Most significant bit of Y delta */
-#define X_OVERFLOW      BIT(6) /* @brief X delta overflowed */
-#define Y_OVERFLOW      BIT(7) /* @brief Y delta overflowed */
-// Byte 1 - X delta
-// Byte 2 - Y delta
+#include <stdint.h>
 
-/* Mouse Commands */
-#define RESET           0xFF /* @brief Reset mouse */
-#define RESEND          0xFE /* @brief Resend command */
-#define DEFAULT         0xF6 /* @brief Set default values */
-#define DIS_DATA_REP    0xF5 /* @brief Disable Data Reporting */
-#define ENABLE_DATA_REP 0xF4 /* @brief Enable Data Reporting */
-#define SET_SAMPLE_RT   0xF3 /* @brief Sets state sampling rate */
-#define SET_REMOTE_MD   0xF0 /* @brief Sets Mouse on Remote Mode, data on request */
-#define READ_DATA       0xEB /* @brief Sends data packet request */
-#define SET_STREAM_MD   0xEA /* @brief Sets mouse on Stream Mode, data on events */
-#define STATUS_REQUEST  0xE9 /* @brief Get mouse configuration */
-#define SET_RESOLUTION  0xE8 /* @brief Sets resolution for mouse movement */
-#define SCALING_ACC_MD  0xE7 /* @brief Sets scaling on acceleration mode */
-#define SCALING_LIN_MD  0xE6 /* @brief Sets scaling on linear mode */
+/**
+ * @brief Subscribes Mouse Interrupts and disables Minix Default IH
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when Mouse Interrupt is pending
+ * @param interrupt_id Mouse Interrupt ID to specify the Mouse Interrupt in other calls
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
 
-/* Mouse Controller Responses */
-#define ACK_OK      0xFA /* @brief Operation sucessful */
-#define ACK_INVALID 0xFE /* @brief Invalid Byte, first occurence */
-#define ACK_ERROR   0xFC /* @brief Invalid Byte on resend */
+struct packet (mouse_parse_packet)(const uint8_t *packet_bytes);
 
-#endif // _MOUSE_H_
+int (mouse_set_data_report)(int on);
+
+#endif /* end of include guard: _MOUSE_FUNC_H_ */
