no-OS
Functions
tmc7300.c File Reference

Source file for the TMC7300 driver. More...

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "no_os_uart.h"
#include "no_os_alloc.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "tmc7300.h"
Include dependency graph for tmc7300.c:

Functions

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

Detailed Description

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

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ tmc7300_drv_enable()

int tmc7300_drv_enable ( struct tmc7300_desc desc,
bool  enable 
)

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

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.

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.

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.

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.

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.

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.

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.

Parameters
desc- The TMC7300 descriptor.
addr- The register address.
val- The value to read.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ tmc7300_reg_update()

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

Update a register.

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.
Here is the caller graph for this function:

◆ tmc7300_reg_write()

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

Write 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.
Here is the caller graph for this function:

◆ tmc7300_remove()

int tmc7300_remove ( struct tmc7300_desc desc)

Free the resources allocated by tmc7300_init().

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.

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.

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.

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.

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.

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.

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.

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