//------------------------------------------------------------------- // Musicplayer_Init //------------------------------------------------------------------- void vInitMusicplayer (void) { // Initialize Audio interface EVAL_AUDIO_SetAudioInterface( AUDIO_INTERFACE_I2S ); EVAL_AUDIO_Init( OUTPUT_DEVICE_BOTH, 60, I2S_AudioFreq_48k ); // Volume 80%, 44Khz samplefrequentie Audio_MAL_Play((uint32_t)AUDIO_SAMPLE, sizeof(AUDIO_SAMPLE) ); // Speel stilte, waarover de toongenerator de toon speelt EVAL_AUDIO_PauseResume(AUDIO_RESUME); // Start met spelen // Motor init motor_init(); // User button init GPIO_InitTypeDef GPIO_InitStructure; #if 0 EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; #endif /* Enable the BUTTON Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /* Configure Button pin as input */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA, &GPIO_InitStructure); #if 0 /* Connect Button EXTI Line to Button GPIO Pin */ SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0); /* Configure Button EXTI line */ EXTI_InitStructure.EXTI_Line = EXTI_Line2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set Button EXTI Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); #endif // Motor test // Dit staat hier omdat een van de andere init's niet werkt zonder evdk //motor_init(); //setLedBlink(); //{int i; for(i=0;i<1000000;i++);} // Small delay for the motor control board to accept the previous command //// Motor ייn rondje //SMC_step(1600,1,1000,1); }
int WavePlayerInit(uint32_t AudioFreq) { /* Initialize I2S interface */ EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, 60, AudioFreq ); return 0; }
/** * @brief Initializes the wave player * @param AudioFreq: Audio sampling frequency * @retval None */ int WavePlayerInit(uint32_t AudioFreq) { /* MEMS Accelerometre configure to manage PAUSE, RESUME and Controle Volume operation */ Mems_Config(); /* EXTI configue to detect interrupts on Z axis click and on Y axis high event */ EXTILine_Config(); /* Initialize I2S interface */ EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, volume, AudioFreq ); return 0; }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Initialize LEDS */ /* Red Led On: buffer overflow */ STM_EVAL_LEDInit(LED3); /* Green Led On: fdmdv+codec2 enabled */ STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); /* Blue Led On: start of application */ STM_EVAL_LEDInit(LED6); STM_EVAL_LEDOn(LED6); /* transparent mode switcher */ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); if(Transparent_mode) STM_EVAL_LEDOff(LED4); else STM_EVAL_LEDOn(LED4); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_USART2Init(&USART_InitStructure); // turn off buffers, so IO occurs immediately setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); /* Output a message on Hyperterminal using printf function */ printf("\r\nFloating-Point Based Codec2 encoder for Cortex-M4F\r\n"); /* Configure TIM4 Peripheral to manage LEDs lighting */ unsigned int idx = 0; Time_Rec_Base=0; int i, buffId; codec2_initialize_all(SPEAKER_FREQ == 48000 ? 1 : 0); /* fill output fifo */ fifoBufferFullness=0; fifoBufferCurrent=0; Switch = 0; /* modulate silence once for padding if happens */ memset(padBuffer, 0x00, (320*(SPEAKER_FREQ/MIC_FREQ)*2)*sizeof(short)); memset(fifoBuffer, 0x00, MODULATOR_QUEUE_SIZE * (SPEAKER_FREQ/MIC_FREQ)*320*2*sizeof(short)); //codec2_modulate((short *) padBuffer, (short *) padBuffer, Transparent_mode); /* Initialize I2S interface */ EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ //EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, 0, SPEAKER_FREQ); EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, 0, SPEAKER_FREQ); EVAL_AUDIO_PauseResume(AUDIO_PAUSE); Audio_MAL_Play((uint32_t) padBuffer, (320*(SPEAKER_FREQ/MIC_FREQ))*2*sizeof(short)); EVAL_AUDIO_PauseResume(AUDIO_RESUME); /* Start the record */ MicListenerInit(32000,16, 1); MicListenerStart(RecBuf_8Khz, PCM_OUT_SIZE); /* GLOBAL SCHEDULER * DO NOT USE LOOPS INSIDE IT! * */ while(1) { /* we have frame from mike */ if(Data_Status == 0) continue; /* Switch the buffers*/ if (Switch ==1) { pAudioRecBuf_8Khz = RecBuf_8Khz; writebuffer = RecBuf1_8Khz; Switch = 0; } else { pAudioRecBuf_8Khz = RecBuf1_8Khz; writebuffer = RecBuf_8Khz; Switch = 1; } #ifdef USE_ST_FILTER //Downsampling 16Khz => 8Khz (this is input for codec, it sampled with 8KHz) for(i=0; i<320; i++) writebuffer[i] = writebuffer[2*i]; #endif //TODO: modulate, even if no data from mike! if(fifoBufferFullness < MODULATOR_QUEUE_SIZE-1) { /* get the next free buffer */ buffId = fifoBufferCurrent + fifoBufferFullness; if(buffId >= MODULATOR_QUEUE_SIZE) buffId -= MODULATOR_QUEUE_SIZE; assert(buffId >= 0 && buffId < MODULATOR_QUEUE_SIZE); codec2_modulate((short *) writebuffer, (short *) fifoBuffer[buffId], Transparent_mode); fifoBufferFullness++; if(idx % 32 == 0) printf("."); if(idx % (32*32) == 0) printf("\r\n"); /* this is hack to remove loud noise at startup */ if(volume_set==1) { STM_EVAL_LEDOff(LED3); EVAL_AUDIO_VolumeCtl(90); volume_set=2; } } else { STM_EVAL_LEDToggle(LED3); printf("x"); if(idx % (32) == 0) printf("\r\n"); } idx++; Data_Status = 0; } EVAL_AUDIO_Mute(AUDIO_MUTE_ON); EVAL_AUDIO_Stop(CODEC_PDWN_HW); MicListenerStop(); //float samples_time = idx*samplesPerFrame/((float) WAVE_Format.NumChannels*WAVE_Format.SampleRate); #if 0 float samples_time = idx*mod->samplesPerFrame/((float) 1*MIC_FREQ); float cpu_time = Time_Rec_Base/((float ) 100); printf("\r\n%8.3f s audio file encoded in %8.3f s\r\n", (double) samples_time, (double) cpu_time); #endif while(1) { STM_EVAL_LEDToggle(LED5); Delay(10); } }
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; } }