[Horus] SD Storage started. UI continued.

+ Some boyscout work on LCD functions
This commit is contained in:
Bertrand Songis
2015-10-22 07:10:19 +02:00
parent d353f3c388
commit c8f77fceec
270 changed files with 2403 additions and 2474 deletions
+388
View File
@@ -0,0 +1,388 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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 "../../opentx.h"
#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)
#else
uint8_t RotPosition ;
int8_t LastRotaryValue ;
int8_t Rotary_diff ;
int8_t RotaryControl ;
uint8_t RotEncoder ;
#define ROTENC_DOWN() (RotEncoder & 0x20)
#endif
void rotencPoll()
{
#if defined(TELEMETREZ)
if (TrotCount != LastTrotCount) {
g_rotenc[0] = LastTrotCount = TrotCount ;
}
#else
// Rotary Encoder polling
PORTA = 0 ; // No pullups
DDRA = 0x1F ; // Top 3 bits input
asm(" rjmp 1f") ;
asm("1:") ;
uint8_t rotary ;
rotary = PINA ;
DDRA = 0xFF ; // Back to all outputs
rotary &= 0xE0 ;
RotEncoder = rotary ; // just read the lcd pin
rotary &= 0xDF ;
if ( rotary != RotPosition ) {
uint8_t x ;
x = RotPosition & 0x40 ;
x <<= 1 ;
x ^= rotary & 0x80 ;
if ( x ) {
g_rotenc[0] -= 1 ;
}
else {
g_rotenc[0] += 1 ;
}
RotPosition = rotary ;
}
#endif // TELEMETREZ
}
#else
#define ROTENC_DOWN() (0)
#endif // ROTARY_ENCODER_NAVIGATION
#ifndef SIMU
inline void boardInit()
{
// Set up I/O port data directions and initial states
DDRA = 0xff; PORTA = 0x00; // LCD data
DDRB = 0x81; PORTB = 0x7e; //pullups keys+nc
#if defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED)
DDRC = 0xff; PORTC = 0x00;
#else
DDRC = 0x3e; PORTC = 0xc1; //pullups nc
#endif
DDRD = 0x00; PORTD = 0xff; //pullups keys
DDRE = (1<<OUT_E_BUZZER); PORTE = 0xff-(1<<OUT_E_BUZZER); //pullups + buzzer 0
DDRF = 0x00; PORTF = 0x00; //anain
DDRG = 0x14; PORTG = 0xfb; //pullups + SIM_CTL=1 = phonejack = ppm_in, Haptic output and off (0)
adcInit();
#if defined(CPUM2561)
TCCR2B = (0b111 << CS20); // Norm mode, clk/1024 (differs from ATmega64 chip)
OCR2A = 156;
TIMSK2 |= (1<<OCIE2A) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts
#else
// TCNT0 10ms = 16MHz/1024/156 periodic timer (9.984ms)
// (with 1:4 duty at 157 to average 10.0ms)
// Timer overflows at about 61Hz or once every 16ms.
TCCR0 = (0b111 << CS00); // Norm mode, clk/1024
OCR0 = 156;
#endif
#if defined(AUDIO) || defined(VOICE)
SET_TIMER_AUDIO_CTRL();
#if defined(CPUM2561)
OCR4A = 0xFF;
RESUME_AUDIO_INTERRUPT();
#else
TIMSK |= (1<<OCIE0) | (1<<TOIE0) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts
#endif
#elif defined(PWM_BACKLIGHT)
/** Smartieparts LED Backlight is connected to PORTB/pin7, which can be used as pwm output of timer2 **/
#if defined(CPUM2561)
#if defined(SP22)
TCCR0A = (1<<WGM00)|(1<<COM0A1)|(1<<COM0A0); // inv. pwm mode, clk/64
#else
TCCR0A = (1<<WGM00)|(1<<COM0A1); // pwm mode, clk/64
#endif
TCCR0B = (0b011<<CS00);
#else
#if defined(SP22)
TCCR2 = (0b011<<CS20)|(1<<WGM20)|(1<<COM21)|(1<<COM20); // inv. pwm mode, clk/64
#else
TCCR2 = (0b011<<CS20)|(1<<WGM20)|(1<<COM21); // pwm mode, clk/64
#endif
TIMSK |= (1<<OCIE0) | (1<<TOIE0); // Enable Output-Compare and Overflow interrrupts
#endif
#else
#if !defined(CPUM2561)
TIMSK |= (1<<OCIE0) | (1<<TOIE0); // Enable Output-Compare and Overflow interrrupts
#endif
#endif
}
#endif
#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];
/**
* Update ADC PF7 using 14051 multiplexer
* X0 : Battery voltage
* X1 : AIL SW
* X2 : THR SW
* X3 : TRIM LEFT VERTICAL UP
* X4 : TRIM LEFT VERTICAL DOWN
*/
void processMultiplexAna()
{
static uint8_t muxNum = MUX_BATT;
uint8_t nextMuxNum = muxNum-1;
switch (muxNum) {
case MUX_BATT:
s_anaFilt[TX_VOLTAGE] = s_anaFilt[X14051];
nextMuxNum = MUX_MAX;
break;
case MUX_AIL:
case MUX_THR:
case MUX_TRM_LV_UP:
case MUX_TRM_LV_DWN:
// Digital switch depend from input voltage
// take half voltage to determine digital state
pf7_digital[muxNum - MUX_PF7_DIGITAL_MIN] = (s_anaFilt[X14051] >= (s_anaFilt[TX_VOLTAGE] / 2)) ? 1 : 0;
break;
}
// set the mux number for the next ADC convert,
// stabilize voltage before ADC read.
muxNum = nextMuxNum;
PORTC &= ~((1 << PC7) | (1 << PC6) | (1 << PC0));
if(muxNum & 1) PORTC |= (1 << PC7); // Mux CTRL A
if(muxNum & 2) PORTC |= (1 << PC6); // Mux CTRL B
if(muxNum & 4) PORTC |= (1 << PC0); // Mux CTRL C
}
#endif
#if !defined(SIMU) && (defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED))
#define THR_STATE() pf7_digital[PF7_THR]
#define AIL_STATE() pf7_digital[PF7_AIL]
#elif defined(JETI) || defined(FRSKY) || defined(ARDUPILOT) || defined(NMEA) || defined(MAVLINK)
#define THR_STATE() (PINC & (1<<INP_C_ThrCt))
#define AIL_STATE() (PINC & (1<<INP_C_AileDR))
#else
#define THR_STATE() (PINE & (1<<INP_E_ThrCt))
#define AIL_STATE() (PINE & (1<<INP_E_AileDR))
#endif
bool switchState(EnumKeys enuk)
{
uint8_t result = 0 ;
if (enuk < (int)DIM(keys))
return keys[enuk].state();
switch(enuk){
case SW_ELE:
result = PINE & (1<<INP_E_ElevDR);
break;
case SW_AIL:
result = AIL_STATE();
break;
case SW_RUD:
result = PING & (1<<INP_G_RuddDR);
break;
// INP_G_ID1 INP_E_ID2
// id0 0 1
// id1 1 1
// id2 1 0
case SW_ID0:
result = !(PING & (1<<INP_G_ID1));
break;
case SW_ID1:
result = (PING & (1<<INP_G_ID1)) && (PINE & (1<<INP_E_ID2));
break;
case SW_ID2:
result = !(PINE & (1<<INP_E_ID2));
break;
case SW_GEA:
result = PINE & (1<<INP_E_Gear);
break;
case SW_THR:
result = THR_STATE();
break;
case SW_TRN:
result = PINE & (1<<INP_E_Trainer);
break;
default:
break;
}
return result;
}
// Trim switches ...
uint8_t trimHelper(uint8_t negpin, uint8_t idx)
{
switch(idx){
case 0: return negpin & TRIMS_GPIO_PIN_LHL;
case 1: return negpin & TRIMS_GPIO_PIN_LHR;
#if !defined(SIMU) && defined(TELEMETRY_MOD_14051_SWAPPED)
case 2: return !pf7_digital[PF7_TRM_LV_DWN];
case 3: return !pf7_digital[PF7_TRM_LV_UP];
#else
case 2: return negpin & TRIMS_GPIO_PIN_LVD;
case 3: return negpin & TRIMS_GPIO_PIN_LVU;
#endif
case 4: return negpin & TRIMS_GPIO_PIN_RVD;
case 5: return negpin & TRIMS_GPIO_PIN_RVU;
case 6: return negpin & TRIMS_GPIO_PIN_RHL;
case 7: return negpin & TRIMS_GPIO_PIN_RHR;
default: return 0;
}
}
uint8_t trimDown(uint8_t idx)
{
return trimHelper(~PIND, idx);
}
FORCEINLINE void readKeysAndTrims()
{
uint8_t enuk = KEY_MENU;
// User buttons ...
uint8_t in = ~PINB;
for (int i=1; i<7; i++) {
keys[enuk].input(in & (1<<i));
++enuk;
}
// Trims ...
in = ~PIND;
for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(trimHelper(in, i));
++enuk;
}
#if defined(ROTARY_ENCODER_NAVIGATION)
keys[enuk].input(ROTENC_DOWN()); // Rotary Enc. Switch
#endif
#if defined(NAVIGATION_STICKS)
if (~PINB & 0x7E) {
StickScrollTimer = STICK_SCROLL_TIMEOUT ;
}
#endif
}
bool checkSlaveMode()
{
// no power -> only phone jack = slave mode
static bool lastSlaveMode = false;
static uint8_t checkDelay = 0;
if (IS_AUDIO_BUSY()) {
checkDelay = 20;
}
else if (checkDelay) {
--checkDelay;
}
else {
lastSlaveMode = (PING & (1<<INP_G_RF_POW));
}
return lastSlaveMode;
}
#if defined(PWM_BACKLIGHT)
// exponential PWM table for linear brightness
static const uint8_t pwmtable[16] PROGMEM =
{
0, 2, 3, 4, 6, 8, 11, 16, 23, 32, 45, 64, 90, 128, 181, 255
};
static uint8_t bl_target;
static uint8_t bl_current;
void backlightEnable()
{
bl_target = 15 - g_eeGeneral.blOnBright;
}
void backlightDisable()
{
bl_target = g_eeGeneral.blOffBright;
}
bool isBacklightEnable()
{
return (bl_target==g_eeGeneral.blOnBright);
}
void backlightFade() // called from per10ms()
{
if (bl_target != bl_current) {
#if defined(CPUM2561)
if (bl_target > bl_current)
OCR0A = pgm_read_byte(&pwmtable[++bl_current]);
else
OCR0A = pgm_read_byte(&pwmtable[--bl_current]);
#else
if (bl_target > bl_current)
OCR2 = pgm_read_byte(&pwmtable[++bl_current]);
else
OCR2 = pgm_read_byte(&pwmtable[--bl_current]);
#endif
}
}
#endif
+253
View File
@@ -0,0 +1,253 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*
*/
#ifndef board_stock_h
#define board_stock_h
#include "../common_avr/board_avr.h"
//
// elev thr
// LV RV
// 2 ^ 4 ^
// 1 2
// | rudd | aile
// <----X--3-> LH <----X--0-> RH
// 6 | 7 1 | 0
// | |
// 3 v 5 v
//
//PORTA 7 6 5 4 3 2 1 0
// O O O O O O O O
// ------------------------ LCD_DAT -----------------------
//
//PORTB 7 6 5 4 3 2 1 0
// O i i i i i i O
// light KEY_LFT KEY_RGT KEY_UP KEY_DWN KEY_EXT KEY_MEN PPM
//
//PORTC 7 6 5 4 3 2 1 0
// - - O O O O O -
// NC NC LCD_E LCD_RNW LCD_A0 LCD_RES LCD_CS1 NC
//
//PORTD 7 6 5 4 3 2 1 0
// i i i i i i i i
// TRM_D_DWN _UP TRM_C_DWN _UP TRM_B_DWN _UP TRM_A_DWN _UP
//
//PORTE 7 6 5 4 3 2 1 0
// i i i i O i i i
// PPM_IN ID2 Trainer Gear Buzzer ElevDR AileDR THRCT
//
//PORTF 7 6 5 4 3 2 1 0
// ai ai ai ai ai ai ai ai
// ANA_ BAT PITT_TRM HOV_THR HOV_PIT STCK_LH STCK_RV STCK_LV STCK_RH
// rud thro elev aile
//PORTG 7 6 5 4 3 2 1 0
// - - - O i i i
// SIM_CTL ID1 Haptic RF_POW RuddDR
// Keys
#define KEYS_GPIO_REG_MENU pinb
#define KEYS_GPIO_PIN_MENU (1<<1)
#define KEYS_GPIO_REG_EXIT pinb
#define KEYS_GPIO_PIN_EXIT (1<<2)
#define KEYS_GPIO_REG_RIGHT pinb
#define KEYS_GPIO_PIN_RIGHT (1<<5)
#define KEYS_GPIO_REG_LEFT pinb
#define KEYS_GPIO_PIN_LEFT (1<<6)
#define KEYS_GPIO_REG_UP pinb
#define KEYS_GPIO_PIN_UP (1<<4)
#define KEYS_GPIO_REG_DOWN pinb
#define KEYS_GPIO_PIN_DOWN (1<<3)
// Trims
#define TRIMS_GPIO_REG_LHL pind
#define TRIMS_GPIO_PIN_LHL (1<<6)
#define TRIMS_GPIO_REG_LVD pind
#define TRIMS_GPIO_PIN_LVD (1<<3)
#define TRIMS_GPIO_REG_RVU pind
#define TRIMS_GPIO_PIN_RVU (1<<4)
#define TRIMS_GPIO_REG_RHL pind
#define TRIMS_GPIO_PIN_RHL (1<<1)
#define TRIMS_GPIO_REG_LHR pind
#define TRIMS_GPIO_PIN_LHR (1<<7)
#define TRIMS_GPIO_REG_LVU pind
#define TRIMS_GPIO_PIN_LVU (1<<2)
#define TRIMS_GPIO_REG_RVD pind
#define TRIMS_GPIO_PIN_RVD (1<<5)
#define TRIMS_GPIO_REG_RHR pind
#define TRIMS_GPIO_PIN_RHR (1<<0)
#if defined(CPUM2561)
#define TIMER_16KHZ_VECT TIMER2_OVF_vect
#define COUNTER_16KHZ TCNT2
#define TIMER_10MS_VECT TIMER2_COMPA_vect
#define TIMER_10MS_COMPVAL OCR2A
#define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<<OCIE2A)
#define RESUME_10MS_INTERRUPT() TIMSK2 |= (1<<OCIE2A)
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
#define TIMER_AUDIO_VECT TIMER4_COMPA_vect
#define SET_TIMER_AUDIO_CTRL() TCCR4B = (1 << WGM42) | (0b010 << CS40)
#define PAUSE_AUDIO_INTERRUPT() TIMSK4 &= ~(1<<OCIE4A)
#define RESUME_AUDIO_INTERRUPT() TIMSK4 |= (1<<OCIE4A)
#else
#define TIMER_16KHZ_VECT TIMER0_OVF_vect
#define COUNTER_16KHZ TCNT0
#define TIMER_10MS_VECT TIMER0_COMP_vect
#define TIMER_10MS_COMPVAL OCR0
#define PAUSE_10MS_INTERRUPT() TIMSK &= ~(1<<OCIE0)
#define RESUME_10MS_INTERRUPT() TIMSK |= (1<<OCIE0)
#define PAUSE_PPMIN_INTERRUPT() ETIMSK &= ~(1<<TICIE3)
#define RESUME_PPMIN_INTERRUPT() ETIMSK |= (1<<TICIE3)
#define TIMER_AUDIO_VECT TIMER2_OVF_vect
#define SET_TIMER_AUDIO_CTRL() TCCR2 = (0b010 << CS00) // Norm mode, clk/8
#define PAUSE_AUDIO_INTERRUPT() TIMSK &= ~(1<<TOIE2)
#define RESUME_AUDIO_INTERRUPT() TIMSK |= (1<<TOIE2)
#endif
// Power driver (none)
#define pwrCheck() (e_power_on)
#define pwrOff()
#define UNEXPECTED_SHUTDOWN() (mcusr & (1 << WDRF))
// Trainer driver
bool checkSlaveMode();
#define OUT_G_SIM_CTL 4 // 1 : phone-jack=ppm_in
#define SLAVE_MODE() checkSlaveMode()
#define JACK_PPM_OUT() PORTG &= ~(1<<OUT_G_SIM_CTL)
#define JACK_PPM_IN() PORTG |= (1<<OUT_G_SIM_CTL)
// PWM Backlight driver
#define OUT_B_LIGHT 7
#if defined(PWM_BACKLIGHT)
void backlightEnable();
void backlightDisable();
bool isBacklightEnable();
void backlightFade();
#elif defined(SP22)
#define backlightEnable() PORTB &= ~(1<<OUT_B_LIGHT)
#define backlightDisable() PORTB |= (1<<OUT_B_LIGHT)
#define isBacklightEnable() (~PORTB & (1<<OUT_B_LIGHT))
#else
#define backlightEnable() PORTB |= (1<<OUT_B_LIGHT)
#define backlightDisable() PORTB &= ~(1<<OUT_B_LIGHT)
#define isBacklightEnable() (PORTB & (1<<OUT_B_LIGHT))
#endif
#define OUT_B_PPM 0
#define INP_E_PPM_IN 7
#define INP_E_ID2 6
#define INP_E_Trainer 5
#define INP_E_Gear 4
#define OUT_E_BUZZER 3
#define INP_E_ElevDR 2
#if defined(JETI) || defined(FRSKY) || defined(ARDUPILOT) || defined(NMEA) || defined(MAVLINK)
#define INP_C_ThrCt 6
#define INP_C_AileDR 7
#else
#define INP_E_ThrCt 0
#define INP_E_AileDR 1
#endif
#define INP_G_ID1 3
#define OUT_G_HAPTIC 2
#define INP_G_RF_POW 1
#define INP_G_RuddDR 0
// Keys driver
#if defined(TELEMETRY_MOD_14051) || defined(TELEMETRY_MOD_14051_SWAPPED)
enum MuxInput {
MUX_BATT,
MUX_AIL,
MUX_PF7_DIGITAL_MIN = MUX_AIL,
MUX_THR,
MUX_TRM_LV_UP,
MUX_TRM_LV_DWN,
MUX_PF7_DIGITAL_MAX = MUX_TRM_LV_DWN,
MUX_MAX = MUX_PF7_DIGITAL_MAX
};
enum Pf7Digital {
PF7_AIL = MUX_AIL - MUX_PF7_DIGITAL_MIN,
PF7_THR = MUX_THR - MUX_PF7_DIGITAL_MIN,
PF7_TRM_LV_UP = MUX_TRM_LV_UP - MUX_PF7_DIGITAL_MIN,
PF7_TRM_LV_DWN = MUX_TRM_LV_DWN - MUX_PF7_DIGITAL_MIN,
};
extern uint8_t pf7_digital[MUX_PF7_DIGITAL_MAX - MUX_PF7_DIGITAL_MIN + 1];
void processMultiplexAna();
#endif
#if defined(TELEMETRY_MOD_14051_SWAPPED)
#define TRIMS_PRESSED() (~PIND & ~0x0c || pf7_digital[PF7_TRM_LV_UP] || pf7_digital[PF7_TRM_LV_DWN])
#else
#define TRIMS_PRESSED() (~PIND)
#endif
#define KEYS_PRESSED() (~PINB)
// LCD driver
#define PORTA_LCD_DAT PORTA
#define PORTC_LCD_CTRL PORTC
#define OUT_C_LCD_E 5
#define OUT_C_LCD_RnW 4
#define OUT_C_LCD_A0 3
#define OUT_C_LCD_RES 2
#define OUT_C_LCD_CS1 1
// Rotary encoder driver
#if defined(ROTARY_ENCODER_NAVIGATION)
extern uint8_t RotEncoder ;
void rotencPoll();
#endif
// Haptic
#define hapticOn() PORTG |= (1 << OUT_G_HAPTIC)
#define hapticOff() PORTG &= ~(1 << OUT_G_HAPTIC)
// USB fake driver
#define usbPlugged() false
// Buzzer driver
#define buzzerOn() PORTE |= (1 << OUT_E_BUZZER)
#define buzzerOff() PORTE &= ~(1 << OUT_E_BUZZER)
// EEPROM driver
#if !defined(SIMU)
#define eepromReadBlock(a, b, c) eeprom_read_block(a, (const void *)b, c)
#endif
#endif
+219
View File
@@ -0,0 +1,219 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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 "opentx.h"
void lcdSendCtl(uint8_t val)
{
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
#if defined(LCD_MULTIPLEX)
DDRA = 0xFF; //Set LCD_DAT pins to output
#endif
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_A0);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
PORTA_LCD_DAT = val;
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
#if defined(LCD_MULTIPLEX)
DDRA = 0x00; //Set LCD_DAT pins to input
#endif
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
}
#if defined(PCBSTD) && defined(VOICE)
volatile uint8_t LcdLock ;
#define LCD_LOCK() LcdLock = 1
#define LCD_UNLOCK() LcdLock = 0
#else
#define LCD_LOCK()
#define LCD_UNLOCK()
#endif
const static pm_uchar lcdInitSequence[] PROGMEM =
{
//ST7565 eq. : KS0713, SED1565, S6B1713, SPLC501C, NT7532 /34 /38, TL03245
#if defined(LCD_ST7565R)
0xE2, //Initialize the internal functions
0xAE, //DON = 0: display OFF
0xA0, //ADC = 0: normal direction (SEG132->SEG1)
0xA6, //REV = 0: non-reverse display
0xA4, //EON = 0: normal display. non-entire
0xA2, //Select LCD bias
0xC8, //SHL = 1: reverse direction (COM64->COM1)
0x2F, //Control power circuit operation VC=VR=VF=1
0x25, //Select int resistance ratio R2 R1 R0 =5
0x81, //Set reference voltage Mode
0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
0xAF, //DON = 1: display ON
0x60 //Set the display start line to zero
#elif defined(LCD_ERC12864FSF)
0xE2, //Initialize the internal functions
0xAE, //DON = 0: display OFF
0xA1, //ADC = 1: reverse direction (SEG132->SEG1)
0xA6, //REV = 0: non-reverse display
0xA4, //EON = 0: normal display. non-entire
0xA3, //Select LCD bias
0xC0, //SHL = 0: normal direction (COM1->COM64)
0x2F, //Control power circuit operation VC=VR=VF=1
0x27, //Select int resistance ratio R2 R1 R0
0x81, //Set reference voltage Mode
0x2D, //24 SV5 SV4 SV3 SV2 SV1 SV0
0xAF //DON = 1: display ON
#elif defined(LCD_ST7920)
0x30, //Set 8-bit interface
0x36, //Repeat with graphics bit set to ON
0x0C, //Display ON, cursor and blink OFF
0x01, //Clear display, reset address
0x06 //Display ON, no cursor
#else //ST7565P (default 9x LCD)
0xE2, //Initialize the internal functions
0xAE, //DON = 0: display OFF
0xA1, //ADC = 1: reverse direction(SEG132->SEG1)
0xA6, //REV = 0: non-reverse display
0xA4, //EON = 0: normal display. non-entire
0xA2, //Select LCD bias=0
0xC0, //SHL = 0: normal direction (COM1->COM64)
0x2F, //Control power circuit operation VC=VR=VF=1
0x25, //Select int resistance ratio R2 R1 R0 =5
0x81, //Set reference voltage Mode
0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
0xAF //DON = 1: display ON
#endif
};
inline void lcdInit()
{
LCD_LOCK();
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD reset
_delay_us(2);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); //LCD normal operation
#if defined(LCD_ST7920)
_delay_ms(40);
#else
_delay_us(1500);
#endif
for (uint8_t i=0; i<DIM(lcdInitSequence); i++) {
lcdSendCtl(pgm_read_byte(&lcdInitSequence[i])) ;
#if defined(LCD_ST7920)
_delay_us(80);
#endif
}
#if defined(LCD_ERC12864FSF)
g_eeGeneral.contrast = 0x2D;
#else
g_eeGeneral.contrast = 0x22;
#endif
LCD_UNLOCK();
}
void lcdSetRefVolt(uint8_t val)
{
#if !defined(LCD_ST7920) // No contrast setting for ST7920
LCD_LOCK();
lcdSendCtl(0x81);
lcdSendCtl(val);
LCD_UNLOCK();
#endif
}
void lcdRefresh()
{
LCD_LOCK();
#if defined(LCD_ST7920)
uint8_t x_addr = 0;
uint8_t y_addr = 0;
uint16_t line_offset = 0;
uint8_t col_offset = 0;
uint16_t byte_offset = 0;
uint8_t bit_count = 0;
for (uint8_t y=0; y<64; y++) {
x_addr = 0;
//Convert coordinates to weirdly-arranged 128x64 screen (the ST7920 is mapped for 256x32 displays)
if (y > 31) {
y_addr = y - 32; //Because there are only 31 addressable lines in the ST7920
x_addr += 8; //so we overflow x (7 visible bytes per line) to reach the bottom half
}
else {
y_addr = y;
}
lcdSendCtl( 0x80 | y_addr ); //Set Vertical Address
_delay_us(49);
lcdSendCtl( 0x80 | x_addr ); //Set Horizontal Address
_delay_us(49);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0); //HIGH RS and LOW RW will put the LCD to
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW); //Write data register mode
bit_count = y & 0x07; //Count from 0 bis 7 -> 0=0, 1=1..7=7, 8=0, 9=1...
col_offset = 1 << bit_count; //Build a value for a AND operation with the vorrect bitposition
line_offset = ( y / 8 ) * 128; //On the ST7565 there are 8 lines with each 128 bytes width
for (coord_t x=0; x<16; x++) { //Walk through 16 bytes form left to right (128 Pixel)
byte_offset = line_offset + ( x * 8 ); //Calculate the position of the first byte im array
// adressing the bytes sequential and shift the bits at the correct position, afterwards a OR operation to get all bits in one byte
// the position of the LSB is the left-most position of the byte to the ST7920
PORTA_LCD_DAT = (((displayBuf[byte_offset] & col_offset) >> bit_count) << 7) | (((displayBuf[byte_offset + 1] & col_offset) >> bit_count) << 6) | (((displayBuf[byte_offset + 2] & col_offset) >> bit_count ) << 5) | (((displayBuf[byte_offset + 3] & col_offset) >> bit_count ) << 4) | (((displayBuf[byte_offset + 4] & col_offset) >> bit_count ) << 3) | (((displayBuf[byte_offset + 5] & col_offset) >> bit_count ) << 2) | (((displayBuf[byte_offset + 6] & col_offset) >> bit_count ) << 1) | (((displayBuf[byte_offset + 7] & col_offset) >> bit_count ) << 0);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
_delay_us(8);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
_delay_us(49);
}
}
#else //All other LCD
uint8_t * p = displayBuf;
for (uint8_t y=0; y < 8; y++) {
#if defined(LCD_ST7565R)
lcdSendCtl(0x01);
#else
lcdSendCtl(0x04);
#endif
lcdSendCtl(0x10); // Column addr 0
lcdSendCtl( y | 0xB0); //Page addr y
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
#if defined(LCD_MULTIPLEX)
DDRA = 0xFF; // Set LCD_DAT pins to output
#endif
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
for (coord_t x=LCD_W; x>0; --x) {
PORTA_LCD_DAT = *p++;
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
}
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
}
#endif
LCD_UNLOCK();
}
+155
View File
@@ -0,0 +1,155 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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 "../../opentx.h"
struct t_voice Voice ;
void pushPrompt(uint16_t value)
{
#ifdef SIMU
TRACE("playFile(\"%04d.ad4\")", value);
#endif
struct t_voice *vptr;
vptr = voiceaddress();
if (vptr->VoiceQueueCount < VOICE_Q_LENGTH) {
vptr->VoiceQueue[vptr->VoiceQueueInIndex++] = value;
vptr->VoiceQueueInIndex &= (VOICE_Q_LENGTH - 1);
vptr->VoiceQueueCount += 1;
}
}
void pushCustomPrompt(uint8_t value)
{
pushPrompt(PROMPT_CUSTOM_BASE + value);
}
void pushNumberPrompt(uint8_t value)
{
pushPrompt(PROMPT_I18N_BASE + value);
}
struct t_voice *voiceaddress()
{
return &Voice ;
}
void t_voice::voice_process(void)
{
if (Backlight)
VoiceLatch |= BACKLIGHT_BIT;
else
VoiceLatch &= ~BACKLIGHT_BIT;
if (VoiceState == V_IDLE) {
PORTB |= (1 << OUT_B_LIGHT); // Latch clock high
if (VoiceQueueCount) {
VoiceSerial = VoiceQueue[VoiceQueueOutIndex++];
VoiceQueueOutIndex &= (VOICE_Q_LENGTH - 1);
VoiceQueueCount -= 1;
VoiceTimer = 17;
if (VoiceSerial & 0x8000) { // Looking for sound volume 1F0-1F7
VoiceTimer = 40;
}
VoiceLatch &= ~VOICE_CLOCK_BIT & ~VOICE_DATA_BIT ;
if (VoiceSerial & 0x8000) {
VoiceLatch |= VOICE_DATA_BIT;
}
PORTA_LCD_DAT = VoiceLatch ; // Latch data set
PORTB &= ~(1<<OUT_B_LIGHT) ; // Latch clock low
VoiceCounter = 31;
VoiceState = V_CLOCKING;
}
else {
PORTA_LCD_DAT = VoiceLatch; // Latch data set
PORTB &= ~(1 << OUT_B_LIGHT); // Latch clock low
}
}
else if (VoiceState == V_STARTUP) {
PORTB |= (1<<OUT_B_LIGHT) ; // Latch clock high
VoiceLatch |= VOICE_CLOCK_BIT | VOICE_DATA_BIT ;
PORTA_LCD_DAT = VoiceLatch ; // Latch data set
if (g_blinkTmr10ms > 60) { // Give module 1.4 secs to initialise
VoiceState = V_WAIT_START_BUSY_OFF ;
}
PORTB &= ~(1<<OUT_B_LIGHT) ; // Latch clock low
}
else if (VoiceState != V_CLOCKING) {
uint8_t busy;
PORTA_LCD_DAT = VoiceLatch; // Latch data set
PORTB |= (1 << OUT_B_LIGHT); // Drive high,pullup enabled
DDRB &= ~(1 << OUT_B_LIGHT); // Change to input
// delay to allow input to settle
asm(" rjmp 1f");
asm("1:");
asm(" nop");
asm(" rjmp 1f");
asm("1:");
busy = PINB & 0x80;
DDRB |= (1 << OUT_B_LIGHT); // Change to output
// The next bit guarantees the backlight output gets clocked out
if (VoiceState == V_WAIT_BUSY_ON) { // check for busy processing here
if (busy == 0) { // Busy is active
VoiceState = V_WAIT_BUSY_OFF;
}
else {
if (--VoiceTimer == 0) {
VoiceState = V_WAIT_BUSY_OFF;
}
}
}
else if (VoiceState == V_WAIT_BUSY_OFF) { // check for busy processing here
if (busy) { // Busy is inactive
VoiceTimer = 3;
VoiceState = V_WAIT_BUSY_DELAY;
}
}
else if (VoiceState == V_WAIT_BUSY_DELAY) {
if (--VoiceTimer == 0) {
VoiceState = V_IDLE;
}
}
else if (VoiceState == V_WAIT_START_BUSY_OFF) { // check for busy processing here
if (busy) { // Busy is inactive
VoiceTimer = 20 ;
VoiceState = V_WAIT_BUSY_DELAY ;
}
}
PORTB &= ~(1 << OUT_B_LIGHT); // Latch clock low
}
}
+142
View File
@@ -0,0 +1,142 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*
*/
// Bits in VoiceLatch
#define VOICE_CLOCK_BIT 0x01
#define VOICE_DATA_BIT 0x02
#define BACKLIGHT_BIT 0x04
#define SPARE_BIT 0x08
#if defined(CPUM64)
#define VOICE_Q_LENGTH 8
#else
#define VOICE_Q_LENGTH 16
#endif
// Voice states
#define V_STARTUP 0
#define V_IDLE 1
#define V_CLOCKING 2
#define V_WAIT_BUSY_ON 3
#define V_WAIT_BUSY_OFF 4
#define V_WAIT_BUSY_DELAY 5
#define V_WAIT_START_BUSY_OFF 6
#define PROMPT_CUSTOM_BASE 0
#define PROMPT_I18N_BASE 256
#define PROMPT_SYSTEM_BASE 480
struct t_voice
{
uint16_t VoiceQueue[VOICE_Q_LENGTH] ;
uint8_t Backlight ;
uint8_t VoiceLatch ;
uint8_t VoiceCounter ;
uint8_t VoiceTimer ;
uint16_t VoiceSerial ;
uint8_t VoiceState ;
uint8_t VoiceQueueCount ;
uint8_t VoiceQueueInIndex ;
uint8_t VoiceQueueOutIndex ;
void voice_process( void ) ;
};
extern void pushPrompt(uint16_t value);
extern void pushCustomPrompt(uint8_t value);
extern void pushNumberPrompt(uint8_t value);
extern struct t_voice *voiceaddress( void ) ;
extern struct t_voice Voice ;
#define VOLUME_LEVEL_MAX 7
#define VOLUME_LEVEL_DEF 7
#define setVolume(v) pushPrompt((v) | 0xFFF0)
inline bool isPlaying()
{
#if defined(SIMU)
return false;
#else
return Voice.VoiceState != V_IDLE;
#endif
}
/*
* Handle the Voice output
* Check for LcdLocked (in interrupt), and voice_enabled
*/
#define VOICE_DRIVER() \
if ( LcdLock == 0 ) { /* LCD not in use */ \
struct t_voice *vptr; \
vptr = voiceaddress(); \
if ( vptr->VoiceState == V_CLOCKING ) { \
if ( vptr->VoiceTimer ) { \
vptr->VoiceTimer -= 1; \
} \
else { \
PORTB |= (1<<OUT_B_LIGHT); /* Latch clock high */ \
if ((vptr->VoiceCounter & 1) == 0) { \
vptr->VoiceLatch &= ~VOICE_DATA_BIT; \
if ( vptr->VoiceSerial & 0x4000 ) { \
vptr->VoiceLatch |= VOICE_DATA_BIT; \
} \
vptr->VoiceSerial <<= 1; \
} \
vptr->VoiceLatch ^= VOICE_CLOCK_BIT; \
PORTA_LCD_DAT = vptr->VoiceLatch; /* Latch data set */ \
PORTB &= ~(1<<OUT_B_LIGHT); /* Latch clock low */ \
if ( --vptr->VoiceCounter == 0 ) { \
vptr->VoiceState = V_WAIT_BUSY_ON; \
vptr->VoiceTimer = 5; /* 50 mS */ \
} \
} \
} \
}
#define I18N_PLAY_FUNCTION(lng, x, ...) void x(__VA_ARGS__)
#define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__)
#define PUSH_CUSTOM_PROMPT(p, ...) pushCustomPrompt((p))
#define PUSH_NUMBER_PROMPT(p) pushNumberPrompt((p))
#define PUSH_SYSTEM_PROMPT(p) pushNumberPrompt(PROMPT_SYSTEM_BASE-PROMPT_I18N_BASE+(p))
#define PLAY_NUMBER(n, u, a) playNumber((n), (u), (a))
#define PLAY_DURATION(d, att) playDuration((d))
#define PLAY_DURATION_ATT
#define PLAY_TIME
#define IS_PLAY_TIME() (0)
#define IS_PLAYING(id) (0) /* isPlaying() */
#define PLAY_VALUE(v, id) playValue((v))