/*------------------------------------------------------------------------------ -- This file is a part of the libuc, microcontroler library -- Copyright (C) 2011, Alexis Jeandet -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org -------------------------------------------------------------------------------*/ #include "bsp.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../../common/bsp_gpio.h" uint32_t OSC0 =12000000; uint32_t INTOSC =16000000; uint32_t RTCOSC =32768; uint32_t currentCpuFreq=0; extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; gpio_t TickLed = LED1; LCD_IF_t lcdIF0={ .init = &bsp_FSMC_init, .status = &bsp_lcd0_status, .writereg = &bsp_lcd0_write_reg, .readreg = &bsp_lcd0_read_reg, .writeGRAM = &bsp_lcd0_writeGRAM, .readGRAM = &bsp_lcd0_readGRAM }; LCD_t lcd0={ .interface = &lcdIF0, .init = &D51E5TA7601init, .paint = &D51E5TA7601paint, .paintFB = D51E5TA7601paintFB, .setFrame = &D51E5TA7601setFrame, .paintText = &D51E5TA7601paintText, .paintFilRect = &D51E5TA7601paintFilRect, .getPix = &D51E5TA7601getPix, .refreshenable = &D51E5TA7601refreshenable, .width= 320, .height = 480, .isFrameBuffer = 0 }; terminal_t terminal0; volatile int16_t* lcd0_CMD=(volatile int16_t*)0x60000000; volatile int16_t* lcd0_DATA=(volatile int16_t*)0x61FFFFF0; volatile int16_t* SRAM_DATA=(volatile int16_t*)0x64000000; // Frame buffers 300kB per buffer, RAM size=1M*16 -> 6.8 buffers max volatile int16_t* FRAME_BUFFER0_data=(volatile int16_t*)0x64000000; volatile int16_t* FRAME_BUFFER1_data=((volatile int16_t*)0x64000000)+(320*480); //300kB per buffer LCD_t __attribute__ ((aligned (4))) FRAME_BUFFER0= { .interface.buffer=(int16_t*)0x64000000, .init = &D51E5TA7601init_FrameBuff, .paint = &D51E5TA7601paint_FrameBuff, .setFrame = &D51E5TA7601setFrame_FrameBuff, .paintText = &D51E5TA7601paintText_FrameBuff, .paintFilRect = &D51E5TA7601paintFilRect_FrameBuff, .getPix = &D51E5TA7601getPix_FrameBuff, .refreshenable = &D51E5TA7601refreshenable_FrameBuff, .width= 480, .height = 320, .isFrameBuffer = 1 }; LCD_t __attribute__ ((aligned (4))) FRAME_BUFFER1= { .interface.buffer=(((int16_t*)0x64000000)+(320*480)), .init = &D51E5TA7601init_FrameBuff, .paint = &D51E5TA7601paint_FrameBuff, .setFrame = &D51E5TA7601setFrame_FrameBuff, .paintText = &D51E5TA7601paintText_FrameBuff, .paintFilRect = &D51E5TA7601paintFilRect_FrameBuff, .getPix = &D51E5TA7601getPix_FrameBuff, .refreshenable = &D51E5TA7601refreshenable_FrameBuff, .width= 480, .height = 320, .isFrameBuffer = 1 }; LCD_t* FRAME_BUFFER=&FRAME_BUFFER0; float VREF0 =(float)3.3; // GPIO config list gpioinitlist_str gpios[]={ {LED1,{gpiooutdir,gpiohighspeed,0,0}}, {LED2,{gpiooutdir,gpiohighspeed,0,0}}, {LED3,{gpiooutdir,gpiohighspeed,0,0}}, {PSU_DISABLE,{gpiooutdir,gpiohighspeed,gpiopushpulltype,0}}, {PSU_ALERT_5V,{gpioindir,gpiohighspeed,0,0}}, {PSU_ALERT_1_5V,{gpioindir,gpiohighspeed,0,0}}, {PSU_ALERT_3_3V,{gpioindir,gpiohighspeed,0,0}}, {BP1,{gpioindir,gpiohighspeed,0,0}}, {BP2,{gpioindir,gpiohighspeed,0,0}}, {BP3,{gpioindir,gpiohighspeed,0,0}}, {BP4,{gpioindir,gpiohighspeed,0,0}}, {TC_IRQ,{gpioindir,gpiohighspeed,0,gpiopulluptype}} }; int bsp_init() { int i=0; for(i=0;i<32;i++) { __opnfiles__[i] = NULL; } bsp_GPIO_init(); // bsp_uart_init(); bsp_iic_init(); bsp_spi_init(); bsp_TC_init(); bsp_FSMC_init(); bsp_GTerm_init(); printf("\r=====================\n\r"); printf( "=====================\n\r"); printf(BSP); printf(" initialised\n\r"); printf( "=====================\n\r"); char uuid[12]; getCpuUUID(uuid); printf("CPU UUID ="); for(int i=0;i<12;i++) { printf( "%02x",uuid[i]); } printf( "\n\r=====================\n\r"); return 1; } void bsp_GPIO_init() { bsp_gpio_init_list(gpios); gpioclr(PSU_DISABLE); pwmopen(PWM9_CH2,LCD_BACKLIGHT); int error = pwmsetconfig(PWM9_CH2,100,80.0); } void bsp_uart_init() { if(__opnfiles__[1]==NULL) { streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); uartmkstreamdev(uart,fd1); __opnfiles__[1] = fd1; } else { uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); } } int bsp_FSMC_init() { #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) gpio_t gpio1 = gpioopen(LCD_RESET); gpiosetspeed(gpio1,gpiohighspeed); gpiosetdir(gpio1,gpiooutdir); gpioclr(LCD_RESET); gpio_t LCD_DBxList[]={ LCD_CS, LCD_RS, LCD_WR, LCD_RD, LCD_D0, LCD_D1, LCD_D2, LCD_D3, LCD_D4, LCD_D5, LCD_D6, LCD_D7, LCD_D8, LCD_D9, LCD_D10, LCD_D11, LCD_D12, LCD_D13, LCD_D14, LCD_D15}; for(int i=0;i<20;i++) { gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); gpiosetconfig(LCD_DBx, gpioaf, gpiohighspeed, gpiopushpulltype, gpionopulltype); GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); } FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p,readtim; /* Enable FSMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /*-- FSMC Configuration ------------------------------------------------------*/ /*----------------------- SRAM Bank 3 ----------------------------------------*/ /* FSMC_Bank1_NORSRAM3 configuration */ p.FSMC_AddressSetupTime = 0xf; p.FSMC_AddressHoldTime = 0xf; //ili9328 -> data setup time > 10ns p.FSMC_DataSetupTime = 0xf; if(getCpuFreq()>100*1000*1000) p.FSMC_DataSetupTime = 0xf;// 11; p.FSMC_BusTurnAroundDuration = 0xf; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0xf; //ili9328 -> data hold time > 15ns if(getCpuFreq()>66*1000*1000) p.FSMC_DataLatency = 0xf; p.FSMC_AccessMode = FSMC_AccessMode_A; readtim.FSMC_AddressSetupTime = 0xf; readtim.FSMC_AddressHoldTime = 0xf; //p.FSMC_DataSetupTime = 9; readtim.FSMC_DataSetupTime = 0xf ;// 11; if(getCpuFreq()>100*1000*1000) readtim.FSMC_DataSetupTime = 0xf;// 11; readtim.FSMC_BusTurnAroundDuration = 0xf; readtim.FSMC_CLKDivision = 2; readtim.FSMC_DataLatency = 0xf; if(getCpuFreq()>66*1000*1000) readtim.FSMC_DataLatency = 0xf; readtim.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readtim; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /* Enable FSMC NOR/SRAM Bank1 */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); gpio_t SRAM_DBxList[]={ SRAM_A0, SRAM_A1, SRAM_A2, SRAM_A3, SRAM_A4, SRAM_A5, SRAM_A6, SRAM_A7, SRAM_A8, SRAM_A9, SRAM_A10, SRAM_A11, SRAM_A12, SRAM_A13, SRAM_A14, SRAM_A15, SRAM_A16, SRAM_A17, SRAM_A18, SRAM_A19, SRAM_NBL0, SRAM_NBL1, SRAM_NCE }; for(int i=0;i<23;i++) { gpio_t SRAM_DBx = gpioopen(SRAM_DBxList[i]); gpiosetconfig(SRAM_DBx, gpioaf, gpiohighspeed, gpiopushpulltype, gpionopulltype); GPIO_PinAFConfig(GPIOGETPORT(SRAM_DBx), (uint8_t)(SRAM_DBx & 0xF), GPIO_AF_FSMC); } /*-- FSMC Configuration ------------------------------------------------------*/ // p.FSMC_AddressSetupTime = 3; p.FSMC_AddressSetupTime = 1; p.FSMC_AddressHoldTime = 1; // p.FSMC_DataSetupTime = 6; p.FSMC_DataSetupTime = 1; p.FSMC_BusTurnAroundDuration = 1; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 1; p.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /*!< Enable FSMC Bank1_SRAM2 Bank */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); gpioset(LCD_RESET); delay_100us(500); gpioclr(LCD_RESET); delay_100us(500); gpioset(LCD_RESET); lcd0.init(&lcd0); return 1; } void bsp_spi_init() { // ads7843init(&tc_dev,spi1,ADS7843_POWER_ADC_ON|ADS7843_MODE_12BITS,&TC_setnCS,&TC_busy); } void bsp_iic_init() { i2copenandconfig(i2c3,0,100000,PH8,PH7); } void bsp_SD_init() { } void vs10XXclearXCS(){} void vs10XXsetXCS(){} int vs10XXDREQ() { return 1; } void bsppowersdcard(char onoff) //always ON { } char bspsdcardpresent() { return 0; } char bspsdcardwriteprotected() { return 0; } void bspsdcardselect(char YESNO) { } void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) { *lcd0_CMD=(uint16_t)reg; *lcd0_DATA=(uint16_t)data; } uint32_t bsp_lcd0_read_reg(uint32_t reg) { uint16_t value; *lcd0_CMD=(uint16_t)reg; value = *lcd0_DATA; value = *lcd0_DATA; return value; } void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) { *lcd0_CMD=(uint16_t)D51E5TA7601_REGISTER_WRITEDATATOGRAM; uint16_t* castedBuff=(uint16_t*)buffer; for(int i=0;i<(int)count;i++) { *lcd0_DATA=castedBuff[i]; } } void bsp_lcd0_setGRAM() { *lcd0_CMD=(uint16_t)D51E5TA7601_REGISTER_WRITEDATATOGRAM; } void bsp_lcd0_readGRAM(void* buffer,uint32_t count) { uint16_t* castedBuff=(uint16_t*)buffer; *lcd0_CMD=(uint16_t)D51E5TA7601_REGISTER_WRITEDATATOGRAM; castedBuff[0]=lcd0_DATA[0]; for(int i=0;i<(int)count;i++) { castedBuff[i]=lcd0_DATA[0]; } } uint32_t bsp_lcd0_status() { uint16_t status = lcd0_CMD[0]; return (uint32_t)status; } void TC_setnCS(char val) { return gpiosetval(TC_BUSY,val); } int TC_busy() { return gpiogetval(TC_BUSY); } void bsp_TC_init() { #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) gpio_t gpio1 = gpioopen(TC_BUSY); gpiosetconfig(gpio1,gpioindir,gpiohighspeed, 0, 0); gpio1 = gpioopen(TC_IRQ); gpiosetconfig(gpio1,gpioindir,gpiohighspeed, 0, 0); gpio1 = gpioopen(TC_CS); gpiosetconfig(gpio1, gpiooutdir, gpiohighspeed, 0, 0); spiopenandconfig(spi1,spimaster|spi8bits|spimsbfirst|spiclkfirstedge,10000000,TC_DIN,TC_DOUT,TC_CLK,-1); } void bsp_GTerm_init() { FRAME_BUFFER->init(FRAME_BUFFER); if(__opnfiles__[1]==NULL) { //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); terminal_init(&terminal0 ,FRAME_BUFFER,&ComicSansMS_8,fd1); __opnfiles__[1] = fd1; } else { } }