MEGA2560 update

This commit is contained in:
JivaroFAD
2014-12-07 11:26:35 +01:00
parent 1b4834b547
commit 5ce8b9bc47
2 changed files with 34 additions and 34 deletions
+18 -19
View File
@@ -1,5 +1,6 @@
/*
* Authors (alphabetical order)
* - Aguerre Franck
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
@@ -41,18 +42,18 @@ inline void boardInit()
{
// Set up I/O port data directions and initial states (unused pin setting : input, pull-up on)
DDRA = 0b11111111; PORTA = 0b00000000; // LCD data
DDRB = 0b01000111; PORTB = 0b00101111; // 7:PPM_IN 6:PPM_OUT, 5:SimCTRL, 4:Buzzer, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS]
DDRB = 0b01110111; PORTB = 0b00001111; // 7:PPM_IN 6:PPM_OUT, 5:SimCTRL, 4:Buzzer, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS]
DDRC = 0b11111100; PORTC = 0b00000011; // 7-3:LCD, 2:BackLight, 1:ID2_SW, 0:ID1_SW
DDRD = 0b00000000; PORTD = 0b11110000; // 7:AilDR_SW, 6:N/A, 5:N/A, 4:N/A, 3:RENC2_B, 2:RENC2_A, 1:N/A, 0:N/A
DDRE = 0b00001010; PORTE = 0b11110100; // 7:N/A, 6:N/A, 5:RENC1_B, 4:RENC1_A, 3:Buzzer(old), 2:N/A, 1:TELEM_TX, 0:TELEM_RX(pull-up off)
DDRD = 0b00000000; PORTD = 0b11111111; // 7:AilDR_SW, 6:N/A, 5:N/A, 4:N/A, 3:RENC2_B, 2:RENC2_A, 1:N/A, 0:N/A
DDRE = 0b00000010; PORTE = 0b11111100; // 7:N/A, 6:N/A, 5:RENC1_B, 4:RENC1_A, 3:N/A, 2:N/A, 1:TELEM_TX, 0:TELEM_RX
DDRF = 0b00000000; PORTF = 0b11111111; // 7-0:Trim switch inputs
DDRG = 0b00000000; PORTG = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:TCut_SW, 1:Gear_SW, 0: RudDr_SW
DDRH = 0b00011000; PORTH = 0b11010111; // 7:N/A, 6:RFPw, 5:JackPres, 4:HoldPw, 3:Speaker, 2:N/A, 1:N/A, 0:N/A
DDRH = 0b00011000; PORTH = 0b10010111; // 7:N/A, 6:RFPw, 5:JackPres, 4:HoldPw, 3:Speaker, 2:N/A, 1:N/A, 0:N/A
DDRJ = 0b00000000; PORTJ = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:N/A, 1:RENC2_push, 0:RENC1_push
DDRK = 0b00000000; PORTK = 0b00000000; // Analogic input (no pull-ups)
DDRL = 0b00000000; PORTL = 0b11111111; // 7:TRN_SW 6:EleDR_SW, 5:ESC, 4:MENU 3:Keyb_Left, 2:Keyb_Right, 1:Keyb_Up, 0:Keyb_Down
ADMUX=ADC_VREF_TYPE; // need to be set to internal reference
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering)
ADCSRB=(1<<MUX5);
@@ -83,18 +84,16 @@ inline void boardInit()
uint8_t pwrCheck()
{
#if !defined(SIMU) //&& !defined(REV0)
//if ((PING & 0b00000010) && (~PINL & 0b01000000)) //temporary disabled
//return e_power_off;
#endif
return e_power_on;
}
/*#if !defined(SIMU) //&& !defined(REV0)
if ((PINH & 0b01000000) && (~PINH & 0b00100000))
return e_power_off;
#endif */
return e_power_on;
}
void pwrOff()
{
#ifndef REV0
PORTL = 0b11111111; //to check !
#endif
//PORTH = 0b11101111; //Hold_PWR pin (PortH4) set to 0
}
FORCEINLINE uint8_t keyDown()
@@ -193,8 +192,8 @@ FORCEINLINE void readKeysAndTrims()
{
uint8_t enuk = KEY_MENU;
keys[BTN_REa].input(~PINJ & 0b00000001);
keys[BTN_REb].input(~PINJ & 0b00000010);
keys[BTN_REa].input(~PINJ & 0b00000001, BTN_REa);
keys[BTN_REb].input(~PINJ & 0b00000010, BTN_REb);
uint8_t tin = ~PINL;
uint8_t in;
@@ -203,7 +202,7 @@ FORCEINLINE void readKeysAndTrims()
for (int i=1; i<7; i++) {
//INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6
keys[enuk].input(in & (1<<i));
keys[enuk].input(in & (1<<i),(EnumKeys)enuk);
++enuk;
}
@@ -211,7 +210,7 @@ FORCEINLINE void readKeysAndTrims()
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));
keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk);
++enuk;
}
}
+16 -15
View File
@@ -1,5 +1,6 @@
/*
* Authors (alphabetical order)
* - Aguerre Franck
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
@@ -78,11 +79,11 @@
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
#define SLAVE_MODE() (PINH & (1<<INP_H_RF_POW))
#define JACK_PPM_OUT() PORTB |= (1<<OUT_B_SIM_CTL)
#define JACK_PPM_IN() PORTB &= ~(1<<OUT_B_SIM_CTL)
#define SPEAKER_ON TCCR0A |= (1 << COM0A0)
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
#define SLAVE_MODE() (PINH & (1<<INP_H_RF_POW)) //not tested
#define JACK_PPM_OUT() PORTB |= (1<<OUT_B_SIM_CTL) //not tested
#define JACK_PPM_IN() PORTB &= ~(1<<OUT_B_SIM_CTL) //not tested
#define SPEAKER_ON TCCR0A |= (1 << COM0A0) //not tested
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0) //not tested
#define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT) //ok
#define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT) //ok
@@ -130,14 +131,14 @@
# define INP_L_Trainer 7 //ok
// Servitudes driver
# define INP_B_PPM_IN 7 //to verify
# define INP_B_PPM_IN 7 //not tested
# define OUT_B_PPM 6 //to verify
# define OUT_B_SIM_CTL 5 //to verify
# define OUT_B_SIM_CTL 5 //not tested
# define OUT_B_BUZZER 4 //to verify
# define INP_H_RF_POW 6 //to verify
# define INP_H_SPARE5 5 //hold power OUT_H_xx 4 ?????
# define INP_H_SPARE6 4 //jack presence INP_H_xx 5 ?????
# define OUT_H_Speaker 3 //to verify
# define INP_H_RF_POW 6 //not tested
//#define INP_H_ 5 //reserved JACKPRES
//#define INP_H_ 4 //reserved HOLDPWR
# define OUT_H_Speaker 3 //not tested
# define INP_E_TELEM_RX 1 //same as Gruvin9x
# define OUT_E_TELEM_TX 0 //same as Gruvin9x
@@ -148,13 +149,13 @@
# define INP_D_ROT_ENC_2_B 3 //ok
# define INP_J_ROT_ENC_1_PUSH 0 //ok
# define INP_J_ROT_ENC_2_PUSH 1 //ok
# define REA_DOWN() (~PINJ & (1<<INP_J_ROT_ENC_1_PUSH))
# define REB_DOWN() (~PINJ & (1<<INP_J_ROT_ENC_2_PUSH))
# define ROTENC_DOWN() (REA_DOWN() || REB_DOWN())
# define REA_DOWN() (~PINJ & (1<<INP_J_ROT_ENC_1_PUSH)) //ok
# define REB_DOWN() (~PINJ & (1<<INP_J_ROT_ENC_2_PUSH)) //ok
# define ROTENC_DOWN() (REA_DOWN() || REB_DOWN()) //ok
// Old #define from Gruvin9x
# define OUT_E_BUZZER 3 //PB : temporary used, crash otherwise at compilation!!!!!!
/*
# define OUT_E_BUZZER 3 //to erase
# define INP_E_USB_D_PLS 4 //to erase
# define INP_E_USB_D_NEG 2 //to erase
# define OUT_D_HAPTIC 7 //to erase