31,6 → 31,7 |
|
/* TODO: |
* - verifiy correctness of values |
* - clean up code :) |
*/ |
|
/* ########################################################################## |
37,10 → 38,13 |
* Debugging and general purpose definitions |
* ##########################################################################*/ |
#define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
#define WRITECHARS 0 // set to 1 and flash firmware to write new char |
#define WRITECHARS 224 // set to 2XX and flash firmware to write new char |
// enables the allchars as well to see results |
#define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
#define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon |
#define NOOSD 0 // set to 1 to disable OSD completely |
#define NOOSD_BUT_WRN 0 // set to 1 to disable OSD completely but show |
// battery and receive signal warnings |
#define UBAT_WRN 94 // voltage for blinking warning, like FC settings |
#define RCLVL_WRN 100 // make the RC level blink if below this number |
|
48,6 → 52,14 |
#define BLINK 0b01001111 // attribute byte for blinking chars |
|
/* ########################################################################## |
* FLAGS usable during runtime |
* ##########################################################################*/ |
#define COSD_FLAG_NTSC 1 |
#define COSD_FLAG_ARTHORIZON 2 |
#define COSD_FLAG_NOOSD 4 |
#define COSD_FLAG_NOOSD_BUT_WRN 8 |
|
/* ########################################################################## |
* Software SPI to communicate with MAX7456 |
* ##########################################################################*/ |
#define MAX_CS_HIGH PORTA |= (1 << PA1); |
74,8 → 86,8 |
/* ########################################################################## |
* switch controll |
* ##########################################################################*/ |
#define S1_PRESSED !(PINC & (1<<PC4)) |
#define S2_PRESSED !(PINC & (1<<PC5)) |
#define S1_PRESSED !(PINC & (1<<PC5)) |
#define S2_PRESSED !(PINC & (1<<PC4)) |
|
/* ########################################################################## |
* gain some fake arm compat :) |
98,7 → 110,6 |
#define NC_SERIAL_LINK_OK 16 |
#define NC_FLAG_TARGET_REACHED 32 |
|
|
#define FLAG_MOTOR_RUN 1 |
#define FLAG_FLY 2 |
#define FLAG_CALIBRATE 4 |
765,6 → 776,13 |
* MAIN |
* ##########################################################################*/ |
int main(void) { |
// set up FLAGS, compiler should flatten this one |
uint8_t COSD_FLAGS = (NTSC << (COSD_FLAG_NTSC - 1)); |
COSD_FLAGS |= (ARTHORIZON << (COSD_FLAG_ARTHORIZON - 1)); |
COSD_FLAGS |= (NOOSD << (COSD_FLAG_NOOSD - 1)); |
COSD_FLAGS |= (NOOSD_BUT_WRN << (COSD_FLAG_NOOSD_BUT_WRN - 1)); |
|
// set up Atmega162 Ports |
DDRA |= (1 << PA1); // PA1 output (/CS) |
MAX_CS_HIGH |
DDRA |= (1 << PA2); // PA2 output (SDIN) |
791,6 → 809,12 |
MAX_RESET_LOW |
MAX_RESET_HIGH |
|
// check for keypress at startup |
if (S2_PRESSED) { // togle COSD_FLAG_ARTHORIZON |
COSD_FLAGS ^= (1 << (COSD_FLAG_ARTHORIZON - 1)); |
_delay_ms(100); |
} |
|
// give the FC/NC and the maxim time to come up |
LED4_ON |
_delay_ms(2000); |
1116,9 → 1140,10 |
0x55, 0x41, 0x55, 0x55, 0x55, 0x55}; |
|
|
// flashing more than 8 chars per time is not profen to be safe |
// flashing more than 8 chars per time is not proven to be safe |
// so take care |
/*learn_char(200, cc8); |
#if WRITECHARS == 200 |
learn_char(200, cc8); |
learn_char(201, cc9); |
learn_char(202, cca); |
learn_char(203, ccb); |
1125,8 → 1150,10 |
learn_char(204, ccc); |
learn_char(205, ccd); |
learn_char(206, cce); |
learn_char(207, ccf);*/ |
/*learn_char(208, cd0); |
learn_char(207, ccf); |
#endif |
#if WRITECHARS == 208 |
learn_char(208, cd0); |
learn_char(209, cd1); |
learn_char(210, cd2); |
learn_char(211, cd3); |
1133,8 → 1160,10 |
learn_char(212, cd4); |
learn_char(213, cd5); |
learn_char(214, cd6); |
learn_char(215, cd7);*/ |
/*learn_char(216, cd8); |
learn_char(215, cd7); |
#endif |
#if WRITECHARS == 216 |
learn_char(216, cd8); |
learn_char(217, cd9); |
learn_char(218, cda); |
learn_char(219, cdb); |
1141,8 → 1170,10 |
learn_char(220, cdc); |
learn_char(221, cdd); |
learn_char(222, cde); |
learn_char(223, cdf);*/ |
/*learn_char(224, ce0); |
learn_char(223, cdf); |
#endif |
#if WRITECHARS == 224 |
learn_char(224, ce0); |
learn_char(225, ce1); |
learn_char(226, ce2); |
learn_char(227, ce3); |
1149,18 → 1180,25 |
learn_char(228, ce4); |
learn_char(229, ce5); |
learn_char(230, ce6); |
learn_char(231, ce7);*/ |
learn_char(231, ce7); |
#endif |
#endif // write char general |
/* ########################################################################## |
* continue normal main |
* ##########################################################################*/ |
#if NTSC |
// NTSC + enable display immediately (VM0) |
spi_send_byte(0x00, 0b00001000); |
#else |
// PAL + enable display immediately (VM0) |
spi_send_byte(0x00, 0b01001000); |
#endif |
|
// Setup Video Mode |
uint8_t top_line = 1; |
uint8_t bottom_line = 0; |
if (COSD_FLAGS & COSD_FLAG_NTSC) { |
// NTSC + enable display immediately (VM0) |
spi_send_byte(0x00, 0b00001000); |
bottom_line = 12; |
} else { |
// PAL + enable display immediately (VM0) |
spi_send_byte(0x00, 0b01001000); |
bottom_line = 14; |
} |
|
// clear all display-mem (DMM) |
spi_send_byte(0x04, 0b00000100); |
1238,16 → 1276,12 |
//ms = 0; |
//sendMKData('d', 0, &ms, 1); |
|
uint8_t top_line = 1; |
#if NTSC |
uint8_t bottom_line = 12; |
#else |
uint8_t bottom_line = 14; |
#endif |
// stats for after flight |
int16_t max_Altimeter = 0; |
uint16_t max_GroundSpeed = 0; |
int16_t max_Distance = 0; |
uint8_t min_UBat = 255; |
uint16_t max_FlyingTime = 0; |
|
// flags from last round to check for changes |
uint8_t old_MKFlags = 0; |
1334,20 → 1368,27 |
write_char_xy(x, 9, 0); |
} |
} |
#if ARTHORIZON |
draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
#endif |
if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
} |
} else { |
// stats |
write_ascii_string(2, 5, "max Altitude:"); |
write_number_s(17, 5, max_Altimeter/10); |
write_char_xy(22, 5, 204); // small meters m |
write_ascii_string(2, 7, "max Speed :"); |
write_3digit_number_u(19, 7, (uint16_t)(((uint32_t)max_GroundSpeed*36)/1000)); |
write_char_xy(22, 7, 203); // km/h |
write_ascii_string(2, 9, "max Distance:"); |
write_number_s(17, 9, max_Distance/100); |
write_char_xy(22, 9, 204); // small meters m |
write_ascii_string(2, 6, "max Speed :"); |
write_3digit_number_u(19, 6, (uint16_t)(((uint32_t)max_GroundSpeed*36)/1000)); |
write_char_xy(22, 6, 203); // km/h |
write_ascii_string(2, 7, "max Distance:"); |
write_number_s(17, 7, max_Distance/100); |
write_char_xy(22, 7, 204); // small meters m |
write_ascii_string(2, 8, "min voltage :"); |
//write_number_s(17, 8, min_UBat/10); |
write_number_u_10th(16, 8, min_UBat); |
write_ascii_string(22, 8, "V"); // voltage |
write_ascii_string(2, 9, "max time :"); |
write_number_s(17, 9, max_FlyingTime); |
write_char_xy(22, 9, 210); // fly clock |
} |
|
// bottom line |
1382,6 → 1423,9 |
if (naviData.HomePositionDeviation.Distance > max_Distance) { |
max_Distance = naviData.HomePositionDeviation.Distance; |
} |
if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
|
old_MKFlags = naviData.MKFlags; |
} |
rxd_buffer_locked = 0; |