mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-25 17:25:10 +03:00
Reindentation of boot.cpp
This commit is contained in:
parent
68c270760c
commit
278218e7a0
1 changed files with 653 additions and 766 deletions
|
@ -45,7 +45,6 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Headers
|
* Headers
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
@ -55,30 +54,17 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef PCBTARANIS
|
#ifdef PCBTARANIS
|
||||||
#include "stm32f2xx.h"
|
|
||||||
#include "stm32f2xx_flash.h"
|
#include "stm32f2xx_flash.h"
|
||||||
#include "../targets/taranis/i2c.h"
|
|
||||||
#include "hal.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "usb_dcd_int.h"
|
|
||||||
#include "usb_bsp.h"
|
|
||||||
#include "../targets/taranis/usbd_desc.h"
|
|
||||||
#include "usbd_msc_core.h"
|
|
||||||
#include "usbd_usr.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "board_taranis.h"
|
#include "board_taranis.h"
|
||||||
#include "../pwr.h"
|
#include "../pwr.h"
|
||||||
#include "../lcd.h"
|
#include "../lcd.h"
|
||||||
#include "../keys.h"
|
#include "../keys.h"
|
||||||
|
|
||||||
#include "../FatFs/ff.h"
|
#include "../FatFs/ff.h"
|
||||||
#include "../FatFs/diskio.h"
|
#include "../FatFs/diskio.h"
|
||||||
|
|
||||||
#ifdef PCBTARANIS
|
#if defined(PCBTARANIS)
|
||||||
#define BOOT_KEY_UP KEY_PLUS
|
#define BOOT_KEY_UP KEY_PLUS
|
||||||
#define BOOT_KEY_DOWN KEY_MINUS
|
#define BOOT_KEY_DOWN KEY_MINUS
|
||||||
#define BOOT_KEY_LEFT KEY_MENU
|
#define BOOT_KEY_LEFT KEY_MENU
|
||||||
|
@ -89,16 +75,17 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// states
|
// states
|
||||||
#define ST_START 0
|
enum BootLoaderStates {
|
||||||
#define ST_DIR_CHECK 1
|
ST_START,
|
||||||
#define ST_OPEN_DIR 2
|
ST_DIR_CHECK,
|
||||||
#define ST_FILE_LIST 3
|
ST_OPEN_DIR,
|
||||||
#define ST_FLASH_CHECK 4
|
ST_FILE_LIST,
|
||||||
#define ST_FLASHING 5
|
ST_FLASH_CHECK,
|
||||||
#define ST_FLASH_DONE 6
|
ST_FLASHING,
|
||||||
#define ST_USB 10
|
ST_FLASH_DONE,
|
||||||
#define ST_REBOOT 11
|
ST_USB = 10,
|
||||||
|
ST_REBOOT = 11,
|
||||||
|
};
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Local variables
|
* Local variables
|
||||||
|
@ -122,7 +109,6 @@ uint32_t Valid ;
|
||||||
|
|
||||||
uint32_t FlashSize;
|
uint32_t FlashSize;
|
||||||
|
|
||||||
|
|
||||||
uint32_t FlashBlocked = 1;
|
uint32_t FlashBlocked = 1;
|
||||||
uint32_t LockBits;
|
uint32_t LockBits;
|
||||||
|
|
||||||
|
@ -132,12 +118,12 @@ UINT BlockCount ;
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
extern int32_t EblockAddress;
|
extern int32_t EblockAddress;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint32_t EepromBlocked;
|
extern uint32_t EepromBlocked;
|
||||||
|
|
||||||
extern void init_spi(void);
|
extern void init_spi(void);
|
||||||
extern void writeBlock(void);
|
extern void writeBlock(void);
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Global functions
|
* Global functions
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
@ -181,16 +167,13 @@ void delay2ms()
|
||||||
|
|
||||||
uint32_t isFirmwareStart(uint32_t *block)
|
uint32_t isFirmwareStart(uint32_t *block)
|
||||||
{
|
{
|
||||||
if ( ( block[0] & 0xFFFC0000 ) != 0x20000000 )
|
if ((block[0] & 0xFFFC0000) != 0x20000000) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( ( block[1] & 0xFFF00000 ) != 0x08000000 )
|
if ((block[1] & 0xFFF00000) != 0x08000000) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( ( block[2] & 0xFFF00000 ) != 0x08000000 )
|
if ((block[2] & 0xFFF00000) != 0x08000000) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -216,12 +199,10 @@ uint32_t isFirmwareStart( uint32_t *block )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
|
|
||||||
uint32_t (*IAP_Function)(uint32_t, uint32_t);
|
uint32_t (*IAP_Function)(uint32_t, uint32_t);
|
||||||
|
|
||||||
|
|
||||||
uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
|
uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
|
||||||
{
|
{
|
||||||
uint32_t FlashSectorNum;
|
uint32_t FlashSectorNum;
|
||||||
|
@ -269,7 +250,6 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t readLockBits()
|
uint32_t readLockBits()
|
||||||
{
|
{
|
||||||
// Always initialise this here, setting a default doesn't seem to work
|
// Always initialise this here, setting a default doesn't seem to work
|
||||||
|
@ -282,7 +262,6 @@ uint32_t readLockBits()
|
||||||
return EFC->EEFC_FRR;
|
return EFC->EEFC_FRR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void clearLockBits()
|
void clearLockBits()
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -385,14 +364,12 @@ void init_hw_timer()
|
||||||
TIM13->CR1 = 1;
|
TIM13->CR1 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// delay in units of 0.1 uS up to 6.5535 mS
|
// delay in units of 0.1 uS up to 6.5535 mS
|
||||||
void hw_delay(uint16_t time)
|
void hw_delay(uint16_t time)
|
||||||
{
|
{
|
||||||
TIM13->CNT = 0;
|
TIM13->CNT = 0;
|
||||||
TIM13->EGR = 1; // Re-start counter
|
TIM13->EGR = 1; // Re-start counter
|
||||||
while ( TIM13->CNT < time )
|
while ( TIM13->CNT < time) {
|
||||||
{
|
|
||||||
// wait
|
// wait
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,8 +391,7 @@ void unlockFlash()
|
||||||
|
|
||||||
void waitFlashIdle()
|
void waitFlashIdle()
|
||||||
{
|
{
|
||||||
while (FLASH->SR & FLASH_FLAG_BSY)
|
while (FLASH->SR & FLASH_FLAG_BSY) {
|
||||||
{
|
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,52 +420,41 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if ( (uint32_t) address == 0x08008000 )
|
if ((uint32_t) address == 0x08008000) {
|
||||||
{
|
if (isFirmwareStart(buffer)) {
|
||||||
if ( isFirmwareStart( buffer) )
|
|
||||||
{
|
|
||||||
FlashBlocked = 0;
|
FlashBlocked = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
FlashBlocked = 1;
|
FlashBlocked = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( FlashBlocked )
|
if (FlashBlocked) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (uint32_t) address == 0x08008000 )
|
if ((uint32_t) address == 0x08008000) {
|
||||||
{
|
|
||||||
eraseSector(2);
|
eraseSector(2);
|
||||||
}
|
}
|
||||||
if ( (uint32_t) address == 0x0800C000 )
|
if ((uint32_t) address == 0x0800C000) {
|
||||||
{
|
|
||||||
eraseSector(3);
|
eraseSector(3);
|
||||||
}
|
}
|
||||||
if ( (uint32_t) address == 0x08010000 )
|
if ((uint32_t) address == 0x08010000) {
|
||||||
{
|
|
||||||
eraseSector(4);
|
eraseSector(4);
|
||||||
}
|
}
|
||||||
if ( (uint32_t) address == 0x08020000 )
|
if ((uint32_t) address == 0x08020000) {
|
||||||
{
|
|
||||||
eraseSector(5);
|
eraseSector(5);
|
||||||
}
|
}
|
||||||
if ( (uint32_t) address == 0x08040000 )
|
if ((uint32_t) address == 0x08040000) {
|
||||||
{
|
|
||||||
eraseSector(6);
|
eraseSector(6);
|
||||||
}
|
}
|
||||||
if ( (uint32_t) address == 0x08060000 )
|
if ((uint32_t) address == 0x08060000) {
|
||||||
{
|
|
||||||
eraseSector(7);
|
eraseSector(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now program the 256 bytes
|
// Now program the 256 bytes
|
||||||
|
|
||||||
for (i = 0 ; i < 64 ; i += 1 )
|
for (i = 0; i < 64; i += 1) {
|
||||||
{
|
|
||||||
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
|
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
|
||||||
be done by word */
|
be done by word */
|
||||||
|
|
||||||
|
@ -507,8 +472,7 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
|
||||||
FLASH->CR &= (~FLASH_CR_PG);
|
FLASH->CR &= (~FLASH_CR_PG);
|
||||||
|
|
||||||
/* Check the written value */
|
/* Check the written value */
|
||||||
if ( *address != *buffer )
|
if (*address != *buffer) {
|
||||||
{
|
|
||||||
/* Flash content doesn't match SRAM content */
|
/* Flash content doesn't match SRAM content */
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -521,7 +485,6 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
uint8_t *cpystr(uint8_t *dest, uint8_t *source)
|
uint8_t *cpystr(uint8_t *dest, uint8_t *source)
|
||||||
{
|
{
|
||||||
while ((*dest++ = *source++))
|
while ((*dest++ = *source++))
|
||||||
|
@ -529,43 +492,34 @@ uint8_t *cpystr( uint8_t *dest, uint8_t *source )
|
||||||
return dest - 1;
|
return dest - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FRESULT readBinDir(DIR *dj, FILINFO *fno)
|
FRESULT readBinDir(DIR *dj, FILINFO *fno)
|
||||||
{
|
{
|
||||||
FRESULT fr;
|
FRESULT fr;
|
||||||
uint32_t loop;
|
uint32_t loop;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
loop = 0;
|
loop = 0;
|
||||||
fr = f_readdir(dj, fno); // First entry
|
fr = f_readdir(dj, fno); // First entry
|
||||||
|
|
||||||
if ( fr != FR_OK || fno->fname[0] == 0 )
|
if (fr != FR_OK || fno->fname[0] == 0) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( *fno->lfname == 0 )
|
if (*fno->lfname == 0) {
|
||||||
{
|
|
||||||
cpystr((uint8_t *) fno->lfname, (uint8_t *) fno->fname); // Copy 8.3 name
|
cpystr((uint8_t *) fno->lfname, (uint8_t *) fno->fname); // Copy 8.3 name
|
||||||
}
|
}
|
||||||
int32_t len = strlen(fno->lfname) - 4;
|
int32_t len = strlen(fno->lfname) - 4;
|
||||||
if ( len < 0 )
|
if (len < 0) {
|
||||||
{
|
|
||||||
loop = 1;
|
loop = 1;
|
||||||
}
|
}
|
||||||
if ( fno->lfname[len] != '.' )
|
if (fno->lfname[len] != '.') {
|
||||||
{
|
|
||||||
loop = 1;
|
loop = 1;
|
||||||
}
|
}
|
||||||
if ( ( fno->lfname[len+1] != 'b' ) && ( fno->lfname[len+1] != 'B' ) )
|
if ((fno->lfname[len + 1] != 'b') && (fno->lfname[len + 1] != 'B')) {
|
||||||
{
|
|
||||||
loop = 1;
|
loop = 1;
|
||||||
}
|
}
|
||||||
if ( ( fno->lfname[len+2] != 'i' ) && ( fno->lfname[len+2] != 'I' ) )
|
if ((fno->lfname[len + 2] != 'i') && (fno->lfname[len + 2] != 'I')) {
|
||||||
{
|
|
||||||
loop = 1;
|
loop = 1;
|
||||||
}
|
}
|
||||||
if ( ( fno->lfname[len+3] != 'n' ) && ( fno->lfname[len+3] != 'N' ) )
|
if ((fno->lfname[len + 3] != 'n') && (fno->lfname[len + 3] != 'N')) {
|
||||||
{
|
|
||||||
loop = 1;
|
loop = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +527,6 @@ FRESULT readBinDir( DIR *dj, FILINFO *fno )
|
||||||
return fr;
|
return fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t fillNames(uint32_t index)
|
uint32_t fillNames(uint32_t index)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -584,23 +537,19 @@ uint32_t fillNames( uint32_t index )
|
||||||
fr = f_readdir(&Dj, &Finfo); // Skip .
|
fr = f_readdir(&Dj, &Finfo); // Skip .
|
||||||
fr = f_readdir(&Dj, &Finfo); // Skip ..
|
fr = f_readdir(&Dj, &Finfo); // Skip ..
|
||||||
i = 0;
|
i = 0;
|
||||||
while ( i <= index )
|
while (i <= index) {
|
||||||
{
|
|
||||||
fr = readBinDir(&Dj, &Finfo); // First entry
|
fr = readBinDir(&Dj, &Finfo); // First entry
|
||||||
FileSize[0] = Finfo.fsize;
|
FileSize[0] = Finfo.fsize;
|
||||||
i += 1;
|
i += 1;
|
||||||
if ( fr == FR_NO_FILE)
|
if (fr == FR_NO_FILE) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( i = 1 ; i < 7 ; i += 1 )
|
for (i = 1; i < 7; i += 1) {
|
||||||
{
|
|
||||||
Finfo.lfname = Filenames[i];
|
Finfo.lfname = Filenames[i];
|
||||||
fr = readBinDir(&Dj, &Finfo); // First entry
|
fr = readBinDir(&Dj, &Finfo); // First entry
|
||||||
FileSize[i] = Finfo.fsize;
|
FileSize[i] = Finfo.fsize;
|
||||||
if ( fr != FR_OK || Finfo.fname[0] == 0 )
|
if (fr != FR_OK || Finfo.fname[0] == 0) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -609,35 +558,31 @@ uint32_t fillNames( uint32_t index )
|
||||||
|
|
||||||
FRESULT openFirmwareFile(uint32_t index)
|
FRESULT openFirmwareFile(uint32_t index)
|
||||||
{
|
{
|
||||||
cpystr( cpystr( (uint8_t *)FlashFilename, (uint8_t *)"\\firmware\\" ), (uint8_t *)Filenames[index] ) ;
|
cpystr(cpystr((uint8_t *) FlashFilename, (uint8_t *) "\\firmware\\"),
|
||||||
|
(uint8_t *) Filenames[index]);
|
||||||
f_open(&FlashFile, FlashFilename, FA_READ);
|
f_open(&FlashFile, FlashFilename, FA_READ);
|
||||||
f_lseek(&FlashFile, 32768);
|
f_lseek(&FlashFile, 32768);
|
||||||
return f_read(&FlashFile, (BYTE *) Block_buffer, 4096, &BlockCount);
|
return f_read(&FlashFile, (BYTE *) Block_buffer, 4096, &BlockCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t flashFile(uint32_t index)
|
uint8_t flashFile(uint32_t index)
|
||||||
{
|
{
|
||||||
FRESULT fr;
|
FRESULT fr;
|
||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_putsLeft(0, "\005Flash File");
|
lcd_putsLeft(0, "\005Flash File");
|
||||||
if ( Valid == 0 )
|
if (Valid == 0) {
|
||||||
{
|
|
||||||
// Validate file here
|
// Validate file here
|
||||||
// return 3 if invalid
|
// return 3 if invalid
|
||||||
fr = openFirmwareFile(index);
|
fr = openFirmwareFile(index);
|
||||||
fr = f_close(&FlashFile);
|
fr = f_close(&FlashFile);
|
||||||
|
|
||||||
Valid = 1;
|
Valid = 1;
|
||||||
if ( isFirmwareStart( Block_buffer ) == 0 )
|
if (isFirmwareStart(Block_buffer) == 0) {
|
||||||
{
|
|
||||||
Valid = 2;
|
Valid = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( Valid == 2 )
|
if (Valid == 2) {
|
||||||
{
|
|
||||||
lcd_putsLeft(3 * FH, "NOT A VALID FIRMWARE");
|
lcd_putsLeft(3 * FH, "NOT A VALID FIRMWARE");
|
||||||
#ifdef PCBTARANIS
|
#ifdef PCBTARANIS
|
||||||
lcd_putsLeft(6 * FH, "\015[EXIT]");
|
lcd_putsLeft(6 * FH, "\015[EXIT]");
|
||||||
|
@ -645,8 +590,7 @@ uint8_t flashFile( uint32_t index )
|
||||||
lcd_putsLeft( 6*FH,"\007[EXIT]");
|
lcd_putsLeft( 6*FH,"\007[EXIT]");
|
||||||
#endif
|
#endif
|
||||||
uint8_t event = getEvent();
|
uint8_t event = getEvent();
|
||||||
if ( event == EVT_KEY_FIRST(BOOT_KEY_EXIT) )
|
if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT)) {
|
||||||
{
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
return 4; //
|
return 4; //
|
||||||
|
@ -663,24 +607,20 @@ uint8_t flashFile( uint32_t index )
|
||||||
|
|
||||||
uint8_t event = getEvent();
|
uint8_t event = getEvent();
|
||||||
|
|
||||||
if ( event == EVT_KEY_FIRST(BOOT_KEY_MENU) )
|
if (event == EVT_KEY_FIRST(BOOT_KEY_MENU)) {
|
||||||
{
|
|
||||||
fr = openFirmwareFile(index);
|
fr = openFirmwareFile(index);
|
||||||
FirmwareSize = FileSize[index];
|
FirmwareSize = FileSize[index];
|
||||||
if ( fr != FR_OK )
|
if (fr != FR_OK) {
|
||||||
{
|
|
||||||
return 4; // File open error
|
return 4; // File open error
|
||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if ( event == EVT_KEY_FIRST(BOOT_KEY_EXIT) )
|
if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT)) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern Key keys[];
|
extern Key keys[];
|
||||||
|
|
||||||
static uint32_t PowerUpDelay;
|
static uint32_t PowerUpDelay;
|
||||||
|
@ -780,22 +720,18 @@ extern uint8_t OptrexDisplay ;
|
||||||
usbStart();
|
usbStart();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
usbMassStorage();
|
usbMassStorage();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
|
|
||||||
if ( Tenms )
|
if (Tenms) {
|
||||||
{
|
|
||||||
wdt_reset(); // Retrigger hardware watchdog
|
wdt_reset(); // Retrigger hardware watchdog
|
||||||
|
|
||||||
if ( EE_timer )
|
if (EE_timer) {
|
||||||
{
|
if (--EE_timer == 0) {
|
||||||
if ( --EE_timer == 0)
|
|
||||||
{
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
writeBlock();
|
writeBlock();
|
||||||
#endif
|
#endif
|
||||||
|
@ -809,21 +745,18 @@ extern uint8_t OptrexDisplay ;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( usbPlugged() )
|
if (usbPlugged()) {
|
||||||
{
|
|
||||||
state = ST_USB;
|
state = ST_USB;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( state == ST_USB )
|
if (state == ST_USB) {
|
||||||
{
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
lcd_putsLeft( 3*FH, "\010BUSY" );
|
lcd_putsLeft( 3*FH, "\010BUSY" );
|
||||||
#endif
|
#endif
|
||||||
#ifdef PCBTARANIS
|
#ifdef PCBTARANIS
|
||||||
lcd_putsLeft(3 * FH, "\016BUSY");
|
lcd_putsLeft(3 * FH, "\016BUSY");
|
||||||
#endif
|
#endif
|
||||||
if ( usbPlugged() == 0 )
|
if (usbPlugged() == 0) {
|
||||||
{
|
|
||||||
state = ST_START;
|
state = ST_START;
|
||||||
}
|
}
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
|
@ -834,34 +767,27 @@ extern uint8_t OptrexDisplay ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( state == ST_START )
|
if (state == ST_START) {
|
||||||
{
|
|
||||||
sdInit();
|
sdInit();
|
||||||
fr = FR_OK;
|
fr = FR_OK;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
fr = FR_OK;
|
fr = FR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fr == FR_OK)
|
if (fr == FR_OK) {
|
||||||
{
|
if (state == ST_START) {
|
||||||
if ( state == ST_START )
|
|
||||||
{
|
|
||||||
state = ST_DIR_CHECK;
|
state = ST_DIR_CHECK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state == ST_DIR_CHECK )
|
if (state == ST_DIR_CHECK) {
|
||||||
{
|
|
||||||
fr = f_chdir("/firmware");
|
fr = f_chdir("/firmware");
|
||||||
if ( fr == FR_OK )
|
if (fr == FR_OK) {
|
||||||
{
|
|
||||||
state = ST_OPEN_DIR;
|
state = ST_OPEN_DIR;
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state == ST_DIR_CHECK )
|
if (state == ST_DIR_CHECK) {
|
||||||
{
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
lcd_putsLeft( 2*FH, "\005No Firmware" );
|
lcd_putsLeft( 2*FH, "\005No Firmware" );
|
||||||
#endif
|
#endif
|
||||||
|
@ -869,11 +795,9 @@ extern uint8_t OptrexDisplay ;
|
||||||
lcd_putsLeft(2 * FH, "\013No Firmware");
|
lcd_putsLeft(2 * FH, "\013No Firmware");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if ( state == ST_OPEN_DIR )
|
if (state == ST_OPEN_DIR) {
|
||||||
{
|
|
||||||
fr = f_opendir(&Dj, ".");
|
fr = f_opendir(&Dj, ".");
|
||||||
if ( fr == FR_OK )
|
if (fr == FR_OK) {
|
||||||
{
|
|
||||||
state = ST_FILE_LIST;
|
state = ST_FILE_LIST;
|
||||||
index = 0;
|
index = 0;
|
||||||
nameCount = fillNames(0);
|
nameCount = fillNames(0);
|
||||||
|
@ -881,110 +805,90 @@ extern uint8_t OptrexDisplay ;
|
||||||
vpos = 0;
|
vpos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state == ST_FILE_LIST )
|
if (state == ST_FILE_LIST) {
|
||||||
{
|
|
||||||
uint32_t limit = 6;
|
uint32_t limit = 6;
|
||||||
if ( nameCount < limit )
|
if (nameCount < limit) {
|
||||||
{
|
|
||||||
limit = nameCount;
|
limit = nameCount;
|
||||||
}
|
}
|
||||||
maxhsize = 0;
|
maxhsize = 0;
|
||||||
for ( i = 0 ; i < limit ; i += 1 )
|
for (i = 0; i < limit; i += 1) {
|
||||||
{
|
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
x = strlen(Filenames[i]);
|
x = strlen(Filenames[i]);
|
||||||
if ( x > maxhsize )
|
if (x > maxhsize) {
|
||||||
{
|
|
||||||
maxhsize = x;
|
maxhsize = x;
|
||||||
}
|
}
|
||||||
if ( x > DISPLAY_CHAR_WIDTH )
|
if (x > DISPLAY_CHAR_WIDTH) {
|
||||||
{
|
if ((hpos + DISPLAY_CHAR_WIDTH) > x) {
|
||||||
if ( ( hpos + DISPLAY_CHAR_WIDTH ) > x )
|
|
||||||
{
|
|
||||||
x = x - DISPLAY_CHAR_WIDTH;
|
x = x - DISPLAY_CHAR_WIDTH;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
x = hpos;
|
x = hpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
lcd_putsnAtt( 0, 16+FH*i, &Filenames[i][x], DISPLAY_CHAR_WIDTH, 0 ) ;
|
lcd_putsnAtt(0, 16 + FH * i, &Filenames[i][x], DISPLAY_CHAR_WIDTH,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
uint8_t event = getEvent();
|
uint8_t event = getEvent();
|
||||||
|
|
||||||
if ( ( event == EVT_KEY_REPT(BOOT_KEY_DOWN) ) || event == EVT_KEY_FIRST(BOOT_KEY_DOWN) )
|
if ((event == EVT_KEY_REPT(BOOT_KEY_DOWN))
|
||||||
{
|
|| event == EVT_KEY_FIRST(BOOT_KEY_DOWN)) {
|
||||||
if ( vpos < limit-1 )
|
if (vpos < limit - 1) {
|
||||||
{
|
|
||||||
vpos += 1;
|
vpos += 1;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (nameCount > limit) {
|
||||||
if ( nameCount > limit )
|
|
||||||
{
|
|
||||||
index += 1;
|
index += 1;
|
||||||
nameCount = fillNames(index);
|
nameCount = fillNames(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ( event == EVT_KEY_REPT(BOOT_KEY_UP)) || ( event == EVT_KEY_FIRST(BOOT_KEY_UP) ) )
|
if ((event == EVT_KEY_REPT(BOOT_KEY_UP))
|
||||||
{
|
|| (event == EVT_KEY_FIRST(BOOT_KEY_UP))) {
|
||||||
if ( vpos > 0 )
|
if (vpos > 0) {
|
||||||
{
|
|
||||||
vpos -= 1;
|
vpos -= 1;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (index) {
|
||||||
if ( index )
|
|
||||||
{
|
|
||||||
index -= 1;
|
index -= 1;
|
||||||
nameCount = fillNames(index);
|
nameCount = fillNames(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ( event == EVT_KEY_REPT(BOOT_KEY_RIGHT)) || ( event == EVT_KEY_FIRST(BOOT_KEY_RIGHT) ) )
|
if ((event == EVT_KEY_REPT(BOOT_KEY_RIGHT))
|
||||||
{
|
|| (event == EVT_KEY_FIRST(BOOT_KEY_RIGHT))) {
|
||||||
if ( hpos + DISPLAY_CHAR_WIDTH < maxhsize )
|
if (hpos + DISPLAY_CHAR_WIDTH < maxhsize) {
|
||||||
{
|
|
||||||
hpos += 1;
|
hpos += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ( event == EVT_KEY_REPT(BOOT_KEY_LEFT)) || ( event == EVT_KEY_FIRST(BOOT_KEY_LEFT) ) )
|
if ((event == EVT_KEY_REPT(BOOT_KEY_LEFT))
|
||||||
{
|
|| (event == EVT_KEY_FIRST(BOOT_KEY_LEFT))) {
|
||||||
if ( hpos )
|
if (hpos) {
|
||||||
{
|
|
||||||
hpos -= 1;
|
hpos -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( event == EVT_KEY_LONG(BOOT_KEY_MENU) )
|
if (event == EVT_KEY_LONG(BOOT_KEY_MENU)) {
|
||||||
{
|
|
||||||
// Select file to flash
|
// Select file to flash
|
||||||
state = ST_FLASH_CHECK;
|
state = ST_FLASH_CHECK;
|
||||||
Valid = 0;
|
Valid = 0;
|
||||||
}
|
}
|
||||||
if ( event == EVT_KEY_LONG(BOOT_KEY_EXIT) )
|
if (event == EVT_KEY_LONG(BOOT_KEY_EXIT)) {
|
||||||
{
|
|
||||||
state = ST_REBOOT;
|
state = ST_REBOOT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcd_invert_line(2 + vpos);
|
lcd_invert_line(2 + vpos);
|
||||||
// lcd_char_inverse( 0, 2*FH+FH*vpos, DISPLAY_CHAR_WIDTH*FW, 0 ) ;
|
// lcd_char_inverse( 0, 2*FH+FH*vpos, DISPLAY_CHAR_WIDTH*FW, 0 ) ;
|
||||||
}
|
}
|
||||||
if ( state == ST_FLASH_CHECK )
|
if (state == ST_FLASH_CHECK) {
|
||||||
{
|
|
||||||
i = flashFile(vpos);
|
i = flashFile(vpos);
|
||||||
FirmwareSize = FileSize[vpos] - 32768;
|
FirmwareSize = FileSize[vpos] - 32768;
|
||||||
if ( i == 1 )
|
if (i == 1) {
|
||||||
{
|
|
||||||
state = ST_FILE_LIST; // Canceled
|
state = ST_FILE_LIST; // Canceled
|
||||||
}
|
}
|
||||||
if ( i == 2 )
|
if (i == 2) {
|
||||||
{
|
|
||||||
#ifdef PCBSKY
|
#ifdef PCBSKY
|
||||||
firmwareAddress = 0x00408000;
|
firmwareAddress = 0x00408000;
|
||||||
#endif
|
#endif
|
||||||
|
@ -994,28 +898,23 @@ extern uint8_t OptrexDisplay ;
|
||||||
firmwareWritten = 0;
|
firmwareWritten = 0;
|
||||||
state = ST_FLASHING; // confirmed
|
state = ST_FLASHING; // confirmed
|
||||||
}
|
}
|
||||||
if ( i == 3 )
|
if (i == 3) {
|
||||||
{
|
|
||||||
// Invalid file
|
// Invalid file
|
||||||
state = ST_FILE_LIST; // Canceled
|
state = ST_FILE_LIST; // Canceled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state == ST_FLASHING )
|
if (state == ST_FLASHING) {
|
||||||
{
|
|
||||||
// Commit to flashing
|
// Commit to flashing
|
||||||
uint32_t blockOffset = 0;
|
uint32_t blockOffset = 0;
|
||||||
lcd_putsLeft(3 * FH, "Flashing");
|
lcd_putsLeft(3 * FH, "Flashing");
|
||||||
while ( BlockCount )
|
while (BlockCount) {
|
||||||
{
|
|
||||||
program((uint32_t *) firmwareAddress, &Block_buffer[blockOffset]);// size is 256 bytes
|
program((uint32_t *) firmwareAddress, &Block_buffer[blockOffset]);// size is 256 bytes
|
||||||
blockOffset += 64; // 32-bit words (256 bytes)
|
blockOffset += 64; // 32-bit words (256 bytes)
|
||||||
firmwareAddress += 256;
|
firmwareAddress += 256;
|
||||||
if ( BlockCount > 256 )
|
if (BlockCount > 256) {
|
||||||
{
|
|
||||||
BlockCount -= 256;
|
BlockCount -= 256;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
BlockCount = 0;
|
BlockCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1024,13 +923,11 @@ extern uint8_t OptrexDisplay ;
|
||||||
lcd_hline(0, 5 * FH - 1, width + 1);
|
lcd_hline(0, 5 * FH - 1, width + 1);
|
||||||
lcd_hline(0, 6 * FH, width + 1);
|
lcd_hline(0, 6 * FH, width + 1);
|
||||||
lcd_vline(width, 5 * FH, 8);
|
lcd_vline(width, 5 * FH, 8);
|
||||||
for ( i = 0 ; i < firmwareWritten ; i += 1 )
|
for (i = 0; i < firmwareWritten; i += 1) {
|
||||||
{
|
|
||||||
lcd_vline(i, 5 * FH, 8);
|
lcd_vline(i, 5 * FH, 8);
|
||||||
}
|
}
|
||||||
fr = f_read(&FlashFile, (BYTE *) Block_buffer, 4096, &BlockCount);
|
fr = f_read(&FlashFile, (BYTE *) Block_buffer, 4096, &BlockCount);
|
||||||
if ( BlockCount == 0 )
|
if (BlockCount == 0) {
|
||||||
{
|
|
||||||
state = ST_FLASH_DONE;
|
state = ST_FLASH_DONE;
|
||||||
}
|
}
|
||||||
if (firmwareWritten > FlashSize / 4 - 9)// (127-8, or 63-8) 4K blocks
|
if (firmwareWritten > FlashSize / 4 - 9)// (127-8, or 63-8) 4K blocks
|
||||||
|
@ -1038,12 +935,10 @@ extern uint8_t OptrexDisplay ;
|
||||||
state = ST_FLASH_DONE; // Backstop
|
state = ST_FLASH_DONE; // Backstop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state == ST_FLASH_DONE )
|
if (state == ST_FLASH_DONE) {
|
||||||
{
|
|
||||||
uint8_t event = getEvent();
|
uint8_t event = getEvent();
|
||||||
lcd_putsLeft(3 * FH, "Flashing Complete");
|
lcd_putsLeft(3 * FH, "Flashing Complete");
|
||||||
if ( event == EVT_KEY_FIRST(BOOT_KEY_EXIT) )
|
if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT)) {
|
||||||
{
|
|
||||||
state = ST_FILE_LIST;
|
state = ST_FILE_LIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1058,33 +953,26 @@ extern uint8_t OptrexDisplay ;
|
||||||
{
|
{
|
||||||
PowerUpDelay += 1;
|
PowerUpDelay += 1;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
sdPoll10ms();
|
sdPoll10ms();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((state < ST_FLASH_CHECK) || (state == ST_FLASH_DONE))
|
if ((state < ST_FLASH_CHECK) || (state == ST_FLASH_DONE)) {
|
||||||
{
|
|
||||||
if (pwrCheck() == e_power_off) {
|
if (pwrCheck() == e_power_off) {
|
||||||
pwrOff();
|
pwrOff();
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// Wait for power to go off
|
// Wait for power to go off
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state < ST_FILE_LIST )
|
if (state < ST_FILE_LIST) {
|
||||||
{
|
if (getEvent() == EVT_KEY_LONG(BOOT_KEY_EXIT)) {
|
||||||
if ( getEvent() == EVT_KEY_LONG(BOOT_KEY_EXIT) )
|
|
||||||
{
|
|
||||||
state = ST_REBOOT;
|
state = ST_REBOOT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( state == ST_REBOOT )
|
if (state == ST_REBOOT) {
|
||||||
{
|
if ((~readKeys() & 0x7E) == 0) {
|
||||||
if ( (~readKeys() & 0x7E) == 0 )
|
|
||||||
{
|
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1094,4 +982,3 @@ extern uint8_t OptrexDisplay ;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue