From 094ad2a537946d68ecfcaec5d4fdf3b6996e181c Mon Sep 17 00:00:00 2001 From: qba667 Date: Mon, 11 Dec 2017 19:43:51 +0100 Subject: [PATCH] Turnigy TGY-CAT01 implemented. --- source/MKL16Z64xxx4_flash.ld | 23 ++-- source/build/makefile | 34 ++--- source/source/alt.c | 253 +++++++++++++++++++++-------------- source/source/alt.h | 86 ++++-------- source/source/flysky.h | 4 + source/source/main.c | 22 ++- source/source/mod.h | 53 +++++--- 7 files changed, 258 insertions(+), 217 deletions(-) diff --git a/source/MKL16Z64xxx4_flash.ld b/source/MKL16Z64xxx4_flash.ld index 3422ee6..a7cdb79 100644 --- a/source/MKL16Z64xxx4_flash.ld +++ b/source/MKL16Z64xxx4_flash.ld @@ -123,11 +123,9 @@ SECTIONS *(.mod_timerValue); *(.mod_ticks100ms); *(.mod_lastTimerUpdate); - *(.mod_altconstVal); - *(.mod_altinitPressure); - *(.mod_altinitPressureRaw); - *(.mod_auxMem*) + *(.mod_altSensorMemory); *(.mod_varioMem); + *(.mod_altSensorMemory); KEEP(*(.AUX_MEM)) } > m_data @@ -172,12 +170,17 @@ SECTIONS *(.mod_sensorsScreens); *(.mod_timerFormat); *(.mod_armed); + *(.mod_defASL); } .reserved_main 0x2800: { KEEP(*(.reserved_main)) } + .mod_beep_silent 0x9C3C : { + *(.mod_beep_silent); + } + /*calls from FW to C code*/ .mod_configurePins_ASM 0xC0D2 : { *(.mod_configurePins_ASM); @@ -257,7 +260,6 @@ SECTIONS /*Free space for code 288 bytes*/ .mod_code_5174_5353 0x5174 : { *(.mod_varioSensorSelect); - *(.mod_log2fix); *(.mod_configurePins); *(.mod_createPacketCh1114); } @@ -270,6 +272,7 @@ SECTIONS *(.mod_parseAC); *(.mod_acHelper); *(.mod_displaySensors); + *(.mod_aslLabels); } .reserved_after_code_65C8_68A7 0x68A8 : { *(.reserved_after_code_65C8_68A7); @@ -353,16 +356,14 @@ SECTIONS *(.mod_alarmConfig); *(.mod_timerConfig); *(.mod_modMenuListFun); + *(.mod_log2fix); + *(.mod_getALT); + *(.mod_asl); } . = ALIGN(1); - .mod_extraMenu 0xFFB0 : { - *(.mod_modMenuList); - *(.mod_txBat); - *(.mod_altText); - *(.mod_alarm); + .mod_extraMenu 0xFFA8 : { *(.mod_extraMenu); } - .reserved_checksum 0xFFFD :{ *(.reserved_checksum*); } diff --git a/source/build/makefile b/source/build/makefile index 8408c54..ab509f5 100644 --- a/source/build/makefile +++ b/source/build/makefile @@ -52,17 +52,17 @@ fs-i6.bin \ SECONDARY_SIZE += \ fs-i6.siz \ -SECONDARY_FLASH_NO_SWE += \ -fs-i6-noswe.bin \ +SECONDARY_FLASH_SWE += \ +fs-i6-swe.bin \ -SECONDARY_SIZE_NO_SWE += \ -fs-i6-noswe.siz \ +SECONDARY_SIZE_SWE += \ +fs-i6-swe.siz \ PARAMS = # All Target all: fs-i6.elf secondary-outputs -all-noswe: fs-i6-noswe.elf secondary-outputs-noswe +all-swe: fs-i6-swe.elf secondary-outputs-swe # Tool invocations fs-i6.elf: $(OBJS) $(USER_OBJS) @@ -71,11 +71,11 @@ fs-i6.elf: $(OBJS) $(USER_OBJS) arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g -T "../MKL16Z64xxx4_flash.ld" -Xlinker --gc-sections -Wl,-Map,"fs-i6.map" --specs=nano.specs -specs=nosys.specs -Xlinker -z -Xlinker muldefs -o "fs-i6.elf" $(OBJS) $(USER_OBJS) $(LIBS) @echo 'Finished building target: $@' @echo ' ' -fs-i6-noswe.elf: PARAMS = -DNO_SWE -fs-i6-noswe.elf: $(OBJS) $(USER_OBJS) +fs-i6-swe.elf: PARAMS = -DSWE +fs-i6-swe.elf: $(OBJS) $(USER_OBJS) @echo 'Building target: $@' @echo 'Invoking: Cross ARM C++ Linker' - arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -Os $(PARAMS) -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g -T "../MKL16Z64xxx4_flash.ld" -Xlinker --gc-sections -Wl,-Map,"fs-i6-noswe.map" --specs=nano.specs -specs=nosys.specs -Xlinker -z -Xlinker muldefs -o "fs-i6-noswe.elf" $(OBJS) $(USER_OBJS) $(LIBS) + arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -Os $(PARAMS) -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g -T "../MKL16Z64xxx4_flash.ld" -Xlinker --gc-sections -Wl,-Map,"fs-i6-swe.map" --specs=nano.specs -specs=nosys.specs -Xlinker -z -Xlinker muldefs -o "fs-i6-swe.elf" $(OBJS) $(USER_OBJS) $(LIBS) @echo 'Finished building target: $@' @echo ' ' fs-i6.bin: fs-i6.elf @@ -86,12 +86,12 @@ fs-i6.bin: fs-i6.elf python3 flysky3.py fs-i6.bin fs-i6 @echo 'Finished building: $@' @echo ' ' -fs-i6-noswe.bin: fs-i6-noswe.elf +fs-i6-swe.bin: fs-i6-swe.elf @echo 'Invoking: Cross ARM GNU Create Flash Image' - arm-none-eabi-objcopy --update-section .interrupts=org.bin "fs-i6-noswe.elf" - arm-none-eabi-objcopy -j .interrupts -j .mod_* -O binary "fs-i6-noswe.elf" "fs-i6-noswe.bin" + arm-none-eabi-objcopy --update-section .interrupts=org.bin "fs-i6-swe.elf" + arm-none-eabi-objcopy -j .interrupts -j .mod_* -O binary "fs-i6-swe.elf" "fs-i6-swe.bin" #python flysky2.py fs-i6.bin fs-i6 - python3 flysky3.py fs-i6-noswe.bin fs-i6-noswe + python3 flysky3.py fs-i6-swe.bin fs-i6-swe @echo 'Finished building: $@' @echo ' ' @@ -102,19 +102,19 @@ fs-i6.siz: fs-i6.elf @echo 'Finished building: $@' @echo ' ' -fs-i6-noswe.siz: fs-i6-noswe.elf +fs-i6-swe.siz: fs-i6-swe.elf @echo 'Invoking: Cross ARM GNU Print Size' - arm-none-eabi-size --format=berkeley "fs-i6-noswe.elf" - arm-none-eabi-size --format=sysv "fs-i6-noswe.elf" -x + arm-none-eabi-size --format=berkeley "fs-i6-swe.elf" + arm-none-eabi-size --format=sysv "fs-i6-swe.elf" -x @echo 'Finished building: $@' @echo ' ' # Other Targets clean: - -$(RM) $(SECONDARY_SIZE)$(C++_DEPS)$(OBJS)$(C_DEPS)$(ASM_DEPS)$(CC_DEPS)$(SECONDARY_FLASH)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS)$(S_UPPER_DEPS)$(SECONDARY_SIZE_NO_SWE)$(SECONDARY_SIZE_NO_SWE) fs-i6.elf fs-i6-noswe.elf + -$(RM) $(SECONDARY_SIZE)$(C++_DEPS)$(OBJS)$(C_DEPS)$(ASM_DEPS)$(CC_DEPS)$(SECONDARY_FLASH)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS)$(S_UPPER_DEPS)$(SECONDARY_SIZE_SWE)$(SECONDARY_SIZE_SWE) fs-i6.elf fs-i6-swe.elf -@echo ' ' secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_SIZE) -secondary-outputs-noswe: $(SECONDARY_FLASH_NO_SWE) $(SECONDARY_SIZE_NO_SWE) +secondary-outputs-swe: $(SECONDARY_FLASH_SWE) $(SECONDARY_SIZE_SWE) .PHONY: all clean dependents .SECONDARY: diff --git a/source/source/alt.c b/source/source/alt.c index b1df101..8c51aa7 100644 --- a/source/source/alt.c +++ b/source/source/alt.c @@ -29,12 +29,11 @@ void add2ByteSensor(uint8_t sensorID, uint8_t sensorIndex, uint16_t value){ } #pragma GCC optimize ("Os") -/* - * getALT(sensorData & 0x7FFFF) - * */ + void acData(uint8_t* rxBuffer){ uint32_t sensorData = 0; uint8_t sensorIndex = 0; + uint16_t shortSensor = 0; int index = 1; int i = 0; int tmp = 0; @@ -47,8 +46,14 @@ void acData(uint8_t* rxBuffer){ sensorData = (rxBuffer[index+6] << 24 | rxBuffer[index+5] << 16 | rxBuffer[index+4] << 8 | rxBuffer[index+3]); if(rxBuffer[index]==IBUS_MEAS_TYPE_PRES){ offset = SENSORS_ARRAY_LENGTH - 1; - add2ByteSensor(IBUS_MEAS_TYPE_TEM, sensorIndex, (uint16_t)(sensorData >> 19)); + shortSensor = (uint16_t)(sensorData >> 19); + add2ByteSensor(IBUS_MEAS_TYPE_TEM, sensorIndex, shortSensor); sensorData = sensorData & 0x7FFFF; + tmp = getALT(sensorData, shortSensor); + i = IBUS_MEAS_TYPE_ALT - IBUS_MEAS_TYPE_GPS_LAT; + longSensors[i] = tmp; + add2ByteSensor(IBUS_MEAS_TYPE_ALT, sensorIndex, i); + } else if(rxBuffer[index]==IBUS_MEAS_TYPE_GPS_FULL){ add2ByteSensor(IBUS_MEAS_TYPE_GPS_STATUS, sensorIndex, rxBuffer[index+4] << 8 | rxBuffer[index+3]); @@ -391,7 +396,7 @@ int getSWState(uint32_t swIndex){ /*Belongs to .mod_modMenu 0xFFA0 */ void displayMenu(){ - showNavPage((const char*) extraMenu, 6, (manuEntry*)menuList); + showNavPage((const char*) extraMenu, 7, (manuEntry*)menuList); } void BatteryType() { @@ -402,8 +407,8 @@ void BatteryType() { while (1) { callSetupDMAandSend(); if(batteryVolt > 900) batteryVolt = 0; - displayPageHeader((char*)&txBat); - displayTextAt((char*)&alarm, 8, 24,0); + displayPageHeader((char*)(extraMenu+EXTRA_MENU_TXBAT)); + displayTextAt((char*)(extraMenu+EXTRA_MENU_ALARM), 8, 24,0); formatSensorValue(buffer, IBUS_MEAS_TYPE_INTV, batteryVolt); displayTextAt((char*)buffer, 8, 32,0); LCD_updateCALL(); @@ -426,6 +431,9 @@ void play(int freq, int duration, int pause){ if(pause > 0) beep(0,pause); } } +void beepSilent(){ + +} #define BEEP_DEFAULT_FREQ (900) @@ -612,6 +620,49 @@ uint8_t prevSensorID(uint8_t sensorID) return sensorID; } +void ASLConfig(){ + uint32_t key = 0; + uint8_t navPos = 0; + int y = 0; + uint32_t values[2]; + char buffer[32]; + getInitPressure(values, &values[1]); + do { + callSetupDMAandSend(); + //displayPageHeader((char*)(extraMenu+EXTRA_MENU_ASL)); //ASL + //values[0] = aslConfig >> 19; + //values[1] = aslConfig & 0x7FFFF; + initPressure = values[0]; + initTemperature = ibusTempToK((int16_t)values[1]); + for(uint8_t index = 0; index< 3; index++){ + y = 16+index*8; + displayTextAt((char*)aslLabels[index], 8, y, 0); + if(index == 0) sprintfCall(buffer, (const char*) formatNumber, values[0]); + if(index == 1) formatSensorValue(buffer, IBUS_MEAS_TYPE_TEM, (uint16_t) (values[1]-400)); + if(index == 2) formatSensorValue(buffer, IBUS_MEAS_TYPE_ALT, IBUS_MEAS_TYPE_ALT - IBUS_MEAS_TYPE_GPS_LAT); + displayTextAt((char*)buffer, 64, y, 0); + } + + displayGFX((gfxInfo*) GFX_ARROW, 56, navPos ? 24 : 16); + LCD_updateCALL(); + key = getKeyCode(); + + if(key == KEY_SHORT_UP || key == KEY_LONG_UP) values[navPos] +=10; + else if(key == KEY_SHORT_DOWN || key == KEY_LONG_DOWN) values[navPos] -=10; + else if(key == KEY_SHORT_OK) navPos = !navPos; + else if(key == KEY_LONG_OK) { + values[0] = defASL & 0x7FFFF; + values[1] = defASL >> 19; + } + } while ( key != KEY_LONG_CANCEL && key != KEY_SHORT_CANCEL); + + if(key == KEY_LONG_CANCEL){ + struct modelConfStruct *configPtr = getModelModConfig(); + configPtr->initAlt = values[0] | (values[1] << 19); + } +} + + void AlarmConfig(){ struct modelConfStruct *configPtr = getModelModConfig(); sensorAlarm alarmItem; @@ -630,7 +681,7 @@ void AlarmConfig(){ while ( 1 ) { callSetupDMAandSend(); - displayPageHeader((char*)alarm); + displayPageHeader((char*)(extraMenu+(EXTRA_MENU_OFFSET*2))); for(int i = 0; i < 3; i++){ y = 16+i*8; alarmItem = alarms[i]; @@ -728,8 +779,8 @@ void TimerConfig(){ displayPageHeader((char*)TEXT_TIMMER); displayTextAt((char*)TEXT_CHANNEL, labelPos, 16,0); displayTextAt((char*)TEXT_VALUE, labelPos, 24,0); - displayTextAt((char*)alarm, labelPos, 32,0); - displayTextAt((char*)TEXT_HOLD, labelPos, 40,0); + displayTextAt((char*)(extraMenu+EXTRA_MENU_ALARM), labelPos, 32,0); + displayTextAt((char*)TEXT_HOLD, labelPos, 40,0); for(int i = 0; i < 4; i++){ @@ -778,17 +829,6 @@ void TimerConfig(){ } } -void parseCoord(uint32_t *deg, uint32_t *min, uint32_t *sec, uint32_t *subSec, uint32_t coord) -{ - /*uint32_t tmp = 0; - *deg = divMod(coord, 10000000, &tmp); - coord = tmp * 60; - *min = divMod(coord, 10000000, &tmp); - coord = tmp * 60; - *sec = divMod(coord, 10000000, &tmp);*/ -} - - void formatSensorValue(char* target, int sensorID, uint16_t sensorValue) { const char* format = (const char*) formatNumber; @@ -830,6 +870,11 @@ void formatSensorValue(char* target, int sensorID, uint16_t sensorValue) { format = (const char*) formatNumberFractial; result = divMod(result, 100, &result2); } + if ((sensorInfo & MUL_010) == MUL_010) { + format = (const char*) formatNumberFractial; + result = divMod(result, 10, &result2); + result2 = result2*10; + } if ((sensorInfo & CUS_SENSOR) != CUS_SENSOR) { if ((sensorInfo & 0xF) != UNIT_NONE) { @@ -878,7 +923,7 @@ void formatSensorValue(char* target, int sensorID, uint16_t sensorValue) { void configurePINS2(){ configurePINs(); -#ifndef NO_SWE +#ifdef SWE PORT_SetPinMux(PORTD, 2u, kPORT_MuxAsGpio); GPIOD->PDDR &= ~(1U << 2); //input #endif @@ -1028,91 +1073,99 @@ void varioSensorSelect(){ } while (key != KEY_LONG_CANCEL && key != KEY_SHORT_CANCEL); } +int32_t log2fix(uint32_t x){ + int32_t b = 1U << (precision - 1); + int32_t y = 0; + while (x < 1U << precision) { + x <<= 1; + y -= 1U << precision; + } -// This implementation is based on Clay. S. Turner's fast binary logarithm algorithm[1]. -//source https://github.com/dmoulding/log2fix/blob/master/log2fix.c - -int32_t log2fix (uint32_t x, size_t precision) -{ - int32_t b = 1U << (precision - 1); - int32_t y = 0; - - if (precision < 1 || precision > 31) { - return INT32_MAX; // indicates an error - } - - if (x == 0) { - return INT32_MIN; // represents negative infinity - } - - while (x < 1U << precision) { - x <<= 1; - y -= 1U << precision; - } - - while (x >= 2U << precision) { - x >>= 1; - y += 1U << precision; - } + while (x >= 2U << precision) { + x >>= 1; + y += 1U << precision; + } uint64_t z = x; - for (size_t i = 0; i < precision; i++) { - z = __mul64(z,z) >> precision; - if (z >= 2U << precision) { - z >>= 1; - y += b; - } - b >>= 1; - } - return y; + for (size_t i = 0; i < precision; i++) { + z = __mul64(z, z) >> precision; + if (z >= 2U << precision) { + z >>= 1; + y += b; + } + b >>= 1; + } + return y; } -void init(uint32_t pressure) { - //constVal = mul(/*R_div_g*/ R_div_g_19_13, /*Tmp_24C*/ Tmp_24C_19_13, PRECISION); - //constVal = R_div_G_MUL_AVG_TEMP_19_13; - constVal = R_div_G_MUL_AVG_TEMP_19_13_8_C; - initPressure = FIXED(pressure); - initPressureRaw = pressure; +uint16_t ibusTempToK(int16_t tempertureIbus){ + return (uint16_t)(tempertureIbus - 400) + 2731; } -int16_t getALT(uint32_t pressure) { - return 0; - /* - if(pressure == 0) return 0; - - if (initPressure == 0) { - init(pressure); - } - - uint32_t tmp = FIXED(pressure); - uint8_t negative = 0; - if (initPressureRaw > pressure) { - //val is already shifted by PRECISION - tmp = div_(initPressure,pressure); - //tmp = (int32_t)(((int64_t)initPressure << PRECISION) / ((int64_t)tmp)); - } - else { - tmp = div_(tmp, initPressureRaw); - //tmp = (int32_t)(((int64_t)tmp << PRECISION) / ((int64_t)initPressure)); - negative = 1; - } - tmp = logfix(tmp, PRECISION); - uint32_t res = mulu16(tmp, constVal); - - //real CD3260DD - //this result CD32 - if (PRECISION < 16) { - res = res << (16 - PRECISION); - } - else if (PRECISION > 16) { - // res = res >> (PRECISION - 16); - } - //rounding - //res = res + ((res & 1 << (PRECISION - 1)) << 1); - int16_t h = res >> PRECISION; - if (negative) h = -h; - return h; - */ +void getInitPressure(uint32_t* pressure, int32_t* temperature){ + struct modelConfStruct *configPtr = getModelModConfig(); + *pressure = configPtr->initAlt & 0x7FFFF; + *temperature = configPtr->initAlt >> 19; +} +int getALT(uint32_t pressurePa, uint16_t tempertureIbus){ + uint16_t temperatureK = ibusTempToK(tempertureIbus); + if (initPressure <= 0) { + getInitPressure(&initPressure, &initTemperature); + initTemperature = ibusTempToK(initTemperature); + } + int temperature = (initTemperature + temperatureK) >> 1; //div 2 + bool tempNegative = temperature < 0; + if (tempNegative) temperature = temperature *-1; + /* + int index = 55; + int i = IBUS_MEAS_TYPE_S85 - IBUS_MEAS_TYPE_GPS_LAT; + longSensors[i] = (uint32_t)temperature; + add2ByteSensor(IBUS_MEAS_TYPE_S85, index, i); + i++; + */ + uint64_t helper = R_DIV_G_MUL_10_Q15; + helper = __mul64(helper, (uint64_t)temperature); + helper = helper >> precision; + + //div seems to take integers and return integers?! + //so can not shift by precision because it will result in negative number + + uint32_t po_to_p = (uint32_t)(initPressure << (precision-1)); + /* + longSensors[i] = po_to_p; + add2ByteSensor(IBUS_MEAS_TYPE_S86, index, i); + */ + po_to_p = div_(po_to_p, pressurePa); + //shift missing bit + po_to_p = po_to_p << 1; + /* + i++; + longSensors[i] = po_to_p; + add2ByteSensor(IBUS_MEAS_TYPE_S87, index, i); + */ + //return po_to_p; + //if (po_to_p == 0) return 0; + //po_to_p = 31130; + + uint64_t t = __mul64(log2fix(po_to_p), INV_LOG2_E_Q1DOT31); + int32_t ln = t >> 31; + /* + i++; + longSensors[i] =(uint32_t)ln; + add2ByteSensor(IBUS_MEAS_TYPE_S88, index, i); + */ + bool neg = ln < 0; + if (neg) ln = ln * -1; + helper = __mul64(helper, (uint64_t)ln); + helper = helper >> precision; + int result = (int)helper; + /* + i++; + longSensors[i] =(uint32_t)result; + add2ByteSensor(IBUS_MEAS_TYPE_S89, index, i); + */ + if (neg ^ tempNegative) result = result * -1; + return result; } #pragma GCC optimize ("O1") diff --git a/source/source/alt.h b/source/source/alt.h index e6d01a2..a654859 100644 --- a/source/source/alt.h +++ b/source/source/alt.h @@ -8,16 +8,16 @@ #ifndef SOURCE_ALT_H_ #define SOURCE_ALT_H_ - #include #include -#define PRECISION 13 -#define FIXED(val) (val << PRECISION) -#define DECIMAL(val) (val >> PRECISION) -#define INV_LOG2_E_Q1DOT31 UINT32_C(0x58b90bfc) // Inverse log base 2 of e -#define R_div_G_MUL_AVG_TEMP_19_13 0x4300C6D; -#define R_div_G_MUL_AVG_TEMP_19_13_8_C 0x4074096 +#define precision 15 +#define FIXED(val) (val << precision) +#define DECIMAL(val) (val >> precision) +#define TMP_OFFSET 19 +#define ALT_MASK 0x7FFFF; +#define R_DIV_G_MUL_10_Q15 UINT64_C(9591506) +#define INV_LOG2_E_Q1DOT31 UINT64_C(0x58b90bfc) // Inverse log base 2 of e #define ALARM_OPERATOR_LT 0 #define ALARM_OPERATOR_GT 0 @@ -62,56 +62,34 @@ typedef struct globalConfigStruct uint16_t batteryVoltage; uint8_t swConfig; modelConfStruct modelConfig[16]; - } globalConfigStruct; -typedef struct configStruct -{ - /*@0*/ uint8_t timerCH; - /*@1*/ uint16_t timerStart; - /*@3*/ uint16_t timerAlarm; - /*@5*/ uint16_t batteryVoltage; - /*@7*//*@11*//*@115*/ sensorAlarm alarm[3]; - /*@19*/ /*uint8_t swB3Pos*/; -} configStruct; - -typedef union config -{ - configStruct cfg; -} config; - -globalConfigStruct __attribute__((section (".mod_modConfigAsModel17"))) modConfig2; -uint8_t __attribute__((section (".mod_mainScreenIndex"))) mainScreenIndex = 0; //referenced from assembly -//configStruct __attribute__((section (".mod_modConfigEeprom"))) modConfig; //16bytes -int32_t __attribute__((section (".mod_longSensors"))) longSensors[SENSORS_ARRAY_LENGTH]; //72bytes referenced from assembly -uint8_t __attribute__((section (".mod_timerBuffer"))) timerBuffer[10]; //10bytes -uint32_t __attribute__((section (".mod_timerValue"))) timerValue; -uint32_t __attribute__((section (".mod_lastTimerUpdate"))) lastTimerUpdate; -uint8_t __attribute__((section (".mod_ticks100ms"))) ticks100MS; -uint8_t __attribute__((section (".mod_mavlinkGPSFrame"))) mavlinkGPSFrame[22]; //22bytes -__attribute__((section (".mod_altconstVal"))) uint32_t constVal = 0; -__attribute__((section (".mod_altinitPressure"))) uint32_t initPressure = 0; -__attribute__((section (".mod_altinitPressureRaw"))) uint32_t initPressureRaw = 0; -__attribute__((section (".mod_auxMem_test1"))) uint32_t allocationTest = 0; - +__attribute__((section (".mod_modConfigAsModel17"))) globalConfigStruct modConfig2; +__attribute__((section (".mod_mainScreenIndex"))) uint8_t mainScreenIndex = 0; //referenced from assembly +__attribute__((section (".mod_longSensors"))) int32_t longSensors[SENSORS_ARRAY_LENGTH]; //72bytes referenced from assembly +__attribute__((section (".mod_timerBuffer"))) uint8_t timerBuffer[10]; //10bytes +__attribute__((section (".mod_timerValue"))) uint32_t timerValue; +__attribute__((section (".mod_lastTimerUpdate"))) uint32_t lastTimerUpdate; +__attribute__((section (".mod_ticks100ms"))) uint8_t ticks100MS; +__attribute__((section (".mod_mavlinkGPSFrame"))) uint8_t mavlinkGPSFrame[22]; //22bytes +__attribute__((section (".mod_altSensorMemory"))) uint32_t initPressure = 0; +__attribute__((section (".mod_altSensorMemory"))) int32_t initTemperature = 0; +__attribute__((section (".mod_varioMem"))) int32_t varioPrevValue = 0; +__attribute__((section (".mod_varioMem"))) int32_t varioPrevTime = 0; +__attribute__((section (".mod_beep_silent "))) void beepSilent(); __attribute__((section (".mod_configurePins"))) void configurePINS2(); - - __attribute__((section (".mod_getAuxChannel"))) int getAuxChannel(uint32_t request); - __attribute__((section (".mod_getSWState"))) int getSWState(uint32_t swIndex); - +__attribute__((section (".mod_getAuxChannel"))) int getAuxChannel(uint32_t request); +__attribute__((section (".mod_getSWState"))) int getSWState(uint32_t swIndex); __attribute__((section (".mod_modMenuListFun"))) void displayMenu(); - __attribute__((section (".mod_acHelper"))) void add2ByteSensor(uint8_t sensorID, uint8_t sensorIndex, uint16_t value); __attribute__((section (".mod_parseAC"))) void acData(uint8_t* rxBuffer); - - __attribute__((section (".mod_printTimer"))) void printTimer(); __attribute__((section (".mod_checkTimerActive"))) uint32_t isTimerActive(); __attribute__((section (".mod_timerConfig"))) void TimerConfig(); - __attribute__((section (".mod_batteryConfig"))) void BatteryType(); + __attribute__((section (".mod_asl"))) void ASLConfig(); __attribute__((section (".mod_nextSensorID"))) uint8_t prevSensorID(uint8_t sensorID); __attribute__((section (".mod_prevSensorID"))) uint8_t nextSensorID(uint8_t sensorID); @@ -129,23 +107,15 @@ __attribute__((section (".mod_parseAC"))) void acData(uint8_t* rxBuffer); __attribute__((section (".mod_loadModEeprom"))) void loadModSettings(); __attribute__((section (".mod_saveModEeprom"))) void saveModSettings(); */ - __attribute__((section (".mod_varioSensorSelect"))) void varioSensorSelect(); - - +__attribute__((section (".mod_varioSensorSelect"))) void varioSensorSelect(); __attribute__((section (".mod_displaySensors"))) void displaySensors(); __attribute__((section (".mod_getSensorName"))) const uint8_t* getSensorName(int sensor); __attribute__((section (".mod_formatSensorValue"))) void formatSensorValue(char* target, int sensorID, uint16_t sensorValue); __attribute__((section (".mod_divMod"))) uint32_t divMod(uint32_t val, uint32_t divisor, uint32_t* mod); -__attribute__((section (".mod_parseCoord"))) void parseCoord(uint32_t *deg, uint32_t *min, uint32_t *sec, uint32_t *subSec, uint32_t coord); -__attribute__((section ("..mod_log2fix"))) int32_t log2fix(uint32_t x, size_t precision); - -__attribute__((section (".mod_varioMem"))) int32_t varioPrevValue = 0; -__attribute__((section (".mod_varioMem"))) int32_t varioPrevTime = 0; - -__attribute__((section (".altinit"))) void init(uint32_t pressure); -__attribute__((section (".altgetALT"))) int16_t getALT(uint32_t pressure); -__attribute__((section (".altlogfix"))) int32_t logfix(uint32_t x, size_t precision); - +__attribute__((section (".mod_log2fix"))) int32_t log2fix(uint32_t x); +__attribute__((section (".mod_getALT"))) uint16_t ibusTempToK(int16_t tempertureIbus); +__attribute__((section (".mod_getALT"))) void getInitPressure(uint32_t* pressure, int32_t* temperature); +__attribute__((section (".mod_getALT"))) int getALT(uint32_t pressurePa, uint16_t tempertureIbus); __attribute__((section (".reserved_main"))) uint32_t keep1 = 0; __attribute__((section (".reserved_after_code_C9B0_CA4F"))) uint32_t keep2 = 0; diff --git a/source/source/flysky.h b/source/source/flysky.h index b09fa28..131f756 100644 --- a/source/source/flysky.h +++ b/source/source/flysky.h @@ -39,6 +39,7 @@ #define TEXT_OFF 0xCA87 #define TEXT_TIMMER 0xDCB7 #define TEXT_HOLD 0xCAB3 +#define FORMAT_TEMP 0x5530 #define KEY_SHORT_UP 9 #define KEY_SHORT_DOWN 8 @@ -76,6 +77,7 @@ typedef size_t (*strLenFun)(const char * str); typedef char* (*strcatFun)(char * str, const char* source); typedef void * (*memSetFun)(void *str, int c, size_t n); typedef uint32_t (*divFun)(uint32_t a, uint32_t b); +typedef uint32_t (*divBy10Fun)(uint32_t a); typedef int (*intVoidFun)(void); typedef int (*eepromFun)(uint8_t * target, int16_t eepromOffset, int length); typedef int (*gfxFun)(gfxInfo* gfx, int x, int y); @@ -104,6 +106,8 @@ __attribute__((section (".mod_MOD_SPACE.STRCAT"))) const strcatFun strcatCall = __attribute__((section (".mod_MOD_SPACE.STRLEN"))) const strLenFun strLenCall = (strLenFun)0x1CB1; __attribute__((section (".mod_MOD_SPACE.MEMSET"))) const memSetFun memsetCall = (memSetFun)0x3201; __attribute__((section (".mod_MOD_SPACE.SEND"))) const voidFun sendPacketWithSysTick = (voidFun)0x9EFD; + +__attribute__((section (".mod_MOD_SPACE.DIVBY10")))const divBy10Fun divBy10 = (divBy10Fun)0x2165; __attribute__((section (".mod_MOD_SPACE.DIVMOD"))) const divFun uidivmod = (divFun)0x1E5F; __attribute__((section (".mod_MOD_SPACE.DIV"))) const divFun div_ = (divFun)0x1E7B; __attribute__((section (".mod_MOD_SPACE.GETKEY"))) const intVoidFun getKeyCode = (intVoidFun)0x2535; diff --git a/source/source/main.c b/source/source/main.c index 43efbf1..0f90012 100644 --- a/source/source/main.c +++ b/source/source/main.c @@ -53,7 +53,7 @@ #include "alt.h" #include "ibustelemetry.h" - +//#define SILENT extern void __call_configurePins_ASM(); extern void __call_extraChannels_ASM(); @@ -90,15 +90,12 @@ int main(void) { getModelModConfig(); printTimer(); if( strLenCall((const char*)RADIO_MODES)){ - init(10000); - getALT(10000); + getALT(10000, 600); acData(buf); } + ASLConfig(); acData(buf); getAuxChannel(0); - - getALT(10000); - displayMenu(); TimerConfig(); BatteryType(); @@ -119,10 +116,6 @@ int main(void) { __call_formatSensorValue_ASM(); __call_formatSensorValue2_ASM(); configurePINS2(); - /* - strLenCall((const char*)txBat); - -*/ CheckCustomAlarms(); //keep few regions if(keep1==0){keep1++;} @@ -143,6 +136,11 @@ int main(void) { //keep this one because of without usage signature block will be removed if(SIGNATURE[0] == 1){ } + + #ifdef SILENT + beepSilent(); + #endif + formatSensorValue((char *)SIGNATURE, 0,0); formatSensorValue((char *)mod_version, 0,0); //divFun dev = (divFun)0x1E5E; @@ -156,8 +154,8 @@ int main(void) { AlarmConfig(); printTimer(0); auxChannels2(); - __mul64((long long)1, (long long)2); - log2fix(1,1); + //__mul64((long long)1, (long long)2); + //log2fix(1,1); //rxTest2(); //initALT(100000); uint32_t reminder=0; diff --git a/source/source/mod.h b/source/source/mod.h index ee45e5e..c27a0a7 100644 --- a/source/source/mod.h +++ b/source/source/mod.h @@ -24,6 +24,7 @@ #define SIGNED__ 1 << 6 #define UNSIGNED 0 << 6 #define MUL_001 0 << 4 +#define MUL_010 1 << 4 #define MUL_100 2 << 4 #define UNIT_NONE 0 @@ -38,7 +39,8 @@ #define UNIT_KMH 9 #define UNIT_CM_S 10 #define UNIT_MAH 11 - +#define TEMP_TEXT_OFFSET 5 +#define ALT_TEXT_OFFSET 15 __attribute__((section (".mod_sensors00"))) const uint8_t SENSOR_00[] = /* 5-byte NULL-terminated strings. The last one has implicit NULL added @@ -185,27 +187,34 @@ const uint8_t __attribute__((section (".mod_timerFormat"))) timerFormat[] = "%02u:%02u:%02u"; const uint8_t __attribute__((section (".mod_timerNull"))) timerNull[] = "00:00:00"; -const uint8_t __attribute__((section (".mod_alarm"))) alarm[] = - "Alarm"; -const uint8_t __attribute__((section (".mod_extraMenu"))) extraMenu[] = - "Extra"; + + #define GAIN_OFFSET 6 const uint8_t __attribute__((section (".mod_varioStrings"))) varioSensor[] = { "Vario\0" "Gain" }; - -const uint8_t __attribute__((section (".mod_txBat"))) txBat[] = - "TX Bat"; +#define EXTRA_MENU_OFFSET 6 +#define EXTRA_MENU_TXBAT 6 +#define EXTRA_MENU_ALARM 13 +#define EXTRA_MENU_ASL 19 + +const uint8_t __attribute__((section (".mod_extraMenu"))) extraMenu[] = { + "Extra\0" + "Tx Bat\0" + "Alarm\0" + "ASL" +}; //contains pointers to functions!!! -const uint32_t __attribute__((section (".mod_modMenuList"))) menuList[] = { +const uint32_t __attribute__((section (".mod_extraMenu"))) menuList[] = { TEXT_TIMMER, (uint32_t)(&TimerConfig+1), - (uint32_t)&alarm, (uint32_t)(&AlarmConfig+1), + (uint32_t)(extraMenu+EXTRA_MENU_ALARM), (uint32_t)(&AlarmConfig+1), SW_B_C, (uint32_t)(&SwBConfig+1), - (uint32_t)&txBat, (uint32_t)(&BatteryType+1), + (uint32_t)(extraMenu+EXTRA_MENU_TXBAT), (uint32_t)(&BatteryType+1), AUX_CH_TEXT, (uint32_t)(&auxChannels2+1), (uint32_t)&varioSensor, (uint32_t)(&varioSensorSelect+1), + (uint32_t)(extraMenu+EXTRA_MENU_ASL), (uint32_t)(&ASLConfig+1), }; @@ -219,7 +228,7 @@ UUUU UNIT const uint8_t __attribute__((section (".mod_sensDesc00"))) sensorDesc00[] = { /*00*/ STD_SENSOR|UNSIGNED|MUL_100|UNIT_V, //IntV -/*01*/ STD_SENSOR|SIGNED__|MUL_001|UNIT_DEG, //Temp +/*01*/ STD_SENSOR|SIGNED__|MUL_010|UNIT_DEG, //Temp /*02*/ STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //Mot /*03*/ STD_SENSOR|UNSIGNED|MUL_100|UNIT_V, //ExtV /*04*/ STD_SENSOR|UNSIGNED|MUL_100|UNIT_V, //Cell @@ -250,12 +259,12 @@ const uint8_t __attribute__((section (".mod_sensDesc80"))) sensorDesc80[] = { STD_SENSOR|SIGNED__|MUL_100|UNIT_M, //Alt -> GPS alt STD_SENSOR|SIGNED__|MUL_100|UNIT_M, //ALT STD_SENSOR|SIGNED__|MUL_100|UNIT_M, //Max Alt - STD_SENSOR|SIGNED__|MUL_100|UNIT_NONE, //s85 - STD_SENSOR|SIGNED__|MUL_100|UNIT_NONE, //s86 - STD_SENSOR|SIGNED__|MUL_100|UNIT_NONE, //s87 - STD_SENSOR|SIGNED__|MUL_100|UNIT_NONE, //s88 - STD_SENSOR|SIGNED__|MUL_100|UNIT_NONE, //s89 - STD_SENSOR|SIGNED__|MUL_100|UNIT_NONE, //s89 + STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //s85 + STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //s86 + STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //s87 + STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //s88 + STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //s89 + STD_SENSOR|UNSIGNED|MUL_001|UNIT_NONE, //s89 }; const uint8_t __attribute__((section (".mod_sensDescFA"))) sensorDescFA[] = { @@ -297,8 +306,14 @@ const uint8_t __attribute__((section (".mod_units"))) units[] = { /*11@31*/'m', 'A', 'h', 0x00, }; + +const uint32_t __attribute__((section (".mod_defASL"))) defASL = ((250 + 400) << 19)|101325; const uint16_t __attribute__((section (".mod_timerMaxValues"))) timerMaxValues[] = { 10, 2200, 0xffff, 1 }; -const uint32_t __attribute__((section (".mod_timerLabels"))) timerLabels[] = { TEXT_CHANNEL, TEXT_VALUE, (uint32_t)&alarm, TEXT_HOLD }; +const uint32_t __attribute__((section (".mod_timerLabels"))) timerLabels[] = { TEXT_CHANNEL, TEXT_VALUE, (uint32_t)(extraMenu+EXTRA_MENU_OFFSET*3), TEXT_HOLD }; +const uint32_t __attribute__((section (".mod_aslLabels"))) aslLabels[] = { (uint32_t)SENSOR_41, (uint32_t)(SENSOR_00 + TEMP_TEXT_OFFSET), (uint32_t)(SENSORS_80 +ALT_TEXT_OFFSET)}; + + + const uint8_t __attribute__((section (".mod_version"))) mod_version[] = "1.7.1"; uint32_t __attribute__((section (".mod_tx_voltage_alarm_address"))) txVoltageAddress = (uint32_t)&modConfig2.batteryVoltage;