Use BDCMotor_class.h instead of motor_class.h
Dependents: HelloWorld_IHM04A1
Fork of X_NUCLEO_IHM04A1 by
Revision 0:2cb6ce8e07bd, committed 2016-05-03
- Comitter:
- brdirais
- Date:
- Tue May 03 11:16:57 2016 +0000
- Child:
- 1:2597a6165252
- Commit message:
- Initial version of X-NUCLEO-IHM04A1 library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/component.h Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,94 @@
+/**
+ ******************************************************************************
+ * @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.
+ *
+ ******************************************************************************
+ */
+
+
+/* Define to 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;
+} Handle_t;
+
+/**
+ * @brief Component's Status enumerator definition.
+ */
+typedef enum
+{
+ COMPONENT_OK = 0,
+ COMPONENT_ERROR,
+ COMPONENT_TIMEOUT,
+ COMPONENT_NOT_IMPLEMENTED
+} Status_t;
+
+#endif /* __COMPONENT_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/motor.h Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,437 @@
+/**
+ ******************************************************************************
+ * @file motor.h
+ * @author IPC Rennes
+ * @version V1.5.0
+ * @date January 25, 2016
+ * @brief This file contains all the functions prototypes for motor drivers.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2016 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 Motor
+ * @{
+ */
+
+/** @defgroup Motor_Exported_Constants 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 Motor Exported Types
+ * @{
+ */
+
+/** @defgroup Motor_Boolean_Type Motor Boolean Type
+ * @{
+ */
+///bool Type
+//typedef uint8_t bool;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Direction_Options Device Direction Options
+ * @{
+ */
+/// Direction options
+typedef enum {
+ BACKWARD = 0,
+ FORWARD = 1,
+ UNKNOW_DIR = ((uint8_t)0xFF)
+} motorDir_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Action_Options Device Action Options
+ * @{
+ */
+/// Action options
+typedef enum {
+ ACTION_RESET = ((uint8_t)0x00),
+ ACTION_COPY = ((uint8_t)0x08)
+} motorAction_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_States Device States
+ * @{
+ */
+/// Device states
+typedef enum {
+ ACCELERATING = 0,
+ DECELERATINGTOSTOP = 1,
+ DECELERATING = 2,
+ STEADY = 3,
+ INDEX_ACCEL = 4,
+ INDEX_RUN = 5,
+ INDEX_DECEL = 6,
+ INDEX_DWELL = 7,
+ INACTIVE = 8,
+ STANDBY = 9,
+ STANDBYTOINACTIVE = 10
+} motorState_t;
+/**
+ * @}
+ */
+
+/** @defgroup Device_Step_mode 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),
+ STEP_MODE_1_256 = ((uint8_t)0x08),
+ STEP_MODE_UNKNOW = ((uint8_t)0xFE),
+ STEP_MODE_WAVE = ((uint8_t)0xFF)
+} motorStepMode_t;
+
+/**
+ * @}
+ */
+
+/** @defgroup Decay_mode Decay mode
+ * @{
+ */
+/// Decay Mode
+typedef enum {
+ SLOW_DECAY = 0,
+ FAST_DECAY = 1,
+ UNKNOW_DECAY = ((uint8_t)0xFF)
+} motorDecayMode_t;
+/**
+ * @}
+ */
+
+/** @defgroup Stop_mode Stop mode
+ * @{
+ */
+/// Stop mode
+typedef enum
+{
+ HOLD_MODE = 0,
+ HIZ_MODE = 1,
+ STANDBY_MODE = 2,
+ UNKNOW_STOP_MODE = ((uint8_t)0xFF)
+} motorStopMode_t;
+/**
+ * @}
+ */
+
+/** @defgroup Torque_mode Torque mode
+ * @{
+ */
+/// Torque mode
+typedef enum
+{
+ ACC_TORQUE = 0,
+ DEC_TORQUE = 1,
+ RUN_TORQUE = 2,
+ HOLD_TORQUE = 3,
+ CURRENT_TORQUE = 4,
+ UNKNOW_TORQUE = ((uint8_t)0xFF)
+} motorTorqueMode_t;
+/**
+ * @}
+ */
+
+/** @defgroup Dual_Full_Bridge_Configuration Dual Full Bridge Configuration
+ * @{
+ */
+///Dual full bridge configurations for brush DC motors
+typedef enum {
+ PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 0,
+ PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 1,
+ PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 2,
+ PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 3,
+ PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B = 4,
+ PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B = 5,
+ PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 6,
+ PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 7,
+ PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B = 8,
+ PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR = 9,
+ PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A = 10,
+ PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR = 11,
+ PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR = 12,
+ PARALLELING_END_ENUM = 13
+} dualFullBridgeConfig_t;
+/**
+ * @}
+ */
+
+/** @defgroup Motor_Driver_Structure Motor Driver Structure
+ * @{
+ */
+/// Motor driver structure definition
+typedef struct
+{
+
+ /* Generic */
+ Status_t (*Init)(void *handle, void *init);
+ Status_t (*ReadID)(void *handle, uint8_t *id);
+
+ /* Interrupts */
+ /// 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 */
+ /// Function pointer to GetAcceleration
+ uint16_t (*GetAcceleration)(void *handle);
+ /// Function pointer to GetCurrentSpeed
+ uint16_t (*GetCurrentSpeed)(void *handle, uint8_t motorId);
+ /// Function pointer to GetDeceleration
+ uint16_t (*GetDeceleration)(void *handle);
+ /// Function pointer to GetDeviceState
+ motorState_t(*GetDeviceState)(void *handle, uint8_t motorId);
+ /// 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, uint8_t motorId);
+ /// Function pointer to GetMinSpeed
+ uint16_t (*GetMinSpeed)(void *handle, uint8_t motorId);
+ /// 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, uint8_t deviceId, int32_t motorId);
+ /// Function pointer to HardStop
+ void (*HardStop)(void *handle, uint8_t motorId);
+ /// 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, uint8_t stepCount, 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, uint8_t motorId, uint16_t newMaxSpeed);
+ /// Function pointer to SetMinSpeed
+ bool (*SetMinSpeed)(void *handle, uint8_t motorId, uint16_t newMinSpeed);
+ /// Function pointer to SoftStop
+ bool (*SoftStop)(void *handle);
+ /// Function pointer to StepClockHandler
+ void (*StepClockHandler)(void *handle);
+ /// Function pointer to WaitWhileActive
+ void (*WaitWhileActive)(void *handle);
+ /// Function pointer to CmdDisable
+ void (*CmdDisable)(void *handle, uint8_t bridgeId);
+ /// Function pointer to CmdEnable
+ void (*CmdEnable)(void *handle, uint8_t bridgeId);
+ /// Function pointer to CmdGetParam
+ uint32_t (*CmdGetParam)(void *handle, uint32_t param);
+ /// Function pointer to CmdGetStatus
+ uint16_t (*CmdGetStatus)(void *handle, uint8_t bridgeId);
+ /// 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 stepMode);
+ /// Function pointer to SetDirection
+ void (*SetDirection)(void *handle, motorDir_t direction);
+ /// Function pointer to CmdGoToDir
+ void (*CmdGoToDir)(void *handle, motorDir_t direction, int32_t abs_pos);
+ /// 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 speed);
+ /// Function pointer to CmdHardHiZ
+ void (*CmdHardHiZ)(void *handle, uint8_t motorId);
+ /// 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 speed);
+ /// 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 param, int32_t value);
+ /// 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);
+ /// Function pointer to StartStepClock
+ void (*StartStepClock)(void *handle);
+ /// Function pointer to StopStepClock
+ void (*StopStepClock)(void *handle);
+ /// Function pointer to SetDualFullBridgeConfig
+ void (*SetDualFullBridgeConfig)(void *handle, uint8_t newConfig);
+ /// Function pointer to GetBridgeInputPwmFreq
+ uint32_t (*GetBridgeInputPwmFreq)(void *handle, uint8_t bridgeId);
+ /// Function pointer to SetBridgeInputPwmFreq
+ void (*SetBridgeInputPwmFreq)(void *handle, uint8_t bridgeId, uint32_t newFreq);
+ /// Function pointer to SetStopMode
+ void (*SetStopMode)(void *handle, motorStopMode_t stopMode);
+ /// Function pointer to GetStopMode
+ motorStopMode_t (*GetStopMode)(void *handle);
+ /// Function pointer to SetDecayMode
+ void (*SetDecayMode)(void *handle, motorDecayMode_t decayMode);
+ /// Function pointer to GetDecayMode
+ motorDecayMode_t (*GetDecayMode)(void *handle);
+ /// Function pointer to GetStepMode
+ motorStepMode_t (*GetStepMode)(void *handle);
+ /// Function pointer to GetDirection
+ motorDir_t (*GetDirection)(void *handle);
+ /// Function pointer to ExitDeviceFromReset
+ void (*ExitDeviceFromReset)(void *handle);
+ /// Function pointer to SetTorque
+ void (*SetTorque)(void *handle, motorTorqueMode_t torqueMode, uint8_t torqueValue);
+ /// Function pointer to GetTorque
+ uint8_t (*GetTorque)(void *handle, motorTorqueMode_t torqueMode);
+ /// Function pointer to SetVRefFreq
+ void (*SetRefFreq)(void *handle, uint32_t freq);
+ /// Function pointer to GetVRefFreq
+ uint32_t (*GetRefFreq)(void *handle);
+ /// Function pointer to SetVRefDc
+ void (*SetRefDc)(void *handle, uint8_t RefDc);
+ /// Function pointer to GetVRefDc
+ uint8_t (*GetRefDc)(void *handle);
+ /// Function pointer to SetNbDevices
+ bool (*SetNbDevices)(void *handle, uint8_t nbDevices);
+ /// Function pointer to set a parameter
+ bool (*SetAnalogValue)(void *handle, uint32_t param, float value);
+ /// Function pointer to get a parameter
+ float (*GetAnalogValue)(void *handle, uint32_t param);
+} MOTOR_VTable_t;
+
+/**
+
+* @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#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 Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,76 @@
+/**
+ ******************************************************************************
+ * @file Component_class.h
+ * @author AST
+ * @version V1.0.0
+ * @date April 13th, 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 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 Initializing the component.
+ * @param[in] init pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+ virtual int Init(void *init) = 0;
+
+ /**
+ * @brief Getting the ID of the component.
+ * @param[out] id pointer to an allocated variable to store the ID into.
+ * @retval "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 Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,102 @@
+/**
+ ******************************************************************************
+ * @file Motor_class.h
+ * @author AST
+ * @version V1.0.0
+ * @date April 13th, 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-SPN4/trunk/Drivers/BSP/Components/Common/motor.h
+ Revision: 0
+*/
+
+
+/* Define to prevent 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 *f) = 0; *
+ *------------------------------------------------------------------------*/
+ virtual uint16_t GetCurrentSpeed(uint8_t motorId) = 0;
+ virtual motorState_t GetDeviceState(uint8_t motorId) = 0;
+ virtual uint8_t GetFwVersion(void) = 0;
+ virtual uint16_t GetMaxSpeed(uint8_t motorId) = 0;
+ virtual void HardStop(uint8_t motorId) = 0;
+ virtual void Run(uint8_t stepCount, motorDir_t direction) = 0;
+ virtual bool SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed) = 0;
+ virtual void CmdDisable(uint8_t bridgeId) = 0;
+ virtual void CmdEnable(uint8_t bridgeId) = 0;
+ virtual uint16_t CmdGetStatus(uint8_t bridgeId) = 0;
+ virtual void CmdHardHiZ(uint8_t motorId) = 0;
+ virtual void ErrorHandler(uint16_t error) = 0;
+ virtual void SetDualFullBridgeConfig(uint8_t newConfig) = 0;
+ virtual uint32_t GetBridgeInputPwmFreq(uint8_t bridgeId) = 0;
+ virtual void SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq) = 0;
+ virtual bool SetNbDevices(uint8_t nbDevices) = 0;
+};
+
+#endif /* __MOTOR_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6206/l6206.h Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,221 @@
+/**
+ ******************************************************************************
+ * @file l6206.h
+ * @author IPC Rennes
+ * @version V1.2.0
+ * @date March 30, 2016
+ * @brief Header for L6206 driver (dual full bridge driver)
+ * @note (C) COPYRIGHT 2015 STMicroelectronics
+ ******************************************************************************
+ * @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 recursive inclusion -------------------------------------*/
+#ifndef __L6206_H
+#define __L6206_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "l6206_target_config.h"
+#include "../Common/motor.h"
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup L6206
+ * @{
+ */
+
+/* Exported Constants --------------------------------------------------------*/
+
+/** @defgroup L6206_Exported_Constants L6206 Exported Constants
+ * @{
+ */
+
+/// Current FW version
+#define L6206_FW_VERSION (0)
+///Max number of Brush DC motors
+#define L6206_NB_MAX_MOTORS (4)
+///Max number of Bridges
+#define L6206_NB_MAX_BRIDGES (2)
+///Max number of input of Bridges
+#define L6206_NB_MAX_BRIDGE_INPUT (2 * L6206_NB_MAX_BRIDGES)
+/// MCU wait time in ms after power bridges are enabled
+#define BSP_MOTOR_CONTROL_BOARD_BRIDGE_TURN_ON_DELAY (20)
+
+ /**
+ * @}
+ */
+
+
+/* Exported Types -------------------------------------------------------*/
+
+/** @defgroup L6206_Exported_Types L6206 Exported Types
+ * @{
+ */
+
+
+
+
+/** @defgroup Initialization_Structure Initialization Structure
+ * @{
+ */
+
+typedef struct
+{
+ /// Bridge configuration structure.
+ dualFullBridgeConfig_t config;
+
+ /// PWM frequency
+ uint32_t pwmFreq[L6206_NB_MAX_BRIDGE_INPUT];
+
+ /// Motor speed
+ uint16_t speed[L6206_NB_MAX_MOTORS];
+
+ /// Motor direction
+ motorDir_t direction[L6206_NB_MAX_MOTORS];
+
+ /// Current motor state
+ motorState_t motionState[L6206_NB_MAX_MOTORS];
+
+ /// Bridge enabled (true) or not (false)
+ bool bridgeEnabled[L6206_NB_MAX_BRIDGES];
+} deviceParams_t;
+
+
+
+
+typedef deviceParams_t L6206_Init_t;
+
+
+
+/**
+ * @}
+ */
+
+
+/** @defgroup Data_Structure Data Structure
+ * @{
+ */
+
+/* ACTION --------------------------------------------------------------------*
+ * Declare here the structure of component's data, if any, one variable per *
+ * line without initialization. *
+ * *
+ * Example: *
+ * typedef struct *
+ * { *
+ * int T0_out; *
+ * int T1_out; *
+ * float T0_degC; *
+ * float T1_degC; *
+ * } COMPONENT_Data_t; *
+ *----------------------------------------------------------------------------*/
+typedef struct
+{
+ /// Function pointer to flag interrupt call back
+ void (*flagInterruptCallback)(void);
+
+ /// Function pointer to error handler call back
+ void (*errorHandlerCallback)(uint16_t error);
+
+ /// number of L6206 devices
+ uint8_t numberOfDevices;
+
+ /// L6206 driver instance
+ uint8_t deviceInstance;
+
+ /// L6206 Device Paramaters structure
+ deviceParams_t devicePrm;
+} L6206_Data_t;
+
+/**
+ * @}
+ */
+
+
+
+/**
+ * @}
+ */
+
+/* Exported functions --------------------------------------------------------*/
+
+
+/** @defgroup MotorControl_Board_Linked_Functions MotorControl Board Linked Functions
+ * @{
+ */
+///Delay of the requested number of milliseconds
+extern void L6206_Board_Delay(void *handle, uint32_t delay);
+///Disable the specified bridge
+extern void L6206_Board_DisableBridge(void *handle, uint8_t bridgeId);
+///Enable the specified bridge
+extern void L6206_Board_EnableBridge(void *handle, uint8_t bridgeId, uint8_t addDelay);
+//Get the status of the flag and enable Pin
+extern uint32_t L6206_Board_GetFlagPinState(void *handle, uint8_t bridgeId);
+///Initialise GPIOs used for L6206s
+extern void L6206_Board_GpioInit(void *handle);
+///Set Briges Inputs PWM frequency and start it
+extern void L6206_Board_PwmSetFreq(void *handle, uint8_t bridgeInput, uint32_t newFreq, uint8_t duty);
+///Deinitialise the PWM of the specified bridge input
+extern void L6206_Board_PwmDeInit(void *handle, uint8_t bridgeInput);
+///Init the PWM of the specified bridge input
+extern void L6206_Board_PwmInit(void *handle, uint8_t bridgeInput);
+///Stop the PWM of the specified bridge input
+extern void L6206_Board_PwmStop(void *handle, uint8_t bridgeInput);
+
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* #ifndef __L6206_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6206/l6206_class.cpp Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,1258 @@
+/**
+ ******************************************************************************
+ * @file l6206_class.cpp
+ * @author IPC Rennes
+ * @version V1.1.0
+ * @date March 02, 2016
+ * @brief L6206 driver (dual full bridge driver)
+ * @note (C) COPYRIGHT 2015 STMicroelectronics
+ ******************************************************************************
+ * @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-SPN4/trunk/Drivers/BSP/Components/l6206/l6206.c
+ Revision: 0
+*/
+
+/* Includes ------------------------------------------------------------------*/
+#include "l6206_class.h"
+#include "l6206.h"
+#include "string.h"
+
+/* Private constants ---------------------------------------------------------*/
+
+
+/* Private variables ---------------------------------------------------------*/
+static uint8_t l6206ArrayNbMaxMotorsByConfig[PARALLELING_END_ENUM] = {2,3,3,4,2,3,2,3,2,1,2,1,1};
+
+/* Private constant ---------------------------------------------------------*/
+
+/** @defgroup L6206_Private_Constants L6206 Private Constants
+ * @{
+ */
+
+/// Max numbers of supported motors depending of the parraleling bridges configuration
+
+
+/* Function prototypes -----------------------------------------------*/
+
+/** @defgroup L6206_Exported_Functions L6206 Exported Functions
+ * @{
+ */
+
+/* Private function prototypes -----------------------------------------------*/
+
+/** @defgroup L6206_Private_functions L6206 Private functions
+ * @{
+ */
+/** @defgroup L6206_Exported_Variables L6206 Exported Variables
+ * @{
+ */
+
+/** @defgroup L6206_Exported_Functions L6206 Exported Functions
+ * @{
+ */
+
+/******************************************************//**
+ * @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 L6206::L6206_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 alert)
+ * @param[in] callback Name of the callback to attach
+ * to the Flag Interrupt
+ * @retval None
+ **********************************************************/
+void L6206::L6206_AttachFlagInterrupt(void (*callback)(void))
+{
+ flagInterruptCallback = (void (*)(void))callback;
+}
+
+/******************************************************//**
+ * @brief Disable the specified bridge
+ * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
+ * @retval None
+ * @note When input of different brigdes are parallelized
+ * together, the disabling of one bridge leads to the disabling
+ * of the second one
+ **********************************************************/
+void L6206::L6206_DisableBridge(uint8_t bridgeId)
+{
+ L6206_Board_DisableBridge(bridgeId);
+
+ devicePrm.bridgeEnabled[bridgeId] = FALSE;
+ if (devicePrm.config >= PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR)
+ {
+ if (bridgeId == BRIDGE_A)
+ {
+ L6206_Board_DisableBridge(BRIDGE_B);
+ devicePrm.bridgeEnabled[BRIDGE_B] = FALSE;
+ }
+ else
+ {
+ L6206_Board_DisableBridge(BRIDGE_A);
+ devicePrm.bridgeEnabled[BRIDGE_A] = FALSE;
+ }
+ }
+}
+
+/******************************************************//**
+ * @brief Enable the specified bridge
+ * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
+ * @retval None
+ * @note When input of different brigdes are parallelized
+ * together, the enabling of one bridge leads to the enabling
+ * of the second one
+ **********************************************************/
+void L6206::L6206_EnableBridge(uint8_t bridgeId)
+{
+ devicePrm.bridgeEnabled[bridgeId] = TRUE;
+ if (devicePrm.config >= PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR)
+ {
+ L6206_Board_EnableBridge(bridgeId, 0);
+ if (bridgeId == BRIDGE_A)
+ {
+ L6206_Board_EnableBridge(BRIDGE_B, 1);
+ devicePrm.bridgeEnabled[BRIDGE_B] = TRUE;
+ }
+ else
+ {
+ L6206_Board_EnableBridge(BRIDGE_A, 1);
+ devicePrm.bridgeEnabled[BRIDGE_A] = TRUE;
+ }
+ }
+ else
+ {
+ L6206_Board_EnableBridge(bridgeId, 1);
+ }
+}
+
+/******************************************************//**
+ * @brief Start the L6206 library
+ * @param[in] init pointer to the initialization data
+ * @retval None
+ **********************************************************/
+Status_t L6206::L6206_Init(void *init)
+{
+ deviceInstance++;
+
+ /* Initialise the GPIOs */
+ L6206_Board_GpioInit();
+
+ if (init == NULL)
+ {
+ /* Set context variables to the predefined values from l6206_target_config.h */
+ /* Set GPIO according to these values */
+ L6206_SetDeviceParamsToPredefinedValues();
+ }
+ else
+ {
+ L6206_SetDeviceParamsToGivenValues((L6206_Init_t*) init);
+ }
+
+ /* Initialise input bridges PWMs */
+ L6206_SetDualFullBridgeConfig(devicePrm.config);
+
+ return COMPONENT_OK;
+}
+
+/******************************************************//**
+ * @brief Get the PWM frequency of the specified bridge
+ * @param[in] bridgeId 0 for bridge A, 1 for bridge B
+ * @retval Freq in Hz
+ **********************************************************/
+uint32_t L6206::L6206_GetBridgeInputPwmFreq(uint8_t bridgeId)
+{
+ return (devicePrm.pwmFreq[(bridgeId << 1)]);
+}
+
+/******************************************************//**
+ * @brief Returns the current speed of the specified motor
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval current speed in % from 0 to 100
+ **********************************************************/
+uint16_t L6206::L6206_GetCurrentSpeed(uint8_t motorId)
+{
+ uint16_t speed = 0;
+
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else if (devicePrm.motionState[motorId] != INACTIVE)
+ {
+ speed = devicePrm.speed[motorId];
+ }
+
+ return (speed);
+}
+
+/******************************************************//**
+ * @brief Returns the device state
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval State (STEADY or INACTIVE)
+ **********************************************************/
+motorState_t L6206::L6206_GetDeviceState(uint8_t motorId)
+{
+ motorState_t state = INACTIVE;
+
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else
+ {
+ state = devicePrm.motionState[motorId];
+ }
+ return (state);
+}
+
+/******************************************************//**
+ * @brief Returns the FW version of the library
+ * @retval L6206_FW_VERSION
+ **********************************************************/
+uint8_t L6206::L6206_GetFwVersion(void)
+{
+ return (L6206_FW_VERSION);
+}
+
+/******************************************************//**
+ * @brief Returns the max speed of the specified motor
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval maxSpeed in % from 0 to 100
+ **********************************************************/
+uint16_t L6206::L6206_GetMaxSpeed(uint8_t motorId)
+{
+ uint16_t speed = 0;
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else
+ {
+ speed = devicePrm.speed[motorId];
+ }
+ return (speed);
+}
+
+
+/******************************************************//**
+ * @brief Get the status of the bridge enabling of the corresponding bridge
+ * @param[in] bridgeId from 0 for bridge A to 1 for bridge B
+ * @retval State of the Enable&Flag pin of the corresponding bridge (1 set, 0 for reset)
+ **********************************************************/
+uint16_t L6206::L6206_GetBridgeStatus(uint8_t bridgeId)
+{
+ uint16_t status = L6206_Board_GetFlagPinState(bridgeId);
+
+ return (status);
+}
+
+/******************************************************//**
+ * @brief Immediatly stops the motor and disable the power bridge
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval None
+ * @note if two motors uses the same power bridge, the
+ * power bridge will be disable only if the two motors are
+ * stopped
+ **********************************************************/
+void L6206::L6206_HardHiz(uint8_t motorId)
+{
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else
+ {
+ /* Get bridge Id of the corresponding motor */
+ uint8_t bridgeId = L6206_GetBridgeIdUsedByMotorId(motorId);
+
+ if (devicePrm.bridgeEnabled[bridgeId] != FALSE)
+ {
+ bool skip = FALSE;
+
+ /* Check if another motor is currently running by using the same bridge */
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if ((motorId > 0) && (devicePrm.motionState[1] == STEADY) && (devicePrm.motionState[2] == STEADY))
+ {
+ skip = TRUE;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if ((motorId < 2) && (devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))
+ {
+ skip = TRUE;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (((motorId < 2) && (devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))||
+ ((motorId > 1) && (devicePrm.motionState[2] == STEADY) && (devicePrm.motionState[3] == STEADY)))
+ {
+ skip = TRUE;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if ((motorId > 0) && (devicePrm.motionState[1] == STEADY) && (devicePrm.motionState[2] == STEADY))
+ {
+ skip = TRUE;
+ }
+ break;
+ case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if ((motorId < 2) && (devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))
+ {
+ skip = TRUE;
+ }
+ break;
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
+ if ((devicePrm.motionState[0] == STEADY) && (devicePrm.motionState[1] == STEADY))
+ {
+ skip = TRUE;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (skip == FALSE)
+ {
+ /* Disable the bridge */
+ L6206_DisableBridge(bridgeId);
+ }
+ }
+ /* Disable the PWM */
+ L6206_HardStop(motorId);
+ }
+}
+
+/******************************************************//**
+ * @brief Stops the motor without disabling the bridge
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval none
+ **********************************************************/
+void L6206::L6206_HardStop(uint8_t motorId)
+{
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else if (devicePrm.motionState[motorId] != INACTIVE)
+ {
+ uint8_t bridgeInput;
+
+ /* Get bridge input of the corresponding motor */
+ bridgeInput = L6206_GetBridgeInputUsedByMotorId(motorId);
+
+ /* Disable corresponding PWM */
+ L6206_Board_PwmStop(bridgeInput);
+
+ /* for bidirectionnal motor, disable second PWM*/
+ if (L6206_IsBidirectionnalMotor(motorId))
+ {
+ bridgeInput = L6206_GetSecondBridgeInputUsedByMotorId(motorId);
+ L6206_Board_PwmStop(bridgeInput);
+ }
+ /* Set inactive state */
+ devicePrm.motionState[motorId] = INACTIVE;
+ }
+}
+
+/******************************************************//**
+ * @brief Read id
+ * @retval Id of the l6206 Driver Instance
+ **********************************************************/
+Status_t L6206::L6206_ReadId(uint8_t *id)
+{
+ *id = deviceInstance;
+
+ return COMPONENT_OK;
+}
+
+/******************************************************//**
+ * @brief Runs the motor
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @param[in] direction FORWARD or BACKWARD
+ * @retval None
+ * @note For unidirectionnal motor, direction parameter has
+ * no effect
+ **********************************************************/
+void L6206::L6206_Run(uint8_t motorId, motorDir_t direction)
+{
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else if ((devicePrm.motionState[motorId] == INACTIVE) ||
+ (devicePrm.direction[motorId] != direction))
+ {
+ uint8_t bridgeId;
+ uint8_t bridgeInput;
+
+ /* Eventually deactivate motor */
+ if (devicePrm.motionState[motorId] != INACTIVE)
+ {
+ L6206_HardStop(motorId);
+ }
+
+ /* Store new direction */
+ devicePrm.direction[motorId] = direction;
+
+ /* Switch to steady state */
+ devicePrm.motionState[motorId] = STEADY;
+
+ /* Get bridge Id of the corresponding motor */
+ bridgeId = L6206_GetBridgeIdUsedByMotorId(motorId);
+
+ /* Get bridge input of the corresponding motor */
+ bridgeInput = L6206_GetBridgeInputUsedByMotorId(motorId);
+
+ /* Enable bridge */
+ L6206_EnableBridge(bridgeId);
+
+ /* Set PWM */
+ if (L6206_IsBidirectionnalMotor(motorId))
+ {
+ /* for bidirectionnal motor */
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],(100 - devicePrm.speed[motorId]));
+ bridgeInput = L6206_GetSecondBridgeInputUsedByMotorId(motorId);
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],100);
+ }
+ else
+ {
+ /* for unidirectionnal motor */
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],devicePrm.speed[motorId]);
+ }
+ }
+}
+/******************************************************//**
+ * @brief Set dual full bridge parallelling configuration
+ * @param[in] newConfig bridge configuration to apply from
+ * dualFullBridgeConfig_t enum
+ * @retval None
+ **********************************************************/
+void L6206::L6206_SetDualFullBridgeConfig(uint8_t newConfig)
+{
+ devicePrm.config = (dualFullBridgeConfig_t)newConfig;
+
+ /* Start to reset all else if several inits are used successively */
+ /* they will fail */
+ L6206_Board_PwmDeInit(INPUT_1A);
+ L6206_Board_PwmDeInit(INPUT_2A);
+ L6206_Board_PwmDeInit(INPUT_1B);
+ L6206_Board_PwmDeInit(INPUT_2B);
+
+
+ /* Initialise the bridges inputs PWMs --------------------------------------*/
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ L6206_Board_PwmInit(INPUT_1A);
+ L6206_Board_PwmInit(INPUT_2A);
+ L6206_Board_PwmInit(INPUT_1B);
+ L6206_Board_PwmInit(INPUT_2B);
+ break;
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ L6206_Board_PwmDeInit(INPUT_2A);
+ L6206_Board_PwmInit(INPUT_1A);
+ L6206_Board_PwmInit(INPUT_1B);
+ L6206_Board_PwmInit(INPUT_2B);
+ break;
+ case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ L6206_Board_PwmDeInit(INPUT_2B);
+ L6206_Board_PwmInit(INPUT_1A);
+ L6206_Board_PwmInit(INPUT_2A);
+ L6206_Board_PwmInit(INPUT_1B);
+ break;
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
+ L6206_Board_PwmDeInit(INPUT_2A);
+ L6206_Board_PwmDeInit(INPUT_2B);
+ L6206_Board_PwmInit(INPUT_1A);
+ L6206_Board_PwmInit(INPUT_1B);
+ break;
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
+ L6206_Board_PwmDeInit(INPUT_1B);
+ L6206_Board_PwmDeInit(INPUT_2B);
+ L6206_Board_PwmInit(INPUT_1A);
+ L6206_Board_PwmInit(INPUT_2A);
+ break;
+ case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
+ L6206_Board_PwmDeInit(INPUT_2A);
+ L6206_Board_PwmDeInit(INPUT_1B);
+ L6206_Board_PwmDeInit(INPUT_2B);
+ L6206_Board_PwmInit(INPUT_1A);
+ break;
+ default:
+ break;
+ }
+}
+/******************************************************//**
+ * @brief Changes the max speed of the specified device
+ * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @param[in] newMaxSpeed in % from 0 to 100
+ * @retval true if the command is successfully executed, else false
+ **********************************************************/
+bool L6206::L6206_SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed)
+{
+ bool cmdExecuted = FALSE;
+
+ if (motorId > l6206ArrayNbMaxMotorsByConfig[devicePrm.config])
+ {
+ L6206_ErrorHandler(L6206_ERROR_1);
+ }
+ else
+ {
+ devicePrm.speed[motorId] = newMaxSpeed;
+ if (devicePrm.motionState[motorId] != INACTIVE)
+ {
+ uint8_t bridgeInput;
+
+ /* Get Bridge input of the corresponding motor */
+ bridgeInput = L6206_GetBridgeInputUsedByMotorId(motorId);
+
+ /* Set PWM frequency*/
+ if (L6206_IsBidirectionnalMotor(motorId))
+ {
+ /* for bidirectionnal motor */
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],(100 - devicePrm.speed[motorId]));
+ }
+ else
+ {
+ /* for unidirectionnal motor */
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],devicePrm.speed[motorId]);
+ }
+ }
+ cmdExecuted = TRUE;
+ }
+ return cmdExecuted;
+}
+
+/******************************************************//**
+ * @brief Changes the PWM frequency of the bridge input
+ * @param[in] bridgeId 0 for bridge A, 1 for bridge B
+ * @param[in] newFreq in Hz
+ * @retval None
+ **********************************************************/
+void L6206::L6206_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq)
+{
+ uint8_t loop;
+
+ if (newFreq > L6206_MAX_PWM_FREQ)
+ {
+ newFreq = L6206_MAX_PWM_FREQ;
+ }
+ for (loop = 0; loop < 2;loop ++)
+ {
+ uint8_t motorId;
+ uint8_t bridgeInput = (bridgeId << 1) + loop;
+ devicePrm.pwmFreq[bridgeInput] = newFreq;
+
+ /* Get motor Id using this bridge */
+ motorId = L6206_GetMotorIdUsingbridgeInput(bridgeInput);
+
+ /* Immediatly update frequency if motor is running */
+ if (devicePrm.motionState[motorId] != INACTIVE)
+ {
+ /* Test if motor is bidir */
+ if (L6206_IsBidirectionnalMotor(motorId))
+ {
+ if (bridgeInput != L6206_GetSecondBridgeInputUsedByMotorId(motorId))
+ {
+ /* Set PWM frequency for bidirectionnal motor of the first bridge*/
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],(100 - devicePrm.speed[motorId]));
+ }
+ else
+ {
+ /* Set PWM frequency for bidirectionnal motor of the second bridge */
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],100);
+ }
+ }
+ else
+ {
+ /* Set PWM frequency for unidirectionnal motor */
+ L6206_Board_PwmSetFreq(bridgeInput, devicePrm.pwmFreq[bridgeInput],devicePrm.speed[motorId]);
+ }
+ }
+ }
+}
+/******************************************************//**
+ * @brief Sets the number of devices to be used
+ * @param[in] nbDevices (from 1 to MAX_NUMBER_OF_DEVICES)
+ * @retval TRUE if successfull, FALSE if failure, attempt to set a number of
+ * devices greater than MAX_NUMBER_OF_DEVICES
+ **********************************************************/
+bool L6206::L6206_SetNbDevices(uint8_t nbDevices)
+{
+ if (nbDevices <= MAX_NUMBER_OF_DEVICES)
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+
+/******************************************************//**
+ * @brief Error handler which calls the user callback (if defined)
+ * @param[in] error Number of the error
+ * @retval None
+ **********************************************************/
+void L6206::L6206_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)
+ * @retval None
+ **********************************************************/
+void L6206::L6206_FlagInterruptHandler(void)
+{
+ bool status;
+
+ status = L6206_GetBridgeStatus(BRIDGE_A);
+ if (status != devicePrm.bridgeEnabled[BRIDGE_A])
+ {
+ devicePrm.bridgeEnabled[BRIDGE_A] = status;
+ }
+
+ status = L6206_GetBridgeStatus(BRIDGE_B);
+ if (status != devicePrm.bridgeEnabled[BRIDGE_B])
+ {
+ devicePrm.bridgeEnabled[BRIDGE_B] = status;
+ }
+
+ if (flagInterruptCallback != 0)
+ {
+ flagInterruptCallback();
+ }
+}
+
+/******************************************************//**
+ * @brief Get the bridges Id used by a given motor
+ * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval bridgeId 0 for bridge A , 1 for bridge B
+ **********************************************************/
+uint8_t L6206::L6206_GetBridgeIdUsedByMotorId(uint8_t motorId)
+{
+ uint8_t bridgeId;
+
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeId = 0;
+ }
+ else
+ {
+ bridgeId = 1;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId < 2)
+ {
+ bridgeId = 0;
+ }
+ else
+ {
+ bridgeId = 1;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
+ case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
+ default:
+ bridgeId = 0;
+ break;
+ }
+ return (bridgeId);
+}
+
+/******************************************************//**
+ * @brief Get the motor Id which is using the specified bridge input
+ * @param bridgeInput 0 for bridgeInput 1A, 1 for 2A, 2 for 1B, 3 for 3B
+ * @retval bridgeId 0 for bridge A , 1 for bridge B
+ **********************************************************/
+uint8_t L6206::L6206_GetMotorIdUsingbridgeInput(uint8_t bridgeInput)
+{
+ uint8_t motorId;
+
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (bridgeInput >= INPUT_1B)
+ {
+ motorId = 1;
+ }
+ else
+ {
+ motorId = 0;
+ }
+ break;
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (bridgeInput == INPUT_2B)
+ {
+ motorId = 2;
+ }
+ else if (bridgeInput == INPUT_1B)
+ {
+ motorId = 1;
+ }
+ else
+ {
+ motorId = 0;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (bridgeInput >= INPUT_1B)
+ {
+ motorId = 2;
+ }
+ else if (bridgeInput == INPUT_2A)
+ {
+ motorId = 1;
+ }
+ else
+ {
+ motorId = 0;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (bridgeInput == INPUT_2B)
+ {
+ motorId = 3;
+ }
+ else if (bridgeInput == INPUT_1B)
+ {
+ motorId = 2;
+ }
+ else if (bridgeInput == INPUT_2A)
+ {
+ motorId = 1;
+ }
+ else
+ {
+ motorId = 0;
+ }
+ break;
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
+ if ((bridgeInput == INPUT_2A) || (bridgeInput == INPUT_2B))
+ {
+ motorId = 1;
+ }
+ else
+ {
+ motorId = 0;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
+ case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
+ default:
+ motorId = 0;
+ break;
+ }
+
+ return (motorId);
+}
+/******************************************************//**
+ * @brief Get the PWM input used by a given motor
+ * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval PWM input 0 for 1A, 1 for 2A, 2 for 1B, 3 for 3B
+ **********************************************************/
+uint8_t L6206::L6206_GetBridgeInputUsedByMotorId(uint8_t motorId)
+{
+ uint8_t bridgeInput;
+
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_2A;
+ }
+ }
+ else
+ {
+ if (devicePrm.direction[1] == FORWARD)
+ {
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_2B;
+ }
+ }
+ break;
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_2A;
+ }
+ }
+ else if (motorId == 1)
+ {
+
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_2B;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else if (motorId == 1)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else
+ {
+ if (devicePrm.direction[2] == FORWARD)
+ {
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_2B;
+ }
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else if (motorId == 1)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else if (motorId == 2)
+ {
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_2B;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ if (devicePrm.direction[1] == FORWARD)
+ {
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_2B;
+ }
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else if (motorId == 1)
+ {
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_2B;
+ }
+ break;
+ case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_2A;
+ }
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ break;
+ case PARALLELING_IN1B_IN2B__2_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else if (motorId == 1)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_UNDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ break;
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_UNDIR_MOTOR_BRIDGE_1A__1_UNDIR_MOTOR_BRIDGE_2A:
+ if (motorId == 0)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_2A;
+ }
+ break;
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_1A;
+ }
+ else
+ {
+ bridgeInput = INPUT_2A;
+ }
+ break;
+ case PARALLELING_ALL_WITH_IN1A___1_UNDIR_MOTOR:
+ default:
+ bridgeInput = INPUT_1A;
+ break;
+ }
+ return (bridgeInput);
+}
+
+/******************************************************//**
+ * @brief Get the second PWM input used by a given bidirectionnal motor
+ * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval PWM input 0 for 1A, 1 for 2A, 2 for 1B, 3 for 3B
+ **********************************************************/
+uint8_t L6206::L6206_GetSecondBridgeInputUsedByMotorId(uint8_t motorId)
+{
+ uint8_t bridgeInput = 0xFF;
+
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1A;
+ }
+ }
+ else
+ {
+ if (devicePrm.direction[1] == FORWARD)
+ {
+ bridgeInput = INPUT_2B;
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ }
+ break;
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1A;
+ }
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 2)
+ {
+ if (devicePrm.direction[2] == FORWARD)
+ {
+ bridgeInput = INPUT_2B;
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ }
+ break;
+
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 1)
+ {
+ if (devicePrm.direction[1] == FORWARD)
+ {
+ bridgeInput = INPUT_2B;
+ }
+ else
+ {
+ bridgeInput = INPUT_1B;
+ }
+ }
+ break;
+
+ case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1A;
+ }
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_1B;
+ }
+ else
+ {
+ bridgeInput = INPUT_1A;
+ }
+ break;
+
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
+ if (devicePrm.direction[0] == FORWARD)
+ {
+ bridgeInput = INPUT_2A;
+ }
+ else
+ {
+ bridgeInput = INPUT_1A;
+ }
+ break;
+ default:
+ bridgeInput = 0XFF;
+ break;
+ }
+ if (bridgeInput == 0XFF)
+ {
+ L6206_ErrorHandler(L6206_ERROR_2);
+ }
+
+ return (bridgeInput);
+}
+
+/******************************************************//**
+ * @brief Test if motor is bidirectionnal
+ * @param motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS
+ * @retval True if motor is bidirectionnal, else false
+ **********************************************************/
+bool L6206::L6206_IsBidirectionnalMotor(uint8_t motorId)
+{
+ bool isBiDir = FALSE;
+
+ switch (devicePrm.config)
+ {
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1A_IN2A__IN1B_IN2B__1_BIDIR_MOTOR:
+ case PARALLELING_IN1A_IN1B__IN2A_IN2B__1_BIDIR_MOTOR:
+ isBiDir = TRUE;
+ break;
+
+ case PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B:
+ case PARALLELING_IN1B_IN2B__1_BIDIR_MOTOR_BRIDGE_A__1_UNDIR_MOTOR_BRIDGE_B:
+ if (motorId == 0)
+ {
+ isBiDir = TRUE;
+ }
+ break;
+ case PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 2)
+ {
+ isBiDir = TRUE;
+ }
+ break;
+ case PARALLELING_IN1A_IN2A__1_UNDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B:
+ if (motorId == 1)
+ {
+ isBiDir = TRUE;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return (isBiDir);
+}
+
+
+/******************************************************//**
+ * @brief Sets the parameters of the device to predefined values
+ * from l6206_target_config.h
+ * @retval None
+ **********************************************************/
+void L6206::L6206_SetDeviceParamsToPredefinedValues(void)
+{
+ uint32_t i;
+
+ memset(&devicePrm, 0, sizeof(devicePrm));
+
+ devicePrm.config = L6206_CONF_PARAM_PARALLE_BRIDGES;
+
+ devicePrm.pwmFreq[INPUT_1A] = L6206_CONF_PARAM_FREQ_PWM1A;
+ devicePrm.pwmFreq[INPUT_2A] = L6206_CONF_PARAM_FREQ_PWM2A;
+ devicePrm.pwmFreq[INPUT_1B] = L6206_CONF_PARAM_FREQ_PWM1B;
+ devicePrm.pwmFreq[INPUT_2B] = L6206_CONF_PARAM_FREQ_PWM2B;
+
+ for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++)
+ {
+ devicePrm.speed[i] = 100;
+ devicePrm.direction[i] = FORWARD;
+ devicePrm.motionState[i] = INACTIVE;
+ }
+ for (i = 0; i < L6206_NB_MAX_BRIDGES; i++)
+ {
+ devicePrm.bridgeEnabled[i] = FALSE;
+ }
+}
+
+
+/******************************************************//**
+ * @brief Set the parameters of the device to values of initDevicePrm structure
+ * Set GPIO according to these values
+ * @param initDevicePrm structure containing values to initialize the device
+ * parameters
+ * @retval None
+ **********************************************************/
+void L6206::L6206_SetDeviceParamsToGivenValues(L6206_Init_t* initDevicePrm)
+{
+ memcpy(&devicePrm, initDevicePrm, sizeof(devicePrm));
+}
+
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6206/l6206_class.h Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,651 @@
+/**
+ ******************************************************************************
+ * @file l6206_class.h
+ * @author IPC Rennes
+ * @version V1.1.0
+ * @date March 02, 2016
+ * @brief L6206 driver (dual full bridge driver)
+ * @note (C) COPYRIGHT 2015 STMicroelectronics
+ ******************************************************************************
+ * @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-SPN4/trunk/Drivers/BSP/Components/l6206/l6206.h
+ Revision: 0
+*/
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __L6206_CLASS_H
+#define __L6206_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here component specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "l6206.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"
+
+
+
+/* Private constants ---------------------------------------------------------*/
+
+/** @defgroup L6206_Private_Constants L6206 Private Constants
+ * @{
+ */
+
+/// The Number of L6206 devices required for initialisation is not supported
+#define L6206_ERROR_0 (0x8000)
+/// Error: Access a motor index greater than the one of the current brigde configuration
+#define L6206_ERROR_1 (0x8001)
+/// Error: Access a motor index which is not bidirectionnal
+#define L6206_ERROR_2 (0x8002)
+
+/// Maximum frequency of the PWMs in Hz
+#define L6206_MAX_PWM_FREQ (100000)
+
+/// Minimum frequency of the PWMs in Hz
+#define L6206_MIN_PWM_FREQ (2)
+
+/// Bridge Input 1A
+#define INPUT_1A (0)
+/// Bridge Input 2A
+#define INPUT_2A (1)
+/// Bridge Input 1B
+#define INPUT_1B (2)
+/// Bridge Input 2B
+#define INPUT_2B (3)
+
+/// Bridge A
+#define BRIDGE_A (0)
+/// Bridge B
+#define BRIDGE_B (1)
+
+
+
+
+
+/* Classes -------------------------------------------------------------------*/
+
+/**
+ * @brief Class representing a L6206 component.
+ */
+class L6206 : public Motor
+{
+public:
+
+ /*** Constructor and Destructor Methods ***/
+
+ /**
+ * @brief Constructor.
+ */
+ L6206(PinName EN_flag_A, PinName EN_flag_B, PinName pwm_1A, PinName pwm_2A, PinName pwm_1B, PinName pwm_2B) : Motor(), flag_A_irq(EN_flag_A), flag_B_irq(EN_flag_B), EN_flag_A(EN_flag_A), EN_flag_B(EN_flag_B), pwm_1A(pwm_1A), pwm_2A(pwm_2A), pwm_1B(pwm_1B), pwm_2B(pwm_2B)
+ {
+ /* ACTION 4 ----------------------------------------------------------*
+ * Initialize here the component's member variables, one variable per *
+ * line. *
+ * *
+ * Example: *
+ * measure = 0; *
+ * instance_id = number_of_instances++; *
+ *--------------------------------------------------------------------*/
+
+ flagInterruptCallback = 0;
+ errorHandlerCallback = 0;
+ numberOfDevices = 0;
+ deviceInstance = 0;
+ }
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~L6206(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 *f) //(1) *
+ * { *
+ * return COMPONENT_GetValue(float *f); *
+ * } *
+ * *
+ * virtual int EnableFeature(void) //(2) *
+ * { *
+ * return COMPONENT_EnableFeature(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ virtual int Init(void *init = NULL)
+ {
+ return (int) L6206_Init((void *) init);
+ }
+
+ virtual int ReadID(uint8_t *id = NULL)
+ {
+ return (int) L6206_ReadId((uint8_t *) id);
+ }
+
+ virtual void AttachErrorHandler(void (*callback)(uint16_t error))
+ {
+ L6206_AttachErrorHandler((void (*)(uint16_t error)) callback);
+ }
+
+ virtual void AttachFlagInterrupt(void (*callback)(void))
+ {
+ L6206_AttachFlagInterrupt((void (*)(void)) callback);
+ }
+
+ virtual uint16_t GetCurrentSpeed(uint8_t motorId)
+ {
+ return (uint16_t) L6206_GetCurrentSpeed((uint8_t) motorId);
+ }
+
+ virtual motorState_t GetDeviceState(uint8_t motorId)
+ {
+ return (motorState_t) L6206_GetDeviceState((uint8_t) motorId);
+ }
+
+ virtual uint8_t GetFwVersion(void)
+ {
+ return (uint8_t) L6206_GetFwVersion();
+ }
+
+ virtual uint16_t GetMaxSpeed(uint8_t motorId)
+ {
+ return (uint16_t) L6206_GetMaxSpeed((uint8_t) motorId);
+ }
+
+ virtual void HardStop(uint8_t motorId)
+ {
+ L6206_HardStop((uint8_t) motorId);
+ }
+
+ virtual void Run(uint8_t stepCount, motorDir_t direction)
+ {
+ L6206_Run((uint8_t) stepCount, (motorDir_t) direction);
+ }
+
+ virtual bool SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed)
+ {
+ return (bool) L6206_SetMaxSpeed((uint8_t) motorId, (uint16_t) newMaxSpeed);
+ }
+
+ virtual void CmdDisable(uint8_t bridgeId)
+ {
+ L6206_DisableBridge((uint8_t) bridgeId);
+ }
+
+ virtual void CmdEnable(uint8_t bridgeId)
+ {
+ L6206_EnableBridge((uint8_t) bridgeId);
+ }
+
+ virtual uint16_t CmdGetStatus(uint8_t bridgeId)
+ {
+ return (uint16_t) L6206_GetBridgeStatus((uint8_t) bridgeId);
+ }
+
+ virtual void CmdHardHiZ(uint8_t motorId)
+ {
+ L6206_HardHiz((uint8_t) motorId);
+ }
+
+ virtual void ErrorHandler(uint16_t error)
+ {
+ L6206_ErrorHandler((uint16_t) error);
+ }
+
+ virtual void SetDualFullBridgeConfig(uint8_t newConfig)
+ {
+ L6206_SetDualFullBridgeConfig((uint8_t) newConfig);
+ }
+
+ virtual uint32_t GetBridgeInputPwmFreq(uint8_t bridgeId)
+ {
+ return (uint32_t) L6206_GetBridgeInputPwmFreq((uint8_t) bridgeId);
+ }
+
+ virtual void SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq)
+ {
+ L6206_SetBridgeInputPwmFreq((uint8_t) bridgeId, (uint32_t) newFreq);
+ }
+
+ virtual bool SetNbDevices(uint8_t nbDevices)
+ {
+ return (bool) L6206_SetNbDevices((uint8_t) nbDevices);
+ }
+
+
+ /*** 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_irq(pin); //Interrupt object. *
+ * feature_irq.fall(callback); //Attach a callback. *
+ * feature_irq.mode(PullNone); //Set interrupt mode. *
+ * feature_irq.enable_irq(); //Enable interrupt. *
+ * feature_irq.disable_irq(); //Disable interrupt. *
+ * + Arduino: *
+ * attachInterrupt(pin, callback, RISING); //Attach a callback. *
+ * detachInterrupt(pin); //Detach a callback. *
+ * *
+ * Example (mbed): *
+ * void AttachFeatureIRQ(void (*fptr) (void)) *
+ * { *
+ * feature_irq.fall(fptr); *
+ * } *
+ * *
+ * void EnableFeatureIRQ(void) *
+ * { *
+ * feature_irq.enable_irq(); *
+ * } *
+ * *
+ * void DisableFeatureIRQ(void) *
+ * { *
+ * feature_irq.disable_irq(); *
+ * } *
+ *------------------------------------------------------------------------*/
+
+
+ /**
+ * @brief Enabling the FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void EnableFlagIRQ(uint8_t bridgeId)
+ {
+ if (bridgeId == BRIDGE_A)
+ {
+ flag_A_irq.mode(PullUp);
+ flag_A_irq.fall(this, &L6206::L6206_FlagInterruptHandler);
+ }
+ else
+ {
+ flag_B_irq.mode(PullUp);
+ flag_B_irq.fall(this, &L6206::L6206_FlagInterruptHandler);
+ }
+ }
+
+ /**
+ * @brief Disabling the FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void DisableFlagIRQ(uint8_t bridgeId)
+ {
+ if (bridgeId == BRIDGE_A)
+ flag_A_irq.fall(NULL);
+ else
+ flag_B_irq.fall(NULL);
+ }
+
+
+ /*** Public In/Out Related Methods ***/
+
+ void OutVal( uint8_t bridgeId, uint8_t val)
+ {
+ if( bridgeId == BRIDGE_A)
+ {
+ EN_flag_A.output();
+ EN_flag_A.mode(PullNone);
+ EN_flag_A.write(val);
+ }
+ else
+ {
+ EN_flag_B.output();
+ EN_flag_B.mode(PullNone);
+ EN_flag_B.write(val);
+ }
+ }
+
+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: *
+ * Status_t COMPONENT_GetValue(float *f); //(1) *
+ * Status_t COMPONENT_EnableFeature(void); //(2) *
+ * Status_t COMPONENT_ComputeAverage(void); //(3) *
+ *------------------------------------------------------------------------*/
+ Status_t L6206_Init(void *init);
+ Status_t L6206_ReadId(uint8_t *id);
+ void L6206_TickHandler(uint8_t deviceId); //Handle the device state machine at each tick timer pulse end
+ void L6206_AttachErrorHandler(void (*callback)(uint16_t error)); //Attach a user callback to the error handler
+ void L6206_AttachFlagInterrupt(void (*callback)(void)); //Attach a user callback to the flag Interrupt
+ void L6206_DisableBridge(uint8_t bridgeId); //Disable the specified bridge
+ void L6206_EnableBridge(uint8_t bridgeId); //Enable the specified bridge
+ uint16_t L6206_GetBridgeStatus(uint8_t deviceId); //Get bridge status
+ uint16_t L6206_GetCurrentSpeed(uint8_t motorId); //Return the current speed in pps
+ motorState_t L6206_GetDeviceState(uint8_t motorId); //Return the device state
+ uint8_t L6206_GetFwVersion(void); //Return the FW version
+ uint16_t L6206_GetMaxSpeed(uint8_t motorId); //Return the max speed in pps
+ void L6206_HardHiz(uint8_t motorId); //Stop the motor and disable the power bridge
+ void L6206_HardStop(uint8_t motorId); //Stop the motor without disabling the power bridge
+ void L6206_Run(uint8_t motorId, motorDir_t direction); //Run the motor
+ uint32_t L6206_GetBridgeInputPwmFreq(uint8_t bridgeId); // Get the PWM frequency of the bridge input
+ void L6206_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq); // Set the PWM frequency of the bridge input
+ void L6206_SetDualFullBridgeConfig(uint8_t newConfig); // Set dual full bridge configuration
+ bool L6206_SetMaxSpeed(uint8_t motorId,uint16_t newMaxSpeed); //Set the max speed in pps
+ bool L6206_SetNbDevices(uint8_t nbDevices); //Set the number of driver devices
+ void L6206_ErrorHandler(uint16_t error);
+ void L6206_FlagInterruptHandler(void);
+ uint8_t L6206_GetBridgeIdUsedByMotorId(uint8_t motorId);
+ uint8_t L6206_GetBridgeInputUsedByMotorId(uint8_t motorId);
+ uint8_t L6206_GetMotorIdUsingbridgeInput(uint8_t bridgeInput);
+ uint8_t L6206_GetSecondBridgeInputUsedByMotorId(uint8_t motorId);
+ bool L6206_IsBidirectionnalMotor(uint8_t motorId);
+ void L6206_SetDeviceParamsToPredefinedValues(void);
+ void L6206_SetDeviceParamsToGivenValues(L6206_Init_t* initDevicePrm);
+
+ /*** Component's I/O Methods ***/
+
+ /* ACTION 8 --------------------------------------------------------------*
+ * Implement here other I/O methods beyond those already implemented *
+ * above, which are declared extern within the component's header file. *
+ *------------------------------------------------------------------------*/
+ void L6206_Board_Delay(uint32_t delay)
+ {
+ wait_ms(delay);
+ }
+
+ void L6206_Board_DisableBridge(uint8_t bridgeId)
+ {
+ DisableFlagIRQ(BRIDGE_A);
+ DisableFlagIRQ(BRIDGE_B);
+
+ __disable_irq();
+ OutVal( bridgeId, 0);
+ __enable_irq();
+ }
+
+ void L6206_Board_EnableBridge(uint8_t bridgeId, uint8_t addDelay)
+ {
+ OutVal( bridgeId, 1);
+
+ if (addDelay != 0)
+ {
+ wait_ms(BSP_MOTOR_CONTROL_BOARD_BRIDGE_TURN_ON_DELAY);
+ }
+
+ EnableFlagIRQ( bridgeId);
+ }
+
+
+ uint32_t L6206_Board_GetFlagPinState(uint8_t bridgeId)
+ {
+ if (bridgeId == 0)
+ {
+ EN_flag_A.input();
+ return EN_flag_A.read();
+ }
+ else
+ {
+ EN_flag_B.input();
+ return EN_flag_B.read();
+ }
+ }
+
+ void L6206_Board_GpioInit(void)
+ {
+ /* Init bridge Enable */
+ EN_flag_A.output();
+ EN_flag_A.write(0);
+ EN_flag_A.input();
+
+ EN_flag_B.output();
+ EN_flag_B.write(0);
+ EN_flag_B.input();
+
+
+ /* Init flag Irq */
+ DisableFlagIRQ(BRIDGE_A);
+ DisableFlagIRQ(BRIDGE_B);
+
+ }
+
+ /** Board PWM management **/
+
+ void L6206_Board_PwmSetFreq(uint8_t bridgeInput, uint32_t newFreq, uint8_t duty)
+ {
+ /* Computing the period of PWM. */
+ float period = 1.0f / newFreq;
+ float duty_cycle;
+ int period_us = (int)(period * 1E6);
+
+ if (duty > 100) duty = 100;
+ duty_cycle = (float)duty / 100.0f;
+
+ switch (bridgeInput)
+ {
+ case 0:
+ default:
+ /* Setting the period and the duty-cycle of PWM. */
+ pwm_1A.period_us(period_us);
+ pwm_1A.write(duty_cycle);
+ break;
+
+ case 1:
+ /* Setting the period and the duty-cycle of PWM. */
+ pwm_2A.period_us(period_us);
+ pwm_2A.write(duty_cycle);
+ break;
+
+ case 2:
+ /* Setting the period and the duty-cycle of PWM. */
+ pwm_1B.period_us(period_us);
+ pwm_1B.write(duty_cycle);
+ break;
+
+ case 3:
+ /* Setting the period and the duty-cycle of PWM. */
+ pwm_2B.period_us(period_us);
+ pwm_2B.write(duty_cycle);
+ break;
+ }
+ }
+
+ void L6206_Board_PwmDeInit(uint8_t bridgeInput)
+ {
+ switch (bridgeInput)
+ {
+ case 0:
+ default:
+ //timer_pwm_1A.detach();
+ break;
+
+ case 1:
+ //timer_pwm_2A.detach();
+ break;
+
+ case 2:
+ //timer_pwm_1B.detach();
+ break;
+
+ case 3:
+ //timer_pwm_2B.detach();
+ break;
+ }
+ }
+
+ void L6206_Board_PwmInit(uint8_t bridgeInput)
+ {
+ }
+
+ void L6206_Board_PwmStop(uint8_t bridgeInput)
+ {
+ switch (bridgeInput)
+ {
+ case 0:
+ default:
+ pwm_1A.write(0.0);
+ break;
+
+ case 1:
+ pwm_2A.write(0.0);
+ break;
+
+ case 2:
+ pwm_1B.write(0.0);
+ break;
+
+ case 3:
+ pwm_2B.write(0.0);
+ break;
+ }
+ }
+
+
+ /*** Component's Instance Variables ***/
+
+ /* ACTION 9 --------------------------------------------------------------*
+ * Declare here interrupt related variables, if needed. *
+ * Note that interrupt handling is platform dependent, see *
+ * "Interrupt Related Methods" above. *
+ * *
+ * Example: *
+ * + mbed: *
+ * InterruptIn feature_irq; *
+ *------------------------------------------------------------------------*/
+
+ /* Flag Interrupt. */
+ InterruptIn flag_A_irq;
+ InterruptIn flag_B_irq;
+
+ /* ACTION 10 -------------------------------------------------------------*
+ * Declare here other pin related variables, if needed. *
+ * *
+ * Example: *
+ * + mbed: *
+ * DigitalOut standby_reset; *
+ *------------------------------------------------------------------------*/
+
+ /* Digital In/Out for Flag EN pin */
+ DigitalInOut EN_flag_A;
+ DigitalInOut EN_flag_B;
+
+ /* PWM Out pin */
+ PwmOut pwm_1A;
+ PwmOut pwm_2A;
+ PwmOut pwm_1B;
+ PwmOut pwm_2B;
+
+ /* ACTION 11 -------------------------------------------------------------*
+ * Declare here communication related variables, if needed. *
+ * *
+ * Example: *
+ * + mbed: *
+ * DigitalOut address; *
+ * DevI2C &dev_i2c; *
+ *------------------------------------------------------------------------*/
+
+ /* ACTION 12 -------------------------------------------------------------*
+ * Declare here identity related variables, if needed. *
+ * Note that there should be only a unique identifier for each component, *
+ * which should be the "who_am_i" parameter. *
+ *------------------------------------------------------------------------*/
+ /* Identity */
+ uint8_t who_am_i;
+
+ /* ACTION 13 -------------------------------------------------------------*
+ * Declare here the component's static and non-static data, one variable *
+ * per line. *
+ * *
+ * Example: *
+ * float measure; *
+ * int instance_id; *
+ * static int number_of_instances; *
+ *------------------------------------------------------------------------*/
+ void (*flagInterruptCallback)(void);
+
+ void (*errorHandlerCallback)(uint16_t error);
+
+ uint8_t numberOfDevices;
+
+ uint8_t deviceInstance;
+
+ deviceParams_t devicePrm;
+
+
+ /** PWM timer variables */
+
+ bool pwm_1A_activated;
+ bool pwm_2A_activated;
+ bool pwm_1B_activated;
+ bool pwm_2B_activated;
+};
+
+#endif /* __L6206_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/l6206/l6206_target_config.h Tue May 03 11:16:57 2016 +0000
@@ -0,0 +1,104 @@
+/**************************************************************************//**
+ * @file L6206_target_config.h
+ * @author IPC Rennes
+ * @version V1.0.0
+ * @date January 06, 2015
+ * @brief Predefines values for the L6206 parameters
+ * and for the devices parameters
+ * @note (C) COPYRIGHT 2015 STMicroelectronics
+ ******************************************************************************
+ * @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 recursive inclusion -------------------------------------*/
+#ifndef __L6206_TARGET_CONFIG_H
+#define __L6206_TARGET_CONFIG_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup L6474
+ * @{
+ */
+
+/** @addtogroup L6206_Exported_Constants
+ * @{
+ */
+
+/** @defgroup Predefined_L6206_Parameters_Values Predefined L6206 Parameters Values
+ * @{
+ */
+
+/// The maximum number of L6206 devices
+#define MAX_NUMBER_OF_DEVICES (1)
+
+/// The maximum number of BLDC motors connected to the L6206
+#define MAX_NUMBER_OF_BRUSH_DC_MOTORS (4)
+
+/// Frequency of PWM of Input 1 Bridge A in Hz up to 100000Hz
+#define L6206_CONF_PARAM_FREQ_PWM1A (20000)
+/// Frequency of PWM of Input 2 Bridge A in Hz up to 100000Hz
+/// ON IHM04A1, must be identical to L6206_CONF_PARAM_FREQ_PWM1A as used timer is the same
+#define L6206_CONF_PARAM_FREQ_PWM2A (20000)
+/// Frequency of PWM of Input 1 Bridge B in Hz up to 100000Hz
+#define L6206_CONF_PARAM_FREQ_PWM1B (20000)
+/// Frequency of PWM of Input 2 Bridge B in Hz up to 100000Hz
+/// On IHM04A1, must be identical to L6206_CONF_PARAM_FREQ_PWM2B as used timer is the same
+#define L6206_CONF_PARAM_FREQ_PWM2B (20000)
+
+/// Frequency of PWM of Input 2 Bridge B (in kHz)
+#define L6206_CONF_PARAM_PARALLE_BRIDGES (PARALLELING_NONE___1_BIDIR_MOTOR_BRIDGE_A__1_BIDIR_MOTOR_BRIDGE_B)
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* __L6206_TARGET_CONFIG_H */
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_COMMON.lib Tue May 03 11:16:57 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#216930edb6b7
