22 #define STw5094A_ADDR_WR 0xE2
23 #define STw5094A_ADDR_RD 0xE3
25 #define STw5094A_I2C_SPEED 100000
32 #define STw5094A_I2C_FLAG_TIMEOUT ((uint32_t)0x1000)
33 #define STw5094A_I2C_LONG_TIMEOUT ((uint32_t)(10 * STw5094A_I2C_FLAG_TIMEOUT))
36 #define CONTROL_REGISTER_1 1
37 #define CONTROL_REGISTER_2 2
38 #define CONTROL_REGISTER_3 3
39 #define CONTROL_REGISTER_4 4
40 #define CONTROL_REGISTER_5 5
41 #define CONTROL_REGISTER_6 6
42 #define CONTROL_REGISTER_7 7
43 #define CONTROL_REGISTER_8 8
44 #define CONTROL_REGISTER_9 9
45 #define CONTROL_REGISTER_10 10
46 #define CONTROL_REGISTER_11 11
47 #define CONTROL_REGISTER_12 12
48 #define CONTROL_REGISTER_13 13
49 #define CONTROL_REGISTER_14 14
50 #define CONTROL_REGISTER_15 15
51 #define CONTROL_REGISTER_16 16
52 #define CONTROL_REGISTER_17 17
53 #define CONTROL_REGISTER_18 18
54 #define CONTROL_REGISTER_19 19
55 #define CONTROL_REGISTER_20 20
56 #define CONTROL_REGISTER_21 21
58 #define LOCAL_BUFFER_SIZE 1024 //size of the local buffer in 16 bits words
61 volatile u8 AUDIO_CODEC_CRs[22];
62 volatile s8 flagWrite_AUDIO_CODEC_CRs = -1;
69 volatile u32 Audio_buffer_index = 0;
70 volatile u32 Audio_buffer_size = 0;
71 volatile s16 Audio_buffer_local[LOCAL_BUFFER_SIZE];
72 s32 Audio_buffer_local_size = LOCAL_BUFFER_SIZE;
76 voice_type* Voice_buffer;
77 volatile u32 Voice_buffer_index = 0;
78 volatile u32 Voice_buffer_size = 0;
91 const u32 I2S_PreDiv2[5] = { RCC_PREDIV2_Div6, RCC_PREDIV2_Div11, RCC_PREDIV2_Div11, RCC_PREDIV2_Div4, RCC_PREDIV2_Div12 };
92 const u32 I2S_Pll3Mul[5] = { RCC_PLL3Mul_20, RCC_PLL3Mul_20, RCC_PLL3Mul_10, RCC_PLL3Mul_20, RCC_PLL3Mul_20 };
93 const u16 I2S_PrescalerVal[5] = { 32, 18, 18, 144, 96 };
96 const u16 I2S_PrescalerVal[5] = { 0x111, 0x117, 0x123, 0x02F, 0x146 };
100 void AUDIO_Init_I2C();
103 s32 AUDIO_I2C_ReadMultByte( u8 ReadAddr, u8 NumByteToRead, u8* pBuffer );
104 s32 AUDIO_I2C_WriteMultByte( u8 WriteAddr, u8 NumByteToWrite, u8* pBuffer );
120 void AUDIO_DeviceSoftwareReset(
void )
122 u8 reset_value = 0x2;
123 AUDIO_I2C_WriteMultByte( CONTROL_REGISTER_21, 1, &reset_value );
141 void AUDIO_UpdateRegisters(
void )
143 if ( ( flagWrite_AUDIO_CODEC_CRs > -1 ) && ( flagWrite_AUDIO_CODEC_CRs < 22 ) )
146 AUDIO_I2C_WriteMultByte( flagWrite_AUDIO_CODEC_CRs, 1, ( u8* ) &AUDIO_CODEC_CRs[flagWrite_AUDIO_CODEC_CRs] );
150 if ( flagWrite_AUDIO_CODEC_CRs >= 22 )
153 AUDIO_I2C_WriteMultByte( CONTROL_REGISTER_0, 22, ( u8* ) AUDIO_CODEC_CRs );
156 flagWrite_AUDIO_CODEC_CRs = -1;
178 RCC_SYSCLKConfig( RCC_SYSCLKSource_HSI );
181 RCC_PLLCmd( DISABLE );
182 RCC_PLL3Cmd( DISABLE );
183 RCC_PLL2Cmd( DISABLE );
186 RCC_PREDIV2Config( I2S_PreDiv2[frequency] );
187 RCC_PLL3Config( I2S_Pll3Mul[frequency] );
190 *( u16* )AUDIO_I2SPR = I2S_PrescalerVal[frequency];
193 RCC_PLL2Cmd( ENABLE );
195 while ( ( RCC->CR & RCC_CR_PLL2RDY ) == 0 )
200 RCC_PLLCmd( ENABLE );
202 while ( ( RCC->CR & RCC_CR_PLLRDY ) == 0 )
207 RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );
209 while ( ( RCC->CFGR & ( uint32_t )RCC_CFGR_SWS ) != ( uint32_t )0x08 )
214 RCC_PLL3Cmd( ENABLE );
216 while ( ( RCC->CR & RCC_CR_PLL3RDY ) == 0 )
239 void AUDIO_Init(
void )
243 RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C2, ENABLE );
245 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
246 RCC_APB2Periph_AFIO, ENABLE );
249 if ( fFirstStartup == FALSE )
255 AUDIO_SpeakerOnOld = AUDIO_SpeakerOn;
264 AUDIO_SpeakerOnOld = 1;
266 AUDIO_Volume = AUDIO_MIN_ATTENUATION;
267 AUDIO_BuzzerOn = TRUE;
274 AUDIO_DeviceSoftwareReset();
277 AUDIO_I2C_ReadMultByte( CONTROL_REGISTER_0, 22, ( u8* ) AUDIO_CODEC_CRs );
285 AUDIO_UpdateRegisters();
291 GPIO_InitTypeDef GPIO_InitStructure;
292 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
293 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
294 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
295 GPIO_Init( GPIOA, &GPIO_InitStructure );
296 RCC_MCOConfig( RCC_MCO_HSE );
312 void AUDIO_Handler(
void )
315 AUDIO_UpdateRegisters();
318 if ( AUDIO_SpeakerOn != AUDIO_SpeakerOnOld )
321 AUDIO_SpeakerOnOld = AUDIO_SpeakerOn;
343 void AUDIO_I2S_GPIO_Init(
void)
345 GPIO_InitTypeDef GPIO_InitStructure;
348 RCC_PERIPH_GPIO_CLOCK_CMD( GPIO_I2S_WS_PERIPH, ENABLE );
349 RCC_PERIPH_GPIO_CLOCK_CMD( GPIO_I2S_SCK_PERIPH, ENABLE );
350 RCC_PERIPH_GPIO_CLOCK_CMD( GPIO_I2S_SD_PERIPH, ENABLE );
353 GPIO_InitStructure.GPIO_Pin = GPIO_I2S_WS_PIN;
354 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
355 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
356 GPIO_Init( GPIOx_I2S_WS_PORT, &GPIO_InitStructure );
358 GPIO_InitStructure.GPIO_Pin = GPIO_I2S_SCK_PIN;
359 GPIO_Init( GPIOx_I2S_SCK_PORT, &GPIO_InitStructure );
361 GPIO_InitStructure.GPIO_Pin = GPIO_I2S_SD_PIN;
362 GPIO_Init( GPIOx_I2S_SD_PORT, &GPIO_InitStructure );
378 void AUDIO_Init_I2C(
void )
381 GPIO_InitTypeDef GPIO_InitStructure;
382 I2C_InitTypeDef I2C_InitStructure;
385 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
388 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
389 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
390 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
391 GPIO_Init( GPIOB, &GPIO_InitStructure );
394 I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
395 I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
396 I2C_InitStructure.I2C_OwnAddress1 = 0xC0;
397 I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
398 I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
399 I2C_InitStructure.I2C_ClockSpeed = STw5094A_I2C_SPEED;
402 I2C_Cmd( I2C2, ENABLE );
405 I2C_Init( I2C2, &I2C_InitStructure );
435 DMA_InitTypeDef DMA_InitStructure;
436 I2S_InitTypeDef I2S_InitStructure;
437 NVIC_InitTypeDef NVIC_InitStructure;
445 RCC_APB1PeriphClockCmd( RCC_APBxPeriph_AUDIO_I2S, ENABLE );
446 I2S_Cmd( AUDIO_I2S, DISABLE );
451 AUDIO_CODEC_CRs[0] = 0x00;
455 AUDIO_CODEC_CRs[1] = 0x14;
458 AUDIO_CODEC_CRs[4] = 0x6f;
461 AUDIO_CODEC_CRs[5] = 0x17;
464 AUDIO_CODEC_CRs[6] = ( AUDIO_SpeakerOn ? 0x10 : 0 ) + 0x0c + 0x02 ;
467 if ( AUDIO_Mute == TRUE )
469 AUDIO_CODEC_CRs[6] |= 0x20;
473 AUDIO_CODEC_CRs[6] &= 0xDF;
476 s32 hp_setting = ( AUDIO_Volume + 2 ) * 2;
477 if ( hp_setting > 0x14 )
481 AUDIO_CODEC_CRs[7] = AUDIO_Volume;
482 AUDIO_CODEC_CRs[8] = hp_setting ;
483 AUDIO_CODEC_CRs[9] = hp_setting ;
486 AUDIO_CODEC_CRs[12] = 0x84;
489 AUDIO_CODEC_CRs[13] = 89;
490 AUDIO_CODEC_CRs[14] = 89;
492 AUDIO_CODEC_CRs[16] = 0x08;
496 AUDIO_CODEC_CRs[18] = 0x61;
498 AUDIO_CODEC_CRs[18] = 0x60;
502 AUDIO_CODEC_CRs[21] = 0x61;
504 flagWrite_AUDIO_CODEC_CRs = 22;
510 NVIC_InitStructure.NVIC_IRQChannel = AUDIO_DMA_TX_Channelx_IRQn;
511 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
512 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
513 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
514 NVIC_Init( &NVIC_InitStructure );
517 RCC_AHBPeriphClockCmd( RCC_AHBPeriph_AUDIO_DMA, ENABLE );
518 DMA_DeInit( AUDIO_DMA_TX );
519 DMA_InitStructure.DMA_PeripheralBaseAddr = ( u32 )&AUDIO_I2S->DR;
520 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
521 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
522 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
523 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
524 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
526 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
528 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
529 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
530 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
531 DMA_Init( AUDIO_DMA_TX, &DMA_InitStructure );
533 DMA_ITConfig( AUDIO_DMA_TX, DMA_IT_TC | DMA_IT_HT, ENABLE );
536 AUDIO_I2S_GPIO_Init();
540 I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
543 I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
544 I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
549 case FRQ_8KHZ : I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
551 case FRQ_16KHZ : I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_16k;
553 case FRQ_22KHZ : I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_22k;
555 case FRQ_44KHZ : I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_44k;
557 case FRQ_48KHZ : I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k;
559 default: I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
562 I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
563 I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
568 I2S_Init( AUDIO_I2S, &I2S_InitStructure );
572 AUDIO_SetClocks( frequency );
575 Audio_buffer_index = 0;
579 AUDIO_Length = length;
580 AUDIO_Frequency = frequency;
581 AUDIO_Format = format;
587 I2S_Cmd( AUDIO_I2S, ENABLE );
613 I2S_InitTypeDef I2S_InitStructure;
614 NVIC_InitTypeDef NVIC_InitStructure;
615 DMA_InitTypeDef DMA_InitStructure;
617 RCC_APB1PeriphClockCmd( RCC_APBxPeriph_AUDIO_I2S , ENABLE );
618 I2S_Cmd( AUDIO_I2S, DISABLE );
623 AUDIO_CODEC_CRs[0] = 0x20;
627 AUDIO_CODEC_CRs[1] = 0x14;
630 AUDIO_CODEC_CRs[4] = 0x6f;
634 AUDIO_CODEC_CRs[5] = 0x13;
637 AUDIO_CODEC_CRs[6] = 0;
640 if ( AUDIO_Mute == TRUE )
642 AUDIO_CODEC_CRs[6] |= 0x20;
646 AUDIO_CODEC_CRs[6] &= 0xDF;
650 s32 hp_setting = ( AUDIO_Volume + 2 ) * 2;
651 if ( hp_setting > 0x14 )
655 AUDIO_CODEC_CRs[7] = AUDIO_Volume;
656 AUDIO_CODEC_CRs[8] = hp_setting ;
657 AUDIO_CODEC_CRs[9] = hp_setting ;
660 AUDIO_CODEC_CRs[12] = 0x00;
663 AUDIO_CODEC_CRs[13] = AUDIO_CODEC_CRs[14] = 0x0;
666 AUDIO_CODEC_CRs[18] = 0x60;
669 AUDIO_CODEC_CRs[21] = 0x01;
671 flagWrite_AUDIO_CODEC_CRs = 22;
676 NVIC_InitStructure.NVIC_IRQChannel = AUDIO_DMA_RX_Channelx_IRQn;
677 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
678 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
679 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
680 NVIC_Init( &NVIC_InitStructure );
683 RCC_AHBPeriphClockCmd( RCC_AHBPeriph_AUDIO_DMA, ENABLE );
684 DMA_DeInit( AUDIO_DMA_RX );
685 DMA_InitStructure.DMA_PeripheralBaseAddr = ( u32 )&AUDIO_I2S->DR;
686 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
687 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
688 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
689 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
690 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
692 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
694 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
695 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
696 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
697 DMA_Init( AUDIO_DMA_RX, &DMA_InitStructure );
699 DMA_ITConfig( AUDIO_DMA_RX, DMA_IT_TC | DMA_IT_HT, ENABLE );
702 AUDIO_I2S_GPIO_Init();
706 I2S_InitStructure.I2S_Standard = I2S_Standard_PCMShort;
709 I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended;
711 I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
714 I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_16k;
715 I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
716 I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
717 I2S_Init( AUDIO_I2S, &I2S_InitStructure );
728 Voice_buffer_index = 0;
737 I2S_Cmd( AUDIO_I2S, ENABLE );
756 void AUDIO_Shutdown(
void )
759 I2S_Cmd( AUDIO_I2S, DISABLE );
762 AUDIO_DeviceSoftwareReset();
765 I2C_Cmd( I2C2, DISABLE );
779 const u8 welcome_16K_8 [] =
781 #include "welcome_stm32_16k_8b.h"
784 void AUDIO_Welcome_Msg(
void )
806 u8 AUDIO_I2C_Read_Register( u8 register_to_read )
809 AUDIO_I2C_ReadMultByte( register_to_read, 1, &val );
830 void AUDIO_I2C_WriteRegister( u8 register_to_write, u8 data_to_write )
832 AUDIO_I2C_WriteMultByte( register_to_write, 1, &data_to_write );
855 s32 AUDIO_I2C_WriteMultByte( u8 WriteAddr, u8 NumByteToWrite, u8* pBuffer )
862 I2C_GenerateSTART( I2C2, ENABLE );
865 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
866 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_MODE_SELECT ) )
868 if ( I2C2->SR1 & I2C_FLAG_RXNE )
871 if ( ( TimeOut-- ) == 0 )
876 I2C_Send7bitAddress( I2C2, STw5094A_ADDR_WR, I2C_Direction_Transmitter );
879 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
880 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) )
882 if ( ( TimeOut-- ) == 0 )
887 I2C_SendData( I2C2, WriteAddr );
891 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
892 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) )
894 if ( ( TimeOut-- ) == 0 )
898 while ( NumByteToWrite )
901 I2C_SendData( I2C2, * pBuffer );
904 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
905 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) )
907 if ( ( TimeOut-- ) == 0 )
911 if ( NumByteToWrite == 1 )
912 { I2C_GenerateSTOP( I2C2, ENABLE ); }
917 for ( i = 0 ; i < 500 ; i++ ) { ; }
943 s32 AUDIO_I2C_ReadMultByte( u8 ReadAddr, u8 NumByteToRead, u8* pBuffer )
950 I2C_GenerateSTART( I2C2, ENABLE );
953 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
954 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_MODE_SELECT ) )
956 if ( I2C2->SR1 & I2C_FLAG_RXNE )
959 if ( ( TimeOut-- ) == 0 )
964 I2C_Send7bitAddress( I2C2, STw5094A_ADDR_WR, I2C_Direction_Transmitter );
968 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
969 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) )
971 if ( ( TimeOut-- ) == 0 )
976 I2C_Cmd( I2C2, ENABLE );
979 I2C_SendData( I2C2, ReadAddr );
982 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
983 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) )
985 if ( ( TimeOut-- ) == 0 )
990 I2C_GenerateSTART( I2C2, ENABLE );
993 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
994 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_MODE_SELECT ) )
996 if ( ( TimeOut-- ) == 0 )
1001 I2C_Send7bitAddress( I2C2, STw5094A_ADDR_RD, I2C_Direction_Receiver );
1004 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
1005 while ( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ) )
1007 if ( ( TimeOut-- ) == 0 )
1012 while ( NumByteToRead )
1014 if ( NumByteToRead == 1 )
1017 I2C_AcknowledgeConfig( I2C2, DISABLE );
1020 I2C_GenerateSTOP( I2C2, ENABLE );
1024 TimeOut = STw5094A_I2C_LONG_TIMEOUT;
1025 if ( I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED ) )
1028 *pBuffer = I2C_ReceiveData( I2C2 );
1038 if ( ( TimeOut-- ) == 0 )
1045 I2C_AcknowledgeConfig( I2C2, ENABLE );
1047 for ( i = 0 ; i < 500 ; i++ ) { ; }
1068 void AUDIO_BUZZER_SetToneFrequency( u16 freq )
1073 valreg = ( 256 * freq ) / 1000;
1077 valreg = ( ( 128 * freq ) / 1000 ) + 32;
1081 valreg = ( ( 64 * freq ) / 1000 ) + 80;
1085 valreg = ( ( 32 * freq ) / 1000 ) + 136;
1093 AUDIO_CODEC_CRs[13] = valreg;
1094 AUDIO_CODEC_CRs[14] = valreg;
1097 SET_FLAG_WRITE_CODEC_CRS( 13 );
1119 AUDIO_CODEC_CRs[6] |= 0x01;
1121 AUDIO_CODEC_CRs[6] &= 0xFE;
1124 SET_FLAG_WRITE_CODEC_CRS( 6 );
1137 void AUDIO_Set_Volume(
void )
1139 s32 hp_setting = ( AUDIO_Volume + 2 ) * 2;
1140 if ( hp_setting > 0x14 )
1144 AUDIO_CODEC_CRs[7] = AUDIO_Volume;
1145 AUDIO_CODEC_CRs[8] = hp_setting ;
1146 AUDIO_CODEC_CRs[9] = hp_setting ;
1149 SET_FLAG_WRITE_CODEC_CRS( 22 );
1163 void AUDIO_Cpy_Mono(
void )
1169 if ( Audio_buffer_index >= Audio_buffer_size )
1180 for ( i = 0 ; i < ( ( Audio_buffer_local_size / 4 ) - 1 ) ; i = i + 2 )
1182 temp = *( s16* )( Audio_buffer + Audio_buffer_index );
1183 Audio_buffer_local[i + 1] = Audio_buffer_local[i] = temp;
1184 Audio_buffer_index += 2;
1189 for ( i = 0; i < ( ( Audio_buffer_local_size / 4 ) - 1 ); i = i + 2 )
1191 temp = ( ( s16 )( ( *( Audio_buffer + Audio_buffer_index ) ^ 0x80 ) ) ) << 8;
1192 Audio_buffer_local[i + 1] = Audio_buffer_local[i] = temp;
1193 Audio_buffer_index++;
1196 bufferstatus_local &= ~LOW_EMPTY;
1204 for ( i = ( Audio_buffer_local_size / 4 ) ; i < ( Audio_buffer_local_size / 2 ); i = i + 2 )
1206 temp = *( s16* )( Audio_buffer + Audio_buffer_index );
1207 Audio_buffer_local[i + 1] = Audio_buffer_local[i] = temp;
1208 Audio_buffer_index += 2;
1213 for ( i = ( Audio_buffer_local_size / 4 ); i < ( ( Audio_buffer_local_size ) / 2 ) - 1; i = i + 2 )
1215 temp = ( ( s16 )( ( *( Audio_buffer + Audio_buffer_index ) ^ 0x80 ) ) ) << 8;
1216 Audio_buffer_local[i + 1] = Audio_buffer_local[i] = temp;
1217 Audio_buffer_index++;
1220 bufferstatus_local &= ~HIGH_EMPTY;
1223 if ( Audio_buffer_index == ( Audio_buffer_size / 2 ) )
1226 if ( audio_buffer_fill & HIGH_EMPTY )
1232 if ( Audio_buffer_index >= Audio_buffer_size )
1235 Audio_buffer_index = 0;
1236 if ( audio_buffer_fill & LOW_EMPTY )
1273 AUDIO_Init_voice_mode( mode );
1275 AUDIO_Init_audio_mode( mode, length, frequency, format );
1277 AUDIO_DeviceMode = mode;
1298 return AUDIO_DeviceMode;
1323 if ( AUDIO_Format ==
STEREO )
1326 AUDIO_DMA_TX->CMAR = ( u32 )buffer;
1327 AUDIO_DMA_TX->CNDTR = size;
1335 Audio_buffer_index = 0;
1336 Audio_buffer_size = size;
1338 AUDIO_DMA_TX->CMAR = ( u32 )Audio_buffer_local;
1339 AUDIO_DMA_TX->CNDTR = ( ( Audio_buffer_local_size ) / 2 );
1342 DMA_Cmd( AUDIO_DMA_TX, ENABLE );
1343 SPI_I2S_DMACmd( AUDIO_I2S, SPI_I2S_DMAReq_Tx, ENABLE );
1362 DMA_Cmd( AUDIO_DMA_TX, DISABLE );
1363 SPI_I2S_DMACmd( AUDIO_I2S, SPI_I2S_DMAReq_Tx, DISABLE );
1369 for ( i = 0; i < 10000 ; i++ ) {;}
1393 Voice_buffer = ( voice_type* ) buffer;
1394 Voice_buffer_size = size;
1395 Voice_buffer_index = 0;
1396 voice_record_buffer_fill =
EMPTY;
1400 AUDIO_DMA_RX->CMAR = ( u32 )buffer;
1401 AUDIO_DMA_RX->CNDTR = size;
1402 DMA_Cmd( AUDIO_DMA_RX, ENABLE );
1403 SPI_I2S_DMACmd( AUDIO_I2S, SPI_I2S_DMAReq_Rx, ENABLE );
1419 DMA_Cmd( AUDIO_DMA_RX, DISABLE );
1420 SPI_I2S_DMACmd( AUDIO_I2S, SPI_I2S_DMAReq_Rx, DISABLE );
1439 return AUDIO_Playback_status;
1461 audio_buffer_fill &= ~value;
1462 return audio_buffer_fill;
1484 voice_record_buffer_fill &= ~value;
1485 return voice_record_buffer_fill;
1503 return AUDIO_Recording_status;
1525 AUDIO_CODEC_CRs[6] |= 0x10;
1526 AUDIO_SpeakerOn = 1;
1530 AUDIO_CODEC_CRs[6] &= 0xEF;
1531 AUDIO_SpeakerOn = 0;
1535 SET_FLAG_WRITE_CODEC_CRS( 6 );
1556 AUDIO_CODEC_CRs[6] |= 0x20;
1561 AUDIO_CODEC_CRs[6] &= 0xDF;
1566 SET_FLAG_WRITE_CODEC_CRS( 6 );
1585 return ( AUDIO_Mute == 1 );
1607 AUDIO_Volume -= dB / 2;
1608 if ( AUDIO_Volume < AUDIO_MIN_ATTENUATION )
1609 AUDIO_Volume = AUDIO_MIN_ATTENUATION;
1612 AUDIO_Set_Volume( );
1634 AUDIO_Volume += ( dB / 2 );
1635 if ( AUDIO_Volume > 15 )
1639 AUDIO_Set_Volume( );
1661 if ( register_to_read < 22 )
1664 AUDIO_I2C_ReadMultByte( register_to_read, 1, &val );
1666 AUDIO_CODEC_CRs[register_to_read] = val;
1691 if ( register_to_write < 22 )
1694 AUDIO_CODEC_CRs[register_to_write] = data_to_write;
1696 SET_FLAG_WRITE_CODEC_CRS( register_to_write );
1723 if ( size > LOCAL_BUFFER_SIZE )
1724 size = LOCAL_BUFFER_SIZE;
1726 Audio_buffer_local_size = size;