Personal fork of the library for direct control instead of library control

Dependencies:   X_NUCLEO_COMMON

Dependents:   Thesis_Rotating_Platform

Fork of X_NUCLEO_IHM01A1 by Arkadi Rafalovich

Revision:
4:83a1eb397a65
Parent:
1:b38ebb8ea286
Child:
5:d3c78f12a78d
--- a/Components/l6474/l6474_class.h	Fri Oct 16 13:30:06 2015 +0000
+++ b/Components/l6474/l6474_class.h	Fri Nov 13 12:56:06 2015 +0000
@@ -73,14 +73,14 @@
  *   #include "../Interfaces/Humidity_class.h"                                *
  *   #include "../Interfaces/Temperature_class.h"                             *
  *----------------------------------------------------------------------------*/
-#include "../Interfaces/Motor_class.h"
+#include "../Interfaces/StepperMotor_class.h"
 
 
 /* Classes -------------------------------------------------------------------*/
 
 /** Class representing a L6474 component.
  */
-class L6474 : public Motor
+class L6474 : public StepperMotor
 {
 public:
 
@@ -88,13 +88,13 @@
 
     /**
      * @brief Constructor.
-     * @param reset     pin name of the STBY\RST pin of the component.
-     * @param direction pin name of the DIR pin of the component.
-     * @param pwm       pin name of the PWM pin of the component.
-     * @param ssel      pin name of the SSEL pin of the SPI device to be used for communication.
-     * @param spi       SPI device to be used for communication.
+     * @param standby_reset pin name of the STBY\RST pin of the component.
+     * @param direction     pin name of the DIR pin of the component.
+     * @param pwm           pin name of the PWM pin of the component.
+     * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
+     * @param spi           SPI device to be used for communication.
      */
-    L6474(PinName reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi) : Motor(), direction(direction), pwm(pwm), reset(reset), ssel(ssel), dev_spi(spi)
+    L6474(PinName standby_reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi) : StepperMotor(), standby_reset(standby_reset), direction(direction), pwm(pwm), ssel(ssel), dev_spi(spi)
     {
         /* ACTION 4 ----------------------------------------------------------*
          * Initialize here the component's member variables, one variable per *
@@ -155,64 +155,99 @@
         return (int) L6474_ReadID((uint8_t *) id);
     }
 
-    virtual void AttachErrorHandler(void (*callback)(uint16_t error))
+    virtual unsigned int GetStatus(void)
     {
-        L6474_AttachErrorHandler((void (*)(uint16_t error)) callback);
+        return (unsigned int) L6474_CmdGetStatus();
     }
 
-    virtual void AttachFlagInterrupt(void (*callback)(void))
+    virtual unsigned int GetParameter(unsigned int parameter)
     {
-        L6474_AttachFlagInterrupt((void (*)(void)) callback);
+        return (unsigned int) L6474_CmdGetParam((unsigned int) parameter);
+    }
+
+    virtual signed int GetPosition(void)
+    {
+        return (signed int) L6474_GetPosition();
     }
 
-    virtual void FlagInterruptHandler(void)
+    virtual signed int GetMark(void)
     {
-        L6474_FlagInterruptHandler();
+        return (signed int) L6474_GetMark();
+    }
+    
+    virtual direction_t GetDirection(void)
+    {
+        return (direction_t) L6474_GetDirection();
     }
 
-    virtual uint16_t GetAcceleration(void)
+    virtual unsigned int GetSpeed(void)
     {
-        return (uint16_t) L6474_GetAcceleration();
+        return (unsigned int) L6474_GetCurrentSpeed();
     }
 
-    virtual uint16_t GetCurrentSpeed(void)
+    virtual unsigned int GetMaxSpeed(void)
+    {
+        return (unsigned int) L6474_GetMaxSpeed();
+    }
+
+    virtual unsigned int GetMinSpeed(void)
     {
-        return (uint16_t) L6474_GetCurrentSpeed();
+        return (unsigned int) L6474_GetMinSpeed();
+    }
+
+    virtual unsigned int GetAcceleration(void)
+    {
+        return (unsigned int) L6474_GetAcceleration();
     }
 
-    virtual uint16_t GetDeceleration(void)
+    virtual unsigned int GetDeceleration(void)
     {
-        return (uint16_t) L6474_GetDeceleration();
+        return (unsigned int) L6474_GetDeceleration();
     }
 
-    virtual motorState_t GetDeviceState(void)
+    virtual void SetParameter(unsigned int parameter, unsigned int value)
     {
-        return (motorState_t) L6474_GetDeviceState();
+        L6474_CmdSetParam((unsigned int) parameter, (unsigned int) value);
     }
 
-    virtual uint8_t GetFwVersion(void)
+    virtual void SetHome(void)
     {
-        return (uint8_t) L6474_GetFwVersion();
+        L6474_SetHome();
+    }
+
+    virtual void SetMark(void)
+    {
+        L6474_SetMark();
     }
 
-    virtual int32_t GetMark(void)
+    virtual void SetDirection(direction_t direction)
     {
-        return (int32_t) L6474_GetMark();
+        L6474_SetDirection((direction_t) direction);
+    }
+
+    virtual void SetMaxSpeed(unsigned int speed)
+    {
+        L6474_SetMaxSpeed((unsigned int) speed);
     }
 
-    virtual uint16_t GetMaxSpeed(void)
+    virtual void SetMinSpeed(unsigned int speed)
     {
-        return (uint16_t) L6474_GetMaxSpeed();
+        L6474_SetMinSpeed((unsigned int) speed);
     }
 
-    virtual uint16_t GetMinSpeed(void)
+    virtual void SetAcceleration(unsigned int acceleration)
     {
-        return (uint16_t) L6474_GetMinSpeed();
+        L6474_SetAcceleration((unsigned int) acceleration);
     }
 
-    virtual int32_t GetPosition(void)
+    virtual void SetDeceleration(unsigned int deceleration)
     {
-        return (int32_t) L6474_GetPosition();
+        L6474_SetDeceleration((unsigned int) deceleration);
+    }
+
+    virtual void GoTo(signed int position)
+    {
+        L6474_GoTo((signed int) position);
     }
 
     virtual void GoHome(void)
@@ -225,9 +260,19 @@
         L6474_GoMark();
     }
 
-    virtual void GoTo(int32_t targetPosition)
+    virtual void Run(direction_t direction)
+    {
+        L6474_Run((direction_t) direction);
+    }
+
+    virtual void Move(direction_t direction, unsigned int steps)
     {
-        L6474_GoTo((int32_t) targetPosition);
+        L6474_Move((direction_t) direction, (unsigned int) steps);
+    }
+
+    virtual void SoftStop(void)
+    {
+        L6474_SoftStop();
     }
 
     virtual void HardStop(void)
@@ -235,49 +280,14 @@
         L6474_HardStop();
     }
 
-    virtual void Move(motorDir_t direction, uint32_t stepCount)
-    {
-        L6474_Move((motorDir_t) direction, (uint32_t) stepCount);
-    }
-
-    virtual void Run(motorDir_t direction)
+    virtual motorState_t GetDeviceState(void)
     {
-        L6474_Run((motorDir_t) direction);
-    }
-
-    virtual bool SetAcceleration(uint16_t newAcc)
-    {
-        return (bool) L6474_SetAcceleration((uint16_t) newAcc);
-    }
-
-    virtual bool SetDeceleration(uint16_t newDec)
-    {
-        return (bool) L6474_SetDeceleration((uint16_t) newDec);
+        return (motorState_t) L6474_GetDeviceState();
     }
 
-    virtual void SetHome(void)
-    {
-        L6474_SetHome();
-    }
-
-    virtual void SetMark(void)
-    {
-        L6474_SetMark();
-    }
-
-    virtual bool SetMaxSpeed(uint16_t newMaxSpeed)
+    virtual uint8_t GetFwVersion(void)
     {
-        return (bool) L6474_SetMaxSpeed((uint16_t) newMaxSpeed);
-    }
-
-    virtual bool SetMinSpeed(uint16_t newMinSpeed)
-    {
-        return (bool) L6474_SetMinSpeed((uint16_t) newMinSpeed);
-    }
-
-    virtual bool SoftStop(void)
-    {
-        return (bool) L6474_SoftStop();
+        return (uint8_t) L6474_GetFwVersion();
     }
 
     virtual void StepClockHandler(void)
@@ -300,26 +310,11 @@
         L6474_CmdEnable();
     }
 
-    virtual uint32_t CmdGetParam(uint32_t param)
-    {
-        return (uint32_t) L6474_CmdGetParam((uint32_t) param);
-    }
-
-    virtual uint16_t CmdGetStatus(void)
-    {
-        return (uint16_t) L6474_CmdGetStatus();
-    }
-
     virtual void CmdNop(void)
     {
         L6474_CmdNop();
     }
 
-    virtual void CmdSetParam(uint32_t param, uint32_t value)
-    {
-        L6474_CmdSetParam((uint32_t) param, (uint32_t) value);
-    }
-
     virtual uint16_t ReadStatusRegister(void)
     {
         return (uint16_t) L6474_ReadStatusRegister();
@@ -340,16 +335,26 @@
         L6474_SelectStepMode((motorStepMode_t) stepMod);
     }
 
-    virtual void SetDirection(motorDir_t direction)
-    {
-        L6474_SetDirection((motorDir_t) direction);
-    }
-
     virtual void ErrorHandler(uint16_t error)
     {
         L6474_ErrorHandler((uint16_t) error);
     }
 
+    virtual void AttachErrorHandler(void (*callback)(uint16_t error))
+    {
+        L6474_AttachErrorHandler((void (*)(uint16_t error)) callback);
+    }
+
+    virtual void AttachFlagInterrupt(void (*callback)(void))
+    {
+        L6474_AttachFlagInterrupt((void (*)(void)) callback);
+    }
+
+    virtual void FlagInterruptHandler(void)
+    {
+        L6474_FlagInterruptHandler();
+    }
+
 
     /*** Public Interrupt Related Methods ***/
 
@@ -420,8 +425,8 @@
     void L6474_GoMark(void);                                         //Move to the Mark position
     void L6474_GoTo(int32_t targetPosition);                         //Go to the specified position
     void L6474_HardStop(void);                                       //Stop the motor and disable the power bridge
-    void L6474_Move(motorDir_t direction, uint32_t stepCount);       //Move the motor of the specified number of steps
-    void L6474_Run(motorDir_t direction);                            //Run the motor 
+    void L6474_Move(direction_t direction, uint32_t stepCount);       //Move the motor of the specified number of steps
+    void L6474_Run(direction_t direction);                            //Run the motor 
     bool L6474_SetAcceleration(uint16_t newAcc);                     //Set the acceleration in pps^2
     bool L6474_SetDeceleration(uint16_t newDec);                     //Set the deceleration in pps^2
     void L6474_SetHome(void);                                        //Set current position to be the home position
@@ -438,7 +443,8 @@
     void L6474_CmdSetParam(uint32_t param, uint32_t value);          //Send the L6474_SET_PARAM command
     uint16_t L6474_ReadStatusRegister(void);                         //Read the L6474_STATUS register without clearing the flags
     void L6474_SelectStepMode(motorStepMode_t stepMod);              //Step mode selection
-    void L6474_SetDirection(motorDir_t direction);                   //Set the L6474 direction pin
+    direction_t L6474_GetDirection(void);                             //Get the direction of rotation
+    void L6474_SetDirection(direction_t direction);                   //Set the direction of rotation
     void L6474_ApplySpeed(uint16_t newSpeed);
     void L6474_ComputeSpeedProfile(uint32_t nbSteps);
     int32_t L6474_ConvertPosition(uint32_t abs_position_reg); 
@@ -562,19 +568,21 @@
     }
 
     /*
-     * Setting the standby/reset pin to high.
+     * Puts the device in standby mode.
      */
     void L6474_ReleaseReset(void)
     {
-        reset = 1;
+        /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
+        standby_reset = 1;
     }
 
     /*
-     * Resetting the standby/reset pin to put the device in standby mode.
+     * Puts the device in reset mode.
      */
     void L6474_Reset(void)
     {
-        reset = 0;
+        /* TO BE IMPLEMENTED BY USING TARGET PLATFORM'S APIs. */
+        standby_reset = 0;
     }
 
     /*
@@ -606,11 +614,8 @@
     /* Type. */
     uint8_t type;
 
-    /* Configuration. */
-    DigitalOut ssel;
-
-    /* Standby and reset pin. */
-    DigitalOut reset;
+    /* Standby/reset pin. */
+    DigitalOut standby_reset;
 
     /* Direction of rotation pin. */
     DigitalOut direction;
@@ -618,12 +623,15 @@
     /* Pulse Width Modulation pin. */
     PwmOut pwm;
 
-    /* Timer to trigger the PWM callback at each PWM pulse. */
-    Ticker ticker;
+    /* Configuration. */
+    DigitalOut ssel;
 
     /* IO Device. */
     DevSPI &dev_spi;
 
+    /* Timer to trigger the PWM callback at each PWM pulse. */
+    Ticker ticker;
+
     /* Interrupts. */
     /* ACTION 10 -------------------------------------------------------------*
      * Put here interrupt related objects, if needed.                         *