Bsongis/9x fixes (#4463)

[9x] Fixes + make firmware target added
This commit is contained in:
Bertrand Songis
2017-02-17 17:11:38 +01:00
committed by GitHub
parent 6106d1b228
commit 3e84e7930c
20 changed files with 209 additions and 187 deletions
+1
View File
@@ -2,6 +2,7 @@ option(SP22 "SmartieParts 2.2 Backlight support" OFF)
option(PWM_BACKLIGHT "PWM Backlight" OFF)
set(ARCH AVR)
set(MCU atmega64)
set(AVRDUDE_MCU m64)
string(TOLOWER ${PCB} FLAVOUR)
set(EEPROM_VARIANT_NEEDED ON)
set(EEPROM EEPROM_RLC)
+27 -37
View File
@@ -23,53 +23,51 @@
#if defined(ROTARY_ENCODER_NAVIGATION)
#if defined(TELEMETREZ)
uint8_t TrotCount ; // TeZ version
uint8_t LastTrotCount ; // TeZ version
uint8_t RotEncoder ;
#define ROTENC_DOWN() (RotEncoder != 0)
uint8_t TrotCount; // TeZ version
uint8_t LastTrotCount; // TeZ version
uint8_t RotEncoder;
#else
uint8_t RotPosition ;
int8_t LastRotaryValue ;
int8_t Rotary_diff ;
int8_t RotaryControl ;
uint8_t RotEncoder ;
#define ROTENC_DOWN() (RotEncoder & 0x20)
uint8_t RotPosition;
int8_t LastRotaryValue;
int8_t Rotary_diff;
int8_t RotaryControl;
uint8_t RotEncoder;
#endif
void rotencPoll()
{
#if defined(TELEMETREZ)
if (TrotCount != LastTrotCount) {
rotencValue[0] = LastTrotCount = TrotCount ;
rotencValue[0] = LastTrotCount = TrotCount;
}
#else
// Rotary Encoder polling
PORTA = 0 ; // No pullups
DDRA = 0x1F ; // Top 3 bits input
PORTA = 0; // No pullups
DDRA = 0x1F; // Top 3 bits input
asm(" rjmp 1f") ;
asm("1:") ;
asm(" rjmp 1f");
asm("1:");
uint8_t rotary ;
rotary = PINA ;
DDRA = 0xFF ; // Back to all outputs
rotary &= 0xE0 ;
uint8_t rotary;
rotary = PINA;
DDRA = 0xFF; // Back to all outputs
rotary &= 0xE0;
RotEncoder = rotary ; // just read the lcd pin
RotEncoder = rotary; // just read the lcd pin
rotary &= 0xDF ;
rotary &= 0xDF;
if ( rotary != RotPosition ) {
uint8_t x ;
x = RotPosition & 0x40 ;
x <<= 1 ;
x ^= rotary & 0x80 ;
uint8_t x;
x = RotPosition & 0x40;
x <<= 1;
x ^= rotary & 0x80;
if ( x ) {
rotencValue[0] -= 1 ;
rotencValue[0] -= 1;
}
else {
rotencValue[0] += 1 ;
rotencValue[0] += 1;
}
RotPosition = rotary ;
RotPosition = rotary;
}
#endif // TELEMETREZ
}
@@ -140,14 +138,6 @@ void boardInit()
#endif // !defined(SIMU)
}
#ifndef SIMU
FORCEINLINE
#endif
uint8_t keyDown()
{
return ((~PINB) & 0x7E) | ROTENC_DOWN();
}
#if !defined(SIMU) && (defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED))
uint8_t pf7_digital[MUX_PF7_DIGITAL_MAX - MUX_PF7_DIGITAL_MIN + 1];
/**
@@ -306,7 +296,7 @@ void readKeysAndTrims()
#if defined(NAVIGATION_STICKS)
if (~PINB & 0x7E) {
StickScrollTimer = STICK_SCROLL_TIMEOUT ;
StickScrollTimer = STICK_SCROLL_TIMEOUT;
}
#endif
}
+17
View File
@@ -183,7 +183,24 @@ bool checkSlaveMode();
#define INP_G_RF_POW 1
#define INP_G_RuddDR 0
// Rotary Encoder driver
#if defined(ROTARY_ENCODER_NAVIGATION)
extern uint8_t RotEncoder;
#if defined(TELEMETREZ)
#define ROTENC_DOWN() (RotEncoder != 0)
#else
#define ROTENC_DOWN() (RotEncoder & 0x20)
#endif
#else
#define ROTENC_DOWN() (0)
#endif
// Keys driver
inline uint8_t keyDown()
{
return ((~PINB) & 0x7E) | ROTENC_DOWN();
}
#if defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED)
enum MuxInput {
MUX_BATT,
+1 -5
View File
@@ -5,7 +5,7 @@ option(BOLD "Bold font" ON)
option(BATTGRAPH "Battery graph" OFF)
option(HAPTIC "Haptic support" OFF)
set(TELEMETRY_TYPES NONE/MAVLINK/ARDUPILOT/FRSKY/FRSKY_SPORT/TELEMETREZ/NMEA)
set(TELEMETRY_TYPES NONE MAVLINK ARDUPILOT FRSKY FRSKY_SPORT TELEMETREZ NMEA)
set(TELEMETRY "NONE" CACHE STRING "Telemetry Type (${TELEMETRY_TYPES})")
set_property(CACHE TELEMETRY PROPERTY STRINGS ${TELEMETRY_TYPES})
@@ -129,7 +129,3 @@ if(TELEMETRY STREQUAL FRSKY OR TELEMETRY STREQUAL FRSKY_SPORT OR TELEMETRY STREQ
math(EXPR EEPROM_VARIANT ${EEPROM_VARIANT}+${FRSKY_VARIANT})
endif()
add_definitions(-DTIMERS=2)
if(EEPROM_VARIANT_NEEDED)
add_definitions(-DEEPROM_VARIANT=${EEPROM_VARIANT})
endif()
+26 -2
View File
@@ -18,6 +18,31 @@
* GNU General Public License for more details.
*/
#if defined(SIMU)
extern volatile unsigned char pina, pinb, pinc, pind, pine, pinf, ping, pinh, pinj, pinl;
#define PINA ~pina
#define PINB ~pinb
#define PINC ~pinc
#define PIND ~pind
#define PINE ~pine
#define PINF ~pinf
#define PING ~ping
#define PINH ~pinh
#define PINJ ~pinj
#define PINL ~pinl
#else
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "pgmtypes.h"
#include <avr/eeprom.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL // 16 MHz
#include <util/delay.h>
#define pgm_read_adr(address_short) pgm_read_word(address_short)
#include <avr/wdt.h>
#endif
// ADC driver
#define NUM_POTS 3
#define NUM_SLIDERS 0
@@ -220,6 +245,5 @@ uint8_t eepromIsTransferComplete();
#define TLM_USART 0
#endif
void telemetryPortInit();
void telemetryPortInit(uint32_t baudrate);
void telemetryPortInitFromIndex(uint8_t index);
void telemetryPortInit(uint8_t baudrate);
void telemetryTransmitBuffer();
@@ -23,7 +23,9 @@
#if defined(TELEMETRY_FRSKY) || defined(TELEMETRY_MAVLINK)
enum SERIAL_BAUDS {// KEEP IN SYNC WITH GUI
// KEEP IN SYNC WITH GUI
enum SERIAL_BAUDS
{
BAUD_4800 = 0,
BAUD_9600,
BAUD_14400,
@@ -101,7 +103,8 @@ ISR(USART_RX_vect_N(TLM_USART))
UCSRB_N(TLM_USART) |= (1 << RXCIE_N(TLM_USART)); // enable Interrupt
}
static void uart_4800(void) {
static void uart_4800(void)
{
#undef BAUD
#define BAUD 4800
#include <util/setbaud.h>
@@ -114,7 +117,8 @@ static void uart_4800(void) {
#endif
}
static void uart_9600(void) {
FORCEINLINE void uart_9600(void)
{
#undef BAUD
#define BAUD 9600
#include <util/setbaud.h>
@@ -127,7 +131,8 @@ static void uart_9600(void) {
#endif
}
static void uart_14400(void) {
static void uart_14400(void)
{
#undef BAUD
#define BAUD 14400
#include <util/setbaud.h>
@@ -140,7 +145,8 @@ static void uart_14400(void) {
#endif
}
static void uart_19200(void) {
static void uart_19200(void)
{
#undef BAUD
#define BAUD 19200
#include <util/setbaud.h>
@@ -153,7 +159,8 @@ static void uart_19200(void) {
#endif
}
static void uart_38400(void) {
static void uart_38400(void)
{
#undef BAUD
#define BAUD 38400
#include <util/setbaud.h>
@@ -166,7 +173,8 @@ static void uart_38400(void) {
#endif
}
static void uart_57600(void) {
static void uart_57600(void)
{
#undef BAUD
#define BAUD 57600
#include <util/setbaud.h>
@@ -179,13 +187,15 @@ static void uart_57600(void) {
#endif
}
static void uart_58798(void) {
static void uart_58798(void)
{
UBRRH_N(TLM_USART) = 0;
UBRRL_N(TLM_USART) = 0x010;
UCSRA_N(TLM_USART) &= ~(1 << U2X_N(TLM_USART)); // disable double speed operation.
}
static void uart_76800(void) {
static void uart_76800(void)
{
#undef BAUD
#define BAUD 76800
#include <util/setbaud.h>
@@ -198,79 +208,42 @@ static void uart_76800(void) {
#endif
}
void telemetryPortInitFromIndex(uint8_t index) {
switch (index) {
case BAUD_4800:
telemetryPortInit(4800);
break;
case BAUD_9600:
telemetryPortInit(9600);
break;
case BAUD_14400:
telemetryPortInit(14400);
break;
case BAUD_19200:
telemetryPortInit(19200);
break;
case BAUD_38400:
telemetryPortInit(38400);
break;
case BAUD_57600:
telemetryPortInit(57600);
break;
case BAUD_58798:
telemetryPortInit(58798);
break;
case BAUD_76800:
telemetryPortInit(76800);
break;
}
}
void telemetryPortInit() {
telemetryPortInit(9600);
}
void telemetryPortInit(uint32_t baudrate)
{
#if !defined(SIMU)
FORCEINLINE void telemetryPortInit(uint8_t baudrate)
{
RXD_DDR_N(TLM_USART) &= ~(1 << RXD_DDR_PIN_N(TLM_USART)); // set RXD pin as input
RXD_PORT_N(TLM_USART) &= ~(1 << RXD_PORT_PIN_N(TLM_USART)); // disable pullup on RXD pin
switch (baudrate) {
case 4800:
uart_4800();
break;
case 9600:
uart_9600();
break;
case 14400:
uart_14400();
break;
case 19200:
uart_19200();
break;
case 38400:
uart_38400();
break;
case 57600:
uart_57600();
break;
case 58798:
uart_58798();
break;
case 76800:
uart_76800();
break;
default:
uart_57600();
break;
case BAUD_4800:
uart_4800();
break;
case BAUD_9600:
uart_9600();
break;
case BAUD_14400:
uart_14400();
break;
case BAUD_19200:
uart_19200();
break;
case BAUD_38400:
uart_38400();
break;
case BAUD_58798:
uart_58798();
break;
case BAUD_76800:
uart_76800();
break;
default:
uart_57600();
break;
}
// set 8N1
UCSRB_N(TLM_USART) = 0 | (0 << RXCIE_N(TLM_USART)) | (0 << TXCIE_N(TLM_USART)) | (0 << UDRIE_N(TLM_USART)) | (0 << RXEN_N(TLM_USART)) | (0 << TXEN_N(TLM_USART)) | (0 << UCSZ2_N(TLM_USART));
UCSRC_N(TLM_USART) = 0 | (1 << UCSZ1_N(TLM_USART)) | (1 << UCSZ0_N(TLM_USART));
while (UCSRA_N(TLM_USART) & (1 << RXC_N(TLM_USART))) UDR_N(TLM_USART); // flush receive buffer
// These should be running right from power up on a FrSky enabled '9X.
@@ -278,12 +251,17 @@ void telemetryPortInit(uint32_t baudrate)
telemetryEnableTx(); // enable FrSky-Telemetry emission
#endif
telemetryEnableRx(); // enable FrSky-Telemetry reception
#endif
}
#endif
void telemetryTransmitBuffer()
{
UCSRB_N(TLM_USART) |= (1 << UDRIE_N(TLM_USART)); // enable UDRE1 interrupt
UCSRB_N(TLM_USART) |= (1 << UDRIE_N(TLM_USART)); // enable UDRE1 interrupt
}
void telemetryPortInit()
{
telemetryPortInit(BAUD_9600);
}
#endif
@@ -1,5 +1,6 @@
set(ARCH AVR)
set(MCU atmega2560)
set(AVRDUDE_MCU m2560)
string(TOLOWER ${PCB} FLAVOUR)
set(EEPROM EEPROM_RLC)
add_definitions(-DEEPROM_VARIANT=0)
+4
View File
@@ -558,6 +558,10 @@ void lcdRefresh()
simuLcdRefresh = true;
}
void telemetryPortInit(uint8_t baudrate)
{
}
void telemetryPortInit()
{
}
-11
View File
@@ -250,16 +250,6 @@ extern void rxPdcUsart( void (*pChProcess)(uint8_t x) );
#define DDRE dummyport
#define DDRF dummyport
#define DDRG dummyport
#define PINA ~pina
#define PINB ~pinb
#define PINC ~pinc
#define PIND ~pind
#define PINE ~pine
#define PINF ~pinf
#define PING ~ping
#define PINH ~pinh
#define PINJ ~pinj
#define PINL ~pinl
#define EEMEM
#define UCSR0B dummyport
@@ -354,7 +344,6 @@ extern uint32_t Master_frequency;
#define __enable_irq()
#endif
extern volatile unsigned char pina, pinb, pinc, pind, pine, pinf, ping, pinh, pinj, pinl;
extern uint8_t portb, portc, porth, dummyport;
extern uint16_t dummyport16;
extern uint8_t main_thread_running;