AquesTalk pico LSI I2C interface

Dependents:   CanSat-C

音声合成LSI AquesTalk pico ATP3011のI2Cインターフェースです。

main.cpp

#include "mbed.h"
#include "ATP3011.h"
ATP3011 talk(P0_0, P0_1); // sda,scl LPC810
RawSerial pc(P0_4, P0_6); // tx,rx

int main()
{
    if (talk.IsActive()) {
        pc.puts("ATP3011 OK\r\n");
    } else {
        pc.puts("ATP3011 NG\r\n");
        while(1); // forever
    }
    const char* msg = "konnitiwa.";
    pc.puts(msg);pc.puts("\r\n");
    talk.Synthe(msg);
    char buf[32];
    for(int n = 1; ; n++) {
        snprintf(buf, sizeof(buf), "<NUMK VAL=%d>.", n);
        pc.puts(buf);pc.puts("\r\n");
        talk.Synthe(buf);
    }
}


参考:
[Arduino] AquesTalk pico LSI を I2C で制御する | N.Yamazaki's blog
音声記号列生成 Webサービス - AquesTalk - 株式会社アクエスト

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Tue Jan 07 23:57:49 2014 +0000
Commit message:
first commit

Changed in this revision

ATP3011.cpp Show annotated file Show diff for this revision Revisions of this file
ATP3011.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r afbfc810f82e ATP3011.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ATP3011.cpp	Tue Jan 07 23:57:49 2014 +0000
@@ -0,0 +1,52 @@
+#include "ATP3011.h"
+
+ATP3011::ATP3011(PinName sda, PinName scl, int addr):_i2c(sda, scl)
+{
+    _addr = addr;
+    _poll_wait.reset();
+    _poll_wait.start();
+}
+
+bool ATP3011::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 ATP3011::Synthe(const char* msg)
+{
+    while(IsBusy()) {
+        ;
+    }
+    Write(msg);
+    Write("\r");
+}
+
+void ATP3011::Write(const char *msg)
+{
+    _i2c.write(_addr, msg, strlen(msg));    
+    _poll_wait.reset();
+}
+
+bool ATP3011::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 afbfc810f82e ATP3011.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ATP3011.h	Tue Jan 07 23:57:49 2014 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#pragma once
+
+#define AQTK_I2C_ADDR (0x2E<<1)
+#define AQTK_STARTUP_WAIT_MS 80
+#define AQTK_POLL_WAIT_MS 10
+
+/** ATP3011 class
+ *
+ * AquesTalk pico LSI I2C interface
+ * Example:
+ * @code
+ *      #include "ATP3011.h"
+ *      ATP3011 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 ATP3011 {
+public:
+    /** Create a AquesTalk pico LSI I2C interface
+     *
+     * @param sda  I2C data pin
+     * @param scl  I2C clock pin
+     * @param addr I2C address
+     */
+    ATP3011(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;
+};