1 | void init_pcm3060(void){
|
2 |
|
3 | printf("Initializing PCM3060\n");
|
4 | int i=0;
|
5 | uint16_t reg[10];
|
6 | uint16_t reg_release=0;
|
7 | //Regs
|
8 | reg[0]=
|
9 | 64<<8 //Register id
|
10 | |0<<7 //MRST: Mode control reset (0=Set to default)
|
11 | |0<<6 //SRST: System reset (0= Resync.)
|
12 | |1<<5 //ADPSV: ADC Power save control (1= power save)
|
13 | |1<<4 //DAPSV: DAC Power save control (1= power save)
|
14 | |0; //S/E: Singled ended or differential select (0=diff)
|
15 |
|
16 | reg[1]=
|
17 | 65<<8 //Register id
|
18 | |255; //DAC Attenuation level left (255=No attenuation)
|
19 | reg[2]=
|
20 | 66<<8 //Register id
|
21 | |255; //DAC Attenuation level right (255=No attenuation)
|
22 | reg[3]=
|
23 | 67<<8 //Register id
|
24 | |0<<7 //CSEL2: Clock select DAC (0= SCK2, BCK2, LRCK2 enabled)
|
25 | |0b000<<4 //M/S: Master select DAC (0b000=Slave mode)
|
26 | |0b01;//FMT2: Audio interface format DAC (0b01=24 bit LJ)
|
27 | reg[4]=
|
28 | 68<<8 //Register id
|
29 | |0<<6 //OVER: Oversampling rate control DAC (0=x32 Oversampling)
|
30 | |0<<2 //DREV2: Output phase select (0=Non-inverted)
|
31 | |0<<1 //MUT22: Soft mute control left (0=No mute)
|
32 | |0; //MUT21: Soft mute control right (0=No mute)
|
33 | reg[5]=
|
34 | 69<<8 //Register id
|
35 | |0 //FLT: Digital filter rolloff control DAC (0=Sharp roloff)
|
36 | |0b01<<5 //DMF: Sampling freq selection for De-Emphasis DAC (0b01=48kHz)
|
37 | |0<<4 //DMC: De-Emphasis control DAC ( 0=Disabled)
|
38 | |0<<1 //ZREV: Zero detect polarity (0=High)
|
39 | |0; //AZRO: Zero flag function select
|
40 | reg[6]=
|
41 | 70<<8 //Register id
|
42 | |215; //ADC Attenuation level left (215==0dB)
|
43 | reg[7]=
|
44 | 71<<8 //Register id
|
45 | |215; //ADC Attenuation level right (215==0dB)
|
46 | reg[8]=
|
47 | 72<<8 //Register id
|
48 | |1<<7 //CSEL1: Clock select ADC (0=SCK1, BCK1)
|
49 | |0b000<<4 //M/S: Master select ADC (0b000=Slave)
|
50 | |0b01;//FMT2: Audio interface format ADC (01=24 bit LJ)
|
51 | reg[9]=
|
52 | 73<<8 //Register id
|
53 | |1<<4 //ZCDD: Zero cross detection disable (1=Disabled)
|
54 | |0<<3 //BYP: HPF Bypass controll ADC (0=HPF enabled)
|
55 | |0<<2 //DREV1: Input phase select ADC (0=Non-inverted)
|
56 | |0<<1 //MUT12: Soft mute control ADC left (0=No mute)
|
57 | |0; //MUT11: Soft mute control ADC right (0=No mute)
|
58 |
|
59 | //Register for releasing the ADC/DAC power save mode
|
60 | reg_release=
|
61 | 64<<8 //Register id
|
62 | |0<<7 //MRST: Mode control reset (0=Set to default)
|
63 | |0<<6 //SRST: System reset (0= Resync.)
|
64 | |0<<5 //ADPSV: ADC Power save control (0=normal mode)
|
65 | |0<<4 //DAPSV: DAC Power save control (0=normal mode)
|
66 | |0; //S/E: Singled ended or differential select (0=diff)
|
67 |
|
68 | //Startup and init sequence
|
69 | HAL_GPIO_WritePin(GPIOG,GPIO_PIN_0,0); //Pull RST pin to low
|
70 | HAL_Delay(100); //Wait for power-up
|
71 |
|
72 | HAL_GPIO_WritePin(GPIOG,GPIO_PIN_1,1); //MS high: SPI Unselect device
|
73 | HAL_Delay(10); //Wait
|
74 |
|
75 | //Write configuration registers
|
76 | for(i=0;i<sizeof(reg)/2;i++){
|
77 | HAL_GPIO_WritePin(GPIOG,GPIO_PIN_1,0); //MS low: SPI Select device
|
78 | HAL_SPI_Transmit(&hspi3,(uint8_t *)®[i],1,1000); //Send config register
|
79 | HAL_GPIO_WritePin(GPIOG,GPIO_PIN_1,1);//MS high: SPI Unselect device
|
80 | HAL_Delay(1); //Wait
|
81 | }
|
82 |
|
83 | //Starting up
|
84 | HAL_GPIO_WritePin(GPIOG,GPIO_PIN_0,1); //Push RST pin to high
|
85 | HAL_Delay(100); //Wait to release power save mode (100ms)
|
86 | HAL_SPI_Transmit(&hspi3,(uint8_t *)®_release,1,1000); //Exit power save mode via SPI command
|
87 | }
|