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.
Fork of FYDP_Final2 by
ADNS5090.cpp
00001 #include "ADNS5090.h" 00002 00003 ADNS5090::ADNS5090(PinName mosi_pin, PinName miso_pin, PinName sclk_pin, PinName ncs_pin, float pxPerMM_) : 00004 spi(mosi_pin, miso_pin, sclk_pin), 00005 ncs(ncs_pin), 00006 dx_px(0), dy_px(0), 00007 pxPerMM(pxPerMM_) 00008 { 00009 ncs = 1; 00010 spi.format(8,3); 00011 spi.frequency(1000000); 00012 reset(); 00013 } 00014 00015 00016 bool ADNS5090::updateMotion() 00017 { 00018 bool ret = false; 00019 dx_px = 0; 00020 dy_px = 0; 00021 00022 ncs = 0; 00023 spi.write(ADNS5090_MOTION_ST_REG); 00024 00025 if(0x80 & spi.write(0)) 00026 { 00027 spi.write(ADNS5090_MOTION_BURST_REG); 00028 dx_px = (int8_t)spi.write(0); 00029 dy_px = (int8_t)spi.write(0); 00030 sq = (uint8_t)spi.write(0); 00031 ret = true; 00032 } 00033 ncs = 1; 00034 return ret; 00035 } 00036 00037 float ADNS5090::dx() 00038 { 00039 return dx_px/pxPerMM; 00040 } 00041 00042 float ADNS5090::dy() 00043 { 00044 return dy_px/pxPerMM; 00045 } 00046 00047 void ADNS5090::reset() 00048 { 00049 ncs = 0; 00050 spi.write(ADNS5090_WRITE_VAL | 00051 ADNS5090_RESET_REG); 00052 spi.write(ADNS5090_RESET_VAL); 00053 ncs = 1; 00054 } 00055 00056 void ADNS5090::powerDown() 00057 { 00058 ncs = 0; 00059 spi.write(ADNS5090_WRITE_VAL | 00060 ADNS5090_MOUSE_CTRL_REG); 00061 spi.write(ADNS5090_POWERDOWN_VAL); 00062 ncs = 1; 00063 } 00064 00065 void ADNS5090::setDPI() 00066 { 00067 ncs = 0; 00068 spi.write(ADNS5090_WRITE_VAL| 00069 ADNS5090_MOUSE_CTRL_REG); 00070 spi.write(0x24); 00071 ncs = 1; 00072 00073 ncs = 0; 00074 spi.write(ADNS5090_WRITE_VAL| 00075 0x21); 00076 spi.write(0x10); 00077 ncs = 1; 00078 }
Generated on Tue Jul 12 2022 16:56:35 by
