Rev 1221 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1221 | Rev 1222 | ||
---|---|---|---|
Line 67... | Line 67... | ||
67 | #include <string.h> |
67 | #include <string.h> |
68 | #include "eeprom.h" |
68 | #include "eeprom.h" |
69 | #include "printf_P.h" |
69 | #include "printf_P.h" |
70 | #include "led.h" |
70 | #include "led.h" |
71 | #include "main.h" |
71 | #include "main.h" |
- | 72 | #include "fc.h" |
|
Line 72... | Line 73... | ||
72 | 73 | ||
73 | 74 | ||
Line 74... | Line 75... | ||
74 | // byte array in eeprom |
75 | // byte array in eeprom |
75 | uint8_t EEPromArray[E2END+1] EEMEM; |
- | |
- | 76 | uint8_t EEPromArray[E2END+1] EEMEM; |
|
Line 76... | Line 77... | ||
76 | 77 | ||
77 | paramset_t ParamSet; |
78 | paramset_t ParamSet; |
78 | 79 | MixerTable_t Mixer; |
|
Line 366... | Line 367... | ||
366 | } |
367 | } |
Line 367... | Line 368... | ||
367 | 368 | ||
368 | /***************************************************/ |
369 | /***************************************************/ |
369 | /* Read Parameter from EEPROM as byte */ |
370 | /* Read Parameter from EEPROM as byte */ |
370 | /***************************************************/ |
371 | /***************************************************/ |
371 | uint8_t GetParamByte(uint8_t param_id) |
372 | uint8_t GetParamByte(uint16_t param_id) |
372 | { |
373 | { |
373 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
374 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
Line 374... | Line 375... | ||
374 | } |
375 | } |
375 | 376 | ||
376 | /***************************************************/ |
377 | /***************************************************/ |
377 | /* Write Parameter to EEPROM as byte */ |
378 | /* Write Parameter to EEPROM as byte */ |
378 | /***************************************************/ |
379 | /***************************************************/ |
379 | void SetParamByte(uint8_t param_id, uint8_t value) |
380 | void SetParamByte(uint16_t param_id, uint8_t value) |
380 | { |
381 | { |
Line 381... | Line 382... | ||
381 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
382 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
382 | } |
383 | } |
383 | 384 | ||
384 | /***************************************************/ |
385 | /***************************************************/ |
385 | /* Read Parameter from EEPROM as word */ |
386 | /* Read Parameter from EEPROM as word */ |
386 | /***************************************************/ |
387 | /***************************************************/ |
387 | uint16_t GetParamWord(uint8_t param_id) |
388 | uint16_t GetParamWord(uint16_t param_id) |
Line 388... | Line 389... | ||
388 | { |
389 | { |
389 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
390 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
390 | } |
391 | } |
391 | 392 | ||
392 | /***************************************************/ |
393 | /***************************************************/ |
393 | /* Write Parameter to EEPROM as word */ |
394 | /* Write Parameter to EEPROM as word */ |
394 | /***************************************************/ |
395 | /***************************************************/ |
Line 395... | Line -... | ||
395 | void SetParamWord(uint8_t param_id, uint16_t value) |
- | |
396 | { |
396 | void SetParamWord(uint16_t param_id, uint16_t value) |
397 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
397 | { |
398 | } |
398 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
399 | 399 | } |
|
400 | 400 | ||
Line 424... | Line 424... | ||
424 | SetActiveParamSet(setnumber); |
424 | SetActiveParamSet(setnumber); |
425 | LED_Init(); |
425 | LED_Init(); |
426 | } |
426 | } |
Line 427... | Line 427... | ||
427 | 427 | ||
- | 428 | /***************************************************/ |
|
- | 429 | /* Read MixerTable from EEPROM */ |
|
- | 430 | /***************************************************/ |
|
- | 431 | uint8_t MixerTable_ReadFromEEProm(void) |
|
- | 432 | { |
|
- | 433 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == EEMIXER_REVISION) |
|
- | 434 | { |
|
- | 435 | eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
|
- | 436 | return 1; |
|
- | 437 | } |
|
- | 438 | else return 0; |
|
- | 439 | } |
|
- | 440 | ||
- | 441 | /***************************************************/ |
|
- | 442 | /* Write Mixer Table to EEPROM */ |
|
- | 443 | /***************************************************/ |
|
- | 444 | uint8_t MixerTable_WriteToEEProm(void) |
|
- | 445 | { |
|
- | 446 | if(Mixer.Revision == EEMIXER_REVISION) |
|
- | 447 | { |
|
- | 448 | eeprom_write_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
|
- | 449 | return 1; |
|
- | 450 | } |
|
- | 451 | else return 0; |
|
- | 452 | } |
|
- | 453 | ||
- | 454 | /***************************************************/ |
|
- | 455 | /* Default Values for Mixer Table */ |
|
- | 456 | /***************************************************/ |
|
- | 457 | void MixerTable_Default(void) // Quadro |
|
- | 458 | { |
|
- | 459 | uint8_t i; |
|
- | 460 | ||
- | 461 | Mixer.Revision = EEMIXER_REVISION; |
|
- | 462 | // clear mixer table |
|
- | 463 | for(i = 0; i < 16; i++) |
|
- | 464 | { |
|
- | 465 | Mixer.Motor[i][MIX_GAS] = 0; |
|
- | 466 | Mixer.Motor[i][MIX_NICK] = 0; |
|
- | 467 | Mixer.Motor[i][MIX_ROLL] = 0; |
|
- | 468 | Mixer.Motor[i][MIX_YAW] = 0; |
|
- | 469 | } |
|
- | 470 | // default = Quadro |
|
- | 471 | Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] = 0; Mixer.Motor[0][MIX_YAW] = +64; |
|
- | 472 | Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] = 0; Mixer.Motor[1][MIX_YAW] = +64; |
|
- | 473 | Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
|
- | 474 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
|
- | 475 | memcpy(Mixer.Name, "Quadro\0", 7); |
|
- | 476 | } |
|
- | 477 | ||
- | 478 | ||
428 | /***************************************************/ |
479 | /***************************************************/ |
429 | /* Get active parameter set */ |
480 | /* Get active parameter set */ |
430 | /***************************************************/ |
481 | /***************************************************/ |
431 | uint8_t GetActiveParamSet(void) |
482 | uint8_t GetActiveParamSet(void) |
432 | { |
483 | { |
Line 453... | Line 504... | ||
453 | /***************************************************/ |
504 | /***************************************************/ |
454 | /* Initialize EEPROM Parameter Sets */ |
505 | /* Initialize EEPROM Parameter Sets */ |
455 | /***************************************************/ |
506 | /***************************************************/ |
456 | void ParamSet_Init(void) |
507 | void ParamSet_Init(void) |
457 | { |
508 | { |
458 | uint8_t Channel_Backup = 0; |
509 | uint8_t Channel_Backup = 0, i; |
459 | // parameter version check |
510 | // parameter version check |
460 | if(eeprom_read_byte(&EEPromArray[PID_VERSION]) != EEPARAM_VERSION) |
511 | if(eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) |
461 | { |
512 | { |
462 | // if version check faild |
513 | // if version check faild |
463 | printf("\n\rInit. EEPROM"); |
514 | printf("\n\rInit Parameter in EEPROM"); |
464 | - | ||
- | 515 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table |
|
465 | // check if cannel mapping backup is valid |
516 | // check if channel mapping backup is valid |
466 | if( (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]) < 12) |
517 | if( (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]) < 12) |
467 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12) |
518 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12) |
468 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12) |
519 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12) |
469 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
520 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
470 | ) |
521 | ) |
471 | { |
522 | { |
472 | Channel_Backup = 1; |
523 | Channel_Backup = 1; |
473 | } |
524 | } |
474 | // fill all 5 parameter settings |
525 | // fill all 5 parameter settings |
475 | for (uint8_t i = 1;i < 6; i++) |
526 | for (i = 1;i < 6; i++) |
476 | { |
527 | { |
477 | switch(i) |
528 | switch(i) |
478 | { |
529 | { |
479 | case 1: |
530 | case 1: |
480 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
531 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
Line 504... | Line 555... | ||
504 | ParamSet_WriteToEEProm(i); |
555 | ParamSet_WriteToEEProm(i); |
505 | } |
556 | } |
506 | // default-Setting is parameter set 3 |
557 | // default-Setting is parameter set 3 |
507 | SetActiveParamSet(3); |
558 | SetActiveParamSet(3); |
508 | // update version info |
559 | // update version info |
509 | SetParamByte(PID_VERSION, EEPARAM_VERSION); |
560 | SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
510 | } |
561 | } |
511 | // read active parameter set to ParamSet stucture |
562 | // read active parameter set to ParamSet stucture |
512 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
563 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
513 | printf("\n\rUsing Parameter Set %d", GetActiveParamSet()); |
564 | printf("\n\rUsing Parameter Set %d", GetActiveParamSet()); |
- | 565 | ||
- | 566 | // load mixer table |
|
- | 567 | if(!MixerTable_ReadFromEEProm() ) |
|
- | 568 | { |
|
- | 569 | printf("\n\rGenerating default Mixer Table"); |
|
- | 570 | MixerTable_Default(); // Quadro |
|
- | 571 | MixerTable_WriteToEEProm(); |
|
- | 572 | } |
|
- | 573 | // determine motornumber |
|
- | 574 | RequiredMotors = 0; |
|
- | 575 | for(i = 0; i < 16; i++) |
|
- | 576 | { |
|
- | 577 | if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++; |
|
- | 578 | } |
|
- | 579 | ||
- | 580 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
|
- | 581 | printf("\n\r=============================="); |
|
514 | } |
582 | } |