Dialog DA7212 evaluating project DEVELOP branch

Dependencies:   FXAS21002 TLV320 mbed sinelookup C12832 FXOS8700

Committer:
K4zuki
Date:
Thu Mar 24 01:18:16 2016 +0900
Revision:
2:3e6fb6a1f3ef
Parent:
1:98b55aeebaa5
Child:
5:f1907e4d1147
PinName correct to match K64F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
k4zuki 1:98b55aeebaa5 1 /** original: p07gbar/code/TLV320_Write_test/
k4zuki 1:98b55aeebaa5 2 * modify by k4zuki
k4zuki 1:98b55aeebaa5 3 * to control Dialog DA7212 codec
k4zuki 1:98b55aeebaa5 4 */
k4zuki 1:98b55aeebaa5 5 #include "mbed.h"
k4zuki 1:98b55aeebaa5 6 #include "sinelookup.h"
k4zuki 1:98b55aeebaa5 7 //#include "TLV320.h"
k4zuki 1:98b55aeebaa5 8 // #include "DA7212.h"
k4zuki 1:98b55aeebaa5 9 //#include "I2S.h"
k4zuki 1:98b55aeebaa5 10
k4zuki 1:98b55aeebaa5 11 #define SAMPLERATE 32000
k4zuki 1:98b55aeebaa5 12
k4zuki 1:98b55aeebaa5 13 /*
K4zuki 2:3e6fb6a1f3ef 14 //DA7212 codec(I2C_SDA, I2C_SCL);
K4zuki 2:3e6fb6a1f3ef 15 TLV320 codec(I2C_SDA, I2C_SCL);
K4zuki 2:3e6fb6a1f3ef 16 I2S i2s(I2S_TRANSMIT, PTC1, PTB19, PTB18);
k4zuki 1:98b55aeebaa5 17
k4zuki 1:98b55aeebaa5 18 AnalogIn aIn(p19);
k4zuki 1:98b55aeebaa5 19 AnalogIn vol(p20);
k4zuki 1:98b55aeebaa5 20
k4zuki 1:98b55aeebaa5 21 float phase_l;
k4zuki 1:98b55aeebaa5 22 float phase_r;
k4zuki 1:98b55aeebaa5 23 int minibuf[16];
k4zuki 1:98b55aeebaa5 24 float skipper;
k4zuki 1:98b55aeebaa5 25 float volume;
k4zuki 1:98b55aeebaa5 26 float phase_kill;
k4zuki 1:98b55aeebaa5 27
k4zuki 1:98b55aeebaa5 28
k4zuki 1:98b55aeebaa5 29 extern "C" void HardFault_Handler()
k4zuki 1:98b55aeebaa5 30 {
k4zuki 1:98b55aeebaa5 31 error("Hard Fault!\n");
k4zuki 1:98b55aeebaa5 32 }
k4zuki 1:98b55aeebaa5 33
k4zuki 1:98b55aeebaa5 34
k4zuki 1:98b55aeebaa5 35 void play(void)
k4zuki 1:98b55aeebaa5 36 {
k4zuki 1:98b55aeebaa5 37 int to_write = i2s.max_fifo_points() - (i2s.fifo_points());
k4zuki 1:98b55aeebaa5 38 for(int i = 0; i < to_write; i+=2) {
k4zuki 1:98b55aeebaa5 39 minibuf[i] = int(float(sine16lookup[int(phase_l)])*volume);
k4zuki 1:98b55aeebaa5 40 //minibuf[i] = int(sine16lookup[int(phase_l)]);
k4zuki 1:98b55aeebaa5 41 minibuf[i+1] = int(float(sine16lookup[int(phase_r)])*volume);
k4zuki 1:98b55aeebaa5 42 phase_l+=skipper;
k4zuki 1:98b55aeebaa5 43 phase_r = phase_l + phase_kill;
k4zuki 1:98b55aeebaa5 44 while(phase_l >= SINE16LENGTH) {
k4zuki 1:98b55aeebaa5 45 phase_l -= SINE16LENGTH;
k4zuki 1:98b55aeebaa5 46 }
k4zuki 1:98b55aeebaa5 47
k4zuki 1:98b55aeebaa5 48 while(phase_r >= SINE16LENGTH) {
k4zuki 1:98b55aeebaa5 49 phase_r -= SINE16LENGTH;
k4zuki 1:98b55aeebaa5 50 }
k4zuki 1:98b55aeebaa5 51 while(phase_r< 0) phase_r += SINE16LENGTH;
k4zuki 1:98b55aeebaa5 52 }
k4zuki 1:98b55aeebaa5 53 i2s.write(minibuf, to_write);
k4zuki 1:98b55aeebaa5 54 }
k4zuki 1:98b55aeebaa5 55 */
k4zuki 1:98b55aeebaa5 56 /* main */
k4zuki 1:98b55aeebaa5 57 int main()
k4zuki 1:98b55aeebaa5 58 {
k4zuki 1:98b55aeebaa5 59 I2S0_TCSR |= 1u<<31;
k4zuki 1:98b55aeebaa5 60 /*
k4zuki 1:98b55aeebaa5 61 skipper = (aIn*49)+1;
k4zuki 1:98b55aeebaa5 62
k4zuki 1:98b55aeebaa5 63 codec.power(true);
k4zuki 1:98b55aeebaa5 64 codec.frequency(SAMPLERATE);
k4zuki 1:98b55aeebaa5 65 codec.wordsize(16);
k4zuki 1:98b55aeebaa5 66 codec.master(false);
k4zuki 1:98b55aeebaa5 67 codec.headphone_volume(0.5);
k4zuki 1:98b55aeebaa5 68 codec.start();
k4zuki 1:98b55aeebaa5 69
k4zuki 1:98b55aeebaa5 70 i2s.frequency(SAMPLERATE);
k4zuki 1:98b55aeebaa5 71 i2s.wordsize(16);
k4zuki 1:98b55aeebaa5 72 i2s.stereomono(I2S_STEREO);
k4zuki 1:98b55aeebaa5 73 i2s.masterslave(I2S_MASTER);
k4zuki 1:98b55aeebaa5 74 i2s.attach(&play);
k4zuki 1:98b55aeebaa5 75 i2s.start();
k4zuki 1:98b55aeebaa5 76 */
k4zuki 1:98b55aeebaa5 77 while(1)
k4zuki 1:98b55aeebaa5 78 {;
k4zuki 1:98b55aeebaa5 79 /*
k4zuki 1:98b55aeebaa5 80 skipper = (aIn*30)+1;
k4zuki 1:98b55aeebaa5 81
k4zuki 1:98b55aeebaa5 82 volume = 1;
k4zuki 1:98b55aeebaa5 83 phase_kill = (vol-0.5)*400;
k4zuki 1:98b55aeebaa5 84
k4zuki 1:98b55aeebaa5 85 //printf("Skipper:%f, %i, %i\n\r",skipper, to_write,i2s.fifo_level());
k4zuki 1:98b55aeebaa5 86 */
k4zuki 1:98b55aeebaa5 87 /*if(flag)
k4zuki 1:98b55aeebaa5 88 {
k4zuki 1:98b55aeebaa5 89 printf(".");
k4zuki 1:98b55aeebaa5 90 flag = false;
k4zuki 1:98b55aeebaa5 91 }*/
k4zuki 1:98b55aeebaa5 92 }
k4zuki 1:98b55aeebaa5 93
k4zuki 1:98b55aeebaa5 94 }