1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 20:35:17 +03:00

Mixer code moved to a separate file

This commit is contained in:
bsongis 2014-05-15 11:10:05 +02:00
parent 6bcf5aa651
commit 55ed62e6ac
12 changed files with 1672 additions and 1569 deletions

View file

@ -69,7 +69,7 @@ const uint8_t modn12x3[4][4]= {
{4, 3, 2, 1} };
#define C9X_MAX_MODELS 60
#define C9X_MAX_FLIGHT_MODES 9
#define C9X_MAX_FLIGHT_MODES 9
#define C9X_MAX_MIXERS 64
#define C9X_MAX_INPUTS 32
#define C9X_MAX_EXPOS 64

View file

@ -61,8 +61,10 @@ namespace Open9xGruvin9x {
#include "radio/src/eeprom_common.cpp"
#include "radio/src/eeprom_rlc.cpp"
#include "radio/src/opentx.cpp"
#include "radio/src/strhelpers.cpp"
#include "radio/src/switches.cpp"
#include "radio/src/curves.cpp"
#include "radio/src/mixer.cpp"
#include "radio/src/protocols/pulses_avr.cpp"
#include "radio/src/stamp.cpp"
#include "radio/src/maths.cpp"

View file

@ -60,8 +60,10 @@ namespace Open9xM128 {
#include "radio/src/eeprom_common.cpp"
#include "radio/src/eeprom_rlc.cpp"
#include "radio/src/opentx.cpp"
#include "radio/src/strhelpers.cpp"
#include "radio/src/switches.cpp"
#include "radio/src/curves.cpp"
#include "radio/src/mixer.cpp"
#include "radio/src/protocols/pulses_avr.cpp"
#include "radio/src/stamp.cpp"
#include "radio/src/maths.cpp"

View file

@ -75,7 +75,9 @@ namespace Open9xSky9x {
#include "radio/src/eeprom_raw.cpp"
#include "radio/src/eeprom_conversions.cpp"
#include "radio/src/opentx.cpp"
#include "radio/src/strhelpers.cpp"
#include "radio/src/switches.cpp"
#include "radio/src/mixer.cpp"
#include "radio/src/curves.cpp"
#include "radio/src/targets/sky9x/pulses_driver.cpp"
#include "radio/src/protocols/pulses_arm.cpp"

View file

@ -78,8 +78,10 @@ inline int geteepromsize() {
#include "radio/src/eeprom_conversions.cpp"
#include "radio/src/eeprom_rlc.cpp"
#include "radio/src/opentx.cpp"
#include "radio/src/strhelpers.cpp"
#include "radio/src/switches.cpp"
#include "radio/src/curves.cpp"
#include "radio/src/mixer.cpp"
#include "radio/src/targets/taranis/pulses_driver.cpp"
#include "radio/src/targets/taranis/rtc_driver.cpp"
#include "radio/src/targets/taranis/trainer_driver.cpp"
@ -97,7 +99,6 @@ inline int geteepromsize() {
#include "radio/src/gui/view_text.cpp"
#include "radio/src/gui/view_about.cpp"
#include "radio/src/lcd.cpp"
#include "radio/src/strhelpers.cpp"
#include "radio/src/logs.cpp"
#include "radio/src/rtc.cpp"
#include "radio/src/targets/taranis/keys_driver.cpp"

View file

@ -66,8 +66,10 @@ namespace Open9x {
#include "radio/src/eeprom_common.cpp"
#include "radio/src/eeprom_rlc.cpp"
#include "radio/src/opentx.cpp"
#include "radio/src/strhelpers.cpp"
#include "radio/src/switches.cpp"
#include "radio/src/curves.cpp"
#include "radio/src/mixer.cpp"
#include "radio/src/protocols/pulses_avr.cpp"
#include "radio/src/stamp.cpp"
#include "radio/src/maths.cpp"

View file

@ -759,7 +759,7 @@ else
TTS_SRC = $(shell sh -c "if test -f $(STD_TTS_SRC); then echo $(STD_TTS_SRC); else echo translations/tts_en.cpp; fi")
endif
CPPSRC += opentx.cpp $(PULSESSRC) switches.cpp curves.cpp stamp.cpp gui/menus.cpp gui/menu_model.cpp gui/menu_general.cpp gui/view_main.cpp gui/view_statistics.cpp $(EEPROMSRC) lcd.cpp keys.cpp maths.cpp translations.cpp fonts.cpp $(TTS_SRC)
CPPSRC += opentx.cpp strhelpers.cpp $(PULSESSRC) switches.cpp curves.cpp mixer.cpp stamp.cpp gui/menus.cpp gui/menu_model.cpp gui/menu_general.cpp gui/view_main.cpp gui/view_statistics.cpp $(EEPROMSRC) lcd.cpp keys.cpp maths.cpp translations.cpp fonts.cpp $(TTS_SRC)
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
@ -968,7 +968,7 @@ endif
ifeq ($(SDCARD), YES)
CPPDEFS += -DSDCARD
CPPSRC += logs.cpp strhelpers.cpp
CPPSRC += logs.cpp
endif
RUN_FROM_FLASH = 1

View file

@ -36,6 +36,102 @@
#include "opentx.h"
#if !defined(CPUARM)
// #define CORRECT_NEGATIVE_SHIFTS
// open.20.fsguruh; shift right operations do the rounding different for negative values compared to positive values
// so all negative divisions round always further down, which give absolute values bigger compared to a usual division
// this is noticable on the display, because instead of -100.0 -99.9 is shown; While in praxis I doublt somebody will notice a
// difference this is more a mental thing. Maybe people are distracted, because the easy calculations are obviously wrong
// this define would correct this, but costs 34 bytes code for stock version
// currently we set this to active always, because it might cause a fault about 1% compared positive and negative values
// is done now in makefile
int16_t calc100to256_16Bits(int16_t x) // return x*2.56
{
// y = 2*x + x/2 +x/16-x/512-x/2048
// 512 and 2048 are out of scope from int8 input --> forget it
#ifdef CORRECT_NEGATIVE_SHIFTS
int16_t res=(int16_t)x<<1;
//int8_t sign=(uint8_t) x>>7;
int8_t sign=(x<0?1:0);
x-=sign;
res+=(x>>1);
res+=sign;
res+=(x>>4);
res+=sign;
return res;
#else
return ((int16_t)x<<1)+(x>>1)+(x>>4);
#endif
}
int16_t calc100to256(int8_t x) // return x*2.56
{
return calc100to256_16Bits(x);
}
int16_t calc100toRESX_16Bits(int16_t x) // return x*10.24
{
#ifdef CORRECT_NEGATIVE_SHIFTS
int16_t res= ((int16_t)x*41)>>2;
int8_t sign=(x<0?1:0);
//int8_t sign=(uint8_t) x>>7;
x-=sign;
res-=(x>>6);
res-=sign;
return res;
#else
// return (int16_t)x*10 + x/4 - x/64;
return ((x*41)>>2) - (x>>6);
#endif
}
int16_t calc100toRESX(int8_t x) // return x*10.24
{
return calc100toRESX_16Bits(x);
}
// return x*1.024
int16_t calc1000toRESX(int16_t x) // improve calc time by Pat MacKenzie
{
// return x + x/32 - x/128 + x/512;
int16_t y = x>>5;
x+=y;
y=y>>2;
x-=y;
return x+(y>>2);
}
int16_t calcRESXto1000(int16_t x) // return x/1.024
{
// *1000/1024 = x - x/32 + x/128
return (x - (x>>5) + (x>>7));
}
int8_t calcRESXto100(int16_t x)
{
return (x*25) >> 8;
}
#endif
#if defined(HELI) || defined(FRSKY_HUB)
uint16_t isqrt32(uint32_t n)
{
uint16_t c = 0x8000;
uint16_t g = 0x8000;
for (;;) {
if ((uint32_t)g*g > n)
g ^= c;
c >>= 1;
if(c == 0)
return g;
g |= c;
}
}
#endif
/*
Division by 10 and rounding or fixed point arithmetic values

1389
radio/src/mixer.cpp Executable file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -668,6 +668,15 @@ extern uint8_t s_perout_flight_mode;
#endif
void perOut(uint8_t mode, uint8_t tick10ms);
#if defined(CPUARM)
#define MIX_FUNCTION_RESULT bool
#else
#define MIX_FUNCTION_RESULT void
#endif
MIX_FUNCTION_RESULT doMixerCalculations();
void perMain();
NOINLINE void per10ms();
@ -905,6 +914,8 @@ enum Analogs {
NUMBER_ANALOG
};
void checkBacklight();
#if defined(PCBSTD) && defined(VOICE) && !defined(SIMU)
#define BACKLIGHT_ON() (Voice.Backlight = 1)
#define BACKLIGHT_OFF() (Voice.Backlight = 0)
@ -1095,6 +1106,20 @@ struct CurveInfo {
extern CurveInfo curveInfo(uint8_t idx);
#endif
// static variables used in perOut - moved here so they don't interfere with the stack
// It's also easier to initialize them here.
#if defined(PCBTARANIS)
extern int8_t virtualInputsTrims[NUM_INPUTS];
#else
extern int16_t rawAnas[NUM_INPUTS];
#endif
extern int16_t anas [NUM_INPUTS];
extern int16_t trims[NUM_STICKS];
extern BeepANACenter bpanaCenter;
extern bool s_mixer_first_run_done;
extern int8_t s_currCh;
uint8_t getExpoMixCount(uint8_t expo);
void deleteExpoMix(uint8_t expo, uint8_t idx);
@ -1103,9 +1128,12 @@ void applyDefaultTemplate();
void incSubtrim(uint8_t idx, int16_t inc);
void instantTrim();
FORCEINLINE void evalTrims();
void copyTrimsToOffset(uint8_t ch);
void moveTrimsToOffsets();
void evalFunctions();
#if defined(CPUARM)
#define ACTIVE_PHASES_TYPE uint16_t
#define DELAY_POS_SHIFT 0

View file

@ -1,5 +1,149 @@
#include <stdlib.h>
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* 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"
const pm_char s_charTab[] PROGMEM = "_-.,";
char idx2char(int8_t idx)
{
if (idx == 0) return ' ';
if (idx < 0) {
if (idx > -27) return 'a' - idx - 1;
idx = -idx;
}
if (idx < 27) return 'A' + idx - 1;
if (idx < 37) return '0' + idx - 27;
if (idx <= 40) return pgm_read_byte(s_charTab+idx-37);
#if LEN_SPECIAL_CHARS > 0
if (idx <= ZCHAR_MAX) return 'z' + 5 + idx - 40;
#endif
return ' ';
}
#if defined(CPUARM) || defined(SIMU)
int8_t char2idx(char c)
{
if (c == '_') return 37;
#if LEN_SPECIAL_CHARS > 0
if (c < 0 && c+128 <= LEN_SPECIAL_CHARS) return 41 + (c+128);
#endif
if (c >= 'a') return 'a' - c - 1;
if (c >= 'A') return c - 'A' + 1;
if (c >= '0') return c - '0' + 27;
if (c == '-') return 38;
if (c == '.') return 39;
if (c == ',') return 40;
return 0;
}
void str2zchar(char *dest, const char *src, int size)
{
memset(dest, 0, size);
for (int c=0; c<size && src[c]; c++) {
dest[c] = char2idx(src[c]);
}
}
void zchar2str(char *dest, const char *src, int size)
{
for (int c=0; c<size; c++) {
dest[c] = idx2char(src[c]);
}
do {
dest[size--] = '\0';
} while (size >= 0 && dest[size] == ' ');
}
#endif
#if defined(CPUARM)
bool zexist(const char *str, uint8_t size)
{
for (int i=0; i<size; i++) {
if (str[i] != 0)
return true;
}
return false;
}
uint8_t zlen(const char *str, uint8_t size)
{
while (size > 0) {
if (str[size-1] != 0)
return size;
size--;
}
return size;
}
char * strcat_zchar(char * dest, char * name, uint8_t size, const char *defaultName, uint8_t defaultNameSize, uint8_t defaultIdx)
{
int8_t len = 0;
if (name) {
memcpy(dest, name, size);
dest[size] = '\0';
int8_t i = size-1;
while (i>=0) {
if (!len && dest[i])
len = i+1;
if (len) {
if (dest[i])
dest[i] = idx2char(dest[i]);
else
dest[i] = '_';
}
i--;
}
}
if (len == 0 && defaultName) {
strcpy(dest, defaultName);
dest[defaultNameSize] = (char)((defaultIdx / 10) + '0');
dest[defaultNameSize + 1] = (char)((defaultIdx % 10) + '0');
len = defaultNameSize + 2;
}
return &dest[len];
}
#endif
#if defined(CPUARM) || defined(SDCARD)
char * strAppend(char * dest, const char * source)
{
while ((*dest++ = *source++))
@ -52,5 +196,5 @@ char * strAppendDate(char * str, bool time)
return &str[11];
}
}
#endif
#endif