Project

General

Profile

Revision 176

all .h to include folder

View differences:

proj/interrupts_func.h
1
#ifndef INTERRUPTS_FUNC_H_INCLUDED
2
#define INTERRUPTS_FUNC_H_INCLUDED
3

  
4
#include <stdint.h>
5

  
6
/**
7
 * @brief Subscribes all drivers used (timer->keyboard->mouse)
8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
9
 * @see {_ERRORS_H_::errors}
10
 */
11
int (subscribe_all)(void);
12

  
13
/**
14
 * @brief Unsubscribes all subscribed interrupts
15
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
16
 * @see {_ERRORS_H_::errors}
17
 */
18
int (unsubscribe_all)(void);
19

  
20
/**
21
 * @brief Calls interrupt handler corresponding to the bit specified by the argument.
22
 * @param handler Interrupt handler to call
23
 */
24
void interrupt_handler(uint8_t handler);
25

  
26
#endif /* end of include guard: INTERRUPTS_FUNC_H_INCLUDED */
27 0

  
proj/kbc_macros.h
1
#ifndef KBC_MACROS_H_INCLUDED
2
#define KBC_MACROS_H_INCLUDED
3

  
4
/* KBC IRQ Line */
5

  
6
#define KBC_IRQ     1   /* @brief KBC Controller IRQ Line */
7
#define MOUSE_IRQ   12  /* @brief Mouse IRQ Line */
8

  
9
/* Delay for KBC */
10
#define DELAY           20000 /* @brief KBC Response Delay */
11
#define KBC_NUM_TRIES   20    /* @brief Number of tries to issue command before timeout */
12

  
13
/* I/O Ports Addresses */
14

  
15
#define KBC_CMD     0x64 /* @brief Address to send commands to KBC */
16
#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */
17
#define STATUS_REG  0x64 /* @brief KBC Status Register address */
18

  
19
#define OUTPUT_BUF  0x60 /* @brief Address of Output Buffer of KBC */
20

  
21
/* KBC Commands */
22
#define READ_KBC_CMD    0x20 /* @brief Read KBC Command Byte */
23
#define WRITE_KBC_CMD   0x60 /* @brief Write KBC Command Byte */
24
#define KBC_SELF_TEST   0xAA /* @brief KBC Diagnostic Tests */
25
#define KBC_INT_TEST    0xAB /* @brief Tests Keyboard Clock and Data lines */
26
#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */
27
#define KBC_INT_ENABLE  0xAE /* @brief Enable KBC Interface */
28
#define MOUSE_DISABLE   0xA7 /* @brief Disable Mouse */
29
#define MOUSE_ENABLE    0xA8 /* @brief Enable Mouse */
30
#define MOUSE_INT_TEST  0xA9 /* @brief Tests Mouse data line */
31
#define MOUSE_WRITE_B   0xD4 /* @brief Write a byte directly to the mouse */
32

  
33
/* Status Byte Masking */
34

  
35
#define OUT_BUF_FUL     BIT(0) /* @brief Output Buffer State */
36
#define IN_BUF_FULL     BIT(1) /* @brief Input Buffer State */
37
#define SYS_FLAG        BIT(2) /* @brief System Flag */
38
#define DATA_CMD_WRITE  BIT(3) /* @brief Identifier of type of byte in input buffer */
39
#define INH_FLAG        BIT(4) /* @brief Keyboard inihibited */
40
#define AUX_MOUSE       BIT(5) /* @brief Mouse Data */
41
#define TIME_OUT_REC    BIT(6) /* @brief Time Out Error - Invalid Data */
42
#define PARITY_ERROR    BIT(7) /* @brief Parity Error - Invalid Data */
43

  
44
/* Scancode Constants */
45

  
46
#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
47
#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
48
#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
49

  
50
/* Command byte masks */
51
#define INT_KBD         BIT(0)  /* @brief Enable Keyboard Interrupts */
52
#define INT_MOU         BIT(1)  /* @brief Enable Mouse Interrupts */
53
#define DIS_KBD         BIT(4)  /* @brief Disable Keyboard */
54
#define DIS_MOU         BIT(5)  /* @brief Disable Mouse */
55

  
56
#endif //KBC_MACROS_H_INCLUDED
57 0

  
proj/mouse.h
1
#ifndef MOUSE_H_INCLUDED
2
#define MOUSE_H_INCLUDED
3

  
4
#include <stdint.h>
5

  
6
/**
7
 * @brief Subscribes Mouse Interrupts and disables Minix Default IH
8
 * @param interrupt_bit Bit of Interrupt Vector that will be set when Mouse Interrupt is pending
9
 * @param interrupt_id Mouse Interrupt ID to specify the Mouse Interrupt in other calls
10
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
11
 * @see {_ERRORS_H_::errors}
12
 */
13
int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
14

  
15
//These have to do with mouse_ih
16
int got_error_mouse_ih;
17
uint8_t packet_mouse_ih[3];
18
int counter_mouse_ih;
19

  
20
/**
21
 * @brief   Parse 3 bytes and returns it as a parsed, struct packet.
22
 * @param   packet_bytes    array of bytes to parse
23
 * @return  parsed struct packet
24
 */
25
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes);
26

  
27
/**
28
 * @brief Polls mouse for data. Blocks execution until a valid mouse packet is obtained.
29
 * @param   pp      pointer to packet struct in which the result will be stored
30
 * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
31
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
32
 */
33
int mouse_poll(struct packet *pp, uint16_t period);
34

  
35
/**
36
 * @brief Sets data report mode for mouse
37
 * @param   on  zero to disable data report, any other value to enable data report
38
 * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
39
 */
40
int (mouse_set_data_report)(int on);
41

  
42
/**
43
 * @brief Reads data byte from mouse
44
 * <summary>
45
 * Polls the mouse till data is available for reading
46
 * </summary>
47
 * @param data Pointer to variable where byte read from mouse will be stored
48
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
49
 * @see {_ERRORS_H_::errors}
50
 */
51
int (mouse_read_data)(uint8_t *data, uint16_t period);
52

  
53
/**
54
 * @brief Issues command to mouse
55
 * <summary>
56
 * Issues command to mouse, returns error after two consecutive errors reported by the acknowledgment byte
57
 * </summary>
58
 * @param cmd Command to be issued
59
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
60
 * @see {_ERRORS_H_::errors}
61
 */
62
int (mouse_issue_cmd)(uint32_t cmd);
63

  
64
/**
65
 * @brief Reads byte from mouse
66
 * <summary>
67
 * Reads byte from mouse, giving error if exceeds number of tries to read
68
 * </summary>
69
 * @param byte Pointer to variable where byte read from mouse will be stored
70
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
71
 * @see {_ERRORS_H_::errors}
72
 */
73
int (mouse_read_byte)(uint8_t *byte);
74

  
75
/**
76
 * @brief Polls OUT_BUF for byte coming from mouse.
77
 * @param   byte    pointer to byte read from OUT_BUF
78
 * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
79
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
80
 */
81
int (mouse_poll_byte)(uint8_t *byte, uint16_t period);
82

  
83
/**
84
 * @brief Converts 9-bit number to 16-bit with sign extension
85
 * @param sign_bit  Sign bit identifiying the signal of the number
86
 * @param byte      Least significant byte that will be extended
87
 * @return Extended 9-bit number
88
 */
89
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte);
90

  
91
#endif //MOUSE_H_INCLUDED
92 0

  
proj/kbc.h
1
/**
2
 * This file concerns everything related to the KBC (KeyBoard Controller, which
3
 * actually also manages the mouse)
4
 */
5

  
6
#ifndef KBC_H_INCLUDED
7
#define KBC_H_INCLUDED
8

  
9
/**
10
 * @brief High-level function that reads the command byte of the KBC
11
 * @param cmd Pointer to variable where command byte read from KBC will be stored
12
 * @return 0 if operation was successful, 1 otherwise
13
 */
14
int (kbc_read_cmd)(uint8_t *cmd);
15

  
16
/**
17
 * @brief High-level function that changes the command byte of the KBC
18
 * @param cmd New value for command byte of KBC
19
 * @return 0 if operation was successful, 1 otherwise
20
 */
21
int (kbc_change_cmd)(uint8_t cmd);
22

  
23
/**
24
 * @brief High-level function that restores KBC to normal state
25
 * High-level function that restores KBC to normal state, because lcf_start
26
 * changes the command byte of KBC. If this function is not used, there is a
27
 * chance that the keyboard and keyboard interrupts remain disabled.
28
 * @return 0 if operation was successful, 1 otherwise
29
 */
30
int (kbc_restore_keyboard)();
31

  
32
/**
33
 * @brief Low-level function to issue a command to keyboard
34
 * @param cmd command to be issued
35
 * @return 0 if operation was successful, 1 otherwise
36
 */
37
int (kbc_issue_cmd)(uint8_t cmd);
38

  
39
/**
40
 * @brief Low-level function to issue an argument of a command
41
 * @param cmd argument to be issued
42
 * @return 0 if operation was successful, 1 otherwise
43
 */
44
int (kbc_issue_arg)(uint8_t arg);
45

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

  
55
#endif //KBC_H_INCLUDED
56 0

  
proj/i8254.h
1
#ifndef _LCOM_I8254_H_
2
#define _LCOM_I8254_H_
3

  
4
#include <lcom/lcf.h>
5

  
6
/** @defgroup i8254 i8254
7
 *
8
 * Constants for programming the i8254 Timer. Needs to be completed.
9
 */
10

  
11
#define TIMER_FREQ     1193182                                                          /**< @brief clock frequency for timer in PC and AT */
12
#define TIMER_MIN_FREQ (TIMER_FREQ/UINT16_MAX) + ((TIMER_FREQ % UINT16_MAX) ? 1 : 0)    /**< @brief mininum frequency for timer */
13
#define TIMER0_IRQ     0                                                                /**< @brief Timer 0 IRQ line */
14

  
15
/* I/O port addresses */
16

  
17
#define TIMER_0    0x40         /**< @brief Timer 0 count register */
18
#define TIMER_1    0x41         /**< @brief Timer 1 count register */
19
#define TIMER_2    0x42         /**< @brief Timer 2 count register */
20
#define TIMER_CTRL 0x43         /**< @brief Control register */
21

  
22
#define SPEAKER_CTRL 0x61       /**< @brief Register for speaker control  */
23

  
24
/* Timer control */
25

  
26
/* Timer selection: bits 7 and 6 */
27

  
28
#define TIMER_SEL0   0x00              /**< @brief Control Word for Timer 0 */
29
#define TIMER_SEL1   BIT(6)            /**< @brief Control Word for Timer 1 */
30
#define TIMER_SEL2   BIT(7)            /**< @brief Control Word for Timer 2 */
31
#define TIMER_RB_CMD (BIT(7) | BIT(6)) /**< @brief Read Back Command */
32

  
33
/* Register selection: bits 5 and 4 */
34

  
35
#define TIMER_LSB     BIT(4)                    /**< @brief Initialize Counter LSB only */
36
#define TIMER_MSB     BIT(5)                    /**< @brief Initialize Counter MSB only */
37
#define TIMER_LSB_MSB (TIMER_LSB | TIMER_MSB)   /**< @brief Initialize LSB first and MSB afterwards */
38
#define TIMER_INMODE_MASK 0x30                  /**< @brief Mask for Timer Counter Mode */
39
#define TIMER_INMODE_POS  4                     /**< @brief Bit position of Timer Counter Mode */
40

  
41
/* Operating mode: bits 3, 2 and 1 */
42

  
43
#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
44
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
45
#define TIMER_MODE_MASK 0x0E             /**< @brief Mask for mode */
46
#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
47
#define TIMER_MODE_2ALT 0x6              /**< @brief Alternative notation for mode 2 */
48
#define TIMER_MODE_3ALT 0x7              /**< @brief Alternative notation for mode 3 */
49
#define TIMER_MODE_RED2 0x03             /**< @brief Reduce 3-bit mode to 2-bit mode */
50

  
51
/* Counting mode: bit 0 */
52

  
53
#define TIMER_BCD 0x01 /**< @brief Count in BCD */
54
#define TIMER_BIN 0x00 /**< @brief Count in binary */
55

  
56
/* READ-BACK COMMAND FORMAT */
57

  
58
#define TIMER_RB_COUNT_  BIT(5)         /**< @brief Read counter value on read-back (0 to activate) */
59
#define TIMER_RB_STATUS_ BIT(4)         /**< @brief Read status value on read-back (0 to activate) */
60
#define TIMER_RB_SEL(n)  BIT((n) + 1)   /**< @brief Select timer to read information from */
61

  
62
/**@}*/
63

  
64
#endif /* _LCOM_I8254_H */
65 0

  
proj/utils.h
1
#ifndef UTILS_H_INCLUDED
2
#define UTILS_H_INCLUDED
3

  
4
/**
5
 * @brief Gets the least significant byte of a 16-bit variable
6
 * @param val 16-bit variable
7
 * @param lsb Pointer to a 8-bit variable to store the value of the LSB
8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
9
 */
10
int(util_get_LSB)(uint16_t val, uint8_t *lsb);
11

  
12
/**
13
 * @brief Gets the most significant byte of a 16-bit variable
14
 * @param val 16-bit variable
15
 * @param lsb Pointer to a 8-bit variable to store the value of the MSB
16
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
17
 */
18
int(util_get_MSB)(uint16_t val, uint8_t *msb);
19

  
20
/**
21
 * @brief sys_inb wrapper
22
 * @param port Port to read from
23
 * @param value Pointer to byte to store value read
24
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
25
 */
26
int (util_sys_inb)(int port, uint8_t *value);
27

  
28
/**
29
 * @brief Unsubcribes Interrupts
30
 * @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
31
 * @see subscribe_kbc_interrupt, subscribe_timer_interrupt
32
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
33
 */
34
int (unsubscribe_interrupt)(int *interrupt_id);
35

  
36
/**
37
 * @brief Gets the minimum value out of two values.
38
 * @param a     First value
39
 * @param b     Second value
40
 * @return  The minimum of the two values
41
 */
42
int32_t min(int32_t a, int32_t b);
43

  
44
/**
45
 * @brief Gets the maximum value out of two values.
46
 * @param a     First value
47
 * @param b     Second value
48
 * @return  The maximum of the two values
49
 */
50
int32_t max(int32_t a, int32_t b);
51

  
52

  
53
#endif //UTILS_H_INCLUDED
54 0

  
proj/keyboard.h
1
/**
2
 * This file concerns everything related to the keyboard
3
 */
4

  
5
#ifndef KEYBOARD_H_INCLUDED
6
#define KEYBOARD_H_INCLUDED
7

  
8
/**
9
 * @brief Subscribes Keyboard Interrupts and disables Minix Default IH
10
 * @param interrupt_bit Bit of Interrupt Vector that will be set when Keyboard Interrupt is pending
11
 * @param interrupt_id Keyboard Interrupt ID to specify the Keyboard Interrupt in other calls
12
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
13
 * @see {_ERRORS_H_::errors}
14
 */
15
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
16

  
17
uint8_t scancode[2];
18
int done;
19
int sz;
20
int got_error_keyboard;
21

  
22
void (kbc_ih)(void);
23

  
24
int (keyboard_poll)(uint8_t bytes[], uint8_t *size);
25

  
26
#endif //KEYBOARD_H_INCLUDED
27 0

  
proj/graph_macros.h
1
#ifndef GRAPHICS_MACROS_H_INCLUDED
2
#define GRAPHICS_MACROS_H_INCLUDED
3

  
4
#define VC_BIOS_SERV  0x10 /** @brief Interrupt service of video card */
5
#define VBE_CALL      0x4F /** @brief VBE call function specifier */
6

  
7
#define MBYTE_BASE  0x0         /** @brief Base address (zero address) */
8
#define MBYTE_SIZE  0xFFFFF     /** @brief Size of a mebibyte */
9

  
10
// Graphics Functions
11
#define VBE_CTRL_INFO       0x00    /** @brief Get VBE Controller Information */
12
#define VBE_MD_INFO         0x01    /** @brief Get VBE Mode Information */
13
#define SET_VBE_MD          0x02    /** @brief Set VBE Mode */
14

  
15
// Error codes (AH)
16
#define AH_SUCCESS          0x00    /** @brief Success code on BIOS call */
17
#define AH_FUNC_CALL_FAIL   0x01    /** @brief Function call failed */
18
#define AH_FUNC_NOT_SUPP    0x02    /** @brief Function call is not supported in current HW configuration */
19
#define AH_FUNC_INVALID     0x03    /** @brief Invalid function in current video mode */
20

  
21
// Graphics modes
22
#define INDEXED_1024_768        0x105
23
#define DIRECT_640_480          0x110
24
#define DIRECT_800_600          0x115
25
#define DIRECT_1280_1024_565    0x11A
26
#define DIRECT_1280_1024_888    0x11B
27
#define LINEAR_FRAME_BUFFER_MD  BIT(14)
28

  
29
// Colors in RBG (8 bit)
30
#define BLACK               0x000000
31

  
32
#endif /* end of include guard: GRAPHICS_MACROS_H_INCLUDED */
33 0

  
proj/errors.h
1
#ifndef ERRORS_H_INCLUDED
2
#define ERRORS_H_INCLUDED
3

  
4
/** @brief Error Codes */
5
enum errors {
6
    SUCCESS = 0,        /* @brief Sucessful */
7
    NULL_PTR,           /* @brief Null Pointer Error */
8
    LCF_ERROR,          /* @brief Error originated on LCF */
9
    SBCR_ERROR,         /* @brief Error on Subscribing Interrupt */
10
    UNSBCR_ERROR,       /* @brief Error on Unsubscring Interrupt*/
11
    READ_ERROR,         /* @brief Error on Reading from Port */
12
    WRITE_ERROR,        /* @brief Error on Writing to Port */
13
    TIMEOUT_ERROR,      /* @brief Timeout error */
14
    INVALID_COMMAND,    /* @brief Invalid Command issued */
15
    INVALID_STATE,      /* @brief State machine reached an invalid state */
16
    BIOS_CALL_ERROR,    /* @brief Error upon BIOS call */
17
    OUT_OF_RANGE,       /* @brief Accessing area out of range of memory */
18
    OTHER_ERROR         /* @brief Unspecified error */
19
};
20

  
21
#endif //ERRORS_H_INCLUDED
22 0

  
proj/proj_macros.h
1
#ifndef PROJ_MACROS_H_INCLUDED
2
#define PROJ_MACROS_H_INCLUDED
3

  
4
// WASD Movement Keys
5
#define W_MAKE_CODE     0x11    /** @brief W Make Code */
6
#define W_BREAK_CODE    0x91    /** @brief W Break Code */
7
#define A_MAKE_CODE     0x1E    /** @brief A Make Code */
8
#define A_BREAK_CODE    0x9E    /** @brief A Break Code */
9
#define S_MAKE_CODE     0x1F    /** @brief S Make Code */
10
#define S_BREAK_CODE    0x9F    /** @brief S Break Code */
11
#define D_MAKE_CODE     0x20    /** @brief D Make Code */
12
#define D_BREAK_CODE    0xA0    /** @brief D Break Code */
13

  
14
// Movement Directions
15
#define UP      -1  /** @brief Moving to the top side of screen */
16
#define DOWN    1   /** @brief Moving to the bottom side of screen */
17
#define LEFT    -1  /** @brief Moving to the left side of screen */
18
#define RIGHT   1   /** @brief Moving to the right side of screen */
19
#define REST    0   /** @brief Not moving */
20

  
21
// Extra Keys
22
#define ESC_MAKE_CODE   0x01    /** @brief ESC Make Code */
23
#define ESC_BREAK_CODE  0x81    /** @brief ESC Break Code */
24

  
25
// Refresh Rate
26
#define REFRESH_RATE    60      /** @brief Screen refresh rate */
27

  
28
//Graphics mode
29
#define GRAPH_MODE      DIRECT_1280_1024_888 /** @brief Graphic mode used */
30

  
31
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */
32 0

  
proj/fast_math.h
1
#ifndef FAST_MATH_H_INCLUDED
2
#define FAST_MATH_H_INCLUDED
3

  
4
double fm_sin(double x);
5
double fm_cos(double x);
6

  
7
#endif //FAST_MATH_H_INCLUDED
8 0

  
proj/timer.h
1
/**
2
 * This file concerns everything related to the timer
3
 */
4

  
5
#ifndef TIMER_H_INCLUDED
6
#define TIMER_H_INCLUDED
7

  
8
#include <stdint.h>
9

  
10
int (subscribe_timer_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
11

  
12
uint32_t no_interrupts;
13

  
14
#endif //TIMER_H_INCLUDED
15 0

  
proj/mouse_macros.h
1
#ifndef MOUSE_MACROS_H_INCLUDED
2
#define MOUSE_MACROS_H_INCLUDED
3

  
4
/* Mouse Data Packet */
5
// Byte 0 - Button States
6
#define LEFT_BUTTON     BIT(0) /* @brief Left button click event*/
7
#define RIGHT_BUTTON    BIT(1) /* @brief Right button click event */
8
#define MIDDLE_BUTTON   BIT(2) /* @brief Middle button click event */
9
#define FIRST_BYTE_ID   BIT(3) /* @brief Identifier of first byte of packet CAREFUL: Not 100% accurate */
10
#define MSB_X_DELTA     BIT(4) /* @brief Most significant bit of X delta */
11
#define MSB_Y_DELTA     BIT(5) /* @brief Most significant bit of Y delta */
12
#define X_OVERFLOW      BIT(6) /* @brief X delta overflowed */
13
#define Y_OVERFLOW      BIT(7) /* @brief Y delta overflowed */
14
// Byte 1 - X delta
15
// Byte 2 - Y delta
16

  
17
/* Mouse Commands */
18
#define RESET           0xFF /* @brief Reset mouse */
19
#define RESEND          0xFE /* @brief Resend command */
20
#define DEFAULT         0xF6 /* @brief Set default values */
21
#define DIS_DATA_REP    0xF5 /* @brief Disable Data Reporting */
22
#define ENABLE_DATA_REP 0xF4 /* @brief Enable Data Reporting */
23
#define SET_SAMPLE_RT   0xF3 /* @brief Sets state sampling rate */
24
#define SET_REMOTE_MD   0xF0 /* @brief Sets Mouse on Remote Mode, data on request */
25
#define READ_DATA       0xEB /* @brief Sends data packet request */
26
#define SET_STREAM_MD   0xEA /* @brief Sets mouse on Stream Mode, data on events */
27
#define STATUS_REQUEST  0xE9 /* @brief Get mouse configuration */
28
#define SET_RESOLUTION  0xE8 /* @brief Sets resolution for mouse movement */
29
#define SCALING_ACC_MD  0xE7 /* @brief Sets scaling on acceleration mode */
30
#define SCALING_LIN_MD  0xE6 /* @brief Sets scaling on linear mode */
31

  
32
/* Mouse Controller Responses */
33
#define ACK_OK      0xFA /* @brief Operation sucessful */
34
#define ACK_INVALID 0xFE /* @brief Invalid Byte, first occurence */
35
#define ACK_ERROR   0xFC /* @brief Invalid Byte on resend */
36

  
37
#endif // MOUSE_MACROS_H_INCLUDED
38 0

  
proj/graph.h
1
#ifndef GRAPH_H_INCLUDED
2
#define GRAPH_H_INCLUDED
3

  
4
#include <lcom/lcf.h>
5
#include <stdint.h>
6

  
7
/// MACROS
8
//#define GET_ALP(n)          (0xFF & ((n) >> 24))
9
#define GET_RED(n)          (0xFF & ((n) >> 16))
10
#define GET_GRE(n)          (0xFF & ((n) >>  8))
11
#define GET_BLU(n)          (0xFF & (n      ))
12
//#define SET_ALP(n)          (((n)&0xFF) << 24)
13
#define SET_RED(n)          (((n)&0xFF) << 16)
14
#define SET_GRE(n)          (((n)&0xFF) <<  8)
15
#define SET_BLU(n)          (((n)&0xFF)      )
16
#define SET_RGB(r,g,b)      (SET_RED(r) | SET_GRE(g) | SET_BLU(b))
17

  
18
/// PUBLIC GET
19
uint16_t   (graph_get_XRes)         (void);
20
uint16_t   (graph_get_YRes)         (void);
21

  
22
/// INIT
23
int (graph_init)(uint16_t mode);
24

  
25
/// CLEANUP
26
int (graph_cleanup)(void);
27

  
28
/// PIXEL DRAWING
29
int (graph_set_pixel)      (uint16_t x, uint16_t y, uint32_t color);
30
int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
31

  
32
/// SCREEN
33
int (graph_clear_screen)(void);
34

  
35
/// DRAW
36
int (graph_draw)(void);
37

  
38

  
39

  
40
/// RECTANGLE
41

  
42

  
43
int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color);
44
int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color);
45

  
46
#endif /* end of include guard: GRAPH_H_INCLUDED */
47 0

  
proj/sprite.h
1
#ifndef SPRITE_H_INCLUDED
2
#define SPRITE_H_INCLUDED
3

  
4
struct sprite;
5
typedef struct sprite sprite_t;
6

  
7
sprite_t* (sprite_ctor)(const char **xpm, int u0, int v0);
8
void      (sprite_dtor)(sprite_t *p);
9

  
10
void (sprite_set_x)     (sprite_t *p, int16_t x);
11
void (sprite_set_y)     (sprite_t *p, int16_t y);
12
void (sprite_set_pos)   (sprite_t *p, int16_t x, int16_t y);
13
void (sprite_set_angle) (sprite_t *p, double angle);
14
void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0);
15

  
16
int sprite_get_x(const sprite_t *p);
17
int sprite_get_y(const sprite_t *p);
18
int sprite_get_w(const sprite_t *p);
19
int sprite_get_h(const sprite_t *p);
20

  
21
void (sprite_draw)(const sprite_t *p);
22

  
23
#endif //SPRITE_H_INCLUDED
24 0

  
proj/proj_func.h
1
#ifndef PROJ_FUNC_H_INCLUDED
2
#define PROJ_FUNC_H_INCLUDED
3

  
4
#include "sprite.h"
5

  
6
/**
7
 * @brief Cleans up all memory, unsubscribes interrupts.
8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
9
 * @see {_ERRORS_H_::errors}
10
 */
11
int cleanup(void);
12

  
13
/**
14
 * @brief Updates movement variables.
15
 */
16
void update_movement(void);
17

  
18
void update_mouse_position(struct packet *p);
19

  
20
int32_t get_mouse_X(void);
21

  
22
int32_t get_mouse_Y(void);
23

  
24
/**
25
 * @brief
26
 * @param
27
 * @param
28
 * @param
29
 * @return Angle
30
 */
31
double get_mouse_angle(sprite_t *p);
32

  
33
/**
34
 * @brief Get horizontal movement direction.
35
 * @return Horizontal movement direction (-1 -> heading LEFT; 0 -> not moving horizontally; 1 -> heading RIGHT)
36
 */
37
int get_hor_movement(void);
38

  
39
/**
40
 * @brief Get vertical movement direction.
41
 * @return Vertical movement direction (-1 -> heading UP; 0 -> not moving vertically; 1 -> heading DOWN)
42
 */
43
int get_ver_movement(void);
44

  
45
#endif /* end of include guard: PROJ_FUNC_H_INCLUDED */
46 0

  
proj/include/errors.h
1
#ifndef ERRORS_H_INCLUDED
2
#define ERRORS_H_INCLUDED
3

  
4
/** @brief Error Codes */
5
enum errors {
6
    SUCCESS = 0,        /* @brief Sucessful */
7
    NULL_PTR,           /* @brief Null Pointer Error */
8
    LCF_ERROR,          /* @brief Error originated on LCF */
9
    SBCR_ERROR,         /* @brief Error on Subscribing Interrupt */
10
    UNSBCR_ERROR,       /* @brief Error on Unsubscring Interrupt*/
11
    READ_ERROR,         /* @brief Error on Reading from Port */
12
    WRITE_ERROR,        /* @brief Error on Writing to Port */
13
    TIMEOUT_ERROR,      /* @brief Timeout error */
14
    INVALID_COMMAND,    /* @brief Invalid Command issued */
15
    INVALID_STATE,      /* @brief State machine reached an invalid state */
16
    BIOS_CALL_ERROR,    /* @brief Error upon BIOS call */
17
    OUT_OF_RANGE,       /* @brief Accessing area out of range of memory */
18
    OTHER_ERROR         /* @brief Unspecified error */
19
};
20

  
21
#endif //ERRORS_H_INCLUDED
0 22

  
proj/include/fast_math.h
1
#ifndef FAST_MATH_H_INCLUDED
2
#define FAST_MATH_H_INCLUDED
3

  
4
double fm_sin(double x);
5
double fm_cos(double x);
6

  
7
#endif //FAST_MATH_H_INCLUDED
0 8

  
proj/include/graph.h
1
#ifndef GRAPH_H_INCLUDED
2
#define GRAPH_H_INCLUDED
3

  
4
#include <lcom/lcf.h>
5
#include <stdint.h>
6

  
7
/// MACROS
8
//#define GET_ALP(n)          (0xFF & ((n) >> 24))
9
#define GET_RED(n)          (0xFF & ((n) >> 16))
10
#define GET_GRE(n)          (0xFF & ((n) >>  8))
11
#define GET_BLU(n)          (0xFF & (n      ))
12
//#define SET_ALP(n)          (((n)&0xFF) << 24)
13
#define SET_RED(n)          (((n)&0xFF) << 16)
14
#define SET_GRE(n)          (((n)&0xFF) <<  8)
15
#define SET_BLU(n)          (((n)&0xFF)      )
16
#define SET_RGB(r,g,b)      (SET_RED(r) | SET_GRE(g) | SET_BLU(b))
17

  
18
/// PUBLIC GET
19
uint16_t   (graph_get_XRes)         (void);
20
uint16_t   (graph_get_YRes)         (void);
21

  
22
/// INIT
23
int (graph_init)(uint16_t mode);
24

  
25
/// CLEANUP
26
int (graph_cleanup)(void);
27

  
28
/// PIXEL DRAWING
29
int (graph_set_pixel)      (uint16_t x, uint16_t y, uint32_t color);
30
int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
31

  
32
/// SCREEN
33
int (graph_clear_screen)(void);
34

  
35
/// DRAW
36
int (graph_draw)(void);
37

  
38

  
39

  
40
/// RECTANGLE
41

  
42

  
43
int (graph_draw_hline)(uint16_t x, uint16_t y, uint16_t len, uint32_t color);
44
int (graph_draw_rectangle)(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color);
45

  
46
#endif /* end of include guard: GRAPH_H_INCLUDED */
0 47

  
proj/include/graph_macros.h
1
#ifndef GRAPHICS_MACROS_H_INCLUDED
2
#define GRAPHICS_MACROS_H_INCLUDED
3

  
4
#define VC_BIOS_SERV  0x10 /** @brief Interrupt service of video card */
5
#define VBE_CALL      0x4F /** @brief VBE call function specifier */
6

  
7
#define MBYTE_BASE  0x0         /** @brief Base address (zero address) */
8
#define MBYTE_SIZE  0xFFFFF     /** @brief Size of a mebibyte */
9

  
10
// Graphics Functions
11
#define VBE_CTRL_INFO       0x00    /** @brief Get VBE Controller Information */
12
#define VBE_MD_INFO         0x01    /** @brief Get VBE Mode Information */
13
#define SET_VBE_MD          0x02    /** @brief Set VBE Mode */
14

  
15
// Error codes (AH)
16
#define AH_SUCCESS          0x00    /** @brief Success code on BIOS call */
17
#define AH_FUNC_CALL_FAIL   0x01    /** @brief Function call failed */
18
#define AH_FUNC_NOT_SUPP    0x02    /** @brief Function call is not supported in current HW configuration */
19
#define AH_FUNC_INVALID     0x03    /** @brief Invalid function in current video mode */
20

  
21
// Graphics modes
22
#define INDEXED_1024_768        0x105
23
#define DIRECT_640_480          0x110
24
#define DIRECT_800_600          0x115
25
#define DIRECT_1280_1024_565    0x11A
26
#define DIRECT_1280_1024_888    0x11B
27
#define LINEAR_FRAME_BUFFER_MD  BIT(14)
28

  
29
// Colors in RBG (8 bit)
30
#define BLACK               0x000000
31

  
32
#endif /* end of include guard: GRAPHICS_MACROS_H_INCLUDED */
0 33

  
proj/include/i8254.h
1
#ifndef _LCOM_I8254_H_
2
#define _LCOM_I8254_H_
3

  
4
#include <lcom/lcf.h>
5

  
6
/** @defgroup i8254 i8254
7
 *
8
 * Constants for programming the i8254 Timer. Needs to be completed.
9
 */
10

  
11
#define TIMER_FREQ     1193182                                                          /**< @brief clock frequency for timer in PC and AT */
12
#define TIMER_MIN_FREQ (TIMER_FREQ/UINT16_MAX) + ((TIMER_FREQ % UINT16_MAX) ? 1 : 0)    /**< @brief mininum frequency for timer */
13
#define TIMER0_IRQ     0                                                                /**< @brief Timer 0 IRQ line */
14

  
15
/* I/O port addresses */
16

  
17
#define TIMER_0    0x40         /**< @brief Timer 0 count register */
18
#define TIMER_1    0x41         /**< @brief Timer 1 count register */
19
#define TIMER_2    0x42         /**< @brief Timer 2 count register */
20
#define TIMER_CTRL 0x43         /**< @brief Control register */
21

  
22
#define SPEAKER_CTRL 0x61       /**< @brief Register for speaker control  */
23

  
24
/* Timer control */
25

  
26
/* Timer selection: bits 7 and 6 */
27

  
28
#define TIMER_SEL0   0x00              /**< @brief Control Word for Timer 0 */
29
#define TIMER_SEL1   BIT(6)            /**< @brief Control Word for Timer 1 */
30
#define TIMER_SEL2   BIT(7)            /**< @brief Control Word for Timer 2 */
31
#define TIMER_RB_CMD (BIT(7) | BIT(6)) /**< @brief Read Back Command */
32

  
33
/* Register selection: bits 5 and 4 */
34

  
35
#define TIMER_LSB     BIT(4)                    /**< @brief Initialize Counter LSB only */
36
#define TIMER_MSB     BIT(5)                    /**< @brief Initialize Counter MSB only */
37
#define TIMER_LSB_MSB (TIMER_LSB | TIMER_MSB)   /**< @brief Initialize LSB first and MSB afterwards */
38
#define TIMER_INMODE_MASK 0x30                  /**< @brief Mask for Timer Counter Mode */
39
#define TIMER_INMODE_POS  4                     /**< @brief Bit position of Timer Counter Mode */
40

  
41
/* Operating mode: bits 3, 2 and 1 */
42

  
43
#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
44
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
45
#define TIMER_MODE_MASK 0x0E             /**< @brief Mask for mode */
46
#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
47
#define TIMER_MODE_2ALT 0x6              /**< @brief Alternative notation for mode 2 */
48
#define TIMER_MODE_3ALT 0x7              /**< @brief Alternative notation for mode 3 */
49
#define TIMER_MODE_RED2 0x03             /**< @brief Reduce 3-bit mode to 2-bit mode */
50

  
51
/* Counting mode: bit 0 */
52

  
53
#define TIMER_BCD 0x01 /**< @brief Count in BCD */
54
#define TIMER_BIN 0x00 /**< @brief Count in binary */
55

  
56
/* READ-BACK COMMAND FORMAT */
57

  
58
#define TIMER_RB_COUNT_  BIT(5)         /**< @brief Read counter value on read-back (0 to activate) */
59
#define TIMER_RB_STATUS_ BIT(4)         /**< @brief Read status value on read-back (0 to activate) */
60
#define TIMER_RB_SEL(n)  BIT((n) + 1)   /**< @brief Select timer to read information from */
61

  
62
/**@}*/
63

  
64
#endif /* _LCOM_I8254_H */
0 65

  
proj/include/interrupts_func.h
1
#ifndef INTERRUPTS_FUNC_H_INCLUDED
2
#define INTERRUPTS_FUNC_H_INCLUDED
3

  
4
#include <stdint.h>
5

  
6
/**
7
 * @brief Subscribes all drivers used (timer->keyboard->mouse)
8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
9
 * @see {_ERRORS_H_::errors}
10
 */
11
int (subscribe_all)(void);
12

  
13
/**
14
 * @brief Unsubscribes all subscribed interrupts
15
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
16
 * @see {_ERRORS_H_::errors}
17
 */
18
int (unsubscribe_all)(void);
19

  
20
/**
21
 * @brief Calls interrupt handler corresponding to the bit specified by the argument.
22
 * @param handler Interrupt handler to call
23
 */
24
void interrupt_handler(uint8_t handler);
25

  
26
#endif /* end of include guard: INTERRUPTS_FUNC_H_INCLUDED */
0 27

  
proj/include/kbc.h
1
/**
2
 * This file concerns everything related to the KBC (KeyBoard Controller, which
3
 * actually also manages the mouse)
4
 */
5

  
6
#ifndef KBC_H_INCLUDED
7
#define KBC_H_INCLUDED
8

  
9
/**
10
 * @brief High-level function that reads the command byte of the KBC
11
 * @param cmd Pointer to variable where command byte read from KBC will be stored
12
 * @return 0 if operation was successful, 1 otherwise
13
 */
14
int (kbc_read_cmd)(uint8_t *cmd);
15

  
16
/**
17
 * @brief High-level function that changes the command byte of the KBC
18
 * @param cmd New value for command byte of KBC
19
 * @return 0 if operation was successful, 1 otherwise
20
 */
21
int (kbc_change_cmd)(uint8_t cmd);
22

  
23
/**
24
 * @brief High-level function that restores KBC to normal state
25
 * High-level function that restores KBC to normal state, because lcf_start
26
 * changes the command byte of KBC. If this function is not used, there is a
27
 * chance that the keyboard and keyboard interrupts remain disabled.
28
 * @return 0 if operation was successful, 1 otherwise
29
 */
30
int (kbc_restore_keyboard)();
31

  
32
/**
33
 * @brief Low-level function to issue a command to keyboard
34
 * @param cmd command to be issued
35
 * @return 0 if operation was successful, 1 otherwise
36
 */
37
int (kbc_issue_cmd)(uint8_t cmd);
38

  
39
/**
40
 * @brief Low-level function to issue an argument of a command
41
 * @param cmd argument to be issued
42
 * @return 0 if operation was successful, 1 otherwise
43
 */
44
int (kbc_issue_arg)(uint8_t arg);
45

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

  
55
#endif //KBC_H_INCLUDED
0 56

  
proj/include/kbc_macros.h
1
#ifndef KBC_MACROS_H_INCLUDED
2
#define KBC_MACROS_H_INCLUDED
3

  
4
/* KBC IRQ Line */
5

  
6
#define KBC_IRQ     1   /* @brief KBC Controller IRQ Line */
7
#define MOUSE_IRQ   12  /* @brief Mouse IRQ Line */
8

  
9
/* Delay for KBC */
10
#define DELAY           20000 /* @brief KBC Response Delay */
11
#define KBC_NUM_TRIES   20    /* @brief Number of tries to issue command before timeout */
12

  
13
/* I/O Ports Addresses */
14

  
15
#define KBC_CMD     0x64 /* @brief Address to send commands to KBC */
16
#define KBC_CMD_ARG 0x60 /* @brief Address to write KBC Command Arguments */
17
#define STATUS_REG  0x64 /* @brief KBC Status Register address */
18

  
19
#define OUTPUT_BUF  0x60 /* @brief Address of Output Buffer of KBC */
20

  
21
/* KBC Commands */
22
#define READ_KBC_CMD    0x20 /* @brief Read KBC Command Byte */
23
#define WRITE_KBC_CMD   0x60 /* @brief Write KBC Command Byte */
24
#define KBC_SELF_TEST   0xAA /* @brief KBC Diagnostic Tests */
25
#define KBC_INT_TEST    0xAB /* @brief Tests Keyboard Clock and Data lines */
26
#define KBC_INT_DISABLE 0xAD /* @brief Disable KBC Interface */
27
#define KBC_INT_ENABLE  0xAE /* @brief Enable KBC Interface */
28
#define MOUSE_DISABLE   0xA7 /* @brief Disable Mouse */
29
#define MOUSE_ENABLE    0xA8 /* @brief Enable Mouse */
30
#define MOUSE_INT_TEST  0xA9 /* @brief Tests Mouse data line */
31
#define MOUSE_WRITE_B   0xD4 /* @brief Write a byte directly to the mouse */
32

  
33
/* Status Byte Masking */
34

  
35
#define OUT_BUF_FUL     BIT(0) /* @brief Output Buffer State */
36
#define IN_BUF_FULL     BIT(1) /* @brief Input Buffer State */
37
#define SYS_FLAG        BIT(2) /* @brief System Flag */
38
#define DATA_CMD_WRITE  BIT(3) /* @brief Identifier of type of byte in input buffer */
39
#define INH_FLAG        BIT(4) /* @brief Keyboard inihibited */
40
#define AUX_MOUSE       BIT(5) /* @brief Mouse Data */
41
#define TIME_OUT_REC    BIT(6) /* @brief Time Out Error - Invalid Data */
42
#define PARITY_ERROR    BIT(7) /* @brief Parity Error - Invalid Data */
43

  
44
/* Scancode Constants */
45

  
46
#define ESC_BREAK_CODE  0x81    /* @brief ESC Break Code */
47
#define TWO_BYTE_CODE   0xE0    /* @brief First byte of a two byte Scancode */
48
#define BREAK_CODE_BIT  BIT(7)  /* @brief Bit to distinguish between Make code and Break code */
49

  
50
/* Command byte masks */
51
#define INT_KBD         BIT(0)  /* @brief Enable Keyboard Interrupts */
52
#define INT_MOU         BIT(1)  /* @brief Enable Mouse Interrupts */
53
#define DIS_KBD         BIT(4)  /* @brief Disable Keyboard */
54
#define DIS_MOU         BIT(5)  /* @brief Disable Mouse */
55

  
56
#endif //KBC_MACROS_H_INCLUDED
0 57

  
proj/include/keyboard.h
1
/**
2
 * This file concerns everything related to the keyboard
3
 */
4

  
5
#ifndef KEYBOARD_H_INCLUDED
6
#define KEYBOARD_H_INCLUDED
7

  
8
/**
9
 * @brief Subscribes Keyboard Interrupts and disables Minix Default IH
10
 * @param interrupt_bit Bit of Interrupt Vector that will be set when Keyboard Interrupt is pending
11
 * @param interrupt_id Keyboard Interrupt ID to specify the Keyboard Interrupt in other calls
12
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
13
 * @see {_ERRORS_H_::errors}
14
 */
15
int (subscribe_kbc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
16

  
17
uint8_t scancode[2];
18
int done;
19
int sz;
20
int got_error_keyboard;
21

  
22
void (kbc_ih)(void);
23

  
24
int (keyboard_poll)(uint8_t bytes[], uint8_t *size);
25

  
26
#endif //KEYBOARD_H_INCLUDED
0 27

  
proj/include/mouse.h
1
#ifndef MOUSE_H_INCLUDED
2
#define MOUSE_H_INCLUDED
3

  
4
#include <stdint.h>
5

  
6
/**
7
 * @brief Subscribes Mouse Interrupts and disables Minix Default IH
8
 * @param interrupt_bit Bit of Interrupt Vector that will be set when Mouse Interrupt is pending
9
 * @param interrupt_id Mouse Interrupt ID to specify the Mouse Interrupt in other calls
10
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
11
 * @see {_ERRORS_H_::errors}
12
 */
13
int (subscribe_mouse_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
14

  
15
//These have to do with mouse_ih
16
int got_error_mouse_ih;
17
uint8_t packet_mouse_ih[3];
18
int counter_mouse_ih;
19

  
20
/**
21
 * @brief   Parse 3 bytes and returns it as a parsed, struct packet.
22
 * @param   packet_bytes    array of bytes to parse
23
 * @return  parsed struct packet
24
 */
25
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes);
26

  
27
/**
28
 * @brief Polls mouse for data. Blocks execution until a valid mouse packet is obtained.
29
 * @param   pp      pointer to packet struct in which the result will be stored
30
 * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
31
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
32
 */
33
int mouse_poll(struct packet *pp, uint16_t period);
34

  
35
/**
36
 * @brief Sets data report mode for mouse
37
 * @param   on  zero to disable data report, any other value to enable data report
38
 * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
39
 */
40
int (mouse_set_data_report)(int on);
41

  
42
/**
43
 * @brief Reads data byte from mouse
44
 * <summary>
45
 * Polls the mouse till data is available for reading
46
 * </summary>
47
 * @param data Pointer to variable where byte read from mouse will be stored
48
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
49
 * @see {_ERRORS_H_::errors}
50
 */
51
int (mouse_read_data)(uint8_t *data, uint16_t period);
52

  
53
/**
54
 * @brief Issues command to mouse
55
 * <summary>
56
 * Issues command to mouse, returns error after two consecutive errors reported by the acknowledgment byte
57
 * </summary>
58
 * @param cmd Command to be issued
59
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
60
 * @see {_ERRORS_H_::errors}
61
 */
62
int (mouse_issue_cmd)(uint32_t cmd);
63

  
64
/**
65
 * @brief Reads byte from mouse
66
 * <summary>
67
 * Reads byte from mouse, giving error if exceeds number of tries to read
68
 * </summary>
69
 * @param byte Pointer to variable where byte read from mouse will be stored
70
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
71
 * @see {_ERRORS_H_::errors}
72
 */
73
int (mouse_read_byte)(uint8_t *byte);
74

  
75
/**
76
 * @brief Polls OUT_BUF for byte coming from mouse.
77
 * @param   byte    pointer to byte read from OUT_BUF
78
 * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
79
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
80
 */
81
int (mouse_poll_byte)(uint8_t *byte, uint16_t period);
82

  
83
/**
84
 * @brief Converts 9-bit number to 16-bit with sign extension
85
 * @param sign_bit  Sign bit identifiying the signal of the number
86
 * @param byte      Least significant byte that will be extended
87
 * @return Extended 9-bit number
88
 */
89
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte);
90

  
91
#endif //MOUSE_H_INCLUDED
0 92

  
proj/include/mouse_macros.h
1
#ifndef MOUSE_MACROS_H_INCLUDED
2
#define MOUSE_MACROS_H_INCLUDED
3

  
4
/* Mouse Data Packet */
5
// Byte 0 - Button States
6
#define LEFT_BUTTON     BIT(0) /* @brief Left button click event*/
7
#define RIGHT_BUTTON    BIT(1) /* @brief Right button click event */
8
#define MIDDLE_BUTTON   BIT(2) /* @brief Middle button click event */
9
#define FIRST_BYTE_ID   BIT(3) /* @brief Identifier of first byte of packet CAREFUL: Not 100% accurate */
10
#define MSB_X_DELTA     BIT(4) /* @brief Most significant bit of X delta */
11
#define MSB_Y_DELTA     BIT(5) /* @brief Most significant bit of Y delta */
12
#define X_OVERFLOW      BIT(6) /* @brief X delta overflowed */
13
#define Y_OVERFLOW      BIT(7) /* @brief Y delta overflowed */
14
// Byte 1 - X delta
15
// Byte 2 - Y delta
16

  
17
/* Mouse Commands */
18
#define RESET           0xFF /* @brief Reset mouse */
19
#define RESEND          0xFE /* @brief Resend command */
20
#define DEFAULT         0xF6 /* @brief Set default values */
21
#define DIS_DATA_REP    0xF5 /* @brief Disable Data Reporting */
22
#define ENABLE_DATA_REP 0xF4 /* @brief Enable Data Reporting */
23
#define SET_SAMPLE_RT   0xF3 /* @brief Sets state sampling rate */
24
#define SET_REMOTE_MD   0xF0 /* @brief Sets Mouse on Remote Mode, data on request */
25
#define READ_DATA       0xEB /* @brief Sends data packet request */
26
#define SET_STREAM_MD   0xEA /* @brief Sets mouse on Stream Mode, data on events */
27
#define STATUS_REQUEST  0xE9 /* @brief Get mouse configuration */
28
#define SET_RESOLUTION  0xE8 /* @brief Sets resolution for mouse movement */
29
#define SCALING_ACC_MD  0xE7 /* @brief Sets scaling on acceleration mode */
30
#define SCALING_LIN_MD  0xE6 /* @brief Sets scaling on linear mode */
31

  
32
/* Mouse Controller Responses */
33
#define ACK_OK      0xFA /* @brief Operation sucessful */
34
#define ACK_INVALID 0xFE /* @brief Invalid Byte, first occurence */
35
#define ACK_ERROR   0xFC /* @brief Invalid Byte on resend */
36

  
37
#endif // MOUSE_MACROS_H_INCLUDED
0 38

  
proj/include/proj_func.h
1
#ifndef PROJ_FUNC_H_INCLUDED
2
#define PROJ_FUNC_H_INCLUDED
3

  
4
#include "sprite.h"
5

  
6
/**
7
 * @brief Cleans up all memory, unsubscribes interrupts.
8
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
9
 * @see {_ERRORS_H_::errors}
10
 */
11
int cleanup(void);
12

  
13
/**
14
 * @brief Updates movement variables.
15
 */
16
void update_movement(void);
17

  
18
void update_mouse_position(struct packet *p);
19

  
20
int32_t get_mouse_X(void);
21

  
22
int32_t get_mouse_Y(void);
23

  
24
/**
25
 * @brief
26
 * @param
27
 * @param
28
 * @param
29
 * @return Angle
30
 */
31
double get_mouse_angle(sprite_t *p);
32

  
33
/**
34
 * @brief Get horizontal movement direction.
35
 * @return Horizontal movement direction (-1 -> heading LEFT; 0 -> not moving horizontally; 1 -> heading RIGHT)
36
 */
37
int get_hor_movement(void);
38

  
39
/**
40
 * @brief Get vertical movement direction.
41
 * @return Vertical movement direction (-1 -> heading UP; 0 -> not moving vertically; 1 -> heading DOWN)
42
 */
43
int get_ver_movement(void);
44

  
45
#endif /* end of include guard: PROJ_FUNC_H_INCLUDED */
0 46

  
proj/include/proj_macros.h
1
#ifndef PROJ_MACROS_H_INCLUDED
2
#define PROJ_MACROS_H_INCLUDED
3

  
4
// WASD Movement Keys
5
#define W_MAKE_CODE     0x11    /** @brief W Make Code */
6
#define W_BREAK_CODE    0x91    /** @brief W Break Code */
7
#define A_MAKE_CODE     0x1E    /** @brief A Make Code */
8
#define A_BREAK_CODE    0x9E    /** @brief A Break Code */
9
#define S_MAKE_CODE     0x1F    /** @brief S Make Code */
10
#define S_BREAK_CODE    0x9F    /** @brief S Break Code */
11
#define D_MAKE_CODE     0x20    /** @brief D Make Code */
12
#define D_BREAK_CODE    0xA0    /** @brief D Break Code */
13

  
14
// Movement Directions
15
#define UP      -1  /** @brief Moving to the top side of screen */
16
#define DOWN    1   /** @brief Moving to the bottom side of screen */
17
#define LEFT    -1  /** @brief Moving to the left side of screen */
18
#define RIGHT   1   /** @brief Moving to the right side of screen */
19
#define REST    0   /** @brief Not moving */
20

  
21
// Extra Keys
22
#define ESC_MAKE_CODE   0x01    /** @brief ESC Make Code */
23
#define ESC_BREAK_CODE  0x81    /** @brief ESC Break Code */
24

  
25
// Refresh Rate
26
#define REFRESH_RATE    60      /** @brief Screen refresh rate */
27

  
28
//Graphics mode
29
#define GRAPH_MODE      DIRECT_1280_1024_888 /** @brief Graphic mode used */
30

  
31
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */
0 32

  
proj/include/sprite.h
1
#ifndef SPRITE_H_INCLUDED
2
#define SPRITE_H_INCLUDED
3

  
4
struct sprite;
5
typedef struct sprite sprite_t;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff