void LCD_Send_A_String(char *StringOfCharacters) { int count=0 ;//to count how much char on the line (it should be 16 char only) while(*StringOfCharacters > 0) { count++; LCD_Send_A_Character(*StringOfCharacters++); if (count == 16 ) // go to the second line { LCD_GotoXY(1,0); //line 1 position zero } else if (count == 32 || count==33) // clear screen and show again { LCD_clear_screen(); LCD_GotoXY(0,0); //line 0 position zero count = 0 ; } } }
void LCD_Pixel(unsigned char x, unsigned char y, int color) { LCD_GotoXY(x,y); SendLcd(LCDCommand,RAMWR); LCD_CS(0); // SendLcd(LCDData, (unsigned char)((color>>4)& 0xff) ); // SendLcd(LCDData, (unsigned char)((color&0xf)<<4)|0x00 ); SendLcd_color( (unsigned char)((color>>4)& 0xff) ); SendLcd_color( (unsigned char)((color&0xf)<<4)|0x00 ); LCD_CS(1); SendLcd(LCDCommand, NOP); }
void disp_addition_op() {char str_disp_addtion_op[20]; sprintf(str_disp_addtion_op,"%d%s",result,str_inputs); LCD_GotoXY(0,0); LCD_Send_A_String(str_disp_addtion_op); }
int mjpegPause(int id) { int seekBytes, media_data_totalBytes, diff; int ret = RET_PLAY_NORM, curX, prevX = 0; int duration = media.video.duration / media.video.timeScale; int swHoldCnt, media_data_denom; int time = duration * (float)((float)*pv_src.videoStcoCount / (float)video_stco.numEntry); char timeStr[20]; LCD_SetRegion(0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1); pcf_typedef pcf; pcf.dst_gram_addr = (uint32_t)frame_buffer; pcf.pixelFormat = PCF_PIXEL_FORMAT_RGB565; pcf.size = 12; pcf.color = WHITE; pcf.colorShadow = GRAY; pcf.alphaSoftBlending = 1; pcf.enableShadow = 1; pcf_font.metrics.hSpacing = 2; drawBuff = (drawBuff_typedef*)cursorRAM; char s[10]; SPRINTF(s, "%d/%d", id, fat.fileCnt - 1); LCD_GotoXY(5, MUSIC_INFO_POS_Y + 1); LCDPutString(s, &pcf); mjpeg_touch.resynch = 1; mjpegTouch(id, *pv_src.videoStcoCount); mjpeg_touch.resynch = 0; LCDPutIcon(4, 100, 12, 12, pause_icon_12x12, pause_icon_12x12_alpha); LCDPutIcon(UI_POS_X, UI_POS_Y, 120, 14, seekbar_120x14, seekbar_120x14_alpha); drawBuff->navigation_loop.x = 140; drawBuff->navigation_loop.y = UI_POS_Y; drawBuff->navigation_loop.width = 18; drawBuff->navigation_loop.height = 14; LCDStoreBgImgToBuff(drawBuff->navigation_loop.x, drawBuff->navigation_loop.y, \ drawBuff->navigation_loop.width, drawBuff->navigation_loop.height, drawBuff->navigation_loop.p); Update_Navigation_Loop_Icon(drawBuff, music_control.b.navigation_loop_mode); drawBuff->posision.width = 12; drawBuff->posision.height = 12; drawBuff->posision.x = UI_POS_X + 1; drawBuff->posision.y = UI_POS_Y + 1; prevX = UI_POS_X + 1; LCDStoreBgImgToBuff(prevX, drawBuff->posision.y, \ drawBuff->posision.width, drawBuff->posision.height, drawBuff->posision.p); DRAW_SEEK_CIRCLE((float)time / (float)duration , seek_circle_12x12); DRAW_MOV_TIME_STR(); DRAW_MOV_REMAIN_TIME_STR(); LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_BLOCKING); int pause_flag = 0; if(LCDStatusStruct.waitExitKey == PLAY_PAUSE || LCDStatusStruct.waitExitKey == PLAY_LOOP_MODE) { pause_flag = 1; LCDStatusStruct.waitExitKey = 1; } extern int8_t vol; while(1){ switch(LCDStatusStruct.waitExitKey) { case 0: return RET_PLAY_STOP; break; case VOL_UP: vol = ++vol < 6 ? vol : 6; // wm8731_left_headphone_volume_set(121 + vol); LCDStatusStruct.waitExitKey = 1; break; case VOL_DOWN: vol = --vol > -121 ? vol : -121; // wm8731_left_headphone_volume_set(121 + vol); LCDStatusStruct.waitExitKey = 1; break; case PLAY_PAUSE: ret = 1; LCDStatusStruct.waitExitKey = 1; goto PAUSE_EXIT; break; case PLAY_LOOP_MODE: Update_Navigation_Loop_Icon(drawBuff, music_control.b.navigation_loop_mode = ++music_control.b.navigation_loop_mode % 5); LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_NOBLOCKING); LCDStatusStruct.waitExitKey = 1; break; case PLAY_SW_HOLD_LEFT: media_data_totalBytes = video_stco.numEntry; seekBytes = *pv_src.videoStcoCount; media_data_denom = 100; swHoldCnt = SW_HOLD_CNT_VAL; while(HAL_GPIO_ReadPin(SW_PUSH_LEFT_PORT, SW_PUSH_LEFT_PIN) == GPIO_PIN_RESET){ diff = seekBytes - media_data_totalBytes / media_data_denom; if(diff < 0){ seekBytes = 2; } else { seekBytes += -media_data_totalBytes / media_data_denom; } mjpegTouch(id, seekBytes); HAL_Delay(20); media_data_denom = 100 / (++swHoldCnt / SW_HOLD_CNT_VAL); } ret = 1; LCDStatusStruct.waitExitKey = 1; if(!pause_flag){ goto PAUSE_EXIT; } break; case PLAY_SW_HOLD_RIGHT: media_data_totalBytes = video_stco.numEntry; seekBytes = *pv_src.videoStcoCount; media_data_denom = 100; swHoldCnt = SW_HOLD_CNT_VAL; while(HAL_GPIO_ReadPin(SW_PUSH_RIGHT_PORT, SW_PUSH_RIGHT_PIN) == GPIO_PIN_RESET){ if((seekBytes + media_data_totalBytes / media_data_denom) > media_data_totalBytes){ continue; } seekBytes += media_data_totalBytes / media_data_denom; mjpegTouch(id, seekBytes); HAL_Delay(20); media_data_denom = 100 / (++swHoldCnt / SW_HOLD_CNT_VAL); } ret = 1; LCDStatusStruct.waitExitKey = 1; if(!pause_flag){ goto PAUSE_EXIT; } break; case PLAY_NEXT: ret = RET_PLAY_NEXT; return ret; case PLAY_PREV: ret = RET_PLAY_PREV; return ret; break; default: break; } HAL_Delay(1); } PAUSE_EXIT: if(media.video.width != LCD_WIDTH || media.video.height != LCD_HEIGHT){ LCD_DrawSquare(0, 0, LCD_WIDTH, media.video.startPosY, BLACK); LCD_DrawSquare(0, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK); LCD_DrawSquare(media.video.startPosX + media.video.width, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK); LCD_DrawSquare(0, media.video.startPosY + media.video.height, LCD_WIDTH, LCD_HEIGHT - (media.video.startPosY + media.video.height), BLACK); } LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_BLOCKING); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// while((SpiLcdHandle.State != HAL_SPI_STATE_READY)){}; memset(dac_intr.buff, '\0', dac_intr.bufferSize); LCD_SetRegion(media.video.startPosX, media.video.startPosY, media.video.startPosX + media.video.width - 1, media.video.startPosY + media.video.height - 1); HAL_I2S_DMAResume(&haudio_i2s); DMA_SOUND_IT_ENABLE; return ret; }
USE MENU #ifdef USE_MENU void mjpegTouch(int id, uint32_t pointed_chunk) // ? ? ? ? ? ? ? ? ? ? Touch pen interrupt processing { uint32_t firstChunk, prevChunk, prevSamples, samples, totalSamples = 0, jFrameOffset; MY_FILE fp_stsc, fp_stsz, fp_stco, fp_frame, fp_frame_cp; uint8_t atombuf[12]; raw_video_typedef raw; memcpy((void*)&fp_stsc, (void*)&video_stsc.fp, sizeof(MY_FILE)); memcpy((void*)&fp_stsz, (void*)&video_stsz.fp, sizeof(MY_FILE)); memcpy((void*)&fp_stco, (void*)&video_stco.fp, sizeof(MY_FILE)); //DANI memcpy((void*)&fp_frame, (void*)&fp_global, sizeof(MY_FILE)); // debug.printf("\r\npointed_chunk:%d video_stco.numEntry:%d", pointed_chunk, video_stco.numEntry); prevChunk = getSampleSize(atombuf, 12, &fp_stsc); // firstChunk samplesPerChunk sampleDescriptionID ????firstChunk?prevChunk? prevSamples = getAtomSize(&atombuf[4]); // ????samplesPerChunk?prevSamples? firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ????firstChunk while(1){ if(prevChunk <= pointed_chunk && firstChunk >= pointed_chunk){ samples = (firstChunk - pointed_chunk) * prevSamples; totalSamples += (pointed_chunk - prevChunk) * prevSamples; break; } samples = (firstChunk - prevChunk) * prevSamples; totalSamples += samples; prevChunk = firstChunk; // ???firstChunk?prevChunk? prevSamples = getSampleSize(atombuf, 8, &fp_stsc); // samplesPerChunk sampleDescriptionID firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ??firstChunk } my_fseek(&fp_stco, (pointed_chunk - 1) * 4, SEEK_CUR); jFrameOffset = getSampleSize(atombuf, 4, &fp_stco); memcpy((void*)&fp_stco, (void*)&video_stco.fp, sizeof(MY_FILE)); my_fseek(&fp_stco, (pointed_chunk - 1) * 4, SEEK_CUR); // my_fseek(&fp_frame, jFrameOffset, SEEK_SET); memcpy((void*)&fp_frame_cp, (void*)&fp_frame, sizeof(MY_FILE)); //DANI my_fseek(&fp_frame, raw.frame_size, SEEK_CUR); *pv_src.firstChunk = firstChunk; *pv_src.prevChunk = prevChunk; *pv_src.prevSamples = prevSamples; *pv_src.samples = samples; *pv_src.totalSamples = totalSamples; *pv_src.videoStcoCount = pointed_chunk + 1; memcpy((void*)pv_src.fp_video_stsc, (void*)&fp_stsc, sizeof(MY_FILE)); memcpy((void*)pv_src.fp_video_stsz, (void*)&fp_stsz, sizeof(MY_FILE)); memcpy((void*)pv_src.fp_video_stco, (void*)&fp_stco, sizeof(MY_FILE)); memcpy((void*)pv_src.fp_frame, (void*)&fp_frame, sizeof(MY_FILE)); // Sound memcpy((void*)&fp_stsc, (void*)&sound_stsc.fp, sizeof(MY_FILE)); memcpy((void*)&fp_stsz, (void*)&sound_stsz.fp, sizeof(MY_FILE)); memcpy((void*)&fp_stco, (void*)&sound_stco.fp, sizeof(MY_FILE)); //DANI memcpy((void*)&fp_frame, (void*)&fp_global, sizeof(MY_FILE)); // debug.printf("\r\npointed_chunk:%d video_stco.numEntry:%d", pointed_chunk, video_stco.numEntry); prevChunk = getSampleSize(atombuf, 12, &fp_stsc); // firstChunk samplesPerChunk sampleDescriptionID ????firstChunk?prevChunk? prevSamples = getAtomSize(&atombuf[4]); // ????samplesPerChunk?prevSamples? firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ????firstChunk totalSamples = 0; while(1){ if(prevChunk <= pointed_chunk && firstChunk >= pointed_chunk){ samples = (firstChunk - pointed_chunk) * prevSamples; totalSamples += (pointed_chunk - prevChunk) * prevSamples; break; } samples = (firstChunk - prevChunk) * prevSamples; totalSamples += samples; prevChunk = firstChunk; // ???firstChunk?prevChunk? prevSamples = getSampleSize(atombuf, 8, &fp_stsc); // samplesPerChunk sampleDescriptionID firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ??firstChunk } my_fseek(&fp_stco, (pointed_chunk - 1) * 4, SEEK_CUR); *ps_src.firstChunk = firstChunk; *ps_src.prevChunk = prevChunk; *ps_src.prevSamples = prevSamples; *ps_src.samples = samples; *ps_src.soundStcoCount = pointed_chunk; memcpy((void*)ps_src.fp_sound_stsc, (void*)&fp_stsc, sizeof(MY_FILE)); memcpy((void*)ps_src.fp_sound_stsz, (void*)&fp_stsz, sizeof(MY_FILE)); memcpy((void*)ps_src.fp_sound_stco, (void*)&fp_stco, sizeof(MY_FILE)); if(mjpeg_touch.resynch){ return; } /* //DANI if(media.video.width != LCD_WIDTH || media.video.height != LCD_HEIGHT){ LCD_DrawSquare(0, 0, LCD_WIDTH, media.video.startPosY, BLACK); LCD_DrawSquare(0, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK); LCD_DrawSquare(media.video.startPosX + media.video.width, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK); LCD_DrawSquare(0, media.video.startPosY + media.video.height, LCD_WIDTH, LCD_HEIGHT - (media.video.startPosY + media.video.height), BLACK); } */ int v; for(v = 0;v < media.video.height;v++) { //(&frame_buffer[media.video.startPosX + v * LCD_WIDTH + media.video.startPosY * LCD_WIDTH], 2, media.video.width, &fp_frame_cp); // read_file (FIL *file, uint8_t *buf, uint32_t sizeofbuf) } int curX, prevX, duration = (int)((float)media.video.duration / (float)media.video.timeScale + 0.5f); int time = duration * (float)*pv_src.videoStcoCount / (float)video_stco.numEntry; char timeStr[20]; LCDPutIcon(4, 100, 12, 12, pause_icon_12x12, pause_icon_12x12_alpha); LCDPutIcon(UI_POS_X, UI_POS_Y, 120, 14, seekbar_120x14, seekbar_120x14_alpha); drawBuff->navigation_loop.x = 140; drawBuff->navigation_loop.y = UI_POS_Y; drawBuff->navigation_loop.width = 18; drawBuff->navigation_loop.height = 14; LCDStoreBgImgToBuff(drawBuff->navigation_loop.x, drawBuff->navigation_loop.y, \ drawBuff->navigation_loop.width, drawBuff->navigation_loop.height, drawBuff->navigation_loop.p); Update_Navigation_Loop_Icon(drawBuff, music_control.b.navigation_loop_mode); drawBuff->posision.width = 12; drawBuff->posision.height = 12; drawBuff->posision.x = UI_POS_X + 1; drawBuff->posision.y = UI_POS_Y + 1; prevX = UI_POS_X + 1; LCDStoreBgImgToBuff(prevX, drawBuff->posision.y, \ drawBuff->posision.width, drawBuff->posision.height, drawBuff->posision.p); DRAW_SEEK_CIRCLE((float)time / (float)duration , seek_active_circle_12x12); pcf_typedef pcf; pcf.dst_gram_addr = (uint32_t)frame_buffer; pcf.pixelFormat = PCF_PIXEL_FORMAT_RGB565; pcf.size = 12; pcf.color = WHITE; pcf.colorShadow = GRAY; pcf.alphaSoftBlending = 1; pcf.enableShadow = 1; pcf_font.metrics.hSpacing = 2; char s[10]; SPRINTF(s, "%d/%d", id, fat.fileCnt - 1); LCD_GotoXY(5, MUSIC_INFO_POS_Y + 1); LCDPutString(s, &pcf); DRAW_MOV_TIME_STR(); DRAW_MOV_REMAIN_TIME_STR(); LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_BLOCKING); }
void Nokia_lcd::cLCD_GotoXY(unsigned char x, unsigned char y){ LCD_GotoXY(x, y); }
int PlaySound(int id) { int i, duration, curX, prevX, media_data_totalBytes; volatile int ret = RET_PLAY_NORM; uint32_t *dst32p; uint8_t *outbuf; char str[10]; WAVEFormatStruct wav; WAVEFormatHeaderStruct wavHeader; WAVEFormatChunkStruct wavChunk; MY_FILE *infile; char timeStr[20]; if(!(infile = my_fopen(id))){ ret = RET_PLAY_STOP; goto EXIT_WAV; } my_fread(&wavHeader, 1, sizeof(WAVEFormatHeaderStruct), infile); debug.printf("\r\n\n[WAVE]"); if(strncmp(wavHeader.headStrRIFF, "RIFF", 4) != 0){ debug.printf("\r\nNot contain RIFF chunk"); ret = RET_PLAY_STOP; goto EXIT_WAV; } debug.printf("\r\nFile Size:%d", wavHeader.fileSize); if(strncmp(wavHeader.headStrWAVE, "WAVE", 4) != 0){ debug.printf("\r\nThis is not WAVE file."); ret = RET_PLAY_STOP; goto EXIT_WAV; } int restBytes = wavHeader.fileSize; while(1){ // loop until format chunk is found my_fread(&wavChunk, 1, sizeof(WAVEFormatChunkStruct), infile); if(strncmp(wavChunk.chunkfmt, "fmt ", 4) == 0){ break; } memset(str, '\0', sizeof(str)); debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt))); debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize); restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct); if(restBytes <= 0){ debug.printf("\r\nNot Found Format Chunk."); ret = RET_PLAY_STOP; goto EXIT_WAV; } my_fseek(infile, wavChunk.chunkSize, SEEK_CUR); } my_fread(&wav, 1, sizeof(WAVEFormatStruct), infile); my_fseek(infile, wavChunk.chunkSize - sizeof(WAVEFormatStruct), SEEK_CUR); restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct); while(1){ // loop until data chunk is found my_fread(&wavChunk, 1, sizeof(WAVEFormatChunkStruct), infile); if(strncmp(wavChunk.chunkfmt, "data", 4) == 0){ break; } memset(str, '\0', sizeof(str)); debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt))); debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize); restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct); if(restBytes <= 0){ debug.printf("\r\nNot Found Format Chunk."); ret = RET_PLAY_STOP; goto EXIT_WAV; } my_fseek(infile, wavChunk.chunkSize, SEEK_CUR); } memset(str, '\0', sizeof(str)); debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt))); debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize); debug.printf("\r\n\nformatID:%d", wav.formatID); debug.printf("\r\nNum Channel:%d", wav.numChannel); debug.printf("\r\nSampling Rate:%d", wav.sampleRate); debug.printf("\r\nData Speed:%d", wav.dataSpeed); debug.printf("\r\nBlock Size:%d", wav.blockSize); debug.printf("\r\nBit Per Sample:%d", wav.bitPerSample); debug.printf("\r\nBytes Wave Data:%d", wavChunk.chunkSize); if(wav.formatID != 1){ debug.printf("\r\nthis media is not a PCM."); ret = RET_PLAY_STOP; goto EXIT_WAV; } int seekBytesSyncWord = infile->seekBytes; media_data_totalBytes = wavChunk.chunkSize; duration = wavChunk.chunkSize / wav.dataSpeed; setStrSec(timeStr, duration); debug.printf("\r\nplay time:%s", timeStr); LCDFadeIn(2, music_bgimg_160x128); memcpy((void*)frame_buffer, (void*)music_bgimg_160x128, sizeof(frame_buffer)); short xTag = 5, yTag = 50, disp_limit = 150, strLen; pcf_typedef pcf; pcf.dst_gram_addr = (uint32_t)frame_buffer; pcf.pixelFormat = PCF_PIXEL_FORMAT_RGB565; pcf.size = 16; pcf.color = WHITE; pcf.colorShadow = BLACK; pcf.alphaSoftBlending = 1; pcf.enableShadow = 1; pcf_font.metrics.hSpacing = 2; uint8_t strNameLFN[80]; if(setLFNname(strNameLFN, id, LFN_WITHOUT_EXTENSION, sizeof(strNameLFN))){ strLen = LCDGetStringLFNPixelLength(strNameLFN, pcf.size); if((xTag + strLen) < LCD_WIDTH){ disp_limit = LCD_WIDTH - 16; } else { disp_limit = LCD_WIDTH - 16; yTag -= 12; } LCD_GotoXY(xTag, yTag); LCDPutStringLFN(xTag, disp_limit - 1, 3, strNameLFN, &pcf); } else { char strNameSFN[9]; memset(strNameSFN, '\0', sizeof(strNameSFN)); setSFNname(strNameSFN, id); LCD_GotoXY(xTag, yTag); LCDPutString(strNameSFN, &pcf); } if(settings_group.music_conf.b.musicinfo && (wav.bitPerSample > 16) && (wav.sampleRate >= 48000)){ pcf.size = 12; pcf.color = RED; pcf.colorShadow = WHITE; LCD_GotoXY(5, 19); LCDPutString("Hi-Res ", &pcf); LCDPutString(wav.bitPerSample == 24 ? "24bit" : "32bit", &pcf); } pcf.size = 12; pcf.color = WHITE; pcf.colorShadow = GRAY; char s[30], s1[10]; SPRINTF(s, "%d/%d", id, fat.fileCnt - 1); LCD_GotoXY(5, MUSIC_INFO_POS_Y + 1); if(settings_group.music_conf.b.musicinfo){ strcat(s, " WAV "); SPRINTF(s1, "%.1fM ", (float)(wav.numChannel * wav.bitPerSample * wav.sampleRate) / 1000000.0f); strcat(s, s1); SPRINTF(s1, "%dkHz", (int)(wav.sampleRate / 1000)); strcat(s, s1); } LCDPutString(s, &pcf); uint16_t SOUND_BUFFER[12288]; uint8_t SOUND_BUFFER_24BIT[((sizeof(SOUND_BUFFER) / 2) / sizeof(uint32_t)) * 3]; dac_intr.fp = infile; dac_intr.buff = (uint8_t*)SOUND_BUFFER; if(wav.bitPerSample <= 16){ dac_intr.bufferSize = sizeof(SOUND_BUFFER) / 2; } else { dac_intr.bufferSize = sizeof(SOUND_BUFFER); } volatile int SoundDMAHalfBlocks = (dac_intr.bufferSize / (sizeof(int16_t) * 2)) / 2; FFT_Struct_Typedef FFT; FFT.bitPerSample = wav.bitPerSample; FFT.ifftFlag = 0; FFT.bitReverseFlag = 1; FFT.length = 16; FFT.samples = (dac_intr.bufferSize / (sizeof(int16_t) * wav.numChannel) / 2) / 1; if(wav.numChannel < 2){ FFT.samples >>= 1; }
/** * @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_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ SystemInit(); /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADCConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 2; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel0 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 2, ADC_SampleTime_55Cycles5); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* To achieve GPIO toggling maximum frequency, the following sequence is mandatory. You can monitor PD0 or PD2 on the scope to measure the output signal. If you need to fine tune this frequency, you can add more GPIO set/reset cycles to minimize more the infinite loop timing. This code needs to be compiled with high speed optimization option. */ /*Init LCD*/ LCD_Init(); while (1) { /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); sprintf(LCD_Buffer,"ADC1=%d ",ADCConvertedValue[0]); LCD_GotoXY(0,0); LCD_PutStr(LCD_Buffer); sprintf(LCD_Buffer,"ADC2=%d ",ADCConvertedValue[1]); LCD_GotoXY(0,1); LCD_PutStr(LCD_Buffer); delay_ms(1000); } }
int main(void) { init(); uart_init(); MSG("INIT"); // cli(); LCD_init(); LCD_contrast(0xff); LCD_PrintStr(STR_HELLO); LCD_GotoXY(1, 1); //LCD_PrintStr(STR_WORLD); //LCD_PrintInt((uint8_t)'А'); // en A - 65 => 65+128 = 193 // rus A - 144 // LCD_PrintInt(a); // // LCD_PrintChar(' '); for (uint8_t i = 0; i < 16;i++) { LCD_PrintChar(40+i); } uint8_t i = 0; while (true) { keyboardCheck(); bool update = false; if (key_click_flag[KEY_UP]) { if (i < 2) { i++; update = true; } } if (key_click_flag[KEY_DOWN]) { if (i != 0) { i--; update = true; } } if (update) { LCD_Clear(); switch(i) { case 0: LCD_PrintStr(STR_START); break; case 1: LCD_PrintStr(STR_PROFILE); break; case 2: LCD_PrintStr(STR_SETTINGS); break; } LCD_GotoXY(0, 1); LCD_PrintInt(i); _delay_ms(500); } // LCD_GotoXY(0, 1); // LCD_PrintInt(key_counter[KEY_UP]); // LCD_PrintChar(' '); // LCD_PrintInt(key_counter[KEY_DOWN]); // LCD_PrintChar(' '); // LCD_PrintInt(key_click_flag[KEY_UP]); _delay_us(1000); } }