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 SWSPI by
ADNS5090.cpp@1:98a9d6fc60ae, 2014-05-08 (annotated)
- Committer:
- Throwbot
- Date:
- Thu May 08 19:10:37 2014 +0000
- Revision:
- 1:98a9d6fc60ae
- Parent:
- SWSPI.cpp@0:6a500a08c7fd
- Child:
- 2:4612564007c0
good version, just intergrated mouse sensor, has shell, has rc
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Throwbot | 1:98a9d6fc60ae | 1 | #include "ADNS5090.h" |
| davervw | 0:6a500a08c7fd | 2 | |
| Throwbot | 1:98a9d6fc60ae | 3 | ADNS5090::ADNS5090(PinName mosi_pin, PinName miso_pin, PinName sclk_pin, PinName ncs_pin, float pxPerMM_) : |
| Throwbot | 1:98a9d6fc60ae | 4 | spi(mosi_pin, miso_pin, sclk_pin), |
| Throwbot | 1:98a9d6fc60ae | 5 | ncs(ncs_pin), |
| Throwbot | 1:98a9d6fc60ae | 6 | dx_px(0), dy_px(0), |
| Throwbot | 1:98a9d6fc60ae | 7 | pxPerMM(pxPerMM_) |
| davervw | 0:6a500a08c7fd | 8 | { |
| Throwbot | 1:98a9d6fc60ae | 9 | ncs = 1; |
| Throwbot | 1:98a9d6fc60ae | 10 | spi.format(8,3); |
| Throwbot | 1:98a9d6fc60ae | 11 | spi.frequency(1000000); |
| Throwbot | 1:98a9d6fc60ae | 12 | reset(); |
| davervw | 0:6a500a08c7fd | 13 | } |
| davervw | 0:6a500a08c7fd | 14 | |
| Throwbot | 1:98a9d6fc60ae | 15 | |
| Throwbot | 1:98a9d6fc60ae | 16 | bool ADNS5090::updateMotion() |
| davervw | 0:6a500a08c7fd | 17 | { |
| Throwbot | 1:98a9d6fc60ae | 18 | bool ret = false; |
| Throwbot | 1:98a9d6fc60ae | 19 | dx_px = 0; |
| Throwbot | 1:98a9d6fc60ae | 20 | dy_px = 0; |
| Throwbot | 1:98a9d6fc60ae | 21 | |
| Throwbot | 1:98a9d6fc60ae | 22 | ncs = 0; |
| Throwbot | 1:98a9d6fc60ae | 23 | spi.write(ADNS5090_MOTION_ST_REG); |
| Throwbot | 1:98a9d6fc60ae | 24 | |
| Throwbot | 1:98a9d6fc60ae | 25 | if(0x80 & spi.write(0)) |
| Throwbot | 1:98a9d6fc60ae | 26 | { |
| Throwbot | 1:98a9d6fc60ae | 27 | spi.write(ADNS5090_MOTION_BURST_REG); |
| Throwbot | 1:98a9d6fc60ae | 28 | dx_px = (int8_t)spi.write(0); |
| Throwbot | 1:98a9d6fc60ae | 29 | dy_px = (int8_t)spi.write(0); |
| Throwbot | 1:98a9d6fc60ae | 30 | sq = (uint8_t)spi.write(0); |
| Throwbot | 1:98a9d6fc60ae | 31 | ret = true; |
| Throwbot | 1:98a9d6fc60ae | 32 | } |
| Throwbot | 1:98a9d6fc60ae | 33 | ncs = 1; |
| Throwbot | 1:98a9d6fc60ae | 34 | return ret; |
| davervw | 0:6a500a08c7fd | 35 | } |
| davervw | 0:6a500a08c7fd | 36 | |
| Throwbot | 1:98a9d6fc60ae | 37 | float ADNS5090::dx() |
| davervw | 0:6a500a08c7fd | 38 | { |
| Throwbot | 1:98a9d6fc60ae | 39 | return dx_px/pxPerMM; |
| davervw | 0:6a500a08c7fd | 40 | } |
| davervw | 0:6a500a08c7fd | 41 | |
| Throwbot | 1:98a9d6fc60ae | 42 | float ADNS5090::dy() |
| davervw | 0:6a500a08c7fd | 43 | { |
| Throwbot | 1:98a9d6fc60ae | 44 | return dy_px/pxPerMM; |
| Throwbot | 1:98a9d6fc60ae | 45 | } |
| Throwbot | 1:98a9d6fc60ae | 46 | |
| Throwbot | 1:98a9d6fc60ae | 47 | void ADNS5090::reset() |
| Throwbot | 1:98a9d6fc60ae | 48 | { |
| Throwbot | 1:98a9d6fc60ae | 49 | ncs = 0; |
| Throwbot | 1:98a9d6fc60ae | 50 | spi.write(ADNS5090_WRITE_VAL | |
| Throwbot | 1:98a9d6fc60ae | 51 | ADNS5090_RESET_REG); |
| Throwbot | 1:98a9d6fc60ae | 52 | spi.write(ADNS5090_RESET_VAL); |
| Throwbot | 1:98a9d6fc60ae | 53 | ncs = 1; |
| davervw | 0:6a500a08c7fd | 54 | } |
| davervw | 0:6a500a08c7fd | 55 | |
| Throwbot | 1:98a9d6fc60ae | 56 | void ADNS5090::powerDown() |
| davervw | 0:6a500a08c7fd | 57 | { |
| Throwbot | 1:98a9d6fc60ae | 58 | ncs = 0; |
| Throwbot | 1:98a9d6fc60ae | 59 | spi.write(ADNS5090_WRITE_VAL | |
| Throwbot | 1:98a9d6fc60ae | 60 | ADNS5090_MOUSE_CTRL_REG); |
| Throwbot | 1:98a9d6fc60ae | 61 | spi.write(ADNS5090_POWERDOWN_VAL); |
| Throwbot | 1:98a9d6fc60ae | 62 | ncs = 1; |
| davervw | 0:6a500a08c7fd | 63 | } |
| davervw | 0:6a500a08c7fd | 64 | |
| Throwbot | 1:98a9d6fc60ae | 65 | void ADNS5090::setDPI() |
| Throwbot | 1:98a9d6fc60ae | 66 | { |
| Throwbot | 1:98a9d6fc60ae | 67 | ncs = 0; |
| Throwbot | 1:98a9d6fc60ae | 68 | spi.write(ADNS5090_WRITE_VAL| |
| Throwbot | 1:98a9d6fc60ae | 69 | ADNS5090_MOUSE_CTRL_REG); |
| Throwbot | 1:98a9d6fc60ae | 70 | spi.write(0x24); |
| Throwbot | 1:98a9d6fc60ae | 71 | ncs = 1; |
| Throwbot | 1:98a9d6fc60ae | 72 | |
| Throwbot | 1:98a9d6fc60ae | 73 | ncs = 0; |
| Throwbot | 1:98a9d6fc60ae | 74 | spi.write(ADNS5090_WRITE_VAL| |
| Throwbot | 1:98a9d6fc60ae | 75 | 0x21); |
| Throwbot | 1:98a9d6fc60ae | 76 | spi.write(0x10); |
| Throwbot | 1:98a9d6fc60ae | 77 | ncs = 1; |
| Throwbot | 1:98a9d6fc60ae | 78 | } |
