ACwing Flow bridge firmware
STM32C011: PMW3901 optical flow over SPI, I2C target 0x3B
Loading...
Searching...
No Matches
pmw3901.c File Reference

PMW3901MB driver (see pmw3901.h). More...

#include "pmw3901.h"
Include dependency graph for pmw3901.c:

Go to the source code of this file.

Macros

#define PMW_PRODUCT_ID   0x49u
 
#define PMW_INV_PRODUCT_ID   0xB6u
 
#define PMW_REG_MOTION_BURST   0x16u
 

Functions

static void wr (uint8_t reg, uint8_t v)
 
static uint8_t rd (uint8_t reg)
 
int pmw_init (const pmw_bus_t *bus)
 0 = product id ok, configured
 
void pmw_burst (pmw_burst_t *b)
 motion burst (register 0x16)

 
uint8_t pmw_valid (const pmw_burst_t *b)
 PixArt rule: SQUAL < 0x19 with the shutter at its maximum = no usable features.
 

Variables

static const pmw_bus_t * s_b
 
static const uint8_t k_init1 [][2]
 
static const uint8_t k_init2 [][2]
 

Detailed Description

PMW3901MB driver (see pmw3901.h).

The power-up check and the "performance optimisation" register sequence are taken from the Bitcraze PMW3901 Arduino driver: Copyright (c) 2017 Bitcraze AB. MIT License: permission is hereby granted, free of charge, to deal in the Software without restriction, subject to including the copyright notice and this permission notice. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.

Definition in file pmw3901.c.

Macro Definition Documentation

◆ PMW_PRODUCT_ID

#define PMW_PRODUCT_ID   0x49u

Definition at line 14 of file pmw3901.c.

◆ PMW_INV_PRODUCT_ID

#define PMW_INV_PRODUCT_ID   0xB6u

Definition at line 15 of file pmw3901.c.

◆ PMW_REG_MOTION_BURST

#define PMW_REG_MOTION_BURST   0x16u

Definition at line 16 of file pmw3901.c.

Function Documentation

◆ wr()

static void wr ( uint8_t  reg,
uint8_t  v 
)
static

Definition at line 20 of file pmw3901.c.

References pmw_bus_t::cs, pmw_bus_t::delay_us, s_b, and pmw_bus_t::xfer.

Referenced by pmw_init().

Here is the caller graph for this function:

◆ rd()

static uint8_t rd ( uint8_t  reg)
static

Definition at line 31 of file pmw3901.c.

References pmw_bus_t::cs, pmw_bus_t::delay_us, s_b, and pmw_bus_t::xfer.

Referenced by pmw_init().

Here is the caller graph for this function:

◆ pmw_init()

int pmw_init ( const pmw_bus_t *  bus)

0 = product id ok, configured

Definition at line 59 of file pmw3901.c.

References pmw_bus_t::cs, pmw_bus_t::delay_us, k_init1, k_init2, PMW_INV_PRODUCT_ID, PMW_PRODUCT_ID, rd(), pmw_bus_t::reset, s_b, and wr().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmw_burst()

void pmw_burst ( pmw_burst_t *  b)

motion burst (register 0x16)

Definition at line 85 of file pmw3901.c.

References pmw_bus_t::cs, pmw_bus_t::delay_us, pmw_burst_t::dx, pmw_burst_t::dy, pmw_burst_t::motion, pmw_burst_t::observation, PMW_REG_MOTION_BURST, pmw_burst_t::raw_max, pmw_burst_t::raw_min, pmw_burst_t::raw_sum, s_b, pmw_burst_t::shutter, pmw_burst_t::squal, and pmw_bus_t::xfer.

Referenced by main().

Here is the caller graph for this function:

◆ pmw_valid()

uint8_t pmw_valid ( const pmw_burst_t *  b)

PixArt rule: SQUAL < 0x19 with the shutter at its maximum = no usable features.

Definition at line 106 of file pmw3901.c.

References pmw_burst_t::shutter, and pmw_burst_t::squal.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ s_b

const pmw_bus_t* s_b
static

Definition at line 18 of file pmw3901.c.

Referenced by pmw_burst(), pmw_init(), rd(), and wr().

◆ k_init1

const uint8_t k_init1[][2]
static
Initial value:
= {
{0x7F,0x00},{0x61,0xAD},{0x7F,0x03},{0x40,0x00},{0x7F,0x05},{0x41,0xB3},{0x43,0xF1},{0x45,0x14},
{0x5B,0x32},{0x5F,0x34},{0x7B,0x08},{0x7F,0x06},{0x44,0x1B},{0x40,0xBF},{0x4E,0x3F},{0x7F,0x08},
{0x65,0x20},{0x6A,0x18},{0x7F,0x09},{0x4F,0xAF},{0x5F,0x40},{0x48,0x80},{0x49,0x80},{0x57,0x77},
{0x60,0x78},{0x61,0x78},{0x62,0x08},{0x63,0x50},{0x7F,0x0A},{0x45,0x60},{0x7F,0x00},{0x4D,0x11},
{0x55,0x80},{0x74,0x1F},{0x75,0x1F},{0x4A,0x78},{0x4B,0x78},{0x44,0x08},{0x45,0x50},{0x64,0xFF},
{0x65,0x1F},{0x7F,0x14},{0x65,0x60},{0x66,0x08},{0x63,0x78},{0x7F,0x15},{0x48,0x58},{0x7F,0x07},
{0x41,0x0D},{0x43,0x14},{0x4B,0x0E},{0x45,0x0F},{0x44,0x42},{0x4C,0x80},{0x7F,0x10},{0x5B,0x02},
{0x7F,0x07},{0x40,0x41},{0x70,0x00}
}

Definition at line 44 of file pmw3901.c.

Referenced by pmw_init().

◆ k_init2

const uint8_t k_init2[][2]
static
Initial value:
= {
{0x32,0x44},{0x7F,0x07},{0x40,0x40},{0x7F,0x06},{0x62,0xF0},{0x63,0x00},{0x7F,0x0D},{0x48,0xC0},
{0x6F,0xD5},{0x7F,0x00},{0x5B,0xA0},{0x4E,0xA8},{0x5A,0x50},{0x40,0x80}
}

Definition at line 54 of file pmw3901.c.

Referenced by pmw_init().