LibL6474-C-Library 1.0
Library Code documentation
Loading...
Searching...
No Matches
LibL6474x.c File Reference
#include "LibL6474.h"
#include "LibL6474Config.h"
+ Include dependency graph for LibL6474x.c:

Data Structures

struct  L6474x_ParameterDescriptor
 
struct  L6474_Handle
 

Macros

#define IN_MILLISEC(x)
 
#define STEP_CMD_NOP_PREFIX   ((char)0x00)
 
#define STEP_CMD_NOP_LENGTH   0x01
 
#define STEP_CMD_SET_PREFIX   ((char)0x00)
 
#define STEP_CMD_SET_LENGTH   0x01
 
#define STEP_CMD_SET_MAX_PAYLOAD   0x04
 
#define STEP_CMD_GET_PREFIX   ((char)0x20)
 
#define STEP_CMD_GET_LENGTH   0x01
 
#define STEP_CMD_GET_MAX_PAYLOAD   0x04
 
#define STEP_CMD_ENA_PREFIX   ((char)0xB8)
 
#define STEP_CMD_ENA_LENGTH   0x01
 
#define STEP_CMD_DIS_PREFIX   ((char)0xA8)
 
#define STEP_CMD_DIS_LENGTH   0x01
 
#define STEP_CMD_STA_PREFIX   ((char)0xD0)
 
#define STEP_CMD_STA_LENGTH   0x03
 
#define STEP_REG_RANGE_MASK   0x1F
 
#define HIGH_POS_BIT   (1 << 21)
 
#define HIGH_POS_MASK   ((HIGH_POS_BIT*2)-1)
 
#define STEP_REG_ABS_POS   0x01
 
#define STEP_LEN_ABS_POS   0x03
 
#define STEP_MASK_ABS_POS   0x3FFFFF
 
#define STEP_OFFSET_ABS_POS   0x0
 
#define STEP_REG_EL_POS   0x02
 
#define STEP_LEN_EL_POS   0x02
 
#define STEP_MASK_EL_POS   0x1FF
 
#define STEP_OFFSET_EL_POS   0x0
 
#define STEP_REG_MARK   0x03
 
#define STEP_LEN_MARK   0x03
 
#define STEP_MASK_MARK   0x3FFFFF
 
#define STEP_OFFSET_MARK   0x0
 
#define STEP_REG_TVAL   L6474_PROP_TORQUE
 
#define STEP_LEN_TVAL   0x01
 
#define STEP_MASK_TVAL   0x7F
 
#define STEP_OFFSET_TVAL   0x0
 
#define STEP_REG_T_FAST   L6474_PROP_TFAST
 
#define STEP_LEN_T_FAST   0x01
 
#define STEP_MASK_T_FAST   0xFF
 
#define STEP_OFFSET_T_FAST   0x0
 
#define STEP_REG_TON_MIN   L6474_PROP_TON
 
#define STEP_LEN_TON_MIN   0x01
 
#define STEP_MASK_TON_MIN   0x7F
 
#define STEP_OFFSET_TON_MIN   0x0
 
#define STEP_REG_TOFF_MIN   L6474_PROP_TOFF
 
#define STEP_LEN_TOFF_MIN   0x01
 
#define STEP_MASK_TOFF_MIN   0x7F
 
#define STEP_OFFSET_TOFF_MIN   0x0
 
#define STEP_REG_ADC_OUT   L6474_PROP_ADC_OUT
 
#define STEP_LEN_ADC_OUT   0x01
 
#define STEP_MASK_ADC_OUT   0x1F
 
#define STEP_OFFSET_ADC_OUT   0x0
 
#define STEP_REG_OCD_TH   L6474_PROP_OCDTH
 
#define STEP_LEN_OCD_TH   0x01
 
#define STEP_MASK_OCD_TH   0x0F
 
#define STEP_OFFSET_OCD_TH   0x0
 
#define STEP_REG_STEP_MODE   0x16
 
#define STEP_LEN_STEP_MODE   0x01
 
#define STEP_MASK_STEP_MODE   0xFF
 
#define STEP_OFFSET_STEP_MODE   0x0
 
#define STEP_REG_ALARM_EN   0x17
 
#define STEP_LEN_ALARM_EN   0x01
 
#define STEP_MASK_ALARM_EN   0xFF
 
#define STEP_OFFSET_ALARM_EN   0x0
 
#define STEP_REG_CONFIG   0x18
 
#define STEP_LEN_CONFIG   0x02
 
#define STEP_MASK_CONFIG   0xFFFF
 
#define STEP_OFFSET_CONFIG   0x0
 
#define STEP_REG_STATUS   0x19
 
#define STEP_LEN_STATUS   0x02
 
#define STEP_MASK_STATUS   0xFFFF
 
#define STEP_OFFSET_STATUS   0x0
 
#define STATUS_HIGHZ_MASK   ( 1 << 0 )
 
#define STATUS_DIRECTION_MASK   ( 1 << 4 )
 
#define STATUS_NOTPERF_CMD_MASK   ( 1 << 7 )
 
#define STATUS_WRONG_CMD_MASK   ( 1 << 8 )
 
#define STATUS_UNDERVOLT_MASK   ( 1 << 9 )
 
#define STATUS_THR_WARN_MASK   ( 1 << 10 )
 
#define STATUS_THR_SHORTD_MASK   ( 1 << 11 )
 
#define STATUS_OCD_MASK   ( 1 << 12 )
 

Typedefs

typedef enum L6474x_AccessFlags L6474x_AccessFlags_t
 
typedef struct L6474x_ParameterDescriptor L6474x_ParameterDescriptor_t
 

Enumerations

enum  L6474x_AccessFlags { afNONE = 0x00 , afREAD = 0x01 , afWRITE = 0x02 , afWRITE_HighZ = 0x04 }
 

Functions

static int L6474_HelperLock (L6474_Handle_t h)
 
static void L6474_HelperUnlock (L6474_Handle_t h)
 
static void L6474_HelperReleaseStep (L6474_Handle_t h)
 
static int L6474_GetStatusCommand (L6474_Handle_t h)
 
static int L6474_NopCommand (L6474_Handle_t h)
 
static int L6474_GetParamCommand (L6474_Handle_t h, int addr)
 
static int L6474_SetParamCommand (L6474_Handle_t h, int addr, int value)
 
static int L6474_EnableCommand (L6474_Handle_t h)
 
static int L6474_DisableCommand (L6474_Handle_t h)
 
L6474_Handle_t L6474_CreateInstance (L6474x_Platform_t *p, void *pIO, void *pGPO, void *pPWM)
 
int L6474_DestroyInstance (L6474_Handle_t h)
 
int L6474_ResetStandBy (L6474_Handle_t h)
 
int L6474_SetBaseParameter (L6474_BaseParameter_t *p)
 
char L6474_EncodePhaseCurrent (float mA)
 
int L6474_EncodePhaseCurrentParameter (L6474_BaseParameter_t *p, float mA)
 
int L6474_Initialize (L6474_Handle_t h, L6474_BaseParameter_t *p)
 
int L6474_IsMoving (L6474_Handle_t h, int *moving)
 
int L6474_SetStepMode (L6474_Handle_t h, L6474x_StepMode_t mode)
 
int L6474_GetStepMode (L6474_Handle_t h, L6474x_StepMode_t *mode)
 
int L6474_SetPowerOutputs (L6474_Handle_t h, int ena)
 
int L6474_GetAbsolutePosition (L6474_Handle_t h, int *position)
 
int L6474_SetAbsolutePosition (L6474_Handle_t h, int position)
 
int L6474_GetElectricalPosition (L6474_Handle_t h, int *position)
 
int L6474_SetElectricalPosition (L6474_Handle_t h, int position)
 
int L6474_GetPositionMark (L6474_Handle_t h, int *position)
 
int L6474_SetPositionMark (L6474_Handle_t h, int position)
 
int L6474_GetAlarmEnables (L6474_Handle_t h, int *bits)
 
int L6474_SetProperty (L6474_Handle_t h, L6474_Property_t prop, int value)
 
int L6474_GetProperty (L6474_Handle_t h, L6474_Property_t prop, int *value)
 
int L6474_SetAlarmEnables (L6474_Handle_t h, int bits)
 
int L6474_GetStatus (L6474_Handle_t h, L6474_Status_t *status)
 
int L6474_GetState (L6474_Handle_t h, L6474x_State_t *state)
 
int L6474_StopMovement (L6474_Handle_t h)
 
int L6474_StepIncremental (L6474_Handle_t h, int steps)
 

Variables

static const L6474x_ParameterDescriptor_t L6474_Parameters [STEP_REG_RANGE_MASK]
 

Macro Definition Documentation

◆ IN_MILLISEC

#define IN_MILLISEC ( x)
Value:
(x)

Function Documentation

◆ L6474_CreateInstance()

L6474_Handle_t L6474_CreateInstance ( L6474x_Platform_t * p,
void * pIO,
void * pGPO,
void * pPWM )

L6474_CreateInstance is used once to create a library instance which encapsulates the handling for one stepper driver chip It needs a L6474x_Platform_t abstraction pointer and optionally some context pointers which are platform specific. The context pointers are passed to the abstraction functions which are provided by the platform structure.

In case it fails, a null pointer is returned. In case it was successful, a handle pointer is returned which is always required for all other API calls

◆ L6474_DestroyInstance()

int L6474_DestroyInstance ( L6474_Handle_t h)

L6474_DestroyInstance is used to destroy a library instance which has been previously created by a call to L6474_CreateInstance

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

◆ L6474_EncodePhaseCurrent()

char L6474_EncodePhaseCurrent ( float mA)

Calling L6474_EncodePhaseCurrent converts the requested phase current into the register value which is required in the base parameter structure. The member for this value is named TorqueVal

The function returns a register value which represents the given current value

◆ L6474_EncodePhaseCurrentParameter()

int L6474_EncodePhaseCurrentParameter ( L6474_BaseParameter_t * p,
float mA )

Calling L6474_EncodePhaseCurrentParameter converts the requested phase current into the register value which is required in the base parameter structure. The member for this value is named TorqueVal. This function directly inserts the converted value into the given base parameter structure.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

◆ L6474_GetAbsolutePosition()

int L6474_GetAbsolutePosition ( L6474_Handle_t h,
int * position )

func L6474_GetAbsolutePosition is used to read the current stepper position. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required. It returns the position

◆ L6474_GetAlarmEnables()

int L6474_GetAlarmEnables ( L6474_Handle_t h,
int * bits )

func L6474_GetAlarmEnables is used to read the current enable bits for the ERROR ALARM and FLAG Pin. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param bits is required. The bitmask can be found in the datasheet

◆ L6474_GetElectricalPosition()

int L6474_GetElectricalPosition ( L6474_Handle_t h,
int * position )

func L6474_GetElectricalPosition is used to read the current stepper electrical position. The library must not be in stRESET state to perform this operation. The electrical Position returns the step state and micro step component of the driver.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_GetPositionMark()

int L6474_GetPositionMark ( L6474_Handle_t h,
int * position )

func L6474_GetPositionMark is used to read the current stepper position mark. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_GetProperty()

int L6474_GetProperty ( L6474_Handle_t h,
L6474_Property_t prop,
int * value )

func L6474_SetProperty is used to read a property of the type of L6474_Property_t. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param prop is required.

param value is required. The value formats can be found in the datasheet

◆ L6474_GetState()

int L6474_GetState ( L6474_Handle_t h,
L6474x_State_t * state )

func L6474_GetState is used to read back the current libraries state. The library can be in state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param state is required. And must not be null

◆ L6474_GetStatus()

int L6474_GetStatus ( L6474_Handle_t h,
L6474_Status_t * status )

func L6474_GetStatus is used to read back the current libraries and devices status. The library must not be in stRESET to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param status is required. And must not be null

◆ L6474_GetStepMode()

int L6474_GetStepMode ( L6474_Handle_t h,
L6474x_StepMode_t * mode )

func L6474_SetStepMode is used to read back the step mode and therefore the resolution. The library must not be in stRESET to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param mode is required and is one out of L6474x_StepMode_t

◆ L6474_Initialize()

int L6474_Initialize ( L6474_Handle_t h,
L6474_BaseParameter_t * p )

func L6474_Initialize is used to set all basic parameters and take the required steps to bring up the driver into an idle state. It sets the library to stDISABLED in case no error happens.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param p is required and can not be null. the struct can be filled by calling L6474_SetBaseParameter before.

◆ L6474_IsMoving()

int L6474_IsMoving ( L6474_Handle_t h,
int * moving )

func L6474_IsMoving is used to read the state of movement. In case the stepper moves, it returns true. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param moving is required. It returns 0 when no movement is pending or 1 when there is a movement.

◆ L6474_ResetStandBy()

int L6474_ResetStandBy ( L6474_Handle_t h)

Calling L6474_ResetStandBy sets the driver in deep power down or reset state and the library will be set to default startup state again. All initialization steps must be done again by at least calling L6474_Initialize. The library is set to stRESET from any other state before.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

note that in case the stepper is enabled an moving, the operation will be safely disabled but depending on the speed, the position can not be tracked properly anymore. So a new reference run after re-initialization is required!

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

◆ L6474_SetAbsolutePosition()

int L6474_SetAbsolutePosition ( L6474_Handle_t h,
int position )

func L6474_SetAbsolutePosition is used to write the current stepper position. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required. It sets the position

◆ L6474_SetAlarmEnables()

int L6474_SetAlarmEnables ( L6474_Handle_t h,
int bits )

func L6474_SetAlarmEnables is used to write the current enable bits for the ERROR ALARM and FLAG Pin. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param bits is required. The bitmask can be found in the datasheet

◆ L6474_SetBaseParameter()

int L6474_SetBaseParameter ( L6474_BaseParameter_t * p)

Calling L6474_SetBaseParameter sets the basic global default parameters for all properties in the L6474_BaseParameter_t structure. These parameters are required when calling L6474_Initialize

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

◆ L6474_SetElectricalPosition()

int L6474_SetElectricalPosition ( L6474_Handle_t h,
int position )

func L6474_SetElectricalPosition is used to write the current stepper electrical position. The library must not be in stRESET state to perform this operation. The electrical Position consists of the step state and micro step component of the driver.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_SetPositionMark()

int L6474_SetPositionMark ( L6474_Handle_t h,
int position )

func L6474_SetPositionMark is used to write the current stepper position mark. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_SetPowerOutputs()

int L6474_SetPowerOutputs ( L6474_Handle_t h,
int ena )

func L6474_SetPowerOutputs is used to enable or disable the driver output stages. The library must not be in stRESET to perform this operation. The libraries state will be changed to stENABLED or stDISABLED depending on the ena parameter.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param ena is required and is either 0 when disabling or 1 when enabling is requested

◆ L6474_SetProperty()

int L6474_SetProperty ( L6474_Handle_t h,
L6474_Property_t prop,
int value )

func L6474_SetProperty is used to write a property of the type of L6474_Property_t. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param prop is required.

param value is required. The value formats can be found in the datasheet

◆ L6474_SetStepMode()

int L6474_SetStepMode ( L6474_Handle_t h,
L6474x_StepMode_t mode )

func L6474_SetStepMode is used to change the step mode and therefore the resolution. It is required to execute a new reference run because the position value of the lib does not match the stepping mode anymore. The library must not be in stRESET to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param mode is required and is one out of L6474x_StepMode_t

◆ L6474_StepIncremental()

int L6474_StepIncremental ( L6474_Handle_t h,
int steps )

func L6474_StepIncremental is used to issue a movement with the given amount of steps. The library has to be in stENABLED state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param steps is required. negative values lead to a counter clock wise movement, 0 does not lead to any movement but returns errcNONE in case no other issue is present.

◆ L6474_StopMovement()

int L6474_StopMovement ( L6474_Handle_t h)

func L6474_StopMovement is used to stop a pending movement in case it has been configured as async. If not, it always return errcNONE in case no other issue is present. The library has to be in stENABLED state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

Variable Documentation

◆ L6474_Parameters

const L6474x_ParameterDescriptor_t L6474_Parameters[STEP_REG_RANGE_MASK]
static
Initial value:
= {
[STEP_REG_ABS_POS] = { .command = STEP_REG_ABS_POS, .defined = 1, .length = STEP_LEN_ABS_POS, .mask = STEP_MASK_ABS_POS, .name = "ABS_POS", .flags = afREAD | afWRITE },
[STEP_REG_EL_POS] = { .command = STEP_REG_EL_POS, .defined = 1, .length = STEP_LEN_EL_POS, .mask = STEP_MASK_EL_POS, .name = "EL_POS", .flags = afREAD | afWRITE },
[STEP_REG_MARK] = { .command = STEP_REG_MARK, .defined = 1, .length = STEP_LEN_MARK, .mask = STEP_MASK_MARK, .name = "MARK", .flags = afREAD | afWRITE },
[STEP_REG_TVAL] = { .command = STEP_REG_TVAL, .defined = 1, .length = STEP_LEN_TVAL, .mask = STEP_MASK_TVAL, .name = "TVAL", .flags = afREAD | afWRITE },
[STEP_REG_T_FAST] = { .command = STEP_REG_T_FAST, .defined = 1, .length = STEP_LEN_T_FAST, .mask = STEP_MASK_T_FAST, .name = "T_FAST", .flags = afREAD | afWRITE_HighZ },
[STEP_REG_TON_MIN] = { .command = STEP_REG_TON_MIN, .defined = 1, .length = STEP_LEN_TON_MIN, .mask = STEP_MASK_TON_MIN, .name = "TON_MIN", .flags = afREAD | afWRITE_HighZ },
[STEP_REG_TOFF_MIN] = { .command = STEP_REG_TOFF_MIN, .defined = 1, .length = STEP_LEN_TOFF_MIN, .mask = STEP_MASK_TOFF_MIN, .name = "TOFF_MIN", .flags = afREAD | afWRITE_HighZ },
[STEP_REG_ADC_OUT] = { .command = STEP_REG_ADC_OUT, .defined = 1, .length = STEP_LEN_ADC_OUT, .mask = STEP_MASK_ADC_OUT, .name = "ADC_OUT", .flags = afREAD },
[STEP_REG_OCD_TH] = { .command = STEP_REG_OCD_TH, .defined = 1, .length = STEP_LEN_OCD_TH, .mask = STEP_MASK_OCD_TH, .name = "OCD_TH", .flags = afREAD | afWRITE },
[STEP_REG_STEP_MODE] = { .command = STEP_REG_STEP_MODE, .defined = 1, .length = STEP_LEN_STEP_MODE, .mask = STEP_MASK_STEP_MODE, .name = "STEP_MODE", .flags = afREAD | afWRITE_HighZ },
[STEP_REG_ALARM_EN] = { .command = STEP_REG_ALARM_EN, .defined = 1, .length = STEP_LEN_ALARM_EN, .mask = STEP_MASK_ALARM_EN, .name = "ALARM_EN", .flags = afREAD | afWRITE },
[STEP_REG_CONFIG] = { .command = STEP_REG_CONFIG, .defined = 1, .length = STEP_LEN_CONFIG, .mask = STEP_MASK_CONFIG, .name = "CONFIG", .flags = afREAD | afWRITE_HighZ },
[STEP_REG_STATUS] = { .command = STEP_REG_STATUS, .defined = 1, .length = STEP_LEN_STATUS, .mask = STEP_MASK_STATUS, .name = "STATUS", .flags = afREAD }
}