diff --git a/radio/bootloader/Makefile b/radio/bootloader/Makefile index a458568b0..f67923ab8 100644 --- a/radio/bootloader/Makefile +++ b/radio/bootloader/Makefile @@ -137,17 +137,20 @@ SRC = system_stm32f2xx.c \ ../src/targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c \ ../src/targets/taranis/usbd_desc.c \ ../src/targets/taranis/aspi.c \ - ../src/targets/taranis/usb_bsp.c + ../src/targets/taranis/usb_bsp.c \ + ../src/targets/taranis/usb_driver.c \ + ../src/targets/taranis/pwr_driver.c CPPSRC = ../src/targets/taranis/lcd_driver.cpp \ + ../src/targets/taranis/keys_driver.cpp \ driversboot.cpp \ logicioboot.cpp \ ../src/targets/taranis/diskio.cpp \ ../src/targets/taranis/usbd_usr.cpp \ usbd_storage_msd.cpp \ ../src/lcd.cpp \ + ../src/keys.cpp \ ../src/fonts.cpp \ - power.cpp \ boot.cpp # List ASM source files here diff --git a/radio/bootloader/boot.cpp b/radio/bootloader/boot.cpp index 479208ed2..b4c39a97d 100644 --- a/radio/bootloader/boot.cpp +++ b/radio/bootloader/boot.cpp @@ -53,17 +53,12 @@ #include #include #include -#ifdef PCBSKY -#include "AT91SAM3S4.h" -#include "core_cm3.h" -#endif #ifdef PCBTARANIS #include "stm32f2xx.h" #include "stm32f2xx_flash.h" #include "../src/targets/taranis/i2c.h" #include "hal.h" -// #include "timers.h" extern "C" { #include "usb_dcd_int.h" @@ -76,13 +71,15 @@ extern "C" { #endif #include "board_taranis.h" +#include "../src/pwr.h" #include "../src/lcd.h" +#include "../src/keys.h" -#include "radio.h" +// #include "radio.h" #include "../src/FatFs/ff.h" #include "../src/FatFs/diskio.h" -#include "drivers.h" -#include "logicio.h" +//#include "drivers.h" +// #include "logicio.h" #ifdef PCBSKY extern void usbMassStorage( void ) ; @@ -204,37 +201,7 @@ void delay2ms() } #endif -static bool usbPlugged(void) -{ -#ifdef PCBSKY - return PIOC->PIO_PDSR & 0x02000000 ; -#endif - #ifdef PCBTARANIS - return GPIOA->IDR & 0x0200 ; -#endif -} - -#ifdef PCBTARANIS - -extern "C" { -USB_OTG_CORE_HANDLE USB_OTG_dev; - -void OTG_FS_IRQHandler(void) -{ - USBD_OTG_ISR_Handler (&USB_OTG_dev); -} -} - -static void usbInit() -{ - USB_OTG_BSP_Init(&USB_OTG_dev); -} - -static void usbStart() -{ - USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb); -} uint32_t isFirmwareStart( uint32_t *block ) { @@ -358,7 +325,8 @@ void clearLockBits() } #endif -void interrupt10ms() +void per10ms(void); +void interrupt10ms(void) { Tenms |= 1 ; // 10 mS has passed per10ms() ; @@ -760,7 +728,7 @@ int main() RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock #endif - init_soft_power() ; + pwrInit() ; #ifdef PCBSKY MATRIX->CCFG_SYSIO |= 0x000000F0L ; // Disable syspins, enable B4,5,6,7 @@ -788,7 +756,7 @@ extern uint8_t OptrexDisplay ; #endif #ifdef PCBTARANIS - init_keys() ; + keysInit() ; I2C_EE_Init() ; init_hw_timer() ; #endif @@ -821,7 +789,7 @@ extern uint8_t OptrexDisplay ; #ifdef PCBTARANIS // SD card detect pin - configure_pins( SD_PRESENT_GPIO_Pin, PIN_PORTD | PIN_INPUT | PIN_PULLUP ) ; + // configure_pins( SD_PRESENT_GPIO_Pin, PIN_PORTD | PIN_INPUT | PIN_PULLUP ) ; disk_initialize( 0 ) ; sdInit() ; unlockFlash() ; @@ -1134,9 +1102,8 @@ extern uint8_t OptrexDisplay ; } if ((state < ST_FLASH_CHECK) || (state == ST_FLASH_DONE)) { - if ( check_soft_power() == POWER_OFF ) - { - soft_power_off() ; + if (pwrCheck() == e_power_off ) { + pwrOff() ; for(;;) { // Wait for power to go off @@ -1152,7 +1119,7 @@ extern uint8_t OptrexDisplay ; } if ( state == ST_REBOOT ) { - if ( (~read_keys() & 0x7E) == 0 ) + if ( (~readKeys() & 0x7E) == 0 ) { NVIC_SystemReset() ; } diff --git a/radio/bootloader/driversboot.cpp b/radio/bootloader/driversboot.cpp index ca3c917d9..4df371a16 100644 --- a/radio/bootloader/driversboot.cpp +++ b/radio/bootloader/driversboot.cpp @@ -21,137 +21,14 @@ #include #include -#ifdef PCBSKY -#include "radio.h" -#include "drivers.h" -#endif +#include "../src/opentx.h" - -#ifdef PCBTARANIS -#include "radio.h" -#include "hal.h" -#include "stm32f2xx.h" -#include "stm32f2xx_gpio.h" -#include "stm32f2xx_rcc.h" -#endif -#include "drivers.h" -#include "logicio.h" - -#ifdef EVT_KEY_MASK -#undef EVT_KEY_MASK -#endif - -#define EVT_KEY_MASK 0x0f - - -void b_putEvent( register uint8_t evt) ; -void per10ms( void ) ; -uint8_t getEvent( void ) ; -void pauseEvents(uint8_t event) ; -void killEvents(uint8_t event) ; - -uint8_t s_evt; -void b_putEvent( uint8_t evt) -{ - s_evt = evt; -} - - -uint8_t getEvent() -{ - register uint8_t evt = s_evt; - s_evt=0; - return evt; -} - -Key keys[NUM_KEYS] ; - -void Key::input(bool val, EnumKeys enuk) -{ - // uint8_t old=m_vals; - m_vals <<= 1; if(val) m_vals |= 1; //portbit einschieben - m_cnt++; - - if(m_state && m_vals==0){ //gerade eben sprung auf 0 - if(m_state!=KSTATE_KILLED) { - b_putEvent(EVT_KEY_BREAK(enuk)); - } - m_cnt = 0; - m_state = KSTATE_OFF; - } - switch(m_state){ - case KSTATE_OFF: - if(m_vals==FFVAL){ //gerade eben sprung auf ff - m_state = KSTATE_START; - m_cnt = 0; - } - break; - //fallthrough - case KSTATE_START: - b_putEvent(EVT_KEY_FIRST(enuk)); -#ifdef KSTATE_RPTDELAY - m_state = KSTATE_RPTDELAY; -#else - m_state = 16; -#endif - m_cnt = 0; - break; -#ifdef KSTATE_RPTDELAY - case KSTATE_RPTDELAY: // gruvin: longer delay before first key repeat - if(m_cnt == 32) b_putEvent(EVT_KEY_LONG(enuk)); // need to catch this inside RPTDELAY time - if (m_cnt == 40) { - m_state = 16; - m_cnt = 0; - } - break; -#endif - case 16: -#ifndef KSTATE_RPTDELAY - if(m_cnt == 32) b_putEvent(EVT_KEY_LONG(enuk)); - //fallthrough -#endif - case 8: - case 4: - case 2: - if(m_cnt >= 48) { //3 6 12 24 48 pulses in every 480ms - m_state >>= 1; - m_cnt = 0; - } - //fallthrough - case 1: - if( (m_cnt & (m_state-1)) == 0) b_putEvent(EVT_KEY_REPT(enuk)); - break; - - case KSTATE_PAUSE: //pause - if(m_cnt >= 64) { - m_state = 8; - m_cnt = 0; - } - break; - - case KSTATE_KILLED: //killed - break; - } -} - -void b_pauseEvents(uint8_t event) -{ - event=event & EVT_KEY_MASK; - if(event < (int)DIM(keys)) keys[event].pauseEvents(); -} - -void killEvents(uint8_t event) -{ - event=event & EVT_KEY_MASK; - if(event < (int)DIM(keys)) keys[event].killEvents(); -} - -void per10ms() +void per10ms(void) { register uint32_t i ; uint8_t enuk = KEY_MENU; - uint8_t in = ~read_keys() ; + uint8_t in = ~readKeys() ; // Bits 3-6 are down, up, right and left // Try to only allow one at a #ifdef REVX diff --git a/radio/bootloader/include/drivers.h b/radio/bootloader/include/drivers.h index bca87090c..2ba37370d 100644 --- a/radio/bootloader/include/drivers.h +++ b/radio/bootloader/include/drivers.h @@ -4,12 +4,7 @@ extern volatile uint32_t Spi_complete ; -extern void putEvent( register uint8_t evt) ; - extern void per10ms( void ) ; -extern uint8_t getEvent( void ) ; -extern void pauseEvents(uint8_t event) ; -extern void killEvents(uint8_t event) ; extern void init_spi( void ) ; extern void end_spi( void ) ; diff --git a/radio/bootloader/include/logicio.h b/radio/bootloader/include/logicio.h deleted file mode 100644 index a8b004eca..000000000 --- a/radio/bootloader/include/logicio.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -* Copyright (c) 2012 by Michael Blandford. All rights reserved. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* -****************************************************************************/ - -#ifdef PCBTARANIS -#define PIN_MODE_MASK 0x0003 -#define PIN_INPUT 0x0000 -#define PIN_OUTPUT 0x0001 -#define PIN_PERIPHERAL 0x0002 -#define PIN_ANALOG 0x0003 -#define PIN_PULL_MASK 0x000C -#define PIN_PULLUP 0x0004 -#define PIN_NO_PULLUP 0x0000 -#define PIN_PULLDOWN 0x0008 -#define PIN_NO_PULLDOWN 0x0000 -#define PIN_NO_PULL 0x0000 -#define PIN_PERI_MASK 0x00F0 -//#define PIN_PERI_MASK_H 0x0020 -#define PIN_PER_0 0x0000 -#define PIN_PER_1 0x0010 -#define PIN_PER_2 0x0020 -#define PIN_PER_3 0x0030 -#define PIN_PER_4 0x0040 -#define PIN_PER_5 0x0050 -#define PIN_PER_6 0x0060 -#define PIN_PER_7 0x0070 -#define PIN_PER_8 0x0080 -#define PIN_PER_9 0x0090 -#define PIN_PER_10 0x00A0 -#define PIN_PER_11 0x00B0 -#define PIN_PER_12 0x00C0 -#define PIN_PER_13 0x00D0 -#define PIN_PER_14 0x00E0 -#define PIN_PER_15 0x00F0 -#define PIN_PORT_MASK 0x0700 -#define PIN_PORTA 0x0000 -#define PIN_PORTB 0x0100 -#define PIN_PORTC 0x0200 -#define PIN_PORTD 0x0300 -#define PIN_PORTE 0x0400 -#define PIN_LOW 0x0000 -#define PIN_HIGH 0x1000 -#define PIN_SPEED_MASK 0x6000 -#define PIN_OS2 0x0000 -#define PIN_OS25 0x2000 -#define PIN_OS50 0x4000 -#define PIN_OS100 0x6000 -#define PIN_PUSHPULL 0x0000 -#define PIN_ODRAIN 0x8000 - -#define GPIO_Pin_0 ((uint16_t)0x0001) /* Pin 0 selected */ -#define GPIO_Pin_1 ((uint16_t)0x0002) /* Pin 1 selected */ -#define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */ -#define GPIO_Pin_3 ((uint16_t)0x0008) /* Pin 3 selected */ -#define GPIO_Pin_4 ((uint16_t)0x0010) /* Pin 4 selected */ -#define GPIO_Pin_5 ((uint16_t)0x0020) /* Pin 5 selected */ -#define GPIO_Pin_6 ((uint16_t)0x0040) /* Pin 6 selected */ -#define GPIO_Pin_7 ((uint16_t)0x0080) /* Pin 7 selected */ -#define GPIO_Pin_8 ((uint16_t)0x0100) /* Pin 8 selected */ -#define GPIO_Pin_9 ((uint16_t)0x0200) /* Pin 9 selected */ -#define GPIO_Pin_10 ((uint16_t)0x0400) /* Pin 10 selected */ -#define GPIO_Pin_11 ((uint16_t)0x0800) /* Pin 11 selected */ -#define GPIO_Pin_12 ((uint16_t)0x1000) /* Pin 12 selected */ -#define GPIO_Pin_13 ((uint16_t)0x2000) /* Pin 13 selected */ -#define GPIO_Pin_14 ((uint16_t)0x4000) /* Pin 14 selected */ -#define GPIO_Pin_15 ((uint16_t)0x8000) /* Pin 15 selected */ -#define GPIO_Pin_All ((uint16_t)0xFFFF) /* All pins selected */ - -#endif - - -#ifdef PCBSKY -#define PIN_ENABLE 0x001 -#define PIN_PERIPHERAL 0x000 -#define PIN_INPUT 0x002 -#define PIN_OUTPUT 0x000 -#define PIN_PULLUP 0x004 -#define PIN_NO_PULLUP 0x000 -#define PIN_PULLDOWN 0x008 -#define PIN_NO_PULLDOWN 0x000 -#define PIN_PERI_MASK_L 0x010 -#define PIN_PERI_MASK_H 0x020 -#define PIN_PER_A 0x000 -#define PIN_PER_B 0x010 -#define PIN_PER_C 0x020 -#define PIN_PER_D 0x030 -#define PIN_PORT_MASK 0x0C0 -#define PIN_PORTA 0x000 -#define PIN_PORTB 0x040 -#define PIN_PORTC 0x080 -#define PIN_LOW 0x000 -#define PIN_HIGH 0x100 -#endif - - -extern void configure_pins( uint32_t pins, uint16_t config ) ; -extern void init_keys( void ) ; -extern uint32_t read_keys( void ) ; -extern uint32_t read_trims( void ) ; -extern uint32_t keyState( enum EnumKeys enuk) ; -extern void init_trims( void ) ; -extern void setup_switches( void ) ; -extern void config_free_pins( void ) ; - -#define GPIO_ResetBits( port, bits ) (port->BSRRH = bits) -#define GPIO_SetBits( port, bits ) (port->BSRRL = bits) -#define GPIO_ReadInputDataBit( port, bit) ( (port->IDR & bit) ? Bit_SET : Bit_RESET) - -#ifdef PCBTARANIS -uint32_t switchPosition( uint32_t swtch ) ; -#endif - diff --git a/radio/bootloader/logicioboot.cpp b/radio/bootloader/logicioboot.cpp index 3b7f02dce..cc3df751a 100644 --- a/radio/bootloader/logicioboot.cpp +++ b/radio/bootloader/logicioboot.cpp @@ -25,14 +25,7 @@ #include "drivers.h" #endif -#ifdef PCBTARANIS -#include "stm32f2xx.h" -#include "stm32f2xx_gpio.h" -#include "radio.h" -#include "hal.h" -#endif - -#include "logicio.h" +#include "../src/opentx.h" #ifndef SIMU @@ -40,7 +33,7 @@ void configure_pins( uint32_t pins, uint16_t config ) { register Pio *pioptr ; - + pioptr = PIOA + ( ( config & PIN_PORT_MASK ) >> 6) ; if ( config & PIN_PULLUP ) { @@ -64,11 +57,11 @@ void configure_pins( uint32_t pins, uint16_t config ) if ( config & PIN_HIGH ) { - pioptr->PIO_SODR = pins ; + pioptr->PIO_SODR = pins ; } else { - pioptr->PIO_CODR = pins ; + pioptr->PIO_CODR = pins ; } if ( config & PIN_INPUT ) @@ -99,11 +92,11 @@ void configure_pins( uint32_t pins, uint16_t config ) if ( config & PIN_ENABLE ) { - pioptr->PIO_PER = pins ; + pioptr->PIO_PER = pins ; } else { - pioptr->PIO_PDR = pins ; + pioptr->PIO_PDR = pins ; } } #endif @@ -153,17 +146,17 @@ void configure_pins( uint32_t pins, uint16_t config ) } } } - + #endif #ifdef PCBSKY - + void init_keys() { register Pio *pioptr ; - + pioptr = PIOC ; // Next section configures the key inputs on the LCD data pioptr->PIO_PER = 0x0000003BL ; // Enable bits 1,3,4,5, 0 @@ -230,7 +223,7 @@ void setup_switches() // PC21, PC19, PC15 (PPM2 output) void config_free_pins() { - + configure_pins( PIO_PB14, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP ) ; } @@ -255,7 +248,7 @@ uint32_t read_keys() register uint32_t y ; x = LcdLock ? LcdInputs : PIOC->PIO_PDSR << 1 ; // 6 LEFT, 5 RIGHT, 4 DOWN, 3 UP () - + y = x & 0x00000020 ; // RIGHT if ( x & 0x00000004 ) { @@ -300,7 +293,7 @@ uint32_t read_trims() { trims |= 1 ; } - + // TRIM_LV_DOWN PA27 (PA24) if ( ( trima & 0x01000000 ) == 0 ) { @@ -375,74 +368,10 @@ uint32_t initReadTrims( void ) { __asm("nop") ; } - + return read_trims() ; } #endif // PCBSKY -#ifdef PCBTARANIS -void init_keys() -{ -// Buttons PE10, 11, 12, PD2, 3, 7 - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN ; // Enable portE clock - configure_pins( 0x1C00, PIN_INPUT | PIN_PULLUP | PIN_PORTE ) ; - configure_pins( 0x008C, PIN_INPUT | PIN_PULLUP | PIN_PORTD ) ; -} -// Reqd. bit 6 LEFT, 5 RIGHT, 4 UP, 3 DOWN 2 EXIT 1 MENU -uint32_t read_keys() -{ - register uint32_t x ; - register uint32_t y ; - - x = GPIOD->IDR ; // 7 MENU, 3 PAGE(UP), 2 EXIT - - y = 0 ; - if ( x & PIN_BUTTON_MENU ) - { - y |= 0x02 << KEY_MENU ; // up -// y |= 0x02 << KEY_MENU ; // MENU - } - if ( x & PIN_BUTTON_PAGE ) - { - y |= 0x02 << KEY_PAGE ; // LEFT - } - if ( x & PIN_BUTTON_EXIT ) - { - y |= 0x02 << KEY_EXIT ; // DOWN -// y |= 0x02 << KEY_EXIT ; // EXIT - } - - x = GPIOE->IDR ; // 10 RIGHT(+), 11 LEFT(-), 12 ENT(DOWN) - if ( x & PIN_BUTTON_PLUS ) - { - y |= 0x02 << KEY_PLUS ; // MENU -// y |= 0x02 << KEY_UP ; // up - } - if ( x & PIN_BUTTON_MINUS ) - { - y |= 0x02 << KEY_MINUS ; // RIGHT -// y |= 0x02 << KEY_DOWN ; // DOWN - } - if ( x & PIN_BUTTON_ENTER ) - { - y |= 0x02 << KEY_ENTER ; // EXIT -// y |= 0x02 << KEY_RIGHT ; // RIGHT - } - return y ; -} - -// -void setup_switches() -{ - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN ; // Enable portB clock - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN ; // Enable portE clock - configure_pins( 0x0020, PIN_INPUT | PIN_PULLUP | PIN_PORTA ) ; - configure_pins( 0x003A, PIN_INPUT | PIN_PULLUP | PIN_PORTB ) ; - configure_pins( 0xE307, PIN_INPUT | PIN_PULLUP | PIN_PORTE ) ; - -} - -#endif // PCBTARANIS diff --git a/radio/bootloader/power.cpp b/radio/bootloader/power.cpp deleted file mode 100644 index 5873d62e1..000000000 --- a/radio/bootloader/power.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Authors (alphabetical order) - * - Andre Bernet - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * open9x is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include -#ifdef PCBSKY -#include "AT91SAM3S4.h" -#endif - - -#ifdef PCBTARANIS -#include "stm32f2xx_gpio.h" -#include "stm32f2xx_rcc.h" -#include "hal.h" -#endif - -#include "radio.h" -#include "logicio.h" - -#ifdef PCBSKY - - -void init_soft_power() -{ - // Configure RF_power (PC17) - configure_pins( PIO_PC17, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_NO_PULLUP | PIN_PULLDOWN ) ; - - configure_pins( PIO_PA8, PIN_ENABLE | PIN_INPUT | PIN_PORTA | PIN_PULLUP ) ; -} - - -// Returns zero if power is switched off -// 1 if power switch is on -// 2 if power switch off, trainer power on -uint32_t check_soft_power() -{ - if ( PIOC->PIO_PDSR & PIO_PC17 ) // Power on - { - return POWER_ON ; - } - return POWER_OFF ; -} - - -// turn off soft power -void soft_power_off() -{ - configure_pins( PIO_PA8, PIN_ENABLE | PIN_OUTPUT | PIN_LOW | PIN_PORTA | PIN_NO_PULLUP ) ; -} - -#endif - -#ifdef PCBTARANIS - -void soft_power_off() -{ - GPIO_ResetBits(GPIOPWR,PIN_MCU_PWR); -} - -uint32_t check_soft_power() -{ - if (GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET) - return POWER_ON; - else - return POWER_OFF; -} - -void init_soft_power() -{ - RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN ; // Enable portD clock - GPIO_ResetBits(GPIOPWR, PIN_INT_RF_PWR | PIN_EXT_RF_PWR); - - /* GPIO Configuration*/ - configure_pins( PIN_INT_RF_PWR | PIN_EXT_RF_PWR | PIN_MCU_PWR, PIN_OUTPUT | PIN_PUSHPULL | PIN_OS25 | PIN_PORTD ) ; - - configure_pins( PIN_PWR_STATUS, PIN_INPUT | PIN_PULLUP | PIN_PORTD ) ; - - configure_pins( PIN_TRNDET, PIN_INPUT | PIN_PULLUP | PIN_PORTA ) ; - - // Soft power ON - - GPIO_SetBits(GPIOPWR,PIN_MCU_PWR); - -} - -#endif - diff --git a/radio/src/keys.cpp b/radio/src/keys.cpp index 3c76e5bba..c6f7c4096 100644 --- a/radio/src/keys.cpp +++ b/radio/src/keys.cpp @@ -37,6 +37,7 @@ #include "opentx.h" uint8_t s_evt; +struct t_inactivity inactivity = {0}; #if defined(CPUARM) uint8_t getEvent(bool trim) @@ -97,7 +98,9 @@ void Key::input(bool val, EnumKeys enuk) break; case KSTATE_RPTDELAY: // gruvin: delay state before first key repeat - if(m_cnt == KEY_LONG_DELAY) putEvent(EVT_KEY_LONG(enuk)); + if (m_cnt == KEY_LONG_DELAY) { + putEvent(EVT_KEY_LONG(enuk)); + } if (m_cnt == 40) { m_state = 16; m_cnt = 0; @@ -108,17 +111,19 @@ void Key::input(bool val, EnumKeys enuk) case 8: case 4: case 2: - if(m_cnt >= 48) { //3 6 12 24 48 pulses in every 480ms + if (m_cnt >= 48) { //3 6 12 24 48 pulses in every 480ms m_state >>= 1; m_cnt = 0; } // no break case 1: - if( (m_cnt & (m_state-1)) == 0) putEvent(EVT_KEY_REPT(enuk)); + if ((m_cnt & (m_state-1)) == 0) { + putEvent(EVT_KEY_REPT(enuk)); + } break; case KSTATE_PAUSE: //pause - if(m_cnt >= 64) { + if (m_cnt >= 64) { m_state = 8; m_cnt = 0; } diff --git a/radio/src/keys.h b/radio/src/keys.h new file mode 100755 index 000000000..350ab81d5 --- /dev/null +++ b/radio/src/keys.h @@ -0,0 +1,231 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef keys_h +#define keys_h + +enum EnumKeys { + KEY_MENU, + KEY_EXIT, +#if defined(PCBTARANIS) + KEY_ENTER, + KEY_PAGE, + KEY_PLUS, + KEY_MINUS, +#else + KEY_DOWN, + KEY_UP, + KEY_RIGHT, + KEY_LEFT, +#endif + + TRM_BASE, + TRM_LH_DWN = TRM_BASE, + TRM_LH_UP, + TRM_LV_DWN, + TRM_LV_UP, + TRM_RV_DWN, + TRM_RV_UP, + TRM_RH_DWN, + TRM_RH_UP, + +#if ROTARY_ENCODERS > 0 || defined(ROTARY_ENCODER_NAVIGATION) + BTN_REa, +#endif +#if ROTARY_ENCODERS > 0 + BTN_REb, +#endif + + NUM_KEYS, + SW_BASE=NUM_KEYS, + +#if defined(PCBTARANIS) + SW_SA0=SW_BASE, + SW_SA1, + SW_SA2, + SW_SB0, + SW_SB1, + SW_SB2, + SW_SC0, + SW_SC1, + SW_SC2, + SW_SD0, + SW_SD1, + SW_SD2, + SW_SE0, + SW_SE1, + SW_SE2, + SW_SF0, + SW_SF2, + SW_SG0, + SW_SG1, + SW_SG2, + SW_SH0, + SW_SH2, +#else + SW_ID0=SW_BASE, + SW_ID1, + SW_ID2, +#if defined(EXTRA_3POS) + SW_ID3, + SW_ID4, + SW_ID5, +#endif + + SW_THR, + SW_RUD, + SW_ELE, + SW_AIL, + SW_GEA, + SW_TRN, +#endif + +}; + +#define EVT_KEY_MASK(e) ((e) & 0x1f) + +#define _MSK_KEY_BREAK 0x20 +#define _MSK_KEY_REPT 0x40 +#define _MSK_KEY_FIRST 0x60 +#define _MSK_KEY_LONG 0x80 + +#define EVT_KEY_BREAK(key) ((key)|_MSK_KEY_BREAK) +#define EVT_KEY_FIRST(key) ((key)|_MSK_KEY_FIRST) +#define EVT_KEY_REPT(key) ((key)|_MSK_KEY_REPT) +#define EVT_KEY_LONG(key) ((key)|_MSK_KEY_LONG) + +#define IS_KEY_BREAK(evt) (((evt)&0xe0) == _MSK_KEY_BREAK) +#define IS_KEY_FIRST(evt) (((evt)&0xe0) == _MSK_KEY_FIRST) +#define IS_KEY_LONG(evt) (((evt)&0xe0) == _MSK_KEY_LONG) + +#define EVT_ENTRY 0xbf +#define EVT_ENTRY_UP 0xbe +#define EVT_MENU_UP 0xbd + +#if defined(PCBTARANIS) + #define EVT_ROTARY_BREAK EVT_KEY_BREAK(KEY_ENTER) + #define EVT_ROTARY_LONG EVT_KEY_LONG(KEY_ENTER) +#else + #define EVT_ROTARY_BREAK 0xcf + #define EVT_ROTARY_LONG 0xce + #define EVT_ROTARY_LEFT 0xdf + #define EVT_ROTARY_RIGHT 0xde +#endif + +#if defined(PCBTARANIS) + #define IS_ROTARY_LEFT(evt) (evt==EVT_KEY_FIRST(KEY_MINUS) || evt==EVT_KEY_REPT(KEY_MINUS)) + #define IS_ROTARY_RIGHT(evt) (evt==EVT_KEY_FIRST(KEY_PLUS) || evt==EVT_KEY_REPT(KEY_PLUS)) + #define IS_ROTARY_UP(evt) (evt==EVT_KEY_FIRST(KEY_PLUS) || evt==EVT_KEY_REPT(KEY_PLUS)) + #define IS_ROTARY_DOWN(evt) (evt==EVT_KEY_FIRST(KEY_MINUS) || evt==EVT_KEY_REPT(KEY_MINUS)) + #define IS_ROTARY_BREAK(evt) (evt==EVT_KEY_BREAK(KEY_ENTER)) + #define IS_ROTARY_LONG(evt) (evt==EVT_KEY_LONG(KEY_ENTER)) + #define IS_ROTARY_EVENT(evt) (0) + #define CASE_EVT_ROTARY_BREAK /*case EVT_KEY_BREAK(KEY_ENTER):*/ + #define CASE_EVT_ROTARY_LONG /*case EVT_KEY_LONG(KEY_ENTER):*/ + #define CASE_EVT_ROTARY_LEFT case EVT_KEY_FIRST(KEY_MOVE_DOWN): case EVT_KEY_REPT(KEY_MOVE_DOWN): + #define CASE_EVT_ROTARY_RIGHT case EVT_KEY_FIRST(KEY_MOVE_UP): case EVT_KEY_REPT(KEY_MOVE_UP): +#elif defined(ROTARY_ENCODER_NAVIGATION) + #define IS_ROTARY_LEFT(evt) (evt == EVT_ROTARY_LEFT) + #define IS_ROTARY_RIGHT(evt) (evt == EVT_ROTARY_RIGHT) + #define IS_ROTARY_UP(evt) IS_ROTARY_LEFT(evt) + #define IS_ROTARY_DOWN(evt) IS_ROTARY_RIGHT(evt) + #define IS_ROTARY_BREAK(evt) (evt == EVT_ROTARY_BREAK) + #define IS_ROTARY_LONG(evt) (evt == EVT_ROTARY_LONG) + #define IS_ROTARY_EVENT(evt) (EVT_KEY_MASK(evt) >= 0x0e) + #define CASE_EVT_ROTARY_BREAK case EVT_ROTARY_BREAK: + #define CASE_EVT_ROTARY_LONG case EVT_ROTARY_LONG: + #define CASE_EVT_ROTARY_LEFT case EVT_ROTARY_LEFT: + #define CASE_EVT_ROTARY_RIGHT case EVT_ROTARY_RIGHT: +#else + #define IS_ROTARY_LEFT(evt) (0) + #define IS_ROTARY_RIGHT(evt) (0) + #define IS_ROTARY_UP(evt) (0) + #define IS_ROTARY_DOWN(evt) (0) + #define IS_ROTARY_BREAK(evt) (0) + #define IS_ROTARY_LONG(evt) (0) + #define IS_ROTARY_EVENT(evt) (0) + #define CASE_EVT_ROTARY_BREAK + #define CASE_EVT_ROTARY_LONG + #define CASE_EVT_ROTARY_LEFT + #define CASE_EVT_ROTARY_RIGHT +#endif + +class Key +{ +#define FILTERBITS 4 + +#ifdef SIMU + #define FFVAL 1 +#else + #define FFVAL ((1< 0; } + void pauseEvents() { m_state = KSTATE_PAUSE; m_cnt = 0; } + void killEvents() { m_state = KSTATE_KILLED; } +}; + +extern Key keys[NUM_KEYS]; + +extern uint8_t s_evt; + +#define putEvent(evt) s_evt = evt + +void clearKeyEvents(); +void pauseEvents(uint8_t enuk); +void killEvents(uint8_t enuk); + +#if defined(CPUARM) + uint8_t getEvent(bool trim=false); +#else + uint8_t getEvent(); +#endif + +uint8_t keyDown(); + +#endif diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index a8090a9aa..2e3183b14 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -45,7 +45,6 @@ int16_t anas [NUM_INPUTS] = {0}; int16_t trims[NUM_STICKS] = {0}; int32_t chans[NUM_CHNOUT] = {0}; BeepANACenter bpanaCenter = 0; -struct t_inactivity inactivity = {0}; int24_t act [MAX_MIXERS] = {0}; SwOn swOn [MAX_MIXERS]; // TODO better name later... diff --git a/radio/src/opentx.h b/radio/src/opentx.h index aafcdacf6..d1fc73358 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -297,83 +297,6 @@ extern void boardInit(); #define NUM_STICKS 4 -enum EnumKeys { - KEY_MENU, - KEY_EXIT, -#if defined(PCBTARANIS) - KEY_ENTER, - KEY_PAGE, - KEY_PLUS, - KEY_MINUS, -#else - KEY_DOWN, - KEY_UP, - KEY_RIGHT, - KEY_LEFT, -#endif - - TRM_BASE, - TRM_LH_DWN = TRM_BASE, - TRM_LH_UP, - TRM_LV_DWN, - TRM_LV_UP, - TRM_RV_DWN, - TRM_RV_UP, - TRM_RH_DWN, - TRM_RH_UP, - -#if ROTARY_ENCODERS > 0 || defined(ROTARY_ENCODER_NAVIGATION) - BTN_REa, -#endif -#if ROTARY_ENCODERS > 0 - BTN_REb, -#endif - - NUM_KEYS, - SW_BASE=NUM_KEYS, - -#if defined(PCBTARANIS) - SW_SA0=SW_BASE, - SW_SA1, - SW_SA2, - SW_SB0, - SW_SB1, - SW_SB2, - SW_SC0, - SW_SC1, - SW_SC2, - SW_SD0, - SW_SD1, - SW_SD2, - SW_SE0, - SW_SE1, - SW_SE2, - SW_SF0, - SW_SF2, - SW_SG0, - SW_SG1, - SW_SG2, - SW_SH0, - SW_SH2, -#else - SW_ID0=SW_BASE, - SW_ID1, - SW_ID2, -#if defined(EXTRA_3POS) - SW_ID3, - SW_ID4, - SW_ID5, -#endif - - SW_THR, - SW_RUD, - SW_ELE, - SW_AIL, - SW_GEA, - SW_TRN, -#endif - -}; #if defined(PCBTARANIS) #define NUM_SWITCHES 8 @@ -587,35 +510,6 @@ extern uint8_t stickMode; extern uint8_t channel_order(uint8_t x); -class Key -{ -#define FILTERBITS 4 - -#ifdef SIMU - #define FFVAL 1 -#else - #define FFVAL ((1< 0; } - void pauseEvents() { m_state = KSTATE_PAUSE; m_cnt = 0; } - void killEvents() { m_state = KSTATE_KILLED; } -}; - -extern Key keys[NUM_KEYS]; - enum BaseCurves { CURVE_NONE, CURVE_X_GT0, @@ -630,77 +524,9 @@ enum BaseCurves { #define THRCHK_DEADBAND 16 #if defined(FSPLASH) || defined(XSPLASH) -#define SPLASH_TIMEOUT (g_eeGeneral.splashMode == 0 ? 60000/*infinite=10mn*/ : ((4*100) * (g_eeGeneral.splashMode & 0x03))) + #define SPLASH_TIMEOUT (g_eeGeneral.splashMode == 0 ? 60000/*infinite=10mn*/ : ((4*100) * (g_eeGeneral.splashMode & 0x03))) #else -#define SPLASH_TIMEOUT (4*100) // 4 seconds -#endif - -#define EVT_KEY_MASK(e) ((e) & 0x1f) - -#define _MSK_KEY_BREAK 0x20 -#define _MSK_KEY_REPT 0x40 -#define _MSK_KEY_FIRST 0x60 -#define _MSK_KEY_LONG 0x80 - -#define EVT_KEY_BREAK(key) ((key)|_MSK_KEY_BREAK) -#define EVT_KEY_FIRST(key) ((key)|_MSK_KEY_FIRST) -#define EVT_KEY_REPT(key) ((key)|_MSK_KEY_REPT) -#define EVT_KEY_LONG(key) ((key)|_MSK_KEY_LONG) - -#define IS_KEY_BREAK(evt) (((evt)&0xe0) == _MSK_KEY_BREAK) -#define IS_KEY_FIRST(evt) (((evt)&0xe0) == _MSK_KEY_FIRST) -#define IS_KEY_LONG(evt) (((evt)&0xe0) == _MSK_KEY_LONG) - -#define EVT_ENTRY 0xbf -#define EVT_ENTRY_UP 0xbe -#define EVT_MENU_UP 0xbd - -#if defined(PCBTARANIS) - #define EVT_ROTARY_BREAK EVT_KEY_BREAK(KEY_ENTER) - #define EVT_ROTARY_LONG EVT_KEY_LONG(KEY_ENTER) -#else - #define EVT_ROTARY_BREAK 0xcf - #define EVT_ROTARY_LONG 0xce - #define EVT_ROTARY_LEFT 0xdf - #define EVT_ROTARY_RIGHT 0xde -#endif - -#if defined(PCBTARANIS) - #define IS_ROTARY_LEFT(evt) (evt==EVT_KEY_FIRST(KEY_MINUS) || evt==EVT_KEY_REPT(KEY_MINUS)) - #define IS_ROTARY_RIGHT(evt) (evt==EVT_KEY_FIRST(KEY_PLUS) || evt==EVT_KEY_REPT(KEY_PLUS)) - #define IS_ROTARY_UP(evt) (evt==EVT_KEY_FIRST(KEY_PLUS) || evt==EVT_KEY_REPT(KEY_PLUS)) - #define IS_ROTARY_DOWN(evt) (evt==EVT_KEY_FIRST(KEY_MINUS) || evt==EVT_KEY_REPT(KEY_MINUS)) - #define IS_ROTARY_BREAK(evt) (evt==EVT_KEY_BREAK(KEY_ENTER)) - #define IS_ROTARY_LONG(evt) (evt==EVT_KEY_LONG(KEY_ENTER)) - #define IS_ROTARY_EVENT(evt) (0) - #define CASE_EVT_ROTARY_BREAK /*case EVT_KEY_BREAK(KEY_ENTER):*/ - #define CASE_EVT_ROTARY_LONG /*case EVT_KEY_LONG(KEY_ENTER):*/ - #define CASE_EVT_ROTARY_LEFT case EVT_KEY_FIRST(KEY_MOVE_DOWN): case EVT_KEY_REPT(KEY_MOVE_DOWN): - #define CASE_EVT_ROTARY_RIGHT case EVT_KEY_FIRST(KEY_MOVE_UP): case EVT_KEY_REPT(KEY_MOVE_UP): -#elif defined(ROTARY_ENCODER_NAVIGATION) - #define IS_ROTARY_LEFT(evt) (evt == EVT_ROTARY_LEFT) - #define IS_ROTARY_RIGHT(evt) (evt == EVT_ROTARY_RIGHT) - #define IS_ROTARY_UP(evt) IS_ROTARY_LEFT(evt) - #define IS_ROTARY_DOWN(evt) IS_ROTARY_RIGHT(evt) - #define IS_ROTARY_BREAK(evt) (evt == EVT_ROTARY_BREAK) - #define IS_ROTARY_LONG(evt) (evt == EVT_ROTARY_LONG) - #define IS_ROTARY_EVENT(evt) (EVT_KEY_MASK(evt) >= 0x0e) - #define CASE_EVT_ROTARY_BREAK case EVT_ROTARY_BREAK: - #define CASE_EVT_ROTARY_LONG case EVT_ROTARY_LONG: - #define CASE_EVT_ROTARY_LEFT case EVT_ROTARY_LEFT: - #define CASE_EVT_ROTARY_RIGHT case EVT_ROTARY_RIGHT: -#else - #define IS_ROTARY_LEFT(evt) (0) - #define IS_ROTARY_RIGHT(evt) (0) - #define IS_ROTARY_UP(evt) (0) - #define IS_ROTARY_DOWN(evt) (0) - #define IS_ROTARY_BREAK(evt) (0) - #define IS_ROTARY_LONG(evt) (0) - #define IS_ROTARY_EVENT(evt) (0) - #define CASE_EVT_ROTARY_BREAK - #define CASE_EVT_ROTARY_LONG - #define CASE_EVT_ROTARY_LEFT - #define CASE_EVT_ROTARY_RIGHT + #define SPLASH_TIMEOUT (4*100) // 4 seconds #endif #if defined(PCBTARANIS) @@ -734,6 +560,7 @@ struct t_inactivity uint16_t counter; uint8_t sum; }; + extern struct t_inactivity inactivity; #if defined(PXX) @@ -754,25 +581,8 @@ void str2zchar(char *dest, const char *src, int size); void zchar2str(char *dest, const char *src, int size); #endif -extern uint8_t s_evt; -#define putEvent(evt) s_evt = evt -void clearKeyEvents(); -void pauseEvents(uint8_t enuk); -void killEvents(uint8_t enuk); -#if defined(CPUARM) - uint8_t getEvent(bool trim); -#else - uint8_t getEvent(); -#endif - -uint8_t keyDown(); - -enum PowerState { - e_power_on, - e_power_trainer, - e_power_usb, - e_power_off -}; +#include "keys.h" +#include "pwr.h" bool switchState(EnumKeys enuk); uint8_t trimDown(uint8_t idx); diff --git a/radio/src/pwr.h b/radio/src/pwr.h new file mode 100755 index 000000000..b6816d590 --- /dev/null +++ b/radio/src/pwr.h @@ -0,0 +1,47 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef pwr_h +#define pwr_h + +enum PowerState { + e_power_on, + e_power_trainer, + e_power_usb, + e_power_off +}; + +#endif diff --git a/radio/src/targets/taranis/board_taranis.cpp b/radio/src/targets/taranis/board_taranis.cpp index 754f6e6c1..5266f1c98 100644 --- a/radio/src/targets/taranis/board_taranis.cpp +++ b/radio/src/targets/taranis/board_taranis.cpp @@ -44,22 +44,6 @@ extern "C" { volatile uint32_t Tenms ; // TODO to remove everywhere / use a #define -#define PIN_MODE_MASK 0x0003 -#define PIN_INPUT 0x0000 -#define PIN_OUTPUT 0x0001 -#define PIN_PERIPHERAL 0x0002 -#define PIN_ANALOG 0x0003 -#define PIN_PULL_MASK 0x000C -#define PIN_PULLUP 0x0004 -#define PIN_NO_PULLUP 0x0000 -#define PIN_PULLDOWN 0x0008 -#define PIN_NO_PULLDOWN 0x0000 -#define PIN_PERI_MASK 0x00F0 -#define PIN_PUSHPULL 0x0000 -#define PIN_ODRAIN 0x8000 -#define PIN_PORT_MASK 0x0700 -#define PIN_SPEED_MASK 0x6000 - #if !defined(SIMU) void configure_pins( uint32_t pins, uint16_t config ) { @@ -106,32 +90,6 @@ void configure_pins( uint32_t pins, uint16_t config ) } #endif -bool usbPlugged(void) -{ - return GPIO_ReadInputDataBit(GPIOA, PIN_FS_VBUS); -} - -#if !defined(SIMU) -extern "C" { -USB_OTG_CORE_HANDLE USB_OTG_dev; - -void OTG_FS_IRQHandler(void) -{ - USBD_OTG_ISR_Handler (&USB_OTG_dev); -} -} - -void usbInit() -{ - USB_OTG_BSP_Init(&USB_OTG_dev); -} - -void usbStart() -{ - USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb); -} -#endif - void watchdogInit(unsigned int duration) { IWDG->KR = 0x5555 ; // Unlock registers diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index f561e979d..6a1a1e783 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -75,6 +75,22 @@ extern "C" { #define JACK_PPM_OUT() #define JACK_PPM_IN() +#define PIN_MODE_MASK 0x0003 +#define PIN_INPUT 0x0000 +#define PIN_OUTPUT 0x0001 +#define PIN_PERIPHERAL 0x0002 +#define PIN_ANALOG 0x0003 +#define PIN_PULL_MASK 0x000C +#define PIN_PULLUP 0x0004 +#define PIN_NO_PULLUP 0x0000 +#define PIN_PULLDOWN 0x0008 +#define PIN_NO_PULLDOWN 0x0000 +#define PIN_PERI_MASK 0x00F0 +#define PIN_PUSHPULL 0x0000 +#define PIN_ODRAIN 0x8000 +#define PIN_PORT_MASK 0x0700 +#define PIN_SPEED_MASK 0x6000 + void configure_pins( uint32_t pins, uint16_t config ); #define strcpy_P strcpy @@ -160,6 +176,10 @@ extern volatile uint16_t Analog_values[]; #define BATT_SCALE 150 #endif +#ifdef __cplusplus +extern "C" { +#endif + // Power driver void pwrInit(void); uint32_t pwrCheck(void); @@ -176,13 +196,15 @@ void pwrOff(void); #define __BACKLIGHT_OFF TIM10->CCR1 = 0 #define IS_BACKLIGHT_ON() (TIM10->CCR1 != 0) -#if !defined(BOOT) // USB driver +int usbPlugged(void); #define BOOTLOADER_REQUEST() (0) #define usbBootloader() void usbInit(void); void usbStart(void); -bool usbPlugged(void); + +#ifdef __cplusplus +} #endif // EEPROM driver diff --git a/radio/src/targets/taranis/pwr_driver.cpp b/radio/src/targets/taranis/pwr_driver.c similarity index 92% rename from radio/src/targets/taranis/pwr_driver.cpp rename to radio/src/targets/taranis/pwr_driver.c index dd43832c6..43c353a6a 100644 --- a/radio/src/targets/taranis/pwr_driver.cpp +++ b/radio/src/targets/taranis/pwr_driver.c @@ -34,26 +34,8 @@ * */ -#include "../../opentx.h" - -void pwrOff() -{ - GPIO_ResetBits(GPIOPWR,PIN_MCU_PWR); -} - -uint32_t pwrCheck() -{ -#if defined(SIMU) - return e_power_on; -#else - if (GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET) - return e_power_on; - else if (usbPlugged()) - return e_power_usb; - else - return e_power_off; -#endif -} +#include "board_taranis.h" +#include "../src/pwr.h" void pwrInit() { @@ -101,5 +83,25 @@ void pwrInit() #endif // Soft power ON - GPIO_SetBits(GPIOPWR,PIN_MCU_PWR); + GPIO_SetBits(GPIOPWR, PIN_MCU_PWR); +} + +void pwrOff() +{ + GPIO_ResetBits(GPIOPWR, PIN_MCU_PWR); +} + +// TODO enums should be UPPERCASE +uint32_t pwrCheck() +{ +#if defined(SIMU) + return e_power_on; +#else + if (GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET) + return e_power_on; + else if (usbPlugged()) + return e_power_usb; + else + return e_power_off; +#endif } diff --git a/radio/src/targets/taranis/usb_driver.c b/radio/src/targets/taranis/usb_driver.c new file mode 100755 index 000000000..734756c09 --- /dev/null +++ b/radio/src/targets/taranis/usb_driver.c @@ -0,0 +1,59 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include "board_taranis.h" + +int usbPlugged(void) +{ + return GPIO_ReadInputDataBit(GPIOA, PIN_FS_VBUS); +} + +USB_OTG_CORE_HANDLE USB_OTG_dev; + +void OTG_FS_IRQHandler(void) +{ + USBD_OTG_ISR_Handler (&USB_OTG_dev); +} + +void usbInit() +{ + USB_OTG_BSP_Init(&USB_OTG_dev); +} + +void usbStart() +{ + USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb); +}