Subversion Repositories MK3Mag

Compare Revisions

Ignore whitespace Rev 71 → Rev 72

/trunk/main.c
453,14 → 453,14
USART0_Print("\n\rthe use of this software is only permitted\n\ron original MikroKopter-Hardware");
USART0_Print("\n\rwww.MikroKopter.de (c) HiSystems GmbH\n\n");
#ifdef HEADTRACKER
USART0_Print("Head-Tracker\n");
USART0_Print("\n\rHead-Tracker");
#endif
if(AccPresent)
{
USART0_Print("ACC present\n");
USART0_Print("\r\rACC present");
}
#ifdef HEADTRACKER
else USART0_Print("\nERROR: NO ACC\n");
else USART0_Print("\n\rERROR: NO ACC");
#endif
 
LED_GRN_ON;
/trunk/makefile
380,17 → 380,17
clean_list :
@echo
@echo $(MSG_CLEANING)
# $(REMOVE) $(TARGET).hex
# $(REMOVE) $(TARGET).eep
# $(REMOVE) $(TARGET).obj
$(REMOVE) MK3Mag_*.hex
$(REMOVE) MK3Mag_*.eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) MK3Mag_*.elf
$(REMOVE) MK3Mag_*.map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) MK3Mag_*.sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) MK3Mag_*.lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
/trunk/menu.c
16,23 → 16,23
 
uint8_t MaxMenuItem = 2;
uint8_t MenuItem = 0;
uint8_t RemoteKeys = 0;
 
#define KEY1 0x01 // left
#define KEY2 0x02 // right
#define KEY3 0x04 // down
#define KEY4 0x08 // up
#define KEY5 0x10
 
 
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
uint8_t DispPtr = 0;
 
 
/************************************/
/* Put Character to LCD Buffer */
/************************************/
void Menu_Putchar(char c)
{
if(DispPtr < DISPLAYBUFFSIZE) DisplayBuff[DispPtr++] = c;
}
 
/************************************/
/* Clear LCD Buffer */
/************************************/
void LCD_Clear(void)
void Menu_Clear(void)
{
uint8_t i;
for( i = 0; i < DISPLAYBUFFSIZE; i++) DisplayBuff[i] = ' ';
43,22 → 43,22
/* Update Menu on LCD */
/************************************/
// Display with 20 characters in 4 lines
void LCD_PrintMenu(void)
void Menu_Update(uint8_t Keys)
{
if(RemoteKeys & KEY1)
if(Keys & KEY1)
{
if(MenuItem) MenuItem--;
else MenuItem = MaxMenuItem;
}
if(RemoteKeys & KEY2)
if(Keys & KEY2)
{
if(MenuItem == MaxMenuItem) MenuItem = 0;
else MenuItem++;
}
if((RemoteKeys & KEY1) && (RemoteKeys & KEY2)) MenuItem = 0;
if((Keys & KEY1) && (Keys & KEY2)) MenuItem = 0;
 
 
LCD_Clear();
Menu_Clear();
 
if(MenuItem > MaxMenuItem) MenuItem = MaxMenuItem;
// print menu item number in the upper right corner
115,8 → 115,8
}
if(!ActualCalstate) LCD_printfxy(13,3,"(start)")
else LCD_printfxy(9,3,"(ESC)(step)");
if(RemoteKeys & KEY4) InternalCalstate++;
if(ActualCalstate >= 5 || (RemoteKeys & KEY3)) InternalCalstate = 0;
if(Keys & KEY4) InternalCalstate++;
if(ActualCalstate >= 5 || (Keys & KEY3)) InternalCalstate = 0;
break;
 
default:
124,5 → 124,4
MenuItem = 0;
break;
}
RemoteKeys = 0;
}
/trunk/menu.h
2,17 → 2,29
#define _MENU_H
 
#include <inttypes.h>
#include "printf_P.h"
 
 
#define DISPLAYBUFFSIZE 80
 
extern void LCD_PrintMenu(void);
extern void LCD_Clear(void);
extern int8_t DisplayBuff[];
 
#define KEY1 0x01
#define KEY2 0x02
#define KEY3 0x04
#define KEY4 0x08
 
extern int8_t DisplayBuff[DISPLAYBUFFSIZE];
extern uint8_t DispPtr;
extern uint8_t MenuItem;
extern uint8_t MaxMenuItem;
extern uint8_t RemoteKeys;
 
extern void Menu_Update(uint8_t Keys);
extern void Menu_Putchar(char c);
extern void Menu_Clear(void);
 
#define LCD_printfxy(x,y,format, args...) { DispPtr = y * 20 + x; _printf_P(&Menu_Putchar, PSTR(format) , ## args);}
#define LCD_printf(format, args...) { _printf_P(&Menu_Putchar, PSTR(format) , ## args);}
 
#endif //_MENU_H
 
 
/trunk/printf_P.c
88,41 → 88,28
 
#include "old_macros.h"
#include "printf_P.h"
#include "menu.h"
#include "uart.h"
 
 
//#define LIGHTPRINTF
char PrintZiel;
 
 
char Putchar(char zeichen)
void PRINT(pVoidFnctChar pPutchar, const char * ptr, unsigned int len)
{
if(PrintZiel == OUT_LCD) { DisplayBuff[DispPtr++] = zeichen; return(1);}
else return(USART0_putchar(zeichen));
for(;len;len--) (*pPutchar)(*ptr++);
}
 
 
void PRINT(const char * ptr, unsigned int len)
void PRINTP(pVoidFnctChar pPutchar, const char * ptr, unsigned int len)
{
for(;len;len--) Putchar(*ptr++);
for(;len;len--) (*pPutchar)(pgm_read_byte(ptr++));
}
 
void PRINTP(const char * ptr, unsigned int len)
void PAD_SP(pVoidFnctChar pPutchar, signed char howmany)
{
for(;len;len--) Putchar(pgm_read_byte(ptr++));
for(;howmany>0;howmany--) (*pPutchar)(' ');
}
 
void PAD_SP(signed char howmany)
void PAD_0(pVoidFnctChar pPutchar, signed char howmany)
{
for(;howmany>0;howmany--) Putchar(' ');
for(;howmany>0;howmany--) (*pPutchar)('0');
}
 
void PAD_0(signed char howmany)
{
for(;howmany>0;howmany--) Putchar('0');
}
 
#define BUF 40
 
/*
129,7 → 116,7
* Macros for converting digits to letters and vice versa
*/
#define to_digit(c) ((c) - '0')
#define is_digit(c) ((c)<='9' && (c)>='0')
#define is_digit(c) ((c)<='9' && (c)>='0')
#define to_char(n) ((n) + '0')
 
/*
137,13 → 124,13
*/
#define LONGINT 0x01 /* long integer */
#define LONGDBL 0x02 /* long double; unimplemented */
#define SHORTINT 0x04 /* short integer */
#define SHORTINT 0x04 /* short integer */
#define ALT 0x08 /* alternate form */
#define LADJUST 0x10 /* left adjustment */
#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
#define HEXPREFIX 0x40 /* add 0x or 0X prefix */
 
void _printf_P (char ziel,char const *fmt0, ...) /* Works with string from FLASH */
void _printf_P (pVoidFnctChar pPutchar, char const *fmt0, ...) /* Works with string from FLASH */
{
va_list ap;
register const char *fmt; /* format string */
170,7 → 157,6
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
char ox[2]; /* space for 0x hex-prefix */
 
PrintZiel = ziel; // bestimmt, LCD oder UART
va_start(ap, fmt0);
 
fmt = fmt0;
182,7 → 168,7
for (fmark = fmt; (ch = pgm_read_byte(fmt)) != '\0' && ch != '%'; fmt++)
/* void */;
if ((n = fmt - fmark) != 0) {
PRINTP(fmark, n);
PRINTP(pPutchar, fmark, n);
}
if (ch == '\0')
goto done;
453,30 → 439,30
 
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0)
PAD_SP(width - fieldsz);
PAD_SP(pPutchar, width - fieldsz);
 
/* prefix */
if (sign) {
PRINT(&sign, 1);
PRINT(pPutchar, &sign, 1);
} else if (flags & HEXPREFIX) {
ox[0] = '0';
ox[1] = ch;
PRINT(ox, 2);
PRINT(pPutchar, ox, 2);
}
 
/* right-adjusting zero padding */
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
PAD_0(width - fieldsz);
PAD_0(pPutchar, width - fieldsz);
 
/* leading zeroes from decimal precision */
PAD_0(dpad);
PAD_0(pPutchar, dpad);
 
/* the string or number proper */
PRINT(cp, size);
PRINT(pPutchar, cp, size);
 
/* left-adjusting padding (always blank) */
if (flags & LADJUST)
PAD_SP(width - fieldsz);
PAD_SP(pPutchar, width - fieldsz);
}
done:
va_end(ap);
/trunk/printf_P.h
3,17 → 3,9
 
#include <avr/pgmspace.h>
 
#define OUT_V24 0
#define OUT_LCD 1
// function pointer to external callback put character function
typedef void (*pVoidFnctChar) (char );
 
void _printf_P (pVoidFnctChar pPutchar, char const *fmt0, ...);
 
void _printf_P (char, char const *fmt0, ...);
extern char PrintZiel;
 
 
#define printf_P(format, args...) _printf_P(OUT_V24,format , ## args)
#define printf(format, args...) _printf_P(OUT_V24,PSTR(format) , ## args)
#define LCD_printfxy(x,y,format, args...) { DispPtr = y * 20 + x; _printf_P(OUT_LCD,PSTR(format) , ## args);}
#define LCD_printf(format, args...) { _printf_P(OUT_LCD,PSTR(format) , ## args);}
 
#endif
#endif //_PRINTF_P_H_
/trunk/uart.c
68,7 → 68,6
#include "uart.h"
#include "timer0.h"
#include "twislave.h"
#include "printf_P.h"
 
// slave addresses
#define FC_ADDRESS 1
101,7 → 100,7
uint8_t RequestFlags = 0x00;
uint8_t RequestDebugLabel = 0;
uint8_t ConfirmFrame = 0;
 
uint8_t RemoteKeys = 0;
uint8_t DisplayLine = 0;
 
uint16_t PC_Connected = 0;
237,17 → 236,18
UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
 
// send version info at startup
USART0_putchar ('\n');
USART0_putchar ('C');
USART0_putchar ('P');
USART0_putchar (':');
USART0_putchar ('V');
USART0_putchar ('0' + VERSION_MAJOR);
USART0_putchar ('.');
USART0_putchar ('0' + VERSION_MINOR/10);
USART0_putchar ('0' + VERSION_MINOR%10);
USART0_putchar ('a' + VERSION_PATCH);
USART0_putchar ('\n');
USART0_Putchar ('\r');
USART0_Putchar ('\n');
USART0_Putchar ('C');
USART0_Putchar ('P');
USART0_Putchar (':');
USART0_Putchar ('V');
USART0_Putchar ('0' + VERSION_MAJOR);
USART0_Putchar ('.');
USART0_Putchar ('0' + VERSION_MINOR/10);
USART0_Putchar ('0' + VERSION_MINOR%10);
USART0_Putchar ('a' + VERSION_PATCH);
USART0_Putchar ('\n');
 
// restore global interrupt flags
SREG = sreg;
490,16 → 490,14
 
 
// --------------------------------------------------------------------------
int16_t USART0_putchar (int8_t c)
void USART0_Putchar (char c)
{
// if tx is not enabled return immediatly
if(!(UCSR0B & (1 << TXEN0))) return (0);
if (c == '\n') USART0_putchar('\r');
if(!(UCSR0B & (1 << TXEN0))) return;
// wait until previous character was send
loop_until_bit_is_set(UCSR0A, UDRE0);
// send character
UDR0 = c;
return (0);
}
 
 
637,7 → 635,8
{
if(DisplayLine > 3)// new format
{
LCD_PrintMenu();
Menu_Update(RemoteKeys);
RemoteKeys = 0;
SendOutData('H', MK3MAG_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
}
else // old format
678,6 → 677,6
uint8_t i = 0;
while(msg[i] != 0)
{
USART0_putchar(msg[i++]);
USART0_Putchar(msg[i++]);
}
}
/trunk/uart.h
2,6 → 2,7
#define _UART_H_
 
#include <inttypes.h>
#include "printf_P.h"
 
#define NICK 0
#define ROLL 1
18,11 → 19,12
void USART0_DisableTXD(void);
void USART0_TransmitTxData(void);
void USART0_ProcessRxData(void);
int16_t USART0_putchar(int8_t c);
void USART0_Putchar(char c);
void USART0_Print(int8_t *msg);
 
#define printf_P(format, args...) _printf_P(&USART0_Putchar, format , ## args)
#define printf(format, args...) _printf_P(&USART0_Putchar, PSTR(format) , ## args)
 
 
typedef struct
{
uint8_t Digital[2];