Trackball based on the NXP LPC11U24 and the ADNS-9500

Dependencies:   ADNS9500 USBDevice mbed 25LCxxx_SPI

Committer:
xxann5
Date:
Wed Dec 12 03:21:38 2012 +0000
Revision:
2:72a8d2b11320
Parent:
1:34085d7e0991
Child:
5:c7056267daa7
added main.h and moved some things there. Cleaned up some code. Also added suport for left, middle and right mouse buttons, A Z button that turns the call into a scrolle wheel and an HR button that toggles the CPI value

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xxann5 2:72a8d2b11320 1 #include "main.h"
xxann5 1:34085d7e0991 2
xxann5 2:72a8d2b11320 3 /*
xxann5 2:72a8d2b11320 4 * type, VID, PID, release
xxann5 2:72a8d2b11320 5 */
xxann5 2:72a8d2b11320 6 USBMouse mouse( REL_MOUSE, 0x192f, 0x0000, 0x0001 ) ;
xxann5 1:34085d7e0991 7
xxann5 1:34085d7e0991 8 /*
xxann5 1:34085d7e0991 9 * mosi miso sclk ncs FREQ, motion
xxann5 1:34085d7e0991 10 */
xxann5 1:34085d7e0991 11 adns9500::ADNS9500 sensor(p5, p6, p7, p8, adns9500::MAX_SPI_FREQUENCY, p21);
xxann5 1:34085d7e0991 12
xxann5 1:34085d7e0991 13 void motionCallback()
xxann5 1:34085d7e0991 14 {
xxann5 2:72a8d2b11320 15 motion_triggered = true;
xxann5 2:72a8d2b11320 16 }
xxann5 2:72a8d2b11320 17
xxann5 2:72a8d2b11320 18 void btn_hr_press(){
xxann5 2:72a8d2b11320 19 high_rez_active = true;
xxann5 2:72a8d2b11320 20 sensor.setResolution( default_hirez_cpi );
xxann5 2:72a8d2b11320 21 }
xxann5 2:72a8d2b11320 22 void btn_hr_release(){
xxann5 2:72a8d2b11320 23 high_rez_active = false;
xxann5 2:72a8d2b11320 24 sensor.setResolution( default_motion_cpi );
xxann5 2:72a8d2b11320 25 }
xxann5 2:72a8d2b11320 26
xxann5 2:72a8d2b11320 27 void btn_z_press(){
xxann5 2:72a8d2b11320 28 z_axis_active = true;
xxann5 2:72a8d2b11320 29 sensor.setResolution( default_z_cpi );
xxann5 2:72a8d2b11320 30 }
xxann5 2:72a8d2b11320 31 void btn_z_release(){
xxann5 2:72a8d2b11320 32 z_axis_active = false;
xxann5 2:72a8d2b11320 33 sensor.setResolution( default_motion_cpi );
xxann5 1:34085d7e0991 34 }
xxann5 1:34085d7e0991 35
xxann5 2:72a8d2b11320 36 void btn_l_press(){
xxann5 2:72a8d2b11320 37 mouse.press(MOUSE_LEFT);
xxann5 2:72a8d2b11320 38 }
xxann5 2:72a8d2b11320 39 void btn_l_release(){
xxann5 2:72a8d2b11320 40 mouse.release(MOUSE_LEFT);
xxann5 2:72a8d2b11320 41 }
xxann5 2:72a8d2b11320 42
xxann5 2:72a8d2b11320 43 void btn_m_press(){
xxann5 2:72a8d2b11320 44 mouse.press(MOUSE_MIDDLE);
xxann5 2:72a8d2b11320 45 }
xxann5 2:72a8d2b11320 46 void btn_m_release(){
xxann5 2:72a8d2b11320 47 mouse.release(MOUSE_MIDDLE);
xxann5 2:72a8d2b11320 48 }
xxann5 2:72a8d2b11320 49
xxann5 2:72a8d2b11320 50 void btn_r_press(){
xxann5 2:72a8d2b11320 51 mouse.press(MOUSE_RIGHT);
xxann5 2:72a8d2b11320 52 }
xxann5 2:72a8d2b11320 53 void btn_r_release(){
xxann5 2:72a8d2b11320 54 mouse.release(MOUSE_RIGHT);
xxann5 2:72a8d2b11320 55 }
xxann5 1:34085d7e0991 56
xxann5 1:34085d7e0991 57
xxann5 1:34085d7e0991 58 int main(void)
xxann5 1:34085d7e0991 59 {
xxann5 2:72a8d2b11320 60
xxann5 2:72a8d2b11320 61 btn_hr.rise(&btn_hr_press);
xxann5 2:72a8d2b11320 62 btn_hr.fall(&btn_hr_release);
xxann5 2:72a8d2b11320 63
xxann5 2:72a8d2b11320 64 btn_z.rise(&btn_z_press);
xxann5 2:72a8d2b11320 65 btn_z.fall(&btn_z_release);
xxann5 1:34085d7e0991 66
xxann5 2:72a8d2b11320 67 btn_l.rise(&btn_l_press);
xxann5 2:72a8d2b11320 68 btn_l.fall(&btn_l_release);
xxann5 2:72a8d2b11320 69
xxann5 2:72a8d2b11320 70 btn_m.rise(&btn_m_press);
xxann5 2:72a8d2b11320 71 btn_m.fall(&btn_m_release);
xxann5 2:72a8d2b11320 72
xxann5 2:72a8d2b11320 73 btn_r.rise(&btn_r_press);
xxann5 2:72a8d2b11320 74 btn_r.fall(&btn_r_release);
xxann5 2:72a8d2b11320 75
xxann5 2:72a8d2b11320 76 int dx, dy;
xxann5 2:72a8d2b11320 77
xxann5 1:34085d7e0991 78 sensor.attach(&motionCallback);
xxann5 1:34085d7e0991 79
xxann5 1:34085d7e0991 80 sensor.reset();
xxann5 1:34085d7e0991 81
xxann5 1:34085d7e0991 82 uint16_t crc = sensor.sromDownload(adns9500FWArray, (uint16_t)ADNS9500_FIRMWARE_LEN );
xxann5 2:72a8d2b11320 83
xxann5 1:34085d7e0991 84 if( (uint16_t)ADNS6010_FIRMWARE_CRC != crc )
xxann5 1:34085d7e0991 85 {
xxann5 2:72a8d2b11320 86 error( "CRC does not match: [%x] [%x], Exiting.\r\n", (uint16_t)ADNS6010_FIRMWARE_CRC, crc );
xxann5 1:34085d7e0991 87 }
xxann5 2:72a8d2b11320 88
xxann5 1:34085d7e0991 89 sensor.enableLaser();
xxann5 2:72a8d2b11320 90
xxann5 2:72a8d2b11320 91 sensor.setResolution( default_motion_cpi );
xxann5 1:34085d7e0991 92
xxann5 1:34085d7e0991 93 while (true)
xxann5 1:34085d7e0991 94 {
xxann5 2:72a8d2b11320 95 if (motion_triggered) {
xxann5 1:34085d7e0991 96 led1 = !led1;
xxann5 2:72a8d2b11320 97 motion_triggered = false;
xxann5 1:34085d7e0991 98
xxann5 1:34085d7e0991 99 sensor.getMotionDelta(dx, dy);
xxann5 1:34085d7e0991 100
xxann5 2:72a8d2b11320 101 /*
xxann5 2:72a8d2b11320 102 * The sensor does not know its upside down and backwords
xxann5 2:72a8d2b11320 103 * so we are helping it out with the y axis.
xxann5 2:72a8d2b11320 104 */
xxann5 2:72a8d2b11320 105 if( z_axis_active ){
xxann5 2:72a8d2b11320 106 mouse.scroll( - dy );
xxann5 2:72a8d2b11320 107 }
xxann5 2:72a8d2b11320 108 else{
xxann5 2:72a8d2b11320 109 mouse.move( dx, - dy );
xxann5 2:72a8d2b11320 110 }
xxann5 1:34085d7e0991 111 }
xxann5 1:34085d7e0991 112 }
xxann5 1:34085d7e0991 113 }
xxann5 1:34085d7e0991 114