f
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IHM01A1 by
Revision 0:2887415a46cd, committed 2015-10-14
- Comitter:
- Davidroid
- Date:
- Wed Oct 14 15:12:18 2015 +0000
- Child:
- 1:b38ebb8ea286
- Commit message:
- Library to handle the X_NUCLEO_IHM01A1 Motor Control Expansion Board.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/component.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,91 @@
+/**
+ ******************************************************************************
+ * @file component.h
+ * @author AST
+ * @version V1.0.0
+ * @date 1 April 2015
+ * @brief Generic header file containing a generic component's definitions
+ * and I/O functions.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Prevent recursive inclusion -----------------------------------------------*/
+
+#ifndef __COMPONENT_H__
+#define __COMPONENT_H__
+
+
+/* Types ---------------------------------------------------------------------*/
+
+/**
+ * @brief Component's Context structure definition.
+ */
+typedef struct
+{
+ /* Identity. */
+ uint8_t who_am_i;
+
+ /* ACTION ----------------------------------------------------------------*/
+ /* There should be only a unique identifier for each component, which */
+ /* should be the "who_am_i" parameter, hence this parameter is optional. */
+ /* -----------------------------------------------------------------------*/
+ /* Type. */
+ uint8_t type;
+
+ /* Configuration. */
+ uint8_t address;
+
+ /* Pointer to the Data. */
+ void *pData;
+
+ /* Pointer to the Virtual Table. */
+ void *pVTable;
+
+ /* ACTION ----------------------------------------------------------------*/
+ /* There should be only a unique virtual table for each component, which */
+ /* should be the "pVTable" parameter, hence this parameter is optional. */
+ /* -----------------------------------------------------------------------*/
+ /* Pointer to the Extended Virtual Table. */
+ void *pExtVTable;
+} DrvContextTypeDef;
+
+/**
+ * @brief Component's Status enumerator definition.
+ */
+typedef enum
+{
+ COMPONENT_OK = 0,
+ COMPONENT_ERROR,
+ COMPONENT_TIMEOUT,
+ COMPONENT_NOT_IMPLEMENTED
+} DrvStatusTypeDef;
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/motor.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,373 @@
+/**
+ ******************************************************************************
+ * @file motor.h
+ * @author IPC Rennes
+ * @version V1.3.0
+ * @date November 12, 2014
+ * @brief This file contains all the functions prototypes for motor drivers.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __MOTOR_H
+#define __MOTOR_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+#include "component.h"
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @defgroup Motor
+ * @{
+ */
+
+/** @defgroup Motor_Exported_Constants
+ * @{
+ */
+
+/// boolean for false condition
+#ifndef FALSE
+#define FALSE (0)
+#endif
+/// boolean for true condition
+#ifndef TRUE
+#define TRUE (1)
+#endif
+
+ /**
+ * @}
+ */
+
+/** @defgroup Motor_Exported_Types
+ * @{
+ */
+
+ /** @defgroup Motor_Boolean_Type
+ * @{
+ */
+///bool Type
+//typedef uint8_t bool;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Direction_Options
+ * @{
+ */
+/// Direction options
+typedef enum {
+ BACKWARD = 0,
+ FORWARD = 1
+} motorDir_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Action_Options
+ * @{
+ */
+/// Action options
+typedef enum {
+ ACTION_RESET = ((uint8_t)0x00),
+ ACTION_COPY = ((uint8_t)0x08)
+} motorAction_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_States
+ * @{
+ */
+/// Device states
+typedef enum {
+ ACCELERATING = 0,
+ DECELERATING = 1,
+ STEADY = 2,
+ INACTIVE= 3
+} motorState_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Step_mode
+ * @{
+ */
+ /// Stepping options
+typedef enum {
+ STEP_MODE_FULL = ((uint8_t)0x00),
+ STEP_MODE_HALF = ((uint8_t)0x01),
+ STEP_MODE_1_4 = ((uint8_t)0x02),
+ STEP_MODE_1_8 = ((uint8_t)0x03),
+ STEP_MODE_1_16 = ((uint8_t)0x04),
+ STEP_MODE_1_32 = ((uint8_t)0x05),
+ STEP_MODE_1_64 = ((uint8_t)0x06),
+ STEP_MODE_1_128 = ((uint8_t)0x07)
+} motorStepMode_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Commands
+ * @{
+ */
+/// Device commands
+typedef enum {
+ RUN_CMD,
+ MOVE_CMD,
+ SOFT_STOP_CMD,
+ NO_CMD
+} deviceCommand_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Parameters
+ * @{
+ */
+/// Device Parameters Structure Type
+typedef struct {
+ /// accumulator used to store speed increase smaller than 1 pps
+ volatile uint32_t accu;
+ /// Position in steps at the start of the goto or move commands
+ volatile int32_t currentPosition;
+ /// position in step at the end of the accelerating phase
+ volatile uint32_t endAccPos;
+ /// nb steps performed from the beggining of the goto or the move command
+ volatile uint32_t relativePos;
+ /// position in step at the start of the decelerating phase
+ volatile uint32_t startDecPos;
+ /// nb steps to perform for the goto or move commands
+ volatile uint32_t stepsToTake;
+
+ /// acceleration in pps^2
+ volatile uint16_t acceleration;
+ /// deceleration in pps^2
+ volatile uint16_t deceleration;
+ /// max speed in pps (speed use for goto or move command)
+ volatile uint16_t maxSpeed;
+ /// min speed in pps
+ volatile uint16_t minSpeed;
+ /// current speed in pps
+ volatile uint16_t speed;
+
+ /// command under execution
+ volatile deviceCommand_t commandExecuted;
+ /// FORWARD or BACKWARD direction
+ volatile motorDir_t direction;
+ /// Current State of the device
+ volatile motorState_t motionState;
+} deviceParams_t;
+/**
+ * @}
+ */
+
+/** @defgroup Motor_Driver_Initialization_Structure
+ * @{
+ */
+/// Motor driver initialization structure definition
+typedef struct
+{
+ int placeholder;
+} MOTOR_InitTypeDef;
+/**
+ * @}
+ */
+
+/** @defgroup Motor_Driver_Structure
+ * @{
+ */
+/// Motor driver structure definition
+typedef struct
+{
+ /* Generic */
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here component's generic functions. *
+ * *
+ * Example: *
+ * DrvStatusTypeDef (*Init)(void *handle, INTERFACE_InitTypeDef *init); *
+ *------------------------------------------------------------------------*/
+ DrvStatusTypeDef (*Init)(void *handle, MOTOR_InitTypeDef *init);
+ DrvStatusTypeDef (*ReadID)(void *handle, uint8_t *id);
+
+ /* Interrupts */
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here component's interrupts related functions. *
+ * *
+ * Example: *
+ * void (*ConfigIT)(void *handle, uint16_t a); *
+ *------------------------------------------------------------------------*/
+ /// Function pointer to AttachErrorHandler
+ void (*AttachErrorHandler)(void *handle, void (*callback)(void *handle, uint16_t error));
+ /// Function pointer to AttachFlagInterrupt
+ void (*AttachFlagInterrupt)(void *handle, void (*callback)(void *handle));
+ /// Function pointer to AttachBusyInterrupt
+ void (*AttachBusyInterrupt)(void *handle, void (*callback)(void *handle));
+ /// Function pointer to FlagInterruptHandler
+ void (*FlagInterruptHandler)(void *handle);
+
+ /* Specific */
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here component's specific functions. *
+ * *
+ * Example: *
+ * DrvStatusTypeDef (*GetValue)(void *handle, float *pfData); *
+ *------------------------------------------------------------------------*/
+ /// Function pointer to GetAcceleration
+ uint16_t (*GetAcceleration)(void *handle);
+ /// Function pointer to GetCurrentSpeed
+ uint16_t (*GetCurrentSpeed)(void *handle);
+ /// Function pointer to GetDeceleration
+ uint16_t (*GetDeceleration)(void *handle);
+ /// Function pointer to GetDeviceState
+ motorState_t(*GetDeviceState)(void *handle);
+ /// Function pointer to GetFwVersion
+ uint8_t (*GetFwVersion)(void *handle);
+ /// Function pointer to GetMark
+ int32_t (*GetMark)(void *handle);
+ /// Function pointer to GetMaxSpeed
+ uint16_t (*GetMaxSpeed)(void *handle);
+ /// Function pointer to GetMinSpeed
+ uint16_t (*GetMinSpeed)(void *handle);
+ /// Function pointer to GetPosition
+ int32_t (*GetPosition)(void *handle);
+ /// Function pointer to GoHome
+ void (*GoHome)(void *handle);
+ /// Function pointer to GoMark
+ void (*GoMark)(void *handle);
+ /// Function pointer to GoTo
+ void (*GoTo)(void *handle, int32_t targetPosition);
+ /// Function pointer to HardStop
+ void (*HardStop)(void *handle);
+ /// Function pointer to Move
+ void (*Move)(void *handle, motorDir_t direction, uint32_t stepCount);
+ /// Function pointer to ResetAllDevices
+ //void (*ResetAllDevices)(void *handle);
+ /// Function pointer to Run
+ void (*Run)(void *handle, motorDir_t direction);
+ /// Function pointer to SetAcceleration
+ bool(*SetAcceleration)(void *handle,uint16_t newAcc);
+ /// Function pointer to SetDeceleration
+ bool(*SetDeceleration)(void *handle, uint16_t newDec);
+ /// Function pointer to SetHome
+ void (*SetHome)(void *handle);
+ /// Function pointer to SetMark
+ void (*SetMark)(void *handle);
+ /// Function pointer to SetMaxSpeed
+ bool (*SetMaxSpeed)(void *handle, uint16_t newMaxSpeed);
+ /// Function pointer to SetMinSpeed
+ bool (*SetMinSpeed)(void *handle, uint16_t newMinSpeed);
+ /// Function pointer to SoftStop
+ bool (*SoftStop)(void *handle);
+ /// Function pointer to StepClockHandler
+ void (*StepClockHandler)(void *handle);
+ /// Function pointer to CmdDisable
+ void (*CmdDisable)(void *handle);
+ /// Function pointer to CmdEnable
+ void (*CmdEnable)(void *handle);
+ /// Function pointer to CmdGetParam
+ uint32_t (*CmdGetParam)(void *handle, uint32_t param);
+ /// Function pointer to CmdGetStatus
+ uint16_t (*CmdGetStatus)(void *handle);
+ /// Function pointer to CmdNop
+ void (*CmdNop)(void *handle);
+ /// Function pointer to CmdSetParam
+ void (*CmdSetParam)(void *handle, uint32_t param, uint32_t value);
+ /// Function pointer to ReadStatusRegister
+ uint16_t (*ReadStatusRegister)(void *handle);
+ /// Function pointer to ReleaseReset
+ void (*ReleaseReset)(void *handle);
+ /// Function pointer to Reset
+ void (*Reset)(void *handle);
+ /// Function pointer to SelectStepMode
+ void (*SelectStepMode)(void *handle, motorStepMode_t stepMod);
+ /// Function pointer to SetDirection
+ void (*SetDirection)(void *handle, motorDir_t direction);
+ /// Function pointer to CmdGoToDir
+ void (*CmdGoToDir)(void *handle, motorDir_t direction, int32_t targetPosition);
+ /// Function pointer to CheckBusyHw
+ uint8_t (*CheckBusyHw)(void *handle);
+ /// Function pointer to CheckStatusHw
+ uint8_t (*CheckStatusHw)(void *handle);
+ /// Function pointer to CmdGoUntil
+ void (*CmdGoUntil)(void *handle, motorAction_t action, motorDir_t direction, uint32_t targetPosition);
+ /// Function pointer to CmdHardHiZ
+ void (*CmdHardHiZ)(void *handle);
+ /// Function pointer to CmdReleaseSw
+ void (*CmdReleaseSw)(void *handle, motorAction_t action, motorDir_t direction);
+ /// Function pointer to CmdResetDevice
+ void (*CmdResetDevice)(void *handle);
+ /// Function pointer to CmdResetPos
+ void (*CmdResetPos)(void *handle);
+ /// Function pointer to CmdRun
+ void (*CmdRun)(void *handle, motorDir_t direction, uint32_t targetPosition);
+ /// Function pointer to CmdSoftHiZ
+ void (*CmdSoftHiZ)(void *handle);
+ /// Function pointer to CmdStepClock
+ void (*CmdStepClock)(void *handle, motorDir_t direction);
+ /// Function pointer to FetchAndClearAllStatus
+ void (*FetchAndClearAllStatus)(void *handle);
+ /// Function pointer to GetFetchedStatus
+ uint16_t (*GetFetchedStatus)(void *handle);
+ /// Function pointer to GetNbDevices
+ uint8_t (*GetNbDevices)(void *handle);
+ /// Function pointer to IsDeviceBusy
+ bool (*IsDeviceBusy)(void *handle);
+ /// Function pointer to SendQueuedCommands
+ void (*SendQueuedCommands)(void *handle);
+ /// Function pointer to QueueCommands
+ void (*QueueCommands)(void *handle, uint8_t temp, uint32_t command);
+ /// Function pointer to WaitForAllDevicesNotBusy
+ void (*WaitForAllDevicesNotBusy)(void *handle);
+ /// Function pointer to ErrorHandler
+ void (*ErrorHandler)(void *handle, uint16_t error);
+ /// Function pointer to BusyInterruptHandler
+ void (*BusyInterruptHandler)(void *handle);
+ /// Function pointer to CmdSoftStop
+ void (*CmdSoftStop)(void *handle);
+} MOTOR_DrvVTableTypeDef;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MOTOR_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Interfaces/Component_class.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,75 @@
+/**
+ ******************************************************************************
+ * @file Component_class.h
+ * @author AST / EST
+ * @version V0.0.1
+ * @date 13-April-2015
+ * @brief This file contains the abstract class describing the interface of a
+ * generic component.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Define to prevent from recursive inclusion --------------------------------*/
+
+#ifndef __COMPONENT_CLASS_H
+#define __COMPONENT_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include <stdint.h>
+
+
+/* Classes ------------------------------------------------------------------*/
+
+/** An abstract class for Generic components.
+ */
+class Component
+{
+public:
+ /**
+ * @brief Initialization of the component.
+ * @param[out] ptr Pointer to device specific initalization structure.
+ * @return 0 in case of success, an error code otherwise.
+ */
+ virtual int Init(void *ptr) = 0;
+
+ /**
+ * @brief Get ID of the component.
+ * @param[out] id Pointer to where to store the ID to.
+ * @return 0 in case of success, an error code otherwise.
+ */
+ virtual int ReadID(uint8_t *id) = 0;
+};
+
+#endif /* __COMPONENT_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Interfaces/Motor_class.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,120 @@
+/**
+ ******************************************************************************
+ * @file Motor_class.h
+ * @author AST / EST
+ * @version V0.0.1
+ * @date 13-April-2015
+ * @brief This file contains the abstract class describing the interface of a
+ * motor component.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Generated with Stm32CubeTOO -----------------------------------------------*/
+
+
+/* Revision ------------------------------------------------------------------*/
+/*
+ Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
+ Branch/Trunk/Tag: trunk
+ Based on: X-CUBE-SPN1/trunk/Drivers/BSP/Components/Common/motor.h
+ Revision: 0
+*/
+
+
+/* Define to prevent from recursive inclusion --------------------------------*/
+
+#ifndef __MOTOR_CLASS_H
+#define __MOTOR_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include <Component_class.h>
+
+
+/* Classes ------------------------------------------------------------------*/
+
+/** An abstract class for Motor components.
+ */
+class Motor : public Component
+{
+public:
+ /* ACTION 1 --------------------------------------------------------------*
+ * Declare here the interface's methods. *
+ * They should be: *
+ * + Methods with the same name of the C component's virtual table *
+ * (and extended virtual table, if any)'s functions, provided that *
+ * the component's driver implements them (i.e.: the corresponding *
+ * pointer to function is not "0"). *
+ * *
+ * Example: *
+ * virtual int GetValue(float *pfData) = 0; *
+ *------------------------------------------------------------------------*/
+ virtual uint16_t GetAcceleration (void) = 0;
+ virtual uint16_t GetCurrentSpeed (void) = 0;
+ virtual uint16_t GetDeceleration (void) = 0;
+ virtual motorState_t GetDeviceState (void) = 0;
+ virtual uint8_t GetFwVersion (void) = 0;
+ virtual int32_t GetMark (void) = 0;
+ virtual uint16_t GetMaxSpeed (void) = 0;
+ virtual uint16_t GetMinSpeed (void) = 0;
+ virtual int32_t GetPosition (void) = 0;
+ virtual void GoHome (void) = 0;
+ virtual void GoMark (void) = 0;
+ virtual void GoTo (int32_t targetPosition) = 0;
+ virtual void HardStop (void) = 0;
+ virtual void Move (motorDir_t direction, uint32_t stepCount) = 0;
+ virtual void Run (motorDir_t direction) = 0;
+ virtual bool SetAcceleration (uint16_t newAcc) = 0;
+ virtual bool SetDeceleration (uint16_t newDec) = 0;
+ virtual void SetHome (void) = 0;
+ virtual void SetMark (void) = 0;
+ virtual bool SetMaxSpeed (uint16_t newMaxSpeed) = 0;
+ virtual bool SetMinSpeed (uint16_t newMinSpeed) = 0;
+ virtual bool SoftStop (void) = 0;
+ virtual void StepClockHandler (void) = 0;
+ virtual void CmdDisable (void) = 0;
+ virtual void CmdEnable (void) = 0;
+ virtual uint32_t CmdGetParam (uint32_t param) = 0;
+ virtual uint16_t CmdGetStatus (void) = 0;
+ virtual void CmdNop (void) = 0;
+ virtual void CmdSetParam (uint32_t param, uint32_t value) = 0;
+ virtual uint16_t ReadStatusRegister (void) = 0;
+ virtual void ReleaseReset (void) = 0;
+ virtual void Reset (void) = 0;
+ virtual void SelectStepMode (motorStepMode_t stepMod) = 0;
+ virtual void SetDirection (motorDir_t direction) = 0;
+ virtual void ErrorHandler (uint16_t error) = 0;
+};
+
+#endif /* __MOTOR_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6474/l6474.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,530 @@
+/**
+ ******************************************************************************
+ * @file l6474.h
+ * @author IPC Rennes
+ * @version V1.5.0
+ * @date November 12, 2014
+ * @brief Header for L6474 driver (fully integrated microstepping motor driver)
+ * @note (C) COPYRIGHT 2014 STMicroelectronics
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __L6474_H
+#define __L6474_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "l6474_target_config.h"
+#include "../Common/motor.h"
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup L6474
+ * @{
+ */
+
+/* Exported Constants --------------------------------------------------------*/
+
+/** @defgroup L6474_Exported_Constants
+ * @{
+ */
+
+/// Current FW version
+#define L6474_FW_VERSION (5)
+
+/// L6474 max number of bytes of command & arguments to set a parameter
+#define L6474_CMD_ARG_MAX_NB_BYTES (4)
+
+/// L6474 command + argument bytes number for GET_STATUS command
+#define L6474_CMD_ARG_NB_BYTES_GET_STATUS (1)
+
+/// L6474 response bytes number
+#define L6474_RSP_NB_BYTES_GET_STATUS (2)
+
+/// L6474 value mask for ABS_POS register
+#define L6474_ABS_POS_VALUE_MASK ((uint32_t) 0x003FFFFF)
+
+/// L6474 sign bit mask for ABS_POS register
+#define L6474_ABS_POS_SIGN_BIT_MASK ((uint32_t) 0x00200000)
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/* Exported Types -------------------------------------------------------*/
+
+/** @defgroup L6474_Exported_Types
+ * @{
+ */
+
+/** @defgroup L6474_Fast_Decay_Time_Options
+ * @{
+ */
+///TOFF_FAST values for T_FAST register
+typedef enum {
+ L6474_TOFF_FAST_2us = ((uint8_t) 0x00 << 4),
+ L6474_TOFF_FAST_4us = ((uint8_t) 0x01 << 4),
+ L6474_TOFF_FAST_6us = ((uint8_t) 0x02 << 4),
+ L6474_TOFF_FAST_8us = ((uint8_t) 0x03 << 4),
+ L6474_TOFF_FAST_10us = ((uint8_t) 0x04 << 4),
+ L6474_TOFF_FAST_12us = ((uint8_t) 0x05 << 4),
+ L6474_TOFF_FAST_14us = ((uint8_t) 0x06 << 4),
+ L6474_TOFF_FAST_16us = ((uint8_t) 0x07 << 4),
+ L6474_TOFF_FAST_18us = ((uint8_t) 0x08 << 4),
+ L6474_TOFF_FAST_20us = ((uint8_t) 0x09 << 4),
+ L6474_TOFF_FAST_22us = ((uint8_t) 0x0A << 4),
+ L6474_TOFF_FAST_24us = ((uint8_t) 0x0B << 4),
+ L6474_TOFF_FAST_26us = ((uint8_t) 0x0C << 4),
+ L6474_TOFF_FAST_28us = ((uint8_t) 0x0D << 4),
+ L6474_TOFF_FAST_30us = ((uint8_t) 0x0E << 4),
+ L6474_TOFF_FAST_32us = ((uint8_t) 0x0F << 4)
+} L6474_TOFF_FAST_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Fall_Step_Time_Options
+ * @{
+ */
+///FAST_STEP values for T_FAST register
+typedef enum {
+ L6474_FAST_STEP_2us = ((uint8_t) 0x00),
+ L6474_FAST_STEP_4us = ((uint8_t) 0x01),
+ L6474_FAST_STEP_6us = ((uint8_t) 0x02),
+ L6474_FAST_STEP_8us = ((uint8_t) 0x03),
+ L6474_FAST_STEP_10us = ((uint8_t) 0x04),
+ L6474_FAST_STEP_12us = ((uint8_t) 0x05),
+ L6474_FAST_STEP_14us = ((uint8_t) 0x06),
+ L6474_FAST_STEP_16us = ((uint8_t) 0x07),
+ L6474_FAST_STEP_18us = ((uint8_t) 0x08),
+ L6474_FAST_STEP_20us = ((uint8_t) 0x09),
+ L6474_FAST_STEP_22us = ((uint8_t) 0x0A),
+ L6474_FAST_STEP_24us = ((uint8_t) 0x0B),
+ L6474_FAST_STEP_26us = ((uint8_t) 0x0C),
+ L6474_FAST_STEP_28us = ((uint8_t) 0x0D),
+ L6474_FAST_STEP_30us = ((uint8_t) 0x0E),
+ L6474_FAST_STEP_32us = ((uint8_t) 0x0F)
+} L6474_FAST_STEP_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Overcurrent_Threshold_options
+ * @{
+ */
+///OCD_TH register
+typedef enum {
+ L6474_OCD_TH_375mA = ((uint8_t) 0x00),
+ L6474_OCD_TH_750mA = ((uint8_t) 0x01),
+ L6474_OCD_TH_1125mA = ((uint8_t) 0x02),
+ L6474_OCD_TH_1500mA = ((uint8_t) 0x03),
+ L6474_OCD_TH_1875mA = ((uint8_t) 0x04),
+ L6474_OCD_TH_2250mA = ((uint8_t) 0x05),
+ L6474_OCD_TH_2625mA = ((uint8_t) 0x06),
+ L6474_OCD_TH_3000mA = ((uint8_t) 0x07),
+ L6474_OCD_TH_3375mA = ((uint8_t) 0x08),
+ L6474_OCD_TH_3750mA = ((uint8_t) 0x09),
+ L6474_OCD_TH_4125mA = ((uint8_t) 0x0A),
+ L6474_OCD_TH_4500mA = ((uint8_t) 0x0B),
+ L6474_OCD_TH_4875mA = ((uint8_t) 0x0C),
+ L6474_OCD_TH_5250mA = ((uint8_t) 0x0D),
+ L6474_OCD_TH_5625mA = ((uint8_t) 0x0E),
+ L6474_OCD_TH_6000mA = ((uint8_t) 0x0F)
+} L6474_OCD_TH_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_STEP_MODE_Register_Masks
+ * @{
+ */
+///STEP_MODE register
+typedef enum {
+ L6474_STEP_MODE_STEP_SEL = ((uint8_t) 0x07),
+ L6474_STEP_MODE_SYNC_SEL = ((uint8_t) 0x70)
+} L6474_STEP_MODE_Masks_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_STEP_SEL_Options_For_STEP_MODE_Register
+ * @{
+ */
+///STEP_SEL field of STEP_MODE register
+typedef enum {
+ L6474_STEP_SEL_1 = ((uint8_t) 0x08), //full step
+ L6474_STEP_SEL_1_2 = ((uint8_t) 0x09), //half step
+ L6474_STEP_SEL_1_4 = ((uint8_t) 0x0A), //1/4 microstep
+ L6474_STEP_SEL_1_8 = ((uint8_t) 0x0B), //1/8 microstep
+ L6474_STEP_SEL_1_16 = ((uint8_t) 0x0C) //1/16 microstep
+} L6474_STEP_SEL_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_SYNC_SEL_Options_For_STEP_MODE_Register
+ * @{
+ */
+///SYNC_SEL field of STEP_MODE register
+typedef enum {
+ L6474_SYNC_SEL_1_2 = ((uint8_t) 0x80),
+ L6474_SYNC_SEL_1 = ((uint8_t) 0x90),
+ L6474_SYNC_SEL_2 = ((uint8_t) 0xA0),
+ L6474_SYNC_SEL_4 = ((uint8_t) 0xB0),
+ L6474_SYNC_SEL_8 = ((uint8_t) 0xC0),
+ L6474_SYNC_SEL_UNUSED = ((uint8_t) 0xD0)
+} L6474_SYNC_SEL_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_ALARM_EN_Register_Options
+ * @{
+ */
+///ALARM_EN register
+typedef enum {
+ L6474_ALARM_EN_OVERCURRENT = ((uint8_t) 0x01),
+ L6474_ALARM_EN_THERMAL_SHUTDOWN = ((uint8_t) 0x02),
+ L6474_ALARM_EN_THERMAL_WARNING = ((uint8_t) 0x04),
+ L6474_ALARM_EN_UNDERVOLTAGE = ((uint8_t) 0x08),
+ L6474_ALARM_EN_SW_TURN_ON = ((uint8_t) 0x40),
+ L6474_ALARM_EN_WRONG_NPERF_CMD = ((uint8_t) 0x80)
+} L6474_ALARM_EN_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_CONFIG_Register_Masks
+ * @{
+ */
+///CONFIG register
+typedef enum {
+ L6474_CONFIG_OSC_SEL = ((uint16_t) 0x0007),
+ L6474_CONFIG_EXT_CLK = ((uint16_t) 0x0008),
+ L6474_CONFIG_EN_TQREG = ((uint16_t) 0x0020),
+ L6474_CONFIG_OC_SD = ((uint16_t) 0x0080),
+ L6474_CONFIG_POW_SR = ((uint16_t) 0x0300),
+ L6474_CONFIG_TOFF = ((uint16_t) 0x7C00)
+} L6474_CONFIG_Masks_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Clock_Source_Options_For_CONFIG_Register
+ * @{
+ */
+///Clock source option for CONFIG register
+typedef enum {
+ L6474_CONFIG_INT_16MHZ = ((uint16_t) 0x0000),
+ L6474_CONFIG_INT_16MHZ_OSCOUT_2MHZ = ((uint16_t) 0x0008),
+ L6474_CONFIG_INT_16MHZ_OSCOUT_4MHZ = ((uint16_t) 0x0009),
+ L6474_CONFIG_INT_16MHZ_OSCOUT_8MHZ = ((uint16_t) 0x000A),
+ L6474_CONFIG_INT_16MHZ_OSCOUT_16MHZ = ((uint16_t) 0x000B),
+ L6474_CONFIG_EXT_8MHZ_XTAL_DRIVE = ((uint16_t) 0x0004),
+ L6474_CONFIG_EXT_16MHZ_XTAL_DRIVE = ((uint16_t) 0x0005),
+ L6474_CONFIG_EXT_24MHZ_XTAL_DRIVE = ((uint16_t) 0x0006),
+ L6474_CONFIG_EXT_32MHZ_XTAL_DRIVE = ((uint16_t) 0x0007),
+ L6474_CONFIG_EXT_8MHZ_OSCOUT_INVERT = ((uint16_t) 0x000C),
+ L6474_CONFIG_EXT_16MHZ_OSCOUT_INVERT = ((uint16_t) 0x000D),
+ L6474_CONFIG_EXT_24MHZ_OSCOUT_INVERT = ((uint16_t) 0x000E),
+ L6474_CONFIG_EXT_32MHZ_OSCOUT_INVERT = ((uint16_t) 0x000F)
+} L6474_CONFIG_OSC_MGMT_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_External_Torque_Regulation_Options_For_CONFIG_Register
+ * @{
+ */
+///External Torque regulation options for CONFIG register
+typedef enum {
+ L6474_CONFIG_EN_TQREG_TVAL_USED = ((uint16_t) 0x0000),
+ L6474_CONFIG_EN_TQREG_ADC_OUT = ((uint16_t) 0x0020)
+} L6474_CONFIG_EN_TQREG_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Over_Current_Shutdown_Options_For_CONFIG_Register
+ * @{
+ */
+///Over Current Shutdown options for CONFIG register
+typedef enum {
+ L6474_CONFIG_OC_SD_DISABLE = ((uint16_t) 0x0000),
+ L6474_CONFIG_OC_SD_ENABLE = ((uint16_t) 0x0080)
+} L6474_CONFIG_OC_SD_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Power_Bridge_Output_Slew_Rate_Options
+ * @{
+ */
+/// POW_SR values for CONFIG register
+typedef enum {
+ L6474_CONFIG_SR_320V_us =((uint16_t)0x0000),
+ L6474_CONFIG_SR_075V_us =((uint16_t)0x0100),
+ L6474_CONFIG_SR_110V_us =((uint16_t)0x0200),
+ L6474_CONFIG_SR_260V_us =((uint16_t)0x0300)
+} L6474_CONFIG_POW_SR_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Off_Time_Options
+ * @{
+ */
+/// TOFF values for CONFIG register
+typedef enum {
+ L6474_CONFIG_TOFF_004us = (((uint16_t) 0x01) << 10),
+ L6474_CONFIG_TOFF_008us = (((uint16_t) 0x02) << 10),
+ L6474_CONFIG_TOFF_012us = (((uint16_t) 0x03) << 10),
+ L6474_CONFIG_TOFF_016us = (((uint16_t) 0x04) << 10),
+ L6474_CONFIG_TOFF_020us = (((uint16_t) 0x05) << 10),
+ L6474_CONFIG_TOFF_024us = (((uint16_t) 0x06) << 10),
+ L6474_CONFIG_TOFF_028us = (((uint16_t) 0x07) << 10),
+ L6474_CONFIG_TOFF_032us = (((uint16_t) 0x08) << 10),
+ L6474_CONFIG_TOFF_036us = (((uint16_t) 0x09) << 10),
+ L6474_CONFIG_TOFF_040us = (((uint16_t) 0x0A) << 10),
+ L6474_CONFIG_TOFF_044us = (((uint16_t) 0x0B) << 10),
+ L6474_CONFIG_TOFF_048us = (((uint16_t) 0x0C) << 10),
+ L6474_CONFIG_TOFF_052us = (((uint16_t) 0x0D) << 10),
+ L6474_CONFIG_TOFF_056us = (((uint16_t) 0x0E) << 10),
+ L6474_CONFIG_TOFF_060us = (((uint16_t) 0x0F) << 10),
+ L6474_CONFIG_TOFF_064us = (((uint16_t) 0x10) << 10),
+ L6474_CONFIG_TOFF_068us = (((uint16_t) 0x11) << 10),
+ L6474_CONFIG_TOFF_072us = (((uint16_t) 0x12) << 10),
+ L6474_CONFIG_TOFF_076us = (((uint16_t) 0x13) << 10),
+ L6474_CONFIG_TOFF_080us = (((uint16_t) 0x14) << 10),
+ L6474_CONFIG_TOFF_084us = (((uint16_t) 0x15) << 10),
+ L6474_CONFIG_TOFF_088us = (((uint16_t) 0x16) << 10),
+ L6474_CONFIG_TOFF_092us = (((uint16_t) 0x17) << 10),
+ L6474_CONFIG_TOFF_096us = (((uint16_t) 0x18) << 10),
+ L6474_CONFIG_TOFF_100us = (((uint16_t) 0x19) << 10),
+ L6474_CONFIG_TOFF_104us = (((uint16_t) 0x1A) << 10),
+ L6474_CONFIG_TOFF_108us = (((uint16_t) 0x1B) << 10),
+ L6474_CONFIG_TOFF_112us = (((uint16_t) 0x1C) << 10),
+ L6474_CONFIG_TOFF_116us = (((uint16_t) 0x1D) << 10),
+ L6474_CONFIG_TOFF_120us = (((uint16_t) 0x1E) << 10),
+ L6474_CONFIG_TOFF_124us = (((uint16_t) 0x1F) << 10)
+} L6474_CONFIG_TOFF_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_STATUS_Register_Bit_Masks
+ * @{
+ */
+///STATUS Register Bit Masks
+typedef enum {
+ L6474_STATUS_HIZ = (((uint16_t) 0x0001)),
+ L6474_STATUS_DIR = (((uint16_t) 0x0010)),
+ L6474_STATUS_NOTPERF_CMD = (((uint16_t) 0x0080)),
+ L6474_STATUS_WRONG_CMD = (((uint16_t) 0x0100)),
+ L6474_STATUS_UVLO = (((uint16_t) 0x0200)),
+ L6474_STATUS_TH_WRN = (((uint16_t) 0x0400)),
+ L6474_STATUS_TH_SD = (((uint16_t) 0x0800)),
+ L6474_STATUS_OCD = (((uint16_t) 0x1000))
+} L6474_STATUS_Masks_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Direction_Field_Of_STATUS_Register
+ * @{
+ */
+///Diretion field of STATUS register
+typedef enum {
+ L6474_STATUS_DIR_FORWARD = (((uint16_t) 0x0001) << 4),
+ L6474_STATUS_DIR_REVERSE = (((uint16_t) 0x0000) << 4)
+} L6474_STATUS_DIR_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Internal_Register_Addresses
+ * @{
+ */
+/// Internal L6474 register addresses
+typedef enum {
+ L6474_ABS_POS = ((uint8_t) 0x01),
+ L6474_EL_POS = ((uint8_t) 0x02),
+ L6474_MARK = ((uint8_t) 0x03),
+ L6474_RESERVED_REG01 = ((uint8_t) 0x04),
+ L6474_RESERVED_REG02 = ((uint8_t) 0x05),
+ L6474_RESERVED_REG03 = ((uint8_t) 0x06),
+ L6474_RESERVED_REG04 = ((uint8_t) 0x07),
+ L6474_RESERVED_REG05 = ((uint8_t) 0x08),
+ L6474_RESERVED_REG06 = ((uint8_t) 0x15),
+ L6474_TVAL = ((uint8_t) 0x09),
+ L6474_RESERVED_REG07 = ((uint8_t) 0x0A),
+ L6474_RESERVED_REG08 = ((uint8_t) 0x0B),
+ L6474_RESERVED_REG09 = ((uint8_t) 0x0C),
+ L6474_RESERVED_REG10 = ((uint8_t) 0x0D),
+ L6474_T_FAST = ((uint8_t) 0x0E),
+ L6474_TON_MIN = ((uint8_t) 0x0F),
+ L6474_TOFF_MIN = ((uint8_t) 0x10),
+ L6474_RESERVED_REG11 = ((uint8_t) 0x11),
+ L6474_ADC_OUT = ((uint8_t) 0x12),
+ L6474_OCD_TH = ((uint8_t) 0x13),
+ L6474_RESERVED_REG12 = ((uint8_t) 0x14),
+ L6474_STEP_MODE = ((uint8_t) 0x16),
+ L6474_ALARM_EN = ((uint8_t) 0x17),
+ L6474_CONFIG = ((uint8_t) 0x18),
+ L6474_STATUS = ((uint8_t) 0x19),
+ L6474_RESERVED_REG13 = ((uint8_t) 0x1A),
+ L6474_RESERVED_REG14 = ((uint8_t) 0x1B),
+ L6474_INEXISTENT_REG = ((uint8_t) 0x1F)
+} L6474_Registers_t;
+/**
+ * @}
+ */
+
+/** @defgroup L6474_Command_Set
+ * @{
+ */
+/// L6474 command set
+typedef enum {
+ L6474_NOP = ((uint8_t) 0x00),
+ L6474_SET_PARAM = ((uint8_t) 0x00),
+ L6474_GET_PARAM = ((uint8_t) 0x20),
+ L6474_ENABLE = ((uint8_t) 0xB8),
+ L6474_DISABLE = ((uint8_t) 0xA8),
+ L6474_GET_STATUS = ((uint8_t) 0xD0),
+ L6474_RESERVED_CMD1 = ((uint8_t) 0xEB),
+ L6474_RESERVED_CMD2 = ((uint8_t) 0xF8)
+} L6474_Commands_t;
+/**
+ * @}
+ */
+
+/**
+ * @brief L6474 driver data structure definition
+ */
+typedef struct
+{
+ /// Function pointer to flag interrupt call back
+ void (*flagInterruptCallback)(void);
+ /// Function pointer to error handler call back
+ void (*errorHandlerCallback)(uint16_t error);
+ uint8_t spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES]; //[MAX_NUMBER_OF_DEVICES];
+ uint8_t spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES]; //[MAX_NUMBER_OF_DEVICES];
+ bool spiPreemtionByIsr; // = FALSE;
+ bool isrFlag; // = FALSE;
+ /// L6474 Device Paramaters structure
+ deviceParams_t devicePrm; //[MAX_NUMBER_OF_DEVICES];
+ uint8_t numberOfDevices;
+ uint8_t deviceInstance;
+} L6474_DrvDataTypeDef;
+
+
+/* Functions -----------------------------------------------------------------*/
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @addtogroup L6474
+ * @{
+ */
+
+/** @defgroup L6474_IO_Functions L6474_IO_Functions
+ * @{
+ */
+/* ACTION --------------------------------------------------------------------*
+ * Declare here extern I/O functions you need and implemented them in a glue *
+ * logic file on the target environment, for example within the expansion *
+ * board "*.c" file. E.g.: *
+ * extern DrvStatusTypeDef COMPONENT_IO_Read (handle, buf, regadd, bytes); *
+ * extern DrvStatusTypeDef COMPONENT_IO_Write(handle, buf, regadd, bytes); *
+ *----------------------------------------------------------------------------*/
+///Delay of the requested number of milliseconds
+extern void L6474_Delay(void *handle, uint32_t delay);
+///Enable Irq
+extern void L6474_EnableIrq(void *handle);
+///Disable Irq
+extern void L6474_DisableIrq(void *handle);
+///Set PWM1 frequency and start it
+extern void L6474_Pwm1SetFreq(void *handle, uint16_t newFreq);
+///Set PWM2 frequency and start it
+extern void L6474_Pwm2SetFreq(void *handle, uint16_t newFreq);
+///Set PWM3 frequency and start it
+extern void L6474_Pwm3SetFreq(void *handle, uint16_t newFreq);
+///Init the PWM
+extern void L6474_PwmInit(void *handle);
+///Stop the PWM
+extern void L6474_PwmStop(void *handle);
+///Reset the L6474 reset pin
+extern void L6474_ReleaseReset(void *handle);
+///Set the L6474 reset pin
+extern void L6474_Reset(void *handle);
+///Set direction GPIO
+extern void L6474_SetDirectionGpio(void *handle, uint8_t gpioState);
+///Write bytes to the L6474s via SPI
+extern uint8_t L6474_SpiWriteBytes(void *handle, uint8_t *pByteToTransmit, uint8_t *pReceivedByte);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* #ifndef __L6474_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6474/l6474_class.cpp Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,1348 @@
+/**
+ ******************************************************************************
+ * @file l6474_class.cpp
+ * @author IPC Rennes
+ * @version V1.5.0
+ * @date November 12, 2014
+ * @brief L6474 driver (fully integrated microstepping motor driver)
+ * @note (C) COPYRIGHT 2014 STMicroelectronics
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Generated with Stm32CubeTOO -----------------------------------------------*/
+
+
+/* Revision ------------------------------------------------------------------*/
+/*
+ Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
+ Branch/Trunk/Tag: trunk
+ Based on: X-CUBE-SPN1/trunk/Drivers/BSP/Components/l6474/l6474.c
+ Revision: 0
+*/
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "l6474_class.h"
+#include "l6474.h"
+
+
+/* Private constants ---------------------------------------------------------*/
+
+/// Error while initialising the SPI
+#define L6474_ERROR_0 (0x8000)
+/// Error: Bad SPI transaction
+#define L6474_ERROR_1 (0x8001)
+
+/// Maximum number of steps
+#define MAX_STEPS (0x7FFFFFFF)
+
+/// Maximum frequency of the PWMs in Hz
+#define L6474_MAX_PWM_FREQ (10000)
+
+/// Minimum frequency of the PWMs in Hz
+#define L6474_MIN_PWM_FREQ (2)
+
+
+/* Private variables --------------------------------------------------------*/
+
+/* Number of devices. */
+uint8_t L6474::numberOfDevices = 0;
+
+
+/* Private function prototypes -----------------------------------------------*/
+
+/******************************************************//**
+ * @brief Attaches a user callback to the error Handler.
+ * The call back will be then called each time the library
+ * detects an error
+ * @param[in] callback Name of the callback to attach
+ * to the error Hanlder
+ * @retval None
+ **********************************************************/
+void L6474::L6474_AttachErrorHandler(void (*callback)(uint16_t error))
+{
+ errorHandlerCallback = (void (*)(uint16_t error)) callback;
+}
+
+/******************************************************//**
+ * @brief Attaches a user callback to the flag Interrupt
+ * The call back will be then called each time the status
+ * flag pin will be pulled down due to the occurrence of
+ * a programmed alarms ( OCD, thermal pre-warning or
+ * shutdown, UVLO, wrong command, non-performable command)
+ * @param[in] callback Name of the callback to attach
+ * to the Flag Interrupt
+ * @retval None
+ **********************************************************/
+void L6474::L6474_AttachFlagInterrupt(void (*callback)(void))
+{
+ flagInterruptCallback = (void (*)(void))callback;
+}
+
+/******************************************************//**
+ * @brief Starts the L6474 library
+ * @retval COMPONENT_OK in case of success
+ **********************************************************/
+DrvStatusTypeDef L6474::L6474_Init(MOTOR_InitTypeDef *L6474_Init)
+{
+ /* Initialise the PWMs used for the Step clocks ----------------------------*/
+ L6474_PwmInit();
+
+ /* Initialise the L6474s ------------------------------------------------*/
+
+ /* Standby-reset deactivation */
+ L6474_ReleaseReset();
+
+ /* Let a delay after reset */
+ L6474_Delay(1);
+
+ /* Set all registers and context variables to the predefined values from l6474_target_config.h */
+ L6474_SetDeviceParamsToPredefinedValues();
+
+ /* Disable L6474 powerstage */
+ L6474_CmdDisable();
+
+ /* Get Status to clear flags after start up */
+ L6474_CmdGetStatus();
+
+ return COMPONENT_OK;
+}
+
+/******************************************************//**
+ * @brief Read id
+ * @param id pointer to the identifier to be read.
+ * @retval COMPONENT_OK in case of success
+ **********************************************************/
+DrvStatusTypeDef L6474::L6474_ReadID(uint8_t *id)
+{
+ *id = type;
+
+ return COMPONENT_OK;
+}
+
+/******************************************************//**
+ * @brief Returns the acceleration of the specified device
+ * @retval Acceleration in pps^2
+ **********************************************************/
+uint16_t L6474::L6474_GetAcceleration(void)
+{
+ return (devicePrm.acceleration);
+}
+
+/******************************************************//**
+ * @brief Returns the current speed of the specified device
+ * @retval Speed in pps
+ **********************************************************/
+uint16_t L6474::L6474_GetCurrentSpeed(void)
+{
+ return devicePrm.speed;
+}
+
+/******************************************************//**
+ * @brief Returns the deceleration of the specified device
+ * @retval Deceleration in pps^2
+ **********************************************************/
+uint16_t L6474::L6474_GetDeceleration(void)
+{
+ return (devicePrm.deceleration);
+}
+
+/******************************************************//**
+ * @brief Returns the device state
+ * @retval State (ACCELERATING, DECELERATING, STEADY or INACTIVE)
+ **********************************************************/
+motorState_t L6474::L6474_GetDeviceState(void)
+{
+ return devicePrm.motionState;
+}
+
+/******************************************************//**
+ * @brief Returns the FW version of the library
+ * @param None
+ * @retval L6474_FW_VERSION
+ **********************************************************/
+uint8_t L6474::L6474_GetFwVersion(void)
+{
+ return (L6474_FW_VERSION);
+}
+
+/******************************************************//**
+ * @brief Returns the mark position of the specified device
+ * @retval Mark register value converted in a 32b signed integer
+ **********************************************************/
+int32_t L6474::L6474_GetMark(void)
+{
+ return L6474_ConvertPosition(L6474_CmdGetParam(L6474_MARK));
+}
+
+/******************************************************//**
+ * @brief Returns the max speed of the specified device
+ * @retval maxSpeed in pps
+ **********************************************************/
+uint16_t L6474::L6474_GetMaxSpeed(void)
+{
+ return (devicePrm.maxSpeed);
+}
+
+/******************************************************//**
+ * @brief Returns the min speed of the specified device
+ * @retval minSpeed in pps
+ **********************************************************/
+uint16_t L6474::L6474_GetMinSpeed(void)
+{
+ return (devicePrm.minSpeed);
+}
+
+/******************************************************//**
+ * @brief Returns the ABS_POSITION of the specified device
+ * @retval ABS_POSITION register value converted in a 32b signed integer
+ **********************************************************/
+int32_t L6474::L6474_GetPosition(void)
+{
+ return L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
+}
+
+/******************************************************//**
+ * @brief Requests the motor to move to the home position (ABS_POSITION = 0)
+ * @retval None
+ **********************************************************/
+void L6474::L6474_GoHome(void)
+{
+ L6474_GoTo(0);
+}
+
+/******************************************************//**
+ * @brief Requests the motor to move to the mark position
+ * @retval None
+ **********************************************************/
+void L6474::L6474_GoMark(void)
+{
+ uint32_t mark;
+
+ mark = L6474_ConvertPosition(L6474_CmdGetParam(L6474_MARK));
+ L6474_GoTo(mark);
+}
+
+/******************************************************//**
+ * @brief Requests the motor to move to the specified position
+ * @param[in] targetPosition absolute position in steps
+ * @retval None
+ **********************************************************/
+void L6474::L6474_GoTo(int32_t targetPosition)
+{
+ motorDir_t direction;
+ int32_t steps;
+
+ /* Eventually deactivate motor */
+ if (devicePrm.motionState != INACTIVE)
+ {
+ L6474_HardStop();
+ }
+
+ /* Get current position */
+ devicePrm.currentPosition = L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
+
+ /* Compute the number of steps to perform */
+ steps = targetPosition - devicePrm.currentPosition;
+
+ if (steps >= 0)
+ {
+ devicePrm.stepsToTake = steps;
+ direction = FORWARD;
+ }
+ else
+ {
+ devicePrm.stepsToTake = -steps;
+ direction = BACKWARD;
+ }
+
+ if (steps != 0)
+ {
+ devicePrm.commandExecuted = MOVE_CMD;
+
+ /* Direction setup */
+ L6474_SetDirection(direction);
+
+ L6474_ComputeSpeedProfile(devicePrm.stepsToTake);
+
+ /* Motor activation */
+ L6474_StartMovement();
+ }
+}
+
+/******************************************************//**
+ * @brief Immediatly stops the motor and disable the power bridge
+ * @retval None
+ **********************************************************/
+void L6474::L6474_HardStop(void)
+{
+ /* Disable corresponding PWM */
+ L6474_PwmStop();
+
+ /* Disable power stage */
+ L6474_CmdDisable();
+
+ /* Set inactive state */
+ devicePrm.motionState = INACTIVE;
+ devicePrm.commandExecuted = NO_CMD;
+ devicePrm.stepsToTake = MAX_STEPS;
+}
+
+/******************************************************//**
+ * @brief Moves the motor of the specified number of steps
+ * @param[in] direction FORWARD or BACKWARD
+ * @param[in] stepCount Number of steps to perform
+ * @retval None
+ **********************************************************/
+void L6474::L6474_Move(motorDir_t direction, uint32_t stepCount)
+{
+ /* Eventually deactivate motor */
+ if (devicePrm.motionState != INACTIVE)
+ {
+ L6474_HardStop();
+ }
+
+ if (stepCount != 0)
+ {
+ devicePrm.stepsToTake = stepCount;
+
+ devicePrm.commandExecuted = MOVE_CMD;
+
+ devicePrm.currentPosition = L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
+
+ /* Direction setup */
+ L6474_SetDirection(direction);
+
+ L6474_ComputeSpeedProfile(stepCount);
+
+ /* Motor activation */
+ L6474_StartMovement();
+ }
+}
+
+#if 0
+/******************************************************//**
+ * @brief Resets all L6474 devices
+ * @param None
+ * @retval None
+ **********************************************************/
+void L6474::L6474_ResetAllDevices(void)
+{
+ uint8_t loop;
+
+ for (loop = 0; loop < numberOfDevices; loop++)
+ {
+ /* Stop movement and disable power stage*/
+ L6474_HardStop(loop);
+ }
+ L6474_Reset();
+ L6474_Delay(1); // Reset pin must be forced low for at least 10us
+ L6474_ReleaseReset();
+ L6474_Delay(1);
+}
+#endif
+
+/******************************************************//**
+ * @brief Runs the motor. It will accelerate from the min
+ * speed up to the max speed by using the device acceleration.
+ * @param[in] direction FORWARD or BACKWARD
+ * @retval None
+ **********************************************************/
+void L6474::L6474_Run(motorDir_t direction)
+{
+ /* Eventually deactivate motor */
+ if (devicePrm.motionState != INACTIVE)
+ {
+ L6474_HardStop();
+ }
+
+ /* Direction setup */
+ L6474_SetDirection(direction);
+
+ devicePrm.commandExecuted = RUN_CMD;
+
+ /* Motor activation */
+ L6474_StartMovement();
+}
+
+/******************************************************//**
+ * @brief Changes the acceleration of the specified device
+ * @param[in] newAcc New acceleration to apply in pps^2
+ * @retval true if the command is successfully executed, else false
+ * @note The command is not performed is the device is executing
+ * a MOVE or GOTO command (but it can be used during a RUN command)
+ **********************************************************/
+bool L6474::L6474_SetAcceleration(uint16_t newAcc)
+{
+ bool cmdExecuted = FALSE;
+ if ((newAcc != 0)&&
+ ((devicePrm.motionState == INACTIVE)||
+ (devicePrm.commandExecuted == RUN_CMD)))
+ {
+ devicePrm.acceleration = newAcc;
+ cmdExecuted = TRUE;
+ }
+ return cmdExecuted;
+}
+
+/******************************************************//**
+ * @brief Changes the deceleration of the specified device
+ * @param[in] newDec New deceleration to apply in pps^2
+ * @retval true if the command is successfully executed, else false
+ * @note The command is not performed is the device is executing
+ * a MOVE or GOTO command (but it can be used during a RUN command)
+ **********************************************************/
+bool L6474::L6474_SetDeceleration(uint16_t newDec)
+{
+ bool cmdExecuted = FALSE;
+ if ((newDec != 0)&&
+ ((devicePrm.motionState == INACTIVE)||
+ (devicePrm.commandExecuted == RUN_CMD)))
+ {
+ devicePrm.deceleration = newDec;
+ cmdExecuted = TRUE;
+ }
+ return cmdExecuted;
+}
+
+/******************************************************//**
+ * @brief Set current position to be the Home position (ABS pos set to 0)
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SetHome(void)
+{
+ L6474_CmdSetParam(L6474_ABS_POS, 0);
+}
+
+/******************************************************//**
+ * @brief Sets current position to be the Mark position
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SetMark(void)
+{
+ uint32_t mark = L6474_CmdGetParam(L6474_ABS_POS);
+ L6474_CmdSetParam(L6474_MARK, mark);
+}
+
+/******************************************************//**
+ * @brief Changes the max speed of the specified device
+ * @param[in] newMaxSpeed New max speed to apply in pps
+ * @retval true if the command is successfully executed, else false
+ * @note The command is not performed is the device is executing
+ * a MOVE or GOTO command (but it can be used during a RUN command).
+ **********************************************************/
+bool L6474::L6474_SetMaxSpeed(uint16_t newMaxSpeed)
+{
+ bool cmdExecuted = FALSE;
+ if ((newMaxSpeed >= L6474_MIN_PWM_FREQ)&&
+ (newMaxSpeed <= L6474_MAX_PWM_FREQ) &&
+ (devicePrm.minSpeed <= newMaxSpeed) &&
+ ((devicePrm.motionState == INACTIVE)||
+ (devicePrm.commandExecuted == RUN_CMD)))
+ {
+ devicePrm.maxSpeed = newMaxSpeed;
+ cmdExecuted = TRUE;
+ }
+ return cmdExecuted;
+}
+
+/******************************************************//**
+ * @brief Changes the min speed of the specified device
+ * @param[in] newMinSpeed New min speed to apply in pps
+ * @retval true if the command is successfully executed, else false
+ * @note The command is not performed is the device is executing
+ * a MOVE or GOTO command (but it can be used during a RUN command).
+ **********************************************************/
+bool L6474::L6474_SetMinSpeed(uint16_t newMinSpeed)
+{
+ bool cmdExecuted = FALSE;
+ if ((newMinSpeed >= L6474_MIN_PWM_FREQ)&&
+ (newMinSpeed <= L6474_MAX_PWM_FREQ) &&
+ (newMinSpeed <= devicePrm.maxSpeed) &&
+ ((devicePrm.motionState == INACTIVE)||
+ (devicePrm.commandExecuted == RUN_CMD)))
+ {
+ devicePrm.minSpeed = newMinSpeed;
+ cmdExecuted = TRUE;
+ }
+ return cmdExecuted;
+}
+
+/******************************************************//**
+ * @brief Stops the motor by using the device deceleration
+ * @retval true if the command is successfully executed, else false
+ * @note The command is not performed is the device is in INACTIVE state.
+ **********************************************************/
+bool L6474::L6474_SoftStop(void)
+{
+ bool cmdExecuted = FALSE;
+ if (devicePrm.motionState != INACTIVE)
+ {
+ devicePrm.commandExecuted = SOFT_STOP_CMD;
+ cmdExecuted = TRUE;
+ }
+ return (cmdExecuted);
+}
+
+/******************************************************//**
+ * @brief Issue the Disable command to the L6474 of the specified device
+ * @retval None
+ **********************************************************/
+void L6474::L6474_CmdDisable(void)
+{
+ L6474_SendCommand(L6474_DISABLE);
+}
+
+/******************************************************//**
+ * @brief Issues the Enable command to the L6474 of the specified device
+ * @retval None
+ **********************************************************/
+void L6474::L6474_CmdEnable(void)
+{
+ L6474_SendCommand(L6474_ENABLE);
+}
+
+/******************************************************//**
+ * @brief Issues the GetParam command to the L6474 of the specified device
+ * @param[in] param Register adress (L6474_ABS_POS, L6474_MARK,...)
+ * @retval Register value
+ **********************************************************/
+uint32_t L6474::L6474_CmdGetParam(uint32_t param)
+{
+ uint32_t i;
+ uint32_t spiRxData;
+ uint8_t maxArgumentNbBytes = 0;
+ bool itDisable = FALSE;
+
+ do
+ {
+ spiPreemtionByIsr = FALSE;
+ if (itDisable)
+ {
+ /* re-enable L6474_EnableIrq if disable in previous iteration */
+ L6474_EnableIrq();
+ itDisable = FALSE;
+ }
+
+ spiTxBursts[0] = L6474_NOP;
+ spiTxBursts[1] = L6474_NOP;
+ spiTxBursts[2] = L6474_NOP;
+ spiTxBursts[3] = L6474_NOP;
+ spiRxBursts[1] = 0;
+ spiRxBursts[2] = 0;
+ spiRxBursts[3] = 0;
+
+ switch (param)
+ {
+ case L6474_ABS_POS: ;
+ case L6474_MARK:
+ spiTxBursts[0] = ((uint8_t)L6474_GET_PARAM )| (param);
+ maxArgumentNbBytes = 3;
+ break;
+ case L6474_EL_POS: ;
+ case L6474_CONFIG: ;
+ case L6474_STATUS:
+ spiTxBursts[1] = ((uint8_t)L6474_GET_PARAM )| (param);
+ maxArgumentNbBytes = 2;
+ break;
+ default:
+ spiTxBursts[2] = ((uint8_t)L6474_GET_PARAM )| (param);
+ maxArgumentNbBytes = 1;
+ }
+
+ /* Disable interruption before checking */
+ /* pre-emption by ISR and SPI transfers*/
+ L6474_DisableIrq();
+ itDisable = TRUE;
+ } while (spiPreemtionByIsr); // check pre-emption by ISR
+
+ for (i = L6474_CMD_ARG_MAX_NB_BYTES-1-maxArgumentNbBytes;
+ i < L6474_CMD_ARG_MAX_NB_BYTES;
+ i++)
+ {
+ L6474_WriteBytes(&spiTxBursts[i], &spiRxBursts[i]);
+ }
+
+ spiRxData = ((uint32_t)spiRxBursts[1] << 16) |
+ (spiRxBursts[2] << 8) |
+ (spiRxBursts[3]);
+
+ /* re-enable L6474_EnableIrq after SPI transfers*/
+ L6474_EnableIrq();
+
+ return (spiRxData);
+}
+
+/******************************************************//**
+ * @brief Issues the GetStatus command to the L6474 of the specified device
+ * @retval Status Register value
+ * @note Once the GetStatus command is performed, the flags of the status register
+ * are reset. This is not the case when the status register is read with the
+ * GetParam command (via the functions L6474ReadStatusRegister or L6474CmdGetParam).
+ **********************************************************/
+uint16_t L6474::L6474_CmdGetStatus(void)
+{
+ uint32_t i;
+ uint16_t status;
+ bool itDisable = FALSE;
+
+ do
+ {
+ spiPreemtionByIsr = FALSE;
+ if (itDisable)
+ {
+ /* re-enable L6474_EnableIrq if disable in previous iteration */
+ L6474_EnableIrq();
+ itDisable = FALSE;
+ }
+
+ spiTxBursts[0] = L6474_NOP;
+ spiTxBursts[1] = L6474_NOP;
+ spiTxBursts[2] = L6474_NOP;
+ spiRxBursts[1] = 0;
+ spiRxBursts[2] = 0;
+ spiTxBursts[0] = L6474_GET_STATUS;
+
+ /* Disable interruption before checking */
+ /* pre-emption by ISR and SPI transfers*/
+ L6474_DisableIrq();
+ itDisable = TRUE;
+ } while (spiPreemtionByIsr); // check pre-emption by ISR
+
+ for (i = 0; i < L6474_CMD_ARG_NB_BYTES_GET_STATUS + L6474_RSP_NB_BYTES_GET_STATUS; i++)
+ {
+ L6474_WriteBytes(&spiTxBursts[i], &spiRxBursts[i]);
+ }
+ status = (spiRxBursts[1] << 8) | (spiRxBursts[2]);
+
+ /* re-enable L6474_EnableIrq after SPI transfers*/
+ L6474_EnableIrq();
+
+ return (status);
+}
+
+/******************************************************//**
+ * @brief Issues the Nop command to the L6474 of the specified device
+ * @retval None
+ **********************************************************/
+void L6474::L6474_CmdNop(void)
+{
+ L6474_SendCommand(L6474_NOP);
+}
+
+/******************************************************//**
+ * @brief Issues the SetParam command to the L6474 of the specified device
+ * @param[in] param Register adress (L6474_ABS_POS, L6474_MARK,...)
+ * @param[in] value Value to set in the register
+ * @retval None
+ **********************************************************/
+void L6474::L6474_CmdSetParam(uint32_t param, uint32_t value)
+{
+ uint32_t i;
+ uint8_t maxArgumentNbBytes = 0;
+ bool itDisable = FALSE;
+ do
+ {
+ spiPreemtionByIsr = FALSE;
+ if (itDisable)
+ {
+ /* re-enable L6474_EnableIrq if disable in previous iteration */
+ L6474_EnableIrq();
+ itDisable = FALSE;
+ }
+
+ spiTxBursts[0] = L6474_NOP;
+ spiTxBursts[1] = L6474_NOP;
+ spiTxBursts[2] = L6474_NOP;
+ spiTxBursts[3] = L6474_NOP;
+
+ switch (param)
+ {
+ case L6474_ABS_POS: ;
+ case L6474_MARK:
+ spiTxBursts[0] = param;
+ spiTxBursts[1] = (uint8_t)(value >> 16);
+ spiTxBursts[2] = (uint8_t)(value >> 8);
+ maxArgumentNbBytes = 3;
+ break;
+ case L6474_EL_POS: ;
+ case L6474_CONFIG:
+ spiTxBursts[1] = param;
+ spiTxBursts[2] = (uint8_t)(value >> 8);
+ maxArgumentNbBytes = 2;
+ break;
+ default:
+ spiTxBursts[2] = param;
+ maxArgumentNbBytes = 1;
+ break;
+ }
+ spiTxBursts[3] = (uint8_t)(value);
+
+ /* Disable interruption before checking */
+ /* pre-emption by ISR and SPI transfers*/
+ L6474_DisableIrq();
+ itDisable = TRUE;
+ } while (spiPreemtionByIsr); // check pre-emption by ISR
+
+ /* SPI transfer */
+ for (i = L6474_CMD_ARG_MAX_NB_BYTES-1-maxArgumentNbBytes;
+ i < L6474_CMD_ARG_MAX_NB_BYTES;
+ i++)
+ {
+ L6474_WriteBytes(&spiTxBursts[i],&spiRxBursts[i]);
+ }
+ /* re-enable L6474_EnableIrq after SPI transfers*/
+ L6474_EnableIrq();
+}
+
+/******************************************************//**
+ * @brief Reads the Status Register value
+ * @retval Status register valued
+ * @note The status register flags are not cleared
+ * at the difference with L6474CmdGetStatus()
+ **********************************************************/
+uint16_t L6474::L6474_ReadStatusRegister(void)
+{
+ return (L6474_CmdGetParam(L6474_STATUS));
+}
+
+/******************************************************//**
+ * @brief Set the stepping mode
+ * @param[in] stepMod from full step to 1/16 microstep as specified in enum motorStepMode_t
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SelectStepMode(motorStepMode_t stepMod)
+{
+ uint8_t stepModeRegister;
+ L6474_STEP_SEL_t l6474StepMod;
+
+ switch (stepMod)
+ {
+ case STEP_MODE_FULL:
+ l6474StepMod = L6474_STEP_SEL_1;
+ break;
+ case STEP_MODE_HALF:
+ l6474StepMod = L6474_STEP_SEL_1_2;
+ break;
+ case STEP_MODE_1_4:
+ l6474StepMod = L6474_STEP_SEL_1_4;
+ break;
+ case STEP_MODE_1_8:
+ l6474StepMod = L6474_STEP_SEL_1_8;
+ break;
+ case STEP_MODE_1_16:
+ default:
+ l6474StepMod = L6474_STEP_SEL_1_16;
+ break;
+ }
+
+ /* Eventually deactivate motor */
+ if (devicePrm.motionState != INACTIVE)
+ {
+ L6474_HardStop();
+ }
+
+ /* Read Step mode register and clear STEP_SEL field */
+ stepModeRegister = (uint8_t)(0xF8 & L6474_CmdGetParam(L6474_STEP_MODE)) ;
+
+ /* Apply new step mode */
+ L6474_CmdSetParam(L6474_STEP_MODE, stepModeRegister | (uint8_t)l6474StepMod);
+
+ /* Reset abs pos register */
+ L6474_SetHome();
+}
+
+/******************************************************//**
+ * @brief Specifies the direction
+ * @param[in] dir FORWARD or BACKWARD
+ * @note The direction change is only applied if the device
+ * is in INACTIVE state
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SetDirection(motorDir_t dir)
+{
+ if (devicePrm.motionState == INACTIVE)
+ {
+ devicePrm.direction = dir;
+ L6474_SetDirectionGpio(dir);
+ }
+}
+
+/******************************************************//**
+ * @brief Updates the current speed of the device
+ * @param[in] newSpeed in pps
+ * @retval None
+ **********************************************************/
+void L6474::L6474_ApplySpeed(uint16_t newSpeed)
+{
+ if (newSpeed < L6474_MIN_PWM_FREQ)
+ {
+ newSpeed = L6474_MIN_PWM_FREQ;
+ }
+ if (newSpeed > L6474_MAX_PWM_FREQ)
+ {
+ newSpeed = L6474_MAX_PWM_FREQ;
+ }
+
+ devicePrm.speed = newSpeed;
+
+ L6474_PwmSetFreq(newSpeed);
+}
+
+/******************************************************//**
+ * @brief Computes the speed profile according to the number of steps to move
+ * @param[in] nbSteps number of steps to perform
+ * @retval None
+ * @note Using the acceleration and deceleration of the device,
+ * this function determines the duration in steps of the acceleration,
+ * steady and deceleration phases.
+ * If the total number of steps to perform is big enough, a trapezoidal move
+ * is performed (i.e. there is a steady phase where the motor runs at the maximum
+ * speed.
+ * Else, a triangular move is performed (no steady phase: the maximum speed is never
+ * reached.
+ **********************************************************/
+void L6474::L6474_ComputeSpeedProfile(uint32_t nbSteps)
+{
+ uint32_t reqAccSteps;
+ uint32_t reqDecSteps;
+
+ /* compute the number of steps to get the targeted speed */
+ uint16_t minSpeed = devicePrm.minSpeed;
+ reqAccSteps = (devicePrm.maxSpeed - minSpeed);
+ reqAccSteps *= (devicePrm.maxSpeed + minSpeed);
+ reqDecSteps = reqAccSteps;
+ reqAccSteps /= (uint32_t)devicePrm.acceleration;
+ reqAccSteps /= 2;
+
+ /* compute the number of steps to stop */
+ reqDecSteps /= (uint32_t)devicePrm.deceleration;
+ reqDecSteps /= 2;
+
+ if(( reqAccSteps + reqDecSteps ) > nbSteps)
+ {
+ /* Triangular move */
+ /* reqDecSteps = (Pos * Dec) /(Dec+Acc) */
+ uint32_t dec = devicePrm.deceleration;
+ uint32_t acc = devicePrm.acceleration;
+
+ reqDecSteps = ((uint32_t) dec * nbSteps) / (acc + dec);
+ if (reqDecSteps > 1)
+ {
+ reqAccSteps = reqDecSteps - 1;
+ if(reqAccSteps == 0)
+ {
+ reqAccSteps = 1;
+ }
+ }
+ else
+ {
+ reqAccSteps = 0;
+ }
+ devicePrm.endAccPos = reqAccSteps;
+ devicePrm.startDecPos = reqDecSteps;
+ }
+ else
+ {
+ /* Trapezoidal move */
+ /* accelerating phase to endAccPos */
+ /* steady phase from endAccPos to startDecPos */
+ /* decelerating from startDecPos to stepsToTake*/
+ devicePrm.endAccPos = reqAccSteps;
+ devicePrm.startDecPos = nbSteps - reqDecSteps - 1;
+ }
+}
+
+/******************************************************//**
+ * @brief Converts the ABS_POSITION register value to a 32b signed integer
+ * @param[in] abs_position_reg value of the ABS_POSITION register
+ * @retval operation_result 32b signed integer corresponding to the absolute position
+ **********************************************************/
+int32_t L6474::L6474_ConvertPosition(uint32_t abs_position_reg)
+{
+ int32_t operation_result;
+
+ if (abs_position_reg & L6474_ABS_POS_SIGN_BIT_MASK)
+ {
+ /* Negative register value */
+ abs_position_reg = ~abs_position_reg;
+ abs_position_reg += 1;
+
+ operation_result = (int32_t) (abs_position_reg & L6474_ABS_POS_VALUE_MASK);
+ operation_result = -operation_result;
+ }
+ else
+ {
+ operation_result = (int32_t) abs_position_reg;
+ }
+ return operation_result;
+}
+
+/******************************************************//**
+ * @brief Error handler which calls the user callback (if defined)
+ * @param[in] error Number of the error
+ * @retval None
+ **********************************************************/
+void L6474::L6474_ErrorHandler(uint16_t error)
+{
+ if (errorHandlerCallback != 0)
+ {
+ (void) errorHandlerCallback(error);
+ }
+ else
+ {
+ while(1)
+ {
+ /* Infinite loop */
+ }
+ }
+}
+
+/******************************************************//**
+ * @brief Handlers of the flag interrupt which calls the user callback (if defined)
+ * @param None
+ * @retval None
+ **********************************************************/
+void L6474::L6474_FlagInterruptHandler(void)
+{
+ if (flagInterruptCallback != 0)
+ {
+ /* Set isr flag */
+ isrFlag = TRUE;
+
+ flagInterruptCallback();
+
+ /* Reset isr flag */
+ isrFlag = FALSE;
+ }
+}
+
+/******************************************************//**
+ * @brief Sends a command without arguments to the L6474 via the SPI
+ * @param[in] param Command to send
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SendCommand(uint8_t param)
+{
+ bool itDisable = FALSE;
+
+ do
+ {
+ spiPreemtionByIsr = FALSE;
+ if (itDisable)
+ {
+ /* re-enable L6474_EnableIrq if disable in previous iteration */
+ L6474_EnableIrq();
+ itDisable = FALSE;
+ }
+
+ spiTxBursts[3] = L6474_NOP;
+ spiTxBursts[3] = param;
+
+ /* Disable interruption before checking */
+ /* pre-emption by ISR and SPI transfers*/
+ L6474_DisableIrq();
+ itDisable = TRUE;
+ } while (spiPreemtionByIsr); // check pre-emption by ISR
+
+ L6474_WriteBytes(&spiTxBursts[3], &spiRxBursts[3]);
+
+ /* re-enable L6474_EnableIrq after SPI transfers*/
+ L6474_EnableIrq();
+}
+
+/******************************************************//**
+ * @brief Sets the registers of the L6474 to their predefined values
+ * from l6474_target_config.h
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SetRegisterToPredefinedValues(void)
+{
+ L6474_CmdSetParam(
+ L6474_ABS_POS,
+ 0);
+ L6474_CmdSetParam(
+ L6474_EL_POS,
+ 0);
+ L6474_CmdSetParam(
+ L6474_MARK,
+ 0);
+ switch (deviceInstance)
+ {
+ case 0:
+ L6474_CmdSetParam(
+ L6474_TVAL,
+ L6474_Tval_Current_to_Par(L6474_CONF_PARAM_TVAL_DEVICE_0));
+ L6474_CmdSetParam(
+ L6474_T_FAST,
+ (uint8_t)L6474_CONF_PARAM_TOFF_FAST_DEVICE_0 |
+ (uint8_t)L6474_CONF_PARAM_FAST_STEP_DEVICE_0);
+ L6474_CmdSetParam(
+ L6474_TON_MIN,
+ L6474_Tmin_Time_to_Par(L6474_CONF_PARAM_TON_MIN_DEVICE_0)
+ );
+ L6474_CmdSetParam(
+ L6474_TOFF_MIN,
+ L6474_Tmin_Time_to_Par(L6474_CONF_PARAM_TOFF_MIN_DEVICE_0));
+ L6474_CmdSetParam(
+ L6474_OCD_TH,
+ L6474_CONF_PARAM_OCD_TH_DEVICE_0);
+ L6474_CmdSetParam(
+ L6474_STEP_MODE,
+ (uint8_t)L6474_CONF_PARAM_STEP_SEL_DEVICE_0 |
+ (uint8_t)L6474_CONF_PARAM_SYNC_SEL_DEVICE_0);
+ L6474_CmdSetParam(
+ L6474_ALARM_EN,
+ L6474_CONF_PARAM_ALARM_EN_DEVICE_0);
+ L6474_CmdSetParam(
+ L6474_CONFIG,
+ (uint16_t)L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_0 |
+ (uint16_t)L6474_CONF_PARAM_TQ_REG_DEVICE_0 |
+ (uint16_t)L6474_CONF_PARAM_OC_SD_DEVICE_0 |
+ (uint16_t)L6474_CONF_PARAM_SR_DEVICE_0 |
+ (uint16_t)L6474_CONF_PARAM_TOFF_DEVICE_0);
+ break;
+ case 1:
+ L6474_CmdSetParam(
+ L6474_TVAL,
+ L6474_Tval_Current_to_Par(L6474_CONF_PARAM_TVAL_DEVICE_1));
+ L6474_CmdSetParam(
+ L6474_T_FAST,
+ (uint8_t)L6474_CONF_PARAM_TOFF_FAST_DEVICE_1 |
+ (uint8_t)L6474_CONF_PARAM_FAST_STEP_DEVICE_1);
+ L6474_CmdSetParam(
+ L6474_TON_MIN,
+ L6474_Tmin_Time_to_Par(L6474_CONF_PARAM_TON_MIN_DEVICE_1));
+ L6474_CmdSetParam(
+ L6474_TOFF_MIN,
+ L6474_Tmin_Time_to_Par(L6474_CONF_PARAM_TOFF_MIN_DEVICE_1));
+ L6474_CmdSetParam(
+ L6474_OCD_TH,
+ L6474_CONF_PARAM_OCD_TH_DEVICE_1);
+ L6474_CmdSetParam(
+ L6474_STEP_MODE,
+ (uint8_t)L6474_CONF_PARAM_STEP_SEL_DEVICE_1 |
+ (uint8_t)L6474_CONF_PARAM_SYNC_SEL_DEVICE_1);
+ L6474_CmdSetParam(
+ L6474_ALARM_EN,
+ L6474_CONF_PARAM_ALARM_EN_DEVICE_1);
+ L6474_CmdSetParam(
+ L6474_CONFIG,
+ (uint16_t)L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_1 |
+ (uint16_t)L6474_CONF_PARAM_TQ_REG_DEVICE_1 |
+ (uint16_t)L6474_CONF_PARAM_OC_SD_DEVICE_1 |
+ (uint16_t)L6474_CONF_PARAM_SR_DEVICE_1 |
+ (uint16_t)L6474_CONF_PARAM_TOFF_DEVICE_1);
+ break;
+ case 2:
+ L6474_CmdSetParam(
+ L6474_TVAL,
+ L6474_Tval_Current_to_Par(L6474_CONF_PARAM_TVAL_DEVICE_2));
+ L6474_CmdSetParam(
+ L6474_T_FAST,
+ (uint8_t)L6474_CONF_PARAM_TOFF_FAST_DEVICE_2 |
+ (uint8_t)L6474_CONF_PARAM_FAST_STEP_DEVICE_2);
+ L6474_CmdSetParam(
+ L6474_TON_MIN,
+ L6474_Tmin_Time_to_Par(L6474_CONF_PARAM_TON_MIN_DEVICE_2));
+ L6474_CmdSetParam(
+ L6474_TOFF_MIN,
+ L6474_Tmin_Time_to_Par(L6474_CONF_PARAM_TOFF_MIN_DEVICE_2));
+ L6474_CmdSetParam(
+ L6474_OCD_TH,
+ L6474_CONF_PARAM_OCD_TH_DEVICE_2);
+ L6474_CmdSetParam(
+ L6474_STEP_MODE,
+ (uint8_t)L6474_CONF_PARAM_STEP_SEL_DEVICE_2 |
+ (uint8_t)L6474_CONF_PARAM_SYNC_SEL_DEVICE_2);
+ L6474_CmdSetParam(
+ L6474_ALARM_EN,
+ L6474_CONF_PARAM_ALARM_EN_DEVICE_2);
+ L6474_CmdSetParam(
+ L6474_CONFIG,
+ (uint16_t)L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_2 |
+ (uint16_t)L6474_CONF_PARAM_TQ_REG_DEVICE_2 |
+ (uint16_t)L6474_CONF_PARAM_OC_SD_DEVICE_2 |
+ (uint16_t)L6474_CONF_PARAM_SR_DEVICE_2 |
+ (uint16_t)L6474_CONF_PARAM_TOFF_DEVICE_2);
+ break;
+ default: ;
+ }
+}
+
+/******************************************************//**
+ * @brief Sets the parameters of the device to predefined values
+ * from l6474_target_config.h
+ * @param None
+ * @retval None
+ **********************************************************/
+void L6474::L6474_SetDeviceParamsToPredefinedValues(void)
+{
+ switch (deviceInstance)
+ {
+ case 0:
+ devicePrm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_0;
+ devicePrm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_0;
+ devicePrm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_0;
+ devicePrm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_0;
+ break;
+
+ case 1:
+ devicePrm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_1;
+ devicePrm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_1;
+ devicePrm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_1;
+ devicePrm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_1;
+ break;
+
+ case 2:
+ devicePrm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_2;
+ devicePrm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_2;
+ devicePrm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_2;
+ devicePrm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_2;
+ break;
+ }
+
+ devicePrm.accu = 0;
+ devicePrm.currentPosition = 0;
+ devicePrm.endAccPos = 0;
+ devicePrm.relativePos = 0;
+ devicePrm.startDecPos = 0;
+ devicePrm.stepsToTake = 0;
+ devicePrm.speed = 0;
+ devicePrm.commandExecuted = NO_CMD;
+ devicePrm.direction = FORWARD;
+ devicePrm.motionState = INACTIVE;
+
+ L6474_SetRegisterToPredefinedValues();
+}
+
+/******************************************************//**
+ * @brief Initialises the bridge parameters to start the movement
+ * and enable the power bridge
+ * @retval None
+ **********************************************************/
+void L6474::L6474_StartMovement(void)
+{
+ /* Enable L6474 powerstage */
+ L6474_CmdEnable();
+ if (devicePrm.endAccPos != 0)
+ {
+ devicePrm.motionState = ACCELERATING;
+ }
+ else
+ {
+ devicePrm.motionState = DECELERATING;
+ }
+ devicePrm.accu = 0;
+ devicePrm.relativePos = 0;
+ L6474_ApplySpeed(devicePrm.minSpeed);
+}
+
+/******************************************************//**
+ * @brief Handles the device state machine at each ste
+ * @retval None
+ * @note Must only be called by the timer ISR
+ **********************************************************/
+void L6474::L6474_StepClockHandler(void)
+{
+ /* Set isr flag */
+ isrFlag = TRUE;
+
+ /* Incrementation of the relative position */
+ devicePrm.relativePos++;
+
+ switch (devicePrm.motionState)
+ {
+ case ACCELERATING:
+ {
+ uint32_t relPos = devicePrm.relativePos;
+ uint32_t endAccPos = devicePrm.endAccPos;
+ uint16_t speed = devicePrm.speed;
+ uint32_t acc = ((uint32_t)devicePrm.acceleration << 16);
+
+ if ((devicePrm.commandExecuted == SOFT_STOP_CMD)||
+ ((devicePrm.commandExecuted != RUN_CMD)&&
+ (relPos == devicePrm.startDecPos)))
+ {
+ devicePrm.motionState = DECELERATING;
+ devicePrm.accu = 0;
+ }
+ else if ((speed >= devicePrm.maxSpeed)||
+ ((devicePrm.commandExecuted != RUN_CMD)&&
+ (relPos == endAccPos)))
+ {
+ devicePrm.motionState = STEADY;
+ }
+ else
+ {
+ bool speedUpdated = FALSE;
+ /* Go on accelerating */
+ if (speed == 0) speed =1;
+ devicePrm.accu += acc / speed;
+ while (devicePrm.accu >= (0X10000L))
+ {
+ devicePrm.accu -= (0X10000L);
+ speed +=1;
+ speedUpdated = TRUE;
+ }
+
+ if (speedUpdated)
+ {
+ if (speed > devicePrm.maxSpeed)
+ {
+ speed = devicePrm.maxSpeed;
+ }
+ devicePrm.speed = speed;
+ L6474_ApplySpeed(devicePrm.speed);
+ }
+ }
+ break;
+ }
+ case STEADY:
+ {
+ uint16_t maxSpeed = devicePrm.maxSpeed;
+ uint32_t relativePos = devicePrm.relativePos;
+ if ((devicePrm.commandExecuted == SOFT_STOP_CMD)||
+ ((devicePrm.commandExecuted != RUN_CMD)&&
+ (relativePos >= (devicePrm.startDecPos))) ||
+ ((devicePrm.commandExecuted == RUN_CMD)&&
+ (devicePrm.speed > maxSpeed)))
+ {
+ devicePrm.motionState = DECELERATING;
+ devicePrm.accu = 0;
+ }
+ else if ((devicePrm.commandExecuted == RUN_CMD)&&
+ (devicePrm.speed < maxSpeed))
+ {
+ devicePrm.motionState = ACCELERATING;
+ devicePrm.accu = 0;
+ }
+ break;
+ }
+ case DECELERATING:
+ {
+ uint32_t relativePos = devicePrm.relativePos;
+ uint16_t speed = devicePrm.speed;
+ uint32_t deceleration = ((uint32_t)devicePrm.deceleration << 16);
+ if (((devicePrm.commandExecuted == SOFT_STOP_CMD)&&(speed <= devicePrm.minSpeed))||
+ ((devicePrm.commandExecuted != RUN_CMD)&&
+ (relativePos >= devicePrm.stepsToTake)))
+ {
+ /* Motion process complete */
+ L6474_HardStop();
+ }
+ else if ((devicePrm.commandExecuted == RUN_CMD)&&
+ (speed <= devicePrm.maxSpeed))
+ {
+ devicePrm.motionState = STEADY;
+ }
+ else
+ {
+ /* Go on decelerating */
+ if (speed > devicePrm.minSpeed)
+ {
+ bool speedUpdated = FALSE;
+ if (speed == 0) speed =1;
+ devicePrm.accu += deceleration / speed;
+ while (devicePrm.accu >= (0X10000L))
+ {
+ devicePrm.accu -= (0X10000L);
+ if (speed > 1)
+ {
+ speed -=1;
+ }
+ speedUpdated = TRUE;
+ }
+
+ if (speedUpdated)
+ {
+ if (speed < devicePrm.minSpeed)
+ {
+ speed = devicePrm.minSpeed;
+ }
+ devicePrm.speed = speed;
+ L6474_ApplySpeed(devicePrm.speed);
+ }
+ }
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ /* Set isr flag */
+ isrFlag = FALSE;
+}
+
+/******************************************************//**
+ * @brief Converts mA in compatible values for TVAL register
+ * @param[in] Tval
+ * @retval TVAL values
+ **********************************************************/
+uint8_t L6474::L6474_Tval_Current_to_Par(double Tval)
+{
+ return ((uint8_t)(((Tval - 31.25)/31.25)+0.5));
+}
+
+/******************************************************//**
+ * @brief Convert time in us in compatible values
+ * for TON_MIN register
+ * @param[in] Tmin
+ * @retval TON_MIN values
+ **********************************************************/
+uint8_t L6474::L6474_Tmin_Time_to_Par(double Tmin)
+{
+ return ((uint8_t)(((Tmin - 0.5)*2)+0.5));
+}
+
+/******************************************************//**
+ * @brief Write and receive a byte via SPI
+ * @param[in] pByteToTransmit pointer to the byte to transmit
+ * @param[in] pReceivedByte pointer to the received byte
+ * @retval None
+ **********************************************************/
+void L6474::L6474_WriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte)
+{
+ if (L6474_SpiWriteBytes(pByteToTransmit, pReceivedByte) != 0)
+ {
+ L6474_ErrorHandler(L6474_ERROR_1);
+ }
+
+ if (isrFlag)
+ {
+ spiPreemtionByIsr = TRUE;
+ }
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6474/l6474_class.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,660 @@
+/**
+ ******************************************************************************
+ * @file l6474_class.h
+ * @author IPC Rennes
+ * @version V1.5.0
+ * @date November 12, 2014
+ * @brief L6474 driver (fully integrated microstepping motor driver)
+ * @note (C) COPYRIGHT 2014 STMicroelectronics
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Generated with Stm32CubeTOO -----------------------------------------------*/
+
+
+/* Revision ------------------------------------------------------------------*/
+/*
+ Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
+ Branch/Trunk/Tag: trunk
+ Based on: X-CUBE-SPN1/trunk/Drivers/BSP/Components/l6474/l6474.h
+ Revision: 0
+*/
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __L6474_CLASS_H
+#define __L6474_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+#include "DevSPI.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here component specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "l6474.h"
+/* ACTION 3 ------------------------------------------------------------------*
+ * Include here interface specific header files. *
+ * *
+ * Example: *
+ * #include "../Interfaces/Humidity_class.h" *
+ * #include "../Interfaces/Temperature_class.h" *
+ *----------------------------------------------------------------------------*/
+#include "../Interfaces/Motor_class.h"
+
+
+/* Functions -----------------------------------------------------------------*/
+
+extern void PWMCallback(void);
+
+
+/* Classes -------------------------------------------------------------------*/
+
+/** Class representing a L6474 component.
+ */
+class L6474 : public Motor
+{
+public:
+
+ /*** Constructor and Destructor Methods ***/
+
+ /**
+ * @brief Constructor.
+ * @param reset pin name of the STBY\RST pin of the component.
+ * @param direction pin name of the DIR pin of the component.
+ * @param pwm pin name of the PWM pin of the component.
+ * @param ssel pin name of the SSEL pin of the SPI device to be used for communication.
+ * @param spi SPI device to be used for communication.
+ */
+ L6474(PinName reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi) : Motor(), direction(direction), pwm(pwm), reset(reset), ssel(ssel), dev_spi(spi)
+ {
+ /* ACTION 4 ----------------------------------------------------------*
+ * Initialize here the component's member variables, one variable per *
+ * line. *
+ * *
+ * Example: *
+ * T0_out = 0; *
+ * T1_out = 0; *
+ * T0_degC = 0; *
+ * T1_degC = 0; *
+ *--------------------------------------------------------------------*/
+ flagInterruptCallback = 0;
+ errorHandlerCallback = 0;
+ memset(spiTxBursts, 0, L6474_CMD_ARG_MAX_NB_BYTES);
+ memset(spiRxBursts, 0, L6474_CMD_ARG_MAX_NB_BYTES);
+ spiPreemtionByIsr = 0;
+ isrFlag = 0;
+ //devicePrm = 0;
+ deviceInstance = numberOfDevices;
+ numberOfDevices++;
+ }
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~L6474(void) {}
+
+
+ /*** Public Component Related Methods ***/
+
+ /* ACTION 5 --------------------------------------------------------------*
+ * Implement here the component's public methods, as wrappers of the C *
+ * component's functions. *
+ * They should be: *
+ * + Methods with the same name of the C component's virtual table's *
+ * functions (1); *
+ * + Methods with the same name of the C component's extended virtual *
+ * table's functions, if any (2). *
+ * *
+ * Example: *
+ * virtual int GetValue(float *pData) //(1) *
+ * { *
+ * return COMPONENT_GetValue(float *pfData); *
+ * } *
+ * *
+ * virtual int EnableFeature(void) //(2) *
+ * { *
+ * return COMPONENT_EnableFeature(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ virtual int Init(void *init)
+ {
+ return (int) L6474_Init((MOTOR_InitTypeDef *) init);
+ }
+
+ virtual int ReadID(uint8_t *id)
+ {
+ return (int) L6474_ReadID((uint8_t *) id);
+ }
+
+ virtual void AttachErrorHandler(void (*callback)(uint16_t error))
+ {
+ L6474_AttachErrorHandler((void (*)(uint16_t error)) callback);
+ }
+
+ virtual void AttachFlagInterrupt(void (*callback)(void))
+ {
+ L6474_AttachFlagInterrupt((void (*)(void)) callback);
+ }
+
+ virtual void FlagInterruptHandler(void)
+ {
+ L6474_FlagInterruptHandler();
+ }
+
+ virtual uint16_t GetAcceleration(void)
+ {
+ return (uint16_t) L6474_GetAcceleration();
+ }
+
+ virtual uint16_t GetCurrentSpeed(void)
+ {
+ return (uint16_t) L6474_GetCurrentSpeed();
+ }
+
+ virtual uint16_t GetDeceleration(void)
+ {
+ return (uint16_t) L6474_GetDeceleration();
+ }
+
+ virtual motorState_t GetDeviceState(void)
+ {
+ return (motorState_t) L6474_GetDeviceState();
+ }
+
+ virtual uint8_t GetFwVersion(void)
+ {
+ return (uint8_t) L6474_GetFwVersion();
+ }
+
+ virtual int32_t GetMark(void)
+ {
+ return (int32_t) L6474_GetMark();
+ }
+
+ virtual uint16_t GetMaxSpeed(void)
+ {
+ return (uint16_t) L6474_GetMaxSpeed();
+ }
+
+ virtual uint16_t GetMinSpeed(void)
+ {
+ return (uint16_t) L6474_GetMinSpeed();
+ }
+
+ virtual int32_t GetPosition(void)
+ {
+ return (int32_t) L6474_GetPosition();
+ }
+
+ virtual void GoHome(void)
+ {
+ L6474_GoHome();
+ }
+
+ virtual void GoMark(void)
+ {
+ L6474_GoMark();
+ }
+
+ virtual void GoTo(int32_t targetPosition)
+ {
+ L6474_GoTo((int32_t) targetPosition);
+ }
+
+ virtual void HardStop(void)
+ {
+ L6474_HardStop();
+ }
+
+ virtual void Move(motorDir_t direction, uint32_t stepCount)
+ {
+ L6474_Move((motorDir_t) direction, (uint32_t) stepCount);
+ }
+
+ virtual void Run(motorDir_t direction)
+ {
+ L6474_Run((motorDir_t) direction);
+ }
+
+ virtual bool SetAcceleration(uint16_t newAcc)
+ {
+ return (bool) L6474_SetAcceleration((uint16_t) newAcc);
+ }
+
+ virtual bool SetDeceleration(uint16_t newDec)
+ {
+ return (bool) L6474_SetDeceleration((uint16_t) newDec);
+ }
+
+ virtual void SetHome(void)
+ {
+ L6474_SetHome();
+ }
+
+ virtual void SetMark(void)
+ {
+ L6474_SetMark();
+ }
+
+ virtual bool SetMaxSpeed(uint16_t newMaxSpeed)
+ {
+ return (bool) L6474_SetMaxSpeed((uint16_t) newMaxSpeed);
+ }
+
+ virtual bool SetMinSpeed(uint16_t newMinSpeed)
+ {
+ return (bool) L6474_SetMinSpeed((uint16_t) newMinSpeed);
+ }
+
+ virtual bool SoftStop(void)
+ {
+ return (bool) L6474_SoftStop();
+ }
+
+ virtual void StepClockHandler(void)
+ {
+ L6474_StepClockHandler();
+ }
+
+ virtual void CmdDisable(void)
+ {
+ L6474_CmdDisable();
+ }
+
+ virtual void CmdEnable(void)
+ {
+ L6474_CmdEnable();
+ }
+
+ virtual uint32_t CmdGetParam(uint32_t param)
+ {
+ return (uint32_t) L6474_CmdGetParam((uint32_t) param);
+ }
+
+ virtual uint16_t CmdGetStatus(void)
+ {
+ return (uint16_t) L6474_CmdGetStatus();
+ }
+
+ virtual void CmdNop(void)
+ {
+ L6474_CmdNop();
+ }
+
+ virtual void CmdSetParam(uint32_t param, uint32_t value)
+ {
+ L6474_CmdSetParam((uint32_t) param, (uint32_t) value);
+ }
+
+ virtual uint16_t ReadStatusRegister(void)
+ {
+ return (uint16_t) L6474_ReadStatusRegister();
+ }
+
+ virtual void ReleaseReset(void)
+ {
+ L6474_ReleaseReset();
+ }
+
+ virtual void Reset(void)
+ {
+ L6474_Reset();
+ }
+
+ virtual void SelectStepMode(motorStepMode_t stepMod)
+ {
+ L6474_SelectStepMode((motorStepMode_t) stepMod);
+ }
+
+ virtual void SetDirection(motorDir_t direction)
+ {
+ L6474_SetDirection((motorDir_t) direction);
+ }
+
+ virtual void ErrorHandler(uint16_t error)
+ {
+ L6474_ErrorHandler((uint16_t) error);
+ }
+
+
+ /*** Public Interrupt Related Methods ***/
+
+ /* ACTION 6 --------------------------------------------------------------*
+ * Implement here interrupt related methods, if any. *
+ * Note that interrupt handling is platform dependent, e.g.: *
+ * + mbed: *
+ * InterruptIn feature_int(pin); //Interrupt object. *
+ * feature_int.rise(callback); //Attach a callback. *
+ * feature_int.mode(PullNone); //Set interrupt mode. *
+ * feature_int.enable_irq(); //Enable interrupt. *
+ * feature_int.disable_irq(); //Disable interrupt. *
+ * + Arduino: *
+ * attachInterrupt(pin, callback, RISING); //Attach a callback. *
+ * detachInterrupt(pin); //Detach a callback. *
+ * *
+ * Example (mbed): *
+ * void Attach_Feature_IRQ(void (*fptr) (void)) *
+ * { *
+ * feature_int.rise(fptr); *
+ * } *
+ * *
+ * void Enable_Feature_IRQ(void) *
+ * { *
+ * feature_int.enable_irq(); *
+ * } *
+ * *
+ * void Disable_Feature_IRQ(void) *
+ * { *
+ * feature_int.disable_irq(); *
+ * } *
+ *------------------------------------------------------------------------*/
+
+
+protected:
+
+ /*** Protected Component Related Methods ***/
+
+ /* ACTION 7 --------------------------------------------------------------*
+ * Declare here the component's specific methods. *
+ * They should be: *
+ * + Methods with the same name of the C component's virtual table's *
+ * functions (1); *
+ * + Methods with the same name of the C component's extended virtual *
+ * table's functions, if any (2); *
+ * + Helper methods, if any, like functions declared in the component's *
+ * source files but not pointed by the component's virtual table (3). *
+ * *
+ * Example: *
+ * DrvStatusTypeDef COMPONENT_GetValue(float* pfData); //(1) *
+ * DrvStatusTypeDef COMPONENT_EnableFeature(void); //(2) *
+ * DrvStatusTypeDef COMPONENT_ComputeAverage(void); //(3) *
+ *------------------------------------------------------------------------*/
+ void L6474_AttachErrorHandler(void (*callback)(uint16_t error)); //Attach a user callback to the error handler
+ void L6474_AttachFlagInterrupt(void (*callback)(void)); //Attach a user callback to the flag Interrupt
+ DrvStatusTypeDef L6474_Init(MOTOR_InitTypeDef *init); //Start the L6474 library
+ DrvStatusTypeDef L6474_ReadID(uint8_t *id); //Read Id to get driver instance
+ uint16_t L6474_GetAcceleration(void); //Return the acceleration in pps^2
+ uint16_t L6474_GetCurrentSpeed(void); //Return the current speed in pps
+ uint16_t L6474_GetDeceleration(void); //Return the deceleration in pps^2
+ motorState_t L6474_GetDeviceState(void); //Return the device state
+ uint8_t L6474_GetFwVersion(void); //Return the FW version
+ int32_t L6474_GetMark(void); //Return the mark position
+ uint16_t L6474_GetMaxSpeed(void); //Return the max speed in pps
+ uint16_t L6474_GetMinSpeed(void); //Return the min speed in pps
+ int32_t L6474_GetPosition(void); //Return the ABS_POSITION (32b signed)
+ void L6474_GoHome(void); //Move to the home position
+ void L6474_GoMark(void); //Move to the Mark position
+ void L6474_GoTo(int32_t targetPosition); //Go to the specified position
+ void L6474_HardStop(void); //Stop the motor and disable the power bridge
+ void L6474_Move(motorDir_t direction, uint32_t stepCount); //Move the motor of the specified number of steps
+ void L6474_Run(motorDir_t direction); //Run the motor
+ bool L6474_SetAcceleration(uint16_t newAcc); //Set the acceleration in pps^2
+ bool L6474_SetDeceleration(uint16_t newDec); //Set the deceleration in pps^2
+ void L6474_SetHome(void); //Set current position to be the home position
+ void L6474_SetMark(void); //Set current position to be the Markposition
+ bool L6474_SetMaxSpeed(uint16_t newMaxSpeed); //Set the max speed in pps
+ bool L6474_SetMinSpeed(uint16_t newMinSpeed); //Set the min speed in pps
+ bool L6474_SoftStop(void); //Progressively stops the motor
+ void L6474_CmdDisable(void); //Send the L6474_DISABLE command
+ void L6474_CmdEnable(void); //Send the L6474_ENABLE command
+ uint32_t L6474_CmdGetParam(uint32_t param); //Send the L6474_GET_PARAM command
+ uint16_t L6474_CmdGetStatus(void); //Send the L6474_GET_STATUS command
+ void L6474_CmdNop(void); //Send the L6474_NOP command
+ void L6474_CmdSetParam(uint32_t param, uint32_t value); //Send the L6474_SET_PARAM command
+ uint16_t L6474_ReadStatusRegister(void); //Read the L6474_STATUS register without clearing the flags
+ void L6474_SelectStepMode(motorStepMode_t stepMod); //Step mode selection
+ void L6474_SetDirection(motorDir_t direction); //Set the L6474 direction pin
+ void L6474_ApplySpeed(uint16_t newSpeed);
+ void L6474_ComputeSpeedProfile(uint32_t nbSteps);
+ int32_t L6474_ConvertPosition(uint32_t abs_position_reg);
+ void L6474_ErrorHandler(uint16_t error);
+ void L6474_FlagInterruptHandler(void);
+ void L6474_SendCommand(uint8_t param);
+ void L6474_SetRegisterToPredefinedValues(void);
+ void L6474_WriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte);
+ void L6474_SetDeviceParamsToPredefinedValues(void);
+ void L6474_StartMovement(void);
+ void L6474_StepClockHandler(void);
+ uint8_t L6474_Tval_Current_to_Par(double Tval);
+ uint8_t L6474_Tmin_Time_to_Par(double Tmin);
+
+
+ /*** Component's I/O Methods ***/
+
+ /**
+ * @brief Utility function to read data from L6474.
+ * @param[out] pBuffer pointer to the buffer to read data into.
+ * @param[in] NumBytesToRead number of bytes to read.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+ DrvStatusTypeDef Read(uint8_t* pBuffer, uint16_t NumBytesToRead)
+ {
+ if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0)
+ return COMPONENT_ERROR;
+ return COMPONENT_OK;
+ }
+
+ /**
+ * @brief Utility function to write data to L6474.
+ * @param[in] pBuffer pointer to the buffer of data to send.
+ * @param[in] NumBytesToWrite number of bytes to write.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+ DrvStatusTypeDef Write(uint8_t* pBuffer, uint16_t NumBytesToWrite)
+ {
+ if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0)
+ return COMPONENT_ERROR;
+ return COMPONENT_OK;
+ }
+
+ /**
+ * @brief Utility function to read and write data from/to L6474 at the same time.
+ * @param[out] pBufferToRead pointer to the buffer to read data into.
+ * @param[in] pBufferToWrite pointer to the buffer of data to send.
+ * @param[in] NumBytes number of bytes to read and write.
+ * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise.
+ */
+ DrvStatusTypeDef ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes)
+ {
+ if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0)
+ return COMPONENT_ERROR;
+ return COMPONENT_OK;
+ }
+
+ /* ACTION 8 --------------------------------------------------------------*
+ * Implement here other I/O methods beyond those already implemented *
+ * above, which are declared extern within the component's header file. *
+ *------------------------------------------------------------------------*/
+ /*
+ * System call to make the CPU wait.
+ */
+ void L6474_Delay(uint32_t delay)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs */
+ wait_ms(delay);
+ }
+
+ /*
+ * System call to enable interrupts.
+ */
+ void L6474_EnableIrq(void)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs */
+ __enable_irq();
+ }
+
+ /*
+ * System call to disable interrupts.
+ */
+ void L6474_DisableIrq(void)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs */
+ __disable_irq();
+ }
+
+ /*
+ * Sets the frequency of PWM.
+ * The frequency is directly the current speed of the device.
+ */
+ void L6474_PwmSetFreq(uint16_t newFreq)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs */
+ double period = 1.0f / newFreq;
+ pwm.period(period);
+ pwm.write(0.5f);
+ ticker.attach(&PWMCallback, period);
+ }
+
+ /*
+ * Initialises the PWM uses by the specified device.
+ * + Device 0 uses PWM1 based on timer 1;
+ * + Device 1 uses PWM2 based on timer 2;
+ * + Device 2 uses PWM3 based on timer 3.
+ */
+ void L6474_PwmInit(void)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs */
+ }
+
+ /*
+ * Stops the PWM.
+ */
+ void L6474_PwmStop(void)
+ {
+ /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs */
+ pwm.write(0.0f);
+ ticker.detach();
+ }
+
+ /*
+ * Setting the standby/reset pin to high.
+ */
+ void L6474_ReleaseReset(void)
+ {
+ reset = 1;
+ }
+
+ /*
+ * Resetting the standby/reset pin to put the device in standby mode.
+ */
+ void L6474_Reset(void)
+ {
+ reset = 0;
+ }
+
+ /*
+ * Set the direction of rotation.
+ */
+ void L6474_SetDirectionGpio(uint8_t gpioState)
+ {
+ direction = gpioState;
+ }
+
+ /*
+ * Write and read bytes to/from the component through the SPI at the same time.
+ */
+ uint8_t L6474_SpiWriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte)
+ {
+ return (uint8_t) ReadWrite(pReceivedByte, pByteToTransmit, numberOfDevices);
+ }
+
+
+ /*** Component's Instance Variables ***/
+
+ /* Identity */
+ uint8_t who_am_i;
+
+ /* ACTION 9 --------------------------------------------------------------*
+ * There should be only a unique identifier for each component, which *
+ * should be the "who_am_i" parameter, hence this parameter is optional. *
+ *------------------------------------------------------------------------*/
+ /* Type. */
+ uint8_t type;
+
+ /* Configuration. */
+ DigitalOut ssel;
+
+ /* Standby and reset pin. */
+ DigitalOut reset;
+
+ /* Direction of rotation pin. */
+ DigitalOut direction;
+
+ /* Pulse Width Modulation pin. */
+ PwmOut pwm;
+
+ /* Timer to trigger the PWM callback at each PWM pulse. */
+ Ticker ticker;
+
+ /* IO Device. */
+ DevSPI &dev_spi;
+
+ /* Interrupts. */
+ /* ACTION 10 -------------------------------------------------------------*
+ * Put here interrupt related objects, if needed. *
+ * Note that interrupt handling is platform dependent, see *
+ * "Interrupt Related Methods" above. *
+ * *
+ * Example: *
+ * + mbed: *
+ * InterruptIn feature_int; *
+ *------------------------------------------------------------------------*/
+
+ /* Data. */
+ /* ACTION 11 -------------------------------------------------------------*
+ * Declare here the component's data, one variable per line. *
+ * *
+ * Example: *
+ * int T0_out; *
+ * int T1_out; *
+ * float T0_degC; *
+ * float T1_degC; *
+ *------------------------------------------------------------------------*/
+ void (*flagInterruptCallback)(void);
+ void (*errorHandlerCallback)(uint16_t error);
+ uint8_t spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES];
+ uint8_t spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES];
+ bool spiPreemtionByIsr;
+ bool isrFlag;
+ deviceParams_t devicePrm;
+ static uint8_t numberOfDevices;
+ uint8_t deviceInstance;
+};
+
+#endif // __L6474_CLASS_H
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6474/l6474_target_config.h Wed Oct 14 15:12:18 2015 +0000
@@ -0,0 +1,238 @@
+/**************************************************************************//**
+ * @file l6474_target_config.h
+ * @author IPC Rennes
+ * @version V1.5.0
+ * @date November 12, 2014
+ * @brief Predefines values for the L6474 registers
+ * and for the devices parameters
+ * @note (C) COPYRIGHT 2014 STMicroelectronics
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * 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 STMicroelectronics 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __L6474_TARGET_CONFIG_H
+#define __L6474_TARGET_CONFIG_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup L6474
+ * @{
+ */
+
+/** @addtogroup L6474_Exported_Constants
+ * @{
+ */
+
+/** @defgroup Predefined_L6474_Registers_Values
+ * @{
+ */
+
+/// The maximum number of devices in the daisy chain
+#define MAX_NUMBER_OF_DEVICES (3)
+
+/************************ Speed Profile *******************************/
+
+/// Acceleration rate in step/s2 for device 0 (must be greater than 0)
+#define L6474_CONF_PARAM_ACC_DEVICE_0 (160)
+/// Acceleration rate in step/s2 for device 1 (must be greater than 0)
+#define L6474_CONF_PARAM_ACC_DEVICE_1 (160)
+/// Acceleration rate in step/s2 for device 2 (must be greater than 0)
+#define L6474_CONF_PARAM_ACC_DEVICE_2 (160)
+
+/// Deceleration rate in step/s2 for device 0 (must be greater than 0)
+#define L6474_CONF_PARAM_DEC_DEVICE_0 (160)
+/// Deceleration rate in step/s2 for device 1 (must be greater than 0)
+#define L6474_CONF_PARAM_DEC_DEVICE_1 (160)
+/// Deceleration rate in step/s2 for device 2 (must be greater than 0)
+#define L6474_CONF_PARAM_DEC_DEVICE_2 (160)
+
+/// Maximum speed in step/s for device 0 (30 step/s < Maximum speed <= 10 000 step/s )
+#define L6474_CONF_PARAM_MAX_SPEED_DEVICE_0 (1600)
+/// Maximum speed in step/s for device 1 (30 step/s < Maximum speed <= 10 000 step/s )
+#define L6474_CONF_PARAM_MAX_SPEED_DEVICE_1 (1600)
+/// Maximum speed in step/s for device 2 (30 step/s < Maximum speed <= 10 000 step/s )
+#define L6474_CONF_PARAM_MAX_SPEED_DEVICE_2 (1600)
+
+/// Minimum speed in step/s for device 0 (30 step/s <= Minimum speed < 10 000 step/s)
+#define L6474_CONF_PARAM_MIN_SPEED_DEVICE_0 (800)
+/// Minimum speed in step/s for device 1 (30 step/s <= Minimum speed < 10 000 step/s)
+#define L6474_CONF_PARAM_MIN_SPEED_DEVICE_1 (800)
+/// Minimum speed in step/s for device 2 (30 step/s <= Minimum speed < 10 000 step/s)
+#define L6474_CONF_PARAM_MIN_SPEED_DEVICE_2 (800)
+
+
+/************************ Phase Current Control *******************************/
+
+// Current value that is assigned to the torque regulation DAC
+/// TVAL register value for device 0 (range 31.25mA to 4000mA)
+#define L6474_CONF_PARAM_TVAL_DEVICE_0 (250)
+/// TVAL register value for device 1 (range 31.25mA to 4000mA)
+#define L6474_CONF_PARAM_TVAL_DEVICE_1 (250)
+/// TVAL register value for device 2 (range 31.25mA to 4000mA)
+#define L6474_CONF_PARAM_TVAL_DEVICE_2 (250)
+
+/// Fall time value (T_FAST field of T_FAST register) for device 0 (range 2us to 32us)
+#define L6474_CONF_PARAM_FAST_STEP_DEVICE_0 (L6474_FAST_STEP_12us)
+/// Fall time value (T_FAST field of T_FAST register) for device 1 (range 2us to 32us)
+#define L6474_CONF_PARAM_FAST_STEP_DEVICE_1 (L6474_FAST_STEP_12us)
+/// Fall time value (T_FAST field of T_FAST register) for device 2 (range 2us to 32us)
+#define L6474_CONF_PARAM_FAST_STEP_DEVICE_2 (L6474_FAST_STEP_12us)
+
+/// Maximum fast decay time (T_OFF field of T_FAST register) for device 0 (range 2us to 32us)
+#define L6474_CONF_PARAM_TOFF_FAST_DEVICE_0 (L6474_TOFF_FAST_8us)
+/// Maximum fast decay time (T_OFF field of T_FAST register) for device 1 (range 2us to 32us)
+#define L6474_CONF_PARAM_TOFF_FAST_DEVICE_1 (L6474_TOFF_FAST_8us)
+/// Maximum fast decay time (T_OFF field of T_FAST register) for device 2 (range 2us to 32us)
+#define L6474_CONF_PARAM_TOFF_FAST_DEVICE_2 (L6474_TOFF_FAST_8us)
+
+/// Minimum ON time (TON_MIN register) for device 0 (range 0.5us to 64us)
+#define L6474_CONF_PARAM_TON_MIN_DEVICE_0 (3)
+/// Minimum ON time (TON_MIN register) for device 1 (range 0.5us to 64us)
+#define L6474_CONF_PARAM_TON_MIN_DEVICE_1 (3)
+/// Minimum ON time (TON_MIN register) for device 2 (range 0.5us to 64us)
+#define L6474_CONF_PARAM_TON_MIN_DEVICE_2 (3)
+
+/// Minimum OFF time (TOFF_MIN register) for device 0 (range 0.5us to 64us)
+#define L6474_CONF_PARAM_TOFF_MIN_DEVICE_0 (21)
+/// Minimum OFF time (TOFF_MIN register) for device 1 (range 0.5us to 64us)
+#define L6474_CONF_PARAM_TOFF_MIN_DEVICE_1 (21)
+/// Minimum OFF time (TOFF_MIN register) for device 2 (range 0.5us to 64us)
+#define L6474_CONF_PARAM_TOFF_MIN_DEVICE_2 (21)
+
+/******************************* Others ***************************************/
+
+/// Overcurrent threshold settings for device 0 (OCD_TH register)
+#define L6474_CONF_PARAM_OCD_TH_DEVICE_0 (L6474_OCD_TH_750mA)
+/// Overcurrent threshold settings for device 1 (OCD_TH register)
+#define L6474_CONF_PARAM_OCD_TH_DEVICE_1 (L6474_OCD_TH_750mA)
+/// Overcurrent threshold settings for device 2 (OCD_TH register)
+#define L6474_CONF_PARAM_OCD_TH_DEVICE_2 (L6474_OCD_TH_750mA)
+
+/// Alarm settings for device 0 (ALARM_EN register)
+#define L6474_CONF_PARAM_ALARM_EN_DEVICE_0 (L6474_ALARM_EN_OVERCURRENT |\
+ L6474_ALARM_EN_THERMAL_SHUTDOWN |\
+ L6474_ALARM_EN_THERMAL_WARNING |\
+ L6474_ALARM_EN_UNDERVOLTAGE |\
+ L6474_ALARM_EN_SW_TURN_ON |\
+ L6474_ALARM_EN_WRONG_NPERF_CMD)
+
+///Alarm settings for device 1 (ALARM_EN register)
+#define L6474_CONF_PARAM_ALARM_EN_DEVICE_1 (L6474_ALARM_EN_OVERCURRENT |\
+ L6474_ALARM_EN_THERMAL_SHUTDOWN |\
+ L6474_ALARM_EN_THERMAL_WARNING |\
+ L6474_ALARM_EN_UNDERVOLTAGE |\
+ L6474_ALARM_EN_SW_TURN_ON |\
+ L6474_ALARM_EN_WRONG_NPERF_CMD)
+
+/// Alarm settings for device 2 (ALARM_EN register)
+#define L6474_CONF_PARAM_ALARM_EN_DEVICE_2 (L6474_ALARM_EN_OVERCURRENT |\
+ L6474_ALARM_EN_THERMAL_SHUTDOWN |\
+ L6474_ALARM_EN_THERMAL_WARNING |\
+ L6474_ALARM_EN_UNDERVOLTAGE |\
+ L6474_ALARM_EN_SW_TURN_ON |\
+ L6474_ALARM_EN_WRONG_NPERF_CMD)
+
+/// Step selection settings for device 0 (STEP_SEL field of STEP_MODE register)
+#define L6474_CONF_PARAM_STEP_SEL_DEVICE_0 (L6474_STEP_SEL_1_16)
+/// Step selection settings for device 1 (STEP_SEL field of STEP_MODE register)
+#define L6474_CONF_PARAM_STEP_SEL_DEVICE_1 (L6474_STEP_SEL_1_16)
+/// Step selection settings for device 2 (STEP_SEL field of STEP_MODE register)
+#define L6474_CONF_PARAM_STEP_SEL_DEVICE_2 (L6474_STEP_SEL_1_16)
+
+/// Synch. selection settings for device 0 (SYNC_SEL field of STEP_MODE register)
+#define L6474_CONF_PARAM_SYNC_SEL_DEVICE_0 (L6474_SYNC_SEL_1_2)
+/// Synch. selection settings for device 1 (SYNC_SEL field of STEP_MODE register)
+#define L6474_CONF_PARAM_SYNC_SEL_DEVICE_1 (L6474_SYNC_SEL_1_2)
+/// Synch. selection settings for device 2 (SYNC_SEL field of STEP_MODE register)
+#define L6474_CONF_PARAM_SYNC_SEL_DEVICE_2 (L6474_SYNC_SEL_1_2)
+
+/// Target Swicthing Period for device 0 (field TOFF of CONFIG register)
+#define L6474_CONF_PARAM_TOFF_DEVICE_0 (L6474_CONFIG_TOFF_044us)
+/// Target Swicthing Period for device 1 (field TOFF of CONFIG register)
+#define L6474_CONF_PARAM_TOFF_DEVICE_1 (L6474_CONFIG_TOFF_044us)
+/// Target Swicthing Period for device 2 (field TOFF of CONFIG register)
+#define L6474_CONF_PARAM_TOFF_DEVICE_2 (L6474_CONFIG_TOFF_044us)
+
+/// Slew rate for device 0 (POW_SR field of CONFIG register)
+#define L6474_CONF_PARAM_SR_DEVICE_0 (L6474_CONFIG_SR_320V_us)
+/// Slew rate for device 1 (POW_SR field of CONFIG register)
+#define L6474_CONF_PARAM_SR_DEVICE_1 (L6474_CONFIG_SR_320V_us)
+/// Slew rate for device 2 (POW_SR field of CONFIG register)
+#define L6474_CONF_PARAM_SR_DEVICE_2 (L6474_CONFIG_SR_320V_us)
+
+/// Over current shutwdown enabling for device 0 (OC_SD field of CONFIG register)
+#define L6474_CONF_PARAM_OC_SD_DEVICE_0 (L6474_CONFIG_OC_SD_ENABLE)
+/// Over current shutwdown enabling for device 1 (OC_SD field of CONFIG register)
+#define L6474_CONF_PARAM_OC_SD_DEVICE_1 (L6474_CONFIG_OC_SD_ENABLE)
+/// Over current shutwdown enabling for device 2 (OC_SD field of CONFIG register)
+#define L6474_CONF_PARAM_OC_SD_DEVICE_2 (L6474_CONFIG_OC_SD_ENABLE)
+
+/// Torque regulation method for device 0 (EN_TQREG field of CONFIG register)
+#define L6474_CONF_PARAM_TQ_REG_DEVICE_0 (L6474_CONFIG_EN_TQREG_TVAL_USED)
+///Torque regulation method for device 1 (EN_TQREG field of CONFIG register)
+#define L6474_CONF_PARAM_TQ_REG_DEVICE_1 (L6474_CONFIG_EN_TQREG_TVAL_USED)
+/// Torque regulation method for device 2 (EN_TQREG field of CONFIG register)
+#define L6474_CONF_PARAM_TQ_REG_DEVICE_2 (L6474_CONFIG_EN_TQREG_TVAL_USED)
+
+/// Clock setting for device 0 (OSC_CLK_SEL field of CONFIG register)
+#define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_0 (L6474_CONFIG_INT_16MHZ)
+/// Clock setting for device 1 (OSC_CLK_SEL field of CONFIG register)
+#define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_1 (L6474_CONFIG_INT_16MHZ)
+/// Clock setting for device 2 (OSC_CLK_SEL field of CONFIG register)
+#define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_2 (L6474_CONFIG_INT_16MHZ)
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* __L6474_TARGET_CONFIG_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_COMMON.lib Wed Oct 14 15:12:18 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#1f35e8bf427b
