Yanni Coroneos
/
mbed_aks_configurator
master fsm
main.cpp@0:f44331af9d8b, 2015-11-25 (annotated)
- Committer:
- sandwich
- Date:
- Wed Nov 25 07:34:40 2015 +0000
- Revision:
- 0:f44331af9d8b
master fsm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandwich | 0:f44331af9d8b | 1 | #include "mbed.h" |
sandwich | 0:f44331af9d8b | 2 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
sandwich | 0:f44331af9d8b | 3 | DigitalOut ak4117cs(p8); |
sandwich | 0:f44331af9d8b | 4 | DigitalOut ak4117pdn(p9); |
sandwich | 0:f44331af9d8b | 5 | DigitalOut ak4396cs(p10); |
sandwich | 0:f44331af9d8b | 6 | DigitalOut ak4396pdn(p11); |
sandwich | 0:f44331af9d8b | 7 | DigitalOut myled(LED1); |
sandwich | 0:f44331af9d8b | 8 | |
sandwich | 0:f44331af9d8b | 9 | uint16_t CONTROL0_CLOCK_SOURCE = 0b0010000000001111; // select PLL as master clock source |
sandwich | 0:f44331af9d8b | 10 | uint16_t CONTROL1_CLOCK_FREQ = 0b0010000100000000; // select master clk for PLL mode, fs = 48kHz |
sandwich | 0:f44331af9d8b | 11 | uint16_t CONTROL2_FORMAT_SETTING = 0b0010001000001101; // select I2S as comm format and channel 1 for fs |
sandwich | 0:f44331af9d8b | 12 | uint16_t CONTROL3_INT_0 = 0b0010001101111111; // enable all the interrupts on INT0 |
sandwich | 0:f44331af9d8b | 13 | |
sandwich | 0:f44331af9d8b | 14 | |
sandwich | 0:f44331af9d8b | 15 | uint16_t CONTROL2_DEFAULT_NORMALSPEED = 0b0010000110000010; |
sandwich | 0:f44331af9d8b | 16 | uint16_t CONTROL1_MODE3_RSTN_AUTO_SETTING = 0b0010000010001110; |
sandwich | 0:f44331af9d8b | 17 | uint16_t CONTROL1_MODE3_AUTO_SETTING = 0b0010000010001111; |
sandwich | 0:f44331af9d8b | 18 | uint16_t CONTROL3_DEFAULT = 0b0010001000000000; |
sandwich | 0:f44331af9d8b | 19 | uint16_t LCH_FULL_VOLUME = 0b0010001111111111; |
sandwich | 0:f44331af9d8b | 20 | uint16_t RCH_FULL_VOLUME = 0b0010010011111111; |
sandwich | 0:f44331af9d8b | 21 | |
sandwich | 0:f44331af9d8b | 22 | //data order is C1,C0,R/W,A4,A3,A2,A1,A0,D7,D6.D5,D4,D3,D2,D1,D0 |
sandwich | 0:f44331af9d8b | 23 | uint16_t CONTROL0_AK4396 = 0b0010000010000111; |
sandwich | 0:f44331af9d8b | 24 | uint16_t CONTROL1_AK4396 = 0b0010000110000010; |
sandwich | 0:f44331af9d8b | 25 | |
sandwich | 0:f44331af9d8b | 26 | |
sandwich | 0:f44331af9d8b | 27 | void ak4117_config(); |
sandwich | 0:f44331af9d8b | 28 | void ak4396_config(); |
sandwich | 0:f44331af9d8b | 29 | |
sandwich | 0:f44331af9d8b | 30 | int main() |
sandwich | 0:f44331af9d8b | 31 | { |
sandwich | 0:f44331af9d8b | 32 | // Setup the spi for 16 bit data, high steady state clock, |
sandwich | 0:f44331af9d8b | 33 | // second edge capture, with a 9600 clock rate |
sandwich | 0:f44331af9d8b | 34 | spi.format(16,3); |
sandwich | 0:f44331af9d8b | 35 | spi.frequency(9600); |
sandwich | 0:f44331af9d8b | 36 | ak4396cs = 1; |
sandwich | 0:f44331af9d8b | 37 | ak4117cs=1; |
sandwich | 0:f44331af9d8b | 38 | |
sandwich | 0:f44331af9d8b | 39 | ak4117_config(); |
sandwich | 0:f44331af9d8b | 40 | wait(0.2); |
sandwich | 0:f44331af9d8b | 41 | ak4396_config(); |
sandwich | 0:f44331af9d8b | 42 | while(1) { |
sandwich | 0:f44331af9d8b | 43 | myled = 1; |
sandwich | 0:f44331af9d8b | 44 | wait(0.2); |
sandwich | 0:f44331af9d8b | 45 | myled = 0; |
sandwich | 0:f44331af9d8b | 46 | wait(0.2); |
sandwich | 0:f44331af9d8b | 47 | } |
sandwich | 0:f44331af9d8b | 48 | } |
sandwich | 0:f44331af9d8b | 49 | |
sandwich | 0:f44331af9d8b | 50 | void ak4396_config() |
sandwich | 0:f44331af9d8b | 51 | { |
sandwich | 0:f44331af9d8b | 52 | // Chip must be deselected |
sandwich | 0:f44331af9d8b | 53 | ak4396cs = 1; |
sandwich | 0:f44331af9d8b | 54 | ak4396pdn=0; //power down |
sandwich | 0:f44331af9d8b | 55 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 56 | ak4396pdn=1; |
sandwich | 0:f44331af9d8b | 57 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 58 | |
sandwich | 0:f44331af9d8b | 59 | |
sandwich | 0:f44331af9d8b | 60 | //while (1) |
sandwich | 0:f44331af9d8b | 61 | // { |
sandwich | 0:f44331af9d8b | 62 | // Select the device by seting chip select low |
sandwich | 0:f44331af9d8b | 63 | ak4396cs = 0; |
sandwich | 0:f44331af9d8b | 64 | // turn on zero_detect |
sandwich | 0:f44331af9d8b | 65 | spi.write(CONTROL0_AK4396); |
sandwich | 0:f44331af9d8b | 66 | // Deselect the device |
sandwich | 0:f44331af9d8b | 67 | ak4396cs = 1; |
sandwich | 0:f44331af9d8b | 68 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 69 | |
sandwich | 0:f44331af9d8b | 70 | ak4396cs=0; |
sandwich | 0:f44331af9d8b | 71 | spi.write(CONTROL1_AK4396); |
sandwich | 0:f44331af9d8b | 72 | ak4396cs=1; |
sandwich | 0:f44331af9d8b | 73 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 74 | return; |
sandwich | 0:f44331af9d8b | 75 | } |
sandwich | 0:f44331af9d8b | 76 | |
sandwich | 0:f44331af9d8b | 77 | void ak4117_config() |
sandwich | 0:f44331af9d8b | 78 | { |
sandwich | 0:f44331af9d8b | 79 | // Chip must be deselected |
sandwich | 0:f44331af9d8b | 80 | ak4117cs = 1; |
sandwich | 0:f44331af9d8b | 81 | ak4117pdn=0; //power down |
sandwich | 0:f44331af9d8b | 82 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 83 | ak4117pdn=1; |
sandwich | 0:f44331af9d8b | 84 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 85 | |
sandwich | 0:f44331af9d8b | 86 | //while (1) |
sandwich | 0:f44331af9d8b | 87 | // { |
sandwich | 0:f44331af9d8b | 88 | // Select the device by seting chip select low |
sandwich | 0:f44331af9d8b | 89 | ak4117cs = 0; |
sandwich | 0:f44331af9d8b | 90 | // turn on zero_detect |
sandwich | 0:f44331af9d8b | 91 | spi.write(CONTROL0_CLOCK_SOURCE); |
sandwich | 0:f44331af9d8b | 92 | // Deselect the device |
sandwich | 0:f44331af9d8b | 93 | ak4117cs = 1; |
sandwich | 0:f44331af9d8b | 94 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 95 | |
sandwich | 0:f44331af9d8b | 96 | ak4117cs=0; |
sandwich | 0:f44331af9d8b | 97 | spi.write(CONTROL1_CLOCK_FREQ); |
sandwich | 0:f44331af9d8b | 98 | ak4117cs=1; |
sandwich | 0:f44331af9d8b | 99 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 100 | |
sandwich | 0:f44331af9d8b | 101 | ak4117cs=0; |
sandwich | 0:f44331af9d8b | 102 | spi.write(CONTROL2_FORMAT_SETTING); |
sandwich | 0:f44331af9d8b | 103 | ak4117cs=1; |
sandwich | 0:f44331af9d8b | 104 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 105 | |
sandwich | 0:f44331af9d8b | 106 | ak4117cs=0; |
sandwich | 0:f44331af9d8b | 107 | spi.write(CONTROL3_INT_0); |
sandwich | 0:f44331af9d8b | 108 | ak4117cs=1; |
sandwich | 0:f44331af9d8b | 109 | wait_ms(1); |
sandwich | 0:f44331af9d8b | 110 | return; |
sandwich | 0:f44331af9d8b | 111 | } |