Directories moved
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
option(TIMERS "Timers count" 2)
|
||||
option(CLI "Command Line Interface" OFF)
|
||||
option(DEBUG "Debug mode" OFF)
|
||||
option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF)
|
||||
option(TRACE_SD_CARD "Traces SD enabled" OFF)
|
||||
option(TRACE_FATFS "Traces FatFS enabled" OFF)
|
||||
option(TRACE_AUDIO "Traces audio enabled" OFF)
|
||||
option(DEBUG_TRACE_BUFFER "Debug Trace Screen" OFF)
|
||||
option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" OFF)
|
||||
option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY
|
||||
option(DEBUG_INTERRUPTS "Count interrupts" OFF)
|
||||
option(DEBUG_TASKS "Task switching statistics" OFF)
|
||||
option(DEBUG_TIMERS "Time critical parts of the code" OFF)
|
||||
|
||||
if(TIMERS EQUAL 3)
|
||||
add_definitions(-DTIMERS=3)
|
||||
else()
|
||||
add_definitions(-DTIMERS=2)
|
||||
endif()
|
||||
if(LOG_TELEMETRY)
|
||||
add_definitions(-DLOG_TELEMETRY)
|
||||
endif()
|
||||
if(TRACE_SD_CARD)
|
||||
add_definitions(-DTRACE_SD_CARD)
|
||||
set(DEBUG ON)
|
||||
set(DEBUG_TRACE_BUFFER ON)
|
||||
endif()
|
||||
if(TRACE_FATFS)
|
||||
add_definitions(-DTRACE_FATFS)
|
||||
set(DEBUG ON)
|
||||
set(DEBUG_TRACE_BUFFER ON)
|
||||
endif()
|
||||
if(TRACE_AUDIO)
|
||||
add_definitions(-DTRACE_AUDIO)
|
||||
set(DEBUG ON)
|
||||
set(DEBUG_TRACE_BUFFER ON)
|
||||
endif()
|
||||
if(DEBUG_TRACE_BUFFER)
|
||||
add_definitions(-DDEBUG_TRACE_BUFFER)
|
||||
endif()
|
||||
if(DEBUG_INTERRUPTS)
|
||||
add_definitions(-DDEBUG_INTERRUPTS)
|
||||
set(DEBUG ON)
|
||||
endif()
|
||||
if(DEBUG_TASKS)
|
||||
add_definitions(-DDEBUG_TASKS)
|
||||
set(DEBUG ON)
|
||||
endif()
|
||||
if(DEBUG_TIMERS)
|
||||
add_definitions(-DDEBUG_TIMERS)
|
||||
set(DEBUG ON)
|
||||
endif()
|
||||
if(CLI)
|
||||
add_definitions(-DCLI)
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} cli.cpp)
|
||||
set(SRC ${SRC} dump.cpp)
|
||||
elseif(DEBUG)
|
||||
set(SRC ${SRC} dump.cpp)
|
||||
endif()
|
||||
if(DEBUG)
|
||||
add_definitions(-DDEBUG)
|
||||
endif()
|
||||
if(SUPPORT_D16_EU_ONLY)
|
||||
add_definitions(-DMODULE_D16_EU_ONLY_SUPPORT)
|
||||
endif()
|
||||
if(HAPTIC)
|
||||
add_definitions(-DHAPTIC)
|
||||
set(SRC ${SRC} haptic.cpp)
|
||||
set(TARGET_SRC ${TARGET_SRC} haptic_driver.cpp)
|
||||
endif()
|
||||
if(MULTIMODULE)
|
||||
add_definitions(-DMULTIMODULE)
|
||||
set(SRC ${SRC} pulses/multi_arm.cpp telemetry/spektrum.cpp)
|
||||
endif()
|
||||
add_definitions(-DCPUARM)
|
||||
add_definitions(-DFRSKY -DFRSKY_SPORT -DFRSKY_HUB -DGPS -DPXX -DDSM2)
|
||||
add_definitions(-DBOLD_FONT -DBATTGRAPH -DTHRTRACE)
|
||||
include_directories(targets/${TARGET_DIR} ${THIRDPARTY_DIR})
|
||||
include_directories(${COOS_DIR} ${COOS_DIR}/kernel ${COOS_DIR}/portable)
|
||||
foreach(LANGUAGE ${TTS_LANGUAGES})
|
||||
set(SRC ${SRC} translations/tts_${LANGUAGE}.cpp)
|
||||
endforeach()
|
||||
set(SRC
|
||||
${SRC}
|
||||
main_arm.cpp
|
||||
tasks_arm.cpp
|
||||
audio_arm.cpp
|
||||
telemetry/telemetry.cpp
|
||||
telemetry/telemetry_holders.cpp
|
||||
telemetry/telemetry_sensors.cpp
|
||||
telemetry/frsky.cpp
|
||||
telemetry/frsky_d_arm.cpp
|
||||
telemetry/frsky_sport.cpp
|
||||
crc16.cpp
|
||||
vario.cpp
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
diskio.cpp
|
||||
)
|
||||
set(TARGET_SRC
|
||||
${TARGET_SRC}
|
||||
pulses_driver.cpp
|
||||
keys_driver.cpp
|
||||
adc_driver.cpp
|
||||
trainer_driver.cpp
|
||||
audio_driver.cpp
|
||||
serial2_driver.cpp
|
||||
telemetry_driver.cpp
|
||||
)
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
${COOS_DIR}/kernel/core.c
|
||||
${COOS_DIR}/kernel/hook.c
|
||||
${COOS_DIR}/kernel/task.c
|
||||
${COOS_DIR}/kernel/event.c
|
||||
${COOS_DIR}/kernel/time.c
|
||||
${COOS_DIR}/kernel/timer.c
|
||||
${COOS_DIR}/kernel/flag.c
|
||||
${COOS_DIR}/kernel/mutex.c
|
||||
${COOS_DIR}/kernel/serviceReq.c
|
||||
${COOS_DIR}/portable/GCC/port.c
|
||||
${COOS_DIR}/portable/arch.c
|
||||
)
|
||||
set(PULSES_SRC
|
||||
${PULSES_SRC}
|
||||
pulses_arm.cpp
|
||||
ppm_arm.cpp
|
||||
pxx_arm.cpp
|
||||
dsm2_arm.cpp
|
||||
)
|
||||
@@ -0,0 +1,87 @@
|
||||
set(LUA "NO" CACHE STRING "Lua scripts (YES/NO/NO_MODEL_SCRIPTS)")
|
||||
set(USB "JOYSTICK" CACHE STRING "USB option (JOYSTICK/MASSSTORAGE/SERIAL)")
|
||||
set(ARCH ARM)
|
||||
set(STM32USB_DIR ${THIRDPARTY_DIR}/STM32_USB-Host-Device_Lib_V2.1.0/Libraries)
|
||||
add_definitions(-DCPUSTM32)
|
||||
add_definitions(-DSBUS -DCROSSFIRE)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_OTG_Driver/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Core/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/hid/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/cdc/inc)
|
||||
set(STM32USB_SRC
|
||||
STM32_USB_OTG_Driver/src/usb_core.c
|
||||
STM32_USB_OTG_Driver/src/usb_dcd.c
|
||||
STM32_USB_OTG_Driver/src/usb_dcd_int.c
|
||||
STM32_USB_Device_Library/Core/src/usbd_core.c
|
||||
STM32_USB_Device_Library/Core/src/usbd_ioreq.c
|
||||
STM32_USB_Device_Library/Core/src/usbd_req.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
usb_bsp.c
|
||||
usbd_desc.c
|
||||
usbd_usr.cpp
|
||||
)
|
||||
if(USB STREQUAL SERIAL)
|
||||
add_definitions(-DUSB_SERIAL)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
usbd_cdc.cpp
|
||||
)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
|
||||
)
|
||||
elseif(USB STREQUAL MASSSTORAGE)
|
||||
add_definitions(-DUSB_MASS_STORAGE)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
usbd_storage_msd.cpp
|
||||
)
|
||||
else()
|
||||
add_definitions(-DUSB_JOYSTICK)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
usbd_hid_joystick.c
|
||||
)
|
||||
endif()
|
||||
if(GVARS)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
menu_model_gvars.cpp
|
||||
)
|
||||
endif()
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
serial.cpp
|
||||
syscalls.c
|
||||
)
|
||||
foreach(FILE ${STM32LIB_SRC})
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
${STM32LIB_DIR}/${FILE}
|
||||
)
|
||||
endforeach()
|
||||
foreach(FILE ${STM32USB_SRC})
|
||||
set(FIRMWARE_SRC
|
||||
${FIRMWARE_SRC}
|
||||
${STM32USB_DIR}/${FILE}
|
||||
)
|
||||
endforeach()
|
||||
set(SRC
|
||||
${SRC}
|
||||
sbus.cpp
|
||||
telemetry/crossfire.cpp
|
||||
)
|
||||
set(PULSES_SRC
|
||||
${PULSES_SRC}
|
||||
crossfire.cpp
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
set(CPU_FAMILY STM32)
|
||||
set(MCU cortex-m3)
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries)
|
||||
include_directories(${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/inc)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Device/ST/STM32F2xx/Include)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/include)
|
||||
set(STM32LIB_SRC
|
||||
${STM32LIB_SRC}
|
||||
CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
|
||||
STM32F2xx_StdPeriph_Driver/src/misc.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dbgmcu.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_i2c.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dma.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rtc.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} system_stm32f2xx.c)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
set(CPU_FAMILY STM32)
|
||||
set(MCU cortex-m4)
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries)
|
||||
include_directories(${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/inc)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Device/ST/STM32F4xx/Include)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/include)
|
||||
add_definitions(-DSTM32F4)
|
||||
set(STM32LIB_SRC
|
||||
${STM32LIB_SRC}
|
||||
STM32F4xx_StdPeriph_Driver/src/misc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dbgmcu.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_i2c.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rtc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_pwr.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} system_stm32f4xx.c)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
option(EXT "Telemetry protocol" OFF) # TODO rename this EXT option to TELEMETRY
|
||||
option(AUDIO "Audio support" OFF)
|
||||
option(VOICE "Voice support" OFF)
|
||||
option(GRAPHICS "Additional graphics" ON)
|
||||
option(BOLD "Bold font" ON)
|
||||
option(BATTGRAPH "Battery graph" OFF)
|
||||
option(HAPTIC "Haptic support" OFF)
|
||||
set(TTS "EN" CACHE STRING "TTS language")
|
||||
set(LCD "DEFAULT" CACHE STRING "LCD type (DEFAULT/ST7565P/ST7565R/ERC12864FSF/ST7920/KS108)")
|
||||
set(DSM2 "NO" CACHE STRING "LCD type (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)
|
||||
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)
|
||||
add_definitions(-DVOICE)
|
||||
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(${EXT} STREQUAL OFF)
|
||||
add_definitions(-DEXTSTD)
|
||||
elseif(EXT STREQUAL ARDUPILOT)
|
||||
add_definitions(-DARDUPILOT)
|
||||
set(SRC ${SRC} telemetry/ardupilot.cpp)
|
||||
elseif(EXT STREQUAL NMEA)
|
||||
add_definitions(-DNMEA)
|
||||
set(SRC ${SRC} telemetry/nmea.cpp)
|
||||
elseif(EXT STREQUAL JETI)
|
||||
add_definitions(-DJETI)
|
||||
set(SRC ${SRC} telemetry/jeti.cpp)
|
||||
elseif(EXT STREQUAL MAVLINK)
|
||||
add_definitions(-DMAVLINK)
|
||||
include_directories(${THIRDPARTY_DIR} gui/${GUI_DIR} targets/common/avr)
|
||||
set(SRC ${SRC} telemetry/mavlink.cpp targets/common/avr/serial_driver.cpp)
|
||||
set(GUI_SRC ${GUI_SRC} view_mavlink.cpp)
|
||||
math(EXPR EEPROM_VARIANT ${EEPROM_VARIANT}+${MAVLINK_VARIANT})
|
||||
elseif(EXT STREQUAL TELEMETREZ)
|
||||
add_definitions(-DTELEMETREZ)
|
||||
set(SRC ${SRC} telemetry/jeti.cpp)
|
||||
elseif(EXT STREQUAL FRSKY_SPORT)
|
||||
add_definitions(-DFRSKY_SPORT)
|
||||
set(SRC ${SRC} crc16.cpp telemetry/frsky_sport.cpp)
|
||||
endif()
|
||||
if(EXT STREQUAL FRSKY OR EXT STREQUAL FRSKY_SPORT OR EXT 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(-DFRSKY)
|
||||
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)
|
||||
if(EEPROM_VARIANT_NEEDED)
|
||||
add_definitions(-DEEPROM_VARIANT=${EEPROM_VARIANT})
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// ADC driver
|
||||
enum Analogs {
|
||||
STICK1,
|
||||
STICK2,
|
||||
STICK3,
|
||||
STICK4,
|
||||
POT1,
|
||||
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,
|
||||
NUMBER_ANALOG
|
||||
};
|
||||
void adcInit();
|
||||
void adcPrepareBandgap();
|
||||
void getADC();
|
||||
void getADC_bandgap();
|
||||
|
||||
// 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 telemetryTransmitBuffer();
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* 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 "serial_driver.h"
|
||||
#include "opentx.h"
|
||||
|
||||
/*
|
||||
Receive serial (RS-232) characters, detecting and storing each Fr-Sky
|
||||
0x7e-framed packet as it arrives. When a complete packet has been
|
||||
received, process its data into storage variables. NOTE: This is an
|
||||
interrupt routine and should not get too lengthy. I originally had
|
||||
the buffer being checked in the perMain function (because per10ms
|
||||
isn't quite often enough for data streaming at 9600baud) but alas
|
||||
that scheme lost packets also. So each packet is parsed as it arrives,
|
||||
directly at the ISR function (through a call to frskyProcessPacket).
|
||||
|
||||
If this proves a problem in the future, then I'll just have to implement
|
||||
a second buffer to receive data while one buffer is being processed (slowly).
|
||||
*/
|
||||
|
||||
#ifndef SIMU
|
||||
ISR (USART0_RX_vect)
|
||||
{
|
||||
uint8_t iostat; //USART control and Status Register 0 A
|
||||
// uint8_t rh; //USART control and Status Register 0 B
|
||||
UCSR0B &= ~(1 << RXCIE0); // disable Interrupt
|
||||
sei();
|
||||
iostat = UCSR0A; //USART control and Status Register 0 A
|
||||
uint8_t byte = UDR0;
|
||||
|
||||
/*
|
||||
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
|
||||
MPCM0: MultiProcessor Comms Mode
|
||||
*/
|
||||
if (iostat & ((1 << FE0) | (1 << DOR0) | (1 << UPE0))) {
|
||||
byte = 0;
|
||||
}
|
||||
//rh = UCSR0B; //USART control and Status Register 0 B
|
||||
#ifdef MAVLINK
|
||||
(RXHandler)(byte);
|
||||
#endif
|
||||
|
||||
cli();
|
||||
UCSR0B |= (1 << RXCIE0); // enable Interrupt
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void SERIAL_EnableRXD(void) {
|
||||
UCSR0B |= (1 << RXEN0); // enable RX
|
||||
UCSR0B |= (1 << RXCIE0); // enable Interrupt
|
||||
}
|
||||
|
||||
#if 0
|
||||
void SERIAL_DisableRXD(void) {
|
||||
UCSR0B &= ~(1 << RXEN0); // disable RX
|
||||
UCSR0B &= ~(1 << RXCIE0); // disable Interrupt
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
USART0 (transmit) Data Register Emtpy ISR
|
||||
Usef to transmit FrSky data packets, which are buffered in frskyTXBuffer.
|
||||
*/
|
||||
uint8_t serialTxBuffer[MAX_TX_BUFFER]; // 32 characters
|
||||
uint8_t serialTxBufferCount = 0;
|
||||
uint8_t * ptrTxISR = 0;
|
||||
serial_tx_state_t serialTxState = TX_STATE_EMPTY;
|
||||
|
||||
#ifndef SIMU
|
||||
ISR(USART0_UDRE_vect)
|
||||
{
|
||||
if (serialTxBufferCount > 0) {
|
||||
UDR0 = *ptrTxISR++;
|
||||
serialTxBufferCount--;
|
||||
} else {
|
||||
UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt
|
||||
serialTxState = TX_STATE_EMPTY;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void SERIAL_start_uart_send() {
|
||||
ptrTxISR = serialTxBuffer;
|
||||
serialTxBufferCount = 0;
|
||||
}
|
||||
|
||||
void SERIAL_end_uart_send() {
|
||||
ptrTxISR = serialTxBuffer;
|
||||
//UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
|
||||
serialTxState = TX_STATE_READY;
|
||||
}
|
||||
|
||||
void SERIAL_send_uart_bytes(const uint8_t * buf, uint16_t len) {
|
||||
while (len--) {
|
||||
*ptrTxISR++ = *buf++;
|
||||
serialTxBufferCount++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
void SERIAL_transmitBuffer(uint8_t len) {
|
||||
serialTxBufferCount = len;
|
||||
ptrTxISR = serialTxBuffer;
|
||||
//UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
|
||||
serialTxState = TX_STATE_READY;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SERIAL_startTX(void) {
|
||||
if (serialTxState == TX_STATE_READY) {
|
||||
serialTxState = TX_STATE_BUSY;
|
||||
UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
|
||||
}
|
||||
}
|
||||
|
||||
static void uart_4800(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 4800
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_9600(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 9600
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_14400(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 14400
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_19200(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 19200
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_38400(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 38400
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_57600(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 57600
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void uart_76800(void) {
|
||||
#ifndef SIMU
|
||||
#undef BAUD // avoid compiler warning
|
||||
#define BAUD 76800
|
||||
#include <util/setbaud.h>
|
||||
UBRR0H = UBRRH_VALUE;
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
#if USE_2X
|
||||
UCSR0A |= (1 << U2X0);
|
||||
#else
|
||||
UCSR0A &= ~(1 << U2X0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void SERIAL_EnableTXD(void) {
|
||||
//UCSR0B |= (1 << TXEN0); // enable TX
|
||||
UCSR0B |= (1 << TXEN0) | (1 << UDRIE0); // enable TX and TX interrupt
|
||||
}
|
||||
|
||||
#if 0
|
||||
void SERIAL_DisableTXD(void) {
|
||||
UCSR0B &= ~(1 << TXEN0); // disable TX
|
||||
UCSR0B &= ~(1 << UDRIE0); // disable Interrupt
|
||||
}
|
||||
#endif
|
||||
|
||||
void SERIAL_Init(void) {
|
||||
DDRE &= ~(1 << DDE0); // set RXD0 pin as input
|
||||
PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin
|
||||
|
||||
switch (g_eeGeneral.mavbaud) {
|
||||
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_57600:
|
||||
uart_57600();
|
||||
break;
|
||||
case BAUD_76800:
|
||||
uart_76800();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// UCSR0A &= ~(1 << U2X0); // disable double speed operation
|
||||
// set 8N1
|
||||
UCSR0B = 0 | (0 << RXCIE0) | (0 << TXCIE0) | (0 << UDRIE0) | (0 << RXEN0) | (0 << TXEN0) | (0 << UCSZ02);
|
||||
UCSR0C = 0 | (1 << UCSZ01) | (1 << UCSZ00);
|
||||
while (UCSR0A & (1 << RXC0))
|
||||
UDR0; // flush receive buffer
|
||||
|
||||
SERIAL_EnableTXD();
|
||||
SERIAL_EnableRXD();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 _SERIAL_DRIVER_H_
|
||||
#define _SERIAL_DRIVER_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef enum serial_tx_state_ {
|
||||
TX_STATE_EMPTY = 0, //
|
||||
TX_STATE_READY, //
|
||||
TX_STATE_BUSY
|
||||
} serial_tx_state_t;
|
||||
extern serial_tx_state_t serialTxState;
|
||||
|
||||
//! \brief Baudrate selection.
|
||||
enum SERIAL_BAUDS {
|
||||
BAUD_4800 = 0,
|
||||
BAUD_9600,
|
||||
BAUD_14400,
|
||||
BAUD_19200,
|
||||
BAUD_38400,
|
||||
BAUD_57600,
|
||||
BAUD_76800
|
||||
};
|
||||
|
||||
//! \brief Definition of baudrate settings item choices.
|
||||
typedef void (*SerialFuncP)(uint8_t event);
|
||||
|
||||
extern SerialFuncP RXHandler;
|
||||
|
||||
#define MAX_TX_BUFFER 32
|
||||
//#if 0
|
||||
extern uint8_t serialTxBuffer[MAX_TX_BUFFER]; // 32 characters
|
||||
extern uint8_t serialTxBufferCount;
|
||||
extern uint8_t * ptrTxISR;
|
||||
//#endif
|
||||
|
||||
void SERIAL_Init(void);
|
||||
//void SERIAL_transmitBuffer(uint8_t len);
|
||||
extern void SERIAL_start_uart_send();
|
||||
extern void SERIAL_end_uart_send();
|
||||
extern void SERIAL_send_uart_bytes(uint8_t * buf, uint16_t len);
|
||||
|
||||
void SERIAL_startTX(void);
|
||||
#define IS_TX_BUSY (serialTxState!=TX_STATE_EMPTY)
|
||||
|
||||
#endif // _SERIAL_DRIVER_H_
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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(FRSKY)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
processFrskyTelemetryData(data);
|
||||
}
|
||||
|
||||
cli() ;
|
||||
UCSRB_N(TLM_USART) |= (1 << RXCIE_N(TLM_USART)); // enable Interrupt
|
||||
}
|
||||
|
||||
void telemetryPortInit()
|
||||
{
|
||||
#if !defined(SIMU)
|
||||
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
|
||||
|
||||
#undef BAUD
|
||||
#define BAUD 9600
|
||||
#include <util/setbaud.h>
|
||||
|
||||
UBRRH_N(TLM_USART) = UBRRH_VALUE;
|
||||
UBRRL_N(TLM_USART) = UBRRL_VALUE;
|
||||
UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation.
|
||||
|
||||
// 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.
|
||||
telemetryEnableTx(); // enable FrSky-Telemetry emission
|
||||
frskyTxBufferCount = 0; // TODO not driver code
|
||||
|
||||
telemetryEnableRx(); // enable FrSky-Telemetry reception
|
||||
#endif
|
||||
}
|
||||
|
||||
void telemetryTransmitBuffer()
|
||||
{
|
||||
UCSRB_N(TLM_USART) |= (1 << UDRIE_N(TLM_USART)); // enable UDRE1 interrupt
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user