トランジスタ技術2015年6月号mbedラジコン・カーp182 リスト3 音声合成LSIのmbedメイン・プログラム
Dependencies: mbed
ATP3012.cpp@0:32f0c58ff820, 2015-06-01 (annotated)
- Committer:
- YoshihitoShimada
- Date:
- Mon Jun 01 02:43:44 2015 +0000
- Revision:
- 0:32f0c58ff820
AquesTalk pico test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YoshihitoShimada | 0:32f0c58ff820 | 1 | #include "ATP3012.h" |
YoshihitoShimada | 0:32f0c58ff820 | 2 | |
YoshihitoShimada | 0:32f0c58ff820 | 3 | ATP3012::ATP3012(PinName sda, PinName scl, int addr):_i2c(sda, scl) |
YoshihitoShimada | 0:32f0c58ff820 | 4 | { |
YoshihitoShimada | 0:32f0c58ff820 | 5 | _addr = addr; |
YoshihitoShimada | 0:32f0c58ff820 | 6 | _poll_wait.reset(); |
YoshihitoShimada | 0:32f0c58ff820 | 7 | _poll_wait.start(); |
YoshihitoShimada | 0:32f0c58ff820 | 8 | } |
YoshihitoShimada | 0:32f0c58ff820 | 9 | |
YoshihitoShimada | 0:32f0c58ff820 | 10 | bool ATP3012::IsActive(int timeout_ms) |
YoshihitoShimada | 0:32f0c58ff820 | 11 | { |
YoshihitoShimada | 0:32f0c58ff820 | 12 | wait_ms(AQTK_STARTUP_WAIT_MS); |
YoshihitoShimada | 0:32f0c58ff820 | 13 | Timer t; |
YoshihitoShimada | 0:32f0c58ff820 | 14 | t.reset(); |
YoshihitoShimada | 0:32f0c58ff820 | 15 | t.start(); |
YoshihitoShimada | 0:32f0c58ff820 | 16 | while(t.read_ms() < timeout_ms) { |
YoshihitoShimada | 0:32f0c58ff820 | 17 | _poll_wait.reset(); |
YoshihitoShimada | 0:32f0c58ff820 | 18 | if (_i2c.write(_addr, NULL, 0) == 0) { |
YoshihitoShimada | 0:32f0c58ff820 | 19 | return true; |
YoshihitoShimada | 0:32f0c58ff820 | 20 | } |
YoshihitoShimada | 0:32f0c58ff820 | 21 | wait_ms(AQTK_POLL_WAIT_MS); |
YoshihitoShimada | 0:32f0c58ff820 | 22 | } |
YoshihitoShimada | 0:32f0c58ff820 | 23 | return false; |
YoshihitoShimada | 0:32f0c58ff820 | 24 | } |
YoshihitoShimada | 0:32f0c58ff820 | 25 | |
YoshihitoShimada | 0:32f0c58ff820 | 26 | void ATP3012::Synthe(const char* msg) |
YoshihitoShimada | 0:32f0c58ff820 | 27 | { |
YoshihitoShimada | 0:32f0c58ff820 | 28 | while(IsBusy()) { |
YoshihitoShimada | 0:32f0c58ff820 | 29 | ; |
YoshihitoShimada | 0:32f0c58ff820 | 30 | } |
YoshihitoShimada | 0:32f0c58ff820 | 31 | Write(msg); |
YoshihitoShimada | 0:32f0c58ff820 | 32 | Write("\r"); |
YoshihitoShimada | 0:32f0c58ff820 | 33 | } |
YoshihitoShimada | 0:32f0c58ff820 | 34 | |
YoshihitoShimada | 0:32f0c58ff820 | 35 | void ATP3012::Write(const char *msg) |
YoshihitoShimada | 0:32f0c58ff820 | 36 | { |
YoshihitoShimada | 0:32f0c58ff820 | 37 | _i2c.write(_addr, msg, strlen(msg)); |
YoshihitoShimada | 0:32f0c58ff820 | 38 | _poll_wait.reset(); |
YoshihitoShimada | 0:32f0c58ff820 | 39 | } |
YoshihitoShimada | 0:32f0c58ff820 | 40 | |
YoshihitoShimada | 0:32f0c58ff820 | 41 | bool ATP3012::IsBusy() |
YoshihitoShimada | 0:32f0c58ff820 | 42 | { |
YoshihitoShimada | 0:32f0c58ff820 | 43 | if (AQTK_POLL_WAIT_MS > _poll_wait.read_ms()) { |
YoshihitoShimada | 0:32f0c58ff820 | 44 | return true; |
YoshihitoShimada | 0:32f0c58ff820 | 45 | } |
YoshihitoShimada | 0:32f0c58ff820 | 46 | _poll_wait.reset(); |
YoshihitoShimada | 0:32f0c58ff820 | 47 | char c = 0x00; |
YoshihitoShimada | 0:32f0c58ff820 | 48 | if (_i2c.read(_addr, &c, 1) != 0) { |
YoshihitoShimada | 0:32f0c58ff820 | 49 | return false; |
YoshihitoShimada | 0:32f0c58ff820 | 50 | } |
YoshihitoShimada | 0:32f0c58ff820 | 51 | return c == '*' || c == 0xff; |
YoshihitoShimada | 0:32f0c58ff820 | 52 | } |