Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ADNS6010.cpp
00001 #include "ADNS6010.h" 00002 00003 ADNS6010::ADNS6010(PinName mosi, PinName miso, PinName sclk, PinName ncs, PinName reset,PinName npd) 00004 : spi_(mosi, miso, sclk), npd_(npd),reset_(reset), ncs_(ncs) { 00005 spi_.format(8,3); 00006 spi_.frequency(500000); 00007 00008 // Chip Reset 00009 creset(); 00010 start(); 00011 00012 npd_ =1; 00013 wait_ms(1); 00014 00015 int prod_id = cread(REGISTER_PRODUCTID); // read Product ID register 00016 int rev_id = cread(REGISTER_REVISONID); // read Revision ID register 00017 00018 if ((prod_id!=ADNS6010_PRODUCTID)||(rev_id!=ADNS6010_REVISIONID)) { 00019 error("The connection with the ADNS-6010 is not established\n"); 00020 } 00021 00022 } 00023 00024 // write data to a register 00025 void ADNS6010::cwrite(unsigned char caddress, unsigned char cdata) { 00026 ncs_=0; 00027 // send the command to read the register 00028 caddress |= 0x80; 00029 spi_.write(caddress); 00030 // send dummy byte 00031 spi_.write(cdata); 00032 ncs_=1; 00033 00034 wait_us(10); // more than the minimum for safety 00035 } 00036 00037 00038 // mouse chip - change resolurion 00039 void ADNS6010::changeCPI(int cpi) { 00040 int config = 0x49;//resolution reset(=default=400) 00041 00042 switch (cpi) { 00043 case 400: 00044 //config = config & 0x49 00045 break; 00046 00047 case 800: // Change cpi to 800 00048 config |= 0x10; 00049 break; 00050 00051 case 1600: // Change cpi to 1600 00052 config |= 0x04; 00053 break; 00054 00055 case 2000: // Change cpi to 2000 00056 config |= 0x14; 00057 break; 00058 00059 default: 00060 error("setting fault\n cpi setting is only 400 or 800 or 1600 or 2000\n\r"); 00061 break; 00062 } 00063 00064 cwrite(REGISTER_CONFIGURATION_BITS,config); 00065 } 00066 00067 00068 void ADNS6010::end() 00069 { 00070 npd_=0; 00071 } 00072 00073 void ADNS6010::start() 00074 { 00075 npd_=1; 00076 } 00077 00078 void ADNS6010::creset() 00079 { 00080 reset_ = 1; 00081 wait_us(10); 00082 reset_ = 0; 00083 } 00084 00085 void ADNS6010::set_freq(int freq) 00086 { 00087 if(freq>=500000&&freq<=2000000) 00088 { 00089 spi_.frequency(freq); 00090 } 00091 } 00092 00093 int ADNS6010::read_squal() 00094 { 00095 return cread(REGISTER_SQUAL)*4; 00096 } 00097 00098 // read the delta_X and delta_Y of the chip 00099 void ADNS6010::read_deltas(int* a_dx, int* a_dy) { 00100 00101 int * dx, * dy; 00102 dx=(int*)a_dx; 00103 dy=(int*)a_dy; 00104 *dx = 0; 00105 *dy = 0; 00106 00107 int motion = cread(REGISTER_MOTION); // read Motion register 00108 00109 if ((motion&0x80)==0x80) { 00110 *dx = MChipMotion(cread(REGISTER_DELTAX)); 00111 *dy = MChipMotion(cread(REGISTER_DELTAY)); 00112 } 00113 } 00114 00115 // read a register 00116 int ADNS6010::cread(unsigned char cregister) { 00117 00118 ncs_=0; 00119 // send the command to read the register 00120 spi_.write(cregister); 00121 00122 if(cregister==REGISTER_MOTION) wait_us(DELAY_TRAD_MOT); 00123 else wait_us(DELAY_TRAD); 00124 00125 // send dummy byte 00126 int reply = spi_.write(0x00); 00127 ncs_=1; 00128 00129 return reply; 00130 } 00131 00132 // Transform the reading of the mouse Delta register to actual motion 00133 int ADNS6010::MChipMotion(int reading) { 00134 00135 int displacement; 00136 if (reading <= 0x7f) { 00137 displacement = reading; 00138 } else { 00139 displacement = reading - 256; 00140 } 00141 return displacement; 00142 }
Generated on Wed Jul 13 2022 17:51:04 by
1.7.2