![]() |
LibL6474-C-Library 1.0
Library Code documentation
|
#include "LibL6474Config.h"
Include dependency graph for LibL6474.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | L6474_Status |
| struct | L6474x_Platform |
| struct | L6474_BaseParameter_t |
Macros | |
| #define | INC_LIBL6474_H_ INC_LIBL6474_H_ |
Typedefs | |
| typedef enum L6474x_State | L6474x_State_t |
| typedef enum L6474x_StepMode | L6474x_StepMode_t |
| typedef enum L6474x_Direction | L6474x_Direction_t |
| typedef enum L6474x_ErrorCode | L6474x_ErrorCode_t |
| typedef struct L6474_Status | L6474_Status_t |
| typedef enum L6474x_OCD_TH | L6474x_OCD_TH_t |
| typedef struct L6474_Handle * | L6474_Handle_t |
| typedef struct L6474x_Platform | L6474x_Platform_t |
Enumerations | |
| enum | L6474x_State { stRESET = 0x00 , stDISABLED = 0x01 , stENABLED = 0x02 , stINVALID = 0x04 } |
| enum | L6474x_StepMode { smFULL = 0x00 , smHALF = 0x01 , smMICRO4 = 0x02 , smMICRO8 = 0x03 , smMICRO16 = 0x04 } |
| enum | L6474x_Direction { dirFOREWARD = 0x00 , dirBACKWARD = 0x01 } |
| enum | L6474x_ErrorCode { errcNONE = 0 , errcINV_ARG = -1 , errcNULL_ARG = -2 , errcINV_STATE = -3 , errcINTERNAL = -4 , errcLOCKING = -5 , errcDEVICE_STATE = -6 , errcPENDING = -7 , errcFORBIDDEN = -8 } |
| enum | L6474x_OCD_TH { ocdth375mA = 0x00 , ocdth750mA = 0x01 , ocdth1125mA = 0x02 , ocdth1500mA = 0x03 , ocdth1875mA = 0x04 , ocdth2250mA = 0x05 , ocdth2625mA = 0x06 , ocdth3000mA = 0x07 , ocdth3375mA = 0x08 , ocdth3750mA = 0x09 , ocdth4125mA = 0x0A , ocdth4500mA = 0x0B , ocdth4875mA = 0x0C , ocdth5250mA = 0x0D , ocdth5625mA = 0x0E , ocdth6000mA = 0x0F } |
| enum | L6474_Property_t { L6474_PROP_TORQUE = 0x09 , L6474_PROP_TON = 0x0F , L6474_PROP_TOFF = 0x10 , L6474_PROP_ADC_OUT = 0x12 , L6474_PROP_OCDTH = 0x13 , L6474_PROP_TFAST = 0x0E } |
| typedef struct L6474_Handle* L6474_Handle_t |
The L6474_Handle_t handle is an instance pointer of the driver library which is generated whenever the L6474_CreateInstance function returns with success. Therefore at least a L6474x_Platform_t platform description pointer is required
| typedef struct L6474_Status L6474_Status_t |
The L6474_Status_t enum describes the status register content of the stepper driver chip. It is reinterpreted so it can be naturally used in the code to get some of the error codes or state bits of the driver.
| typedef enum L6474x_Direction L6474x_Direction_t |
The L6474x_Direction_t enum describes the direction of the driver and therefore the rotation of the stepper axis.
| typedef enum L6474x_ErrorCode L6474x_ErrorCode_t |
The L6474x_ErrorCode_t enum describes the possible error codes when using the API commands. Those error codes are mostly returned as return value by the API function which has been called previously
| typedef enum L6474x_OCD_TH L6474x_OCD_TH_t |
The L6474x_OCD_TH_t enum describes the possible overcurrent threshold values which can be set in the library and which are then taken into account by the stepper driver
| typedef struct L6474x_Platform L6474x_Platform_t |
The L6474x_Platform_t structure is used to encapsulate platform specific parameters and to provide environment specific functions in a generalized format. Theses functions are malloc and free or some PWM and GPIO abstractions The lock guards and thread safety mechanisms are also abstracted by this structure
| typedef enum L6474x_State L6474x_State_t |
The LibL6474Config.h must be provided by the user project. The header in conf folder is only a template!
The L6474x_State_t enum is used to describe the current state of the driver library which helps the user to decide the next steps to be taken or to get notified about an unexpected state which is caused by an error
| typedef enum L6474x_StepMode L6474x_StepMode_t |
The L6474x_StepMode_t enum is used to describe the current step mode (resolution) of the driver library and the stepper motor. This changes the internal calculations for speed and position and requires a new reference run in case it will be changed at runtime.
| enum L6474_Property_t |
The L6474_Property_t enum is a address representation for externally changeable properties by the library via the API commands. In case the torque shall be changed, the user can call L6474_SetProperty with the L6474_PROP_TORQUE entry. Some of the properties can not be changed while the driver outputs are enabled and the library is in stENABLED state
| enum L6474x_Direction |
The L6474x_Direction_t enum describes the direction of the driver and therefore the rotation of the stepper axis.
| Enumerator | |
|---|---|
| dirFOREWARD | dirFOREWARD is interpreted as clock wise rotation |
| dirBACKWARD | dirFOREWARD is interpreted as counter clock wise rotation |
| enum L6474x_ErrorCode |
The L6474x_ErrorCode_t enum describes the possible error codes when using the API commands. Those error codes are mostly returned as return value by the API function which has been called previously
| Enumerator | |
|---|---|
| errcNONE | errcNONE means no error and the operation was successful |
| errcINV_ARG | errcINV_ARG means that at least one argument was invalid or out of range |
| errcNULL_ARG | errcNULL_ARG means that at least one argument was a null pointer where it was not expected |
| errcINV_STATE | errcINV_STATE means that the stepper driver or the library is not in the state of type L6474x_State_t and therefore the operation can not be executed |
| errcINTERNAL | errcINTERNAL means an error which happens when calling abstraction functions which then return an error code |
| errcLOCKING | errcLOCKING in case the library is used multi-threaded, it might happen, that a function can not be locked because another caller is still using the library (lock guard principle). In mutex case this should not be returned by the API |
| errcDEVICE_STATE | errcDEVICE_STATE means that the state of the driver chip permits the operation |
| errcPENDING | errcPENDING means that another operation is still pending and therefore the operation can not be executed while there is still a pending one |
| errcFORBIDDEN | errcFORBIDDEN means that operation is not possible with the given arguments or this library |
| enum L6474x_OCD_TH |
The L6474x_OCD_TH_t enum describes the possible overcurrent threshold values which can be set in the library and which are then taken into account by the stepper driver
| enum L6474x_State |
The LibL6474Config.h must be provided by the user project. The header in conf folder is only a template!
The L6474x_State_t enum is used to describe the current state of the driver library which helps the user to decide the next steps to be taken or to get notified about an unexpected state which is caused by an error
| enum L6474x_StepMode |
The L6474x_StepMode_t enum is used to describe the current step mode (resolution) of the driver library and the stepper motor. This changes the internal calculations for speed and position and requires a new reference run in case it will be changed at runtime.
| 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
| 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
| 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
| 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
| 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
| 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
| 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.
| 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.
| 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
| 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
| 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
| 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
| 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.
| 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.
| 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.
| 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
| 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
| 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
| 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.
| 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.
| 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
| 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
| 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
| 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.
| 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.