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