PlayBack

Dependencies:   TPixy-Interface

Fork of ManualControlFinal by ECE4333 - 2018 - Ahmed & Brandon

Revision:
1:3e9684e81312
Parent:
0:a355e511bc5d
Child:
7:73fd05fe556a
--- a/Drivers/DE0_driver.cpp	Thu Feb 01 03:58:00 2018 +0000
+++ b/Drivers/DE0_driver.cpp	Sat Feb 03 00:05:08 2018 +0000
@@ -13,6 +13,19 @@
 DigitalOut SpiReset(p14);   // 0-1-0 tells the DE0 SPI interace that the next word sent is a control word
 
 
+int SignExtend(int16_t x)
+{
+
+    // if number is negative
+    if(x&0x00008000) {
+        // reserve the sign bit into the 32-bit number
+        x = x|0xFFFF0000;
+    }
+
+    return x;
+}
+
+
 // To reset all SPI peripheral on the FPGA:
 void ResetDE0(void){
     IoReset=0; // Reset all DE0 peripherals
@@ -67,7 +80,7 @@
  */
 
 
-void DE0_read(uint16_t * id, uint16_t * dP, uint16_t * dT)
+void DE0_read(uint16_t * id, int * dP, uint16_t * dT)
 {
     // To place SPI module into control mode, where the next word received by the
     // slave is interpreted as a control word.
@@ -77,8 +90,8 @@
     *id = (uint16_t)DE0.write(0x8002);
     
     // Read the two 16 bits registers from the FPGA 
-    *dP = (uint16_t)DE0.write(DUMMY); // A SPI read only transaction occurs.
-    *dT = (uint16_t)DE0.write(DUMMY); //
+    *dP = SignExtend(DE0.write(DUMMY)); // A SPI read only transaction occurs.
+    *dT = DE0.write(DUMMY); //
 }