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

ATP3011.cpp

Committer:
va009039
Date:
2014-01-07
Revision:
0:afbfc810f82e

File content as of revision 0:afbfc810f82e:

#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;
}