Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qba667/FlySkyI6
Browse files Browse the repository at this point in the history
  • Loading branch information
qba667 committed Jan 5, 2018
2 parents 90d4fbf + 7d5abdb commit 4335fcd
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 17 deletions.
3 changes: 2 additions & 1 deletion source/MKL16Z64xxx4_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ SECTIONS
*(.screenBuffer);
} > m_data

.MOD_CONFIG2 0x20000BC4 :
.MOD_CONFIG2 0x20000B32 :
{
*(.mod_modConfigAsModel17);
} > m_data
Expand Down Expand Up @@ -262,6 +262,7 @@ SECTIONS
*(.mod_varioSensorSelect);
*(.mod_configurePins);
*(.mod_createPacketCh1114);

}
.reserved_after_code_5174_5353 0x5354 : {
*(.reserved_after_code_5174_5353);
Expand Down
102 changes: 101 additions & 1 deletion source/source/alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,105 @@ 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;
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 )
{
Expand Down Expand Up @@ -184,6 +283,8 @@ uint32_t isTimerActive(){

return chValue > configVal;
}


#define SW_A 0u
#define SW_B 1u
#define SW_C 2u
Expand Down Expand Up @@ -276,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;
Expand Down
66 changes: 52 additions & 14 deletions source/source/alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,62 @@ 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
#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
//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;


Expand Down Expand Up @@ -116,6 +150,10 @@ __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 (".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;
Expand Down
1 change: 1 addition & 0 deletions source/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion source/source/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,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_ALARM), 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";
Expand Down

0 comments on commit 4335fcd

Please sign in to comment.