トランジスタ技術2015年6月号mbedラジコン・カーp182 リスト3 音声合成LSIのmbedメイン・プログラム

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
YoshihitoShimada
Date:
Mon Jun 01 02:43:44 2015 +0000
Commit message:
AquesTalk pico test program

Changed in this revision

ATP3012.cpp Show annotated file Show diff for this revision Revisions of this file
ATP3012.h 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
diff -r 000000000000 -r 32f0c58ff820 ATP3012.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ATP3012.cpp	Mon Jun 01 02:43:44 2015 +0000
@@ -0,0 +1,52 @@
+#include "ATP3012.h"
+ 
+ATP3012::ATP3012(PinName sda, PinName scl, int addr):_i2c(sda, scl)
+{
+    _addr = addr;
+    _poll_wait.reset();
+    _poll_wait.start();
+}
+ 
+bool ATP3012::IsActive(int timeout_ms)
+{
+    wait_ms(AQTK_STARTUP_WAIT_MS);
+    Timer t;
+    t.reset();
+    t.start();
+    while(t.read_ms() < timeout_ms) {
+        _poll_wait.reset();
+        if (_i2c.write(_addr, NULL, 0) == 0) {
+            return true;
+        }
+        wait_ms(AQTK_POLL_WAIT_MS);
+    }
+    return false;
+}
+    
+void ATP3012::Synthe(const char* msg)
+{
+    while(IsBusy()) {
+        ;
+    }
+    Write(msg);
+    Write("\r");
+}
+ 
+void ATP3012::Write(const char *msg)
+{
+    _i2c.write(_addr, msg, strlen(msg));    
+    _poll_wait.reset();
+}
+ 
+bool ATP3012::IsBusy()
+{
+    if (AQTK_POLL_WAIT_MS > _poll_wait.read_ms()) {
+        return true;
+    } 
+    _poll_wait.reset();
+    char c = 0x00;
+    if (_i2c.read(_addr, &c, 1) != 0) {
+        return false;
+    }
+    return c == '*' || c == 0xff;
+}
diff -r 000000000000 -r 32f0c58ff820 ATP3012.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ATP3012.h	Mon Jun 01 02:43:44 2015 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#pragma once
+ 
+#define AQTK_I2C_ADDR (0x2E<<1)
+#define AQTK_STARTUP_WAIT_MS 80
+#define AQTK_POLL_WAIT_MS 10
+ 
+/** ATP3012 class
+ *
+ * AquesTalk pico LSI I2C interface
+ * Example:
+ * @code
+ *      #include "ATP3012.h"
+ *      ATP3012 talk(P0_10,P0_11); // I2C sda scl
+ *      
+ *      int main() {
+ *          talk.Synthe("konnichiwa.");
+ *          for(int n = 1; ; n++) {
+ *              char buf[32];
+ *              snprintf(buf, sizeof(buf), "<NUMK VAL=%d>.", n);
+ *              talk.Synthe(buf);
+ *          }
+ *      } 
+ * @endcode
+ *
+ */
+class ATP3012 {
+public:
+    /** Create a AquesTalk pico LSI I2C interface
+     *
+     * @param sda  I2C data pin
+     * @param scl  I2C clock pin
+     * @param addr I2C address
+     */
+    ATP3012(PinName sda, PinName scl, int addr = AQTK_I2C_ADDR);
+    bool IsActive(int timeout_ms = 500);
+    void Synthe(const char* msg);
+    void Write(const char* msg);
+    bool IsBusy();
+private:
+    int _addr;
+    I2C _i2c; 
+    Timer _poll_wait;
+};
+
diff -r 000000000000 -r 32f0c58ff820 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 01 02:43:44 2015 +0000
@@ -0,0 +1,10 @@
+#include "mbed.h"
+#include "ATP3012.h"
+
+ATP3012 talk(P0_5, P0_4); // sda, scl
+
+int main() {
+    talk.Synthe("konosaki;<NUMK VAL=3 COUNTER=kiro>/ju-taichu-.\r");
+    talk.Synthe("tu-kadi'kann;<NUMK VAL=10 COUNTER=funn>de_su.\r");
+    while (1);
+}
\ No newline at end of file
diff -r 000000000000 -r 32f0c58ff820 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jun 01 02:43:44 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file