Only imu output

Dependencies:   Servo mbed

Fork of FYDP_Final2 by Mark Vandermeulen

Committer:
tntmarket
Date:
Wed Mar 25 09:58:50 2015 +0000
Revision:
5:d2e955a94940
Parent:
0:21019d94ad33
only imu output

Who changed what in which revision?

UserRevisionLine numberNew contents of line
majik 0:21019d94ad33 1 #include "ADNS5090.h"
majik 0:21019d94ad33 2
majik 0:21019d94ad33 3 ADNS5090::ADNS5090(PinName mosi_pin, PinName miso_pin, PinName sclk_pin, PinName ncs_pin, float pxPerMM_) :
majik 0:21019d94ad33 4 spi(mosi_pin, miso_pin, sclk_pin),
majik 0:21019d94ad33 5 ncs(ncs_pin),
majik 0:21019d94ad33 6 dx_px(0), dy_px(0),
majik 0:21019d94ad33 7 pxPerMM(pxPerMM_)
majik 0:21019d94ad33 8 {
majik 0:21019d94ad33 9 ncs = 1;
majik 0:21019d94ad33 10 spi.format(8,3);
majik 0:21019d94ad33 11 spi.frequency(1000000);
majik 0:21019d94ad33 12 reset();
majik 0:21019d94ad33 13 }
majik 0:21019d94ad33 14
majik 0:21019d94ad33 15
majik 0:21019d94ad33 16 bool ADNS5090::updateMotion()
majik 0:21019d94ad33 17 {
majik 0:21019d94ad33 18 bool ret = false;
majik 0:21019d94ad33 19 dx_px = 0;
majik 0:21019d94ad33 20 dy_px = 0;
majik 0:21019d94ad33 21
majik 0:21019d94ad33 22 ncs = 0;
majik 0:21019d94ad33 23 spi.write(ADNS5090_MOTION_ST_REG);
majik 0:21019d94ad33 24
majik 0:21019d94ad33 25 if(0x80 & spi.write(0))
majik 0:21019d94ad33 26 {
majik 0:21019d94ad33 27 spi.write(ADNS5090_MOTION_BURST_REG);
majik 0:21019d94ad33 28 dx_px = (int8_t)spi.write(0);
majik 0:21019d94ad33 29 dy_px = (int8_t)spi.write(0);
majik 0:21019d94ad33 30 sq = (uint8_t)spi.write(0);
majik 0:21019d94ad33 31 ret = true;
majik 0:21019d94ad33 32 }
majik 0:21019d94ad33 33 ncs = 1;
majik 0:21019d94ad33 34 return ret;
majik 0:21019d94ad33 35 }
majik 0:21019d94ad33 36
majik 0:21019d94ad33 37 float ADNS5090::dx()
majik 0:21019d94ad33 38 {
majik 0:21019d94ad33 39 return dx_px/pxPerMM;
majik 0:21019d94ad33 40 }
majik 0:21019d94ad33 41
majik 0:21019d94ad33 42 float ADNS5090::dy()
majik 0:21019d94ad33 43 {
majik 0:21019d94ad33 44 return dy_px/pxPerMM;
majik 0:21019d94ad33 45 }
majik 0:21019d94ad33 46
majik 0:21019d94ad33 47 void ADNS5090::reset()
majik 0:21019d94ad33 48 {
majik 0:21019d94ad33 49 ncs = 0;
majik 0:21019d94ad33 50 spi.write(ADNS5090_WRITE_VAL |
majik 0:21019d94ad33 51 ADNS5090_RESET_REG);
majik 0:21019d94ad33 52 spi.write(ADNS5090_RESET_VAL);
majik 0:21019d94ad33 53 ncs = 1;
majik 0:21019d94ad33 54 }
majik 0:21019d94ad33 55
majik 0:21019d94ad33 56 void ADNS5090::powerDown()
majik 0:21019d94ad33 57 {
majik 0:21019d94ad33 58 ncs = 0;
majik 0:21019d94ad33 59 spi.write(ADNS5090_WRITE_VAL |
majik 0:21019d94ad33 60 ADNS5090_MOUSE_CTRL_REG);
majik 0:21019d94ad33 61 spi.write(ADNS5090_POWERDOWN_VAL);
majik 0:21019d94ad33 62 ncs = 1;
majik 0:21019d94ad33 63 }
majik 0:21019d94ad33 64
majik 0:21019d94ad33 65 void ADNS5090::setDPI()
majik 0:21019d94ad33 66 {
majik 0:21019d94ad33 67 ncs = 0;
majik 0:21019d94ad33 68 spi.write(ADNS5090_WRITE_VAL|
majik 0:21019d94ad33 69 ADNS5090_MOUSE_CTRL_REG);
majik 0:21019d94ad33 70 spi.write(0x24);
majik 0:21019d94ad33 71 ncs = 1;
majik 0:21019d94ad33 72
majik 0:21019d94ad33 73 ncs = 0;
majik 0:21019d94ad33 74 spi.write(ADNS5090_WRITE_VAL|
majik 0:21019d94ad33 75 0x21);
majik 0:21019d94ad33 76 spi.write(0x10);
majik 0:21019d94ad33 77 ncs = 1;
majik 0:21019d94ad33 78 }