/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW1_2.c |
---|
0,0 → 1,132 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
// *Hardwareabhängige Definitionen und Prozeduren |
// * Hardware Leiterplatte V1.2 sebseb7 |
#ifndef HAL_HW1_2_C_ |
#define HAL_HW1_2_C_ |
#include "cpu.h" |
#include <inttypes.h> |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/eeprom.h> |
#include <util/delay.h> |
#include "main.h" |
#if defined HWVERSION1_2W || defined HWVERSION1_2 |
#include "usart.h" |
#include "uart1.h" |
#include "lcd.h" |
#include "display.h" |
#include "timer.h" |
#include "eeprom.h" |
#include "Wi232.h" |
#include "twimaster.h" |
void InitHWPorts(void) /* Initialisierung der Hardware für die jeweilige Leiterplattenversion */ |
{ |
// enable pull ups for the 4 keys |
PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); |
DDRC |= (1<<DDC0)|(1<<DDC1)|(1<<DDC6)|(1<<DDC5)|(1<<DDC7); |
DDRD |= (1<<DDD7); |
DDRB = 0xFF; |
set_LED1(); |
set_D_LIGHT(); |
Timer0_Init (); |
Timer1_Init (); // pwm |
Timer2_Init (); // Displaybeleuchtung |
LCD_Init (0); |
BeepTime = 500; |
BeepMuster = 0x0080; |
// _delay_ms(250); |
clr_LED1(); |
Display_on = 1; |
USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); |
// I2C_Init(1); |
sei (); |
ReadParameter (); |
LCD_Init (1); |
OCR2A =LCD_Helligkeit*2.55; |
#ifdef HWVERSION1_2W |
if (WiIsSet==false) |
InitWi232(); /* wenn Wi232 nicht initialisiert ist, dann jetzt tun*/ |
else |
{ |
discoverWi232(); /* Wi232 suchen*/ |
_delay_ms(1000); |
} |
#endif |
} |
void set_D_LIGHT(void) /* Displaybeleuchtung ein*/ |
{ |
PORTC &= ~(1<<PORTC0); |
PORTC &= ~(1<<PORTC1); |
PORTD &= ~(1<<PORTD7); |
} |
void clr_D_LIGHT(void) /* Displaybeleuchtung aus*/ |
{ |
PORTC |= (1<<PORTC0); |
PORTC |= (1<<PORTC1); |
PORTD |= (1<<PORTD7); |
} |
#endif |
#endif /* HAL_HW3_2_C_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW1_2.h |
---|
0,0 → 1,99 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
// * Hardwareabhängige Definitionen und Prozeduren |
// * Hardware Leiterplatte V1.2 sebseb7 |
/* Belegung der Ports*/ |
/*Hardware 1.2 sebseb7 Portbelegung |
Servo PD4 Pin 13 |
Servo PD5 Pin 14 |
Displaybeleuchtung PD7 Pin 16 LED an + |
Displaybeleuchtung PC0 Pin 10 LED an + |
Displaybeleuchtung PC1 Pin 20 LED an + |
Summer PC6 Pin 25 Summer an GND |
Wi232 PC7 Pin 26 Wi232 CMD Pin |
*/ |
#ifndef HAL_HW1_2_H_ |
#define HAL_HW1_2_H_ |
#define set_cs() (PORTB |= (1 << PB4)) // Display |
#define clr_cs() (PORTB &= ~(1 << PB4)) |
#define set_reset() (PORTB |= (1 << PB2)) |
#define clr_reset() (PORTB &= ~(1 << PB2)) |
#define set_A0() (PORTB |= (1 << PB3)) // Data |
#define clr_A0() (PORTB &= ~(1 << PB3)) // Command |
#define set_scl() (PORTB |= (1 << PB7)) |
#define clr_scl() (PORTB &= ~(1 << PB7)) |
#define set_si() (PORTB |= (1 << PB5)) |
#define clr_si() (PORTB &= ~(1 << PB5)) |
#define set_LED1() (PORTC &= ~(1 << PC3)) // Leds |
#define clr_LED1() (PORTC |= (1 << PC3)) |
#define set_LED2() (PORTC &= ~(1 << PC2)) |
#define clr_LED2() (PORTC |= (1 << PC2)) |
#define set_LED3() (PORTB &= ~(1 << PB1)) |
#define clr_LED3() (PORTB |= (1 << PB1)) |
#define set_LED4() (PORTB &= ~(1 << PB0)) |
#define clr_LED4() (PORTB |= (1 << PB0)) |
#define clr_BEEP() (PORTC &= ~(1 << PC6)) //Summer |
#define set_BEEP() (PORTC |= (1 << PC6)) |
#define set_WI232CMD() (PORTC &= ~(1 << PC7)) |
#define clr_WI232CMD() (PORTC |= (1 << PC7)) |
#define KEY_PIN PINA |
#define KEY_ENTER PA7 |
#define KEY_ESC PA6 |
#define KEY_PLUS PA5 |
#define KEY_MINUS PA4 |
void set_D_LIGHT(void); /* Displaybeleuchtung ein*/ |
void clr_D_LIGHT(void); /* Displaybeleuchtung aus*/ |
void InitHWPorts(void); |
#endif /* HAL_HW1_2_H_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW1_3.c |
---|
0,0 → 1,137 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
// *Hardwareabhängige Definitionen und Prozeduren |
// * Hardware Leiterplatte V1.3 sebseb7 |
// * USB,LED |
#ifndef HAL_HW1_3_C_ |
#define HAL_HW1_3_C_ |
#include "cpu.h" |
#include <inttypes.h> |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/eeprom.h> |
#include <util/delay.h> |
#include "main.h" |
#if defined HWVERSION1_3W || defined HWVERSION1_3 |
#include "lcd.h" |
#include "usart.h" |
#include "uart1.h" |
#include "display.h" |
#include "timer.h" |
#include "eeprom.h" |
#include "Wi232.h" |
#include "twimaster.h" |
void InitHWPorts(void) /* Initialisierung der Hardware für die jeweilige Leiterplattenversion */ |
{ |
// enable pull ups for the 4 keys |
PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); |
DDRD |= (1<<DDD7)|(1<<DDD6); |
DDRC |= (1<<DDC2)|(1<<DDC3)|(1<<DDC6)|(1<<DDC5)|(1<<DDC7); /* Leds,Summer*/ |
DDRB = 0xFF; |
set_LED1(); |
BeepTime = 500; |
BeepMuster = 0x0080; |
set_D_LIGHT(); |
clr_WI232CMD(); |
_delay_ms(250); |
clr_LED1(); |
Display_on = 1; |
LCD_Init (0); |
USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); |
uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); /* USB*/ |
uart1_putc('R'); |
// I2C_Init(1); |
Timer0_Init (); |
Timer1_Init (); // pwm |
Timer2_Init (); // Displaybeleuchtung |
sei (); |
ReadParameter (); |
LCD_Init (1); |
OCR2A =LCD_Helligkeit*2.55; |
// InitWi232(); |
#ifdef HWVERSION1_3W |
if (WiIsSet==false) |
InitWi232(); /* wenn Wi232 nicht initialisiert ist, dann jetzt tun*/ |
else |
{ |
discoverWi232(); /* Wi232 suchen*/ |
_delay_ms(1000); |
} |
#endif |
} |
void set_D_LIGHT(void) /* Displaybeleuchtung ein*/ |
{ |
PORTD &= ~(1<<PORTD6); |
PORTC &= ~(1<<PORTC2); |
PORTD &= ~(1<<PORTD7); |
} |
void clr_D_LIGHT(void) /* Displaybeleuchtung aus*/ |
{ |
PORTD |= (1<<PORTD6); |
PORTD |= (1<<PORTD7); |
PORTC |= (1<<PORTC2); |
} |
#endif |
#endif /* HAL_HW1_3_C_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW1_3.h |
---|
0,0 → 1,108 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
// * Hardwareabhängige Definitionen und Prozeduren |
// * Hardware Leiterplatte V1.3 sebseb7 |
// * USB,LED |
/*Hardware 1.3.1 Portbelegung |
Servo PD4 Pin 13 |
Servo PD5 Pin 14 |
Bootlader LED PC3 Pin 22 LED an GND |
Summer PC6 Pin 25 Summer an GND |
Displaybeleuchtung PD6 Pin 15 LED an + |
Displaybeleuchtung PD7 Pin 16 LED an + |
Displaybeleuchtung PC2 Pin 21 LED an + |
Wi232 PC7 Pin 26 Wi232 CMD Pin |
*/ |
#ifndef HAL_HW1_3_H_ |
#define HAL_HW1_3_H_ |
#define set_cs() (PORTB |= (1 << PB4)) // Display |
#define clr_cs() (PORTB &= ~(1 << PB4)) |
#define set_reset() (PORTB |= (1 << PB2)) |
#define clr_reset() (PORTB &= ~(1 << PB2)) |
#define set_A0() (PORTB |= (1 << PB3)) // Data |
#define clr_A0() (PORTB &= ~(1 << PB3)) // Command |
#define set_scl() (PORTB |= (1 << PB7)) |
#define clr_scl() (PORTB &= ~(1 << PB7)) |
#define set_si() (PORTB |= (1 << PB5)) |
#define clr_si() (PORTB &= ~(1 << PB5)) |
#define clr_LED1() (PORTC &= ~(1 << PC3)) // Leds |
#define set_LED1() (PORTC |= (1 << PC3)) |
#define set_LED2() (PORTC &= ~(1 << PC2)) |
#define clr_LED2() (PORTC |= (1 << PC2)) |
#define set_LED3() (PORTB &= ~(1 << PB1)) |
#define clr_LED3() (PORTB |= (1 << PB1)) |
#define set_LED4() (PORTB &= ~(1 << PB0)) |
#define clr_LED4() (PORTB |= (1 << PB0)) |
#define clr_BEEP() (PORTC &= ~(1 << PC6)) //Summer |
#define set_BEEP() (PORTC |= (1 << PC6)) |
#define set_WI232CMD() (PORTC &= ~(1 << PC7)) |
#define clr_WI232CMD() (PORTC |= (1 << PC7)) |
#define KEY_PIN PINA |
#define KEY_ENTER PA7 |
#define KEY_ESC PA6 |
#define KEY_PLUS PA5 |
#define KEY_MINUS PA4 |
void set_D_LIGHT(void); /* Displaybeleuchtung ein*/ |
void clr_D_LIGHT(void); /* Displaybeleuchtung aus*/ |
void InitHWPorts(void); |
void Port_USB2FC(void); |
#endif /* HAL_HW1_3_H_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW3_1.c |
---|
0,0 → 1,122 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
// *Hardwareabhängige Definitionen und Prozeduren |
// * Hardware Leiterplatte V3.2 Cebra |
// * USB,Wi232,LED |
#ifndef HAL_HW3_2_C_ |
#define HAL_HW3_2_C_ |
#include "cpu.h" |
#include <inttypes.h> |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/eeprom.h> |
#include <util/delay.h> |
#include "main.h" |
#ifdef HWVERSION3_1 |
#include "lcd.h" |
#include "usart.h" |
#include "uart1.h" |
#include "display.h" |
#include "timer.h" |
#include "eeprom.h" |
#include "Wi232.h" |
#include "twimaster.h" |
void InitHWPorts(void) /* Initialisierung der Hardware für die jeweilige Leiterplattenversion */ |
{ |
// enable pull ups for the 4 keys |
PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); |
DDRD |= (1<<DDD7)|(1<<DDD6); |
DDRC |= (1<<DDC2)|(1<<DDC3)|(1<<DDC7); /* Leds,Summer*/ |
DDRB = 0xFF; |
set_LED1(); |
set_LED2(); |
set_LED3(); |
set_LED4(); |
BeepTime = 500; |
BeepMuster = 0x0080; |
set_D_LIGHT(); |
clr_WI232CMD(); |
_delay_ms(250); |
clr_LED1(); |
clr_LED2(); |
clr_LED3(); |
clr_LED4(); |
Display_on = 1; |
LCD_Init (); |
USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); |
uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); /* USB*/ |
uart1_putc('R'); |
I2C_Init(1); |
Timer0_Init (); |
Timer1_Init (); // pwm |
// TIMER2_Init(); //PWM Displaybeleuchtung |
sei (); |
ReadParameter (); |
LCD_Init (); |
InitWi232(); |
} |
#endif |
#endif /* HAL_HW3_2_C_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW3_1.h |
---|
0,0 → 1,108 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
// * Hardwareabhängige Definitionen und Prozeduren |
// * Hardware Leiterplatte V3.2 Cebra |
// * USB,Wi232,LED |
/* Hardware 3.1 Portbelegung |
Servo PD4 Pin 13 |
Servo PD5 Pin 14 |
Wi.232 CMD PD6 Pin 15 aktiv low |
Displaybeleuchtung PD7 Pin 16 LED an + |
I2C PC0 Pin 19 |
I2C PC1 Pin 20 |
LED2 PC2 Pin 21 LED an + |
LED1 PC3 Pin 22 LED an + |
Summer PC6 Pin 25 Summer an + |
LED3 PB1 Pin 41 LED an + |
LED4 PB0 Pin 40 LED an + |
*/ |
#ifndef HAL_HW3_2_H_ |
#define HAL_HW3_2_H_ |
#define set_cs() (PORTB |= (1 << PB4)) // Display |
#define clr_cs() (PORTB &= ~(1 << PB4)) |
#define set_reset() (PORTB |= (1 << PB2)) |
#define clr_reset() (PORTB &= ~(1 << PB2)) |
#define set_A0() (PORTB |= (1 << PB3)) // Data |
#define clr_A0() (PORTB &= ~(1 << PB3)) // Command |
#define set_scl() (PORTB |= (1 << PB7)) |
#define clr_scl() (PORTB &= ~(1 << PB7)) |
#define set_si() (PORTB |= (1 << PB5)) |
#define clr_si() (PORTB &= ~(1 << PB5)) |
#define set_LED1() (PORTC &= ~(1 << PC3)) // Leds |
#define clr_LED1() (PORTC |= (1 << PC3)) |
#define set_LED2() (PORTC &= ~(1 << PC2)) |
#define clr_LED2() (PORTC |= (1 << PC2)) |
#define set_LED3() (PORTB &= ~(1 << PB1)) |
#define clr_LED3() (PORTB |= (1 << PB1)) |
#define set_LED4() (PORTB &= ~(1 << PB0)) |
#define clr_LED4() (PORTB |= (1 << PB0)) |
#define set_BEEP() (PORTC &= ~(1 << PC6)) //Summer |
#define clr_BEEP() (PORTC |= (1 << PC6)) |
#define set_D_LIGHT() (PORTD |= (1 << PD7)) // Displaybeleuchtung |
#define clr_D_LIGHT() (PORTD &= ~(1 << PD7)) |
#define set_WI232CMD() (PORTD &= ~(1 << PD6)) |
#define clr_WI232CMD() (PORTD |= (1 << PD6)) |
#define KEY_PIN PINA |
//#if defined HWVERSION1_2 || defined HWVERSION1_3 || defined HWVERSION3_2 |
//#define KEY_ENTER PA7 |
//#define KEY_ESC PA6 |
//#define KEY_PLUS PA5 |
//#define KEY_MINUS PA4 |
//#endif |
/*in der Hardwareversion sind die Tasten im Layout verdreht*/ |
#define KEY_ENTER PA4 |
#define KEY_ESC PA5 |
#define KEY_PLUS PA6 |
#define KEY_MINUS PA7 |
void InitHWPorts(void); |
#endif /* HAL_HW3_2_H_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW3_9.c |
---|
0,0 → 1,196 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef HAL_HW3_9_C_ |
#define HAL_HW3_9_C_ |
#include "cpu.h" |
#include <inttypes.h> |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/eeprom.h> |
#include <util/delay.h> |
#include <stdbool.h> |
#include "main.h" |
#if defined HWVERSION3_9 |
#include "messages.h" |
#include "lcd.h" |
#include "usart.h" |
#include "uart1.h" |
#include "display.h" |
#include "timer.h" |
#include "eeprom.h" |
#include "Wi232.h" |
#include "twimaster.h" |
#include "uart1.h" |
#include "bluetooth.h" |
#include "error.h" |
#include "connect.h" |
#include "lipo.h" |
#include "setup.h" |
volatile uint8_t USBBT; |
volatile uint8_t U02SV2; |
//-------------------------------------------------------------- |
void InitHWPorts(void) // Initialisierung der Hardware für die jeweilige Leiterplattenversion |
{ |
PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); // Enable Pull Up for the 4 keys |
DDRA &= ~(1<<DDA4); // Eingang: A4 auf Low setzen (Power On) |
DDRB = 0xFF; // Alles Ausgänge |
PORTC |= (1<<PORTC4)|(1<<PORTC7); // Enable Pull Up for LBO + Summer |
DDRC |= (1<<DDC2)|(1<<DDC3)|(1<<DDC5)|(1<<DDC6)|(1<<DDC7); // Ausgang: Led2,Rs232Switch,Summer |
DDRC &= ~(1<<DDC4); // Eingang: LowBat LTC1308 |
set_BTOn(); // Erstmal USB dektivieren, damit beim versehentlichen Einschalten USB im PC ruhig bleibt |
PORTD |= (1<<PORTD6); // Wi232-CMD auf High schalten |
DDRD |= (1<<DDD4)|(1<<DDD5)|(1<<DDD6)|(1<<DDD7); // Ausgang: PiepserTest, Servo, Wi232-CMD und Beleuchtung |
set_V_On(); // Spannung mit T3 halten |
Timer0_Init (); // system |
Timer1_Init (); // pwm |
Timer2_Init (); // display |
Display_on = 1; |
USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); |
uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); // USB |
I2C_Init(1); |
sei (); |
LCD_Init (0); // muss vor "ReadParameter" stehen |
ReadParameter (); // Aktuelle Werte aus EEProm auslesen |
if (DisplayLanguage > NUM_LANG) // Beim ersten Start Sprache abfragen |
{ DisplayLanguage = 1; |
DisplayLanguage = Edit_Language(DisplayLanguage,0,3,DISPLAY3); |
WriteParameter(); |
} |
OCR2A = LCD_Helligkeit * 2.55; |
LCD_Init (1); |
BeepTime = 200; |
BeepMuster = 0x0080; |
ADC_Init(); // ADC für Lipomessung |
// Power On Delay |
// lcd_printp_at (2,2,PSTR("Taste 1 Sekunde"), 0); |
// lcd_printp_at (2,3,PSTR("lang festhalten."), 0); |
lcd_puts_at(0, 2, strGet(BOOT1), 0); |
lcd_puts_at(0, 3, strGet(BOOT2), 0); |
_delay_ms(800); |
if (PINA & (1<<PINA7)) // Spannung eingeschaltet lassen |
clr_V_On(); |
_delay_ms(100); |
BeepTime = 500; |
BeepMuster = 0x0080; |
get_key_press(KEY_ALL); |
lcd_cls(); |
if ((UseWi == true) && (WiIsSet == false)) |
{ |
InitWi232(); // wenn Wi232 nicht initialisiert ist, dann jetzt tun |
} |
lcd_cls(); |
set_USBOn(); // USB erstmal wieder einschalten |
if ((UseBT == true) && (BTIsSet == false)) |
{ |
bt_init(); |
set_USBOn(); |
} |
lcd_cls(); |
if ((UseWi == true) && (U02SV2 == 0)) |
{ |
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen |
if (PKT_StartInfo == true) |
{ |
// lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0); |
// lcd_printp_at (0, 1, PSTR("auf Wi232 eingestellt"), 0); |
lcd_puts_at(0, 0, strGet(BOOT_WI1), 0); |
lcd_puts_at(0, 1, strGet(BOOT_WI2), 0); |
_delay_ms(2000); |
} |
} |
else |
{ |
Change_Output(Uart02FC); // Verbindung zu SV" (Kabel) herstellen |
if (PKT_StartInfo == true) |
{ |
// lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0); |
// lcd_printp_at (0, 1, PSTR("auf Kabel eingestellt"), 0); |
lcd_puts_at(0, 0, strGet(BOOT_WI1), 0); |
lcd_puts_at(0, 1, strGet(BOOT_SV), 0); |
_delay_ms(2000); |
} |
} |
lcd_cls(); |
} |
void set_D_LIGHT(void) /* Displaybeleuchtung ein*/ |
{ |
// PWM einschalten |
TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1); |
TCCR2B |= (1 << CS20); |
} |
void clr_D_LIGHT(void) /* Displaybeleuchtung aus*/ |
{ |
// PWM ausschalten |
TCCR2A = 0; |
TCCR2B = 0; |
} |
#endif |
#endif // HAL_HW3_9_C_ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/HAL_HW3_9.h |
---|
0,0 → 1,139 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef HAL_HW3_9_H_ |
#define HAL_HW3_9_H_ |
//#define PIEPSER_NERVT // Summer zu Testzwecken ganz Ausschalten |
// Hardware 3.9 Portbelegung |
#define KEY_PIN PINA // Port A als Input |
#define Touch0 PA0 // Pin 37 |
#define Touch1 PA1 // Pin 36 |
#define Touch2 PA2 // Pin 35 |
#define Touch3 PA3 // Pin 34 |
#define Key1 PA4 // Pin 33 |
#define Key2 PA5 // Pin 32 |
#define Key3 PA6 // Pin 31 |
#define Key4 PA7 // Pin 30 |
#define USB2Wi PB0 // Pin 40 aktiv low > IC5 |
#define VoltageHold PB1 // Pin 41 High = Spannung T3 halten |
#define Display_Reset PB2 // Pin 42 |
#define Display_A0 PB3 // Pin 43 |
#define Display_CS PB4 // Pin 44 |
#define Display_SI PB5 // Pin 1 |
#define LED1 PB6 // Pin 2 Low = LED1 (nicht benutzbar wegen SCL |
#define Display_SCL PB7 // Pin 3 |
#define I2C_SCL PC0 // Pin 19 SCL |
#define I2C_CDA PC1 // Pin 20 SDA |
#define USB2FC PC2 // Pin 21 aktiv low > IC5 |
#define USB_BT PC3 // Pin 22 high = USB, Low = Bluetooth, LED2 |
#define LowBat PC4 // Pin 23 Low Bat Warning Lipo PKT,Input |
#define Uart02Wi PC5 // Pin 24 aktiv Low > IC4 |
#define Uart02FC PC6 // Pin 25 aktiv Low > IC4 |
#define Summer PC7 // Pin 26 Low = Summer |
#define Uart0RxD PD0 // Pin 9 über IC4 =Wi | SV2 |
#define Uart0TxD PD1 // Pin 10 über IC4 =Wi | SV2 |
#define Uart1RxD PD2 // Pin 11 direkt = USB, BTM, über IC5 = Wi | SV2 |
#define Uart1TxD PD3 // Pin 12 direkt = USB, BTM, über IC5 = Wi | SV2 |
#define PiepserTest PD4 // Pin 13 CTC für Piepser |
#define Servo PD5 // Pin 14 PWM für Servo |
#define Wi232_CMD PD6 // Pin 15 aktiv Low = Wi232 CMD |
#define Displaybeleuchtung PD7 // Pin 16 High = Display-LED |
#define KEY_ENTER Key1 |
#define KEY_ESC Key2 |
#define KEY_PLUS Key3 |
#define KEY_MINUS Key4 |
// |= schaltet Ausgang auf HIGH |
// &= ~ schaltet Ausgang auf LOW |
#define set_reset() (PORTB |= (1 << Display_Reset)) |
#define clr_reset() (PORTB &= ~(1 << Display_Reset)) |
#define set_A0() (PORTB |= (1 << Display_A0)) |
#define clr_A0() (PORTB &= ~(1 << Display_A0)) |
#define set_cs() (PORTB |= (1 << Display_CS)) |
#define clr_cs() (PORTB &= ~(1 << Display_CS)) |
#define set_si() (PORTB |= (1 << Display_SI)) |
#define clr_si() (PORTB &= ~(1 << Display_SI)) |
#define set_scl() (PORTB |= (1 << Display_SCL)) |
#define clr_scl() (PORTB &= ~(1 << Display_SCL)) |
#define set_BTOn() (PORTC &= ~(1 << USB_BT)) // Bluetooth ein |
#define set_USBOn() (PORTC |= (1 << USB_BT)) // USB ein |
#define clr_V_On() (PORTB &= ~(1 << VoltageHold)) // Spannung mit T3 halten |
#define set_V_On() (PORTB |= (1 << VoltageHold)) |
#define set_USB2FC() (PORTC &= ~(1 << USB2FC)) // USB mit FC-Kabel verbinden |
#define clr_USB2FC() (PORTC |= (1 << USB2FC)) |
#define set_USB2Wi() (PORTB &= ~(1 << USB2Wi)) // USB mit Wi232 verbinden |
#define clr_USB2Wi() (PORTB |= (1 << USB2Wi)) |
#define set_Uart02FC() (PORTC &= ~(1 << Uart02FC)) // Uart0 mit FC-Kabel verbinden |
#define clr_Uart02FC() (PORTC |= (1 << Uart02FC)) |
#define set_Uart02Wi() (PORTC &= ~(1 << Uart02Wi)) // Uart0 mit Wi232 verbinden |
#define clr_Uart02Wi() (PORTC |= (1 << Uart02Wi)) |
#define set_BEEP() (PORTC &= ~(1 << Summer)) // Summer |
#define clr_BEEP() (PORTC |= (1 << Summer)) |
#define set_WI232CMD() (PORTD &= ~(1 << Wi232_CMD)) // Wi232 Programmierpin |
#define clr_WI232CMD() (PORTD |= (1 << Wi232_CMD)) |
void set_D_LIGHT(void); /* Displaybeleuchtung ein*/ |
void clr_D_LIGHT(void); /* Displaybeleuchtung aus */ |
void InitHWPorts(void); |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/TODO.txt |
---|
0,0 → 1,12 |
24.8.2011 Cebra |
Waypointlisten speichern und zum MK übertragen |
Menüs überarbeiten um die Varianten der Schnittstellen einfacher handhaben zu können |
Touchsreen entfällt, bring keine wirklichen Vorteile, kostet nur viel Speicher |
22.7.2011 Cebra |
HArdwareplatine mit Stick und Schalter zum Steuern der seriellen Kanäle. |
22.6.2011 Cebra |
- erl. I2C Motortest für BL-Controller |
- erl. zur Zeit sind durch einen Layoutfehler noch die Tasten vertauscht, in timer.h zu ändern |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/Wi232.c |
---|
0,0 → 1,562 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/pgmspace.h> |
#include <util/delay.h> |
#include <stdlib.h> |
#include <string.h> |
#include "lcd.h" |
#include "usart.h" |
#include "uart1.h" |
#include "main.h" |
#include "Wi232.h" |
#include "timer.h" |
#include "eeprom.h" |
#if defined HWVERSION1_3W || defined HWVERSION3_9 |
uint8_t Wi232_hardware = 0; |
uint8_t InitErr=0; |
/************************************************************************* |
Function: discoverWI232() |
Purpose: check if Wi232 available |
Returns: Version or 0 = timeout |
**************************************************************************/ |
void discoverWi232(void) |
{ |
int16_t RegisterWi232; |
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/ |
set_WI232CMD(); |
_delay_ms(200); |
USART_Init( UART_BAUD_SELECT(57600,F_CPU) ); /* erstmal mit 57600 versuchen*/ |
lcd_printpns_at (0, 0, PSTR("search Wi.232 Modul"),0); |
lcd_printpns_at (0, 1, PSTR("with 57600 Baud "),0); |
RegisterWi232 = ReadWi232(regDiscover); |
Wi232_hardware = 1; |
if (RegisterWi232 == 0) |
{ |
USART_Init( UART_BAUD_SELECT(2400,F_CPU) ); /* neues Modul mit 2400 suchen*/ |
lcd_printpns_at (0, 1, PSTR("with 2400 Baud "),0); |
RegisterWi232 = ReadWi232(regDiscover); |
Wi232_hardware = 2; |
} |
if (RegisterWi232 == 0) |
{ |
lcd_cls(); |
lcd_printpns_at (0, 0, PSTR("no Wi.232 found "),0); |
Wi232_hardware = 0; |
} |
if (RegisterWi232 == 0xFF) |
{ |
lcd_cls(); |
lcd_printpns_at (0, 0, PSTR("Wi.232 Sytaxerror "),0); |
BeepTime = 1000; |
BeepMuster = 0x0040; |
_delay_ms(2000); |
} |
if (RegisterWi232 != 0) |
{ |
lcd_cls(); |
if (Wi232_hardware ==1) |
lcd_printpns_at (0, 0, PSTR("Wi.232 found 57600"),0); |
if (Wi232_hardware ==2) // bei 2400 Baud |
{ |
WiIsSet= false; //wenn hier 2400 gefunden wurde ist Wi232 nicht initialisiert |
lcd_printpns_at (0, 0, PSTR("Wi.232 found 2400"),0); |
if (WriteWi232(regNVDATARATE,Wi232_57600)!=0) /* NV-Ram auf 57600 setzen*/ |
{ |
lcd_printpns_at (0, 1, PSTR("Error set NV-RAM"),0); |
BeepTime = 1000; |
BeepMuster = 0x0040; |
_delay_ms(2000); |
} |
else |
{ |
_delay_ms(1000); |
lcd_printpns_at (0, 1, PSTR("NV-RAM set to 57600"),0); |
lcd_printpns_at (0, 2, PSTR("ok "),0); |
_delay_ms(2000); |
} |
if (WriteWi232(regDATARATE,Wi232_57600)!=0) /* Ram auf 57600 setzen*/ |
{ |
lcd_printpns_at (0, 3, PSTR("Error set RAM "),0); |
BeepTime = 1000; |
BeepMuster = 0x0040; |
_delay_ms(2000); |
} |
else |
{ |
_delay_ms(1000); |
lcd_printpns_at (0, 1, PSTR("RAM set to 57600 "),0); |
lcd_printpns_at (0, 2, PSTR("ok "),0); |
_delay_ms(2000); |
} |
USART_Init( UART_BAUD_SELECT(57600,F_CPU) ); |
} |
lcd_cls_line (0,1,21); |
lcd_printpns_at (0, 1, PSTR("Version:"),0); |
lcd_print_hex_at(9,1,RegisterWi232,0); |
} |
clr_WI232CMD(); |
} |
/************************************************************************* |
Function: InitWI232() |
Purpose: set Wi232Register for Mikrokopter |
Returns: 0 = ACK, FF = NAK |
**************************************************************************/ |
void InitWi232(void) |
{ |
uint8_t i = 0; |
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen |
discoverWi232(); // Check if Wi232 available |
if (Wi232_hardware != 0) |
{ |
lcd_printpns_at (0, 2, PSTR("Init Wi232 wait...."),0); |
set_WI232CMD(); |
_delay_ms(200); |
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/ |
USART_Init( UART_BAUD_SELECT(57600,F_CPU) ); /* erstmal mit 57600 versuchen*/ |
if (WriteWi232(regNETGRP,126)!=0) /*damit Wi232 nix mehr vom Kopter schickt erstmal Networkgroup ins Nirwana setzen */ |
lcd_printpns_at (i++,4,PSTR("."),0); |
// InitErr =12; |
// Grund: |
//If RF packets are received while the CMD line is active, |
//they are still processed and presented to the module’s UART for transmission. |
// wenn sich ein EEPROM-Wert ändert wird auch das Ram beschrieben damit die Änderung sofort wirksam wird |
if (WriteWi232(regNVTXCHANNEL,WiTXRXChannel)!=0) |
InitErrorWi232(1); /*TX Channel*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regTXCHANNEL,WiTXRXChannel)!=0) |
InitErrorWi232(2);/*TX Channel*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVRXCHANNEL,WiTXRXChannel)!=0) |
InitErrorWi232(3);/* RX Channel*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regRXCHANNEL,WiTXRXChannel)!=0) |
InitErrorWi232(4);/* RX Channel*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVSLPMODE ,Sleep_Awake)!=0) |
InitErrorWi232(5);/* Sleepmode*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVPWRMODE,WbModeP15)!=0) |
InitErrorWi232(6);/* Transceiver Mode/Powermode */ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVTXTO,WiTXTO)!=0) |
InitErrorWi232(7);/* UART Timeout */ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regTXTO,WiTXTO)!=0) |
InitErrorWi232(8);/* UART Timeout */ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVUARTMTU,WiUartMTU)!=0) |
InitErrorWi232(9);/* UART Buffer*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regUARTMTU,WiUartMTU)!=0) |
InitErrorWi232(10);/* UART Buffer*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVNETMODE,WiNetworkMode)!=0) |
InitErrorWi232(11);/* Networkmode*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNETMODE,WiNetworkMode)!=0) |
InitErrorWi232(12);/* Networkmode*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVUSECRC ,CRC_Enable)!=0) |
InitErrorWi232(13);/* CRC*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVCSMAMODE,CSMA_En)!=0) |
InitErrorWi232(14);/* CSMA*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVDATARATE,Wi232_57600)!=0) |
InitErrorWi232(15);/* Baudrate*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regDATARATE,Wi232_57600)!=0) |
InitErrorWi232(16);/* Baudrate*/ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNVNETGRP,WiNetworkGroup)!=0) |
InitErrorWi232(17);/* Networkgroup */ |
lcd_printpns_at (i++,4,PSTR("."),0); |
if (WriteWi232(regNETGRP,WiNetworkGroup)!=0) |
InitErrorWi232(18);/* Networkgroup */ |
lcd_printpns_at (i++,4,PSTR("."),0); |
clr_WI232CMD(); |
if (InitErr !=0) |
{ |
lcd_printpns_at (0, 2, PSTR("Wi232 InitError "),0); |
lcd_print_hex(InitErr,0); |
BeepTime = 1000; |
BeepMuster = 0x0040; |
_delay_ms(2000); |
} |
else |
{ |
lcd_printpns_at (0, 2, PSTR("Wi232 Init ok...."),0); |
WriteWiInitFlag(); // Init merken |
} |
USART_Init (UART_BAUD_SELECT(57600,F_CPU)); |
_delay_ms(2000); |
} |
} |
/************************************************************************* |
Function: InitErrorWI232() |
Purpose: Show Wi232 Error, Value |
Returns: |
**************************************************************************/ |
void InitErrorWi232(uint8_t Error) |
{ |
lcd_printpns_at (0, 3, PSTR("Wi232 InitError "),0); |
lcd_print_hex(Error,0); |
InitErr=Error; |
BeepTime = 500; |
BeepMuster = 0x0040; |
_delay_ms(500); |
} |
/************************************************************************* |
Function: WriteWI232() |
Purpose: set Register to Wi232, Register, Value |
Returns: 0 = ACK, FF = NAK |
ACHTUNG nur für Value <0x80 |
**************************************************************************/ |
int16_t WriteWi232(uint8_t Wi232Register, uint8_t RegisterValue) |
{ |
uint8_t timeout=10; |
uint8_t tc=0; |
unsigned int v; |
USART_putc(0xff); |
USART_putc(0x02); |
USART_putc(Wi232Register); |
USART_putc(RegisterValue); |
// lcd_print_hex(Wi232Register,0); |
// lcd_print_hex(RegisterValue,0); |
do |
{ |
v = USART_getc(); /*ACK erwartet*/ |
_delay_ms(100); |
tc ++; |
} |
while (v==0 && tc!=timeout); |
// lcd_print_hex(v,0); |
if (v != 0x06) |
{ |
lcd_printpns_at (0, 2, PSTR("Wi.232 NAK"),0); |
BeepTime = 1000; |
BeepMuster = 0x0040; |
_delay_ms(2000); |
return 0xFF; |
} |
if (v==0x06) |
return 0; |
return 0xFF; |
} |
/************************************************************************* |
Function: ReadWI232() |
Purpose: send Readcommand to Wi232, |
Returns: Registervalue, 0 = timeout 0xFF = Syntaxerror |
**************************************************************************/ |
int16_t ReadWi232(uint16_t Wi232Register) |
{ |
uint8_t timeout=10; |
uint8_t tc=0; |
unsigned int v; |
v = USART_getc(); /*Zeichen löschen*/ |
USART_putc(0xff); |
USART_putc(0x02); |
USART_putc(0xfe); |
USART_putc(Wi232Register); |
_delay_ms(50); |
// lcd_printpns_at (0, 2, PSTR("read Wi232"),0); |
do |
{ |
v = USART_getc(); /*ACK erwartet*/ |
_delay_ms(100); |
tc ++; |
} |
while (v==0 && tc!=timeout); |
if (tc == timeout) |
return 0; /* Timeout*/ |
if (v != 0x06) |
return 0xFF; /* Syntaxerror*/ |
lcd_print_hex(v,0); |
v = USART_getc(); /*Register*/ |
// lcd_print_hex(v,0); |
v = USART_getc(); /*Value*/ |
// lcd_print_hex(v,0); |
return v; |
} |
/************************************************************************* |
Function: EscapeString() |
Purpose: |
Returns: |
Quelle: Radiotronix Wi.232 Manual |
**************************************************************************/ |
int EscapeString(char *src, char src_len, char *dest) |
{ |
// The following function copies and encodes the first |
// src_len characters from *src into *dest. This |
// encoding is necessary for Wi.232 command formats. |
// The resulting string is null terminated. The size |
// of this string is the function return value. |
// --------------------------------------------------- |
uint8_t src_idx, dest_idx; |
// Save space for the command header and size bytes |
// ------------------------------------------------ |
dest_idx = 2; |
// Loop through source string and copy/encode |
// ------------------------------------------ |
for (src_idx = 0; src_idx < src_len; src_idx++) |
{ |
if (src[src_idx] > 127) |
{ |
dest[dest_idx++] = 0xFE; |
} |
dest[dest_idx++] = (src[src_idx] & 0x7F); |
} |
// Add null terminator |
// ------------------- |
dest[dest_idx] = 0; |
// Add command header |
// ------------------ |
dest[0] = 0xFF; |
dest[1] = dest_idx-2; |
// Return escape string size |
// ------------------------- |
return dest_idx; |
} |
//#if defined HWVERSION1_3W || defined HWVERSION3_9 |
/************************************************************************* |
Function: Wi232USB() |
Purpose: Connect Wi232 Programmmode to PKT USB, |
Returns: |
**************************************************************************/ |
void Wi232_USB(void) |
{ |
unsigned int c0,c1; |
if (Wi232_hardware==1) |
{ |
// USART_Init (UART_BAUD_SELECT(57600,F_CPU)); |
// uart1_init( UART_BAUD_SELECT(57600,F_CPU) ); |
// USART_Init (UART_BAUD_SELECT(2400,F_CPU)); |
// uart1_init( UART_BAUD_SELECT(2400,F_CPU) ); |
} |
if (Wi232_hardware==2) |
{ |
USART_Init (UART_BAUD_SELECT(2400,F_CPU)); |
uart1_init( UART_BAUD_SELECT(2400,F_CPU) ); |
} |
lcd_cls (); |
// SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/ |
set_WI232CMD(); |
lcd_printpns_at (0, 0, PSTR("Wi.232 Konfiguration "),0); |
lcd_printpns_at (0, 1, PSTR("PC mit USB verbinden"),0); |
lcd_printpns_at (0, 2, PSTR("Wi.232"),0); |
lcd_printpns_at (0, 3, PSTR("Programm starten"),0); |
lcd_printpns_at (17, 7, PSTR("Exit"),0); |
c1 = 0; |
for(;;) |
{ |
c0 = uart1_getc(); /* from USB*/ |
if ( c0 & UART_NO_DATA ) |
{ |
c1 = USART_getc(); |
if (c1 == 0) |
{} |
else |
{ |
// lcd_print_hex(c1,0); |
uart1_putc (c1); /*to USB*/; |
} |
} |
else |
{ |
USART_putc(c0 ); /* to Wi232*/ |
// lcd_print_hex(c0,0); |
// _delay_ms(1); |
} |
if ((get_key_press (1 << KEY_ENTER))) |
{ |
clr_WI232CMD(); |
// uart1_init( UART_BAUD_SELECT(57600,F_CPU) ); |
// USART_Init( UART_BAUD_SELECT(57600,F_CPU) ); |
// SwitchToFC(); |
return; |
} |
} |
} |
/************************************************************************* |
Function: Wi232_FC() |
Purpose: Connect Wi232 to PKT USB, Transparent |
Returns: |
**************************************************************************/ |
void Wi232_FC(void) |
{ |
unsigned int c0,c1; |
USART_Init (UART_BAUD_SELECT(57600,F_CPU)); |
uart1_init( UART_BAUD_SELECT(57600,F_CPU) ); |
// USART_Init (UART_BAUD_SELECT(2400,F_CPU)); |
// uart1_init( UART_BAUD_SELECT(2400,F_CPU) ); |
lcd_cls (); |
// SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/ |
lcd_printpns_at (0, 0, PSTR("Wi.232 to FC "),0); |
lcd_printpns_at (0, 1, PSTR("PC mit USB verbinden"),0); |
lcd_printpns_at (0, 2, PSTR("und Mikrokoptertool"),0); |
lcd_printpns_at (0, 3, PSTR("starten"),0); |
lcd_printpns_at (17, 7, PSTR("Exit"),0); |
c1 = 0; |
for(;;) |
{ |
c0 = uart1_getc(); /* from USB*/ |
if ( c0 & UART_NO_DATA ) |
{ |
c1 = USART_getc(); |
if (c1 == 0) |
{} |
else |
{ |
// lcd_print_hex(c1,0); |
uart1_putc (c1); /*to USB*/; |
} |
} |
else |
{ |
USART_putc(c0 ); /* to Wi232*/ |
// lcd_print_hex(c0,0); |
// _delay_ms(1); |
} |
if ((get_key_press (1 << KEY_ENTER))) |
{ |
return; |
} |
} |
} |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/Wi232.h |
---|
0,0 → 1,177 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef WI232_H_ |
#define WI232_H_ |
void discoverWi232(void); |
void InitWi232(void); |
int16_t WriteWi232(uint8_t Wi232Register, uint8_t RegisterValue); |
int16_t ReadWi232(uint16_t Wi232Register); |
void InitErrorWi232(uint8_t Error); |
extern uint8_t Wi232_hardware; |
// Non-volatile Registers |
// Name Address Description Default |
#define regNVTXCHANNEL 0x00 // Transmit channel setting ## 0 ## |
#define regNVRXCHANNEL 0x01 // Receive channel setting ## 0 ## |
#define regNVPWRMODE 0x02 // Operating mode settings ## +13 dBm widebandmode ## |
#define regNVDATARATE 0x03 // UART data rate ## 2400bps ## |
#define regNVNETMODE 0x04 // Network mode (Normal/Slave) ## Normal ## |
#define regNVTXTO 0x05 // Transmit wait timeout ## ~16ms ## |
#define regNVNETGRP 0x06 // Network group ID ## 0x00 ## |
#define regNVUSECRC 0x08 // Enable/Disable CRC ## Enabled ## |
#define regNVUARTMTU 0x09 // Minimum transmission unit. ## 64 bytes ## |
#define regNVSHOWVER 0x0A // Enable/Disable start-up message ## Enabled ## |
#define regNVCSMAMODE 0x0B // Enable/Disable CSMA ## Enabled ## |
#define regNVSLPMODE 0x0D // Power state of module ## Awake ## |
#define regNVACKONWAKE 0x0E // Send ACK character to host on wake |
// Non-volatile Read Only Registers |
// Name Address Description |
#define regMAC0 0x22 // These registers form the unique 48-bit MAC address. |
#define regMAC1 0x23 // MAC |
#define regMAC2 0x24 // MAC |
#define regOUI0 0x25 // MAC |
#define regOUI1 0x26 // MAC |
#define regOUI2 0x27 // MAC |
#define regDiscover 0x78 // Versionsregister |
// Volatile Read/Write Registers |
// Name Address Description |
#define regTXCHANNEL 0x4B // Transmit channel setting |
#define regRXCHANNEL 0x4C // Receive channel setting |
#define regPWRMODE 0x4D // Operating mode settings |
#define regDATARATE 0x4E // UART data rate |
#define regNETMODE 0x4F // Network mode (Normal or Slave) |
#define regTXTO 0x50 // Transmit wait timeout |
#define regNETGRP 0x51 // Network group ID |
#define regUSECRC 0x53 // Enable/Disable CRC |
#define regUARTMTU 0x54 // Minimum transmission unit. |
#define regSHOWVER 0x55 // Enable/Disable start-up message |
#define regCSMAMODE 0x56 // Enable/disable CSMA |
#define regSLPMODE 0x58 // Power state of module |
#define regACKONWAKE 0x59 // Send ACK character to host on wake |
// Wideband Channels |
// regNVTXCHAN (0x00) regTXCHAN (0x4B) |
// Channel Number Frequency |
#define wChan0 0x00 // 868.300 MHz |
#define wChan1 0x01 // 868.95 MHz ## MK ## |
// Narrowband Channels |
// regNVRXCHAN (0x01) regRXCHAN (0x4C) |
// Channel Number Frequency |
#define nChan0 0x00 // 868.225 MHz |
#define nChan1 0x01 // 868.375 MHz ## MK ## |
#define nChan2 0x02 // 868.850 MHz |
#define nChan3 0x03 // 869.050 MHz |
#define nChan4 0x04 // 869.525 MHz |
#define nChan5 0x05 // 869.850 MHz |
// Power Mode |
// regNVPWRMODE (0x02) regPWRMODE (0x4D) |
// PM1 PM1 PM0 Mode |
#define NbModeN0 0x00 // 0 0 0 Narrowband Mode 0dBm power setting (typical) |
#define WbModeP5 0x01 // 0 0 1 Wideband Mode +5dBm power setting (typical) |
#define WbModeP10 0x02 // 0 1 0 Wideband Mode +10dBm power setting (typical) |
#define WbModeP15 0x03 // 0 1 1 Wideband Mode +15dBm power setting (typical) ## MK ## |
#define WbModeN0 0x04 // 1 0 0 Wideband Mode 0dBm power setting (typical) |
#define NbModeP5 0x05 // 1 0 1 Narrowband Mode +5dBm power setting (typical) |
#define NbModeP10 0x06 // 1 1 0 Narrowband Mode +10dBm power setting (typical) |
#define NbModeP15 0x07 // 1 1 1 Narrowband Mode +15dBm power setting (typical) |
// Wi232 UART Baudrate |
// regNVDATARATE (0x03) regDATARATE (0x4E) |
// Baud Rate BR2 BR1 BR0 |
#define Wi232_2400 0x00 // 0 0 0* (default 2400) |
#define Wi232_9600 0x01 // 0 0 1 |
#define Wi232_19200 0x02 // 0 1 0 |
#define Wi232_38400 0x03 // 0 1 1 |
#define Wi232_57600 0x04 // 1 0 0 ## MK ## |
#define Wi232_115200 0x05 // 1 0 1 |
#define Wi232_10400 0x06 // 1 1 0 |
#define Wi232_31250 0x07 // 1 1 1 |
// NetworkMode |
// regNVNETMODE (0x04) regNETMODE (0x4F) |
#define NetMode_Slave 0x00 // Slavemode |
#define NetMode_Normal 0x01 // Normalmode (default) |
// Transmit Wait Timeout |
// regNVTXTO (0x05) regTXTO (0x50) |
#define TWaitTimeFull 0x00 // full Buffer required |
#define TWaitTime16 0x10 // 16 ms Delay (default) |
// Network Group |
// regNVNETGRP (0x06) regNETGRP (0x51) |
#define NetWorkGroup 66 // default = 0, valid 0-127 ## MK = 66 ## |
// CRC Control |
// regNVUSECRC (0x08) regUSECRC (0x53) |
#define CRC_Disable 0x00 // no CRC check |
#define CRC_Enable 0x01 // CRC check (default) |
// UART minimum transmission unit |
// regNVUARTMTU (0x09) regUARTMTU (0x54) |
#define UartMTU64 64 // default=64, valid 1-144 |
// Verbose mode |
// regNVSHOWVER (0x0A) |
#define ShowVers_Dis 0x00 // do not show Startupmessage ## MK = 66 ## |
#define ShowVers_En 0x01 // show Startupmessage (default) |
// CSMA enable |
// regNVCSMAMODE (0x0B) regCSMAMODE (0x56) |
#define CSMA_Dis 0x00 // disable CSMA Carrier-sense multiple access |
#define CSMA_En 0x01 // enable CSMA (default) |
// Sleep control |
// regNVSLPMODE (0x0D) regSLPMODE (0x58) |
#define Sleep_Awake 0x00 // Sleepmode = Awake (default) |
#define Sleep 0x01 // Sleepmode = Sleep |
#define Sleep_Stby 0x02 // Sleepmode = Standby |
// ACK on Wake |
// regNVACKONWAKE (0x0D) regACKONWAKE (0x59) |
#define ACKwake_Dis 0x00 // disable ACK on Wake |
#define ACKwake_En 0x01 // enable ACK on Wake (default) |
#endif // WI232_H_ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/fifo.c |
---|
0,0 → 1,114 |
/** |
* a simple Fifo |
* @file fifo.c |
* @author Pascal Schnurr |
*/ |
#include "fifo.h" |
//-------------------------------------------------------------- |
void fifo_init (fifo_t * fifo, uint8_t * buffer, uint16_t size) |
{ |
fifo->size = size; |
fifo->buffer = buffer; |
fifo->head = 0; |
fifo->count = 0; |
} |
//-------------------------------------------------------------- |
bool fifo_is_empty (const fifo_t * fifo) |
{ |
return (fifo->count == 0); |
} |
//-------------------------------------------------------------- |
bool fifo_is_full (const fifo_t * fifo) |
{ |
return (fifo->size - fifo->count == 0); |
} |
//-------------------------------------------------------------- |
bool fifo_read (fifo_t * fifo, char *data) |
{ |
if (fifo_is_empty (fifo)) |
return false; |
uint8_t *head = fifo->buffer + fifo->head; |
*data = (char) * head; |
fifo->head = ( (fifo->head + 1) % fifo->size); |
fifo->count--; |
return true; |
} |
//-------------------------------------------------------------- |
bool fifo_write (fifo_t * fifo, const char data) |
{ |
if (fifo_is_full (fifo)) |
return false; |
uint8_t *end = fifo->buffer + ( (fifo->head + fifo->count) % fifo->size); |
*end = (uint8_t) data; |
fifo->count++; |
return true; |
} |
//-------------------------------------------------------------- |
bool fifo_clear (fifo_t * fifo) |
{ |
fifo->count = 0; |
fifo->head = 0; |
return true; |
} |
//-------------------------------------------------------------- |
static bool fifo_cmp_pgm_at (fifo_t * fifo, const prog_char * pgm, const uint16_t index) |
{ |
uint16_t i; |
uint8_t fifo_byte; |
uint8_t pgm_byte; |
for (i = 0; pgm_read_byte (pgm + i) != 0; i++) |
{ |
if (fifo->count <= (i + index)) |
return false; |
pgm_byte = pgm_read_byte (pgm + i); |
fifo_byte = * (fifo->buffer + ( (fifo->head + i + index) % fifo->size)); |
if (fifo_byte != pgm_byte) |
return false; |
} |
// We found the string, lets move the pointer |
fifo->head = ( (fifo->head + i + index) % fifo->size); |
fifo->count -= (i + index); |
return true; |
} |
//-------------------------------------------------------------- |
bool fifo_cmp_pgm (fifo_t * fifo, const prog_char * pgm) |
{ |
return fifo_cmp_pgm_at (fifo, pgm, 0); |
} |
//-------------------------------------------------------------- |
bool fifo_strstr_pgm (fifo_t * fifo, const prog_char * pgm) |
{ |
for (uint16_t i = 0; i < fifo->count; i++) |
{ |
if (fifo_cmp_pgm_at (fifo, pgm, i)) |
return true; |
} |
return false; |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/fifo.h |
---|
0,0 → 1,83 |
/** |
* a simple Fifo |
* @file fifo.h |
* @author Pascal Schnurr |
*/ |
#include <avr/pgmspace.h> |
#include <stdbool.h> |
#ifndef _FIFO_H_ |
#define _FIFO_H_ |
/** |
*fifo data structure all vital fifo information |
*/ |
typedef struct |
{ |
uint16_t count; /**< current number of elements */ |
uint16_t head; /**< position of the head element */ |
uint16_t size; /**< size equals max number of entrys*/ |
uint8_t* buffer; /**< pointer to memory area where the fifo is to be saved */ |
} fifo_t; |
/** \brief initialize of a fifo |
* sets all the information in your given fifo structure |
* @param fifo pointer to an allocated fifo_t structure |
* @param buffer pointer to an a allocated memory space for the fifo of size = sizeof(uint8_t) * size |
* @param size max number of entrys the fifo will hold |
*/ |
void fifo_init (fifo_t *fifo, uint8_t *buffer, uint16_t size); |
/** \brief checks if fifo is empty |
* @param fifo pointer to your initialized fifo_t structure |
* @return true if empty otherwise false |
*/ |
bool fifo_is_empty (const fifo_t *fifo); |
/** \brief checks if fifo is full |
* @param fifo pointer to your initialized fifo_t structure |
* @return true if full otherwise false |
*/ |
bool fifo_is_full (const fifo_t *fifo); |
/** \brief clears the fifo |
* resets your fifo structure to 0 elements |
* @param fifo pointer to your initialized fifo_t structure |
* @return always true (never fails) |
*/ |
bool fifo_clear (fifo_t *fifo); |
/** \brief reads head of fifo |
* reads the first element and removes it |
* @param fifo pointer to your initialized fifo_t structure |
* @return false if fifo is empty false otherwise |
*/ |
bool fifo_read (fifo_t *fifo, char *data); |
/** \brief inserts a char into the fifo |
* adds a char to the end of the fifo |
* @param fifo pointer to your initialized fifo_t structure |
* @param data the char data to be inserted |
* @return false if fifo is full true otherwise |
*/ |
bool fifo_write (fifo_t *fifo, const char data); |
/** \brief compares first elements with prog_char string |
* if pgm equals the first elements of the fifo these elements are removed |
* @param fifo pointer to your initialized fifo_t structure |
* @param pgm a prog_char string for comparison |
* @return true if pgm is equal to the first entrys in the fifo, false otherwise |
*/ |
bool fifo_cmp_pgm (fifo_t* fifo, const prog_char* pgm); |
/** \brief searches a string in the whole fifo |
* starts at the beginning and searches for the pgm string in the fifo, |
* if they are found previous entrys and the string are removed from the fifo |
* @param fifo pointer to your initialized fifo_t structure |
* @param pgm a prog_char with the search string |
* @return true if found, false otherwise |
*/ |
bool fifo_strstr_pgm (fifo_t *fifo, const prog_char *pgm); |
#endif /* _FIFO_H_ */ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/font8x6.c |
---|
0,0 → 1,171 |
/***************************************************************************** |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* - font provided by Claas Anders "CaScAdE" Rathje * |
* - umlauts and special characters by Peter "woggle" Mack * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
*****************************************************************************/ |
#include <avr/pgmspace.h> |
// one byte is a column |
// bit 7 is the bottom |
// |
// 123456 |
// L 1 | XXX | |
// O 2 |X X | |
// W 4 |X X | |
// 8 | XXX | |
// H 1 |X X | |
// I 2 |X X | |
// G 4 | XXX | |
// H 8 | | |
// |
// 0x36,0x49,0x49,0x49,0x36,0x00 |
// |
prog_uint8_t font8x6[128][6] = |
{ |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 0 00 (not useable) |
{ 0x78,0x15,0x14,0x15,0x78,0x00 }, // ASCII - 1 01 'Ä' |
{ 0x20,0x55,0x54,0x55,0x78,0x00 }, // ASCII - 2 02 'ä' |
{ 0x38,0x45,0x44,0x45,0x38,0x00 }, // ASCII - 3 03 'Ö' |
{ 0x30,0x49,0x48,0x49,0x30,0x00 }, // ASCII - 4 04 'ö' |
{ 0x3c,0x41,0x40,0x41,0x3c,0x00 }, // ASCII - 5 05 'Ü' |
{ 0x38,0x41,0x40,0x21,0x78,0x00 }, // ASCII - 6 06 'ü' |
{ 0x7e,0x15,0x15,0x15,0x0a,0x00 }, // ASCII - 7 07 'ß' |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 8 08 |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 9 09 |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 10 0A (not useable) |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 11 0B |
{ 0x10,0x38,0x54,0x10,0x10,0x1e }, // ASCII - 12 0C Enter Symbol |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 13 0D (not useable) |
{ 0x10,0x10,0x10,0x10,0x10,0x10 }, // ASCII - 14 0E hor. line |
{ 0x10,0x10,0x10,0x7c,0x10,0x10 }, // ASCII - 15 0F hor. line with tick mark |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 16 10 |
{ 0x08,0x14,0x00,0x00,0x14,0x08 }, // ASCII - 17 11 <> Change |
{ 0x10,0x08,0x04,0x04,0x08,0x10 }, // ASCII - 18 12 /\ Up |
{ 0x08,0x10,0x20,0x20,0x10,0x08 }, // ASCII - 19 13 \/ Down |
{ 0x00,0x08,0x14,0x22,0x41,0x00 }, // ASCII - 20 14 < Left |
{ 0x00,0x41,0x22,0x14,0x08,0x00 }, // ASCII - 21 15 > Right |
{ 0x04,0x02,0x7f,0x02,0x04,0x00 }, // ASCII - 22 16 /|\ Arrow up |
{ 0x10,0x20,0x7f,0x20,0x10,0x00 }, // ASCII - 23 17 \|/ Arrow down |
{ 0x10,0x38,0x54,0x10,0x10,0x10 }, // ASCII - 24 18 <- Arrow left |
{ 0x10,0x10,0x10,0x54,0x38,0x10 }, // ASCII - 25 19 -> Arrow right |
{ 0x10,0x18,0x1c,0x1c,0x18,0x10 }, // ASCII - 26 1A ^ Triangle up |
{ 0x08,0x18,0x38,0x38,0x18,0x08 }, // ASCII - 27 1B v Triangle down |
{ 0x00,0x08,0x1c,0x3e,0x7f,0x00 }, // ASCII - 28 1C < Triangle left |
{ 0x00,0x7f,0x3e,0x1c,0x08,0x00 }, // ASCII - 29 1D > Triangle right |
{ 0x06,0x09,0x09,0x09,0x06,0x00 }, // ASCII - 30 1E '°' |
{ 0x06,0x49,0x7d,0x49,0x06,0x00 }, // ASCII - 31 1F Antenne |
{ 0x00,0x00,0x00,0x00,0x00,0x00 }, // ASCII - 32 20 ' ' |
{ 0x00,0x00,0x2f,0x00,0x00,0x00 }, // ASCII - 33 21 '!' |
{ 0x00,0x07,0x00,0x07,0x00,0x00 }, // ASCII - 34 22 '"' |
{ 0x14,0x7f,0x14,0x7f,0x14,0x00 }, // ASCII - 35 23 '#' |
{ 0x24,0x2a,0x6b,0x2a,0x12,0x00 }, // ASCII - 36 24 '$' |
{ 0x23,0x13,0x08,0x64,0x62,0x00 }, // ASCII - 37 25 '%' |
{ 0x36,0x49,0x55,0x22,0x50,0x00 }, // ASCII - 38 26 '&' |
{ 0x00,0x05,0x03,0x00,0x00,0x00 }, // ASCII - 39 27 ''' |
{ 0x00,0x1c,0x22,0x41,0x00,0x00 }, // ASCII - 40 28 '(' |
{ 0x00,0x41,0x22,0x1c,0x00,0x00 }, // ASCII - 41 29 ')' |
{ 0x14,0x08,0x3e,0x08,0x14,0x00 }, // ASCII - 42 2a '*' |
{ 0x08,0x08,0x3e,0x08,0x08,0x00 }, // ASCII - 43 2b '+' |
{ 0x00,0x50,0x30,0x00,0x00,0x00 }, // ASCII - 44 2c ',' |
{ 0x08,0x08,0x08,0x08,0x08,0x00 }, // ASCII - 45 2d '-' |
{ 0x00,0x60,0x60,0x00,0x00,0x00 }, // ASCII - 46 2e '.' |
{ 0x20,0x10,0x08,0x04,0x02,0x00 }, // ASCII - 47 2f '/' |
{ 0x3e,0x51,0x49,0x45,0x3e,0x00 }, // ASCII - 48 30 '0' |
{ 0x00,0x42,0x7f,0x40,0x00,0x00 }, // ASCII - 49 31 '1' |
{ 0x42,0x61,0x51,0x49,0x46,0x00 }, // ASCII - 50 32 '2' |
{ 0x21,0x41,0x45,0x4b,0x31,0x00 }, // ASCII - 51 33 '3' |
{ 0x18,0x14,0x12,0x7f,0x10,0x00 }, // ASCII - 52 34 '4' |
{ 0x27,0x45,0x45,0x45,0x39,0x00 }, // ASCII - 53 35 '5' |
{ 0x3c,0x4a,0x49,0x49,0x30,0x00 }, // ASCII - 54 36 '6' |
{ 0x03,0x01,0x71,0x09,0x07,0x00 }, // ASCII - 55 37 '7' |
{ 0x36,0x49,0x49,0x49,0x36,0x00 }, // ASCII - 56 38 '8' |
{ 0x06,0x49,0x49,0x29,0x1e,0x00 }, // ASCII - 57 39 '9' |
{ 0x00,0x36,0x36,0x00,0x00,0x00 }, // ASCII - 58 3a ':' |
{ 0x00,0x56,0x36,0x00,0x00,0x00 }, // ASCII - 59 3b ';' |
{ 0x08,0x14,0x22,0x41,0x00,0x00 }, // ASCII - 60 3c '<' |
{ 0x14,0x14,0x14,0x14,0x14,0x00 }, // ASCII - 61 3d '=' |
{ 0x00,0x41,0x22,0x14,0x08,0x00 }, // ASCII - 62 3e '>' |
{ 0x02,0x01,0x51,0x09,0x06,0x00 }, // ASCII - 63 3f '?' |
{ 0x32,0x49,0x79,0x41,0x3e,0x00 }, // ASCII - 64 40 '@' |
{ 0x7e,0x11,0x11,0x11,0x7e,0x00 }, // ASCII - 65 41 'A' |
{ 0x7f,0x49,0x49,0x49,0x36,0x00 }, // ASCII - 66 42 'B' |
{ 0x3e,0x41,0x41,0x41,0x22,0x00 }, // ASCII - 67 43 'C' |
{ 0x7f,0x41,0x41,0x22,0x1c,0x00 }, // ASCII - 68 44 'D' |
{ 0x7f,0x49,0x49,0x49,0x41,0x00 }, // ASCII - 69 45 'E' |
{ 0x7f,0x09,0x09,0x09,0x01,0x00 }, // ASCII - 70 46 'F' |
{ 0x3e,0x41,0x49,0x49,0x7a,0x00 }, // ASCII - 71 47 'G' |
{ 0x7f,0x08,0x08,0x08,0x7f,0x00 }, // ASCII - 72 48 'H' |
{ 0x00,0x41,0x7f,0x41,0x00,0x00 }, // ASCII - 73 49 'I' |
{ 0x20,0x40,0x41,0x3f,0x01,0x00 }, // ASCII - 74 4a 'J' |
{ 0x7f,0x08,0x14,0x22,0x41,0x00 }, // ASCII - 75 4b 'K' |
{ 0x7f,0x40,0x40,0x40,0x40,0x00 }, // ASCII - 76 4c 'L' |
{ 0x7f,0x02,0x0c,0x02,0x7f,0x00 }, // ASCII - 77 4d 'M' |
{ 0x7f,0x04,0x08,0x10,0x7f,0x00 }, // ASCII - 78 4e 'N' |
{ 0x3e,0x41,0x41,0x41,0x3e,0x00 }, // ASCII - 79 4f 'O' |
{ 0x7f,0x09,0x09,0x09,0x06,0x00 }, // ASCII - 80 50 'P' |
{ 0x3e,0x41,0x51,0x21,0x5e,0x00 }, // ASCII - 81 51 'Q' |
{ 0x7f,0x09,0x19,0x29,0x46,0x00 }, // ASCII - 82 52 'R' |
{ 0x46,0x49,0x49,0x49,0x31,0x00 }, // ASCII - 83 53 'S' |
{ 0x01,0x01,0x7f,0x01,0x01,0x00 }, // ASCII - 84 54 'T' |
{ 0x3f,0x40,0x40,0x40,0x3f,0x00 }, // ASCII - 85 55 'U' |
{ 0x1f,0x20,0x40,0x20,0x1f,0x00 }, // ASCII - 86 56 'V' |
{ 0x3f,0x40,0x38,0x40,0x3f,0x00 }, // ASCII - 87 57 'W' |
{ 0x63,0x14,0x08,0x14,0x63,0x00 }, // ASCII - 88 58 'X' |
{ 0x07,0x08,0x70,0x08,0x07,0x00 }, // ASCII - 89 59 'Y' |
{ 0x61,0x51,0x49,0x45,0x43,0x00 }, // ASCII - 90 5a 'Z' |
{ 0x7f,0x41,0x41,0x00,0x00,0x00 }, // ASCII - 91 5b '[' |
{ 0x02,0x04,0x08,0x10,0x20,0x00 }, // ASCII - 92 5c '\' |
{ 0x00,0x41,0x41,0x7f,0x00,0x00 }, // ASCII - 93 5d ']' |
{ 0x04,0x02,0x01,0x02,0x04,0x00 }, // ASCII - 94 5e '^' |
{ 0x40,0x40,0x40,0x40,0x40,0x00 }, // ASCII - 95 5f '_' |
{ 0x00,0x01,0x02,0x04,0x00,0x00 }, // ASCII - 96 60 '`' |
{ 0x20,0x54,0x54,0x54,0x78,0x00 }, // ASCII - 97 61 'a' |
{ 0x7f,0x48,0x44,0x44,0x38,0x00 }, // ASCII - 98 62 'b' |
{ 0x38,0x44,0x44,0x44,0x20,0x00 }, // ASCII - 99 63 'c' |
{ 0x38,0x44,0x44,0x48,0x7f,0x00 }, // ASCII - 100 64 'd' |
{ 0x38,0x54,0x54,0x54,0x18,0x00 }, // ASCII - 101 65 'e' |
{ 0x08,0x7e,0x09,0x01,0x02,0x00 }, // ASCII - 102 66 'f' |
{ 0x0c,0x52,0x52,0x52,0x3e,0x00 }, // ASCII - 103 67 'g' |
{ 0x7f,0x08,0x04,0x04,0x78,0x00 }, // ASCII - 104 68 'h' |
{ 0x00,0x44,0x7d,0x40,0x00,0x00 }, // ASCII - 105 69 'i' |
{ 0x20,0x40,0x44,0x3d,0x00,0x00 }, // ASCII - 106 6a 'j' |
{ 0x7f,0x10,0x28,0x44,0x00,0x00 }, // ASCII - 107 6b 'k' |
{ 0x00,0x41,0x7f,0x40,0x00,0x00 }, // ASCII - 108 6c 'l' |
{ 0x7c,0x04,0x18,0x04,0x78,0x00 }, // ASCII - 109 6d 'm' |
{ 0x7c,0x08,0x04,0x04,0x78,0x00 }, // ASCII - 110 6e 'n' |
{ 0x38,0x44,0x44,0x44,0x38,0x00 }, // ASCII - 111 6f 'o' |
{ 0x7c,0x14,0x14,0x14,0x08,0x00 }, // ASCII - 112 70 'p' |
{ 0x08,0x14,0x14,0x18,0x7c,0x00 }, // ASCII - 113 71 'q' |
{ 0x7c,0x08,0x04,0x04,0x08,0x00 }, // ASCII - 114 72 'r' |
{ 0x48,0x54,0x54,0x54,0x20,0x00 }, // ASCII - 115 73 's' |
{ 0x04,0x3f,0x44,0x40,0x20,0x00 }, // ASCII - 116 74 't' |
{ 0x3c,0x40,0x40,0x20,0x7c,0x00 }, // ASCII - 117 75 'u' |
{ 0x1c,0x20,0x40,0x20,0x1c,0x00 }, // ASCII - 118 76 'v' |
{ 0x3c,0x40,0x38,0x40,0x3c,0x00 }, // ASCII - 119 77 'w' |
{ 0x44,0x28,0x10,0x28,0x44,0x00 }, // ASCII - 120 78 'x' |
{ 0x0c,0x50,0x50,0x50,0x3c,0x00 }, // ASCII - 121 79 'y' |
{ 0x44,0x64,0x54,0x4c,0x44,0x00 }, // ASCII - 122 7a 'z' |
{ 0x00,0x08,0x36,0x41,0x00,0x00 }, // ASCII - 123 7b '{' |
{ 0x00,0x00,0x7f,0x00,0x00,0x00 }, // ASCII - 124 7c '|' |
{ 0x00,0x41,0x36,0x08,0x00,0x00 }, // ASCII - 125 7d '}' |
{ 0x08,0x08,0x2a,0x1c,0x08,0x00 }, // ASCII - 126 7e -> |
{ 0x08,0x1c,0x2a,0x08,0x08,0x00 }, // ASCII - 127 7f <- |
}; |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/font8x6.h |
---|
0,0 → 1,29 |
/***************************************************************************** |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* - font provided by Claas Anders "CaScAdE" Rathje * |
* - umlauts and special characters by Peter "woggle" Mack * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
*****************************************************************************/ |
#ifndef _FONT8X6_H |
#define _FONT8X6_H |
#include <avr/pgmspace.h> |
extern prog_uint8_t font8x6[128][6]; |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/gps.c |
---|
0,0 → 1,364 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include <avr/io.h> |
#include <inttypes.h> |
#include <stdlib.h> |
#include <avr/pgmspace.h> |
#include "main.h" |
#include "lcd.h" |
#include "timer.h" |
#include "usart.h" |
#define TIMEOUT 200 // 2 sec |
uint8_t ck_a = 0; |
uint8_t ck_b = 0; |
uint8_t UBX_class = 0; |
uint8_t UBX_id = 0; |
uint8_t UBX_buffer[250]; |
uint8_t UBX_payload_counter = 0; |
void checksum(uint8_t); |
void UBX_process(void); |
uint32_t join_4_bytes(uint8_t*); |
uint8_t display_mode = 0; |
//-------------------------------------------------------------- |
void gps(void) |
{ |
lcd_cls(); |
display_mode = 2; |
if (hardware == FC) |
{ |
lcd_printp_at(0, 3, PSTR("Nur mit NC !"), 0); |
timer = 100; |
while (timer > 0); |
return; |
} |
if(current_hardware != NC) |
SwitchToNC(); |
SwitchToGPS(); |
uint8_t mode = 0; |
// SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
timer = TIMEOUT; |
uint8_t data = 0; |
uint8_t length = 0; |
uint8_t UBX_ck_a = 0; |
do |
{ |
// if (rxFlag == 1) |
if (uart_getc_nb(&data)) |
{ |
//rxFlag = 0; |
//data = rx_byte; |
timer = TIMEOUT; |
switch(mode) |
{ |
case 0: // init 1 |
if(data == 0xB5) |
{ |
UBX_payload_counter = 0; |
UBX_id = 0; |
UBX_class = 0; |
ck_a = 0; |
ck_b = 0; |
mode++; |
} |
break; |
case 1: // init 2 |
if(data == 0x62) |
mode++; |
else |
mode = 0; |
break; |
case 2: //class |
if(data != 1) |
mode = 0; |
else |
{ |
checksum(data); |
UBX_class = data; |
mode++; |
} |
break; |
case 3: // id |
if((data != 48)&&(data != 6)&&(data != 18)&&(data != 2)) |
mode = 0; |
else |
{ |
UBX_id = data; |
checksum(data); |
mode++; |
} |
break; |
case 4: // length lo |
if(data > 250) |
mode = 0; |
else |
{ |
checksum(data); |
length = data; |
mode++; |
} |
break; |
case 5: // length hi |
if(data != 0) |
mode = 0; |
else |
{ |
checksum(data); |
mode++; |
} |
break; |
case 6: // length hi |
length--; |
UBX_buffer[UBX_payload_counter] = data; |
checksum(data); |
UBX_payload_counter++; |
if(length==0) |
{ |
mode++; |
}; |
break; |
case 7: // check lo |
mode++; |
UBX_ck_a = data; |
break; |
case 8: // check hi |
mode=0; |
if((UBX_ck_a == ck_a) && (data == ck_b)) |
UBX_process(); |
} |
// write_ndigit_number_u (14, 0, data, 3, 0); |
} |
} |
while (!get_key_press (1 << KEY_ESC) && timer); |
get_key_press(KEY_ALL); |
SwitchToNC(); |
} |
//-------------------------------------------------------------- |
void UBX_process() |
{ |
if ((get_key_press (1 << KEY_MINUS))||(display_mode == 2)) |
{ |
if (display_mode != 1) |
{ |
lcd_cls(); |
lcd_printp_at (0,0, PSTR("Fix Type : "), 0); |
lcd_printp_at (0,1, PSTR("Sat : "), 0); |
lcd_printp_at (0,2, PSTR("Accuracy : "), 0); |
lcd_printp_at (0,3, PSTR("PDOP : "), 0); |
lcd_printp_at (0,4, PSTR("Speed : "), 0); |
lcd_printp_at (0,5, PSTR("Long : "), 0); |
lcd_printp_at (0,6, PSTR("Lat : "), 0); |
lcd_printp_at (0,7, PSTR("Alt : "), 0); |
} |
display_mode = 1; |
} |
if((UBX_class == 1) && (UBX_id == 48)&&(display_mode == 0)) |
{ |
uint8_t channels = UBX_buffer[4]; |
uint8_t i = 0; |
for(i = 0; i < channels; i++) |
{ |
if (i > 15) |
break; |
uint8_t line; |
uint8_t col; |
if (i > 7) |
{ |
line = i-7; |
col = 11; |
} |
else |
col = 0; line = i; |
write_ndigit_number_u (col, line, UBX_buffer[9 + 12*i], 3, 0); |
write_ndigit_number_u (col+4, line, UBX_buffer[12 + 12*i], 2, 0); |
if((UBX_buffer[10 + 12*i] & 3) == 3) |
lcd_printp_at (col+7,line, PSTR("O"), 0); |
else if((UBX_buffer[10 + 12*i] & 1) == 1) |
lcd_printp_at (col+7,line, PSTR("X"), 0); |
else if(UBX_buffer[11 + 12*i] > 4) |
lcd_printp_at (col+7,line, PSTR("x"), 0); |
else if(UBX_buffer[11 + 12*i] > 1) |
lcd_printp_at (col+7,line, PSTR("-"), 0); |
else |
lcd_printp_at (col+7,line, PSTR(" "), 0); |
} |
} |
if(display_mode == 1) |
{ |
if((UBX_class == 1) && (UBX_id == 6)) //SVINFO |
{ |
switch (UBX_buffer[10]) |
{ |
case 4: |
case 3: |
lcd_printp_at (11,0, PSTR("3D"), 0); |
break; |
case 2: |
lcd_printp_at (11,0, PSTR("2D"), 0); |
break; |
default: |
lcd_printp_at (11,0, PSTR("no"), 0); |
} |
if((UBX_buffer[11] & 3) == 3) |
lcd_printp_at (17,0, PSTR("D"), 0); |
else |
lcd_printp_at (17,0, PSTR(" "), 0); |
if((UBX_buffer[11] & 1) == 1) |
lcd_printp_at (14,0, PSTR("ok"), 0); |
else |
lcd_printp_at (14,0, PSTR(" "), 0); |
lcd_write_number_u_at (11, 1, UBX_buffer[47]); |
uint16_t acc = (uint16_t)join_4_bytes(&UBX_buffer[24]); |
write_ndigit_number_u (11, 2, acc, 5, 0); |
lcd_printp_at (17,2, PSTR("cm"), 0); |
uint16_t pdop = UBX_buffer[44]+UBX_buffer[45]*255; |
write_ndigit_number_u (11, 3, pdop/100, 2, 0); |
lcd_printp_at (13,3, PSTR("."), 0); |
write_ndigit_number_u (14, 3, (pdop % 100),2, 1); |
} |
if((UBX_class == 1) && (UBX_id == 18)) //VELNED |
{ |
uint16_t speed = (uint16_t)((join_4_bytes(&UBX_buffer[20])*60*60)/100000); |
write_ndigit_number_u (11, 4, speed, 3, 0); |
lcd_printp_at (15,4, PSTR("km/h"), 0); |
} |
if((UBX_class == 1) && (UBX_id == 2)) //POSLLH |
{ |
uint32_t lon = join_4_bytes(&UBX_buffer[4]); |
write_ndigit_number_u (10, 5, (uint16_t)(lon/10000000), 2, 0); |
lcd_printp_at (12,5, PSTR("."), 0); |
write_ndigit_number_u (13, 5, (uint16_t)((lon/1000) % 10000), 4, 1); |
write_ndigit_number_u (17, 5, (uint16_t)((lon/10) % 100), 2, 1); |
uint32_t lat = join_4_bytes(&UBX_buffer[8]); |
write_ndigit_number_u (10, 6, (uint16_t)(lat/10000000), 2, 0); |
lcd_printp_at (12,6, PSTR("."), 0); |
write_ndigit_number_u (13, 6, (uint16_t)((lat/1000) % 10000), 4, 1); |
write_ndigit_number_u (17, 6, (uint16_t)((lat/10) % 100), 2, 1); |
uint16_t height = (uint16_t)(join_4_bytes(&UBX_buffer[16])/1000); |
write_ndigit_number_u (11, 7, height, 4, 0); |
lcd_printp_at (16,7, PSTR("m"), 0); |
} |
} |
} |
//-------------------------------------------------------------- |
union long_union |
{ |
uint32_t dword; |
uint8_t byte[4]; |
} longUnion; |
//-------------------------------------------------------------- |
union int_union |
{ |
uint16_t dword; |
uint8_t byte[2]; |
} intUnion; |
//-------------------------------------------------------------- |
uint32_t join_4_bytes(uint8_t Buffer[]) |
{ |
longUnion.byte[0] = *Buffer; |
longUnion.byte[1] = *(Buffer+1); |
longUnion.byte[2] = *(Buffer+2); |
longUnion.byte[3] = *(Buffer+3); |
return (longUnion.dword); |
} |
//-------------------------------------------------------------- |
void checksum(uint8_t data) |
{ |
ck_a += data; |
ck_b += ck_a; |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/gps.h |
---|
0,0 → 1,40 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef _GPS_H |
#define _GPS_H |
void gps (void); |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/servo.c |
---|
0,0 → 1,156 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include "lcd.h" |
#include "timer.h" |
#include "servo.h" |
#include "messages.h" |
#define SERVO_CORRECT 3.125 |
//-------------------------------------------------------------- |
// |
void servo_test (void) |
{ |
uint8_t chg = 0; |
uint8_t Pos = 150; // 1,5mS |
OCR1A = 150 * SERVO_CORRECT; // Servomitte |
lcd_cls (); |
lcd_printp (PSTR(" Servo Tester "), 2); |
lcd_printp_at (7, 5, PSTR("%"), 0); |
lcd_printp_at (16, 5, PSTR("mS"), 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_3), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE3), 0); |
lcd_printp_at (18, 7, PSTR("\x19O\x18"), 0); |
lcd_rect(3, 23, 120, 8, 1); // +-150% Rahmen |
lcd_line(23,23,23,31,1); // -100% |
lcd_line(43,23,43,31,1); // -50% |
lcd_frect(61, 23, 3, 8, 1); // 0% |
lcd_line(83,23,83,31,1); // +50% |
lcd_line(103,23,103,31,1); // +100% |
write_ndigit_number_u (4, 5, 0, 3, 0); // Pulse width in % |
write_ndigit_number_u_100th(12, 5, 150, 3, 0); // Pulse width in ms |
do |
{ |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Pos < 225)) |
{ |
if (Pos < 150) |
lcd_frect ((63 - ((150 - Pos) * 0.8)), 24, 1, 6, 0); |
Pos++; |
if (Pos == 75 || Pos == 100 || Pos == 125 || Pos == 150 || Pos == 175 || Pos == 200 || Pos == 225) |
{ |
BeepTime = 200; |
BeepMuster = 0x0080; |
} |
if (Pos >= 225) |
Pos = 225; |
chg++; |
} |
else if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Pos > 75)) |
{ |
if (Pos > 150) |
lcd_frect ((((Pos - 150) * 0.8) + 63), 24, ((Pos - 150) * 0.8), 6, 0); |
Pos--; |
if (Pos == 75 || Pos == 100 || Pos == 125 || Pos == 150 || Pos == 175 || Pos == 200 || Pos == 225) |
{ |
BeepTime = 200; |
BeepMuster = 0x0080; |
} |
if (Pos <= 75) |
Pos = 75; |
chg++; |
} |
else if (get_key_press (1 << KEY_ENTER)) |
{ |
lcd_frect (4, 24, 118, 6, 0); // Balken löschen |
lcd_frect(61, 23, 3, 8, 1); // 0% |
Pos = 150; |
BeepTime = 200; |
BeepMuster = 0x0080; |
chg++; |
} |
if (chg) |
{ |
chg = 0; |
if (Pos >= 150) |
{ |
lcd_frect (63, 24, ((Pos - 150) * 0.8), 6, 1); |
write_ndigit_number_u (4, 5, ((Pos - 150) * 2), 3, 0); // Pulse width in % |
lcd_frect(62, 23, 2, 8, 1); // 0% |
} |
else |
{ |
lcd_frect (63 - ((150 - Pos) * 0.8), 24, ((150 - Pos) * 0.8), 6, 1); |
write_ndigit_number_u (4, 5, ((150 - Pos) * 2), 3, 0); // Pulse width in % |
lcd_frect(61, 23, 2, 8, 1); // 0% |
} |
write_ndigit_number_u_100th(12, 5, Pos, 3, 0); // Pulse width in ms |
lcd_line(3, 23,3, 31,1); // -150% |
lcd_line(23, 23,23, 31,1); // -100% |
lcd_line(43, 23,43, 31,1); // -50% |
lcd_line(83, 23,83, 31,1); // +50% |
lcd_line(103,23,103,31,1); // +100% |
lcd_line(123,23,123,31,1); // +150% |
OCR1A = Pos * SERVO_CORRECT; // Servostellung |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
get_key_press(KEY_ALL); |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/servo.h |
---|
0,0 → 1,40 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef _SERVO_H |
#define _SERVO_H |
void servo_test (void); |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/setup.c |
---|
0,0 → 1,1969 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <string.h> |
#include <util/delay.h> |
#include "main.h" |
#include "setup.h" |
#include "lcd.h" |
#include "eeprom.h" |
#include "timer.h" |
#include "menu.h" |
#include "Wi232.h" |
#include "bluetooth.h" |
#include "connect.h" |
#include "lipo.h" |
#include "messages.h" |
#include "eeprom.h" |
uint8_t spalte; |
uint8_t mmode; |
uint8_t edit; |
uint8_t LCD_Orientation; |
uint8_t edit = 0; |
uint8_t LCD_Change = 0; |
uint8_t PKT_Change = 0; |
uint8_t Pre; |
uint16_t Pre16; |
char EditString[21]; |
uint8_t bt_name_len; |
//-------------------------------------------------------------- |
#define ITEMS_PKT 9 |
prog_char param_menuitems_pkt[ITEMS_PKT][NUM_LANG][18]= // zeilen,zeichen+1 |
// German, English, French, Dutch |
{ |
{"Verbindung zum MK","connection to MK "," connexion a MK " ,"Aansluiting op MK"}, |
{"MK LowBat Warnung","MK LowBat warning","MK LowBat Attent", "MK LowBat waarsch"}, |
{"Anzeige \x1d","Display \x1d","d'affichage \x1d","tonen \x1d"}, |
{"Wi.232 \x1d","Wi.232 \x1d","Wi.232 \x1d","Wi.232 \x1d"}, |
{"BTM-222 \x1d","BTM-222 \x1d","BTM-222 \x1d","BTM-222 \x1d"}, |
{"PKT-Akku \x1d","PKT-Accu \x1d","PKT-Accu \x1d","PKT-Accu \x1d"}, |
{"PKT Update ","PKT Update ","PKT Mise à jour ","PKT Update "}, |
{"Debug PKT ","Debug PKT ","Debug PKT ","Debug PKT "}, |
{"EEProm Reset ","EEProm Reset ","EEProm Réinitiali","EEProm Reset "}, |
}; |
#define ITEMS_LCD 7 |
prog_char param_menuitems_lcd[ITEMS_LCD][NUM_LANG][18]= // zeilen,zeichen+1 |
// German, English, French, Dutch |
{ |
{"Infos beim Start ","info at startup ","Infor. sur lancer","Infor. o.de start"}, |
{"Sprache ","language ","Langue ","taal "}, |
{"Licht aus nach...","light off after ","Lumière au bout ","Lichten uit voor "}, |
{"Helligkeit ","brightness ","luminosité ","helderheid "}, |
{"Kontrast ","contrast ","contraste ","contrast "}, |
{"Normal/Invers ","normal/inverted ","Normal / inversé ","Normal/inverted "}, |
{"Orientierung ","orientation ","orientation ","orientatie "}, |
}; |
#define ITEMS_WI 8 |
prog_char param_menuitems_wi[ITEMS_WI][NUM_LANG][18]= // zeilen,zeichen+1 |
// German, English, French, Dutch |
{ |
{"Modul eingebaut? ","module built in? ","Module installé ","module geïnstall?"}, |
{"TX/RX Kanal ","TX/RX Channel ","TX/RX Channel ","TX/RX Channel "}, |
{"NetW. Gruppe ","NetW. Group ","NetW. Group ","NetW. Group "}, |
{"NetW. Mode ","NetW. Mode ","NetW. Mode ","NetW. Mode "}, |
{"TX Timeout ","TX Timeout ","TX Timeout ","TX Timeout "}, |
{"TX MTU ","TX MTU ","TX MTU ","TX MTU "}, |
{"Initialisieren ","initialize ","initialiser ","Initialize "}, |
{"Konfig. mit PC ","config. with PC ","Config. avec PC ","Config. met PC "}, |
}; |
#define ITEMS_BT 5 |
prog_char param_menuitems_bt[ITEMS_BT][NUM_LANG][18]= // zeilen,zeichen+1 |
// German, English, French, Dutch |
{ |
{"Modul eingebaut? ","module built in? ","Module installé ","module geïnstall?"}, |
{"Name ","name ","Nom ","Naam "}, |
{"Pin ","pin ","Pin ","Pin "}, |
{"Initialisieren ","initialize ","initialiser ","Initialize "}, |
{"Konfig. mit PC ","config. with PC ","Config. avec PC ","Config. met PC "}, |
}; |
#define ITEMS_Accu 2 |
prog_char param_menuitems_Accu[ITEMS_Accu][NUM_LANG][18]= // zeilen,zeichen+1 |
// German, English, French, Dutch |
{ |
{"PKT-Akkutyp ","PKT-Accutyp ","PKT-Type de batt.","PKT-batterij type"}, |
{"PKT Akku Messung ","PKT AccuMeasure ","batt. de mesure ","PKT batt. meting"}, |
}; |
//-------------------------------------------------------------- |
void Show_Error_HW12(void) |
{ |
lcd_cls(); |
lcd_printp_at (0,3,PSTR(" Mit Hardware 1.x "), 2); |
lcd_printp_at (0,4,PSTR(" nicht möglich "), 2); |
_delay_ms(1000); |
} |
//-------------------------------------------------------------- |
uint8_t Edit_Int10th_Value(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
write_ndigit_number_u_10th (16, 2,Value, 3, 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Value < max)) |
{ |
edit = 1; |
Value++; |
write_ndigit_number_u_10th (16, 2,Value, 3, 0); |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Value > min)) |
{ |
edit = 1; |
Value--; |
write_ndigit_number_u_10th (16, 2,Value, 3, 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
return Value; |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_Int_Value(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
Pre = Value; |
write_ndigit_number_u (16, 2, Value, 3, 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max)) |
{ |
edit = 1; |
Value++; |
write_ndigit_number_u (16, 2,Value, 3, 0); |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min)) |
{ |
edit = 1; |
Value--; |
write_ndigit_number_u (16, 2,Value, 3, 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
return Value; |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
} |
#if defined HWVERSION3_9 ||HWVERSION1_3W |
//-------------------------------------------------------------- |
uint8_t ChangeWi_SV2(uint8_t Value) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 1, PSTR("Verbinde das PKT mit"), 0); |
// lcd_printp_at (0, 2, PSTR("dem MK über:"), 0); |
lcd_puts_at(0, 1, strGet(CONNECT1), 0); |
lcd_puts_at(0, 2, strGet(CONNECT2), 0); |
if(UseWi == false) |
{ |
// lcd_printp_at (0, 0, PSTR("Verbinde das PKT mit "), 0); |
// lcd_printp_at (0, 1, PSTR("dem MK über: Kabel, "), 0); |
// lcd_printp_at (0, 2, PSTR("da kein Wi.232 Modul "), 0); |
// lcd_printp_at (0, 3, PSTR("eingebaut ist. "), 0); |
// lcd_printp_at (0, 4, PSTR("Wenn doch, dann bitte"), 0); |
// lcd_printp_at (0, 5, PSTR("das Modul zuerst im "), 0); |
// lcd_printp_at (0, 6, PSTR("Setupmenü aktivieren."), 0); |
lcd_puts_at(0, 1, strGet(CONNECT1), 0); |
lcd_puts_at(0, 2, strGet(CONNECT4), 0); |
lcd_puts_at(0, 1, strGet(CONNECT5), 0); |
lcd_puts_at(0, 2, strGet(CONNECT6), 0); |
lcd_puts_at(0, 1, strGet(CONNECT7), 0); |
lcd_puts_at(0, 2, strGet(CONNECT8), 0); |
lcd_puts_at(0, 1, strGet(CONNECT9), 0); |
// lcd_printp_at (12, 7, PSTR("Ende"), 0); |
lcd_puts_at(12, 7, strGet(ENDE), 0); |
while (!get_key_press (1 << KEY_ESC)); |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
else |
{ |
switch (Value) |
{ |
case 0x0 :lcd_printp_at (14, 2, PSTR("Wi232"), 0); |
break; |
case 0x1 : lcd_puts_at(14, 2, strGet(KABEL), 0); |
//lcd_printp_at (14, 2, PSTR("Kabel"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if(UseWi == true) |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
edit = 1; |
Value = 1; |
// lcd_printp_at (14, 2, PSTR("Kabel"), 0); |
lcd_puts_at(14, 2, strGet(KABEL), 0); |
Change_Output(Uart02FC); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1)) |
{ |
edit = 1; |
Value = 0; |
lcd_printp_at (14, 2, PSTR("Wi232"), 0); |
Change_Output(Uart02Wi); |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
// lcd_printp_at (0, 4, PSTR("Sie müssen das PKT"), 0); |
// lcd_printp_at (0, 5, PSTR("jetzt neu starten!"), 0); |
lcd_puts_at(0, 4, strGet(CONNECT10), 0); |
lcd_puts_at(0, 5, strGet(CONNECT11), 0); |
lcd_cls_line (0, 7, 18); |
while (!get_key_press (1 << KEY_ENTER)); |
return Value; |
} |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
} |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
#endif |
//-------------------------------------------------------------- |
uint8_t Edit_Wi_NetMode_Value(uint8_t Value) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2, PSTR("Wi NetW. Mode:"), 0); |
lcd_puts_at(0, 2, strGet(WINETWM), 0); |
switch (Value) |
{ |
case 0x0 :lcd_puts_at(15, 2, strGet(SLAVE), 0);//lcd_printp_at (15, 2, PSTR("Slave "), 0); |
break; |
case 0x1 :lcd_puts_at(15, 2, strGet(NORMAL), 0);//lcd_printp_at (15, 2, PSTR("Normal"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
edit = 1; |
Value = NetMode_Normal; |
// lcd_printp_at (15, 2, PSTR("Normal"), 0); |
lcd_puts_at(15, 2, strGet(NORMAL), 0); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1)) |
{ |
edit = 1; |
Value = NetMode_Slave; |
// lcd_printp_at (15, 2, PSTR("Slave "), 0); |
lcd_puts_at(15, 2, strGet(SLAVE), 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
return Value; |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_StartInfo(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2,Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
switch (Value) |
{ |
case false :lcd_puts_at(17, 2, strGet(OFF), 0);//lcd_printp_at (17, 2, PSTR("Aus"), 0); |
break; |
case true :lcd_puts_at(17, 2, strGet(ON), 0);//cd_printp_at (17, 2, PSTR("Ein"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
Value = 1; |
// lcd_printp_at (17, 2, PSTR("Ein"), 0); |
lcd_puts_at(17, 2, strGet(ON), 0); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1)) |
{ |
Value = 0; |
// lcd_printp_at (17, 2, PSTR("Aus"), 0); |
lcd_puts_at(17, 2, strGet(OFF), 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
PKT_StartInfo = Value; |
WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
PKT_StartInfo = Pre; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_YesNo(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2,Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
switch (Value) |
{ |
case false :lcd_puts_at(17, 2, strGet(NOO), 0);//lcd_printp_at (17, 2, PSTR("Aus"), 0); |
break; |
case true :lcd_puts_at(17, 2, strGet(YES), 0);//cd_printp_at (17, 2, PSTR("Ein"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
Value = 1; |
// lcd_printp_at (17, 2, PSTR("Ein"), 0); |
lcd_puts_at(17, 2, strGet(YES), 0); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1)) |
{ |
Value = 0; |
// lcd_printp_at (17, 2, PSTR("Aus"), 0); |
lcd_puts_at(17, 2, strGet(NOO), 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
// PKT_StartInfo = Value; |
// WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
// PKT_StartInfo = Pre; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
//uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,const char *Text) |
uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2,strGet(Text), 0); |
switch (Value) |
{ |
case |
0x0 : lcd_puts_at(10, 2, strGet(DEUTSCH), 0);//lcd_printp_at (14, 2, PSTR("Deutsch"), 0); |
break; |
case 0x1 : lcd_puts_at(10, 2, strGet(ENGLISCH), 0);//lcd_printp_at (14, 2, PSTR("English"), 0); |
break; |
case 0x2 : lcd_puts_at(10, 2, strGet(FRANCE), 0);//lcd_printp_at (14, 2, PSTR("France "), 0); |
break; |
case 0x3 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value < max)) |
{ |
edit = 1; |
Value++; |
//DisplayLanguage = Value; |
switch (Value) |
{ |
case 0x0 : lcd_puts_at(10, 2, strGet(DEUTSCH), 0);//lcd_printp_at (14, 2, PSTR("Deutsch"), 0); |
break; |
case 0x1 : lcd_puts_at(10, 2, strGet(ENGLISCH), 0);//lcd_printp_at (14, 2, PSTR("English"), 0); |
break; |
case 0x2 : lcd_puts_at(10, 2, strGet(FRANCE), 0);//lcd_printp_at (14, 2, PSTR("France "), 0); |
break; |
case 0x3 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0); |
break; |
break; |
} |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value > min)) |
{ |
edit = 1; |
Value--; |
//DisplayLanguage = Value; |
switch (Value) |
{ |
case 0x0 : lcd_puts_at(10, 2, strGet(DEUTSCH), 0);//lcd_printp_at (14, 2, PSTR("Deutsch"), 0); |
break; |
case 0x1 : lcd_puts_at(10, 2, strGet(ENGLISCH), 0);//lcd_printp_at (14, 2, PSTR("English"), 0); |
break; |
case 0x2 : lcd_puts_at(10, 2, strGet(FRANCE), 0);//lcd_printp_at (14, 2, PSTR("France "), 0); |
break; |
case 0x3 : lcd_puts_at(10, 2, strGet(NETHERL), 0);//lcd_printp_at (14, 2, PSTR("Netherl"), 0); |
break; |
break; |
} |
} |
if (get_key_press (1 << KEY_ENTER)) |
return Value; |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_Orientation(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
switch (Value) |
{ |
case 0x0 :lcd_puts_at(14, 2, strGet(NORMAL), 0);//lcd_printp_at (14, 2, PSTR("Normal "), 0); |
break; |
case 0x4 :lcd_puts_at(14, 2, strGet(REVERSE), 0);//lcd_printp_at (14, 2, PSTR("Reverse"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
Value=4; |
// lcd_printp_at (14, 2, PSTR("Reverse"), 0); |
lcd_puts_at(14, 2, strGet(REVERSE), 0); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 4)) |
{ |
Value = 0; |
// lcd_printp_at (14, 2, PSTR("Normal "), 0); |
lcd_puts_at(14, 2, strGet(NORMAL), 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
cli(); |
clr_A0 (); |
if (Value == 0) |
{ |
send_byte (0xA1); // normal |
send_byte (0xC0); // normal |
} |
else |
{ |
send_byte (0xA0); // reverse |
send_byte (0xC8); // reverse |
} |
set_A0 (); |
sei(); |
LCD_Orientation = Value; |
WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_DisplayMode(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
//lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
switch (Value) |
{ |
case 0x0 :lcd_puts_at(14, 2, strGet(NORMAL), 0);//lcd_printp_at (14, 2, PSTR("Normal "), 0); |
break; |
case 0x4 :lcd_puts_at(14, 2, strGet(REVERSE), 0);//lcd_printp_at (14, 2, PSTR("Reverse"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
Value=4; |
// lcd_printp_at (14, 2, PSTR("Inverse"), 0); |
lcd_puts_at(14, 2, strGet(REVERSE), 0); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 4)) |
{ |
Value=0; |
// lcd_printp_at (14, 2, PSTR("Normal "), 0); |
lcd_puts_at(14, 2, strGet(NORMAL), 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
cli(); |
clr_A0 (); |
if (Value == 0) |
send_byte (0xA6); // normal |
else |
send_byte (0xA7); // inverse |
set_A0 (); |
sei(); |
LCD_DisplayMode = Value; |
WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
LCD_DisplayMode = Pre; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_DisplayKontrast(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
write_ndigit_number_u (16, 2, Value, 3, 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
write_ndigit_number_u (16, 2,Value, 3, 0); |
lcd_frect ((8*0), (8*4), (Value * (16*8) / 64), 6, 1); |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max)) |
{ |
Value++; |
if (Value >= max) |
{ |
Value = max; |
BeepTime = 200; |
BeepMuster = 0x0080; |
} |
else |
{ |
cli(); |
clr_A0 (); |
send_byte (0x81); |
send_byte (Value); // Daten zum LCD senden |
set_A0 (); |
sei(); |
} |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min)) |
{ |
lcd_frect (((Value - 1) * (16*8) / 64), (8*4), (16*8), 6, 0); |
Value--; |
if (Value == min) |
{ |
Value = min; |
BeepTime = 200; |
BeepMuster = 0x0080; |
} |
else |
{ |
// edit = 1; |
cli(); |
clr_A0 (); |
send_byte (0x81); |
send_byte (Value); // Daten zum LCD senden |
set_A0 (); |
sei(); |
} |
} |
write_ndigit_number_u (16, 2,Value, 3, 0); |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
LCD_Kontrast = Value; |
WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
cli(); |
clr_A0 (); |
send_byte (0x81); |
send_byte (Pre); // Daten zum LCD senden |
set_A0 (); |
sei(); |
edit = 0; |
LCD_Kontrast = Pre; |
WriteParameter(); |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_DisplayHelligkeit(uint8_t Value, uint8_t min, uint8_t max, uint8_t Text) |
{ |
float ValCorr = 2.55; // (Value * ValCorr) maximal 255 |
Pre = Value; |
OCR2A = Value * ValCorr; |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(Text), 0); |
write_ndigit_number_u (16, 2, Value, 3, 0); |
lcd_printp_at (17, 2, PSTR("%"), 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
write_ndigit_number_u (16, 2,Value, 3, 0); |
lcd_frect ((8*0), (8*4), (Value * (16*8) / 100), 6, 1); |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) && (Value < max)) |
{ |
Value++; |
if (Value >= max) |
{ |
Value = max; |
BeepTime = 200; |
BeepMuster = 0x0080; |
} |
else |
OCR2A = Value * ValCorr; |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 3)) && (Value > min)) |
{ |
lcd_frect (((Value - 1) * (16*8) / 100), (8*4), (16*8), 6, 0); |
Value--; |
if (Value == min) |
{ |
Value = min; |
BeepTime = 200; |
BeepMuster = 0x0080; |
} |
else |
OCR2A = Value * ValCorr; |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
OCR2A = Value * ValCorr; |
LCD_Helligkeit = Value; |
WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
OCR2A = Pre * ValCorr; |
LCD_Helligkeit = Pre; |
WriteParameter(); |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
void Reset_EEprom(void) |
{ |
lcd_cls(); |
get_key_press(KEY_ALL); |
// lcd_printp_at (0, 2, PSTR(" EEProm wirklich"), 0); |
// lcd_printp_at (0, 3, PSTR(" löschen?"), 0); |
// lcd_printp_at (12, 7, PSTR("Ende OK"), 0); |
lcd_puts_at(0, 2, strGet(EEPROM1), 0); |
lcd_puts_at(0, 3, strGet(EEPROM2), 0); |
lcd_puts_at(12, 7, strGet(ENDOK), 0); |
do |
{ |
if (get_key_press (1 << KEY_ENTER)) |
{ |
Delete_EEPROM(); |
return; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
get_key_press(KEY_ALL); |
} |
//-------------------------------------------------------------- |
void PKT_Setup (void) |
{ |
uint8_t ii = 0; |
uint8_t Offset = 0; |
uint8_t size = 0; |
size = ITEMS_PKT; |
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
uint8_t val; |
lcd_cls (); |
mmode = 0; |
edit= 0; |
val = 0; |
while(1) |
{ |
lcd_cls (); |
lcd_printp_at (0, 0, PSTR(" PKT-Setup "), 2); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(1) |
{ |
ii = 0; |
if(Offset > 0) |
lcd_printp_at(1,1, PSTR("\x12"), 0); |
for(ii = 0;ii < 6 ; ii++) |
{ |
if((ii+Offset) < size) |
lcd_printp_at(3,ii+1,param_menuitems_pkt[ii+Offset][DisplayLanguage], 0); |
if((ii == 5)&&(ii+Offset < (size-1))) |
lcd_printp_at(1,6, PSTR("\x13"), 0); |
} |
if(dmode == 0) |
{ |
if(Offset == 0) |
{ |
if(size > 6) |
val = menu_choose2 (1, 5, target_pos,0,1); |
else |
val = menu_choose2 (1, size, target_pos,0,0); |
} |
else |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
if(dmode == 1) |
{ |
if(Offset+7 > size) |
val = menu_choose2 (2, 6, target_pos,1,0); |
else |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
if(val == 254) |
{ |
Offset++; |
dmode = 1; |
target_pos = 5; |
} |
else if(val == 253) |
{ |
Offset--; |
dmode = 0; |
target_pos = 2; |
} |
else if(val == 255) |
{ // Ende mit ESC, speichern |
if (edit == 1) |
{ |
WriteParameter(); |
return; |
} |
return; |
} |
else |
break; |
} |
target_pos = val; |
if((val + Offset) == 1) |
{ |
#ifdef HWVERSION3_9 |
U02SV2 = ChangeWi_SV2(U02SV2); |
if (edit == 1) |
PKT_Change = 1; |
#else |
Show_Error_HW12(); |
#endif |
} |
if((val + Offset) == 2) |
MK_LowBat = Edit_Int10th_Value(MK_LowBat,33,247,LOWBAT); |
if((val + Offset) == 3) |
Display_Setup(); |
if((val + Offset) == 4) |
{ |
#if defined HWVERSION3_9 || defined HWVERSION1_2W || defined HWVERSION1_3W |
if(UseWi == false) |
// Wi_Use(); |
{ |
UseWi = Edit_YesNo(UseWi,0,1,WI2321); |
if (edit==1) |
if (UseWi== true) InitWi232(); |
} |
else |
Wi_Setup(); |
#else |
Show_Error_HW12(); |
#endif |
} |
if((val + Offset) == 5) |
{ |
#ifdef HWVERSION3_9 |
if(UseBT == 0) |
{ |
UseBT = Edit_YesNo(UseBT,0,1,BT1); |
if (edit==1) |
if (UseBT == 1) |
{ |
if (bt_init()) BTIsSet = true; else BTIsSet = false; |
WriteParameter(); |
} |
} |
else |
BT_Setup(); |
#else |
Show_Error_HW12(); |
#endif |
} |
if((val + Offset) == 6) |
#ifdef HWVERSION3_9 |
Accu_Setup(); |
#else |
Show_Error_HW12(); |
#endif |
if((val + Offset) == 7) |
Update_PKT(); |
if((val + Offset) == 8) |
Debug = Edit_Int_Value(Debug,0,1,DEBUGPKT); |
if((val + Offset) == 9) |
Reset_EEprom(); |
} |
} |
//-------------------------------------------------------------- |
void Display_Setup (void) |
{ |
uint8_t ii = 0; |
uint8_t Offset = 0; |
uint8_t size = 0; |
size = ITEMS_LCD; |
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
uint8_t val; |
lcd_cls (); |
mmode = 0; |
edit= 0; |
LCD_Change = 0; |
val = 0; |
while(1) |
{ |
lcd_cls (); |
// lcd_printp_at (0, 0, PSTR(" Display Setup "), 2); |
lcd_puts_at(0, 0, strGet(DISPLAY1), 2); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(1) |
{ |
ii = 0; |
if(Offset > 0) |
lcd_printp_at(1, 1, PSTR("\x12"), 0); |
for(ii = 0; ii < 6 ; ii++) |
{ |
if((ii + Offset) < size) |
lcd_printp_at(3, ii + 1, param_menuitems_lcd[ii + Offset][DisplayLanguage], 0); |
if((ii == 5)&&(ii+Offset < (size - 1))) |
lcd_printp_at(1,6, PSTR("\x13"), 0); |
} |
if(dmode == 0) |
{ |
if(Offset == 0) |
{ |
if(size > 6) |
val = menu_choose2 (1, 5, target_pos,0,1); |
else |
val = menu_choose2 (1, size, target_pos,0,0); |
} |
else |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
if(dmode == 1) |
{ |
if(Offset + 7 > size) |
val = menu_choose2 (2, 6, target_pos,1,0); |
else |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
if(val == 254) |
{ |
Offset++; |
dmode = 1; |
target_pos = 5; |
} |
else if(val == 253) |
{ |
Offset--; |
dmode = 0; |
target_pos = 2; |
} |
else if(val == 255) |
{ // Ende mit ESC, speichern |
if (edit == 1) |
{ |
WriteParameter(); |
return; |
} |
return; |
} |
else |
break; |
} |
target_pos = val; |
if((val + Offset) == 1) |
PKT_StartInfo = Edit_StartInfo(PKT_StartInfo,0,2,DISPLAY2); |
if((val + Offset) == 2) |
DisplayLanguage = Edit_Language(DisplayLanguage,0,3,DISPLAY3); |
// Edit_Language(DisplayLanguage,0,3,DISPLAY3); |
if((val + Offset) == 3) |
DisplayTimeout = Edit_Int_Value(DisplayTimeout,0,254,DISPLAY4); |
if((val + Offset) == 4) |
LCD_Helligkeit = Edit_DisplayHelligkeit(LCD_Helligkeit,0,100,DISPLAY5); |
if (edit == 1) |
if(!LCD_Change) |
LCD_Change =1; |
if((val + Offset) == 5) |
LCD_Kontrast = Edit_DisplayKontrast(LCD_Kontrast,0,63,DISPLAY6); |
if (edit == 1) |
if(!LCD_Change) |
LCD_Change =1; |
if((val + Offset) == 6) |
{ |
LCD_DisplayMode = Edit_DisplayMode(LCD_DisplayMode,0,4,DISPLAY7); |
if (edit == 1) |
if(!LCD_Change) |
LCD_Change =1; |
} |
if((val + Offset) == 7) |
{ |
LCD_Orientation = Edit_Orientation(LCD_Orientation,0,4,DISPLAY8); |
if (edit == 1) |
if(!LCD_Change) |
LCD_Change =1; |
} |
} |
} |
#if defined HWVERSION3_9 ||HWVERSION1_3W |
////-------------------------------------------------------------- |
//void Wi_Use (void) |
//{ |
// Pre = UseWi; |
// |
// lcd_cls (); |
// |
// lcd_cls (); |
//// lcd_printp_at (0, 0, PSTR(" Wi.232 Setup "), 2); |
//// lcd_printp_at (0, 2, PSTR("Ist ein Wi.232-Modul "), 0); |
//// lcd_printp_at (0, 4, PSTR("eingebaut?"), 0); |
// lcd_puts_at(0, 0, strGet(WI2321), 2); |
// lcd_puts_at(0, 2, strGet(WI2322), 0); |
// lcd_puts_at(0, 4, strGet(WI2323), 0); |
//// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
// lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
// |
// while(1) |
// { |
// if(UseWi == false) |
//// lcd_printp_at (12, 4, PSTR("Nein"), 0); |
// lcd_puts_at(12, 4, strGet(NOO), 0); |
// else |
// //lcd_printp_at (12, 4, PSTR("Ja "), 0); |
// lcd_puts_at(12, 4, strGet(YES), 0); |
// |
// if(get_key_press (1 << KEY_MINUS)) |
// { |
// UseWi = false; |
// edit = 1; |
// } |
// |
// if(get_key_press (1 << KEY_PLUS)) |
// { |
// UseWi = true; |
// edit = 1; |
// } |
// |
// if(get_key_short (1 << KEY_ENTER)) |
// { |
//// WiIsSet = false; |
//// WriteParameter(); |
//// if(UseWi == true) |
//// Wi_Setup(); |
// return; |
// } |
// |
// if (get_key_press (1 << KEY_ESC)) |
// { |
// get_key_press(KEY_ALL); |
// UseWi = Pre; |
// return; |
// } |
// } |
//} |
//-------------------------------------------------------------- |
void Wi_Setup (void) |
{ |
uint8_t ii = 0; |
uint8_t Offset = 0; |
uint8_t size = 0; |
size = ITEMS_WI; |
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
uint8_t val = 0; |
mmode = 0; |
edit = 0; |
// WiIsSet = true; |
lcd_cls (); |
while(1) |
{ |
lcd_cls (); |
lcd_printp_at (0, 0, PSTR(" Wi.232 Setup "), 2); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(1) |
{ |
ii = 0; |
if(Offset > 0) |
lcd_printp_at(1, 1, PSTR("\x12"), 0); |
for(ii = 0; ii < 6; ii++) |
{ |
if((ii + Offset) < size) |
lcd_printp_at(3, ii+1, param_menuitems_wi[ii+Offset][DisplayLanguage], 0); |
if((ii == 5)&&(ii + Offset < (size - 1))) |
lcd_printp_at(1, 6, PSTR("\x13"), 0); |
} |
if(dmode == 0) |
{ |
if(Offset == 0) |
{ |
if(size > 6) |
val = menu_choose2 (1, 5, target_pos,0,1); |
else |
val = menu_choose2 (1, size, target_pos,0,0); |
} |
else |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
if(dmode == 1) |
{ |
if(Offset + 7 > size) |
val = menu_choose2 (2, 6, target_pos, 1, 0); |
else |
val = menu_choose2 (2, 5, target_pos, 1, 1); |
} |
if(val == 254) |
{ |
Offset++; |
dmode = 1; |
target_pos = 5; |
} |
else if(val == 253) |
{ |
Offset--; |
dmode = 0; |
target_pos = 2; |
} |
else if(val == 255) |
{ // Ende mit ESC, speichern |
// if (edit == 1) |
// { |
// if (UseWi==true) InitWi232(); |
// WriteParameter(); |
// } |
return; |
} |
else |
if (edit == 1) |
{ |
if (UseWi==true) InitWi232(); |
WriteParameter(); |
} |
break; |
} |
target_pos = val; |
if((val + Offset) == 1) |
{ |
UseWi = Edit_YesNo(UseWi,0,1,WI2321); |
} |
if((val + Offset) == 2) |
{ |
WiTXRXChannel = Edit_Int_Value(WiTXRXChannel, 0, 5,WINETWG); |
} |
if((val + Offset) == 3) |
{ |
WiNetworkGroup = Edit_Int_Value(WiNetworkGroup, 0, 127, WINETWG); |
} |
if((val + Offset) == 4) |
{ |
WiNetworkMode = Edit_Wi_NetMode_Value(WiNetworkMode); |
} |
if((val + Offset) == 5) |
{ |
WiTXTO = Edit_Int_Value(WiTXTO,0,127,WITIMEOUT); |
} |
if((val + Offset) == 6) |
{ |
WiUartMTU = Edit_Int_Value(WiUartMTU,0,127,WIUART); |
} |
if((val + Offset) == 7) |
InitWi232(); |
if((val + Offset) == 8) |
Port_USB2CFG_Wi(); |
} |
} |
#endif |
#ifdef HWVERSION3_9 |
//-------------------------------------------------------------- |
// |
uint8_t Edit_String(const char *data, const uint8_t length, uint8_t type, const char *Text) |
{ |
uint8_t y = 1; |
uint8_t x = 1; |
uint8_t I = 0; |
lcd_cls(); |
lcd_printp_at (0, 0, Text, 2); |
for (uint8_t i = 0; i < length; i++) |
{ |
lcd_putc (y++, 3, data[i], 0); |
lcd_printp_at (y++, 3, PSTR(" "), 0); |
EditString[i] = data[i]; |
} |
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1); |
lcd_printp_at (0, 6, PSTR(" C"), 0); |
lcd_printp_at (0, 7, PSTR(" \x17 \x16 \x19 OK"), 0); |
do |
{ |
if (type == 1) // Name |
{ |
for (uint8_t i = bt_name_length; i > 0; i--) |
{ |
if (EditString[i - 1] != ' ') |
{ |
bt_name_len = i; |
break; |
} |
} |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && EditString[I] < 'z') |
{ |
EditString[I]++; |
if (EditString[I] >= 0x00 && EditString[I] < ' ') |
EditString[I] = ' '; |
if (EditString[I] > ' ' && EditString[I] < '0') |
EditString[I] = '0'; |
if (EditString[I] > '9' && EditString[I] < 'A') |
EditString[I] = 'A'; |
if (EditString[I] > 'Z' && EditString[I] < 'a') |
EditString[I] = 'a'; |
lcd_putc (x, 3, EditString[I], 0); |
edit = 1; |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && EditString[I] > ' ') |
{ |
EditString[I]--; |
if (EditString[I] < 'a' && EditString[I] > 'Z') |
EditString[I] = 'Z'; |
if (EditString[I] < 'A' && EditString[I] > '9') |
EditString[I] = '9'; |
if (EditString[I] < '0' && EditString[I] > ' ') |
EditString[I] = ' '; |
lcd_putc (x, 3, EditString[I], 0); |
edit = 1; |
} |
} |
else if (type == 2) // PIN |
{ |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 1)) && (EditString[I] < '9')) |
{ |
EditString[I]++; |
lcd_putc (x, 3, EditString[I], 0); |
edit = 1; |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 1)) && (EditString[I] > '0')) |
{ |
EditString[I]--; |
lcd_putc (x, 3, EditString[I], 0); |
edit = 1; |
} |
} |
if (get_key_long (1 << KEY_ESC)) |
{ |
EditString[I] = ' '; // Zeichen l�schen |
lcd_putc (x, 3, EditString[I], 0); |
edit = 1; |
} |
if (get_key_short (1 << KEY_ESC)) |
{ |
if ((x / 2) + 2 > bt_name_length) |
{ |
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 0); |
x = 1; |
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1); |
I = 0; |
} |
else |
{ |
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 0); |
x++; |
x++; |
lcd_rect ((x*6)-3, (8*3)-2, 10, 10, 1); |
I++; //Zeiger auf Zeichen |
} |
} |
} |
while (!get_key_press (1 << KEY_ENTER)); |
{ |
get_key_press(KEY_ALL); |
return 1; |
} |
} |
////-------------------------------------------------------------- |
//void BT_Use (void) |
//{ |
// Pre = UseBT; |
// |
// lcd_cls (); |
// |
// lcd_cls (); |
//// lcd_printp_at (0, 0, PSTR(" BTM-222 Setup "), 2); |
//// lcd_printp_at (0, 2, PSTR("Ist ein BTM-222-Modul"), 0); |
//// lcd_printp_at (0, 4, PSTR("eingebaut?"), 0); |
// lcd_puts_at(0, 0, strGet(BT1), 2); |
// lcd_puts_at(0, 2, strGet(BT2), 0); |
// lcd_puts_at(0, 4, strGet(BT3), 0); |
//// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
// lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
// |
// while(1) |
// { |
// if(UseBT == false) |
//// lcd_printp_at (12, 4, PSTR("Nein"), 0); |
// lcd_puts_at(12, 4, strGet(NOO), 0); |
// else |
//// lcd_printp_at (12, 4, PSTR("Ja "), 0); |
// lcd_puts_at(12, 4, strGet(YES), 0); |
// if(get_key_press (1 << KEY_MINUS)) |
// UseBT = false; |
// |
// if(get_key_press (1 << KEY_PLUS)) |
// UseBT = true; |
// |
// if(get_key_short (1 << KEY_ENTER)) |
// { |
//// BTIsSet = false; |
// WriteParameter(); |
// if(UseBT == true) |
// BT_Setup(); |
// return; |
// } |
// |
// if (get_key_press (1 << KEY_ESC)) |
// { |
// get_key_press(KEY_ALL); |
// UseBT = Pre; |
// return; |
// } |
// } |
//} |
//-------------------------------------------------------------- |
// |
void BT_Setup (void) |
{ |
uint8_t ii = 0; |
uint8_t Offset = 0; |
uint8_t size = 0; |
size = ITEMS_BT; |
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
uint8_t val; |
char string[20]; |
mmode = 0; |
edit = 0; |
val = 0; |
// BTIsSet = true; |
lcd_cls (); |
while(1) |
{ |
lcd_cls (); |
// lcd_printp_at (0, 0, PSTR(" BTM-222 Setup "), 2); |
lcd_puts_at(0, 0, strGet(BT1), 2); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(1) |
{ |
ii = 0; |
if(Offset > 0) |
lcd_printp_at(1,1, PSTR("\x12"), 0); |
for(ii = 0; ii < 6; ii++) |
{ |
if((ii + Offset) < size) |
lcd_printp_at(3, ii + 1, param_menuitems_bt[ii+Offset][DisplayLanguage], 0); |
if((ii == 5) && (ii + Offset < (size - 1))) |
lcd_printp_at(1,6, PSTR("\x13"), 0); |
} |
if(dmode == 0) |
{ |
if(Offset == 0) |
{ |
if(size > 6) |
val = menu_choose2 (1, 5, target_pos, 0, 1); |
else |
val = menu_choose2 (1, size, target_pos, 0, 0); |
} |
else |
val = menu_choose2 (2, 5, target_pos, 1, 1); |
} |
if(dmode == 1) |
{ |
if(Offset + 7 > size) |
val = menu_choose2 (2, 6, target_pos, 1, 0); |
else |
val = menu_choose2 (2, 5, target_pos, 1, 1); |
} |
if(val == 254) |
{ |
Offset++; |
dmode = 1; |
target_pos = 5; |
} |
else if(val == 253) |
{ |
Offset--; |
dmode = 0; |
target_pos = 2; |
} |
else if(val == 255) |
{ // Ende mit ESC, speichern |
// if (edit == 1) |
// { |
// if (UseBT == 1); |
// if (bt_init()) BTIsSet = true; else BTIsSet = false; |
// WriteParameter(); |
// return; |
// } |
return; |
} |
else |
if (edit == 1) |
{ |
if (UseBT == 1); |
if (bt_init()) BTIsSet = true; else BTIsSet = false; |
WriteParameter(); |
return; |
} |
break; |
} |
target_pos = val; |
if((val + Offset) == 1) |
// BT_Use(); |
UseBT = Edit_YesNo(UseBT,0,1,BT1); |
if((val + Offset) == 2) |
{ |
for (uint8_t i = 0; i < bt_name_length; i++) |
{ |
string[i] = bt_name[i]; |
} |
string[bt_name_length] = 0; |
Edit_String(string, bt_name_length, 1, PSTR(" Bluetooth Name ")); |
if (edit == 1) |
{ |
for (uint8_t i = 0; i < bt_name_len; i++) |
{ |
bt_name[i] = EditString[i]; |
WriteParameter(); |
} |
if (bt_name_len < 10) |
{ |
for (uint8_t i = bt_name_len; i < 10; i++) |
{ |
bt_name[i] = ' '; |
WriteParameter(); |
} |
} |
} |
} |
if((val + Offset) == 3) |
{ |
for (uint8_t i = 0; i < bt_pin_length; i++) |
{ |
string[i] = bt_pin[i]; |
} |
string[bt_pin_length] = 0; |
Edit_String(string, bt_pin_length, 2, PSTR(" Bluetooth Pin ")); |
if (edit == 1) |
{ |
for (uint8_t i = 0; i < bt_pin_length; i++) |
{ |
bt_pin[i] = EditString[i]; |
WriteParameter(); |
} |
} |
} |
if((val + Offset) == 4) |
{ |
// if (edit == 1) |
// if(BTIsSet) |
// BTIsSet = false; |
if (bt_init() == true) |
{ |
lcd_printp_at (0, 3, PSTR("BT Init ok"), 0); |
WriteBTInitFlag(); |
} |
else |
{ |
lcd_printp_at (0, 3, PSTR("BT Init Error"), 0); |
BTIsSet = false; |
BeepTime = 1000; |
BeepMuster = 0x0040; |
} |
} |
if((val + Offset) == 5) |
Port_FC2CFG_BT(); |
} |
} |
//-------------------------------------------------------------- |
uint8_t Edit_PKT_Accu(uint8_t Value, uint8_t min, uint8_t max) |
{ |
Pre = Value; |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(LIPO2), 0); |
switch (Value) |
{ |
case false :lcd_printp_at (15, 2, PSTR("LiIo"), 0); |
break; |
case true :lcd_printp_at (15, 2, PSTR("LiPo"), 0); |
break; |
break; |
} |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS)) && (Value == 0)) |
{ |
Value = 1; |
lcd_printp_at (15, 2, PSTR("LiPo"), 0); |
} |
if ((get_key_press (1 << KEY_MINUS)) && (Value == 1)) |
{ |
Value = 0; |
lcd_printp_at (15, 2, PSTR("LiIo"), 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
{ |
edit = 1; |
PKT_Accutyp = Value; |
// WriteParameter(); |
return Value; |
} |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
PKT_Accutyp = Pre; |
return Pre; |
} |
} |
//-------------------------------------------------------------- |
uint16_t Edit_LipoOffset(uint16_t Value, uint16_t min, uint16_t max) |
{ |
lcd_cls(); |
// lcd_printp_at (0, 2, Text, 0); |
lcd_puts_at(0, 2, strGet(LIPO3), 0); |
lcd_puts_at(0, 5, strGet(LIPO5), 0); |
lcd_puts_at(0, 6, strGet(LIPO6), 0); |
// lcd_printp_at (0, 3, PSTR("Offset verstellen bis"), 0); |
// lcd_printp_at (0, 4, PSTR("die Spannung passt"), 0); |
Pre16 = Value; |
write_ndigit_number_u (16, 2, Value, 4, 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_2), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE2), 0); |
do |
{ |
if ((get_key_press (1 << KEY_PLUS) || get_key_long_rpt_sp ((1 << KEY_PLUS), 2)) && (Value < max-10)) |
{ |
edit = 1; |
Value = Value +10; |
Lipo_UOffset = Value; |
write_ndigit_number_u (16, 2,Value, 4, 0); |
} |
if ((get_key_press (1 << KEY_MINUS) || get_key_long_rpt_sp ((1 << KEY_MINUS), 2)) && (Value > min)) |
{ |
edit = 1; |
Value=Value -10; |
Lipo_UOffset = Value; |
write_ndigit_number_u (16, 2,Value, 4, 0); |
} |
if (get_key_press (1 << KEY_ENTER)) |
return Value; |
show_Lipo(); |
write_ndigit_number_u_100th(8, 3, volt_avg, 0, 0); |
lcd_printp_at(3, 3, PSTR("Volt"), 0); |
} |
while (!get_key_press (1 << KEY_ESC)); |
{ |
get_key_press(KEY_ALL); |
edit = 0; |
Lipo_UOffset = Pre16; |
return Pre16; |
} |
} |
//-------------------------------------------------------------- |
void Accu_Setup (void) |
{ |
uint8_t ii = 0; |
uint8_t Offset = 0; |
uint8_t size = 0; |
size = ITEMS_Accu; |
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
uint8_t val; |
mmode = 0; |
edit = 0; |
val = 0; |
lcd_cls (); |
while(1) |
{ |
lcd_cls (); |
// lcd_printp_at (0, 0, PSTR(" PKT Accu Setup "), 2); |
lcd_puts_at(0, 0, strGet(LIPO1), 2); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(1) |
{ |
ii = 0; |
if(Offset > 0) |
lcd_printp_at(1,1, PSTR("\x12"), 0); |
for(ii = 0; ii < 6; ii++) |
{ |
if((ii + Offset) < size) |
lcd_printp_at(3, ii + 1, param_menuitems_Accu[ii+Offset][DisplayLanguage], 0); |
if((ii == 5) && (ii + Offset < (size - 1))) |
lcd_printp_at(1,6, PSTR("\x13"), 0); |
} |
if(dmode == 0) |
{ |
if(Offset == 0) |
{ |
if(size > 6) |
val = menu_choose2 (1, 5, target_pos, 0, 1); |
else |
val = menu_choose2 (1, size, target_pos, 0, 0); |
} |
else |
val = menu_choose2 (2, 5, target_pos, 1, 1); |
} |
if(dmode == 1) |
{ |
if(Offset + 7 > size) |
val = menu_choose2 (2, 6, target_pos, 1, 0); |
else |
val = menu_choose2 (2, 5, target_pos, 1, 1); |
} |
if(val == 254) |
{ |
Offset++; |
dmode = 1; |
target_pos = 5; |
} |
else if(val == 253) |
{ |
Offset--; |
dmode = 0; |
target_pos = 2; |
} |
else if(val == 255) |
{ // Ende mit ESC, speichern |
if (edit == 1) |
{ |
WriteParameter(); |
return; |
} |
return; |
} |
else |
break; |
} |
target_pos = val; |
if((val + Offset) == 1) |
{ |
PKT_Accutyp= Edit_PKT_Accu(PKT_Accutyp,0,1); |
if (edit == 1) WriteParameter(); |
} |
if((val + Offset) == 2) |
{ |
Lipo_UOffset = Edit_LipoOffset(Lipo_UOffset,0,9999); |
if (edit == 1) WriteParameter(); |
} |
} |
} |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/setup.h |
---|
0,0 → 1,50 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef _setup_H |
#define _setup_H |
void PKT_Setup (void); |
void Display_Setup (void); |
void Wi_Use (void); |
void Wi_Setup (void); |
void BT_Use (void); |
void BT_Setup (void); |
void Show_Error_HW12(void); |
void Accu_Setup (void); |
uint8_t Edit_Language(uint8_t Value, uint8_t min, uint8_t max,uint8_t Text); |
extern uint8_t bt_name_len; |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/timer.c |
---|
0,0 → 1,519 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* based on the key handling by Peter Dannegger * |
* see www.mikrocontroller.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <string.h> |
#include <util/delay.h> |
#include <inttypes.h> |
#include "main.h" |
#include "timer.h" |
#include "eeprom.h" |
#include "lcd.h" |
#include "uart1.h" |
#if defined HWVERSION1_2W || defined HWVERSION1_2 |
#include "HAL_HW1_2.h" |
#endif |
#if defined HWVERSION1_3W || defined HWVERSION1_3 |
#include "HAL_HW1_3.h" |
#endif |
#ifdef HWVERSION3_9 |
#include "HAL_HW3_9.h" |
#endif |
volatile uint16_t timer; |
volatile uint16_t abo_timer; |
volatile static unsigned int tim_main; |
uint8_t key_state = 0; // debounced and inverted key state: |
// bit = 1: key pressed |
uint8_t key_press = 0; // key press detect |
uint8_t key_long = 0; // key long press |
uint8_t key_rpt = 0; // key repeat |
uint8_t key_lrpt = 0; // key long press and repeat |
uint8_t key_rpts = 0; // key long press and speed repeat |
uint8_t repeat_speed = 0; |
uint16_t DisplayTime = 0; // Leuchtdauer |
volatile uint16_t IdleTimer = 0; // InaktivitätsTimer |
uint16_t WarnCount = 0; // Zähler der LIPO Warnzeit |
uint16_t WarnToggle = 0; // Togglezähler zum blinken |
uint16_t WarnTime = 10; // Länge der LIPO Warnzeit 10 Sek. |
uint16_t PoffTime = 30; // Länge der Wartezeit vor Abschalten 30 Sek. |
//uint8_t servo = 0; |
volatile uint8_t Display_on;// Flag Display on/off |
unsigned int BeepTime = 0; |
unsigned int BeepMuster = 0xffff; |
volatile unsigned int CountMilliseconds = 0; |
// Size of Buffer for Converting unsigned int Value to ASCII |
#define STRING_BUFFER_SIZE 5 |
// Buffer for Converting unsigned int Value to ASCII |
char String_Buffer[STRING_BUFFER_SIZE]; |
//-------------------------------------------------------------- |
// |
void Timer1_Init (void) // Timer 1-A |
{ |
// löschen |
TCCR1A = 0; |
TCCR1B = 0; |
TIMSK1 = 0; |
// setzen |
TCCR1A |= (1 << COM1A1) | (1 << WGM11); |
TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM13) | (1 << WGM12); |
ICR1 = (F_CPU / 64) * 20 / 1000; |
OCR1A = 470; // ca. Servomitte |
} |
//-------------------------------------------------------------- |
void Timer2_Init (void) // Displayhelligkeit |
{ |
DDRD |= (1 << DDD7); // PD7 output |
TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1); // non invers |
TCCR2B |= (1 << CS20); // Prescaler 1/1 |
TIMSK2 |= (1 << OCIE2A) | (1 << OCIE2B); |
OCR2A = 255; |
} |
#if defined HWVERSION1_2 || defined HWVERSION1_2W |
//-------------------------------------------------------------- |
ISR(TIMER2_COMPA_vect) |
{ |
PORTD &= ~(1 << PD7); |
PORTC &= ~(1 << PC0); |
PORTC &= ~(1 << PC1); |
} |
ISR(TIMER2_COMPB_vect) |
{ |
PORTD |= (1 << PD7); |
PORTC |= (1 << PC0); |
PORTC |= (1 << PC1); |
} |
#endif |
#if defined HWVERSION1_3 || defined HWVERSION1_3W |
//-------------------------------------------------------------- |
ISR(TIMER2_COMPA_vect) |
{ |
PORTD &= ~(1 << PD7); |
PORTD &= ~(1 << PD6); |
PORTC &= ~(1 << PC2); |
} |
ISR(TIMER2_COMPB_vect) |
{ |
PORTD |= (1 << PD7); |
PORTD |= (1 << PD6); |
PORTC |= (1 << PC2); |
} |
#endif |
#ifdef HWVERSION3_9 |
//-------------------------------------------------------------- |
ISR(TIMER2_COMPA_vect) |
{ |
PORTD |= (1 << PD7); |
} |
ISR(TIMER2_COMPB_vect) |
{ |
PORTD &= ~(1 << PD7); |
} |
#endif |
//-------------------------------------------------------------- |
void Timer0_Init (void) // System (100Hz) |
{ |
timer = 0; |
TCCR0A = (1 << WGM01); |
TCCR0B = (1 << CS02) | (1 << CS00); |
OCR0A = (F_CPU / (100L * 1024L)) ; |
TIMSK0 |= (1 << OCIE0A); // enable interrupt for OCR |
} |
//-------------------------------------------------------------- |
ISR(TIMER0_COMPA_vect) // Timer-Interrupt (100 Hz) |
{ |
static uint8_t ct0 = 0; |
static uint8_t ct1 = 0; |
static uint8_t k_time_l = 0; |
static uint8_t k_time_r = 0; |
static uint8_t k_time_lr = 0; |
static uint8_t k_time_rs = 0; |
uint8_t i; |
static unsigned char cnt_1ms = 1,cnt = 0; |
unsigned char beeper_ein = 0; |
// unsigned char pieper_ein = 0; |
// Key handling by Peter Dannegger |
// see www.mikrocontroller.net |
i = key_state ^ ~KEY_PIN; // key changed ? |
ct0 = ~(ct0 & i); // reset or count ct0 |
ct1 = ct0 ^ (ct1 & i); // reset or count ct1 |
i &= (ct0 & ct1); // count until roll over ? |
key_state ^= i; // then toggle debounced state |
key_press |= (key_state & i); // 0->1: key press detect |
if (PKT_IdleBeep == 1) |
{ |
IdleTimer ++; // nix zu tun? Timer hochzählen |
if (IdleTimer == 12000) // Warnhinweis |
{ |
BeepTime = 200; |
BeepMuster = 0x0080; |
IdleTimer = 0; |
} |
} |
if (!cnt--) |
{ |
cnt = 9; |
CountMilliseconds++; |
cnt_1ms++; |
} |
if (i!=0) |
{ // Displaylicht einschalten, und bzw. Timeoutzählerreset wenn Taste gedrückt wurde |
if (Display_on == 0) |
set_D_LIGHT(); |
Display_on = 1; // Flag Display on |
DisplayTime = 0; // Timer Reset |
IdleTimer = 0; // Idletimeout Reset |
} |
if (DisplayTimeout > 0) |
{ |
if (Display_on == 1) |
{ |
DisplayTime++; |
if ((DisplayTime / 100) == DisplayTimeout) // ISR läuft mit 100Hz |
{ // Displaylicht ausschalten |
clr_D_LIGHT(); |
Display_on = 0; // Flag Display off |
} |
} |
} |
//-------------------------------------------------------------- |
#ifdef HWVERSION3_9 |
LipoCheck(); // Lipo prüfen |
#endif |
//-------------------------------------------------------------- |
if (BeepTime) |
{ |
if (BeepTime > 10) |
BeepTime -= 10; |
else |
BeepTime = 0; |
if (BeepTime & BeepMuster) |
beeper_ein = 1; |
else |
beeper_ein = 0; |
} |
else |
{ |
beeper_ein = 0; |
BeepMuster = 0xffff; |
} |
if (beeper_ein) |
set_BEEP(); |
else |
clr_BEEP(); |
//-------------------------------------------------------------- |
if ((key_state & LONG_MASK) == 0) // check long key function |
k_time_l = REPEAT_START; // start delay |
if (--k_time_l == 0) // long countdown |
key_long |= (key_state & LONG_MASK); |
//-------------------------------------------------------------- |
if ((key_state & REPEAT_MASK) == 0) // check repeat function |
k_time_r = 1; // kein delay |
if (--k_time_r == 0) |
{ |
k_time_r = REPEAT_NEXT; // repeat delay |
key_rpt |= (key_state & REPEAT_MASK); |
} |
//-------------------------------------------------------------- |
if ((key_state & LONG_REPEAT_MASK) == 0) // check repeat function |
k_time_lr = REPEAT_START; // start delay |
if (--k_time_lr == 0) |
{ |
k_time_lr = REPEAT_NEXT; // repeat delay |
key_lrpt |= (key_state & LONG_REPEAT_MASK); |
} |
//-------------------------------------------------------------- |
if ((key_state & LONG_REPEAT_SP_MASK) == 0) // check repeatX function |
k_time_rs = REPEAT_START; // start delay |
if (--k_time_rs == 0) // repeat countdown |
{ |
if (repeat_speed == 1) |
{ |
k_time_rs = REPEAT_SPEED_1; |
key_rpts |= (key_state & LONG_REPEAT_SP_MASK); |
} |
else if (repeat_speed == 2) |
{ |
k_time_rs = REPEAT_SPEED_2; |
key_rpts |= (key_state & LONG_REPEAT_SP_MASK); |
} |
else if (repeat_speed == 3) |
{ |
k_time_rs = REPEAT_SPEED_3; |
key_rpts |= (key_state & LONG_REPEAT_SP_MASK); |
} |
} |
if (timer > 0) |
timer --; |
if (abo_timer > 0) |
abo_timer --; |
} |
//-------------------------------------------------------------- |
#ifdef HWVERSION3_9 |
void LipoCheck (void) // Lowbatpin des Spannungswandlers prüfen |
// LBO des LT1308 wechselt zum Ende der Batterielaufzeit häufig seinen Zustand in der Übergangsphase zum LowBat |
// Die Akkuspannung schwankt auch abhängig vom momentanen Stromverbrauch |
{ |
if (WarnToggle == 1) // Beim ersten Auftreten Warnung ausgeben, Rythmus 5/10 Sekunden |
{ |
BeepTime = 1000; |
BeepMuster = 0x0020; |
lcd_printp_at (0, 0, PSTR(" LIPO !!Warnung!! "), 2); |
} |
if (WarnToggle == WarnTime * 100) |
WarnToggle = 0; // erstmal bis hier warnen |
if (WarnToggle > 0) |
WarnToggle++; // weiter hochzählen |
if (PINC & (1 << LowBat)) // Kurzzeitige Unterspannung bearbeiten und Warnung ausgeben |
{ |
WarnCount = 0; |
// if (WarnCount > 0) |
// WarnCount--; // Bei LIPO OK erstmal runterzählen, LT1308 überlegt sich noch genauer ob nun ok oder nicht |
} |
if (!(PINC & (1 << LowBat)) ) // LT1308 hat Unterspannung erkannt |
{ |
WarnCount++; // solange LBO low ist Zähler hochzählen |
if (WarnCount == 10 && WarnToggle == 0) // mit "10" etwas unempfindlicher gegen kurze Impulse machen |
WarnToggle = 1; // Warnhinweis starten |
} |
if ((WarnCount) == PoffTime * 100) |
clr_V_On(); // Spannung abschalten |
} |
#endif |
//-------------------------------------------------------------- |
unsigned int SetDelay (unsigned int t) |
{ |
return(CountMilliseconds + t + 1); |
} |
//-------------------------------------------------------------- |
char CheckDelay(unsigned int t) |
{ |
return(((t - CountMilliseconds) & 0x8000) >> 9); |
} |
//-------------------------------------------------------------- |
void Delay_ms(unsigned int w) |
{ |
unsigned int akt; |
akt = SetDelay(w); |
while (!CheckDelay(akt)); |
} |
//-------------------------------------------------------------- |
// |
uint8_t get_key_press (uint8_t key_mask) |
{ |
uint8_t sreg = SREG; |
// disable all interrupts |
cli(); |
key_mask &= key_press; // read key(s) |
key_press ^= key_mask; // clear key(s) |
SREG = sreg; // restore status register |
return key_mask; |
} |
//-------------------------------------------------------------- |
// |
uint8_t get_key_short (uint8_t key_mask) |
{ |
uint8_t ret; |
uint8_t sreg = SREG; |
// disable all interrupts |
cli(); |
ret = get_key_press (~key_state & key_mask); |
SREG = sreg; // restore status register |
return ret; |
} |
//-------------------------------------------------------------- |
// |
uint8_t get_key_long (uint8_t key_mask) |
{ |
uint8_t sreg = SREG; |
// disable all interrupts |
cli(); |
key_mask &= key_long; // read key(s) |
key_long ^= key_mask; // clear key(s) |
SREG = sreg; // restore status register |
return get_key_press (get_key_rpt (key_mask)); |
} |
//-------------------------------------------------------------- |
// |
uint8_t get_key_rpt (uint8_t key_mask) |
{ |
uint8_t sreg = SREG; |
// disable all interrupts |
cli(); |
key_mask &= key_rpt; // read key(s) |
key_rpt ^= key_mask; // clear key(s) |
SREG = sreg; // restore status register |
return key_mask; |
} |
//-------------------------------------------------------------- |
// |
uint8_t get_key_long_rpt (uint8_t key_mask) |
{ |
uint8_t sreg = SREG; |
// disable all interrupts |
cli(); |
key_mask &= key_lrpt; // read key(s) |
key_lrpt ^= key_mask; // clear key(s) |
SREG = sreg; // restore status register |
return get_key_rpt (~key_press^key_mask); |
} |
//-------------------------------------------------------------- |
// |
uint8_t get_key_long_rpt_sp (uint8_t key_mask, uint8_t key_speed) |
{ |
uint8_t sreg = SREG; |
// disable all interrupts |
cli(); |
key_mask &= key_rpts; // read key(s) |
key_rpts ^= key_mask; // clear key(s) |
repeat_speed = key_speed; |
SREG = sreg; // restore status register |
return key_mask; |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/timer.h |
---|
0,0 → 1,87 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* based on the key handling by Peter Dannegger * |
* see www.mikrocontroller.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef _TIMER_H |
#define _TIMER_H |
#include "cpu.h" |
#include "main.h" |
#define KEY_ALL ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC)) |
#define LONG_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC)) |
#define REPEAT_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC)) |
#define LONG_REPEAT_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC)) |
#define LONG_REPEAT_SP_MASK ((1 << KEY_PLUS) | (1 << KEY_MINUS) | (1 << KEY_ENTER) | (1 << KEY_ESC)) |
#define REPEAT_START 70 // after 700ms |
#define REPEAT_NEXT 15 // every 150ms |
#define REPEAT_SPEED_1 20 // every 200ms |
#define REPEAT_SPEED_2 8 // every 80ms |
#define REPEAT_SPEED_3 1 // every 10ms |
#define ABO_TIMEOUT 300 // 3 sec |
extern volatile uint8_t Display_on; |
extern volatile uint16_t IdleTimer; |
extern volatile uint16_t timer; |
extern volatile uint16_t abo_timer; |
extern uint16_t WarnCount; |
//extern volatile unsigned int BeepTime; |
extern unsigned int BeepTime; |
extern unsigned int BeepMuster; |
void Timer0_Init (void); // Systeminterrupt |
void Timer1_Init (void); // Servotester |
void Timer2_Init (void); // Displayhelligkeit |
uint8_t get_key_press (uint8_t key_mask); // sofort beim drücken |
uint8_t get_key_short (uint8_t key_mask); // erst beim loslassen |
uint8_t get_key_long (uint8_t key_mask); // verzögert |
uint8_t get_key_rpt (uint8_t key_mask); // mit verzögerung |
uint8_t get_key_long_rpt (uint8_t key_mask); // |
uint8_t get_key_long_rpt_sp (uint8_t key_mask, uint8_t key_speed); // mit verzögerung und 3 versch. geschw. |
extern volatile unsigned int CountMilliseconds; |
void Delay_ms(unsigned int); |
unsigned int SetDelay (unsigned int t); |
char CheckDelay (unsigned int t); |
void LipoCheck (void); // Lowbatpin des Spannungswandlers prüfen |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/tools.c |
---|
0,0 → 1,332 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <string.h> |
#include <stdlib.h> |
#include <stdbool.h> |
#include <util/delay.h> |
#include "main.h" |
#include "setup.h" |
#include "lcd.h" |
#include "menu.h" |
#include "servo.h" |
#include "motortest.h" |
#include "eeprom.h" |
#include "timer.h" |
#include "connect.h" |
#ifdef HWVERSION3_9 |
#include "HAL_HW3_9.h" |
#endif |
#ifdef HWVERSION1_3 |
#include "HAL_HW1_3.h" |
#endif |
//#include "voltmeter.h" |
#include "lipo.h" |
#include "messages.h" |
//-------------------------------------------------------------- |
#define ITEMS_PKT 6 |
prog_char tools_menuitems_pkt[ITEMS_PKT][NUM_LANG][18]= // zeilen,zeichen+1 |
// German, English, French, Netherlands |
{ |
{"Motor Tester ","Motor Tester ","Motor Tester ","Motor Tester "}, |
{"Servo Tester ","Servo Tester ","Servo Tester ","Servo Tester "}, |
{"PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter "}, |
{"PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter "}, |
{"PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d"}, |
{"PKT Version ","PKT Version ","PKT Version ","PKT Version "}, |
}; |
//-------------------------------------------------------------- |
void PKT_Tools (void) |
{ |
uint8_t ii = 0; |
uint8_t Offset = 0; |
uint8_t size = 0; |
size = ITEMS_PKT ; |
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
uint8_t val; |
val = 0; |
while(1) |
{ |
lcd_cls (); |
lcd_printp_at (0, 0, PSTR(" PKT-Tools "), 2); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(2) |
{ |
ii = 0; |
if(Offset > 0) |
{ |
lcd_printp_at(1,1, PSTR("\x12"), 0); |
} |
for(ii = 0;ii < 6 ; ii++) |
{ |
if((ii+Offset) < size) |
{ |
lcd_printp_at(3,ii+1,tools_menuitems_pkt[ii+Offset][DisplayLanguage], 0); |
} |
if((ii == 5)&&(ii+Offset < (size-1))) |
{ |
lcd_printp_at(1,6, PSTR("\x13"), 0); |
} |
} |
if(dmode == 0) |
{ |
if(Offset == 0) |
{ |
if(size > 6) |
{ |
val = menu_choose2 (1, 5, target_pos,0,1); |
} |
else |
{ |
val = menu_choose2 (1, size, target_pos,0,0); |
} |
} |
else |
{ |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
} |
if(dmode == 1) |
{ |
if(Offset+7 > size) |
{ |
val = menu_choose2 (2, 6, target_pos,1,0); |
} |
else |
{ |
val = menu_choose2 (2, 5, target_pos,1,1); |
} |
} |
if(val == 254) |
{ |
Offset++; |
dmode = 1; |
target_pos = 5; |
} |
else if(val == 253) |
{ |
Offset--; |
dmode = 0; |
target_pos = 2; |
} |
else if(val == 255) |
{ |
return; |
} |
else |
{ |
break; |
} |
} |
target_pos = val; |
if((val+Offset) == 1 ) |
motor_test(FC_Mode); |
if((val+Offset) == 2 ) |
servo_test(); |
#ifdef HWVERSION3_9 |
if(U02SV2 == 0) |
{ |
if((val+Offset) == 3 ) |
Port_BT2Wi(); |
if((val+Offset) == 4 ) |
Port_USB2Wi(); |
} |
else if(U02SV2 == 1) |
{ |
if((val+Offset) == 3 ) |
Port_BT2FC(); |
if((val+Offset) == 4 ) |
Port_USB2FC(); |
} |
#else |
if((val+Offset) == 3 ) |
Show_Error_HW(); |
if((val+Offset) == 4 ) |
Show_Error_HW(); |
#endif |
if((val+Offset) == 5) |
PKT_Setup(); |
if((val+Offset) == 6) |
Show_Version(); |
} |
} |
//-------------------------------------------------------------- |
// |
void PC_Fast_Connect (void) |
{ |
uint8_t value = 1; |
while(1) |
{ |
lcd_cls(); |
// lcd_printp_at (0, 0, PSTR(" PC-Quick-Verbindung "), 2); |
lcd_puts_at(0, 8, strGet(TOOLS1), 2); |
lcd_printp_at (3, 3, PSTR("PC BT > Kopter"), 0); |
lcd_printp_at (3, 4, PSTR("PC USB > Kopter"), 0); |
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0); |
lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
// lcd_puts_at(0, 7, strGet(KEYLINE1), 0); |
while(2) |
{ |
if(value == 1) |
{ |
lcd_printp_at (1, 3, PSTR("\x1d"), 0); |
lcd_printp_at (1, 4, PSTR(" "), 0); |
} |
else |
{ |
lcd_printp_at (1, 3, PSTR(" "), 0); |
lcd_printp_at (1, 4, PSTR("\x1d"), 0); |
} |
if(get_key_press (1 << KEY_MINUS)) |
value = 1; |
if(get_key_press (1 << KEY_PLUS)) |
value = 2; |
if(get_key_short (1 << KEY_ENTER)) |
{ |
#ifdef HWVERSION3_9 |
if(U02SV2 == 0) |
{ |
if(value == 1) |
Port_BT2Wi(); |
if(value == 2) |
Port_USB2Wi(); |
} |
else if(U02SV2 == 1) |
{ |
if(value == 1) |
Port_BT2FC(); |
if(value == 2) |
Port_USB2FC(); |
} |
#else |
if(value == 1) |
Show_Error_HW(); |
if(value == 2) |
Show_Error_HW(); |
#endif |
break; |
} |
if(get_key_press (1 << KEY_ESC)) |
{ |
get_key_press(KEY_ALL); |
return; |
} |
} |
} |
} |
void Test_HB (void) // bleibt für Tests |
{ |
// ADC_Init(); |
// |
// uint16_t volt_avg = 0; |
//// uint64_t volt_tmp = 0; |
// uint16_t Balken = 0; |
lcd_cls(); |
lcd_printp_at(12, 7, PSTR("Ende"), 0); |
// lcd_rect(104, 0, 23, 8, 1); // Rahmen |
do |
{ |
// |
// |
if(samples>4095) |
{ |
// write_ndigit_number_u(0, 4, accumulator, 5, 0); |
oversampled(); |
volt_avg = Vin; |
} |
// // write_ndigit_number_u(0, 3, samples, 5, 0); |
// |
//// write_ndigit_number_u(0, 1, Vin, 5, 0); |
// _delay_ms(50); |
show_Lipo(); |
write_ndigit_number_u_100th(5, 5, volt_avg, 0, 0); |
lcd_printp_at(10, 5, PSTR("Volt"), 0); |
// |
// |
// |
write_ndigit_number_u(0, 6, Lipo_UOffset, 5, 0); |
// write_ndigit_number_u(15, 6, WarnCount, 4, 0); |
//// write_ndigit_number_u(10, 5, Vcorr, 4, 0); |
if (get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 3)) |
{ |
Lipo_UOffset = Lipo_UOffset +10; |
} |
if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS),3)) |
{ |
Lipo_UOffset = Lipo_UOffset -10; |
} |
// |
} |
while(!get_key_press (1 << KEY_ESC)); |
get_key_press(KEY_ALL); |
return; |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/tools.h |
---|
0,0 → 1,41 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef _tools_H |
#define _tools_H |
void PKT_Tools (void); |
void Test_HB (void); // TestTool für Softwareentwicklung |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/twimaster.c |
---|
0,0 → 1,511 |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Copyright (c) Holger Buss, Ingo Busker |
// + Nur f?r den privaten Gebrauch |
// + www.MikroKopter.com |
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Es gilt f?r das gesamte Projekt (Hardware, Software, Bin?rfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur f?r den privaten (nicht-kommerziellen) Gebrauch zul?ssig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Best?ckung und Verkauf von Platinen oder Baus?tzen, |
// + Verkauf von Luftbildaufnahmen, usw. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder ver?ffentlicht, |
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright m?ssen dann beiliegen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
// + auf anderen Webseiten oder sonstigen Medien ver?ffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
// + eindeutig als Ursprung verlinkt werden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Keine Gew?hr auf Fehlerfreiheit, Vollst?ndigkeit oder Funktion |
// + Benutzung auf eigene Gefahr |
// + Wir ?bernehmen keinerlei Haftung f?r direkte oder indirekte Personen- oder Sachsch?den |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + mit unserer Zustimmung zul?ssig |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + this list of conditions and the following disclaimer. |
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
// + from this software without specific prior written permission. |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
// + for non-commercial use (directly or indirectly) |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + with our written permission |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <util/twi.h> |
#include <util/delay.h> |
#include "eeprom.h" |
#include "twimaster.h" |
#include "timer.h" |
volatile uint8_t twi_state = TWI_STATE_MOTOR_TX; |
volatile uint8_t dac_channel = 0; |
volatile uint8_t motor_write = 0; |
volatile uint8_t motor_read = 0; |
volatile uint8_t I2C_TransferActive = 0; |
volatile uint16_t I2CTimeout = 100; |
uint8_t MissingMotor = 0; |
uint8_t RequiredMotors = 1; |
char MotorenEin = 0; |
volatile uint8_t BLFlags = 0; |
MotorData_t Motor[MAX_MOTORS]; |
// bit mask for witch BL the configuration should be sent |
volatile uint16_t BLConfig_WriteMask = 0; |
// bit mask for witch BL the configuration should be read |
volatile uint16_t BLConfig_ReadMask = 0; |
// buffer for BL Configuration |
BLConfig_t BLConfig; |
#define I2C_WriteByte(byte) {TWDR = byte; TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);} |
#define I2C_ReceiveByte() {TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA);} |
#define I2C_ReceiveLastByte() {TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);} |
#define SCL_CLOCK 200000L |
#define I2C_TIMEOUT 30000 |
#define TWI_BASE_ADDRESS 0x52 |
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
{ |
uint8_t crc = 0xAA; |
uint16_t i; |
for(i=0; i<len; i++) |
{ |
crc += pBuffer[i]; |
} |
return crc; |
} |
//-------------------------------------------------------------- |
// Initialize I2C (TWI) |
// |
void I2C_Init(char clear) |
{ |
uint8_t i; |
uint8_t sreg = SREG; |
cli(); |
// SDA is INPUT |
DDRC &= ~(1<<DDC1); |
// SCL is output |
DDRC |= (1<<DDC0); |
// pull up SDA |
//PORTC |= (1<<PORTC0)|(1<<PORTC1); |
// TWI Status Register |
// prescaler 1 (TWPS1 = 0, TWPS0 = 0) |
TWSR &= ~((1<<TWPS1)|(1<<TWPS0)); |
// set TWI Bit Rate Register |
TWBR = ((F_CPU/SCL_CLOCK)-16)/2; |
twi_state = TWI_STATE_MOTOR_TX; |
motor_write = 0; |
motor_read = 0; |
if(clear) for(i=0; i < MAX_MOTORS; i++) |
{ |
Motor[i].Version = 0; |
Motor[i].SetPoint = 0; |
Motor[i].SetPointLowerBits = 0; |
Motor[i].State = 0; |
Motor[i].ReadMode = BL_READMODE_STATUS; |
Motor[i].Current = 0; |
Motor[i].MaxPWM = 0; |
Motor[i].Temperature = 0; |
} |
sei(); |
SREG = sreg; |
} |
//-------------------------------------------------------------- |
void I2C_Reset(void) |
{ |
// stop i2c bus |
I2C_Stop(TWI_STATE_MOTOR_TX); |
TWCR = (1<<TWINT); // reset to original state incl. interrupt flag reset |
TWAMR = 0; |
TWAR = 0; |
TWDR = 0; |
TWSR = 0; |
TWBR = 0; |
I2C_TransferActive = 0; |
I2C_Init(0); |
I2C_WriteByte(0); |
BLFlags |= BLFLAG_READ_VERSION; |
} |
//-------------------------------------------------------------- |
// I2C ISR |
// |
ISR (TWI_vect) |
{ |
static uint8_t missing_motor = 0, motor_read_temperature = 0; |
static uint8_t *pBuff = 0; |
static uint8_t BuffLen = 0; |
switch (twi_state++) |
{ |
// Master Transmit |
case 0: // TWI_STATE_MOTOR_TX |
I2C_TransferActive = 1; |
// skip motor if not used in mixer |
// while((Mixer.Motor[motor_write][MIX_GAS] <= 0) && (motor_write < MAX_MOTORS)) motor_write++; |
if(motor_write >= MAX_MOTORS) // writing finished, read now |
{ |
BLConfig_WriteMask = 0; // reset configuration bitmask |
motor_write = 0; // reset motor write counter for next cycle |
twi_state = TWI_STATE_MOTOR_RX; |
I2C_WriteByte(TWI_BASE_ADDRESS + TW_READ + (motor_read<<1) ); // select slave address in rx mode |
} |
else I2C_WriteByte(TWI_BASE_ADDRESS + TW_WRITE + (motor_write<<1) ); // select slave address in tx mode |
break; |
case 1: // Send Data to Slave |
I2C_WriteByte(Motor[motor_write].SetPoint); // transmit setpoint |
// if old version has been detected |
if(!(Motor[motor_write].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)) |
{ |
twi_state = 4; //jump over sending more data |
} |
// the new version has been detected |
else if(!( (Motor[motor_write].SetPointLowerBits && (RequiredMotors < 7)) || BLConfig_WriteMask || BLConfig_ReadMask ) ) |
{ // or LowerBits are zero and no BlConfig should be sent (saves round trip time) |
twi_state = 4; //jump over sending more data |
} |
break; |
case 2: // lower bits of setpoint (higher resolution) |
if ((0x0001<<motor_write) & BLConfig_ReadMask) |
{ |
Motor[motor_write].ReadMode = BL_READMODE_CONFIG; // configuration request |
} |
else |
{ |
Motor[motor_write].ReadMode = BL_READMODE_STATUS; // normal status request |
} |
// send read mode and the lower bits of setpoint |
I2C_WriteByte((Motor[motor_write].ReadMode<<3)|(Motor[motor_write].SetPointLowerBits & 0x07)); |
// configuration tranmission request? |
if((0x0001<<motor_write) & BLConfig_WriteMask) |
{ // redirect tx pointer to configuration data |
pBuff = (uint8_t*)&BLConfig; // select config for motor |
BuffLen = sizeof(BLConfig_t); |
} |
else |
{ // jump to end of transmission for that motor |
twi_state = 4; |
} |
break; |
case 3: // send configuration |
I2C_WriteByte(*pBuff); |
pBuff++; |
if(--BuffLen > 0) |
twi_state = 3; // if there are some bytes left |
break; |
case 4: // repeat case 0-4 for all motors |
if(TWSR == TW_MT_DATA_NACK) // Data transmitted, NACK received |
{ |
if(!missing_motor) |
missing_motor = motor_write + 1; |
if((Motor[motor_write].State & MOTOR_STATE_ERROR_MASK) < MOTOR_STATE_ERROR_MASK) |
Motor[motor_write].State++; // increment error counter and handle overflow |
} |
I2C_Stop(TWI_STATE_MOTOR_TX); |
I2CTimeout = 10; |
motor_write++; // next motor |
I2C_Start(TWI_STATE_MOTOR_TX); // Repeated start -> switch slave or switch Master Transmit -> Master Receive |
break; |
// Master Receive Data |
case 5: // TWI_STATE_MOTOR_RX |
if(TWSR != TW_MR_SLA_ACK) // SLA+R transmitted but no ACK received |
{ // no response from the addressed slave received |
Motor[motor_read].State &= ~MOTOR_STATE_PRESENT_MASK; // clear present bit |
if(++motor_read >= MAX_MOTORS) |
{ // all motors read |
motor_read = 0; // restart from beginning |
BLConfig_ReadMask = 0; // reset read configuration bitmask |
if(++motor_read_temperature >= MAX_MOTORS) |
{ |
motor_read_temperature = 0; |
BLFlags &= ~BLFLAG_READ_VERSION; |
} |
} |
BLFlags |= BLFLAG_TX_COMPLETE; |
I2C_Stop(TWI_STATE_MOTOR_TX); |
I2C_TransferActive = 0; |
} |
else |
{ // motor successfully addressed |
Motor[motor_read].State |= MOTOR_STATE_PRESENT_MASK; // set present bit |
if(Motor[motor_read].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) |
{ |
// new BL found |
switch(Motor[motor_read].ReadMode) |
{ |
case BL_READMODE_CONFIG: |
pBuff = (uint8_t*)&BLConfig; |
BuffLen = sizeof(BLConfig_t); |
break; |
case BL_READMODE_STATUS: |
pBuff = (uint8_t*)&(Motor[motor_read].Current); |
if(motor_read == motor_read_temperature) BuffLen = 3; // read Current, MaxPwm & Temp |
else BuffLen = 1;// read Current only |
break; |
} |
} |
else // old BL version |
{ |
pBuff = (uint8_t*)&(Motor[motor_read].Current); |
if((BLFlags & BLFLAG_READ_VERSION) || (motor_read == motor_read_temperature)) BuffLen = 2; // Current & MaxPwm |
else BuffLen = 1; // read Current only |
} |
if(BuffLen == 1) |
{ |
I2C_ReceiveLastByte(); // read last byte |
} |
else |
{ |
I2C_ReceiveByte(); // read next byte |
} |
} |
MissingMotor = missing_motor; |
missing_motor = 0; |
break; |
case 6: // receive bytes |
*pBuff = TWDR; |
pBuff++; |
BuffLen--; |
if(BuffLen>1) |
{ |
I2C_ReceiveByte(); // read next byte |
} |
else if (BuffLen == 1) |
{ |
I2C_ReceiveLastByte(); // read last byte |
} |
else // nothing left |
{ |
if(BLFlags & BLFLAG_READ_VERSION) |
{ |
// if(!(FC_StatusFlags & FC_STATUS_MOTOR_RUN) && (Motor[motor_read].MaxPWM == 250) ) Motor[motor_read].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK; |
if((Motor[motor_read].MaxPWM == 250) ) Motor[motor_read].Version |= MOTOR_STATE_NEW_PROTOCOL_MASK; |
else Motor[motor_read].Version = 0; |
} |
if(++motor_read >= MAX_MOTORS) |
{ |
motor_read = 0; // restart from beginning |
BLConfig_ReadMask = 0; // reset read configuration bitmask |
if(++motor_read_temperature >= MAX_MOTORS) |
{ |
motor_read_temperature = 0; |
BLFlags &= ~BLFLAG_READ_VERSION; |
} |
} |
I2C_Stop(TWI_STATE_MOTOR_TX); |
BLFlags |= BLFLAG_TX_COMPLETE; |
I2C_TransferActive = 0; |
return; |
} |
twi_state = 6; // if there are some bytes left |
break; |
case 21: |
I2C_WriteByte(0x80); // 2nd byte for all channels is 0x80 |
break; |
case 22: |
I2C_Stop(TWI_STATE_MOTOR_TX); |
I2C_TransferActive = 0; |
I2CTimeout = 10; |
// repeat case 18...22 until all DAC Channels are updated |
if(dac_channel < 2) |
{ |
dac_channel ++; // jump to next channel |
I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // start transmission for next channel |
} |
else |
{ |
dac_channel = 0; // reset dac channel counter |
BLFlags |= BLFLAG_TX_COMPLETE; |
} |
break; |
default: |
I2C_Stop(TWI_STATE_MOTOR_TX); |
BLFlags |= BLFLAG_TX_COMPLETE; |
I2CTimeout = 10; |
motor_write = 0; |
motor_read = 0; |
I2C_TransferActive = 0; |
break; |
} |
} |
//-------------------------------------------------------------- |
uint8_t I2C_WriteBLConfig(uint8_t motor) |
{ |
uint8_t i; |
uint16_t timer; |
// if(MotorenEin || PC_MotortestActive) |
// return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running! |
if(MotorenEin) |
return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running! |
if(motor > MAX_MOTORS) |
return (BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist! |
if(motor) |
{ |
if(!(Motor[motor-1].State & MOTOR_STATE_PRESENT_MASK)) |
return(BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist! |
if(!(Motor[motor-1].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)) |
return(BLCONFIG_ERR_HW_NOT_COMPATIBLE); // not a new BL! |
} |
// check BL configuration to send |
if(BLConfig.Revision != BLCONFIG_REVISION) |
return (BLCONFIG_ERR_SW_NOT_COMPATIBLE); // bad revison |
i = RAM_Checksum((uint8_t*)&BLConfig, sizeof(BLConfig_t) - 1); |
if(i != BLConfig.crc) |
return(BLCONFIG_ERR_CHECKSUM); // bad checksum |
timer = SetDelay(2000); |
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
// prepare the bitmask |
if(!motor) // 0 means all |
{ |
BLConfig_WriteMask = 0xFF; // all motors at once with the same configuration |
} |
else //only one specific motor |
{ |
BLConfig_WriteMask = 0x0001<<(motor-1); |
} |
for(i = 0; i < MAX_MOTORS; i++) |
{ |
if((0x0001<<i) & BLConfig_WriteMask) |
{ |
Motor[i].SetPoint = 0; |
Motor[i].SetPointLowerBits = 0; |
} |
} |
motor_write = 0; |
// needs at least MAX_MOTORS loops of 2 ms (12*2ms = 24ms) |
do |
{ |
I2C_Start(TWI_STATE_MOTOR_TX); // start an i2c transmission |
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
} |
while(BLConfig_WriteMask && !CheckDelay(timer)); // repeat until the BL config has been sent |
if(BLConfig_WriteMask) return(BLCONFIG_ERR_MOTOR_NOT_EXIST); |
return(BLCONFIG_SUCCESS); |
} |
//-------------------------------------------------------------- |
uint8_t I2C_ReadBLConfig(uint8_t motor) |
{ |
uint8_t i; |
uint16_t timer; |
// if(MotorenEin || PC_MotortestActive) |
return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running! |
if(MotorenEin) |
return(BLCONFIG_ERR_MOTOR_RUNNING); // not when motors are running! |
if(motor > MAX_MOTORS) |
return (BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist! |
if(motor == 0) |
return (BLCONFIG_ERR_READ_NOT_POSSIBLE); |
if(!(Motor[motor-1].State & MOTOR_STATE_PRESENT_MASK)) |
return(BLCONFIG_ERR_MOTOR_NOT_EXIST); // motor does not exist! |
if(!(Motor[motor-1].Version & MOTOR_STATE_NEW_PROTOCOL_MASK)) |
return(BLCONFIG_ERR_HW_NOT_COMPATIBLE); // not a new BL! |
timer = SetDelay(2000); |
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
// prepare the bitmask |
BLConfig_ReadMask = 0x0001<<(motor-1); |
for(i = 0; i < MAX_MOTORS; i++) |
{ |
if((0x0001<<i) & BLConfig_ReadMask) |
{ |
Motor[i].SetPoint = 0; |
Motor[i].SetPointLowerBits = 0; |
} |
} |
motor_read = 0; |
BLConfig.Revision = 0; // bad revision |
BLConfig.crc = 0; // bad checksum |
// needs at least MAX_MOTORS loops of 2 ms (12*2ms = 24ms) |
do |
{ |
I2C_Start(TWI_STATE_MOTOR_TX); // start an i2c transmission |
while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
}while(BLConfig_ReadMask && !CheckDelay(timer)); // repeat until the BL config has been received from all motors |
// validate result |
if(BLConfig.Revision != BLCONFIG_REVISION) return (BLCONFIG_ERR_SW_NOT_COMPATIBLE); // bad revison |
i = RAM_Checksum((uint8_t*)&BLConfig, sizeof(BLConfig_t) - 1); |
if(i != BLConfig.crc) return(BLCONFIG_ERR_CHECKSUM); // bad checksum |
return(BLCONFIG_SUCCESS); |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/twimaster.h |
---|
0,0 → 1,100 |
#ifndef _I2C_MASTER_H |
#define _I2C_MASTER_H |
+ |
+#include <inttypes.h> |
+ |
+#define TWI_STATE_MOTOR_TX 0 |
+#define TWI_STATE_MOTOR_RX 5 |
+#define TWI_STATE_GYRO_OFFSET_TX 18 |
+ |
+extern volatile uint8_t twi_state; |
+extern volatile uint8_t motor_write; |
+extern volatile uint8_t motor_read; |
+extern volatile uint8_t I2C_TransferActive; |
+ |
+extern uint8_t MissingMotor; |
+ |
+#define MAX_MOTORS 12 |
+#define MOTOR_STATE_PRESENT_MASK 0x80 |
+#define MOTOR_STATE_ERROR_MASK 0x7F |
+#define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
+#define BLFLAG_TX_COMPLETE 0x01 |
+#define BLFLAG_READ_VERSION 0x02 |
+ |
+extern volatile uint8_t BLFlags; |
+extern char MotorenEin; |
+unsigned char MotorTest[16]; |
+#define BL_READMODE_STATUS 0 |
+#define BL_READMODE_CONFIG 16 |
+ |
+typedef struct |
+{ |
+ uint8_t Version; // the version of the BL (0 = old) |
+ uint8_t SetPoint; // written by attitude controller |
+ uint8_t SetPointLowerBits; // for higher Resolution of new BLs |
+ uint8_t State; // 7 bit for I2C error counter, highest bit indicates if motor is present |
+ uint8_t ReadMode; // select data to read |
+ // the following bytes must be exactly in that order! |
+ uint8_t Current; // in 0.1 A steps, read back from BL |
+ uint8_t MaxPWM; // read back from BL is less than 255 if BL is in current limit |
+ int8_t Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in �C |
+} __attribute__((packed)) MotorData_t; |
+ |
+extern MotorData_t Motor[MAX_MOTORS]; |
+ |
+#define BLCONFIG_REVISION 2 |
+ |
+#define MASK_SET_PWM_SCALING 0x01 |
+#define MASK_SET_CURRENT_LIMIT 0x02 |
+#define MASK_SET_TEMP_LIMIT 0x04 |
+#define MASK_SET_CURRENT_SCALING 0x08 |
+#define MASK_SET_BITCONFIG 0x10 |
+#define MASK_RESET_CAPCOUNTER 0x20 |
+#define MASK_SET_DEFAULT_PARAMS 0x40 |
+#define MASK_SET_SAVE_EEPROM 0x80 |
+ |
+#define BITCONF_REVERSE_ROTATION 0x01 |
+#define BITCONF_RES1 0x02 |
+#define BITCONF_RES2 0x04 |
+#define BITCONF_RES3 0x08 |
+#define BITCONF_RES4 0x10 |
+#define BITCONF_RES5 0x20 |
+#define BITCONF_RES6 0x40 |
+#define BITCONF_RES7 0x80 |
+ |
+typedef struct |
+{ |
+ uint8_t Revision; // must be BL_REVISION |
+ uint8_t SetMask; // settings mask |
+ uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit |
+ uint8_t CurrentLimit; // current limit in A |
+ uint8_t TempLimit; // in �C |
+ uint8_t CurrentScaling; // scaling factor for current measurement |
+ uint8_t BitConfig; // see defines above |
+ uint8_t crc; // checksum |
+} __attribute__((packed)) BLConfig_t; |
+ |
+extern BLConfig_t BLConfig; |
+ |
+extern volatile uint16_t I2CTimeout; |
+ |
+void I2C_Init(char); // Initialize I2C |
+#define I2C_Start(start_state) {twi_state = start_state; BLFlags &= ~BLFLAG_TX_COMPLETE; TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE);} |
+#define I2C_Stop(start_state) {twi_state = start_state; TWCR = (1<<TWEN) | (1<<TWSTO) | (1<<TWINT);} |
+void I2C_Reset(void); // Reset I2C |
+ |
+#define BLCONFIG_SUCCESS 0 |
+#define BLCONFIG_ERR_MOTOR_RUNNING 1 |
+#define BLCONFIG_ERR_MOTOR_NOT_EXIST 2 |
+#define BLCONFIG_ERR_HW_NOT_COMPATIBLE 3 |
+#define BLCONFIG_ERR_SW_NOT_COMPATIBLE 4 |
+#define BLCONFIG_ERR_CHECKSUM 5 |
+#define BLCONFIG_ERR_READ_NOT_POSSIBLE 6 |
+ |
+uint8_t I2C_WriteBLConfig(uint8_t motor); |
+uint8_t I2C_ReadBLConfig(uint8_t motor); |
+ |
+#endif |
+ |
+ |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/uart1.c |
---|
0,0 → 1,303 |
/************************************************************************* |
Title: Interrupt UART library with receive/transmit circular buffers |
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury |
File: $Id: uart.c,v 1.6.2.2 2009/11/29 08:56:12 Peter Exp $ |
Software: AVR-GCC 4.1, AVR Libc 1.4.6 or higher |
Hardware: any AVR with built-in UART, |
License: GNU General Public License |
DESCRIPTION: |
An interrupt is generated when the UART has finished transmitting or |
receiving a byte. The interrupt handling routines use circular buffers |
for buffering received and transmitted data. |
The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define |
the buffer size in bytes. Note that these variables must be a |
power of 2. |
USAGE: |
Refere to the header file uart.h for a description of the routines. |
See also example test_uart.c. |
NOTES: |
Based on Atmel Application Note AVR306 |
LICENSE: |
Copyright (C) 2006 Peter Fleury |
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License as published by |
the Free Software Foundation; either version 2 of the License, or |
any later version. |
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
*************************************************************************/ |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include "uart1.h" |
#include "main.h" |
// |
// constants and macros |
// |
// size of RX/TX buffers |
#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1) |
#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1) |
#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK ) |
#error RX buffer size is not a power of 2 |
#endif |
#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK ) |
#error TX buffer size is not a power of 2 |
#endif |
// ATmega with two USART |
#define ATMEGA_USART1 |
#define UART1_STATUS UCSR1A |
#define UART1_CONTROL UCSR1B |
#define UART1_DATA UDR1 |
#define UART1_UDRIE UDRIE1 |
// |
// module global variables |
// |
#if defined( ATMEGA_USART1 ) |
static volatile unsigned char UART1_TxBuf[UART_TX_BUFFER_SIZE]; |
static volatile unsigned char UART1_RxBuf[UART_RX_BUFFER_SIZE]; |
static volatile unsigned char UART1_TxHead; |
static volatile unsigned char UART1_TxTail; |
static volatile unsigned char UART1_RxHead; |
static volatile unsigned char UART1_RxTail; |
static volatile unsigned char UART1_LastRxError; |
#endif |
// |
// these functions are only for ATmegas with two USART |
// |
#if defined( ATMEGA_USART1 ) |
//-------------------------------------------------------------- |
// Function: UART1 Receive Complete interrupt |
// Purpose: called when the UART1 has received a character |
//-------------------------------------------------------------- |
ISR(USART1_RX_vect) |
{ |
unsigned char tmphead; |
unsigned char data; |
unsigned char usr; |
unsigned char lastRxError; |
// read UART status register and UART data register |
usr = UART1_STATUS; |
data = UART1_DATA; |
lastRxError = (usr & (_BV(FE1)|_BV(DOR1)) ); |
// calculate buffer index |
tmphead = ( UART1_RxHead + 1) & UART_RX_BUFFER_MASK; |
if ( tmphead == UART1_RxTail ) |
{ |
// error: receive buffer overflow |
lastRxError = UART_BUFFER_OVERFLOW >> 8; |
} |
else |
{ |
// store new index |
UART1_RxHead = tmphead; |
// store received data in buffer |
UART1_RxBuf[tmphead] = data; |
} |
UART1_LastRxError = lastRxError; |
} |
//-------------------------------------------------------------- |
// Function: UART1 Data Register Empty interrupt |
// Purpose: called when the UART1 is ready to transmit the next byte |
//-------------------------------------------------------------- |
ISR(USART1_UDRE_vect) |
{ |
unsigned char tmptail; |
if ( UART1_TxHead != UART1_TxTail) |
{ |
// calculate and store new buffer index |
tmptail = (UART1_TxTail + 1) & UART_TX_BUFFER_MASK; |
UART1_TxTail = tmptail; |
// get one byte from buffer and write it to UART |
UART1_DATA = UART1_TxBuf[tmptail]; // start transmission |
} |
else |
{ |
// tx buffer empty, disable UDRE interrupt |
UART1_CONTROL &= ~_BV(UART1_UDRIE); |
} |
} |
//-------------------------------------------------------------- |
// Function: uart1_init() |
// Purpose: initialize UART1 and set baudrate |
// Input: baudrate using macro UART_BAUD_SELECT() |
// Returns: none |
//-------------------------------------------------------------- |
void uart1_init(unsigned int baudrate) |
{ |
UART1_TxHead = 0; |
UART1_TxTail = 0; |
UART1_RxHead = 0; |
UART1_RxTail = 0; |
// Set baud rate |
if ( baudrate & 0x8000 ) |
{ |
UART1_STATUS = (1<<U2X1); //Enable 2x speed |
baudrate &= ~0x8000; |
} |
UBRR1H = (unsigned char)(baudrate>>8); |
UBRR1L = (unsigned char) baudrate; |
// Enable USART receiver and transmitter and receive complete interrupt |
UART1_CONTROL = _BV(RXCIE1)|(1<<RXEN1)|(1<<TXEN1); |
// Set frame format: asynchronous, 8data, no parity, 1stop bit |
#ifdef URSEL1 |
UCSR1C = (1<<URSEL1)|(3<<UCSZ10); |
#else |
UCSR1C = (3<<UCSZ10); |
#endif |
} |
//-------------------------------------------------------------- |
// Function: uart1_getc() |
// Purpose: return byte from ringbuffer |
// Returns: lower byte: received byte from ringbuffer |
// higher byte: last receive error |
//-------------------------------------------------------------- |
unsigned int uart1_getc(void) |
{ |
unsigned char tmptail; |
unsigned char data; |
if ( UART1_RxHead == UART1_RxTail ) |
{ |
return UART_NO_DATA; // no data available |
} |
// calculate /store buffer index |
tmptail = (UART1_RxTail + 1) & UART_RX_BUFFER_MASK; |
UART1_RxTail = tmptail; |
// get data from receive buffer |
data = UART1_RxBuf[tmptail]; |
return (UART1_LastRxError << 8) + data; |
} |
//-------------------------------------------------------------- |
// Function: uart1_putc() |
// Purpose: write byte to ringbuffer for transmitting via UART |
// Input: byte to be transmitted |
// Returns: 1 on succes, 0 if remote not ready |
//-------------------------------------------------------------- |
int uart1_putc(unsigned char data) |
{ |
unsigned char tmphead; |
tmphead = (UART1_TxHead + 1) & UART_TX_BUFFER_MASK; |
while ( tmphead == UART1_TxTail ) |
{;} // wait for free space in buffer |
UART1_TxBuf[tmphead] = data; |
UART1_TxHead = tmphead; |
// enable UDRE interrupt |
UART1_CONTROL |= _BV(UART1_UDRIE); |
return (UART1_LastRxError << 8) + data; |
} |
//-------------------------------------------------------------- |
// Function: uart1_puts() |
// Purpose: transmit string to UART1 |
// Input: string to be transmitted |
// Returns: none |
//-------------------------------------------------------------- |
void uart1_puts(const char *s ) |
{ |
while (*s) |
uart1_putc(*s++); |
} |
//-------------------------------------------------------------- |
// Function: uart1_puts_p() |
// Purpose: transmit string from program memory to UART1 |
// Input: program memory string to be transmitted |
// Returns: none |
//-------------------------------------------------------------- |
void uart1_puts_p(const char *progmem_s ) |
{ |
register char c; |
while ( (c = pgm_read_byte(progmem_s++)) ) |
uart1_putc(c); |
} |
//-------------------------------------------------------------- |
// Function: uart1_available() |
// Purpose: Determine the number of bytes waiting in the receive buffer |
// Input: None |
// Returns: Integer number of bytes in the receive buffer |
//-------------------------------------------------------------- |
int uart1_available(void) |
{ |
return (UART_RX_BUFFER_MASK + UART1_RxHead - UART1_RxTail) % UART_RX_BUFFER_MASK; |
} |
//-------------------------------------------------------------- |
// Function: uart1_flush() |
// Purpose: Flush bytes waiting the receive buffer. Acutally ignores them. |
// Input: None |
// Returns: None |
//-------------------------------------------------------------- |
void uart1_flush(void) |
{ |
UART1_RxHead = UART1_RxTail; |
} |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/uart1.h |
---|
0,0 → 1,167 |
/************************************************************************ |
Title: Interrupt UART library with receive/transmit circular buffers |
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury |
File: $Id: uart.h,v 1.8.2.1 2007/07/01 11:14:38 peter Exp $ |
Software: AVR-GCC 4.1, AVR Libc 1.4 |
Hardware: any AVR with built-in UART, tested on AT90S8515 & ATmega8 at 4 Mhz |
License: GNU General Public License |
Usage: see Doxygen manual |
LICENSE: |
Copyright (C) 2006 Peter Fleury |
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License as published by |
the Free Software Foundation; either version 2 of the License, or |
any later version. |
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
************************************************************************/ |
// |
// @defgroup pfleury_uart UART Library |
// @code #include <uart.h> @endcode |
// |
// @brief Interrupt UART library using the built-in UART with transmit and receive circular buffers. |
// |
// This library can be used to transmit and receive data through the built in UART. |
// |
// An interrupt is generated when the UART has finished transmitting or |
// receiving a byte. The interrupt handling routines use circular buffers |
// for buffering received and transmitted data. |
// |
// The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants define |
// the size of the circular buffers in bytes. Note that these constants must be a power of 2. |
// You may need to adapt this constants to your target and your application by adding |
// CDEFS += -DUART_RX_BUFFER_SIZE=nn -DUART_RX_BUFFER_SIZE=nn to your Makefile. |
// |
// @note Based on Atmel Application Note AVR306 |
// @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury |
// |
#ifndef UART_H |
#define UART_H |
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 |
#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" |
#endif |
// constants and macros |
// @brief UART Baudrate Expression |
// @param xtalcpu system clock in Mhz, e.g. 4000000L for 4Mhz |
// @param baudrate baudrate in bps, e.g. 1200, 2400, 9600 |
// |
#define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1) |
// @brief UART Baudrate Expression for ATmega double speed mode |
// @param xtalcpu system clock in Mhz, e.g. 4000000L for 4Mhz |
// @param baudrate baudrate in bps, e.g. 1200, 2400, 9600 |
// |
#define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) (((xtalCpu)/((baudRate)*8l)-1)|0x8000) |
// Size of the circular receive buffer, must be power of 2 |
#ifndef UART_RX_BUFFER_SIZE |
#define UART_RX_BUFFER_SIZE 32 |
#endif |
// Size of the circular transmit buffer, must be power of 2 |
#ifndef UART_TX_BUFFER_SIZE |
#define UART_TX_BUFFER_SIZE 32 |
#endif |
// test if the size of the circular buffers fits into SRAM |
#if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) ) |
#error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM" |
#endif |
// high byte error return code of uart_getc() |
#define UART_FRAME_ERROR 0x0800 // Framing Error by UART |
#define UART_OVERRUN_ERROR 0x0400 // Overrun condition by UART |
#define UART_BUFFER_OVERFLOW 0x0200 // receive ringbuffer overflow |
#define UART_NO_DATA 0x0100 // no receive data available |
// |
// function prototypes |
// |
// |
// @brief Initialize UART and set baudrate |
// @param baudrate Specify baudrate using macro UART_BAUD_SELECT() |
// @return none |
// |
extern void uart_init(unsigned int baudrate); |
// |
// @brief Get received byte from ringbuffer |
// |
// Returns in the lower byte the received character and in the |
// higher byte the last receive error. |
// UART_NO_DATA is returned when no data is available. |
// |
// @param void |
// @return lower byte: received byte from ringbuffer |
// @return higher byte: last receive status |
// - \b 0 successfully received data from UART |
// - \b UART_NO_DATA |
// <br>no receive data available |
// - \b UART_BUFFER_OVERFLOW |
// <br>Receive ringbuffer overflow. |
// We are not reading the receive buffer fast enough, |
// one or more received character have been dropped |
// - \b UART_OVERRUN_ERROR |
// <br>Overrun condition by UART. |
// A character already present in the UART UDR register was |
// not read by the interrupt handler before the next character arrived, |
// one or more received characters have been dropped. |
// - \b UART_FRAME_ERROR |
// <br>Framing Error by UART |
// |
extern unsigned int uart_getc(void); |
// |
// @brief Put byte to ringbuffer for transmitting via UART |
// @param data byte to be transmitted |
// @return none |
// |
// @brief Initialize USART1 (only available on selected ATmegas) @see uart_init |
extern void uart1_init(unsigned int baudrate); |
// @brief Get received byte of USART1 from ringbuffer. (only available on selected ATmega) @see uart_getc |
extern unsigned int uart1_getc(void); |
// @brief Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_putc |
//extern void uart1_putc(unsigned char data); |
extern int uart1_putc(unsigned char data); |
// @brief Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts |
extern void uart1_puts(const char *s ); |
// @brief Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts_p |
extern void uart1_puts_p(const char *s ); |
// @brief Macro to automatically put a string constant into program memory |
#define uart1_puts_P(__s) uart1_puts_p(PSTR(__s)) |
extern char *utoa1(char* buffer, const unsigned int size, unsigned int value); |
#endif // UART_H |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/usart.c |
---|
0,0 → 1,634 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#include "cpu.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/wdt.h> |
#include <util/delay.h> |
#include <stdarg.h> |
#include "main.h" |
#include "usart.h" |
#include "lcd.h" |
#include "timer.h" |
uint8_t buffer[30]; |
volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
volatile uint8_t txd_complete = TRUE; |
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
volatile uint8_t rxd_buffer_locked = FALSE; |
volatile uint8_t ReceivedBytes = 0; |
volatile uint8_t *pRxData = 0; |
volatile uint8_t RxDataLen = 0; |
volatile uint16_t stat_crc_error = 0; |
volatile uint16_t stat_overflow_error = 0; |
volatile uint8_t rx_byte; |
volatile uint8_t rxFlag = 0; |
#define UART_RXBUFSIZE 64 |
#define UART_NO_DATA 0x0100 /* no receive data available */ |
volatile static uint8_t rxbuf[UART_RXBUFSIZE]; |
volatile static uint8_t *volatile rxhead, *volatile rxtail; |
/* |
//----------------------------------------------------------------------------- |
// USART1 transmitter ISR |
ISR (USART1_TX_vect) |
{ |
static uint16_t ptr_txd1_buffer = 0; |
uint8_t tmp_tx1; |
if(!txd1_complete) // transmission not completed |
{ |
ptr_txd1_buffer++; // [0] was already sent |
tmp_tx1 = txd1_buffer[ptr_txd1_buffer]; |
// if terminating character or end of txd buffer was reached |
if((tmp_tx1 == '\r') || (ptr_txd1_buffer == TXD_BUFFER_LEN)) |
{ |
ptr_txd1_buffer = 0; // reset txd pointer |
txd1_complete = TRUE; // stop transmission |
} |
UDR1 = tmp_tx1; // send current byte will trigger this ISR again |
} |
// transmission completed |
else ptr_txd1_buffer = 0; |
} |
*/ |
#ifdef USART_INT |
//----------------------------------------------------------------------------- |
// USART0 transmitter ISR |
ISR (USART_TX_vect) |
{ |
static uint16_t ptr_txd_buffer = 0; |
uint8_t tmp_tx; |
if(!txd_complete) // transmission not completed |
{ |
ptr_txd_buffer++; // [0] was already sent |
tmp_tx = txd_buffer[ptr_txd_buffer]; |
// if terminating character or end of txd buffer was reached |
if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) |
{ |
ptr_txd_buffer = 0; // reset txd pointer |
txd_complete = TRUE; // stop transmission |
} |
UDR = tmp_tx; // send current byte will trigger this ISR again |
} |
// transmission completed |
else ptr_txd_buffer = 0; |
} |
#endif |
//----------------------------------------------------------------------------- |
// |
// |
//uint8_t uart_getc_nb(uint8_t *c) |
//{ |
// if (rxhead==rxtail) return 0; |
// *c = *rxtail; |
// if (++rxtail == (rxbuf + UART_RXBUFSIZE)) rxtail = rxbuf; |
// return 1; |
//} |
ISR (USART0_RX_vect) |
{ |
static uint16_t crc; |
static uint8_t ptr_rxd_buffer = 0; |
uint8_t crc1, crc2; |
uint8_t c; |
// IdleTimer = 0; |
if (current_hardware == Wi232) |
{ |
// rx_byte = c; |
// rxFlag = 1; |
int diff; |
uint8_t c; |
c=UDR; |
diff = rxhead - rxtail; |
if (diff < 0) diff += UART_RXBUFSIZE; |
if (diff < UART_RXBUFSIZE -1) |
{ |
*rxhead = c; |
++rxhead; |
if (rxhead == (rxbuf + UART_RXBUFSIZE)) rxhead = rxbuf; |
}; |
// USART_putc (c); |
return; |
} |
if (current_hardware == MKGPS) |
{ |
// rx_byte = c; |
// rxFlag = 1; |
int diff; |
uint8_t c; |
c=UDR; |
diff = rxhead - rxtail; |
if (diff < 0) diff += UART_RXBUFSIZE; |
if (diff < UART_RXBUFSIZE -1) |
{ |
*rxhead = c; |
++rxhead; |
if (rxhead == (rxbuf + UART_RXBUFSIZE)) rxhead = rxbuf; |
}; |
return; |
} |
c = UDR; // catch the received byte |
if (rxd_buffer_locked) |
return; // if rxd buffer is locked immediately return |
// the rxd buffer is unlocked |
if ((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received |
{ |
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 |
if (mode == rxd_buffer[2]) |
{ |
rxd_buffer_locked = TRUE; // lock the rxd buffer |
// if 2nd byte is an 'R' enable watchdog that will result in an reset |
if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando |
} |
} |
else |
{ // checksum invalid |
stat_crc_error++; |
rxd_buffer_locked = FALSE; // unlock rxd buffer |
} |
ptr_rxd_buffer = 0; // reset rxd buffer pointer |
} |
} |
else // rxd buffer overrun |
{ |
stat_overflow_error++; |
ptr_rxd_buffer = 0; // reset rxd buffer |
rxd_buffer_locked = FALSE; // unlock rxd buffer |
} |
} |
//----------------------------------------------------------------------------- |
// Function: uart0_getc() |
// Purpose: return byte from ringbuffer |
// Returns: lower byte: received byte from ringbuffer |
// higher byte: last receive error |
//----------------------------------------------------------------------------- |
char USART_getc(void) |
{ |
char val; |
// while(rxhead==rxtail) ; |
if (rxhead==rxtail) |
return val=0; |
// IdleTimer = 0; |
val = *rxtail; |
if (++rxtail == (rxbuf + UART_RXBUFSIZE)) |
rxtail = rxbuf; |
return val; |
} |
uint8_t uart_getc_nb(uint8_t *c) |
{ |
if (rxhead==rxtail) |
return 0; |
// IdleTimer = 0; |
*c = *rxtail; |
if (++rxtail == (rxbuf + UART_RXBUFSIZE)) |
rxtail = rxbuf; |
return 1; |
} |
//----------------------------------------------------------------------------- |
// |
//----------------------------------------------------------------------------- |
// |
void USART_Init (unsigned int baudrate) |
{ |
// set clock divider |
// #undef BAUD |
// #define BAUD baudrate |
// #include <util/setbaud.h> |
// UBRRH = UBRRH_VALUE; |
// UBRRL = UBRRL_VALUE; |
UBRRH = (unsigned char)(baudrate>>8); |
UBRRL = (unsigned char) baudrate; |
#if USE_2X |
UCSRA |= (1 << U2X); // enable double speed operation |
#else |
UCSRA &= ~(1 << U2X); // disable double speed operation |
#endif |
// set 8N1 |
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega32__) |
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0); |
#else |
UCSRC = (1 << UCSZ1) | (1 << UCSZ0); |
#endif |
UCSRB &= ~(1 << UCSZ2); |
// flush receive buffer |
while ( UCSRA & (1 << RXC) ) UDR; |
UCSRB |= (1 << RXEN) | (1 << TXEN); |
#ifdef USART_INT |
UCSRB |= (1 << RXCIE) | (1 << TXCIE); |
#else |
UCSRB |= (1 << RXCIE); |
#endif |
rxhead = rxtail = rxbuf; |
} |
//----------------------------------------------------------------------------- |
// disable the txd pin of usart |
void USART_DisableTXD (void) |
{ |
#ifdef USART_INT |
UCSRB &= ~(1 << TXCIE); // disable TX-Interrupt |
#endif |
UCSRB &= ~(1 << TXEN); // disable TX in USART |
DDRB &= ~(1 << DDB3); // set TXD pin as input |
PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin |
} |
//----------------------------------------------------------------------------- |
// enable the txd pin of usart |
void USART_EnableTXD (void) |
{ |
DDRB |= (1 << DDB3); // set TXD pin as output |
PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin |
UCSRB |= (1 << TXEN); // enable TX in USART |
#ifdef USART_INT |
UCSRB |= (1 << TXCIE); // enable TX-Interrupt |
#endif |
} |
//----------------------------------------------------------------------------- |
// short script to directly send a request thorugh usart including en- and disabling it |
// where <address> is the address of the receipient, <label> is which data set to request |
// and <ms> represents the milliseconds delay between data |
void USART_request_mk_data (uint8_t cmd, uint8_t addr, uint8_t ms) |
{ |
USART_EnableTXD (); // re-enable TXD pin |
unsigned char mstenth = ms/10; |
SendOutData(cmd, addr, 1, &mstenth, 1); |
// wait until command transmitted |
while (txd_complete == FALSE); |
USART_DisableTXD (); // disable TXD pin again |
} |
//----------------------------------------------------------------------------- |
// |
void USART_putc (char c) |
{ |
#ifdef USART_INT |
#else |
loop_until_bit_is_set(UCSRA, UDRE); |
UDR = c; |
#endif |
} |
//----------------------------------------------------------------------------- |
// |
void USART_puts (char *s) |
{ |
#ifdef USART_INT |
#else |
while (*s) |
{ |
USART_putc (*s); |
s++; |
} |
#endif |
} |
//----------------------------------------------------------------------------- |
// |
void USART_puts_p (const char *s) |
{ |
#ifdef USART_INT |
#else |
while (pgm_read_byte(s)) |
{ |
USART_putc (pgm_read_byte(s)); |
s++; |
} |
#endif |
} |
//----------------------------------------------------------------------------- |
// |
void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) // uint8_t *pdata, uint8_t len, ... |
{ |
va_list ap; |
uint16_t pt = 0; |
uint8_t a,b,c; |
uint8_t ptr = 0; |
uint16_t tmpCRC = 0; |
uint8_t *pdata = 0; |
int len = 0; |
txd_buffer[pt++] = '#'; // Start character |
txd_buffer[pt++] = 'a' + addr; // Address (a=0; b=1,...) |
txd_buffer[pt++] = cmd; // Command |
va_start(ap, numofbuffers); |
if(numofbuffers) |
{ |
pdata = va_arg (ap, uint8_t*); |
len = va_arg (ap, int); |
ptr = 0; |
numofbuffers--; |
} |
while(len) |
{ |
if(len) |
{ |
a = pdata[ptr++]; |
len--; |
if((!len) && numofbuffers) |
{ |
pdata = va_arg(ap, uint8_t*); |
len = va_arg(ap, int); |
ptr = 0; |
numofbuffers--; |
} |
} |
else |
a = 0; |
if(len) |
{ |
b = pdata[ptr++]; |
len--; |
if((!len) && numofbuffers) |
{ |
pdata = va_arg(ap, uint8_t*); |
len = va_arg(ap, int); |
ptr = 0; |
numofbuffers--; |
} |
} |
else |
b = 0; |
if(len) |
{ |
c = pdata[ptr++]; |
len--; |
if((!len) && numofbuffers) |
{ |
pdata = va_arg(ap, uint8_t*); |
len = va_arg(ap, int); |
ptr = 0; |
numofbuffers--; |
} |
} |
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); |
} |
va_end(ap); |
for(a = 0; a < pt; a++) |
{ |
tmpCRC += txd_buffer[a]; |
} |
tmpCRC %= 4096; |
txd_buffer[pt++] = '=' + tmpCRC / 64; |
txd_buffer[pt++] = '=' + tmpCRC % 64; |
txd_buffer[pt++] = '\r'; |
txd_complete = FALSE; |
#ifdef USART_INT |
UDR = txd_buffer[0]; // initiates the transmittion (continued in the TXD ISR) |
#else |
for(a = 0; a < pt; a++) |
{ |
loop_until_bit_is_set(UCSRA, UDRE); |
UDR = txd_buffer[a]; |
} |
txd_complete = TRUE; |
#endif |
} |
//----------------------------------------------------------------------------- |
// |
void Decode64 (void) |
{ |
uint8_t a,b,c,d; |
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++] - '='; |
//if(ptrIn > ReceivedBytes - 3) break; |
if (len--) |
rxd_buffer[ptrOut++] = (a << 2) | (b >> 4); |
else |
break; |
if (len--) |
rxd_buffer[ptrOut++] = ((b & 0x0f) << 4) | (c >> 2); |
else |
break; |
if (len--) |
rxd_buffer[ptrOut++] = ((c & 0x03) << 6) | d; |
else |
break; |
} |
pRxData = &rxd_buffer[3]; |
RxDataLen = ptrOut - 3; |
} |
//----------------------------------------------------------------------------- |
// |
void SwitchToNC (void) |
{ |
if(hardware == NC) |
{ |
// switch to NC |
USART_putc (0x1b); |
USART_putc (0x1b); |
USART_putc (0x55); |
USART_putc (0xaa); |
USART_putc (0x00); |
current_hardware = NC; |
_delay_ms (50); |
} |
} |
//----------------------------------------------------------------------------- |
// |
//----------------------------------------------------------------------------- |
// |
void SwitchToWi232 (void) |
{ |
// if(hardware == NC) |
{ |
// switch to Wi232 |
current_hardware = Wi232; |
_delay_ms (50); |
} |
} |
//----------------------------------------------------------------------------- |
// |
void SwitchToFC (void) |
{ |
uint8_t cmd; |
if (current_hardware == NC) |
{ |
// switch to FC |
cmd = 0x00; // 0 = FC, 1 = MK3MAG, 2 = MKGPS |
SendOutData('u', ADDRESS_NC, 1, &cmd, 1); |
current_hardware = FC; |
_delay_ms (50); |
} |
} |
//----------------------------------------------------------------------------- |
// |
void SwitchToMAG (void) |
{ |
uint8_t cmd; |
if (current_hardware == NC) |
{ |
// switch to MK3MAG |
cmd = 0x01; // 0 = FC, 1 = MK3MAG, 2 = MKGPS |
SendOutData('u', ADDRESS_NC, 1, &cmd, 1); |
current_hardware = MK3MAG; |
_delay_ms (50); |
} |
} |
//----------------------------------------------------------------------------- |
// |
void SwitchToGPS (void) |
{ |
uint8_t cmd; |
if (current_hardware == NC) |
{ |
// switch to MKGPS |
cmd = 0x02; // 0 = FC, 1 = MK3MAG, 2 = MKGPS |
SendOutData('u', ADDRESS_NC, 1, &cmd, 1); |
current_hardware = MKGPS; |
_delay_ms (50); |
} |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/usart.h |
---|
0,0 → 1,149 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
* Copyright (C) 2011 Harald Bongartz * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
* * |
* Credits to: * |
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
* http://www.mikrokopter.de * |
* Gregor "killagreg" Stobrawa for his version of the MK code * |
* Thomas Kaiser "thkais" for the original project. See * |
* http://www.ft-fanpage.de/mikrokopter/ * |
* http://forum.mikrokopter.de/topic-4061-1.html * |
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
* http://www.mylifesucks.de/oss/c-osd/ * |
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
*****************************************************************************/ |
#ifndef _USART_H |
#define _USART_H |
//-------------------------------------------------------------- |
// |
#ifndef FALSE |
#define FALSE 0 |
#endif |
#ifndef TRUE |
#define TRUE 1 |
#endif |
// addresses |
#define ADDRESS_ANY 0 |
#define ADDRESS_FC 1 |
#define ADDRESS_NC 2 |
#define ADDRESS_MAG 3 |
// must be at least 4('#'+Addr+'CmdID'+'\r')+ (80 * 4)/3 = 111 bytes |
#define TXD_BUFFER_LEN 60 |
#define RXD_BUFFER_LEN 180 |
// Baud rate of the USART |
#define USART_BAUD 57600 |
//#define USART_BAUD 125000 |
//-------------------------------------------------------------- |
// |
extern uint8_t buffer[30]; |
extern volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
extern volatile uint8_t txd_complete; |
extern volatile uint8_t txd1_buffer[TXD_BUFFER_LEN]; |
extern volatile uint8_t txd1_complete; |
extern volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
extern volatile uint8_t rxd_buffer_locked; |
extern volatile uint8_t ReceivedBytes; |
extern volatile uint8_t *pRxData; |
extern volatile uint8_t RxDataLen; |
extern volatile uint16_t stat_crc_error; |
extern volatile uint16_t stat_overflow_error; |
extern volatile uint8_t rxFlag; |
extern volatile uint8_t rx_byte; |
//-------------------------------------------------------------- |
// |
void USART_Init (unsigned int baudrate); |
void USART_DisableTXD (void); |
void USART_EnableTXD (void); |
void USART_request_mk_data (uint8_t cmd, uint8_t addr, uint8_t ms); |
void USART_putc (char c); |
void USART_puts (char *s); |
void USART_puts_p (const char *s); |
extern char USART_getc(void); |
void SendOutData (uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...); // uint8_t *pdata, uint8_t len, ... |
//void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, uint8_t *pdata, uint8_t len); // uint8_t *pdata, uint8_t len, ... |
void Decode64 (void); |
void SwitchToNC (void); |
void SwitchToFC (void); |
void SwitchToMAG (void); |
void SwitchToGPS (void); |
void SwitchToWi232 (void); |
void debug1(void); |
uint8_t uart_getc_nb(uint8_t*); |
//-------------------------------------------------------------- |
//Anpassen der seriellen Schnittstellen Register |
#define USART_RXC_vect USART0_RX_vect |
//-------------------------------------------------------------- |
#define UCSRA UCSR0A |
#define UCSRB UCSR0B |
#define UCSRC UCSR0C |
#define UDR UDR0 |
#define UBRRL UBRR0L |
#define UBRRH UBRR0H |
// UCSRA |
#define RXC RXC0 |
#define TXC TXC0 |
#define UDRE UDRE0 |
#define FE FE0 |
#define UPE UPE0 |
#define U2X U2X0 |
#define MPCM MPCM0 |
// UCSRB |
#define RXCIE RXCIE0 |
#define TXCIE TXCIE0 |
#define UDRIE UDRIE0 |
#define TXEN TXEN0 |
#define RXEN RXEN0 |
#define UCSZ2 UCSZ02 |
#define RXB8 RXB80 |
#define TXB8 TXB80 |
// UCSRC |
#define UMSEL1 UMSEL01 |
#define UMSEL0 UMSEL00 |
#define UPM1 UPM01 |
#define UPM0 UPM00 |
#define USBS USBS0 |
#define UCSZ1 UCSZ01 |
#define UCSZ0 UCSZ00 |
#define UCPOL UCPOL0 |
#endif |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/waypoints.c |
---|
0,0 → 1,347 |
/*#######################################################################################*/ |
/* !!! THIS IS NOT FREE SOFTWARE !!! */ |
/*#######################################################################################*/ |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Copyright (c) 2008 Ingo Busker, Holger Buss |
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
// + FOR NON COMMERCIAL USE ONLY |
// + www.MikroKopter.com |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
// + Verkauf von Luftbildaufnahmen, usw. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
// + eindeutig als Ursprung verlinkt werden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
// + Benutzung auf eigene Gefahr |
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + mit unserer Zustimmung zulässig |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + this list of conditions and the following disclaimer. |
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
// + from this software without specific prior written permission. |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
// + for non-commercial use (directly or indirectly) |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + with our written permission |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
// |
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include <string.h> |
#include "91x_lib.h" |
#include "waypoints.h" |
#include "uart1.h" |
// the waypoints list |
#define MAX_LIST_LEN 31 |
Point_t PointList[MAX_LIST_LEN]; |
u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
u8 WPCount = 0; // number of waypoints |
u8 PointCount = 0; // number of wp in the list can be maximal equal to MAX_LIST_LEN |
u8 POICount = 0; |
u8 WPActive = FALSE; |
u8 PointList_Init(void) |
{ |
return PointList_Clear(); |
} |
u8 PointList_Clear(void) |
{ |
u8 i; |
WPIndex = 0; // real list position are 1 ,2, 3 ... |
POIIndex = 0; // real list position are 1 ,2, 3 ... |
WPCount = 0; // no waypoints |
POICount = 0; |
PointCount = 0; // no contents |
WPActive = FALSE; |
NaviData.WaypointNumber = WPCount; |
NaviData.WaypointIndex = 0; |
for(i = 0; i < MAX_LIST_LEN; i++) |
{ |
PointList[i].Position.Status = INVALID; |
PointList[i].Position.Latitude = 0; |
PointList[i].Position.Longitude = 0; |
PointList[i].Position.Altitude = 0; |
PointList[i].Heading = 361; // invalid value |
PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
PointList[i].Type = POINT_TYPE_INVALID; |
PointList[i].Event_Flag = 0; // future implementation |
PointList[i].AltitudeRate = 0; // no change of setpoint |
} |
return TRUE; |
} |
u8 PointList_GetCount(void) |
{ |
return PointCount; // number of points in the list |
} |
Point_t* PointList_GetAt(u8 index) |
{ |
if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
else return(NULL); |
} |
u8 PointList_SetAt(Point_t* pPoint) |
{ |
// if index is in range |
if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
{ |
// check list entry before update |
switch(PointList[pPoint->Index-1].Type) |
{ |
case POINT_TYPE_INVALID: // was invalid |
switch(pPoint->Type) |
{ |
default: |
case POINT_TYPE_INVALID: |
// nothing to do |
break; |
case POINT_TYPE_WP: |
WPCount++; |
PointCount++; |
break; |
case POINT_TYPE_POI: |
POICount++; |
PointCount++; |
break; |
} |
break; |
case POINT_TYPE_WP: // was a waypoint |
switch(pPoint->Type) |
{ |
case POINT_TYPE_INVALID: |
WPCount--; |
PointCount--; |
break; |
default: |
case POINT_TYPE_WP: |
//nothing to do |
break; |
case POINT_TYPE_POI: |
POICount++; |
WPCount--; |
break; |
} |
break; |
case POINT_TYPE_POI: // was a poi |
switch(pPoint->Type) |
{ |
case POINT_TYPE_INVALID: |
POICount--; |
PointCount--; |
break; |
case POINT_TYPE_WP: |
WPCount++; |
POICount--; |
break; |
case POINT_TYPE_POI: |
default: |
// nothing to do |
break; |
} |
break; |
} |
memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
NaviData.WaypointNumber = WPCount; |
return pPoint->Index; |
} |
else return(0); |
} |
// returns the pointer to the first waypoint within the list |
Point_t* PointList_WPBegin(void) |
{ |
u8 i; |
WPIndex = 0; // set list position invalid |
if(WPActive == FALSE) return(NULL); |
POIIndex = 0; // set invalid POI |
if(PointCount > 0) |
{ |
// search for first wp in list |
for(i = 0; i <MAX_LIST_LEN; i++) |
{ |
if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
{ |
WPIndex = i + 1; |
break; |
} |
} |
if(WPIndex) // found a WP in the list |
{ |
NaviData.WaypointIndex = 1; |
// update index to POI |
if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
else POIIndex = 0; |
} |
else // some points in the list but no WP found |
{ |
NaviData.WaypointIndex = 0; |
//Check for an existing POI |
for(i = 0; i < MAX_LIST_LEN; i++) |
{ |
if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
{ |
POIIndex = i + 1; |
break; |
} |
} |
} |
} |
else // no point in the list |
{ |
POIIndex = 0; |
NaviData.WaypointIndex = 0; |
} |
if(WPIndex) return(&(PointList[WPIndex-1])); |
else return(NULL); |
} |
// returns the last waypoint |
Point_t* PointList_WPEnd(void) |
{ |
u8 i; |
WPIndex = 0; // set list position invalid |
POIIndex = 0; // set invalid |
if(WPActive == FALSE) return(NULL); |
if(PointCount > 0) |
{ |
// search backward! |
for(i = 1; i <= MAX_LIST_LEN; i++) |
{ |
if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
{ |
WPIndex = MAX_LIST_LEN - i + 1; |
break; |
} |
} |
if(WPIndex) // found a WP within the list |
{ |
NaviData.WaypointIndex = WPCount; |
if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
else POIIndex = 0; |
} |
else // list contains some points but no WP in the list |
{ |
// search backward for a POI! |
for(i = 1; i <= MAX_LIST_LEN; i++) |
{ |
if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
{ |
POIIndex = MAX_LIST_LEN - i + 1; |
break; |
} |
} |
NaviData.WaypointIndex = 0; |
} |
} |
else // no point in the list |
{ |
POIIndex = 0; |
NaviData.WaypointIndex = 0; |
} |
if(WPIndex) return(&(PointList[WPIndex-1])); |
else return(NULL); |
} |
// returns a pointer to the next waypoint or NULL if the end of the list has been reached |
Point_t* PointList_WPNext(void) |
{ |
u8 wp_found = 0; |
if(WPActive == FALSE) return(NULL); |
if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
{ |
u8 i; |
for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
{ |
if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
{ |
wp_found = i+1; |
break; |
} |
} |
} |
if(wp_found) |
{ |
WPIndex = wp_found; // update list position |
NaviData.WaypointIndex++; |
if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
else POIIndex = 0; |
return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
} |
else |
{ // no next wp found |
NaviData.WaypointIndex = 0; |
POIIndex = 0; |
return(NULL); |
} |
} |
void PointList_WPActive(u8 set) |
{ |
if(set) |
{ |
WPActive = TRUE; |
PointList_WPBegin(); // uopdates POI index |
} |
else |
{ |
WPActive = FALSE; |
POIIndex = 0; // disable POI also |
} |
} |
Point_t* PointList_GetPOI(void) |
{ |
return PointList_GetAt(POIIndex); |
} |
/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/waypoints.h |
---|
0,0 → 1,56 |
#ifndef _WAYPOINTS_H |
#define _WAYPOINTS_H |
//#include "ubx.h" |
#define POINT_TYPE_INVALID 255 |
#define POINT_TYPE_WP 0 |
#define POINT_TYPE_POI 1 |
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 |
{ |
GPS_Pos_t Position; // the gps position of the waypoint, see ubx.h for details |
s16 Heading; // orientation, 0 no action, 1...360 fix heading, neg. = Index to POI in WP List |
u8 ToleranceRadius; // in meters, if the MK is within that range around the target, then the next target is triggered |
u8 HoldTime; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
u8 Event_Flag; // future implementation |
u8 Index; // to indentify different waypoints, workaround for bad communications PC <-> NC |
u8 Type; // typeof Waypoint |
u8 WP_EventChannelValue; // |
u8 AltitudeRate; // rate to change the setpoint |
u8 reserve[8]; // reserve |
} __attribute__((packed)) Point_t; |
// Init List, return TRUE on success |
u8 PointList_Init(void); |
// Clear List, return TRUE on success |
u8 PointList_Clear(void); |
// Returns number of points in the list |
u8 PointList_GetCount(void); |
// return pointer to point at position |
Point_t* PointList_GetAt(u8 index); |
// set a point in the list at index, returns its index on success, else 0 |
u8 PointList_SetAt(Point_t* pPoint); |
// goto the first WP in the list and return pointer to it |
Point_t* PointList_WPBegin(void); |
// goto the last WP in the list and return pointer to it |
Point_t* PointList_WPEnd(void); |
// goto next WP in the list and return pointer to it |
Point_t* PointList_WPNext(void); |
// enables/disables waypoint function |
void PointList_WPActive(u8 set); |
// returns pointer to actual POI |
Point_t* PointList_GetPOI(void); |
#endif // _WAYPOINTS_H |