uint8_t AudioStartPlayFile ( char * sFilename ) { FRESULT res; uint8_t rc = 0; // find the extension of the filename char * extension = strrchr ( sFilename, '.' ); // no or wrong extension -> exit if ( NULL == extension ) return ( 1 ); audioContext.format = FILEFORMAT_UNKNOWN; if ( !strnicmp ( extension, ".wav", 4 ) ) audioContext.format = FILEFORMAT_WAVE; else if ( !strnicmp ( extension, ".wav", 4 ) ) audioContext.format = FILEFORMAT_MP3; else if ( !strnicmp ( extension, ".flac", 4 ) ) audioContext.format = FILEFORMAT_FLAC; else if ( !strnicmp ( extension, ".fla", 4 ) ) audioContext.format = FILEFORMAT_FLAC; else if ( !strnicmp ( extension, ".ape", 4 ) ) audioContext.format = FILEFORMAT_APE; if ( FILEFORMAT_UNKNOWN == audioContext.format ) return ( 2 ); // open file, on error exit res = f_open ( &audioContext.fil, sFilename, FA_OPEN_EXISTING | FA_READ ); // open existing file in read mode if ( res ) return ( 2 ); audioContext.fileIsOpen = 1; rc = AudioProvideSamplesFromFile ( ); if ( 0 == rc ) EVAL_AUDIO_Play ( audioContext.dmaBuffer, audioContext.sampleBufferSize ); return ( rc ); };
//MAIN int main(void) { printf("Hello World!\r\n"); //confirm dingus program has started //INITS SystemInit(); gpioInit(); timInit(); TIM_ITConfig(TIM6, TIM_IT_Update, DISABLE); //DISABLE INTERRUPTS FOR AUDIO INITS EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, 100, SAMPLE_FREQ); //should default to headphones, full volume, 48kHz EVAL_AUDIO_Play((uint16_t*) audio_buffer, BUFF); //add once there's audio to hear TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE); //ENABLE INTERRUPTS AFTER printf("Ready!\n"); //print when everythin' is done voiceInit(&voice, 1.f, 1.f); //YEAH BABY while(1) { printf("\nP\nI\nZ\nZ\nA\n"); //confirm in loop with pizza spelling contest delay(80000); } }
int main(void) { RCC_ClocksTypeDef RCC_Clocks; /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); RCC_GetClocksFreq(&RCC_Clocks);//test EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 86, I2S_AudioFreq_16k);//init speaker (optional) USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &AUDIO_cb, &USR_cb); simple_rec_start();//initialise MIC and start capture data from MIC EVAL_AUDIO_Play((uint16_t*)(&audiodata[0]),MIC_FILTER_RESULT_LENGTH*2*2);//play data to speaker (optional) while(1) { asm("nop"); } }
/** * @brief Calculates the remaining file size and new position of the pointer. * @param None * @retval None */ void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size) { /* Calculate the remaining audio data in the file and the new size for the DMA transfer. If the Audio files size is less than the DMA max data transfer size, so there is no calculation to be done, just restart from the beginning of the file ... */ /* Check if the end of file has been reached */ #ifdef AUDIO_MAL_MODE_NORMAL /* Replay from the beginning */ EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUDIO_START_ADDRESS), (AUDIO_FILE_SIZE - AUDIO_START_ADDRESS)); #endif /* AUDIO_MAL_MODE_NORMAL */ }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Initialize LEDs, Key Button, LCD available on STM324xG-EVAL board ******************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the Push buttons */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Key button for Pause/Resume */ STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO); /* Key button for Volume High */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); /* Key button for Volume Low */ /* Initialize the LCD */ STM324xG_LCD_Init(); /* Display message on STM324xG-EVAL LCD *************************************/ /* Clear the LCD */ LCD_Clear(LCD_COLOR_BLUE); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); LCD_DisplayStringLine(Line2, MESSAGE3); /* Turn on leds available on STM324xG-EVAL **********************************/ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, volume, I2S_AudioFreq_48k) == 0) { LCD_DisplayStringLine(Line3, "===================="); LCD_DisplayStringLine(Line4, "Key : Play/Pause "); LCD_DisplayStringLine(Line5, "Tamper: Vol+/Headph"); LCD_DisplayStringLine(Line6, "Wakeup: Vol-/Spkr "); LCD_DisplayStringLine(Line7, "===================="); LCD_DisplayStringLine(Line8, " AUDIO CODEC OK "); } else { LCD_DisplayStringLine(Line4, " AUDIO CODEC FAIL "); LCD_DisplayStringLine(Line5, " Try to reset board "); } /* Normal mode description: Start playing the audio file (using DMA stream) . Using this mode, the application can run other tasks in parallel since the DMA is handling the Audio Transfer instead of the CPU. The only task remaining for the CPU will be the management of the DMA Transfer Complete interrupt or the Half Transfer Complete interrupt in order to load again the buffer and to calculate the remaining data. Circular mode description: Start playing the file from a circular buffer, once the DMA is enabled it always run. User has to fill periodically the buffer with the audio data using Transfer complete and/or half transfer complete interrupts callbacks (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()... In this case the audio data file is smaller than the DMA max buffer size 65535 so there is no need to load buffer continuously or manage the transfer complete or Half transfer interrupts callbacks. */ EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS), (AUDIO_FILE_SZE - AUIDO_START_ADDRESS)); /* Display the state on the screen */ LCD_DisplayStringLine(Line8, " PLAYING "); /* Infinite loop */ while (1) { /* Check on the Pause/Resume button */ if (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET) { /* wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET); EVAL_AUDIO_PauseResume(cmd); if (cmd == AUDIO_PAUSE) { /* Display the current state of the player */ LCD_DisplayStringLine(Line8, " PAUSED "); /* Next time Resume command should be processed */ cmd = AUDIO_RESUME; /* Push buttons will be used to switch between Speaker and Headphone modes */ SpHpSwitch = 1; } else { /* Display the current state of the player */ LCD_DisplayStringLine(Line8, " PLAYING "); /* Next time Pause command should be processed */ cmd = AUDIO_PAUSE; /* Push buttons will be used to control volume level */ SpHpSwitch = 0; } } /* Check on the Volume high button */ if (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET) { /* Check if the current state is paused (push buttons are used for volume control or for speaker/headphone mode switching) */ if (SpHpSwitch) { /* Set output to Speaker */ Codec_SwitchOutput(OUTPUT_DEVICE_SPEAKER); /* Display the current state of the player */ LCD_DisplayStringLine(Line9, " SPEAKER "); } else { /* wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET); /* Decrease volume by 5% */ if (volume > 5) volume -= 5; else volume = 0; /* Apply the new volume to the codec */ EVAL_AUDIO_VolumeCtl(volume); LCD_DisplayStringLine(Line9, " VOL: - "); } } /* Check on the Volume high button */ if (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET) { /* Check if the current state is paused (push buttons are used for volume control or for speaker/headphone mode switching) */ if (SpHpSwitch) { /* Set output to Headphone */ Codec_SwitchOutput(OUTPUT_DEVICE_HEADPHONE); /* Display the current state of the player */ LCD_DisplayStringLine(Line9, " HEADPHONE "); } else { /* wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET); /* Increase volume by 5% */ if (volume < 95) volume += 5; else volume = 100; /* Apply the new volume to the codec */ EVAL_AUDIO_VolumeCtl(volume); LCD_DisplayStringLine(Line9, " VOL: + "); } } /* Toggle LD4 */ STM_EVAL_LEDToggle(LED3); /* Insert 50 ms delay */ Delay(5); /* Toggle LD2 */ STM_EVAL_LEDToggle(LED2); /* Insert 50 ms delay */ Delay(5); } }
/** * @brief Play wave file from internal Flash * @param None * @retval None */ uint32_t AudioFlashPlay(uint16_t* pBuffer, uint32_t FullSize, uint32_t StartAdd) { EVAL_AUDIO_Play((uint16_t*)pBuffer, (FullSize - StartAdd)); return 0; }
int Mp3Decode(const char* pszFile) { int nResult = 0; BYTE* pInData = g_Mp3InBuffer; UINT unInDataLeft = 0; FIL fIn; UINT bEof = FALSE; UINT bOutOfData = FALSE; MP3FrameInfo mp3FrameInfo; uint32_t unDmaBufMode = 0; g_pMp3DmaBufferPtr = g_pMp3DmaBuffer; g_pMp3DecoderThread = chThdSelf(); FRESULT errFS = f_open(&fIn, pszFile, FA_READ); if(errFS != FR_OK) { chprintf((BaseChannel*)&SD2, "Mp3Decode: Failed to open file \"%s\" for reading, err=%d\r\n", pszFile, errFS); return -1; } HMP3Decoder hMP3Decoder = MP3InitDecoder(); if(hMP3Decoder == NULL) { chprintf((BaseChannel*)&SD2, "Mp3Decode: Failed to initialize mp3 decoder engine\r\n"); return -2; } chprintf((BaseChannel*)&SD2, "Mp3Decode: Start decoding \"%s\"\r\n", pszFile); char szArtist[80]; char szTitle[80]; palSetPad(GPIOD, 12); // green LED Mp3ReadId3V2Tag(&fIn, szArtist, sizeof(szArtist), szTitle, sizeof(szTitle)); palClearPad(GPIOD, 12); // green LED if(szArtist[0] != 0 || szTitle[0] != 0) { chprintf((BaseChannel*)&SD2, "Mp3Decode: Now playing (ID3v2): %s - %s\r\n", szArtist, szTitle); } int nDecodeRes = ERR_MP3_NONE; UINT unFramesDecoded = 0; do { if(unInDataLeft < (2 * MAINBUF_SIZE) && (!bEof)) { UINT unRead = Mp3FillReadBuffer(pInData, unInDataLeft, &fIn); unInDataLeft += unRead; pInData = g_Mp3InBuffer; if(unRead == 0) { bEof = 1; } } // find start of next MP3 frame - assume EOF if no sync found int nOffset = MP3FindSyncWord(pInData, unInDataLeft); if(nOffset < 0) { bOutOfData = TRUE; break; } pInData += nOffset; unInDataLeft -= nOffset; // decode one MP3 frame - if offset < 0 then bytesLeft was less than a full frame nDecodeRes = MP3Decode(hMP3Decoder, &pInData, (int*)&unInDataLeft, (short*)g_pMp3OutBuffer, 0); switch(nDecodeRes) { case ERR_MP3_NONE: { MP3GetLastFrameInfo(hMP3Decoder, &mp3FrameInfo); if(unFramesDecoded == 0) { chprintf((BaseChannel*)&SD2, "Mp3Decode: %d Hz %d Bit %d Channels\r\n", mp3FrameInfo.samprate, mp3FrameInfo.bitsPerSample, mp3FrameInfo.nChans); if((mp3FrameInfo.samprate > 48000) || (mp3FrameInfo.bitsPerSample != 16) || (mp3FrameInfo.nChans != 2)) { chprintf((BaseChannel*)&SD2, "Mp3Decode: incompatible MP3 file.\r\n"); nResult = -5; break; } } if((unFramesDecoded) % 100 == 0) { chprintf((BaseChannel*)&SD2, "Mp3Decode: frame %u, bitrate=%d\r\n", unFramesDecoded, mp3FrameInfo.bitrate); } unFramesDecoded++; g_pMp3OutBufferPtr = g_pMp3OutBuffer; uint32_t unOutBufferAvail= mp3FrameInfo.outputSamps; while(unOutBufferAvail > 0) { // fill up the whole dma buffer uint32_t unDmaBufferSpace = 0; if(unDmaBufMode == 0) { // fill the whole buffer // dma buf ptr was reset to beginning of the buffer unDmaBufferSpace = g_pMp3DmaBuffer + MP3_DMA_BUFFER_SIZE - g_pMp3DmaBufferPtr; } else if(unDmaBufMode == 1) { // fill the first half of the buffer // dma buf ptr was reset to beginning of the buffer unDmaBufferSpace = g_pMp3DmaBuffer + (MP3_DMA_BUFFER_SIZE / 2) - g_pMp3DmaBufferPtr; } else { // fill the last half of the buffer // dma buf ptr was reset to middle of the buffer unDmaBufferSpace = g_pMp3DmaBuffer + MP3_DMA_BUFFER_SIZE - g_pMp3DmaBufferPtr; } uint32_t unCopy = unDmaBufferSpace > unOutBufferAvail ? unOutBufferAvail : unDmaBufferSpace; if(unCopy > 0) { memcpy(g_pMp3DmaBufferPtr, g_pMp3OutBufferPtr, unCopy * sizeof(uint16_t)); unOutBufferAvail -= unCopy; g_pMp3OutBufferPtr += unCopy; unDmaBufferSpace -= unCopy; g_pMp3DmaBufferPtr += unCopy; } if(unDmaBufferSpace == 0) { // dma buffer full // see if this was the first run if(unDmaBufMode == 0) { // on the first buffer fill up, // start the dma transfer if(EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 80, (uint32_t)mp3FrameInfo.samprate)) { chprintf((BaseChannel *) &SD2, "Mp3Decode: audio init failed\r\n"); nResult = -4; break; } EVAL_AUDIO_Play(g_pMp3DmaBuffer, MP3_DMA_BUFFER_SIZE * sizeof(uint16_t)); } // we must wait for the dma stream tx interrupt here eventmask_t em = chEvtWaitAny((eventmask_t)2 | 4 | 8); if(em & 8) { // stop requested chprintf((BaseChannel*)&SD2, "Mp3Decode: Stop requested\r\n"); nResult = 1; break; } if((em & 2) && (em & 4)) { chprintf((BaseChannel*)&SD2, "Mp3Decode: DMA out of sync (HT and TC both set)\r\n"); nResult = -3; break; } if(unDmaBufMode == 0 || unDmaBufMode == 2) { // the dma event we expect is "half transfer" (=2) if(em & 2) { // set up first half mode unDmaBufMode = 1; g_pMp3DmaBufferPtr = g_pMp3DmaBuffer; } else { chprintf((BaseChannel*)&SD2, "Mp3Decode: DMA out of sync (expected HT, got TC)\r\n"); nResult = -3; break; } } else { // the dma event we expect is "transfer complete" (=4) if(em & 4) { // set up last half mode unDmaBufMode = 2; g_pMp3DmaBufferPtr = g_pMp3DmaBuffer + (MP3_DMA_BUFFER_SIZE / 2); } else { chprintf((BaseChannel*)&SD2, "Mp3Decode: DMA out of sync (expected TC, got HT)\r\n"); nResult = -3; } } } } break; } case ERR_MP3_MAINDATA_UNDERFLOW: { // do nothing - next call to decode will provide more mainData break; } case ERR_MP3_FREE_BITRATE_SYNC: { break; } case ERR_MP3_INDATA_UNDERFLOW: { chprintf((BaseChannel*)&SD2, "Mp3Decode: Decoding error ERR_MP3_INDATA_UNDERFLOW\r\n"); bOutOfData = TRUE; break; } default: { chprintf((BaseChannel*)&SD2, "Mp3Decode: Decoding error %d\r\n", nDecodeRes); bOutOfData = TRUE; break; } } } while((!bOutOfData) && (nResult == 0)); chprintf((BaseChannel*)&SD2, "Mp3Decode: Finished decoding\r\n"); MP3FreeDecoder(hMP3Decoder); if(EVAL_AUDIO_Stop(CODEC_PDWN_HW)) { chprintf((BaseChannel*)&SD2, "Mp3Decode: Failed to stop audio\r\n"); } EVAL_AUDIO_DeInit(); f_close(&fIn); // this is the only legit way I know // to remvove still pending event flags // from the thread chEvtWaitOneTimeout(2, 50); chEvtWaitOneTimeout(4, 50); return nResult; }
int main(void) { int i; // General purpose variable uint8_t* pMIDI_buffer; // MIDI variables uint8_t nb_MIDI_bytes; uint8_t* pPARAMETERS_buffer; // PARAMETERS variables uint8_t nb_PARAMETERS_bytes; // Initializations // --------------- // Start peripherals LED_PUSH_Start(); // Start Discovery KIT LEDS and PUSH BUTTON peripherals FDTI_Start(); // Start the debug terminal (printf) pMIDI_buffer = MIDI_Start(); // Start the MIDI input interface (DMA) pPARAMETERS_buffer = PARAMETERS_Start(); // Empty the audio buffer and initialize sample pointer for (i=0; i<BUFF_LEN; i=i+2) { audiobuff[i] = (uint16_t)((int16_t) 0.0f); // Left Channel value audiobuff[i+1] = (uint16_t)((int16_t) 0.0f); // Right Channel Value } // Initialize Synth params.pitch = 220.0f; params.bend = 0.0f; params.detune = 0.0f; params.osc1_waveform = 0; params.osc2_waveform = 1; params.osc1_octave = 1.0f; params.osc2_octave = 0.0f; params.osc1_mix = 1.0f; params.osc2_mix = 0.0f; params.cutoff = 24.0f; params.reso = 1.0f; params.adsr1_attack = 0.1f; params.adsr1_decay = 0.1f; params.adsr1_sustain = 0.5f; params.adsr1_release = 0.1f; params.adsr2_attack = 0.1f; params.adsr2_decay = 0.1f; params.adsr2_sustain = 0.5f; params.adsr2_release = 0.1f; params.lfo1_frequency = 0.0f; params.lfo1_depth = 0.0f; params.lfo2_frequency = 0.0f; params.lfo2_depth = 0.0f; // Start Audio EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, VOL, SAMPLERATE); EVAL_AUDIO_Play((uint16_t*)audiobuff, BUFF_LEN); // Test Terminal printf("\n\n"); printf("Init terminated \n"); // Main Loop // --------- while(1) { // Test if MIDI bytes have arrived nb_MIDI_bytes = MIDI_GetNbNewBytes(pMIDI_buffer); // If yes, parse message if (nb_MIDI_bytes) { // printf("bytes arrived : %d\n", nb_MIDI_bytes); MIDI_parser(pMIDI_buffer, nb_MIDI_bytes); } nb_PARAMETERS_bytes = PARAMETERS_GetNbNewBytes(pPARAMETERS_buffer); // If yes, parse message if (nb_PARAMETERS_bytes) { // printf(" parameters bytes arrived : %d\n", nb_PARAMETERS_bytes); PARAMETERS_parser(pPARAMETERS_buffer, nb_PARAMETERS_bytes); } } }
void audio_init(void) { EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, VOL, SAMPLERATE); EVAL_AUDIO_Play((uint16_t*) audiobuff, BUFF_LEN); // start sound }
int main(void) { //uint8_t Rx1_Buffer[BUFFER_SIZE1]; volatile uint16_t NumDataRead = 0; volatile uint16_t symbol; uint8_t command_buffer[10]= {0xe2,0xeb,0x81,120,0xc6,0xaf,0x88,0xb0,0x00,0x10}; uint32_t xtal_value; /* 0: 0xe2 - 11100010 - System Reset 1: 0xeb - 11101011 - Set LCD BIAS ratio [b1:b0] 2: 0x81 - 10000001 - Set VBIAS potentiometer 3: 0x50 - 01010000 - VBIAS potentiometer value 4: 0xc6 - 11000110 - Set LCD Mapping Control [b2:b1] 5: 0xaf - 10101111 - Set display ENABLE [b0] 6: 0x89 - 10001001 - Set RAM adress Control [b2:b0] 7: 0xb0 - 10110000 - Set Page Adress [b3:b0] 8: 0x00 - 00000000 - Set Column Adress LSB [b3:b0] 9: 0x10 - 00010000 - Set Column Adress MSB [b3:b0] */ uint32_t decimal[8]; //uint8_t string0[]="Display Works Fine"; //uint8_t tune.tune_freq_vis[]="14000000"; /*Start Frequency*/ //uint8_t string2[]="FREQUENCY"; //uint8_t string3[]="HAM RADIO BAND"; uint8_t string4[]="20m USB 2800Hz x100";/*BAND MODE FILTER GAIN*/ //uint8_t string5[]="MODE SSB USB"; //uint8_t string6[]="GAIN 1000"; uint8_t string7[]="PRE:Off ATT:20 AGC:S"; uint8_t data_buffer[132]; uint8_t data_buffer1[132]; uint8_t data_buffer2[132]; uint8_t data_buffer3[132]; uint8_t si570_buf[11]; uint32_t bit_order; uint8_t current_pointer; uint8_t k, n, sp, lzs_flag, symb_width, enc1_pulse_ccw, enc1_pulse_cw,enc2_pulse_ccw, enc2_pulse_cw, show_it; uint8_t option_select, sub_option_select; uint8_t n1; uint8_t hs_div_code; uint32_t i,j/*,noise_filter_button*/; uint8_t display_menu; uint8_t offcet_x; extern menu_struct_t menu[MAX_MENU_QTY]; extern band_struct_t band_menu[MAX_BAND_QTY]; extern mode_struct_t mode_menu[MAX_MODE_QTY]; extern filter_struct_t filter_menu[MAX_FILTER_QTY]; extern gain_struct_t gain_menu; extern tune_struct_t tune; RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* SysTick end of count event each 10ms */ //if (FLASH_OB_GetRDP()!=SET) //{ // FLASH_OB_Unlock(); /*enable the FLASH option control register access*/ // FLASH_OB_RDPConfig(OB_RDP_Level_1); /*SET RDP=1*/ // FLASH_OB_Launch(); /*launch the Option Bytes programming process*/ // FLASH_OB_Lock(); /*disable the FLASH option control register*/ //} /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /* Initialize user button STM324xG-EVAL board *****************/ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); STM_EVAL_ControlInit(CODEC_RESET); BOARD_GPIO_Init(); /*encoder input init*/ /* Turn on LEDs available on STM324xG-EVAL **********************************/ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); STM_EVAL_ControlOn(CODEC_RESET); Delay (300); STM_EVAL_ControlOff(CODEC_RESET); xtal_value=(uint32_t)114197425;/*0x6cfd9c8*/ freq_code_old=0; NumDataRead = 1; /* Initialize the I2C EEPROM driver ----------------------------------------*/ sEE_Init(); /* Initialize the CODEC driver*/ EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 255, I2S_AudioFreq_48k); EVAL_AUDIO_Play(sound, 96); /*Continuous Beep from codec*/ Codec_WriteRegister(0x1E, 0xC0); Delay (100); LCD_Write_Command(0x70, command_buffer, 1); Delay (10); LCD_Write_Command(0x70, (command_buffer+1), 5); Delay (10); n=0xA1;/*100 Hz frame rate*/ LCD_Write_Command(0x70, &n, 1); bit_order=0x989680; /*1e+7 decimal*/ for (j=0; j<8; j++) /*filling array for decimal to binary conversion*/ { decimal[j]=bit_order; bit_order=bit_order/10; } /*Clear display*/ symbol=0x00; for (j=0; j<8; j++) { for (i=0; i<131; i++) { data_buffer[i]=symbol; } LCD_Write_Command(0x70, (command_buffer+6), 4); Delay (10); LCD_Write_Data(0x70, data_buffer, (uint32_t)132); command_buffer[7]++; Delay (10); } si570_buf[6]=0x10;/*freeze DCO reg 137*/ si570_buf[7]=0x00;/*unfreeze DCO reg 137*/ si570_buf[8]=0x40;/*status new dco reg 135*/ si570_buf[9]=0x20;/*freeze M bit reg 135*/ si570_buf[10]=0x00;/*unfreeze M bit reg 135*/ // command_buffer[7]=0xb3; // LCD_Write_Command(0x70, (command_buffer+6), 4); freq2=0; i=5; j=0; k=0; sp=0; display_menu=0; show_it=1; /*initial display*/ display_menu=1; current_menu=0; old_value=new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK; while (1) { new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK; if (new_value!=old_value) { current_pointer=1; enc1_old_value=old_value&ENCODER1_MASK; enc2_old_value=old_value&ENCODER2_MASK; enc1_new_value=new_value&ENCODER1_MASK; enc2_new_value=new_value&ENCODER2_MASK; if (enc2_new_value!=enc2_old_value) { current_pointer=0; if ((enc2_old_value&ENCODER2_A_MASK)!=((enc2_new_value<<1)&ENCODER2_A_MASK))/*==ENCODER2_MASK*/ { STM_EVAL_LEDToggle(LED3); enc2_pulse_ccw=0; enc2_pulse_cw++; } else { STM_EVAL_LEDToggle(LED6); enc2_pulse_cw=0; enc2_pulse_ccw++; } //old_value=new_value; if (enc2_pulse_cw==4) /*increment*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/ { menu[current_menu].menu_current_state++; if(menu[current_menu].menu_current_state>menu[current_menu].menu_states_qty-1) /*control if submenu<MAX_SUBMENU*/ { menu[current_menu].menu_current_state=0; } /*apply handler with action parameter*/ } else /*change menu*/ { current_menu++; if (current_menu>MAX_MENU_QTY-1) /*control if menu<MAX_MENU*/ { current_menu=0; } } enc2_pulse_cw=0; enc2_pulse_ccw=0; display_menu=1; if (current_menu==0) show_it=1; } else { if (enc2_pulse_ccw==4) /*decrement*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/ { menu[current_menu].menu_current_state--; if (menu[current_menu].menu_current_state<0) { menu[current_menu].menu_current_state=menu[current_menu].menu_states_qty-1; } /*apply handler with action parameter*/ } else /*change menu*/ { current_menu--;/*control if menu<MAX_MENU*/ if (current_menu<0) { current_menu=MAX_MENU_QTY-1; } } enc2_pulse_cw=0; enc2_pulse_ccw=0; display_menu=1; if (current_menu==0) show_it=1; } } } if (current_pointer==1) { if ((enc1_old_value&ENCODER1_A_MASK)!=((enc1_new_value<<1)&ENCODER1_A_MASK))/*==ENCODER1_MASK*/ { STM_EVAL_LEDToggle(LED5); enc1_pulse_ccw=0; enc1_pulse_cw++; } else { STM_EVAL_LEDToggle(LED4); enc1_pulse_cw=0; enc1_pulse_ccw++; } old_value=new_value; /*--------------------------------------------------*/ if (enc1_pulse_cw==4) /*increment*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) { for (j=1; j<8-i; j++) { tune.tune_freq_vis[i+j]=0x30; } enc1_pulse_cw=0; enc1_pulse_ccw=0; if ((tune.tune_freq_vis[i]&0x0f)==0x09) { tune.tune_freq_vis[i]=0; j=1; while ((tune.tune_freq_vis[i-j]&0x0f)==0x09) { tune.tune_freq_vis[i-j]=0; j++; } tune.tune_freq_vis[i-j]++; } else { tune.tune_freq_vis[i]++; } show_it=1; } else { enc1_pulse_cw=0; enc1_pulse_ccw=0; if (i==7) { i=0; } else { i++; } show_it=1; } } /*--------------------------------------------------*/ else { if (enc1_pulse_ccw==4) /*decrement*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) { for (j=1; j<8-i; j++) { tune.tune_freq_vis[i+j]=0x30; } enc1_pulse_cw=0; enc1_pulse_ccw=0; if ((tune.tune_freq_vis[i]&0x0f)==0x00) { tune.tune_freq_vis[i]=9; j=1; while ((tune.tune_freq_vis[i-j]&0x0f)==0x00) { tune.tune_freq_vis[i-j]=9; j++; } tune.tune_freq_vis[i-j]--; } else { tune.tune_freq_vis[i]--; } } else { enc1_pulse_cw=0; enc1_pulse_ccw=0; if (i==0) { i=7; } else { i--; } show_it=1; } } show_it=1; } } if (display_menu==1) /*build menu buffer*/ { display_menu=0; pp1=menu[current_menu].pFunc(MODIFY); for (j=0; j<MAX_MENU_QTY; j++) { k=0; offcet_x=menu[j].menu_x_pos; pp1=menu[j].pFunc(DISPLAY); if (j==current_menu) { data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; k++; while ((*pp1)!=0) { for (jj=0; jj<5; jj++) { symbol=symboltable[(*pp1)-0x20][jj]; data_buffer2[k+offcet_x]=~(symbol<<2);/*Fill Upper buffer*/ data_buffer3[k+offcet_x]=~((symbol>>6)|0xF8); k++; } data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; k++; pp1++; } data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; } else { data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; k++; while ((*pp1)!=0) { for (jj=0; jj<5; jj++) { symbol=symboltable[(*pp1)-0x20][jj]; data_buffer2[k+offcet_x]=(uint8_t)symbol<<2;/*Fill Upper buffer*/ data_buffer3[k+offcet_x]=(uint8_t)symbol>>6; k++; } data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; k++; pp1++; } data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f429_439xx.s) before to branch to application main. */ /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Initialize LEDs mounted on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* KEY button for Volume High */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* WAKEUP button for Volume Low */ STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO); /* Configure PLLSAI */ PLLSAI_Config(); /* Initialize the Audio codec and all related peripherals (SAI, I2C, IOs...) */ if (EVAL_AUDIO_Init(OUTPUT_DEVICE_BOTH, uwVolume, SAI_AudioFreq_48k) == 0) { /* AUDIO CODEC OK */ STM_EVAL_LEDOn(LED1); } else { /* AUDIO CODEC FAIL */ STM_EVAL_LEDOn(LED2); } /* Insert 50 ms delay */ Delay(5); /* Play audio sample stored in internal FLASH */ EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUDIO_START_ADDRESS), (AUDIO_FILE_SIZE - AUDIO_START_ADDRESS)); /* Infinite loop */ while(1) { /* Check on the Volume high button */ if (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET) { /* Wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET); /* Increase volume by 5% */ if (uwVolume < 95) { uwVolume += 5; } else { uwVolume = 100; } /* Apply the new volume to the codec */ EVAL_AUDIO_VolumeCtl(uwVolume); } /* Check on the Volume high button */ if (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET) { /* Wait to avoid rebound */ while (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET); /* Decrease volume by 5% */ if (uwVolume > 5) { uwVolume -= 5; } else { uwVolume = 0; } /* Apply the new volume to the codec */ EVAL_AUDIO_VolumeCtl(uwVolume); } } }