diff --git a/radio/src/audio_avr.cpp b/radio/src/audio_avr.cpp deleted file mode 100644 index 5dbc464d0..000000000 --- a/radio/src/audio_avr.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/* - * 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" - -audioQueue::audioQueue() -{ - toneTimeLeft = 0; - tonePause = 0; - tone2TimeLeft = 0; - - t_queueRidx = 0; - t_queueWidx = 0; -} - - -// heartbeat is responsibile for issueing the audio tones and general square waves -// it is essentially the life of the class. -// it is called every 10ms -void audioQueue::heartbeat() -{ -#if defined(SIMU) - return; -#else - if (toneTimeLeft > 0) { - if (toneFreq == 0) { //pause only events - speakerOff(); - } - else { -#if defined(CPUM2560) - if (toneFreq) { - OCR4A = (5000 / toneFreq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?). - speakerOn(); - } -#endif - toneFreq += toneFreqIncr; - } - toneTimeLeft--; //time gets counted down - } - else { - if (tonePause > 0) { - speakerOff(); - tonePause--; //time gets counted down - } - else if (t_queueRidx != t_queueWidx) { - toneFreq = queueToneFreq[t_queueRidx]; - toneTimeLeft = queueToneLength[t_queueRidx]; - toneFreqIncr = queueToneFreqIncr[t_queueRidx]; - tonePause = queueTonePause[t_queueRidx]; - if (!queueToneRepeat[t_queueRidx]--) { - t_queueRidx = (t_queueRidx + 1) & (AUDIO_QUEUE_LENGTH-1); - } - } - else { - if (tone2TimeLeft > 0) { -#if defined(CPUM2560) - if (tone2Freq) { - OCR4A = (5000 / tone2Freq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?). - speakerOn(); - } -#else - toneFreq = tone2Freq; -#endif - tone2TimeLeft--; //time gets counted down - } - else { - speakerOff(); - } - } - } -#endif // defined(SIMU) -} - -inline uint8_t audioQueue::getToneLength(uint8_t tLen) -{ - uint8_t result = tLen; // default - if (g_eeGeneral.beepLength < 0) { - result /= (1-g_eeGeneral.beepLength); - } - if (g_eeGeneral.beepLength > 0) { - result *= (1+g_eeGeneral.beepLength); - } - return result; -} - -void audioQueue::pause(uint8_t tLen) -{ - play(0, tLen, 5); // a pause -} - -void audioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlags) -{ - if (tFlags & PLAY_BACKGROUND) { - tone2Freq = tFreq; - tone2TimeLeft = tLen; - } - else { - int8_t tFreqIncr = (tFlags >> 6); - if (tFreqIncr == 3) tFreqIncr = -1; - - tFreq += g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator - tLen = getToneLength(tLen); - - if ((tFlags & PLAY_NOW) || (!busy() && empty())) { - toneFreq = tFreq; - toneTimeLeft = tLen; - tonePause = tPause; - toneFreqIncr = tFreqIncr; - t_queueWidx = t_queueRidx; - } - else { - tFlags++; - } - - tFlags &= 0x0f; - if (tFlags) { - uint8_t next_queueWidx = (t_queueWidx + 1) & (AUDIO_QUEUE_LENGTH-1); - if (next_queueWidx != t_queueRidx) { - queueToneFreq[t_queueWidx] = tFreq; - queueToneLength[t_queueWidx] = tLen; - queueTonePause[t_queueWidx] = tPause; - queueToneRepeat[t_queueWidx] = tFlags - 1; - queueToneFreqIncr[t_queueWidx] = tFreqIncr; - t_queueWidx = next_queueWidx; - } - } - } -} - -void audioQueue::event(uint8_t e) -{ -#if defined(HAPTIC) - haptic.event(e); //do this before audio to help sync timings -#endif - - if (e <= AU_ERROR || (e >= AU_WARNING1 && e < AU_SPECIAL_SOUND_FIRST)) { - if (g_eeGeneral.alarmsFlash) { - flashCounter = FLASH_DURATION; - } - } - - if (g_eeGeneral.beepMode >= e_mode_nokeys || (g_eeGeneral.beepMode >= e_mode_alarms && e <= AU_ERROR)) { - if (e < AU_SPECIAL_SOUND_FIRST || empty()) { - // TODO when VOICE enable some cases here are not needed! - switch (e) { -#if !defined(VOICE) - case AU_TX_BATTERY_LOW: - if (empty()) { - play(60, 20, 3, PLAY_REPEAT(2)|PLAY_INCREMENT(1)); - play(80, 20, 3, PLAY_REPEAT(2)|PLAY_INCREMENT(-1)); - } - break; -#endif - case AU_SPECIAL_SOUND_RING: - play(BEEP_DEFAULT_FREQ+25, 5, 2, PLAY_REPEAT(10)); - play(BEEP_DEFAULT_FREQ+25, 5, 10, PLAY_REPEAT(1)); - play(BEEP_DEFAULT_FREQ+25, 5, 2, PLAY_REPEAT(10)); - break; - case AU_SPECIAL_SOUND_SCIFI: - play(80, 10, 3, PLAY_REPEAT(2)|PLAY_INCREMENT(-1)); - play(60, 10, 3, PLAY_REPEAT(2)|PLAY_INCREMENT(1)); - play(70, 10, 1); - break; - case AU_SPECIAL_SOUND_ROBOT: - play(70, 5, 1, PLAY_REPEAT(1)); - play(50, 15, 2, PLAY_REPEAT(1)); - play(80, 15, 2, PLAY_REPEAT(1)); - break; - case AU_SPECIAL_SOUND_CHIRP: - play(BEEP_DEFAULT_FREQ+40, 5, 1, PLAY_REPEAT(2)); - play(BEEP_DEFAULT_FREQ+54, 5, 1, PLAY_REPEAT(3)); - break; - case AU_SPECIAL_SOUND_TADA: - play(50, 5, 5); - play(90, 5, 5); - play(110, 3, 4, PLAY_REPEAT(2)); - break; - case AU_SPECIAL_SOUND_CRICKET: - play(80, 5, 10, PLAY_REPEAT(3)); - play(80, 5, 20, PLAY_REPEAT(1)); - play(80, 5, 10, PLAY_REPEAT(3)); - break; - case AU_SPECIAL_SOUND_ALARMC: - play(50, 4, 10, PLAY_REPEAT(2)); - play(70, 8, 20, PLAY_REPEAT(1)); - play(50, 8, 10, PLAY_REPEAT(2)); - play(70, 4, 20, PLAY_REPEAT(1)); - break; - default: - { - static const pm_uint8_t singleSounds[] PROGMEM = { - 70, 10, 2, PLAY_REPEAT(2)|PLAY_NOW, // INACTIVITY - BEEP_DEFAULT_FREQ, 40, 1, PLAY_NOW, // ERROR - BEEP_DEFAULT_FREQ, 10, 1, PLAY_NOW, // WARNING1 - BEEP_DEFAULT_FREQ, 20, 1, PLAY_NOW, // WARNING2 - BEEP_DEFAULT_FREQ, 30, 1, PLAY_NOW, // WARNING3 - 60, 10, 2, PLAY_NOW, // TRIM_MIDDLE - BEEP_DEFAULT_FREQ + 50, 10, 1, PLAY_NOW, // POT_STICK_MIDDLE - BEEP_DEFAULT_FREQ + 50, 6, 0, 0, // MIX_WARNING_1 - BEEP_DEFAULT_FREQ + 52, 6, 3, PLAY_REPEAT(1), // MIX_WARNING_2 - BEEP_DEFAULT_FREQ + 54, 6, 3, PLAY_REPEAT(2), // MIX_WARNING_3 - BEEP_DEFAULT_FREQ, 10, 1, 0, // FRSKY_BEEP1 - BEEP_DEFAULT_FREQ, 20, 1, 0, // FRSKY_BEEP2 - BEEP_DEFAULT_FREQ, 30, 1, 0, // FRSKY_BEEP3 - BEEP_DEFAULT_FREQ+20, 15, 5, PLAY_REPEAT(2), // FRSKY_WARN1 - BEEP_DEFAULT_FREQ+30, 15, 5, PLAY_REPEAT(2), // FRSKY_WARN2 - BEEP_DEFAULT_FREQ+30, 10, 2, PLAY_REPEAT(2)|PLAY_INCREMENT(2), // FRSKY_CHEEP - BEEP_DEFAULT_FREQ+50, 5, 10, PLAY_REPEAT(10), // FRSKY_RATATA - BEEP_DEFAULT_FREQ+50, 5, 50, PLAY_REPEAT(2), // FRSKY_TICK - 10, 20, 5, PLAY_REPEAT(2)|PLAY_INCREMENT(1), // FRSKY_SIREN - }; - - const pm_uint8_t *ptr = &singleSounds[(e-AU_INACTIVITY)<<2]; - uint8_t tFreq = pgm_read_byte(ptr++); - uint8_t tLen = pgm_read_byte(ptr++); - uint8_t tPause = pgm_read_byte(ptr++); - uint8_t tFlags = pgm_read_byte(ptr); - play(tFreq, tLen, tPause, tFlags); - break; - } - } - } - } -} - -void audioDefevent(uint8_t e) -{ - audio.event(e); -} - -void audioKeyPress() -{ -#if defined(AUDIO) - if (g_eeGeneral.beepMode == e_mode_all) { - audio.play(BEEP_DEFAULT_FREQ, 10, 1, PLAY_NOW); - } -#else - beep(0); -#endif - -#if defined(HAPTIC) - if (g_eeGeneral.hapticMode == e_mode_all) { - haptic.play(5, 0, PLAY_NOW); - } -#endif -} - -void audioTrimPress(int16_t value) -{ - if (g_eeGeneral.beepMode >= e_mode_nokeys) { -#if defined(AUDIO) - value = limit(TRIM_MIN, value, TRIM_MAX); - value >>= 2; - value += 60; - audio.play(value, 6, 1, PLAY_NOW); -#else - warble = true; - beep(1); -#endif - } -} - -void audioTimerCountdown(uint8_t timer, int value) -{ - if (0) { - // pass - } - -#if defined(CPUM2560) && (defined(VOICE_WTV20) || defined(VOICE_JQ6500)) - else if (g_model.timers[timer].countdownBeep == COUNTDOWN_VOICE) { - if (value >= 0 && value <= TIMER_COUNTDOWN_START(timer)) { - playNumber(value, 0, 0); - } - else if (value == 30 || value == 20) { - playDuration(value); - } - } -#endif - -#if defined(HAPTIC) - else if (g_model.timers[timer].countdownBeep == COUNTDOWN_HAPTIC) { - if (value == 0) { - haptic.play(15, 3, PLAY_NOW); - } - else if (value > 0 && value <= 10) { - haptic.play(5, 0, PLAY_NOW); - } - else if (value == 30) { - haptic.play(10, 3, PLAY_REPEAT(2) | PLAY_NOW); - } - else if (value == 20) { - haptic.play(10, 3, PLAY_REPEAT(1) | PLAY_NOW); - } - } -#endif - - else { - if (value == 0) { - audio.play(BEEP_DEFAULT_FREQ + 50, 30, 3, PLAY_NOW); - } - else if (value > 0 && value <= 10) { - audio.play(BEEP_DEFAULT_FREQ + 50, 15, 3, PLAY_NOW); - } - else if (value == 30) { - audio.play(BEEP_DEFAULT_FREQ + 50, 15, 3, PLAY_REPEAT(2) | PLAY_NOW); - } - else if (value == 20) { - audio.play(BEEP_DEFAULT_FREQ + 50, 15, 3, PLAY_REPEAT(1) | PLAY_NOW); - } - } -} diff --git a/radio/src/audio_avr.h b/radio/src/audio_avr.h deleted file mode 100644 index 1194f9de6..000000000 --- a/radio/src/audio_avr.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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. - */ - -#ifndef _AUDIO_AVR_H_ -#define _AUDIO_AVR_H_ - -#if defined(PCBSTD) - #define speakerOn() buzzerOn() - #define speakerOff() toneFreq=0; buzzerOff() -#endif - -//audio -#define AUDIO_QUEUE_LENGTH (8) // 8 seems to suit most alerts -#define BEEP_DEFAULT_FREQ (70) -#define BEEP_OFFSET (10) - -class audioQueue -{ - public: - - audioQueue(); - - void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlags=0); - void pause(uint8_t tLen); - - inline bool busy() { return (toneTimeLeft > 0); } - - void event(uint8_t e); - - inline void driver() { - if (toneFreq) { - toneCounter += toneFreq; - if ((toneCounter & 0x80) == 0x80) - buzzerOn(); - else - buzzerOff(); - } - } - - // heartbeat is responsibile for issueing the audio tones and general square waves - // it is essentially the life of the class. - void heartbeat(); - - inline bool empty() { - return (t_queueRidx == t_queueWidx); - } - - protected: - inline uint8_t getToneLength(uint8_t tLen); - - private: - uint8_t t_queueRidx; - uint8_t t_queueWidx; - - uint8_t toneFreq; - int8_t toneFreqIncr; - uint8_t toneTimeLeft; - uint8_t tonePause; - - // vario has less priority - uint8_t tone2Freq; - uint8_t tone2TimeLeft; - - // queue arrays - uint8_t queueToneFreq[AUDIO_QUEUE_LENGTH]; - int8_t queueToneFreqIncr[AUDIO_QUEUE_LENGTH]; - uint8_t queueToneLength[AUDIO_QUEUE_LENGTH]; - uint8_t queueTonePause[AUDIO_QUEUE_LENGTH]; - uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH]; - - uint8_t toneCounter; - -}; - -extern audioQueue audio; - -void audioDefevent(uint8_t e); - -#if defined(AUDIO) && defined(BUZZER) - #define AUDIO_BUZZER(a, b) do { a; b; } while(0) -#elif defined(AUDIO) - #define AUDIO_BUZZER(a, b) a -#else - #define AUDIO_BUZZER(a, b) b -#endif - -#if defined(VOICE) - #define VOICE_AUDIO_BUZZER(v, a, b) v -#else - #define VOICE_AUDIO_BUZZER(v, a, b) AUDIO_BUZZER(a, b) -#endif - -void audioKeyPress(); -void audioKeyError(); -void audioTrimPress(int16_t value); -void audioTimerCountdown(uint8_t timer, int value); - -#define AUDIO_KEY_PRESS() audioKeyPress() -#define AUDIO_KEY_ERROR() AUDIO_WARNING2() -#define AUDIO_WARNING1() AUDIO_BUZZER(audioDefevent(AU_WARNING1), beep(3)) -#define AUDIO_WARNING2() AUDIO_BUZZER(audioDefevent(AU_WARNING2), beep(2)) -#define AUDIO_ERROR() AUDIO_BUZZER(audioDefevent(AU_ERROR), beep(4)) -#define AUDIO_HELLO() VOICE_AUDIO_BUZZER(PUSH_SYSTEM_PROMPT(AUDIO_HELLO),,) -#define AUDIO_BYE() -#define AUDIO_TX_BATTERY_LOW() VOICE_AUDIO_BUZZER(PUSH_SYSTEM_PROMPT(AU_TX_BATTERY_LOW), audioDefevent(AU_TX_BATTERY_LOW), beep(4)) -#define AUDIO_INACTIVITY() VOICE_AUDIO_BUZZER(PUSH_SYSTEM_PROMPT(AU_INACTIVITY), audioDefevent(AU_INACTIVITY), beep(3)) -#define AUDIO_ERROR_MESSAGE(e) VOICE_AUDIO_BUZZER(PUSH_SYSTEM_PROMPT((e)), audioDefevent(AU_ERROR), beep(4)) -#define AUDIO_TIMER_MINUTE(t) VOICE_AUDIO_BUZZER(playDuration(t), audioDefevent(AU_WARNING1), beep(2)) -#define AUDIO_TIMER_COUNTDOWN(idx, val) audioTimerCountdown(idx, val) -#define AUDIO_TIMER_ELAPSED(idx) AUDIO_BUZZER(audioTimerCountdown(idx, 0), beep(3)) - -//#define AUDIO_TIMER_30() // VOICE_AUDIO_BUZZER(PUSH_SYSTEM_PROMPT(AU_TIMER_30), audioDefevent(AU_TIMER_30), { beepAgain=2; beep(2); }) -//#define AUDIO_TIMER_20() // VOICE_AUDIO_BUZZER(PUSH_SYSTEM_PROMPT(AU_TIMER_20), audioDefevent(AU_TIMER_20), { beepAgain=1; beep(2); }) -//#define AUDIO_TIMER_LT10(m, x) // AUDIO_BUZZER(audioDefevent(AU_TIMER_LT10), beep(2)) -//#define AUDIO_TIMER_00(m) // AUDIO_BUZZER(audioDefevent(AU_TIMER_00), beep(3)) -#define AUDIO_MIX_WARNING(x) AUDIO_BUZZER(audioDefevent(AU_MIX_WARNING_1+x-1), beep(1)) -#define AUDIO_POT_MIDDLE() AUDIO_BUZZER(audioDefevent(AU_POT_MIDDLE), beep(2)) -#define AUDIO_VARIO_UP() // audioDefevent(AU_KEYPAD_UP) -#define AUDIO_VARIO_DOWN() // audioDefevent(AU_KEYPAD_DOWN) -#define AUDIO_TRIM_MIDDLE() // AUDIO_BUZZER(audio.event(AU_TRIM_MIDDLE, f), beep(2)) -#define AUDIO_TRIM_MIN() // AUDIO_BUZZER(audioDefevent(f), beep(2)) -#define AUDIO_TRIM_MAX() // AUDIO_BUZZER(audioDefevent(f), beep(2)) -#define AUDIO_TRIM_PRESS(val) audioTrimPress(val) -#define AUDIO_PLAY(p) audio.event(p) -#define AUDIO_VARIO(f, t) audio.play(f, t, 0, PLAY_BACKGROUND) - -#define AUDIO_DRIVER() audio.driver() -#define AUDIO_HEARTBEAT() audio.heartbeat() -#define IS_AUDIO_BUSY() audio.busy() -#define AUDIO_RESET() -#define AUDIO_FLUSH() - -#define PLAY_PHASE_OFF(phase) -#define PLAY_PHASE_ON(phase) -#define PLAY_SWITCH_MOVED(sw) -#define PLAY_LOGICAL_SWITCH_OFF(sw) -#define PLAY_LOGICAL_SWITCH_ON(sw) -#define PLAY_MODEL_NAME() -#define START_SILENCE_PERIOD() - -#endif // _AUDIO_AVR_H_ diff --git a/radio/src/main_avr.cpp b/radio/src/main_avr.cpp deleted file mode 100644 index 24aaa1e9f..000000000 --- a/radio/src/main_avr.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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" - -void checkBattery(); -uint8_t checkTrim(event_t event); - -void perMain() -{ -#if defined(SIMU) - doMixerCalculations(); -#endif -#if defined(LCD_ST7920) - uint8_t lcdstate=0; - #define IS_LCD_REFRESH_ALLOWED() (0==lcdstate) -#else - #define IS_LCD_REFRESH_ALLOWED() (1) -#endif - uint16_t t0 = getTmr16KHz(); - int16_t delta = (nextMixerEndTime - lastMixerDuration) - t0; - if (delta > 0 && delta < MAX_MIXER_DELTA) { -#if defined(PCBSTD) && defined(ROTARY_ENCODER_NAVIGATION) - rotencPoll(); -#endif - - // @@@ open.20.fsguruh - // SLEEP(); // wouldn't that make sense? should save a lot of battery power!!! -/* for future use; currently very very beta... */ -#if defined(POWER_SAVE) - ADCSRA&=0x7F; // disable ADC for power saving - ACSR&=0xF7; // disable ACIE Interrupts - ACSR|=0x80; // disable Analog Comparator - // maybe we disable here a lot more hardware components in future to save even more power - - - - MCUCR|=0x20; // enable Sleep (bit5) - // MCUCR|=0x28; // enable Sleep (bit5) enable ADC Noise Reduction (bit3) - // first tests showed: simple sleep would reduce cpu current from 40.5mA to 32.0mA - // noise reduction sleep would reduce it down to 28.5mA; However this would break pulses in theory - // however with standard module, it will need about 95mA. Therefore the drop to 88mA is not much noticable - do { - asm volatile(" sleep \n\t"); // if _SLEEP() is not defined use this - t0=getTmr16KHz(); - delta= (nextMixerEndTime - lastMixerDuration) - t0; - } while ((delta>0) && (delta maxMixerDuration) maxMixerDuration = t0; - -#if defined(MODULE_ALWAYS_SEND_PULSES) - if (startupWarningState < STARTUP_WARNING_DONE) { - // don't do menu's until throttle and switch warnings are handled - return; - } -#endif - - if (eepromIsTransferComplete()) { - if (theFile.isWriting()) - theFile.nextWriteStep(); - else if (TIME_TO_WRITE()) - storageCheck(false); - } - -#if defined(SDCARD) - sdMountPoll(); - logsWrite(); -#endif - - event_t evt = getEvent(); - evt = checkTrim(evt); - - if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on - doLoopCommonActions(); - -#if defined(TELEMETRY_FRSKY) || defined(TELEMETRY_MAVLINK) - telemetryWakeup(); -#endif - -#if defined(NAVIGATION_STICKS) - uint8_t sticks_evt = getSticksNavigationEvent(); - if (sticks_evt) evt = sticks_evt; -#endif - -#if defined(GUI) - const char * warn = warningText; - bool popupMenuActive = (popupMenuNoItems > 0); - - if (IS_LCD_REFRESH_ALLOWED()) { // No need to redraw until lcdRefresh_ST7920(0) below completely refreshes the display. - lcdClear(); - if (menuEvent) { - menuVerticalPosition = menuEvent == EVT_ENTRY_UP ? menuVerticalPositions[menuLevel] : 0; - menuHorizontalPosition = 0; - evt = menuEvent; - menuEvent = 0; - } - menuHandlers[menuLevel]((warn || popupMenuActive) ? 0 : evt); - - if (warn) DISPLAY_WARNING(evt); -#if defined(NAVIGATION_MENUS) - if (popupMenuActive) { - const char * result = runPopupMenu(evt); - if (result) { - popupMenuHandler(result); - } - } -#endif - drawStatusLine(); - } - -#if defined(LCD_KS108) - lcdRefreshSide(); -#elif defined(LCD_ST7920) - lcdstate = lcdRefresh_ST7920(0); -#else - lcdRefresh(); -#endif - -#endif // defined(GUI) - - if (SLAVE_MODE()) { - JACK_PPM_OUT(); - } - else { - JACK_PPM_IN(); - } - - checkBattery(); -} diff --git a/radio/src/targets/9x/CMakeLists.txt b/radio/src/targets/9x/CMakeLists.txt deleted file mode 100644 index 67131794c..000000000 --- a/radio/src/targets/9x/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -option(SP22 "SmartieParts 2.2 Backlight support" OFF) -option(PWM_BACKLIGHT "PWM Backlight" OFF) -set(ARCH AVR) -set(MCU atmega64) -set(AVRDUDE_MCU m64) -string(TOLOWER ${PCB} FLAVOUR) -set(EEPROM_VARIANT_NEEDED ON) -set(EEPROM EEPROM_RLC) -set(SDCARD NO) -set(GUI_DIR 128x64) -set(TARGET_DIR 9x) -set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} 9x_bitmaps) -add_definitions(-DPCBSTD -DPCB${PCB} -DCPUM64) -set(TARGET_SRC ${TARGET_SRC} board.cpp) -set(GUI_SRC - ${GUI_SRC} - model_inputs_mixes.cpp - radio_diagkeys.cpp - radio_diaganas.cpp - ) -if(SP22) - add_definitions(-DSP22) -endif() -if(PWM_BACKLIGHT) - add_definitions(-DPWM_BACKLIGHT) -endif() -set(FIRMWARE_TARGET_SRC - ${FIRMWARE_TARGET_SRC} - lcd_driver.cpp - ) - diff --git a/radio/src/targets/9x/board.cpp b/radio/src/targets/9x/board.cpp deleted file mode 100644 index 7cb8fa1b9..000000000 --- a/radio/src/targets/9x/board.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/* - * 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 diff --git a/radio/src/targets/9x/board.h b/radio/src/targets/9x/board.h deleted file mode 100644 index b23ee8e9b..000000000 --- a/radio/src/targets/9x/board.h +++ /dev/null @@ -1,273 +0,0 @@ -/* - * 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. - */ - -#ifndef _BOARD_STOCK_H_ -#define _BOARD_STOCK_H_ - -#include "../common/avr/board_avr.h" - -// -// elev thr -// LV RV -// 2 ^ 4 ^ -// 1 2 -// | rudd | aile -// <----X--3-> LH <----X--0-> RH -// 6 | 7 1 | 0 -// | | -// 3 v 5 v -// -//PORTA 7 6 5 4 3 2 1 0 -// O O O O O O O O -// ------------------------ LCD_DAT ----------------------- -// -//PORTB 7 6 5 4 3 2 1 0 -// O i i i i i i O -// light KEY_LFT KEY_RGT KEY_UP KEY_DWN KEY_EXT KEY_MEN PPM -// -//PORTC 7 6 5 4 3 2 1 0 -// - - O O O O O - -// NC NC LCD_E LCD_RNW LCD_A0 LCD_RES LCD_CS1 NC -// -//PORTD 7 6 5 4 3 2 1 0 -// i i i i i i i i -// TRM_D_DWN _UP TRM_C_DWN _UP TRM_B_DWN _UP TRM_A_DWN _UP -// -//PORTE 7 6 5 4 3 2 1 0 -// i i i i O i i i -// PPM_IN ID2 Trainer Gear Buzzer ElevDR AileDR THRCT -// -//PORTF 7 6 5 4 3 2 1 0 -// ai ai ai ai ai ai ai ai -// ANA_ BAT PITT_TRM HOV_THR HOV_PIT STCK_LH STCK_RV STCK_LV STCK_RH -// rud thro elev aile -//PORTG 7 6 5 4 3 2 1 0 -// - - - O i i i -// SIM_CTL ID1 Haptic RF_POW RuddDR - -// Board driver -void boardInit(void); -#define boardOff() pwrOff() - -// Keys -#define KEYS_GPIO_REG_MENU pinb -#define KEYS_GPIO_PIN_MENU (1<<1) -#define KEYS_GPIO_REG_EXIT pinb -#define KEYS_GPIO_PIN_EXIT (1<<2) -#define KEYS_GPIO_REG_RIGHT pinb -#define KEYS_GPIO_PIN_RIGHT (1<<5) -#define KEYS_GPIO_REG_LEFT pinb -#define KEYS_GPIO_PIN_LEFT (1<<6) -#define KEYS_GPIO_REG_UP pinb -#define KEYS_GPIO_PIN_UP (1<<4) -#define KEYS_GPIO_REG_DOWN pinb -#define KEYS_GPIO_PIN_DOWN (1<<3) -#define IS_SHIFT_KEY(index) (false) -#define IS_SHIFT_PRESSED() (false) - -// Trims -#define NUM_TRIMS 4 -#define NUM_TRIMS_KEYS (NUM_TRIMS * 2) -#define TRIMS_GPIO_REG_LHL pind -#define TRIMS_GPIO_PIN_LHL (1<<6) -#define TRIMS_GPIO_REG_LVD pind -#define TRIMS_GPIO_PIN_LVD (1<<3) -#define TRIMS_GPIO_REG_RVU pind -#define TRIMS_GPIO_PIN_RVU (1<<4) -#define TRIMS_GPIO_REG_RHL pind -#define TRIMS_GPIO_PIN_RHL (1<<1) -#define TRIMS_GPIO_REG_LHR pind -#define TRIMS_GPIO_PIN_LHR (1<<7) -#define TRIMS_GPIO_REG_LVU pind -#define TRIMS_GPIO_PIN_LVU (1<<2) -#define TRIMS_GPIO_REG_RVD pind -#define TRIMS_GPIO_PIN_RVD (1<<5) -#define TRIMS_GPIO_REG_RHR pind -#define TRIMS_GPIO_PIN_RHR (1<<0) - -#if defined(CPUM2561) - #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<SEG1) - 0xA6, //REV = 0: non-reverse display - 0xA4, //EON = 0: normal display. non-entire - 0xA2, //Select LCD bias - 0xC8, //SHL = 1: reverse direction (COM64->COM1) - 0x2F, //Control power circuit operation VC=VR=VF=1 - 0x25, //Select int resistance ratio R2 R1 R0 =5 - 0x81, //Set reference voltage Mode - 0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18 - 0xAF, //DON = 1: display ON - 0x60 //Set the display start line to zero -#elif defined(LCD_ERC12864FSF) - 0xE2, //Initialize the internal functions - 0xAE, //DON = 0: display OFF - 0xA1, //ADC = 1: reverse direction (SEG132->SEG1) - 0xA6, //REV = 0: non-reverse display - 0xA4, //EON = 0: normal display. non-entire - 0xA3, //Select LCD bias - 0xC0, //SHL = 0: normal direction (COM1->COM64) - 0x2F, //Control power circuit operation VC=VR=VF=1 - 0x27, //Select int resistance ratio R2 R1 R0 - 0x81, //Set reference voltage Mode - 0x2D, //24 SV5 SV4 SV3 SV2 SV1 SV0 - 0xAF //DON = 1: display ON -#else //ST7565P (default 9x LCD) - 0xE2, //Initialize the internal functions - 0xAE, //DON = 0: display OFF - 0xA1, //ADC = 1: reverse direction(SEG132->SEG1) - 0xA6, //REV = 0: non-reverse display - 0xA4, //EON = 0: normal display. non-entire - 0xA2, //Select LCD bias=0 - 0xC0, //SHL = 0: normal direction (COM1->COM64) - 0x2F, //Control power circuit operation VC=VR=VF=1 - 0x25, //Select int resistance ratio R2 R1 R0 =5 - 0x81, //Set reference voltage Mode - 0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18 - 0xAF //DON = 1: display ON -#endif -}; - -void lcdInit() -{ - LCD_LOCK(); - PORTC_LCD_CTRL &= ~(1<0; --x) { - PORTA_LCD_DAT = *p++; - PORTC_LCD_CTRL |= (1<0; --x) { - PORTA_LCD_DAT = *p++; - lcdPulseEnable(); - } - p += 64; - } - A0_off; -} - -void lcdRefresh() -{ - lcdRefreshSide(); - lcdRefreshSide(); -} diff --git a/radio/src/targets/9x/lcd_st7920_driver.cpp b/radio/src/targets/9x/lcd_st7920_driver.cpp deleted file mode 100644 index f0acf748e..000000000 --- a/radio/src/targets/9x/lcd_st7920_driver.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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. - */ - -void lcdSendCtl(uint8_t val) -{ - PORTC_LCD_CTRL &= ~(1< 31) { - y_addr = y - 32; //Because there are only 31 addressable lines in the ST7920 - x_addr += 8; //so we overflow x (7 visible bytes per line) to reach the bottom half - } - else { - y_addr = y; - } - lcdSendCtl( 0x80 | y_addr ); //Set Vertical Address - _delay_us(49); - lcdSendCtl( 0x80 | x_addr ); //Set Horizontal Address - _delay_us(49); - PORTC_LCD_CTRL |= (1< 0=0, 1=1..7=7, 8=0, 9=1... - col_offset = 1 << bit_count; //Build a value for a AND operation with the vorrect bitposition - line_offset = ( y / 8 ) * 128; //On the ST7565 there are 8 lines with each 128 bytes width - for (coord_t x=0; x<16; x++) { //Walk through 16 bytes form left to right (128 Pixel) - p = displayBuf + line_offset + ( x * 8 ); //Calculate the position of the first byte im array - // adressing the bytes sequential and set the bits at the correct position merging them with an OR operation to get all bits in one byte - // the position of the LSB is the right-most position of the byte to the ST7920 - result = ((*p++ & col_offset)!=0?0x80:0); - result |= ((*p++ & col_offset)!=0?0x40:0); - result |= ((*p++ & col_offset)!=0?0x20:0); - result |= ((*p++ & col_offset)!=0?0x10:0); - result |= ((*p++ & col_offset)!=0?0x08:0); - result |= ((*p++ & col_offset)!=0?0x04:0); - result |= ((*p++ & col_offset) !=0?0x02:0); - result |= ((*p++ & col_offset)!=0?0x01:0); - PORTA_LCD_DAT = result; - PORTC_LCD_CTRL |= (1<VoiceQueueCount < VOICE_Q_LENGTH) { - vptr->VoiceQueue[vptr->VoiceQueueInIndex++] = value; - vptr->VoiceQueueInIndex &= (VOICE_Q_LENGTH - 1); - vptr->VoiceQueueCount += 1; - } -} - -void pushCustomPrompt(uint8_t value) -{ - pushPrompt(PROMPT_CUSTOM_BASE + value); -} - -void pushNumberPrompt(uint8_t value) -{ - pushPrompt(PROMPT_I18N_BASE + value); -} - -struct t_voice *voiceaddress() -{ - return &Voice ; -} - -void t_voice::voice_process(void) -{ - if (Backlight) - VoiceLatch |= BACKLIGHT_BIT; - else - VoiceLatch &= ~BACKLIGHT_BIT; - - if (VoiceState == V_IDLE) { - PORTB |= (1 << OUT_B_LIGHT); // Latch clock high - if (VoiceQueueCount) { - VoiceSerial = VoiceQueue[VoiceQueueOutIndex++]; - VoiceQueueOutIndex &= (VOICE_Q_LENGTH - 1); - VoiceQueueCount -= 1; - VoiceTimer = 17; - if (VoiceSerial & 0x8000) { // Looking for sound volume 1F0-1F7 - VoiceTimer = 40; - } - VoiceLatch &= ~VOICE_CLOCK_BIT & ~VOICE_DATA_BIT ; - if (VoiceSerial & 0x8000) { - VoiceLatch |= VOICE_DATA_BIT; - } - PORTA_LCD_DAT = VoiceLatch ; // Latch data set - PORTB &= ~(1< 60) { // Give module 1.4 secs to initialise - VoiceState = V_WAIT_START_BUSY_OFF ; - } - PORTB &= ~(1<VoiceState == V_CLOCKING ) { \ - if ( vptr->VoiceTimer ) { \ - vptr->VoiceTimer -= 1; \ - } \ - else { \ - PORTB |= (1<VoiceCounter & 1) == 0) { \ - vptr->VoiceLatch &= ~VOICE_DATA_BIT; \ - if ( vptr->VoiceSerial & 0x4000 ) { \ - vptr->VoiceLatch |= VOICE_DATA_BIT; \ - } \ - vptr->VoiceSerial <<= 1; \ - } \ - vptr->VoiceLatch ^= VOICE_CLOCK_BIT; \ - PORTA_LCD_DAT = vptr->VoiceLatch; /* Latch data set */ \ - PORTB &= ~(1<VoiceCounter == 0 ) { \ - vptr->VoiceState = V_WAIT_BUSY_ON; \ - vptr->VoiceTimer = 5; /* 50 mS */ \ - } \ - } \ - } \ - } - -#define I18N_PLAY_FUNCTION(lng, x, ...) void x(__VA_ARGS__) -#define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__) -#define PUSH_CUSTOM_PROMPT(p, ...) pushCustomPrompt((p)) -#define PUSH_NUMBER_PROMPT(p) pushNumberPrompt((p)) -#define PUSH_SYSTEM_PROMPT(p) pushNumberPrompt(PROMPT_SYSTEM_BASE-PROMPT_I18N_BASE+(p)) -#define PLAY_NUMBER(n, u, a) playNumber((n), (u), (a)) -#define PLAY_DURATION(d, att) playDuration((d)) -#define PLAY_DURATION_ATT -#define PLAY_TIME -#define IS_PLAY_TIME() (0) -#define IS_PLAYING(id) (0) /* isPlaying() */ -#define PLAY_VALUE(v, id) playValue((v)) diff --git a/radio/src/targets/common/avr/CMakeLists.txt b/radio/src/targets/common/avr/CMakeLists.txt deleted file mode 100644 index d94bac83f..000000000 --- a/radio/src/targets/common/avr/CMakeLists.txt +++ /dev/null @@ -1,144 +0,0 @@ -option(AUDIO "Audio support" OFF) -set(VOICE "OFF" CACHE STRING "Voice support (OFF/ON/WTV20/JQ6500)") -option(GRAPHICS "Additional graphics" ON) -option(BOLD "Bold font" ON) -option(BATTGRAPH "Battery graph" OFF) -option(HAPTIC "Haptic support" OFF) - -set(TELEMETRY_TYPES NONE MAVLINK ARDUPILOT FRSKY FRSKY_SPORT TELEMETREZ NMEA) -set(TELEMETRY "NONE" CACHE STRING "Telemetry Type (${TELEMETRY_TYPES})") -set_property(CACHE TELEMETRY PROPERTY STRINGS ${TELEMETRY_TYPES}) - -set(TTS "EN" CACHE STRING "TTS language, one of: ${TTS_LANGUAGES}") -set_property(CACHE TTS PROPERTY STRINGS ${TTS_LANGUAGES}) - -set(LCD_TYPES DEFAULT ST7565P ST7565R ERC12864FSF ST7920 KS108) -set(LCD "DEFAULT" CACHE STRING "LCD type (${LCD_TYPES})") -set_property(CACHE LCD PROPERTY STRINGS ${LCD_TYPES}) - -set(DSM2 "NO" CACHE STRING "DSM2 support/interface (NO/PPM/SERIAL)") -set_property(CACHE DSM2 PROPERTY STRINGS NO PPM SERIAL) - -set(LUA NO) -set(PULSES_SRC pulses_avr.cpp) -set(SRC ${SRC} main_avr.cpp) -set(FIRMWARE_SRC - ${FIRMWARE_SRC} - targets/common/avr/adc_driver.cpp - targets/common/avr/eeprom_driver.cpp - ) -add_definitions(-DLCD_${LCD}) -if(DSM2) - add_definitions(-DDSM2 -DDSM2_${DSM2}) -endif() -if(SDCARD) - set(FIRMWARE_SRC ${FIRMWARE_SRC} targets/gruvin9x/diskio.cpp) -endif() -if(AUDIO) - add_definitions(-DAUDIO) - set(SRC ${SRC} audio_avr.cpp) - set(BUZZER OFF) -else() - set(BUZZER ON) -endif() -if(BUZZER) - add_definitions(-DBUZZER) - set(SRC ${SRC} buzzer.cpp) -endif() -if((VOICE STREQUAL ON AND NOT PCB STREQUAL MEGA2560) OR ((VOICE STREQUAL WTV20 OR VOICE STREQUAL JQ6500) AND (PCB STREQUAL MEGA2560))) - add_definitions(-DVOICE) - if(PCB STREQUAL MEGA2560) - add_definitions(-DVOICE_${VOICE}) - endif() - set(TARGET_SRC ${TARGET_SRC} voice.cpp) - foreach(LANGUAGE ${TTS_LANGUAGES}) - string(TOUPPER ${LANGUAGE} LANGUAGE_CAPITALIZED) - if(TTS STREQUAL ${LANGUAGE_CAPITALIZED}) - add_definitions(-DTTS_${LANGUAGE_CAPITALIZED}) - set(SRC ${SRC} translations/tts_${LANGUAGE}.cpp) - endif() - endforeach() -endif() -if(GRAPHICS) - add_definitions(-DGRAPHICS) -endif() -if(BOLD) - add_definitions(-DBOLD_FONT) -endif() -if(BATTGRAPH) - add_definitions(-DBATTGRAPH) -endif() -if(HAPTIC) - add_definitions(-DHAPTIC) - set(SRC ${SRC} haptic.cpp) -endif() -if(${TELEMETRY} STREQUAL OFF) - add_definitions(-DTELEMETRY_NONE) -elseif(TELEMETRY STREQUAL ARDUPILOT) - add_definitions(-DTELEMETRY_ARDUPILOT) - set(SRC ${SRC} telemetry/ardupilot.cpp) -elseif(TELEMETRY STREQUAL NMEA) - add_definitions(-DTELEMETRY_NMEA) - set(SRC ${SRC} telemetry/nmea.cpp) -elseif(TELEMETRY STREQUAL JETI) - add_definitions(-DTELEMETRY_JETI) - set(SRC ${SRC} telemetry/jeti.cpp) -elseif(TELEMETRY STREQUAL MAVLINK) - add_definitions(-DTELEMETRY_MAVLINK) - include_directories(${THIRDPARTY_DIR} gui/${GUI_DIR} targets/common/avr) - if(NOT EXISTS ${THIRDPARTY_DIR}/GCS_MAVLink/include_v1.0/mavlink_types.h) - message(WARNING "Warning: ${THIRDPARTY_DIR}/GCS_MAVLink/include_v1.0 is empty, trying to clone submodules") - execute_process(COMMAND git submodule update --init - RESULT_VARIABLE GIT_SUBMODULE_RESULT - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - if(NOT ${GIT_SUBMODULE_RESULT} EQUAL 0) - message(FATAL_ERROR "Error: Cannot clone submodule at ${THIRDPARTY_DIR}/GCS_MAVLink/include_v1.0 -If you downloaded this project as a ZIP file, please instead run -'git clone --recursive https://github.com/opentx/opentx.git'") - endif() - endif() - set(FIRMWARE_SRC - ${FIRMWARE_SRC} - targets/common/avr/telemetry_driver.cpp - ) - set(SRC ${SRC} telemetry/mavlink.cpp) - set(GUI_SRC ${GUI_SRC} view_mavlink.cpp) - math(EXPR EEPROM_VARIANT ${EEPROM_VARIANT}+${MAVLINK_VARIANT}) -elseif(TELEMETRY STREQUAL TELEMETREZ) - add_definitions(-DTELEMETRY_TELEMETREZ) -elseif(TELEMETRY STREQUAL FRSKY_SPORT) - add_definitions(-DTELEMETRY_FRSKY_SPORT) - set(SRC ${SRC} crc16.cpp telemetry/frsky_sport.cpp) -endif() -if(TELEMETRY STREQUAL FRSKY OR TELEMETRY STREQUAL FRSKY_SPORT OR TELEMETRY STREQUAL TELEMETREZ) - option(FRSKY_HUB "FrSky Hub support" ON) - option(WS_HOW_HIGH "Winged Shadow sensors support" ON) - option(GAUGES "Telemetry gauges" OFF) - option(GPS "GPS support" ON) - option(VARIO "Vario support" ON) - add_definitions(-DTELEMETRY_FRSKY) - set(SRC ${SRC} telemetry/telemetry.cpp telemetry/telemetry_holders.cpp telemetry/frsky.cpp telemetry/frsky_d.cpp) - set(FIRMWARE_SRC - ${FIRMWARE_SRC} - targets/common/avr/telemetry_driver.cpp - ) - set(GUI_SRC ${GUI_SRC} view_telemetry.cpp) - if(FRSKY_HUB) - add_definitions(-DFRSKY_HUB) - endif() - if(WS_HOW_HIGH) - add_definitions(-DWS_HOW_HIGH) - endif() - if(GAUGES) - add_definitions(-DGAUGES) - endif() - if(GPS) - add_definitions(-DGPS) - endif() - if(VARIO) - add_definitions(-DVARIO) - set(SRC ${SRC} vario.cpp) - endif() - math(EXPR EEPROM_VARIANT ${EEPROM_VARIANT}+${FRSKY_VARIANT}) -endif() -add_definitions(-DTIMERS=2) diff --git a/radio/src/targets/common/avr/adc_driver.cpp b/radio/src/targets/common/avr/adc_driver.cpp deleted file mode 100644 index d8091bec4..000000000 --- a/radio/src/targets/common/avr/adc_driver.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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" - -#define ADC_VREF_TYPE (1 << REFS0) // AVCC with external capacitor at AREF pin - -void adcInit() -{ - ADMUX = ADC_VREF_TYPE; - ADCSRA = 0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering) -#if defined(CPUM2560) - ADCSRB = (1 << MUX5); -#endif -} - -void adcPrepareBandgap() -{ - // #if structure identical to the one in getADC_bandgap() -#if defined(PCBGRUVIN9X) - // For PCB V4, use our own 1.2V, external reference (connected to ADC3) - ADCSRB &= ~(1< -#include -#include "pgmtypes.h" -#include -#include -#include -#define F_CPU 16000000UL // 16 MHz -#include -#define pgm_read_adr(address_short) pgm_read_word(address_short) -#include -#endif - -// ADC driver -#define NUM_POTS 3 -#define NUM_SLIDERS 0 -#define NUM_XPOTS 0 - -enum Analogs { - STICK1, - STICK2, - STICK3, - STICK4, - POT_FIRST, - POT1 = POT_FIRST, - POT2, - POT3, - POT_LAST = POT3, -#if defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED) - // When the mod is applied, ADC7 is connected to 14051's X pin and TX_VOLTAGE - // is connected to 14051's X0 pin (one of the multiplexed inputs). TX_VOLTAGE - // value is filled in by processMultiplexAna(). - - // This shifts TX_VOLTAGE from 7 to 8 and makes X14051 take the 7th position - // corresponding to ADC7. - X14051, -#endif - TX_VOLTAGE, - NUM_ANALOGS -}; - -enum CalibratedAnalogs { - CALIBRATED_STICK1, - CALIBRATED_STICK2, - CALIBRATED_STICK3, - CALIBRATED_STICK4, - CALIBRATED_POT_FIRST, - CALIBRATED_POT1 = CALIBRATED_POT_FIRST, - CALIBRATED_POT2, - CALIBRATED_POT3, - CALIBRATED_POT_LAST = CALIBRATED_POT3, - NUM_CALIBRATED_ANALOGS -}; - -void adcInit(); -void adcPrepareBandgap(); -void getADC(); -void getADC_bandgap(); - -// Keys driver -#define NUM_SWITCHES 7 -enum EnumKeys -{ - KEY_MENU, - KEY_ENTER=KEY_MENU, - KEY_EXIT, - KEY_DOWN, - KEY_MINUS = KEY_DOWN, - KEY_UP, - KEY_PLUS = KEY_UP, - KEY_RIGHT, - KEY_LEFT, - - TRM_BASE, - TRM_LH_DWN = TRM_BASE, - TRM_LH_UP, - TRM_LV_DWN, - TRM_LV_UP, - TRM_RV_DWN, - TRM_RV_UP, - TRM_RH_DWN, - TRM_RH_UP, - TRM_LAST = TRM_RH_UP, - -#if ROTARY_ENCODERS > 0 || defined(ROTARY_ENCODER_NAVIGATION) - BTN_REa, -#endif -#if ROTARY_ENCODERS > 0 - BTN_REb, -#endif - - NUM_KEYS -}; - -enum EnumSwitches -{ - SW_ID0, - SW_ID1, - SW_ID2, - SW_THR, - SW_RUD, - SW_ELE, - SW_AIL, - SW_GEA, - SW_TRN, -}; -#define IS_3POS(sw) ((sw) == 0) -#define IS_TOGGLE(sw) ((sw) == SWSRC_TRN) -uint8_t keyState(uint8_t index); -uint8_t switchState(uint8_t index); - -// LCD driver -#define LCD_W 128 -#define LCD_H 64 -#define LCD_DEPTH 1 -#define LCD_CONTRAST_MIN 10 -#define LCD_CONTRAST_MAX 45 -#define LCD_CONTRAST_DEFAULT 25 -void lcdRefresh(void); -#define lcdRefreshWait() -void lcdSetRefVolt(unsigned char val); -void lcdSetContrast(void); -void lcdInit(void); -#define lcdOff() - -#if defined(LCD_KS108) -void lcdRefreshSide(); -#endif - -#if defined(LCD_ST7920) -uint8_t lcdRefresh_ST7920(uint8_t full); -#endif - -// EEPROM driver -#if defined(CPUM2560) || defined(CPUM2561) || defined(CPUM128) - #define EEPROM_SIZE 4096 -#else - #define EEPROM_SIZE 2048 -#endif -#if defined(SIMU) -void eepromReadBlock(uint8_t * buffer, size_t address, size_t size); -#else -#define eepromReadBlock(buffer, address, size) eeprom_read_block(buffer, (const void *)address, size) -#endif -uint8_t eepromIsTransferComplete(); - -// USART driver (static register dispatcher) -#define RXD_DDR1 DDRD -#define RXD_DDR_PIN1 DDD2 -#define RXD_PORT1 PORTD -#define RXD_PORT_PIN1 PORTD2 -#define RXD_DDR0 DDRE -#define RXD_DDR_PIN0 DDE0 -#define RXD_PORT0 PORTE -#define RXD_PORT_PIN0 PORTE0 - -#define _DOR_N(usart_no) DOR ## usart_no -#define _FE_N(usart_no) FE ## usart_no -#define _RXCIE_N(usart_no) RXCIE ## usart_no -#define _RXC_N(usart_no) RXC ## usart_no -#define _RXD_DDR_N(usart_no) RXD_DDR ## usart_no -#define _RXD_DDR_PIN_N(usart_no) RXD_DDR ## usart_no -#define _RXD_PORT_N(usart_no) RXD_DDR ## usart_no -#define _RXD_PORT_PIN_N(usart_no) RXD_DDR ## usart_no -#define _RXEN_N(usart_no) RXEN ## usart_no -#define _TXCIE_N(usart_no) TXCIE ## usart_no -#define _TXEN_N(usart_no) TXEN ## usart_no -#define _U2X_N(usart_no) U2X ## usart_no -#define _UBRRH_N(usart_no) UBRR ## usart_no ## H -#define _UBRRL_N(usart_no) UBRR ## usart_no ## L -#define _UCSRA_N(usart_no) UCSR ## usart_no ## A -#define _UCSRB_N(usart_no) UCSR ## usart_no ## B -#define _UCSRC_N(usart_no) UCSR ## usart_no ## C -#define _UCSZ0_N(usart_no) UCSZ ## usart_no ## 0 -#define _UCSZ1_N(usart_no) UCSZ ## usart_no ## 1 -#define _UCSZ2_N(usart_no) UCSZ ## usart_no ## 2 -#define _UDRIE_N(usart_no) UDRIE ## usart_no -#define _UDR_N(usart_no) UDR ## usart_no -#define _UPE_N(usart_no) UPE ## usart_no -#define _USART_RX_vect_N(usart_no) USART ## usart_no ## _RX_vect -#define _USART_UDRE_vect_N(usart_no) USART ## usart_no ## _UDRE_vect - -#define DOR_N(usart_no) _DOR_N(usart_no) -#define FE_N(usart_no) _FE_N(usart_no) -#define RXCIE_N(usart_no) _RXCIE_N(usart_no) -#define RXC_N(usart_no) _RXC_N(usart_no) -#define RXD_DDR_N(usart_no) _RXD_DDR_N(usart_no) -#define RXD_DDR_PIN_N(usart_no) _RXD_DDR_PIN_N(usart_no) -#define RXD_PORT_N(usart_no) _RXD_PORT_N(usart_no) -#define RXD_PORT_PIN_N(usart_no) _RXD_PORT_PIN_N(usart_no) -#define RXEN_N(usart_no) _RXEN_N(usart_no) -#define TXCIE_N(usart_no) _TXCIE_N(usart_no) -#define TXEN_N(usart_no) _TXEN_N(usart_no) -#define U2X_N(usart_no) _U2X_N(usart_no) -#define UBRRH_N(usart_no) _UBRRH_N(usart_no) -#define UBRRL_N(usart_no) _UBRRL_N(usart_no) -#define UCSRA_N(usart_no) _UCSRA_N(usart_no) -#define UCSRB_N(usart_no) _UCSRB_N(usart_no) -#define UCSRC_N(usart_no) _UCSRC_N(usart_no) -#define UCSZ0_N(usart_no) _UCSZ0_N(usart_no) -#define UCSZ1_N(usart_no) _UCSZ1_N(usart_no) -#define UCSZ2_N(usart_no) _UCSZ2_N(usart_no) -#define UDRIE_N(usart_no) _UDRIE_N(usart_no) -#define UDR_N(usart_no) _UDR_N(usart_no) -#define UPE_N(usart_no) _UPE_N(usart_no) -#define USART_RX_vect_N(usart_no) _USART_RX_vect_N(usart_no) -#define USART_UDRE_vect_N(usart_no) _USART_UDRE_vect_N(usart_no) - -// Telemetry driver -#if defined(TELEMETRY_MOD_14051_SWAPPED) -#define TLM_USART 1 -#else -#define TLM_USART 0 -#endif -void telemetryPortInit(); -void telemetryPortInit(uint8_t baudrate); -void telemetryTransmitBuffer(); diff --git a/radio/src/targets/common/avr/eeprom_driver.cpp b/radio/src/targets/common/avr/eeprom_driver.cpp deleted file mode 100644 index c803255dd..000000000 --- a/radio/src/targets/common/avr/eeprom_driver.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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" - -uint16_t eeprom_pointer; -uint8_t * eeprom_buffer_data; -volatile int8_t eeprom_buffer_size = 0; - -inline void eeprom_write_byte() -{ - EEAR = eeprom_pointer; - EEDR = *eeprom_buffer_data; -// TODO add some define here -#if defined (CPUM2560) || defined(CPUM2561) - EECR |= 1< 0) { - eeprom_write_byte(); - } - else { -#if defined(CPUM2560) || defined(CPUM2561) - EECR &= ~(1< - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -FORCEINLINE void uart_9600(void) -{ - #undef BAUD - #define BAUD 9600 - #include - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -static void uart_14400(void) -{ - #undef BAUD - #define BAUD 14400 - #include - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -static void uart_19200(void) -{ - #undef BAUD - #define BAUD 19200 - #include - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -static void uart_38400(void) -{ - #undef BAUD - #define BAUD 38400 - #include - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -static void uart_57600(void) -{ - #undef BAUD - #define BAUD 57600 - #include - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -static void uart_58798(void) -{ - UBRRH_N(TLM_USART) = 0; - UBRRL_N(TLM_USART) = 0x010; - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -} - -static void uart_76800(void) -{ - #undef BAUD - #define BAUD 76800 - #include - UBRRH_N(TLM_USART) = UBRRH_VALUE; - UBRRL_N(TLM_USART) = UBRRL_VALUE; -#if defined USE_2X - UCSRA_N(TLM_USART) |= (1 << U2X_N(TLM_USART)); // enable double speed operation. -#else - UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation. -#endif -} - -#if !defined(SIMU) -FORCEINLINE void telemetryPortInit(uint8_t baudrate) -{ - RXD_DDR_N(TLM_USART) &= ~(1 << RXD_DDR_PIN_N(TLM_USART)); // set RXD pin as input - RXD_PORT_N(TLM_USART) &= ~(1 << RXD_PORT_PIN_N(TLM_USART)); // disable pullup on RXD pin - switch (baudrate) { - case BAUD_4800: - uart_4800(); - break; - case BAUD_9600: - uart_9600(); - break; - case BAUD_14400: - uart_14400(); - break; - case BAUD_19200: - uart_19200(); - break; - case BAUD_38400: - uart_38400(); - break; - case BAUD_58798: - uart_58798(); - break; - case BAUD_76800: - uart_76800(); - break; - default: - uart_57600(); - break; - } - - // set 8N1 - UCSRB_N(TLM_USART) = 0 | (0 << RXCIE_N(TLM_USART)) | (0 << TXCIE_N(TLM_USART)) | (0 << UDRIE_N(TLM_USART)) | (0 << RXEN_N(TLM_USART)) | (0 << TXEN_N(TLM_USART)) | (0 << UCSZ2_N(TLM_USART)); - UCSRC_N(TLM_USART) = 0 | (1 << UCSZ1_N(TLM_USART)) | (1 << UCSZ0_N(TLM_USART)); - - while (UCSRA_N(TLM_USART) & (1 << RXC_N(TLM_USART))) UDR_N(TLM_USART); // flush receive buffer - - // These should be running right from power up on a FrSky enabled '9X. -#if defined(TELEMETRY_FRSKY) - telemetryEnableTx(); // enable FrSky-Telemetry emission -#endif - telemetryEnableRx(); // enable FrSky-Telemetry reception -} -#endif - -void telemetryTransmitBuffer() -{ - UCSRB_N(TLM_USART) |= (1 << UDRIE_N(TLM_USART)); // enable UDRE1 interrupt -} - -void telemetryPortInit() -{ - telemetryPortInit(BAUD_9600); -} - -#endif diff --git a/radio/src/targets/gruvin9x/CMakeLists.txt b/radio/src/targets/gruvin9x/CMakeLists.txt deleted file mode 100644 index 158cba68f..000000000 --- a/radio/src/targets/gruvin9x/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -set(ARCH AVR) -set(MCU atmega2560) -set(AVRDUDE_MCU m2560) -string(TOLOWER ${PCB} FLAVOUR) -set(EEPROM EEPROM_RLC) -add_definitions(-DEEPROM_VARIANT=0) -set(SDCARD NO) -set(GUI_DIR 128x64) -set(TARGET_DIR gruvin9x) -set(FIRMWARE_DEPENDENCIES ${FIRMWARE_DEPENDENCIES} 9x_bitmaps) -add_definitions(-DPCB${PCB} -DCPUM2560 -DROTARY_ENCODERS=2) -set(TARGET_SRC ${TARGET_SRC} board.cpp) -set(GUI_SRC - ${GUI_SRC} - model_inputs_mixes.cpp - radio_diagkeys.cpp - radio_diaganas.cpp - ) -set(FIRMWARE_SRC ${FIRMWARE_SRC} targets/9x/lcd_driver.cpp) diff --git a/radio/src/targets/gruvin9x/board.cpp b/radio/src/targets/gruvin9x/board.cpp deleted file mode 100644 index 125824c1c..000000000 --- a/radio/src/targets/gruvin9x/board.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * 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" - -void boardInit() -{ -#if !defined(SIMU) - // Set up I/O port data directions and initial states - DDRA = 0xff; PORTA = 0x00; // LCD data - DDRB = 0b11000111; PORTB = 0b00111111; // 7:SPKR, 6:PPM_OUT, 5:TrainSW, 4:IDL2_SW, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS] - DDRC = 0x3f; PORTC = 0xc0; // 7:AilDR, 6:EleDR, LCD[5,4,3,2,1], 0:BackLight - 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 = 0x00; PORTF = 0x00; // 7-4:JTAG, 3:ADC_REF_1.2V input, 2-0:ADC_SPARE_2-0 - DDRG = 0b00010000; PORTG = 0xff; // 7-6:N/A, 5:GearSW, 4: Sim_Ctrl[out], 3:IDL1_Sw, 2:TCut_Sw, 1:RF_Power[in], 0: RudDr_Sw - -#if defined(DEBUG) && !defined(VOICE) - DDRH = 0b11111000; PORTH = 0b11010111; // PORTH:7-6 enabled for timing analysis output ... see below ... -#else - 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] -#endif - - DDRJ = 0x00; PORTJ = 0xff; // 7-0:Trim switch inputs - DDRK = 0x00; PORTK = 0x00; // anain. No pull-ups! -#ifdef REV0 - DDRL = 0x80; PORTL = 0x7f; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: User Button inputs -#else - DDRL = 0x80; PORTL = 0xff; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: User Button inputs -#endif - - adcInit(); - - /**** 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< 2 - EIMSK = (3< 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< 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); - } 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 - -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 -} - -uint8_t keyDown() -{ - return ((~PINL) & 0x3F) || ROTENC_DOWN(); -} - -uint8_t keyState(uint8_t index) -{ - return keys[index].state(); -} - -uint8_t switchState(uint8_t index) -{ - uint8_t result = 0; - - switch (index) { - case SW_ELE: - result = PINC & (1<> 3; - for (int i=1; i<7; i++) { - keys[index].input(in & (1< 0 && delta < MAX_MIXER_DELTA) return; - - nextMixerEndTime = t0 + MAX_MIXER_DELTA; - - doMixerCalculations(); - - t0 = getTmr16KHz() - t0; - lastMixerDuration = t0; - if (t0 > maxMixerDuration) maxMixerDuration = t0; -} - -#define loop_mixer_until_bit_is_set(sfr, bit) do { checkMixer(); wdt_reset(); } while (bit_is_clear(sfr, bit)) -#endif - -/*-----------------------------------------------------------------------*/ -/* Transmit a byte to MMC via SPI (Platform dependent) */ -/*-----------------------------------------------------------------------*/ - -#define xmit_spi(dat) SPDR=(dat); loop_mixer_until_bit_is_set(SPSR,SPIF) - - - -/*-----------------------------------------------------------------------*/ -/* Receive a byte from MMC via SPI (Platform dependent) */ -/*-----------------------------------------------------------------------*/ - -static -BYTE rcvr_spi (void) -{ - SPDR = 0xFF; - loop_mixer_until_bit_is_set(SPSR, SPIF); - return SPDR; -} - -/* Alternative macro to receive data fast */ -#define rcvr_spi_m(dst) SPDR=0xFF; loop_mixer_until_bit_is_set(SPSR,SPIF); *(dst)=SPDR - - - -/*-----------------------------------------------------------------------*/ -/* Wait for card ready */ -/*-----------------------------------------------------------------------*/ - -static -int wait_ready (void) /* 1:OK, 0:Timeout */ -{ - Timer2 = 50; /* Wait for ready in timeout of 500ms (G: now 50x16ms) */ - rcvr_spi(); - do - if (rcvr_spi() == 0xFF) return 1; - while (Timer2); - - return 0; -} - - - -/*-----------------------------------------------------------------------*/ -/* Deselect the card and release SPI bus */ -/*-----------------------------------------------------------------------*/ - -static -void deselect (void) -{ - CS_HIGH(); - rcvr_spi(); -} - - - -/*-----------------------------------------------------------------------*/ -/* Select the card and wait for ready */ -/*-----------------------------------------------------------------------*/ - -static -int select (void) /* 1:Successful, 0:Timeout */ -{ - CS_LOW(); - if (!wait_ready()) { - deselect(); - return 0; - } - return 1; -} - - - -/*-----------------------------------------------------------------------*/ -/* Power Control (Platform dependent) */ -/*-----------------------------------------------------------------------*/ -/* When the target system does not support socket power control, there */ -/* is nothing to do in these functions and chk_power always returns 1. */ - -static -int power_status(void) /* Socket power state: 0=off, 1=on */ -{ - return (PORTE & 0x80) ? 0 : 1; -} - - -static -void power_on (void) -{ - // PORTE &= ~0x80; // Socket power on -#ifndef SIMU - for (Timer1 = 2; Timer1; ); // Wait for 20ms -#endif - //PORTB = 0b10110101; // Enable drivers - //DDRB = 0b11000111; - - SPCR = 0x52; // Enable SPI function in mode 0 - SPSR = 0x00; // G: was 0x01; // SPI 2x mode -} - - -static -void power_off (void) -{ - SPCR = 0; /* Disable SPI function */ - // DDRB = 0b11000000; /* Disable drivers */ - // PORTB = 0b10110000; - - // PORTE |= 0x80; /* Socket power off */ - Stat |= STA_NOINIT; -} - - - -/*-----------------------------------------------------------------------*/ -/* Receive a data packet from MMC */ -/*-----------------------------------------------------------------------*/ - -static -int rcvr_datablock ( - BYTE *buff, /* Data buffer to store received data */ - UINT btr /* Byte count (must be multiple of 4) */ - ) -{ - BYTE token; - - - Timer1 = 20; - do { /* Wait for data packet in timeout of 200ms */ - token = rcvr_spi(); - } while ((token == 0xFF) && Timer1); - if(token != 0xFE) return 0; /* If not valid data token, retutn with error */ - - do { /* Receive the data block into buffer */ - rcvr_spi_m(buff++); - rcvr_spi_m(buff++); - rcvr_spi_m(buff++); - rcvr_spi_m(buff++); - } while (btr -= 4); - rcvr_spi(); /* Discard CRC */ - rcvr_spi(); - - return 1; /* Return with success */ -} - - - -/*-----------------------------------------------------------------------*/ -/* Send a data packet to MMC */ -/*-----------------------------------------------------------------------*/ - -static -int xmit_datablock ( - const BYTE *buff, /* 512 byte data block to be transmitted */ - BYTE token /* Data/Stop token */ - ) -{ - BYTE resp, wc; - - - if (!wait_ready()) return 0; - - xmit_spi(token); /* Xmit data token */ - if (token != 0xFD) { /* Is data token */ - wc = 0; - do { /* Xmit the 512 byte data block to MMC */ - xmit_spi(*buff++); - xmit_spi(*buff++); - } while (--wc); - xmit_spi(0xFF); /* CRC (Dummy) */ - xmit_spi(0xFF); - resp = rcvr_spi(); /* Reveive data response */ - if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */ - return 0; - } - - return 1; -} - - - -/*-----------------------------------------------------------------------*/ -/* Send a command packet to MMC */ -/*-----------------------------------------------------------------------*/ - -static -BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */ - BYTE cmd, /* Command index */ - DWORD arg /* Argument */ - ) -{ - BYTE n, res; - - - if (cmd & 0x80) { /* ACMD is the command sequense of CMD55-CMD */ - cmd &= 0x7F; - res = send_cmd(CMD55, 0); - if (res > 1) return res; - } - - /* Select the card and wait for ready */ - deselect(); - if (!select()) return 0xFF; - - /* Send command packet */ - xmit_spi(0x40 | cmd); /* Start + Command index */ - xmit_spi((BYTE)(arg >> 24)); /* Argument[31..24] */ - xmit_spi((BYTE)(arg >> 16)); /* Argument[23..16] */ - xmit_spi((BYTE)(arg >> 8)); /* Argument[15..8] */ - xmit_spi((BYTE)arg); /* Argument[7..0] */ - n = 0x01; /* Dummy CRC + Stop */ - if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */ - if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */ - xmit_spi(n); - - /* Receive command response */ - if (cmd == CMD12) rcvr_spi(); /* Skip a stuff byte when stop reading */ - n = 10; /* Wait for a valid response in timeout of 10 attempts */ - do - res = rcvr_spi(); - while ((res & 0x80) && --n); - - return res; /* Return with the response value */ -} - - - -/*-------------------------------------------------------------------------- - - Public Functions - - ---------------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* Initialize Disk Drive */ -/*-----------------------------------------------------------------------*/ - -DSTATUS disk_initialize ( - BYTE drv /* Physical drive nmuber (0) */ - ) -{ - BYTE n, cmd, ty, ocr[4]; - - - if (drv) return STA_NOINIT; /* Supports only single drive */ - if (Stat & STA_NODISK) return Stat; /* No card in the socket */ - - power_on(); /* Force socket power on */ - FCLK_SLOW(); - for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */ - - ty = 0; - if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */ - Timer1 = 100; /* Initialization timeout of 1000 msec */ - if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2? */ - for (n = 0; n < 4; n++) ocr[n] = rcvr_spi(); /* Get trailing return value of R7 resp */ - if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */ - while (Timer1 && send_cmd(ACMD41, 1UL << 30)); /* Wait for leaving idle state (ACMD41 with HCS bit) */ - if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */ - for (n = 0; n < 4; n++) ocr[n] = rcvr_spi(); - ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 */ - } - } - } else { /* SDv1 or MMCv3 */ - if (send_cmd(ACMD41, 0) <= 1) { - ty = CT_SD1; cmd = ACMD41; /* SDv1 */ - } else { - ty = CT_MMC; cmd = CMD1; /* MMCv3 */ - } - while (Timer1 && send_cmd(cmd, 0)); /* Wait for leaving idle state */ - if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */ - ty = 0; - } - } - CardType = ty; - deselect(); - - if (ty) { /* Initialization succeded */ - Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */ - FCLK_FAST(); - } else { /* Initialization failed */ - power_off(); - } - - return Stat; -} - - - -/*-----------------------------------------------------------------------*/ -/* Get Disk Status */ -/*-----------------------------------------------------------------------*/ - -DSTATUS disk_status ( - BYTE drv /* Physical drive number (0) */ - ) -{ - if (drv) return STA_NOINIT; /* Supports only single drive */ - return Stat; -} - - - -/*-----------------------------------------------------------------------*/ -/* Read Sector(s) */ -/*-----------------------------------------------------------------------*/ - -DRESULT disk_read ( - BYTE drv, /* Physical drive nmuber (0) */ - BYTE *buff, /* Pointer to the data buffer to store read data */ - DWORD sector, /* Start sector number (LBA) */ - UINT count /* Sector count (1..255) */ - ) -{ - if (drv || !count) return RES_PARERR; - if (Stat & STA_NOINIT) return RES_NOTRDY; - - if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */ - - if (count == 1) { /* Single block read */ - if ((send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */ - && rcvr_datablock(buff, 512)) - count = 0; - } - else { /* Multiple block read */ - if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */ - do { - if (!rcvr_datablock(buff, 512)) break; - buff += 512; - } while (--count); - send_cmd(CMD12, 0); /* STOP_TRANSMISSION */ - } - } - deselect(); - - return count ? RES_ERROR : RES_OK; -} - - - -/*-----------------------------------------------------------------------*/ -/* Write Sector(s) */ -/*-----------------------------------------------------------------------*/ - -DRESULT disk_write ( - BYTE drv, /* Physical drive nmuber (0) */ - const BYTE *buff, /* Pointer to the data to be written */ - DWORD sector, /* Start sector number (LBA) */ - UINT count /* Sector count (1..255) */ - ) -{ - if (drv || !count) return RES_PARERR; - if (Stat & STA_NOINIT) return RES_NOTRDY; - if (Stat & STA_PROTECT) return RES_WRPRT; - - if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */ - - if (count == 1) { /* Single block write */ - if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */ - && xmit_datablock(buff, 0xFE)) - count = 0; - } - else { /* Multiple block write */ - if (CardType & CT_SDC) send_cmd(ACMD23, count); - if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */ - do { - if (!xmit_datablock(buff, 0xFC)) break; - buff += 512; - } while (--count); - if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */ - count = 1; - } - } - deselect(); - - return count ? RES_ERROR : RES_OK; -} - - - -/*-----------------------------------------------------------------------*/ -/* Miscellaneous Functions */ -/*-----------------------------------------------------------------------*/ - -DRESULT disk_ioctl ( - BYTE drv, /* Physical drive nmuber (0) */ - BYTE ctrl, /* Control code */ - void *buff /* Buffer to send/receive control data */ - ) -{ - DRESULT res; - BYTE n, csd[16], *ptr = (BYTE*)buff; - WORD csize; - - - if (drv) return RES_PARERR; - - res = RES_ERROR; - - if (ctrl == CTRL_POWER) { - switch (ptr[0]) { - case 0: /* Sub control code (POWER_OFF) */ - power_off(); /* Power off */ - res = RES_OK; - break; - case 1: /* Sub control code (POWER_GET) */ - ptr[1] = (BYTE)power_status(); - res = RES_OK; - break; - default : - res = RES_PARERR; - } - } - else { - if (Stat & STA_NOINIT) return RES_NOTRDY; - - switch (ctrl) { - case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */ - if (select()) { - deselect(); - res = RES_OK; - } - break; - - case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */ - if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { - if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */ - csize = csd[9] + ((WORD)csd[8] << 8) + 1; - *(DWORD*)buff = (DWORD)csize << 10; - } else { /* SDC ver 1.XX or MMC*/ - n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2; - csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1; - *(DWORD*)buff = (DWORD)csize << (n - 9); - } - res = RES_OK; - } - break; - - case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */ - *(WORD*)buff = 512; - res = RES_OK; - break; - - case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */ - if (CardType & CT_SD2) { /* SDv2? */ - if (send_cmd(ACMD13, 0) == 0) { /* Read SD status */ - rcvr_spi(); - if (rcvr_datablock(csd, 16)) { /* Read partial block */ - for (n = 64 - 16; n; n--) rcvr_spi(); /* Purge trailing data */ - *(DWORD*)buff = 16UL << (csd[10] >> 4); - res = RES_OK; - } - } - } else { /* SDv1 or MMCv3 */ - if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { /* Read CSD */ - if (CardType & CT_SD1) { /* SDv1 */ - *(DWORD*)buff = (((csd[10] & 63) << 1) + ((WORD)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1); - } else { /* MMCv3 */ - *(DWORD*)buff = ((WORD)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1); - } - res = RES_OK; - } - } - break; - - case MMC_GET_TYPE : /* Get card type flags (1 byte) */ - *ptr = CardType; - res = RES_OK; - break; - - case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */ - if (send_cmd(CMD9, 0) == 0 /* READ_CSD */ - && rcvr_datablock(ptr, 16)) - res = RES_OK; - break; - - case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */ - if (send_cmd(CMD10, 0) == 0 /* READ_CID */ - && rcvr_datablock(ptr, 16)) - res = RES_OK; - break; - - case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */ - if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */ - for (n = 4; n; n--) *ptr++ = rcvr_spi(); - res = RES_OK; - } - break; - - case MMC_GET_SDSTAT : /* Receive SD statsu as a data block (64 bytes) */ - if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */ - rcvr_spi(); - if (rcvr_datablock(ptr, 64)) - res = RES_OK; - } - break; - - default: - res = RES_PARERR; - } - - deselect(); - } - - return res; -} - - - -/*-----------------------------------------------------------------------*/ -/* Device Timer Interrupt Procedure */ -/*-----------------------------------------------------------------------*/ -/* This function must be called in period of 10ms */ - -void sdPoll10ms() -{ - BYTE s; - - /* - n = Timer1; // 100Hz decrement timer - if (n) Timer1 = --n; - n = Timer2; - if (n) Timer2 = --n; - */ - if (Timer1) Timer1--; - if (Timer2) Timer2--; - - s = Stat; - - /* G: Not implemented - if (SOCKWP) // Write protected - s |= STA_PROTECT; - else // Write enabled - s &= ~STA_PROTECT; - if (SOCKINS) // Card inserted - s &= ~STA_NODISK; - else // Socket empty - s |= (STA_NODISK | STA_NOINIT); - */ - s &= ~STA_NODISK; - s &= ~STA_PROTECT; - - Stat = s; -} - -#if !defined(SIMU) -bool sdMounted() -{ - return g_FATFS_Obj.fs_type != 0; -} - -void sdMountPoll() -{ - static uint8_t mountTimer; - if (mountTimer-- == 0) { - mountTimer = 100; - if (!sdMounted()) { - f_mount(&g_FATFS_Obj, "", 1); - f_chdir(ROOT_PATH); - } - } -} -#endif - -FATFS g_FATFS_Obj; diff --git a/radio/src/targets/gruvin9x/fuses_2561.txt b/radio/src/targets/gruvin9x/fuses_2561.txt deleted file mode 100644 index 0c1417a63..000000000 --- a/radio/src/targets/gruvin9x/fuses_2561.txt +++ /dev/null @@ -1,36 +0,0 @@ -The ATmega2561 uses quite different bit assignment for its option fuses - - -Fuse defaults for ATmega64A - -Default values for ATmega64 are: - hfuse = 0b10011001 (0x99) - lfuse = 0b11100001 (0xE1) - efuse = 0b11111101 (0xFD) - -Preferred values for ATmega64A are: - hfuse = 0x11 - lfuse = 0x1F - efuse = 0xff - -... which includes EESAVE feature, so that the EEPROM model data does NOT get -erased during chip erase prior to re-programming ... respectively. - -- - - - - - - - - - - - - - - - - - - - - - - -Fuse defaults for ATmega2560/1 are: - - hfuse = 0b10011001 (0x99) - lfuse = 0b01100010 (0x62) - efuse = 0b11111111 (0xFF) - -The bit assignments ae quite different from the AT'64A in all cases. - -Preferred vale es for ATmega2560/1 are: - hfuse = 0b10011001 (0x11) [OCD enabled, JTAG enabled, WDT disabled :(, - EESAVE enabled, BOOT at 0x0000] - lfuse = 0b01101110 (0xd7) [CKDIV8 disabled, CKOUT disabled, - Full Swing Xtal Osc, 16K CK + 0ms reset, - BOD enabled] - efuse = 0b11111111 (0xfc) [ Brown out detector (BOD) = 4.3V ] - diff --git a/radio/src/targets/gruvin9x/rtc_driver.cpp b/radio/src/targets/gruvin9x/rtc_driver.cpp deleted file mode 100644 index 7066a59af..000000000 --- a/radio/src/targets/gruvin9x/rtc_driver.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* - * 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. - */ - -/*--------------------------------------------------------------------------*/ -/* 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; - -#define SCL_LOW() DDRD |= 0x01 /* SCL = LOW */ -#define SCL_HIGH() DDRD &= ~0x01 /* SCL = High-Z */ -#define SCL_VAL ((PIND & 0x01) ? 1 : 0) /* SCL input level */ -#define SDA_LOW() DDRD |= 0x02 /* SDA = LOW */ -#define SDA_HIGH() DDRD &= ~0x02 /* SDA = High-Z */ -#define SDA_VAL ((PIND & 0x02) ? 1 : 0) /* SDA input level */ - -/*-------------------------------------------------*/ -/* I2C bus protocol */ - -static -void iic_delay (void) -{ -#ifndef SIMU - for (int n = 4; n; n--) PINB; -#endif -} - - -/* Generate start condition on the IIC bus */ -static -void iic_start (void) -{ - SDA_HIGH(); - iic_delay(); - SCL_HIGH(); - iic_delay(); - SDA_LOW(); - iic_delay(); - SCL_LOW(); - iic_delay(); -} - - -/* Generate stop condition on the IIC bus */ -static -void iic_stop (void) -{ - SDA_LOW(); - iic_delay(); - SCL_HIGH(); - iic_delay(); - SDA_HIGH(); - iic_delay(); -} - - -/* Send a byte to the IIC bus */ -static -int iic_send (BYTE dat) -{ - BYTE b = 0x80; - int ack; - - - do { - if (dat & b) { /* SDA = Z/L */ - SDA_HIGH(); - } else { - SDA_LOW(); - } - iic_delay(); - SCL_HIGH(); - iic_delay(); - SCL_LOW(); - iic_delay(); - } while (b >>= 1); - SDA_HIGH(); - iic_delay(); - SCL_HIGH(); - ack = SDA_VAL ? 0 : 1; /* Sample ACK */ - iic_delay(); - SCL_LOW(); - iic_delay(); - return ack; -} - - -/* Receive a byte from the IIC bus */ -static -BYTE iic_rcvr (int ack) -{ - UINT d = 1; - - - do { - d <<= 1; - SCL_HIGH(); - if (SDA_VAL) d++; - iic_delay(); - SCL_LOW(); - iic_delay(); - } while (d < 0x100); - if (ack) { /* SDA = ACK */ - SDA_LOW(); - } else { - SDA_HIGH(); - } - iic_delay(); - SCL_HIGH(); - iic_delay(); - SCL_LOW(); - SDA_HIGH(); - iic_delay(); - - return (BYTE)d; -} - - - -/*-------------------------------------------------*/ -/* I2C block read/write controls */ - - -int iic_read ( - BYTE dev, /* Device address */ - UINT adr, /* Read start address */ - UINT cnt, /* Read byte count */ - BYTE *buff /* Read data buffer */ -) -{ - BYTE *rbuff = buff; - int n; - - - if (!cnt) return 0; - - n = 10; - do { /* Select device */ - iic_start(); - } while (!iic_send(dev) && --n); - if (n) { - if (iic_send((BYTE)adr)) { /* Set start address */ - iic_start(); /* Reselect device in read mode */ - if (iic_send(dev | 1)) { - do { /* Receive data */ - cnt--; - *rbuff++ = iic_rcvr(cnt ? 1 : 0); - } while (cnt); - } - } - } - - iic_stop(); /* Deselect device */ - - return cnt ? 0 : 1; -} - - - -int iic_write ( - BYTE dev, /* Device address */ - UINT adr, /* Write start address */ - UINT cnt, /* Write byte count */ - const BYTE *buff /* Data to be written */ -) -{ - const BYTE *wbuff = buff; - int n; - - - if (!cnt) return 0; - - n = 10; - do { /* Select device */ - iic_start(); - } while (!iic_send(dev) && --n); - if (n) { - if (iic_send((BYTE)adr)) { /* Set start address */ - do { /* Send data */ - if (!iic_send(*wbuff++)) break; - } while (--cnt); - } - } - - iic_stop(); /* Deselect device */ - - return cnt ? 0 : 1; -} - -/*-------------------------------------------------*/ -/* RTC functions */ - -int g9x_rtcGetTime (RTC *rtc) -{ - BYTE buf[8]; - - if (!iic_read(0xD0, 0, 7, buf)) return 0; - - rtc->sec = (buf[0] & 0x0F) + ((buf[0] >> 4) & 7) * 10; - rtc->min = (buf[1] & 0x0F) + (buf[1] >> 4) * 10; - rtc->hour = (buf[2] & 0x0F) + ((buf[2] >> 4) & 3) * 10; - rtc->wday = (buf[2] & 0x07); - rtc->mday = (buf[4] & 0x0F) + ((buf[4] >> 4) & 3) * 10; - rtc->month = (buf[5] & 0x0F) + ((buf[5] >> 4) & 1) * 10; - rtc->year = 2000 + (buf[6] & 0x0F) + (buf[6] >> 4) * 10; - - return 1; -} - -int g9x_rtcSetTime (const RTC *rtc) -{ - BYTE buf[8]; - - buf[0] = rtc->sec / 10 * 16 + rtc->sec % 10; - buf[1] = rtc->min / 10 * 16 + rtc->min % 10; - buf[2] = rtc->hour / 10 * 16 + rtc->hour % 10; - buf[3] = rtc->wday & 7; - buf[4] = rtc->mday / 10 * 16 + rtc->mday % 10; - buf[5] = rtc->month / 10 * 16 + rtc->month % 10; - buf[6] = (rtc->year - 2000) / 10 * 16 + (rtc->year - 2000) % 10; - return iic_write(0xD0, 0, 7, buf); -} - -void rtcGetTime(struct gtm * utm) -{ - RTC rtc = {0,0,0,0,0,0,0}; - - g9x_rtcGetTime(&rtc); - - utm->tm_year = rtc.year - TM_YEAR_BASE; - 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(const struct gtm * t) -{ - g_ms100 = 0; // start of next second begins now - - RTC rtc; - rtc.year = t->tm_year + TM_YEAR_BASE; - 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); -} - -void rtcInit (void) -{ - BYTE buf[8]; /* RTC R/W buffer */ - UINT adr; - - - /* Read RTC registers */ - if (!iic_read(0xD0, 0, 8, buf)) return; /* IIC error */ - - if (buf[7] & 0x20) { /* When data has been volatiled, set default time */ - /* Clear nv-ram. Reg[8..63] */ - memset(buf, 0, 8); - for (adr = 8; adr < 64; adr += 8) - iic_write(0x0D, adr, 8, buf); - /* Reset time to Jan 1, '08. Reg[0..7] */ - buf[4] = 1; buf[5] = 1; buf[6] = 8; - iic_write(0x0D, 0, 8, buf); - } - - struct gtm utm; - rtcGetTime(&utm); - g_rtcTime = gmktime(&utm); -} - diff --git a/radio/src/targets/gruvin9x/voice.cpp b/radio/src/targets/gruvin9x/voice.cpp deleted file mode 100644 index f2b370178..000000000 --- a/radio/src/targets/gruvin9x/voice.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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. - */ - -/* - Cam: I did think about implimenting this with an array for the timing durations - like the original bit bang DSM2 code was done but that meant another array - on top of the playlist one, therefore more memory waisted, and because - the playlist must be executed one after another it would mean putting - the code to fill the array in the interrupt (This would be unlike the - old DSM2 code) which seemed to much for the interrupt. - */ - -#include "opentx.h" - -// Start and stop bits need to be 2ms in duration. Start bit is low, stop bit is high -#define SOMOSSBIT 5 //The 2ms of a stop/start bit -#define SOMOSTOP 48 //This is the needed 2ms (4) + 20ms (40) to allow for the - //point at which the busy flag is checkable + 2ms for saftey (4) -#define SOMOSTART 60 //This is the needed 2ms (4) + 2ms (4) for safety + 26ms (52) for the - //undocumented delay that must exist between playbacks. -#define SOMOBUSY (PINH & 0x40) /* SOMO14D Busy flag */ -#define SOMOCLK (PINH & 0x10) /* SOMO14D CLK */ - -#define QUEUE_LENGTH 10 -uint16_t somo14playlist[QUEUE_LENGTH] = {0}; -uint16_t somo14command = 0; -uint8_t somo14RIdx = 0; -volatile uint8_t somo14WIdx = 0; - -#ifdef SIMU -#define BUSY busy -#else -#define BUSY -#endif - -NOINLINE uint8_t SomoWakeup() -{ - static uint16_t somo14_current; - static uint8_t i = 0; - static uint8_t busy = 0; // debugging make BOOL when done - static uint8_t startstop = SOMOSSBIT; // Only the first playback can have this short delay - - // printf("startstop=%d i=%d\n", startstop, i); fflush(stdout); - -// Send no data unless we are either not busy or it's a command - - // Only when stop bit is sent do we increment read pointer - // This will happen before the SOMO14D busy flag gets set - // Busy flag happens 20ms after the last data is clocked in - if (i==0 && !busy) { - if (somo14command) { // Allow a command to be send even if the SOMO is busy, i.e. STOP or PAUSE - somo14_current = somo14command; - somo14command = 0; - busy = 1; - } - else if (!SOMOBUSY) { - if (somo14RIdx == somo14WIdx) { - return 1; - } - somo14_current = somo14playlist[somo14RIdx]; - somo14RIdx = (somo14RIdx + 1) % QUEUE_LENGTH; - busy = 1; - } - } - - // Start and stop bits - if (busy && startstop) { - // Start bit - if (i==0) { - if (startstop < SOMOSSBIT) { // This stretches the time before we start sending data to allow for the - // undocumented delay that must exist between playbacks. Unfortunately the - // device isn't ready even though the busy flag says it is. - PORTH &= ~(1<> 3; - - for (int i=1; i<7; i++) { - keys[index].input(in & (1< = Mark Sproul msproul@skycharoit.com -//* Jul 7, 2010 Working on mega2560. No Auto-restart -//* Jul 7, 2010 Switched to 8K bytes (4K words) so that we have room for the monitor -//* Jul 8, 2010 Found older version of source that had auto restart, put that code back in -//* Jul 8, 2010 Adding monitor code -//* Jul 11, 2010 Added blinking LED while waiting for download to start -//* Jul 11, 2010 Added EEPROM test -//* Jul 29, 2010 Added recchar_timeout for timing out on bootloading -//* Aug 23, 2010 Added support for atmega2561 -//* Aug 26, 2010 Removed support for BOOT_BY_SWITCH -//* Sep 8, 2010 Added support for atmega16 -//* Nov 9, 2010 Issue 392:Fixed bug that 3 !!! in code would cause it to jump to monitor -//* Jun 24, 2011 Removed analogRead (was not used) -//* Dec 29, 2011 Issue 181: added watch dog timmer support -//* Dec 29, 2011 Issue 505: bootloader is comparing the seqNum to 1 or the current sequence -//* Jan 1, 2012 Issue 543: CMD_CHIP_ERASE_ISP now returns STATUS_CMD_FAILED instead of STATUS_CMD_OK -//* Jan 1, 2012 Issue 543: Write EEPROM now does something (NOT TESTED) -//* Jan 1, 2012 Issue 544: stk500v2 bootloader doesn't support reading fuses -//************************************************************************ - -//************************************************************************ -//* these are used to test issues -//* http://code.google.com/p/arduino/issues/detail?id=505 -//* Reported by mark.stubbs, Mar 14, 2011 -//* The STK500V2 bootloader is comparing the seqNum to 1 or the current sequence -//* (IE: Requiring the sequence to be 1 or match seqNum before continuing). -//* The correct behavior is for the STK500V2 to accept the PC's sequence number, and echo it back for the reply message. -#define _FIX_ISSUE_505_ -//************************************************************************ -//* Issue 181: added watch dog timmer support -#define _FIX_ISSUE_181_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "command.h" - - -#if defined(_MEGA_BOARD_) || defined(_BOARD_AMBER128_) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) \ - || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1284P__) || defined(ENABLE_MONITOR) - #undef ENABLE_MONITOR - #define ENABLE_MONITOR - static void RunMonitor(void); -#endif - -#ifndef EEWE - #define EEWE 1 -#endif -#ifndef EEMWE - #define EEMWE 2 -#endif - -//#define _DEBUG_SERIAL_ -//#define _DEBUG_WITH_LEDS_ - - -/* - * Uncomment the following lines to save code space - */ -//#define REMOVE_PROGRAM_LOCK_BIT_SUPPORT // disable program lock bits -//#define REMOVE_BOOTLOADER_LED // no LED to show active bootloader -//#define REMOVE_CMD_SPI_MULTI // disable processing of SPI_MULTI commands, Remark this line for AVRDUDE -// - - - -//************************************************************************ -//* LED on pin "PROGLED_PIN" on port "PROGLED_PORT" -//* indicates that bootloader is active -//* PG2 -> LED on Wiring board -//************************************************************************ -#define BLINK_LED_WHILE_WAITING - -#ifdef _MEGA_BOARD_ - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB7 -#elif defined( _BOARD_AMBER128_ ) - //* this is for the amber 128 http://www.soc-robotics.com/ - //* onbarod led is PORTE4 - #define PROGLED_PORT PORTD - #define PROGLED_DDR DDRD - #define PROGLED_PIN PINE7 -#elif defined( _CEREBOTPLUS_BOARD_ ) || defined(_CEREBOT_II_BOARD_) - //* this is for the Cerebot 2560 board and the Cerebot-ii - //* onbarod leds are on PORTE4-7 - #define PROGLED_PORT PORTE - #define PROGLED_DDR DDRE - #define PROGLED_PIN PINE7 -#elif defined( _PENGUINO_ ) - //* this is for the Penguino - //* onbarod led is PORTE4 - #define PROGLED_PORT PORTC - #define PROGLED_DDR DDRC - #define PROGLED_PIN PINC6 -#elif defined( _ANDROID_2561_ ) || defined( __AVR_ATmega2561__ ) - //* this is for the Boston Android 2561 - //* onbarod led is PORTE4 - #define PROGLED_PORT PORTA - #define PROGLED_DDR DDRA - #define PROGLED_PIN PINA3 -#elif defined( _BOARD_MEGA16 ) - //* onbarod led is PORTA7 - #define PROGLED_PORT PORTA - #define PROGLED_DDR DDRA - #define PROGLED_PIN PINA7 - #define UART_BAUDRATE_DOUBLE_SPEED 0 - -#elif defined( _BOARD_BAHBOT_ ) - //* dosent have an onboard LED but this is what will probably be added to this port - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB0 - -#elif defined( _BOARD_ROBOTX_ ) - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB6 -#elif defined( _BOARD_CUSTOM1284_BLINK_B0_ ) - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB0 -#elif defined( _BOARD_CUSTOM1284_ ) - #define PROGLED_PORT PORTD - #define PROGLED_DDR DDRD - #define PROGLED_PIN PIND5 -#elif defined( _AVRLIP_ ) - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB5 -#elif defined( _BOARD_STK500_ ) - #define PROGLED_PORT PORTA - #define PROGLED_DDR DDRA - #define PROGLED_PIN PINA7 -#elif defined( _BOARD_STK502_ ) - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB5 -#elif defined( _BOARD_STK525_ ) - #define PROGLED_PORT PORTB - #define PROGLED_DDR DDRB - #define PROGLED_PIN PINB7 -#else - #define PROGLED_PORT PORTG - #define PROGLED_DDR DDRG - #define PROGLED_PIN PING2 -#endif - - - -/* - * define CPU frequency in Mhz here if not defined in Makefile - */ -#ifndef F_CPU - #define F_CPU 16000000UL -#endif - -#define _BLINK_LOOP_COUNT_ (F_CPU / 2250) -/* - * UART Baudrate, AVRStudio AVRISP only accepts 115200 bps - */ - -#ifndef BAUDRATE - #define BAUDRATE 115200 -#endif - -/* - * Enable (1) or disable (0) USART double speed operation - */ -#ifndef UART_BAUDRATE_DOUBLE_SPEED - #if defined (__AVR_ATmega32__) - #define UART_BAUDRATE_DOUBLE_SPEED 0 - #else - #define UART_BAUDRATE_DOUBLE_SPEED 1 - #endif -#endif - -/* - * HW and SW version, reported to AVRISP, must match version of AVRStudio - */ -#define CONFIG_PARAM_BUILD_NUMBER_LOW 0 -#define CONFIG_PARAM_BUILD_NUMBER_HIGH 0 -#define CONFIG_PARAM_HW_VER 0x0F -#define CONFIG_PARAM_SW_MAJOR 2 -#define CONFIG_PARAM_SW_MINOR 0x0A - -/* - * Calculate the address where the bootloader starts from FLASHEND and BOOTSIZE - * (adjust BOOTSIZE below and BOOTLOADER_ADDRESS in Makefile if you want to change the size of the bootloader) - */ -//#define BOOTSIZE 1024 -#if FLASHEND > 0x0F000 - #define BOOTSIZE 8192 -#else - #define BOOTSIZE 2048 -#endif - -#define MAX_ERR_COUNT 10 -#define APP_END (FLASHEND -(2*BOOTSIZE) + 1) - -/* - * Signature bytes are not available in avr-gcc io_xxx.h - */ -#if defined (__AVR_ATmega8__) - #define SIGNATURE_BYTES 0x1E9307 -#elif defined (__AVR_ATmega16__) - #define SIGNATURE_BYTES 0x1E9403 -#elif defined (__AVR_ATmega32__) - #define SIGNATURE_BYTES 0x1E9502 -#elif defined (__AVR_ATmega8515__) - #define SIGNATURE_BYTES 0x1E9306 -#elif defined (__AVR_ATmega8535__) - #define SIGNATURE_BYTES 0x1E9308 -#elif defined (__AVR_ATmega162__) - #define SIGNATURE_BYTES 0x1E9404 -#elif defined (__AVR_ATmega128__) - #define SIGNATURE_BYTES 0x1E9702 -#elif defined (__AVR_ATmega1280__) - #define SIGNATURE_BYTES 0x1E9703 -#elif defined (__AVR_ATmega2560__) - #define SIGNATURE_BYTES 0x1E9801 -#elif defined (__AVR_ATmega2561__) - #define SIGNATURE_BYTES 0x1e9802 -#elif defined (__AVR_ATmega1284P__) - #define SIGNATURE_BYTES 0x1e9705 -#elif defined (__AVR_ATmega640__) - #define SIGNATURE_BYTES 0x1e9608 -#elif defined (__AVR_ATmega64__) - #define SIGNATURE_BYTES 0x1E9602 -#elif defined (__AVR_ATmega169__) - #define SIGNATURE_BYTES 0x1e9405 -#elif defined (__AVR_AT90USB1287__) - #define SIGNATURE_BYTES 0x1e9782 -#else - #error "no signature definition for MCU available" -#endif - - -#if defined(_BOARD_ROBOTX_) || defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) - #define UART_BAUD_RATE_LOW UBRR1L - #define UART_STATUS_REG UCSR1A - #define UART_CONTROL_REG UCSR1B - #define UART_ENABLE_TRANSMITTER TXEN1 - #define UART_ENABLE_RECEIVER RXEN1 - #define UART_TRANSMIT_COMPLETE TXC1 - #define UART_RECEIVE_COMPLETE RXC1 - #define UART_DATA_REG UDR1 - #define UART_DOUBLE_SPEED U2X1 - -#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \ - || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__) - /* ATMega8 with one USART */ - #define UART_BAUD_RATE_LOW UBRRL - #define UART_STATUS_REG UCSRA - #define UART_CONTROL_REG UCSRB - #define UART_ENABLE_TRANSMITTER TXEN - #define UART_ENABLE_RECEIVER RXEN - #define UART_TRANSMIT_COMPLETE TXC - #define UART_RECEIVE_COMPLETE RXC - #define UART_DATA_REG UDR - #define UART_DOUBLE_SPEED U2X - -#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega162__) \ - || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) - /* ATMega with two USART, use UART0 */ - #define UART_BAUD_RATE_LOW UBRR0L - #define UART_STATUS_REG UCSR0A - #define UART_CONTROL_REG UCSR0B - #define UART_ENABLE_TRANSMITTER TXEN0 - #define UART_ENABLE_RECEIVER RXEN0 - #define UART_TRANSMIT_COMPLETE TXC0 - #define UART_RECEIVE_COMPLETE RXC0 - #define UART_DATA_REG UDR0 - #define UART_DOUBLE_SPEED U2X0 -#elif defined(UBRR0L) && defined(UCSR0A) && defined(TXEN0) - /* ATMega with two USART, use UART0 */ - #define UART_BAUD_RATE_LOW UBRR0L - #define UART_STATUS_REG UCSR0A - #define UART_CONTROL_REG UCSR0B - #define UART_ENABLE_TRANSMITTER TXEN0 - #define UART_ENABLE_RECEIVER RXEN0 - #define UART_TRANSMIT_COMPLETE TXC0 - #define UART_RECEIVE_COMPLETE RXC0 - #define UART_DATA_REG UDR0 - #define UART_DOUBLE_SPEED U2X0 -#elif defined(UBRRL) && defined(UCSRA) && defined(UCSRB) && defined(TXEN) && defined(RXEN) - //* catch all - #define UART_BAUD_RATE_LOW UBRRL - #define UART_STATUS_REG UCSRA - #define UART_CONTROL_REG UCSRB - #define UART_ENABLE_TRANSMITTER TXEN - #define UART_ENABLE_RECEIVER RXEN - #define UART_TRANSMIT_COMPLETE TXC - #define UART_RECEIVE_COMPLETE RXC - #define UART_DATA_REG UDR - #define UART_DOUBLE_SPEED U2X -#else - #error "no UART definition for MCU available" -#endif - - - -/* - * Macro to calculate UBBR from XTAL and baudrate - */ -#if defined(__AVR_ATmega32__) && UART_BAUDRATE_DOUBLE_SPEED - #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu / 4 / baudRate - 1) / 2) -#elif defined(__AVR_ATmega32__) - #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu / 8 / baudRate - 1) / 2) -#elif UART_BAUDRATE_DOUBLE_SPEED - #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*8.0)-1.0+0.5) -#else - #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*16.0)-1.0+0.5) -#endif - - -/* - * States used in the receive state machine - */ -#define ST_START 0 -#define ST_GET_SEQ_NUM 1 -#define ST_MSG_SIZE_1 2 -#define ST_MSG_SIZE_2 3 -#define ST_GET_TOKEN 4 -#define ST_GET_DATA 5 -#define ST_GET_CHECK 6 -#define ST_PROCESS 7 - -/* - * use 16bit address variable for ATmegas with <= 64K flash - */ -#if defined(RAMPZ) - typedef uint32_t address_t; -#else - typedef uint16_t address_t; -#endif - -/* - * function prototypes - */ -static void sendchar(char c); -static unsigned char recchar(void); - -/* - * since this bootloader is not linked against the avr-gcc crt1 functions, - * to reduce the code size, we need to provide our own initialization - */ -void __jumpMain (void) __attribute__ ((naked)) __attribute__ ((section (".init9"))); -#include - -//#define SPH_REG 0x3E -//#define SPL_REG 0x3D - -//***************************************************************************** -void __jumpMain(void) -{ -//* July 17, 2010 Added stack pointer initialzation -//* the first line did not do the job on the ATmega128 - - asm volatile ( ".set __stack, %0" :: "i" (RAMEND) ); - -//* set stack pointer to top of RAM - - asm volatile ( "ldi 16, %0" :: "i" (RAMEND >> 8) ); - asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_HI_ADDR) ); - - asm volatile ( "ldi 16, %0" :: "i" (RAMEND & 0x0ff) ); - asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_LO_ADDR) ); - - asm volatile ( "clr __zero_reg__" ); // GCC depends on register r1 set to 0 - asm volatile ( "out %0, __zero_reg__" :: "I" (_SFR_IO_ADDR(SREG)) ); // set SREG to 0 - asm volatile ( "jmp main"); // jump to main() -} - - -//***************************************************************************** -void delay_ms(unsigned int timedelay) -{ - unsigned int i; - for (i=0;i> 1) -//***************************************************************************** -static unsigned char recchar_timeout(void) -{ -uint32_t count = 0; - - while (!(UART_STATUS_REG & (1 << UART_RECEIVE_COMPLETE))) - { - // wait for data - count++; - if (count > MAX_TIME_COUNT) - { - unsigned int data; - #if (FLASHEND > 0x10000) - data = pgm_read_word_far(0); //* get the first word of the user program - #else - data = pgm_read_word_near(0); //* get the first word of the user program - #endif - if (data != 0xffff) //* make sure its valid before jumping to it. - { - asm volatile( - "clr r30 \n\t" - "clr r31 \n\t" - "ijmp \n\t" - ); - } - count = 0; - } - } - return UART_DATA_REG; -} - -//* for watch dog timer startup -void (*app_start)(void) = 0x0000; - - -//***************************************************************************** -int main(void) -{ - address_t address = 0; - address_t eraseAddress = 0; - unsigned char msgParseState; - unsigned int ii = 0; - unsigned char checksum = 0; - unsigned char seqNum = 0; - unsigned int msgLength = 0; - unsigned char msgBuffer[285]; - unsigned char c, *p; - unsigned char isLeave = 0; - unsigned char errCnt = 0; - - unsigned long boot_timeout; - unsigned long boot_timer; - unsigned int boot_state; -#ifdef ENABLE_MONITOR - unsigned int exPointCntr = 0; - unsigned int rcvdCharCntr = 0; -#endif - - //* some chips dont set the stack properly - asm volatile ( ".set __stack, %0" :: "i" (RAMEND) ); - asm volatile ( "ldi 16, %0" :: "i" (RAMEND >> 8) ); - asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_HI_ADDR) ); - asm volatile ( "ldi 16, %0" :: "i" (RAMEND & 0x0ff) ); - asm volatile ( "out %0,16" :: "i" (AVR_STACK_POINTER_LO_ADDR) ); - -#ifdef _FIX_ISSUE_181_ - //************************************************************************ - //* Dec 29, 2011 Issue #181, added watch dog timmer support - //* handle the watch dog timer - uint8_t mcuStatusReg; - mcuStatusReg = MCUSR; - - __asm__ __volatile__ ("cli"); - __asm__ __volatile__ ("wdr"); - MCUSR = 0; - WDTCSR |= _BV(WDCE) | _BV(WDE); - WDTCSR = 0; - __asm__ __volatile__ ("sei"); - // check if WDT generated the reset, if so, go straight to app - if (mcuStatusReg & _BV(WDRF)) - { - app_start(); - } - //************************************************************************ -#endif - - - boot_timer = 0; - boot_state = 0; - -#ifdef BLINK_LED_WHILE_WAITING -// boot_timeout = 90000; //* should be about 4 seconds -// boot_timeout = 170000; - boot_timeout = 20000; //* should be about 1 second -#else - boot_timeout = 3500000; // 7 seconds , approx 2us per step when optimize "s" -#endif - /* - * Branch to bootloader or application code ? - */ - -#ifndef REMOVE_BOOTLOADER_LED - /* PROG_PIN pulled low, indicate with LED that bootloader is active */ - PROGLED_DDR |= (1< boot_timeout) - { - boot_state = 1; // (after ++ -> boot_state=2 bootloader timeout, jump to main 0x00000 ) - } - #ifdef BLINK_LED_WHILE_WAITING - if ((boot_timer % _BLINK_LOOP_COUNT_) == 0) - { - //* toggle the LED - PROGLED_PORT ^= (1< MAX_ERR_COUNT) - { - msgBuffer[0]=CMD_LEAVE_PROGMODE_ISP; - msgParseState=ST_PROCESS; - } - } - break; - - case ST_GET_SEQ_NUM: - #ifdef _FIX_ISSUE_505_ - seqNum = c; - msgParseState = ST_MSG_SIZE_1; - checksum ^= c; - #else - if ( (c == 1) || (c == seqNum) ) - { - seqNum = c; - msgParseState = ST_MSG_SIZE_1; - checksum ^= c; - } - else - { - msgParseState = ST_START; - } - #endif - break; - - case ST_MSG_SIZE_1: - msgLength = c<<8; - msgParseState = ST_MSG_SIZE_2; - checksum ^= c; - break; - - case ST_MSG_SIZE_2: - msgLength |= c; - msgParseState = ST_GET_TOKEN; - checksum ^= c; - break; - - case ST_GET_TOKEN: - if ( c == TOKEN ) - { - msgParseState = ST_GET_DATA; - checksum ^= c; - ii = 0; - } - else - { - msgParseState = ST_START; - } - break; - - case ST_GET_DATA: - msgBuffer[ii++] = c; - checksum ^= c; - if (ii == msgLength ) - { - msgParseState = ST_GET_CHECK; - } - break; - - case ST_GET_CHECK: - if ( c == checksum ) - { - msgParseState = ST_PROCESS; - } - else - { - msgParseState = ST_START; - } - break; - } // switch - } // while(msgParseState) - - /* - * Now process the STK500 commands, see Atmel Appnote AVR068 - */ - - switch (msgBuffer[0]) - { - #ifndef REMOVE_CMD_SPI_MULTI - case CMD_SPI_MULTI: - { - unsigned char answerByte; - unsigned char flag=0; - - if ( msgBuffer[4]== 0x30 ) - { - unsigned char signatureIndex = msgBuffer[6]; - - if ( signatureIndex == 0 ) - { - answerByte = (SIGNATURE_BYTES >> 16) & 0x000000FF; - } - else if ( signatureIndex == 1 ) - { - answerByte = (SIGNATURE_BYTES >> 8) & 0x000000FF; - } - else - { - answerByte = SIGNATURE_BYTES & 0x000000FF; - } - } - else if ( msgBuffer[4] & 0x50 ) - { - //* Issue 544: stk500v2 bootloader doesn't support reading fuses - //* I cant find the docs that say what these are supposed to be but this was figured out by trial and error - // answerByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS); - // answerByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS); - // answerByte = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS); - if (msgBuffer[4] == 0x50) - { - answerByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS); - } - else if (msgBuffer[4] == 0x58) - { - answerByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS); - } - else - { - answerByte = 0; - } - } - else - { - answerByte = 0; // for all others command are not implemented, return dummy value for AVRDUDE happy - } - if ( !flag ) - { - msgLength = 7; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = 0; - msgBuffer[3] = msgBuffer[4]; - msgBuffer[4] = 0; - msgBuffer[5] = answerByte; - msgBuffer[6] = STATUS_CMD_OK; - } - } - break; - #endif - case CMD_SIGN_ON: - msgLength = 11; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = 8; - msgBuffer[3] = 'A'; - msgBuffer[4] = 'V'; - msgBuffer[5] = 'R'; - msgBuffer[6] = 'I'; - msgBuffer[7] = 'S'; - msgBuffer[8] = 'P'; - msgBuffer[9] = '_'; - msgBuffer[10] = '2'; - break; - - case CMD_GET_PARAMETER: - { - unsigned char value; - - switch(msgBuffer[1]) - { - case PARAM_BUILD_NUMBER_LOW: - value = CONFIG_PARAM_BUILD_NUMBER_LOW; - break; - case PARAM_BUILD_NUMBER_HIGH: - value = CONFIG_PARAM_BUILD_NUMBER_HIGH; - break; - case PARAM_HW_VER: - value = CONFIG_PARAM_HW_VER; - break; - case PARAM_SW_MAJOR: - value = CONFIG_PARAM_SW_MAJOR; - break; - case PARAM_SW_MINOR: - value = CONFIG_PARAM_SW_MINOR; - break; - default: - value = 0; - break; - } - msgLength = 3; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = value; - } - break; - - case CMD_LEAVE_PROGMODE_ISP: - isLeave = 1; - //* fall thru - - case CMD_SET_PARAMETER: - case CMD_ENTER_PROGMODE_ISP: - msgLength = 2; - msgBuffer[1] = STATUS_CMD_OK; - break; - - case CMD_READ_SIGNATURE_ISP: - { - unsigned char signatureIndex = msgBuffer[4]; - unsigned char signature; - - if ( signatureIndex == 0 ) - signature = (SIGNATURE_BYTES >>16) & 0x000000FF; - else if ( signatureIndex == 1 ) - signature = (SIGNATURE_BYTES >> 8) & 0x000000FF; - else - signature = SIGNATURE_BYTES & 0x000000FF; - - msgLength = 4; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = signature; - msgBuffer[3] = STATUS_CMD_OK; - } - break; - - case CMD_READ_LOCK_ISP: - msgLength = 4; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = boot_lock_fuse_bits_get( GET_LOCK_BITS ); - msgBuffer[3] = STATUS_CMD_OK; - break; - - case CMD_READ_FUSE_ISP: - { - unsigned char fuseBits; - - if ( msgBuffer[2] == 0x50 ) - { - if ( msgBuffer[3] == 0x08 ) - fuseBits = boot_lock_fuse_bits_get( GET_EXTENDED_FUSE_BITS ); - else - fuseBits = boot_lock_fuse_bits_get( GET_LOW_FUSE_BITS ); - } - else - { - fuseBits = boot_lock_fuse_bits_get( GET_HIGH_FUSE_BITS ); - } - msgLength = 4; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = fuseBits; - msgBuffer[3] = STATUS_CMD_OK; - } - break; - - #ifndef REMOVE_PROGRAM_LOCK_BIT_SUPPORT - case CMD_PROGRAM_LOCK_ISP: - { - unsigned char lockBits = msgBuffer[4]; - - lockBits = (~lockBits) & 0x3C; // mask BLBxx bits - boot_lock_bits_set(lockBits); // and program it - boot_spm_busy_wait(); - - msgLength = 3; - msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[2] = STATUS_CMD_OK; - } - break; - #endif - case CMD_CHIP_ERASE_ISP: - eraseAddress = 0; - msgLength = 2; - // msgBuffer[1] = STATUS_CMD_OK; - msgBuffer[1] = STATUS_CMD_FAILED; //* isue 543, return FAILED instead of OK - break; - - case CMD_LOAD_ADDRESS: - #if defined(RAMPZ) - address = ( ((address_t)(msgBuffer[1])<<24)|((address_t)(msgBuffer[2])<<16)|((address_t)(msgBuffer[3])<<8)|(msgBuffer[4]) )<<1; - #else - address = ( ((msgBuffer[3])<<8)|(msgBuffer[4]) )<<1; //convert word to byte address - #endif - msgLength = 2; - msgBuffer[1] = STATUS_CMD_OK; - break; - - case CMD_PROGRAM_FLASH_ISP: - case CMD_PROGRAM_EEPROM_ISP: - { - unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2]; - unsigned char *p = msgBuffer+10; - unsigned int data; - unsigned char highByte, lowByte; - address_t tempaddress = address; - - - if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP ) - { - // erase only main section (bootloader protection) - if (eraseAddress < APP_END ) - { - boot_page_erase(eraseAddress); // Perform page erase - boot_spm_busy_wait(); // Wait until the memory is erased. - eraseAddress += SPM_PAGESIZE; // point to next page to be erase - } - - /* Write FLASH */ - do { - lowByte = *p++; - highByte = *p++; - - data = (highByte << 8) | lowByte; - boot_page_fill(address,data); - - address = address + 2; // Select next word in memory - size -= 2; // Reduce number of bytes to write by two - } while (size); // Loop until all bytes written - - boot_page_write(tempaddress); - boot_spm_busy_wait(); - boot_rww_enable(); // Re-enable the RWW section - } - else - { - //* issue 543, this should work, It has not been tested. - uint16_t ii = address >> 1; - /* write EEPROM */ - while (size) { - eeprom_write_byte((uint8_t*)ii, *p++); - address+=2; // Select next EEPROM byte - ii++; - size--; - } - } - msgLength = 2; - msgBuffer[1] = STATUS_CMD_OK; - } - break; - - case CMD_READ_FLASH_ISP: - case CMD_READ_EEPROM_ISP: - { - unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2]; - unsigned char *p = msgBuffer+1; - msgLength = size+3; - - *p++ = STATUS_CMD_OK; - if (msgBuffer[0] == CMD_READ_FLASH_ISP ) - { - unsigned int data; - - // Read FLASH - do { - //#if defined(RAMPZ) - #if (FLASHEND > 0x10000) - data = pgm_read_word_far(address); - #else - data = pgm_read_word_near(address); - #endif - *p++ = (unsigned char)data; //LSB - *p++ = (unsigned char)(data >> 8); //MSB - address += 2; // Select next word in memory - size -= 2; - }while (size); - } - else - { - /* Read EEPROM */ - do { - EEARL = address; // Setup EEPROM address - EEARH = ((address >> 8)); - address++; // Select next EEPROM byte - EECR |= (1<>8)&0xFF); - sendchar(c); - checksum ^= c; - - c = msgLength&0x00FF; - sendchar(c); - checksum ^= c; - - sendchar(TOKEN); - checksum ^= TOKEN; - - p = msgBuffer; - while ( msgLength ) - { - c = *p++; - sendchar(c); - checksum ^=c; - msgLength--; - } - sendchar(checksum); - seqNum++; - - #ifndef REMOVE_BOOTLOADER_LED - //* toggle the LED - PROGLED_PORT ^= (1< - - -base address = f000 -avrdude: Device signature = 0x1e9703 -avrdude: safemode: lfuse reads as FF -avrdude: safemode: hfuse reads as D8 -avrdude: safemode: efuse reads as F5 -avrdude> -*/ - -//************************************************************************ -#ifdef ENABLE_MONITOR -#include - -unsigned long gRamIndex; -unsigned long gFlashIndex; -unsigned long gEepromIndex; - - -#define true 1 -#define false 0 - -#include "avr_cpunames.h" - -#ifndef _AVR_CPU_NAME_ - #error cpu name not defined -#endif - -#ifdef _VECTORS_SIZE - #define kInterruptVectorCount (_VECTORS_SIZE / 4) -#else - #define kInterruptVectorCount 23 -#endif - - -void PrintDecInt(int theNumber, int digitCnt); - -#ifdef _AVR_CPU_NAME_ - const char gTextMsg_CPU_Name[] PROGMEM = _AVR_CPU_NAME_; -#else - const char gTextMsg_CPU_Name[] PROGMEM = "UNKNOWN"; -#endif - - const char gTextMsg_Explorer[] PROGMEM = "Arduino explorer stk500V2 by MLS"; - const char gTextMsg_Prompt[] PROGMEM = "Bootloader>"; - const char gTextMsg_HUH[] PROGMEM = "Huh?"; - const char gTextMsg_COMPILED_ON[] PROGMEM = "Compiled on = "; - const char gTextMsg_CPU_Type[] PROGMEM = "CPU Type = "; - const char gTextMsg_AVR_ARCH[] PROGMEM = "__AVR_ARCH__= "; - const char gTextMsg_AVR_LIBC[] PROGMEM = "AVR LibC Ver= "; - const char gTextMsg_GCC_VERSION[] PROGMEM = "GCC Version = "; - const char gTextMsg_CPU_SIGNATURE[] PROGMEM = "CPU ID = "; - const char gTextMsg_FUSE_BYTE_LOW[] PROGMEM = "Low fuse = "; - const char gTextMsg_FUSE_BYTE_HIGH[] PROGMEM = "High fuse = "; - const char gTextMsg_FUSE_BYTE_EXT[] PROGMEM = "Ext fuse = "; - const char gTextMsg_FUSE_BYTE_LOCK[] PROGMEM = "Lock fuse = "; - const char gTextMsg_GCC_DATE_STR[] PROGMEM = __DATE__; - const char gTextMsg_AVR_LIBC_VER_STR[] PROGMEM = __AVR_LIBC_VERSION_STRING__; - const char gTextMsg_GCC_VERSION_STR[] PROGMEM = __VERSION__; - const char gTextMsg_VECTOR_HEADER[] PROGMEM = "V# ADDR op code instruction addr Interrupt"; - const char gTextMsg_noVector[] PROGMEM = "no vector"; - const char gTextMsg_rjmp[] PROGMEM = "rjmp "; - const char gTextMsg_jmp[] PROGMEM = "jmp "; - const char gTextMsg_WHAT_PORT[] PROGMEM = "What port:"; - const char gTextMsg_PortNotSupported[] PROGMEM = "Port not supported"; - const char gTextMsg_MustBeLetter[] PROGMEM = "Must be a letter"; - const char gTextMsg_SPACE[] PROGMEM = " "; - const char gTextMsg_WriteToEEprom[] PROGMEM = "Writting EE"; - const char gTextMsg_ReadingEEprom[] PROGMEM = "Reading EE"; - const char gTextMsg_EEPROMerrorCnt[] PROGMEM = "EE err cnt="; - const char gTextMsg_PORT[] PROGMEM = "PORT"; - - -//************************************************************************ -//* Help messages - const char gTextMsg_HELP_MSG_0[] PROGMEM = "0=Zero addr"; - const char gTextMsg_HELP_MSG_QM[] PROGMEM = "?=CPU stats"; - const char gTextMsg_HELP_MSG_AT[] PROGMEM = "@=EEPROM test"; - const char gTextMsg_HELP_MSG_B[] PROGMEM = "B=Blink LED"; - const char gTextMsg_HELP_MSG_E[] PROGMEM = "E=Dump EEPROM"; - const char gTextMsg_HELP_MSG_F[] PROGMEM = "F=Dump FLASH"; - const char gTextMsg_HELP_MSG_H[] PROGMEM = "H=Help"; - const char gTextMsg_HELP_MSG_L[] PROGMEM = "L=List I/O Ports"; -// const char gTextMsg_HELP_MSG_Q[] PROGMEM = "Q=Quit & jump to user pgm"; - const char gTextMsg_HELP_MSG_Q[] PROGMEM = "Q=Quit"; - const char gTextMsg_HELP_MSG_R[] PROGMEM = "R=Dump RAM"; - const char gTextMsg_HELP_MSG_V[] PROGMEM = "V=show interrupt Vectors"; - const char gTextMsg_HELP_MSG_Y[] PROGMEM = "Y=Port blink"; - - const char gTextMsg_END[] PROGMEM = "*"; - - -//************************************************************************ -void PrintFromPROGMEM(const void *dataPtr, unsigned char offset) -{ -char theChar; - - dataPtr += offset; - - do { - #if (FLASHEND > 0x10000) - theChar = pgm_read_byte_far((uint16_t)dataPtr++); - #else - theChar = pgm_read_byte_near((uint16_t)dataPtr++); - #endif - if (theChar != 0) - { - sendchar(theChar); - } - } while (theChar != 0); -} - -//************************************************************************ -void PrintNewLine(void) -{ - sendchar(0x0d); - sendchar(0x0a); -} - - -//************************************************************************ -void PrintFromPROGMEMln(const void *dataPtr, unsigned char offset) -{ - PrintFromPROGMEM(dataPtr, offset); - - PrintNewLine(); -} - - -//************************************************************************ -void PrintString(char *textString) -{ -char theChar; -int ii; - - theChar = 1; - ii = 0; - while (theChar != 0) - { - theChar = textString[ii]; - if (theChar != 0) - { - sendchar(theChar); - } - ii++; - } -} - -//************************************************************************ -void PrintHexByte(unsigned char theByte) -{ -char theChar; - - theChar = 0x30 + ((theByte >> 4) & 0x0f); - if (theChar > 0x39) - { - theChar += 7; - } - sendchar(theChar ); - - theChar = 0x30 + (theByte & 0x0f); - if (theChar > 0x39) - { - theChar += 7; - } - sendchar(theChar ); -} - -//************************************************************************ -void PrintDecInt(int theNumber, int digitCnt) -{ -int theChar; -int myNumber; - - myNumber = theNumber; - - if ((myNumber > 100) || (digitCnt >= 3)) - { - theChar = 0x30 + myNumber / 100; - sendchar(theChar ); - } - - if ((myNumber > 10) || (digitCnt >= 2)) - { - theChar = 0x30 + ((myNumber % 100) / 10 ); - sendchar(theChar ); - } - theChar = 0x30 + (myNumber % 10); - sendchar(theChar ); -} - - - - -//************************************************************************ -static void PrintCPUstats(void) -{ -unsigned char fuseByte; - - PrintFromPROGMEMln(gTextMsg_Explorer, 0); - - PrintFromPROGMEM(gTextMsg_COMPILED_ON, 0); - PrintFromPROGMEMln(gTextMsg_GCC_DATE_STR, 0); - - PrintFromPROGMEM(gTextMsg_CPU_Type, 0); - PrintFromPROGMEMln(gTextMsg_CPU_Name, 0); - - PrintFromPROGMEM(gTextMsg_AVR_ARCH, 0); - PrintDecInt(__AVR_ARCH__, 1); - PrintNewLine(); - - PrintFromPROGMEM(gTextMsg_GCC_VERSION, 0); - PrintFromPROGMEMln(gTextMsg_GCC_VERSION_STR, 0); - - //* these can be found in avr/version.h - PrintFromPROGMEM(gTextMsg_AVR_LIBC, 0); - PrintFromPROGMEMln(gTextMsg_AVR_LIBC_VER_STR, 0); - -#if defined(SIGNATURE_0) - PrintFromPROGMEM(gTextMsg_CPU_SIGNATURE, 0); - //* these can be found in avr/iomxxx.h - PrintHexByte(SIGNATURE_0); - PrintHexByte(SIGNATURE_1); - PrintHexByte(SIGNATURE_2); - PrintNewLine(); -#endif - - -#if defined(GET_LOW_FUSE_BITS) - //* fuse settings - PrintFromPROGMEM(gTextMsg_FUSE_BYTE_LOW, 0); - fuseByte = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS); - PrintHexByte(fuseByte); - PrintNewLine(); - - PrintFromPROGMEM(gTextMsg_FUSE_BYTE_HIGH, 0); - fuseByte = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS); - PrintHexByte(fuseByte); - PrintNewLine(); - - PrintFromPROGMEM(gTextMsg_FUSE_BYTE_EXT, 0); - fuseByte = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS); - PrintHexByte(fuseByte); - PrintNewLine(); - - PrintFromPROGMEM(gTextMsg_FUSE_BYTE_LOCK, 0); - fuseByte = boot_lock_fuse_bits_get(GET_LOCK_BITS); - PrintHexByte(fuseByte); - PrintNewLine(); - -#endif - -} - - -//************************************************************************ -static void BlinkLED(void) -{ - PROGLED_DDR |= (1< 0) - { - if (myAddressPointer > 0x10000) - { - PrintHexByte((myAddressPointer >> 16) & 0x00ff); - } - PrintHexByte((myAddressPointer >> 8) & 0x00ff); - PrintHexByte(myAddressPointer & 0x00ff); - sendchar(0x20); - sendchar('-'); - sendchar(0x20); - - asciiDump[0] = 0; - for (ii=0; ii<16; ii++) - { - switch(dumpWhat) - { - case kDUMP_FLASH: - #if (FLASHEND > 0x10000) - theValue = pgm_read_byte_far(myAddressPointer); - #else - theValue = pgm_read_byte_near(myAddressPointer); - #endif - break; - - case kDUMP_EEPROM: - theValue = eeprom_read_byte((uint8_t *)(uint16_t)myAddressPointer); - break; - - case kDUMP_RAM: - theValue = ramPtr[myAddressPointer]; - break; - - } - PrintHexByte(theValue); - sendchar(0x20); - if ((theValue >= 0x20) && (theValue < 0x7f)) - { - asciiDump[ii % 16] = theValue; - } - else - { - asciiDump[ii % 16] = '.'; - } - - myAddressPointer++; - } - asciiDump[16] = 0; - PrintString(asciiDump); - PrintNewLine(); - - numRows--; - } -} - - - -//************************************************************************ -//* returns amount of extended memory -static void EEPROMtest(void) -{ -int ii; -char theChar; -char theEEPROMchar; -int errorCount; - - PrintFromPROGMEMln(gTextMsg_WriteToEEprom, 0); - PrintNewLine(); - ii = 0; -#if (FLASHEND > 0x10000) - while (((theChar = pgm_read_byte_far(((uint16_t)gTextMsg_Explorer) + ii)) != '*') && (ii < 512)) -#else - while (((theChar = pgm_read_byte_near(((uint16_t)gTextMsg_Explorer) + ii)) != '*') && (ii < 512)) -#endif - { - eeprom_write_byte((uint8_t *)ii, theChar); - if (theChar == 0) - { - PrintFromPROGMEM(gTextMsg_SPACE, 0); - } - else - { - sendchar(theChar); - } - ii++; - } - - //* no go back through and test - PrintNewLine(); - PrintNewLine(); - PrintFromPROGMEMln(gTextMsg_ReadingEEprom, 0); - PrintNewLine(); - errorCount = 0; - ii = 0; -#if (FLASHEND > 0x10000) - while (((theChar = pgm_read_byte_far((uint16_t)gTextMsg_Explorer + ii)) != '*') && (ii < 512)) -#else - while (((theChar = pgm_read_byte_near((uint16_t)gTextMsg_Explorer + ii)) != '*') && (ii < 512)) -#endif - { - theEEPROMchar = eeprom_read_byte((uint8_t *)ii); - if (theEEPROMchar == 0) - { - PrintFromPROGMEM(gTextMsg_SPACE, 0); - } - else - { - sendchar(theEEPROMchar); - } - if (theEEPROMchar != theChar) - { - errorCount++; - } - ii++; - } - PrintNewLine(); - PrintNewLine(); - PrintFromPROGMEM(gTextMsg_EEPROMerrorCnt, 0); - PrintDecInt(errorCount, 1); - PrintNewLine(); - PrintNewLine(); - - gEepromIndex = 0; //* set index back to zero for next eeprom dump - -} - - - -#if (FLASHEND > 0x08000) -//* this includes the interrupt names for the monitor portion. There is no longer enough -//* memory to include this -// #include "avrinterruptnames.h" -// #ifndef _INTERRUPT_NAMES_DEFINED_ -// #warning Interrupt vectors not defined -// #endif -#endif - -//************************************************************************ -static void VectorDisplay(void) -{ -unsigned long byte1; -unsigned long byte2; -unsigned long byte3; -unsigned long byte4; -unsigned long word1; -unsigned long word2; -int vectorIndex; -unsigned long myMemoryPtr; -unsigned long wordMemoryAddress; -unsigned long realitiveAddr; -unsigned long myFullAddress; -unsigned long absoluteAddr; -#if defined(_INTERRUPT_NAMES_DEFINED_) - long stringPointer; -#endif - - myMemoryPtr = 0; - vectorIndex = 0; - PrintFromPROGMEMln(gTextMsg_CPU_Name, 0); - PrintFromPROGMEMln(gTextMsg_VECTOR_HEADER, 0); - // V# ADDR op code - // 1 - 0000 = C3 BB 00 00 rjmp 03BB >000776 RESET - while (vectorIndex < kInterruptVectorCount) - { - wordMemoryAddress = myMemoryPtr / 2; - // 01 - 0000 = 12 34 - PrintDecInt(vectorIndex + 1, 2); - sendchar(0x20); - sendchar('-'); - sendchar(0x20); - PrintHexByte((wordMemoryAddress >> 8) & 0x00ff); - PrintHexByte((wordMemoryAddress) & 0x00ff); - sendchar(0x20); - sendchar('='); - sendchar(0x20); - - - //* the AVR is LITTLE ENDIAN, swap the byte order - #if (FLASHEND > 0x10000) - byte1 = pgm_read_byte_far(myMemoryPtr++); - byte2 = pgm_read_byte_far(myMemoryPtr++); - byte3 = pgm_read_byte_far(myMemoryPtr++); - byte4 = pgm_read_byte_far(myMemoryPtr++); - #else - byte1 = pgm_read_byte_near(myMemoryPtr++); - byte2 = pgm_read_byte_near(myMemoryPtr++); - byte3 = pgm_read_byte_near(myMemoryPtr++); - byte4 = pgm_read_byte_near(myMemoryPtr++); - #endif - word1 = (byte2 << 8) + byte1; - word2 = (byte4 << 8) + byte3; - - - PrintHexByte(byte2); - sendchar(0x20); - PrintHexByte(byte1); - sendchar(0x20); - PrintHexByte(byte4); - sendchar(0x20); - PrintHexByte(byte3); - sendchar(0x20); - - if (word1 == 0xffff) - { - PrintFromPROGMEM(gTextMsg_noVector, 0); - } - else if ((word1 & 0xc000) == 0xc000) - { - //* rjmp instruction - realitiveAddr = word1 & 0x3FFF; - absoluteAddr = wordMemoryAddress + realitiveAddr; //* add the offset to the current address - absoluteAddr = absoluteAddr << 1; //* multiply by 2 for byte address - - PrintFromPROGMEM(gTextMsg_rjmp, 0); - PrintHexByte((realitiveAddr >> 8) & 0x00ff); - PrintHexByte((realitiveAddr) & 0x00ff); - sendchar(0x20); - sendchar('>'); - PrintHexByte((absoluteAddr >> 16) & 0x00ff); - PrintHexByte((absoluteAddr >> 8) & 0x00ff); - PrintHexByte((absoluteAddr) & 0x00ff); - - } - else if ((word1 & 0xfE0E) == 0x940c) - { - //* jmp instruction, this is REALLY complicated, refer to the instruction manual (JMP) - myFullAddress = ((byte1 & 0x01) << 16) + - ((byte1 & 0xf0) << 17) + - ((byte2 & 0x01) << 21) + - word2; - - absoluteAddr = myFullAddress << 1; - - PrintFromPROGMEM(gTextMsg_jmp, 0); - PrintHexByte((myFullAddress >> 16) & 0x00ff); - PrintHexByte((myFullAddress >> 8) & 0x00ff); - PrintHexByte((myFullAddress) & 0x00ff); - sendchar(0x20); - sendchar('>'); - PrintHexByte((absoluteAddr >> 16) & 0x00ff); - PrintHexByte((absoluteAddr >> 8) & 0x00ff); - PrintHexByte((absoluteAddr) & 0x00ff); - } - - #if defined(_INTERRUPT_NAMES_DEFINED_) - sendchar(0x20); - #if (FLASHEND > 0x10000) - stringPointer = pgm_read_word_far(&(gInterruptNameTable[vectorIndex])); - #else - stringPointer = pgm_read_word_near(&(gInterruptNameTable[vectorIndex])); - #endif - PrintFromPROGMEM((char *)stringPointer, 0); - #endif - PrintNewLine(); - - vectorIndex++; - } -} - -//************************************************************************ -static void PrintAvailablePort(char thePortLetter) -{ - PrintFromPROGMEM(gTextMsg_PORT, 0); - sendchar(thePortLetter); - PrintNewLine(); -} - -//************************************************************************ -static void ListAvailablePorts(void) -{ - -#ifdef DDRA - PrintAvailablePort('A'); -#endif - -#ifdef DDRB - PrintAvailablePort('B'); -#endif - -#ifdef DDRC - PrintAvailablePort('C'); -#endif - -#ifdef DDRD - PrintAvailablePort('D'); -#endif - -#ifdef DDRE - PrintAvailablePort('E'); -#endif - -#ifdef DDRF - PrintAvailablePort('F'); -#endif - -#ifdef DDRG - PrintAvailablePort('G'); -#endif - -#ifdef DDRH - PrintAvailablePort('H'); -#endif - -#ifdef DDRI - PrintAvailablePort('I'); -#endif - -#ifdef DDRJ - PrintAvailablePort('J'); -#endif - -#ifdef DDRK - PrintAvailablePort('K'); -#endif - -#ifdef DDRL - PrintAvailablePort('L'); -#endif - -} - -//************************************************************************ -static void AVR_PortOutput(void) -{ -char portLetter; -char getCharFlag; - - PrintFromPROGMEM(gTextMsg_WHAT_PORT, 0); - - portLetter = recchar(); - portLetter = portLetter & 0x5f; - sendchar(portLetter); - PrintNewLine(); - - if ((portLetter >= 'A') && (portLetter <= 'Z')) - { - getCharFlag = true; - switch(portLetter) - { - #ifdef DDRA - case 'A': - DDRA = 0xff; - while (!Serial_Available()) - { - PORTA ^= 0xff; - delay_ms(200); - } - PORTA = 0; - break; - #endif - - #ifdef DDRB - case 'B': - DDRB = 0xff; - while (!Serial_Available()) - { - PORTB ^= 0xff; - delay_ms(200); - } - PORTB = 0; - break; - #endif - - #ifdef DDRC - case 'C': - DDRC = 0xff; - while (!Serial_Available()) - { - PORTC ^= 0xff; - delay_ms(200); - } - PORTC = 0; - break; - #endif - - #ifdef DDRD - case 'D': - DDRD = 0xff; - while (!Serial_Available()) - { - PORTD ^= 0xff; - delay_ms(200); - } - PORTD = 0; - break; - #endif - - #ifdef DDRE - case 'E': - DDRE = 0xff; - while (!Serial_Available()) - { - PORTE ^= 0xff; - delay_ms(200); - } - PORTE = 0; - break; - #endif - - #ifdef DDRF - case 'F': - DDRF = 0xff; - while (!Serial_Available()) - { - PORTF ^= 0xff; - delay_ms(200); - } - PORTF = 0; - break; - #endif - - #ifdef DDRG - case 'G': - DDRG = 0xff; - while (!Serial_Available()) - { - PORTG ^= 0xff; - delay_ms(200); - } - PORTG = 0; - break; - #endif - - #ifdef DDRH - case 'H': - DDRH = 0xff; - while (!Serial_Available()) - { - PORTH ^= 0xff; - delay_ms(200); - } - PORTH = 0; - break; - #endif - - #ifdef DDRI - case 'I': - DDRI = 0xff; - while (!Serial_Available()) - { - PORTI ^= 0xff; - delay_ms(200); - } - PORTI = 0; - break; - #endif - - #ifdef DDRJ - case 'J': - DDRJ = 0xff; - while (!Serial_Available()) - { - PORTJ ^= 0xff; - delay_ms(200); - } - PORTJ = 0; - break; - #endif - - #ifdef DDRK - case 'K': - DDRK = 0xff; - while (!Serial_Available()) - { - PORTK ^= 0xff; - delay_ms(200); - } - PORTK = 0; - break; - #endif - - #ifdef DDRL - case 'L': - DDRL = 0xff; - while (!Serial_Available()) - { - PORTL ^= 0xff; - delay_ms(200); - } - PORTL = 0; - break; - #endif - - default: - PrintFromPROGMEMln(gTextMsg_PortNotSupported, 0); - getCharFlag = false; - break; - } - if (getCharFlag) - { - recchar(); - } - } - else - { - PrintFromPROGMEMln(gTextMsg_MustBeLetter, 0); - } -} - - -//******************************************************************* -static void PrintHelp(void) -{ - PrintFromPROGMEMln(gTextMsg_HELP_MSG_0, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_QM, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_AT, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_B, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_E, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_F, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_H, 0); - - PrintFromPROGMEMln(gTextMsg_HELP_MSG_L, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_Q, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_R, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_V, 0); - PrintFromPROGMEMln(gTextMsg_HELP_MSG_Y, 0); -} - -//************************************************************************ -static void RunMonitor(void) -{ -char keepGoing; -unsigned char theChar; -int ii, jj; - - for (ii=0; ii<5; ii++) - { - for (jj=0; jj<25; jj++) - { - sendchar('!'); - } - PrintNewLine(); - } - - gRamIndex = 0; - gFlashIndex = 0; - gEepromIndex = 0; - - PrintFromPROGMEMln(gTextMsg_Explorer, 0); - - keepGoing = 1; - while (keepGoing) - { - PrintFromPROGMEM(gTextMsg_Prompt, 0); - theChar = recchar(); - if (theChar >= 0x60) - { - theChar = theChar & 0x5F; - } - - if (theChar >= 0x20) - { - sendchar(theChar); - sendchar(0x20); - } - - switch(theChar) - { - case '0': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_0, 2); - gFlashIndex = 0; - gRamIndex = 0; - gEepromIndex = 0; - break; - - case '?': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_QM, 2); - PrintCPUstats(); - break; - - case '@': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_AT, 2); - EEPROMtest(); - break; - - case 'B': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_B, 2); - BlinkLED(); - break; - - case 'E': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_E, 2); - DumpHex(kDUMP_EEPROM, gEepromIndex, 16); - gEepromIndex += 256; - if (gEepromIndex > E2END) - { - gEepromIndex = 0; - } - break; - - case 'F': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_F, 2); - DumpHex(kDUMP_FLASH, gFlashIndex, 16); - gFlashIndex += 256; - break; - - case 'H': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_H, 2); - PrintHelp(); - break; - - case 'L': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_L, 2); - ListAvailablePorts(); - break; - - case 'Q': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_Q, 2); - keepGoing = false; - break; - - case 'R': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_R, 2); - DumpHex(kDUMP_RAM, gRamIndex, 16); - gRamIndex += 256; - break; - - case 'V': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_V, 2); - VectorDisplay(); - break; - - case 'Y': - PrintFromPROGMEMln(gTextMsg_HELP_MSG_Y, 2); - AVR_PortOutput(); - break; - - default: - PrintFromPROGMEMln(gTextMsg_HUH, 0); - break; - } - } -} - -#endif - diff --git a/radio/src/targets/mega2560/i2c_driver.cpp b/radio/src/targets/mega2560/i2c_driver.cpp deleted file mode 100644 index a3cb4bb49..000000000 --- a/radio/src/targets/mega2560/i2c_driver.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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. - */ - -// From https://github.com/g4lvanix/I2C-master-lib - -#include -#include - -#include "i2c_driver.h" - -//#define F_SCL 400000UL // SCL frequency -#define F_SCL 800000UL // SCL frequency -#define Prescaler 1 -#define TWBR_val ((((F_CPU / F_SCL) / Prescaler) - 16 ) / 2) - -void wait() -{ - while( !(TWCR & (1< `(0x2F)<<1` = `0x5E`) - -##### uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length); -This function is used to read [length] number of bytes from the I2C device with the given -I2C address into the [data]. -The [address] passed to this function is the 7-bit slave address, left -shifted by one bit (i.e. 7-bit slave address is `0x2F` -> `(0x2F)<<1` = `0x5E`) - -##### void I2C_stop(void) -This function disables the TWI peripheral completely -and therefore disconnects the device from the bus. -*/ diff --git a/radio/src/targets/mega2560/voice.cpp b/radio/src/targets/mega2560/voice.cpp deleted file mode 100644 index 789b3bf24..000000000 --- a/radio/src/targets/mega2560/voice.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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(VOICE_WTV20) -#include "targets/mega2560/voice_wtv20.cpp" -#elif defined(VOICE_JQ6500) -#include "targets/mega2560/voice_jq6500.cpp" -#endif diff --git a/radio/src/targets/mega2560/voice.h b/radio/src/targets/mega2560/voice.h deleted file mode 100644 index cd23b0936..000000000 --- a/radio/src/targets/mega2560/voice.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ - -#define PROMPT_CUSTOM_BASE 0 -#define PROMPT_I18N_BASE 256 -#define PROMPT_SYSTEM_BASE 480 - -extern void pushPrompt(uint16_t prompt); -extern bool isPlaying(); - -#define I18N_PLAY_FUNCTION(lng, x, ...) void x(__VA_ARGS__) -#define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__) -#define PUSH_CUSTOM_PROMPT(p, id) pushPrompt(PROMPT_CUSTOM_BASE+(p)) -#define PUSH_NUMBER_PROMPT(p) pushPrompt(PROMPT_I18N_BASE+(p)) -#define PUSH_SYSTEM_PROMPT(p) pushPrompt(PROMPT_SYSTEM_BASE+(p)) -#define PLAY_NUMBER(n, u, a) playNumber((n), (u), (a)) -#define PLAY_DURATION(d, att) playDuration((d)) -#define PLAY_DURATION_ATT -#define PLAY_TIME -#define IS_PLAY_TIME() (0) -#define IS_PLAYING(id) isPlaying() -#define PLAY_VALUE(v, id) playValue((v)) - -#define VOLUME_LEVEL_MAX 7 -#define VOLUME_LEVEL_DEF 7 -#define setScaledVolume(v) diff --git a/radio/src/targets/mega2560/voice_jq6500.cpp b/radio/src/targets/mega2560/voice_jq6500.cpp deleted file mode 100644 index a2adb0a1b..000000000 --- a/radio/src/targets/mega2560/voice_jq6500.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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. - */ - -// JQ6500 mp3 module driver -// 6 X 10 (bits) X 104µs = 6.24 mS to send a playfile command - -#include "opentx.h" - -#define QUEUE_LENGTH 16*2 //bytes - -enum JQ6500_State -{ - START = 0x7E, //Start - NUMBY = 0x04, //Num bytes follow - SELEC = 0X03, //Select file - FILEH = 0x00, //Dummy file - FILEL = 0x01, //Dummy file - TERMI = 0xEF //Termination -}; - -JQ6500_State state = START; -uint8_t JQ6500_playlist[QUEUE_LENGTH] = {0}; -volatile uint8_t JQ6500_InputIndex = 0; -uint8_t JQ6500_PlayIndex = 0; - -bool isPlaying() -{ - /* interrupts active on Output Compare A Match ? */ -#if defined(SIMU) - return false; -#else - return (TIMSK5 & (1< no voice - if (g_eeGeneral.beepMode == e_mode_quiet) return; - ++prompt; // With SDformatter, first FAT address = 1 ? Not all th time ?? - /* Load playlist and activate interrupt */ - JQ6500_playlist[JQ6500_InputIndex] = (uint8_t)(prompt >> 8); // MSB first - ++JQ6500_InputIndex; - JQ6500_playlist[JQ6500_InputIndex] = (uint8_t)(prompt & 0xFF); // LSB after - ++JQ6500_InputIndex; - if (JQ6500_InputIndex == QUEUE_LENGTH) JQ6500_InputIndex = 0; - if (!isPlaying()) { - TCNT5=0; - OCR5A = 0xFA; - TIMSK5 |= (1<> (i-1)) & 0x01) { JQ6500_Serial_on;} else { JQ6500_Serial_off;} // send data bits - ++i; - return 0; -} - -#if !defined(SIMU) -ISR(TIMER5_COMPA_vect) // every 104µS -{ - sei(); - - if (state == START) { OCR5A = 0x19; if (JQ6500_BUSY) return; if (JQ6500_sendbyte(state)) { state = NUMBY; return; } } - - if (state == NUMBY) { if (JQ6500_sendbyte(state)) { state = SELEC; return; } } - - if (state == SELEC) { if (JQ6500_sendbyte(state)) { state = FILEH; return; } } - - if (state == FILEH) { if (JQ6500_sendbyte(JQ6500_playlist[JQ6500_PlayIndex])) { ++JQ6500_PlayIndex; state = FILEL; return; } } - - if (state == FILEL) { if (JQ6500_sendbyte(JQ6500_playlist[JQ6500_PlayIndex])) { ++JQ6500_PlayIndex; state = TERMI; return; } } - - if (state == TERMI) { - if (JQ6500_sendbyte(state)) { - state = START; - if (JQ6500_PlayIndex == QUEUE_LENGTH) JQ6500_PlayIndex = 0; - if (JQ6500_PlayIndex == JQ6500_InputIndex) { OCR5A = 0x19; TIMSK5 &= ~(1< no voice - if (g_eeGeneral.beepMode == e_mode_quiet) return; - - /* Load playlist and activate interrupt */ - WTV20_playlist[WTV20_InputIndex] = prompt; - ++WTV20_InputIndex; - if (WTV20_InputIndex == QUEUE_LENGTH) WTV20_InputIndex = 0; - - if (!isPlaying()) { - TIMSK5 |= (1<