Subversion Repositories FlightCtrl

Rev

Rev 1927 | Rev 2099 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1910 - 1
#include <util/delay.h>
2
#include <avr/eeprom.h>
3
#include <stddef.h>
4
#include "configuration.h"
5
#include "eeprom.h"
6
#include "uart0.h"
7
 
8
int16_t variables[8] = {0,0,0,0,0,0,0,0};
2025 - 9
 
10
dynamicParam_t dynamicParams;
1910 - 11
uint8_t CPUType = ATMEGA644;
12
uint8_t BoardRelease = 13;
13
 
14
/************************************************************************
15
 * Map the parameter to pot values                                    
16
 * Replacing this code by the code below saved almost 1 kbyte.
17
 ************************************************************************/
18
 
19
void configuration_staticToDynamic(void) {
20
  uint8_t i;
21
#define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;}
22
#define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}}
23
  SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight);
24
  SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100);
25
  SET_POT_MM(dynamicParams.HeightP,staticParams.HeightP,0,100);
26
    SET_POT(dynamicParams.CompassYawEffect,staticParams.CompassYawEffect);
27
 
28
  SET_POT(dynamicParams.GyroPitchP,staticParams.GyroPitchP);
29
  SET_POT(dynamicParams.GyroRollP,staticParams.GyroRollP);
30
  SET_POT(dynamicParams.GyroYawP,staticParams.GyroYawP);
31
 
32
  SET_POT(dynamicParams.GyroPitchD,staticParams.GyroPitchD);
33
  SET_POT(dynamicParams.GyroRollD,staticParams.GyroRollD);
34
  SET_POT(dynamicParams.GyroYawD,staticParams.GyroYawD);
35
 
1926 - 36
  for (i=0; i<sizeof(staticParams.UserParams); i++) {
37
    SET_POT(dynamicParams.UserParams[i],staticParams.UserParams[i]);
1910 - 38
  }
2025 - 39
 
1910 - 40
  SET_POT_MM(dynamicParams.J16Timing,staticParams.J16Timing,1,255);
41
  SET_POT_MM(dynamicParams.J17Timing,staticParams.J17Timing,1,255);
42
 
43
  SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl);
44
}
45
 
46
uint8_t getCPUType(void) {   // works only after reset or power on when the registers have default values
47
  uint8_t CPUType = ATMEGA644;
48
  //if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P;  // initial Values for 644P after reset
49
  return CPUType;
50
}
51
 
52
/*
53
 * Automatic detection of hardware components is not supported in this development-oriented
54
 * FC firmware. It would go against the point of it: To enable alternative hardware
55
 * configurations with otherwise unsupported components. Instead, one should write
56
 * custom code + adjust constants for the new hardware, and include the relevant code
57
 * from the makefile.
58
 * However - we still do detect the board release. Reason: Otherwise it would be too
59
 * tedious to have to modify the code for how to turn on and off LEDs when deploying
60
 * on different HW version....
61
 */
62
 
63
uint8_t getBoardRelease(void) {
64
  uint8_t BoardRelease = 13;
65
  // the board release is coded via the pull up or down the 2 status LED
66
 
67
  PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate
68
  DDRB  &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input
69
 
70
  _delay_loop_2(1000); // make some delay
71
 
72
  switch( PINB & ((1<<PINB1)|(1<<PINB0))) {
73
    case 0x00:
74
      BoardRelease = 10; // 1.0
75
      break;
76
    case 0x01:
77
      BoardRelease = 11; // 1.1 or 1.2
78
      break;
79
    case 0x02:
80
      BoardRelease = 20; // 2.0
81
      break;
82
    case 0x03:
83
      BoardRelease = 13; // 1.3
84
      break;
85
    default:
86
      break;
87
    }
88
  // set LED ports as output
89
  DDRB |= (1<<DDB1)|(1<<DDB0);
90
  RED_ON;
91
  GRN_OFF;
92
  return BoardRelease;
93
}