Library to use my Photo MOS Relays Circuit having 16 or less channels.

Fork of PMRC4ch by Akifumi Takahashi

Revision:
21:fa067e2a30f2
Parent:
20:26972de3cf90
Child:
22:4aad836d3333
--- a/PMRC16ch.h	Thu Jun 28 08:49:54 2018 +0000
+++ b/PMRC16ch.h	Tue Oct 23 15:10:56 2018 +0000
@@ -42,7 +42,9 @@
  *  Log
  *  ver.1   2016/dec/11-
  *  ch.16 VER.
- *  ver.16.1   2018/jun/01-
+ *  ver.16.1    2018/jun/01-
+ *  ver.16.2    2018/jun/28-
+ *      major change
  */
 #include "mbed.h"
 class PMRC16ch
@@ -53,6 +55,9 @@
     //
     PMRC16ch();
     PMRC16ch(
+        uint8_t arg_num_ch
+    );
+    PMRC16ch(
         uint8_t arg_num_ch,
         PinName arg_SCK,
         PinName arg_CLR,
@@ -63,73 +68,90 @@
 
     //  Const.
     enum State {
-        ALLGROUND = 0,
-        CH1 = /*1V*/0b10000000/**/00000000/**/00000000/**/00000000/*16G*/,
-        CH2 = /*1V*/0b00100000/**/00000000/**/00000000/**/00000000/*16G*/,
-        CH3 = /*1V*/0b00001000/**/00000000/**/00000000/**/00000000/*16G*/,
-        CH4 = /*1V*/0b00000010/**/00000000/**/00000000/**/00000000/*16G*/,
-        CH5 = /*1V*/0b00000000/**/10000000/**/00000000/**/00000000/*16G*/,
-        CH6 = /*1V*/0b00000000/**/00100000/**/00000000/**/00000000/*16G*/,
-        CH7 = /*1V*/0b00000000/**/00001000/**/00000000/**/00000000/*16G*/,
-        CH8 = /*1V*/0b00000000/**/00000010/**/00000000/**/00000000/*16G*/,
-        CH9 = /*1V*/0b00000000/**/00000000/**/10000000/**/00000000/*16G*/,
-        CH10= /*1V*/0b00000000/**/00000000/**/00100000/**/00000000/*16G*/,
-        CH11= /*1V*/0b00000000/**/00000000/**/00001000/**/00000000/*16G*/,
-        CH12= /*1V*/0b00000000/**/00000000/**/00000010/**/00000000/*16G*/,
-        CH13= /*1V*/0b00000000/**/00000000/**/00000000/**/10000000/*16G*/,
-        CH14= /*1V*/0b00000000/**/00000000/**/00000000/**/00100000/*16G*/,
-        CH15= /*1V*/0b00000000/**/00000000/**/00000000/**/00001000/*16G*/,
-        CH16= /*1V*/0b00000000/**/00000000/**/00000000/**/00000010/*16G*/,
-        ALLHiZ = 9999
+        ALLGROUND = 0x55555555,
+        CH1 = /*1V*/0b10000000000000000000000000000000/*16G*/,
+        CH2 = /*1V*/0b00100000000000000000000000000000/*16G*/,
+        CH3 = /*1V*/0b00001000000000000000000000000000/*16G*/,
+        CH4 = /*1V*/0b00000010000000000000000000000000/*16G*/,
+        CH5 = /*1V*/0b00000000100000000000000000000000/*16G*/,
+        CH6 = /*1V*/0b00000000001000000000000000000000/*16G*/,
+        CH7 = /*1V*/0b00000000000010000000000000000000/*16G*/,
+        CH8 = /*1V*/0b00000000000000100000000000000000/*16G*/,
+        CH9 = /*1V*/0b00000000000000001000000000000000/*16G*/,
+        CH10= /*1V*/0b00000000000000000010000000000000/*16G*/,
+        CH11= /*1V*/0b00000000000000000000100000000000/*16G*/,
+        CH12= /*1V*/0b00000000000000000000001000000000/*16G*/,
+        CH13= /*1V*/0b00000000000000000000000010000000/*16G*/,
+        CH14= /*1V*/0b00000000000000000000000000100000/*16G*/,
+        CH15= /*1V*/0b00000000000000000000000000001000/*16G*/,
+        CH16= /*1V*/0b00000000000000000000000000000010/*16G*/,
+        ALLHiZ    = 0x00000000
     };
     enum Polarity {Anodic = 0, Cathodic = 1};
+    enum StimMode {ONE_VS_THEOTHERS, TWIN_ELECTRODES};
     //
-    //  Function to set channel
+    //  Function to prepare channels
     //
     void allGround();
     void allHiZ();
-    void setCh(char ch, Polarity cp = Cathodic);
-    void setBits(uint32_t bits, int num_of_bits, Polarity cp = Cathodic);
+    void setPol(Polarity pol);  //inline definition
+    void setOvsO(char ch);
+    void setTwin(char stim_ch, char ref_ch);
     //
     //  Function to get prameter
     //
-    uint32_t getState();//inline definition
-    bool getPol();  //inline definition
+    uint32_t getState();        //inline definition
+    bool getPol();              //inline definition
 
 private:
+    //  The number of channels to use
+    const uint8_t m_num_ch;
     //
     //  Sig var to controll PRM circuit
     //
-    uint8_t m_num_ch;   //  The number of channels to use
     DigitalOut m_SCK;   //  Shift-resister's clock
     DigitalOut m_CLR;   //  To use when you want to clear shift-resister
     DigitalOut m_RCK;   //  FF's clock
     DigitalOut m_SER;   //  Serial input to shift data in a shift-resister
     DigitalIn  m_OUT;   //  Output data overflowed from shift-resister
+    //
+    // Var of state
+    //
+    //  Position of stimulation bits
+    //  0: no stimbits, 1~m_num_ch: channel of stimulation
+    uint32_t m_pos_stim;
+    static const uint32_t m_statearray[];
+    uint32_t m_PMRC_state;
+    Polarity m_PMRC_POL;
+    StimMode m_PMRC_mode;
     //  Initialization
     void init();
     //
-    //  Function to set channel
+    //  Function to control buffer of shift-resister
     //
     //  shift the bits arbitary times
     void shiftby(int times);
-    //  this is the function with which to rapidly set it all-off
+    //  the function with which to rapidly set it all-ground
     void sweep();
     //  set the simulation bits of 01
     void setStimbits();
+    //  set all bits arbitarily
+    void setBits(const uint32_t bits);
+    //
+    //  Clock Function
+    //
     //update the clock of shift-resister
     void update();
     //  output the data by uploading them to FF Resitors
     void upload();
-    //
-    // Var for store state
-    //
-    uint32_t m_PMRC_state;
-    Polarity m_PMRC_POL;
 };
+inline void PMRC16ch::setPol(Polarity arg_pol)
+{
+    m_PMRC_POL = arg_pol;
+}
 inline uint32_t PMRC16ch::getState()
 {
-    return static_cast<uint32_t>(m_PMRC_state);
+    return m_PMRC_state;
 }
 inline bool PMRC16ch::getPol()
 {