Library used to control ST Nucleo Evaluation board IHM12A1, based on STSPIN240 low voltage dual brush DC motor control driver.
Dependencies: ST_INTERFACES
Dependents: motori prova_motore SchedamotoriIHM12A1 prova_motore_duck ... more
Fork of X-NUCLEO-IHM12A1 by
Brush DC Motor Control Library
Library to handle the X-NUCLEO-IHM12A1 Motor Control Expansion Board based on the STSPIN240 component.
It allows a complete management of the STSPIN240, a low voltage dual brush DC driver, by providing a complete APIs.
The key features of the library are :
- Configuration of the STSPIN240 (bridges input and enabling signals)
- Flag interrupt handling (overcurrent and thermal alarms reporting)
- Handling of up to two bidirectional Brush DC motors
- Nucleo and expansion board configuration (GPIOs, PWMs, IRQs…)
To use the STSPIN240 driver library, the user first has to call its initialization method which:
- Setups the required GPIOs to handle the bridges enable pins, the FLAG interrupt which reports overcurrent detection or thermal protection.
- Loads the driver parameters with initial values configured by the user or with their predefined values from “stspin240_250_target_config.h”, in order to program the PWMs frequency of the bridges inputs, the number of brush DC motors.
Once the initialization is done, the user can modify the driver parameters by calling specific functions to change the numbers of motors or the PWMs frequency.
The user can also write callback functions and attach them to:
- The flag interrupt handler depending on the actions he wants to perform when an overcurrent or a thermal alarm is reported.
- The Error handler which is called by the library when it reports an error.
Then, the user can drive the different brush DC motors by requesting to run in a specified direction and by changing the maximal speed. When a motor is requested to run, the corresponding bridge is automatically enabled.
A motion command can be stopped at any moment:
- Either by a hard stop which immediately stops the motor.
- Or by a hardHiz command which immediately stops the motor and disables the bridge which is used by the motor.
The library also provides functions to disable or enable the bridges independently from the run or stop commands.
Arduino Connector Compatibility Warning
Using the X-NUCLEO-IHM12A1 expansion board with the NUCLEO-F429ZI requires adopting the following patch:
- to connect with a wire the
PB_3Nucleo pin to thePWMBexpansion board pin.
Board configuration for HelloWorld_IHM12A1 example
Revision 0:13bc901c90aa, committed 2016-04-28
- Comitter:
- Manu_L
- Date:
- Thu Apr 28 14:03:11 2016 +0000
- Child:
- 1:a68f20f0d233
- Commit message:
- X-NUCLEO-IHM12A1 (STSPIN240) Library creation
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Common/component.h Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,93 @@
+/**
+ ******************************************************************************
+ * @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 Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,446 @@
+/**
+ ******************************************************************************
+ * @file motor.h
+ * @author IPC Rennes
+ * @version V1.6.0
+ * @date April 7th, 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"
+
+/* Definitions ---------------------------------------------------------------*/
+/// boolean for false condition
+#ifndef FALSE
+#define FALSE (0)
+#endif
+/// boolean for true condition
+#ifndef TRUE
+#define TRUE (1)
+#endif
+
+/* Types ---------------------------------------------------------------------*/
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @defgroup Motor Motor
+ * @{
+ */
+
+/** @defgroup Motor_Exported_Types Motor Exported Types
+ * @{
+ */
+
+/** @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
+ * @{
+ */
+/**
+ * @brief MOTOR driver virtual table structure definition.
+ */
+typedef struct
+{
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here the component's generic functions. *
+ * Tag this group of functions with the " Generic " C-style comment. *
+ * A component's interface has to define at least the two generic *
+ * functions provided here below within the "Example" section, as the *
+ * first and second functions of its Virtual Table. They have to be *
+ * specified exactly in the given way. *
+ * *
+ * Example: *
+ * Status_t (*Init) (void *handle, void *init); *
+ * Status_t (*ReadID) (void *handle, uint8_t *id); *
+ *------------------------------------------------------------------------*/
+ /* Generic */
+ Status_t (*Init)(void *handle, void *init);
+ Status_t (*ReadID)(void *handle, uint8_t *id);
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here the component's interrupts related functions. *
+ * Tag this group of functions with the " Interrupts " C-style comment. *
+ * Do not specify any function if not required. *
+ * *
+ * Example: *
+ * void (*ConfigIT) (void *handle, int a); *
+ *------------------------------------------------------------------------*/
+ /* 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);
+ /* ACTION ----------------------------------------------------------------*
+ * Declare here the component's specific functions. *
+ * Tag this group of functions with the " Specific " C-style comment. *
+ * Do not specify any function if not required. *
+ * *
+ * Example: *
+ * Status_t (*GetValue) (void *handle, float *f); *
+ *------------------------------------------------------------------------*/
+ /* Specific */
+ /// 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
+ uint32_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 WaitWhileActive
+ void (*WaitWhileActive)(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
+ bool (*SelectStepMode)(void *handle, motorStepMode_t);
+ /// 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 command, 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, uint16_t newFreq);
+ /// Function pointer to StopStepClock
+ void (*StopStepClock)(void *handle);
+ /// Function pointer to SetDualFullBridgeConfig
+ void (*SetDualFullBridgeConfig)(void *handle, uint8_t config);
+ /// Function pointer to GetBridgeInputPwmFreq
+ uint32_t (*GetBridgeInputPwmFreq)(void *handle);
+ /// Function pointer to SetBridgeInputPwmFreq
+ void (*SetBridgeInputPwmFreq)(void *handle, 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 newFreq);
+ /// Function pointer to GetVRefFreq
+ uint32_t (*GetRefFreq)(void *handle);
+ /// Function pointer to SetVRefDc
+ void (*SetRefDc)(void *handle, uint8_t newDc);
+ /// 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/BDCMotor_class.h Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,190 @@
+/**
+ ******************************************************************************
+ * @file BCDMotor_class.h
+ * @author IPC Rennes
+ * @version V1.0.0
+ * @date April 6th, 2016
+ * @brief This file contains the abstract class describing the interface of a
+ * Brush DC motor component.
+ ******************************************************************************
+ * @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 from recursive inclusion --------------------------------*/
+
+#ifndef __BCDMMOTOR_CLASS_H
+#define __BCDMMOTOR_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include <Component_class.h>
+
+
+/* Classes ------------------------------------------------------------------*/
+
+/** An abstract class for BDCMotor components.
+ */
+class BDCMotor : public Component
+{
+public:
+ /**
+ * @brief Rotation modes.
+ */
+ typedef enum
+ {
+ BWD = 0, /* Backward. */
+ FWD = 1 /* Forward. */
+ } direction_t;
+
+ /**
+ * @brief Disabling the specified bridge.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @retval None.
+ */
+ virtual void DisableBridge(unsigned int) = 0;
+
+ /**
+ * @brief Enabling the specified bridge.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B
+ * @retval None.
+ */
+ virtual void EnableBridge(unsigned int) = 0;
+
+ /**
+ * @brief Getting the PWM frequency of the specified bridge;
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @retval The frequency in Hz of the specified bridge input PWM.
+ */
+ virtual unsigned int GetBridgeInputPwmFreq(unsigned int) = 0;
+
+ /**
+ * @brief Getting the bridge status.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @retval The status.
+ */
+ virtual unsigned int GetBridgeStatus(unsigned int) = 0;
+
+ /**
+ * @brief Getting the device State.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval The device state
+ */
+ virtual motorState_t GetDeviceState(unsigned int) = 0;
+
+ /**
+ * @brief Getting the duty cycle of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @retval duty cycle in % (from 0 to 100)
+ */
+ virtual unsigned int GetRefPwmDc(unsigned int) = 0;
+
+ /**
+ * @brief Getting the frequency of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @retval frequency in Hz.
+ */
+ virtual unsigned int GetRefPwmFreq(unsigned int) = 0;
+
+ /**
+ * @brief Getting the current speed in % of the specified motor.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval The current speed in %.
+ */
+ virtual unsigned int GetSpeed(unsigned int) = 0;
+
+ /**
+ * @brief Stopping the motor and disabling the power bridge immediately.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval None.
+ */
+ virtual void HardHiZ(unsigned int) = 0;
+
+ /**
+ * @brief Stopping the motor immediately.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval None.
+ */
+ virtual void HardStop(unsigned int) = 0;
+
+ /**
+ * @brief Running the motor.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @param direction The direction of rotation.
+ * @retval None.
+ */
+ virtual void Run(unsigned int, direction_t) = 0;
+
+ /**
+ * @brief Setting the PWM frequency of the specified bridge.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @param frequency of the PWM in Hz
+ * @retval None.
+ */
+ virtual void SetBridgeInputPwmFreq(unsigned int, unsigned int) = 0;
+
+ /**
+ * @brief Setting the dual bridge configuration mode.
+ * @param configuration. The bridge configuration.
+ * @retval None.
+ */
+ virtual void SetDualFullBridgeconfig(unsigned int) = 0;
+
+
+ /**
+ * @brief Setting the duty cycle of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @param newDc new duty cycle from 0 to 100
+ * @retval None.
+ */
+ virtual void SetRefPwmDc(unsigned int, unsigned int) = 0;
+
+ /**
+ * @brief Setting the frequency of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @param frequency in Hz.
+ * @retval None.
+ */
+ virtual void SetRefPwmFreq(unsigned int, unsigned int) = 0;
+
+ /**
+ * @brief Setting the speed in %.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @param speed The new speed in %.
+ * @retval "true" in case of success, "false" otherwise.
+ */
+ virtual bool SetSpeed(unsigned int, unsigned int) = 0;
+
+
+};
+
+#endif /* __BCDMMOTOR_CLASS_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Interfaces/Component_class.h Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,75 @@
+/**
+ ******************************************************************************
+ * @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/stspin240_250/stspin240_250.h Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,243 @@
+/**
+ ******************************************************************************
+ * @file stspin240_250.h
+ * @author IPC Rennes
+ * @version V1.0.0
+ * @date February 10, 2016
+ * @brief Header for Stspin240 (low voltage dual brush DC motor driver) and
+ * Stspin250 driver (low voltage brush DC motor driver)
+ * @note (C) COPYRIGHT 2016 STMicroelectronics
+ ******************************************************************************
+ * @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 __STSPIN240_250_H
+#define __STSPIN240_250_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stspin240_250_target_config.h"
+#include "motor.h"
+
+/* Definitions ---------------------------------------------------------------*/
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @defgroup STSPIN240_250 STSPIN240_250
+ * @{
+ */
+
+/** @defgroup STSPIN240_250_Exported_Defines STSPIN240_250 Exported Defines
+ * @{
+ */
+
+/// Current FW version
+
+/// Current FW major version
+#define STSPIN240_250_FW_MAJOR_VERSION (uint8_t)(1)
+/// Current FW minor version
+#define STSPIN240_250_FW_MINOR_VERSION (uint8_t)(0)
+/// Current FW patch version
+#define STSPIN240_250_FW_PATCH_VERSION (uint8_t)(0)
+/// Current FW version
+#define STSPIN240_250_FW_VERSION (uint32_t)((STSPIN240_250_FW_MAJOR_VERSION<<16)|\
+ (STSPIN240_250_FW_MINOR_VERSION<<8)|\
+ (STSPIN240_250_FW_PATCH_VERSION))
+
+///Max number of Brush DC motors
+#define STSPIN240_250_NB_MAX_MOTORS (2)
+///Number of Bridges
+#define STSPIN240_250_NB_BRIDGES (2)
+
+ /**
+ * @}
+ */
+
+/* Types ---------------------------------------------------------------------*/
+
+/** @defgroup STSPIN240_250_Exported_Types STSPIN240_250 Exported Types
+ * @{
+ */
+
+
+/** @defgroup Device_Parameters Device Parameters
+ * @{
+ */
+
+/// Device Parameters Structure Type
+typedef struct {
+ /// Pwm frequency of the bridge input
+ uint32_t bridgePwmFreq[STSPIN240_250_NB_BRIDGES];
+ /// Pwm frequency of the ref pin
+ uint32_t refPwmFreq;
+ /// Pwm Duty Cycle of the ref pin
+ uint8_t refPwmDc;
+ /// Speed% (from 0 to 100) of the corresponding motor
+ uint16_t speed[STSPIN240_250_NB_MAX_MOTORS];
+ /// FORWARD or BACKWARD direction of the motors
+ motorDir_t direction[STSPIN240_250_NB_MAX_MOTORS];
+ /// Current State of the motors
+ motorState_t motionState[STSPIN240_250_NB_MAX_MOTORS];
+ /// Current State of the bridges
+ bool bridgeEnabled[STSPIN240_250_NB_BRIDGES];
+ /// Enabling of a dual bridge configuration
+ bool dualBridgeEnabled;
+}deviceParams_t;
+
+/**
+ * @}
+ */
+
+
+
+/** @defgroup Stspin240_250_Initialization_Structure Stspin240_250 Initialization Structure
+ * @{
+ */
+/* ACTION --------------------------------------------------------------------*
+ * Declare here the component's initialization structure, if any, one *
+ * variable per line without initialization. *
+ * *
+ * Example: *
+ * typedef struct *
+ * { *
+ * int frequency; *
+ * int update_mode; *
+ * } COMPONENT_Init_t; *
+ *----------------------------------------------------------------------------*/
+typedef struct {
+ /* Frequency of the bridge PWMs in Hz up to 100000Hz */
+ uint32_t bridgePwmFreq[STSPIN240_250_NB_BRIDGES];
+ /* Frequency of the PWM used for Ref pin in Hz up to 100000Hz */
+ uint32_t refPwmFreq;
+ /* Duty cycle of the PWM used for Ref pin in % (0..100) */
+ uint8_t refPwmDc;
+ /* Dual Bridge configuration (0 for mono, 1 for dual brush dc (STSPIN240 only) */
+ bool dualBridgeEnabled;
+} Stspin240_250_Init_t;
+
+/**
+ * @}
+ */
+
+/**
+ * @brief Powerstep01 driver data structure definition.
+ */
+/* 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; *
+ *----------------------------------------------------------------------------*/
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/* Functions -----------------------------------------------------------------*/
+
+
+/** @defgroup STSPIN240_250_Board_Linked_Functions STSPIN240_250 Board Linked Functions
+ * @{
+ */
+
+/* ACTION --------------------------------------------------------------------*
+ * Declare here extern platform-dependent APIs you might need (e.g.: I/O and *
+ * interrupt related functions), and implement them in a glue-logic file on *
+ * the target environment, for example within the "x_nucleo_board.c" file. *
+ * E.g.: *
+ * extern Status_t COMPONENT_IO_Init (void *handle); *
+ * extern Status_t COMPONENT_IO_Read (handle, buf, regadd, bytes); *
+ * extern Status_t COMPONENT_IO_Write(handle, buf, regadd, bytes); *
+ * extern void COMPONENT_IO_ITConfig(void); *
+ *----------------------------------------------------------------------------*/
+
+///Delay of the requested number of milliseconds
+extern void Stspin240_250_Board_Delay(void *handle, uint32_t delay);
+///Disable the bridges
+extern void Stspin240_250_Board_DisableBridge(void *handle);
+///Enable the specified bridge
+extern void Stspin240_250_Board_EnableBridge(void *handle, uint8_t addDelay);
+//Get the status of the flag and enable Pin
+extern uint8_t Stspin240_250_Board_GetFaultPinState(void *handle);
+//Get the status of the reset Pin
+extern uint8_t Stspin240_250_Board_GetResetPinState(void *handle);
+///Set Briges Inputs PWM frequency and start it
+extern void Stspin240_250_Board_PwmSetFreq(void *handle, uint8_t pwmId, uint32_t newFreq, uint8_t duty);
+///Deinitialise the PWM of the specified bridge input
+extern void Stspin240_250_Board_PwmDeInit(void *handle, uint8_t pwmId);
+///Init the PWM of the specified bridge input
+extern void Stspin240_250_Board_PwmInit(void *handle, uint8_t pwmId, uint8_t onlyChannel);
+///Stop the PWM of the specified brigde input
+extern void Stspin240_250_Board_PwmStop(void *handle, uint8_t pwmId);
+///Release the reset pin of the Stspin240 or Stspin250
+extern void Stspin240_250_Board_ReleaseReset(void *handle, uint8_t deviceId);
+///Reset the Stspin240 or Stspin250
+extern void Stspin240_250_Board_Reset(void *handle, uint8_t deviceId);
+///Set direction of the specified bridge
+extern void Stspin240_250_Board_SetDirectionGpio(void *handle, uint8_t bridgeId, uint8_t gpioState);
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* #ifndef __STSPIN240_250_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/stspin240_250/stspin240_250_class.cpp Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,664 @@
+/**
+ ******************************************************************************
+ * @file stspin240_250_class.cpp
+ * @author IPC Rennes
+ * @version V1.0.0
+ * @date April 25th, 2016
+ * @brief Stspin240 motor driver (Dual brush DC motors)
+ * @note (C) COPYRIGHT 2016 STMicroelectronics
+ ******************************************************************************
+ * @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.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stspin240_250_class.h"
+
+/* Definitions ---------------------------------------------------------------*/
+
+/* Error: Access a motor index greater than the one of the current brigde configuration */
+#define STSPIN240_250_ERROR_1 (0xC001)
+/* Error: Use of a bridgeId greater than BRIDGE_B */
+#define STSPIN240_250_ERROR_2 (0xC002)
+
+/* Maximum frequency of the PWMs in Hz */
+#define STSPIN240_250_MAX_PWM_FREQ (100000)
+
+/* Minimum frequency of the PWMs in Hz */
+#define STSPIN240_250_MIN_PWM_FREQ (2)
+
+/* Bridge A */
+#define BRIDGE_A (0)
+
+/* Bridge B */
+#define BRIDGE_B (1)
+
+/* PWM id for PWM_A */
+#define PWM_A (0)
+
+/* PWM id for PWM_B */
+#define PWM_B (1)
+
+/* PWM id for PWM_REF */
+#define PWM_REF (2)
+
+/* Variables ----------------------------------------------------------------*/
+
+/* Number of devices. */
+uint8_t STSPIN240_250::numberOfDevices = 0;
+uint8_t STSPIN240_250::arrayNbMaxMotorsByConfig[2] = {1,2};
+/* Methods -------------------------------------------------------------------*/
+
+/**********************************************************
+ * @brief Starts the STSPIN240_250 library
+ * @param[in] pInit pointer to the initialization data
+ * @retval COMPONENT_OK in case of success.
+ **********************************************************/
+Status_t STSPIN240_250::Stspin240_250_Init(void* pInit)
+{
+ /* Standby-reset deactivation */
+ Stspin240_250_Board_ReleaseReset();
+
+ /* Let a delay after reset */
+ Stspin240_250_Board_Delay(1);
+
+ if (pInit == 0)
+ {
+ // Set all registers to their predefined values
+ // from powerstep01_target_config.h
+ Stspin240_250_SetDeviceParamsToPredefinedValues();
+ }
+ else
+ {
+ Stspin240_250_SetDeviceParamsToGivenValues((Stspin240_250_Init_t *)pInit);
+ }
+
+ /* Initialise input PWM of bridges*/
+ Stspin240_250_SetDualFullBridgeconfig(device_prm.dualBridgeEnabled);
+
+ return COMPONENT_OK;
+}
+
+/**********************************************************
+ * @brief Read id
+ * @param[in] id pointer to the identifier to be read.
+ * @retval COMPONENT_OK in case of success.
+ **********************************************************/
+Status_t STSPIN240_250::Stspin240_250_ReadId(uint8_t *id)
+{
+ *id = deviceInstance;
+
+ return COMPONENT_OK;
+}
+
+/**********************************************************
+ * @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 STSPIN240_250::Stspin240_250_AttachErrorHandler(void (*callback)(uint16_t error))
+{
+ errorHandlerCallback = (void (*)(uint16_t error)) callback;
+}
+
+
+/******************************************************//**
+ * @brief Disable the specified bridge
+ * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
+ * @retval None
+ * @note Bridge A and bridge B share the same enable pin.
+ * When bridge A is disabled, bridge B is disabled and
+ * reversely
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_DisableBridge(uint8_t bridgeId)
+{
+ Stspin240_250_Board_DisableBridge();
+ device_prm.bridgeEnabled[BRIDGE_A] = FALSE;
+ device_prm.bridgeEnabled[BRIDGE_B] = FALSE;
+}
+
+/******************************************************//**
+ * @brief Enable the specified bridge
+ * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
+ * @retval None
+ * @note Bridge A and bridge B share the same enable pin.
+ * When bridge A is enabled, bridge B is enabled and
+ * reversely
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_EnableBridge(uint8_t bridgeId)
+{
+ device_prm.bridgeEnabled[BRIDGE_A] = TRUE;
+ device_prm.bridgeEnabled[BRIDGE_B] = TRUE;
+ Stspin240_250_Board_EnableBridge(1);
+}
+
+/**********************************************************
+ * @brief Error handler which calls the user callback (if defined)
+ * @param[in] error Number of the error
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_ErrorHandler(uint16_t error)
+{
+ if (errorHandlerCallback != 0)
+ {
+ (void) errorHandlerCallback(error);
+ }
+ else
+ {
+ /* Aborting the program. */
+ exit(EXIT_FAILURE);
+ }
+}
+
+/******************************************************//**
+ * @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 STSPIN240_250::Stspin240_250_GetBridgeInputPwmFreq(uint8_t bridgeId)
+{
+ if (bridgeId > BRIDGE_B)
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_2);
+ }
+
+ return (device_prm.bridgePwmFreq[(bridgeId << 1)]);
+}
+
+/******************************************************//**
+ * @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&Fault pin (shared for bridge A and B)
+ **********************************************************/
+uint16_t STSPIN240_250::Stspin240_250_GetBridgeStatus(void)
+{
+ uint16_t status = Stspin240_250_Board_GetFaultPinState();
+
+ return (status);
+}
+
+/******************************************************//**
+ * @brief Returns the current speed of the specified motor
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @retval current speed in % from 0 to 100
+ **********************************************************/
+uint16_t STSPIN240_250::Stspin240_250_GetCurrentSpeed(uint8_t motorId)
+{
+ uint16_t speed = 0;
+
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else if (device_prm.motionState[motorId] != INACTIVE)
+ {
+ speed = device_prm.speed[motorId];
+ }
+ return (speed);
+}
+
+/******************************************************//**
+ * @brief Returns the device state
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @retval State (STEADY or INACTIVE)
+ **********************************************************/
+motorState_t STSPIN240_250::Stspin240_250_GetDeviceState(uint8_t motorId)
+{
+ motorState_t state = INACTIVE;
+
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else
+ {
+ state = device_prm.motionState[motorId];
+ }
+ return (state);
+}
+
+/******************************************************//**
+ * @brief Get the motor current direction
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @retval direction
+ **********************************************************/
+motorDir_t STSPIN240_250::Stspin240_250_GetDirection(uint8_t motorId)
+{
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+
+ return device_prm.direction[motorId];
+}
+
+/******************************************************//**
+ * @brief Returns the FW version of the library
+ * @retval STSPIN240_250_FW_VERSION
+ **********************************************************/
+uint32_t STSPIN240_250::Stspin240_250_GetFwVersion(void)
+{
+ return (STSPIN240_250_FW_VERSION);
+}
+
+
+/******************************************************//**
+ * @brief Return the duty cycle of PWM used for REF
+ * @param[in] refId 0 is the only supported id for Stspin240 or
+ * Stspin250
+ * @retval duty cycle in % (from 0 to 100)
+ **********************************************************/
+uint8_t STSPIN240_250::Stspin240_250_GetRefPwmDc(uint8_t refId)
+{
+ uint32_t duty = 0;
+
+ if (duty == 0)
+ {
+ duty = device_prm.refPwmDc;
+ }
+ return (duty);
+}
+
+/******************************************************//**
+ * @brief Return the frequency of PWM used for REF
+ * @param[in] refId 0 is the only supported id for Stspin240 or
+ * Stspin250
+ * @retval Frequency in Hz
+ **********************************************************/
+uint32_t STSPIN240_250::Stspin240_250_GetRefPwmFreq(uint8_t refId)
+{
+ uint32_t freq = 0;
+
+ if (refId == 0)
+ {
+ freq = device_prm.refPwmFreq;
+ }
+ return (freq);
+}
+
+/******************************************************//**
+ * @brief Immediatly stops the motor and disable the power bridge
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @retval None
+ * @note As all motors uses the same power bridge, the
+ * power bridge will be disable only if all motors are
+ * stopped
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_HardHiz(uint8_t motorId)
+{
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else
+ {
+ if (device_prm.bridgeEnabled[motorId] != FALSE)
+ {
+ /* Only disable bridges if dual bridge mode is disabled or */
+ /* if all motors are inactive as there are sharing the same power stage */
+ if ((device_prm.dualBridgeEnabled == 0)||
+ ((motorId == 0)&&(device_prm.motionState[1] == INACTIVE))||
+ ((motorId == 1)&&(device_prm.motionState[0] == INACTIVE)))
+ {
+ /* Disable the bridge */
+ Stspin240_250_DisableBridge(motorId);
+ }
+ }
+ /* Disable the PWM */
+ Stspin240_250_HardStop(motorId);
+ }
+}
+
+/******************************************************//**
+ * @brief Stops the motor without disabling the bridge
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @retval none
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_HardStop(uint8_t motorId)
+{
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else if (device_prm.motionState[motorId] != INACTIVE)
+ {
+ /* Disable corresponding PWM */
+ Stspin240_250_Board_PwmStop(motorId);
+
+ /* Set inactive state */
+ device_prm.motionState[motorId] = INACTIVE;
+ }
+}
+
+/******************************************************//**
+ * @brief Release reset (exit standby mode)
+ * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1)
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_ReleaseReset(void)
+{
+ Stspin240_250_Board_ReleaseReset();
+
+ /* Start PWM used for REF pin */
+ Stspin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc);
+}
+
+/******************************************************//**
+ * @brief Reset (enter standby mode)
+ * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1)
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_Reset(void)
+{
+ uint8_t loop;
+ for (loop = 0; loop < STSPIN240_250_NB_MAX_MOTORS; loop++)
+ {
+ /* Stop motor if needed*/
+ if (device_prm.motionState[loop] != INACTIVE)
+ {
+ Stspin240_250_HardStop(loop);
+ }
+ /* Disable bridge if needed */
+ if (device_prm.bridgeEnabled[loop] != FALSE)
+ {
+ Stspin240_250_DisableBridge(loop);
+ }
+ }
+
+ /* Stop PWM used for REF pin */
+ Stspin240_250_Board_PwmStop(PWM_REF);
+
+ /* Reset the STBY/RESET pin */
+ Stspin240_250_Board_Reset();
+}
+
+/******************************************************//**
+ * @brief Runs the motor
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @param[in] direction FORWARD or BACKWARD
+ * @retval None
+ * @note For unidirectionnal motor, direction parameter has
+ * no effect
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_Run(uint8_t motorId, motorDir_t direction)
+{
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else if ((device_prm.motionState[motorId] == INACTIVE) ||
+ (device_prm.direction[motorId] != direction))
+ {
+
+ /* Release reset if required */
+ if (Stspin240_250_GetResetState() == 0)
+ {
+ Stspin240_250_ReleaseReset();
+ }
+
+ /* Eventually deactivate motor */
+ if (device_prm.motionState[motorId] != INACTIVE)
+ {
+ Stspin240_250_HardStop(motorId);
+ }
+
+ /* Set direction */
+ Stspin240_250_SetDirection(motorId, direction);
+
+ /* Switch to steady state */
+ device_prm.motionState[motorId] = STEADY;
+
+ /* Enable bridge */
+ if (device_prm.bridgeEnabled[motorId] == FALSE)
+ {
+ Stspin240_250_EnableBridge(motorId);
+ }
+ /* Set PWM */
+ Stspin240_250_Board_PwmSetFreq(motorId, device_prm.bridgePwmFreq[motorId],device_prm.speed[motorId]);
+ }
+}
+
+/******************************************************//**
+ * @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
+ * @note 1)The PWM is only enabled when the motor is requested
+ * to run.
+ * 2) If the two bridges share the same timer, their frequency
+ * has to be the same
+ * 3) If the two bridges share the same timer, the frequency
+ * is updated on the fly is there is only one motor running
+ * on the targeted bridge.
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq)
+{
+ if (bridgeId > BRIDGE_B)
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_2);
+ }
+
+ if (newFreq > STSPIN240_250_MAX_PWM_FREQ)
+ {
+ newFreq = STSPIN240_250_MAX_PWM_FREQ;
+ }
+
+ device_prm.bridgePwmFreq[bridgeId] = newFreq;
+
+ if (device_prm.motionState[bridgeId] != INACTIVE)
+ {
+ Stspin240_250_Board_PwmSetFreq(bridgeId, device_prm.bridgePwmFreq[bridgeId],device_prm.speed[bridgeId]);
+ }
+}
+
+/******************************************************//**
+ * @brief Specifies the direction
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @param[in] dir FORWARD or BACKWARD
+ * @note The direction change is only applied if the device
+ * is in INACTIVE state. To change direction while motor is
+ * running, use the Run function
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetDirection(uint8_t motorId, motorDir_t dir)
+{
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else if (device_prm.motionState[motorId] == INACTIVE)
+ {
+ Stspin240_250_Board_SetDirectionGpio(motorId, dir);
+ device_prm.direction[motorId] = dir;
+ }
+}
+
+/******************************************************//**
+ * @brief Set the dual bridge configuration mode
+ * @param[in] enable 0 to disable,
+ * 1 to enable (not supported by STSPIN250)
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetDualFullBridgeconfig(uint8_t enable)
+{
+ device_prm.dualBridgeEnabled = enable;
+
+ /* Check reset pin state*/
+ if (Stspin240_250_GetResetState() != 0)
+ {
+ Stspin240_250_Reset();
+ Stspin240_250_ReleaseReset();
+ }
+}
+
+/******************************************************//**
+ * @brief Changes the max speed of the specified device
+ * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
+ * @param[in] newMaxSpeed in % from 0 to 100
+ * @retval true if the command is successfully executed, else false
+ **********************************************************/
+bool STSPIN240_250::Stspin240_250_SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed)
+{
+ bool cmdExecuted = FALSE;
+
+ if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
+ {
+ Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
+ }
+ else
+ {
+ device_prm.speed[motorId] = newMaxSpeed;
+ if (device_prm.motionState[motorId] != INACTIVE)
+ {
+ /* Set PWM frequency*/
+ Stspin240_250_Board_PwmSetFreq(motorId, device_prm.bridgePwmFreq[motorId],device_prm.speed[motorId]);
+ }
+ cmdExecuted = TRUE;
+ }
+ return cmdExecuted;
+}
+
+/******************************************************//**
+ * @brief Changes the duty cycle of the PWM used for REF
+ * @param[in] refId 0 is the only supported id for Stspin240 or
+ * Stspin250
+ * @param[in] newDc new duty cycle from 0 to 100
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetRefPwmDc(uint8_t refId, uint8_t newDc)
+{
+ if (newDc > 100)
+ {
+ newDc = 100;
+ }
+
+ device_prm.refPwmDc = newDc;
+
+ if (Stspin240_250_GetResetState() != 0)
+ {
+ /* Immediatly set the PWM frequency for ref if chip is not in reset */
+ Stspin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc);
+ }
+}
+
+/******************************************************//**
+ * @brief Changes the frequency of PWM used for REF
+ * @param[in] refId 0 is the only supported id for Stspin240 or
+ * Stspin250
+ * @param[in] newFreq in Hz
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetRefPwmFreq(uint8_t refId, uint32_t newFreq)
+{
+ if (newFreq > STSPIN240_250_MAX_PWM_FREQ)
+ {
+ newFreq = STSPIN240_250_MAX_PWM_FREQ;
+ }
+
+ device_prm.refPwmFreq = newFreq;
+
+ if (Stspin240_250_GetResetState() != 0)
+ {
+ /* Immediatly set the PWM frequency for ref if chip is not in reset */
+ Stspin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc);
+ }
+}
+
+
+/******************************************************//**
+ * @brief Get the status of the bridge enabling of the corresponding bridge
+ * @retval State of the Enable&Fault pin (shared for bridge A and B)
+ **********************************************************/
+uint8_t STSPIN240_250::Stspin240_250_GetResetState(void)
+{
+ uint8_t status = Stspin240_250_Board_GetResetPinState();
+
+ return (status);
+}
+
+/******************************************************//**
+ * @brief Set the parameters of the device to values of pInitPrm structure
+ * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1)
+ * @param pInitPrm pointer to a structure containing the initial device parameters
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetDeviceParamsToGivenValues(Stspin240_250_Init_t *pInitPrm)
+{
+ uint32_t i;
+
+ device_prm.dualBridgeEnabled = pInitPrm->dualBridgeEnabled;
+
+ device_prm.bridgePwmFreq[BRIDGE_A] = pInitPrm->bridgePwmFreq[BRIDGE_A];
+ device_prm.bridgePwmFreq[BRIDGE_B] = pInitPrm->bridgePwmFreq[BRIDGE_B];;
+
+ device_prm.refPwmFreq = pInitPrm->refPwmFreq;
+ device_prm.refPwmDc = pInitPrm->refPwmDc;
+
+ for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++)
+ {
+ device_prm.speed[i] = 100;
+ device_prm.direction[i] = FORWARD;
+ device_prm.motionState[i] = INACTIVE;
+ }
+ for (i = 0; i < STSPIN240_250_NB_BRIDGES; i++)
+ {
+ device_prm.bridgeEnabled[i] = FALSE;
+ }
+}
+/******************************************************//**
+ * @brief Sets the parameters of the device to predefined values
+ * from stspin240_250_target_config.h
+ * @retval None
+ **********************************************************/
+void STSPIN240_250::Stspin240_250_SetDeviceParamsToPredefinedValues(void)
+{
+ uint32_t i;
+
+ device_prm.dualBridgeEnabled = STSPIN240_250_CONF_PARAM_DUAL_BRIDGE_ENABLING;
+
+ device_prm.bridgePwmFreq[BRIDGE_A] = STSPIN240_250_CONF_PARAM_FREQ_PWM_A;
+ device_prm.bridgePwmFreq[BRIDGE_B] = STSPIN240_250_CONF_PARAM_FREQ_PWM_B;
+
+ device_prm.refPwmFreq = STSPIN240_250_CONF_PARAM_FREQ_PWM_REF;
+ device_prm.refPwmDc = STSPIN240_250_CONF_PARAM_DC_PWM_REF;
+
+ for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++)
+ {
+ device_prm.speed[i] = 100;
+ device_prm.direction[i] = FORWARD;
+ device_prm.motionState[i] = INACTIVE;
+ }
+ for (i = 0; i < STSPIN240_250_NB_BRIDGES; i++)
+ {
+ device_prm.bridgeEnabled[i] = FALSE;
+ }
+}
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/stspin240_250/stspin240_250_class.h Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,786 @@
+/**
+ ******************************************************************************
+ * @file stspin240_250_class.h
+ * @author IPC Rennes
+ * @version V1.0.0
+ * @date April 20th, 2016
+ * @brief This file contains the class of a Stspin240_250 Motor Control component.
+ * @note (C) COPYRIGHT 2016 STMicroelectronics
+ ******************************************************************************
+ * @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 __STSPIN240_250_CLASS_H
+#define __STSPIN240_250_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here component specific header files. *
+ *----------------------------------------------------------------------------*/
+#include "stspin240_250.h"
+/* ACTION 3 ------------------------------------------------------------------*
+ * Include here interface specific header files. *
+ * *
+ * Example: *
+ * #include "../Interfaces/Humidity_class.h" *
+ * #include "../Interfaces/Temperature_class.h" *
+ *----------------------------------------------------------------------------*/
+#include "../Interfaces/BDCMotor_class.h"
+
+/* Defines -------------------------------------------------------------------*/
+
+/* MCU wait time in ms after power bridges are enabled */
+#define BRIDGE_TURN_ON_DELAY (1)
+
+/* MCU wait time in ms after exit standby mode */
+#define EXIT_STANDBY_MODE_DELAY (1)
+
+/* Classes -------------------------------------------------------------------*/
+
+
+/**
+ * @brief Class representing a Stspin240_250 component.
+ */
+class STSPIN240_250 : public BDCMotor
+{
+public:
+
+ /*** Constructor and Destructor Methods ***/
+
+ /**
+ * @brief Constructor.
+ * @param flag_and_enable_pin pin name of the EN pin of the component.
+ * @param standby_reset_pin pin name of the STBY\RST pin of the component.
+ * @param pwmA_pin pin name for the PWM input for bridge A
+ * @param pwmB_pin pin name for the PWM input for bridge B
+ * @param dirA_pin pin name for the direction pinfor bridge A
+ * @param dirB_pin pin name for the direction pinfor bridge B
+ */
+ STSPIN240_250(PinName flag_and_enable_pin, PinName standby_reset_pin, PinName dirA_pin, PinName dirB_pin, PinName pwmA_pin, PinName pwmB_pin, PinName pwmRef_pin) : BDCMotor(), flag_and_enable(flag_and_enable_pin), standby_reset(standby_reset_pin), dirA(dirA_pin), dirB(dirB_pin), pwmA(pwmA_pin), pwmB(pwmB_pin), pwmRef(pwmRef_pin)
+ {
+ /* Checking stackability. */
+ if (!(numberOfDevices < MAX_NUMBER_OF_DEVICES))
+ error("Instantiation of the Stpin240_250 component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_DEVICES);
+
+ /* ACTION 4 ----------------------------------------------------------*
+ * Initialize here the component's member variables, one variable per *
+ * line. *
+ * *
+ * Example: *
+ * measure = 0; *
+ * instance_id = number_of_instances++; *
+ *--------------------------------------------------------------------*/
+ errorHandlerCallback = 0;
+ deviceInstance = numberOfDevices++;
+ }
+
+ /**
+ * @brief Destructor.
+ */
+ virtual ~STSPIN240_250(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(); *
+ * } *
+ *------------------------------------------------------------------------*/
+
+ /**
+ * @brief Public functions inherited from the Component Class
+ */
+
+ /**
+ * @brief Initialize the component.
+ * @param init Pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+ virtual int Init(void *init = NULL)
+ {
+ return (int) Stspin240_250_Init((void *) init);
+ }
+
+ /**
+ * @brief Getting the ID of the component.
+ * @param 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 = NULL)
+ {
+ return (int) Stspin240_250_ReadId((uint8_t *) id);
+ }
+
+ /**
+ * @brief Public functions inherited from the BCDMotor Class
+ */
+
+ /**
+ * @brief Disabling the specified bridge.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @retval None.
+ */
+ virtual void DisableBridge(unsigned int bridgeId)
+ {
+ Stspin240_250_DisableBridge(bridgeId);
+ }
+
+ /**
+ * @brief Enabling the specified bridge.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B
+ * @retval None.
+ */
+ virtual void EnableBridge(unsigned int bridgeId)
+ {
+ Stspin240_250_EnableBridge(bridgeId);
+ }
+
+ /**
+ * @brief Getting the PWM frequency of the specified bridge;
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @retval The frequency in Hz of the specified bridge input PWM.
+ */
+ virtual unsigned int GetBridgeInputPwmFreq(unsigned int bridgeId)
+ {
+ return (unsigned int) Stspin240_250_GetBridgeInputPwmFreq(bridgeId);
+ }
+
+ /**
+ * @brief Getting the bridge status.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @retval The status.
+ */
+ virtual unsigned int GetBridgeStatus(unsigned int bridgeId)
+ {
+ return (unsigned int) Stspin240_250_GetBridgeStatus();
+ }
+
+ /**
+ * @brief Getting the device State.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval The device state (STEADY or INACTIVE)
+ */
+ virtual motorState_t GetDeviceState(unsigned int motorId)
+ {
+ return (motorState_t) Stspin240_250_GetDeviceState(motorId);
+ }
+
+ /**
+ * @brief Getting the duty cycle of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @retval duty cycle in % (from 0 to 100)
+ */
+ virtual unsigned int GetRefPwmDc(unsigned int refId)
+ {
+ return (unsigned int) Stspin240_250_GetRefPwmDc(refId);
+ }
+
+ /**
+ * @brief Getting the frequency of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @retval frequency in Hz.
+ */
+ virtual unsigned int GetRefPwmFreq(unsigned int refId)
+ {
+ return (unsigned int) Stspin240_250_GetRefPwmFreq(refId);
+ }
+
+ /**
+ * @brief Getting the current speed in % of the specified motor.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval The current speed in %.
+ */
+ virtual unsigned int GetSpeed(unsigned int motorId)
+ {
+ return (unsigned int) Stspin240_250_GetCurrentSpeed(motorId);
+ }
+
+ /**
+ * @brief Stopping the motor and disabling the power bridge immediately.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval None.
+ */
+ virtual void HardHiZ(unsigned int motorId)
+ {
+ Stspin240_250_HardHiz(motorId);
+ }
+
+ /**
+ * @brief Stopping the motor immediately.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval None.
+ */
+ virtual void HardStop(unsigned int motorId)
+ {
+ Stspin240_250_HardStop(motorId);
+ }
+
+ /**
+ * @brief Running the motor.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @param direction The direction of rotation.
+ * @retval None.
+ */
+ virtual void Run(unsigned int motorId, direction_t direction)
+ {
+ Stspin240_250_Run(motorId, (motorDir_t) direction);
+ }
+
+ /**
+ * @brief Setting the PWM frequency of the specified bridge.
+ * @param bridgeId from 0 for bridge A to 1 for bridge B.
+ * @param frequency of the PWM in Hz
+ * @retval None.
+ */
+ virtual void SetBridgeInputPwmFreq(unsigned int bridgeId, unsigned int frequency)
+ {
+ Stspin240_250_SetBridgeInputPwmFreq(bridgeId, frequency);
+ }
+
+ /**
+ * @brief Setting the dual bridge configuration mode.
+ * @param configuration. The bridge configuration.
+ * @retval None.
+ */
+ virtual void SetDualFullBridgeconfig(unsigned int configuration)
+ {
+ Stspin240_250_SetDualFullBridgeconfig(configuration);
+ }
+
+ /**
+ * @brief Setting the duty cycle of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @param newDc new duty cycle from 0 to 100
+ * @retval None.
+ */
+ virtual void SetRefPwmDc(unsigned int refId, unsigned int newDc)
+ {
+ Stspin240_250_SetRefPwmDc(refId, newDc);
+ }
+
+ /**
+ * @brief Setting the frequency of the PWM used for REF.
+ * @param refId Id of the reference PWM signal.
+ * @param frequency in Hz.
+ * @retval None.
+ */
+ virtual void SetRefPwmFreq(unsigned int refId, unsigned int frequency)
+ {
+ Stspin240_250_SetRefPwmFreq(refId, frequency);
+ }
+
+ /**
+ * @brief Setting the speed in %.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @param speed The new speed in %.
+ * @retval "true" in case of success, "false" otherwise.
+ */
+ virtual bool SetSpeed(unsigned int motorId, unsigned int speed)
+ {
+ return (bool) Stspin240_250_SetMaxSpeed(motorId, speed);
+ }
+
+ /**
+ * @brief Public functions NOT inherited
+ */
+
+ /**
+ * @brief Attaching an error handler.
+ * @param fptr An error handler.
+ * @retval None.
+ */
+ virtual void AttachErrorHandler(void (*fptr)(uint16_t error))
+ {
+ Stspin240_250_AttachErrorHandler((void (*)(uint16_t error)) fptr);
+ }
+
+ /**
+ * @brief Getting the motor current direction.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @retval direction The direction of rotation.
+ */
+ virtual direction_t GetDirection(unsigned int motorId)
+ {
+ return (direction_t) Stspin240_250_GetDirection(motorId);
+ }
+
+ /**
+ * @brief Getting the version of the firmware.
+ * @param None.
+ * @retval The version of the firmware.
+ */
+ virtual unsigned int GetFwVersion(void)
+ {
+ return (unsigned int) Stspin240_250_GetFwVersion();
+ }
+
+ /**
+ * @brief Releasing the reset (exiting standby mode).
+ * @param None.
+ * @retval None.
+ */
+ virtual void ReleaseReset(void)
+ {
+ Stspin240_250_ReleaseReset();
+ }
+
+ /**
+ * @brief Reseting (entering standby mode).
+ * @param None.
+ * @retval None.
+ */
+ virtual void Reset(void)
+ {
+ Stspin240_250_Reset();
+ }
+
+ /**
+ * @brief Setting the direction of rotation of the firmware.
+ * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
+ * @param direction The direction of rotation.
+ * @retval None
+ */
+ virtual void SetDirection(unsigned int motorId, direction_t direction)
+ {
+ Stspin240_250_SetDirection(motorId, (motorDir_t) direction);
+ }
+
+ /**
+ * @brief Public static functions
+ */
+ static uint8_t GetNbDevices(void)
+ {
+ return numberOfDevices;
+ }
+
+ /*** 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.rise(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.rise(fptr); *
+ * } *
+ * *
+ * void EnableFeatureIRQ(void) *
+ * { *
+ * feature_irq.enable_irq(); *
+ * } *
+ * *
+ * void DisableFeatureIRQ(void) *
+ * { *
+ * feature_irq.disable_irq(); *
+ * } *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Attaching an interrupt handler to the FLAG interrupt.
+ * @param fptr An interrupt handler.
+ * @retval None.
+ */
+ void AttachFlagIRQ(void (*fptr)(void))
+ {
+ flag_and_enable.mode(PullDown);
+ flag_and_enable.fall(fptr);
+ }
+
+ /**
+ * @brief Enabling the FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void EnableFlagIRQ(void)
+ {
+ flag_and_enable.enable_irq();
+ }
+
+ /**
+ * @brief Disabling the FLAG interrupt handling.
+ * @param None.
+ * @retval None.
+ */
+ void DisableFlagIRQ(void)
+ {
+ flag_and_enable.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: *
+ * Status_t COMPONENT_GetValue(float *f); //(1) *
+ * Status_t COMPONENT_EnableFeature(void); //(2) *
+ * Status_t COMPONENT_ComputeAverage(void); //(3) *
+ *------------------------------------------------------------------------*/
+
+ Status_t Stspin240_250_Init(void *init);
+ Status_t Stspin240_250_ReadId(uint8_t *id);
+ void Stspin240_250_AttachErrorHandler(void (*callback)(uint16_t error));
+ void Stspin240_250_DisableBridge(uint8_t bridgeId);
+ void Stspin240_250_EnableBridge(uint8_t bridgeId);
+ void Stspin240_250_ErrorHandler(uint16_t error);
+ uint32_t Stspin240_250_GetBridgeInputPwmFreq(uint8_t bridgeId);
+ uint16_t Stspin240_250_GetBridgeStatus(void);
+ uint16_t Stspin240_250_GetCurrentSpeed(uint8_t motorId);
+ motorState_t Stspin240_250_GetDeviceState(uint8_t motorId);
+ motorDir_t Stspin240_250_GetDirection(uint8_t motorId);
+ uint32_t Stspin240_250_GetFwVersion(void);
+ uint8_t Stspin240_250_GetRefPwmDc(uint8_t refId);
+ uint32_t Stspin240_250_GetRefPwmFreq(uint8_t refId);
+ void Stspin240_250_HardHiz(uint8_t motorId);
+ void Stspin240_250_HardStop(uint8_t motorId);
+ void Stspin240_250_ReleaseReset(void);
+ void Stspin240_250_Reset(void);
+ void Stspin240_250_Run(uint8_t motorId, motorDir_t direction);
+ void Stspin240_250_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq);
+ void Stspin240_250_SetDirection(uint8_t motorId, motorDir_t dir);
+ void Stspin240_250_SetDualFullBridgeconfig(uint8_t enable);
+ bool Stspin240_250_SetMaxSpeed(uint8_t motorId,uint16_t newMaxSpeed);
+ void Stspin240_250_SetRefPwmDc(uint8_t refId, uint8_t newDc);
+ void Stspin240_250_SetRefPwmFreq(uint8_t refId, uint32_t newFreq);
+
+ /**
+ * @brief Functions to initialize the registers
+ */
+ void Stspin240_250_SetDeviceParamsToGivenValues(Stspin240_250_Init_t *pInitPrm);
+ void Stspin240_250_SetDeviceParamsToPredefinedValues(void);
+
+ /**
+ * @brief Get the state of the standby/reset pin
+ */
+ uint8_t Stspin240_250_GetResetState(void);
+
+ /*** 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. *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Making the CPU wait.
+ * @param None.
+ * @retval None.
+ */
+ void Stspin240_250_Board_Delay(uint32_t delay)
+ {
+ wait_ms(delay);
+ }
+
+ /**
+ * @brief Disable bridge.
+ * @param None.
+ * @retval None.
+ */
+ void Stspin240_250_Board_DisableBridge(void)
+ {
+ flag_and_enable.disable_irq();
+ flag_and_enable.mode(PullDown);
+ }
+
+ /**
+ * @brief Enable bridge.
+ * @param addDelay if different from 0, a delay is added after bridge activation..
+ * @retval None.
+ */
+ void Stspin240_250_Board_EnableBridge(uint8_t addDelay)
+ {
+ flag_and_enable.mode(PullUp);
+ if (addDelay)
+ {
+ Stspin240_250_Board_Delay(BRIDGE_TURN_ON_DELAY);
+ }
+ flag_and_enable.enable_irq();
+ }
+
+ /**
+ * @brief Get the status of the reset Pin.
+ * @param None.
+ * @retval None.
+ */
+ uint16_t Stspin240_250_Board_GetResetPinState(void)
+ {
+ return((uint16_t)flag_and_enable.read());
+ }
+
+ /**
+ * @brief Get the status of the flag and enable Pin.
+ * @param None.
+ * @retval None.
+ */
+ uint16_t Stspin240_250_Board_GetFaultPinState(void)
+ {
+ return((uint16_t)flag_and_enable.read());
+ }
+
+ /**
+ * @brief Deinitialising the PWM.
+ * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
+ * @retval None.
+ */
+ void Stspin240_250_Board_PwmDeInit(uint8_t pwmId)
+ {
+
+ }
+
+ /**
+ * @brief Initialising the PWM.
+ * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
+ * @param onlyChannel.
+ * @retval None.
+ */
+ void Stspin240_250_Board_PwmInit(uint8_t pwmId, uint8_t onlyChannel)
+ {
+
+ }
+
+ /**
+ * @brief Setting the frequency of PWM.
+ * The frequency of bridge A and B controls directly the speed of the device.
+ * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
+ * @param newFreq frequency to apply in Hz.
+ * @param duty Duty cycle to use from 0 to 100.
+ * @retval None.
+ */
+ void Stspin240_250_Board_PwmSetFreq(int8_t pwmId, uint32_t newFreq, uint8_t duty)
+ {
+ /* Computing the period of PWM. */
+ double period = 1.0f / newFreq;
+
+ switch (pwmId)
+ {
+ case 0:
+ default:
+ /* Setting the period and the duty-cycle of PWM A. */
+ pwmA.period(period);
+ pwmA.write((float)(duty / 100.0f));
+ break;
+ case 1:
+ /* Setting the period and the duty-cycle of PWM B. */
+ pwmB.period(period);
+ pwmB.write((float)(duty / 100.0f));
+ break;
+ case 2:
+ /* Setting the period and the duty-cycle of PWM Ref. */
+ pwmRef.period(period);
+ pwmRef.write((float)(duty / 100.0f));
+ break;
+ }
+ }
+
+ /**
+ * @brief Stopping the PWM.
+ * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
+ * @retval None.
+ */
+ void Stspin240_250_Board_PwmStop(uint8_t pwmId)
+ {
+ switch (pwmId)
+ {
+ case 0:
+ default:
+ pwmA.write(0.0f);
+ break;
+ case 1:
+ pwmB.write(0.0f);
+ break;
+ case 2:
+ pwmRef.write(0.0f);
+ break;
+ }
+ }
+
+ /**
+ * @brief Putting the device in standby mode.
+ * @param None.
+ * @retval None.
+ */
+ void Stspin240_250_Board_ReleaseReset(void)
+ {
+ standby_reset = 1;
+ Stspin240_250_Board_Delay(EXIT_STANDBY_MODE_DELAY);
+ }
+
+ /**
+ * @brief Putting the device in reset mode.
+ * @param None.
+ * @retval None.
+ */
+ void Stspin240_250_Board_Reset(void)
+ {
+ standby_reset = 0;
+ }
+
+ /**
+ * @brief Setting the direction of rotation.
+ * @param bridgeId 0 for bridge A, 1 for bridge B.
+ * @param gpioState direction of rotation: "1" for forward, "0" for backward.
+ * @retval None.
+ */
+ void Stspin240_250_Board_SetDirectionGpio(uint8_t bridgeId, uint8_t gpioState)
+ {
+ if (bridgeId == 0)
+ {
+ dirA = gpioState;
+ }
+ else
+ {
+ dirB = gpioState;
+ }
+ }
+
+ /*** 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_and_enable;
+
+ /* ACTION 10 -------------------------------------------------------------*
+ * Declare here other pin related variables, if needed. *
+ * *
+ * Example: *
+ * + mbed: *
+ * DigitalOut standby_reset; *
+ *------------------------------------------------------------------------*/
+ /* Standby/reset pin. */
+ DigitalOut standby_reset;
+
+ /* Direction pin of bridge A. */
+ DigitalOut dirA;
+
+ /* Direction pin of bridge B. */
+ DigitalOut dirB;
+
+ /* Pulse Width Modulation pin for bridge A input. */
+ PwmOut pwmA;
+
+ /* Pulse Width Modulation pin for bridge A input. */
+ PwmOut pwmB;
+
+ /* Pulse Width Modulation pin for Ref signal. */
+ PwmOut pwmRef;
+
+ /* ACTION 11 -------------------------------------------------------------*
+ * Declare here communication related variables, if needed. *
+ * *
+ * Example: *
+ * + mbed: *
+ * DigitalOut ssel; *
+ * DevSPI &dev_spi; *
+ *------------------------------------------------------------------------*/
+
+ /* 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; *
+ *------------------------------------------------------------------------*/
+ /* Data. */
+ void (*errorHandlerCallback)(uint16_t error);
+ deviceParams_t device_prm;
+ uint8_t deviceInstance;
+
+
+ /* Static data. */
+ static uint8_t numberOfDevices;
+ static uint8_t arrayNbMaxMotorsByConfig[2];
+
+public:
+
+ /* Static data. */
+
+};
+
+#endif // __STSPIN240_250_CLASS_H
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/stspin240_250/stspin240_250_target_config.h Thu Apr 28 14:03:11 2016 +0000
@@ -0,0 +1,100 @@
+/**************************************************************************//**
+ * @file stspin240_250_target_config.h
+ * @author IPC Rennes
+ * @version V1.0.0
+ * @date February 10, 2016
+ * @brief Predefines values for the Stspin240 or Stspin250 parameters
+ * and for the devices parameters
+ * @note (C) COPYRIGHT 2016 STMicroelectronics
+ ******************************************************************************
+ * @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 __STSPIN240_250_TARGET_CONFIG_H
+#define __STSPIN240_250_TARGET_CONFIG_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/** @addtogroup STSPIN240_250
+ * @{
+ */
+
+/** @addtogroup STSPIN240_250_Exported_Defines STSPIN240_250 Exported Defines
+ * @{
+ */
+
+/** @defgroup Predefined_STSPIN240_250_Parameters_Values Predefined STSPIN240_250 Parameters Values
+ * @{
+ */
+
+/// The maximum number of Stspin240 or Stspin250 devices
+#define MAX_NUMBER_OF_DEVICES (1)
+
+/// The maximum number of Brush DC motors connected to the Stspin240 or Stspin250
+#define MAX_NUMBER_OF_BRUSH_DC_MOTORS (2)
+
+/// Frequency of PWM of Input Bridge A in Hz up to 100000Hz
+#define STSPIN240_250_CONF_PARAM_FREQ_PWM_A (20000)
+
+/// Frequency of PWM of Input Bridge B in Hz up to 100000Hz
+/// On the X-NUCLEO-IHM01A12 expansion board the PWM_A and PWM_B
+/// share the same timer, so the frequency must be the same
+#define STSPIN240_250_CONF_PARAM_FREQ_PWM_B (20000)
+
+/// Frequency of PWM used for Ref pinin Hz up to 100000Hz
+#define STSPIN240_250_CONF_PARAM_FREQ_PWM_REF (20000)
+
+/// Duty cycle of PWM used for Ref pin (from 0 to 100)
+#define STSPIN240_250_CONF_PARAM_DC_PWM_REF (50)
+
+/// Dual Bridge configuration (0 for mono, 1 for dual brush dc (STSPIN240 only)
+#define STSPIN240_250_CONF_PARAM_DUAL_BRIDGE_ENABLING (0)
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* __STSPIN240_250_TARGET_CONFIG_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\ No newline at end of file

X-NUCLEO-IHM12A1 Low Voltage Dual Brush DC Motor Driver