/*------------------------------------------------------------------------------ -- 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 uint32_t OSC0 =8000000; uint32_t INTOSC =16000000; uint32_t RTCOSC =32768; uint32_t currentCpuFreq=0; extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; LCD_IF_t lcdIF0={ .init = &SDLCD_init, .writereg = &SDLCD_writereg, .readreg = &SDLCD_readreg, .writeGRAM = &SDLCD_writeGRAM_16bpp, .readGRAM = &SDLCD_readGRAM_16bpp }; LCD_t lcd0={ .interface = &lcdIF0, .init = &ili9328init, .paint = &ili9328paint, .paintText = &ili9328paintText, .paintFilRect = &ili9328paintFilRect, .getPix = &ili9328getPix, .refreshenable = &ili9328refreshenable, .width= 240, .height = 320 }; terminal_t terminal0; volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); float VREF0 =(float)3.3; volatile vs10XXDev audioCodec0; sdcardDev sdcard2; blkdevice sdcard2blkdev; dikpartition sdcard2Part1; FAT32fs sdcard2FAT32part1; dikpartition sdcard2Part2; FAT32fs sdcard2FAT32part2; dikpartition sdcard2Part3; FAT32fs sdcard2FAT32part3; dikpartition sdcard2Part4; FAT32fs sdcard2FAT32part4; int bsp_init() { int i=0; for(i=0;i<__MAX_OPENED_FILES__;i++) { __opnfiles__[i] = NULL; } bsp_GPIO_init(); bsp_uart_init(); bsp_iic_init(); bsp_FSMC_init(); bsp_GTerm_init(); bsp_spi_init(); bsp_SD_init(); bsp_Audio_init(); printf("\r=====================\n\r"); printf( "=====================\n\r"); printf(BSP); printf(" initialised\n\r"); printf( "=====================\n\r"); return 1; } void bsp_GPIO_init() { } void bsp_uart_init() { } /* D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 D5 PE8 D6 PE9 D7 PE10 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S FSMC_NOE PD4 RD */ int bsp_FSMC_init() { return 1; } void bsp_spi_init() { } void bsp_iic_init() { } void bsp_Audio_init() { } void bsp_SD_init() { sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) { if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) printf("Can't open fat32 partition 1\n"); } else { printf("Can't open or read MBR\n"); } delay_100us(1000); if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) printf("Can't open fat32 partition 2\n"); } else { printf("Can't open or read MBR\n"); } delay_100us(1000); if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) printf("Can't open fat32 partition 3\n"); } else { printf("Can't open or read MBR\n"); } delay_100us(1000); if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) { if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) printf("Can't open fat32 partition 4\n"); } else { printf("Can't open or read MBR\n"); } } else { printf("Can't initialize SDCARD\n"); } delay_100us(2000); } void vs1052setXCS(char val) { } void vs1052setXDCS(char val) { } void vs1052setRST(char val) { } int vs10XXDREQ() { return 1; } void bsppowersdcard(char onoff) //always ON { } char bspsdcardpresent() { return 1; } char bspsdcardwriteprotected() { return 0; } void bspsdcardselect(char YESNO) { } void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) { } uint32_t bsp_lcd0_read_reg(uint32_t reg) { return 0; } void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) { } void bsp_lcd0_readGRAM(void* buffer,uint32_t count) { } void bsp_GTerm_init() { SDLCD_mkscreen(240,320,16,LCDILI9328); if(__opnfiles__[1]==NULL) { streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); lcd0.paintFilRect(&lcd0,0,0,240,320,0,0,0x0f0f); __opnfiles__[1] = fd1; } else { } } void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } } Uint32 getpixel(SDL_Surface *surface, int x, int y) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to retrieve */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: return *p; case 2: return *(Uint16 *)p; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; else return p[0] | p[1] << 8 | p[2] << 16; case 4: return *(Uint32 *)p; default: return 0; } /* shouldn’t happen, but avoids warnings */ }