Merge pull request #1893 from opentx/projectkk2glider/lcd_dma_in_background

Projectkk2glider/lcd dma in background
This commit is contained in:
Bertrand Songis
2014-12-08 18:53:43 +01:00
31 changed files with 908 additions and 566 deletions
+4
View File
@@ -339,6 +339,10 @@ void *main_thread(void *)
s_current_protocol[0] = 0;
while (main_thread_running) {
#if defined(CPUARM)
doMixerCalculations();
checkTrims();
#endif
perMain();
sleep(10/*ms*/);
}
-1
View File
@@ -336,7 +336,6 @@ extern void rxPdcUsart( void (*pChProcess)(uint8_t x) );
#define asm(x)
#if defined(CPUARM)
extern volatile uint32_t Tenms;
extern uint32_t Master_frequency;
#define NVIC_EnableIRQ(x)
#define NVIC_DisableIRQ(x)
+32
View File
@@ -42,6 +42,13 @@ volatile uint32_t Tenms ;
volatile uint8_t lcdLock;
volatile uint32_t lcdInputs;
#if !defined(REVA)
uint16_t Current_analogue;
uint16_t Current_max;
uint32_t Current_accumulator;
uint32_t Current_used;
#endif
extern "C" void sam_boot( void ) ;
// Prototype
@@ -672,3 +679,28 @@ void setSticksGain(uint8_t gains)
padc->ADC_CGR = gain;
padc->ADC_COR = offset;
}
#if !defined(REVA)
void calcConsumption()
{
Current_accumulator += Current_analogue ;
static uint32_t OneSecTimer;
if (++OneSecTimer >= 100) {
OneSecTimer -= 100 ;
Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled)
Current_accumulator = 0 ;
}
}
#endif
void checkTrainerSettings()
{
if (SLAVE_MODE()) {
PIOC->PIO_PDR = PIO_PC22;
}
else {
PIOC->PIO_PER = PIO_PC22;
}
}
+5 -2
View File
@@ -168,11 +168,14 @@ extern uint16_t Current_max;
extern uint32_t Current_accumulator;
extern uint32_t Current_used;
extern uint16_t sessionTimer;
void calcConsumption();
#endif
#define SLAVE_MODE() (pwrCheck() == e_power_trainer)
#define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22
#define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22
// #define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22
// #define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22
void checkTrainerSettings();
void setSticksGain(uint8_t gains);
+87 -2
View File
@@ -46,8 +46,6 @@ extern "C" {
}
#endif
volatile uint32_t Tenms ; // TODO to remove everywhere / use a #define
void watchdogInit(unsigned int duration)
{
IWDG->KR = 0x5555 ; // Unlock registers
@@ -150,3 +148,90 @@ void boardInit()
}
#endif
#if defined(USB_JOYSTICK) && !defined(SIMU)
extern USB_OTG_CORE_HANDLE USB_OTG_dev;
/*
Prepare and send new USB data packet
The format of HID_Buffer is defined by
USB endpoint description can be found in
file usb_hid_joystick.c, variable HID_JOYSTICK_ReportDesc
*/
void usbJoystickUpdate(void)
{
static uint8_t HID_Buffer[HID_IN_PACKET];
//buttons
HID_Buffer[0] = 0; //buttons
for (int i = 0; i < 8; ++i) {
if ( channelOutputs[i+8] > 0 ) {
HID_Buffer[0] |= (1 << i);
}
}
//analog values
//uint8_t * p = HID_Buffer + 1;
for (int i = 0; i < 8; ++i) {
int16_t value = channelOutputs[i] / 8;
if ( value > 127 ) value = 127;
else if ( value < -127 ) value = -127;
HID_Buffer[i+1] = static_cast<int8_t>(value);
}
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
}
#endif //#if defined(USB_JOYSTICK) && defined(PCBTARANIS) && !defined(SIMU)
uint8_t currentTrainerMode = 0xff;
void checkTrainerSettings()
{
uint8_t requiredTrainerMode = g_model.trainerMode;
if (requiredTrainerMode != currentTrainerMode) {
switch (currentTrainerMode) {
case TRAINER_MODE_MASTER:
stop_trainer_capture();
break;
case TRAINER_MODE_SLAVE:
stop_trainer_ppm();
break;
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
stop_cppm_on_heartbeat_capture() ;
break;
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
stop_sbus_on_heartbeat_capture() ;
break;
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
uart3Stop();
}
currentTrainerMode = requiredTrainerMode;
switch (requiredTrainerMode) {
case TRAINER_MODE_SLAVE:
init_trainer_ppm();
break;
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
init_cppm_on_heartbeat_capture() ;
break;
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
init_sbus_on_heartbeat_capture() ;
break;
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
if (g_eeGeneral.uart3Mode == UART_MODE_SBUS_TRAINER) {
uart3SbusInit();
break;
}
// no break
default:
// master is default
init_trainer_capture();
break;
}
}
}
+10 -5
View File
@@ -82,8 +82,8 @@ extern "C" {
#define TIMER_MULT_APB1 2
#define TIMER_MULT_APB2 2
#define JACK_PPM_OUT()
#define JACK_PPM_IN()
// #define JACK_PPM_OUT()
// #define JACK_PPM_IN()
#define PIN_MODE_MASK 0x0003
#define PIN_INPUT 0x0000
@@ -174,9 +174,9 @@ uint32_t readTrims(void);
#if defined(REV9E)
// Rotary Encoder driver
void rotencInit();
void rotencEnd();
void checkRotaryEncoder();
void rotencInit(void);
void rotencEnd(void);
void checkRotaryEncoder(void);
#endif
// WDT driver
@@ -277,5 +277,10 @@ void uart3Stop(void);
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
#if defined(USB_JOYSTICK) && !defined(SIMU)
void usbJoystickUpdate(void);
#endif
void checkTrainerSettings();
#endif
+5 -5
View File
@@ -41,13 +41,13 @@
uint32_t readKeys()
{
register uint32_t d = GPIOD->IDR;
#if !defined(REV9E)
register uint32_t e = GPIOE->IDR;
#else
register uint32_t f = GPIOF->IDR;
#endif
register uint32_t result = 0;
(void)e;
(void)f;
#if defined(REV9E)
if (f & PIN_BUTTON_ENTER)
#else
@@ -55,7 +55,7 @@ uint32_t readKeys()
#endif
result |= 0x02 << KEY_ENTER;
#if !defined(REV9E)
#if !defined(REV9E) || defined(SIMU)
if (e & PIN_BUTTON_PLUS)
result |= 0x02 << KEY_PLUS;
if (e & PIN_BUTTON_MINUS)
@@ -145,7 +145,7 @@ void readKeysAndTrims()
#if defined(REV9E)
static rotenc_t rePreviousValue;
rotenc_t reNewValue = (x9de_rotenc / ROTARY_ENCODER_GRANULARITY);
rotenc_t reNewValue = (x9de_rotenc / 2);
int8_t scrollRE = reNewValue - rePreviousValue;
if (scrollRE) {
rePreviousValue = reNewValue;
+55 -27
View File
@@ -17,9 +17,11 @@
#if defined(REVPLUS)
#define CONTRAST_OFS 160
#define RESET_WAIT_DELAY_MS 300 //wait time after LCD reset before first command
#define WAIT_FOR_DMA_END() { while(lcd_busy) {}; }
#else
#define CONTRAST_OFS 5
#define RESET_WAIT_DELAY_MS 1300 //wait time after LCD reset before first command
#define WAIT_FOR_DMA_END()
#endif
#if defined(BOOT)
@@ -42,7 +44,6 @@ static void Delay(uint32_t ms)
}
#if defined(REVPLUS)
static void LCD_Hardware_Init() ;
// New hardware SPI driver for LCD
void initLcdSpi()
@@ -64,24 +65,25 @@ void initLcdSpi()
configure_pins( PIN_LCD_RST, PIN_OUTPUT | PIN_PORTD | PIN_PUSHPULL | PIN_OS25 | PIN_NO_PULLUP ) ;
configure_pins( PIN_LCD_A0, PIN_OUTPUT | PIN_PORTC | PIN_PUSHPULL | PIN_OS50 | PIN_NO_PULLUP ) ;
configure_pins( PIN_LCD_MOSI|PIN_LCD_CLK, PIN_PORTC | PIN_PUSHPULL | PIN_OS50 | PIN_NO_PULLUP | PIN_PER_6 | PIN_PERIPHERAL ) ;
}
void setupSPIdma()
{
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN ; // Enable DMA1 clock
// Chan 0, 8-bit wide, Medium priority, memory increments
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
// NVIC_SetPriority( DMA1_Stream7_IRQn, 8 ) ;
NVIC_EnableIRQ(DMA1_Stream7_IRQn) ;
DMA1->HIFCR |= DMA_HIFCR_CTCIF7; //clear interrupt flag
DMA1->LISR |= DMA_HISR_TCIF7; //enable DMA TX end interrupt
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN ; // Enable DMA1 clock
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
DMA1->HIFCR = DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7 ; // Write ones to clear bits
DMA1_Stream7->CR = DMA_SxCR_PL_0 | DMA_SxCR_MINC | DMA_SxCR_DIR_0 ;
DMA1_Stream7->PAR = (uint32_t) &SPI3->DR ;
DMA1_Stream7->M0AR = (uint32_t)displayBuf;
DMA1_Stream7->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
DMA1_Stream7->NDTR = LCD_W*LCD_H/8*4 ;
// NVIC_SetPriority( DMA1_Stream7_IRQn, 2 ) ; // Lower priority interrupt
// NVIC_EnableIRQ(DMA1_Stream7_IRQn) ;
}
static void LCD_Init()
{
WriteCommand(0x2F); //Internal pump control
@@ -174,35 +176,59 @@ void Set_Address(u8 x, u8 y)
LCD_CLK_HIGH();
#if defined(REVPLUS)
volatile bool lcd_busy;
#if !defined(LCD_DUAL_BUFFER)
void lcdRefreshWait()
{
WAIT_FOR_DMA_END();
}
#endif
void lcdRefresh(bool wait)
{
//wait if previous DMA transfer still active
WAIT_FOR_DMA_END();
lcd_busy = true;
Set_Address(0, 0);
LCD_NCS_LOW();
LCD_A0_HIGH();
setupSPIdma() ;
DMA1_Stream7->CR |= DMA_SxCR_EN ; // Enable DMA
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
DMA1->HIFCR = DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7 ; // Write ones to clear bits
#if defined(LCD_DUAL_BUFFER)
//switch LCD buffer
DMA1_Stream7->M0AR = (uint32_t)displayBuf;
displayBuf = (displayBuf == displayBuf1) ? displayBuf2 : displayBuf1;
#endif
DMA1_Stream7->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE; // Enable DMA & tXe interrupt
SPI3->CR2 |= SPI_CR2_TXDMAEN ;
}
while ( ( DMA1->HISR & DMA_HISR_TCIF7 ) == 0 ) {
// wait
}
extern "C" void DMA1_Stream7_IRQHandler()
{
//clear interrupt flag
DMA1_Stream7->CR &= ~DMA_SxCR_TCIE ; // Stop interrupt
DMA1->HIFCR |= DMA_HIFCR_CTCIF7; // Clear interrupt flag
SPI3->CR2 &= ~SPI_CR2_TXDMAEN ;
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
while ( ( SPI3->SR & SPI_SR_TXE ) == 0 ) {
// wait
} // Last byte being sent
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
while ( SPI3->SR & SPI_SR_BSY ) {
// wait
/* Wait for SPI to finish sending data
The DMA TX End interrupt comes two bytes before the end of SPI transmission,
therefore we have to wait here.
*/
}
LCD_NCS_HIGH();
lcd_busy = false;
}
#else
#else // #if defined(REVPLUS)
void lcdRefresh()
{
for (uint32_t y=0; y<LCD_H; y++) {
@@ -280,7 +306,7 @@ static void LCD_BL_Config()
#endif
}
/** Init the anolog spi gpio
/** Init the analog SPI GPIO
*/
static void LCD_Hardware_Init()
{
@@ -288,7 +314,7 @@ static void LCD_Hardware_Init()
GPIO_InitTypeDef GPIO_InitStructure;
/*!< Configure lcd CLK\ MOSI\ A0pin in output pushpull mode *************/
/*!< Configure lcd CLK\ MOSI\ A0pin in output push-pull mode *************/
GPIO_InitStructure.GPIO_Pin = PIN_LCD_MOSI | PIN_LCD_CLK | PIN_LCD_A0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
@@ -298,7 +324,7 @@ static void LCD_Hardware_Init()
LCD_NCS_HIGH();
/*!< Configure lcd NCS pin in output pushpull mode ,PULLUP *************/
/*!< Configure lcd NCS pin in output push-pull mode ,PULLUP *************/
GPIO_InitStructure.GPIO_Pin = PIN_LCD_NCS;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
@@ -317,6 +343,7 @@ static void LCD_Hardware_Init()
*/
void lcdOff()
{
WAIT_FOR_DMA_END();
AspiCmd(0xE2); //system reset
Delay(3); //wait for caps to drain
}
@@ -378,6 +405,7 @@ void lcdInitFinish()
void lcdSetRefVolt(uint8_t val)
{
WAIT_FOR_DMA_END();
AspiCmd(0x81); //Set Vop
AspiCmd(val+CONTRAST_OFS); //0--255
}