no-OS
tmc7300.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef _TMC7300_H_
34 #define _TMC7300_H_
35 
36 #include <stdint.h>
37 #include "no_os_uart.h"
38 #include "no_os_gpio.h"
39 
40 #define TMC7300_BRIDGE_NUM 2
41 #define TMC7300_DUTY_MAX_VALUE 511
42 #define TMC7300_SENDDELAY_MAX_VALUE 15
43 
44 #define TMC7300_GCONF_REG 0x00
45 #define TMC7300_IFCNT_REG 0x02
46 #define TMC7300_SLAVECONF_REG 0x03
47 #define TMC7300_IOIN_REG 0x03
48 #define TMC7300_CURRENT_LIMIT_REG 0x10
49 #define TMC7300_PWM_AB_REG 0x22
50 #define TMC7300_CHOPCONF_REG 0x6C
51 #define TMC7300_DRV_STATUS_REG 0x6F
52 #define TMC7300_PWMCONF_REG 0x70
53 
54 #define TMC7300_PAR_MODE_MASK NO_OS_BIT(2)
55 #define TMC7300_PWM_DIRECT_MASK NO_OS_BIT(0)
56 #define TMC7300_DRV_ENABLE_MASK NO_OS_BIT(0)
57 #define TMC7300_SLAVECONF_MASK NO_OS_GENMASK(11, 8)
58 #define TMC7300_IRUN_MASK NO_OS_GENMASK(12, 8)
59 #define TMC7300_PWM_B_MASK NO_OS_GENMASK(24, 16)
60 #define TMC7300_PWM_FREQ_MASK NO_OS_GENMASK(17, 16)
61 #define TMC7300_FREEWHEEL_MASK NO_OS_GENMASK(21, 20)
62 #define TMC7300_BLANK_TIME_MASK NO_OS_GENMASK(16, 15)
63 
64 #define TMC7300_LI_MASK(bridge) (bridge == 0) ? NO_OS_BIT(6) : \
65  NO_OS_BIT(7)
66 
67 #define TMC7300_PWM_MASK(bridge) (bridge == 0) ? NO_OS_GENMASK(8, 0) : \
68  NO_OS_GENMASK(24, 16)
69 
73 };
74 
79 };
80 
86 };
87 
93 };
94 
98 };
99 
101  uint8_t otpw : 1;
102  uint8_t ot : 1;
103  uint8_t s2ga : 1;
104  uint8_t s2gb : 1;
105  uint8_t s2vsa : 1;
106  uint8_t s2vsb : 1;
107  uint8_t lia : 1;
108  uint8_t lib : 1;
109  uint8_t t120: 1;
110  uint8_t t150: 1;
111  uint32_t reserved: 22;
112 };
113 
116  uint32_t val;
117 };
118 
120  uint8_t en : 1;
121  uint8_t nstdby : 1;
122  uint8_t ad0 : 1;
123  uint8_t ad1 : 1;
124  uint8_t diag : 1;
125  uint8_t uart_on : 1;
126  uint8_t uart_input : 1;
127  uint8_t mode_input : 1;
128  uint8_t a2 : 1;
129  uint8_t a1 : 1;
130  uint8_t comp_a1a2 : 1;
131  uint8_t comp_b1b2 : 1;
132  uint16_t reserved : 12;
133  uint8_t version : 8;
134 };
135 
138  uint32_t val;
139 };
140 
142  uint8_t pwm_duty;
144 };
145 
150 struct tmc7300_desc {
152  uint32_t addr;
159 
165  /* Current limit setting */
166  uint8_t irun;
169 };
170 
177  uint32_t addr;
186 };
187 
189 int tmc7300_reg_read(struct tmc7300_desc *, uint32_t, uint32_t *);
190 
192 int tmc7300_reg_write(struct tmc7300_desc *, uint32_t, uint32_t);
193 
195 int tmc7300_reg_update(struct tmc7300_desc *, uint32_t, uint32_t, uint32_t);
196 
199  uint32_t *);
200 
202 int tmc7300_drv_enable(struct tmc7300_desc *, bool);
203 
205 int tmc7300_set_pwm_duty(struct tmc7300_desc *, enum tmc7300_bridge, int32_t);
206 
208 int tmc7300_set_send_delay(struct tmc7300_desc *, uint8_t);
209 
211 int tmc7300_set_current_limit(struct tmc7300_desc *, uint32_t);
212 
214 int tmc7300_get_ifcnt(struct tmc7300_desc *, uint8_t *);
215 
218 
220 int tmc7300_get_ioin(struct tmc7300_desc *, union tmc7300_ioin *);
221 
225 
228 
231 
234 
237 
240  uint8_t, enum tmc7300_motor_dir);
241 
243 int tmc7300_init(struct tmc7300_desc **, struct tmc7300_init_param *);
244 
246 int tmc7300_remove(struct tmc7300_desc *);
247 
248 #endif
tmc7300_desc::bridge_priv
struct tmc7300_bridge_priv bridge_priv[TMC7300_BRIDGE_NUM]
Definition: tmc7300.h:168
tmc7300_init_param::addr
uint32_t addr
Definition: tmc7300.h:177
tmc7300_get_blank_time
int tmc7300_get_blank_time(struct tmc7300_desc *, enum tmc7300_blank_time *)
Get the comparator blank time register.
Definition: tmc7300.c:443
no_os_alloc.h
tmc7300_remove
int tmc7300_remove(struct tmc7300_desc *desc)
Free the resources allocated by tmc7300_init().
Definition: tmc7300.c:551
tmc7300_reg_write
int tmc7300_reg_write(struct tmc7300_desc *desc, uint32_t addr, uint32_t val)
Write a register.
Definition: tmc7300.c:77
_tmc7300_ioin::ad1
uint8_t ad1
Definition: tmc7300.h:123
tmc7300_reg_read
int tmc7300_reg_read(struct tmc7300_desc *, uint32_t, uint32_t *)
Read a register.
Definition: tmc7300.c:113
TMC7300_SLAVECONF_REG
#define TMC7300_SLAVECONF_REG
Definition: tmc7300.h:46
tmc7300_desc::irun
uint8_t irun
Definition: tmc7300.h:166
TMC7300_BRIDGE_NUM
#define TMC7300_BRIDGE_NUM
Definition: tmc7300.h:40
no_os_uart_write
int32_t no_os_uart_write(struct no_os_uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
Write to UART.
Definition: no_os_uart.c:144
tmc7300_get_load_indicator
int tmc7300_get_load_indicator(struct tmc7300_desc *desc, enum tmc7300_bridge bridge, uint32_t *val)
Get the load indicator.
Definition: tmc7300.c:189
TMC7300_BRIDGE_B
@ TMC7300_BRIDGE_B
Definition: tmc7300.h:72
TMC7300_PAR_MODE_MASK
#define TMC7300_PAR_MODE_MASK
Definition: tmc7300.h:54
tmc7300_set_pwm_duty
int tmc7300_set_pwm_duty(struct tmc7300_desc *desc, enum tmc7300_bridge bridge, int32_t duty)
Set the PWM duty cycle.
Definition: tmc7300.c:232
_tmc7300_ioin::comp_b1b2
uint8_t comp_b1b2
Definition: tmc7300.h:131
tmc7300_get_blank_time
int tmc7300_get_blank_time(struct tmc7300_desc *desc, enum tmc7300_blank_time *time)
Get the comparator blank time register.
Definition: tmc7300.c:443
tmc7300_set_send_delay
int tmc7300_set_send_delay(struct tmc7300_desc *desc, uint8_t delay)
Set the UART response delay.
Definition: tmc7300.c:288
_tmc7300_drv_status::s2gb
uint8_t s2gb
Definition: tmc7300.h:104
TMC7300_IFCNT_REG
#define TMC7300_IFCNT_REG
Definition: tmc7300.h:45
tmc7300_desc::motor_drive
bool motor_drive
Definition: tmc7300.h:164
_tmc7300_ioin
Definition: tmc7300.h:119
TMC7300_BLANK_TIME_24
@ TMC7300_BLANK_TIME_24
Definition: tmc7300.h:90
no_os_uart_read
int32_t no_os_uart_read(struct no_os_uart_desc *desc, uint8_t *data, uint32_t bytes_number)
Read data from UART.
Definition: no_os_uart.c:118
TMC7300_BRIDGE_A
@ TMC7300_BRIDGE_A
Definition: tmc7300.h:71
TMC7300_PWM_DIRECT_MASK
#define TMC7300_PWM_DIRECT_MASK
Definition: tmc7300.h:55
tmc7300.h
Header file for the TMC7300 driver.
TMC7300_SLAVECONF_MASK
#define TMC7300_SLAVECONF_MASK
Definition: tmc7300.h:57
_tmc7300_ioin::reserved
uint16_t reserved
Definition: tmc7300.h:132
TMC7300_DRV_ENABLE_MASK
#define TMC7300_DRV_ENABLE_MASK
Definition: tmc7300.h:56
tmc7300_get_ifcnt
int tmc7300_get_ifcnt(struct tmc7300_desc *, uint8_t *)
Get the number of UART valid write accesses. Wraps around at 255.
Definition: tmc7300.c:303
tmc7300_init_param::en_gpio
struct no_os_gpio_desc * en_gpio
Definition: tmc7300.h:181
_tmc7300_ioin::mode_input
uint8_t mode_input
Definition: tmc7300.h:127
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
tmc7300_reg_update
int tmc7300_reg_update(struct tmc7300_desc *desc, uint32_t addr, uint32_t mask, uint32_t val)
Update a register.
Definition: tmc7300.c:162
TMC7300_DUTY_MAX_VALUE
#define TMC7300_DUTY_MAX_VALUE
Definition: tmc7300.h:41
_tmc7300_drv_status::reserved
uint32_t reserved
Definition: tmc7300.h:111
tmc7300_desc::addr
uint32_t addr
Definition: tmc7300.h:152
tmc7300_desc::vio_gpio
struct no_os_gpio_desc * vio_gpio
Definition: tmc7300.h:158
tmc7300_get_drv_status
int tmc7300_get_drv_status(struct tmc7300_desc *desc, union tmc7300_drv_status *status)
Read the driver status register.
Definition: tmc7300.c:323
TMC7300_DIR_CW
@ TMC7300_DIR_CW
Definition: tmc7300.h:96
TMC7300_BLANK_TIME_32
@ TMC7300_BLANK_TIME_32
Definition: tmc7300.h:91
_tmc7300_drv_status::otpw
uint8_t otpw
Definition: tmc7300.h:101
TMC7300_DIR_CCW
@ TMC7300_DIR_CCW
Definition: tmc7300.h:97
no_os_field_prep
uint32_t no_os_field_prep(uint32_t mask, uint32_t val)
_tmc7300_drv_status::ot
uint8_t ot
Definition: tmc7300.h:102
_tmc7300_ioin::uart_input
uint8_t uart_input
Definition: tmc7300.h:126
tmc7300_drv_status::val
uint32_t val
Definition: tmc7300.h:116
tmc7300_reg_read
int tmc7300_reg_read(struct tmc7300_desc *desc, uint32_t addr, uint32_t *val)
Read a register.
Definition: tmc7300.c:113
no_os_uart_desc
Stucture holding the UART descriptor.
Definition: no_os_uart.h:134
no_os_error.h
Error codes definition.
tmc7300_ioin::val
uint32_t val
Definition: tmc7300.h:138
tmc7300_set_pwm_duty
int tmc7300_set_pwm_duty(struct tmc7300_desc *, enum tmc7300_bridge, int32_t)
Set the PWM duty cycle.
Definition: tmc7300.c:232
tmc7300_desc
Definition: tmc7300.h:150
_tmc7300_drv_status::lia
uint8_t lia
Definition: tmc7300.h:107
tmc7300_desc::en_gpio
struct no_os_gpio_desc * en_gpio
Definition: tmc7300.h:156
TMC7300_PWMCONF_REG
#define TMC7300_PWMCONF_REG
Definition: tmc7300.h:52
no_os_put_unaligned_be32
void no_os_put_unaligned_be32(uint32_t val, uint8_t *buf)
tmc7300_reg_update
int tmc7300_reg_update(struct tmc7300_desc *, uint32_t, uint32_t, uint32_t)
Update a register.
Definition: tmc7300.c:162
tmc7300_set_blank_time
int tmc7300_set_blank_time(struct tmc7300_desc *, enum tmc7300_blank_time)
Set the comparator blank time register.
Definition: tmc7300.c:426
tmc7300_set_send_delay
int tmc7300_set_send_delay(struct tmc7300_desc *, uint8_t)
Set the UART response delay.
Definition: tmc7300.c:288
TMC7300_GCONF_REG
#define TMC7300_GCONF_REG
Definition: tmc7300.h:44
TMC7300_BLANK_TIME_40
@ TMC7300_BLANK_TIME_40
Definition: tmc7300.h:92
TMC7300_BREAK_LS
@ TMC7300_BREAK_LS
Definition: tmc7300.h:77
tmc7300_get_ifcnt
int tmc7300_get_ifcnt(struct tmc7300_desc *desc, uint8_t *ifcnt)
Get the number of UART valid write accesses. Wraps around at 255.
Definition: tmc7300.c:303
_tmc7300_drv_status::s2vsb
uint8_t s2vsb
Definition: tmc7300.h:106
tmc7300_bridge_priv::pwm_duty
uint8_t pwm_duty
Definition: tmc7300.h:142
_tmc7300_ioin::a2
uint8_t a2
Definition: tmc7300.h:128
TMC7300_BREAK_HS
@ TMC7300_BREAK_HS
Definition: tmc7300.h:78
tmc7300_drv_enable
int tmc7300_drv_enable(struct tmc7300_desc *desc, bool enable)
Enable the bridge driver.
Definition: tmc7300.c:210
tmc7300_blank_time
tmc7300_blank_time
Definition: tmc7300.h:88
tmc7300_set_current_limit
int tmc7300_set_current_limit(struct tmc7300_desc *, uint32_t)
Set the current limit.
Definition: tmc7300.c:261
TMC7300_CHOPCONF_REG
#define TMC7300_CHOPCONF_REG
Definition: tmc7300.h:50
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:104
TMC7300_SENDDELAY_MAX_VALUE
#define TMC7300_SENDDELAY_MAX_VALUE
Definition: tmc7300.h:42
_tmc7300_ioin::nstdby
uint8_t nstdby
Definition: tmc7300.h:121
tmc7300_set_pwm_duty_dir
int tmc7300_set_pwm_duty_dir(struct tmc7300_desc *desc, enum tmc7300_bridge bridge, uint8_t duty, enum tmc7300_motor_dir dir)
Set the PWM duty cycle and direction.
Definition: tmc7300.c:466
tmc7300_set_pwm_freq
int tmc7300_set_pwm_freq(struct tmc7300_desc *desc, enum tmc7300_pwm_freq freq)
Set the frequency of the PWM signal.
Definition: tmc7300.c:390
tmc7300_bridge_priv::motor_dir
enum tmc7300_motor_dir motor_dir
Definition: tmc7300.h:143
_tmc7300_ioin::comp_a1a2
uint8_t comp_a1a2
Definition: tmc7300.h:130
tmc7300_standstill_mode
tmc7300_standstill_mode
Definition: tmc7300.h:75
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
tmc7300_get_ioin
int tmc7300_get_ioin(struct tmc7300_desc *desc, union tmc7300_ioin *ioin)
Read the IOIN register.
Definition: tmc7300.c:344
tmc7300_pwm_freq
tmc7300_pwm_freq
Definition: tmc7300.h:81
TMC7300_IOIN_REG
#define TMC7300_IOIN_REG
Definition: tmc7300.h:47
TMC7300_PWM_MASK
#define TMC7300_PWM_MASK(bridge)
Definition: tmc7300.h:67
tmc7300_bridge_priv
Definition: tmc7300.h:141
tmc7300_drv_status::bits
struct _tmc7300_drv_status bits
Definition: tmc7300.h:115
TMC7300_CURRENT_LIMIT_REG
#define TMC7300_CURRENT_LIMIT_REG
Definition: tmc7300.h:48
tmc7300_drv_status
Definition: tmc7300.h:114
_tmc7300_drv_status::t120
uint8_t t120
Definition: tmc7300.h:109
tmc7300_set_current_limit
int tmc7300_set_current_limit(struct tmc7300_desc *desc, uint32_t val)
Set the current limit.
Definition: tmc7300.c:261
tmc7300_init
int tmc7300_init(struct tmc7300_desc **desc, struct tmc7300_init_param *param)
Initialize the TMC7300 driver.
Definition: tmc7300.c:495
tmc7300_drv_enable
int tmc7300_drv_enable(struct tmc7300_desc *, bool)
Enable the bridge driver.
Definition: tmc7300.c:210
TMC7300_PWM_FREQ_2_410
@ TMC7300_PWM_FREQ_2_410
Definition: tmc7300.h:85
_tmc7300_ioin::a1
uint8_t a1
Definition: tmc7300.h:129
TMC7300_FREEWHEELING
@ TMC7300_FREEWHEELING
Definition: tmc7300.h:76
TMC7300_PWM_FREQ_MASK
#define TMC7300_PWM_FREQ_MASK
Definition: tmc7300.h:60
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
tmc7300_get_load_indicator
int tmc7300_get_load_indicator(struct tmc7300_desc *, enum tmc7300_bridge, uint32_t *)
Get the load indicator.
Definition: tmc7300.c:189
TMC7300_PWM_FREQ_2_512
@ TMC7300_PWM_FREQ_2_512
Definition: tmc7300.h:84
_tmc7300_ioin::en
uint8_t en
Definition: tmc7300.h:120
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
TMC7300_LI_MASK
#define TMC7300_LI_MASK(bridge)
Definition: tmc7300.h:64
tmc7300_init
int tmc7300_init(struct tmc7300_desc **, struct tmc7300_init_param *)
Initialize the TMC7300 driver.
Definition: tmc7300.c:495
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
tmc7300_get_drv_status
int tmc7300_get_drv_status(struct tmc7300_desc *, union tmc7300_drv_status *)
Read the driver status register.
Definition: tmc7300.c:323
_tmc7300_drv_status::lib
uint8_t lib
Definition: tmc7300.h:108
_tmc7300_drv_status
Definition: tmc7300.h:100
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:197
no_os_get_unaligned_be32
uint32_t no_os_get_unaligned_be32(uint8_t *buf)
TMC7300_BLANK_TIME_MASK
#define TMC7300_BLANK_TIME_MASK
Definition: tmc7300.h:62
tmc7300_set_pwm_freq
int tmc7300_set_pwm_freq(struct tmc7300_desc *, enum tmc7300_pwm_freq)
Set the frequency of the PWM signal.
Definition: tmc7300.c:390
tmc7300_desc::comm_desc
struct no_os_uart_desc * comm_desc
Definition: tmc7300.h:154
tmc7300_init_param::comm_desc
struct no_os_uart_desc * comm_desc
Definition: tmc7300.h:179
TMC7300_PWM_AB_REG
#define TMC7300_PWM_AB_REG
Definition: tmc7300.h:49
no_os_gpio.h
Header file of GPIO Interface.
TMC7300_PWM_FREQ_2_683
@ TMC7300_PWM_FREQ_2_683
Definition: tmc7300.h:83
tmc7300_set_standstill_mode
int tmc7300_set_standstill_mode(struct tmc7300_desc *desc, enum tmc7300_standstill_mode mode)
Set the standstill mode. The motorrun bit will be set to 0.
Definition: tmc7300.c:364
tmc7300_get_ioin
int tmc7300_get_ioin(struct tmc7300_desc *, union tmc7300_ioin *)
Read the IOIN register.
Definition: tmc7300.c:344
tmc7300_init_param
TMC7300 initialization structure.
Definition: tmc7300.h:175
tmc7300_motor_dir
tmc7300_motor_dir
Definition: tmc7300.h:95
no_os_uart.h
Header file of UART interface.
TMC7300_BLANK_TIME_16
@ TMC7300_BLANK_TIME_16
Definition: tmc7300.h:89
_tmc7300_drv_status::t150
uint8_t t150
Definition: tmc7300.h:110
tmc7300_ioin
Definition: tmc7300.h:136
no_os_util.h
Header file of utility functions.
tmc7300_set_standstill_mode
int tmc7300_set_standstill_mode(struct tmc7300_desc *, enum tmc7300_standstill_mode)
Set the standstill mode. The motorrun bit will be set to 0.
Definition: tmc7300.c:364
_tmc7300_ioin::ad0
uint8_t ad0
Definition: tmc7300.h:122
TMC7300_FREEWHEEL_MASK
#define TMC7300_FREEWHEEL_MASK
Definition: tmc7300.h:61
_tmc7300_ioin::diag
uint8_t diag
Definition: tmc7300.h:124
_tmc7300_drv_status::s2vsa
uint8_t s2vsa
Definition: tmc7300.h:105
tmc7300_init_param::parallel_mode
bool parallel_mode
Definition: tmc7300.h:185
no_os_spi_desc::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:202
TMC7300_DRV_STATUS_REG
#define TMC7300_DRV_STATUS_REG
Definition: tmc7300.h:51
tmc7300_get_pwm_freq
int tmc7300_get_pwm_freq(struct tmc7300_desc *desc, enum tmc7300_pwm_freq *freq)
Get the frequency of the PWM signal.
Definition: tmc7300.c:406
_tmc7300_ioin::version
uint8_t version
Definition: tmc7300.h:133
_tmc7300_drv_status::s2ga
uint8_t s2ga
Definition: tmc7300.h:103
tmc7300_set_pwm_duty_dir
int tmc7300_set_pwm_duty_dir(struct tmc7300_desc *, enum tmc7300_bridge, uint8_t, enum tmc7300_motor_dir)
Set the PWM duty cycle and direction.
Definition: tmc7300.c:466
tmc7300_remove
int tmc7300_remove(struct tmc7300_desc *)
Free the resources allocated by tmc7300_init().
Definition: tmc7300.c:551
tmc7300_init_param::vio_gpio
struct no_os_gpio_desc * vio_gpio
Definition: tmc7300.h:183
tmc7300_reg_write
int tmc7300_reg_write(struct tmc7300_desc *, uint32_t, uint32_t)
Write a register.
Definition: tmc7300.c:77
tmc7300_bridge
tmc7300_bridge
Definition: tmc7300.h:70
TMC7300_IRUN_MASK
#define TMC7300_IRUN_MASK
Definition: tmc7300.h:58
TMC7300_PWM_FREQ_2_1024
@ TMC7300_PWM_FREQ_2_1024
Definition: tmc7300.h:82
tmc7300_set_blank_time
int tmc7300_set_blank_time(struct tmc7300_desc *desc, enum tmc7300_blank_time time)
Set the comparator blank time register.
Definition: tmc7300.c:426
_tmc7300_ioin::uart_on
uint8_t uart_on
Definition: tmc7300.h:125
tmc7300_ioin::bits
struct _tmc7300_ioin bits
Definition: tmc7300.h:137
tmc7300_get_pwm_freq
int tmc7300_get_pwm_freq(struct tmc7300_desc *, enum tmc7300_pwm_freq *)
Get the frequency of the PWM signal.
Definition: tmc7300.c:406