Yoji KURODA / AD7490

Files at this revision

API Documentation at this revision

Comitter:
ykuroda
Date:
Wed Aug 29 14:10:30 2012 +0000
Parent:
0:95be7403a10c
Child:
2:a547c48d2152
Commit message:
Just refine the code

Changed in this revision

AD7490.cpp Show annotated file Show diff for this revision Revisions of this file
AD7490.h Show annotated file Show diff for this revision Revisions of this file
--- a/AD7490.cpp	Wed Aug 29 11:01:51 2012 +0000
+++ b/AD7490.cpp	Wed Aug 29 14:10:30 2012 +0000
@@ -5,7 +5,7 @@
 :   spi(_spi),
     cs(_cs)
 {
-    short x = 0;
+    unsigned short x = 0;
 
     for(int i=0; i<3; i++){
  
@@ -23,7 +23,7 @@
         x |= CREG_CODING;
      
         cs = 0;
-        ret = spi.write(x<<4);
+        unsigned short ret = spi.write(x<<4);
         cs = 1;
     
 //        printf("INIT: send = 0x%X, ret = 0x%X\n", x, ret);
@@ -53,7 +53,7 @@
     x |= CREG_CODING;
 
     cs = 0;
-    ret = spi.write(x<<4);
+    unsigned short ret = spi.write(x<<4);
     cs = 1;
 
 //    printf("send = 0x%X, ch = %2d, ret = %d\n", x, (ret>>12)&0xF, ret&0xFFF);
@@ -92,7 +92,7 @@
     x |= CREG_CODING;
 
     cs = 0;
-    ret = spi.write(x<<4);
+    unsigned short ret = spi.write(x<<4);
     cs = 1;
 
     return ret;
@@ -119,7 +119,7 @@
 //    x |= CREG_CODING;
 
     cs = 0;
-    ret = spi.write(x<<4);
+    unsigned short ret = spi.write(x<<4);
     cs = 1;
 
 //    printf("send = 0x%X, ch = %2d, ret = %d\n", x, (ret>>12)&0xF, ret&0xFFF);
@@ -137,43 +137,3 @@
         data[ ret>>12&0xF ] = ret&0xFFF;
     }
 }
-
-
-
-
-
-
-#if 0
-int main() {
-
-    wait(1);
-
-    // set up SPI interface
-    SPI spi(p11,p12,p13);
-    spi.format(16,0);
-    spi.frequency(1000000);
-
-    AD7490 ad1(spi, p9);
-    AD7490 ad2(spi, p10);
-
-    while(1) {
-
-        int ret=0;
-        for(int ch=0; ch<16; ch++){
-            ret = ad1.convert(ch);
-            printf("ch=%2d, ret= %d, %f\n", (ret>>12)&0xF, ret&0xFFF, 3.3*(float)(ret&0xFFF)/0xFFF);
-        }
-        printf("\n");
-        for(int ch=0; ch<16; ch++){
-            ret = ad2.convert(ch);
-            printf("ch=%2d, ret= %d, %f\n", (ret>>12)&0xF, ret&0xFFF, 3.3*(float)(ret&0xFFF)/0xFFF);
-        }
-        printf("\n");
-
-        myled = 1;
-        wait(0.1);
-        myled = 0;
-        wait(0.9);
-    }
-}
-#endif
--- a/AD7490.h	Wed Aug 29 11:01:51 2012 +0000
+++ b/AD7490.h	Wed Aug 29 14:10:30 2012 +0000
@@ -6,22 +6,23 @@
 
 class AD7490 {
   protected:
-    #define CREG_WRITE    0x800
-    #define CREG_SEQ      0x400
-    #define CREG_ADD3     0x200
-    #define CREG_ADD2     0x100
-    #define CREG_ADD1     0x080
-    #define CREG_ADD0     0x040
-    #define CREG_PM1      0x020
-    #define CREG_PM0      0x010
-    #define CREG_SHADOW   0x008
-    #define CREG_WEAK     0x004
-    #define CREG_RANGE    0x002
-    #define CREG_CODING   0x001
-
+    enum CREG {
+        CREG_WRITE  = 0x800,
+        CREG_SEQ    = 0x400,
+        CREG_ADD3   = 0x200,
+        CREG_ADD2   = 0x100,
+        CREG_ADD1   = 0x080,
+        CREG_ADD0   = 0x040,
+        CREG_PM1    = 0x020,
+        CREG_PM0    = 0x010,
+        CREG_SHADOW = 0x008,
+        CREG_WEAK   = 0x004,
+        CREG_RANGE  = 0x002,
+        CREG_CODING = 0x001
+    };
+    
     SPI spi;
     DigitalOut cs;
-    short ret;
     
   public:
     AD7490(SPI _spi, PinName _cs);
@@ -34,40 +35,4 @@
     void read(short data[]);
 };
 
-
-#if 0
-int main() {
-
-    wait(1);
-
-    // set up SPI interface
-    SPI spi(p11,p12,p13);
-    spi.format(16,0);
-    spi.frequency(1000000);
-
-    AD7490 ad1(spi, p9);
-    AD7490 ad2(spi, p10);
-
-    while(1) {
-
-        int ret=0;
-        for(int ch=0; ch<16; ch++){
-            ret = ad1.convert(ch);
-            printf("ch=%2d, ret= %d, %f\n", (ret>>12)&0xF, ret&0xFFF, 3.3*(float)(ret&0xFFF)/0xFFF);
-        }
-        printf("\n");
-        for(int ch=0; ch<16; ch++){
-            ret = ad2.convert(ch);
-            printf("ch=%2d, ret= %d, %f\n", (ret>>12)&0xF, ret&0xFFF, 3.3*(float)(ret&0xFFF)/0xFFF);
-        }
-        printf("\n");
-
-        myled = 1;
-        wait(0.1);
-        myled = 0;
-        wait(0.9);
-    }
-}
-#endif  // test main
-
-#endif  // _AD7490_H
+#endif  // _AD7490_H
\ No newline at end of file