[Horus] Next round of screen changes + refactoring

This commit is contained in:
Bertrand Songis
2015-11-03 19:53:55 +01:00
parent 8f4c161dc0
commit a556c50956
106 changed files with 1848 additions and 1195 deletions
+4
View File
@@ -63,6 +63,8 @@ const int8_t ana_direction[NUMBER_ANALOG] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
void adcInit()
{
return ;
// Enable clocks
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
RCC->AHB1ENR |= ADC_RCC_AHB1Periph_GPIO | RCC_AHB1ENR_DMA2EN;
@@ -93,6 +95,8 @@ void adcInit()
void adcRead()
{
return ;
DMA2_Stream0->CR &= ~DMA_SxCR_EN ; // Disable DMA
ADC1->SR &= ~(uint32_t) ( ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR ) ;
DMA2->LIFCR = DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 |DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0 ; // Write ones to clear bits
+9 -14
View File
@@ -72,7 +72,7 @@ void init5msTimer()
{
// Timer14
RCC->APB1ENR |= RCC_APB1ENR_TIM14EN ; // Enable clock
TIM14->ARR = 4999 ; // 5mS
TIM14->ARR = 999 ; // 5mS
TIM14->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1 ; // 1uS from 30MHz
TIM14->CCER = 0 ;
TIM14->CCMR1 = 0 ;
@@ -95,13 +95,18 @@ void interrupt5ms()
{
static uint32_t pre_scale ; // Used to get 10 Hz counter
AUDIO_HEARTBEAT();
++pre_scale;
if (pre_scale == 5 || pre_scale == 10) {
AUDIO_HEARTBEAT();
#if defined(HAPTIC)
HAPTIC_HEARTBEAT();
HAPTIC_HEARTBEAT();
#endif
if ( ++pre_scale >= 2 ) {
}
if ( pre_scale >= 10 ) {
pre_scale = 0 ;
per10ms();
}
@@ -244,13 +249,3 @@ void checkTrainerSettings()
}
}
}
// TODO
bool eeCopyModel(uint8_t dst, uint8_t src) { }
void eeSwapModels(uint8_t id1, uint8_t id2) { }
void eeDeleteModel(uint8_t idx) { }
uint8_t eeFindEmptyModel(uint8_t id, bool down) { return 0; };
bool eeModelExists(uint8_t id) { return true; }
const pm_char * eeBackupModel(uint8_t i_fileSrc) { return NULL; }
const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name) { return NULL; }
void selectModel(uint8_t sub) { }
+3 -7
View File
@@ -104,15 +104,9 @@ extern "C" {
#define PIN_PORTA 0x0000
#define PIN_PORTB 0x0100
#define PIN_PORTC 0x0200
#define PIN_PORTD 0x0300
#define PIN_PORTE 0x0400
#define PIN_PORTF 0x0500
#define PIN_PER_1 0x0010
#define PIN_PER_2 0x0020
#define PIN_PER_3 0x0030
#define PIN_PER_5 0x0050
#define PIN_PER_6 0x0060
#define PIN_PER_8 0x0080
#define PIN_OS25 0x2000
#define PIN_OS50 0x4000
#define PIN_OS100 0x6000
@@ -241,7 +235,7 @@ void pwrOn(void);
void pwrOff(void);
uint32_t pwrPressed(void);
uint32_t pwrPressedDuration(void);
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
#define UNEXPECTED_SHUTDOWN() (false) // (g_eeGeneral.unexpectedShutdown)
// Led driver
void ledInit(void);
@@ -253,6 +247,8 @@ void ledBlue(void);
void lcdInit(void);
void lcdRefresh(void);
void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
void lcdStoreBackupBuffer(void);
void lcdRestoreBackupBuffer(void);
// Backlight driver
#define setBacklight(xx)
+98 -60
View File
@@ -17,8 +17,7 @@
/*-----------------------------------------------------------------------*/
#if !defined(BOOT)
static OS_MutexID ioMutex;
volatile int mutexCheck = 0;
unsigned int ioMutexReq = 0, ioMutexRel = 0;
int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex)
{
*mutex = ioMutex;
@@ -27,11 +26,13 @@ int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex)
int ff_req_grant (_SYNC_t mutex)
{
ioMutexReq += 1;
return CoEnterMutexSection(mutex) == E_OK;
}
void ff_rel_grant (_SYNC_t mutex)
{
ioMutexRel += 1;
CoLeaveMutexSection(mutex);
}
@@ -87,7 +88,7 @@ DSTATUS disk_status (
return(stat);
}
unsigned int sdReadRetries = 0;
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
@@ -99,56 +100,78 @@ DRESULT disk_read (
UINT count /* Number of sectors to read (1..255) */
)
{
SD_Error Status;
DRESULT res = RES_OK;
SD_Error Status;
// TRACE("disk_read %d %p %10d %d\n",drv,buff,sector,count);
// TRACE("disk_read %d %p %10d %d", drv, buff, sector, count);
if (SD_Detect() != SD_PRESENT)
return(RES_NOTRDY);
if (SD_Detect() != SD_PRESENT) {
TRACE("SD_Detect() != SD_PRESENT");
return RES_NOTRDY;
}
if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer
{
DRESULT res = RES_OK;
DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack
if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer
{
TRACE("DMA Alignment failure, align buffer");
while(count--)
{
res = disk_read(drv, (BYTE *)scratch, sector++, 1);
DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack
if (res != RES_OK) {
TRACE("disk_read() status=%d", res);
break;
}
while(count--) {
res = disk_read(drv, (BYTE *)scratch, sector++, 1);
memcpy(buff, scratch, BLOCK_SIZE);
if (res != RES_OK) {
TRACE("disk_read() status=%d", res);
break;
}
buff += BLOCK_SIZE;
}
memcpy(buff, scratch, BLOCK_SIZE);
return(res);
}
buff += BLOCK_SIZE;
}
Status = SD_ReadMultiBlocksFIXED(buff, sector, BLOCK_SIZE, count); // 4GB Compliant
return res;
}
if (Status == SD_OK)
{
SDTransferState State;
for (int retry=0; retry<3; retry++) {
res = RES_OK;
Status = SD_WaitReadOperation(); // Check if the Transfer is finished
if (count == 1) {
Status = SD_ReadBlock(buff, sector, BLOCK_SIZE); // 4GB Compliant
}
else {
Status = SD_ReadMultiBlocks(buff, sector, BLOCK_SIZE, count); // 4GB Compliant
}
while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
#if defined(SD_DMA_MODE)
if (Status == SD_OK) {
SDTransferState State;
if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK)) {
TRACE("SD_ReadMultiBlocksFIXED() wait error (State=%d Status=%d)", State, Status);
return(RES_ERROR);
}
else
return(RES_OK);
}
else {
TRACE("SD_ReadMultiBlocksFIXED() error (Status=%d)", Status);
return(RES_ERROR);
}
Status = SD_WaitReadOperation(); // Check if the Transfer is finished
while ((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if (State == SD_TRANSFER_ERROR) {
TRACE("State=SD_TRANSFER_ERROR");
res = RES_ERROR;
}
else if (Status != SD_OK) {
TRACE("Status(WaitRead)=%d", Status);
res = RES_ERROR;
}
}
else {
TRACE("Status(ReadBlock)=%d", Status);
res = RES_ERROR;
}
#endif
if (res == RES_OK)
break;
sdReadRetries += 1;
}
return res;
}
/*-----------------------------------------------------------------------*/
@@ -163,15 +186,15 @@ DRESULT disk_write (
)
{
SD_Error Status;
DRESULT res = RES_OK;
// TRACE("disk_write %d %p %10d %d\n",drv,buff,sector,count);
// TRACE("disk_write %d %p %10d %d", drv, buff, sector, count);
if (SD_Detect() != SD_PRESENT)
return(RES_NOTRDY);
if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer
{
DRESULT res = RES_OK;
DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack
while(count--)
@@ -181,7 +204,7 @@ DRESULT disk_write (
res = disk_write(drv, (BYTE *)scratch, sector++, 1);
if (res != RES_OK)
break;
break;
buff += BLOCK_SIZE;
}
@@ -189,7 +212,12 @@ DRESULT disk_write (
return(res);
}
Status = SD_WriteMultiBlocksFIXED((uint8_t *)buff, sector, BLOCK_SIZE, count); // 4GB Compliant
if (count == 1) {
Status = SD_WriteBlock((uint8_t *)buff, sector*BLOCK_SIZE, BLOCK_SIZE); // 4GB Compliant
}
else {
Status = SD_WriteMultiBlocks((uint8_t *)buff, sector, BLOCK_SIZE, count); // 4GB Compliant
}
if (Status == SD_OK)
{
@@ -200,12 +228,14 @@ DRESULT disk_write (
while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK))
return(RES_ERROR);
else
return(RES_OK);
res = RES_ERROR;
}
else
return(RES_ERROR);
else {
res = RES_ERROR;
}
// TRACE("result=%d", res);
return res;
}
#endif /* _READONLY */
@@ -221,7 +251,25 @@ DRESULT disk_ioctl (
void *buff /* Buffer to send/receive control data */
)
{
return RES_OK;
DRESULT res;
if (drv) return RES_PARERR;
res = RES_ERROR;
switch (ctrl) {
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
*(DWORD*)buff = SDCardInfo.CardCapacity / BLOCK_SIZE;
res = RES_OK;
break;
case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
*(WORD*)buff = BLOCK_SIZE;
res = RES_OK;
break;
}
return res;
}
// TODO everything here should not be in the driver layer ...
@@ -231,15 +279,6 @@ FATFS g_FATFS_Obj;
FIL g_telemetryFile = {0};
#endif
#if defined(BOOT)
void sdInit(void)
{
if (f_mount(&g_FATFS_Obj, "", 1) == FR_OK) {
f_chdir("/");
}
}
#else
// TODO shouldn't be there!
void sdInit(void)
{
ioMutex = CoCreateMutex();
@@ -276,7 +315,6 @@ void sdDone()
f_mount(NULL, "", 0); // unmount SD
}
}
#endif
uint32_t sdMounted()
{
+20 -20
View File
@@ -54,22 +54,22 @@
#define SWITCHES_GPIO_PIN_H GPIO_Pin_7 // PG.07
// Trims
#define TRIMS_GPIO_REG_LHL GPIOC->IDR
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_0 // PC.00
#define TRIMS_GPIO_REG_LHR GPIOI->IDR
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_4 // PI.04
#define TRIMS_GPIO_REG_LVD GPIOG->IDR
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_12 // PG.12
#define TRIMS_GPIO_REG_LVU GPIOJ->IDR
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_14 // PJ.14
#define TRIMS_GPIO_REG_RVD GPIOJ->IDR
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_13 // PJ.13
#define TRIMS_GPIO_REG_RHL GPIOD->IDR
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_3 // PD.03
#define TRIMS_GPIO_REG_RHL GPIOC->IDR
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_0 // PC.00
#define TRIMS_GPIO_REG_RHR GPIOI->IDR
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_4 // PI.04
#define TRIMS_GPIO_REG_RVD GPIOG->IDR
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_12 // PG.12
#define TRIMS_GPIO_REG_RVU GPIOJ->IDR
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_12 // PJ.12
#define TRIMS_GPIO_REG_RHR GPIOD->IDR
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_7 // PD.07
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_14 // PJ.14
#define TRIMS_GPIO_REG_LVD GPIOJ->IDR
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_13 // PJ.13
#define TRIMS_GPIO_REG_LHL GPIOD->IDR
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_3 // PD.03
#define TRIMS_GPIO_REG_LVU GPIOJ->IDR
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_12 // PJ.12
#define TRIMS_GPIO_REG_LHR GPIOD->IDR
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_7 // PD.07
#define TRIMS_GPIO_REG_RSD GPIOJ->IDR
#define TRIMS_GPIO_PIN_RSD GPIO_Pin_8 // PJ.08
#define TRIMS_GPIO_REG_RSU GPIOD->IDR
@@ -81,13 +81,13 @@
// Index of all keys
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | TRIMS_GPIO_PIN_LSD | TRIMS_GPIO_PIN_LSU)
#define KEYS_GPIOC_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_RIGHT | TRIMS_GPIO_PIN_LHL)
#define KEYS_GPIOD_PINS (SWITCHES_GPIO_PIN_C_L | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR | TRIMS_GPIO_PIN_RSU)
#define KEYS_GPIOC_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_RIGHT | TRIMS_GPIO_PIN_RHL)
#define KEYS_GPIOD_PINS (SWITCHES_GPIO_PIN_C_L | TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_RSU)
#define KEYS_GPIOE_PINS (SWITCHES_GPIO_PIN_E_L)
#define KEYS_GPIOG_PINS (KEYS_GPIO_PIN_UP | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | TRIMS_GPIO_PIN_LVD)
#define KEYS_GPIOG_PINS (KEYS_GPIO_PIN_UP | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | TRIMS_GPIO_PIN_RVD)
#define KEYS_GPIOH_PINS (SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_F | ENC_GPIO_PIN_A | ENC_GPIO_PIN_B)
#define KEYS_GPIOI_PINS (KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_LEFT | KEYS_GPIO_PIN_DOWN | SWITCHES_GPIO_PIN_A_H | TRIMS_GPIO_PIN_LHR)
#define KEYS_GPIOJ_PINS (SWITCHES_GPIO_PIN_D_H | TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RSD)
#define KEYS_GPIOI_PINS (KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_LEFT | KEYS_GPIO_PIN_DOWN | SWITCHES_GPIO_PIN_A_H | TRIMS_GPIO_PIN_RHR)
#define KEYS_GPIOJ_PINS (SWITCHES_GPIO_PIN_D_H | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_RSD)
// ADC
#define ADC_RCC_AHB1Periph_GPIO (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC)
+51 -45
View File
@@ -9,22 +9,20 @@
#define HFP 3
#define VFP 2
#define LCD_PIXEL_WIDTH ((uint16_t)480)
#define LCD_PIXEL_HEIGHT ((uint16_t)272)
#define LCD_DIR_HORIZONTAL 0x0000
#define LCD_DIR_VERTICAL 0x0001
#define LCD_DIR_HORIZONTAL 0x0000
#define LCD_DIR_VERTICAL 0x0001
#define LCD_FIRST_LAYER 0
#define LCD_SECOND_LAYER 1
#define LCD_BACKGROUND_LAYER 0x0000
#define LCD_FOREGROUND_LAYER 0x0001
#define LCD_BKLIGHT_PWM_FREQ 300
#define LCD_BKLIGHT_PWM_FREQ 300
#define LCD_FIRST_FRAME_BUFFER SDRAM_BANK_ADDR
#define LCD_SECOND_FRAME_BUFFER (SDRAM_BANK_ADDR + DISPLAY_BUFFER_SIZE)
#define LCD_BACKUP_FRAME_BUFFER (SDRAM_BANK_ADDR + 2*DISPLAY_BUFFER_SIZE)
#define LCD_DEFAULT_FRAME_BUFFER SDRAM_BANK_ADDR
#define FRAME_BUFFER_OFFSET ((uint32_t)0x100000)
uint32_t CurrentFrameBuffer = LCD_DEFAULT_FRAME_BUFFER;
uint32_t CurrentLayer = LCD_BACKGROUND_LAYER;
uint32_t CurrentFrameBuffer = LCD_FIRST_FRAME_BUFFER;
uint32_t CurrentLayer = LCD_FIRST_LAYER;
#define NRST_LOW() do { LCD_GPIO_NRST->BSRRH = LCD_GPIO_PIN_NRST; } while(0)
#define NRST_HIGH() do { LCD_GPIO_NRST->BSRRL = LCD_GPIO_PIN_NRST; } while(0)
@@ -193,13 +191,13 @@ void LCD_Init_LTDC(void)
/* Configure accumulated vertical back porch */
LTDC_InitStruct.LTDC_AccumulatedVBP = VBP;
/* Configure accumulated active width */
LTDC_InitStruct.LTDC_AccumulatedActiveW = LCD_PIXEL_WIDTH + HBP;
LTDC_InitStruct.LTDC_AccumulatedActiveW = LCD_W + HBP;
/* Configure accumulated active height */
LTDC_InitStruct.LTDC_AccumulatedActiveH = LCD_PIXEL_HEIGHT + VBP;
LTDC_InitStruct.LTDC_AccumulatedActiveH = LCD_H + VBP;
/* Configure total width */
LTDC_InitStruct.LTDC_TotalWidth = LCD_PIXEL_WIDTH + HBP + HFP;
LTDC_InitStruct.LTDC_TotalWidth = LCD_W + HBP + HFP;
/* Configure total height */
LTDC_InitStruct.LTDC_TotalHeigh = LCD_PIXEL_HEIGHT + VBP + VFP;
LTDC_InitStruct.LTDC_TotalHeigh = LCD_H + VBP + VFP;
// init ltdc
LTDC_Init(&LTDC_InitStruct);
@@ -240,9 +238,9 @@ void LCD_LayerInit()
Vertical start = vertical synchronization + vertical back porch = 4
Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */
LTDC_Layer_InitStruct.LTDC_HorizontalStart = HBP + 1;
LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_PIXEL_WIDTH + HBP);
LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_W + HBP);
LTDC_Layer_InitStruct.LTDC_VerticalStart = VBP + 1;;
LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_PIXEL_HEIGHT + VBP);
LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_H + VBP);
/* Pixel Format configuration*/
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
@@ -260,20 +258,20 @@ void LCD_LayerInit()
/* 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 = LCD_PIXEL_WIDTH
Active high width = LCD_W
number of bytes per pixel = 2 (pixel_format : RGB565)
*/
LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_PIXEL_WIDTH * 2) + 3);
LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_W * 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 = (LCD_PIXEL_WIDTH * 2);
LTDC_Layer_InitStruct.LTDC_CFBPitch = (LCD_W * 2);
/* Configure the number of lines */
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_PIXEL_HEIGHT;
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_H;
/* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_DEFAULT_FRAME_BUFFER;
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FIRST_FRAME_BUFFER;
/* Initialize LTDC layer 1 */
LTDC_LayerInit(LTDC_Layer1, &LTDC_Layer_InitStruct);
@@ -283,7 +281,7 @@ void LCD_LayerInit()
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;
/* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_DEFAULT_FRAME_BUFFER + FRAME_BUFFER_OFFSET;
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FIRST_FRAME_BUFFER + DISPLAY_BUFFER_SIZE;
/* Initialize LTDC layer 2 */
LTDC_LayerInit(LTDC_Layer2, &LTDC_Layer_InitStruct);
@@ -377,25 +375,21 @@ void LCD_Init(void)
*/
void LCD_SetLayer(uint32_t Layerx)
{
if (Layerx == LCD_BACKGROUND_LAYER)
if (Layerx == LCD_FIRST_LAYER)
{
CurrentFrameBuffer = LCD_DEFAULT_FRAME_BUFFER;
CurrentLayer = LCD_BACKGROUND_LAYER;
CurrentFrameBuffer = LCD_FIRST_FRAME_BUFFER;
CurrentLayer = LCD_FIRST_LAYER;
}
else
{
CurrentFrameBuffer = LCD_DEFAULT_FRAME_BUFFER + FRAME_BUFFER_OFFSET;
CurrentLayer = LCD_FOREGROUND_LAYER;
CurrentFrameBuffer = LCD_FIRST_FRAME_BUFFER + DISPLAY_BUFFER_SIZE;
CurrentLayer = LCD_SECOND_LAYER;
}
}
void LCD_Clear(uint16_t Color)
{
uint16_t *index ;
/* erase memory */
for (index = (uint16_t *)CurrentFrameBuffer; index < (uint16_t *)(CurrentFrameBuffer+(FRAME_BUFFER_OFFSET)); index++)
{
for (uint16_t * index = (uint16_t *)CurrentFrameBuffer; index < (uint16_t *)(CurrentFrameBuffer+DISPLAY_BUFFER_SIZE); index++) {
*index = Color;
}
}
@@ -408,12 +402,10 @@ void LCD_Clear(uint16_t Color)
*/
void LCD_SetTransparency(uint8_t transparency)
{
if (CurrentLayer == LCD_BACKGROUND_LAYER)
{
if (CurrentLayer == LCD_FIRST_LAYER) {
LTDC_LayerAlpha(LTDC_Layer1, transparency);
}
else
{
else {
LTDC_LayerAlpha(LTDC_Layer2, transparency);
}
LTDC_ReloadConfig(LTDC_IMReload);
@@ -429,19 +421,19 @@ void lcdInit(void)
LTDC_Cmd(ENABLE);
/* Set Background layer */
LCD_SetLayer(LCD_BACKGROUND_LAYER);
LCD_SetLayer(LCD_FIRST_LAYER);
LCD_Clear(0);
LCD_SetTransparency(0);
/* Set Foreground layer */
LCD_SetLayer(LCD_FOREGROUND_LAYER);
LCD_SetLayer(LCD_SECOND_LAYER);
LCD_Clear(0);
LCD_SetTransparency(255);
}
void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
{
uint32_t addr = CurrentFrameBuffer + 2*(LCD_PIXEL_WIDTH*y + x);
uint32_t addr = CurrentFrameBuffer + 2*(LCD_W*y + x);
uint16_t red = (0xF800 & color) >> 11;
uint16_t blue = 0x001F & color;
uint16_t green = (0x07E0 & color) >> 5;
@@ -456,7 +448,7 @@ void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, u
DMA2D_InitStruct.DMA2D_OutputRed = red;
DMA2D_InitStruct.DMA2D_OutputAlpha = 0x0F;
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = addr;
DMA2D_InitStruct.DMA2D_OutputOffset = (LCD_PIXEL_WIDTH - w);
DMA2D_InitStruct.DMA2D_OutputOffset = (LCD_W - w);
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
DMA2D_Init(&DMA2D_InitStruct);
@@ -468,12 +460,26 @@ void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, u
while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET);
}
void lcdStoreBackupBuffer()
{
for (uint16_t * src = (uint16_t *)CurrentFrameBuffer, * dest = (uint16_t *)LCD_BACKUP_FRAME_BUFFER; src < (uint16_t *)(CurrentFrameBuffer+DISPLAY_BUFFER_SIZE); src++, dest++) {
*dest = *src;
}
}
void lcdRestoreBackupBuffer()
{
for (uint16_t * dest = (uint16_t *)CurrentFrameBuffer, * src = (uint16_t *)LCD_BACKUP_FRAME_BUFFER; dest < (uint16_t *)(CurrentFrameBuffer+DISPLAY_BUFFER_SIZE); src++, dest++) {
*dest = *src;
}
}
void lcdRefresh()
{
LCD_SetTransparency(255);
if (CurrentLayer == LCD_BACKGROUND_LAYER)
LCD_SetLayer(LCD_FOREGROUND_LAYER);
if (CurrentLayer == LCD_FIRST_LAYER)
LCD_SetLayer(LCD_SECOND_LAYER);
else
LCD_SetLayer(LCD_BACKGROUND_LAYER);
LCD_SetLayer(LCD_FIRST_LAYER);
LCD_SetTransparency(0);
}
+69 -231
View File
@@ -331,21 +331,6 @@
*/
#define SDIO_SEND_IF_COND ((uint32_t)0x00000008)
/**
* @}
*/
/** @defgroup STM32F4_DISCOVERY_SDIO_SD_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32F4_DISCOVERY_SDIO_SD_Private_Variables
* @{
*/
static uint32_t CardType = SDIO_STD_CAPACITY_SD_CARD_V1_1;
static uint32_t CSD_Tab[4], CID_Tab[4], RCA = 0;
static uint8_t SDSTATUS_Tab[16];
@@ -357,14 +342,7 @@ SD_CardInfo SDCardInfo;
SDIO_InitTypeDef SDIO_InitStructure;
SDIO_CmdInitTypeDef SDIO_CmdInitStructure;
SDIO_DataInitTypeDef SDIO_DataInitStructure;
/**
* @}
*/
/** @defgroup STM32F4_DISCOVERY_SDIO_SD_Private_Function_Prototypes
* @{
*/
static SD_Error CmdError(void);
static SD_Error CmdResp1Error(uint8_t cmd);
static SD_Error CmdResp7Error(void);
@@ -440,7 +418,7 @@ void SD_LowLevel_Init(void)
/* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
@@ -498,7 +476,7 @@ void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize)
SDDMA_InitStructure.DMA_PeripheralBaseAddr = SD_SDIO_FIFO_ADDRESS;
SDDMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferSRC;
SDDMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
SDDMA_InitStructure.DMA_BufferSize = 0;
SDDMA_InitStructure.DMA_BufferSize = 1;
SDDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
SDDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
SDDMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
@@ -540,7 +518,7 @@ void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize)
SDDMA_InitStructure.DMA_PeripheralBaseAddr = SD_SDIO_FIFO_ADDRESS;
SDDMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferDST;
SDDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
SDDMA_InitStructure.DMA_BufferSize = 0;
SDDMA_InitStructure.DMA_BufferSize = 1;
SDDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
SDDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
SDDMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
@@ -712,13 +690,17 @@ uint8_t SD_Detect(void)
return status;
}
//---------------------------------------------------------------------------------------
//disable optimize
#define OPTIMIZE(level) __attribute__((optimize(level)))
/**
* @brief Enquires cards about their operating voltage and configures
* clock controls.
* @param None
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_PowerON(void)
OPTIMIZE("O0") SD_Error SD_PowerON(void)
{
__IO SD_Error errorstatus = SD_OK;
uint32_t response = 0, count = 0, validvoltage = 0;
@@ -865,7 +847,7 @@ SD_Error SD_PowerON(void)
* @param None
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_PowerOFF(void)
OPTIMIZE("O0") SD_Error SD_PowerOFF(void)
{
SD_Error errorstatus = SD_OK;
@@ -881,7 +863,7 @@ SD_Error SD_PowerOFF(void)
* @param None
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_InitializeCards(void)
OPTIMIZE("O0") SD_Error SD_InitializeCards(void)
{
SD_Error errorstatus = SD_OK;
uint16_t rca = 0x01;
@@ -970,7 +952,7 @@ SD_Error SD_InitializeCards(void)
* information.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
OPTIMIZE("O0") SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
{
SD_Error errorstatus = SD_OK;
uint8_t tmp = 0;
@@ -1061,7 +1043,7 @@ SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
/*!< Byte 10 */
tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
cardinfo->CardCapacity = (uint64_t)(cardinfo->SD_csd.DeviceSize + 1) * (uint64_t)(512 * 1024);
cardinfo->CardCapacity = ((uint64_t)cardinfo->SD_csd.DeviceSize + 1) * 512 * 1024;
cardinfo->CardBlockSize = 512;
}
@@ -1182,7 +1164,7 @@ SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
* @arg SDIO_BusWide_1b: 1-bit data transfer
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
OPTIMIZE("O0") SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
{
SD_Error errorstatus = SD_OK;
uint8_t tmp = 0;
@@ -1267,7 +1249,7 @@ SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
* @arg SDIO_BusWide_1b: 1-bit data transfer
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
OPTIMIZE("O0") SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
{
SD_Error errorstatus = SD_OK;
@@ -1326,7 +1308,7 @@ SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
* @param addr: Address of the Card to be selected.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_SelectDeselect(uint32_t addr)
OPTIMIZE("O0") SD_Error SD_SelectDeselect(uint32_t addr)
{
SD_Error errorstatus = SD_OK;
@@ -1357,7 +1339,7 @@ SD_Error SD_SelectDeselect(uint32_t addr)
* @param BlockSize: the SD card Data block size. The Block size should be 512.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
OPTIMIZE("O0") SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
{
SD_Error errorstatus = SD_OK;
#if defined (SD_POLLING_MODE)
@@ -1367,13 +1349,21 @@ SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
TransferError = SD_OK;
TransferEnd = 0;
StopCondition = 0;
DMAEndOfTransfer = 0;
SDIO->DCTRL = 0x0;
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
{
#if defined (SD_DMA_MODE)
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
#endif
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD) {
BlockSize = 512;
ReadAddr /= 512;
}
else {
ReadAddr *= 512;
}
/* Set Block Size for Card */
@@ -1464,10 +1454,6 @@ SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
/*!< Clear all the static flags */
SDIO_ClearFlag(SDIO_STATIC_FLAGS);
#elif defined (SD_DMA_MODE)
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
#endif
return(errorstatus);
@@ -1488,19 +1474,25 @@ SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
* @param NumberOfBlocks: number of blocks to be read.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
OPTIMIZE("O0") SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
{
SD_Error errorstatus = SD_OK;
TransferError = SD_OK;
TransferEnd = 0;
StopCondition = 1;
DMAEndOfTransfer = 0;
SDIO->DCTRL = 0x0;
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
{
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
SDIO_DMACmd(ENABLE);
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD) {
BlockSize = 512;
ReadAddr /= 512;
}
else {
ReadAddr *= 512;
}
/*!< Set Block Size for Card */
@@ -1541,71 +1533,6 @@ SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t Block
return(errorstatus);
}
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
return(errorstatus);
}
// FIXED Version where ReadAddr is in BLOCKS NOT BYTES, permits SDHC media >4GB
SD_Error SD_ReadMultiBlocksFIXED(uint8_t *readbuff, uint32_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
{
SD_Error errorstatus = SD_OK;
TransferError = SD_OK;
TransferEnd = 0;
StopCondition = 1;
SDIO->DCTRL = 0x0;
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
BlockSize = 512;
else
ReadAddr *= BlockSize; // Convert to Bytes for NON SDHC
/*!< Set Block Size for Card */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
if (SD_OK != errorstatus)
{
return(errorstatus);
}
SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
SDIO_DataConfig(&SDIO_DataInitStructure);
/*!< Send CMD18 READ_MULT_BLOCK with argument data address */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_MULT_BLOCK;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_READ_MULT_BLOCK);
if (errorstatus != SD_OK)
{
return(errorstatus);
}
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
return(errorstatus);
}
@@ -1617,7 +1544,7 @@ SD_Error SD_ReadMultiBlocksFIXED(uint8_t *readbuff, uint32_t ReadAddr, uint32_t
* @param None.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_WaitReadOperation(void)
OPTIMIZE("O0") SD_Error SD_WaitReadOperation(void)
{
SD_Error errorstatus = SD_OK;
uint32_t timeout;
@@ -1641,6 +1568,7 @@ SD_Error SD_WaitReadOperation(void)
if (StopCondition == 1)
{
errorstatus = SD_StopTransfer();
StopCondition = 0;
}
if ((timeout == 0) && (errorstatus == SD_OK))
@@ -1675,7 +1603,7 @@ SD_Error SD_WaitReadOperation(void)
* @param BlockSize: the SD card Data block size. The Block size should be 512.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize)
OPTIMIZE("O0") SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize)
{
SD_Error errorstatus = SD_OK;
@@ -1690,6 +1618,11 @@ SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSiz
SDIO->DCTRL = 0x0;
#if defined (SD_DMA_MODE)
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, BlockSize);
SDIO_DMACmd(ENABLE);
#endif
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
{
@@ -1784,10 +1717,6 @@ SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSiz
errorstatus = SD_START_BIT_ERR;
return(errorstatus);
}
#elif defined (SD_DMA_MODE)
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, BlockSize);
SDIO_DMACmd(ENABLE);
#endif
return(errorstatus);
@@ -1808,7 +1737,7 @@ SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSiz
* @param NumberOfBlocks: number of blocks to be written.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
OPTIMIZE("O0") SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
{
SD_Error errorstatus = SD_OK;
@@ -1818,6 +1747,10 @@ SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t Bl
SDIO->DCTRL = 0x0;
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_TXUNDERR | SDIO_IT_STBITERR, ENABLE);
SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));
SDIO_DMACmd(ENABLE);
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
{
BlockSize = 512;
@@ -1893,105 +1826,9 @@ SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t Bl
SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
SDIO_DataConfig(&SDIO_DataInitStructure);
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));
return(errorstatus);
}
// FIXED Version where WriteAddr is in BLOCKS NOT BYTES, permits SDHC media >4GB
SD_Error SD_WriteMultiBlocksFIXED(uint8_t *writebuff, uint32_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
{
SD_Error errorstatus = SD_OK;
TransferError = SD_OK;
TransferEnd = 0;
StopCondition = 1;
SDIO->DCTRL = 0x0;
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
BlockSize = 512;
else
WriteAddr *= BlockSize; // Convert to Bytes for NON SDHC
/* Set Block Size for Card */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
if (SD_OK != errorstatus)
{
return(errorstatus);
}
/*!< To improve performance */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) (RCA << 16);
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
if (errorstatus != SD_OK)
{
return(errorstatus);
}
/*!< To improve performance */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)NumberOfBlocks;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCK_COUNT;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_SET_BLOCK_COUNT);
if (errorstatus != SD_OK)
{
return(errorstatus);
}
/*!< Send CMD25 WRITE_MULT_BLOCK with argument data address */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)WriteAddr;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK);
if (SD_OK != errorstatus)
{
return(errorstatus);
}
SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
SDIO_DataConfig(&SDIO_DataInitStructure);
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));
return(errorstatus);
}
/**
* @brief This function waits until the SDIO DMA data transfer is finished.
@@ -2001,7 +1838,7 @@ SD_Error SD_WriteMultiBlocksFIXED(uint8_t *writebuff, uint32_t WriteAddr, uint32
* @param None.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_WaitWriteOperation(void)
OPTIMIZE("O0") SD_Error SD_WaitWriteOperation(void)
{
SD_Error errorstatus = SD_OK;
uint32_t timeout;
@@ -2025,6 +1862,7 @@ SD_Error SD_WaitWriteOperation(void)
if (StopCondition == 1)
{
errorstatus = SD_StopTransfer();
StopCondition = 0;
}
if ((timeout == 0) && (errorstatus == SD_OK))
@@ -2053,7 +1891,7 @@ SD_Error SD_WaitWriteOperation(void)
* - SD_TRANSFER_OK: No data transfer is acting
* - SD_TRANSFER_BUSY: Data transfer is acting
*/
SDTransferState SD_GetTransferState(void)
OPTIMIZE("O0") SDTransferState SD_GetTransferState(void)
{
if (SDIO->STA & (SDIO_FLAG_TXACT | SDIO_FLAG_RXACT))
{
@@ -2070,7 +1908,7 @@ SDTransferState SD_GetTransferState(void)
* @param None
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_StopTransfer(void)
OPTIMIZE("O0") SD_Error SD_StopTransfer(void)
{
SD_Error errorstatus = SD_OK;
@@ -2093,7 +1931,7 @@ SD_Error SD_StopTransfer(void)
* @param endaddr: the end address.
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
OPTIMIZE("O0") SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
{
SD_Error errorstatus = SD_OK;
uint32_t delay = 0;
@@ -2189,7 +2027,7 @@ SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
* status (Card Status register).
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_SendStatus(uint32_t *pcardstatus)
OPTIMIZE("O0") SD_Error SD_SendStatus(uint32_t *pcardstatus)
{
SD_Error errorstatus = SD_OK;
@@ -2224,7 +2062,7 @@ SD_Error SD_SendStatus(uint32_t *pcardstatus)
* (SD Status register).
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_SendSDStatus(uint32_t *psdstatus)
OPTIMIZE("O0") SD_Error SD_SendSDStatus(uint32_t *psdstatus)
{
SD_Error errorstatus = SD_OK;
uint32_t count = 0;
@@ -2341,7 +2179,7 @@ SD_Error SD_SendSDStatus(uint32_t *psdstatus)
* @param None
* @retval SD_Error: SD Card Error code.
*/
SD_Error SD_ProcessIRQ(void)
OPTIMIZE("O0") SD_Error SD_ProcessIRQ(void)
{
if (SDIO_GetITStatus(SDIO_IT_DATAEND) != RESET)
{
@@ -2386,7 +2224,7 @@ SD_Error SD_ProcessIRQ(void)
* @param None.
* @retval None.
*/
void SD_ProcessDMAIRQ(void)
OPTIMIZE("O0") void SD_ProcessDMAIRQ(void)
{
if(DMA2->LISR & SD_SDIO_DMA_FLAG_TCIF)
{
@@ -2400,7 +2238,7 @@ void SD_ProcessDMAIRQ(void)
* @param None
* @retval SD_Error: SD Card Error code.
*/
static SD_Error CmdError(void)
OPTIMIZE("O0") static SD_Error CmdError(void)
{
SD_Error errorstatus = SD_OK;
uint32_t timeout;
@@ -2429,7 +2267,7 @@ static SD_Error CmdError(void)
* @param None
* @retval SD_Error: SD Card Error code.
*/
static SD_Error CmdResp7Error(void)
OPTIMIZE("O0") static SD_Error CmdResp7Error(void)
{
SD_Error errorstatus = SD_OK;
uint32_t status;
@@ -2466,7 +2304,7 @@ static SD_Error CmdResp7Error(void)
* @param cmd: The sent command index.
* @retval SD_Error: SD Card Error code.
*/
static SD_Error CmdResp1Error(uint8_t cmd)
OPTIMIZE("O0") static SD_Error CmdResp1Error(uint8_t cmd)
{
SD_Error errorstatus = SD_OK;
uint32_t status;
@@ -2612,7 +2450,7 @@ static SD_Error CmdResp1Error(uint8_t cmd)
* @param None
* @retval SD_Error: SD Card Error code.
*/
static SD_Error CmdResp3Error(void)
OPTIMIZE("O0") static SD_Error CmdResp3Error(void)
{
SD_Error errorstatus = SD_OK;
uint32_t status;
@@ -2640,7 +2478,7 @@ static SD_Error CmdResp3Error(void)
* @param None
* @retval SD_Error: SD Card Error code.
*/
static SD_Error CmdResp2Error(void)
OPTIMIZE("O0") static SD_Error CmdResp2Error(void)
{
SD_Error errorstatus = SD_OK;
uint32_t status;
@@ -2678,7 +2516,7 @@ static SD_Error CmdResp2Error(void)
* address RCA.
* @retval SD_Error: SD Card Error code.
*/
static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca)
OPTIMIZE("O0") static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca)
{
SD_Error errorstatus = SD_OK;
uint32_t status;
@@ -2747,7 +2585,7 @@ static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca)
* This parameter can be: ENABLE or DISABLE.
* @retval SD_Error: SD Card Error code.
*/
static SD_Error SDEnWideBus(FunctionalState NewState)
OPTIMIZE("O0") static SD_Error SDEnWideBus(FunctionalState NewState)
{
SD_Error errorstatus = SD_OK;
@@ -2861,7 +2699,7 @@ static SD_Error SDEnWideBus(FunctionalState NewState)
* @param pstatus: pointer to the variable that will contain the SD card state.
* @retval SD_Error: SD Card Error code.
*/
static SD_Error IsCardProgramming(uint8_t *pstatus)
OPTIMIZE("O0") static SD_Error IsCardProgramming(uint8_t *pstatus)
{
SD_Error errorstatus = SD_OK;
__IO uint32_t respR1 = 0, status = 0;
@@ -3020,7 +2858,7 @@ static SD_Error IsCardProgramming(uint8_t *pstatus)
* @param pscr: pointer to the buffer that will contain the SCR value.
* @retval SD_Error: SD Card Error code.
*/
static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)
OPTIMIZE("O0") static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)
{
uint32_t index = 0;
SD_Error errorstatus = SD_OK;
@@ -3129,7 +2967,7 @@ static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)
* @param NumberOfBytes: number of bytes.
* @retval None
*/
uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes)
OPTIMIZE("O0") uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes)
{
uint8_t count = 0;
+2
View File
@@ -386,6 +386,8 @@ SD_Error SD_WaitWriteOperation(void);
}
#endif
extern SD_CardInfo SDCardInfo;
#endif /* __STM32F4_DISCOVERY_SDIO_SD_H */
/**
* @}
+1 -1
View File
@@ -43,7 +43,7 @@
* when FS core is used.
*******************************************************************************/
#ifndef USE_USB_OTG_FS
#define USE_USB_OTG_FS
#define USE_USB_OTG_FS // USB2.0 Full Speed == 12 Mbit
#endif /* USE_USB_OTG_FS */
#ifdef USE_USB_OTG_FS
+4 -4
View File
@@ -65,22 +65,22 @@
#if defined(BOOT)
#define USBD_PID 0x5720
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Bootloader"
#define USBD_PRODUCT_FS_STRING "FrSky Horus Bootloader"
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_INTERFACE_FS_STRING "MSC Interface"
#elif defined(USB_JOYSTICK)
#define USBD_PID 0x5710
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Joystick"
#define USBD_PRODUCT_FS_STRING "FrSky Horus Joystick"
#define USBD_CONFIGURATION_FS_STRING "HID Config"
#define USBD_INTERFACE_FS_STRING "HID Interface"
#elif defined(USB_SERIAL)
#define USBD_PID 0x5740 // do not change, this ID is used by the ST USB driver for Windows
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Serial Port"
#define USBD_PRODUCT_FS_STRING "FrSky Horus Serial Port"
#define USBD_CONFIGURATION_FS_STRING "VSP Config"
#define USBD_INTERFACE_FS_STRING "VSP Interface"
#elif defined(USB_MASS_STORAGE)
#define USBD_PID 0x5720
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Mass Storage"
#define USBD_PRODUCT_FS_STRING "FrSky Horus Mass Storage"
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_INTERFACE_FS_STRING "MSC Interface"
#endif
+2 -1
View File
@@ -31,7 +31,8 @@
#define __USB_DESC_H
/* Includes ------------------------------------------------------------------*/
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_def.h"
#include "usb_core.h"
#include "usbd_def.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
+17 -14
View File
@@ -191,20 +191,23 @@ int8_t STORAGE_Read (uint8_t lun,
uint32_t blk_addr,
uint16_t blk_len)
{
if (SD_ReadMultiBlocksFIXED(buf, blk_addr, BLOCKSIZE, blk_len) != 0) {
return -1;
for (int retry=0; retry<3; retry++) {
if (SD_ReadMultiBlocks(buf, blk_addr, BLOCKSIZE, blk_len) != 0) {
continue;
}
SDTransferState State;
SD_Error Status = SD_WaitReadOperation(); // Check if the Transfer is finished
while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if ((State == SD_TRANSFER_OK) && (Status == SD_OK)) {
return 0;
}
}
SDTransferState State;
SD_Error Status = SD_WaitReadOperation(); // Check if the Transfer is finished
while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK))
return -1;
return 0;
return -1;
}
/**
* @brief Write data to the medium
@@ -220,7 +223,7 @@ int8_t STORAGE_Write (uint8_t lun,
uint32_t blk_addr,
uint16_t blk_len)
{
if (SD_WriteMultiBlocksFIXED(buf, blk_addr, BLOCKSIZE, blk_len) != 0)
if (SD_WriteMultiBlocks(buf, blk_addr, BLOCKSIZE, blk_len) != 0)
return -1;
SDTransferState State;
-1
View File
@@ -81,7 +81,6 @@
/*-----------------------------------------------------------------------*/
#if !defined(BOOT)
static OS_MutexID ioMutex;
volatile int mutexCheck = 0;
int ff_cre_syncobj (BYTE vol, _SYNC_t *mutex)
{
+2 -2
View File
@@ -30,8 +30,8 @@
#include "usb_bsp.h"
#include "../Taranis/board_taranis.h"
#include "../Taranis/usbd_conf.h"
#include "board_taranis.h"
#include "usbd_conf.h"
extern uint32_t SystemCoreClock;
+1 -1
View File
@@ -34,7 +34,7 @@
*
*/
#include "../Taranis/board_taranis.h"
#include "board_taranis.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
int usbPlugged(void)
+1 -1
View File
@@ -34,7 +34,7 @@
extern "C" {
/* Includes ------------------------------------------------------------------*/
#include "../Taranis/usb_conf.h"
#include "usb_conf.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
+1 -1
View File
@@ -30,7 +30,7 @@
#define __USBD_CONF__H__
/* Includes ------------------------------------------------------------------*/
#include "../Taranis/usb_conf.h"
#include "usb_conf.h"
#define USBD_CFG_MAX_NUM 1
#define USBD_ITF_MAX_NUM 1
+3 -3
View File
@@ -27,12 +27,12 @@
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "usbd_desc.h"
#include "board_taranis.h"
#include "usbd_conf.h"
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_req.h"
#include "usbd_conf.h"
#include "usb_regs.h"
#include "board_taranis.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
@@ -47,9 +47,9 @@
*/
/* Includes ------------------------------------------------------------------*/
#include "../Taranis/usbd_desc.h"
#include "usbd_hid_core.h"
#include "usbd_req.h"
#include "usbd_desc.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
@@ -28,14 +28,14 @@
/* Includes ------------------------------------------------------------------*/
#include "../../opentx.h"
#include "../../thirdparty/FatFs/diskio.h"
#include "../Taranis/board_taranis.h"
#include "board_taranis.h"
#if defined(__cplusplus) && !defined(SIMU)
extern "C" {
#endif
#include "usbd_msc_mem.h"
#include "../Taranis/usb_conf.h"
#include "usb_conf.h"
#if defined(BOOT)
#define STORAGE_LUN_NBR 2
+23 -8
View File
@@ -716,7 +716,7 @@ namespace simu {
FATFS g_FATFS_Obj;
#endif
char *convertSimuPath(const char *path)
char * convertSimuPath(const char *path)
{
static char result[1024];
if (path[0] == '/' && strcmp(simuSdDirectory, "/") != 0)
@@ -975,11 +975,15 @@ FRESULT f_unlink (const TCHAR * name)
FRESULT f_rename(const TCHAR *oldname, const TCHAR *newname)
{
if (rename(oldname, newname) < 0) {
TRACE("f_rename(%s, %s) = error %d (%s)", oldname, newname, errno, strerror(errno));
char old[1024];
strcpy(old, convertSimuPath(oldname));
char * path = convertSimuPath(newname);
if (rename(old, path) < 0) {
TRACE("f_rename(%s, %s) = error %d (%s)", old, path, errno, strerror(errno));
return FR_INVALID_NAME;
}
TRACE("f_rename(%s, %s) = OK", oldname, newname);
TRACE("f_rename(%s, %s) = OK", old, path);
return FR_OK;
}
@@ -1226,8 +1230,8 @@ uint32_t sdGetSpeed()
#endif // #if defined(SIMU_DISKIO)
bool lcd_refresh = true;
display_t lcd_buf[DISPLAY_BUFFER_SIZE];
bool simuLcdRefresh = true;
display_t simuLcdBuf[DISPLAY_BUFFER_SIZE];
#if !defined(PCBFLAMENCO) && !defined(PCBHORUS)
void lcdSetRefVolt(uint8_t val)
@@ -1251,8 +1255,19 @@ void lcdRefresh()
TW8823_SendScreen();
#endif
memcpy(lcd_buf, displayBuf, sizeof(lcd_buf));
lcd_refresh = true;
memcpy(simuLcdBuf, displayBuf, sizeof(simuLcdBuf));
simuLcdRefresh = true;
}
display_t simuLcdBackupBuf[DISPLAY_BUFFER_SIZE];
void lcdStoreBackupBuffer()
{
memcpy(simuLcdBackupBuf, displayBuf, sizeof(simuLcdBackupBuf));
}
void lcdRestoreBackupBuffer()
{
memcpy(displayBuf, simuLcdBackupBuf, sizeof(displayBuf));
}
#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)