Stand Alone mBed OS Text To Speech Click Board Example

Fork of Hexi_Click_Relay-v3_Example by Hexiwear

Committer:
daveyclk
Date:
Wed Oct 26 16:36:28 2016 +0000
Revision:
2:84ca2f63ecdf
Parent:
1:070fc531e5cb
Small update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daveyclk 1:070fc531e5cb 1 /****************************************************************************
daveyclk 1:070fc531e5cb 2 * Title : Hexiware Text To Speech Click
daveyclk 1:070fc531e5cb 3 * Filename : Hexi_talking_one_main
daveyclk 1:070fc531e5cb 4 * Author : Dave Clarke
daveyclk 1:070fc531e5cb 5 * Origin Date : 26/10/2016
daveyclk 1:070fc531e5cb 6 * Notes : mBed OS Text to Speech Click Interface (rough)
daveyclk 1:070fc531e5cb 7 *****************************************************************************/
daveyclk 1:070fc531e5cb 8 /**************************CHANGE LIST **************************************
daveyclk 1:070fc531e5cb 9 *
daveyclk 1:070fc531e5cb 10 * Date Software Version Initials Description
daveyclk 1:070fc531e5cb 11 * 26/10/16 1.0.0 DC Interface Created.
daveyclk 1:070fc531e5cb 12 *
daveyclk 1:070fc531e5cb 13 *****************************************************************************/
daveyclk 1:070fc531e5cb 14
daveyclk 1:070fc531e5cb 15 /**
daveyclk 1:070fc531e5cb 16 * @page TEST_CFG Test Configurations
daveyclk 1:070fc531e5cb 17 * <h3> Test configuration : </h3>
daveyclk 1:070fc531e5cb 18 * @par
daveyclk 1:070fc531e5cb 19 * <ul>
daveyclk 1:070fc531e5cb 20 * <li><b> MCU </b> : MK64FN1M0XXX12 </li>
daveyclk 1:070fc531e5cb 21 * <li><b> Dev. Board </b> : HEXIWEAR </li>
daveyclk 1:070fc531e5cb 22 * <li><b> Oscillator </b> : 12 MHz external </li>
daveyclk 1:070fc531e5cb 23 * <li><b> Ext. Modules </b> : none </li>
daveyclk 1:070fc531e5cb 24 * <li><b> Ext. Modules </b> : TTS Click on mikroBUS 2 </li>
daveyclk 1:070fc531e5cb 25 * <li><b> SW </b> : mBed OS5 </li>
daveyclk 1:070fc531e5cb 26 * </ul>
daveyclk 1:070fc531e5cb 27 */
daveyclk 1:070fc531e5cb 28
daveyclk 1:070fc531e5cb 29 /**
daveyclk 1:070fc531e5cb 30 * @mainpage
daveyclk 1:070fc531e5cb 31 * <h3> Text To Speech with HEXIWEAR and mBed OS 5 </h3>
daveyclk 1:070fc531e5cb 32 * @par Using mBed)S and a Hexiware you can now use the Text To Speech Click Board
daveyclk 1:070fc531e5cb 33 *
daveyclk 1:070fc531e5cb 34 *
daveyclk 1:070fc531e5cb 35 *
daveyclk 1:070fc531e5cb 36
daveyclk 1:070fc531e5cb 37 * <h3> Speech Features </h3>
daveyclk 1:070fc531e5cb 38 * @par Text to Speech Click, Hexiwear docking station, Hexiware
daveyclk 1:070fc531e5cb 39 */
daveyclk 1:070fc531e5cb 40
daveyclk 1:070fc531e5cb 41 /******************************************************************************
daveyclk 1:070fc531e5cb 42 * Includes
daveyclk 1:070fc531e5cb 43 *******************************************************************************/
GregC 0:ac93d26bbdb5 44
GregC 0:ac93d26bbdb5 45 #include "mbed.h"
daveyclk 1:070fc531e5cb 46 #include "text_to_speech.h"
daveyclk 1:070fc531e5cb 47 #include "text_to_speech_hal.h"
daveyclk 1:070fc531e5cb 48 #include "text_to_speech_hw.h"
daveyclk 1:070fc531e5cb 49 #include "text_to_speech_img.h"
daveyclk 1:070fc531e5cb 50 #include "string.h"
daveyclk 1:070fc531e5cb 51 #include <stdbool.h>
daveyclk 1:070fc531e5cb 52 #include <stdlib.h>
daveyclk 1:070fc531e5cb 53
daveyclk 1:070fc531e5cb 54
daveyclk 1:070fc531e5cb 55
daveyclk 1:070fc531e5cb 56
daveyclk 1:070fc531e5cb 57 /******************************************************************************
daveyclk 1:070fc531e5cb 58 * Module Variable Definitions
daveyclk 1:070fc531e5cb 59 *******************************************************************************/
daveyclk 1:070fc531e5cb 60 /* Indication Flags */
daveyclk 1:070fc531e5cb 61 static volatile bool _tts_rdy_f;
daveyclk 1:070fc531e5cb 62 static volatile bool _spc_rdy_f;
daveyclk 1:070fc531e5cb 63 static volatile bool _tts_fin_f;
daveyclk 1:070fc531e5cb 64 static volatile bool _spc_fin_f;
daveyclk 1:070fc531e5cb 65 /* Error Buffers */
daveyclk 1:070fc531e5cb 66 static uint16_t _req_err;
daveyclk 1:070fc531e5cb 67 static uint16_t _err_code;
daveyclk 1:070fc531e5cb 68 /* Default Configuration */
daveyclk 1:070fc531e5cb 69 static ACONF_t _audio_conf;
daveyclk 1:070fc531e5cb 70 static TTSCONF_t _tts_conf;
daveyclk 1:070fc531e5cb 71 static PMANCONF_t _pman_conf;
GregC 0:ac93d26bbdb5 72
daveyclk 1:070fc531e5cb 73 static bool _flush_enable;
daveyclk 1:070fc531e5cb 74 /* Timer flag and counter */
daveyclk 1:070fc531e5cb 75 static volatile bool _ticker_f;
daveyclk 1:070fc531e5cb 76 static volatile uint16_t _ticker;
daveyclk 1:070fc531e5cb 77 /* Input and output buffers */
daveyclk 1:070fc531e5cb 78 static ISC_REQ_t _last_req;
daveyclk 1:070fc531e5cb 79 static ISC_RESP_t _last_rsp;
daveyclk 1:070fc531e5cb 80 /* Text Buffer */
daveyclk 1:070fc531e5cb 81 char text[20];
daveyclk 1:070fc531e5cb 82 static uint8_t test[ 8 ] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
daveyclk 1:070fc531e5cb 83 int frequency = 750000;
daveyclk 1:070fc531e5cb 84 VER_t *version;
daveyclk 1:070fc531e5cb 85 /******************************************************************************
daveyclk 1:070fc531e5cb 86 * Function Prototypes
daveyclk 1:070fc531e5cb 87 *******************************************************************************/
daveyclk 1:070fc531e5cb 88 /* Checks for indications */
daveyclk 1:070fc531e5cb 89 static int _parse_ind( void );
daveyclk 1:070fc531e5cb 90 /* Message block and error callback function pointers */
daveyclk 1:070fc531e5cb 91 static void ( *_fatal_err_callback )( uint16_t *err_code );
daveyclk 1:070fc531e5cb 92 static void ( *_err_callback )( uint16_t *err_code );
daveyclk 1:070fc531e5cb 93 static void ( *_msg_block_callback )( uint16_t *msg_code,
daveyclk 1:070fc531e5cb 94 uint16_t *err_code );
daveyclk 1:070fc531e5cb 95
daveyclk 1:070fc531e5cb 96
daveyclk 1:070fc531e5cb 97 /* Instantiate the Click Text to Speech pinout */
daveyclk 1:070fc531e5cb 98 DigitalOut TTS_RST(PTB19);
daveyclk 1:070fc531e5cb 99 DigitalOut TTS_CS(PTC3);
daveyclk 1:070fc531e5cb 100 DigitalOut TTS_MUTE(PTB3);
daveyclk 1:070fc531e5cb 101 DigitalIn TTS_RDY(PTB8);
daveyclk 1:070fc531e5cb 102
daveyclk 1:070fc531e5cb 103 //Instantiate SPI for comms with Speak module
daveyclk 1:070fc531e5cb 104 SPI TextToSpeech(PTC6, PTC7, PTC5); // MOSI, MISO, SCK
daveyclk 1:070fc531e5cb 105
daveyclk 1:070fc531e5cb 106
daveyclk 1:070fc531e5cb 107 // Debug Serial
daveyclk 1:070fc531e5cb 108 Serial pc(USBTX, USBRX);
daveyclk 1:070fc531e5cb 109
daveyclk 1:070fc531e5cb 110 void SysInit(void)
daveyclk 1:070fc531e5cb 111 {
daveyclk 1:070fc531e5cb 112 tts_hal_cs_high();
daveyclk 1:070fc531e5cb 113 TextToSpeech.format(8,3);
daveyclk 1:070fc531e5cb 114 TextToSpeech.frequency(frequency);
GregC 0:ac93d26bbdb5 115
daveyclk 1:070fc531e5cb 116
daveyclk 1:070fc531e5cb 117 }
daveyclk 1:070fc531e5cb 118
daveyclk 1:070fc531e5cb 119 void fatal_err( uint16_t *err );
daveyclk 1:070fc531e5cb 120 void msg_blk( uint16_t *req, uint16_t *err );
GregC 0:ac93d26bbdb5 121
daveyclk 1:070fc531e5cb 122 int main()
daveyclk 1:070fc531e5cb 123 {
daveyclk 1:070fc531e5cb 124
daveyclk 1:070fc531e5cb 125 SysInit();
daveyclk 1:070fc531e5cb 126 pc.printf("System Init Done!\r\n");
daveyclk 1:070fc531e5cb 127 tts_init();
daveyclk 1:070fc531e5cb 128 pc.printf("tts Init Done!\r\n");
daveyclk 1:070fc531e5cb 129 tts_setup();
daveyclk 1:070fc531e5cb 130 pc.printf("tts setup Done!\r\n");
daveyclk 1:070fc531e5cb 131 tts_msg_block_callback( msg_blk );
daveyclk 1:070fc531e5cb 132 tts_fatal_err_callback( fatal_err );
daveyclk 1:070fc531e5cb 133 tts_config( 0x01, false, TTSV_US, 0x0090 );
daveyclk 1:070fc531e5cb 134 //tts_mute();
daveyclk 1:070fc531e5cb 135 //tts_speak( "[:nw][:dv ap 195 pr 80]" );
daveyclk 1:070fc531e5cb 136 //tts_speak( "[:np][:dv ap 100 pr 50]" );
daveyclk 1:070fc531e5cb 137 //tts_speak( "[:nw]" );
daveyclk 1:070fc531e5cb 138 //wait( 2 );
daveyclk 1:070fc531e5cb 139 //tts_unmute();
daveyclk 1:070fc531e5cb 140
daveyclk 1:070fc531e5cb 141 while(1)
daveyclk 1:070fc531e5cb 142 {
daveyclk 1:070fc531e5cb 143 /* frozen
daveyclk 1:070fc531e5cb 144 verse one
daveyclk 1:070fc531e5cb 145 tts_speak( "The snow glows white on the mountain tonight, Not a footprint to be seen. " );
daveyclk 1:070fc531e5cb 146 wait(0.1);
daveyclk 1:070fc531e5cb 147 tts_speak( "A kingdom of isolation, and it looks like I'm the Queen. " );
daveyclk 1:070fc531e5cb 148 wait(0.1);
daveyclk 1:070fc531e5cb 149 tts_speak( "The wind is howling like this swirling storm inside. " );
daveyclk 1:070fc531e5cb 150 wait(0.1);
daveyclk 1:070fc531e5cb 151 tts_speak( "Couldn't keep it in. " );
daveyclk 1:070fc531e5cb 152 wait(0.1);
daveyclk 1:070fc531e5cb 153 tts_speak( "Heaven knows I've tried. " );
daveyclk 1:070fc531e5cb 154 wait(0.1);
daveyclk 1:070fc531e5cb 155 tts_speak( "Don't let them in, don't let them see. " );
daveyclk 1:070fc531e5cb 156 wait(0.1);
daveyclk 1:070fc531e5cb 157 tts_speak( "Be the good girl you always have to be. " );
daveyclk 1:070fc531e5cb 158 wait(0.1);
daveyclk 1:070fc531e5cb 159 tts_speak( "Conceal, don't feel, don't let them know. " );
daveyclk 1:070fc531e5cb 160 wait(0.1);
daveyclk 1:070fc531e5cb 161 tts_speak( "Well now they know. " );
daveyclk 1:070fc531e5cb 162 wait(0.1);
daveyclk 1:070fc531e5cb 163
daveyclk 1:070fc531e5cb 164 chorus one
daveyclk 1:070fc531e5cb 165 tts_speak( "Let it go, let it go. " );
daveyclk 1:070fc531e5cb 166 wait(0.1);
daveyclk 1:070fc531e5cb 167 tts_speak( "Can't hold it back anymore. " );
daveyclk 1:070fc531e5cb 168 wait(0.1);
daveyclk 1:070fc531e5cb 169 tts_speak( "I don't care " );
daveyclk 1:070fc531e5cb 170 wait(0.1);
daveyclk 1:070fc531e5cb 171 tts_speak( "what they're going to say" );
daveyclk 1:070fc531e5cb 172 wait(0.1);
daveyclk 1:070fc531e5cb 173 tts_speak( "Let the storm rage on." );
daveyclk 1:070fc531e5cb 174 wait(0.1);
daveyclk 1:070fc531e5cb 175 tts_speak( "The cold never bothered me anyway" );
daveyclk 1:070fc531e5cb 176 wait(0.1);
daveyclk 1:070fc531e5cb 177
daveyclk 1:070fc531e5cb 178 verse two
daveyclk 1:070fc531e5cb 179 tts_speak( "It's funny how some distance " );
daveyclk 1:070fc531e5cb 180 wait(0.1);
daveyclk 1:070fc531e5cb 181 tts_speak( "Makes everything seem small " );
daveyclk 1:070fc531e5cb 182 wait(0.1);
daveyclk 1:070fc531e5cb 183 tts_speak( "And the fears that once controlled me " );
daveyclk 1:070fc531e5cb 184 wait(0.1);
daveyclk 1:070fc531e5cb 185 tts_speak( "Can't get to me at all " );
daveyclk 1:070fc531e5cb 186 wait(0.1);
daveyclk 1:070fc531e5cb 187 tts_speak( "It's time to see what I can do " );
daveyclk 1:070fc531e5cb 188 wait(0.1);
daveyclk 1:070fc531e5cb 189 tts_speak( "To test the limits and break through" );
daveyclk 1:070fc531e5cb 190 wait(0.1);
daveyclk 1:070fc531e5cb 191 tts_speak( "No right, no wrong, no rules for me, " );
daveyclk 1:070fc531e5cb 192 wait(0.1);
daveyclk 1:070fc531e5cb 193 tts_speak( "I'm free! " );
daveyclk 1:070fc531e5cb 194 wait(0.1);
daveyclk 1:070fc531e5cb 195
daveyclk 1:070fc531e5cb 196 chorus two
daveyclk 1:070fc531e5cb 197 tts_speak( "Let it go, let it go. " );
daveyclk 1:070fc531e5cb 198 wait(0.1);
daveyclk 1:070fc531e5cb 199 tts_speak( "I am one with the wind and sky " );
daveyclk 1:070fc531e5cb 200 wait(0.1);
daveyclk 1:070fc531e5cb 201 tts_speak( "Let it go, let it go " );
daveyclk 1:070fc531e5cb 202 wait(0.1);
daveyclk 1:070fc531e5cb 203 tts_speak( "You'll never see me cry" );
daveyclk 1:070fc531e5cb 204 wait(0.1);
daveyclk 1:070fc531e5cb 205 tts_speak( "Here I stand" );
daveyclk 1:070fc531e5cb 206 wait(0.1);
daveyclk 1:070fc531e5cb 207 tts_speak( "And here I'll stay" );
daveyclk 1:070fc531e5cb 208 wait(0.1);
daveyclk 1:070fc531e5cb 209 tts_speak( "Let the storm rage on" );
daveyclk 1:070fc531e5cb 210 wait(0.1);
daveyclk 1:070fc531e5cb 211
daveyclk 1:070fc531e5cb 212 middle eight
daveyclk 1:070fc531e5cb 213 tts_speak( "My power flurries through the air into the ground " );
daveyclk 1:070fc531e5cb 214 wait(0.1);
daveyclk 1:070fc531e5cb 215 tts_speak( "My soul is spiraling in frozen fractals all around " );
daveyclk 1:070fc531e5cb 216 wait(0.1);
daveyclk 1:070fc531e5cb 217 tts_speak( "And one thought crystallizes like an icy blast " );
daveyclk 1:070fc531e5cb 218 wait(0.1);
daveyclk 1:070fc531e5cb 219 tts_speak( "I'm never going back, the past is in the past" );
daveyclk 1:070fc531e5cb 220 wait(0.1);
daveyclk 1:070fc531e5cb 221
daveyclk 1:070fc531e5cb 222 last chorus
daveyclk 1:070fc531e5cb 223 tts_speak( "Let it go, let it go" );
daveyclk 1:070fc531e5cb 224 wait(0.1);
daveyclk 1:070fc531e5cb 225 tts_speak( "And I'll rise like the break of dawn" );
daveyclk 1:070fc531e5cb 226 wait(0.1);
daveyclk 1:070fc531e5cb 227 tts_speak( "Let it go, let it go" );
daveyclk 1:070fc531e5cb 228 wait(0.1);
daveyclk 1:070fc531e5cb 229 tts_speak( "That perfect girl is gone" );
daveyclk 1:070fc531e5cb 230 wait(0.1);
daveyclk 1:070fc531e5cb 231 tts_speak( "Here I stand" );
daveyclk 1:070fc531e5cb 232 wait(0.1);
daveyclk 1:070fc531e5cb 233 tts_speak( "In the light of day" );
daveyclk 1:070fc531e5cb 234 wait(0.1);
daveyclk 1:070fc531e5cb 235 tts_speak( "Let the storm rage on" );
daveyclk 1:070fc531e5cb 236 wait(0.5);
daveyclk 1:070fc531e5cb 237 tts_speak( "The cold never bothered me anyway" );
daveyclk 1:070fc531e5cb 238 wait(1);
daveyclk 1:070fc531e5cb 239 */
daveyclk 1:070fc531e5cb 240
daveyclk 1:070fc531e5cb 241 // keep talking
daveyclk 1:070fc531e5cb 242 tts_speak( "For millions of years mankind lived just like the animals." );
daveyclk 1:070fc531e5cb 243 wait(0.5);
daveyclk 1:070fc531e5cb 244 tts_speak( "Then something happenend which unleashed the power of our imagination" );
daveyclk 1:070fc531e5cb 245 wait(0.5);
daveyclk 1:070fc531e5cb 246 tts_speak( "We learned to talk" );
daveyclk 1:070fc531e5cb 247 wait(10);
daveyclk 1:070fc531e5cb 248
daveyclk 1:070fc531e5cb 249 }
daveyclk 1:070fc531e5cb 250 }
daveyclk 1:070fc531e5cb 251
daveyclk 1:070fc531e5cb 252 void msg_blk( uint16_t *req, uint16_t *err )
daveyclk 1:070fc531e5cb 253 {
daveyclk 1:070fc531e5cb 254 char txt[ 6 ];
daveyclk 1:070fc531e5cb 255
daveyclk 1:070fc531e5cb 256 pc.printf( " MSG BLOCKED \r\n" );
daveyclk 1:070fc531e5cb 257 sprintf( txt, "%x\r\n", *req );
daveyclk 1:070fc531e5cb 258 pc.printf( txt );
daveyclk 1:070fc531e5cb 259 sprintf( txt, "%x\r\n", *err );
daveyclk 1:070fc531e5cb 260 pc.printf( txt );
daveyclk 1:070fc531e5cb 261 }
daveyclk 1:070fc531e5cb 262
daveyclk 1:070fc531e5cb 263 void fatal_err( uint16_t *err )
daveyclk 1:070fc531e5cb 264 {
daveyclk 1:070fc531e5cb 265 pc.printf( "Fatal Error Detected" );
daveyclk 1:070fc531e5cb 266 tts_init();
daveyclk 1:070fc531e5cb 267 tts_fatal_err_callback( fatal_err );
daveyclk 1:070fc531e5cb 268 }
daveyclk 1:070fc531e5cb 269
daveyclk 1:070fc531e5cb 270
daveyclk 1:070fc531e5cb 271 ///////////////////text_to_speech_hal.c///////////////
daveyclk 1:070fc531e5cb 272 void tts_hal_cs_high()
daveyclk 1:070fc531e5cb 273 {
daveyclk 1:070fc531e5cb 274
daveyclk 1:070fc531e5cb 275 TTS_CS = 1;
daveyclk 1:070fc531e5cb 276 }
daveyclk 1:070fc531e5cb 277
daveyclk 1:070fc531e5cb 278 void tts_hal_cs_low()
daveyclk 1:070fc531e5cb 279 {
daveyclk 1:070fc531e5cb 280 TTS_CS = 0;
daveyclk 1:070fc531e5cb 281
daveyclk 1:070fc531e5cb 282 }
daveyclk 1:070fc531e5cb 283
daveyclk 1:070fc531e5cb 284 void tts_hal_mut_high()
daveyclk 1:070fc531e5cb 285 {
daveyclk 1:070fc531e5cb 286 TTS_MUTE = 1;
daveyclk 1:070fc531e5cb 287 }
GregC 0:ac93d26bbdb5 288
daveyclk 1:070fc531e5cb 289 void tts_hal_mut_low()
daveyclk 1:070fc531e5cb 290 {
daveyclk 1:070fc531e5cb 291 TTS_MUTE = 0;
daveyclk 1:070fc531e5cb 292 }
daveyclk 1:070fc531e5cb 293 /*
daveyclk 1:070fc531e5cb 294 void tts_hal_reset( void )
daveyclk 1:070fc531e5cb 295 {
daveyclk 1:070fc531e5cb 296 TTS_RST = 0;
daveyclk 1:070fc531e5cb 297 wait(0.01);
daveyclk 1:070fc531e5cb 298 TTS_RST = 1;
daveyclk 1:070fc531e5cb 299 //wait(1);
daveyclk 1:070fc531e5cb 300 wait(POR_TIME / 1000);
daveyclk 1:070fc531e5cb 301 }
daveyclk 1:070fc531e5cb 302 */
daveyclk 1:070fc531e5cb 303 void tts_hal_reset( void )
daveyclk 1:070fc531e5cb 304 {
daveyclk 1:070fc531e5cb 305 tts_hal_cs_high();
daveyclk 1:070fc531e5cb 306 TTS_RST = 0;
daveyclk 1:070fc531e5cb 307 tts_hal_write_pad(1);
daveyclk 1:070fc531e5cb 308 wait(0.01);
daveyclk 1:070fc531e5cb 309 TTS_RST = 1;
daveyclk 1:070fc531e5cb 310 wait(POR_TIME);
daveyclk 1:070fc531e5cb 311 }
daveyclk 1:070fc531e5cb 312 bool tts_hal_msg_rdy( void )
daveyclk 1:070fc531e5cb 313 {
daveyclk 1:070fc531e5cb 314 return TTS_RDY;
daveyclk 1:070fc531e5cb 315 }
daveyclk 1:070fc531e5cb 316
daveyclk 1:070fc531e5cb 317 void tts_hal_init()
daveyclk 1:070fc531e5cb 318 {
daveyclk 1:070fc531e5cb 319 tts_hal_reset();
daveyclk 1:070fc531e5cb 320 tts_hal_cs_high();
daveyclk 1:070fc531e5cb 321 tts_hal_mut_low();
daveyclk 1:070fc531e5cb 322 }
daveyclk 1:070fc531e5cb 323
daveyclk 1:070fc531e5cb 324
daveyclk 1:070fc531e5cb 325 void tts_hal_write( uint8_t *buffer,
daveyclk 1:070fc531e5cb 326 uint16_t count, bool boot )
daveyclk 1:070fc531e5cb 327 {
daveyclk 1:070fc531e5cb 328
daveyclk 1:070fc531e5cb 329 while( count-- )
daveyclk 1:070fc531e5cb 330 {
daveyclk 1:070fc531e5cb 331 if(!boot)
daveyclk 1:070fc531e5cb 332 pc.printf("%02X\r\n", *buffer);
daveyclk 1:070fc531e5cb 333
daveyclk 1:070fc531e5cb 334 TextToSpeech.write( *buffer++ );
daveyclk 1:070fc531e5cb 335
daveyclk 1:070fc531e5cb 336 }
daveyclk 1:070fc531e5cb 337 }
daveyclk 1:070fc531e5cb 338
daveyclk 1:070fc531e5cb 339 void tts_hal_write_pad( int cnt )
daveyclk 1:070fc531e5cb 340 {
daveyclk 1:070fc531e5cb 341
daveyclk 1:070fc531e5cb 342 tts_hal_cs_low();
daveyclk 1:070fc531e5cb 343 while(cnt--)
daveyclk 1:070fc531e5cb 344 {
daveyclk 1:070fc531e5cb 345 TextToSpeech.write( PADDING_BYTE );
daveyclk 1:070fc531e5cb 346 }
daveyclk 1:070fc531e5cb 347
daveyclk 1:070fc531e5cb 348 tts_hal_cs_high();
daveyclk 1:070fc531e5cb 349 }
daveyclk 1:070fc531e5cb 350
daveyclk 1:070fc531e5cb 351 void tts_hal_read( uint8_t *buffer,
daveyclk 1:070fc531e5cb 352 uint16_t count )
daveyclk 1:070fc531e5cb 353 {
daveyclk 1:070fc531e5cb 354
daveyclk 1:070fc531e5cb 355 while(count--)
daveyclk 1:070fc531e5cb 356 {
daveyclk 1:070fc531e5cb 357 *buffer++ = TextToSpeech.write( DUMMY_BYTE ); //read spi bus
daveyclk 1:070fc531e5cb 358
daveyclk 1:070fc531e5cb 359
daveyclk 1:070fc531e5cb 360 //pc.printf("buffer = %X\n\r", *buffer);
daveyclk 1:070fc531e5cb 361 }
daveyclk 1:070fc531e5cb 362 }
daveyclk 1:070fc531e5cb 363
daveyclk 1:070fc531e5cb 364 ////////////////text_to_speech.c///////////////////////////////
daveyclk 1:070fc531e5cb 365
daveyclk 1:070fc531e5cb 366 static int _parse_ind( void )
daveyclk 1:070fc531e5cb 367 {
daveyclk 1:070fc531e5cb 368 uint16_t rsp_idx = tts_rsp_idx();
daveyclk 1:070fc531e5cb 369 if ( rsp_idx == ISC_MSG_BLOCKED_RESP )
daveyclk 1:070fc531e5cb 370 {
daveyclk 1:070fc531e5cb 371 uint8_t rsp_data[ 4 ] = { 0 };
daveyclk 1:070fc531e5cb 372
daveyclk 1:070fc531e5cb 373 _req_err = 0;
daveyclk 1:070fc531e5cb 374 _err_code = 0;
daveyclk 1:070fc531e5cb 375
daveyclk 1:070fc531e5cb 376 tts_rsp_data( rsp_data );
daveyclk 1:070fc531e5cb 377
daveyclk 1:070fc531e5cb 378 _req_err |= rsp_data[ 0 ];
daveyclk 1:070fc531e5cb 379 _req_err |= rsp_data[ 1 ] << 8;
daveyclk 1:070fc531e5cb 380 _err_code |= rsp_data[ 2 ];
daveyclk 1:070fc531e5cb 381 _err_code |= rsp_data[ 3 ] << 8;
daveyclk 1:070fc531e5cb 382
daveyclk 1:070fc531e5cb 383 if( _msg_block_callback != NULL )
daveyclk 1:070fc531e5cb 384 _msg_block_callback( &_req_err, &_err_code );
daveyclk 1:070fc531e5cb 385
daveyclk 1:070fc531e5cb 386 return 1;
daveyclk 1:070fc531e5cb 387
daveyclk 1:070fc531e5cb 388 } else if ( rsp_idx == ISC_ERROR_IND ) {
daveyclk 1:070fc531e5cb 389
daveyclk 1:070fc531e5cb 390 uint8_t rsp_data[ 4 ] = { 0 };
daveyclk 1:070fc531e5cb 391
daveyclk 1:070fc531e5cb 392 _req_err = 0;
daveyclk 1:070fc531e5cb 393 _err_code = 0;
daveyclk 1:070fc531e5cb 394
daveyclk 1:070fc531e5cb 395 tts_rsp_data( rsp_data );
daveyclk 1:070fc531e5cb 396
daveyclk 1:070fc531e5cb 397 _err_code |= rsp_data[ 0 ];
daveyclk 1:070fc531e5cb 398 _err_code |= rsp_data[ 1 ] << 8;
daveyclk 1:070fc531e5cb 399
daveyclk 1:070fc531e5cb 400 if ( _err_code && _err_code < 0x8000 )
daveyclk 1:070fc531e5cb 401 {
daveyclk 1:070fc531e5cb 402 if( _err_callback != NULL )
daveyclk 1:070fc531e5cb 403 _err_callback( &_err_code );
daveyclk 1:070fc531e5cb 404
daveyclk 1:070fc531e5cb 405 } else if ( _err_code && _err_code > 0x7FFF ) {
daveyclk 1:070fc531e5cb 406
daveyclk 1:070fc531e5cb 407 if( _fatal_err_callback != NULL )
daveyclk 1:070fc531e5cb 408 _fatal_err_callback( &_err_code );
daveyclk 1:070fc531e5cb 409 }
daveyclk 1:070fc531e5cb 410
daveyclk 1:070fc531e5cb 411 return 1;
daveyclk 1:070fc531e5cb 412
daveyclk 1:070fc531e5cb 413 } else if ( rsp_idx == ISC_TTS_READY_IND ) {
daveyclk 1:070fc531e5cb 414
daveyclk 1:070fc531e5cb 415 _tts_rdy_f = 1;
daveyclk 1:070fc531e5cb 416
daveyclk 1:070fc531e5cb 417 } else if ( rsp_idx == ISC_SPCODEC_READY_IND ) {
daveyclk 1:070fc531e5cb 418
daveyclk 1:070fc531e5cb 419 _spc_rdy_f = 1;
daveyclk 1:070fc531e5cb 420
daveyclk 1:070fc531e5cb 421 } else if ( rsp_idx == ISC_TTS_FINISHED_IND ) {
daveyclk 1:070fc531e5cb 422
daveyclk 1:070fc531e5cb 423 _tts_fin_f = 1;
daveyclk 1:070fc531e5cb 424
daveyclk 1:070fc531e5cb 425 } else if ( rsp_idx == ISC_SPCODEC_FINISHED_IND ) {
GregC 0:ac93d26bbdb5 426
daveyclk 1:070fc531e5cb 427 _spc_fin_f = 1;
daveyclk 1:070fc531e5cb 428 }
daveyclk 1:070fc531e5cb 429
daveyclk 1:070fc531e5cb 430 return 0;
daveyclk 1:070fc531e5cb 431 }
daveyclk 1:070fc531e5cb 432 /******************************************************************************
daveyclk 1:070fc531e5cb 433 * Public Function Definitions
daveyclk 1:070fc531e5cb 434 *******************************************************************************/
daveyclk 1:070fc531e5cb 435
daveyclk 1:070fc531e5cb 436
daveyclk 1:070fc531e5cb 437 void tts_init()
daveyclk 1:070fc531e5cb 438 {
daveyclk 1:070fc531e5cb 439 _req_err = 0;
daveyclk 1:070fc531e5cb 440 _err_code = 0;
daveyclk 1:070fc531e5cb 441
daveyclk 1:070fc531e5cb 442 _tts_rdy_f = true;
daveyclk 1:070fc531e5cb 443 _spc_rdy_f = true;
daveyclk 1:070fc531e5cb 444 _tts_fin_f = true;
daveyclk 1:070fc531e5cb 445 _spc_fin_f = true;
daveyclk 1:070fc531e5cb 446
daveyclk 1:070fc531e5cb 447 _audio_conf.as = 0x00;
daveyclk 1:070fc531e5cb 448 _audio_conf.ag = 0x43;
daveyclk 1:070fc531e5cb 449 _audio_conf.amp = 0x00;
daveyclk 1:070fc531e5cb 450 _audio_conf.asr = ASR_11KHZ;
daveyclk 1:070fc531e5cb 451 _audio_conf.ar = 0x00;
daveyclk 1:070fc531e5cb 452 _audio_conf.atc = 0x00;
daveyclk 1:070fc531e5cb 453 _audio_conf.acs = 0x00;
daveyclk 1:070fc531e5cb 454 _audio_conf.dc = 0x00;
daveyclk 1:070fc531e5cb 455
daveyclk 1:070fc531e5cb 456 _tts_conf.sr = 0x01;
daveyclk 1:070fc531e5cb 457 _tts_conf.voice = 0x00;
daveyclk 1:070fc531e5cb 458 _tts_conf.ep = 0x00;
daveyclk 1:070fc531e5cb 459 _tts_conf.lang = TTSV_US;
daveyclk 1:070fc531e5cb 460 _tts_conf.sr_wpm_lsb = 0xc8;
daveyclk 1:070fc531e5cb 461 _tts_conf.sr_wpm_msb = 0x00;
daveyclk 1:070fc531e5cb 462 _tts_conf.ds = 0x00;
daveyclk 1:070fc531e5cb 463 _tts_conf.res = 0x00;
daveyclk 1:070fc531e5cb 464
daveyclk 1:070fc531e5cb 465 _pman_conf.am_lsb = 0x01;
daveyclk 1:070fc531e5cb 466 _pman_conf.am_msb = 0x00;
daveyclk 1:070fc531e5cb 467 _pman_conf.spi_clk = 0x01;
daveyclk 1:070fc531e5cb 468 _pman_conf.pad = PADDING_BYTE;
daveyclk 1:070fc531e5cb 469
daveyclk 1:070fc531e5cb 470 _flush_enable = false;
daveyclk 1:070fc531e5cb 471
daveyclk 1:070fc531e5cb 472 _msg_block_callback = NULL;
daveyclk 1:070fc531e5cb 473 _fatal_err_callback = NULL;
daveyclk 1:070fc531e5cb 474 _err_callback = NULL;
daveyclk 1:070fc531e5cb 475
daveyclk 1:070fc531e5cb 476 tts_hw_init();
daveyclk 1:070fc531e5cb 477 }
daveyclk 1:070fc531e5cb 478
daveyclk 1:070fc531e5cb 479 void tts_msg_block_callback( void( *msg_blk_ptr )( uint16_t *req_ptr,
daveyclk 1:070fc531e5cb 480 uint16_t *err_ptr ) )
daveyclk 1:070fc531e5cb 481 {
daveyclk 1:070fc531e5cb 482 _msg_block_callback = msg_blk_ptr;
daveyclk 1:070fc531e5cb 483 }
daveyclk 1:070fc531e5cb 484
daveyclk 1:070fc531e5cb 485 void tts_fatal_err_callback( void( *fatal_err_ptr )( uint16_t *err_ptr ) )
daveyclk 1:070fc531e5cb 486 {
daveyclk 1:070fc531e5cb 487 _fatal_err_callback = fatal_err_ptr;
daveyclk 1:070fc531e5cb 488 }
daveyclk 1:070fc531e5cb 489
daveyclk 1:070fc531e5cb 490 void tts_err_callback( void( *error_ptr )( uint16_t *err_ptr ) )
daveyclk 1:070fc531e5cb 491 {
daveyclk 1:070fc531e5cb 492 _err_callback = error_ptr;
daveyclk 1:070fc531e5cb 493 }
GregC 0:ac93d26bbdb5 494
daveyclk 1:070fc531e5cb 495 void tts_mute()
daveyclk 1:070fc531e5cb 496 {
daveyclk 1:070fc531e5cb 497 tts_mute_cmd( true );
daveyclk 1:070fc531e5cb 498 }
daveyclk 1:070fc531e5cb 499
daveyclk 1:070fc531e5cb 500 void tts_unmute()
daveyclk 1:070fc531e5cb 501 {
daveyclk 1:070fc531e5cb 502 tts_mute_cmd( false );
daveyclk 1:070fc531e5cb 503 }
daveyclk 1:070fc531e5cb 504
GregC 0:ac93d26bbdb5 505
daveyclk 1:070fc531e5cb 506 void tts_setup()
daveyclk 1:070fc531e5cb 507 {
daveyclk 1:070fc531e5cb 508
daveyclk 1:070fc531e5cb 509
daveyclk 1:070fc531e5cb 510
daveyclk 1:070fc531e5cb 511 // pc.printf( "tts init data size: %i\n\r", sizeof(TTS_INIT_DATA2));
daveyclk 1:070fc531e5cb 512
daveyclk 1:070fc531e5cb 513 tts_version_boot();
daveyclk 1:070fc531e5cb 514 int succ = tts_image_load( (uint8_t*)TTS_INIT_DATA, sizeof( TTS_INIT_DATA ) );
daveyclk 1:070fc531e5cb 515
daveyclk 1:070fc531e5cb 516 if ( succ != 0x0001 )
daveyclk 1:070fc531e5cb 517 {
daveyclk 1:070fc531e5cb 518 pc.printf("tts init data failed!\n\r");
daveyclk 1:070fc531e5cb 519 pc.printf("returned value: %04X\n\r", succ);
daveyclk 1:070fc531e5cb 520 wait(100);
daveyclk 1:070fc531e5cb 521 }
daveyclk 1:070fc531e5cb 522 pc.printf("tts image load done\n\r"); //executes OK
daveyclk 1:070fc531e5cb 523 succ = tts_image_exec(); // executes ok
daveyclk 1:070fc531e5cb 524
daveyclk 1:070fc531e5cb 525 if ( succ != 0x0001 )
daveyclk 1:070fc531e5cb 526 {
daveyclk 1:070fc531e5cb 527 pc.printf("tts image exec failed!\n\r");
daveyclk 1:070fc531e5cb 528 pc.printf("returned value: %04X\n\r", succ);
daveyclk 1:070fc531e5cb 529 wait(100);
daveyclk 1:070fc531e5cb 530 }
daveyclk 1:070fc531e5cb 531 pc.printf("tts image exec done\n\r");
daveyclk 1:070fc531e5cb 532 tts_interface_test();
daveyclk 1:070fc531e5cb 533 pc.printf("tts interface test done\n\r");
daveyclk 1:070fc531e5cb 534 tts_power_default_config();
daveyclk 1:070fc531e5cb 535 pc.printf("tts power default done\n\r");
daveyclk 1:070fc531e5cb 536 tts_audio_default_config();
daveyclk 1:070fc531e5cb 537 pc.printf("tts audio default done\n\r");
daveyclk 1:070fc531e5cb 538 tts_volume_set( 0 );
daveyclk 1:070fc531e5cb 539 pc.printf("tts volume set done\n\r");
daveyclk 1:070fc531e5cb 540 tts_default_config();
daveyclk 1:070fc531e5cb 541 pc.printf("tts default config done\n\r");
daveyclk 1:070fc531e5cb 542 }
daveyclk 1:070fc531e5cb 543
daveyclk 1:070fc531e5cb 544 void tts_version_boot( void )
daveyclk 1:070fc531e5cb 545 {
daveyclk 1:070fc531e5cb 546
daveyclk 1:070fc531e5cb 547 uint8_t tmp_resp[ 16 ] = { 0 };
daveyclk 1:070fc531e5cb 548
daveyclk 1:070fc531e5cb 549 wait( RESET_TO_BOOT_TIME );
daveyclk 1:070fc531e5cb 550
daveyclk 1:070fc531e5cb 551
daveyclk 1:070fc531e5cb 552 tts_parse_req( ISC_VERSION_REQ_BOOT, NULL, 0 );
daveyclk 1:070fc531e5cb 553
daveyclk 1:070fc531e5cb 554
daveyclk 1:070fc531e5cb 555 while( !tts_rsp_chk( ISC_VERSION_RESP_BOOT ) )
daveyclk 1:070fc531e5cb 556 {
daveyclk 1:070fc531e5cb 557 tts_get_resp();
daveyclk 1:070fc531e5cb 558
daveyclk 1:070fc531e5cb 559 }
daveyclk 1:070fc531e5cb 560 tts_hal_write_pad( 16);
daveyclk 1:070fc531e5cb 561 tts_rsp_data( tmp_resp );
daveyclk 1:070fc531e5cb 562 pc.printf("hwver0 %X \n\r", tmp_resp[ 0 ]);
daveyclk 1:070fc531e5cb 563 pc.printf("hwver1 %X \n\r", tmp_resp[ 1 ]);
daveyclk 1:070fc531e5cb 564 }
GregC 0:ac93d26bbdb5 565
GregC 0:ac93d26bbdb5 566
GregC 0:ac93d26bbdb5 567
daveyclk 1:070fc531e5cb 568 uint16_t tts_image_load(const uint8_t *image,
daveyclk 1:070fc531e5cb 569 uint16_t count )
daveyclk 1:070fc531e5cb 570 {
daveyclk 1:070fc531e5cb 571
daveyclk 1:070fc531e5cb 572 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 573 uint16_t index = 0;
daveyclk 1:070fc531e5cb 574 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 575
daveyclk 1:070fc531e5cb 576 while ( ( count - index ) > ( BOOT_MESSAGE_MAX - 4 ) )
daveyclk 1:070fc531e5cb 577 {
daveyclk 1:070fc531e5cb 578
daveyclk 1:070fc531e5cb 579 tts_parse_boot_img( image + index, BOOT_MESSAGE_MAX - 4 );
daveyclk 1:070fc531e5cb 580 wait(0.01);
daveyclk 1:070fc531e5cb 581 index += ( BOOT_MESSAGE_MAX - 4 );
daveyclk 1:070fc531e5cb 582 }
daveyclk 1:070fc531e5cb 583 tts_parse_boot_img( image + index, count - index );
daveyclk 1:070fc531e5cb 584 wait(0.01);
daveyclk 1:070fc531e5cb 585
daveyclk 1:070fc531e5cb 586 while( !tts_rsp_chk( ISC_BOOT_LOAD_RESP ) )
daveyclk 1:070fc531e5cb 587 {
daveyclk 1:070fc531e5cb 588 tts_get_resp();
daveyclk 1:070fc531e5cb 589
daveyclk 1:070fc531e5cb 590 if( _parse_ind() )
daveyclk 1:070fc531e5cb 591 return _err_code;
daveyclk 1:070fc531e5cb 592 }
daveyclk 1:070fc531e5cb 593 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 594
daveyclk 1:070fc531e5cb 595 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 596 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 597
daveyclk 1:070fc531e5cb 598 return tmp_resp;
daveyclk 1:070fc531e5cb 599 //return ( tmp_resp == 1 ) ? tmp_resp : 0x0000;
daveyclk 1:070fc531e5cb 600 }
GregC 0:ac93d26bbdb5 601
daveyclk 1:070fc531e5cb 602 uint16_t tts_image_exec()
GregC 0:ac93d26bbdb5 603 {
daveyclk 1:070fc531e5cb 604 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 605 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 606
daveyclk 1:070fc531e5cb 607
daveyclk 1:070fc531e5cb 608 tts_parse_req( ISC_BOOT_RUN_REQ, NULL, 0 );
daveyclk 1:070fc531e5cb 609
daveyclk 1:070fc531e5cb 610
daveyclk 1:070fc531e5cb 611
daveyclk 1:070fc531e5cb 612
daveyclk 1:070fc531e5cb 613 while( !tts_rsp_chk( ISC_BOOT_RUN_RESP ) )
daveyclk 1:070fc531e5cb 614 {
daveyclk 1:070fc531e5cb 615
daveyclk 1:070fc531e5cb 616 tts_get_resp();
daveyclk 1:070fc531e5cb 617
daveyclk 1:070fc531e5cb 618 if( _parse_ind() )
daveyclk 1:070fc531e5cb 619 return _err_code;
daveyclk 1:070fc531e5cb 620 }
daveyclk 1:070fc531e5cb 621 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 622
daveyclk 1:070fc531e5cb 623 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 624 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 625
daveyclk 1:070fc531e5cb 626 return tmp_resp;
daveyclk 1:070fc531e5cb 627 }
daveyclk 1:070fc531e5cb 628
daveyclk 1:070fc531e5cb 629 uint16_t tts_interface_test()
daveyclk 1:070fc531e5cb 630 {
daveyclk 1:070fc531e5cb 631 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 632 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 633
daveyclk 1:070fc531e5cb 634
daveyclk 1:070fc531e5cb 635 wait( BOOT_TO_MAIN_MODE );
GregC 0:ac93d26bbdb5 636
daveyclk 1:070fc531e5cb 637 tts_parse_req( ISC_TEST_REQ, test, 8 );
daveyclk 1:070fc531e5cb 638
daveyclk 1:070fc531e5cb 639 while( !tts_rsp_chk( ISC_TEST_RESP ) )
daveyclk 1:070fc531e5cb 640 {
daveyclk 1:070fc531e5cb 641 tts_get_resp();
daveyclk 1:070fc531e5cb 642
daveyclk 1:070fc531e5cb 643 if( _parse_ind() )
daveyclk 1:070fc531e5cb 644 return _err_code;
daveyclk 1:070fc531e5cb 645 }
daveyclk 1:070fc531e5cb 646
daveyclk 1:070fc531e5cb 647 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 648
daveyclk 1:070fc531e5cb 649 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 650 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 651
daveyclk 1:070fc531e5cb 652 return tmp_resp;
daveyclk 1:070fc531e5cb 653 }
daveyclk 1:070fc531e5cb 654
daveyclk 1:070fc531e5cb 655 uint16_t tts_version_main( VER_t *buffer )
daveyclk 1:070fc531e5cb 656 {
daveyclk 1:070fc531e5cb 657 char tmp_char[ 3 ] = { 0 };
daveyclk 1:070fc531e5cb 658 uint32_t tmp_fwf = 0;
daveyclk 1:070fc531e5cb 659 uint32_t tmp_fwef = 0;
daveyclk 1:070fc531e5cb 660 uint8_t tmp_resp[ 20 ] = { 0 };
daveyclk 1:070fc531e5cb 661
daveyclk 1:070fc531e5cb 662 tts_parse_req( ISC_VERSION_REQ_MAIN, NULL, 0 );
daveyclk 1:070fc531e5cb 663
daveyclk 1:070fc531e5cb 664 while( !tts_rsp_chk( ISC_VERSION_RESP_MAIN ) )
daveyclk 1:070fc531e5cb 665 {
daveyclk 1:070fc531e5cb 666 tts_get_resp();
daveyclk 1:070fc531e5cb 667
daveyclk 1:070fc531e5cb 668 if( _parse_ind() )
daveyclk 1:070fc531e5cb 669 return _err_code;
daveyclk 1:070fc531e5cb 670 }
daveyclk 1:070fc531e5cb 671
daveyclk 1:070fc531e5cb 672 tts_rsp_data( tmp_resp );
daveyclk 1:070fc531e5cb 673 sprintf(tmp_char, "%c", tmp_resp[ 0 ]);
daveyclk 1:070fc531e5cb 674 strcpy( buffer->hwver, tmp_char );
daveyclk 1:070fc531e5cb 675 strcat( buffer->hwver, "." );
daveyclk 1:070fc531e5cb 676 sprintf(tmp_char, "%c", tmp_resp[ 1 ]);
daveyclk 1:070fc531e5cb 677 strcat( buffer->hwver, tmp_char );
daveyclk 1:070fc531e5cb 678 sprintf(tmp_char, "%c", tmp_resp[ 2 ]);
daveyclk 1:070fc531e5cb 679 strcpy( buffer->fwver, tmp_char );
daveyclk 1:070fc531e5cb 680 strcat( buffer->fwver, "." );
daveyclk 1:070fc531e5cb 681 sprintf(tmp_char, "%c", tmp_resp[ 3 ]);
daveyclk 1:070fc531e5cb 682 strcat( buffer->fwver, tmp_char );
daveyclk 1:070fc531e5cb 683 strcat( buffer->fwver, "." );
daveyclk 1:070fc531e5cb 684 sprintf(tmp_char, "%c", tmp_resp[ 12 ]);
daveyclk 1:070fc531e5cb 685 strcat( buffer->fwver, tmp_char );
daveyclk 1:070fc531e5cb 686
daveyclk 1:070fc531e5cb 687 tmp_fwf |= tmp_resp[ 4 ];
daveyclk 1:070fc531e5cb 688 tmp_fwf |= tmp_resp[ 5 ] << 8;
daveyclk 1:070fc531e5cb 689 tmp_fwf |= tmp_resp[ 6 ] << 16;
daveyclk 1:070fc531e5cb 690 tmp_fwf |= tmp_resp[ 7 ] << 24;
daveyclk 1:070fc531e5cb 691 buffer->fwf = (FF_t)tmp_fwf;
daveyclk 1:070fc531e5cb 692 tmp_fwef |= tmp_resp[ 8 ];
daveyclk 1:070fc531e5cb 693 tmp_fwef |= tmp_resp[ 9 ] << 8;
daveyclk 1:070fc531e5cb 694 tmp_fwef |= tmp_resp[ 10 ] << 16;
daveyclk 1:070fc531e5cb 695 tmp_fwef |= tmp_resp[ 11 ] << 24;
daveyclk 1:070fc531e5cb 696 buffer->fwef = (EFF_t)tmp_fwef;
daveyclk 1:070fc531e5cb 697
daveyclk 1:070fc531e5cb 698 return 0x0000;
daveyclk 1:070fc531e5cb 699 }
daveyclk 1:070fc531e5cb 700
daveyclk 1:070fc531e5cb 701 uint16_t tts_power_default_config()
daveyclk 1:070fc531e5cb 702 {
daveyclk 1:070fc531e5cb 703 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 704 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 705
daveyclk 1:070fc531e5cb 706 tts_parse_req( ISC_PMAN_CONFIG_REQ, ( uint8_t* )&_pman_conf, 4 );
daveyclk 1:070fc531e5cb 707
daveyclk 1:070fc531e5cb 708 while( !tts_rsp_chk( ISC_PMAN_CONFIG_RESP ) )
daveyclk 1:070fc531e5cb 709 {
daveyclk 1:070fc531e5cb 710 tts_get_resp();
daveyclk 1:070fc531e5cb 711
daveyclk 1:070fc531e5cb 712 if( _parse_ind() )
daveyclk 1:070fc531e5cb 713 return _err_code;
daveyclk 1:070fc531e5cb 714 }
daveyclk 1:070fc531e5cb 715
daveyclk 1:070fc531e5cb 716 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 717
daveyclk 1:070fc531e5cb 718 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 719 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 720
daveyclk 1:070fc531e5cb 721 return tmp_resp;
daveyclk 1:070fc531e5cb 722 }
daveyclk 1:070fc531e5cb 723
daveyclk 1:070fc531e5cb 724 uint16_t tts_standby_enter()
daveyclk 1:070fc531e5cb 725 {
daveyclk 1:070fc531e5cb 726 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 727 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 728
daveyclk 1:070fc531e5cb 729 tts_parse_req( ISC_PMAN_STANDBY_ENTRY_REQ, NULL, 0 );
daveyclk 1:070fc531e5cb 730
daveyclk 1:070fc531e5cb 731 while( !tts_rsp_chk( ISC_PMAN_STANDBY_ENTRY_RESP ) )
daveyclk 1:070fc531e5cb 732 {
daveyclk 1:070fc531e5cb 733 tts_get_resp();
daveyclk 1:070fc531e5cb 734
daveyclk 1:070fc531e5cb 735 if( _parse_ind() )
daveyclk 1:070fc531e5cb 736 return _err_code;
daveyclk 1:070fc531e5cb 737 }
daveyclk 1:070fc531e5cb 738
daveyclk 1:070fc531e5cb 739 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 740
daveyclk 1:070fc531e5cb 741 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 742 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 743
daveyclk 1:070fc531e5cb 744 return tmp_resp;
daveyclk 1:070fc531e5cb 745 }
daveyclk 1:070fc531e5cb 746
daveyclk 1:070fc531e5cb 747 uint16_t tts_standby_exit()
daveyclk 1:070fc531e5cb 748 {
daveyclk 1:070fc531e5cb 749 wait( STBY_MODE_ENTERY );
daveyclk 1:070fc531e5cb 750 tts_parse_req( ISC_PMAN_STANDBY_EXIT_IND, NULL, 0 );
daveyclk 1:070fc531e5cb 751
daveyclk 1:070fc531e5cb 752 while( !tts_rsp_chk( ISC_PMAN_STANDBY_EXIT_IND ) )
daveyclk 1:070fc531e5cb 753 {
daveyclk 1:070fc531e5cb 754 tts_get_resp();
daveyclk 1:070fc531e5cb 755
daveyclk 1:070fc531e5cb 756 if( _parse_ind() )
daveyclk 1:070fc531e5cb 757 return _err_code;
daveyclk 1:070fc531e5cb 758 }
daveyclk 1:070fc531e5cb 759
daveyclk 1:070fc531e5cb 760 return 0x0000;
daveyclk 1:070fc531e5cb 761 }
daveyclk 1:070fc531e5cb 762
daveyclk 1:070fc531e5cb 763 uint16_t tts_audio_default_config()
daveyclk 1:070fc531e5cb 764 {
daveyclk 1:070fc531e5cb 765 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 766 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 767
daveyclk 1:070fc531e5cb 768 tts_parse_req( ISC_AUDIO_CONFIG_REQ, ( uint8_t* )&_audio_conf, 8 );
daveyclk 1:070fc531e5cb 769
daveyclk 1:070fc531e5cb 770 while( !tts_rsp_chk( ISC_AUDIO_CONFIG_RESP ) )
daveyclk 1:070fc531e5cb 771 {
daveyclk 1:070fc531e5cb 772 tts_get_resp();
daveyclk 1:070fc531e5cb 773
daveyclk 1:070fc531e5cb 774 if( _parse_ind() )
daveyclk 1:070fc531e5cb 775 return _err_code;
daveyclk 1:070fc531e5cb 776 }
daveyclk 1:070fc531e5cb 777
daveyclk 1:070fc531e5cb 778 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 779
daveyclk 1:070fc531e5cb 780 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 781 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 782
daveyclk 1:070fc531e5cb 783 return tmp_resp;
GregC 0:ac93d26bbdb5 784 }
GregC 0:ac93d26bbdb5 785
daveyclk 1:070fc531e5cb 786 uint16_t tts_audio_config( int8_t audio_gain,
daveyclk 1:070fc531e5cb 787 ASR_t sample_rate,
daveyclk 1:070fc531e5cb 788 bool dac_control )
daveyclk 1:070fc531e5cb 789 {
daveyclk 1:070fc531e5cb 790 ACONF_t audio_conf;
daveyclk 1:070fc531e5cb 791 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 792 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 793
daveyclk 1:070fc531e5cb 794 if ( audio_gain < -48 || audio_gain > 18 )
daveyclk 1:070fc531e5cb 795 return 0xFFFF;
daveyclk 1:070fc531e5cb 796
daveyclk 1:070fc531e5cb 797 if ( sample_rate != 0 || sample_rate != 1 || sample_rate != 3 )
daveyclk 1:070fc531e5cb 798 return 0xFFFF;
daveyclk 1:070fc531e5cb 799
daveyclk 1:070fc531e5cb 800 audio_conf.ag = ( uint8_t )audio_gain;
daveyclk 1:070fc531e5cb 801 audio_conf.asr = sample_rate;
daveyclk 1:070fc531e5cb 802 audio_conf.dc = dac_control;
daveyclk 1:070fc531e5cb 803
daveyclk 1:070fc531e5cb 804 tts_parse_req( ISC_AUDIO_CONFIG_REQ, ( uint8_t* )&audio_conf, 8 );
daveyclk 1:070fc531e5cb 805
daveyclk 1:070fc531e5cb 806 while( !tts_rsp_chk( ISC_AUDIO_CONFIG_RESP ) )
daveyclk 1:070fc531e5cb 807 {
daveyclk 1:070fc531e5cb 808 tts_get_resp();
daveyclk 1:070fc531e5cb 809
daveyclk 1:070fc531e5cb 810 if( _parse_ind() )
daveyclk 1:070fc531e5cb 811 return _err_code;
daveyclk 1:070fc531e5cb 812 }
daveyclk 1:070fc531e5cb 813
daveyclk 1:070fc531e5cb 814 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 815
daveyclk 1:070fc531e5cb 816 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 817 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 818
daveyclk 1:070fc531e5cb 819 return tmp_resp;
daveyclk 1:070fc531e5cb 820 }
daveyclk 1:070fc531e5cb 821
daveyclk 1:070fc531e5cb 822 uint16_t tts_volume_set( int16_t gain )
GregC 0:ac93d26bbdb5 823 {
daveyclk 1:070fc531e5cb 824 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 825 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 826 uint8_t tmp_gain[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 827
daveyclk 1:070fc531e5cb 828 tmp_gain[ 0 ] = gain & 0x00FF;
daveyclk 1:070fc531e5cb 829 tmp_gain[ 1 ] = ( gain & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 830
daveyclk 1:070fc531e5cb 831 tts_parse_req( ISC_AUDIO_VOULME_REQ, tmp_gain, 2 );
daveyclk 1:070fc531e5cb 832
daveyclk 1:070fc531e5cb 833 while( !tts_rsp_chk( ISC_AUDIO_VOLUME_RESP ) )
daveyclk 1:070fc531e5cb 834 {
daveyclk 1:070fc531e5cb 835 tts_get_resp();
daveyclk 1:070fc531e5cb 836
daveyclk 1:070fc531e5cb 837 if( _parse_ind() )
daveyclk 1:070fc531e5cb 838 return _err_code;
daveyclk 1:070fc531e5cb 839 }
daveyclk 1:070fc531e5cb 840
daveyclk 1:070fc531e5cb 841 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 842
daveyclk 1:070fc531e5cb 843 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 844 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 845
daveyclk 1:070fc531e5cb 846 return tmp_resp;
daveyclk 1:070fc531e5cb 847 }
daveyclk 1:070fc531e5cb 848
daveyclk 1:070fc531e5cb 849 uint16_t tts_audio_mute()
daveyclk 1:070fc531e5cb 850 {
daveyclk 1:070fc531e5cb 851 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 852 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 853 uint8_t tmp_mute[ 2 ] = { 1, 0 };
daveyclk 1:070fc531e5cb 854
daveyclk 1:070fc531e5cb 855 tts_parse_req( ISC_AUDIO_MUTE_REQ, tmp_mute, 2 );
daveyclk 1:070fc531e5cb 856
daveyclk 1:070fc531e5cb 857 while( !tts_rsp_chk( ISC_AUDIO_MUTE_RESP ) )
daveyclk 1:070fc531e5cb 858 {
daveyclk 1:070fc531e5cb 859 tts_get_resp();
daveyclk 1:070fc531e5cb 860
daveyclk 1:070fc531e5cb 861 if( _parse_ind() )
daveyclk 1:070fc531e5cb 862 return _err_code;
daveyclk 1:070fc531e5cb 863 }
daveyclk 1:070fc531e5cb 864
daveyclk 1:070fc531e5cb 865 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 866
daveyclk 1:070fc531e5cb 867 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 868 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 869
daveyclk 1:070fc531e5cb 870 return tmp_resp;
daveyclk 1:070fc531e5cb 871 }
daveyclk 1:070fc531e5cb 872
daveyclk 1:070fc531e5cb 873 uint16_t tts_audio_unmute()
daveyclk 1:070fc531e5cb 874 {
daveyclk 1:070fc531e5cb 875 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 876 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 877 uint8_t tmp_mute[ 2 ] = { 0, 0 };
daveyclk 1:070fc531e5cb 878
daveyclk 1:070fc531e5cb 879 tts_parse_req( ISC_AUDIO_MUTE_REQ, tmp_mute, 2 );
daveyclk 1:070fc531e5cb 880
daveyclk 1:070fc531e5cb 881 while( !tts_rsp_chk( ISC_AUDIO_MUTE_RESP ) )
daveyclk 1:070fc531e5cb 882 {
daveyclk 1:070fc531e5cb 883 tts_get_resp();
daveyclk 1:070fc531e5cb 884
daveyclk 1:070fc531e5cb 885 if( _parse_ind() )
daveyclk 1:070fc531e5cb 886 return _err_code;
daveyclk 1:070fc531e5cb 887 }
daveyclk 1:070fc531e5cb 888
daveyclk 1:070fc531e5cb 889 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 890
daveyclk 1:070fc531e5cb 891 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 892 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 893
daveyclk 1:070fc531e5cb 894 return tmp_resp;
GregC 0:ac93d26bbdb5 895 }
GregC 0:ac93d26bbdb5 896
daveyclk 1:070fc531e5cb 897 uint16_t tts_default_config()
GregC 0:ac93d26bbdb5 898 {
daveyclk 1:070fc531e5cb 899 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 900 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 901
daveyclk 1:070fc531e5cb 902 tts_parse_req( ISC_TTS_CONFIG_REQ, ( uint8_t* )&_tts_conf, 8 );
daveyclk 1:070fc531e5cb 903
daveyclk 1:070fc531e5cb 904 while( !tts_rsp_chk( ISC_TTS_CONFIG_RESP ) )
daveyclk 1:070fc531e5cb 905 {
daveyclk 1:070fc531e5cb 906 tts_get_resp();
daveyclk 1:070fc531e5cb 907
daveyclk 1:070fc531e5cb 908 if( _parse_ind() )
daveyclk 1:070fc531e5cb 909 return _err_code;
daveyclk 1:070fc531e5cb 910 }
daveyclk 1:070fc531e5cb 911
daveyclk 1:070fc531e5cb 912 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 913
daveyclk 1:070fc531e5cb 914 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 915 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 916
daveyclk 1:070fc531e5cb 917 return tmp_resp;
GregC 0:ac93d26bbdb5 918 }
GregC 0:ac93d26bbdb5 919
daveyclk 1:070fc531e5cb 920 uint16_t tts_config( uint8_t voice_type,
daveyclk 1:070fc531e5cb 921 bool epson_parse,
daveyclk 1:070fc531e5cb 922 TTSV_t language,
daveyclk 1:070fc531e5cb 923 uint16_t speaking_rate )
daveyclk 1:070fc531e5cb 924 {
daveyclk 1:070fc531e5cb 925 TTSCONF_t tts_conf;
daveyclk 1:070fc531e5cb 926 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 927 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 928
daveyclk 1:070fc531e5cb 929 if ( voice_type > 8 )
daveyclk 1:070fc531e5cb 930 return 0xFFFF;
daveyclk 1:070fc531e5cb 931
daveyclk 1:070fc531e5cb 932 if ( language > 4 )
daveyclk 1:070fc531e5cb 933 return 0xFFFF;
daveyclk 1:070fc531e5cb 934
daveyclk 1:070fc531e5cb 935 if ( speaking_rate < 0x004B || speaking_rate > 0x0258 )
daveyclk 1:070fc531e5cb 936 return 0xFFFF;
daveyclk 1:070fc531e5cb 937
daveyclk 1:070fc531e5cb 938 tts_conf.voice = voice_type;
daveyclk 1:070fc531e5cb 939 tts_conf.ep = epson_parse;
daveyclk 1:070fc531e5cb 940 tts_conf.lang = language;
daveyclk 1:070fc531e5cb 941 tts_conf.sr_wpm_lsb = ( speaking_rate & 0x00FF );
daveyclk 1:070fc531e5cb 942 tts_conf.sr_wpm_msb = ( speaking_rate & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 943
daveyclk 1:070fc531e5cb 944 tts_parse_req( ISC_TTS_CONFIG_REQ, ( uint8_t* )&tts_conf, 8 );
daveyclk 1:070fc531e5cb 945
daveyclk 1:070fc531e5cb 946 while( !tts_rsp_chk( ISC_TTS_CONFIG_RESP ) )
daveyclk 1:070fc531e5cb 947 {
daveyclk 1:070fc531e5cb 948 tts_get_resp();
daveyclk 1:070fc531e5cb 949
daveyclk 1:070fc531e5cb 950 if( _parse_ind() )
daveyclk 1:070fc531e5cb 951 return _err_code;
daveyclk 1:070fc531e5cb 952 }
daveyclk 1:070fc531e5cb 953
daveyclk 1:070fc531e5cb 954 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 955
daveyclk 1:070fc531e5cb 956 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 957 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 958
daveyclk 1:070fc531e5cb 959 return tmp_resp;
daveyclk 1:070fc531e5cb 960 }
daveyclk 1:070fc531e5cb 961
daveyclk 1:070fc531e5cb 962 uint16_t tts_speak( char *word )
daveyclk 1:070fc531e5cb 963 {
daveyclk 1:070fc531e5cb 964 bool tmp_f = false;
daveyclk 1:070fc531e5cb 965 char *wptr = word;
daveyclk 1:070fc531e5cb 966 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 967 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 968 uint32_t wlen = strlen( wptr );
daveyclk 1:070fc531e5cb 969
daveyclk 1:070fc531e5cb 970 tts_parse_speak_req( ISC_TTS_SPEAK_REQ, _flush_enable, wptr, wlen );
daveyclk 1:070fc531e5cb 971
daveyclk 1:070fc531e5cb 972 _tts_rdy_f = 0;
daveyclk 1:070fc531e5cb 973 _tts_fin_f = 0;
daveyclk 1:070fc531e5cb 974
daveyclk 1:070fc531e5cb 975 while( !( tmp_f && _tts_rdy_f ) )
daveyclk 1:070fc531e5cb 976 {
daveyclk 1:070fc531e5cb 977 tts_get_resp();
daveyclk 1:070fc531e5cb 978
daveyclk 1:070fc531e5cb 979 if( _parse_ind() )
daveyclk 1:070fc531e5cb 980 return _err_code;
daveyclk 1:070fc531e5cb 981
daveyclk 1:070fc531e5cb 982 if( tts_rsp_chk( ISC_TTS_SPEAK_RESP ) )
daveyclk 1:070fc531e5cb 983 {
daveyclk 1:070fc531e5cb 984 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 985
daveyclk 1:070fc531e5cb 986 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 987 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 988 tmp_f = true;
daveyclk 1:070fc531e5cb 989 }
daveyclk 1:070fc531e5cb 990 }
daveyclk 1:070fc531e5cb 991
daveyclk 1:070fc531e5cb 992 return tmp_resp;
daveyclk 1:070fc531e5cb 993 }
daveyclk 1:070fc531e5cb 994
daveyclk 1:070fc531e5cb 995 uint16_t tts_pause( void )
daveyclk 1:070fc531e5cb 996 {
daveyclk 1:070fc531e5cb 997 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 998 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 999 uint8_t tmp_pause[ 2 ] = { 1, 0 };
daveyclk 1:070fc531e5cb 1000
daveyclk 1:070fc531e5cb 1001 tts_parse_req( ISC_TTS_PAUSE_REQ, tmp_pause, 2 );
daveyclk 1:070fc531e5cb 1002
daveyclk 1:070fc531e5cb 1003 while( !tts_rsp_chk( ISC_TTS_PAUSE_RESP ) )
daveyclk 1:070fc531e5cb 1004 {
daveyclk 1:070fc531e5cb 1005 tts_get_resp();
daveyclk 1:070fc531e5cb 1006
daveyclk 1:070fc531e5cb 1007 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1008 return _err_code;
daveyclk 1:070fc531e5cb 1009 }
daveyclk 1:070fc531e5cb 1010
daveyclk 1:070fc531e5cb 1011 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1012
daveyclk 1:070fc531e5cb 1013 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1014 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1015
daveyclk 1:070fc531e5cb 1016 return tmp_resp;
GregC 0:ac93d26bbdb5 1017 }
GregC 0:ac93d26bbdb5 1018
daveyclk 1:070fc531e5cb 1019 uint16_t tts_unpause( void )
daveyclk 1:070fc531e5cb 1020 {
daveyclk 1:070fc531e5cb 1021 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1022 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1023 uint8_t tmp_pause[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1024
daveyclk 1:070fc531e5cb 1025 tts_parse_req( ISC_TTS_PAUSE_REQ, tmp_pause, 2 );
daveyclk 1:070fc531e5cb 1026
daveyclk 1:070fc531e5cb 1027 while( !tts_rsp_chk( ISC_TTS_PAUSE_RESP ) )
daveyclk 1:070fc531e5cb 1028 {
daveyclk 1:070fc531e5cb 1029 tts_get_resp();
daveyclk 1:070fc531e5cb 1030
daveyclk 1:070fc531e5cb 1031 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1032 return _err_code;
daveyclk 1:070fc531e5cb 1033 }
daveyclk 1:070fc531e5cb 1034
daveyclk 1:070fc531e5cb 1035 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1036
daveyclk 1:070fc531e5cb 1037 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1038 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1039
daveyclk 1:070fc531e5cb 1040 return tmp_resp;
daveyclk 1:070fc531e5cb 1041 }
daveyclk 1:070fc531e5cb 1042
daveyclk 1:070fc531e5cb 1043 uint16_t tts_stop( bool reset )
daveyclk 1:070fc531e5cb 1044 {
daveyclk 1:070fc531e5cb 1045 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1046 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1047 uint8_t tmp_reset[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1048
daveyclk 1:070fc531e5cb 1049 if( reset )
daveyclk 1:070fc531e5cb 1050 tmp_reset[ 0 ] = 0x01;
daveyclk 1:070fc531e5cb 1051
daveyclk 1:070fc531e5cb 1052 tts_parse_req( ISC_TTS_STOP_REQ, tmp_reset, 2 );
daveyclk 1:070fc531e5cb 1053
daveyclk 1:070fc531e5cb 1054 while( !tts_rsp_chk( ISC_TTS_STOP_RESP ) )
daveyclk 1:070fc531e5cb 1055 {
daveyclk 1:070fc531e5cb 1056 tts_get_resp();
daveyclk 1:070fc531e5cb 1057
daveyclk 1:070fc531e5cb 1058 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1059 return _err_code;
daveyclk 1:070fc531e5cb 1060 }
daveyclk 1:070fc531e5cb 1061
daveyclk 1:070fc531e5cb 1062 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1063
daveyclk 1:070fc531e5cb 1064 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1065 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1066
daveyclk 1:070fc531e5cb 1067 return tmp_resp;
daveyclk 1:070fc531e5cb 1068 }
daveyclk 1:070fc531e5cb 1069
daveyclk 1:070fc531e5cb 1070 uint16_t tts_user_dict( bool erase,
daveyclk 1:070fc531e5cb 1071 uint8_t *udict_data,
daveyclk 1:070fc531e5cb 1072 uint16_t count )
daveyclk 1:070fc531e5cb 1073 {
daveyclk 1:070fc531e5cb 1074 uint16_t cnt = 2;
daveyclk 1:070fc531e5cb 1075 uint16_t tmp_rsp = 0;
daveyclk 1:070fc531e5cb 1076 uint8_t rsp_data[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1077 uint8_t tmp_data[ BOOT_MESSAGE_MAX ] = { 0 };
daveyclk 1:070fc531e5cb 1078
daveyclk 1:070fc531e5cb 1079 if ( erase )
daveyclk 1:070fc531e5cb 1080 tmp_data[ 0 ] = 1;
daveyclk 1:070fc531e5cb 1081
daveyclk 1:070fc531e5cb 1082 while ( count-- )
daveyclk 1:070fc531e5cb 1083 tmp_data[ cnt ++ ] = *( udict_data++ );
daveyclk 1:070fc531e5cb 1084
daveyclk 1:070fc531e5cb 1085 tts_parse_req( ISC_TTS_UDICT_DATA_REQ, tmp_data, count + 2 );
daveyclk 1:070fc531e5cb 1086
daveyclk 1:070fc531e5cb 1087 while( !tts_rsp_chk( ISC_TTS_UDICT_DATA_RESP ) )
daveyclk 1:070fc531e5cb 1088 {
daveyclk 1:070fc531e5cb 1089 tts_get_resp();
daveyclk 1:070fc531e5cb 1090
daveyclk 1:070fc531e5cb 1091 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1092 return _err_code;
daveyclk 1:070fc531e5cb 1093 }
daveyclk 1:070fc531e5cb 1094
daveyclk 1:070fc531e5cb 1095 tts_rsp_data( rsp_data );
daveyclk 1:070fc531e5cb 1096
daveyclk 1:070fc531e5cb 1097 tmp_rsp |= rsp_data[ 0 ];
daveyclk 1:070fc531e5cb 1098 tmp_rsp |= rsp_data[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1099
daveyclk 1:070fc531e5cb 1100 return tmp_rsp;
daveyclk 1:070fc531e5cb 1101 }
daveyclk 1:070fc531e5cb 1102
daveyclk 1:070fc531e5cb 1103 uint16_t tts_codec_configure()
daveyclk 1:070fc531e5cb 1104 {
daveyclk 1:070fc531e5cb 1105 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1106 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1107 uint8_t tmp_codec[ 32 ] = { 0 };
daveyclk 1:070fc531e5cb 1108
daveyclk 1:070fc531e5cb 1109 tmp_codec[ 0 ] = 0x01;
daveyclk 1:070fc531e5cb 1110 tmp_codec[ 1 ] = 0x01;
daveyclk 1:070fc531e5cb 1111 tmp_codec[ 24 ] = 0x02;
daveyclk 1:070fc531e5cb 1112
daveyclk 1:070fc531e5cb 1113 tts_parse_req( ISC_SPCODEC_CONFIG_REQ , tmp_codec, 32 );
daveyclk 1:070fc531e5cb 1114
daveyclk 1:070fc531e5cb 1115 while( !tts_rsp_chk( ISC_SPCODEC_CONFIG_RESP ) )
daveyclk 1:070fc531e5cb 1116 {
daveyclk 1:070fc531e5cb 1117 tts_get_resp();
daveyclk 1:070fc531e5cb 1118
daveyclk 1:070fc531e5cb 1119 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1120 return _err_code;
daveyclk 1:070fc531e5cb 1121 }
daveyclk 1:070fc531e5cb 1122
daveyclk 1:070fc531e5cb 1123 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1124
daveyclk 1:070fc531e5cb 1125 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1126 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1127
daveyclk 1:070fc531e5cb 1128 return tmp_resp;
daveyclk 1:070fc531e5cb 1129 }
daveyclk 1:070fc531e5cb 1130
daveyclk 1:070fc531e5cb 1131 uint16_t tts_codec_start( uint8_t *codec_data,
daveyclk 1:070fc531e5cb 1132 uint16_t count )
daveyclk 1:070fc531e5cb 1133 {
daveyclk 1:070fc531e5cb 1134 bool tmp_f = false;
daveyclk 1:070fc531e5cb 1135 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1136 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1137
daveyclk 1:070fc531e5cb 1138 if ( count != 512 || count != 1024 || count != 2048 )
daveyclk 1:070fc531e5cb 1139 return 0xFFFF;
GregC 0:ac93d26bbdb5 1140
daveyclk 1:070fc531e5cb 1141 while( !_spc_fin_f )
daveyclk 1:070fc531e5cb 1142 {
daveyclk 1:070fc531e5cb 1143 tts_get_resp();
daveyclk 1:070fc531e5cb 1144
daveyclk 1:070fc531e5cb 1145 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1146 return _err_code;
daveyclk 1:070fc531e5cb 1147 }
daveyclk 1:070fc531e5cb 1148
daveyclk 1:070fc531e5cb 1149 tts_parse_req( ISC_SPCODEC_START_REQ , codec_data, count );
daveyclk 1:070fc531e5cb 1150
daveyclk 1:070fc531e5cb 1151 _spc_rdy_f = 0;
daveyclk 1:070fc531e5cb 1152 _spc_fin_f = 0;
daveyclk 1:070fc531e5cb 1153
daveyclk 1:070fc531e5cb 1154 while( !( tmp_f && _spc_rdy_f ) )
daveyclk 1:070fc531e5cb 1155 {
daveyclk 1:070fc531e5cb 1156 tts_get_resp();
daveyclk 1:070fc531e5cb 1157
daveyclk 1:070fc531e5cb 1158 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1159 return _err_code;
daveyclk 1:070fc531e5cb 1160
daveyclk 1:070fc531e5cb 1161 if( tts_rsp_chk( ISC_TTS_SPEAK_RESP ) )
daveyclk 1:070fc531e5cb 1162 {
daveyclk 1:070fc531e5cb 1163 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1164
daveyclk 1:070fc531e5cb 1165 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1166 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1167 tmp_f = true;
daveyclk 1:070fc531e5cb 1168 }
daveyclk 1:070fc531e5cb 1169 }
daveyclk 1:070fc531e5cb 1170
daveyclk 1:070fc531e5cb 1171 return tmp_resp;
daveyclk 1:070fc531e5cb 1172 }
daveyclk 1:070fc531e5cb 1173
daveyclk 1:070fc531e5cb 1174 uint16_t tts_codec_pause()
daveyclk 1:070fc531e5cb 1175 {
daveyclk 1:070fc531e5cb 1176 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1177 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1178 uint8_t tmp_data[ 2 ] = { 1, 0 };
daveyclk 1:070fc531e5cb 1179
daveyclk 1:070fc531e5cb 1180 tts_parse_req( ISC_SPCODEC_PAUSE_REQ , tmp_data, 2 );
daveyclk 1:070fc531e5cb 1181
daveyclk 1:070fc531e5cb 1182 while( !tts_rsp_chk( ISC_SPCODEC_PAUSE_RESP ) )
daveyclk 1:070fc531e5cb 1183 {
daveyclk 1:070fc531e5cb 1184 tts_get_resp();
daveyclk 1:070fc531e5cb 1185
daveyclk 1:070fc531e5cb 1186 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1187 return _err_code;
daveyclk 1:070fc531e5cb 1188 }
daveyclk 1:070fc531e5cb 1189
daveyclk 1:070fc531e5cb 1190 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1191
daveyclk 1:070fc531e5cb 1192 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1193 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1194
daveyclk 1:070fc531e5cb 1195 return tmp_resp;
daveyclk 1:070fc531e5cb 1196 }
daveyclk 1:070fc531e5cb 1197
daveyclk 1:070fc531e5cb 1198 uint16_t tts_codec_unpause()
daveyclk 1:070fc531e5cb 1199 {
daveyclk 1:070fc531e5cb 1200 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1201 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1202 uint8_t tmp_data[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1203
daveyclk 1:070fc531e5cb 1204 tts_parse_req( ISC_SPCODEC_PAUSE_REQ , tmp_data, 2 );
daveyclk 1:070fc531e5cb 1205
daveyclk 1:070fc531e5cb 1206 while( !tts_rsp_chk( ISC_SPCODEC_PAUSE_RESP ) )
daveyclk 1:070fc531e5cb 1207 {
daveyclk 1:070fc531e5cb 1208 tts_get_resp();
daveyclk 1:070fc531e5cb 1209
daveyclk 1:070fc531e5cb 1210 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1211 return _err_code;
daveyclk 1:070fc531e5cb 1212 }
daveyclk 1:070fc531e5cb 1213
daveyclk 1:070fc531e5cb 1214 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1215
daveyclk 1:070fc531e5cb 1216 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1217 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1218
daveyclk 1:070fc531e5cb 1219 return tmp_resp;
daveyclk 1:070fc531e5cb 1220 }
daveyclk 1:070fc531e5cb 1221
daveyclk 1:070fc531e5cb 1222 uint16_t tts_codec_stop( bool reset )
daveyclk 1:070fc531e5cb 1223 {
daveyclk 1:070fc531e5cb 1224 uint16_t tmp_resp = 0;
daveyclk 1:070fc531e5cb 1225 uint8_t raw_resp[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1226 uint8_t tmp_data[ 2 ] = { 0 };
daveyclk 1:070fc531e5cb 1227
daveyclk 1:070fc531e5cb 1228 if( reset )
daveyclk 1:070fc531e5cb 1229 tmp_data[ 0 ] = 1;
daveyclk 1:070fc531e5cb 1230
daveyclk 1:070fc531e5cb 1231 tts_parse_req( ISC_SPCODEC_STOP_REQ, tmp_data, 2 );
daveyclk 1:070fc531e5cb 1232
daveyclk 1:070fc531e5cb 1233 while( !tts_rsp_chk( ISC_SPCODEC_PAUSE_RESP ) )
daveyclk 1:070fc531e5cb 1234 {
daveyclk 1:070fc531e5cb 1235 tts_get_resp();
daveyclk 1:070fc531e5cb 1236
daveyclk 1:070fc531e5cb 1237 if( _parse_ind() )
daveyclk 1:070fc531e5cb 1238 return _err_code;
daveyclk 1:070fc531e5cb 1239 }
daveyclk 1:070fc531e5cb 1240
daveyclk 1:070fc531e5cb 1241 tts_rsp_data( raw_resp );
daveyclk 1:070fc531e5cb 1242
daveyclk 1:070fc531e5cb 1243 tmp_resp |= raw_resp[ 0 ];
daveyclk 1:070fc531e5cb 1244 tmp_resp |= raw_resp[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1245
daveyclk 1:070fc531e5cb 1246 return tmp_resp;
daveyclk 1:070fc531e5cb 1247 }
daveyclk 1:070fc531e5cb 1248 /******************************************************************************
daveyclk 1:070fc531e5cb 1249 * text_to_speech_hw.c
daveyclk 1:070fc531e5cb 1250 *******************************************************************************/
daveyclk 1:070fc531e5cb 1251 void _read_rsp()
daveyclk 1:070fc531e5cb 1252 {
daveyclk 1:070fc531e5cb 1253 uint8_t tmp_byte = 0;
daveyclk 1:070fc531e5cb 1254 uint16_t tmp_len = 0;
daveyclk 1:070fc531e5cb 1255
daveyclk 1:070fc531e5cb 1256 tts_hal_cs_low();
GregC 0:ac93d26bbdb5 1257
daveyclk 1:070fc531e5cb 1258 tts_hal_read( &tmp_byte, 1 );
GregC 0:ac93d26bbdb5 1259
daveyclk 1:070fc531e5cb 1260 if( tmp_byte == START_MESSAGE )
daveyclk 1:070fc531e5cb 1261 {
daveyclk 1:070fc531e5cb 1262
daveyclk 1:070fc531e5cb 1263 tts_hal_read( ( uint8_t* )&_last_rsp, 2 );
daveyclk 1:070fc531e5cb 1264 tmp_len |= _last_rsp.len[ 0 ];
daveyclk 1:070fc531e5cb 1265 tmp_len |= _last_rsp.len[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1266 tts_hal_read( ( uint8_t* )&_last_rsp + 2, tmp_len );
GregC 0:ac93d26bbdb5 1267
daveyclk 1:070fc531e5cb 1268 } else {
daveyclk 1:070fc531e5cb 1269
daveyclk 1:070fc531e5cb 1270 wait( 0.005 );
daveyclk 1:070fc531e5cb 1271 }
daveyclk 1:070fc531e5cb 1272
daveyclk 1:070fc531e5cb 1273 tts_hal_cs_high();
daveyclk 1:070fc531e5cb 1274 }
daveyclk 1:070fc531e5cb 1275
daveyclk 1:070fc531e5cb 1276 void _write_req(bool boot)
daveyclk 1:070fc531e5cb 1277 {
daveyclk 1:070fc531e5cb 1278 uint16_t cnt = 0;
daveyclk 1:070fc531e5cb 1279 uint8_t start = START_MESSAGE;
daveyclk 1:070fc531e5cb 1280
daveyclk 1:070fc531e5cb 1281 cnt |= _last_req.len[ 0 ];
daveyclk 1:070fc531e5cb 1282 cnt |= _last_req.len[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1283
daveyclk 1:070fc531e5cb 1284 tts_hal_cs_low();
daveyclk 1:070fc531e5cb 1285
daveyclk 1:070fc531e5cb 1286
daveyclk 1:070fc531e5cb 1287 if(boot)
daveyclk 1:070fc531e5cb 1288 {
daveyclk 1:070fc531e5cb 1289 tts_hal_write( &start, 1, true );
daveyclk 1:070fc531e5cb 1290 tts_hal_write( ( uint8_t* )&_last_req, cnt, true);
daveyclk 1:070fc531e5cb 1291 }
daveyclk 1:070fc531e5cb 1292 else
daveyclk 1:070fc531e5cb 1293 {
daveyclk 1:070fc531e5cb 1294 tts_hal_write( &start, 1, false );
daveyclk 1:070fc531e5cb 1295 tts_hal_write( ( uint8_t* ) &_last_req, cnt, false );
daveyclk 1:070fc531e5cb 1296 }
daveyclk 1:070fc531e5cb 1297
daveyclk 1:070fc531e5cb 1298 tts_hal_cs_high();
daveyclk 1:070fc531e5cb 1299
daveyclk 1:070fc531e5cb 1300 }
daveyclk 1:070fc531e5cb 1301
daveyclk 1:070fc531e5cb 1302 /******************************************************************************
daveyclk 1:070fc531e5cb 1303 * Public Function Definitions
daveyclk 1:070fc531e5cb 1304 *******************************************************************************/
daveyclk 1:070fc531e5cb 1305 void tts_hw_init( void )
daveyclk 1:070fc531e5cb 1306 {
daveyclk 1:070fc531e5cb 1307 tts_hal_init();
daveyclk 1:070fc531e5cb 1308
daveyclk 1:070fc531e5cb 1309 _ticker_f = false;
daveyclk 1:070fc531e5cb 1310 _ticker = 0;
daveyclk 1:070fc531e5cb 1311
daveyclk 1:070fc531e5cb 1312 _last_req.idx[ 0 ] = 0;
daveyclk 1:070fc531e5cb 1313 _last_req.idx[ 1 ] = 0;
daveyclk 1:070fc531e5cb 1314 _last_req.len[ 0 ] = 0;
daveyclk 1:070fc531e5cb 1315 _last_req.len[ 1 ] = 0;
daveyclk 1:070fc531e5cb 1316 memset( _last_req.payload, 0, MAIN_MESSAGE_MAX );
daveyclk 1:070fc531e5cb 1317
daveyclk 1:070fc531e5cb 1318 _last_rsp.idx[ 0 ] = 255;
daveyclk 1:070fc531e5cb 1319 _last_rsp.idx[ 1 ] = 255;
daveyclk 1:070fc531e5cb 1320 _last_rsp.len[ 0 ] = 0;
daveyclk 1:070fc531e5cb 1321 _last_rsp.len[ 1 ] = 0;
daveyclk 1:070fc531e5cb 1322 memset( _last_rsp.payload, 0, RESP_MESSAGE_MAX );
daveyclk 1:070fc531e5cb 1323 }
daveyclk 1:070fc531e5cb 1324
daveyclk 1:070fc531e5cb 1325 void tts_tick_isr()
daveyclk 1:070fc531e5cb 1326 {
daveyclk 1:070fc531e5cb 1327 _ticker++;
daveyclk 1:070fc531e5cb 1328
daveyclk 1:070fc531e5cb 1329 if( _ticker > 500 )
daveyclk 1:070fc531e5cb 1330 _ticker_f == true;
daveyclk 1:070fc531e5cb 1331 }
daveyclk 1:070fc531e5cb 1332
daveyclk 1:070fc531e5cb 1333 void tts_mute_cmd( bool cmd )
daveyclk 1:070fc531e5cb 1334 {
daveyclk 1:070fc531e5cb 1335 if( cmd )
daveyclk 1:070fc531e5cb 1336 tts_hal_mut_high();
daveyclk 1:070fc531e5cb 1337 else
daveyclk 1:070fc531e5cb 1338 tts_hal_mut_low();
daveyclk 1:070fc531e5cb 1339 }
daveyclk 1:070fc531e5cb 1340
daveyclk 1:070fc531e5cb 1341 void tts_parse_req( uint16_t req,
daveyclk 1:070fc531e5cb 1342 uint8_t *payload,
daveyclk 1:070fc531e5cb 1343 uint16_t pl_len )
daveyclk 1:070fc531e5cb 1344 {
daveyclk 1:070fc531e5cb 1345 uint8_t *pl = payload;
daveyclk 1:070fc531e5cb 1346 uint16_t i = 0;
daveyclk 1:070fc531e5cb 1347 uint16_t tmp = pl_len + 4;
daveyclk 1:070fc531e5cb 1348
daveyclk 1:070fc531e5cb 1349
daveyclk 1:070fc531e5cb 1350
daveyclk 1:070fc531e5cb 1351 _last_req.len[ 0 ] = tmp & 0x00FF;
daveyclk 1:070fc531e5cb 1352 _last_req.len[ 1 ] = ( tmp & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 1353 _last_req.idx[ 0 ] = req & 0x00FF;
daveyclk 1:070fc531e5cb 1354 _last_req.idx[ 1 ] = ( req & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 1355 _last_rsp.idx[ 0 ] = 0xFF;
daveyclk 1:070fc531e5cb 1356 _last_rsp.idx[ 1 ] = 0xFF;
daveyclk 1:070fc531e5cb 1357
daveyclk 1:070fc531e5cb 1358 if ( payload != NULL )
daveyclk 1:070fc531e5cb 1359 {
daveyclk 1:070fc531e5cb 1360 while ( pl_len-- )
daveyclk 1:070fc531e5cb 1361 _last_req.payload[ i++ ] = *( pl++ );
daveyclk 1:070fc531e5cb 1362
GregC 0:ac93d26bbdb5 1363 }
daveyclk 1:070fc531e5cb 1364
daveyclk 1:070fc531e5cb 1365 _write_req(true);
daveyclk 1:070fc531e5cb 1366 }
daveyclk 1:070fc531e5cb 1367
daveyclk 1:070fc531e5cb 1368 void tts_parse_boot_img( const uint8_t *payload,
daveyclk 1:070fc531e5cb 1369 uint16_t pl_len )
daveyclk 1:070fc531e5cb 1370 {
daveyclk 1:070fc531e5cb 1371
daveyclk 1:070fc531e5cb 1372
daveyclk 1:070fc531e5cb 1373 uint16_t i = 0;
daveyclk 1:070fc531e5cb 1374 uint16_t tmp = pl_len + 0x04;
daveyclk 1:070fc531e5cb 1375
daveyclk 1:070fc531e5cb 1376 _last_req.len[ 0 ] = tmp & 0x00FF;
daveyclk 1:070fc531e5cb 1377 _last_req.len[ 1 ] = ( tmp & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 1378 _last_req.idx[ 0 ] = 0x00;
daveyclk 1:070fc531e5cb 1379 _last_req.idx[ 1 ] = 0x10;
daveyclk 1:070fc531e5cb 1380 _last_rsp.idx[ 0 ] = 0xFF;
daveyclk 1:070fc531e5cb 1381 _last_rsp.idx[ 1 ] = 0xFF;
daveyclk 1:070fc531e5cb 1382
daveyclk 1:070fc531e5cb 1383 if ( payload != NULL )
daveyclk 1:070fc531e5cb 1384 {
daveyclk 1:070fc531e5cb 1385 while ( pl_len-- )
daveyclk 1:070fc531e5cb 1386 _last_req.payload[ i++ ] = payload[ i ];
daveyclk 1:070fc531e5cb 1387 }
daveyclk 1:070fc531e5cb 1388
daveyclk 1:070fc531e5cb 1389 _write_req(true);
daveyclk 1:070fc531e5cb 1390 }
daveyclk 1:070fc531e5cb 1391
daveyclk 1:070fc531e5cb 1392 void tts_parse_speak_req( uint16_t req,
daveyclk 1:070fc531e5cb 1393 uint8_t flush_en,
daveyclk 1:070fc531e5cb 1394 char *word,
daveyclk 1:070fc531e5cb 1395 uint16_t word_len )
daveyclk 1:070fc531e5cb 1396 {
daveyclk 1:070fc531e5cb 1397 char *ptr = word;
daveyclk 1:070fc531e5cb 1398 uint16_t i = 1;
daveyclk 1:070fc531e5cb 1399 uint16_t tmp = word_len;
daveyclk 1:070fc531e5cb 1400
daveyclk 1:070fc531e5cb 1401 word_len += 7;
daveyclk 1:070fc531e5cb 1402
daveyclk 1:070fc531e5cb 1403 _last_req.len[ 0 ] = word_len & 0x00FF;
daveyclk 1:070fc531e5cb 1404 _last_req.len[ 1 ] = ( word_len & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 1405 _last_req.idx[ 0 ] = req & 0x00FF;
daveyclk 1:070fc531e5cb 1406 _last_req.idx[ 1 ] = ( req & 0xFF00 ) >> 8;
daveyclk 1:070fc531e5cb 1407 _last_rsp.idx[ 0 ] = 0xFF;
daveyclk 1:070fc531e5cb 1408 _last_rsp.idx[ 1 ] = 0xFF;
daveyclk 1:070fc531e5cb 1409
daveyclk 1:070fc531e5cb 1410 if( flush_en )
daveyclk 1:070fc531e5cb 1411 {
daveyclk 1:070fc531e5cb 1412 _last_req.payload[ 0 ] = 1;
daveyclk 1:070fc531e5cb 1413
daveyclk 1:070fc531e5cb 1414 } else {
daveyclk 1:070fc531e5cb 1415
daveyclk 1:070fc531e5cb 1416 _last_req.payload[ 0 ] = 0;
daveyclk 1:070fc531e5cb 1417 }
daveyclk 1:070fc531e5cb 1418
daveyclk 1:070fc531e5cb 1419 while( tmp-- )
daveyclk 1:070fc531e5cb 1420 _last_req.payload[ i++ ] = *( ptr++ );
daveyclk 1:070fc531e5cb 1421
daveyclk 1:070fc531e5cb 1422 _last_req.payload[ i++ ] = 0x20;
daveyclk 1:070fc531e5cb 1423 _last_req.payload[ i ] = 0x00;
daveyclk 1:070fc531e5cb 1424
daveyclk 1:070fc531e5cb 1425 _write_req(true);
daveyclk 1:070fc531e5cb 1426 }
daveyclk 1:070fc531e5cb 1427
daveyclk 1:070fc531e5cb 1428 void tts_get_resp()
daveyclk 1:070fc531e5cb 1429 {
daveyclk 1:070fc531e5cb 1430 if( tts_hal_msg_rdy() )
daveyclk 1:070fc531e5cb 1431 {
daveyclk 1:070fc531e5cb 1432 _read_rsp();
daveyclk 1:070fc531e5cb 1433 }
daveyclk 1:070fc531e5cb 1434 }
daveyclk 1:070fc531e5cb 1435
daveyclk 1:070fc531e5cb 1436 bool tts_rsp_chk( uint16_t idx )
daveyclk 1:070fc531e5cb 1437 {
daveyclk 1:070fc531e5cb 1438 uint16_t tmp = 0;
daveyclk 1:070fc531e5cb 1439
daveyclk 1:070fc531e5cb 1440 tmp |= _last_rsp.idx[ 0 ];
daveyclk 1:070fc531e5cb 1441 tmp |= _last_rsp.idx[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1442
daveyclk 1:070fc531e5cb 1443 // pc.printf(" idx = %X\n\r", tmp);
daveyclk 1:070fc531e5cb 1444
daveyclk 1:070fc531e5cb 1445 return ( idx == tmp ) ? true : false;
daveyclk 1:070fc531e5cb 1446 }
daveyclk 1:070fc531e5cb 1447
daveyclk 1:070fc531e5cb 1448 uint16_t tts_rsp_idx()
daveyclk 1:070fc531e5cb 1449 {
daveyclk 1:070fc531e5cb 1450 uint16_t tmp = 0;
daveyclk 1:070fc531e5cb 1451
daveyclk 1:070fc531e5cb 1452 tmp |= _last_rsp.idx[ 0 ];
daveyclk 1:070fc531e5cb 1453 tmp |= _last_rsp.idx[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1454
daveyclk 1:070fc531e5cb 1455 return tmp;
daveyclk 1:070fc531e5cb 1456 }
daveyclk 1:070fc531e5cb 1457
daveyclk 1:070fc531e5cb 1458 void tts_rsp_data( uint8_t *buffer )
daveyclk 1:070fc531e5cb 1459 {
daveyclk 1:070fc531e5cb 1460 uint8_t *bfr = buffer;
daveyclk 1:070fc531e5cb 1461 uint16_t cnt = 0;
daveyclk 1:070fc531e5cb 1462 uint8_t *ptr = _last_rsp.payload;
daveyclk 1:070fc531e5cb 1463
daveyclk 1:070fc531e5cb 1464 cnt |= _last_rsp.len[ 0 ];
daveyclk 1:070fc531e5cb 1465 cnt |= _last_rsp.len[ 1 ] << 8;
daveyclk 1:070fc531e5cb 1466 cnt -= 4;
daveyclk 1:070fc531e5cb 1467
daveyclk 1:070fc531e5cb 1468 while( cnt-- )
daveyclk 1:070fc531e5cb 1469 *( bfr++ ) = *( ptr++ );
daveyclk 1:070fc531e5cb 1470 }
daveyclk 1:070fc531e5cb 1471
daveyclk 1:070fc531e5cb 1472 /*************** END OF FUNCTIONS *********************************************/