MDテスト用プログラム

Dependencies:   FastPWM GMD_template_lib mbed

Fork of NewMD2 by tarou yamada

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Fri Jul 01 06:31:56 2016 +0000
Child:
1:29e84d1e7bcc
Commit message:
??????

Changed in this revision

FastPWM.lib Show annotated file Show diff for this revision Revisions of this file
GMD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FastPWM.lib	Fri Jul 01 06:31:56 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/FastPWM/#87e38b846651
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GMD.lib	Fri Jul 01 06:31:56 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/inst/code/NewMD2_GMD/#010c6f6ac7c0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 01 06:31:56 2016 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "GMD.hpp"
+
+char read_address() {
+    const size_t din_num = 4;
+    DigitalIn din[] = {
+        DigitalIn(dp26),
+        DigitalIn(dp25),
+        DigitalIn(dp18),
+        DigitalIn(dp17)
+    };
+    
+    char address = 0;
+    for (size_t i = 0; i < din_num; ++i) {
+        address |= din[i].read() << (i + 2);
+    }
+    return address;
+}
+
+int main(){
+    I2CSlave i2c(dp5, dp27);
+    i2c.address(read_address());
+    GMD md(dp1, dp2, dp9);
+    
+    while (true){
+        char buf;
+        switch (i2c.receive()){
+            case I2CSlave::ReadAddressed:
+                break;
+            
+            case I2CSlave::WriteGeneral:
+                break;
+            
+            case I2CSlave::WriteAddressed:
+                i2c.read(&buf, 1);
+                
+                float p = (buf & 0x80) ? -1.0f: 1.0f;
+                p *= (buf & 0x7F);
+                p *= 1.0f / 0x7F;
+                
+                md.set(p);
+                break;
+                
+            case I2CSlave::NoData:
+                break;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jul 01 06:31:56 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file