#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdlib.h>
#include "usrat.h"
#include "ioconfig.h"
#include "ps2.h"
#include "mouse.h"
#include "tdelay.h"
Functions | |
uint8_t | mouse_reset () |
int16_t | mouse_command (uint8_t cmd, uint8_t wait) |
void | mouse_setres (uint8_t res) |
Set mouse resolution. | |
uint8_t | mouse_boot () |
Boot mouse, check and return initial button state. | |
Variables | |
const char PSTR_OK[] | PROGMEM = "OK" |
uint8_t mouse_boot | ( | ) |
Boot mouse, check and return initial button state.
00086 { 00087 uint8_t buttons = 0; 00088 00089 ps2_enable_recv(1); 00090 00091 for(;;) { 00092 printf_P(PSTR("\nRESET: ")); 00093 if (mouse_reset() == 0) { 00094 puts_P(PSTR_OK); 00095 break; 00096 } else { 00097 puts_P(PSTR_ERROR); 00098 } 00099 } 00100 00101 mouse_command(MOUSE_DDR, 1); 00102 mouse_command(MOUSE_SETSCALE21, 1); 00103 00104 mouse_command(MOUSE_SETRES, 1); 00105 mouse_command(1,1); // 0 = 1, 1 = 2, 2 = 4, 3 = 8 counts/mm 00106 00107 mouse_command(MOUSE_STATUSRQ, 1); 00108 tdelay(22); 00109 if (ps2_avail()) buttons = ps2_getbyte() & 7; 00110 00111 mouse_flush(22); 00112 00113 printf_P(PSTR("B:%x\n"), buttons); 00114 00115 mouse_command(MOUSE_EDR, 1); 00116 00117 mouse_flush(100); 00118 00119 printf_P(PSTR("\n")); 00120 00121 return buttons; 00122 }
int16_t mouse_command | ( | uint8_t | cmd, | |
uint8_t | wait | |||
) |
00062 { 00063 int16_t response = -1; 00064 00065 ps2_sendbyte(cmd); 00066 if (wait) { 00067 tdelay(22); 00068 if (ps2_avail()) response = ps2_getbyte(); 00069 } 00070 00071 printf_P(PSTR("%02x>%02x "), cmd, response); 00072 00073 return response; 00074 }
uint8_t mouse_reset | ( | ) |
00030 { 00031 uint8_t i, b = 33; 00032 const int ntries = 11; 00033 00034 // send reset command 00035 ps2_sendbyte(MOUSE_RESET); 00036 ps2_sendbyte(MOUSE_RESET); 00037 ps2_sendbyte(MOUSE_RESET); 00038 00039 // wait for some time for mouse self-test to complete 00040 for (i = 0; i < ntries; i++) { 00041 tdelay(250); 00042 if (ps2_avail()) { 00043 b = ps2_getbyte(); printf_P(PSTR("%02x ")); 00044 if (b == MOUSE_RESETOK) { 00045 break; 00046 } else { 00047 i = ntries; 00048 break; 00049 } 00050 } 00051 } 00052 00053 if (i == ntries) return -1; 00054 00055 // flush the rest of reponse, most likely mouse id == 0 00056 tdelay(100); 00057 mouse_flush(0); 00058 00059 return 0; 00060 }
void mouse_setres | ( | uint8_t | res | ) |
Set mouse resolution.
res | resolution code 0: 1 count per mm 1: 2 counts per mm 2: 4 counts per mm 3: 8 counts per mm |
00077 { 00078 mouse_command(MOUSE_DDR,1); 00079 00080 mouse_command(MOUSE_SETRES, 1); 00081 mouse_command(res, 1); // 0 = 1, 1 = 2, 2 = 4, 3 = 8 counts/mm 00082 00083 mouse_command(MOUSE_EDR,1); 00084 }
const char PSTR_ERROR [] PROGMEM = "OK" |