[MEGA2560] Special commit for Franck. Thanks!

This commit is contained in:
bsongis
2013-10-10 18:24:00 +00:00
parent e7a7916d8a
commit d08e1e8e7a
14 changed files with 584 additions and 449 deletions
+8 -13
View File
@@ -453,7 +453,7 @@ ifeq ($(PCB), GRUVIN9X)
TRGT = avr-
MCU = atmega2560
OPT = 2
CPPDEFS += -DF_CPU=$(F_CPU)UL -DPCBGRUVIN9X -DEEPROM_VARIANT=0 -DAUDIO -DHAPTIC
CPPDEFS += -DF_CPU=$(F_CPU)UL -DPCBGRUVIN9X -DCPUM2560 -DEEPROM_VARIANT=0 -DAUDIO -DHAPTIC
SDCARD = NO
BUZZER = NO
THR_TRACE = YES
@@ -492,27 +492,22 @@ ifeq ($(PCB), MEGA2560)
TRGT = avr-
MCU = atmega2560
OPT = 2
CPPDEFS = -DF_CPU=$(F_CPU)UL -DPCBGRUVIN9X -DEEPROM_VARIANT=0 -DAUDIO -DHAPTIC
SDCARD = NO
CPPDEFS = -DF_CPU=$(F_CPU)UL -DPCBMEGA2560 -DCPUM2560 -DEEPROM_VARIANT=0 -DAUDIO -DRTCLOCK
SDCARD = YES
THR_TRACE = YES
EXTRAINCDIRS = targets/gruvin9x targets/stock FatFs FatFs/option
EXTRAINCDIRS = targets/mega2560 targets/stock FatFs FatFs/option
BOARDSRC = targets/mega2560/board_mega2560.cpp
EXTRABOARDSRC = targets/mega2560/lcd_driver_ST7565R.cpp
EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp
PULSESSRC = protocols/pulses_avr.cpp
CPPSRC += audio_avr.cpp haptic.cpp
CPPSRC += audio_avr.cpp
ifeq ($(SDCARD), YES)
EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c targets/gruvin9x/diskio.cpp
CPPDEFS += -DRTCLOCK
CPPSRC += rtc.cpp targets/gruvin9x/rtc_driver.cpp
EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c targets/gruvin9x/diskio.cpp
CPPSRC += rtc.cpp targets/mega2560/rtc_driver.cpp
endif
ifeq ($(VOICE), YES)
CPPSRC += targets/gruvin9x/somo14d.cpp
CPPDEFS += -DVOICE
endif
# Enable extra rotary encoders (Gruvin9x board only)
# Values = YES, NO
ROTARY_ENCODERS = 2
+3 -3
View File
@@ -59,7 +59,7 @@ inline void eeprom_write_byte()
EEAR = eeprom_pointer;
EEDR = *eeprom_buffer_data;
// TODO add some define here
#if defined (PCBGRUVIN9X) || defined(CPUM2561)
#if defined (CPUM2560) || defined(CPUM2561)
EECR |= 1<<EEMPE;
EECR |= 1<<EEPE;
#else
@@ -76,7 +76,7 @@ ISR(EE_READY_vect)
eeprom_write_byte();
}
else {
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
EECR &= ~(1<<EERIE);
#else
EECR &= ~(1<<EERIE);
@@ -95,7 +95,7 @@ void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_
#if defined(SIMU)
sem_post(eeprom_write_sem);
#elif defined (PCBGRUVIN9X) || defined(CPUM2561)
#elif defined (CPUM2560) || defined(CPUM2561)
EECR |= (1<<EERIE);
#else
EECR |= (1<<EERIE);
+1 -1
View File
@@ -53,7 +53,7 @@
#define EEFS_VERS 5
#define MAXFILES 62
#define BS 64
#elif defined(PCBGRUVIN9X) || defined(CPUM2561) || defined(CPUM128)
#elif defined(CPUM2560) || defined(CPUM2561) || defined(CPUM128)
#define blkid_t uint8_t
#define EESIZE 4096
#define EEFS_VERS 5
+1 -1
View File
@@ -129,7 +129,7 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags)
* by ten bottom bytes (20 bytes per * char) */
q = &font_10x14[((uint16_t)c_remapped)*20];
for (int8_t i=11; i>=0; i--) {
if (flags & CONDENSED && i<=1) break;
if ((flags & CONDENSED) && i<=1) break;
uint8_t b1=0, b2=0;
if (i>1) {
b1 = pgm_read_byte(q++); /*top byte*/
+10 -20
View File
@@ -55,9 +55,7 @@
#define EEPROM_VER 215
#elif defined(PCBSKY9X)
#define EEPROM_VER 215
#elif defined(PCBGRUVIN9X)
#define EEPROM_VER 214
#elif defined(CPUM2561)
#elif defined(CPUM2560) || defined(CPUM2561)
#define EEPROM_VER 214
#elif defined(CPUM128)
#define EEPROM_VER 215
@@ -77,15 +75,7 @@
#define MAX_EXPOS 32
#define NUM_CSW 32 // number of custom switches
#define NUM_CFN 32 // number of functions assigned to switches
#elif defined(PCBGRUVIN9X)
#define MAX_MODELS 30
#define NUM_CHNOUT 16 // number of real output channels CH1-CH16
#define MAX_PHASES 6
#define MAX_MIXERS 32
#define MAX_EXPOS 16
#define NUM_CSW 15 // number of custom switches
#define NUM_CFN 24 // number of functions assigned to switches
#elif defined(CPUM2561)
#elif defined(CPUM2560) || defined(CPUM2561)
#define MAX_MODELS 30
#define NUM_CHNOUT 16 // number of real output channels CH1-CH16
#define MAX_PHASES 6
@@ -356,7 +346,7 @@ PACK(typedef struct t_ExpoData {
char name[LEN_EXPOMIX_NAME];
int8_t curveParam;
}) ExpoData;
#elif defined(PCBGRUVIN9X) || defined(CPUM2561)
#elif defined(CPUM2560) || defined(CPUM2561)
PACK(typedef struct t_ExpoData {
uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both
uint8_t chn:2;
@@ -481,7 +471,7 @@ PACK( union u_int8int16_t {
#define DELAY_MAX 15 /* 7.5 seconds */
#define SLOW_MAX 15 /* 7.5 seconds */
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
PACK(typedef struct t_MixData {
uint8_t destCh:4; // 0, 1..NUM_CHNOUT
uint8_t curveMode:1; // O=curve, 1=differential
@@ -972,7 +962,7 @@ PACK(typedef struct t_SwashRingData { // Swash Ring data
#define NUM_ROTARY_ENCODERS (2+NUM_ROTARY_ENCODERS_EXTRA)
#define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[2];
#define ROTARY_ENCODER_ARRAY_EXTRA int16_t rotaryEncodersExtra[MAX_PHASES][NUM_ROTARY_ENCODERS_EXTRA];
#elif defined(PCBGRUVIN9X) && ROTARY_ENCODERS <= 2
#elif defined(CPUM2560) && ROTARY_ENCODERS <= 2
#define NUM_ROTARY_ENCODERS_EXTRA 0
#define NUM_ROTARY_ENCODERS 2
#define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[2];
@@ -1119,7 +1109,7 @@ enum MixSources {
#if defined(PCBSKY9X)
MIXSRC_REa,
#elif defined(PCBGRUVIN9X)
#elif defined(PCBGRUVIN9X) || defined(PCBMEGA2560)
MIXSRC_REa,
MIXSRC_REb,
#if ROTARY_ENCODERS > 2
@@ -1208,7 +1198,7 @@ enum MixSources {
#define TMRMODE_THR_REL 3
#define TMRMODE_THR_TRG 4
#if defined(PCBGRUVIN9X) || defined(CPUARM)
#if defined(CPUARM) || defined(CPUM2560)
PACK(typedef struct t_TimerData {
int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
uint16_t start:12;
@@ -1292,10 +1282,10 @@ enum FailsafeModes {
#define TELEMETRY_DATA
#endif
#if defined(PCBGRUVIN9X) || defined(CPUARM)
#define BeepANACenter uint16_t
#if defined(CPUARM) || defined(PCBGRUVIN9X) || defined(PCBMEGA2560)
#define BeepANACenter uint16_t
#else
#define BeepANACenter uint8_t
#define BeepANACenter uint8_t
#endif
PACK(typedef struct t_ModelHeader {
+13 -42
View File
@@ -856,7 +856,7 @@ getvalue_t getValue(uint8_t i)
/*srcRaw is shifted +1!*/
if (i<NUM_STICKS+NUM_POTS) return calibratedStick[i];
#if defined(PCBGRUVIN9X) || defined(PCBSKY9X)
#if defined(PCBGRUVIN9X) || defined(PCBMEGA2560) || defined(PCBSKY9X)
else if (i<NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS) return getRotaryEncoder(i-(NUM_STICKS+NUM_POTS));
#endif
else if (i<MIXSRC_MAX) return 1024;
@@ -1936,7 +1936,7 @@ static uint16_t s_anaFilt[NUMBER_ANALOG];
#if defined(SIMU)
uint16_t BandGap = 225;
#elif defined(PCBGRUVIN9X)
#elif defined(CPUM2560)
// #define STARTADCONV (ADCSRA = (1<<ADEN) | (1<<ADPS0) | (1<<ADPS1) | (1<<ADPS2) | (1<<ADSC) | (1 << ADIE))
// G: Note that the above would have set the ADC prescaler to 128, equating to
// 125KHz sample rate. We now sample at 500KHz, with oversampling and other
@@ -2080,7 +2080,7 @@ void getADC()
#if !defined(CPUARM)
void getADC_bandgap()
{
#if defined (PCBGRUVIN9X)
#if defined(CPUM2560)
static uint8_t s_bgCheck = 0;
static uint16_t s_bgSum = 0;
ADCSRA|=0x40; // request sample
@@ -3167,7 +3167,7 @@ void doMixerCalculations()
Current_analogue = (Current_analogue*31 + s_anaFilt[8] ) >> 5 ;
if (Current_analogue > Current_max)
Current_max = Current_analogue ;
#elif defined(PCBGRUVIN9X) && !defined(SIMU)
#elif defined(CPUM2560) && !defined(SIMU)
// For PCB V4, use our own 1.2V, external reference (connected to ADC3)
ADCSRB &= ~(1<<MUX5);
ADMUX = 0x03|ADC_VREF_TYPE; // Switch MUX to internal reference
@@ -3599,7 +3599,7 @@ void opentxStart()
}
}
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUARM) || defined(CPUM2560)
void opentxClose()
{
#if defined(FRSKY)
@@ -3893,7 +3893,7 @@ void perMain()
#elif defined(PCBSKY9X)
instant_vbat = (instant_vbat + instant_vbat*(g_eeGeneral.vBatCalib)/128) * 4191;
instant_vbat /= 55296;
#elif defined(PCBGRUVIN9X)
#elif defined(CPUM2560)
instant_vbat = (instant_vbat*1112 + instant_vbat*g_eeGeneral.vBatCalib + (BandGap<<2)) / (BandGap<<3);
#else
instant_vbat = (instant_vbat*16 + instant_vbat*g_eeGeneral.vBatCalib/8) / BandGap;
@@ -4052,35 +4052,6 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS
cli(); // disable other interrupts for stack pops before this function's RETI
RESUME_PPMIN_INTERRUPT();
}
/*
// gruvin: Fuse declarations work if we use the .elf file for AVR Studio (v4)
// instead of the Intel .hex files. They should also work with AVRDUDE v5.10
// (reading from the .hex file), since a bug relating to Intel HEX file record
// interpretation was fixed. However, I leave these commented out, just in case
// it causes trouble for others.
#if defined (PCBGRUVIN9X)
// See fuses_2561.txt
FUSES =
{
// BOD=4.3V, WDT OFF (enabled in code), Boot Flash 4096 bytes at 0x1F000,
// JTAG and OCD enabled, EESAVE enabled, BOOTRST/CKDIV8/CKOUT disabled,
// Full swing Xtal oscillator. Start-up 16K clks + 0ms. BOD enabled.
0xD7, // .low
0x11, // .high
0xFC // .extended
};
#else
FUSES =
{
// G: Changed 2011-07-04 to include EESAVE. Tested OK on stock 9X
0x1F, // LFUSE
0x11, // HFUSE
0xFF // EFUSE
};
#endif
*/
#endif
/*
@@ -4193,7 +4164,7 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim
AUDIO_WARNING2();
}
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUARM) || defined(CPUM2560)
void saveTimers()
{
for (uint8_t i=0; i<MAX_TIMERS; i++) {
@@ -4291,7 +4262,7 @@ uint16_t stack_free()
}
#endif
#if defined(PCBGRUVIN9X)
#if defined(CPUM2560)
#define OPENTX_INIT_ARGS const uint8_t mcusr
#elif defined(PCBSTD)
#define OPENTX_INIT_ARGS const uint8_t mcusr
@@ -4353,7 +4324,7 @@ inline void opentxInit(OPENTX_INIT_ARGS)
opentxStart();
}
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUARM) || defined(CPUM2560)
if (!g_eeGeneral.unexpectedShutdown) {
g_eeGeneral.unexpectedShutdown = 1;
eeDirty(EE_GENERAL);
@@ -4442,7 +4413,7 @@ int main(void)
// important to disable it before commencing with system initialisation (or
// we could put a bunch more wdt_reset()s in. But I don't like that approach
// during boot up.)
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
uint8_t mcusr = MCUSR; // save the WDT (etc) flags
MCUSR = 0; // must be zeroed before disabling the WDT
#elif defined(PCBSTD)
@@ -4549,12 +4520,12 @@ int main(void)
CoStartOS();
#else
#if defined(PCBGRUVIN9X)
#if defined(CPUM2560)
uint8_t shutdown_state = 0;
#endif
while(1) {
#if defined(PCBGRUVIN9X)
#if defined(CPUM2560)
if ((shutdown_state=pwrCheck()) > e_power_trainer)
break;
#endif
@@ -4568,7 +4539,7 @@ int main(void)
}
#endif
#if defined(PCBGRUVIN9X)
#if defined(CPUM2560)
// Time to switch off
lcd_clear();
displayPopup(STR_SHUTDOWN);
+5 -3
View File
@@ -74,7 +74,7 @@
#define IF_BATTGRAPH(x)
#endif
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUARM) || defined(CPUM2560)
#define IF_PERSISTENT_TIMERS(x) x,
#else
#define IF_PERSISTENT_TIMERS(x)
@@ -247,6 +247,8 @@
#include "targets/sky9x/board_sky9x.h"
#elif defined(PCBGRUVIN9X)
#include "targets/gruvin9x/board_gruvin9x.h"
#elif defined(PCBMEGA2560)
#include "targets/mega2560/board_mega2560.h"
#else
#include "targets/stock/board_stock.h"
#endif
@@ -843,7 +845,7 @@ extern void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim);
void incRotaryEncoder(uint8_t idx, int8_t inc);
#endif
#if defined(PCBGRUVIN9X)
#if defined(PCBGRUVIN9X) || defined(PCBMEGA2560)
#define ROTARY_ENCODER_GRANULARITY (1)
#elif defined(CPUARM)
#define ROTARY_ENCODER_GRANULARITY (2 << g_eeGeneral.rotarySteps)
@@ -1074,7 +1076,7 @@ inline void resumeMixerCalculations()
#define resumeMixerCalculations()
#endif
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUARM) || defined(CPUM2560)
void saveTimers();
#else
#define saveTimers()
+8 -8
View File
@@ -750,7 +750,7 @@ void setupPulses()
TCCR1B = 0; // Stop counter
TCNT1 = 0;
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
TIMSK1 &= ~0x2F; // All Timer1 interrupts off
TIMSK1 &= ~(1<<OCIE1C); // COMPC1 off
TIFR1 = 0x2F;
@@ -771,7 +771,7 @@ void setupPulses()
OCR1C = 200; // 100 uS
TCNT1 = 300; // Past the OCR1C value
ICR1 = 44000; // Next frame starts in 22 mS
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
TIMSK1 |= 0x28; // Enable Timer1 COMPC and CAPT interrupts
TCCR1A = (0 << WGM10); // Set output waveform mode to normal, for now. Note that
// WGM will be changed to toggle OCR1B pin on compare capture,
@@ -790,7 +790,7 @@ void setupPulses()
set_timer3_capture();
OCR1B = 6000; // Next frame starts in 3 mS
OCR1C = 4000; // Next frame setup in 2 mS
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
TIMSK1 |= (1<<OCIE1B); // Enable COMPB
TIMSK1 |= (1<<OCIE1C); // Enable COMPC
TCCR1A = (3 << COM1B0); // Connect OC1B for hardware PPM switching
@@ -805,7 +805,7 @@ void setupPulses()
case PROTO_PPM16:
OCR1A = 40000; // Next frame starts in 20 mS
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
TIMSK1 |= (1<<OCIE1A); // Enable COMPA
TCCR1A = (3 << COM1B0); // Connect OC1B for hardware PPM switching
#else
@@ -820,7 +820,7 @@ void setupPulses()
break;
case PROTO_PPMSIM:
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
TCCR1A = 0; // Disconnect OC1B for bit-bang PPM switching
#endif
setupPulsesPPM(PROTO_PPMSIM);
@@ -846,7 +846,7 @@ void setupPulses()
// and
// PPM mode will dynamically adjust to the frame rate set in model SETUP menu,
// from within setupPulsesPPM().
#if defined(PCBGRUVIN9X) || defined(CPUM2561)
#if defined(CPUM2560) || defined(CPUM2561)
TIMSK1 |= (1<<OCIE1A); // Enable COMPA
TCCR1A = (3 << COM1B0); // Connect OC1B for hardware PPM switching. G: Not needed
// for DSM2=SERIAL. But OK.
@@ -1018,7 +1018,7 @@ ISR(TIMER1_COMPC_vect) // DSM2_PPM or PXX end of frame
void set_timer3_capture()
{
#ifndef SIMU
#if defined (PCBGRUVIN9X) || defined(CPUM2561) // TODO TIMSK3 in #define!
#if defined (CPUM2560) || defined(CPUM2561) // TODO TIMSK3 in #define!
TIMSK3 &= ~( (1<<OCIE3A) | (1<<OCIE3B) | (1<<OCIE3C) ) ; // Stop compare interrupts
#else
ETIMSK &= ~( (1<<OCIE3A) | (1<<OCIE3B) | (1<<OCIE3C) ) ; // Stop compare interrupts
@@ -1047,7 +1047,7 @@ void set_timer3_ppm()
TCCR3A = (0<<WGM10);
TCCR3B = (1 << WGM12) | (2<<CS10); // CTC OCR1A, 16MHz / 8
#if defined (PCBGRUVIN9X) || defined(CPUM2561)
#if defined (CPUM2560) || defined(CPUM2561)
TIMSK3 |= ( (1<<OCIE3A) | (1<<OCIE3B) ); // enable immediately before mainloop
#else
ETIMSK |= ( (1<<OCIE3A) | (1<<OCIE3B) ); // enable immediately before mainloop
+2 -2
View File
@@ -71,8 +71,8 @@ inline const pm_char *SDCARD_ERROR(FRESULT result)
#define O9X_FOURCC 0x3378396F // o9x for Taranis
#elif defined(PCBSKY9X)
#define O9X_FOURCC 0x3278396F // o9x for sky9x
#elif defined(PCBGRUVIN9X)
#define O9X_FOURCC 0x3178396F // o9x for gruvin9x
#else
#define O9X_FOURCC 0x3178396F // o9x for gruvin9x/MEGA2560
#endif
#endif
+274 -333
View File
@@ -1,333 +1,274 @@
#include "../opentx.h"
#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 )
{
uint32_t address ;
GPIO_TypeDef *pgpio ;
uint32_t thispin ;
uint32_t pos ;
address = ( config & PIN_PORT_MASK ) >> 8 ;
address *= (GPIOB_BASE-GPIOA_BASE) ;
address += GPIOA_BASE ;
pgpio = (GPIO_TypeDef* ) address ;
/* -------------------------Configure the port pins---------------- */
/*-- GPIO Mode Configuration --*/
for (thispin = 0x0001, pos = 0; thispin < 0x10000; thispin <<= 1, pos +=1 )
{
if ( pins & thispin)
{
pgpio->MODER &= ~(GPIO_MODER_MODER0 << (pos * 2)) ;
pgpio->MODER |= (config & PIN_MODE_MASK) << (pos * 2) ;
if ( ( (config & PIN_MODE_MASK ) == PIN_OUTPUT) || ( (config & PIN_MODE_MASK) == PIN_PERIPHERAL) )
{
/* Speed mode configuration */
pgpio->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR0 << (pos * 2) ;
pgpio->OSPEEDR |= ((config & PIN_SPEED_MASK) >> 13 ) << (pos * 2) ;
/* Output mode configuration*/
pgpio->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pos)) ;
if ( config & PIN_ODRAIN )
{
pgpio->OTYPER |= (GPIO_OTYPER_OT_0) << pos ;
}
}
/* Pull-up Pull down resistor configuration*/
pgpio->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pos * 2));
pgpio->PUPDR |= ((config & PIN_PULL_MASK) >> 2) << (pos * 2) ;
pgpio->AFR[pos >> 3] &= ~(0x000F << (pos & 7)) ;
pgpio->AFR[pos >> 3] |= ((config & PIN_PERI_MASK) >> 4) << (pos & 7) ;
}
}
}
#endif
#ifndef SIMU
inline void boardInit()
{
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering)
ADCSRB=(1<<MUX5);
/**** Set up timer/counter 0 ****/
/** Move old 64A Timer0 functions to Timer2 and use WGM on OC0(A) (PB7) for spkear tone output **/
// TCNT0 10ms = 16MHz/1024/156(.25) periodic timer (100ms interval)
// cycles at 9.984ms but includes 1:4 duty cycle correction to /157 to average at 10.0ms
TCCR2B = (0b111 << CS20); // Norm mode, clk/1024 (differs from ATmega64 chip)
OCR2A = 156;
TIMSK2 |= (1<<OCIE2A) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts
// Set up Phase correct Waveform Gen. mode, at clk/64 = 250,000 counts/second
// (Higher speed allows for finer control of frquencies in the audio range.)
// Used for audio tone generation
TCCR0B = (1<<WGM02) | (0b011 << CS00);
TCCR0A = (0b01<<WGM00);
/***************************************************/
/* Rotary encoder interrupt set-up */
// All external interrupts initialise to disabled.
EIMSK = 0; // disable ALL external interrupts.
// encoder 1
EICRB = (1<<ISC60) | (1<<ISC50); // 01 = interrupt on any edge
EIFR = (3<<INTF5); // clear the int. flag in case it got set when changing modes
// encoder 2
EICRA = (1<<ISC30) | (1<<ISC20); // do the same for encoder 1
EIFR = (3<<INTF2);
#if ROTARY_ENCODERS > 2
EIMSK = (3<<INT5); // enable the ONE rot. enc. ext. int. pairs.
#else
EIMSK = (3<<INT5) | (3<<INT2); // enable the two rot. enc. ext. int. pairs.
#endif
/***************************************************/
#if defined (VOICE)
/*
* SOMO set-up (V4 board only)
*/
OCR4A = 0x1F4; //2ms
TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
TIMSK4 |= (1<<OCIE4A); // Start the interrupt so the unit reset can occur
#endif
#if ROTARY_ENCODERS > 2
//configure uart1 here
DDRD &= ~(1 << 2);
PORTD &= ~(1 << 2);
#define EXTRA_ROTARY_ENCODERS_USART_BAUD 9600UL
UBRR1 = F_CPU/(16*EXTRA_ROTARY_ENCODERS_USART_BAUD)-1;
//9 bit mode
UCSR1C = (1<<USBS1)|(3<<UCSZ10);
UCSR1B = (1<<RXEN1)|(0<<TXEN1)|(1<<UCSZ12);
UCSR1B |= 1 << RXCIE1; //enable interrupt on rx
#endif
}
#if ROTARY_ENCODERS > 2
uint8_t vpotToChange = 0;
uint8_t vpot_mod_state = 0;
ISR(USART1_RX_vect)
{
//receive data from extension board
//bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value
/* Get status and 9th bit, then data */
/* from buffer */
uint16_t resh = UCSR1B;
uint16_t resl = UDR1;
uint16_t res = 0;
/* Filter the 9th bit, then return */
resh = (resh >> 1) & 0x01;
res = ((resh << 8) | resl);
if((res == 0x180) | (res == 0x1C0)){ //button REb filter
keys[BTN_REa].input((res & 0x1C0) == 0x1C0, BTN_REa);
} else if((res & 0x100) == 0x100){ //rotary filter
vpotToChange = res & 0xEF;
vpot_mod_state = 1;
}
else {
if(vpot_mod_state & (vpotToChange < NUM_ROTARY_ENCODERS))
{
int8_t vpot_inc = res & 0xFF;
if(vpot_inc){
incRotaryEncoder(vpotToChange, vpot_inc);
}
vpot_mod_state = 0;
}
}
}
#endif
#endif // !SIMU
uint8_t pwrCheck()
{
#if !defined(SIMU) && !defined(REV0)
if ((PING & 0b00000010) && (~PINL & 0b01000000))
return e_power_off;
#endif
return e_power_on;
}
void pwrOff()
{
#ifndef REV0
PORTL = 0x7f;
#endif
}
#if ROTARY_ENCODERS <= 2
#define ROTENC_DOWN() ((~PIND & 0x20) || (~PIND & 0x10))
#else
#define ROTENC_DOWN() (0)
#endif
FORCEINLINE uint8_t keyDown()
{
return ((~PINL) & 0x3F) || ROTENC_DOWN();
}
bool switchState(EnumKeys enuk)
{
uint8_t result = 0 ;
if (enuk < (int)DIM(keys))
return keys[enuk].state() ? 1 : 0;
switch(enuk){
case SW_ELE:
result = PINC & (1<<INP_C_ElevDR);
break;
case SW_AIL:
result = PINC & (1<<INP_C_AileDR);
break;
case SW_RUD:
result = PING & (1<<INP_G_RuddDR);
break;
// INP_G_ID1 INP_B_ID2
// id0 0 1
// id1 1 1
// id2 1 0
case SW_ID0:
result = !(PING & (1<<INP_G_ID1));
break;
case SW_ID1:
result = (PING & (1<<INP_G_ID1))&& (PINB & (1<<INP_B_ID2));
break;
case SW_ID2:
result = !(PINB & (1<<INP_B_ID2));
break;
#if 0
case SW_ID3:
result = (calibratedStick[POT1+EXTRA_3POS-1] < 0);
break;
case SW_ID4:
result = (calibratedStick[POT1+EXTRA_3POS-1] == 0);
break;
case SW_ID5:
result = (calibratedStick[POT1+EXTRA_3POS-1] > 0);
break;
#endif
case SW_GEA:
result = PING & (1<<INP_G_Gear);
break;
case SW_THR:
result = PING & (1<<INP_G_ThrCt);
break;
case SW_TRN:
result = PINB & (1<<INP_B_Trainer);
break;
default:
break;
}
return result;
}
FORCEINLINE void readKeysAndTrims()
{
uint8_t enuk = KEY_MENU;
#if ROTARY_ENCODERS <= 2
keys[BTN_REa].input(~PIND & 0x20, BTN_REa);
#endif
keys[BTN_REb].input(~PIND & 0x10, BTN_REb);
uint8_t tin = ~PINL;
uint8_t in;
in = (tin & 0x0f) << 3;
in |= (tin & 0x30) >> 3;
for (int i=1; i<7; i++)
{
//INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6
keys[enuk].input(in & (1<<i),(EnumKeys)enuk);
++enuk;
}
// Trim switches ...
static const pm_uchar crossTrim[] PROGMEM ={
1<<INP_J_TRM_LH_DWN,
1<<INP_J_TRM_LH_UP,
1<<INP_J_TRM_LV_DWN,
1<<INP_J_TRM_LV_UP,
1<<INP_J_TRM_RV_DWN,
1<<INP_J_TRM_RV_UP,
1<<INP_J_TRM_RH_DWN,
1<<INP_J_TRM_RH_UP
};
in = ~PINJ;
for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk);
++enuk;
}
}
#if ROTARY_ENCODERS <= 2
ISR(INT2_vect)
{
uint8_t input = (PIND & 0x0C);
if (input == 0 || input == 0x0C) incRotaryEncoder(0, -1);
}
ISR(INT3_vect)
{
uint8_t input = (PIND & 0x0C);
if (input == 0 || input == 0x0C) incRotaryEncoder(0, +1);
}
#endif
ISR(INT5_vect)
{
uint8_t input = (PINE & 0x60);
if (input == 0 || input == 0x60) incRotaryEncoder(1, +1);
}
ISR(INT6_vect)
{
uint8_t input = (PINE & 0x60);
if (input == 0 || input == 0x60) incRotaryEncoder(1, -1);
}
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - 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 "../../opentx.h"
#ifndef SIMU
inline void boardInit() // Done 2013.10.09 : trims, keyboard, LCD, ID1+2 SW warning PORTF-3 (1.2V ADC_ref)
{
// Set up I/O port data directions and initial states
DDRA = 0b11111111; PORTA = 0b00000000; // LCD data
DDRB = 0b11000111; PORTB = 0b00111111; // 7:SPKR, 6:PPM_OUT, 5:TrainSW, 4:xxxxx, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS]
DDRC = 0b11111100; PORTC = 0b00000011; // LCD[7,6,5,4,3], 2:BackLight, 1:ID2_Sw, 0:ID1_Sw
DDRD = 0b11000000; PORTD = 0b11111100; // 7:VIB, 6:LED BL, 5:RENC2_PUSH, 4:RENC1_PUSH, 3:RENC2_B, 2:RENC2_A, 1:I2C_SDA, 0:I2C_SCL
DDRE = 0b00001010; PORTE = 0b11110100; // 7:PPM_IN, 6: RENC1_B, 5:RENC1_A, 4:USB_DNEG, 3:BUZZER, 2:USB_DPOS, 1:TELEM_TX, 0:TELEM_RX(pull-up off)
//DDRF = 0b00000000; PORTF = 0b00000000; // 7-4:JTAG, 3:ADC_REF_1.2V input, 2-0:ADC_SPARE_2-0
DDRF = 0b00000000; PORTF = 0b11111111; // 7-0:Trim switch inputs
DDRG = 0b00010000; PORTG = 0b00111111; // 7-6:N/A, 5:GearSW, 4: Sim_Ctrl[out], 3:xxxxx, 2:TCut_Sw, 1:RF_Power[in], 0: RudDr_Sw
DDRH = 0b10111000; PORTH = 0b11010111; // [7:0 DSM/PPM TX-caddy control. 1=PPM, 0=DSM ]
// [6:SOMO14D-BUSY 5:SOMO14D-DATA 4:SOMO14D-CLK 3:SOMO14D-RESET]
// [2:VIB_OPTION -- setting to input for now]
// [1:TxD 0:RxD Spare serial port]
//DDRJ = 0b00000000; PORTJ = 0b11111111; // 7-0:Trim switch inputs
DDRK = 0b00000000; PORTK = 0b00000000; // Analogic input (no pull-ups)
DDRL = 0b10000000; PORTL = 0b11111111; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: Keyboard inputs
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering)
ADCSRB=(1<<MUX5);
/**** Set up timer/counter 0 ****/
/** Move old 64A Timer0 functions to Timer2 and use WGM on OC0(A) (PB7) for spkear tone output **/
// TCNT0 10ms = 16MHz/1024/156(.25) periodic timer (100ms interval)
// cycles at 9.984ms but includes 1:4 duty cycle correction to /157 to average at 10.0ms
TCCR2B = (0b111 << CS20); // Norm mode, clk/1024 (differs from ATmega64 chip)
OCR2A = 156;
TIMSK2 |= (1<<OCIE2A) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts
// Set up Phase correct Waveform Gen. mode, at clk/64 = 250,000 counts/second
// (Higher speed allows for finer control of frquencies in the audio range.)
// Used for audio tone generation
TCCR0B = (1<<WGM02) | (0b011 << CS00);
TCCR0A = (0b01<<WGM00);
/***************************************************/
/* Rotary encoder interrupt set-up */
EIMSK = 0; // disable ALL external interrupts.
// encoder 1
EICRB = (1<<ISC60) | (1<<ISC50); // 01 = interrupt on any edge
EIFR = (3<<INTF5); // clear the int. flag in case it got set when changing modes
// encoder 2
EICRA = (1<<ISC30) | (1<<ISC20); // do the same for encoder 1
EIFR = (3<<INTF2);
EIMSK = (3<<INT5) | (3<<INT2); // enable the two rot. enc. ext. int. pairs.
/***************************************************/
#if defined (VOICE)
/*
* SOMO set-up (V4 board only)
*/
OCR4A = 0x1F4; //2ms
TCCR4B = (1 << WGM42) | (0b011 << CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
TIMSK4 |= (1<<OCIE4A); // Start the interrupt so the unit reset can occur
#endif
}
#endif // !SIMU
uint8_t pwrCheck()
{
#if !defined(SIMU) && !defined(REV0)
if ((PING & 0b00000010) && (~PINL & 0b01000000))
return e_power_off;
#endif
return e_power_on;
}
void pwrOff()
{
#ifndef REV0
PORTL = 0x7f;
#endif
}
#if ROTARY_ENCODERS <= 2
#define ROTENC_DOWN() ((~PIND & 0x20) || (~PIND & 0x10))
#else
#define ROTENC_DOWN() (0)
#endif
FORCEINLINE uint8_t keyDown()
{
return ((~PINL) & 0x3F) || ROTENC_DOWN();
}
bool switchState(EnumKeys enuk)
{
uint8_t result = 0 ;
if (enuk < (int)DIM(keys))
return keys[enuk].state() ? 1 : 0;
switch(enuk){
//case SW_ELE:
// result = PINC & (1<<INP_C_ElevDR);
// break;
//case SW_AIL:
// result = PINC & (1<<INP_C_AileDR);
// break;
case SW_RUD:
result = PING & (1<<INP_G_RuddDR);
break;
// INP_G_ID1 INP_B_ID2
// id0 0 1
// id1 1 1
// id2 1 0
case SW_ID0:
result = !(PINC & (1<<INP_C_ID1));
break;
case SW_ID1:
result = (PINC & (1<<INP_C_ID1))&& (PINC & (1<<INP_C_ID2));
break;
case SW_ID2:
result = !(PINC & (1<<INP_C_ID2));
break;
#if 0
case SW_ID3:
result = (calibratedStick[POT1+EXTRA_3POS-1] < 0);
break;
case SW_ID4:
result = (calibratedStick[POT1+EXTRA_3POS-1] == 0);
break;
case SW_ID5:
result = (calibratedStick[POT1+EXTRA_3POS-1] > 0);
break;
#endif
case SW_GEA:
result = PING & (1<<INP_G_Gear);
break;
case SW_THR:
result = PING & (1<<INP_G_ThrCt);
break;
case SW_TRN:
result = PINB & (1<<INP_B_Trainer);
break;
default:
break;
}
return result;
}
FORCEINLINE void readKeysAndTrims()
{
/* Original keys were connected to PORTB as follows:
Bit Key
7 other use
6 LEFT
5 RIGHT
4 UP
3 DOWN
2 EXIT
1 MENU
0 other use
*/
uint8_t enuk = KEY_MENU;
keys[BTN_REa].input(~PIND & 0x20, BTN_REa);
keys[BTN_REb].input(~PIND & 0x10, BTN_REb);
uint8_t tin = ~PINL;
uint8_t in;
in = (tin & 0x0f) << 3;
in |= (tin & 0x30) >> 3;
for (int i=1; i<7; i++)
{
//INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6
keys[enuk].input(in & (1<<i),(EnumKeys)enuk);
++enuk;
}
// Trim switches ...
static const pm_uchar crossTrim[] PROGMEM ={
1<<INP_F_TRM_LH_DWN,
1<<INP_F_TRM_LH_UP,
1<<INP_F_TRM_LV_DWN,
1<<INP_F_TRM_LV_UP,
1<<INP_F_TRM_RV_DWN,
1<<INP_F_TRM_RV_UP,
1<<INP_F_TRM_RH_DWN,
1<<INP_F_TRM_RH_UP
};
in = ~PINF;
for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk);
++enuk;
}
}
ISR(INT2_vect)
{
uint8_t input = (PIND & 0x0C);
if (input == 0 || input == 0x0C) incRotaryEncoder(0, -1);
}
ISR(INT3_vect)
{
uint8_t input = (PIND & 0x0C);
if (input == 0 || input == 0x0C) incRotaryEncoder(0, +1);
}
ISR(INT5_vect)
{
uint8_t input = (PINE & 0x60);
if (input == 0 || input == 0x60) incRotaryEncoder(1, +1);
}
ISR(INT6_vect)
{
uint8_t input = (PINE & 0x60);
if (input == 0 || input == 0x60) incRotaryEncoder(1, -1);
}
+158 -17
View File
@@ -1,31 +1,159 @@
#ifndef board_gruvin9x_h
#define board_gruvin9x_h
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - 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 "io_mega2560.h"
#ifndef board_mega2560_h
#define board_mega2560_h
#define TIMER_16KHZ_VECT TIMER2_OVF_vect
#define COUNTER_16KHZ TCNT2
#define TIMER_10MS_VECT TIMER2_COMPA_vect
#define TIMER_10MS_COMPVAL OCR2A
#define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<<OCIE2A)
#define RESUME_10MS_INTERRUPT() TIMSK2 |= (1<<OCIE2A)
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
#define GPIO_BUTTON_MENU pinl
#define GPIO_BUTTON_EXIT pinl
#define GPIO_BUTTON_RIGHT pinl
#define GPIO_BUTTON_LEFT pinl
#define GPIO_BUTTON_UP pinl
#define GPIO_BUTTON_DOWN pinl
#define PIN_BUTTON_MENU (1<<INP_L_KEY_MEN)
#define PIN_BUTTON_EXIT (1<<INP_L_KEY_EXT)
#define PIN_BUTTON_UP (1<<INP_L_KEY_UP)
#define PIN_BUTTON_DOWN (1<<INP_L_KEY_DWN)
#define PIN_BUTTON_RIGHT (1<<INP_L_KEY_RGT)
#define PIN_BUTTON_LEFT (1<<INP_L_KEY_LFT)
#define GPIO_TRIM_LH_L pinf
#define GPIO_TRIM_LV_DN pinf
#define GPIO_TRIM_RV_UP pinf
#define GPIO_TRIM_RH_L pinf
#define GPIO_TRIM_LH_R pinf
#define GPIO_TRIM_LV_UP pinf
#define GPIO_TRIM_RV_DN pinf
#define GPIO_TRIM_RH_R pinf
#define PIN_TRIM_LH_L (1<<INP_F_TRM_LH_DWN)
#define PIN_TRIM_LV_DN (1<<INP_F_TRM_LV_DWN)
#define PIN_TRIM_RV_UP (1<<INP_F_TRM_RV_UP)
#define PIN_TRIM_RH_L (1<<INP_F_TRM_RH_DWN)
#define PIN_TRIM_LH_R (1<<INP_F_TRM_LH_UP)
#define PIN_TRIM_LV_UP (1<<INP_F_TRM_LV_UP)
#define PIN_TRIM_RV_DN (1<<INP_F_TRM_RV_DWN)
#define PIN_TRIM_RH_R (1<<INP_F_TRM_RH_UP)
#define TIMER_16KHZ_VECT TIMER2_OVF_vect
#define COUNTER_16KHZ TCNT2
#define TIMER_10MS_VECT TIMER2_COMPA_vect
#define TIMER_10MS_COMPVAL OCR2A
#define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<<OCIE2A)
#define RESUME_10MS_INTERRUPT() TIMSK2 |= (1<<OCIE2A)
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
#define SLAVE_MODE() (PING & (1<<INP_G_RF_POW))
#define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT)
#define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT)
#define IS_BACKLIGHT_ON() (PORTC & (1<<OUT_C_LIGHT))
#define SLAVE_MODE() (PING & (1<<INP_G_RF_POW))
#define JACK_PPM_OUT() PORTG |= (1<<OUT_G_SIM_CTL)
#define JACK_PPM_IN() PORTG &= ~(1<<OUT_G_SIM_CTL)
// SD driver
#if !defined(SIMU)
bool sdMounted();
void sdMountPoll();
void sdPoll10ms();
#define sdDone()
#define SD_IS_HC() (0)
#define SD_GET_BLOCKNR() (0)
#define SD_GET_SIZE_MB() (0)
#define SD_GET_SPEED() (0)
#endif
#define SPEAKER_ON TCCR0A |= (1 << COM0A0)
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
#define SPEAKER_ON TCCR0A |= (1 << COM0A0)
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
#define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT)
#define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT)
#define IS_BACKLIGHT_ON() (PORTC & (1<<OUT_C_LIGHT))
# define INP_L_SPARE6 7
# define INP_L_SPARE5 6
# define INP_L_KEY_EXT 5
# define INP_L_KEY_MEN 4
# define INP_L_KEY_LFT 3
# define INP_L_KEY_RGT 2
# define INP_L_KEY_UP 1
# define INP_L_KEY_DWN 0
# define INP_F_TRM_RH_UP 7
# define INP_F_TRM_RH_DWN 6
# define INP_F_TRM_RV_UP 5
# define INP_F_TRM_RV_DWN 4
# define INP_F_TRM_LV_UP 3
# define INP_F_TRM_LV_DWN 2
# define INP_F_TRM_LH_UP 1
# define INP_F_TRM_LH_DWN 0
# define INP_E_PPM_IN 7
# define INP_E_ROT_ENC_1_B 6
# define INP_E_ROT_ENC_1_A 5
# define INP_E_USB_D_PLS 4
# define OUT_E_BUZZER 3
# define INP_E_USB_D_NEG 2
# define INP_E_TELEM_RX 1
# define OUT_E_TELEM_TX 0
# define OUT_D_HAPTIC 7
# define INP_D_SPARE4 6
# define INP_D_ROT_ENC_2_PUSH 5
# define INP_D_ROT_ENC_1_PUSH 4
# define OUT_D_ROT_ENC_2_B 3
# define INP_D_ROT_ENC_2_A 2
# define INP_D_I2C_SCL 1
# define INP_D_I2C_SDA 0
# define INP_G_Gear 5
# define INP_G_ThrCt 2
# define OUT_G_SIM_CTL 4 //1 : phone-jack=ppm_in
# define INP_C_ID1 0
# define INP_G_RF_POW 1
# define INP_G_RuddDR 0
# define INP_C_AileDR 7
# define INP_C_ElevDR 6
# define OUT_C_LIGHT 2
# define OUT_B_Speaker 7
# define OUT_B_PPM 6
# define INP_B_Trainer 5
# define INP_C_ID2 1
#if defined(VOICE)
# define OUT_H_14DRESET 3
@@ -35,17 +163,30 @@ void sdPoll10ms();
#endif
// Keys driver
#define KEYS_PRESSED() (~PINL) // used only for DBLKEYS code.
#define KEYS_PRESSED() (~PINL) // used only for DBLKEYS code
#define DBLKEYS_PRESSED_RGT_LFT(i) ((in & ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_LFT))) == ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_LFT)))
#define DBLKEYS_PRESSED_UP_DWN(i) ((in & ((1<<INP_L_KEY_UP) + (1<<INP_L_KEY_DWN))) == ((1<<INP_L_KEY_UP) + (1<<INP_L_KEY_DWN)))
#define DBLKEYS_PRESSED_RGT_UP(i) ((in & ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_UP))) == ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_UP)))
#define DBLKEYS_PRESSED_LFT_DWN(i) ((in & ((1<<INP_L_KEY_LFT) + (1<<INP_L_KEY_DWN))) == ((1<<INP_L_KEY_LFT) + (1<<INP_L_KEY_DWN)))
// LCD driver
#define PORTA_LCD_DAT PORTA
#define PORTC_LCD_CTRL PORTC
#define OUT_C_LCD_E 7
#define OUT_C_LCD_RnW 6
#define OUT_C_LCD_A0 5
#define OUT_C_LCD_RES 4
#define OUT_C_LCD_CS1 3
// Power driver
uint8_t pwrCheck();
void pwrOff();
#define UNEXPECTED_SHUTDOWN() ((mcusr & (1 << WDRF)) || g_eeGeneral.unexpectedShutdown)
// USB fake driver
#define usbPlugged() false
// Haptic driver
#define hapticOff() // TODO hapticOn() cleaner ...
#endif
+95
View File
@@ -0,0 +1,95 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - 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.
*
*/
/*--------------------------------------------------------------------------*/
/* RTC controls */
#include "../opentx.h"
#include "../FatFs/integer.h"
typedef struct {
WORD year; /* 2000..2099 */
BYTE month; /* 1..12 */
BYTE mday; /* 1.. 31 */
BYTE wday; /* 1..7 */
BYTE hour; /* 0..23 */
BYTE min; /* 0..59 */
BYTE sec; /* 0..59 */
} RTC;
void rtc_gettime(struct gtm * utm)
{
RTC rtc = {0,0,0,0,0,0,0};
// TODO g9x_rtc_gettime(&rtc);
utm->tm_year = rtc.year - 1900;
utm->tm_mon = rtc.month - 1;
utm->tm_mday = rtc.mday;
utm->tm_hour = rtc.hour;
utm->tm_min = rtc.min;
utm->tm_sec = rtc.sec;
utm->tm_wday = rtc.wday - 1;
}
void rtcSetTime(struct gtm * t)
{
g_rtcTime = gmktime(t); // update local timestamp and get wday calculated
g_ms100 = 0; // start of next second begins now
#if 0
RTC rtc;
rtc.year = t->tm_year + 1900;
rtc.month = t->tm_mon + 1;
rtc.mday = t->tm_mday;
rtc.hour = t->tm_hour;
rtc.min = t->tm_min;
rtc.sec = t->tm_sec;
rtc.wday = t->tm_wday + 1;
g9x_rtcSetTime(&rtc);
#endif
}
void rtcInit (void)
{
// TODO
struct gtm utm;
rtc_gettime(&utm);
g_rtcTime = gmktime(&utm);
}
+3 -3
View File
@@ -94,7 +94,7 @@ const pm_char STR_OPEN9X[] PROGMEM =
ISTR(VSWITCHES)
ISTR(VSRCRAW)
ISTR(VTMRMODES)
#if defined(PCBGRUVIN9X) || defined(CPUARM)
#if defined(CPUM2560) || defined(CPUARM)
ISTR(DATETIME)
#endif
#if defined(CPUARM)
@@ -269,7 +269,7 @@ const pm_char STR_EEPROMOVERFLOW[] PROGMEM = TR_EEPROMOVERFLOW;
const pm_char STR_TRIMS2OFFSETS[] PROGMEM = TR_TRIMS2OFFSETS;
const pm_char STR_MENURADIOSETUP[] PROGMEM = TR_MENURADIOSETUP;
#if defined(PCBGRUVIN9X) || defined(CPUARM)
#if defined(CPUM2560) || defined(CPUARM)
const pm_char STR_MENUDATEANDTIME[] PROGMEM = TR_MENUDATEANDTIME;
#endif
@@ -332,7 +332,7 @@ const pm_char STR_LATITUDE[] PROGMEM = TR_LATITUDE;
const pm_char STR_LONGITUDE[] PROGMEM = TR_LONGITUDE;
#endif
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUM2560) || defined(PCBGRUVIN9X)
const pm_char STR_SHUTDOWN[] PROGMEM = TR_SHUTDOWN;
#endif
+3 -3
View File
@@ -143,7 +143,7 @@ extern const pm_char STR_OPEN9X[];
#define OFS_VSRCRAW (OFS_VSWITCHES + sizeof(TR_VSWITCHES))
#define OFS_VTMRMODES (OFS_VSRCRAW + sizeof(TR_VSRCRAW))
#define OFS_DATETIME (OFS_VTMRMODES + sizeof(TR_VTMRMODES))
#if defined(PCBGRUVIN9X) || defined(CPUARM)
#if defined(CPUM2560) || defined(CPUARM)
#define OFS_VLCD (OFS_DATETIME + sizeof(TR_DATETIME))
#else
#define OFS_VLCD (OFS_DATETIME)
@@ -244,7 +244,7 @@ extern const pm_char STR_OPEN9X[];
#define STR_VRENCODERS (STR_OPEN9X + OFS_VRENCODERS)
#endif
#if defined(PCBGRUVIN9X) || defined(CPUARM)
#if defined(CPUM2560) || defined(CPUARM)
#define STR_DATETIME (STR_OPEN9X + OFS_DATETIME)
#endif
@@ -469,7 +469,7 @@ extern const pm_char STR_LATITUDE[];
extern const pm_char STR_LONGITUDE[];
#endif
#if defined(CPUARM) || defined(PCBGRUVIN9X)
#if defined(CPUARM) || defined(CPUM2560)
extern const pm_char STR_SHUTDOWN[];
#endif