Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 330 → Rev 331

/C-OSD/trunk/main.c/main.c
28,6 → 28,8
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "max7456_software_spi.c"
#include "usart1.h"
 
/* TODO:
* - verifiy correctness of values
68,18 → 70,6
#define COSD_ICONS_WRITTEN 16
 
/* ##########################################################################
* Software SPI to communicate with MAX7456
* ##########################################################################*/
#define MAX_CS_HIGH PORTA |= (1 << PA1);
#define MAX_CS_LOW PORTA &= ~(1 << PA1);
#define MAX_SDIN_HIGH PORTA |= (1 << PA2);
#define MAX_SDIN_LOW PORTA &= ~(1 << PA2);
#define MAX_SCLK_HIGH PORTA |= (1 << PA3);
#define MAX_SCLK_LOW PORTA &= ~(1 << PA3);
#define MAX_RESET_HIGH PORTA |= (1 << PA5);
#define MAX_RESET_LOW PORTA &= ~(1 << PA5);
 
/* ##########################################################################
* LED controll
* ##########################################################################*/
#define LED1_ON PORTC |= (1 << PC0);
97,94 → 87,13
#define S1_PRESSED !(PINC & (1<<PC5))
#define S2_PRESSED !(PINC & (1<<PC4))
 
/* ##########################################################################
* gain some fake arm compat :)
* ##########################################################################*/
#define u8 uint8_t
#define s8 int8_t
#define u16 uint16_t
#define s16 int16_t
#define u32 uint32_t
#define s32 int32_t
 
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
/* ##########################################################################
* MK data strucs & flags
* ##########################################################################*/
#define NC_FLAG_FREE 1
#define NC_FLAG_PH 2
#define NC_FLAG_CH 4
#define NC_FLAG_RANGE_LIMIT 8
#define NC_SERIAL_LINK_OK 16
#define NC_FLAG_TARGET_REACHED 32
// data structs
#include "mk-data-structs.h"
 
#define FLAG_MOTOR_RUN 1
#define FLAG_FLY 2
#define FLAG_CALIBRATE 4
#define FLAG_START 8
 
/*
* FC Debug Struct
* portions taken and adapted from
* http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.h
*/
typedef struct {
uint8_t Digital[2];
uint16_t Analog[32]; // Debugvalues
} __attribute__((packed)) DebugOut_t;
 
/*
* NaviCtrl OSD Structs
* portions taken and adapted from
* http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=NaviCtrl&path=%2Ftags%2FV0.14e%2Fuart1.h
*/
typedef struct {
s32 Longitude; // in 1E-7 deg
s32 Latitude; // in 1E-7 deg
s32 Altitude; // in mm
u8 Status; // validity of data
} __attribute__((packed)) GPS_Pos_t;
 
typedef struct {
s16 Distance; // distance to target in cm
s16 Bearing; // course to target in deg
} __attribute__((packed)) GPS_PosDev_t;
 
typedef struct {
GPS_Pos_t CurrentPosition; // see ubx.h for details
GPS_Pos_t TargetPosition;
GPS_PosDev_t TargetPositionDeviation;
GPS_Pos_t HomePosition;
GPS_PosDev_t HomePositionDeviation;
u8 WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1
u8 WaypointNumber; // number of stored waypoints
u8 SatsInUse; // no of satellites used for position solution
s16 Altimeter; // hight according to air pressure
s16 Variometer; // climb(+) and sink(-) rate
u16 FlyingTime; // in seconds
u8 UBat; // Battery Voltage in 0.1 Volts
u16 GroundSpeed; // speed over ground in cm/s (2D)
s16 Heading; // current flight direction in deg as angle to north
s16 CompassHeading; // current compass value
s8 AngleNick; // current Nick angle in 1°
s8 AngleRoll; // current Rick angle in 1°
u8 RC_Quality; // RC_Quality
u8 MKFlags; // Flags from FC
u8 NCFlags; // Flags from NC
u8 Errorcode; // 0 --> okay
u8 OperatingRadius; // current operation radius around the Home Position in m
u8 Reserve[7]; // for future use
} __attribute__((packed)) NaviData_t;
 
 
/* ##########################################################################
* global definitions and global vars
* ##########################################################################*/
#define baud 57600
 
#define RXD_BUFFER_LEN 150
#define TXD_BUFFER_LEN 150
 
volatile uint8_t rxd_buffer_locked = 0;
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
205,6 → 114,9
volatile uint16_t uptime = 0;
volatile uint16_t timer = 0;
 
// remember last time data was received
volatile uint8_t seconds_since_last_data = 0;
 
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
 
// general PAL|NTSC distingiusch stuff
233,450 → 145,21
return 0;
}
 
/* ##########################################################################
* MAX7456 SPI & Display stuff
* ##########################################################################*/
 
/**
* Send a byte through SPI
*/
void spi_send(uint8_t byte) {
for (int8_t i = 7; i >= 0; i--) {
if (((byte >> i) & 1)) {
MAX_SDIN_HIGH
} else {
MAX_SDIN_LOW
}
MAX_SCLK_HIGH
MAX_SCLK_LOW
}
}
 
/**
* Send <byte> to <address> of MAX7456
*/
void spi_send_byte(uint8_t address, uint8_t byte) {
// start sending
MAX_CS_LOW
 
spi_send(address);
spi_send(byte);
 
// end sending
MAX_CS_HIGH
}
 
/**
* write a <character> to <address> of MAX7456 display memory
*/
void write_char(uint16_t address, char character) {
spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
spi_send_byte(0x06, (address & 0x00FF)); // DMAL
spi_send_byte(0x07, character); // DMDI
}
 
/**
* write a character <attribute> to <address> of MAX7456 display memory
*/
void write_char_att(uint16_t address, char attribute) {
// the only important part is that the DMAH[1] is set
// so we add 2 which binary is the 2nd lowest byte
spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
spi_send_byte(0x06, (address & 0x00FF)); // DMAL
spi_send_byte(0x07, attribute); // DMDI
}
 
/**
* write a <character> at <x>/<y> to MAX7456 display memory
*/
void write_char_xy(uint8_t x, uint8_t y, char character) {
uint16_t address = y * 30 + x;
write_char(address, character);
}
 
/**
* write a character <attribute> at <x>/<y> to MAX7456 display memory
*/
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
uint16_t address = y * 30 + x;
write_char_att(address, attribute);
}
 
/**
* clear display by writing blank characters all over it
*/
void clear(void) {
uint16_t memory_address = 0;
for (unsigned int a = 0; a < 480; a++) {
write_char(memory_address++, 0);
}
}
 
/**
* write an ascii <character> to <address> of MAX7456 display memory
*/
void write_ascii_char(uint16_t address, char c) {
if (c == 32) c = 0; // remap space
else if (c > 48 && c <= 57) c -= 48; // remap numbers
else if (c == '0') c = 10; // remap zero
else if (c >= 65 && c <= 90) c -= 54; // remap big letters
else if (c >= 97 && c <= 122) c -= 60; // remap small letters
else if (c == '(') c = 63; // remap
else if (c == ')') c = 64; // remap
else if (c == '.') c = 65; // remap
else if (c == '?') c = 66; // remap
else if (c == ';') c = 67; // remap
else if (c == ':') c = 68; // remap
else if (c == ',') c = 69; // remap
else if (c == '\'') c = 70; // remap
else if (c == '/') c = 71; // remap
else if (c == '"') c = 72; // remap
else if (c == '-') c = 73; // remap minus
else if (c == '<') c = 74; // remap
else if (c == '>') c = 75; // remap
else if (c == '@') c = 76; // remap
write_char(address, c);
}
 
/**
* write an ascii <string> at <x>/<y> to MAX7456 display memory
*/
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
while (*string) {
write_ascii_char(((x++)+(y * 30)), *string);
string++;
}
}
 
/**
* Write only the last three digits of a <number> at <x>/<y> to MAX7456
* display memory. takes full 16bit numbers as well for stuff
* like compass only taking three characters (values <= 999)
*/
void write_3digit_number_u(uint8_t x, uint8_t y, uint16_t number) {
uint16_t num = 100;
uint8_t started = 0;
 
while (num > 0) {
uint8_t b = number / num;
if (b > 0 || started || num == 1) {
write_ascii_char((x++)+(y * 30), '0' + b);
started = 1;
} else {
write_ascii_char((x++)+(y * 30), 0);
}
number -= b * num;
 
num /= 10;
}
}
 
/**
* Write only the last two digits of a number at <x>/<y> to MAX7456
* display memory. takes full 16bit numbers as well for stuff
* like seconds only taking two characters (values <= 99)
* Since this is used for seconds only and it looks better, there
* is a trading 0 attached
*/
void write_2digit_number_u(uint8_t x, uint8_t y, uint16_t number) {
uint16_t num = 10;
uint8_t started = 0;
 
while (num > 0) {
uint8_t b = number / num;
if (b > 0 || started || num == 1) {
write_ascii_char((x++)+(y * 30), '0' + b);
started = 1;
} else {
write_ascii_char((x++)+(y * 30), '0');
}
number -= b * num;
 
num /= 10;
}
}
 
/**
* write a unsigned number as /10th at <x>/<y> to MAX7456 display memory
*/
void write_number_u_10th(uint8_t x, uint8_t y, uint16_t number) {
uint16_t num = 10000;
uint8_t started = 0;
 
while (num > 0) {
uint8_t b = number / num;
 
if (b > 0 || started || num == 1) {
if ((num / 10) == 0) write_char((x++)+(y * 30), 65);
write_ascii_char((x++)+(y * 30), '0' + b);
started = 1;
} else {
write_ascii_char((x++)+(y * 30), 0);
}
number -= b * num;
 
num /= 10;
}
}
 
/**
* write a unsigned number at <x>/<y> to MAX7456 display memory
*/
void write_number_u(uint8_t x, uint8_t y, uint16_t number) {
uint16_t num = 10000;
uint8_t started = 0;
 
while (num > 0) {
uint8_t b = number / num;
if (b > 0 || started || num == 1) {
write_ascii_char((x++)+(y * 30), '0' + b);
started = 1;
} else {
write_ascii_char((x++)+(y * 30), 0);
}
number -= b * num;
 
num /= 10;
}
}
 
/**
* write a signed number at <x>/<y> to MAX7456 display memory
*/
void write_number_s(uint8_t x, uint8_t y, int16_t w) {
if (((uint16_t) w) > 32767) {
w = w - 65536;
 
int16_t num = -10000;
uint8_t started = 0;
 
while (num < 0) {
uint8_t b = w / num;
if (b > 0 || started || num == 1) {
if (!started) write_char((x - 1)+(y * 30), 0x49);
write_ascii_char((x++)+(y * 30), '0' + b);
started = 1;
} else {
write_ascii_char((x++)+(y * 30), 0);
}
w -= b * num;
 
num /= 10;
}
} else {
write_char((x)+(y * 30), 0);
write_number_u(x, y, w);
}
}
 
/**
* write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
*/
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
uint16_t min = seconds / 60;
seconds -= min * 60;
write_3digit_number_u(x, y, min);
write_char_xy(x + 3, y, 68);
write_2digit_number_u(x + 4, y, seconds);
}
 
/**
* for testing write all chars to screen
*/
void write_all_chars() {
uint16_t x = 3, y = 2, t = 0;
while (t < 256) {
write_char_xy(x++, y, t++);
if (x > 25) {
y++;
x = 3;
}
}
}
 
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
/* ##########################################################################
* USART stuff
* ##########################################################################*/
 
/**
* init usart1
* serial support
*/
void usart1_init() {
UBRR1H = ((F_CPU / (16UL * baud)) - 1) >> 8;
UBRR1L = (F_CPU / (16UL * baud)) - 1;
#include "usart1.c"
 
// Enable receiver and transmitter; enable RX interrupt
UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
 
//asynchronous 8N1
UCSR1C = (1 << URSEL1) | (3 << UCSZ10);
}
 
/**
* send a single <character> through usart1
*/
void usart1_putc(unsigned char character) {
// wait until UDR ready
while (!(UCSR1A & (1 << UDRE1)));
UDR1 = character;
}
 
/**
* send a <string> throught usart1
*/
void usart1_puts(char *s) {
while (*s) {
usart1_putc(*s);
s++;
}
}
 
/**
* receive data through usart1
* portions taken and adapted from
* http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c
*/
ISR(SIG_USART1_RECV) {
if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return
LED1_ON
static uint16_t crc;
static uint8_t ptr_rxd_buffer = 0;
uint8_t crc1, crc2;
uint8_t c;
 
c = UDR1; // catch the received byte
 
// the rxd buffer is unlocked
if ((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received
{
/*
// skip other datasets
if (ptr_rxd_buffer == 2 && rxd_buffer[ptr_rxd_buffer] != 'O') {
ptr_rxd_buffer = 0; // reset rxd buffer
rxd_buffer_locked = 0; // unlock rxd buffer
}*/
rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer
crc = c; // init crc
} else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes
{
if (c != '\r') // no termination character
{
rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer
crc += c; // update crc
} else // termination character was received
{
// the last 2 bytes are no subject for checksum calculation
// they are the checksum itself
crc -= rxd_buffer[ptr_rxd_buffer - 2];
crc -= rxd_buffer[ptr_rxd_buffer - 1];
// calculate checksum from transmitted data
crc %= 4096;
crc1 = '=' + crc / 64;
crc2 = '=' + crc % 64;
// compare checksum to transmitted checksum bytes
if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 == rxd_buffer[ptr_rxd_buffer - 1])) { // checksum valid
rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes
rxd_buffer_locked = 1; // lock the rxd buffer
} else { // checksum invalid
rxd_buffer_locked = 0; // unlock rxd buffer
}
ptr_rxd_buffer = 0; // reset rxd buffer pointer
}
} else // rxd buffer overrun
{
ptr_rxd_buffer = 0; // reset rxd buffer
rxd_buffer_locked = 0; // unlock rxd buffer
}
LED1_OFF
}
 
/**
* Decode the recevied Buffer
* portions taken and adapted from
* http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c
*/
void Decode64(void) {
uint8_t a, b, c, d;
uint8_t x, y, z;
uint8_t ptrIn = 3;
uint8_t ptrOut = 3;
uint8_t len = ReceivedBytes - 6;
 
while (len) {
a = rxd_buffer[ptrIn++] - '=';
b = rxd_buffer[ptrIn++] - '=';
c = rxd_buffer[ptrIn++] - '=';
d = rxd_buffer[ptrIn++] - '=';
 
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
 
if (len--) rxd_buffer[ptrOut++] = x;
else break;
if (len--) rxd_buffer[ptrOut++] = y;
else break;
if (len--) rxd_buffer[ptrOut++] = z;
else break;
}
pRxData = &rxd_buffer[3];
RxDataLen = ptrOut - 3;
}
 
/**
* request Data through USART in special MK format by adding checksum and
* encode data in modified Base64
* portions taken and adapted from
* http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c
*/
void sendMKData(unsigned char cmd, unsigned char addr, unsigned char *snd, unsigned char len) {
unsigned int pt = 0;
unsigned char a, b, c;
unsigned char ptr = 0;
 
txd_buffer[pt++] = '#'; // Start-Byte
txd_buffer[pt++] = 'a' + addr; // Adress
txd_buffer[pt++] = cmd; // Command
while (len) {
if (len) {
a = snd[ptr++];
len--;
} else a = 0;
if (len) {
b = snd[ptr++];
len--;
} else b = 0;
if (len) {
c = snd[ptr++];
len--;
} else c = 0;
txd_buffer[pt++] = '=' + (a >> 2);
txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
txd_buffer[pt++] = '=' + (c & 0x3f);
}
 
// add crc
unsigned int tmpCRC = 0, i;
for (i = 0; i < pt; i++) {
tmpCRC += txd_buffer[i];
}
tmpCRC %= 4096;
txd_buffer[i++] = '=' + tmpCRC / 64;
txd_buffer[i++] = '=' + tmpCRC % 64;
txd_buffer[i++] = '\r';
 
usart1_puts((char*) txd_buffer);
}
 
/* ##########################################################################
* timer stuff
* ##########################################################################*/
 
/*
* timer kicks in every 1000uS
/**
* timer kicks in every 1000uS ^= 1ms
*/
ISR(TIMER0_OVF_vect) {
OCR0 = 6; // preload
683,6 → 166,7
if (!timer--) {
uptime++;
timer = 999;
seconds_since_last_data++;
}
}
 
923,419 → 407,15
 
LED4_OFF
 
/* ##########################################################################
* Pushing NEW chars to the MAX7456
* ##########################################################################*/
 
//Pushing NEW chars to the MAX7456
#if (WRITECHARS != -1)
void learn_char(uint8_t number, unsigned char* data) {
// select character to write (CMAH)
spi_send_byte(0x09, number);
 
for (uint8_t i = 0; i < 54; i++) {
// select 4pixel byte of char (CMAL)
spi_send_byte(0x0A, i);
 
// write 4pixel byte of char (CMDI)
spi_send_byte(0x0B, data[i]);
}
 
// write to the NVM array from the shadow RAM (CMM)
spi_send_byte(0x08, 0b10100000);
 
// according to maxim writing to nvram takes about 12ms, lets wait longer
_delay_ms(120);
}
 
// DISABLE display (VM0)
// DISABLE display (VM0)
spi_send_byte(0x00, 0b00000000);
 
/**
* easy char creation:
* http://cascade.dyndns.org/~cascade/scripts/max7456/
*/
// flashing more than 8 chars per time is not proven to be safe
// so take care
#if WRITECHARS == 200
// GPS
unsigned char cc8[54] = {0x55, 0x50, 0x55, 0x55, 0x4a, 0x15, 0x55, 0x2a,
0x85, 0x55, 0x2a, 0xa1, 0x55, 0x4a, 0xa8, 0x55,
0x52, 0xa8, 0x55, 0x54, 0xaa, 0x55, 0x55, 0x09,
0x55, 0x55, 0x52, 0x55, 0x55, 0x1a, 0x55, 0x51,
0x96, 0x55, 0x18, 0x85, 0x54, 0x88, 0x28, 0x54,
0x82, 0x05, 0x55, 0x20, 0xa1, 0x55, 0x48, 0x15,
0x55, 0x52, 0x85, 0x55, 0x54, 0x15};
#include "characters.c"
#endif
 
unsigned char cc9[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x45,
0x55, 0x55, 0x21, 0x55, 0x55, 0xa8, 0x55, 0x55,
0xa1, 0x55, 0x55, 0x98, 0x15, 0x55, 0x2a, 0x85,
0x55, 0x4a, 0xa1, 0x55, 0x4a, 0xa8, 0x55, 0x52,
0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55,
0x55, 0x41, 0x55, 0x55, 0x55, 0x55};
 
// RC
unsigned char cca[54] = {0x54, 0xaa, 0x85, 0x52, 0x00, 0x21, 0x48, 0x2a,
0x08, 0x60, 0x80, 0x82, 0x62, 0x08, 0x22, 0x62,
0x2a, 0x22, 0x62, 0x08, 0x22, 0x60, 0x88, 0x82,
0x48, 0x08, 0x08, 0x52, 0x08, 0x21, 0x54, 0x48,
0x45, 0x55, 0x48, 0x55, 0x55, 0x48, 0x55, 0x55,
0x48, 0x55, 0x55, 0x48, 0x55, 0x55, 0x48, 0x55,
0x55, 0x2a, 0x15, 0x54, 0xaa, 0x85};
 
// km/h
unsigned char ccb[54] = {0x55, 0x55, 0x55, 0x01, 0x55, 0x55, 0x21, 0x55,
0x55, 0x20, 0x15, 0x55, 0x22, 0x15, 0x55, 0x28,
0x15, 0x55, 0x22, 0x15, 0x55, 0x00, 0x00, 0x15,
0x52, 0xaa, 0x15, 0x52, 0x22, 0x15, 0x52, 0x22,
0x15, 0x50, 0x00, 0x05, 0x55, 0x54, 0x85, 0x55,
0x54, 0x80, 0x55, 0x54, 0xa8, 0x55, 0x54, 0x88,
0x55, 0x54, 0x88, 0x55, 0x54, 0x00};
 
 
// small meters m
unsigned char ccc[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x15, 0x22,
0x8a, 0x15, 0x28, 0xa2, 0x15, 0x20, 0x82, 0x15,
0x20, 0x82, 0x15, 0x00, 0x00, 0x15};
 
// vario down
unsigned char ccd[54] = {0x55, 0x00, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55,
0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55,
0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
0x55, 0x00, 0x28, 0x00, 0x2a, 0xaa, 0xa8, 0x0a,
0xaa, 0xa0, 0x42, 0xaa, 0x81, 0x50, 0xaa, 0x05,
0x54, 0x28, 0x15, 0x55, 0x00, 0x55};
 
// vario hold
unsigned char cce[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x00,
0x2a, 0xaa, 0xa8, 0x2a, 0xaa, 0xa8, 0x00, 0x00,
0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// vario up
unsigned char ccf[54] = {0x55, 0x00, 0x55, 0x54, 0x28, 0x15, 0x50, 0xaa,
0x05, 0x42, 0xaa, 0x81, 0x0a, 0xaa, 0xa0, 0x2a,
0xaa, 0xa8, 0x00, 0x28, 0x00, 0x55, 0x28, 0x55,
0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55,
0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55,
0x55, 0x28, 0x55, 0x55, 0x00, 0x55};
 
learn_char(200, cc8);
learn_char(201, cc9);
learn_char(202, cca);
learn_char(203, ccb);
learn_char(204, ccc);
learn_char(205, ccd);
learn_char(206, cce);
learn_char(207, ccf);
#endif
#if WRITECHARS == 208
// degree symbol
unsigned char cd0[54] = {0x55, 0x55, 0x55, 0x54, 0x01, 0x55, 0x52, 0xa8,
0x55, 0x48, 0x02, 0x15, 0x48, 0x52, 0x15, 0x48,
0x52, 0x15, 0x48, 0x02, 0x15, 0x52, 0xa8, 0x55,
0x54, 0x01, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// clock on symbol
unsigned char cd1[54] = {0x54, 0x14, 0x51, 0x52, 0x82, 0x08, 0x48, 0x22,
0x88, 0x48, 0x22, 0x28, 0x48, 0x22, 0x28, 0x52,
0x82, 0x08, 0x54, 0x14, 0x51, 0x55, 0x40, 0x55,
0x55, 0x2a, 0x15, 0x54, 0x88, 0x85, 0x52, 0x08,
0x21, 0x48, 0x48, 0x08, 0x48, 0x4a, 0x88, 0x48,
0x50, 0x08, 0x52, 0x15, 0x21, 0x54, 0x80, 0x85,
0x55, 0x2a, 0x15, 0x55, 0x40, 0x55};
 
// clock fly symbol
unsigned char cd2[54] = {0x40, 0x45, 0x11, 0x2a, 0x20, 0x88, 0x20, 0x20,
0x88, 0x28, 0x21, 0x21, 0x21, 0x20, 0x21, 0x21,
0x2a, 0x21, 0x45, 0x40, 0x45, 0x55, 0x40, 0x55,
0x55, 0x2a, 0x15, 0x54, 0x88, 0x85, 0x52, 0x08,
0x21, 0x48, 0x48, 0x08, 0x48, 0x4a, 0x88, 0x48,
0x50, 0x08, 0x52, 0x15, 0x21, 0x54, 0x80, 0x85,
0x55, 0x2a, 0x15, 0x55, 0x40, 0x55};
 
// compass north
unsigned char cd3[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
0x54, 0x55, 0x52, 0x12, 0x15, 0x52, 0x82, 0x15,
0x02, 0x82, 0x00, 0xa2, 0x22, 0x2a, 0x02, 0x0a,
0x00, 0x52, 0x0a, 0x15, 0x52, 0x12, 0x15, 0x54,
0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// compass south
unsigned char cd4[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x01, 0x55, 0x54, 0xa8, 0x55, 0x52, 0x02, 0x15,
0x04, 0x84, 0x40, 0xa1, 0x21, 0x2a, 0x04, 0x48,
0x40, 0x52, 0x02, 0x15, 0x54, 0xa8, 0x55, 0x55,
0x01, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// compass east
unsigned char cd5[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
0x00, 0x55, 0x52, 0xaa, 0x15, 0x52, 0x00, 0x55,
0x02, 0x05, 0x40, 0xa2, 0xa1, 0x2a, 0x02, 0x05,
0x40, 0x52, 0x00, 0x55, 0x52, 0xaa, 0x15, 0x54,
0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// compass west
unsigned char cd6[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
0x54, 0x55, 0x52, 0x12, 0x15, 0x52, 0x12, 0x15,
0x02, 0x02, 0x00, 0xa2, 0x22, 0x2a, 0x02, 0x8a,
0x00, 0x52, 0x8a, 0x15, 0x52, 0x12, 0x15, 0x54,
0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// compass between
unsigned char cd7[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x45, 0x55, 0x55, 0x21, 0x55,
0x01, 0x21, 0x00, 0xa8, 0x20, 0xaa, 0x01, 0x21,
0x00, 0x55, 0x21, 0x55, 0x55, 0x45, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
learn_char(208, cd0);
learn_char(209, cd1);
learn_char(210, cd2);
learn_char(211, cd3);
learn_char(212, cd4);
learn_char(213, cd5);
learn_char(214, cd6);
learn_char(215, cd7);
#endif
#if WRITECHARS == 216
// compass line
unsigned char cd8[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0x00, 0x00,
0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow right
unsigned char cd9[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x15, 0x55, 0x54, 0x85, 0x40, 0x00, 0xa1,
0x2a, 0xaa, 0xa8, 0x2a, 0xaa, 0xa8, 0x40, 0x00,
0xa1, 0x55, 0x54, 0x85, 0x55, 0x55, 0x15, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow right-up
unsigned char cda[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x40, 0x01, 0x55, 0x2a, 0xa8, 0x55,
0x4a, 0xa8, 0x55, 0x52, 0xa8, 0x55, 0x4a, 0xa8,
0x55, 0x2a, 0x28, 0x54, 0xa8, 0x48, 0x52, 0xa1,
0x51, 0x4a, 0x85, 0x55, 0x52, 0x15, 0x55, 0x54,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow up
unsigned char cdb[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x41, 0x55, 0x55, 0x28, 0x55, 0x54,
0xaa, 0x15, 0x52, 0xaa, 0x85, 0x54, 0x28, 0x15,
0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55,
0x28, 0x55, 0x55, 0x41, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow left-up
unsigned char cdc[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x40, 0x01, 0x55, 0x2a, 0xa8, 0x55, 0x2a,
0xa1, 0x55, 0x2a, 0x85, 0x55, 0x2a, 0xa1, 0x55,
0x28, 0xa8, 0x55, 0x21, 0x2a, 0x15, 0x45, 0x4a,
0x85, 0x55, 0x52, 0xa1, 0x55, 0x54, 0x85, 0x55,
0x55, 0x15, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow left
unsigned char cdd[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
0x55, 0x55, 0x52, 0x15, 0x55, 0x4a, 0x00, 0x01,
0x2a, 0xaa, 0xa8, 0x2a, 0xaa, 0xa8, 0x4a, 0x00,
0x01, 0x52, 0x15, 0x55, 0x54, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow left-down
unsigned char cde[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x15, 0x55,
0x54, 0x85, 0x55, 0x52, 0xa1, 0x45, 0x4a, 0x85,
0x21, 0x2a, 0x15, 0x28, 0xa8, 0x55, 0x2a, 0xa1,
0x55, 0x2a, 0x85, 0x55, 0x2a, 0xa1, 0x55, 0x2a,
0xa8, 0x55, 0x40, 0x01, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// arrow down
unsigned char cdf[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x41, 0x55, 0x55, 0x28, 0x55, 0x55,
0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55,
0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x54, 0x28,
0x15, 0x52, 0xaa, 0x85, 0x54, 0xaa, 0x15, 0x55,
0x28, 0x55, 0x55, 0x41, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
learn_char(216, cd8);
learn_char(217, cd9);
learn_char(218, cda);
learn_char(219, cdb);
learn_char(220, cdc);
learn_char(221, cdd);
learn_char(222, cde);
learn_char(223, cdf);
#endif
#if WRITECHARS == 224
// arrow right-down
unsigned char ce0[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x54, 0x55, 0x55, 0x52,
0x15, 0x55, 0x4a, 0x85, 0x55, 0x52, 0xa1, 0x51,
0x54, 0xa8, 0x48, 0x55, 0x2a, 0x28, 0x55, 0x4a,
0xa8, 0x55, 0x52, 0xa8, 0x55, 0x4a, 0xa8, 0x55,
0x2a, 0xa8, 0x55, 0x40, 0x01, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// horizon up
unsigned char ce1[54] ={0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// horizon middle
unsigned char ce2[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00,
0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
 
// horizon down
unsigned char ce3[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0x00, 0x00, 0x00, 0x55, 0x55, 0x55};
 
// horizon center
unsigned char ce4[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
0x14, 0x00, 0xaa, 0x14, 0xaa, 0xaa, 0x82, 0xaa,
0x00, 0xaa, 0x00, 0x54, 0x00, 0x15};
 
// horizon roll
unsigned char ce5[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x00, 0x55, 0x00, 0x2a, 0x14, 0xa8, 0x4a,
0x82, 0xa1, 0x52, 0xaa, 0x85, 0x54, 0xaa, 0x15,
0x55, 0x28, 0x55, 0x55, 0x41, 0x55};
// gps PH
unsigned char ce6[54] ={0x55, 0x05, 0x11, 0x54, 0xa0, 0x88, 0x54, 0x88,
0x88, 0x54, 0xa0, 0xa8, 0x54, 0x84, 0x88, 0x44,
0x84, 0x88, 0x21, 0x15, 0x11, 0xa8, 0x55, 0x55,
0xa1, 0x55, 0x55, 0x98, 0x15, 0x55, 0x2a, 0x85,
0x55, 0x4a, 0xa1, 0x55, 0x4a, 0xa8, 0x55, 0x52,
0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55,
0x55, 0x41, 0x55, 0x55, 0x55, 0x55};
// gps CH
unsigned char ce7[54] ={0x55, 0x55, 0x41, 0x55, 0x55, 0x28, 0x55, 0x54,
0x81, 0x55, 0x54, 0x85, 0x55, 0x54, 0x81, 0x45,
0x55, 0x28, 0x21, 0x55, 0x01, 0xa8, 0x54, 0x88,
0xa1, 0x54, 0x88, 0x98, 0x14, 0xa8, 0x2a, 0x84,
0x88, 0x4a, 0xa0, 0x88, 0x4a, 0xa8, 0x11, 0x52,
0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55,
0x55, 0x41, 0x55, 0x55, 0x55, 0x55};
 
learn_char(224, ce0);
learn_char(225, ce1);
learn_char(226, ce2);
learn_char(227, ce3);
learn_char(228, ce4);
learn_char(229, ce5);
learn_char(230, ce6);
learn_char(231, ce7);
#endif
 
#if WRITECHARS == 232
 
// small arrow down
unsigned char ce8[54] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x00,0x00,0x00,
0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x0a,0xaa,
0xa0,0x52,0xaa,0x85,0x54,0xaa,0x15,0x55,
0x28,0x55,0x55,0x41,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55};
 
// big arrow down
unsigned char ce9[54] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x00,0x00,0x00,
0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x00,0x28,
0x00,0x55,0x28,0x55,0x40,0x28,0x01,0x2a,
0xaa,0xa8,0x4a,0xaa,0xa1,0x52,0xaa,0x85,
0x54,0xaa,0x15,0x55,0x28,0x55};
 
// small arrow up
unsigned char cea[54] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x41,0x55,0x55,0x28,0x55,0x54,
0xaa,0x15,0x52,0xaa,0x85,0x0a,0xaa,0xa0,
0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x00,0x00,
0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55};
 
// big arrow up
unsigned char ceb[54] = {0x55,0x28,0x55,0x54,0xaa,0x15,0x52,0xaa,
0x85,0x4a,0xaa,0xa1,0x2a,0xaa,0xa8,0x40,
0x28,0x01,0x55,0x28,0x55,0x00,0x28,0x00,
0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x00,0x00,
0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55};
 
learn_char(232, ce8);
learn_char(233, ce9);
learn_char(234, cea);
learn_char(235, ceb);
 
#endif
 
 
 
#endif // write char general
/* ##########################################################################
* continue normal main
* ##########################################################################*/
// Setup Video Mode
if (COSD_FLAGS & COSD_FLAG_NTSC) {
// NTSC + enable display immediately (VM0)
1417,6 → 497,9
//ms = 0;
//sendMKData('d', 0, &ms, 1);
 
// disable TXD-pin
usart1_DisableTXD();
 
// stats for after flight
int16_t max_Altimeter = 0;
uint16_t max_GroundSpeed = 0;
1450,16 → 533,12
debugData = *((DebugOut_t*) pRxData);
write_number_s(12, 2, RxDataLen);
write_number_s(20, 2, setsReceived++);
write_number_s(12, 3, debugData.Analog[0]);
write_number_s(12, 4, debugData.Analog[2]);
write_number_s(12, 5, debugData.Analog[1]);
write_number_s(12, 6, debugData.Analog[3]);
write_number_s(12, 7, debugData.Analog[9]);
write_number_s(12, 8, debugData.Analog[10]);
write_number_s(12, 4, debugData.Analog[12]);
write_number_s(12, 5, debugData.Analog[13]);
write_number_s(12, 6, debugData.Analog[14]);
write_number_s(12, 7, debugData.Analog[15]);*/
write_number_s(12, 3, debugData.Analog[0]); // AngleNick
write_number_s(12, 4, debugData.Analog[1]); // AngleRoll
write_number_s(12, 5, debugData.Analog[5]); // Height
write_number_s(12, 6, debugData.Analog[9]); // Voltage
write_number_s(12, 7, debugData.Analog[10]);// RC Signal
write_number_s(12, 8, debugData.Analog[11]);// Gyro compass*/
} else if (rxd_buffer[2] == 'O') { // NC OSD Data
Decode64();
naviData = *((NaviData_t*) pRxData);
1573,6 → 652,7
old_MKFlags = naviData.MKFlags;
}
seconds_since_last_data = 0;
rxd_buffer_locked = 0;
}
// handle keypress
1588,6 → 668,21
uptime = 0;
_delay_ms(100);
}
if (seconds_since_last_data > 2) {
// re-request OSD Data from NC
// re-enable TXD pin
usart1_EnableTXD();
// every 100ms
unsigned char ms = 10;
sendMKData('o', 1, &ms, 1);
// disable TXD pin again
usart1_DisableTXD();
 
seconds_since_last_data = 0;
}
}
#endif
return 0;