#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
#define ADNS7530_NORMAL_OPERATION 0x00 |
Definition at line 20 of file lib_adns7530.h.
#define ADNS7530_FORCE_REST1 0x10 |
Definition at line 21 of file lib_adns7530.h.
#define ADNS7530_FORCE_REST2 0x20 |
Definition at line 22 of file lib_adns7530.h.
#define ADNS7530_FORCE_REST3 0x30 |
Definition at line 23 of file lib_adns7530.h.
#define ADNS7530_FORCE_AWAKE 0x08 |
Definition at line 26 of file lib_adns7530.h.
#define ADNS7530_2MS_RUN_RATE 0x00 |
Definition at line 27 of file lib_adns7530.h.
#define ADNS7530_3MS_RUN_RATE 0x01 |
Definition at line 28 of file lib_adns7530.h.
#define ADNS7530_4MS_RUN_RATE 0x02 |
Definition at line 29 of file lib_adns7530.h.
#define ADNS7530_5MS_RUN_RATE 0x03 |
Definition at line 30 of file lib_adns7530.h.
#define ADNS7530_6MS_RUN_RATE 0x04 |
Definition at line 31 of file lib_adns7530.h.
#define ADNS7530_7MS_RUN_RATE 0x05 |
Definition at line 32 of file lib_adns7530.h.
#define ADNS7530_8MS_RUN_RATE 0x06 |
Definition at line 33 of file lib_adns7530.h.
#define ADNS7530_RES1600CPI 0x60 |
Definition at line 34 of file lib_adns7530.h.
#define ADNS7530_RES1200CPI 0x40 |
Definition at line 35 of file lib_adns7530.h.
#define ADNS7530_RES800CPI 0x20 |
Definition at line 36 of file lib_adns7530.h.
#define ADNS7530_RES400CPI 0x00 |
Definition at line 37 of file lib_adns7530.h.
#define ADNS7530_POWERUPRESET_INIT 0x5A |
Definition at line 39 of file lib_adns7530.h.
#define ADNS7530_LASERCTRL0_DEBUG 0xC0 |
Definition at line 41 of file lib_adns7530.h.
#define ADNS7530_LASERCTRL1_DEBUG 0x00 |
Definition at line 42 of file lib_adns7530.h.
#define ADNS7530_LSRPWRCFG0_DEBUG 0x80 |
Definition at line 43 of file lib_adns7530.h.
#define ADNS7530_LSRPWRCFG1_DEBUG 0x7F |
Definition at line 44 of file lib_adns7530.h.
#define ADNS7530_PRODUCTID_ADDR 0x00 |
Definition at line 47 of file lib_adns7530.h.
#define ADNS7530_REVISIONID_ADDR 0x01 |
Definition at line 48 of file lib_adns7530.h.
#define ADNS7530_MOTION_ADDR 0x02 |
Definition at line 49 of file lib_adns7530.h.
#define ADNS7530_DELTAX_L_ADDR 0x03 |
Definition at line 50 of file lib_adns7530.h.
#define ADNS7530_DELTAY_L_ADDR 0x04 |
Definition at line 51 of file lib_adns7530.h.
#define ADNS7530_DELTAXY_H_ADDR 0x05 |
Definition at line 52 of file lib_adns7530.h.
#define ADNS7530_SQUAL_ADDR 0x06 |
Definition at line 53 of file lib_adns7530.h.
#define ADNS7530_SHUTTER_UPPER_ADDR 0x07 |
Definition at line 54 of file lib_adns7530.h.
#define ADNS7530_SHUTTER_LOWER_ADDR 0x08 |
Definition at line 55 of file lib_adns7530.h.
#define ADNS7530_MAXIMUM_PIXEL_ADDR 0x09 |
Definition at line 56 of file lib_adns7530.h.
#define ADNS7530_PIXEL_SUM_ADDR 0x0A |
Definition at line 57 of file lib_adns7530.h.
#define ADNS7530_MINIMUM_PIXEL_ADDR 0x0B |
Definition at line 58 of file lib_adns7530.h.
#define ADNS7530_CRC0_ADDR 0x0C |
Definition at line 59 of file lib_adns7530.h.
#define ADNS7530_CRC1_ADDR 0x0D |
Definition at line 60 of file lib_adns7530.h.
#define ADNS7530_CRC2_ADDR 0x0E |
Definition at line 61 of file lib_adns7530.h.
#define ADNS7530_CRC3_ADDR 0x0F |
Definition at line 62 of file lib_adns7530.h.
#define ADNS7530_SELFTEST_ADDR 0x10 |
Definition at line 63 of file lib_adns7530.h.
#define ADNS7530_CONFIG2_BITS_ADDR 0x12 |
Definition at line 65 of file lib_adns7530.h.
#define ADNS7530_RUN_DOWNSHIFT_ADDR 0x13 |
Definition at line 66 of file lib_adns7530.h.
#define ADNS7530_REST1_RATE_ADDR 0x14 |
Definition at line 67 of file lib_adns7530.h.
#define ADNS7530_REST1_DOWNSHITF_ADDR 0x15 |
Definition at line 68 of file lib_adns7530.h.
#define ADNS7530_REST2_RATE_ADDR 0x16 |
Definition at line 69 of file lib_adns7530.h.
#define ADNS7530_REST2_DOWNSHITF_ADDR 0x17 |
Definition at line 70 of file lib_adns7530.h.
#define ADNS7530_REST3_RATE_ADDR 0x18 |
Definition at line 71 of file lib_adns7530.h.
#define ADNS7530_LASERCTRL0_ADDR 0x1A |
Definition at line 73 of file lib_adns7530.h.
#define ADNS7530_LSRPWRCFG0_ADDR 0x1C |
Definition at line 74 of file lib_adns7530.h.
#define ADNS7530_LSRPWRCFG1_ADDR 0x1D |
Definition at line 75 of file lib_adns7530.h.
#define ADNS7530_LASERCTRL1_ADDR 0x1F |
Definition at line 76 of file lib_adns7530.h.
#define ADNS7530_OBSERVATION_ADDR 0x2E |
Definition at line 78 of file lib_adns7530.h.
#define ADNS7530_PIXEL_GRAB_ADDR 0x35 |
Definition at line 80 of file lib_adns7530.h.
#define ADNS7530_POWERUPRESET_ADDR 0x3A |
Definition at line 82 of file lib_adns7530.h.
#define ADNS7530_SHUTDOWN_ADDR 0x3B |
Definition at line 83 of file lib_adns7530.h.
#define ADNS7530_AUTO_RUN_ADDR 0x3D |
Definition at line 85 of file lib_adns7530.h.
#define ADNS7530_INVERSEREVISIONID_ADDR 0x3E |
Definition at line 86 of file lib_adns7530.h.
#define ADNS7530_INVERSEPRODUCTID_ADDR 0x3F |
Definition at line 87 of file lib_adns7530.h.
#define ADNS7530_MOTIONBURST_ADDR 0x42 |
Definition at line 89 of file lib_adns7530.h.
#define ADNS7530_WRITE 0x80 |
Definition at line 92 of file lib_adns7530.h.
#define ADNS7530_READ 0x00 |
Definition at line 93 of file lib_adns7530.h.
#define ADNS7530_DUMMYDATA 0xFF |
Definition at line 94 of file lib_adns7530.h.
void hal_adns7530_enable | ( | void | ) |
Definition at line 30 of file lib_adns7530.c.
{ SPI_CS = 0; uSecDelay(15); }
void hal_adns7530_disable | ( | void | ) |
Definition at line 36 of file lib_adns7530.c.
{ uSecDelay(10); SPI_CS = 1; }
uint8_t hal_adns7530_readRegister | ( | uint8_t | regAddress ) |
Definition at line 42 of file lib_adns7530.c.
{ uint8_t returnVal; hal_adns7530_enable(); hal_spi_master_read_write(regAddress); // Supply the register address to read from uSecDelay(10); returnVal = hal_spi_master_read_write(0); hal_adns7530_disable(); return (returnVal); }
void hal_adns7530_writeRegister | ( | uint8_t | regAddress, |
uint8_t | innData | ||
) |
Definition at line 53 of file lib_adns7530.c.
{ hal_adns7530_enable(); hal_spi_master_read_write(ADNS7530_WRITE | regAddress); // Supply the register address to write to uSecDelay(10); hal_spi_master_read_write(innData); // Send out the data to be written to that register address hal_adns7530_disable(); }
void hal_adns7530_init | ( | ) |
Definition at line 62 of file lib_adns7530.c.
{ // One-time initialization for ADNS-7530 optical sensor hal_adns7530_writeRegister(ADNS7530_POWERUPRESET_ADDR, ADNS7530_POWERUPRESET_INIT); // Power Up Reset register data frameDelay(); hal_adns7530_writeRegister(ADNS7530_OBSERVATION_ADDR, 0x00); frameDelay(); hal_adns7530_readRegister(ADNS7530_OBSERVATION_ADDR); frameDelay(); hal_adns7530_readRegister(ADNS7530_MOTION_ADDR); hal_adns7530_readRegister(ADNS7530_DELTAX_L_ADDR); hal_adns7530_readRegister(ADNS7530_DELTAY_L_ADDR); hal_adns7530_readRegister(ADNS7530_DELTAXY_H_ADDR); hal_adns7530_writeRegister(0x3c,0x27); hal_adns7530_writeRegister(0x22,0x0a); hal_adns7530_writeRegister(0x21,0x01); hal_adns7530_writeRegister(0x3c,0x32); hal_adns7530_writeRegister(0x23,0x20) ; hal_adns7530_writeRegister(0x3c,0x05); frameDelay(); // Delay to wait until sensor fully reset hal_adns7530_writeRegister(ADNS7530_LSRPWRCFG0_ADDR, 0x7f); // LSRPWR CFG0 register data hal_adns7530_writeRegister(ADNS7530_LSRPWRCFG1_ADDR, 0x80); // LSRPWR CFG1 register data hal_adns7530_writeRegister(ADNS7530_LASERCTRL0_ADDR, 0xc0); // LASER CTRL0 register data hal_adns7530_writeRegister(ADNS7530_LASERCTRL1_ADDR, 0x00); // LASER CTRL1 register data hal_adns7530_writeRegister(ADNS7530_CONFIG2_BITS_ADDR, ADNS7530_RES800CPI | ADNS7530_8MS_RUN_RATE); }
_Bool hal_adns7530_readMotionBurst | ( | int16_t * | deltaX, |
int16_t * | deltaY | ||
) |
Definition at line 107 of file lib_adns7530.c.
{ uint8_t motion; int16_t deltaX_l, deltaY_l, deltaX_h, deltaY_h, deltaXY_h; hal_adns7530_enable(); hal_spi_master_read_write(ADNS7530_MOTIONBURST_ADDR); uSecDelay(10); motion = hal_spi_master_read_write(0); deltaX_l = hal_spi_master_read_write(0); // Low byte deltaY_l = hal_spi_master_read_write(0); // Low byte deltaXY_h = hal_spi_master_read_write(0); // XY High nibble deltaX_h = ((int16_t)deltaXY_h << 4) & 0xF00; if(deltaX_h & 0x800) { deltaX_h |= 0xf000; } deltaY_h = ((int16_t)deltaXY_h << 8) & 0xF00; if(deltaY_h & 0x800) { deltaY_h |= 0xf000; } *deltaX = deltaX_h | deltaX_l; *deltaY = deltaY_h | deltaY_l; hal_adns7530_disable(); // If motion occured if(motion & 0x80) { return true; } else { return false; } }
void hal_adns7530_mod_cpi | ( | ) |
Definition at line 95 of file lib_adns7530.c.
{ static xdata uint8_t cpi = ADNS7530_RES800CPI; cpi += 0x20; if(cpi > 0x60) { cpi = 0; } hal_adns7530_writeRegister(ADNS7530_CONFIG2_BITS_ADDR, cpi | ADNS7530_8MS_RUN_RATE); }