MorphGI / Mbed OS MGI_Rebuild_MidLevel_9_0-Basic_PWM

Dependencies:   ros_lib_kinetic

Revision:
36:4459be8296e9
Parent:
34:54e9ebe9e87f
Child:
37:37da606f4466
diff -r 54e9ebe9e87f -r 4459be8296e9 LLComms.cpp
--- a/LLComms.cpp	Mon Apr 15 15:12:51 2019 +0000
+++ b/LLComms.cpp	Tue Jul 09 18:46:44 2019 +0000
@@ -4,9 +4,10 @@
 
 LLComms::LLComms() : 
     queue(32 * EVENTS_EVENT_SIZE), //32 //8 * EVENTS_EVENT_SIZE
-    pinGate6(PE_11),
+    pinGate6(PA_5),
     spi_0(PC_12, PC_11, PC_10),
     spi_1(PF_9, PF_8, PF_7),
+    spi_2(PB_15, PC_2, PB_13),
     // These interrupt pins have to be declared AFTER SPI declaration. No Clue Why.
     pinGate0(PF_11),
     pinGate1(PG_14),
@@ -14,28 +15,30 @@
     pinGate3(PF_12),
     pinGate4(PF_3),
     pinGate5(PC_7),
-    //pinGate5(PF_13),
-    //pinGate6(PE_11), // See above nonsense
     pinGate7(PE_13),
-    pinReset(PD_2)
+    pinGate8(PF_4),//PB_3),
+    pinReset(PD_2),
+    chrp(PB_8),
+    chrp1(PC_6)
 { // Constructor
 
     spi_0.format(16,2);
     spi_0.frequency(LOW_LEVEL_SPI_FREQUENCY);
     spi_1.format(16,2);
     spi_1.frequency(LOW_LEVEL_SPI_FREQUENCY);
+    spi_2.format(16,2);
+    spi_2.frequency(LOW_LEVEL_SPI_FREQUENCY);
 
-    PinName LLPins[8] = {PD_15, PE_10, PD_11, PD_14, PE_7, PB_1, PF_10, PD_13};
-    //PinName LLPins[8] = {PD_15, PE_10, PD_11, PD_14, PE_7, PD_12, PF_10, PD_13};
-    //PinName ADCPins[8] = {PG_12, PG_9, PE_1, PG_0, PD_0, PD_1, PF_0, PF_1};
-    for (short int i = 0; i < 8; i++) {
+    //PinName LLPins[N_CHANNELS] = {PD_15, PE_10, PD_11, PD_14, PE_7, PB_1, PF_10, PD_13};
+    PinName LLPins[N_CHANNELS] = {PD_15, PE_10, PD_11, PD_14, PE_7, PB_1, PB_12, PD_13, PB_5};
+    for (short int i=0; i<N_CHANNELS; i++) {
         isDataReady[i] = 0;
         cs_LL[i] = new DigitalOut(LLPins[i]);
         //cs_ADC[i] = new DigitalOut(ADCPins[i]);
     }
     
     // Initialise relevant variables
-    for(short int i = 0; i<N_CHANNELS; i++) {
+    for(short int i=0; i<N_CHANNELS; i++) {
         // All chip selects in off state
         *cs_LL[i] = 1;
         //*cs_ADC[i] = 1;
@@ -60,6 +63,7 @@
     pinGate5.rise(callback(this,&LLComms::rise5));
     pinGate6.rise(callback(this,&LLComms::rise6));
     pinGate7.rise(callback(this,&LLComms::rise7));
+    pinGate8.rise(callback(this,&LLComms::rise8));
     // Set up fall interrupts MIGHT NOT NEED TO BE POINTERS
     pinGate0.fall(callback(this,&LLComms::fall0));
     pinGate1.fall(callback(this,&LLComms::fall1));
@@ -69,6 +73,7 @@
     pinGate5.fall(callback(this,&LLComms::fall5));
     pinGate6.fall(callback(this,&LLComms::fall6));
     pinGate7.fall(callback(this,&LLComms::fall7));
+    pinGate8.fall(callback(this,&LLComms::fall8));
 }
 
 //LLComms::~LLComms(void) { } // Destructor
@@ -163,8 +168,10 @@
     bool isSPIsuccess = false;
     if( channel < 4 ) {
         isSPIsuccess = PerformMasterSPI(&spi_0,outboundMsgs,inboundMsgsData);
+    } else if( channel < 7 ) {//was 7, but should have been 8?
+        isSPIsuccess = PerformMasterSPI(&spi_1,outboundMsgs,inboundMsgsData);
     } else {
-        isSPIsuccess = PerformMasterSPI(&spi_1,outboundMsgs,inboundMsgsData);
+        isSPIsuccess = PerformMasterSPI(&spi_2,outboundMsgs,inboundMsgsData);
     }
     *cs_LL[channel] = 1; // Deselect chip
     if( isSPIsuccess ) {
@@ -185,6 +192,8 @@
 // Common rise handler function 
 void LLComms::common_rise_handler(int channel) {
     //printf("%d %d common_rise_handler\n\r",channel,isDataReady[channel]);
+    if(channel==6) chrp = 1;
+    if(channel==0) chrp1 = 1;
     if (isDataReady[channel]) { // Check if data is ready for transmission
         ThreadID[channel] = queue.call(this,&LLComms::SendReceiveData,channel); // Schedule transmission
     }
@@ -192,6 +201,8 @@
 
 // Common fall handler functions
 void LLComms::common_fall_handler(int channel) {
+    if(channel==6) chrp = 0;
+    if(channel==0) chrp1 = 0;
     queue.cancel(ThreadID[channel]); // Cancel relevant queued event
 }
 
@@ -204,6 +215,7 @@
 void LLComms::rise5(void) { common_rise_handler(5); }
 void LLComms::rise6(void) { common_rise_handler(6); }
 void LLComms::rise7(void) { common_rise_handler(7); }
+void LLComms::rise8(void) { common_rise_handler(8); }
 // Stub fall functions
 void LLComms::fall0(void) { common_fall_handler(0); }
 void LLComms::fall1(void) { common_fall_handler(1); }
@@ -212,4 +224,5 @@
 void LLComms::fall4(void) { common_fall_handler(4); }
 void LLComms::fall5(void) { common_fall_handler(5); }
 void LLComms::fall6(void) { common_fall_handler(6); }
-void LLComms::fall7(void) { common_fall_handler(7); }
\ No newline at end of file
+void LLComms::fall7(void) { common_fall_handler(7); }
+void LLComms::fall8(void) { common_fall_handler(8); }
\ No newline at end of file