void init(){ GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC VIC_Init(); // GLCD init GLCD_Init (NULL, NULL); // Disable Hardware cursor GLCD_Cursor_Dis(0); // Touched indication LED USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; __enable_interrupt(); // Enable GLCD GLCD_Ctrl (TRUE); }
/** * This function will initial LPC17xx board. */ void rt_hw_board_init() { /* NVIC Configuration */ #define NVIC_VTOR_MASK 0x3FFFFF80 #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x10000000 */ SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x00000000 */ SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK); #endif /* init systick */ SysTick_Config( SystemCoreClock/RT_TICK_PER_SECOND - 1); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1<<__NVIC_PRIO_BITS) - 1); rt_hw_uart_init(); rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #if LPC_EXT_SDRAM == 1 { SDRAM_Init(); } #endif }
void Init_Cpu(void) { __set_PSP((uint32_t)msp_top); __set_PRIMASK(1); __set_FAULTMASK(1); __set_CONTROL(0); #if (CN_CPU_OPTIONAL_FPU == 1) pg_scb_reg->CPACR = (3UL << 20)|(3UL << 22); //使能FPU pg_scb_reg->FPCCR = (1UL << 31); //关闭lazy stacking #endif switch(pg_scb_reg->CPUID) { // case cn_revision_r0p1://todo // break; //好像没什么要做的 } extern void WDT_Disable(void); WDT_Disable(); //关狗 extern void SysClockInit(void); SysClockInit(); extern void SDRAM_Init(void); SDRAM_Init(); extern void Cache_Init(void); Cache_Init(); Load_Preload(); }
int main(void) { GUI_MEMDEV_Handle hMem0,hMem1; SysTick_Config(180000); SDRAM_Init(); LCD_Config(); GUI_Init(); GUI_SetFont(&GUI_Font32B_ASCII); GUI_SetBkColor(GUI_BLUE); GUI_SetColor(GUI_YELLOW); GUI_Clear(); // GUI_DispStringAt("blacklight",0,100); // GUIDEMO_Main(); hMem0 = GUI_MEMDEV_CreateFixed(0,0,100,50,GUI_MEMDEV_NOTRANS,GUI_MEMDEV_APILIST_32,GUI_COLOR_CONV_888); hMem1 = GUI_MEMDEV_CreateFixed(0,0,100,50,GUI_MEMDEV_NOTRANS,GUI_MEMDEV_APILIST_32,GUI_COLOR_CONV_888); GUI_MEMDEV_Select(hMem0); GUI_Clear(); GUI_DispString("Text"); GUI_MEMDEV_CopyToLCDAt(hMem0,0,0); while(1) { GUI_MEMDEV_Select(hMem1); GUI_MEMDEV_DrawPerspectiveX(hMem0,0,0,50,50-50*i/100,100-100*i/100,25*i/100); GUI_MEMDEV_CopyToLCDAt(hMem1,i,50+i); GUI_Delay(10); GUI_MEMDEV_Select(hMem1); GUI_Clear(); GUI_MEMDEV_CopyToLCDAt(hMem1,i,50+i); i+=1; if(i>100) { i=0; } } while(1); }
void configSDRAM(void) { SDRAM_Init(); #if 0 int qsource[16]; int qdest[16]; int i; for (i = 0; i < 16; i++) { qsource[i] = i; } // a small test... SDRAM_WriteBuffer(&qsource[0], 0, 16); for (i = 0; i < 16; i++) { qdest[i] = 0; } SDRAM_ReadBuffer(&qdest[0], 0, 16); #endif }
void MainTask_ColorKeying(void) { uint32_t lastMiliseconds = 0; LCD_Init(); SDRAM_Init(); while(!tamperPushed) { LCD_ReSetColorKeying(); LTDC_DitherCmd(ENABLE); DrawText((uint8_t*)" Color Keying OFF"); DMA2D_CopySTLogo(LOGO_OFFSET); LCD_BackgroundLayerInit(); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } LCD_SetColorKeying(0xFFFFFF); DrawText((uint8_t*)" Color Keying ON"); DMA2D_CopySTLogo(LOGO_OFFSET); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } LTDC_CLUTCmd(LTDC_Layer1, DISABLE); LTDC_CLUTCmd(LTDC_Layer2, DISABLE); LCD_ReSetColorKeying(); LTDC_ReloadConfig(LTDC_IMReload); } }
int main(void) { pInt8U pBuffer; Int32U Size,TranSize; int i=0,j; int k=0; int cnt=0; int tempcnt=0; int concurCnt = 0; Flo64 curP, curQ; int meanCalc=1,displayIntro=1; AlgoPowers_t PowerLines[3]; AlgoPowers_t prevPLines; AlgoPowers_t curPLines; int LearnNewMean = 1; int learning =1; int recognized=0; int plugOut = 0; Flo64 cInterval = 5000; int debug = 0; // int deviceCnt[3] = {0}; //AlgoLine_t TestLine; // pAlgoLine_t pTestLine=&TestLine; AlgoDevice_t tmpDev; // AlgoDevice_t devProfiles[3]={0}; AlgoDevice_t devProfiles[3]; int devNum=0; bool addDevice = 1; Int32S devLamps[3]; #if CDC_DEVICE_SUPPORT_LINE_CODING > 0 CDC_LineCoding_t CDC_LineCoding; UartLineCoding_t UartLineCoding; #endif // CDC_DEVICE_SUPPORT_LINE_CODING > 0 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // GUI init START ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // initialize touch parametres Int32U cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2; ToushRes_t XY_Touch; Boolean Touch = FALSE; GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC ---interrupt VIC_Init(); // GLCD init GLCD_Init (NULL, NULL); GLCD_Cursor_Dis(0); GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U)); GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32); GLCD_Move_Cursor(cursor_x, cursor_y); GLCD_Cursor_En(0); // Init touch screen TouchScrInit(); // Touched indication LED USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; // Init UART 0 UartInit(UART_0,0,NORM); __enable_interrupt(); GLCD_Ctrl (TRUE); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // GUI init END ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* devProfiles[0].dP= 101366.22; //blow dryer devProfiles[0].dQ =51765.90; devProfiles[1].dP= 35957.14; //light bulb devProfiles[1].dQ = 9045.64; */ // GLCD_print("Device char %f %f\r\n",devProfiles[devNum].dP, devProfiles[devNum].dQ ); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update the baud rate UartLineCoding.dwDTERate = 115200; // Update the stop bits number UartLineCoding.bStopBitsFormat = UART_ONE_STOP_BIT; // Update the parity type UartLineCoding.bParityType = UART_NO_PARITY; // Update the word width UartLineCoding.bDataBits = (UartWordWidth_t)(3); //Description: Init UART Baud rate, Word width, Stop bits, Parity type UartSetLineCoding(UART_0,UartLineCoding); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //calculate the no load powerlines //calcMeanRange(&prevPLines); // GLCD_print("P %f %f\n\r",prevPLines.P.CiHigh, prevPLines.P.CiLow); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// for(i=0; i<3; i++){ devProfiles[i].dP=0; devProfiles[i].dQ=0; devLamps[i]=0; } // initialize gui //gui_monitoringScreen(devProfiles,devLamps); gui_mainScreen(); GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); GLCD_SetWindow(0,0,319,239); GLCD_TextSetPos(0,0); //calculate the no load powerlines calcMeanRange(&prevPLines); while(1) { /////////////////////////////////////////////////////////////////////////////// GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); GLCD_SetWindow(0,0,319,239); GLCD_TextSetPos(0,0); ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// //algo START ///////////////////////////////////////////////////////////////////////////////// if(dataReady){ dataReady=0; GLCD_print("%s\r\n",dataArray); // GLCD_print("reach reach!!!\r\n"); //convert the incoming data to floats dataConversion(dataArray, dataP, dataQ, dataT, cnt); //keep track of devices GLCD_print("Device zero:%d one:%d two:%d\r",devLamps[0], devLamps[1],devLamps[2]); concurCnt=0; //detect a step change. if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){ tempcnt=(int) fmod(cnt+4,45); while(cnt != tempcnt){ if(dataReady){ dataConversion(dataArray, dataP, dataQ, dataT, cnt); if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){ concurCnt++; } cnt++; dataReady=0; if(cnt>=45){ cnt=0; } } } if(concurCnt>=3){ //calculate new powerlines calcMeanRange(&curPLines); tmpDev.dP = curPLines.P.mean - prevPLines.P.mean; tmpDev.dQ = curPLines.Q.mean - prevPLines.Q.mean; GLCD_print("test dev dP is %f\r\n",tmpDev.dP); GLCD_print("test dev dQ is %f\r\n",tmpDev.dQ); //in learning phase if(screen==1){ // GLCD_print("we can now add DEVICES!!!\r\n"); if(devNum==3){ GLCD_print("Can't learn anymore devices\r\n"); learning=0; } else{ if(tmpDev.dP>0 && tmpDev.dQ>0){ GLCD_print("add device or not?\r\n"); if(addDevice){ devProfiles[devNum].dP = tmpDev.dP; devProfiles[devNum].dQ = tmpDev.dQ; GLCD_print("new profile %d p:%f q:%f\r\n",devNum, tmpDev.dP,tmpDev.dQ); devNum++; } } else{ GLCD_print("device is unplugged\r\n"); //DO THE CHECK // determineDevice(devProfiles,tmpDev,&devNum,devLamps); //gui_monitoringScreen(devProfiles,devLamps); } } } //in user phase else if (screen==0){ if(devNum==0){ GLCD_print("No devices on file. Please enter learning mode"); } else{ //check aganst known devices for(k=0;k<3;k++){ GLCD_print("devProfile %d p:%f q:%f\r\n",k, devProfiles[k].dP, devProfiles[k].dQ); //if plugging out, the deltas will be negative if(tmpDev.dP<0 && tmpDev.dQ<0){ plugOut=1; tmpDev.dP = fabs(tmpDev.dP); tmpDev.dQ = fabs(tmpDev.dQ); } if(withinRange(tmpDev,devProfiles[k],cInterval)){ if(plugOut){ GLCD_print("device %d unplugged!\r\n",k); plugOut=0; devLamps[k]=0; } else{ GLCD_print("device %d plugged in!\r\n",k); devLamps[k]=1; } gui_monitoringScreen(devProfiles,devLamps); break; } } } // end of if(devNum>0) } // end user phase prevPLines = curPLines; GLCD_print("prevPlines %f, %f\r",prevPLines.P,prevPLines.Q); } // end of (concurCnt>=3) } // end of detectStepChange() cnt++; //dataReady=0; if(cnt >= 45){ cnt=0; } } // end of dataReady ///////////////////////////////////////////////////////////////////////////////// // End of Algo ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // GUI start ///////////////////////////////////////////////////////////////////////////////// if(TouchGet(&XY_Touch)) { cursor_x = XY_Touch.X; cursor_y = XY_Touch.Y; GLCD_Move_Cursor(cursor_x, cursor_y); if (FALSE == Touch) { Touch = TRUE; USB_H_LINK_LED_FCLR = USB_H_LINK_LED_MASK; } } // check the need to swtich screen else if(Touch) { switch(screen) { case 0: // 0 = Monitoring screen // Touch logic if(modeButtonState) { if (cursor_x <= 80 && cursor_y >= 190) { gui_toggleMode(devProfiles,devLamps); break; } } if(settingsButtonState) { if (cursor_x >= 239 && cursor_y >= 190) { gui_settingsScreen(); break; } } // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 1: // 1 = Learning screen // Touch logic if(modeButtonState) { if (cursor_x <= 80 && cursor_y >= 190) // mode { gui_toggleMode(devProfiles,devLamps); break; } } if(addDeviceButtonState) { // add device button placement (80,70,240,120) if (cursor_x >= 80 && cursor_y >= 70 && cursor_x <= 240 && cursor_y <= 120) { addDevice = 1; //gui_addDeviceScreen(); break; } } // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 2: // 2 = Devices screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 3: // 3: Webserver screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 4: // 4: Inormation Screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 5: // 5: Settings Screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 9: // 9: Main Screen // Monitor Button if (cursor_x >= 59 && cursor_y >= 64 && cursor_x <= 119 && cursor_y <= 124) { gui_monitoringScreen(devProfiles,devLamps); break; } // Learn Button else if (cursor_x >= 129 && cursor_y >= 64 && cursor_x <= 189 && cursor_y <= 124) { gui_learningScreen(); break; } // Devices Button else if (cursor_x >= 199 && cursor_y >= 64 && cursor_x <= 259 && cursor_y <= 124) { gui_devicesScreen(); break; } // Server Button else if (cursor_x >= 59 && cursor_y >= 134 && cursor_x <= 119 && cursor_y <= 194) { gui_serverScreen(); break; } // Info Button else if (cursor_x >= 129 && cursor_y >= 134 && cursor_x <= 189 && cursor_y <= 194) { gui_infoScreen(); break; } // Settings Button else if (cursor_x >= 199 && cursor_y >= 134 && cursor_x <= 259 && cursor_y <= 194) { gui_settingsScreen(); break; } break; } USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; Touch = FALSE; } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// } }
LCDTFTConf::LCDTFTConf() { CurrentFrameBuffer = LCD_FRAME_BUFFER; CurrentLayer = LCD_BACKGROUND_LAYER; LTDC_InitTypeDef LTDC_InitStruct; /* Configure the LCD Control pins ------------------------------------------*/ LCD_CtrlLinesConfig(); LCD_ChipSelect(DISABLE); LCD_ChipSelect(ENABLE); /* Configure the LCD_SPI interface -----------------------------------------*/ LCD_SPIConfig(); /* Power on the LCD --------------------------------------------------------*/ LCD_PowerOn(); /* Enable the LTDC Clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE); /* Enable the DMA2D Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE); /* Configure the LCD Control pins */ LCD_AF_GPIOConfig(); /* Configure the FMC Parallel interface : SDRAM is used as Frame Buffer for LCD */ SDRAM_Init(); /* LTDC Configuration *********************************************************/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL; /* Initialize the vertical synchronization polarity as active low */ LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL; /* Initialize the data enable polarity as active low */ LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL; /* Initialize the pixel clock polarity as input pixel clock */ LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC; /* Configure R,G,B component values for LCD background color */ LTDC_InitStruct.LTDC_BackgroundRedValue = 0; LTDC_InitStruct.LTDC_BackgroundGreenValue = 0; LTDC_InitStruct.LTDC_BackgroundBlueValue = 0; /* Configure PLLSAI prescalers for LCD */ /* Enable Pixel Clock */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/4 = 48 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 48/8 = 6 Mhz */ RCC_PLLSAIConfig(192, 7, 4); RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8); /* Enable PLLSAI Clock */ RCC_PLLSAICmd(ENABLE); /* Wait for PLLSAI activation */ while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET); /* Timing configuration */ /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = 9; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = 1; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = 29; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = 3; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = 269; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = 323; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = 279; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = 327; LTDC_Init(<DC_InitStruct); LCD_LayerInit(); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); }
static void LCD_Config(void) { LTDC_InitTypeDef LTDC_InitStruct; LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Configure NCS in Output Push-Pull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure the LCD Control pins ------------------------------------------*/ LCD_CtrlLinesConfig(); LCD_ChipSelect(DISABLE); LCD_ChipSelect(ENABLE); /* Configure the LCD_SPI interface -----------------------------------------*/ LCD_SPIConfig(); /* Power on the LCD --------------------------------------------------------*/ LCD_PowerOn(); /* Enable the LTDC Clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE); /* Enable the DMA2D Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE); /* Configure the LCD Control pins */ LCD_AF_GPIOConfig(); /* Configure the FMC Parallel interface : SDRAM is used as Frame Buffer for LCD */ SDRAM_Init(); /* Enable Pixel Clock --------------------------------------------------------*/ /* Configure PLLSAI prescalers for LCD */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */ RCC_PLLSAIConfig(192, 7, 3); RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8); /* Enable PLLSAI Clock */ RCC_PLLSAICmd(ENABLE); /* Wait for PLLSAI activation */ while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET) { } /* LTDC Initialization -------------------------------------------------------*/ /* Initialize the horizontal synchronization polarity as active low*/ LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL; /* Initialize the vertical synchronization polarity as active low */ LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL; /* Initialize the data enable polarity as active low */ LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL; /* Initialize the pixel clock polarity as input pixel clock */ LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC; /* Timing configuration */ /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = 9; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = 1; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = 29; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = 3; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = 269; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = 323; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = 279; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = 327; LTDC_Init(<DC_InitStruct); /* Configure R,G,B component values for LCD background color */ LTDC_InitStruct.LTDC_BackgroundRedValue = 0; LTDC_InitStruct.LTDC_BackgroundGreenValue = 0; LTDC_InitStruct.LTDC_BackgroundBlueValue = 0; LTDC_Init(<DC_InitStruct); /* LTDC initialization end ---------------------------------------------------*/ /* Layer1 Configuration ------------------------------------------------------*/ /* Windowing configuration */ /* In this case all the active display area is used to display a picture then : Horizontal start = horizontal synchronization + Horizontal back porch = 30 Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1 Vertical start = vertical synchronization + vertical back porch = 4 Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */ LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1); LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; LTDC_Layer_InitStruct.LTDC_VerticalStop = (320 + 4 - 1); /* Pixel Format configuration*/ LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; /* Alpha constant (255 totally opaque) */ LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; /* Configure blending factors */ LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; /* Default Color configuration (configure A,R,G,B component values) */ LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0; /* Input Address configuration */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (uint32_t)&RGB565_240x320; /* the length of one line of pixels in bytes + 3 then : Line Lenth = Active high width x number of bytes per pixel + 3 Active high width = 240 number of bytes per pixel = 2 (pixel_format : RGB565) */ LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 2) + 3); /* the pitch is the increment from the start of one line of pixels to the start of the next line in bytes, then : Pitch = Active high width x number of bytes per pixel */ LTDC_Layer_InitStruct.LTDC_CFBPitch = (240 * 2); /* configure the number of lines */ LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320; LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct); LTDC_DitherCmd(ENABLE); }
/* * Application entry point. */ int main(void) { Thread *shelltp = NULL; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Shell manager initialization. */ shellInit(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Initialise SDRAM, board.h has already configured GPIO correctly (except that ST example uses 50MHz not 100MHz?) */ SDRAM_Init(); sdram_bulk_erase(); /* * Activates the LCD-related drivers. */ spiStart(&SPID5, &spi_cfg5); ili9341Start(&ILI9341D1, &ili9341_cfg); initialize_lcd(); ltdcStart(<DCD1, <dc_cfg); /* * Activates the DMA2D-related drivers. */ dma2dStart(&DMA2DD1, &dma2d_cfg); dma2d_test(); /* * Creating the blinker threads. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 10, Thread1, NULL); chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO + 10, Thread2, NULL); /* * Normal main() thread activity, in this demo it just performs * a shell respawn upon its termination. */ while (TRUE) { if (!shelltp) { if (SDU1.config->usbp->state == USB_ACTIVE) { /* Spawns a new shell.*/ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); } } else { /* If the previous shell exited.*/ if (chThdTerminated(shelltp)) { /* Recovers memory of the previous shell.*/ chThdRelease(shelltp); shelltp = NULL; } } chThdSleepMilliseconds(500); } }
void MainTask_ColorFormat(void) { uint32_t lastMiliseconds = 0; LCD_Init(); SDRAM_Init(); /* LTDC configuration reload */ LTDC_ReloadConfig(LTDC_IMReload); while(!tamperPushed) { DMA2D_CopyPicture(DMA2D_RGB888); LTDC_DitherCmd(ENABLE); DrawText((uint8_t*)" RGB888 Dither"); LCD_RGB888LayerInit(); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } LTDC_DitherCmd(DISABLE); DrawText((uint8_t*)" RGB888"); LCD_RGB888LayerInit(); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } LTDC_DitherCmd(ENABLE); DMA2D_CopyPicture(DMA2D_RGB565); DrawText((uint8_t*)" RGB565"); LCD_RGB565LayerInit(); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } DrawText((uint8_t*)" L8 CLUT"); LCD_OptCLUTLayerInit(); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } DrawText((uint8_t*)" L8 CLUT Dither"); LCD_DithCLUTLayerInit(); /* wait 2s */ lastMiliseconds = getMiliseconds(); while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000)) { } LTDC_CLUTCmd(LTDC_Layer1, DISABLE); LTDC_CLUTCmd(LTDC_Layer2, DISABLE); LCD_ReSetColorKeying(); LTDC_ReloadConfig(LTDC_IMReload); } }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int main(void) { typedef Int32U ram_unit; // int cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2; // unsigned long int deltaT; static float freq_aveg; int LCD_updatecount; LCD_updatecount = 0; //From uip start unsigned int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; //From uip end /*** COMPARE FIX POINT 523235 ***/ /*** COMPARE FIX POINT 523235 ***/ GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC VIC_Init(); // GLCD init // GLCD_Init (IarLogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well // GLCD_Init (LogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well GLCD_Init (what_is_a_blissPic.pPicStream, NULL); GLCD_Cursor_Dis(0); //From uip // GLCD_Cursor_Dis(0); // GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U)); /*** COMPARE FIX POINT 534252 ***/ /*** COMPARE FIX POINT 534252 ***/ GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32); //From uip // GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_64); // GLCD_Move_Cursor(cursor_x, cursor_y); // GLCD_Cursor_En(0); //From uip start // Sys timer init 1/100 sec tick clock_init(2); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); //From uip end // Init USB Link LED USB_D_LINK_LED_SEL = 0; // GPIO USB_D_LINK_LED_FSET = USB_D_LINK_LED_MASK; USB_D_LINK_LED_FDIR |= USB_D_LINK_LED_MASK; USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; /*-----------------------------------------------------------------*/ // Init AD0[3] for current meassurement PINSEL1_bit.P0_26 = 1; // Assign P26 to AD0[3], page 180 PINMODE1_bit.P0_26 = 2; // //Neither pull-up or pull-down // PCONP_bit.PCAD = 1; // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN // Other initial parameters are already set // AD0CR_bit.SEL = 8; // select Ch3 [1111] current_amp = 0; /*-----------------------------------------------------------------*/ // Init the DAC converter //Clock: In the PCLK_SEL0 register (Table 4�), select PCLK_DAC //PCLKSEL0_bit.PCLK_DAC = 3UL;// **HAS Desided for values yet!** // '11' at bit 23 and 22 (which is CCLK/8) //or use 0x3 for 3UL instead //Pins: Select the DAC pin and pin mode in registers PINSEL1 and PINMODE1 (see Section 9�. //PINSEL1 |= (2UL<<20); // PINSEL1_bit.P0_26 = 1; //?? //PINSEL1_bit.P0_26 = 2UL; //"PINMODE registers control the on-chip pull-up/pull-down resistor feature for all GPIO ports." - page 178 //PINMODE1 |= ________; // See table 128 for values. Write to bit 21:20 //PINMODE1_bit.P0_26 = 2UL; //P0.26MODE = 2UL; //Neither pull-up or pull-down /* ------------------------------------------------------------------*/ // Init ADC converter // Power the ADC converter PINSEL1_bit.P0_25 = 1; // Assign Pin 25 to ADO[2] PINMODE1_bit.P0_25 = 1; // Neither pull-up or pull-dow PCONP_bit.PCAD = 1; // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN AD0CR_bit.PDN = 1; // A/D converter is operational AD0CR_bit.START = 0; // Conversion not started AD0CR_bit.BURST = 0; // disable burst // AD0CR_bit.SEL = 4; // select Ch2 [11] // Select number of clocks for each conversion AD0CR_bit.CLKS = 0; // [000] 11 clocks / 10 bits AD0CR_bit.CLKDIV = SYS_GetFpclk(ADC_PCLK_OFFSET)/ 10000; // 4500000; // Should be equal to 10K samplingrate ADINTEN_bit.ADGINTEN = 1; // Global A/D channels enabled by ADINTEN 7:0 // Since only on channel is used at the moment the global flag is enabled VIC_SetVectoredIRQ(AD0IntrHandler,1,VIC_AD0); // Set the interrupt call VICINTENABLE |= 1UL << VIC_AD0; // Setting parameters for the low-pass filter DACR_previous = 0; // Initialize DACR_temp which is y(i-1) deltaT = 1.0/TIMER0_TICK_PER_SEC; // Set the sample rate // Calculate the R*C for cut-off frequency of the low pass filter alpha = deltaT/(1./(2.*3.1416*100.) + deltaT); // Cut-off = 100 Hz done = 0; // Channel stage /* ------------------------------------------------------------------*/ // Setting the port to P0[11] and P0[19] PINSEL1_bit.P0_19 = 0; // GPIO to P0[19] PINSEL0_bit.P0_11 = 0; // GPIO to P0[11] PINMODE1_bit.P0_19 = 2; // Pin has neither pull up or down PINMODE0_bit.P0_11 = 2; // Pin has neither pull up or down FIO0DIR_bit.P0_19 = 1; FIO0CLR = (1UL<<19); FIO0DIR_bit.P0_11 = 1; FIO0CLR = (1UL<<11); FIO0PIN_bit.P0_19 = 1; FIO0PIN_bit.P0_11 = 1; /* ------------------------------------------------------------------*/ // Enable TIM0 clocks PCONP_bit.PCTIM0 = 1; // enable clock // Init Time0 T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 0; T0MR0 = SYS_GetFpclk(TIMER0_PCLK_OFFSET)/(TIMER0_TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable __enable_interrupt(); GLCD_Ctrl (TRUE); #if 0 SDRAM_Test(); #endif /* // SMB380_Init(); SMB380_GetID(&Smb380Id, &Smb380Ver); SMB380_Data_t XYZT; */ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ //From uip start GLCD_SetFont(&Terminal_18_24_12,0x000000,0x000cd4ff); GLCD_SetWindow(85,10,255,33); GLCD_TextSetPos(0,0); GLCD_print("\f Room Station"); //From uip start /*** COMPARE FIX POINT 458923 ***/ /*** COMPARE FIX POINT 458923 ***/ // GLCD_SetWindow(5,200,319,239); // GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); // Initialize the ethernet device driver do { GLCD_TextSetPos(0,0); } while(!tapdev_init()); GLCD_TextSetPos(0,0); // uIP web server // Initialize the uIP TCP/IP stack. uip_init(); uip_ipaddr(ipaddr, 192,168,0,100); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // Initialize the HTTP server. httpd_init(); /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** WHILE LOOP START ***/ while(1) { /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ uip_len = tapdev_read(uip_buf); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { tapdev_send(uip_buf,uip_len); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } #define AVERAGECOUNT 100000 if(LCD_updatecount <= AVERAGECOUNT) { ++LCD_updatecount; freq_aveg += freq; } else { freq_aveg = freq_aveg/AVERAGECOUNT; updateFreqHistory(freq_aveg); //Must be kept together with freq calculation! GLCD_SetWindow(20,55,150,80); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f Hz %3.3f", freq_aveg); freq_aveg = 0; GLCD_SetWindow(20,90,150,115); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f V %3.3f", sqrtf(vol_rms_result)); updateVoltageHistory(sqrtf(vol_rms_result)); GLCD_SetWindow(20,125,150,150); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f uA %3.3f", sqrtf(current_amp)); GLCD_SetWindow(20,160,150,185); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f uP %3.3f", sqrtf(vol_rms_result)*sqrtf(current_amp)); LCD_updatecount = 0; } }//while(1) loop }//main function