Dialog DA7212 evaluating project DEVELOP branch
Dependencies: FXAS21002 TLV320 mbed sinelookup C12832 FXOS8700
main.cpp@16:2edf3d4ccbe3, 2017-07-04 (annotated)
- Committer:
- k4zuki
- Date:
- Tue Jul 04 16:53:05 2017 +0000
- Revision:
- 16:2edf3d4ccbe3
- Parent:
- 15:f9f642239cb6
update frdm_i2s to make it more flexible over chip models
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
k4zuki | 1:98b55aeebaa5 | 1 | /** original: p07gbar/code/TLV320_Write_test/ |
k4zuki | 1:98b55aeebaa5 | 2 | * modify by k4zuki |
k4zuki | 14:c852e468923e | 3 | * to control Dialog DA7212 codec from FRDM-K64F/K66F |
k4zuki | 14:c852e468923e | 4 | * - FRDM |
k4zuki | 14:c852e468923e | 5 | * - https://developer.mbed.org/platforms/FRDM-K64F/ |
k4zuki | 14:c852e468923e | 6 | * - I2S |
k4zuki | 14:c852e468923e | 7 | * - I2S_TXD: PTC1 |
k4zuki | 14:c852e468923e | 8 | * - I2S_TX_FS: PTB19 |
k4zuki | 14:c852e468923e | 9 | * - I2S_TX_BCLK: PTB18 |
k4zuki | 14:c852e468923e | 10 | * - FXOS8700CQ - Accelerometer and Magnetometer |
k4zuki | 14:c852e468923e | 11 | * - SCL:SCL |
k4zuki | 14:c852e468923e | 12 | * - SDA:SDA |
k4zuki | 14:c852e468923e | 13 | * - 8-bit Address: 0x3A |
k4zuki | 14:c852e468923e | 14 | * - https://developer.mbed.org/platforms/FRDM-K66F/ |
k4zuki | 14:c852e468923e | 15 | * - I2S |
k4zuki | 14:c852e468923e | 16 | * - I2S_TXD: PTC1 |
k4zuki | 14:c852e468923e | 17 | * - I2S_TX_FS: PTE11 |
k4zuki | 14:c852e468923e | 18 | * - I2S_TX_BCLK: PTE12 |
k4zuki | 14:c852e468923e | 19 | * - FXOS8700CQ - Accelerometer and Magnetometer |
k4zuki | 14:c852e468923e | 20 | * - SCL:SCL |
k4zuki | 14:c852e468923e | 21 | * - SDA:SDA |
k4zuki | 14:c852e468923e | 22 | * - 8-bit Address: 0x3A |
k4zuki | 14:c852e468923e | 23 | * - FXAS21002 - Gyroscope |
k4zuki | 14:c852e468923e | 24 | * - SCL:SCL |
k4zuki | 14:c852e468923e | 25 | * - SDA:SDA |
k4zuki | 14:c852e468923e | 26 | * - 8-bit Address: 0x42 |
k4zuki | 14:c852e468923e | 27 | * - 2 user push-buttons |
k4zuki | 14:c852e468923e | 28 | * - RGB LED |
k4zuki | 14:c852e468923e | 29 | * - DA7212 (on-board(K66F) or off-board(K64F+ARD-AUDIO-7212)) |
k4zuki | 14:c852e468923e | 30 | * - https://developer.mbed.org/components/ARD-AUDIO-DA7212/ |
k4zuki | 14:c852e468923e | 31 | * - SCL:SCL |
k4zuki | 14:c852e468923e | 32 | * - SDA:SDA |
k4zuki | 14:c852e468923e | 33 | * - 8-bit address: 0x34 |
k4zuki | 14:c852e468923e | 34 | * - Application Shield |
k4zuki | 14:c852e468923e | 35 | * - https://developer.mbed.org/components/mbed-Application-Shield/ |
k4zuki | 14:c852e468923e | 36 | * - 3 Axis +/1 1.5g Accelerometer,I2C Interface Freescale MMA7660 |
k4zuki | 14:c852e468923e | 37 | * - SCL: SCL |
k4zuki | 14:c852e468923e | 38 | * - SDA: SDA |
k4zuki | 14:c852e468923e | 39 | * - 8-bit Address: 0x98 |
k4zuki | 14:c852e468923e | 40 | * - Temperature sensor LM75B |
k4zuki | 14:c852e468923e | 41 | * - SCL: SCL |
k4zuki | 14:c852e468923e | 42 | * - SDA: SDA |
k4zuki | 14:c852e468923e | 43 | * - 8-bit Address: 0x90 |
k4zuki | 14:c852e468923e | 44 | * - 2 x Potentiometers Iskra PNZ10ZA, 10k |
k4zuki | 14:c852e468923e | 45 | * - Pot 1 (left) : A0 |
k4zuki | 14:c852e468923e | 46 | * - Pot 2 (right): A1 |
k4zuki | 14:c852e468923e | 47 | * - 5 way Joystick ALPS SKRHADE010 |
k4zuki | 14:c852e468923e | 48 | * - Up: A2 |
k4zuki | 14:c852e468923e | 49 | * - Down: A3 |
k4zuki | 14:c852e468923e | 50 | * - Left: A4 |
k4zuki | 14:c852e468923e | 51 | * - Right: A5 |
k4zuki | 14:c852e468923e | 52 | * - Centre: D4 |
k4zuki | 14:c852e468923e | 53 | * - 128x32 Graphics LCD, SPI Interface Newhaven C12332A1Z |
k4zuki | 14:c852e468923e | 54 | * - A0: D7 |
k4zuki | 14:c852e468923e | 55 | * - nCS: D10 |
k4zuki | 14:c852e468923e | 56 | * - MOSI: D11 |
k4zuki | 14:c852e468923e | 57 | * - nRESET: D12 |
k4zuki | 14:c852e468923e | 58 | * - SCK: D13 |
k4zuki | 14:c852e468923e | 59 | * - RGB LED, PWM connected Cree Inc CLV1A-FKB |
k4zuki | 14:c852e468923e | 60 | * - Red: D5 |
k4zuki | 14:c852e468923e | 61 | * - Blue: D8 |
k4zuki | 14:c852e468923e | 62 | * - Green: D9 |
k4zuki | 14:c852e468923e | 63 | * - Speaker, PWM Connected MULTICOMP MCSMT-8030B-3717 |
k4zuki | 14:c852e468923e | 64 | * - D6 |
k4zuki | 14:c852e468923e | 65 | * - Xbee socket |
k4zuki | 14:c852e468923e | 66 | * - Tx: D0 |
k4zuki | 14:c852e468923e | 67 | * - Rx: D1 |
k4zuki | 14:c852e468923e | 68 | * - Status: D2 |
k4zuki | 14:c852e468923e | 69 | * - nReset: D3 |
k4zuki | 1:98b55aeebaa5 | 70 | */ |
k4zuki | 14:c852e468923e | 71 | |
k4zuki | 1:98b55aeebaa5 | 72 | #include "mbed.h" |
k4zuki | 14:c852e468923e | 73 | |
k4zuki | 14:c852e468923e | 74 | AnalogIn pot1 (A0); |
k4zuki | 14:c852e468923e | 75 | AnalogIn pot2 (A1); |
k4zuki | 14:c852e468923e | 76 | |
k4zuki | 14:c852e468923e | 77 | InterruptIn left(PTA4); |
k4zuki | 14:c852e468923e | 78 | InterruptIn right(PTC6); |
k4zuki | 14:c852e468923e | 79 | |
k4zuki | 14:c852e468923e | 80 | #include "FXOS8700.h" |
k4zuki | 15:f9f642239cb6 | 81 | FXOS8700 acc(PTD9, PTD8); |
k4zuki | 15:f9f642239cb6 | 82 | FXOS8700 mag(PTD9, PTD8); |
k4zuki | 14:c852e468923e | 83 | |
k4zuki | 14:c852e468923e | 84 | #include "C12832.h" |
k4zuki | 14:c852e468923e | 85 | C12832 lcd(D11, D13, D12, D7, D10); |
k4zuki | 14:c852e468923e | 86 | |
k4zuki | 14:c852e468923e | 87 | |
k4zuki | 14:c852e468923e | 88 | #include "DA7212.h" |
k4zuki | 14:c852e468923e | 89 | #include "FrdmI2s.h" |
k4zuki | 14:c852e468923e | 90 | #define SAMPLERATE 32000 |
k4zuki | 1:98b55aeebaa5 | 91 | #include "sinelookup.h" |
K4zuki | 2:3e6fb6a1f3ef | 92 | //DA7212 codec(I2C_SDA, I2C_SCL); |
k4zuki | 9:fe61a56fa5a9 | 93 | //TLV320 codec(I2C_SDA, I2C_SCL); |
k4zuki | 16:2edf3d4ccbe3 | 94 | FrdmI2s i2s(PTC6,PTC1, PTE11, PTE12,TRANSMIT); |
k4zuki | 1:98b55aeebaa5 | 95 | |
k4zuki | 14:c852e468923e | 96 | uint16_t phase_l; |
k4zuki | 14:c852e468923e | 97 | uint16_t phase_r; |
k4zuki | 14:c852e468923e | 98 | int minibuf[16]; |
k4zuki | 14:c852e468923e | 99 | unsigned short skipper; |
k4zuki | 14:c852e468923e | 100 | unsigned short volume; |
k4zuki | 14:c852e468923e | 101 | |
k4zuki | 9:fe61a56fa5a9 | 102 | //float phase_kill; |
k4zuki | 9:fe61a56fa5a9 | 103 | //extern "C" void HardFault_Handler() |
k4zuki | 9:fe61a56fa5a9 | 104 | //{ |
k4zuki | 9:fe61a56fa5a9 | 105 | // error("Hard Fault!\n"); |
k4zuki | 9:fe61a56fa5a9 | 106 | //} |
k4zuki | 14:c852e468923e | 107 | |
k4zuki | 14:c852e468923e | 108 | void play(void) |
k4zuki | 14:c852e468923e | 109 | { |
k4zuki | 16:2edf3d4ccbe3 | 110 | int to_write = i2s.get_fifo_limit() - (i2s.fifo_points()); |
k4zuki | 14:c852e468923e | 111 | for(int i = 0; i < to_write; i+=2) { |
k4zuki | 14:c852e468923e | 112 | minibuf[i] = (int)sine16lookup[(SINE16LENGTH - 1) &( phase_l+skipper)]; |
k4zuki | 14:c852e468923e | 113 | minibuf[i+1] = (int)sine16lookup[(SINE16LENGTH - 1) & (phase_r+skipper)]; |
k4zuki | 14:c852e468923e | 114 | } |
k4zuki | 14:c852e468923e | 115 | i2s.write(minibuf, to_write); |
k4zuki | 14:c852e468923e | 116 | } |
k4zuki | 14:c852e468923e | 117 | |
k4zuki | 9:fe61a56fa5a9 | 118 | Serial pc(USBTX,USBRX); |
k4zuki | 14:c852e468923e | 119 | |
k4zuki | 1:98b55aeebaa5 | 120 | /* main */ |
k4zuki | 1:98b55aeebaa5 | 121 | int main() |
k4zuki | 1:98b55aeebaa5 | 122 | { |
k4zuki | 9:fe61a56fa5a9 | 123 | pc.baud(115200); |
k4zuki | 14:c852e468923e | 124 | skipper = pot1.read_u16() >> 8; |
k4zuki | 14:c852e468923e | 125 | volume = pot2.read_u16() >> 10; |
k4zuki | 14:c852e468923e | 126 | phase_l = 0; |
k4zuki | 14:c852e468923e | 127 | phase_r = 512; |
k4zuki | 16:2edf3d4ccbe3 | 128 | int to_write =0; |
k4zuki | 16:2edf3d4ccbe3 | 129 | int irq=0; |
k4zuki | 11:2fcbac0f72dd | 130 | |
k4zuki | 14:c852e468923e | 131 | // codec.power(true); |
k4zuki | 8:42093f0e5d9e | 132 | // codec.frequency(SAMPLERATE); |
k4zuki | 8:42093f0e5d9e | 133 | // codec.wordsize(16); |
k4zuki | 8:42093f0e5d9e | 134 | // codec.master(false); |
k4zuki | 8:42093f0e5d9e | 135 | // codec.headphone_volume(0.5); |
k4zuki | 14:c852e468923e | 136 | // codec.start(); |
k4zuki | 11:2fcbac0f72dd | 137 | |
k4zuki | 14:c852e468923e | 138 | i2s.frequency(SAMPLERATE); |
k4zuki | 14:c852e468923e | 139 | i2s.wordsize(16); |
k4zuki | 16:2edf3d4ccbe3 | 140 | i2s.stereomono(FrdmI2s::STEREO); |
k4zuki | 16:2edf3d4ccbe3 | 141 | i2s.role(FrdmI2s::MASTER); |
k4zuki | 15:f9f642239cb6 | 142 | // i2s.attach(&play); |
k4zuki | 14:c852e468923e | 143 | i2s.start(); |
k4zuki | 14:c852e468923e | 144 | |
k4zuki | 14:c852e468923e | 145 | while(1) { |
k4zuki | 9:fe61a56fa5a9 | 146 | pc.printf("."); |
k4zuki | 15:f9f642239cb6 | 147 | wait_ms(50); |
k4zuki | 15:f9f642239cb6 | 148 | // skipper = pot1.read_u16() >> 8; |
k4zuki | 15:f9f642239cb6 | 149 | // volume = pot2.read_u16() >> 10; // 6-bit unsigned int |
k4zuki | 14:c852e468923e | 150 | // codec.headphone_volume((int)(volume)); |
k4zuki | 11:2fcbac0f72dd | 151 | |
k4zuki | 14:c852e468923e | 152 | lcd.locate(0,3); |
k4zuki | 15:f9f642239cb6 | 153 | lcd.printf("%08X",I2S0->TCSR); |
k4zuki | 15:f9f642239cb6 | 154 | I2S0->TCSR |= I2S_TCSR_FEF(1); |
k4zuki | 15:f9f642239cb6 | 155 | // lcd.printf("Volume: %+03d", (volume - 57)); |
k4zuki | 15:f9f642239cb6 | 156 | // lcd.locate(0,15); |
k4zuki | 15:f9f642239cb6 | 157 | // lcd.printf("Skipper: %04d", skipper); |
k4zuki | 16:2edf3d4ccbe3 | 158 | irq = (I2S0->TCSR &I2S_TCSR_FEF_MASK) >> I2S_TCSR_FEF_SHIFT; |
k4zuki | 16:2edf3d4ccbe3 | 159 | to_write = i2s.get_fifo_limit() - (i2s.fifo_level()); |
k4zuki | 16:2edf3d4ccbe3 | 160 | pc.printf("%d, %d\r",irq,to_write); |
k4zuki | 16:2edf3d4ccbe3 | 161 | for(int j=0;j<to_write ;j++){ |
k4zuki | 16:2edf3d4ccbe3 | 162 | I2S0->TDR[0] = 0x55AA; |
k4zuki | 15:f9f642239cb6 | 163 | } |
k4zuki | 1:98b55aeebaa5 | 164 | } |
k4zuki | 1:98b55aeebaa5 | 165 | } |