Library for STMicroelectronics dSPIN L6470 stepper driver. "daisy-chain" supported.

Dependents:   L6470_daisy_chain l6470

Revision:
1:db64ad30b4b3
Parent:
0:e1964b6e160c
Child:
2:2af83d3ccd97
--- a/L6470SDC.h	Sat May 30 14:32:48 2015 +0000
+++ b/L6470SDC.h	Fri Jun 05 08:48:29 2015 +0000
@@ -64,18 +64,161 @@
 #define REG_CONFIG 0x18
 #define REG_STATUS 0x19
 
+/** Library for STMicroelectronics dSPIN L6470 stepper driver. "daisy-chain" supported.
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "L6470SDC.h"
+ *
+ * L6470SDC l6470(USBTX, USBRX, SPI_MOSI, SPI_MISO, SPI_SCK, D10);
+ *
+ * int main() {
+ *     //initialize
+ *     l6470.init();
+ *
+ *     //set maximum speed
+ *     l6470.setMaximumSpeed(1, l6470.calcMaxSpd(100));
+ *
+ *     //run 300step/s,clockwise
+ *     l6470.run(1, l6470.calcSpd(300), true);
+ *     wait(5.0);
+ *
+ *     //motor stop
+ *     l6470.stop(1);
+ *
+ *     //motor return home position.
+ *     l6470.home(1);
+ * }
+ * @endcode
+ */
 class L6470SDC{
 public:
-    //充実のコンストラクタ
+    /** Constructor:(Serial, SPI, CS) PinName
+    *
+    * @param tx Serial USB_TX PinName
+    * @param rx Serial USB_RX PinName
+    * @param mosi SPI Master-out PinName
+    * @param miso SPI Slave-out PinName
+    * @param sclk SPI Clock PinName
+    * @param csel SPI ChipSelect PinName
+    */
     L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, PinName csel);
+    
+    /** Constructor:(Serial, SPI, CS) PinName & DigitalOut*
+    *
+    * @param tx Serial USB_TX PinName
+    * @param rx Serial USB_RX PinName
+    * @param mosi SPI Master-out PinName
+    * @param miso SPI Slave-out PinName
+    * @param sclk SPI Clock PinName
+    * @param *csel SPI ChipSelect
+    * Example:
+    *     DigitalOut my_cs(D10);
+    *     L6470SDC stepper(USBTX, USBRX, SPI_MOSI, SPI_MISO, SPI_SCLK, &my_cs);
+    *                                                                  ~~~~~~
+    */
     L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, DigitalOut *csel);
+    
+    /** Constructor:(Serial, SPI, CS) Serial* & PinName
+    *
+    * @param *serial Serial
+    * @param mosi SPI Master-out PinName
+    * @param miso SPI Slave-out PinName
+    * @param sclk SPI Clock PinName
+    * @param csel SPI ChipSelect PinName
+    * Example:
+    *     Serial usb_serial(USBTX, USBRX);
+    *     L6470SDC stepper(&usb_serial, SPI_MOSI, SPI_MISO, SPI_SCLK, D10);
+    *                      ~~~~~~~~~~~
+    */
     L6470SDC(Serial *serial, PinName mosi, PinName miso, PinName sclk, PinName csel);
+
+    /** Constructor:(Serial, SPI, CS) Serial* & PinName & DigitalOut*
+    *
+    * @param *serial Serial
+    * @param mosi SPI Master-out PinName
+    * @param miso SPI Slave-out PinName
+    * @param sclk SPI Clock PinName
+    * @param *csel SPI ChipSelect
+    * Example:
+    *     Serial usb_serial(USBTX, USBRX);
+    *     DigitalOut my_cs(D10);
+    *     L6470SDC stepper(&usb_serial, SPI_MOSI, SPI_MISO, SPI_SCLK, &my_cs);
+    *                      ~~~~~~~~~~~                                ~~~~~~
+    */
     L6470SDC(Serial *serial, PinName mosi, PinName miso, PinName sclk, DigitalOut *csel);
+
+    /** Constructor:(Serial, SPI, CS) Serial* & SPI* & PinName
+    *
+    * @param *serial Serial
+    * @param *spi SPI
+    * @param csel SPI ChipSelect PinName
+    * Example:
+    *     Serial usb_serial(USBTX, USBRX);
+    *     SPI my_spi(SPI_MOSI, SPI_MISO, SPI_SCLK);
+    *     L6470SDC stepper(&usb_serial, &my_spi, D10);
+    *                      ~~~~~~~~~~~  ~~~~~~~
+    */
     L6470SDC(Serial *serial, SPI *spi, PinName csel);
+
+    /** Constructor:(Serial, SPI, CS) Serial* & SPI* & DigitalOut*
+    *
+    * @param *serial Serial
+    * @param *spi SPI
+    * @param *csel SPI ChipSelect
+    * Example:
+    *     Serial usb_serial(USBTX, USBRX);
+    *     SPI my_spi(SPI_MOSI, SPI_MISO, SPI_SCLK);
+    *     DigitalOut my_cs(D10);
+    *     L6470SDC stepper(&usb_serial, &my_spi, &my_cs);
+    *                      ~~~~~~~~~~~  ~~~~~~~  ~~~~~~
+    */
     L6470SDC(Serial *serial, SPI *spi, DigitalOut *csel);
+
+    /** Constructor: without Debug Serial (SPI, CS) PinName
+    *
+    * @param mosi SPI Master-out PinName
+    * @param miso SPI Slave-out PinName
+    * @param sclk SPI Clock PinName
+    * @param csel SPI ChipSelect PinName
+    */
     L6470SDC(PinName mosi, PinName miso, PinName sclk, PinName csel);
+
+    /** Constructor: without Debug Serial (SPI, CS) PinName & DigitalOut*
+    *
+    * @param mosi SPI Master-out PinName
+    * @param miso SPI Slave-out PinName
+    * @param sclk SPI Clock PinName
+    * @param *csel SPI ChipSelect
+    * Example:
+    *     DigitalOut cs1(D10);
+    *     L6470SDC stepper(SPI_MOSI, SPI_MISO, SPI_SCLK, &cs1);
+    *                                                    ~~~~
+    */
     L6470SDC(PinName mosi, PinName miso, PinName sclk, DigitalOut *csel);
+
+    /** Constructor: without Debug Serial (SPI, CS) SPI* & PinName
+    *
+    * @param *spi SPI
+    * @param csel SPI ChipSelect PinName
+    * Example:
+    *     SPI spi1(SPI_MOSI, SPI_MISO, SPI_SCLK);
+    *     L6470SDC stepper(&spi1, D10);
+    *                      ~~~~~
+    */
     L6470SDC(SPI *spi, PinName csel);
+
+    /** Constructor: without Debug Serial (SPI, CS) SPI* & DigitalOut*
+    *
+    * @param *spi SPI
+    * @param *csel SPI ChipSelect
+    * Example:
+    *     SPI spi1(SPI_MOSI, SPI_MISO, SPI_SCLK);
+    *     DigitalOut cs1(D10);
+    *     L6470SDC stepper(&spi1, &cs1);
+    *                      ~~~~~  ~~~~
+    */
     L6470SDC(SPI *spi, DigitalOut *csel);
 
 private:
@@ -84,20 +227,41 @@
     DigitalOut *cs;
 
     bool hasSerial;
-    int motor_count;                                                                                //モーターの総数
+    int motor_count;
 
-    void setCmd(int motorNumber, unsigned char cmdAddress, unsigned long value, int bitLen);        //コマンド実行
-    void setParam(int motorNumber, unsigned char regAddress, unsigned long value, int bitLen);      //パラメーター設定
-    unsigned long getParam(int motorNumber, unsigned char regAddress, int bitLen);                  //パラメーター取得
-    void sendCMD(unsigned char cmd);                                                                //コマンド送信
+    void setCmd(int motorNumber, unsigned char cmdAddress, unsigned long value, int bitLen);
+    void setParam(int motorNumber, unsigned char regAddress, unsigned long value, int bitLen);
+    unsigned long getParam(int motorNumber, unsigned char regAddress, int bitLen);
+    void sendCMD(unsigned char cmd);
 
 public:
-    void init();                                                                                    //初期化
-    int getMotorCount();                                                                            //モーター個数
+    /** Initialize L6470
+    *
+    * @param initSPI If initialize SPI parameters.(e.g. clockspeed and mode) = true(default)
+    */
+    void init(bool initSPI = true);
+
+    /** Get connected(daisy-chained) motor count.
+    *
+    * @returns Connected(daisy-chained) motor count. If not using daisy-chain, return always 1. maybe...
+    */
+    int getMotorCount();
 
-    // cmd method ------------------------------------------------------------------------------
+    /** Get motor Busy-flag status.
+    *
+    * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1.
+    * @returns Busy status.(false = Busy-flag 0, true = Busy-flag 1)
+    */
     bool isBusy(int motorNumber);
+
+    /** Get motor Busy-flag status.
+    *
+    * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1.
+    * @param hex_speed Motor rotate speed(hex_value Step/s). -> please use "calcSpd(stepPerSecond)" method.
+    * @param isClockwise clockwise = true. counter clockwise = false.
+    */
     void run(int motorNumber, unsigned long hex_speed, bool isClockwise);
+
     void step(int motorNumber, unsigned int count, bool isClockwise);
     void move(int motorNumber, unsigned long stepsCount, bool isClockwise);
     void goto1(int motorNumber, unsigned long ABSPos);