/* * Copyright (C) OpenTX * * Based on code named * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html * * 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" #if defined(ROTARY_ENCODER_NAVIGATION) #if defined(TELEMETREZ) uint8_t TrotCount; // TeZ version uint8_t LastTrotCount; // TeZ version uint8_t RotEncoder; #else uint8_t RotPosition; int8_t LastRotaryValue; int8_t Rotary_diff; int8_t RotaryControl; uint8_t RotEncoder; #endif void rotencPoll() { #if defined(TELEMETREZ) if (TrotCount != LastTrotCount) { rotencValue[0] = LastTrotCount = TrotCount; } #else // Rotary Encoder polling PORTA = 0; // No pullups DDRA = 0x1F; // Top 3 bits input asm(" rjmp 1f"); asm("1:"); uint8_t rotary; rotary = PINA; DDRA = 0xFF; // Back to all outputs rotary &= 0xE0; RotEncoder = rotary; // just read the lcd pin rotary &= 0xDF; if ( rotary != RotPosition ) { uint8_t x; x = RotPosition & 0x40; x <<= 1; x ^= rotary & 0x80; if ( x ) { rotencValue[0] -= 1; } else { rotencValue[0] += 1; } RotPosition = rotary; } #endif // TELEMETREZ } #else #define ROTENC_DOWN() (0) #endif // ROTARY_ENCODER_NAVIGATION void boardInit() { #if !defined(SIMU) // Set up I/O port data directions and initial states DDRA = 0xff; PORTA = 0x00; // LCD data DDRB = 0x81; PORTB = 0x7e; //pullups keys+nc #if defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED) DDRC = 0xff; PORTC = 0x00; #else DDRC = 0x3e; PORTC = 0xc1; //pullups nc #endif DDRD = 0x00; PORTD = 0xff; //pullups keys DDRE = (1<= (s_anaFilt[TX_VOLTAGE] / 2)) ? 1 : 0; break; } // set the mux number for the next ADC convert, // stabilize voltage before ADC read. muxNum = nextMuxNum; PORTC &= ~((1 << PC7) | (1 << PC6) | (1 << PC0)); if(muxNum & 1) PORTC |= (1 << PC7); // Mux CTRL A if(muxNum & 2) PORTC |= (1 << PC6); // Mux CTRL B if(muxNum & 4) PORTC |= (1 << PC0); // Mux CTRL C } #endif #if !defined(SIMU) && (defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED)) #define THR_STATE() pf7_digital[PF7_THR] #define AIL_STATE() pf7_digital[PF7_AIL] #elif defined(TELEMETRY_JETI) || defined(TELEMETRY_FRSKY) || defined(TELEMETRY_ARDUPILOT) || defined(TELEMETRY_NMEA) || defined(TELEMETRY_MAVLINK) #define THR_STATE() (PINC & (1< only phone jack = slave mode static bool lastSlaveMode = false; static uint8_t checkDelay = 0; if (IS_AUDIO_BUSY()) { checkDelay = 20; } else if (checkDelay) { --checkDelay; } else { lastSlaveMode = (PING & (1< bl_current) OCR0A = pgm_read_byte(&pwmtable[++bl_current]); else OCR0A = pgm_read_byte(&pwmtable[--bl_current]); #else if (bl_target > bl_current) OCR2 = pgm_read_byte(&pwmtable[++bl_current]); else OCR2 = pgm_read_byte(&pwmtable[--bl_current]); #endif } } #endif