AquesTalk pico LSI I2C interface

音声合成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 - 株式会社アクエスト

Committer:
va009039
Date:
Tue Jan 07 23:57:49 2014 +0000
Revision:
0:afbfc810f82e
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:afbfc810f82e 1 #include "ATP3011.h"
va009039 0:afbfc810f82e 2
va009039 0:afbfc810f82e 3 ATP3011::ATP3011(PinName sda, PinName scl, int addr):_i2c(sda, scl)
va009039 0:afbfc810f82e 4 {
va009039 0:afbfc810f82e 5 _addr = addr;
va009039 0:afbfc810f82e 6 _poll_wait.reset();
va009039 0:afbfc810f82e 7 _poll_wait.start();
va009039 0:afbfc810f82e 8 }
va009039 0:afbfc810f82e 9
va009039 0:afbfc810f82e 10 bool ATP3011::IsActive(int timeout_ms)
va009039 0:afbfc810f82e 11 {
va009039 0:afbfc810f82e 12 wait_ms(AQTK_STARTUP_WAIT_MS);
va009039 0:afbfc810f82e 13 Timer t;
va009039 0:afbfc810f82e 14 t.reset();
va009039 0:afbfc810f82e 15 t.start();
va009039 0:afbfc810f82e 16 while(t.read_ms() < timeout_ms) {
va009039 0:afbfc810f82e 17 _poll_wait.reset();
va009039 0:afbfc810f82e 18 if (_i2c.write(_addr, NULL, 0) == 0) {
va009039 0:afbfc810f82e 19 return true;
va009039 0:afbfc810f82e 20 }
va009039 0:afbfc810f82e 21 wait_ms(AQTK_POLL_WAIT_MS);
va009039 0:afbfc810f82e 22 }
va009039 0:afbfc810f82e 23 return false;
va009039 0:afbfc810f82e 24 }
va009039 0:afbfc810f82e 25
va009039 0:afbfc810f82e 26 void ATP3011::Synthe(const char* msg)
va009039 0:afbfc810f82e 27 {
va009039 0:afbfc810f82e 28 while(IsBusy()) {
va009039 0:afbfc810f82e 29 ;
va009039 0:afbfc810f82e 30 }
va009039 0:afbfc810f82e 31 Write(msg);
va009039 0:afbfc810f82e 32 Write("\r");
va009039 0:afbfc810f82e 33 }
va009039 0:afbfc810f82e 34
va009039 0:afbfc810f82e 35 void ATP3011::Write(const char *msg)
va009039 0:afbfc810f82e 36 {
va009039 0:afbfc810f82e 37 _i2c.write(_addr, msg, strlen(msg));
va009039 0:afbfc810f82e 38 _poll_wait.reset();
va009039 0:afbfc810f82e 39 }
va009039 0:afbfc810f82e 40
va009039 0:afbfc810f82e 41 bool ATP3011::IsBusy()
va009039 0:afbfc810f82e 42 {
va009039 0:afbfc810f82e 43 if (AQTK_POLL_WAIT_MS > _poll_wait.read_ms()) {
va009039 0:afbfc810f82e 44 return true;
va009039 0:afbfc810f82e 45 }
va009039 0:afbfc810f82e 46 _poll_wait.reset();
va009039 0:afbfc810f82e 47 char c = 0x00;
va009039 0:afbfc810f82e 48 if (_i2c.read(_addr, &c, 1) != 0) {
va009039 0:afbfc810f82e 49 return false;
va009039 0:afbfc810f82e 50 }
va009039 0:afbfc810f82e 51 return c == '*' || c == 0xff;
va009039 0:afbfc810f82e 52 }