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;
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
enum SPIClockPolarity cpol
clock polarity control
enum SPIClockPhase cpha
clock phase control
enum SPISlaveSelect select
slave selection behavior
SPICallback before_cb
NULL or function called before the transaction.
SPICallback after_cb
NULL or function called after the transaction.
enum SPIDataSizeSelect dss
data transfer word size
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
uint16_t input_length
number of data words to read
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
volatile uint8_t * input_buf
pointer to receive buffer for DMA
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
enum SPIBitOrder bitorder
MSB/LSB order.
uint16_t output_length
number of data words to write
enum SPITransactionStatus status
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
static bool spi_blocking_transceive(struct spi_periph *p, struct spi_transaction *t)
Perform a spi transaction (blocking).
@ SPICpolIdleLow
CPOL = 0.
@ SPISelect
slave is selected before transaction but not unselected
@ SPISelectUnselect
slave is selected before transaction and unselected after
@ SPIUnselect
slave is not selected but unselected after transaction
SPI peripheral structure.
static uint8_t readRegister_blocking(struct pmw3901_t *pmw, uint8_t addr)
#define PMW3901_RAD_PER_PX
#define PMW3901_REG_MOTION
bool pmw3901_is_idle(struct pmw3901_t *pmw)
void pmw3901_start_read(struct pmw3901_t *pmw)
static bool readRegister_nonblocking(struct pmw3901_t *pmw, uint8_t addr, uint8_t *value)
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)
void pmw3901_event(struct pmw3901_t *pmw)
#define PMW3901_REG_DELTA_X_H
#define readRegister(_addr)
bool pmw3901_data_available(struct pmw3901_t *pmw)
#define PMW3901_REG_DELTA_X_L
#define PMW3901_REG_DELTA_Y_H
#define writeRegister(_addr, _data)
bool pmw3901_get_data(struct pmw3901_t *pmw, int16_t *delta_x, int16_t *delta_y)
#define PMW3901_REG_DELTA_Y_L
static void initializeSensor(struct pmw3901_t *pmw)
volatile uint8_t spi_output_buf[SPI_BUFFER_SIZE]
struct spi_periph * periph
volatile uint8_t spi_input_buf[SPI_BUFFER_SIZE]
struct spi_transaction trans
uint32_t readwrite_timeout
@ PMW3901_READ_DELTAXHIGH
@ PMW3901_READ_DELTAYHIGH
Architecture independent timing functions.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.