25static constexpr uint8_t REG_GCONF = 0x00;
26static constexpr uint8_t REG_GSTAT = 0x01;
27static constexpr uint8_t REG_IOIN = 0x06;
28static constexpr uint8_t REG_FACTORY_CONF = 0x07;
29static constexpr uint8_t REG_IHOLD_IRUN = 0x10;
30static constexpr uint8_t REG_TPOWERDOWN = 0x11;
31static constexpr uint8_t REG_TPWMTHRS = 0x13;
32static constexpr uint8_t REG_VACTUAL = 0x22;
33static constexpr uint8_t REG_CHOPCONF = 0x6C;
34static constexpr uint8_t REG_DRV_STATUS = 0x6F;
35static constexpr uint8_t REG_PWMCONF = 0x70;
36static constexpr uint8_t REG_PWM_SCALE = 0x71;
37static constexpr uint8_t REG_PWM_AUTO = 0x72;
40static constexpr std::array<uint8_t, 4> RESTORED_REGISTERS{REG_GCONF, REG_FACTORY_CONF, REG_CHOPCONF, REG_PWMCONF};
42static constexpr RegisterField I_SCALE_ANALOG{REG_GCONF, 0, 1,
false};
43static constexpr RegisterField INTERNAL_RSENSE{REG_GCONF, 1, 1,
false};
44static constexpr RegisterField EN_SPREADCYCLE{REG_GCONF, 2, 1,
false};
45static constexpr RegisterField SHAFT{REG_GCONF, 3, 1,
false};
46static constexpr RegisterField INDEX_OTPW{REG_GCONF, 4, 1,
false};
47static constexpr RegisterField INDEX_STEP{REG_GCONF, 5, 1,
false};
48static constexpr RegisterField PDN_DISABLE{REG_GCONF, 6, 1,
false};
49static constexpr RegisterField MSTEP_REG_SELECT{REG_GCONF, 7, 1,
false};
50static constexpr RegisterField MULTISTEP_FILT{REG_GCONF, 8, 1,
false};
51static constexpr RegisterField
VERSION{REG_IOIN, 24, 8,
false};
52static constexpr RegisterField OTTRIM{REG_FACTORY_CONF, 8, 2,
false};
53static constexpr RegisterField IHOLD{REG_IHOLD_IRUN, 0, 5,
false};
54static constexpr RegisterField IRUN{REG_IHOLD_IRUN, 8, 5,
false};
55static constexpr RegisterField IHOLDDELAY{REG_IHOLD_IRUN, 16, 4,
false};
56static constexpr RegisterField TPOWERDOWN{REG_TPOWERDOWN, 0, 8,
false};
57static constexpr RegisterField TPWMTHRS{REG_TPWMTHRS, 0, 20,
false};
58static constexpr RegisterField VACTUAL{REG_VACTUAL, 0, 24,
true};
59static constexpr RegisterField TOFF{REG_CHOPCONF, 0, 4,
false};
60static constexpr RegisterField HSTRT{REG_CHOPCONF, 4, 3,
false};
61static constexpr RegisterField HEND{REG_CHOPCONF, 7, 4,
false};
62static constexpr RegisterField TBL{REG_CHOPCONF, 15, 2,
false};
63static constexpr RegisterField VSENSE{REG_CHOPCONF, 17, 1,
false};
64static constexpr RegisterField MRES{REG_CHOPCONF, 24, 4,
false};
65static constexpr RegisterField INTPOL{REG_CHOPCONF, 28, 1,
false};
66static constexpr RegisterField DEDGE{REG_CHOPCONF, 29, 1,
false};
67static constexpr RegisterField CS_ACTUAL{REG_DRV_STATUS, 16, 5,
false};
68static constexpr RegisterField PWM_OFS{REG_PWMCONF, 0, 8,
false};
69static constexpr RegisterField PWM_GRAD{REG_PWMCONF, 8, 8,
false};
70static constexpr RegisterField PWM_FREQ{REG_PWMCONF, 16, 2,
false};
71static constexpr RegisterField PWM_AUTOSCALE{REG_PWMCONF, 18, 1,
false};
72static constexpr RegisterField PWM_AUTOGRAD{REG_PWMCONF, 19, 1,
false};
73static constexpr RegisterField FREEWHEEL{REG_PWMCONF, 20, 2,
false};
74static constexpr RegisterField PWM_REG{REG_PWMCONF, 24, 4,
false};
75static constexpr RegisterField PWM_LIM{REG_PWMCONF, 28, 4,
false};
76static constexpr RegisterField PWM_SCALE_SUM{REG_PWM_SCALE, 0, 8,
false};
77static constexpr RegisterField PWM_SCALE_AUTO{REG_PWM_SCALE, 16, 9,
true};
78static constexpr RegisterField PWM_OFS_AUTO{REG_PWM_AUTO, 0, 8,
false};
79static constexpr RegisterField PWM_GRAD_AUTO{REG_PWM_AUTO, 16, 8,
false};
125 void setup()
override;
126 void loop()
override;
BedjetMode mode
BedJet operating mode.
Helper class to request loop() to be called as fast as possible.
Base class for Trinamic stepper drivers that are configured over the single wire UART interface.
void set_step_pin(GPIOPin *pin)
int32_t speed_to_vactual_(float speed) const
void set_address(uint8_t address)
uint8_t status_poll_skip_
float initial_run_current_
void set_ottrim(uint8_t ottrim)
void set_enn_pin(GPIOPin *pin)
void apply_config_()
Write the settings from the configuration to the readable registers.
void set_irun(uint8_t irun)
void set_dir_pin(GPIOPin *pin)
void set_pwm_freq(uint8_t freq)
void on_shutdown() override
void set_tpowerdown(uint8_t tpowerdown)
std::array< uint32_t, RESTORED_REGISTERS.size()> restored_values_
bool write_register(uint8_t reg, uint32_t value)
static uint32_t extract_field(uint32_t data, const RegisterField &field)
int32_t get_vactual_() const
void set_microsteps(uint16_t microsteps)
void set_toff(uint8_t toff)
Chopper off time (1-15). TOFF=0 is used to disable the outputs, so this is applied on the next enable...
void add_on_status_callback(F &&callback)
Called with the condition and whether it became active or cleared.
optional< uint8_t > current_to_scale_(float current)
void set_pwm_grad(uint8_t grad)
float initial_hold_current_
void set_pwm_lim(uint8_t lim)
void set_vsense(bool vsense)
virtual uint32_t * shadow_register(uint8_t reg)
Return the cached value of a write-only register, or nullptr when the register is readable.
void set_ihold(uint8_t ihold)
virtual void restore_registers()
Write the cached write-only registers and the last written configuration registers to the driver,...
void set_pwm_ofs(uint8_t ofs)
uint32_t clock_frequency_
void set_hstrt(uint8_t hstrt)
void set_analog_current_scale(bool enable)
void set_iholddelay(uint8_t delay)
void set_enabled(bool enabled)
Enable or disable the motor outputs, using the ENN pin when configured and TOFF otherwise.
uint16_t get_microsteps()
void set_initial_hold_current(float current)
void set_standstill_mode(StandstillMode mode)
bool is_unreachable() const
True while the driver does not answer, until the status poll reads it again (every 10 s).
optional< uint32_t > read_register(uint8_t reg)
uint16_t initial_microsteps_
HighFrequencyLoopRequester high_freq_
optional< uint32_t > read_field(const RegisterField &field)
void set_diag_pin(InternalGPIOPin *pin)
IndexPulseStore index_store_
void set_clock_frequency(uint32_t frequency)
InternalGPIOPin * diag_pin_
void set_spreadcycle(bool enable)
void set_hold_current(float current)
float full_scale_current_()
void set_index_pin(InternalGPIOPin *pin)
LazyCallbackManager< void(DriverEvent, bool)> status_callback_
virtual uint8_t expected_version() const =0
IC version reported in IOIN by the supported chip.
float scale_to_current(uint8_t scale)
Convert a current scale (0-31) to A RMS, without analog current scale.
void set_hend(uint8_t hend)
float get_setup_priority() const override
void set_initial_microsteps(uint16_t microsteps)
void set_pwm_autoscale(bool enable)
void set_tbl(uint8_t tbl)
void dump_config() override
void set_pwm_reg(uint8_t reg)
InternalGPIOPin * index_pin_
void set_interpolation(bool enable)
uint8_t restored_written_
bool analog_current_scale_
bool update_status_()
Read GSTAT and DRV_STATUS and report changes. Returns false when the status could not be read.
optional< uint8_t > ottrim_
void set_run_current(float current)
Set the motor run or hold current in A RMS.
void set_tpwm_threshold(uint32_t threshold)
bool write_field(const RegisterField &field, uint32_t value)
void set_pwm_autograd(bool enable)
virtual void on_diag_without_error()
Called when DIAG rises without a driver error.
void set_initial_run_current(float current)
void set_rsense(float rsense)
void set_inverse_direction(bool inverse)
constexpr uint16_t VERSION
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
@ STANDSTILL_MODE_COIL_SHORT_HS
@ STANDSTILL_MODE_FREEWHEELING
@ STANDSTILL_MODE_COIL_SHORT_LS
DriverEvent
Driver conditions reported to on_status, in the order of their status bits: GSTAT bits 0-2,...
@ DRIVER_EVENT_TEMPERATURE_157C
@ DRIVER_EVENT_SHORT_TO_GROUND_B
@ DRIVER_EVENT_LOW_SIDE_SHORT_A
@ DRIVER_EVENT_CHARGE_PUMP_UNDERVOLTAGE
@ DRIVER_EVENT_DRIVER_ERROR
@ DRIVER_EVENT_TEMPERATURE_120C
@ DRIVER_EVENT_SHORT_TO_GROUND_A
@ DRIVER_EVENT_OVERTEMPERATURE_PREWARNING
@ DRIVER_EVENT_OPEN_LOAD_A
@ DRIVER_EVENT_TEMPERATURE_143C
@ DRIVER_EVENT_OVERTEMPERATURE
@ DRIVER_EVENT_TEMPERATURE_150C
@ DRIVER_EVENT_LOW_SIDE_SHORT_B
@ DRIVER_EVENT_OPEN_LOAD_B
void HOT delay(uint32_t ms)
Set by a rising edge on DIAG, which signals a driver error or, on chips that support it,...
static void gpio_intr(DiagPinStore *arg)
Counts the step pulses the driver reports on INDEX while it runs from VACTUAL.
static void gpio_intr(IndexPulseStore *arg)
volatile int8_t direction
A bit field inside one register.
constexpr uint32_t mask() const