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

ACwing Flow rev A bridge firmware (STM32C011F4U6). More...

#include "stm32c0xx.h"
#include "bridge.h"
#include "pmw3901.h"
#include "flow_regs.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define SYSCLK_HZ   48000000u
 
#define LOOP_MS   10u
 
#define REINIT_MS   1000u
 

Functions

void SysTick_Handler (void)
 
static void iwdg_feed (void)
 
static void clock_init (void)
 
static void gpio_mode (GPIO_TypeDef *g, uint32_t pin, uint32_t mode, uint32_t af)
 
static void board_init (void)
 
static void iwdg_start (void)
 
void I2C1_IRQHandler (void)
 
static void delay_us (uint32_t us)
 
static uint8_t spi_xfer (uint8_t b)
 
static void pin_cs (uint8_t l)
 
static void pin_reset (uint8_t l)
 
static void led (uint8_t on)
 
int main (void)
 

Variables

static volatile uint32_t s_ms
 
static const pmw_bus_t k_bus = { spi_xfer, pin_cs, pin_reset, delay_us }
 

Detailed Description

ACwing Flow rev A bridge firmware (STM32C011F4U6).

PMW3901 –SPI1 (mode 3, 1.5 MHz)--> STM32C011 –I2C1 target 0x3B--> Qwiic --> ACwing FC

Pins (ACwing_Flow_A schematic, checked against ST open pin data): PA0 TOF_XSHUT left in its reset state (analog, high impedance): the 10 k pull-up keeps the VL53L1X running. Never drive it low. PA1 TOF_INT not used (the FC polls the ToF), high impedance PA2 PMW_NRESET output, high = running PA3 PMW_MOTION not used (motion burst polled at 100 Hz) PA4 PMW_NCS output, high = deselected PA5/6/7 SPI1 SCK / MISO / MOSI (AF0) PA8 LED_K output, low = LED on PA13/PA14 SWD (untouched) PB6/PB7 I2C1 SCL / SDA (AF6, open drain, pull-ups on the FC)

Main loop: every 10 ms a motion burst; the deltas of good samples are added to the accumulators with the time they cover (bridge.c). The I2C interrupt serves the register map and latches a frame when the FC reads from 0x02. The independent watchdog (~0.5 s) is fed by the main loop only.

LED: on = sensor OK and the FC reading frames; slow blink (1 Hz) = sensor OK, no reads from the FC; fast blink (5 Hz) = PMW3901 not found (retried every second); short flash every 2 s = sensor OK but no surface features.

Definition in file main.c.

Macro Definition Documentation

◆ SYSCLK_HZ

#define SYSCLK_HZ   48000000u

Definition at line 33 of file main.c.

◆ LOOP_MS

#define LOOP_MS   10u

Definition at line 34 of file main.c.

◆ REINIT_MS

#define REINIT_MS   1000u

Definition at line 35 of file main.c.

Function Documentation

◆ SysTick_Handler()

void SysTick_Handler ( void  )

Definition at line 39 of file main.c.

References s_ms.

◆ iwdg_feed()

static void iwdg_feed ( void  )
static

Definition at line 42 of file main.c.

Referenced by delay_us(), iwdg_start(), and main().

Here is the caller graph for this function:

◆ clock_init()

static void clock_init ( void  )
static

Definition at line 44 of file main.c.

References SYSCLK_HZ.

Referenced by main().

Here is the caller graph for this function:

◆ gpio_mode()

static void gpio_mode ( GPIO_TypeDef *  g,
uint32_t  pin,
uint32_t  mode,
uint32_t  af 
)
static

Definition at line 54 of file main.c.

Referenced by board_init().

Here is the caller graph for this function:

◆ board_init()

static void board_init ( void  )
static

Definition at line 62 of file main.c.

References FLOW_I2C_ADDR, gpio_mode(), and SYSCLK_HZ.

Referenced by main().

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

◆ iwdg_start()

static void iwdg_start ( void  )
static

Definition at line 109 of file main.c.

References iwdg_feed().

Referenced by main().

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

◆ I2C1_IRQHandler()

void I2C1_IRQHandler ( void  )

Definition at line 121 of file main.c.

References bridge_i2c_addr_read(), bridge_i2c_addr_write(), bridge_i2c_rx(), bridge_i2c_stop(), and bridge_i2c_tx().

Here is the call graph for this function:

◆ delay_us()

static void delay_us ( uint32_t  us)
static

Definition at line 146 of file main.c.

References iwdg_feed().

Here is the call graph for this function:

◆ spi_xfer()

static uint8_t spi_xfer ( uint8_t  b)
static

Definition at line 157 of file main.c.

◆ pin_cs()

static void pin_cs ( uint8_t  l)
static

Definition at line 165 of file main.c.

◆ pin_reset()

static void pin_reset ( uint8_t  l)
static

Definition at line 166 of file main.c.

◆ led()

static void led ( uint8_t  on)
static

Definition at line 167 of file main.c.

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( void  )

Definition at line 172 of file main.c.

References board_init(), bridge_add_sample(), bridge_init(), bridge_reads(), bridge_set_sensor_ok(), bridge_take_ctrl(), clock_init(), pmw_burst_t::dx, pmw_burst_t::dy, FLOW_CTRL_REINIT, FLOW_CTRL_RESET, iwdg_feed(), iwdg_start(), k_bus, led(), LOOP_MS, pmw_burst(), pmw_init(), pmw_valid(), REINIT_MS, s_ms, pmw_burst_t::shutter, and pmw_burst_t::squal.

Here is the call graph for this function:

Variable Documentation

◆ s_ms

volatile uint32_t s_ms
static

Definition at line 37 of file main.c.

Referenced by main(), and SysTick_Handler().

◆ k_bus

const pmw_bus_t k_bus = { spi_xfer, pin_cs, pin_reset, delay_us }
static

Definition at line 169 of file main.c.

Referenced by main().