36 #ifndef PMW3901_RAD_PER_PX
37 #define PMW3901_RAD_PER_PX 0.002443389
42 #ifndef PMW3901_SPI_CDIV
43 #define PMW3901_SPI_CDIV SPIDiv256
46 #define PMW3901_REG_MOTION 0x02
47 #define PMW3901_REG_DELTA_X_L 0x03
48 #define PMW3901_REG_DELTA_X_H 0x04
49 #define PMW3901_REG_DELTA_Y_L 0x05
50 #define PMW3901_REG_DELTA_Y_H 0x06
89 default:
return false;
119 #define writeRegister(_addr, _data) writeRegister_blocking(pmw, (_addr), (_data))
120 #define readRegister(_addr) readRegister_blocking(pmw, (_addr))
121 #define wait_ms(_ms) sys_time_usleep((_ms) * 1000)
276 switch (pmw->
state) {
282 if (!(temp & 0x80))
return;
294 pmw->
delta_x |= (temp << 8) & 0xFF00;
304 pmw->
delta_y |= (temp << 8) & 0xFF00;
enum SPIClockPolarity cpol
clock polarity control
volatile uint8_t spi_output_buf[SPI_BUFFER_SIZE]
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
uint16_t output_length
number of data words to write
slave is selected before transaction but not unselected
slave is not selected but unselected after transaction
#define writeRegister(_addr, _data)
uint32_t readwrite_timeout
bool pmw3901_get_data(struct pmw3901_t *pmw, int16_t *delta_x, int16_t *delta_y)
bool pmw3901_data_available(struct pmw3901_t *pmw)
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
enum SPIBitOrder bitorder
MSB/LSB order.
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
static bool spi_blocking_transceive(struct spi_periph *p, struct spi_transaction *t)
Perform a spi transaction (blocking).
enum SPISlaveSelect select
slave selection behavior
#define PMW3901_REG_DELTA_Y_H
enum SPIClockPhase cpha
clock phase control
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
struct spi_transaction trans
SPI peripheral structure.
static bool readRegister_nonblocking(struct pmw3901_t *pmw, uint8_t addr, uint8_t *value)
static void initializeSensor(struct pmw3901_t *pmw)
#define readRegister(_addr)
Architecture independent timing functions.
void pmw3901_init(struct pmw3901_t *pmw, struct spi_periph *periph, uint8_t slave_idx)
static void writeRegister_blocking(struct pmw3901_t *pmw, uint8_t addr, uint8_t data)
SPICallback after_cb
NULL or function called after the transaction.
void pmw3901_event(struct pmw3901_t *pmw)
void pmw3901_start_read(struct pmw3901_t *pmw)
bool pmw3901_is_idle(struct pmw3901_t *pmw)
static uint8_t readRegister_blocking(struct pmw3901_t *pmw, uint8_t addr)
#define PMW3901_REG_MOTION
#define PMW3901_RAD_PER_PX
uint16_t input_length
number of data words to read
#define PMW3901_REG_DELTA_Y_L
slave is selected before transaction and unselected after
volatile uint8_t spi_input_buf[SPI_BUFFER_SIZE]
enum SPIDataSizeSelect dss
data transfer word size
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
#define PMW3901_REG_DELTA_X_L
volatile uint8_t * input_buf
pointer to receive buffer for DMA
SPICallback before_cb
NULL or function called before the transaction.
struct spi_periph * periph
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
#define PMW3901_REG_DELTA_X_H
enum SPITransactionStatus status