no-OS
Loading...
Searching...
No Matches
tmc7300.h File Reference

Header file for the TMC7300 driver. More...

#include <stdint.h>
#include "no_os_uart.h"
#include "no_os_gpio.h"
Include dependency graph for tmc7300.h:

Classes

struct  _tmc7300_drv_status
 
union  tmc7300_drv_status
 
struct  _tmc7300_ioin
 
union  tmc7300_ioin
 
struct  tmc7300_bridge_priv
 
struct  tmc7300_desc
 
struct  tmc7300_init_param
 TMC7300 initialization structure. More...
 

Macros

#define TMC7300_BRIDGE_NUM   2
 
#define TMC7300_DUTY_MAX_VALUE   511
 
#define TMC7300_SENDDELAY_MAX_VALUE   15
 
#define TMC7300_GCONF_REG   0x00
 
#define TMC7300_IFCNT_REG   0x02
 
#define TMC7300_SLAVECONF_REG   0x03
 
#define TMC7300_IOIN_REG   0x03
 
#define TMC7300_CURRENT_LIMIT_REG   0x10
 
#define TMC7300_PWM_AB_REG   0x22
 
#define TMC7300_CHOPCONF_REG   0x6C
 
#define TMC7300_DRV_STATUS_REG   0x6F
 
#define TMC7300_PWMCONF_REG   0x70
 
#define TMC7300_PAR_MODE_MASK   NO_OS_BIT(2)
 
#define TMC7300_PWM_DIRECT_MASK   NO_OS_BIT(0)
 
#define TMC7300_DRV_ENABLE_MASK   NO_OS_BIT(0)
 
#define TMC7300_SLAVECONF_MASK   NO_OS_GENMASK(11, 8)
 
#define TMC7300_IRUN_MASK   NO_OS_GENMASK(12, 8)
 
#define TMC7300_PWM_B_MASK   NO_OS_GENMASK(24, 16)
 
#define TMC7300_PWM_FREQ_MASK   NO_OS_GENMASK(17, 16)
 
#define TMC7300_FREEWHEEL_MASK   NO_OS_GENMASK(21, 20)
 
#define TMC7300_BLANK_TIME_MASK   NO_OS_GENMASK(16, 15)
 
#define TMC7300_LI_MASK(bridge)
 
#define TMC7300_PWM_MASK(bridge)
 

Enumerations

enum  tmc7300_bridge {
  TMC7300_BRIDGE_A ,
  TMC7300_BRIDGE_B
}
 
enum  tmc7300_standstill_mode {
  TMC7300_FREEWHEELING = 1 ,
  TMC7300_BREAK_LS ,
  TMC7300_BREAK_HS
}
 
enum  tmc7300_pwm_freq {
  TMC7300_PWM_FREQ_2_1024 ,
  TMC7300_PWM_FREQ_2_683 ,
  TMC7300_PWM_FREQ_2_512 ,
  TMC7300_PWM_FREQ_2_410
}
 
enum  tmc7300_blank_time {
  TMC7300_BLANK_TIME_16 ,
  TMC7300_BLANK_TIME_24 ,
  TMC7300_BLANK_TIME_32 ,
  TMC7300_BLANK_TIME_40
}
 
enum  tmc7300_motor_dir {
  TMC7300_DIR_CW ,
  TMC7300_DIR_CCW
}
 

Functions

int tmc7300_reg_read (struct tmc7300_desc *, uint32_t, uint32_t *)
 Read a register.
 
int tmc7300_reg_write (struct tmc7300_desc *, uint32_t, uint32_t)
 Write a register.
 
int tmc7300_reg_update (struct tmc7300_desc *, uint32_t, uint32_t, uint32_t)
 Update a register.
 
int tmc7300_get_load_indicator (struct tmc7300_desc *, enum tmc7300_bridge, uint32_t *)
 Get the load indicator.
 
int tmc7300_drv_enable (struct tmc7300_desc *, bool)
 Enable the bridge driver.
 
int tmc7300_set_pwm_duty (struct tmc7300_desc *, enum tmc7300_bridge, int32_t)
 Set the PWM duty cycle.
 
int tmc7300_set_send_delay (struct tmc7300_desc *, uint8_t)
 Set the UART response delay.
 
int tmc7300_set_current_limit (struct tmc7300_desc *, uint32_t)
 Set the current limit.
 
int tmc7300_get_ifcnt (struct tmc7300_desc *, uint8_t *)
 Get the number of UART valid write accesses. Wraps around at 255.
 
int tmc7300_get_drv_status (struct tmc7300_desc *, union tmc7300_drv_status *)
 Read the driver status register.
 
int tmc7300_get_ioin (struct tmc7300_desc *, union tmc7300_ioin *)
 Read the IOIN register.
 
int tmc7300_set_standstill_mode (struct tmc7300_desc *, enum tmc7300_standstill_mode)
 Set the standstill mode. The motorrun bit will be set to 0.
 
int tmc7300_set_pwm_freq (struct tmc7300_desc *, enum tmc7300_pwm_freq)
 Set the frequency of the PWM signal.
 
int tmc7300_get_pwm_freq (struct tmc7300_desc *, enum tmc7300_pwm_freq *)
 Get the frequency of the PWM signal.
 
int tmc7300_get_blank_time (struct tmc7300_desc *, enum tmc7300_blank_time *)
 Get the comparator blank time register.
 
int tmc7300_set_blank_time (struct tmc7300_desc *, enum tmc7300_blank_time)
 Set the comparator blank time register.
 
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.
 
int tmc7300_init (struct tmc7300_desc **, struct tmc7300_init_param *)
 Initialize the TMC7300 driver.
 
int tmc7300_remove (struct tmc7300_desc *)
 Free the resources allocated by tmc7300_init().
 

Detailed Description

Header file for the TMC7300 driver.

Author
Ciprian Regus (cipri.nosp@m.an.r.nosp@m.egus@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2024(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ TMC7300_BLANK_TIME_MASK

#define TMC7300_BLANK_TIME_MASK   NO_OS_GENMASK(16, 15)

◆ TMC7300_BRIDGE_NUM

#define TMC7300_BRIDGE_NUM   2

◆ TMC7300_CHOPCONF_REG

#define TMC7300_CHOPCONF_REG   0x6C

◆ TMC7300_CURRENT_LIMIT_REG

#define TMC7300_CURRENT_LIMIT_REG   0x10

◆ TMC7300_DRV_ENABLE_MASK

#define TMC7300_DRV_ENABLE_MASK   NO_OS_BIT(0)

◆ TMC7300_DRV_STATUS_REG

#define TMC7300_DRV_STATUS_REG   0x6F

◆ TMC7300_DUTY_MAX_VALUE

#define TMC7300_DUTY_MAX_VALUE   511

◆ TMC7300_FREEWHEEL_MASK

#define TMC7300_FREEWHEEL_MASK   NO_OS_GENMASK(21, 20)

◆ TMC7300_GCONF_REG

#define TMC7300_GCONF_REG   0x00

◆ TMC7300_IFCNT_REG

#define TMC7300_IFCNT_REG   0x02

◆ TMC7300_IOIN_REG

#define TMC7300_IOIN_REG   0x03

◆ TMC7300_IRUN_MASK

#define TMC7300_IRUN_MASK   NO_OS_GENMASK(12, 8)

◆ TMC7300_LI_MASK

#define TMC7300_LI_MASK ( bridge)
Value:
(bridge == 0) ? NO_OS_BIT(6) : \
NO_OS_BIT(7)
#define NO_OS_BIT(x)
Definition no_os_util.h:23

◆ TMC7300_PAR_MODE_MASK

#define TMC7300_PAR_MODE_MASK   NO_OS_BIT(2)

◆ TMC7300_PWM_AB_REG

#define TMC7300_PWM_AB_REG   0x22

◆ TMC7300_PWM_B_MASK

#define TMC7300_PWM_B_MASK   NO_OS_GENMASK(24, 16)

◆ TMC7300_PWM_DIRECT_MASK

#define TMC7300_PWM_DIRECT_MASK   NO_OS_BIT(0)

◆ TMC7300_PWM_FREQ_MASK

#define TMC7300_PWM_FREQ_MASK   NO_OS_GENMASK(17, 16)

◆ TMC7300_PWM_MASK

#define TMC7300_PWM_MASK ( bridge)
Value:
(bridge == 0) ? NO_OS_GENMASK(8, 0) : \
NO_OS_GENMASK(24, 16)
#define NO_OS_GENMASK(h, l)
Definition no_os_util.h:60

◆ TMC7300_PWMCONF_REG

#define TMC7300_PWMCONF_REG   0x70

◆ TMC7300_SENDDELAY_MAX_VALUE

#define TMC7300_SENDDELAY_MAX_VALUE   15

◆ TMC7300_SLAVECONF_MASK

#define TMC7300_SLAVECONF_MASK   NO_OS_GENMASK(11, 8)

◆ TMC7300_SLAVECONF_REG

#define TMC7300_SLAVECONF_REG   0x03

Enumeration Type Documentation

◆ tmc7300_blank_time

Enumerator
TMC7300_BLANK_TIME_16 
TMC7300_BLANK_TIME_24 
TMC7300_BLANK_TIME_32 
TMC7300_BLANK_TIME_40 

◆ tmc7300_bridge

Enumerator
TMC7300_BRIDGE_A 
TMC7300_BRIDGE_B 

◆ tmc7300_motor_dir

Enumerator
TMC7300_DIR_CW 
TMC7300_DIR_CCW 

◆ tmc7300_pwm_freq

Enumerator
TMC7300_PWM_FREQ_2_1024 
TMC7300_PWM_FREQ_2_683 
TMC7300_PWM_FREQ_2_512 
TMC7300_PWM_FREQ_2_410 

◆ tmc7300_standstill_mode

Enumerator
TMC7300_FREEWHEELING 
TMC7300_BREAK_LS 
TMC7300_BREAK_HS 

Function Documentation

◆ tmc7300_drv_enable()

int tmc7300_drv_enable ( struct tmc7300_desc * desc,
bool enable )

Enable the bridge driver.

Set the state of the bridge driver

Parameters
desc- The TMC7300 descriptor.
enable- Enable or disable the driver.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_get_blank_time()

int tmc7300_get_blank_time ( struct tmc7300_desc * desc,
enum tmc7300_blank_time * time )

Get the comparator blank time register.

Read the comparator's blank time.

Parameters
desc- The TMC7300 descriptor.
time- The blank time setting.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_get_drv_status()

int tmc7300_get_drv_status ( struct tmc7300_desc * desc,
union tmc7300_drv_status * status )

Read the driver status register.

Read the DRV_STATUS register

Parameters
desc- The TMC7300 descriptor.
status- The driver status.
Returns
0 in case of success, negative error code otherwise.

◆ 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.

Read the valid write access counter

Parameters
desc- The TMC7300 descriptor.
ifcnt- The number of valid write accesses.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_get_ioin()

int tmc7300_get_ioin ( struct tmc7300_desc * desc,
union tmc7300_ioin * ioin )

Read the IOIN register.

Read the IOIN register

Parameters
desc- The TMC7300 descriptor.
ioin- The IOIN register value.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_get_load_indicator()

int tmc7300_get_load_indicator ( struct tmc7300_desc * desc,
enum tmc7300_bridge bridge,
uint32_t * val )

Get the load indicator.

Read the LI{A,B} field, indicating if the bridge output is current limited or not

Parameters
desc- The TMC7300 descriptor.
bridge- The bridge to get the load indicator for.
val- The load indicator value.
Returns
0 in case of success, negative error code otherwise.

◆ 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.

Read the PWM frequency

Parameters
desc- The TMC7300 descriptor.
freq- Division factor for the internal clock oscillator (12 MHz).
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_init()

int tmc7300_init ( struct tmc7300_desc ** desc,
struct tmc7300_init_param * param )

Initialize the TMC7300 driver.

Configure the initial state of the TMC7300

Parameters
desc- The TMC7300 descriptor.
param- The initialization parameters.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_reg_read()

int tmc7300_reg_read ( struct tmc7300_desc * desc,
uint32_t addr,
uint32_t * val )

Read a register.

Read the value of a register

Parameters
desc- The TMC7300 descriptor.
addr- The register address.
val- The value to read.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_reg_update()

int tmc7300_reg_update ( struct tmc7300_desc * desc,
uint32_t addr,
uint32_t mask,
uint32_t val )

Update a register.

Update the value of a field specified using a bit mask

Parameters
desc- The TMC7300 descriptor.
addr- The register address.
mask- The mask to apply.
val- The value of the field specified by the mask. Will be shifted to the correct position.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_reg_write()

int tmc7300_reg_write ( struct tmc7300_desc * desc,
uint32_t addr,
uint32_t val )

Write a register.

Write the value of a register

Parameters
desc- The TMC7300 descriptor.
addr- The register address.
val- The value to write.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_remove()

int tmc7300_remove ( struct tmc7300_desc * desc)

Free the resources allocated by tmc7300_init().

Free the resources allocated by the tmc7300_init() function

Parameters
desc- The TMC7300 descriptor.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_set_blank_time()

int tmc7300_set_blank_time ( struct tmc7300_desc * desc,
enum tmc7300_blank_time time )

Set the comparator blank time register.

Set the comparator's blank time.

Parameters
desc- The TMC7300 descriptor.
time- The blank time setting.
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_set_current_limit()

int tmc7300_set_current_limit ( struct tmc7300_desc * desc,
uint32_t val )

Set the current limit.

Set the current limit field

Parameters
desc- The TMC7300 descriptor.
val- The current limit value.
Returns
0 in case of success, negative error code otherwise.

◆ 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.

Set the value of the PWM duty cycle. The sign specifies the full bridge output direction

Parameters
desc- The TMC7300 descriptor.
bridge- The bridge to set the PWM duty cycle for.
duty- The duty cycle value.
Returns
0 in case of success, negative error code otherwise.

◆ 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.

Set the PWM duty cycle in the 0 - 255 (0% - 100%) range and the output direction (CW/CCW)

Parameters
desc- The TMC7300 descriptor.
bridge- The bridge to set the PWM duty cycle for.
duty- The duty cycle value.
dir- The direction of the motor.
Returns
0 in case of success, negative error code otherwise.

◆ 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.

Set the PWM frequency

Parameters
desc- The TMC7300 descriptor.
freq- Division factor for the internal clock oscillator (12 MHz).
Returns
0 in case of success, negative error code otherwise.

◆ tmc7300_set_send_delay()

int tmc7300_set_send_delay ( struct tmc7300_desc * desc,
uint8_t delay )

Set the UART response delay.

Set the delay in the device's UART access response

Parameters
desc- The TMC7300 descriptor.
delay- The delay value.
Returns
0 in case of success, negative error code otherwise.

◆ 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.

Set the standstill mode (freewheeling/braking). The PWM output will be stopped.

Parameters
desc- The TMC7300 descriptor.
mode- The standstill mode setting (freewheeling or break).
Returns
0 in case of success, negative error code otherwise.