David Kester / Mbed 2 deprecated GonioTrainer

Dependencies:   mbed commands BLE_API nRF51822

Revision:
3:a3e1a06c486d
Parent:
1:b44bd62c542f
Child:
4:2a5a08b14539
--- a/Storage.cpp	Sat May 30 12:26:02 2015 +0000
+++ b/Storage.cpp	Mon Jun 01 15:41:01 2015 +0000
@@ -17,17 +17,75 @@
     return instance;
 }
 
-int32_t Storage::setup(){
+void Storage::setup(){
+    }
+    
+void Storage::endAction(){
+    cs = 1;
+    }
+    
+bool Storage::setWREN(){
+    cs = 0;
+    spi.write(0x06);
+    cs = 1;
+    
     cs = 0;
- 
-    // Send 0x8f, the command to read the WHOAMI register
-    spi.write(0x00);
+    spi.write(0x05);
+    
+    if(spi.write(0x00) & 0x2){
+        cs = 0;
+        return true;
+    } else {
+        cs = 0;
+        return 1;
+    }
+}
+
+bool Storage::isBusy(){
+    cs = 0;
+    spi.write(0x05);
+    
+    if(spi.write(0x00) & 0x1){
+        cs = 0;
+        return true;
+    } else {
+        cs = 0;
+        return 1;
+    }
+}
  
-    // Send a dummy byte to receive the contents of the WHOAMI register
-    int32_t whoami = spi.write(0x00);
- 
-    // Deselect the device
-    cs = 1;
-    return whoami;
+void Storage::pageProgram(int32_t addr){
+        cs = 0;
+        spi.write(0x12);
+        
+        for(int i = 3; i >= 0; i--){
+            spi.write((addr >> (8*i)) & 0xff);
+        }
+    }
+    
+void Storage::writeData(int8_t data){
+    spi.write(data);
+    }  
+    
+void Storage::read(int32_t addr){
+    cs = 0;
+    
+    spi.write(0x13);
     
-    }
\ No newline at end of file
+    //char[4] bytes;
+    //bytes[0] = (addr >> 24) & 0xff;
+    //bytes[1] = (addr >> 16) & 0xff;
+    //bytes[2] = (addr >> 8) & 0xff;
+    //bytes[3] = addr & 0xff;
+    
+    for(int i = 3; i < 0; i--){
+        spi.write((addr >> (8*i)) & 0xff);
+        }
+    }
+    
+int8_t Storage::readData(){
+    return spi.write(0x00);
+    }
+    
+
+    
\ No newline at end of file