Kostya B. / Mbed 2 deprecated ADNS3080_LCD

Dependencies:   BSP_DISCO_F429ZI LCD_DISCO_F429ZI mbed

Fork of ADNS3080_HelloWorld by ryosuke yumoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ADNS3080.cpp Source File

ADNS3080.cpp

00001 /*
00002  *author Ryosuke Yumoto
00003  */
00004 #include "ADNS3080.h"
00005 
00006 ADNS3080::ADNS3080(PinName mosi,
00007                    PinName miso,
00008                    PinName sck,
00009                    PinName cs) : spi_(mosi, miso, sck), nCS_(cs){
00010     
00011     spi_.frequency(2000000);
00012     spi_.format(8, 3);
00013     
00014     nCS_=1;
00015     
00016     wait_us(500);
00017     
00018 }
00019 //
00020 int ADNS3080::getProdID(void) {
00021     
00022     return ReadRegister(ADNS3080_PRODUCT_ID);
00023     
00024 }
00025 
00026 int ADNS3080::getRevID(void) {
00027     
00028     return ReadRegister(ADNS3080_REVISION_ID);
00029     
00030 }
00031 
00032 int ADNS3080::getMotion(void) {
00033     
00034     return ReadRegister(ADNS3080_MOTION);
00035     
00036 }
00037 
00038 signed char ADNS3080::getDelta_X(void) {
00039     
00040     return ReadRegister(ADNS3080_DELTA_X);
00041     
00042 }
00043 
00044 signed char ADNS3080::getDelta_Y(void) {
00045     
00046     return ReadRegister(ADNS3080_DELTA_Y);
00047     
00048 }
00049 
00050 unsigned int ADNS3080::getSQUAL(void) {
00051     
00052     return ReadRegister(ADNS3080_SQUAL);
00053     
00054 }
00055 
00056 unsigned short ADNS3080::getPixel_sum(void) {
00057     
00058     return ReadRegister(ADNS3080_PIXEL_SUM);    
00059     
00060 }
00061 
00062 char ADNS3080::getMax_Pixel(void) {
00063 
00064     return ReadRegister(ADNS3080_MAXIMUM_PIXEL);
00065         
00066 }
00067 
00068 int ADNS3080::getConfiguration_bits(void){
00069 
00070     return ReadRegister(ADNS3080_CONFIGURATION_BITS);
00071 
00072 }
00073 
00074 void ADNS3080::setConfiguration_bits(char configuration){
00075 
00076     WriteRegister(ADNS3080_CONFIGURATION_BITS, configuration);
00077 
00078 }
00079 
00080 int ADNS3080::getExtended_config(void){
00081     
00082     return ReadRegister(ADNS3080_EXTENDED_CONFIG);   
00083 
00084 }
00085 void ADNS3080::setExtended_config(char extended_config){
00086     
00087     WriteRegister(ADNS3080_EXTENDED_CONFIG, extended_config);
00088     
00089 }
00090 
00091 /*
00092 short getData_Out(void){
00093 
00094     ReadRegister(ADNS3080_DATA_OUT_UPPER);
00095     ReadRegister(ADNS3080_DATA_OUT_LOWER);    
00096 
00097 }
00098 unsigned int getShutter(void);
00099 unsigned int getFrame_Period(void);
00100 void Motion_Clear(void);
00101 */
00102 
00103 int ADNS3080::getInverProdID(void) {
00104     
00105     return ReadRegister(ADNS3080_INVERSE_PRODUCT_ID);
00106     
00107 }
00108 
00109 int ADNS3080::ReadRegister(int address) {
00110     
00111     int tx = (ADNS3080_SPI_READ | address);
00112     int rx = 0;
00113     
00114     nCS_=0;
00115     
00116     spi_.write(tx);
00117     wait_us(50);
00118     rx = spi_.write(0x00);
00119     nCS_ = 1;
00120     
00121     return rx;
00122 }
00123 
00124 void ADNS3080::WriteRegister(int address, char data) {
00125     
00126     int tx = ( ADNS3080_SPI_WRITE | address);
00127     
00128     nCS_=0;
00129     spi_.write(tx);
00130     spi_.write(data);
00131     
00132     nCS_=1;
00133     
00134 }