[X9D] Patch from Robert@FrSky amended with #ifdef, thanks Robert!

This commit is contained in:
bsongis
2013-03-11 09:24:53 +00:00
parent 2d1f3e3441
commit a81d77b364
2 changed files with 52 additions and 18 deletions
+22 -4
View File
@@ -38,6 +38,7 @@
#define PIN_ANALOG 0x0003 #define PIN_ANALOG 0x0003
#define PIN_PORTA 0x0000 #define PIN_PORTA 0x0000
#define PIN_PORTB 0x0100
#define PIN_PORTC 0x0200 #define PIN_PORTC 0x0200
#define STICK_LV 3 #define STICK_LV 3
@@ -45,7 +46,11 @@
#define STICK_RV 0 #define STICK_RV 0
#define STICK_RH 1 #define STICK_RH 1
#define POT_L 6 #define POT_L 6
#define POT_R 7 #if defined(REV3)
#define POT_R 7
#else
#define POT_R 8
#endif
#define SLIDE_L 14 #define SLIDE_L 14
#define SLIDE_R 15 #define SLIDE_R 15
#define BATTERY 10 #define BATTERY 10
@@ -54,6 +59,9 @@
#define SAMPTIME 2 // sample time = 15 cycles #define SAMPTIME 2 // sample time = 15 cycles
volatile uint16_t Analog_values[NUMBER_ANALOG]; volatile uint16_t Analog_values[NUMBER_ANALOG];
#if !defined(REV3)
const char ana_direction[NUMBER_ANALOG] = {0,1,1,1, 1,0,1,0, 0};
#endif
void adcInit() void adcInit()
{ {
@@ -61,8 +69,9 @@ void adcInit()
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOADC ; // Enable ports A&C clocks RCC->AHB1ENR |= RCC_AHB1Periph_GPIOADC ; // Enable ports A&C clocks
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN ; // Enable DMA2 clock RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN ; // Enable DMA2 clock
configure_pins( PIN_STK_J1 | PIN_STK_J2 | PIN_STK_J3 | PIN_STK_J4 | configure_pins( PIN_STK_J1 | PIN_STK_J2 | PIN_STK_J3 | PIN_STK_J4 |
PIN_FLP_J1 | PIN_FLP_J2, PIN_ANALOG | PIN_PORTA ) ; PIN_FLP_J1, PIN_ANALOG | PIN_PORTA ) ;
configure_pins( PIN_SLD_J1 | PIN_SLD_J2 | PIN_MVOLT, PIN_ANALOG | PIN_PORTC ) ; configure_pins( PIN_SLD_J1 | PIN_SLD_J2 | PIN_MVOLT, PIN_ANALOG | PIN_PORTC ) ;
configure_pins(PIN_FLP_J2, PIN_ANALOG|PIN_PORTB);
ADC1->CR1 = ADC_CR1_SCAN ; ADC1->CR1 = ADC_CR1_SCAN ;
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS ; ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS ;
@@ -93,13 +102,22 @@ void adcRead()
DMA2_Stream0->NDTR = NUMBER_ANALOG ; DMA2_Stream0->NDTR = NUMBER_ANALOG ;
DMA2_Stream0->CR |= DMA_SxCR_EN ; // Enable DMA DMA2_Stream0->CR |= DMA_SxCR_EN ; // Enable DMA
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART ; ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART ;
for ( i = 0 ; i < 10000 ; i += 1 ) { for (i=0; i<10000; i++) {
if ( DMA2->LISR & DMA_LISR_TCIF0 ) { if (DMA2->LISR & DMA_LISR_TCIF0) {
break ; break ;
} }
} }
DMA2_Stream0->CR &= ~DMA_SxCR_EN ; // Disable DMA DMA2_Stream0->CR &= ~DMA_SxCR_EN ; // Disable DMA
// return ( i < 10000 ) ? 1 : 0 ; // return ( i < 10000 ) ? 1 : 0 ;
#if !defined(REV3)
// adc direction correct
for (i=0; i<NUMBER_ANALOG; i++) {
if (ana_direction[i]) {
Analog_values[i] = 4096-Analog_values[i];
}
}
#endif
} }
// TODO // TODO
+28 -12
View File
@@ -15,11 +15,11 @@
#define GPIO_BUTTON_EXIT GPIOD->IDR #define GPIO_BUTTON_EXIT GPIOD->IDR
#define GPIO_BUTTON_PAGE GPIOD->IDR #define GPIO_BUTTON_PAGE GPIOD->IDR
#define PIN_BUTTON_PLUS GPIO_Pin_10 //SW3 PE.10 #define PIN_BUTTON_PLUS GPIO_Pin_10 //SW3 PE.10
#define PIN_BUTTON_MINUS GPIO_Pin_11 //SW1 PE.12 #define PIN_BUTTON_MINUS GPIO_Pin_11 //SW1 PE.12
#define PIN_BUTTON_ENTER GPIO_Pin_12 //SW2 PE.11 #define PIN_BUTTON_ENTER GPIO_Pin_12 //SW2 PE.11
#define PIN_BUTTON_MENU GPIO_Pin_7 //SW4 PD.07 #define PIN_BUTTON_MENU GPIO_Pin_7 //SW4 PD.07
#define PIN_BUTTON_PAGE GPIO_Pin_3 //SW6 PD.02 #define PIN_BUTTON_PAGE GPIO_Pin_3 //SW6 PD.02
#define PIN_BUTTON_EXIT GPIO_Pin_2 //SW5 PD.03 #define PIN_BUTTON_EXIT GPIO_Pin_2 //SW5 PD.03
// Trims // Trims
#define GPIO_TRIM_LH_L GPIOE->IDR #define GPIO_TRIM_LH_L GPIOE->IDR
@@ -34,10 +34,15 @@
#define PIN_TRIM_RV_UP GPIO_Pin_2 //PC.02 #define PIN_TRIM_RV_UP GPIO_Pin_2 //PC.02
#define PIN_TRIM_RH_L GPIO_Pin_1 //PC.01 #define PIN_TRIM_RH_L GPIO_Pin_1 //PC.01
#define PIN_TRIM_RH_R GPIO_Pin_13 //PC.13 #define PIN_TRIM_RH_R GPIO_Pin_13 //PC.13
#define PIN_TRIM_LH_R GPIO_Pin_4 //PE.04 #if defined(REV3)
#define PIN_TRIM_LH_L GPIO_Pin_3 //PE.03 #define PIN_TRIM_LH_R GPIO_Pin_4 //PE.04
#define PIN_TRIM_LV_DN GPIO_Pin_6 //PE.06 #define PIN_TRIM_LH_L GPIO_Pin_3 //PE.03
#define PIN_TRIM_LV_UP GPIO_Pin_5 //PE.05 #else
#define PIN_TRIM_LH_L GPIO_Pin_4 //PE.04
#define PIN_TRIM_LH_R GPIO_Pin_3 //PE.03
#endif
#define PIN_TRIM_LV_DN GPIO_Pin_6 //PE.06
#define PIN_TRIM_LV_UP GPIO_Pin_5 //PE.05
// Switchs // Switchs
#if defined(REV3) #if defined(REV3)
@@ -127,9 +132,17 @@
#define PIN_SLD_J1 GPIO_Pin_4 //PC.04 #define PIN_SLD_J1 GPIO_Pin_4 //PC.04
#define PIN_SLD_J2 GPIO_Pin_5 //PC.05 #define PIN_SLD_J2 GPIO_Pin_5 //PC.05
#define PIN_FLP_J1 GPIO_Pin_6 //PA.06 #define PIN_FLP_J1 GPIO_Pin_6 //PA.06
#define PIN_FLP_J2 GPIO_Pin_7 //PA.07 #if defined(REV3)
#define PIN_FLP_J2 GPIO_Pin_7 //PA.07
#else
#define PIN_FLP_J2 GPIO_Pin_0 //PB.00
#endif
#define PIN_MVOLT GPIO_Pin_0 //PC.00 #define PIN_MVOLT GPIO_Pin_0 //PC.00
#define RCC_AHB1Periph_GPIOADC RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC #if defined(REV3)
#define RCC_AHB1Periph_GPIOADC RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC
#else
#define RCC_AHB1Periph_GPIOADC RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC
#endif
// DAC // DAC
#define PIN_AUDIO_DAC GPIO_Pin_4 //PA.04 #define PIN_AUDIO_DAC GPIO_Pin_4 //PA.04
@@ -143,13 +156,14 @@
#define GPIOPWR GPIOD #define GPIOPWR GPIOD
// Trainer Port // Trainer Port
#define PIN_TR_PPM_IN GPIO_Pin_5 //PC.08 #define PIN_TR_PPM_IN GPIO_Pin_8 //PC.08
#define PIN_TR_PPM_OUT GPIO_Pin_9 //PC.09 #define PIN_TR_PPM_OUT GPIO_Pin_9 //PC.09
// TODO merge these constants // TODO merge these constants
#define PIN_PER_1 0x0010 #define PIN_PER_1 0x0010
#define PIN_PORTA 0x0000 #define PIN_PORTA 0x0000
#define PIN_PER_3 0x030 #define PIN_PER_3 0x0030
#define PIN_PER_5 0x0050
// #define PIN_OS2 0x0000 // #define PIN_OS2 0x0000
#define PIN_OS25 0x2000 #define PIN_OS25 0x2000
// #define PIN_OS50 0x4000 // #define PIN_OS50 0x4000
@@ -157,7 +171,7 @@
// Cppm // Cppm
#define RCC_AHB1Periph_GPIOCPPM RCC_AHB1Periph_GPIOA #define RCC_AHB1Periph_GPIOCPPM RCC_AHB1Periph_GPIOA
#define PIN_CPPM_OUT GPIO_Pin_8 //PA.08 #define PIN_CPPM_OUT GPIO_Pin_7 //PA.07
#define GPIOCPPM GPIOA #define GPIOCPPM GPIOA
#define GPIO_PinSource_CPPM GPIO_PinSource8 #define GPIO_PinSource_CPPM GPIO_PinSource8
@@ -304,5 +318,7 @@
#define DMA_Channel_SPI_SD_TX DMA1_Channel3 #define DMA_Channel_SPI_SD_TX DMA1_Channel3
#define DMA_FLAG_SPI_SD_TC_RX DMA1_FLAG_TC2 #define DMA_FLAG_SPI_SD_TC_RX DMA1_FLAG_TC2
#define DMA_FLAG_SPI_SD_TC_TX DMA1_FLAG_TC3 #define DMA_FLAG_SPI_SD_TC_TX DMA1_FLAG_TC3
#define DMA_Channel_SPI1_TX DMA_Channel_3
#define DMA_Stream_SPI1_TX DMA2_Stream3
#endif #endif