Rev 321 | Rev 325 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 321 | Rev 324 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | #include <avr/interrupt.h> |
29 | #include <avr/interrupt.h> |
30 | #include <util/delay.h> |
30 | #include <util/delay.h> |
Line 31... | Line 31... | ||
31 | 31 | ||
32 | /* TODO: |
32 | /* TODO: |
- | 33 | * - verifiy correctness of values |
|
33 | * - verifiy correctness of values |
34 | * - clean up code :) |
Line 34... | Line 35... | ||
34 | */ |
35 | */ |
35 | 36 | ||
36 | /* ########################################################################## |
37 | /* ########################################################################## |
37 | * Debugging and general purpose definitions |
38 | * Debugging and general purpose definitions |
38 | * ##########################################################################*/ |
39 | * ##########################################################################*/ |
39 | #define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
40 | #define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
40 | #define WRITECHARS 0 // set to 1 and flash firmware to write new char |
41 | #define WRITECHARS 224 // set to 2XX and flash firmware to write new char |
41 | // enables the allchars as well to see results |
42 | // enables the allchars as well to see results |
- | 43 | #define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
|
- | 44 | #define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon |
|
- | 45 | #define NOOSD 0 // set to 1 to disable OSD completely |
|
42 | #define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
46 | #define NOOSD_BUT_WRN 0 // set to 1 to disable OSD completely but show |
43 | #define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon |
47 | // battery and receive signal warnings |
Line 44... | Line 48... | ||
44 | #define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
48 | #define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
45 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
49 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
Line 46... | Line 50... | ||
46 | 50 | ||
- | 51 | // ### read datasheet before changing stuff below this line :) |
|
- | 52 | #define BLINK 0b01001111 // attribute byte for blinking chars |
|
- | 53 | ||
- | 54 | /* ########################################################################## |
|
- | 55 | * FLAGS usable during runtime |
|
- | 56 | * ##########################################################################*/ |
|
- | 57 | #define COSD_FLAG_NTSC 1 |
|
- | 58 | #define COSD_FLAG_ARTHORIZON 2 |
|
47 | // ### read datasheet before changing stuff below this line :) |
59 | #define COSD_FLAG_NOOSD 4 |
48 | #define BLINK 0b01001111 // attribute byte for blinking chars |
60 | #define COSD_FLAG_NOOSD_BUT_WRN 8 |
49 | 61 | ||
50 | /* ########################################################################## |
62 | /* ########################################################################## |
51 | * Software SPI to communicate with MAX7456 |
63 | * Software SPI to communicate with MAX7456 |
Line 72... | Line 84... | ||
72 | #define LED4_OFF PORTC &= ~(1 << PC3); |
84 | #define LED4_OFF PORTC &= ~(1 << PC3); |
Line 73... | Line 85... | ||
73 | 85 | ||
74 | /* ########################################################################## |
86 | /* ########################################################################## |
75 | * switch controll |
87 | * switch controll |
76 | * ##########################################################################*/ |
88 | * ##########################################################################*/ |
77 | #define S1_PRESSED !(PINC & (1<<PC4)) |
89 | #define S1_PRESSED !(PINC & (1<<PC5)) |
Line 78... | Line 90... | ||
78 | #define S2_PRESSED !(PINC & (1<<PC5)) |
90 | #define S2_PRESSED !(PINC & (1<<PC4)) |
79 | 91 | ||
80 | /* ########################################################################## |
92 | /* ########################################################################## |
81 | * gain some fake arm compat :) |
93 | * gain some fake arm compat :) |
Line 96... | Line 108... | ||
96 | #define NC_FLAG_CH 4 |
108 | #define NC_FLAG_CH 4 |
97 | #define NC_FLAG_RANGE_LIMIT 8 |
109 | #define NC_FLAG_RANGE_LIMIT 8 |
98 | #define NC_SERIAL_LINK_OK 16 |
110 | #define NC_SERIAL_LINK_OK 16 |
99 | #define NC_FLAG_TARGET_REACHED 32 |
111 | #define NC_FLAG_TARGET_REACHED 32 |
Line 100... | Line -... | ||
100 | - | ||
101 | 112 | ||
102 | #define FLAG_MOTOR_RUN 1 |
113 | #define FLAG_MOTOR_RUN 1 |
103 | #define FLAG_FLY 2 |
114 | #define FLAG_FLY 2 |
104 | #define FLAG_CALIBRATE 4 |
115 | #define FLAG_CALIBRATE 4 |
Line 763... | Line 774... | ||
763 | 774 | ||
764 | /* ########################################################################## |
775 | /* ########################################################################## |
765 | * MAIN |
776 | * MAIN |
766 | * ##########################################################################*/ |
777 | * ##########################################################################*/ |
- | 778 | int main(void) { |
|
- | 779 | // set up FLAGS, compiler should flatten this one |
|
- | 780 | uint8_t COSD_FLAGS = (NTSC << (COSD_FLAG_NTSC - 1)); |
|
- | 781 | COSD_FLAGS |= (ARTHORIZON << (COSD_FLAG_ARTHORIZON - 1)); |
|
- | 782 | COSD_FLAGS |= (NOOSD << (COSD_FLAG_NOOSD - 1)); |
|
- | 783 | COSD_FLAGS |= (NOOSD_BUT_WRN << (COSD_FLAG_NOOSD_BUT_WRN - 1)); |
|
- | 784 | ||
767 | int main(void) { |
785 | // set up Atmega162 Ports |
768 | DDRA |= (1 << PA1); // PA1 output (/CS) |
786 | DDRA |= (1 << PA1); // PA1 output (/CS) |
769 | MAX_CS_HIGH |
787 | MAX_CS_HIGH |
770 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
788 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
771 | MAX_SDIN_LOW |
789 | MAX_SDIN_LOW |
Line 789... | Line 807... | ||
789 | PORTC |= (1 << PC5); // pullup |
807 | PORTC |= (1 << PC5); // pullup |
Line 790... | Line 808... | ||
790 | 808 | ||
791 | MAX_RESET_LOW |
809 | MAX_RESET_LOW |
Line -... | Line 810... | ||
- | 810 | MAX_RESET_HIGH |
|
- | 811 | ||
- | 812 | // check for keypress at startup |
|
- | 813 | if (S2_PRESSED) { // togle COSD_FLAG_ARTHORIZON |
|
- | 814 | COSD_FLAGS ^= (1 << (COSD_FLAG_ARTHORIZON - 1)); |
|
- | 815 | _delay_ms(100); |
|
792 | MAX_RESET_HIGH |
816 | } |
793 | 817 | ||
794 | // give the FC/NC and the maxim time to come up |
818 | // give the FC/NC and the maxim time to come up |
Line 795... | Line 819... | ||
795 | LED4_ON |
819 | LED4_ON |
Line 1114... | Line 1138... | ||
1114 | 0x88, 0x4a, 0xa0, 0x88, 0x4a, 0xa8, 0x11, 0x52, |
1138 | 0x88, 0x4a, 0xa0, 0x88, 0x4a, 0xa8, 0x11, 0x52, |
1115 | 0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55, |
1139 | 0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55, |
1116 | 0x55, 0x41, 0x55, 0x55, 0x55, 0x55}; |
1140 | 0x55, 0x41, 0x55, 0x55, 0x55, 0x55}; |
Line 1117... | Line 1141... | ||
1117 | 1141 | ||
1118 | 1142 | ||
- | 1143 | // flashing more than 8 chars per time is not proven to be safe |
|
1119 | // flashing more than 8 chars per time is not profen to be safe |
1144 | // so take care |
1120 | // so take care |
1145 | #if WRITECHARS == 200 |
1121 | /*learn_char(200, cc8); |
1146 | learn_char(200, cc8); |
1122 | learn_char(201, cc9); |
1147 | learn_char(201, cc9); |
1123 | learn_char(202, cca); |
1148 | learn_char(202, cca); |
1124 | learn_char(203, ccb); |
1149 | learn_char(203, ccb); |
1125 | learn_char(204, ccc); |
1150 | learn_char(204, ccc); |
1126 | learn_char(205, ccd); |
1151 | learn_char(205, ccd); |
- | 1152 | learn_char(206, cce); |
|
- | 1153 | learn_char(207, ccf); |
|
1127 | learn_char(206, cce); |
1154 | #endif |
1128 | learn_char(207, ccf);*/ |
1155 | #if WRITECHARS == 208 |
1129 | /*learn_char(208, cd0); |
1156 | learn_char(208, cd0); |
1130 | learn_char(209, cd1); |
1157 | learn_char(209, cd1); |
1131 | learn_char(210, cd2); |
1158 | learn_char(210, cd2); |
1132 | learn_char(211, cd3); |
1159 | learn_char(211, cd3); |
1133 | learn_char(212, cd4); |
1160 | learn_char(212, cd4); |
1134 | learn_char(213, cd5); |
1161 | learn_char(213, cd5); |
- | 1162 | learn_char(214, cd6); |
|
- | 1163 | learn_char(215, cd7); |
|
1135 | learn_char(214, cd6); |
1164 | #endif |
1136 | learn_char(215, cd7);*/ |
1165 | #if WRITECHARS == 216 |
1137 | /*learn_char(216, cd8); |
1166 | learn_char(216, cd8); |
1138 | learn_char(217, cd9); |
1167 | learn_char(217, cd9); |
1139 | learn_char(218, cda); |
1168 | learn_char(218, cda); |
1140 | learn_char(219, cdb); |
1169 | learn_char(219, cdb); |
1141 | learn_char(220, cdc); |
1170 | learn_char(220, cdc); |
1142 | learn_char(221, cdd); |
1171 | learn_char(221, cdd); |
- | 1172 | learn_char(222, cde); |
|
- | 1173 | learn_char(223, cdf); |
|
1143 | learn_char(222, cde); |
1174 | #endif |
1144 | learn_char(223, cdf);*/ |
1175 | #if WRITECHARS == 224 |
1145 | /*learn_char(224, ce0); |
1176 | learn_char(224, ce0); |
1146 | learn_char(225, ce1); |
1177 | learn_char(225, ce1); |
1147 | learn_char(226, ce2); |
1178 | learn_char(226, ce2); |
1148 | learn_char(227, ce3); |
1179 | learn_char(227, ce3); |
1149 | learn_char(228, ce4); |
1180 | learn_char(228, ce4); |
1150 | learn_char(229, ce5); |
1181 | learn_char(229, ce5); |
1151 | learn_char(230, ce6); |
1182 | learn_char(230, ce6); |
- | 1183 | learn_char(231, ce7); |
|
1152 | learn_char(231, ce7);*/ |
1184 | #endif |
1153 | #endif |
1185 | #endif // write char general |
1154 | /* ########################################################################## |
1186 | /* ########################################################################## |
- | 1187 | * continue normal main |
|
1155 | * continue normal main |
1188 | * ##########################################################################*/ |
- | 1189 | ||
- | 1190 | // Setup Video Mode |
|
- | 1191 | uint8_t top_line = 1; |
|
1156 | * ##########################################################################*/ |
1192 | uint8_t bottom_line = 0; |
1157 | #if NTSC |
1193 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
- | 1194 | // NTSC + enable display immediately (VM0) |
|
1158 | // NTSC + enable display immediately (VM0) |
1195 | spi_send_byte(0x00, 0b00001000); |
1159 | spi_send_byte(0x00, 0b00001000); |
1196 | bottom_line = 12; |
1160 | #else |
1197 | } else { |
- | 1198 | // PAL + enable display immediately (VM0) |
|
1161 | // PAL + enable display immediately (VM0) |
1199 | spi_send_byte(0x00, 0b01001000); |
Line 1162... | Line 1200... | ||
1162 | spi_send_byte(0x00, 0b01001000); |
1200 | bottom_line = 14; |
1163 | #endif |
1201 | } |
Line 1164... | Line 1202... | ||
1164 | 1202 | ||
Line 1236... | Line 1274... | ||
1236 | sendMKData('o', 1, &ms, 1); |
1274 | sendMKData('o', 1, &ms, 1); |
1237 | // and disable debug... |
1275 | // and disable debug... |
1238 | //ms = 0; |
1276 | //ms = 0; |
1239 | //sendMKData('d', 0, &ms, 1); |
1277 | //sendMKData('d', 0, &ms, 1); |
Line 1240... | Line -... | ||
1240 | - | ||
1241 | uint8_t top_line = 1; |
- | |
1242 | #if NTSC |
- | |
1243 | uint8_t bottom_line = 12; |
- | |
1244 | #else |
- | |
1245 | uint8_t bottom_line = 14; |
- | |
1246 | #endif |
1278 | |
1247 | // stats for after flight |
1279 | // stats for after flight |
1248 | int16_t max_Altimeter = 0; |
1280 | int16_t max_Altimeter = 0; |
1249 | uint16_t max_GroundSpeed = 0; |
1281 | uint16_t max_GroundSpeed = 0; |
- | 1282 | int16_t max_Distance = 0; |
|
- | 1283 | uint8_t min_UBat = 255; |
|
Line 1250... | Line 1284... | ||
1250 | int16_t max_Distance = 0; |
1284 | uint16_t max_FlyingTime = 0; |
1251 | 1285 | ||
Line 1252... | Line 1286... | ||
1252 | // flags from last round to check for changes |
1286 | // flags from last round to check for changes |
Line 1332... | Line 1366... | ||
1332 | write_char_xy(x, 5, 0); |
1366 | write_char_xy(x, 5, 0); |
1333 | write_char_xy(x, 7, 0); |
1367 | write_char_xy(x, 7, 0); |
1334 | write_char_xy(x, 9, 0); |
1368 | write_char_xy(x, 9, 0); |
1335 | } |
1369 | } |
1336 | } |
1370 | } |
1337 | #if ARTHORIZON |
1371 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
1338 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
1372 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
1339 | #endif |
1373 | } |
1340 | } else { |
1374 | } else { |
1341 | // stats |
1375 | // stats |
1342 | write_ascii_string(2, 5, "max Altitude:"); |
1376 | write_ascii_string(2, 5, "max Altitude:"); |
1343 | write_number_s(17, 5, max_Altimeter/10); |
1377 | write_number_s(17, 5, max_Altimeter/10); |
1344 | write_char_xy(22, 5, 204); // small meters m |
1378 | write_char_xy(22, 5, 204); // small meters m |
1345 | write_ascii_string(2, 7, "max Speed :"); |
1379 | write_ascii_string(2, 6, "max Speed :"); |
1346 | write_3digit_number_u(19, 7, (uint16_t)(((uint32_t)max_GroundSpeed*36)/1000)); |
1380 | write_3digit_number_u(19, 6, (uint16_t)(((uint32_t)max_GroundSpeed*36)/1000)); |
1347 | write_char_xy(22, 7, 203); // km/h |
1381 | write_char_xy(22, 6, 203); // km/h |
1348 | write_ascii_string(2, 9, "max Distance:"); |
1382 | write_ascii_string(2, 7, "max Distance:"); |
1349 | write_number_s(17, 9, max_Distance/100); |
1383 | write_number_s(17, 7, max_Distance/100); |
1350 | write_char_xy(22, 9, 204); // small meters m |
1384 | write_char_xy(22, 7, 204); // small meters m |
- | 1385 | write_ascii_string(2, 8, "min voltage :"); |
|
- | 1386 | //write_number_s(17, 8, min_UBat/10); |
|
- | 1387 | write_number_u_10th(16, 8, min_UBat); |
|
- | 1388 | write_ascii_string(22, 8, "V"); // voltage |
|
- | 1389 | write_ascii_string(2, 9, "max time :"); |
|
- | 1390 | write_number_s(17, 9, max_FlyingTime); |
|
- | 1391 | write_char_xy(22, 9, 210); // fly clock |
|
1351 | } |
1392 | } |
Line 1352... | Line 1393... | ||
1352 | 1393 | ||
1353 | // bottom line |
1394 | // bottom line |
1354 | write_number_u_10th(0, bottom_line, naviData.UBat); |
1395 | write_number_u_10th(0, bottom_line, naviData.UBat); |
Line 1380... | Line 1421... | ||
1380 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
1421 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
1381 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
1422 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
1382 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
1423 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
1383 | max_Distance = naviData.HomePositionDeviation.Distance; |
1424 | max_Distance = naviData.HomePositionDeviation.Distance; |
1384 | } |
1425 | } |
- | 1426 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
|
- | 1427 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
|
- | 1428 | ||
1385 | old_MKFlags = naviData.MKFlags; |
1429 | old_MKFlags = naviData.MKFlags; |
1386 | } |
1430 | } |
1387 | rxd_buffer_locked = 0; |
1431 | rxd_buffer_locked = 0; |
1388 | } |
1432 | } |
1389 | // handle keypress |
1433 | // handle keypress |