does not work yet. Sound starts but then stops after a few seconds, whole thing hangs. Published so as I can import through mbed CLI.

Dependencies:   mbed sinelookup SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Mon Oct 01 18:58:35 2018 +0000
Revision:
0:004cb0595aa8
Child:
1:ec4e2020522c
current version does not print everything due to weird error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roryhand 0:004cb0595aa8 1
roryhand 0:004cb0595aa8 2 // 24/03/2018 update - I appear to be able to address the device and write something, as I am getting an ACK returned from the i2c write() function.
roryhand 0:004cb0595aa8 3 //however if i use the write function with 4 arguments (as opposed to just 1 argument) then it doesnt work
roryhand 0:004cb0595aa8 4 //only works with the 1 argument version!!!
roryhand 0:004cb0595aa8 5
roryhand 0:004cb0595aa8 6
roryhand 0:004cb0595aa8 7 //THIS VERSION WORKED, CHANGED SOME THINGS, THEN CHANGED THEM BACK. NOW IT NO LONGER WORKS!!!!
roryhand 0:004cb0595aa8 8 #include "mbed.h"
roryhand 0:004cb0595aa8 9 #include "sinelookup.h"
roryhand 0:004cb0595aa8 10 #include "I2S.h"
roryhand 0:004cb0595aa8 11 #define sample_freq 48000
roryhand 0:004cb0595aa8 12 DigitalOut myled(LED1);
roryhand 0:004cb0595aa8 13 DigitalOut led2(LED2);
roryhand 0:004cb0595aa8 14 DigitalOut led3(LED3);
roryhand 0:004cb0595aa8 15 Ticker sampletick;
roryhand 0:004cb0595aa8 16 Timer t;
roryhand 0:004cb0595aa8 17 #include "SDFileSystem.h"
roryhand 0:004cb0595aa8 18 #include "WOLFSON_config.h"
roryhand 0:004cb0595aa8 19 Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
roryhand 0:004cb0595aa8 20 DigitalOut cs(p8);
roryhand 0:004cb0595aa8 21 I2S i2s(I2S_TRANSMIT,p5,p6,p7);
roryhand 0:004cb0595aa8 22 I2C i2c(p9, p10);
roryhand 0:004cb0595aa8 23
roryhand 0:004cb0595aa8 24 SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
roryhand 0:004cb0595aa8 25
roryhand 0:004cb0595aa8 26 typedef struct uFMT_STRUCT{
roryhand 0:004cb0595aa8 27 short comp_code;
roryhand 0:004cb0595aa8 28 short num_channels;
roryhand 0:004cb0595aa8 29 unsigned sample_rate;
roryhand 0:004cb0595aa8 30 unsigned avg_Bps;
roryhand 0:004cb0595aa8 31 short block_align;
roryhand 0:004cb0595aa8 32 short sig_bps;
roryhand 0:004cb0595aa8 33 } FMT_STRUCT;
roryhand 0:004cb0595aa8 34
roryhand 0:004cb0595aa8 35 typedef struct uDATA_STRUCT {
roryhand 0:004cb0595aa8 36 unsigned subchunk2_ID;
roryhand 0:004cb0595aa8 37 unsigned subchunk2_size;
roryhand 0:004cb0595aa8 38 char * data_buf;
roryhand 0:004cb0595aa8 39 }DATA_STRUCT;
roryhand 0:004cb0595aa8 40 short hello;
roryhand 0:004cb0595aa8 41 int i = 0;
roryhand 0:004cb0595aa8 42 int h = 0;
roryhand 0:004cb0595aa8 43 int bufflen = 1;
roryhand 0:004cb0595aa8 44 int buffer[1];
roryhand 0:004cb0595aa8 45 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
roryhand 0:004cb0595aa8 46 char *slice_buf;
roryhand 0:004cb0595aa8 47 int *data_sptr;
roryhand 0:004cb0595aa8 48 int newvar;
roryhand 0:004cb0595aa8 49 //long long slice_value;
roryhand 0:004cb0595aa8 50 int slice_value;
roryhand 0:004cb0595aa8 51 FILE *my_wav;
roryhand 0:004cb0595aa8 52 FMT_STRUCT wav_format;
roryhand 0:004cb0595aa8 53 DATA_STRUCT wav_data;
roryhand 0:004cb0595aa8 54
roryhand 0:004cb0595aa8 55 Ticker flipper;
roryhand 0:004cb0595aa8 56 //test
roryhand 0:004cb0595aa8 57 void flip() {
roryhand 0:004cb0595aa8 58 led2 = !led2;
roryhand 0:004cb0595aa8 59 }
roryhand 0:004cb0595aa8 60
roryhand 0:004cb0595aa8 61
roryhand 0:004cb0595aa8 62 void isr()
roryhand 0:004cb0595aa8 63 {
roryhand 0:004cb0595aa8 64
roryhand 0:004cb0595aa8 65 //buffer[0] = (int*)data_sptr;
roryhand 0:004cb0595aa8 66 //buffer[0] = newvar;
roryhand 0:004cb0595aa8 67 //buffer[0] = sine16lookup[i];//>>1;//sine16lookup[i];//scale down volume a bit on amp//how would this scale down the volume a bit??
roryhand 0:004cb0595aa8 68 //buffer[0] = *fp;
roryhand 0:004cb0595aa8 69 //printf("value: %d",data_sptr);
roryhand 0:004cb0595aa8 70 //i2s.write(buffer, 2);//Send next PWM value to amp
roryhand 0:004cb0595aa8 71 }
roryhand 0:004cb0595aa8 72 //i++;
roryhand 0:004cb0595aa8 73 //int hi =i2s.read(buffer[0], bufflen);
roryhand 0:004cb0595aa8 74 //i2s.stop();
roryhand 0:004cb0595aa8 75 //pc.printf("%d", buffer[0]);
roryhand 0:004cb0595aa8 76
roryhand 0:004cb0595aa8 77 //pc.printf("Playing Sound!!\n");//0 = ack, 1 = Nack
roryhand 0:004cb0595aa8 78 //if (i>= SINE16LENGTH) {//SINE16LENGTH) {
roryhand 0:004cb0595aa8 79 /*if (i>= wav_format.block_align){
roryhand 0:004cb0595aa8 80 i = 0;
roryhand 0:004cb0595aa8 81 i2s.stop();
roryhand 0:004cb0595aa8 82 sampletick.detach();
roryhand 0:004cb0595aa8 83
roryhand 0:004cb0595aa8 84 //pc.printf("Sound ended!!");
roryhand 0:004cb0595aa8 85 myled = 0;
roryhand 0:004cb0595aa8 86 CE
roryhand 0:004cb0595aa8 87 }
roryhand 0:004cb0595aa8 88
roryhand 0:004cb0595aa8 89 }*/
roryhand 0:004cb0595aa8 90
roryhand 0:004cb0595aa8 91 void wm8731_setup(int chip_addr, int addr, int cmd){
roryhand 0:004cb0595aa8 92 addr = addr << 1;
roryhand 0:004cb0595aa8 93 addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
roryhand 0:004cb0595aa8 94 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 95 i2c.start();
roryhand 0:004cb0595aa8 96 i2c.write( chip_addr );
roryhand 0:004cb0595aa8 97 i2c.write( addr );
roryhand 0:004cb0595aa8 98 i2c.write( cmd );
roryhand 0:004cb0595aa8 99 i2c.stop();
roryhand 0:004cb0595aa8 100 }
roryhand 0:004cb0595aa8 101
roryhand 0:004cb0595aa8 102
roryhand 0:004cb0595aa8 103 void wm8731_config(void){
roryhand 0:004cb0595aa8 104 wm8731_setup( WM8731_ADDRESS, WM8731_REG_RESET, _WM8731_RESET );//1
roryhand 0:004cb0595aa8 105 wm8731_setup( WM8731_ADDRESS, WM8731_REG_LLINE_IN, _WM8731_LEFT_LINEIN );//2
roryhand 0:004cb0595aa8 106 wm8731_setup( WM8731_ADDRESS, WM8731_REG_RLINE_IN, _WM8731_RIGHT_LINEIN );//3
roryhand 0:004cb0595aa8 107 wm8731_setup( WM8731_ADDRESS, WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP );//4
roryhand 0:004cb0595aa8 108 wm8731_setup( WM8731_ADDRESS, WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP );//5
roryhand 0:004cb0595aa8 109 wm8731_setup( WM8731_ADDRESS, WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO );//6
roryhand 0:004cb0595aa8 110 wm8731_setup( WM8731_ADDRESS, WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO );//7
roryhand 0:004cb0595aa8 111 wm8731_setup( WM8731_ADDRESS, WM8731_REG_PDOWN_CTRL, _WM8731_POWER );//8
roryhand 0:004cb0595aa8 112 wm8731_setup( WM8731_ADDRESS, WM8731_REG_DIGITAL_IF, _WM8731_DAIF );//9
roryhand 0:004cb0595aa8 113 wm8731_setup( WM8731_ADDRESS, WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING );//10
roryhand 0:004cb0595aa8 114 }
roryhand 0:004cb0595aa8 115
roryhand 0:004cb0595aa8 116 void wm8731_configTEST(void){
roryhand 0:004cb0595aa8 117 int addr = WM8731_REG_RESET;
roryhand 0:004cb0595aa8 118 int cmd = _WM8731_RESET;
roryhand 0:004cb0595aa8 119 addr = addr << 1;
roryhand 0:004cb0595aa8 120 addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
roryhand 0:004cb0595aa8 121 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 122 i2c.start();
roryhand 0:004cb0595aa8 123 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 124 i2c.write( addr );
roryhand 0:004cb0595aa8 125 i2c.write( cmd );
roryhand 0:004cb0595aa8 126 i2c.stop();
roryhand 0:004cb0595aa8 127
roryhand 0:004cb0595aa8 128 addr = WM8731_REG_LLINE_IN;
roryhand 0:004cb0595aa8 129 cmd = _WM8731_LEFT_LINEIN;
roryhand 0:004cb0595aa8 130 addr = addr << 1;
roryhand 0:004cb0595aa8 131 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 132 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 133 i2c.start();
roryhand 0:004cb0595aa8 134 i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
roryhand 0:004cb0595aa8 135 i2c.write( addr );
roryhand 0:004cb0595aa8 136 i2c.write( cmd );
roryhand 0:004cb0595aa8 137 i2c.stop();
roryhand 0:004cb0595aa8 138
roryhand 0:004cb0595aa8 139
roryhand 0:004cb0595aa8 140 addr = WM8731_REG_RLINE_IN;
roryhand 0:004cb0595aa8 141 cmd = _WM8731_RIGHT_LINEIN;
roryhand 0:004cb0595aa8 142 addr = addr << 1;
roryhand 0:004cb0595aa8 143 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 144 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 145 i2c.start();
roryhand 0:004cb0595aa8 146 i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
roryhand 0:004cb0595aa8 147 i2c.write( addr );
roryhand 0:004cb0595aa8 148 i2c.write( cmd );
roryhand 0:004cb0595aa8 149 i2c.stop();
roryhand 0:004cb0595aa8 150
roryhand 0:004cb0595aa8 151
roryhand 0:004cb0595aa8 152 //4
roryhand 0:004cb0595aa8 153 addr = WM8731_REG_LHPHONE_OUT;
roryhand 0:004cb0595aa8 154 cmd = _WM8731_LEFT_HP;
roryhand 0:004cb0595aa8 155 addr = addr << 1;
roryhand 0:004cb0595aa8 156 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 157 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 158 i2c.start();
roryhand 0:004cb0595aa8 159 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 160 i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP
roryhand 0:004cb0595aa8 161 i2c.write(cmd);
roryhand 0:004cb0595aa8 162 i2c.stop();
roryhand 0:004cb0595aa8 163
roryhand 0:004cb0595aa8 164 //5
roryhand 0:004cb0595aa8 165 addr = WM8731_REG_RHPHONE_OUT;
roryhand 0:004cb0595aa8 166 cmd = _WM8731_RIGHT_HP;
roryhand 0:004cb0595aa8 167 addr = addr << 1;
roryhand 0:004cb0595aa8 168 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 169 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 170 i2c.start();
roryhand 0:004cb0595aa8 171 i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP
roryhand 0:004cb0595aa8 172 i2c.write( addr );
roryhand 0:004cb0595aa8 173 i2c.write( cmd );
roryhand 0:004cb0595aa8 174 i2c.stop();
roryhand 0:004cb0595aa8 175
roryhand 0:004cb0595aa8 176
roryhand 0:004cb0595aa8 177 //6
roryhand 0:004cb0595aa8 178 addr = WM8731_REG_ANALOG_PATH;
roryhand 0:004cb0595aa8 179 cmd = _WM8731_ANALOGAUDIO;
roryhand 0:004cb0595aa8 180 addr = addr << 1;
roryhand 0:004cb0595aa8 181 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 182 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 183 i2c.start();
roryhand 0:004cb0595aa8 184 i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
roryhand 0:004cb0595aa8 185 i2c.write( addr );
roryhand 0:004cb0595aa8 186 i2c.write( cmd );
roryhand 0:004cb0595aa8 187 i2c.stop();
roryhand 0:004cb0595aa8 188
roryhand 0:004cb0595aa8 189 //7
roryhand 0:004cb0595aa8 190 addr = WM8731_REG_DIGITAL_PATH;
roryhand 0:004cb0595aa8 191 cmd = _WM8731_DIGITALAUDIO;
roryhand 0:004cb0595aa8 192 addr = addr << 1;
roryhand 0:004cb0595aa8 193 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 194 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 195 i2c.start();
roryhand 0:004cb0595aa8 196 i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
roryhand 0:004cb0595aa8 197 i2c.write( addr );
roryhand 0:004cb0595aa8 198 i2c.write( cmd );
roryhand 0:004cb0595aa8 199 i2c.stop();
roryhand 0:004cb0595aa8 200
roryhand 0:004cb0595aa8 201 //8
roryhand 0:004cb0595aa8 202 addr = WM8731_REG_PDOWN_CTRL;
roryhand 0:004cb0595aa8 203 cmd = _WM8731_POWER;
roryhand 0:004cb0595aa8 204 addr = addr << 1;
roryhand 0:004cb0595aa8 205 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 206 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 207 i2c.start();
roryhand 0:004cb0595aa8 208 i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
roryhand 0:004cb0595aa8 209 i2c.write( addr );
roryhand 0:004cb0595aa8 210 i2c.write( cmd );
roryhand 0:004cb0595aa8 211 i2c.stop();
roryhand 0:004cb0595aa8 212
roryhand 0:004cb0595aa8 213
roryhand 0:004cb0595aa8 214 //9
roryhand 0:004cb0595aa8 215 addr = WM8731_REG_DIGITAL_IF;
roryhand 0:004cb0595aa8 216 cmd = _WM8731_DAIF;
roryhand 0:004cb0595aa8 217 addr = addr << 1;
roryhand 0:004cb0595aa8 218 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 219 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 220 i2c.start();
roryhand 0:004cb0595aa8 221 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 222 i2c.write( addr );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
roryhand 0:004cb0595aa8 223 i2c.write( cmd );
roryhand 0:004cb0595aa8 224 i2c.stop();
roryhand 0:004cb0595aa8 225
roryhand 0:004cb0595aa8 226
roryhand 0:004cb0595aa8 227 //10
roryhand 0:004cb0595aa8 228 addr = WM8731_REG_SAMPLING_CTRL;
roryhand 0:004cb0595aa8 229 cmd = _WM8731_SAMPLING;
roryhand 0:004cb0595aa8 230 addr = addr << 1;
roryhand 0:004cb0595aa8 231 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 232 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 233 i2c.start();
roryhand 0:004cb0595aa8 234 i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
roryhand 0:004cb0595aa8 235 i2c.write( addr );
roryhand 0:004cb0595aa8 236 i2c.write( cmd );
roryhand 0:004cb0595aa8 237 i2c.stop();
roryhand 0:004cb0595aa8 238
roryhand 0:004cb0595aa8 239
roryhand 0:004cb0595aa8 240
roryhand 0:004cb0595aa8 241
roryhand 0:004cb0595aa8 242 //11
roryhand 0:004cb0595aa8 243 addr = WM8731_REG_ACTIVE_CTRL;
roryhand 0:004cb0595aa8 244 cmd = _WM8731_ACTIVATE;
roryhand 0:004cb0595aa8 245 addr = addr << 1;
roryhand 0:004cb0595aa8 246 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 247 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 248 i2c.start();
roryhand 0:004cb0595aa8 249 i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
roryhand 0:004cb0595aa8 250 i2c.write( addr );
roryhand 0:004cb0595aa8 251 i2c.write( cmd );//there is also a deactive version!!
roryhand 0:004cb0595aa8 252 i2c.stop();
roryhand 0:004cb0595aa8 253
roryhand 0:004cb0595aa8 254
roryhand 0:004cb0595aa8 255
roryhand 0:004cb0595aa8 256 }
roryhand 0:004cb0595aa8 257
roryhand 0:004cb0595aa8 258 int main() {
roryhand 0:004cb0595aa8 259 FMT_STRUCT wav_format;
roryhand 0:004cb0595aa8 260 char data[2];
roryhand 0:004cb0595aa8 261 pc.printf("Beginning of program\n");
roryhand 0:004cb0595aa8 262 data[0] = 0x0F;
roryhand 0:004cb0595aa8 263 data[1] = 0x00;
roryhand 0:004cb0595aa8 264 FILE *my_wav;
roryhand 0:004cb0595aa8 265 //my_wav = fopen("/sd/mydir/gp40.wav", "rb");//i think that it is "w" for write, "r" for read.
roryhand 0:004cb0595aa8 266 my_wav = fopen("/sd/mydir/gp40_48K.wav", "rb");//i think that it is "w" for write, "r" for read.
roryhand 0:004cb0595aa8 267 fseek(my_wav, 20, SEEK_SET); // set pointer to byte 20
roryhand 0:004cb0595aa8 268 fread(&AudioFormat, 2, 1, my_wav); // check file is PCM
roryhand 0:004cb0595aa8 269 if (AudioFormat==0x01) {
roryhand 0:004cb0595aa8 270 printf("Wav file is PCM data\n\r");
roryhand 0:004cb0595aa8 271 }
roryhand 0:004cb0595aa8 272 else {
roryhand 0:004cb0595aa8 273 printf("Wav file is not PCM data\n\r");
roryhand 0:004cb0595aa8 274 }
roryhand 0:004cb0595aa8 275
roryhand 0:004cb0595aa8 276 fseek (my_wav,20,SEEK_SET);
roryhand 0:004cb0595aa8 277 fread(&wav_format,sizeof(wav_format),1,my_wav);
roryhand 0:004cb0595aa8 278 printf("%d block align\n",wav_format.block_align);
roryhand 0:004cb0595aa8 279 printf(" %d channels\n",wav_format.num_channels);
roryhand 0:004cb0595aa8 280
roryhand 0:004cb0595aa8 281
roryhand 0:004cb0595aa8 282 fseek(my_wav, 36, SEEK_SET);
roryhand 0:004cb0595aa8 283 fread(&wav_data.subchunk2_ID,4,1,my_wav);
roryhand 0:004cb0595aa8 284 fseek(my_wav, 40, SEEK_SET);
roryhand 0:004cb0595aa8 285 fread(&wav_data.subchunk2_size,4,1,my_wav);
roryhand 0:004cb0595aa8 286 printf("DATA chunck\n");
roryhand 0:004cb0595aa8 287 printf(" %d subchunk 2 ID\n",wav_data.subchunk2_ID);
roryhand 0:004cb0595aa8 288 printf(" %d subchunk 2 size\n",wav_data.subchunk2_size);
roryhand 0:004cb0595aa8 289
roryhand 0:004cb0595aa8 290
roryhand 0:004cb0595aa8 291 fseek(my_wav,36,SEEK_SET);
roryhand 0:004cb0595aa8 292 fread(&wav_format.sig_bps,2,1,my_wav);
roryhand 0:004cb0595aa8 293 printf("%d bits per sample\n",wav_format.sig_bps);//check how many bits per sample we have
roryhand 0:004cb0595aa8 294
roryhand 0:004cb0595aa8 295
roryhand 0:004cb0595aa8 296
roryhand 0:004cb0595aa8 297
roryhand 0:004cb0595aa8 298
roryhand 0:004cb0595aa8 299
roryhand 0:004cb0595aa8 300
roryhand 0:004cb0595aa8 301 i2c.frequency(100000);
roryhand 0:004cb0595aa8 302 long j = 0;
roryhand 0:004cb0595aa8 303 /*while(j<1000){
roryhand 0:004cb0595aa8 304 j=j+1;
roryhand 0:004cb0595aa8 305 wm8731_configTEST();
roryhand 0:004cb0595aa8 306 }*/
roryhand 0:004cb0595aa8 307
roryhand 0:004cb0595aa8 308 /*while(j<1000){
roryhand 0:004cb0595aa8 309 j=j+1;
roryhand 0:004cb0595aa8 310 int addr = WM8731_REG_RESET;
roryhand 0:004cb0595aa8 311 int cmd = _WM8731_RESET;
roryhand 0:004cb0595aa8 312 addr = addr << 1;
roryhand 0:004cb0595aa8 313 addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
roryhand 0:004cb0595aa8 314 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 315 i2c.start();
roryhand 0:004cb0595aa8 316 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 317 i2c.write( addr );
roryhand 0:004cb0595aa8 318 i2c.write( cmd );
roryhand 0:004cb0595aa8 319 //wait(1);
roryhand 0:004cb0595aa8 320 i2c.stop();
roryhand 0:004cb0595aa8 321 //}//am receiving ack = 0 i.e. an anknowledgment!!! when I loop round this section. 14/06/18
roryhand 0:004cb0595aa8 322 //}
roryhand 0:004cb0595aa8 323 //i2c.stop();
roryhand 0:004cb0595aa8 324 //while(1){}
roryhand 0:004cb0595aa8 325 //wait(3);
roryhand 0:004cb0595aa8 326 ///try not using the int ack stuff
roryhand 0:004cb0595aa8 327
roryhand 0:004cb0595aa8 328 //pc.printf("Decimals1: %d", ack1);//0 = ack, 1 = Nack
roryhand 0:004cb0595aa8 329 //int ack12 =
roryhand 0:004cb0595aa8 330 //pc.printf("Decimals12: %d", ack12);//0 = ack, 1 = Nack
roryhand 0:004cb0595aa8 331 //int ack13 = i2c.write( cmd );
roryhand 0:004cb0595aa8 332 //pc.printf("Decimals13: %d", ack13);//0 = ack, 1 = Nack
roryhand 0:004cb0595aa8 333 //i2c.stop();
roryhand 0:004cb0595aa8 334
roryhand 0:004cb0595aa8 335 //2
roryhand 0:004cb0595aa8 336
roryhand 0:004cb0595aa8 337 //while(1){
roryhand 0:004cb0595aa8 338 // }
roryhand 0:004cb0595aa8 339
roryhand 0:004cb0595aa8 340
roryhand 0:004cb0595aa8 341 //while(1){
roryhand 0:004cb0595aa8 342 addr = WM8731_REG_LLINE_IN;
roryhand 0:004cb0595aa8 343 cmd = _WM8731_LEFT_LINEIN;
roryhand 0:004cb0595aa8 344 addr = addr << 1;
roryhand 0:004cb0595aa8 345 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 346 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 347 i2c.start();
roryhand 0:004cb0595aa8 348 i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
roryhand 0:004cb0595aa8 349 i2c.write( addr );
roryhand 0:004cb0595aa8 350 i2c.write( cmd );
roryhand 0:004cb0595aa8 351 i2c.stop();
roryhand 0:004cb0595aa8 352
roryhand 0:004cb0595aa8 353
roryhand 0:004cb0595aa8 354 addr = WM8731_REG_RLINE_IN;
roryhand 0:004cb0595aa8 355 cmd = _WM8731_RIGHT_LINEIN;
roryhand 0:004cb0595aa8 356 addr = addr << 1;
roryhand 0:004cb0595aa8 357 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 358 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 359 i2c.start();
roryhand 0:004cb0595aa8 360 i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
roryhand 0:004cb0595aa8 361 i2c.write( addr );
roryhand 0:004cb0595aa8 362 i2c.write( cmd );
roryhand 0:004cb0595aa8 363 i2c.stop();
roryhand 0:004cb0595aa8 364
roryhand 0:004cb0595aa8 365
roryhand 0:004cb0595aa8 366 //4
roryhand 0:004cb0595aa8 367 addr = WM8731_REG_LHPHONE_OUT;
roryhand 0:004cb0595aa8 368 cmd = _WM8731_LEFT_HP;
roryhand 0:004cb0595aa8 369 addr = addr << 1;
roryhand 0:004cb0595aa8 370 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 371 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 372 i2c.start();
roryhand 0:004cb0595aa8 373 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 374 i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP
roryhand 0:004cb0595aa8 375 i2c.write(cmd);
roryhand 0:004cb0595aa8 376 i2c.stop();
roryhand 0:004cb0595aa8 377
roryhand 0:004cb0595aa8 378 //5
roryhand 0:004cb0595aa8 379 addr = WM8731_REG_RHPHONE_OUT;
roryhand 0:004cb0595aa8 380 cmd = _WM8731_RIGHT_HP;
roryhand 0:004cb0595aa8 381 addr = addr << 1;
roryhand 0:004cb0595aa8 382 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 383 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 384 i2c.start();
roryhand 0:004cb0595aa8 385 i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP
roryhand 0:004cb0595aa8 386 i2c.write( addr );
roryhand 0:004cb0595aa8 387 i2c.write( cmd );
roryhand 0:004cb0595aa8 388 i2c.stop();
roryhand 0:004cb0595aa8 389
roryhand 0:004cb0595aa8 390
roryhand 0:004cb0595aa8 391 //6
roryhand 0:004cb0595aa8 392 addr = WM8731_REG_ANALOG_PATH;
roryhand 0:004cb0595aa8 393 cmd = _WM8731_ANALOGAUDIO;
roryhand 0:004cb0595aa8 394 addr = addr << 1;
roryhand 0:004cb0595aa8 395 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 396 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 397 i2c.start();
roryhand 0:004cb0595aa8 398 i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
roryhand 0:004cb0595aa8 399 i2c.write( addr );
roryhand 0:004cb0595aa8 400 i2c.write( cmd );
roryhand 0:004cb0595aa8 401 i2c.stop();
roryhand 0:004cb0595aa8 402
roryhand 0:004cb0595aa8 403 //7
roryhand 0:004cb0595aa8 404 addr = WM8731_REG_DIGITAL_PATH;
roryhand 0:004cb0595aa8 405 cmd = _WM8731_DIGITALAUDIO;
roryhand 0:004cb0595aa8 406 addr = addr << 1;
roryhand 0:004cb0595aa8 407 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 408 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 409 i2c.start();
roryhand 0:004cb0595aa8 410 i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
roryhand 0:004cb0595aa8 411 i2c.write( addr );
roryhand 0:004cb0595aa8 412 i2c.write( cmd );
roryhand 0:004cb0595aa8 413 i2c.stop();
roryhand 0:004cb0595aa8 414
roryhand 0:004cb0595aa8 415 //8
roryhand 0:004cb0595aa8 416 addr = WM8731_REG_PDOWN_CTRL;
roryhand 0:004cb0595aa8 417 cmd = _WM8731_POWER;
roryhand 0:004cb0595aa8 418 addr = addr << 1;
roryhand 0:004cb0595aa8 419 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 420 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 421 i2c.start();
roryhand 0:004cb0595aa8 422 i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
roryhand 0:004cb0595aa8 423 i2c.write( addr );
roryhand 0:004cb0595aa8 424 i2c.write( cmd );
roryhand 0:004cb0595aa8 425 i2c.stop();
roryhand 0:004cb0595aa8 426
roryhand 0:004cb0595aa8 427
roryhand 0:004cb0595aa8 428 //9
roryhand 0:004cb0595aa8 429 addr = WM8731_REG_DIGITAL_IF;
roryhand 0:004cb0595aa8 430 cmd = _WM8731_DAIF;
roryhand 0:004cb0595aa8 431 addr = addr << 1;
roryhand 0:004cb0595aa8 432 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 433 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 434 i2c.start();
roryhand 0:004cb0595aa8 435 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 436 i2c.write( addr );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
roryhand 0:004cb0595aa8 437 i2c.write( cmd );
roryhand 0:004cb0595aa8 438 i2c.stop();
roryhand 0:004cb0595aa8 439
roryhand 0:004cb0595aa8 440
roryhand 0:004cb0595aa8 441 //10
roryhand 0:004cb0595aa8 442 addr = WM8731_REG_SAMPLING_CTRL;
roryhand 0:004cb0595aa8 443 cmd = _WM8731_SAMPLING;
roryhand 0:004cb0595aa8 444 addr = addr << 1;
roryhand 0:004cb0595aa8 445 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 446 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 447 i2c.start();
roryhand 0:004cb0595aa8 448 i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
roryhand 0:004cb0595aa8 449 i2c.write( addr );
roryhand 0:004cb0595aa8 450 i2c.write( cmd );
roryhand 0:004cb0595aa8 451 i2c.stop();
roryhand 0:004cb0595aa8 452
roryhand 0:004cb0595aa8 453
roryhand 0:004cb0595aa8 454
roryhand 0:004cb0595aa8 455
roryhand 0:004cb0595aa8 456 //11
roryhand 0:004cb0595aa8 457 addr = WM8731_REG_ACTIVE_CTRL;
roryhand 0:004cb0595aa8 458 cmd = _WM8731_ACTIVATE;
roryhand 0:004cb0595aa8 459 addr = addr << 1;
roryhand 0:004cb0595aa8 460 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 461 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 462 i2c.start();
roryhand 0:004cb0595aa8 463 i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
roryhand 0:004cb0595aa8 464 i2c.write( addr );
roryhand 0:004cb0595aa8 465 i2c.write( cmd );//there is also a deactive version!!
roryhand 0:004cb0595aa8 466 /*(from data sheet) - To prevent any comms problems from arising across te DAI the audio interface (AI) is disabled
roryhand 0:004cb0595aa8 467 (tristate with weak 100k pulldown). ONce the audio interface and the sampling scontrol has been programmed its
roryhand 0:004cb0595aa8 468 activated by setting the ACTIVE bit under software control.*/
roryhand 0:004cb0595aa8 469 //i2c.stop();
roryhand 0:004cb0595aa8 470 //}
roryhand 0:004cb0595aa8 471 printf("set up the codec\n\r");
roryhand 0:004cb0595aa8 472 wm8731_configTEST();
roryhand 0:004cb0595aa8 473 //i2s audio data transfer code??
roryhand 0:004cb0595aa8 474 i2s.stereomono(I2S_STEREO);
roryhand 0:004cb0595aa8 475 i2s.masterslave(I2S_MASTER);//MASTER definitely works!
roryhand 0:004cb0595aa8 476 i2s.frequency(sample_freq);
roryhand 0:004cb0595aa8 477 int yes = i2s.setup_ok();
roryhand 0:004cb0595aa8 478 pc.printf("Setup went ok?: %d\n", yes);//0 = ack, 1 = Nack*/
roryhand 0:004cb0595aa8 479 printf("can we get to this point? 1\n\r");
roryhand 0:004cb0595aa8 480 led3 = 1;
roryhand 0:004cb0595aa8 481 //myled = 1;
roryhand 0:004cb0595aa8 482 led2 = 1;
roryhand 0:004cb0595aa8 483 printf("can we get to this point? 2\n\r");
roryhand 0:004cb0595aa8 484
roryhand 0:004cb0595aa8 485 /*fseek(my_wav, 40, SEEK_SET);
roryhand 0:004cb0595aa8 486 fread(&wav_data.subchunk2_size,4,1,my_wav);
roryhand 0:004cb0595aa8 487 printf("subchunk2 size: %d",wav_data.subchunk2_size);*/
roryhand 0:004cb0595aa8 488 int num_slices = wav_data.subchunk2_size/wav_format.block_align;
roryhand 0:004cb0595aa8 489 printf("block align is:%d\n\r",wav_format.block_align);
roryhand 0:004cb0595aa8 490 int a = 44;
roryhand 0:004cb0595aa8 491 //sampletick.attach(&isr,1.0/sample_freq);
roryhand 0:004cb0595aa8 492
roryhand 0:004cb0595aa8 493 myled = 1;
roryhand 0:004cb0595aa8 494 i2s.start();
roryhand 0:004cb0595aa8 495 //while (1) {
roryhand 0:004cb0595aa8 496 fread(&wav_format,sizeof(wav_format),1,my_wav);
roryhand 0:004cb0595aa8 497 printf("wav_format %d\n\r",wav_format);
roryhand 0:004cb0595aa8 498 //sampletick.attach(&isr,1/96000);
roryhand 0:004cb0595aa8 499 /*if (wav_data.subchunk2_size > sizeof(wav_format)){
roryhand 0:004cb0595aa8 500 fseek(my_wav,wav_data.subchunk2_size-sizeof(wav_format),SEEK_CUR);
roryhand 0:004cb0595aa8 501 printf("chunk_size - sizeof(wav_format) %d",wav_data.subchunk2_size-sizeof(wav_format));
roryhand 0:004cb0595aa8 502 }
roryhand 0:004cb0595aa8 503 else {
roryhand 0:004cb0595aa8 504
roryhand 0:004cb0595aa8 505 break;
roryhand 0:004cb0595aa8 506 }*/
roryhand 0:004cb0595aa8 507
roryhand 0:004cb0595aa8 508 fseek(my_wav,20,SEEK_SET);
roryhand 0:004cb0595aa8 509 fread(&wav_format,sizeof(wav_format),1,my_wav);
roryhand 0:004cb0595aa8 510 fseek(my_wav,36,SEEK_SET);
roryhand 0:004cb0595aa8 511 fread(&wav_data,sizeof(wav_data),1,my_wav);
roryhand 0:004cb0595aa8 512 num_slices = wav_data.subchunk2_size/wav_format.block_align;
roryhand 0:004cb0595aa8 513 printf("wav_data.subchunk2_size: %d\n\r",wav_data.subchunk2_size);
roryhand 0:004cb0595aa8 514 printf("wav_format.block_align: %d\n\r",wav_format.block_align);
roryhand 0:004cb0595aa8 515 printf("num_slices: %d\n\r",num_slices);
roryhand 0:004cb0595aa8 516 printf("num_slices*wav_format.block_align %d\n\r",num_slices*wav_format.block_align);
roryhand 0:004cb0595aa8 517 printf("wav_format.num_channels*wav_format.sig_bps/8: %d\n\r",wav_format.num_channels*wav_format.sig_bps/8);
roryhand 0:004cb0595aa8 518 printf("chunk_size - sizeof(wav_format) %d\n\r",wav_data.subchunk2_size-sizeof(wav_format));
roryhand 0:004cb0595aa8 519 printf("sizeof(wav_format): %d\n\r",sizeof(wav_format));
roryhand 0:004cb0595aa8 520 //sampletick.attach(&isr,1/96000);
roryhand 0:004cb0595aa8 521 //while(!feof(my_wav)){
roryhand 0:004cb0595aa8 522 //while(1){
roryhand 0:004cb0595aa8 523 //if (wav_data.subchunk2_size > sizeof(wav_format)){
roryhand 0:004cb0595aa8 524 //fseek(my_wav,wav_data.subchunk2_size-sizeof(wav_format),SEEK_CUR);
roryhand 0:004cb0595aa8 525 /*if(wav_data.subchunk2_size > (num_slices*wav_format.block_align)){
roryhand 0:004cb0595aa8 526 fseek(my_wav,wav_data.subchunk2_size - (num_slices*wav_format.block_align),SEEK_CUR);
roryhand 0:004cb0595aa8 527 printf("chunk_size - sizeof(wav_format) %d\n\r",wav_data.subchunk2_size-sizeof(wav_format));
roryhand 0:004cb0595aa8 528 printf("sizeof(wav_format): %d\n\r",sizeof(wav_format));
roryhand 0:004cb0595aa8 529 }
roryhand 0:004cb0595aa8 530 else {
roryhand 0:004cb0595aa8 531
roryhand 0:004cb0595aa8 532 break;
roryhand 0:004cb0595aa8 533 }*/
roryhand 0:004cb0595aa8 534
roryhand 0:004cb0595aa8 535 slice_buf=(char *)malloc(wav_format.block_align);
roryhand 0:004cb0595aa8 536 for(int slice = 0; slice<num_slices; slice+=1)
roryhand 0:004cb0595aa8 537 {
roryhand 0:004cb0595aa8 538 //printf("slice: %d\n\r",slice);
roryhand 0:004cb0595aa8 539 fread(&slice_buf,wav_format.block_align,1,my_wav);
roryhand 0:004cb0595aa8 540 //int filePositionIndicator=ftell(my_wav);
roryhand 0:004cb0595aa8 541 //printf("filePositionIndicator: %d\n\r",filePositionIndicator);
roryhand 0:004cb0595aa8 542 //printf("slice: %d\n\r",slice);
roryhand 0:004cb0595aa8 543 //printf("num_slices: %d\n\r",num_slices);
roryhand 0:004cb0595aa8 544 data_sptr=(int *)slice_buf;
roryhand 0:004cb0595aa8 545 //printf("data_sptr:%d\n\r",data_sptr);
roryhand 0:004cb0595aa8 546 //printf("wav_format.num_channels: %d\n\r",wav_format.num_channels);
roryhand 0:004cb0595aa8 547 //}
roryhand 0:004cb0595aa8 548 slice_value = 0;
roryhand 0:004cb0595aa8 549
roryhand 0:004cb0595aa8 550 //for (int channel=0;channel<wav_format.num_channels;channel++)
roryhand 0:004cb0595aa8 551 // {
roryhand 0:004cb0595aa8 552 int channel = 0;
roryhand 0:004cb0595aa8 553 //printf("channel: %d\n\r",channel);
roryhand 0:004cb0595aa8 554 //printf("wav_format.num_channels: %d\n\r",wav_format.num_channels);
roryhand 0:004cb0595aa8 555 int var = 1;//data_sptr[channel];
roryhand 0:004cb0595aa8 556 printf("var: %d\n\r", var);
roryhand 0:004cb0595aa8 557 //slice_value+=data_sptr[channel];
roryhand 0:004cb0595aa8 558 //printf("slice_value %d\n\r",slice_value);
roryhand 0:004cb0595aa8 559 //printf("data_sptr[channel] %d\n\r",data_sptr[channel] );
roryhand 0:004cb0595aa8 560 //slice_value = 21;//
roryhand 0:004cb0595aa8 561 //malloc(sizeof(data_sptr[channel]));
roryhand 0:004cb0595aa8 562 //printf("SIZEOF DATASPTR %d:\n\r",sizeof(data_sptr[channel]));
roryhand 0:004cb0595aa8 563 //newvar = data_sptr[channel];
roryhand 0:004cb0595aa8 564 //printf("newvar %d\n\r",newvar);
roryhand 0:004cb0595aa8 565 channel = channel + 1;
roryhand 0:004cb0595aa8 566 newvar = data_sptr[channel];
roryhand 0:004cb0595aa8 567 //printf("newvar %d\n\r",newvar);
roryhand 0:004cb0595aa8 568 //printf("channel: %d\n\r",channel);
roryhand 0:004cb0595aa8 569 //slice_value+=data_sptr[channel];
roryhand 0:004cb0595aa8 570
roryhand 0:004cb0595aa8 571 //printf("did it get to this point\n\r");
roryhand 0:004cb0595aa8 572
roryhand 0:004cb0595aa8 573
roryhand 0:004cb0595aa8 574 //printf("channel: %d data %d\n\r",channel,data_sptr[channel]);
roryhand 0:004cb0595aa8 575 //printf("slice_value: %d\n\r",slice_value);
roryhand 0:004cb0595aa8 576 //}
roryhand 0:004cb0595aa8 577
roryhand 0:004cb0595aa8 578 }
roryhand 0:004cb0595aa8 579
roryhand 0:004cb0595aa8 580
roryhand 0:004cb0595aa8 581
roryhand 0:004cb0595aa8 582 //a = a + wav_format.block_align;
roryhand 0:004cb0595aa8 583 //}
roryhand 0:004cb0595aa8 584 //}
roryhand 0:004cb0595aa8 585 //}
roryhand 0:004cb0595aa8 586 sampletick.detach();
roryhand 0:004cb0595aa8 587 i2s.stop();
roryhand 0:004cb0595aa8 588
roryhand 0:004cb0595aa8 589 fclose(my_wav);
roryhand 0:004cb0595aa8 590 printf("File is now closed.");
roryhand 0:004cb0595aa8 591 return 0;
roryhand 0:004cb0595aa8 592 }
roryhand 0:004cb0595aa8 593 /*while(1){
roryhand 0:004cb0595aa8 594 sampletick.attach(&isr,1.0/sample_freq);
roryhand 0:004cb0595aa8 595 led3 = !led3;
roryhand 0:004cb0595aa8 596 wait(1.0);
roryhand 0:004cb0595aa8 597
roryhand 0:004cb0595aa8 598 //COMMENTS BELOW ARE OUT OF DATE
roryhand 0:004cb0595aa8 599 //The code above is IDENTICAL!!! to code run in TickerHello World.
roryhand 0:004cb0595aa8 600 //However, the 2nd led doesn't even light up and start "flipping" until led 1 has flipped....
roryhand 0:004cb0595aa8 601 //Looks as if it cannot attach.
roryhand 0:004cb0595aa8 602 //sampletick.attach_us(&isr, 20.833);//try using attach_us instead.
roryhand 0:004cb0595aa8 603 //Not sure why the osther guy just didn't use this in the first place
roryhand 0:004cb0595aa8 604 //sampletick.attach(&isr,1/sample_freq);
roryhand 0:004cb0595aa8 605 //if myled is assigned AFTER the tick is attached, it never switches on if sound does not come on.
roryhand 0:004cb0595aa8 606 }
roryhand 0:004cb0595aa8 607 //sampletick.attach(&isr, 2.0);
roryhand 0:004cb0595aa8 608 }
roryhand 0:004cb0595aa8 609 */
roryhand 0:004cb0595aa8 610
roryhand 0:004cb0595aa8 611
roryhand 0:004cb0595aa8 612
roryhand 0:004cb0595aa8 613
roryhand 0:004cb0595aa8 614
roryhand 0:004cb0595aa8 615
roryhand 0:004cb0595aa8 616
roryhand 0:004cb0595aa8 617
roryhand 0:004cb0595aa8 618
roryhand 0:004cb0595aa8 619
roryhand 0:004cb0595aa8 620
roryhand 0:004cb0595aa8 621
roryhand 0:004cb0595aa8 622
roryhand 0:004cb0595aa8 623
roryhand 0:004cb0595aa8 624
roryhand 0:004cb0595aa8 625
roryhand 0:004cb0595aa8 626
roryhand 0:004cb0595aa8 627
roryhand 0:004cb0595aa8 628
roryhand 0:004cb0595aa8 629
roryhand 0:004cb0595aa8 630
roryhand 0:004cb0595aa8 631
roryhand 0:004cb0595aa8 632
roryhand 0:004cb0595aa8 633
roryhand 0:004cb0595aa8 634 //old LEGACY code!!!
roryhand 0:004cb0595aa8 635 /*int addr = WM8731_REG_RESET;
roryhand 0:004cb0595aa8 636 int cmd = _WM8731_RESET;
roryhand 0:004cb0595aa8 637 addr = addr << 1;
roryhand 0:004cb0595aa8 638 addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
roryhand 0:004cb0595aa8 639 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 640 i2c.start();
roryhand 0:004cb0595aa8 641 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 642 i2c.write( addr );
roryhand 0:004cb0595aa8 643 i2c.write( cmd );
roryhand 0:004cb0595aa8 644 i2c.stop();
roryhand 0:004cb0595aa8 645
roryhand 0:004cb0595aa8 646 addr = WM8731_REG_LLINE_IN;
roryhand 0:004cb0595aa8 647 cmd = _WM8731_LEFT_LINEIN;
roryhand 0:004cb0595aa8 648 addr = addr << 1;
roryhand 0:004cb0595aa8 649 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 650 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 651 i2c.start();
roryhand 0:004cb0595aa8 652 i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
roryhand 0:004cb0595aa8 653 i2c.write( addr );
roryhand 0:004cb0595aa8 654 i2c.write( cmd );
roryhand 0:004cb0595aa8 655 i2c.stop();
roryhand 0:004cb0595aa8 656
roryhand 0:004cb0595aa8 657
roryhand 0:004cb0595aa8 658 addr = WM8731_REG_RLINE_IN;
roryhand 0:004cb0595aa8 659 cmd = _WM8731_RIGHT_LINEIN;
roryhand 0:004cb0595aa8 660 addr = addr << 1;
roryhand 0:004cb0595aa8 661 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 662 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 663 i2c.start();
roryhand 0:004cb0595aa8 664 i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
roryhand 0:004cb0595aa8 665 i2c.write( addr );
roryhand 0:004cb0595aa8 666 i2c.write( cmd );
roryhand 0:004cb0595aa8 667 i2c.stop();
roryhand 0:004cb0595aa8 668
roryhand 0:004cb0595aa8 669
roryhand 0:004cb0595aa8 670 //4
roryhand 0:004cb0595aa8 671 addr = WM8731_REG_LHPHONE_OUT;
roryhand 0:004cb0595aa8 672 cmd = _WM8731_LEFT_HP;
roryhand 0:004cb0595aa8 673 addr = addr << 1;
roryhand 0:004cb0595aa8 674 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 675 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 676 i2c.start();
roryhand 0:004cb0595aa8 677 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 678 i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP
roryhand 0:004cb0595aa8 679 i2c.write(cmd);
roryhand 0:004cb0595aa8 680 i2c.stop();
roryhand 0:004cb0595aa8 681
roryhand 0:004cb0595aa8 682 //5
roryhand 0:004cb0595aa8 683 addr = WM8731_REG_RHPHONE_OUT;
roryhand 0:004cb0595aa8 684 cmd = _WM8731_RIGHT_HP;
roryhand 0:004cb0595aa8 685 addr = addr << 1;
roryhand 0:004cb0595aa8 686 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 687 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 688 i2c.start();
roryhand 0:004cb0595aa8 689 i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP
roryhand 0:004cb0595aa8 690 i2c.write( addr );
roryhand 0:004cb0595aa8 691 i2c.write( cmd );
roryhand 0:004cb0595aa8 692 i2c.stop();
roryhand 0:004cb0595aa8 693
roryhand 0:004cb0595aa8 694
roryhand 0:004cb0595aa8 695 //6
roryhand 0:004cb0595aa8 696 addr = WM8731_REG_ANALOG_PATH;
roryhand 0:004cb0595aa8 697 cmd = _WM8731_ANALOGAUDIO;
roryhand 0:004cb0595aa8 698 addr = addr << 1;
roryhand 0:004cb0595aa8 699 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 700 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 701 i2c.start();
roryhand 0:004cb0595aa8 702 i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
roryhand 0:004cb0595aa8 703 i2c.write( addr );
roryhand 0:004cb0595aa8 704 i2c.write( cmd );
roryhand 0:004cb0595aa8 705 i2c.stop();
roryhand 0:004cb0595aa8 706
roryhand 0:004cb0595aa8 707 //7
roryhand 0:004cb0595aa8 708 addr = WM8731_REG_DIGITAL_PATH;
roryhand 0:004cb0595aa8 709 cmd = _WM8731_DIGITALAUDIO;
roryhand 0:004cb0595aa8 710 addr = addr << 1;
roryhand 0:004cb0595aa8 711 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 712 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 713 i2c.start();
roryhand 0:004cb0595aa8 714 i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
roryhand 0:004cb0595aa8 715 i2c.write( addr );
roryhand 0:004cb0595aa8 716 i2c.write( cmd );
roryhand 0:004cb0595aa8 717 i2c.stop();
roryhand 0:004cb0595aa8 718
roryhand 0:004cb0595aa8 719 //8
roryhand 0:004cb0595aa8 720 addr = WM8731_REG_PDOWN_CTRL;
roryhand 0:004cb0595aa8 721 cmd = _WM8731_POWER;
roryhand 0:004cb0595aa8 722 addr = addr << 1;
roryhand 0:004cb0595aa8 723 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 724 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 725 i2c.start();
roryhand 0:004cb0595aa8 726 i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
roryhand 0:004cb0595aa8 727 i2c.write( addr );
roryhand 0:004cb0595aa8 728 i2c.write( cmd );
roryhand 0:004cb0595aa8 729 i2c.stop();
roryhand 0:004cb0595aa8 730
roryhand 0:004cb0595aa8 731
roryhand 0:004cb0595aa8 732 //9
roryhand 0:004cb0595aa8 733 addr = WM8731_REG_DIGITAL_IF;
roryhand 0:004cb0595aa8 734 cmd = _WM8731_DAIF;
roryhand 0:004cb0595aa8 735 addr = addr << 1;
roryhand 0:004cb0595aa8 736 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 737 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 738 i2c.start();
roryhand 0:004cb0595aa8 739 i2c.write( WM8731_ADDRESS );
roryhand 0:004cb0595aa8 740 i2c.write( addr );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
roryhand 0:004cb0595aa8 741 i2c.write( cmd );
roryhand 0:004cb0595aa8 742 i2c.stop();
roryhand 0:004cb0595aa8 743
roryhand 0:004cb0595aa8 744
roryhand 0:004cb0595aa8 745 //10
roryhand 0:004cb0595aa8 746 addr = WM8731_REG_SAMPLING_CTRL;
roryhand 0:004cb0595aa8 747 cmd = _WM8731_SAMPLING;
roryhand 0:004cb0595aa8 748 addr = addr << 1;
roryhand 0:004cb0595aa8 749 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 750 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 751 i2c.start();
roryhand 0:004cb0595aa8 752 i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
roryhand 0:004cb0595aa8 753 i2c.write( addr );
roryhand 0:004cb0595aa8 754 i2c.write( cmd );
roryhand 0:004cb0595aa8 755 i2c.stop();
roryhand 0:004cb0595aa8 756
roryhand 0:004cb0595aa8 757
roryhand 0:004cb0595aa8 758
roryhand 0:004cb0595aa8 759
roryhand 0:004cb0595aa8 760 //11
roryhand 0:004cb0595aa8 761 addr = WM8731_REG_ACTIVE_CTRL;
roryhand 0:004cb0595aa8 762 cmd = _WM8731_ACTIVATE;
roryhand 0:004cb0595aa8 763 addr = addr << 1;
roryhand 0:004cb0595aa8 764 addr = addr|((cmd >> 8 )) & 0x01;
roryhand 0:004cb0595aa8 765 cmd = cmd&0xFF;
roryhand 0:004cb0595aa8 766 i2c.start();
roryhand 0:004cb0595aa8 767 i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
roryhand 0:004cb0595aa8 768 i2c.write( addr );
roryhand 0:004cb0595aa8 769 i2c.write( cmd );//there is also a deactive version!!
roryhand 0:004cb0595aa8 770 i2c.stop();*/
roryhand 0:004cb0595aa8 771
roryhand 0:004cb0595aa8 772