Interface to access to Avago ADNS-9500 laser mouse sensors.
Fork of ADNS9500 by
adns9500.hpp@15:85ea51a56fdc, 2012-12-09 (annotated)
- Committer:
- xxann5
- Date:
- Sun Dec 09 05:27:51 2012 +0000
- Revision:
- 15:85ea51a56fdc
- Parent:
- 10:bbf9ff378632
- Child:
- 16:de76a70defb3
added the srom in a header file as well as tweaked some methods to my likeing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aplatanado |
0:782f2061a8f5 | 1 | /* |
aplatanado |
1:fa3052be61b5 | 2 | * adns9500.hpp - Interface to access to Avago ADNS-9500 laser mouse sensors |
aplatanado |
0:782f2061a8f5 | 3 | * |
aplatanado |
0:782f2061a8f5 | 4 | * Copyright 2012 Jesus Torres <jmtorres@ull.es> |
aplatanado |
0:782f2061a8f5 | 5 | * |
aplatanado |
0:782f2061a8f5 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
aplatanado |
0:782f2061a8f5 | 7 | * you may not use this file except in compliance with the License. |
aplatanado |
0:782f2061a8f5 | 8 | * You may obtain a copy of the License at |
aplatanado |
0:782f2061a8f5 | 9 | * |
aplatanado |
0:782f2061a8f5 | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
aplatanado |
0:782f2061a8f5 | 11 | * |
aplatanado |
0:782f2061a8f5 | 12 | * Unless required by applicable law or agreed to in writing, software |
aplatanado |
0:782f2061a8f5 | 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
aplatanado |
0:782f2061a8f5 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
aplatanado |
0:782f2061a8f5 | 15 | * See the License for the specific language governing permissions and |
aplatanado |
0:782f2061a8f5 | 16 | * limitations under the License. |
aplatanado |
0:782f2061a8f5 | 17 | */ |
aplatanado |
0:782f2061a8f5 | 18 | |
aplatanado |
0:782f2061a8f5 | 19 | #ifndef ADNS9500_HPP_ |
aplatanado |
0:782f2061a8f5 | 20 | #define ADNS9500_HPP_ |
aplatanado |
0:782f2061a8f5 | 21 | |
aplatanado |
0:782f2061a8f5 | 22 | #include <mbed.h> |
aplatanado |
0:782f2061a8f5 | 23 | #include <stdint.h> |
aplatanado |
0:782f2061a8f5 | 24 | #include <string> |
xxann5 | 15:85ea51a56fdc | 25 | #include "adns9500_firmware.hpp" |
aplatanado |
0:782f2061a8f5 | 26 | |
aplatanado |
0:782f2061a8f5 | 27 | #define ADNS9500_CONFIGURATION_II_RPT_MOD (1 << 2) |
aplatanado |
0:782f2061a8f5 | 28 | #define ADNS9500_CONFIGURATION_IV_SROM_SIZE (1 << 1) |
aplatanado |
0:782f2061a8f5 | 29 | #define ADNS9500_LASER_CTRL0_FORCE_DISABLED (1 << 0) |
aplatanado |
0:782f2061a8f5 | 30 | #define ADNS9500_OBSERVATION_CHECK_BITS 0x3f |
aplatanado |
0:782f2061a8f5 | 31 | |
aplatanado |
0:782f2061a8f5 | 32 | #define ADNS9500_IF_MOTION(x) (bool)(x & 0x80) |
aplatanado |
0:782f2061a8f5 | 33 | #define ADNS9500_IF_LASER_FAULT(x) (bool)(x & 0x40) |
aplatanado |
0:782f2061a8f5 | 34 | #define ADNS9500_IF_RUNNING_SROM_CODE(x) (bool)(x & 0x80) |
aplatanado | 3:898ed1944119 | 35 | #define ADNS9500_IF_FRAME_FIRST_PIXEL(x) (bool)(x & 0x01) |
aplatanado |
0:782f2061a8f5 | 36 | #define ADNS9500_IF_OBSERVATION_TEST(x) (bool)(x & ADNS9500_OBSERVATION_CHECK_BITS) |
aplatanado | 7:1771f1c89df6 | 37 | #define ADNS9500_UINT16(ub, lb) (uint16_t)(((ub & 0xff) << 8) | (lb & 0xff)) |
aplatanado | 7:1771f1c89df6 | 38 | #define ADNS9500_INT16(ub, lb) (int16_t)(((ub & 0xff) << 8) | (lb & 0xff)) |
aplatanado |
0:782f2061a8f5 | 39 | |
xxann5 | 15:85ea51a56fdc | 40 | #define BYTETOBINARYPATTERN "%d%d%d%d%d%d%d%d" |
xxann5 | 15:85ea51a56fdc | 41 | #define BYTETOBINARY(byte) \ |
xxann5 | 15:85ea51a56fdc | 42 | (byte & 0x80 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 43 | (byte & 0x40 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 44 | (byte & 0x20 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 45 | (byte & 0x10 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 46 | (byte & 0x08 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 47 | (byte & 0x04 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 48 | (byte & 0x02 ? 1 : 0), \ |
xxann5 | 15:85ea51a56fdc | 49 | (byte & 0x01 ? 1 : 0) |
xxann5 | 15:85ea51a56fdc | 50 | |
aplatanado |
0:782f2061a8f5 | 51 | namespace adns9500 |
aplatanado |
0:782f2061a8f5 | 52 | { |
aplatanado |
0:782f2061a8f5 | 53 | // Maximum SPI clock frequency supported by the sensor |
aplatanado | 10:bbf9ff378632 | 54 | const int MAX_SPI_FREQUENCY = 2000000; |
aplatanado |
0:782f2061a8f5 | 55 | |
aplatanado |
0:782f2061a8f5 | 56 | // Internal oscillator norminal frequency |
aplatanado |
0:782f2061a8f5 | 57 | const int INTERNAL_OSCILLATOR_FREQUENCY = 47000000; |
aplatanado |
0:782f2061a8f5 | 58 | |
aplatanado |
0:782f2061a8f5 | 59 | // Number of pixels per frame |
aplatanado |
0:782f2061a8f5 | 60 | const int NUMBER_OF_PIXELS_PER_FRAME = 900; |
aplatanado | 2:ee0c13ef1320 | 61 | |
aplatanado | 2:ee0c13ef1320 | 62 | // Maximum surface quality |
aplatanado | 2:ee0c13ef1320 | 63 | const int MAX_SURFACE_QUALITY = 676; // 169 * 4 |
aplatanado |
0:782f2061a8f5 | 64 | |
aplatanado |
0:782f2061a8f5 | 65 | // |
aplatanado |
0:782f2061a8f5 | 66 | // Sensor registers |
aplatanado |
0:782f2061a8f5 | 67 | // |
aplatanado |
0:782f2061a8f5 | 68 | |
aplatanado |
0:782f2061a8f5 | 69 | enum Register |
aplatanado |
0:782f2061a8f5 | 70 | { |
aplatanado |
0:782f2061a8f5 | 71 | PRODUCT_ID = 0x00, |
aplatanado |
0:782f2061a8f5 | 72 | REVISION_ID = 0x01, |
aplatanado |
0:782f2061a8f5 | 73 | MOTION = 0x02, |
aplatanado |
0:782f2061a8f5 | 74 | DELTA_X_L = 0x03, |
aplatanado |
0:782f2061a8f5 | 75 | DELTA_X_H = 0x04, |
aplatanado |
0:782f2061a8f5 | 76 | DELTA_Y_L = 0x05, |
aplatanado |
0:782f2061a8f5 | 77 | DELTA_Y_H = 0x06, |
aplatanado |
0:782f2061a8f5 | 78 | SQUAL = 0x07, |
aplatanado |
0:782f2061a8f5 | 79 | PIXEL_SUM = 0x08, |
aplatanado |
0:782f2061a8f5 | 80 | MAXIMUM_PIXEL = 0x09, |
aplatanado |
0:782f2061a8f5 | 81 | MINIMUM_PIXEL = 0x0a, |
aplatanado |
0:782f2061a8f5 | 82 | SHUTTER_LOWER = 0x0b, |
aplatanado |
0:782f2061a8f5 | 83 | SHUTTER_UPPER = 0x0c, |
aplatanado |
0:782f2061a8f5 | 84 | FRAME_PERIOD_LOWER = 0x0d, |
aplatanado |
0:782f2061a8f5 | 85 | FRAME_PERIOD_UPPER = 0x0e, |
aplatanado |
0:782f2061a8f5 | 86 | CONFIGURATION_I = 0x0f, |
aplatanado |
0:782f2061a8f5 | 87 | CONFIGURATION_II = 0x10, |
aplatanado |
0:782f2061a8f5 | 88 | FRAME_CAPTURE = 0x12, |
aplatanado |
0:782f2061a8f5 | 89 | SROM_ENABLE = 0x13, |
aplatanado |
0:782f2061a8f5 | 90 | LASER_CTRL0 = 0x20, |
aplatanado |
0:782f2061a8f5 | 91 | DATA_OUT_LOWER = 0x25, |
aplatanado |
0:782f2061a8f5 | 92 | DATA_OUT_UPPER = 0x26, |
aplatanado |
0:782f2061a8f5 | 93 | SROM_ID = 0x2a, |
aplatanado |
0:782f2061a8f5 | 94 | OBSERVATION = 0x24, |
aplatanado |
0:782f2061a8f5 | 95 | CONFIGURATION_V = 0x2f, |
aplatanado |
0:782f2061a8f5 | 96 | CONFIGURATION_IV = 0x39, |
aplatanado |
0:782f2061a8f5 | 97 | POWER_UP_RESET = 0x3a, |
aplatanado |
0:782f2061a8f5 | 98 | MOTION_BURST = 0x50, |
aplatanado |
0:782f2061a8f5 | 99 | SROM_LOAD_BURST = 0x62, |
aplatanado | 3:898ed1944119 | 100 | PIXEL_BURST = 0x64 |
aplatanado |
0:782f2061a8f5 | 101 | }; |
aplatanado |
0:782f2061a8f5 | 102 | |
aplatanado |
0:782f2061a8f5 | 103 | // |
aplatanado |
0:782f2061a8f5 | 104 | // Supported resolutions |
aplatanado |
0:782f2061a8f5 | 105 | // |
aplatanado |
0:782f2061a8f5 | 106 | |
aplatanado |
0:782f2061a8f5 | 107 | enum Resolution |
aplatanado |
0:782f2061a8f5 | 108 | { |
aplatanado |
0:782f2061a8f5 | 109 | CPI_90 = 0x01, |
aplatanado |
0:782f2061a8f5 | 110 | CPI_1630 = 0x12, |
aplatanado |
0:782f2061a8f5 | 111 | CPI_3240 = 0x24, |
aplatanado |
0:782f2061a8f5 | 112 | CPI_5040 = 0x38 |
aplatanado |
0:782f2061a8f5 | 113 | }; |
aplatanado |
0:782f2061a8f5 | 114 | |
aplatanado |
0:782f2061a8f5 | 115 | // |
aplatanado |
0:782f2061a8f5 | 116 | // Motion burst data |
aplatanado |
0:782f2061a8f5 | 117 | // |
aplatanado |
0:782f2061a8f5 | 118 | |
aplatanado |
0:782f2061a8f5 | 119 | struct MotionData |
aplatanado |
0:782f2061a8f5 | 120 | { |
aplatanado | 2:ee0c13ef1320 | 121 | MotionData() |
aplatanado | 2:ee0c13ef1320 | 122 | : motion(0), observation(0), dx(0), dy(0), dxMM(0), dyMM(0), |
aplatanado | 2:ee0c13ef1320 | 123 | surfaceQuality(0), averagePixel(0), maximumPixel(0), |
aplatanado | 2:ee0c13ef1320 | 124 | minimumPixel(0), shutter(0), framePeriod(0) |
aplatanado | 2:ee0c13ef1320 | 125 | {} |
aplatanado | 2:ee0c13ef1320 | 126 | |
aplatanado |
0:782f2061a8f5 | 127 | int motion; |
aplatanado |
0:782f2061a8f5 | 128 | int observation; |
aplatanado |
0:782f2061a8f5 | 129 | int dx; |
aplatanado |
0:782f2061a8f5 | 130 | int dy; |
aplatanado | 2:ee0c13ef1320 | 131 | float dxMM; |
aplatanado | 2:ee0c13ef1320 | 132 | float dyMM; |
aplatanado | 2:ee0c13ef1320 | 133 | int surfaceQuality; |
aplatanado | 2:ee0c13ef1320 | 134 | float averagePixel; |
aplatanado |
0:782f2061a8f5 | 135 | int maximumPixel; |
aplatanado |
0:782f2061a8f5 | 136 | int minimumPixel; |
aplatanado |
0:782f2061a8f5 | 137 | int shutter; |
aplatanado |
0:782f2061a8f5 | 138 | int framePeriod; |
aplatanado |
0:782f2061a8f5 | 139 | }; |
aplatanado |
0:782f2061a8f5 | 140 | |
aplatanado |
0:782f2061a8f5 | 141 | // |
aplatanado |
0:782f2061a8f5 | 142 | // Interface to access to ADNS-9500 mouse sensor |
aplatanado |
0:782f2061a8f5 | 143 | // |
aplatanado |
0:782f2061a8f5 | 144 | |
aplatanado |
0:782f2061a8f5 | 145 | class ADNS9500 |
aplatanado |
0:782f2061a8f5 | 146 | { |
aplatanado |
0:782f2061a8f5 | 147 | public: |
aplatanado |
0:782f2061a8f5 | 148 | |
aplatanado |
0:782f2061a8f5 | 149 | // |
aplatanado |
0:782f2061a8f5 | 150 | // Create the sensor interface |
aplatanado |
0:782f2061a8f5 | 151 | // |
aplatanado |
0:782f2061a8f5 | 152 | // @param mosi MOSI pin for the SPI interface |
aplatanado |
0:782f2061a8f5 | 153 | // @param miso MISO pin for the SPI interface |
aplatanado |
0:782f2061a8f5 | 154 | // @param sclk SCLK pin for the SPI interface |
aplatanado |
0:782f2061a8f5 | 155 | // @param spi_frequency SPI clock frequency in Hz up to MAX_SPI_PORT_FREQUENCY |
aplatanado |
0:782f2061a8f5 | 156 | // @param ncs A digital active-low output pin for sensor chip select |
aplatanado |
0:782f2061a8f5 | 157 | // @param motion A digital active-low input pin activated by the sensor when motion |
aplatanado |
0:782f2061a8f5 | 158 | // is detected |
aplatanado |
0:782f2061a8f5 | 159 | // |
aplatanado |
0:782f2061a8f5 | 160 | ADNS9500(PinName mosi, PinName miso, PinName sclk, PinName ncs, |
aplatanado |
0:782f2061a8f5 | 161 | int spi_frequency = MAX_SPI_FREQUENCY, PinName motion = NC); |
aplatanado |
0:782f2061a8f5 | 162 | |
aplatanado |
0:782f2061a8f5 | 163 | // |
aplatanado |
0:782f2061a8f5 | 164 | // Destroy de sensor interface |
aplatanado |
0:782f2061a8f5 | 165 | // |
aplatanado |
0:782f2061a8f5 | 166 | ~ADNS9500(); |
aplatanado |
0:782f2061a8f5 | 167 | |
aplatanado |
0:782f2061a8f5 | 168 | // |
aplatanado |
0:782f2061a8f5 | 169 | // Power up/reset the sensor |
aplatanado |
0:782f2061a8f5 | 170 | // Terminate with error if the connection can not be established |
aplatanado |
0:782f2061a8f5 | 171 | // |
aplatanado |
0:782f2061a8f5 | 172 | // @param firmware If the firmware has to be downloaded, C-string containing the name |
aplatanado |
0:782f2061a8f5 | 173 | // of the file where it is stored, or NULL in other case |
aplatanado |
0:782f2061a8f5 | 174 | // |
xxann5 | 15:85ea51a56fdc | 175 | void reset(const uint8_t* fw = NULL, uint16_t fw_len = 0 ); |
aplatanado |
0:782f2061a8f5 | 176 | |
aplatanado |
0:782f2061a8f5 | 177 | // |
aplatanado |
0:782f2061a8f5 | 178 | // Shutdown the sensor |
aplatanado |
0:782f2061a8f5 | 179 | // |
aplatanado |
0:782f2061a8f5 | 180 | void shutdown(); |
aplatanado |
0:782f2061a8f5 | 181 | |
aplatanado |
0:782f2061a8f5 | 182 | // |
aplatanado |
0:782f2061a8f5 | 183 | // Read the value of a sensor register |
aplatanado |
0:782f2061a8f5 | 184 | // |
aplatanado |
0:782f2061a8f5 | 185 | // @param lregister The register which to read its value |
aplatanado |
0:782f2061a8f5 | 186 | // @return The value of the register |
aplatanado |
0:782f2061a8f5 | 187 | // |
aplatanado |
0:782f2061a8f5 | 188 | int read(Register lregister); |
aplatanado |
0:782f2061a8f5 | 189 | |
aplatanado |
0:782f2061a8f5 | 190 | // |
aplatanado |
0:782f2061a8f5 | 191 | // Read the values of sensor registers |
aplatanado |
0:782f2061a8f5 | 192 | // |
aplatanado |
0:782f2061a8f5 | 193 | // @param uregister The register which to read the upper byte |
aplatanado |
0:782f2061a8f5 | 194 | // @param lregister The register which to read the lower byte |
aplatanado |
0:782f2061a8f5 | 195 | // @return The values of registers as a 16-bit integer, putting the value |
aplatanado |
0:782f2061a8f5 | 196 | // of uregister in the upper byte and the value of lregister in the |
aplatanado |
0:782f2061a8f5 | 197 | // lower byte |
aplatanado |
0:782f2061a8f5 | 198 | // |
aplatanado |
0:782f2061a8f5 | 199 | int read(Register uregister, Register lregister); |
aplatanado |
0:782f2061a8f5 | 200 | |
aplatanado |
0:782f2061a8f5 | 201 | // |
aplatanado |
0:782f2061a8f5 | 202 | // Get information about sensor status |
aplatanado |
0:782f2061a8f5 | 203 | // |
aplatanado |
0:782f2061a8f5 | 204 | // @return The value of MOTION register. It tells if motion or laser fault |
aplatanado |
0:782f2061a8f5 | 205 | // conditions have ocurred, laser power setting status and operating |
aplatanado |
0:782f2061a8f5 | 206 | // mode in current frame |
aplatanado |
0:782f2061a8f5 | 207 | // |
aplatanado |
0:782f2061a8f5 | 208 | int status() |
aplatanado |
0:782f2061a8f5 | 209 | { return read(MOTION); } |
aplatanado |
0:782f2061a8f5 | 210 | |
aplatanado |
0:782f2061a8f5 | 211 | // |
aplatanado |
0:782f2061a8f5 | 212 | // Download the firmware to the sensor SROM |
aplatanado |
0:782f2061a8f5 | 213 | // |
aplatanado |
0:782f2061a8f5 | 214 | // @param filename The name of the file which contains the sensor firmware |
aplatanado |
0:782f2061a8f5 | 215 | // @return The SROM CRC value |
aplatanado |
0:782f2061a8f5 | 216 | // |
xxann5 | 15:85ea51a56fdc | 217 | int sromDownload(const uint8_t*, uint16_t); |
aplatanado |
0:782f2061a8f5 | 218 | |
aplatanado |
0:782f2061a8f5 | 219 | // |
aplatanado |
0:782f2061a8f5 | 220 | // Enable the laser |
aplatanado |
0:782f2061a8f5 | 221 | // |
aplatanado |
0:782f2061a8f5 | 222 | // @param enable True if laser must be enabled, or false if laser must be disabled |
aplatanado |
0:782f2061a8f5 | 223 | // |
aplatanado |
0:782f2061a8f5 | 224 | void enableLaser(bool enable=true); |
xxann5 | 15:85ea51a56fdc | 225 | void getLaser(void); |
aplatanado |
0:782f2061a8f5 | 226 | |
aplatanado |
0:782f2061a8f5 | 227 | // |
aplatanado |
0:782f2061a8f5 | 228 | // Get motion deltas from sensor |
aplatanado |
0:782f2061a8f5 | 229 | // |
aplatanado |
0:782f2061a8f5 | 230 | // @param dx The component X of displacement |
aplatanado |
0:782f2061a8f5 | 231 | // @param dy The component Y of displacement |
aplatanado |
0:782f2061a8f5 | 232 | // @return True if motion was occurred since the last time the function was called, |
aplatanado |
0:782f2061a8f5 | 233 | // or false in other case |
aplatanado |
0:782f2061a8f5 | 234 | // |
aplatanado |
0:782f2061a8f5 | 235 | bool getMotionDelta(int& dx, int& dy); |
aplatanado |
0:782f2061a8f5 | 236 | |
aplatanado |
0:782f2061a8f5 | 237 | // |
aplatanado |
0:782f2061a8f5 | 238 | // Get motion deltas in mm. from sensor |
aplatanado |
0:782f2061a8f5 | 239 | // |
aplatanado |
0:782f2061a8f5 | 240 | // @param dx The component X of displacement in mm. |
aplatanado |
0:782f2061a8f5 | 241 | // @param dy The component Y of displacement in mm. |
aplatanado |
0:782f2061a8f5 | 242 | // @return True if motion was occurred since the last time the function was called, |
aplatanado |
0:782f2061a8f5 | 243 | // or false in other case |
aplatanado |
0:782f2061a8f5 | 244 | // |
aplatanado |
0:782f2061a8f5 | 245 | bool getMotionDeltaMM(float& dx, float& dy); |
aplatanado |
0:782f2061a8f5 | 246 | |
aplatanado |
0:782f2061a8f5 | 247 | // |
aplatanado |
0:782f2061a8f5 | 248 | // Get all information about motion |
aplatanado |
0:782f2061a8f5 | 249 | // |
aplatanado |
0:782f2061a8f5 | 250 | // @param data The struct where sensor data will be stored |
aplatanado |
0:782f2061a8f5 | 251 | // @return True if motion was occurred since the last time the function was called, |
aplatanado |
0:782f2061a8f5 | 252 | // or false in other case |
aplatanado |
0:782f2061a8f5 | 253 | // |
aplatanado |
0:782f2061a8f5 | 254 | bool getMotionData(MotionData& data); |
aplatanado |
0:782f2061a8f5 | 255 | |
aplatanado |
0:782f2061a8f5 | 256 | // |
aplatanado |
0:782f2061a8f5 | 257 | // Set the resolution on XY axes together |
aplatanado |
0:782f2061a8f5 | 258 | // |
aplatanado |
0:782f2061a8f5 | 259 | // @param xy_resolution The resolution for X-axis and Y-axis |
aplatanado |
0:782f2061a8f5 | 260 | // |
aplatanado |
0:782f2061a8f5 | 261 | void setResolution(Resolution xy_resolution); |
aplatanado |
0:782f2061a8f5 | 262 | |
aplatanado |
0:782f2061a8f5 | 263 | // |
aplatanado |
0:782f2061a8f5 | 264 | // Set the resolutions on X-axis and Y-axis |
aplatanado |
0:782f2061a8f5 | 265 | // |
aplatanado |
0:782f2061a8f5 | 266 | // @param x_resolution The resolution for X-axis |
aplatanado |
0:782f2061a8f5 | 267 | // @param y_resolution The resolution for Y-axis |
aplatanado |
0:782f2061a8f5 | 268 | // |
aplatanado |
0:782f2061a8f5 | 269 | void setResolution(Resolution x_resolution, Resolution y_resolution); |
aplatanado |
0:782f2061a8f5 | 270 | |
aplatanado |
0:782f2061a8f5 | 271 | // |
aplatanado |
0:782f2061a8f5 | 272 | // Get a full array of pixel values from a single frame. |
aplatanado |
0:782f2061a8f5 | 273 | // This disables navigation and overwrites any donwloaded firmware, |
aplatanado |
0:782f2061a8f5 | 274 | // so call to reset() is needed to restore them |
aplatanado |
0:782f2061a8f5 | 275 | // |
aplatanado | 3:898ed1944119 | 276 | // @param pixels A pointer to the array where pixel values will be stored |
aplatanado |
0:782f2061a8f5 | 277 | // |
aplatanado | 3:898ed1944119 | 278 | void captureFrame(uint8_t* pixels); |
aplatanado |
0:782f2061a8f5 | 279 | |
aplatanado |
0:782f2061a8f5 | 280 | // |
aplatanado |
0:782f2061a8f5 | 281 | // Member function invoked when motion has ocurred and if a motion pin |
aplatanado |
0:782f2061a8f5 | 282 | // was specified when the object constructor was called. |
aplatanado |
0:782f2061a8f5 | 283 | // By default it invokes the function specified by a previous call to attach() |
aplatanado |
0:782f2061a8f5 | 284 | // |
aplatanado |
0:782f2061a8f5 | 285 | virtual void motionTrigger() |
aplatanado |
0:782f2061a8f5 | 286 | { motionTrigger_.call(); } |
aplatanado |
0:782f2061a8f5 | 287 | |
aplatanado |
0:782f2061a8f5 | 288 | // |
aplatanado |
0:782f2061a8f5 | 289 | // Attach a function to call when a falling edge occurs on motion pin |
aplatanado |
0:782f2061a8f5 | 290 | // |
aplatanado |
0:782f2061a8f5 | 291 | // @param function A pointer to a function or 0 to set the attached function as none |
aplatanado |
0:782f2061a8f5 | 292 | // |
aplatanado |
0:782f2061a8f5 | 293 | void attach(void (*function)(void)) |
aplatanado |
0:782f2061a8f5 | 294 | { motionTrigger_.attach(function); } |
aplatanado |
0:782f2061a8f5 | 295 | |
aplatanado |
0:782f2061a8f5 | 296 | // |
aplatanado |
0:782f2061a8f5 | 297 | // Attach a member function to call when a falling edge occurs on motion pin |
aplatanado |
0:782f2061a8f5 | 298 | // |
aplatanado |
0:782f2061a8f5 | 299 | // @param object A reference to the object to call the member function on |
aplatanado |
0:782f2061a8f5 | 300 | // @param function A pointer to the member function to be called |
aplatanado |
0:782f2061a8f5 | 301 | // |
aplatanado |
0:782f2061a8f5 | 302 | template<typename T> |
aplatanado |
0:782f2061a8f5 | 303 | void attach(T& object, void (T::*member)(void)) |
aplatanado |
0:782f2061a8f5 | 304 | { motionTrigger_.attach(object, member); } |
aplatanado |
0:782f2061a8f5 | 305 | |
aplatanado |
0:782f2061a8f5 | 306 | private: |
aplatanado |
0:782f2061a8f5 | 307 | SPI spi_; |
aplatanado |
0:782f2061a8f5 | 308 | InterruptIn motion_; |
aplatanado |
0:782f2061a8f5 | 309 | DigitalOut ncs_; |
aplatanado | 2:ee0c13ef1320 | 310 | |
aplatanado |
0:782f2061a8f5 | 311 | bool enabled_; |
aplatanado |
0:782f2061a8f5 | 312 | int xCpi_, yCpi_; |
aplatanado |
0:782f2061a8f5 | 313 | |
aplatanado |
0:782f2061a8f5 | 314 | FunctionPointer motionTrigger_; |
aplatanado | 2:ee0c13ef1320 | 315 | |
aplatanado | 2:ee0c13ef1320 | 316 | // |
aplatanado | 2:ee0c13ef1320 | 317 | // Write a byte to the specified register |
aplatanado | 2:ee0c13ef1320 | 318 | // |
aplatanado | 2:ee0c13ef1320 | 319 | // @param address The register address |
aplatanado | 2:ee0c13ef1320 | 320 | // @param value The value to be written to the register |
aplatanado | 2:ee0c13ef1320 | 321 | // |
aplatanado | 2:ee0c13ef1320 | 322 | void spiSend(Register address, int value); |
aplatanado | 2:ee0c13ef1320 | 323 | |
aplatanado | 2:ee0c13ef1320 | 324 | // |
aplatanado | 2:ee0c13ef1320 | 325 | // Read a byte from the specified register |
aplatanado | 2:ee0c13ef1320 | 326 | // |
aplatanado | 2:ee0c13ef1320 | 327 | // @param address The register address |
aplatanado | 2:ee0c13ef1320 | 328 | // @return The value of the register |
aplatanado | 2:ee0c13ef1320 | 329 | // |
aplatanado | 2:ee0c13ef1320 | 330 | int spiReceive(Register address); |
aplatanado |
0:782f2061a8f5 | 331 | }; |
aplatanado |
0:782f2061a8f5 | 332 | } |
aplatanado |
0:782f2061a8f5 | 333 | |
aplatanado |
0:782f2061a8f5 | 334 | #endif /* ADNS9500_HPP_ */ |