This commit is contained in:
bsongis
2015-06-28 16:12:49 +02:00
parent d96f1f3400
commit 18d8edce36
3 changed files with 124 additions and 125 deletions
+16 -16
View File
@@ -117,31 +117,31 @@ void simuInit()
break; break;
#if defined(CPUARM) #if defined(CPUARM)
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
#define SWITCH_CASE NEG_CASE #define SWITCH_CASE NEG_CASE
#else #else
#define SWITCH_CASE POS_CASE #define SWITCH_CASE POS_CASE
#endif #endif
#define SWITCH_3_CASE(swtch, pin1, pin2, mask1, mask2) \ #define SWITCH_3_CASE(swtch, pin1, pin2, mask1, mask2) \
case swtch: \ case swtch: \
if ((int)state < 0) pin1 &= ~(mask1); else pin1 |= (mask1); \ if ((int)state < 0) pin1 &= ~(mask1); else pin1 |= (mask1); \
if ((int)state > 0) pin2 &= ~(mask2); else pin2 |= (mask2); \ if ((int)state > 0) pin2 &= ~(mask2); else pin2 |= (mask2); \
break; break;
#define KEY_CASE NEG_CASE #define KEY_CASE NEG_CASE
#define TRIM_CASE KEY_CASE #define TRIM_CASE NEG_CASE
#else #else
#if defined(PCBMEGA2560) #if defined(PCBMEGA2560)
#define SWITCH_CASE POS_CASE #define SWITCH_CASE POS_CASE
#else #else
#define SWITCH_CASE NEG_CASE #define SWITCH_CASE NEG_CASE
#endif #endif
#define SWITCH_3_CASE(swtch, pin1, pin2, mask1, mask2) \ #define SWITCH_3_CASE(swtch, pin1, pin2, mask1, mask2) \
case swtch: \ case swtch: \
if ((int)state >= 0) pin1 &= ~(mask1); else pin1 |= (mask1); \ if ((int)state >= 0) pin1 &= ~(mask1); else pin1 |= (mask1); \
if ((int)state <= 0) pin2 &= ~(mask2); else pin2 |= (mask2); \ if ((int)state <= 0) pin2 &= ~(mask2); else pin2 |= (mask2); \
break; break;
#define KEY_CASE POS_CASE #define KEY_CASE POS_CASE
#define TRIM_CASE KEY_CASE #define TRIM_CASE KEY_CASE
#endif #endif
void simuSetKey(uint8_t key, bool state) void simuSetKey(uint8_t key, bool state)
+104 -105
View File
@@ -43,114 +43,114 @@
extern uint16_t ResetReason; extern uint16_t ResetReason;
#define BOOTLOADER_SIZE 0x8000 #define BOOTLOADER_SIZE 0x8000
#define FIRMWARE_SIZE (256*1024) #define FIRMWARE_SIZE (256*1024)
#define FIRMWARE_ADDRESS 0x00400000 #define FIRMWARE_ADDRESS 0x00400000
#if defined(REVA) #if defined(REVA)
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR #define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
#define KEYS_GPIO_REG_EXIT PIOA->PIO_PDSR #define KEYS_GPIO_REG_EXIT PIOA->PIO_PDSR
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR #define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR #define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR #define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR #define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
#define KEYS_GPIO_PIN_MENU 0x00000040 #define KEYS_GPIO_PIN_MENU 0x00000040
#define KEYS_GPIO_PIN_EXIT 0x80000000 #define KEYS_GPIO_PIN_EXIT 0x80000000
#define KEYS_GPIO_PIN_UP 0x00000004 #define KEYS_GPIO_PIN_UP 0x00000004
#define KEYS_GPIO_PIN_DOWN 0x00000008 #define KEYS_GPIO_PIN_DOWN 0x00000008
#define KEYS_GPIO_PIN_RIGHT 0x00000010 #define KEYS_GPIO_PIN_RIGHT 0x00000010
#define KEYS_GPIO_PIN_LEFT 0x00000020 #define KEYS_GPIO_PIN_LEFT 0x00000020
#else #else
#define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR #define KEYS_GPIO_REG_MENU PIOB->PIO_PDSR
#define KEYS_GPIO_REG_EXIT PIOC->PIO_PDSR #define KEYS_GPIO_REG_EXIT PIOC->PIO_PDSR
#define KEYS_GPIO_REG_UP PIOC->PIO_PDSR #define KEYS_GPIO_REG_UP PIOC->PIO_PDSR
#define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR #define KEYS_GPIO_REG_DOWN PIOC->PIO_PDSR
#define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR #define KEYS_GPIO_REG_RIGHT PIOC->PIO_PDSR
#define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR #define KEYS_GPIO_REG_LEFT PIOC->PIO_PDSR
#define KEYS_GPIO_PIN_MENU 0x00000020 #define KEYS_GPIO_PIN_MENU 0x00000020
#define KEYS_GPIO_PIN_EXIT 0x01000000 #define KEYS_GPIO_PIN_EXIT 0x01000000
#define KEYS_GPIO_PIN_UP 0x00000002 #define KEYS_GPIO_PIN_UP 0x00000002
#define KEYS_GPIO_PIN_DOWN 0x00000020 #define KEYS_GPIO_PIN_DOWN 0x00000020
#define KEYS_GPIO_PIN_RIGHT 0x00000010 #define KEYS_GPIO_PIN_RIGHT 0x00000010
#define KEYS_GPIO_PIN_LEFT 0x00000008 #define KEYS_GPIO_PIN_LEFT 0x00000008
#endif #endif
#if defined(REVX) #if defined(REVX)
#define TRIMS_GPIO_REG_LHL PIOB->PIO_PDSR #define TRIMS_GPIO_REG_LHL PIOB->PIO_PDSR
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR #define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_RVU PIOC->PIO_PDSR #define TRIMS_GPIO_REG_RVU PIOC->PIO_PDSR
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR #define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_LHR PIOA->PIO_PDSR #define TRIMS_GPIO_REG_LHR PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR #define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
#define TRIMS_GPIO_REG_RVD PIOA->PIO_PDSR #define TRIMS_GPIO_REG_RVD PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR #define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
#else #else
#define TRIMS_GPIO_REG_LHL PIOA->PIO_PDSR #define TRIMS_GPIO_REG_LHL PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR #define TRIMS_GPIO_REG_LVD PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_RVU PIOA->PIO_PDSR #define TRIMS_GPIO_REG_RVU PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR #define TRIMS_GPIO_REG_RHL PIOA->PIO_PDSR
#define TRIMS_GPIO_REG_LHR PIOB->PIO_PDSR #define TRIMS_GPIO_REG_LHR PIOB->PIO_PDSR
#define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR #define TRIMS_GPIO_REG_LVU PIOC->PIO_PDSR
#define TRIMS_GPIO_REG_RVD PIOC->PIO_PDSR #define TRIMS_GPIO_REG_RVD PIOC->PIO_PDSR
#define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR #define TRIMS_GPIO_REG_RHR PIOC->PIO_PDSR
#endif #endif
#if defined(REVX) #if defined(REVX)
#define TRIMS_GPIO_PIN_LHL 0x00000010 #define TRIMS_GPIO_PIN_LHL 0x00000010
#define TRIMS_GPIO_PIN_LVD 0x01000000 #define TRIMS_GPIO_PIN_LVD 0x01000000
#define TRIMS_GPIO_PIN_RVU 0x00000400 #define TRIMS_GPIO_PIN_RVU 0x00000400
#define TRIMS_GPIO_PIN_RHL 0x00000001 #define TRIMS_GPIO_PIN_RHL 0x00000001
#define TRIMS_GPIO_PIN_LHR 0x00800000 #define TRIMS_GPIO_PIN_LHR 0x00800000
#define TRIMS_GPIO_PIN_LVU 0x10000000 #define TRIMS_GPIO_PIN_LVU 0x10000000
#define TRIMS_GPIO_PIN_RVD 0x00000002 #define TRIMS_GPIO_PIN_RVD 0x00000002
#define TRIMS_GPIO_PIN_RHR 0x00000200 #define TRIMS_GPIO_PIN_RHR 0x00000200
#elif defined(REVA) #elif defined(REVA)
#define TRIMS_GPIO_PIN_LHL 0x00000080 #define TRIMS_GPIO_PIN_LHL 0x00000080
#define TRIMS_GPIO_PIN_LVD 0x08000000 #define TRIMS_GPIO_PIN_LVD 0x08000000
#define TRIMS_GPIO_PIN_RVU 0x40000000 #define TRIMS_GPIO_PIN_RVU 0x40000000
#define TRIMS_GPIO_PIN_RHL 0x20000000 #define TRIMS_GPIO_PIN_RHL 0x20000000
#define TRIMS_GPIO_PIN_LHR 0x00000010 #define TRIMS_GPIO_PIN_LHR 0x00000010
#define TRIMS_GPIO_PIN_LVU 0x10000000 #define TRIMS_GPIO_PIN_LVU 0x10000000
#define TRIMS_GPIO_PIN_RVD 0x00000400 #define TRIMS_GPIO_PIN_RVD 0x00000400
#define TRIMS_GPIO_PIN_RHR 0x00000200 #define TRIMS_GPIO_PIN_RHR 0x00000200
#else #else
#define TRIMS_GPIO_PIN_LHL 0x00800000 #define TRIMS_GPIO_PIN_LHL 0x00800000
#define TRIMS_GPIO_PIN_LVD 0x01000000 #define TRIMS_GPIO_PIN_LVD 0x01000000
#define TRIMS_GPIO_PIN_RVU 0x00000002 #define TRIMS_GPIO_PIN_RVU 0x00000002
#define TRIMS_GPIO_PIN_RHL 0x00000001 #define TRIMS_GPIO_PIN_RHL 0x00000001
#define TRIMS_GPIO_PIN_LHR 0x00000010 #define TRIMS_GPIO_PIN_LHR 0x00000010
#define TRIMS_GPIO_PIN_LVU 0x10000000 #define TRIMS_GPIO_PIN_LVU 0x10000000
#define TRIMS_GPIO_PIN_RVD 0x00000400 #define TRIMS_GPIO_PIN_RVD 0x00000400
#define TRIMS_GPIO_PIN_RHR 0x00000200 #define TRIMS_GPIO_PIN_RHR 0x00000200
#endif #endif
void usbMassStorage(); void usbMassStorage();
#define PIN_ENABLE 0x001 #define PIN_ENABLE 0x001
#define PIN_PERIPHERAL 0x000 #define PIN_PERIPHERAL 0x000
#define PIN_INPUT 0x002 #define PIN_INPUT 0x002
#define PIN_OUTPUT 0x000 #define PIN_OUTPUT 0x000
#define PIN_PULLUP 0x004 #define PIN_PULLUP 0x004
#define PIN_NO_PULLUP 0x000 #define PIN_NO_PULLUP 0x000
#define PIN_PULLDOWN 0x008 #define PIN_PULLDOWN 0x008
#define PIN_NO_PULLDOWN 0x000 #define PIN_NO_PULLDOWN 0x000
#define PIN_PERI_MASK_L 0x010 #define PIN_PERI_MASK_L 0x010
#define PIN_PERI_MASK_H 0x020 #define PIN_PERI_MASK_H 0x020
#define PIN_PER_A 0x000 #define PIN_PER_A 0x000
#define PIN_PER_B 0x010 #define PIN_PER_B 0x010
#define PIN_PER_C 0x020 #define PIN_PER_C 0x020
#define PIN_PER_D 0x030 #define PIN_PER_D 0x030
#define PIN_PORT_MASK 0x0C0 #define PIN_PORT_MASK 0x0C0
#define PIN_PORTA 0x000 #define PIN_PORTA 0x000
#define PIN_PORTB 0x040 #define PIN_PORTB 0x040
#define PIN_PORTC 0x080 #define PIN_PORTC 0x080
#define PIN_LOW 0x000 #define PIN_LOW 0x000
#define PIN_HIGH 0x100 #define PIN_HIGH 0x100
// Telemetry port // Telemetry port
#define SECOND_USART USART0 #define SECOND_USART USART0
#define SECOND_ID ID_USART0 #define SECOND_ID ID_USART0
#define SECOND_PINS {PINS_USART0} #define SECOND_PINS { PINS_USART0 }
void configure_pins( uint32_t pins, uint16_t config ); void configure_pins( uint32_t pins, uint16_t config );
uint16_t getCurrent(); uint16_t getCurrent();
@@ -171,23 +171,22 @@ extern uint16_t sessionTimer;
void calcConsumption(); void calcConsumption();
#endif #endif
#define SLAVE_MODE() (pwrCheck() == e_power_trainer) #define SLAVE_MODE() (pwrCheck() == e_power_trainer)
// #define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22 // #define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22
// #define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22 // #define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22
void checkTrainerSettings(); void checkTrainerSettings();
void setSticksGain(uint8_t gains); void setSticksGain(uint8_t gains);
// Write Flash driver // Write Flash driver
#define FLASH_PAGESIZE 256 #define FLASH_PAGESIZE 256
void writeFlash(uint32_t * address, uint32_t * buffer); void writeFlash(uint32_t * address, uint32_t * buffer);
// Keys driver // Keys driver
extern uint32_t readKeys(); extern uint32_t readKeys();
extern uint32_t readTrims(); extern uint32_t readTrims();
#define TRIMS_PRESSED() (readTrims()) #define TRIMS_PRESSED() readTrims()
#define KEYS_PRESSED() (readKeys()) #define KEYS_PRESSED() readKeys()
// Pulses driver // Pulses driver
void init_no_pulses(uint32_t port); void init_no_pulses(uint32_t port);
@@ -218,15 +217,15 @@ void disable_dsm2(uint32_t port);
// WDT driver // WDT driver
#if !defined(SIMU) #if !defined(SIMU)
#define wdt_disable() #define wdt_disable()
#define wdt_enable(x) WDT->WDT_MR = 0x3FFF207F #define wdt_enable(x) WDT->WDT_MR = 0x3FFF207F
#define wdt_reset() WDT->WDT_CR = 0xA5000001 #define wdt_reset() WDT->WDT_CR = 0xA5000001
#endif #endif
// Backlight driver // Backlight driver
#define setBacklight(xx) (PWM->PWM_CH_NUM[0].PWM_CDTYUPD = xx) #define setBacklight(xx) (PWM->PWM_CH_NUM[0].PWM_CDTYUPD = xx)
#define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright) #define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
#define backlightDisable() (PWM->PWM_CH_NUM[0].PWM_CDTY = 100) #define backlightDisable() (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
#define isBacklightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100) #define isBacklightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
// ADC driver // ADC driver
void adcInit(); void adcInit();
@@ -236,7 +235,7 @@ inline uint16_t getAnalogValue(uint32_t value);
// Buzzer driver // Buzzer driver
void buzzerSound(uint8_t duration); void buzzerSound(uint8_t duration);
void buzzerHeartbeat(); void buzzerHeartbeat();
#define BUZZER_HEARTBEAT buzzerHeartbeat #define BUZZER_HEARTBEAT buzzerHeartbeat
// i2c driver // i2c driver
void i2cCheck(); void i2cCheck();
@@ -266,7 +265,7 @@ void btPushByte(uint8_t data);
void pwrInit(); void pwrInit();
void pwrOff(); void pwrOff();
uint32_t pwrCheck(); uint32_t pwrCheck();
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown) #define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
// EEPROM driver // EEPROM driver
void eepromInit(); void eepromInit();
@@ -277,9 +276,9 @@ void rotencInit();
void rotencEnd(); void rotencEnd();
#if ROTARY_ENCODERS > 0 #if ROTARY_ENCODERS > 0
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40)) #define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
#else #else
#define REA_DOWN() (0) #define REA_DOWN() (0)
#endif #endif
// Debug driver // Debug driver
+4 -4
View File
@@ -63,9 +63,9 @@ uint32_t readKeys()
result |= 0x02 << KEY_UP; result |= 0x02 << KEY_UP;
if (x & KEYS_GPIO_PIN_DOWN) if (x & KEYS_GPIO_PIN_DOWN)
result |= 0x02 << KEY_DOWN; result |= 0x02 << KEY_DOWN;
if (KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT) if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
result |= 0x02 << KEY_EXIT; result |= 0x02 << KEY_EXIT;
if (KEYS_GPIO_REG_MENU & 0x000000040) if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
result |= 0x02 << KEY_MENU; result |= 0x02 << KEY_MENU;
#else #else
if (x & KEYS_GPIO_PIN_RIGHT) if (x & KEYS_GPIO_PIN_RIGHT)
@@ -78,7 +78,7 @@ uint32_t readKeys()
result |= 0x02 << KEY_DOWN; result |= 0x02 << KEY_DOWN;
if (x & KEYS_GPIO_PIN_EXIT) if (x & KEYS_GPIO_PIN_EXIT)
result |= 0x02 << KEY_EXIT; result |= 0x02 << KEY_EXIT;
if (KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU) if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
result |= 0x02 << KEY_MENU; result |= 0x02 << KEY_MENU;
#endif #endif
@@ -130,7 +130,7 @@ void readKeysAndTrims()
#endif #endif
uint8_t enuk = KEY_MENU; uint8_t enuk = KEY_MENU;
uint8_t in = ~readKeys(); uint8_t in = readKeys();
for (i = 1; i < 7; i++) { for (i = 1; i < 7; i++) {
keys[enuk].input(in & (1 << i)); keys[enuk].input(in & (1 << i));
++enuk; ++enuk;