Files

67 lines
3.8 KiB
C
Raw Permalink Normal View History

2026-03-31 13:10:37 +02:00
// Tmc2209.h
#ifndef TMC2209_H
#define TMC2209_H
#include "pico/stdlib.h"
#include "Tmc_uart.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <math.h>
#include <string.h>
typedef struct {
TMC_UART* serial_instance;
int mtr_id;
uint8_t rFrame[4];
uint8_t wFrame[8];
uint64_t result[4];
} TMC2209;
void TMC2209_Init(TMC2209* tmc2209, TMC_UART* serial_instance); //ok
void TMC2209_destroy(TMC2209* tmc2209); //TODO
uint8_t compute_crc8_atm(const uint8_t *datagram, size_t length, uint8_t initial_value); //ok
uint64_t* read_reg(TMC2209* tmc2209, int reg) ; //ok
uint32_t read_int(TMC2209* tmc2209, int reg); //ok
bool write_reg(TMC2209* tmc2209, int reg, int val); //ok
bool write_reg_check(TMC2209* tmc2209, int reg, int val) ; //ok
void driver_status(TMC2209* tmc2209); //NotWork
void general_config(TMC2209* tmc2209); //NotWork
void general_stat(TMC2209* tmc2209); //NotWork
bool set_vactual(TMC2209* tmc2209, int value); //ok
void set_voltage_sense(TMC2209* tmc2209, bool enabled); //ok
bool get_voltage_sense(TMC2209* tmc2209); //ok
void set_current_flow(TMC2209* tmc2209, double run_current, double hold_current_multiplier, int hold_current_delay, double Vref);//averif NotWork
int get_iscale_analog(TMC2209* tmc2209); //ok
void set_iscale_analog(TMC2209* tmc2209, bool enabled); //ok
int get_interpolation(TMC2209* tmc2209); //ok
void set_interpolation(TMC2209* tmc2209, bool enabled); //ok
int get_internal_resistor_sense(TMC2209* tmc2209); //ok
void set_internal_resistor_sense(TMC2209* tmc2209, bool enabled); //ok
int get_spread_cycle(TMC2209* tmc2209); //NotWork
void set_spread_cycle(TMC2209* tmc2209, bool enabled); //NotWork
void set_microstepping_resolution(TMC2209* tmc2209, int msres); //ok
int get_microstepping_resolution(TMC2209* tmc2209); //ok
void set_microstep_resolution_regselect(TMC2209* tmc2209, bool enabled); //ok
void set_irun_ihold(TMC2209* tmc2209, double IHold, double IRun, int IHoldDelay); //ok
int get_direction_shart(TMC2209* tmc2209); //ok
void ioin(TMC2209* tmc2209);
void clear_general_stat(TMC2209* tmc2209); //ok
void set_direction_shart(TMC2209* tmc2209, int direction); //ok
int get_stallguard(TMC2209* tmc2209);
void set_stallguard_threshold(TMC2209* tmc2209, int threshold);
void set_coolstep_threshold(TMC2209* tmc2209, int threshold);
void set_stallguard_callback(TMC2209* tmc2209, int stallguard_pin, int threshold, int callback, int min_speed);
int get_tstep(TMC2209* tmc2209);
int get_microstep_counter(TMC2209* tmc2209, bool in_steps, int offset);
#endif