Functions

lib/adns7530/lib_adns7530.c File Reference

#include "nrf24le1.h"
#include "lib_adns7530.h"
#include "hal_spi.h"
#include "nrfr_mouse.h"

Go to the source code of this file.

Functions

void uSecDelay (uint8_t len)
void frameDelay ()
void hal_adns7530_enable (void)
void hal_adns7530_disable (void)
uint8_t hal_adns7530_readRegister (uint8_t regAddress)
void hal_adns7530_writeRegister (uint8_t regAddress, uint8_t innData)
void hal_adns7530_init ()
void hal_adns7530_mod_cpi ()
_Bool hal_adns7530_readMotionBurst (int16_t *deltaX, int16_t *deltaY)

Function Documentation

void uSecDelay ( uint8_t  len )

Definition at line 19 of file lib_adns7530.c.

{
  len += (len>>1);
  while(len--);
}
void frameDelay (  )

Definition at line 25 of file lib_adns7530.c.

{
  uint8_t frameDel = 200;
  while(frameDel--)uSecDelay(98);
}
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 (  )
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);
}
_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;
  }
}