avr-remove remove files in main dir and targets
This commit is contained in:
@@ -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)
|
||||
@@ -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<<MUX5);
|
||||
ADMUX = 0x03|ADC_VREF_TYPE; // Switch MUX to internal reference
|
||||
#elif defined(PCBMEGA2560)
|
||||
#else
|
||||
ADMUX = 0x1E|ADC_VREF_TYPE; // Switch MUX to internal reference
|
||||
#endif
|
||||
}
|
||||
|
||||
void getADC()
|
||||
{
|
||||
for (uint8_t adc_input=0; adc_input<8; adc_input++) {
|
||||
uint16_t temp_ana;
|
||||
ADMUX = adc_input|ADC_VREF_TYPE;
|
||||
ADCSRA |= 1 << ADSC; // Start the AD conversion
|
||||
while (ADCSRA & (1 << ADSC)); // Wait for the AD conversion to complete
|
||||
temp_ana = ADC;
|
||||
ADCSRA |= 1 << ADSC; // Start the second AD conversion
|
||||
while (ADCSRA & (1 << ADSC)); // Wait for the AD conversion to complete
|
||||
temp_ana += ADC;
|
||||
s_anaFilt[adc_input] = temp_ana;
|
||||
}
|
||||
|
||||
#if defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED)
|
||||
processMultiplexAna();
|
||||
#endif
|
||||
}
|
||||
|
||||
void getADC_bandgap()
|
||||
{
|
||||
#if defined(PCBGRUVIN9X)
|
||||
static uint8_t s_bgCheck = 0;
|
||||
static uint16_t s_bgSum = 0;
|
||||
ADCSRA |= (1 << ADSC); // request sample
|
||||
s_bgCheck += 32;
|
||||
while ((ADCSRA & (1 << ADIF))==0); // wait for sample
|
||||
ADCSRA |= (1 << ADIF);
|
||||
if (s_bgCheck == 0) { // 8x over-sample (256/32=8)
|
||||
BandGap = s_bgSum+ADC;
|
||||
s_bgSum = 0;
|
||||
}
|
||||
else {
|
||||
s_bgSum += ADC;
|
||||
}
|
||||
ADCSRB |= (1 << MUX5);
|
||||
#elif defined(PCBMEGA2560)
|
||||
BandGap = 2000;
|
||||
#else
|
||||
/*
|
||||
MCUCR|=0x28; // enable Sleep (bit5) enable ADC Noise Reduction (bit2)
|
||||
asm volatile(" sleep \n\t"); // if _SLEEP() is not defined use this
|
||||
// ADCSRA|=0x40;
|
||||
while ((ADCSRA & 0x10)==0);
|
||||
ADCSRA|=0x10; // take sample clear flag?
|
||||
BandGap=ADC;
|
||||
MCUCR&=0x08; // disable sleep
|
||||
*/
|
||||
|
||||
ADCSRA |= (1 << ADSC);
|
||||
while (ADCSRA & (1 << ADSC));
|
||||
BandGap = ADC;
|
||||
#endif
|
||||
}
|
||||
@@ -1,249 +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.
|
||||
*/
|
||||
|
||||
#if defined(SIMU)
|
||||
extern volatile unsigned char pina, pinb, pinc, pind, pine, pinf, ping, pinh, pinj, pinl;
|
||||
#define PINA ~pina
|
||||
#define PINB ~pinb
|
||||
#define PINC ~pinc
|
||||
#define PIND ~pind
|
||||
#define PINE ~pine
|
||||
#define PINF ~pinf
|
||||
#define PING ~ping
|
||||
#define PINH ~pinh
|
||||
#define PINJ ~pinj
|
||||
#define PINL ~pinl
|
||||
#else
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "pgmtypes.h"
|
||||
#include <avr/eeprom.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/interrupt.h>
|
||||
#define F_CPU 16000000UL // 16 MHz
|
||||
#include <util/delay.h>
|
||||
#define pgm_read_adr(address_short) pgm_read_word(address_short)
|
||||
#include <avr/wdt.h>
|
||||
#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();
|
||||
@@ -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<<EEMPE;
|
||||
EECR |= 1<<EEPE;
|
||||
#else
|
||||
EECR |= 1<<EEMWE;
|
||||
EECR |= 1<<EEWE;
|
||||
#endif
|
||||
eeprom_pointer++;
|
||||
eeprom_buffer_data++;
|
||||
}
|
||||
|
||||
ISR(EE_READY_vect)
|
||||
{
|
||||
if (--eeprom_buffer_size > 0) {
|
||||
eeprom_write_byte();
|
||||
}
|
||||
else {
|
||||
#if defined(CPUM2560) || defined(CPUM2561)
|
||||
EECR &= ~(1<<EERIE);
|
||||
#else
|
||||
EECR &= ~(1<<EERIE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
assert(eeprom_buffer_size == 0);
|
||||
|
||||
eeprom_pointer = address;
|
||||
eeprom_buffer_data = buffer;
|
||||
eeprom_buffer_size = size+1;
|
||||
|
||||
#if defined (CPUM2560) || defined(CPUM2561)
|
||||
EECR |= (1<<EERIE);
|
||||
#else
|
||||
EECR |= (1<<EERIE);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t eepromIsTransferComplete()
|
||||
{
|
||||
return eeprom_buffer_size == 0;
|
||||
}
|
||||
|
||||
void eepromWriteBlock(uint8_t * buffer, size_t address, size_t size)
|
||||
{
|
||||
eepromStartWrite(buffer, address, size);
|
||||
|
||||
if (s_sync_write) {
|
||||
while (!eepromIsTransferComplete()) {
|
||||
wdt_reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,267 +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(TELEMETRY_FRSKY) || defined(TELEMETRY_MAVLINK)
|
||||
|
||||
// KEEP IN SYNC WITH GUI
|
||||
enum SERIAL_BAUDS
|
||||
{
|
||||
BAUD_4800 = 0,
|
||||
BAUD_9600,
|
||||
BAUD_14400,
|
||||
BAUD_19200,
|
||||
BAUD_38400,
|
||||
BAUD_57600,
|
||||
BAUD_58798,
|
||||
BAUD_76800
|
||||
};
|
||||
|
||||
void telemetryEnableTx(void)
|
||||
{
|
||||
UCSRB_N(TLM_USART) |= (1 << TXEN_N(TLM_USART)); // enable TX
|
||||
}
|
||||
|
||||
void telemetryEnableRx(void)
|
||||
{
|
||||
UCSRB_N(TLM_USART) |= (1 << RXEN_N(TLM_USART)); // enable RX
|
||||
UCSRB_N(TLM_USART) |= (1 << RXCIE_N(TLM_USART)); // enable Interrupt
|
||||
}
|
||||
|
||||
void processTelemetryData(uint8_t data);
|
||||
extern uint8_t telemetryRxBufferCount;
|
||||
|
||||
ISR(USART_RX_vect_N(TLM_USART))
|
||||
{
|
||||
uint8_t stat;
|
||||
uint8_t data;
|
||||
|
||||
UCSRB_N(TLM_USART) &= ~(1 << RXCIE_N(TLM_USART)); // disable Interrupt
|
||||
sei();
|
||||
|
||||
stat = UCSRA_N(TLM_USART); // USART control and Status Register 0/1 A
|
||||
|
||||
/*
|
||||
bit 7 6 5 4 3 2 1 0
|
||||
RxC0 TxC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0
|
||||
|
||||
RxC0: Receive complete
|
||||
TXC0: Transmit Complete
|
||||
UDRE0: USART Data Register Empty
|
||||
FE0: Frame Error
|
||||
DOR0: Data OverRun
|
||||
UPE0: USART Parity Error
|
||||
U2X0: Double Tx Speed
|
||||
PCM0: MultiProcessor Comms Mode
|
||||
*/
|
||||
// rh = UCSRB_N(TLM_USART); //USART control and Status Register 0/1 B
|
||||
|
||||
/*
|
||||
bit 7 6 5 4 3 2 1 0
|
||||
RXCIE0 TxCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80
|
||||
|
||||
RxCIE0: Receive Complete int enable
|
||||
TXCIE0: Transmit Complete int enable
|
||||
UDRIE0: USART Data Register Empty int enable
|
||||
RXEN0: Rx Enable
|
||||
TXEN0: Tx Enable
|
||||
UCSZ02: Character Size bit 2
|
||||
RXB80: Rx data bit 8
|
||||
TXB80: Tx data bit 8
|
||||
*/
|
||||
|
||||
data = UDR_N(TLM_USART); // USART data register 0
|
||||
|
||||
if (stat & ((1 << FE_N(TLM_USART)) | (1 << DOR_N(TLM_USART)) | (1 << UPE_N(TLM_USART)))) {
|
||||
// discard buffer and start fresh on any comms error
|
||||
telemetryRxBufferCount = 0;
|
||||
}
|
||||
else {
|
||||
processTelemetryData(data);
|
||||
}
|
||||
|
||||
cli() ;
|
||||
UCSRB_N(TLM_USART) |= (1 << RXCIE_N(TLM_USART)); // enable Interrupt
|
||||
}
|
||||
|
||||
static void uart_4800(void)
|
||||
{
|
||||
#undef BAUD
|
||||
#define BAUD 4800
|
||||
#include <util/setbaud.h>
|
||||
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 <util/setbaud.h>
|
||||
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 <util/setbaud.h>
|
||||
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 <util/setbaud.h>
|
||||
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 <util/setbaud.h>
|
||||
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 <util/setbaud.h>
|
||||
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 <util/setbaud.h>
|
||||
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
|
||||
Reference in New Issue
Block a user