bsp.c
379 lines
| 10.2 KiB
| text/x-c
|
CLexer
r74 | /*------------------------------------------------------------------------------ | |||
-- 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 <streamdevices.h> | ||||
#include <malloc.h> | ||||
#include <gpio.h> | ||||
#include <uart.h> | ||||
#include <stdio.h> | ||||
#include <ili9328.h> | ||||
#include <genericLCD_Controler.h> | ||||
#include <stm32f4xx.h> | ||||
#include <stm32f4xx_gpio.h> | ||||
#include <stm32f4xx_rcc.h> | ||||
#include <stm32f4xx_gpio.h> | ||||
#include <stm32f4xx_fsmc.h> | ||||
#include <terminal.h> | ||||
uint32_t OSC0 =8000000; | ||||
uint32_t INTOSC =16000000; | ||||
uint32_t RTCOSC =32768; | ||||
uint32_t currentCpuFreq=0; | ||||
extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | ||||
r79 | gpio_t TickLed = LED1; | |||
r74 | ||||
volatile uint8_t* lcd0_CMD=(volatile uint8_t*)0x60000000; | ||||
volatile uint8_t* lcd0_DATA=(volatile uint8_t*)0x61FFFFF0; | ||||
terminal_t terminal0; | ||||
volatile vs10XXDev audioCodec0; | ||||
sdcardDev sdcard2; | ||||
blkdevice sdcard2blkdev; | ||||
dikpartition sdcard2Part1; | ||||
FAT32fs sdcard2FAT32part1; | ||||
dikpartition sdcard2Part2; | ||||
FAT32fs sdcard2FAT32part2; | ||||
dikpartition sdcard2Part3; | ||||
FAT32fs sdcard2FAT32part3; | ||||
dikpartition sdcard2Part4; | ||||
FAT32fs sdcard2FAT32part4; | ||||
LCD_IF_t lcdIF0={ | ||||
.init = &bsp_FSMC_init, | ||||
.writereg = &bsp_lcd0_write_reg, | ||||
.readreg = &bsp_lcd0_read_reg, | ||||
.writeGRAM = &bsp_lcd0_writeGRAM, | ||||
.readGRAM = &bsp_lcd0_readGRAM | ||||
}; | ||||
LCD_t lcd0={ | ||||
.interface = &lcdIF0, | ||||
.init = &ili9328init, | ||||
.paint = &ili9328paint, | ||||
.paintText = &ili9328paintText, | ||||
.paintFilRect = &ili9328paintFilRect, | ||||
.refreshenable = &ili9328refreshenable, | ||||
.width= 240, | ||||
.height = 320 | ||||
}; | ||||
float VREF0 =(float)3.3; | ||||
int bsp_init() | ||||
{ | ||||
int i=0; | ||||
for(i=0;i<32;i++) | ||||
{ | ||||
__opnfiles__[i] = NULL; | ||||
} | ||||
bsp_GPIO_init(); | ||||
bsp_uart_init(); | ||||
bsp_FSMC_init(); | ||||
bsp_GTerm_init(); | ||||
printf("\r================================================================\n\r"); | ||||
printf("================================================================\n\r"); | ||||
printf(BSP); | ||||
printf(" initialised\n\r"); | ||||
printf("================================================================\n\r"); | ||||
return 1; | ||||
} | ||||
void bsp_GPIO_init() | ||||
{ | ||||
gpio_t gpio1 = gpioopen(PD12);//gpioopen(LED1); //PD9 D=> 0x0300 9 => 0x0009 | ||||
gpio_t gpio2 = gpioopen(PD13);//gpioopen(LED2); | ||||
gpio_t gpio3 = gpioopen(PD14);//gpioopen(LED2); | ||||
gpio_t gpio4 = gpioopen(PD15);//gpioopen(LED2); | ||||
gpiosetspeed(&gpio1,gpiohighspeed); | ||||
gpiosetspeed(&gpio2,gpiohighspeed); | ||||
gpiosetspeed(&gpio3,gpiohighspeed); | ||||
gpiosetspeed(&gpio4,gpiohighspeed); | ||||
gpiosetdir(&gpio1,gpiooutdir); | ||||
gpiosetdir(&gpio3,gpiooutdir); | ||||
gpiosetdir(&gpio2,gpiooutdir); | ||||
gpiosetdir(&gpio4,gpiooutdir); | ||||
} | ||||
void bsp_uart_init() | ||||
{ | ||||
// if(__opnfiles__[1]==NULL) | ||||
// { | ||||
// //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | ||||
// streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | ||||
// uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,19200,PB10,PB11,-1,-1); | ||||
// uartmkstreamdev(uart,fd1); | ||||
// __opnfiles__[1] = fd1; //stdo | ||||
// __opnfiles__[0] = fd1; //stdi | ||||
// } | ||||
// else | ||||
// { | ||||
// uartopenandconfig(2,uartparitynone | uart8bits | uartonestop,115200,PB10,PB11,-1,-1); | ||||
// } | ||||
} | ||||
void bsp_spi_init() | ||||
{ | ||||
} | ||||
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 LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ | ||||
,PD4,PD5,PD7,PE4}; | ||||
for(int i=0;i<12;i++) | ||||
{ | ||||
gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); | ||||
LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | ||||
gpiosetconfig(&LCD_DBx); | ||||
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_NORSRAM4 configuration */ | ||||
p.FSMC_AddressSetupTime = 3; | ||||
p.FSMC_AddressHoldTime = 3; | ||||
//ili9328 -> data setup time > 10ns | ||||
p.FSMC_DataSetupTime = 1; | ||||
if(getCpuFreq()>100*1000*1000) | ||||
p.FSMC_DataSetupTime = 2;// 11; | ||||
p.FSMC_BusTurnAroundDuration = 0; | ||||
p.FSMC_CLKDivision = 0; | ||||
p.FSMC_DataLatency = 0; | ||||
//ili9328 -> data hold time > 15ns | ||||
if(getCpuFreq()>66*1000*1000) | ||||
p.FSMC_DataLatency = 1; | ||||
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 = 0; | ||||
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_8b; | ||||
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); | ||||
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); | ||||
gpioset(LCD_RESET); | ||||
gpioclr(LCD_RESET); | ||||
delay_100us(500); | ||||
gpioset(LCD_RESET); | ||||
delay_100us(500); | ||||
lcd0.init(&lcd0); | ||||
gpioset(LCD_BACKL); | ||||
return 1; | ||||
} | ||||
void bsp_iic_init() | ||||
{ | ||||
} | ||||
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) | ||||
{ | ||||
uint8_t* pt8 = (uint8_t*)(void*)® | ||||
#if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | ||||
*lcd0_CMD=pt8[3]; | ||||
*lcd0_CMD=pt8[2]; | ||||
pt8 = (uint8_t*)(void*)&data; | ||||
*lcd0_DATA=pt8[3]; | ||||
*lcd0_DATA=pt8[2]; | ||||
#else | ||||
*lcd0_CMD=pt8[1]; | ||||
*lcd0_CMD=pt8[0]; | ||||
pt8 = (uint8_t*)(void*)&data; | ||||
*lcd0_DATA=pt8[1]; | ||||
*lcd0_DATA=pt8[0]; | ||||
#endif | ||||
} | ||||
uint32_t bsp_lcd0_read_reg(uint32_t reg) | ||||
{ | ||||
uint8_t* pt8 = (uint8_t*)(void*)® | ||||
uint32_t DATA=0; | ||||
#if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | ||||
*lcd0_CMD=pt8[3]; | ||||
*lcd0_CMD=pt8[2]; | ||||
pt8 = (uint8_t*)(void*)&DATA; | ||||
pt8[3]=*lcd0_DATA; | ||||
pt8[2]=*lcd0_DATA; | ||||
#else | ||||
*lcd0_CMD=pt8[1]; | ||||
*lcd0_CMD=pt8[0]; | ||||
pt8 = (uint8_t*)(void*)&DATA; | ||||
pt8[1]=*lcd0_DATA; | ||||
pt8[0]=*lcd0_DATA; | ||||
#endif | ||||
return DATA; | ||||
} | ||||
void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | ||||
{ | ||||
uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | ||||
uint8_t* pt8 = (uint8_t*)(void*)(®); | ||||
#if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | ||||
*lcd0_CMD=pt8[3]; | ||||
*lcd0_CMD=pt8[2]; | ||||
pt8 = (uint8_t*)(void*)buffer; | ||||
for(int i=0;i<(int)count;i++) | ||||
{ | ||||
*lcd0_DATA=pt8[(2*i) +1]; | ||||
*lcd0_DATA=pt8[2*i]; | ||||
} | ||||
#else | ||||
*lcd0_CMD=pt8[1]; | ||||
*lcd0_CMD=pt8[0]; | ||||
pt8 = (uint8_t*)(void*)buffer; | ||||
for(int i=0;i<(int)count;i++) | ||||
{ | ||||
*lcd0_DATA=pt8[(2*i) +1]; | ||||
*lcd0_DATA=pt8[2*i]; | ||||
} | ||||
#endif | ||||
} | ||||
void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | ||||
{ | ||||
uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | ||||
uint8_t* pt8 = (uint8_t*)(void*)® | ||||
#if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | ||||
*lcd0_CMD=pt8[3]; | ||||
*lcd0_CMD=pt8[2]; | ||||
pt8 = (uint8_t*)(void*)buffer; | ||||
for(int i=0;i<(int)count;i++) | ||||
{ | ||||
pt8[(2*i) +1]=*lcd0_DATA; | ||||
pt8[2*i]=*lcd0_DATA; | ||||
} | ||||
#else | ||||
*lcd0_CMD=pt8[1]; | ||||
*lcd0_CMD=pt8[0]; | ||||
pt8 = (uint8_t*)(void*)buffer; | ||||
/* | ||||
* x dummy reads Cf ili9328 datasheet p79! | ||||
*/ | ||||
pt8[0]=*lcd0_DATA; | ||||
pt8[0]=*lcd0_DATA; | ||||
for(int i=0;i<(int)count;i++) | ||||
{ | ||||
pt8[(2*i) +1]=*lcd0_DATA; | ||||
pt8[2*i]=*lcd0_DATA; | ||||
// pt8[(2*i) +1]=(uint8_t)0; | ||||
// pt8[(2*i)]=(uint8_t)0; | ||||
} | ||||
#endif | ||||
} | ||||
void bsp_GTerm_init() | ||||
{ | ||||
if(__opnfiles__[1]==NULL) | ||||
{ | ||||
streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | ||||
terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); | ||||
__opnfiles__[1] = fd1; | ||||
} | ||||
else | ||||
{ | ||||
} | ||||
} | ||||