From 7f293bdcfb77424d744f38f5ae747dcb4c7db6d6 Mon Sep 17 00:00:00 2001 From: qba667 Date: Tue, 12 Dec 2017 15:31:58 +0100 Subject: [PATCH 1/2] Text mix method added. Model count reduced to 15. Mix config stored in mod config. --- source/MKL16Z64xxx4_flash.ld | 3 +- source/source/alt.c | 24 ++++++++++++++ source/source/alt.h | 62 ++++++++++++++++++++++++++++-------- source/source/main.c | 1 + 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/source/MKL16Z64xxx4_flash.ld b/source/MKL16Z64xxx4_flash.ld index a7cdb79..8fdbdd3 100644 --- a/source/MKL16Z64xxx4_flash.ld +++ b/source/MKL16Z64xxx4_flash.ld @@ -107,7 +107,7 @@ SECTIONS *(.screenBuffer); } > m_data - .MOD_CONFIG2 0x20000BC4 : + .MOD_CONFIG2 0x20000B32 : { *(.mod_modConfigAsModel17); } > m_data @@ -262,6 +262,7 @@ SECTIONS *(.mod_varioSensorSelect); *(.mod_configurePins); *(.mod_createPacketCh1114); + } .reserved_after_code_5174_5353 0x5354 : { *(.reserved_after_code_5174_5353); diff --git a/source/source/alt.c b/source/source/alt.c index 8c51aa7..918116e 100644 --- a/source/source/alt.c +++ b/source/source/alt.c @@ -111,6 +111,30 @@ modelConfStruct* getModelModConfig(){ return ptr; } +int mix(int value, int8_t min, int8_t max, int8_t subtrim){ + uint8_t input_range_fixed_q20 = 105; + int16_t lim_p = max * 100; + int16_t lim_n = min * 100; + int16_t ofs = subtrim * 100; + uint8_t neg = 0; //get from config + + if (value) { + int16_t tmp = (value > 0) ? (lim_p - ofs) : (-lim_n + ofs); + value = (int32_t)value * tmp; + if (value < 0) { + value *= -1; + neg = !neg; + } + value = (int)(__mul64((uint64_t)value, (uint64_t)input_range_fixed_q20) >> 20); + if (neg) value *= -1; + ofs += value; + } + if (ofs > lim_p) ofs = lim_p; + if (ofs < lim_n) ofs = lim_n; + return ofs; +} + + const uint8_t* getSensorName(int sensor){ if ( sensor >= IBUS_MEAS_TYPE_INTV && sensor <= IBUS_MEAS_TYPE_UNKNOWN ) { diff --git a/source/source/alt.h b/source/source/alt.h index a654859..eb7b24a 100644 --- a/source/source/alt.h +++ b/source/source/alt.h @@ -40,28 +40,61 @@ typedef struct sensorAlarm #define VARIO_MAX_GAIN_BITS 4 // do not need the whole byte //24 + sensorAlarm (3 * 4 bytes) 12 bytes = 36 bytes + +#define TOTAL_MODELS 15 +#define OLD_MODEL_COUNT 20 +#define OLD_CONFIGSIZE 146 +#define NEW_MODEL_MEM MODEL_SETTINGS + TOTAL_MODELS * OLD_CONFIGSIZE +//to use this in linker we need to run linker on ld file +//https://stackoverflow.com/questions/28837199/can-i-use-preprocessor-directives-in-ld-file +//for now just calcualte +//MODEL_SETTINGS 0x200002A4 +//0x200002A4 + 15* 146 = 0x20000B32 + + +typedef struct mixConfStruct{ + int8_t min; + int8_t max; + int8_t subtrim; +} mixConfStruct; typedef struct modelConfStruct { - uint8_t ch11_12; - uint8_t ch13_14; - uint16_t timerAlarm; - uint8_t timerCH; - uint16_t timerStart; - sensorAlarm alarm[3]; - uint32_t initAlt; - uint8_t varioSensorID; - uint8_t varioGain : VARIO_MAX_GAIN_BITS; - uint8_t reserved_bits : (8 - VARIO_MAX_GAIN_BITS); - uint8_t reserved[11]; -} modelConfStruct; + uint8_t ch11_12; // 1 + uint8_t ch13_14; // 1 + uint16_t timerAlarm; // 2 + uint8_t timerCH; // 1 + uint16_t timerStart; // 2 + sensorAlarm alarm[3]; // 3*4 = 12 + uint32_t initAlt; // 4 + uint8_t varioSensorID; // 1 + uint8_t varioGain : VARIO_MAX_GAIN_BITS; // 1 + uint8_t reserved_bits : (8 - VARIO_MAX_GAIN_BITS); // 1 + mixConfStruct mix[8]; // 8*3 = 24 + uint8_t reserved[8]; // 8 +} modelConfStruct; // 58 + + +//Change allocation to 15 +//TOTAL 58 * 15 = 870 +//Version magic 2 bytes, battery 2 bytes, sw config 1 byte +//Total 875 +//5 *146 = 876 + /*total 146*4 = 584 bytes*/ -/*used: 3+ 16* 36 = 579*/ +/*used: 3+ 16* 55 = 803*/ +/*needed 6 -> 876 -803 /*free: 5*/ +//clear method +//mem set to 0 +//mix default -100, 100, 0 + + typedef struct globalConfigStruct { uint16_t batteryVoltage; uint8_t swConfig; - modelConfStruct modelConfig[16]; + modelConfStruct modelConfig[TOTAL_MODELS]; + uint16_t verionMagic; } globalConfigStruct; @@ -116,6 +149,7 @@ __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 (".find_space_mix"))) int mix(int value, int8_t min, int8_t max, int8_t subtrim); __attribute__((section (".reserved_main"))) uint32_t keep1 = 0; __attribute__((section (".reserved_after_code_C9B0_CA4F"))) uint32_t keep2 = 0; diff --git a/source/source/main.c b/source/source/main.c index 0f90012..053ba49 100644 --- a/source/source/main.c +++ b/source/source/main.c @@ -154,6 +154,7 @@ int main(void) { AlarmConfig(); printTimer(0); auxChannels2(); + mix(10000, -100, 100, 0); //__mul64((long long)1, (long long)2); //log2fix(1,1); //rxTest2(); From 7d5abdb0e9d84863bc4b27583af7b7b22c701746 Mon Sep 17 00:00:00 2001 From: qba667 Date: Wed, 13 Dec 2017 15:53:03 +0100 Subject: [PATCH 2/2] Endpoint/subtrim menu added for channels 7-14. --- source/source/alt.c | 78 ++++++++++++++++++++++++++++++++++++++++++++- source/source/alt.h | 4 +++ source/source/mod.h | 2 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/source/source/alt.c b/source/source/alt.c index 918116e..b22de2a 100644 --- a/source/source/alt.c +++ b/source/source/alt.c @@ -111,6 +111,81 @@ modelConfStruct* getModelModConfig(){ return ptr; } +void mixConfig() { + uint32_t key = 0; + struct modelConfStruct *configPtr = getModelModConfig(); + int8_t config[MIX_CONFIG_SIZE_BYTES]; + memcpy_(config, configPtr->mix, MIX_CONFIG_SIZE_BYTES); + char buffer[8]; + uint8_t row = 0; + uint8_t col = 0; + uint8_t rowPos = 0; + do { + callSetupDMAandSend(); + //displayPageHeader((char*)0xDBEC); + for (uint8_t rowIndex= 0; rowIndex < 8; rowIndex++) { + rowPos = rowIndex << 3; + buffer[0] = '7' + rowIndex; + buffer[1] = 0; + displayTextAt(buffer, 8, rowPos, 0); + for (uint8_t colIndex = 0; colIndex < 3; colIndex++) { + sprintfCall(buffer, (const char*)0x5564, config[3 * rowIndex + colIndex]); + displayTextAt(buffer, mixPos[colIndex] + 8, buffer, 0); + } + displayGFX((gfxInfo*)GFX_ARROW, mixPos[col], row << 3); + } + LCD_updateCALL(); + key = getKeyCode(); + + if (key == KEY_SHORT_OK) + { + col++; + if (col >= 3) { + col = 0; + row++; + } + if (row >= 3) row = 0; + } + + if (key == KEY_SHORT_UP || key == KEY_LONG_UP) { + config[3 * row + col]++; + } + if (key == KEY_SHORT_DOWN || key == KEY_LONG_DOWN) { + config[3 * row + col]--; + } + } while (key != KEY_LONG_CANCEL && key != KEY_SHORT_CANCEL); + + if (key == KEY_LONG_CANCEL) { + memcpy_(configPtr->mix, config, MIX_CONFIG_SIZE_BYTES); + } +} +void createPacketCh7_14(){ + int32_t channel7Address = 0x1FFFFDF8; + struct modelConfStruct *configPtr = getModelModConfig(); + uint16_t ch11_14 = *((uint16_t*)&(configPtr->ch11_12)); + uint8_t lsb = 0; + //skip 7,8,9,10 + channel7Address += 16; + for(uint8_t i=0; i < 4; i++){ + //*((int32_t*)channel11Address) = getAuxChannel((ch11_14 >> lsb) & ~(~0 << (msb-lsb+1))); + *((int32_t*)channel7Address) = getAuxChannel((ch11_14 >> lsb) & ~(~0 << 4)); + lsb +=4; + channel7Address += 4; + } + + // + + //uint8_t auxChannels[4]; + //auxChannels[0] = configPtr->ch11_12 >> 4; + //auxChannels[1] = configPtr->ch11_12 & 0xF; + //auxChannels[2] = configPtr->ch13_14 >> 4; + //auxChannels[3] = configPtr->ch13_14 & 0xF; + //for(uint8_t i=0; i < sizeof(auxChannels); i++){ + // *((int32_t*)(channel11Address + 4*i)) = getAuxChannel(auxChannels[i]); + //} +} + + int mix(int value, int8_t min, int8_t max, int8_t subtrim){ uint8_t input_range_fixed_q20 = 105; int16_t lim_p = max * 100; @@ -208,6 +283,8 @@ uint32_t isTimerActive(){ return chValue > configVal; } + + #define SW_A 0u #define SW_B 1u #define SW_C 2u @@ -300,7 +377,6 @@ void createPacketCh1114(){ for(uint8_t i=0; i < sizeof(auxChannels); i++){ *((int32_t*)(channel11Address + 4*i)) = getAuxChannel(auxChannels[i]); } - } int getAuxChannel(uint32_t request){ int sw1 = 0; diff --git a/source/source/alt.h b/source/source/alt.h index eb7b24a..91c49a3 100644 --- a/source/source/alt.h +++ b/source/source/alt.h @@ -45,6 +45,7 @@ typedef struct sensorAlarm #define OLD_MODEL_COUNT 20 #define OLD_CONFIGSIZE 146 #define NEW_MODEL_MEM MODEL_SETTINGS + TOTAL_MODELS * OLD_CONFIGSIZE +#define MIX_CONFIG_SIZE_BYTES 24 //to use this in linker we need to run linker on ld file //https://stackoverflow.com/questions/28837199/can-i-use-preprocessor-directives-in-ld-file //for now just calcualte @@ -150,6 +151,9 @@ __attribute__((section (".mod_getALT"))) uint16_t ibusTempToK(int16_t temperture __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 (".find_space_mix"))) int mix(int value, int8_t min, int8_t max, int8_t subtrim); +__attribute__((section (".find_space_mix"))) void mixConfig(); +__attribute__((section (".find_space_mix"))) void createPacketCh7_14(); + __attribute__((section (".reserved_main"))) uint32_t keep1 = 0; __attribute__((section (".reserved_after_code_C9B0_CA4F"))) uint32_t keep2 = 0; diff --git a/source/source/mod.h b/source/source/mod.h index c27a0a7..7732ca4 100644 --- a/source/source/mod.h +++ b/source/source/mod.h @@ -311,7 +311,7 @@ const uint32_t __attribute__((section (".mod_defASL"))) defASL = ((250 + 400) << 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)(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 mixPos[] = { 8, 48, 88 }; const uint8_t __attribute__((section (".mod_version"))) mod_version[] = "1.7.1";