techmannih/nema34-mounted-stepper-controller

A 48 V USB‑C PD 3.1 EPR NEMA‑34 stepper controller PCB combining STM32/TMC5160 control, external MOSFET motor bridges, protected power and regenerative braking, USB data, telemetry, diagnostics, status LEDs, and buzzer alarms.

Version
0.3.92
License
unset
Stars
1

firmware/include/tmc5160.h

#pragma once
#include <stdbool.h>
#include <stdint.h>

typedef bool (*pd1180_spi_frame_fn)(void *context, const uint8_t tx[5], uint8_t rx[5]);
typedef struct {
  pd1180_spi_frame_fn frame;
  void *context;
  bool configured;
  uint32_t chopconf;
  uint8_t irun;
} pd1180_tmc_t;
typedef struct {
  uint32_t ioin, gstat, drv_status;
  bool valid, fault;
} pd1180_tmc_status_t;

bool pd1180_tmc_read(pd1180_tmc_t *driver, uint8_t address, uint32_t *value);
bool pd1180_tmc_write(pd1180_tmc_t *driver, uint8_t address, uint32_t value);
bool pd1180_tmc_status(pd1180_tmc_t *driver, pd1180_tmc_status_t *status);
/* Caller must hold DRV_ENN high and hold SD_MODE low before initialization.
 * No OTP writes. Bridge timing/short thresholds keep manufacturer defaults
 * pending scope qualification. This function leaves TOFF=0 (bridge disabled). */
bool pd1180_tmc_configure_ramp(pd1180_tmc_t *driver, uint16_t current_permille);
bool pd1180_tmc_set_current(pd1180_tmc_t *driver, uint16_t current_permille);
bool pd1180_tmc_set_chopper(pd1180_tmc_t *driver, bool enabled);
void pd1180_tmc_invalidate(pd1180_tmc_t *driver);

/* Bounded commissioning profile; caller must first qualify and enable the bridge. */
bool pd1180_tmc_velocity(pd1180_tmc_t *driver, uint32_t target);
bool pd1180_tmc_actual_velocity(pd1180_tmc_t *driver, int32_t *velocity);