/branches/extra_encoders_rework merged

This commit is contained in:
maxim.karban@gmail.com
2012-05-21 19:08:21 +00:00
parent 8a62c195d2
commit 0682da0ff1
12 changed files with 105 additions and 60 deletions
+22 -16
View File
@@ -101,7 +101,11 @@ inline void board_init()
EICRA = (1<<ISC30) | (1<<ISC20); // do the same for encoder 1
EIFR = (3<<INTF2);
#if defined(EXTRA_ROTARY_ENCODERS)
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
/***************************************************/
/*
@@ -111,15 +115,15 @@ inline void board_init()
TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
#ifdef EXTRA_ROTARY_ENCODERS
//configure uart2 here
DDRH &= ~(1 << 0);
PORTH &= ~(1 << 0);
//configure uart1 here
DDRD &= ~(1 << 2);
PORTD &= ~(1 << 2);
#define EXTRA_ROTARY_ENCODERS_USART_BAUD 9600UL
UBRR2 = F_CPU/(16*EXTRA_ROTARY_ENCODERS_USART_BAUD)-1;
UBRR1 = F_CPU/(16*EXTRA_ROTARY_ENCODERS_USART_BAUD)-1;
//9 bit mode
UCSR2C = (1<<USBS2)|(3<<UCSZ20);
UCSR2B = (1<<RXEN2)|(0<<TXEN2)|(1<<UCSZ22);
UCSR2B |= 1 << RXCIE2; //enable interrupt on rx
UCSR1C = (1<<USBS1)|(3<<UCSZ10);
UCSR1B = (1<<RXEN1)|(0<<TXEN1)|(1<<UCSZ12);
UCSR1B |= 1 << RXCIE1; //enable interrupt on rx
#endif //EXTRA_ROTARY_ENCODERS
}
@@ -128,17 +132,15 @@ inline void board_init()
uint8_t vpotToChange = 0;
uint8_t vpot_mod_state = 0;
ISR(USART2_RX_vect)
ISR(USART1_RX_vect)
{
//receive data from extension board
//bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value
//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 */
//uint8_t status = UCSR2A;
uint16_t resh = UCSR2B;
uint16_t resl = UDR2;
uint16_t resh = UCSR1B;
uint16_t resl = UDR1;
uint16_t res = 0;
//if ( status & (1<<FEn)|(1<<DORn)|(1<<UPEn) )
/* Filter the 9th bit, then return */
resh = (resh >> 1) & 0x01;
@@ -148,11 +150,11 @@ ISR(USART2_RX_vect)
vpot_mod_state = 1;
}
else {
if(vpot_mod_state & (vpotToChange>0) & (vpotToChange<=NUM_EXTRA_ROTARY_ENCODERS))
if(vpot_mod_state & (vpotToChange>0) & (vpotToChange<=NUM_UART_ROTARY_ENCODERS))
{
int8_t vpot_inc = res & 0xff;
if(vpot_inc){
incRotaryEncoder(NUM_ROTARY_ENCODERS-NUM_EXTRA_ROTARY_ENCODERS+vpotToChange-1, vpot_inc);
incRotaryEncoder((NUM_ROTARY_ENCODERS - NUM_UART_ROTARY_ENCODERS) + (vpotToChange - 1), vpot_inc);
}
vpot_mod_state = 0;
}
@@ -260,8 +262,12 @@ void readKeysAndTrims()
uint8_t enuk = KEY_MENU;
#if !defined(EXTRA_ROTARY_ENCODERS)
keys[BTN_REa].input(~PIND & 0x20, BTN_REa);
keys[BTN_REb].input(~PIND & 0x10, BTN_REb);
#else //EXTRA_ROTARY_ENCODERS
keys[BTN_REa].input(~PIND & 0x10, BTN_REa);
#endif //EXTRA_ROTARY_ENCODERS
uint8_t tin = ~PINL;
uint8_t in;
+5 -1
View File
@@ -581,7 +581,11 @@ void putsTrimMode(uint8_t x, uint8_t y, uint8_t phase, uint8_t idx, uint8_t att)
#if defined(PCBV4)
void putsRotaryEncoderMode(uint8_t x, uint8_t y, uint8_t phase, uint8_t idx, uint8_t att)
{
int16_t v = phaseaddress(phase)->rotaryEncoders[idx];
int16_t v;
if(idx < (NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS))
v = phaseaddress(phase)->rotaryEncoders[idx];
else
v = g_model.rotaryEncodersExtra[phase][idx - (NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS)];
if (v > ROTARY_ENCODER_MAX) {
uint8_t p = v - ROTARY_ENCODER_MAX - 1;
+2 -2
View File
@@ -313,8 +313,8 @@ void menuMainView(uint8_t event)
int16_t val = getRotaryEncoder(i);
int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT); // TODO uint16_t?
#if defined(EXTRA_ROTARY_ENCODERS)
#define V_BAR_W 4
V_BAR(SCREEN_WIDTH/2-9+V_BAR_W*i, SCREEN_HEIGHT-8, len)
#define V_BAR_W 5
V_BAR(SCREEN_WIDTH/2-8+V_BAR_W*i, SCREEN_HEIGHT-8, len)
#else //EXTRA_ROTARY_ENCODERS
#define V_BAR_W 5
V_BAR(SCREEN_WIDTH/2-3+V_BAR_W*i, SCREEN_HEIGHT-8, len)
+9 -2
View File
@@ -860,12 +860,19 @@ void menuProcPhaseOne(uint8_t event)
for (uint8_t t=0; t<NUM_ROTARY_ENCODERS; t++) {
putsRotaryEncoderMode((14+t)*FW+2, y, s_currIdx, t, (attr && m_posHorz==4+t) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
if (attr && m_posHorz==4+t && ((s_editMode>0) || p1valdiff)) {
int16_t v = phaseaddress(s_currIdx)->rotaryEncoders[t];
int16_t v;
if(t < (NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS))
v = phaseaddress(s_currIdx)->rotaryEncoders[t];
else
v = g_model.rotaryEncodersExtra[s_currIdx][t-(NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS)];
if (v < ROTARY_ENCODER_MAX) v = ROTARY_ENCODER_MAX;
v = checkIncDec(event, v, ROTARY_ENCODER_MAX, ROTARY_ENCODER_MAX+MAX_PHASES-1, EE_MODEL);
if (checkIncDec_Ret) {
if (v == ROTARY_ENCODER_MAX) v = 0;
phaseaddress(s_currIdx)->rotaryEncoders[t] = v;
if(t < (NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS))
phaseaddress(s_currIdx)->rotaryEncoders[t] = v;
else
g_model.rotaryEncodersExtra[s_currIdx][t-(NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS)] = v;
}
}
}
+15 -7
View File
@@ -443,17 +443,24 @@ PACK(typedef struct t_SwashRingData { // Swash Ring data
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define NUM_EXTRA_ROTARY_ENCODERS 3
#else
#define NUM_EXTRA_ROTARY_ENCODERS 0
#endif
#define NUM_EXTRA_ROTARY_ENCODERS 2
#define NUM_ROTARY_ENCODERS (2+NUM_EXTRA_ROTARY_ENCODERS)
#define NUM_UART_ROTARY_ENCODERS 3
#define ROTARY_ENCODER_ARRAY_EXTRA int16_t rotaryEncodersExtra[MAX_PHASES][2];
#else //EXTRA_ROTARY_ENCODERS
#define NUM_EXTRA_ROTARY_ENCODERS 0
#define NUM_ROTARY_ENCODERS 2
#define ROTARY_ENCODER_ARRAY_EXTRA
#endif //EXTRA_ROTARY_ENCODERS
#define ROTARY_ENCODER_MAX 1024
#define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[NUM_ROTARY_ENCODERS];
#else
#define ROTARY_ENCODER_ARRAY int16_t rotaryEncoders[2];
#else //PCBV4
#define NUM_ROTARY_ENCODERS 0
#define NUM_EXTRA_ROTARY_ENCODERS 0
#define ROTARY_ENCODER_ARRAY
#endif
#define ROTARY_ENCODER_ARRAY_EXTRA
#endif //PCBV4
#if defined(PCBSTD)
#define TRIM_ARRAY int8_t trim[4]; int8_t trim_ext:8
@@ -576,6 +583,7 @@ PACK(typedef struct t_ModelData {
uint8_t varioSpeedDownMin;
uint8_t switchWarningStates;
ROTARY_ENCODER_ARRAY_EXTRA;
}) ModelData;
extern EEGeneral g_eeGeneral;
+28 -8
View File
@@ -685,7 +685,11 @@ uint8_t getRotaryEncoderFlightPhase(uint8_t idx)
uint8_t phase = s_perout_flight_phase;
for (uint8_t i=0; i<MAX_PHASES; i++) {
if (phase == 0) return 0;
int16_t value = phaseaddress(phase)->rotaryEncoders[idx];
int16_t value = 0;
if(idx<(NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS))
value = phaseaddress(phase)->rotaryEncoders[idx];
else
value = g_model.rotaryEncodersExtra[phase][idx-(NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS)];
if (value <= ROTARY_ENCODER_MAX) return phase;
uint8_t result = value-ROTARY_ENCODER_MAX-1;
if (result >= phase) result++;
@@ -696,13 +700,20 @@ uint8_t getRotaryEncoderFlightPhase(uint8_t idx)
int16_t getRotaryEncoder(uint8_t idx)
{
return phaseaddress(getRotaryEncoderFlightPhase(idx))->rotaryEncoders[idx];
if(idx < (NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS))
return phaseaddress(getRotaryEncoderFlightPhase(idx))->rotaryEncoders[idx];
else
return g_model.rotaryEncodersExtra[getRotaryEncoderFlightPhase(idx)][idx-(NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS)];
}
void incRotaryEncoder(uint8_t idx, int8_t inc)
{
g_rotenc[idx] += inc;
int16_t *value = &(phaseaddress(getRotaryEncoderFlightPhase(idx))->rotaryEncoders[idx]);
int16_t *value;
if(idx < (NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS))
value = &(phaseaddress(getRotaryEncoderFlightPhase(idx))->rotaryEncoders[idx]);
else
value = &(g_model.rotaryEncodersExtra[getRotaryEncoderFlightPhase(idx)][idx-(NUM_ROTARY_ENCODERS - NUM_EXTRA_ROTARY_ENCODERS)]);
*value = limit((int16_t)-1024, (int16_t)(*value + (inc * 8)), (int16_t)+1024);
eeDirty(EE_MODEL);
}
@@ -1445,7 +1456,7 @@ void evalFunctions()
}
}
if (~active_switches & switch_mask) {
if (~active_switches & switch_mask) {
if (sd->func == FUNC_RESET) {
switch (sd->param) {
case 0:
@@ -2470,6 +2481,7 @@ volatile uint8_t g_rotenc[2] = {0};
#ifndef SIMU
#if defined (PCBV4)
#if !defined(EXTRA_ROTARY_ENCODERS)
ISR(INT2_vect)
{
uint8_t input = PIND & 0b00001100;
@@ -2480,16 +2492,24 @@ ISR(INT3_vect)
uint8_t input = PIND & 0b00001100;
if (input == 0 || input == 0b00001100) incRotaryEncoder(0, +1);
}
#endif //EXTRA_ROTARY_ENCODERS
#if !defined(EXTRA_ROTARY_ENCODERS)
#define ENC_B_ID 1
#else
#define ENC_B_ID 0
#endif
ISR(INT5_vect)
{
uint8_t input = PINE & 0b01100000;
if (input == 0 || input == 0b01100000) incRotaryEncoder(1, +1);
if (input == 0 || input == 0b01100000) incRotaryEncoder(ENC_B_ID, +1);
}
ISR(INT6_vect)
{
uint8_t input = PINE & 0b01100000;
if (input == 0 || input == 0b01100000) incRotaryEncoder(1, -1);
if (input == 0 || input == 0b01100000) incRotaryEncoder(ENC_B_ID, -1);
}
#endif
@@ -2708,9 +2728,9 @@ int main(void)
lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ;
refreshDisplay() ;
#if defined(HAPTIC)
hapticOff() ;
hapticOff();
#endif
/* end force haptic to be disabled in this mode */
/* end force haptic to be disabled in this mode */
usb_mode();
}
#endif
+2 -2
View File
@@ -32,7 +32,7 @@
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "SVPK123abcde"
#define TR_RETA123 "SVPK123abcd"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "SVPK123ab"
#endif //EXTRA_ROTARY_ENCODERS
@@ -186,7 +186,7 @@
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd ""REe "
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
+2 -2
View File
@@ -32,7 +32,7 @@
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "RETA123abcde"
#define TR_RETA123 "RETA123abcd"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "RETA123ab"
#endif //EXTRA_ROTARY_ENCODERS
@@ -186,7 +186,7 @@
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd ""REe "
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
+2 -2
View File
@@ -32,7 +32,7 @@
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "RETA123abcde"
#define TR_RETA123 "RETA123abcd"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "RETA123ab"
#endif //EXTRA_ROTARY_ENCODERS
@@ -186,7 +186,7 @@
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd ""REe "
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
+2 -2
View File
@@ -32,7 +32,7 @@
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "RETA123abcde"
#define TR_RETA123 "RETA123abcd"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "RETA123ab"
#endif //EXTRA_ROTARY_ENCODERS
@@ -189,7 +189,7 @@
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd ""REe "
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
+2 -2
View File
@@ -32,7 +32,7 @@
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "RETA123abcde"
#define TR_RETA123 "RETA123abcd"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "RETA123ab"
#endif //EXTRA_ROTARY_ENCODERS
@@ -186,7 +186,7 @@
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd ""REe "
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
+14 -14
View File
@@ -29,13 +29,13 @@
#define LEN_VTRIMINC "\006"
#define TR_VTRIMINC "Exp ""xFin ""Fin ""Medel.""Grov "
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "RHGS123abcde"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "RHGS123ab"
#endif //EXTRA_ROTARY_ENCODERS
#define LEN_RETA123 "\001"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_RETA123 "RHGS123abcd"
#else //EXTRA_ROTARY_ENCODERS
#define TR_RETA123 "RHGS123ab"
#endif //EXTRA_ROTARY_ENCODERS
#else
#define TR_RETA123 "RHGS123"
#endif
@@ -186,13 +186,13 @@
#define TR_VSWITCHES "GAS""ROD""H\205J""ID0""ID1""ID2""SKE""LAN""TRN""BR1""BR2""BR3""BR4""BR5""BR6""BR7""BR8""BR9""BRA""BRB""BRC"
#endif
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd ""REe "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
#define LEN_VSRCRAW "\004"
#if defined(PCBV4)
#if defined(EXTRA_ROTARY_ENCODERS)
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd "
#else
#define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb "
#endif
#else
#define TR_ROTARY_ENCODERS_VSRCRAW
#endif