[Taranis] Asterisk BMP (thanks Martin!)

[Taranis] WDT timeout adjustable when dealing with long delays without pulses (thanks Mike for the trick!)
[Taranis] After USB is disconnected, the SD and the EEPROM are read inside the main, not inside the interrupt
[Taranis] Removed dead code about CPU temperature
[stock] Flash saving (thanks Mike for your emails!)
This commit is contained in:
bsongis@gmail.com
2013-05-17 16:30:30 +00:00
parent 80b0f0ee52
commit a41dc24a2e
17 changed files with 187 additions and 148 deletions
+23 -15
View File
@@ -37,9 +37,9 @@
#include "opentx.h"
#define delay_1us() _delay_us(1)
void delay_1_5us(int ms)
void delay_1_5us(uint16_t ms)
{
for(int i=0; i<ms; i++) delay_1us();
for (uint16_t i=0; i<ms; i++) delay_1us();
}
void lcdSendCtl(uint8_t val)
@@ -69,6 +69,22 @@ volatile uint8_t LcdLock ;
#define LCD_UNLOCK()
#endif
const static pm_uchar lcdInitSequence[] PROGMEM =
{
0xe2, //Initialize the internal functions
0xae, //DON = 0: display OFF
0xa1, //ADC = 1: reverse direction(SEG132->SEG1)
0xA6, //REV = 0: non-reverse display
0xA4, //EON = 0: normal display. non-entire
0xA2, // Select LCD bias=0
0xC0, //SHL = 0: normal direction (COM1->COM64)
0x2F, //Control power circuit operation VC=VR=VF=1
0x25, //Select int resistance ratio R2 R1 R0 =5
0x81, //Set reference voltage Mode
0x22, // 24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
0xAF //DON = 1: display ON
};
inline void lcdInit()
{
// /home/thus/txt/datasheets/lcd/KS0713.pdf
@@ -76,22 +92,14 @@ inline void lcdInit()
LCD_LOCK();
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD_RES
// TODO delay_2us ?
delay_1us();
delay_1us();// f520 call 0xf4ce delay_1us() ; 0x0xf4ce
delay_1us(); // f520 call 0xf4ce delay_1us() ; 0x0xf4ce
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); // f524 sbi 0x15, 2 IOADR-PORTC_LCD_CTRL; 21 1
delay_1_5us(1500);
lcdSendCtl(0xe2); //Initialize the internal functions
lcdSendCtl(0xae); //DON = 0: display OFF
lcdSendCtl(0xa1); //ADC = 1: reverse direction(SEG132->SEG1)
lcdSendCtl(0xA6); //REV = 0: non-reverse display
lcdSendCtl(0xA4); //EON = 0: normal display. non-entire
lcdSendCtl(0xA2); // Select LCD bias=0
lcdSendCtl(0xC0); //SHL = 0: normal direction (COM1->COM64)
lcdSendCtl(0x2F); //Control power circuit operation VC=VR=VF=1
lcdSendCtl(0x25); //Select int resistance ratio R2 R1 R0 =5
lcdSendCtl(0x81); //Set reference voltage Mode
lcdSendCtl(0x22); // 24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
lcdSendCtl(0xAF); //DON = 1: display ON
for (uint8_t i=0; i<12; i++) {
lcdSendCtl(pgm_read_byte(&lcdInitSequence[i]) ) ;
}
g_eeGeneral.contrast = 0x22;
LCD_UNLOCK();
}
+4 -12
View File
@@ -39,11 +39,8 @@ extern "C" {
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
}
// TODO needed?
uint8_t temperature = 0; // Raw temp reading
uint8_t maxTemperature = 0 ; // Raw temp reading
volatile uint32_t Tenms ; // TODO to remove everywhere / use a #define
uint8_t usb_connected = 0;
UsbState usbState = USB_DISCONNECTED;
#define PIN_MODE_MASK 0x0003
#define PIN_INPUT 0x0000
@@ -109,7 +106,7 @@ void configure_pins( uint32_t pins, uint16_t config )
uint8_t usbPlugged(void)
{
return usb_connected;
return usbState == USB_CONNECTED;
}
#if defined(DEBUG)
@@ -119,11 +116,6 @@ void debugPutc(const char c)
}
#endif
uint8_t getTemperature()
{
return temperature + g_eeGeneral.temperatureCalib;
}
void start_ppm_capture()
{
}
@@ -144,12 +136,12 @@ void usbInit()
}
#endif
void watchdogInit()
void watchdogInit(unsigned int duration)
{
IWDG->KR = 0x5555 ; // Unlock registers
IWDG->PR = 3 ; // Divide by 32 => 1kHz clock
IWDG->KR = 0x5555 ; // Unlock registers
IWDG->RLR = 1500 ; // 1.5 seconds nominal
IWDG->RLR = duration ; // 1.5 seconds nominal
IWDG->KR = 0xAAAA ; // reload
IWDG->KR = 0xCCCC ; // start
}
+21 -19
View File
@@ -68,11 +68,6 @@ extern "C" {
#define JACK_PPM_IN()
void configure_pins( uint32_t pins, uint16_t config );
uint16_t getCurrent();
extern uint8_t temperature ; // Raw temp reading
extern uint8_t maxTemperature ; // Raw temp reading
uint8_t getTemperature();
#define strcpy_P strcpy
#define strcat_P strcat
@@ -101,16 +96,18 @@ void delaysInit(void);
void delay_01us(uint16_t nb);
// SD driver
#if !defined(SIMU)
#define SD_IS_HC() (1)
#define SD_GET_SIZE_MB() (0)
#define SD_GET_BLOCKNR() (0)
#define SD_GET_SPEED() (0)
void sdInit();
void sdPoll10ms();
#define sdMountPoll()
uint32_t sdMounted();
#define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_Pin)
#if defined(SIMU)
#define sdInit()
#else
#define SD_IS_HC() (1)
#define SD_GET_SIZE_MB() (0)
#define SD_GET_BLOCKNR() (0)
#define SD_GET_SPEED() (0)
void sdInit();
void sdPoll10ms();
#define sdMountPoll()
uint32_t sdMounted();
#define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_Pin)
#endif
// Pulses driver
@@ -139,8 +136,8 @@ uint32_t readKeys();
// WDT driver
#if !defined(SIMU)
#define wdt_disable()
void watchdogInit();
#define wdt_enable(x) watchdogInit()
void watchdogInit(unsigned int duration);
#define wdt_enable(x) watchdogInit(1500)
#define wdt_reset() IWDG->KR = 0xAAAA
#endif
@@ -172,7 +169,12 @@ void pwrOff();
// USB driver
void usbInit(void);
extern uint8_t usb_connected;
enum UsbState {
USB_DISCONNECTED,
USB_CONNECTED,
USB_DISCONNECTING,
};
extern UsbState usbState;
// EEPROM driver
#if !defined(SIMU)
@@ -183,7 +185,7 @@ extern uint8_t usb_connected;
#define eepromInit()
void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t size);
#endif
#define EEPROM_MASSSTORAGE() (usb_connected)
#define EEPROM_MASSSTORAGE() usbPlugged()
extern uint8_t currentTrainerMode;
+29 -32
View File
@@ -271,7 +271,7 @@ const char g_FATboot[BLOCKSIZE] =
0x01, // Sectors per FS cluster.
0x01, 0x00, // Reserved sector count
0x01, // Number of FATs
0x01, // Number of FATs
0x10, 0x00, // Number of root directory entries
0x83, 0x00, // Total sectors = 131
0xf8, // Media descriptor
@@ -280,7 +280,7 @@ const char g_FATboot[BLOCKSIZE] =
0x40, 0x00, // Number of heads
0x00, 0x00, 0x00, 0x00, // Number of hidden sectors
0x00, 0x00, 0x00, 0x00, // Large number of sectors.
0x00, 0x00, 0x00, 0x00, // Large number of sectors.
0x00, // Physical drive number
0x00, // Reserved
0x29, // Extended boot signature
@@ -289,21 +289,21 @@ const char g_FATboot[BLOCKSIZE] =
0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, // FAT file system type
0x00, 0x00, // OS boot code
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -323,19 +323,20 @@ const char g_FATboot[BLOCKSIZE] =
const char g_FAT[BLOCKSIZE] =
{
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B,
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60,
0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02,
0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B,
0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60,
0x03, 0x37, 0x80, 0x03, 0x39, 0xA0, 0x03, 0x3B, 0xC0, 0x03, 0x3D, 0xE0, 0x03, 0x3F, 0x00, 0x04,
0x41, 0x20, 0x04, 0x43, 0x40, 0x04, 0x45, 0x60, 0x04, 0x47, 0x80, 0x04, 0x49, 0xA0, 0x04, 0x4B,
0xC0, 0x04, 0x4D, 0xE0, 0x04, 0x4F, 0x00, 0x05, 0x51, 0x20, 0x05, 0x53, 0x40, 0x05, 0x55, 0x60,
0x05, 0x57, 0x80, 0x05, 0x59, 0xA0, 0x05, 0x5B, 0xC0, 0x05, 0x5D, 0xE0, 0x05, 0x5F, 0x00, 0x06,
0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B,
0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60,
0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08,
0x81, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B,
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60,
0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02,
0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B,
0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60,
0x03, 0x37, 0x80, 0x03, 0x39, 0xA0, 0x03, 0x3B, 0xC0, 0x03, 0x3D, 0xE0, 0x03, 0x3F, 0x00, 0x04,
0x41, 0x20, 0x04, 0x43, 0x40, 0x04, 0x45, 0x60, 0x04, 0x47, 0x80, 0x04, 0x49, 0xA0, 0x04, 0x4B,
0xC0, 0x04, 0x4D, 0xE0, 0x04, 0x4F, 0x00, 0x05, 0x51, 0x20, 0x05, 0x53, 0x40, 0x05, 0x55, 0x60,
0x05, 0x57, 0x80, 0x05, 0x59, 0xA0, 0x05, 0x5B, 0xC0, 0x05, 0x5D, 0xE0, 0x05, 0x5F, 0x00, 0x06,
0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B,
0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60,
0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08,
0x81, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -348,7 +349,6 @@ const char g_FAT[BLOCKSIZE] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -635,21 +635,17 @@ int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count )
{
while ( count )
{
if (sector == 0)
{
memcpy( buffer, g_FATboot, BLOCKSIZE ) ;
if (sector == 0) {
memcpy( buffer, g_FATboot, BLOCKSIZE ) ;
}
else if (sector == 1/*Reserved sector count*/)
{
// FAT table.
memcpy( buffer, g_FAT, BLOCKSIZE);
else if (sector == 1/*Reserved sector count*/) {
// FAT table.
memcpy( buffer, g_FAT, BLOCKSIZE);
}
else if (sector == 2)
{
else if (sector == 2) {
memcpy( buffer, g_DIRroot, BLOCKSIZE ) ;
}
else
{
else {
eeprom_read_block (buffer, (sector-3)*512, 512);
}
buffer += 512 ;
@@ -676,8 +672,9 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
buffer += 512;
sector++;
count--;
if (sector-offset+1==EESIZE/512)
if (sector-offset+1==EESIZE/512) {
offset = 0;
}
}
return 0 ;
}
+2 -7
View File
@@ -114,7 +114,7 @@ void USBD_USR_DeviceConnected (void)
}
eeCheck(true);
usb_connected = 1;
usbState = USB_CONNECTED;
}
@@ -126,12 +126,7 @@ void USBD_USR_DeviceConnected (void)
*/
void USBD_USR_DeviceDisconnected (void)
{
usb_connected = 0;
eeReadAll();
eeLoadModel(g_eeGeneral.currModel);
sdInit();
usbState = USB_DISCONNECTING;
}