Stripped ^M (CR's) from end of all lines in board_gruvin9x.cpp

(Serves as first test commit for me, also.)
This commit is contained in:
gruvin
2012-08-18 11:35:08 +00:00
parent 640a4c21dc
commit bec173556d
+279 -279
View File
@@ -1,142 +1,142 @@
/* /*
* Authors (alphabetical order) * Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com> * - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com> * - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv * - Erez Raviv
* - Jean-Pierre Parisy * - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de> * - Karl Szmutny <shadow@privy.de>
* - Michael Blandford * - Michael Blandford
* - Michal Hlavinka * - Michal Hlavinka
* - Pat Mackenzie * - Pat Mackenzie
* - Philip Moss * - Philip Moss
* - Rob Thomson * - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com> * - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer * - Thomas Husterer
* *
* open9x is based on code named * open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/, * er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by * and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ * Thomas Husterer, th9x: http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
*/ */
#include "open9x.h" #include "open9x.h"
#ifdef SDCARD #ifdef SDCARD
uint8_t g_ms100 = 0; // global to allow time set function to reset to zero uint8_t g_ms100 = 0; // global to allow time set function to reset to zero
#endif #endif
#ifndef SIMU #ifndef SIMU
inline void board_init() inline void board_init()
{ {
// Set up I/O port data directions and initial states // Set up I/O port data directions and initial states
DDRA = 0xff; PORTA = 0x00; // LCD data DDRA = 0xff; PORTA = 0x00; // LCD data
DDRB = 0b11000111; PORTB = 0b00111111; // 7:SPKR, 6:PPM_OUT, 5:TrainSW, 4:IDL2_SW, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS] DDRB = 0b11000111; PORTB = 0b00111111; // 7:SPKR, 6:PPM_OUT, 5:TrainSW, 4:IDL2_SW, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS]
DDRC = 0x3f; PORTC = 0xc0; // 7:AilDR, 6:EleDR, LCD[5,4,3,2,1], 0:BackLight DDRC = 0x3f; PORTC = 0xc0; // 7:AilDR, 6:EleDR, LCD[5,4,3,2,1], 0:BackLight
DDRD = 0b11000000; PORTD = 0b11111100; // 7:VIB, 6:LED BL, 5:RENC2_PUSH, 4:RENC1_PUSH, 3:RENC2_B, 2:RENC2_A, 1:I2C_SDA, 0:I2C_SCL DDRD = 0b11000000; PORTD = 0b11111100; // 7:VIB, 6:LED BL, 5:RENC2_PUSH, 4:RENC1_PUSH, 3:RENC2_B, 2:RENC2_A, 1:I2C_SDA, 0:I2C_SCL
DDRE = 0b00001010; PORTE = 0b11110100; // 7:PPM_IN, 6: RENC1_B, 5:RENC1_A, 4:USB_DNEG, 3:BUZZER, 2:USB_DPOS, 1:TELEM_TX, 0:TELEM_RX(pull-up off) DDRE = 0b00001010; PORTE = 0b11110100; // 7:PPM_IN, 6: RENC1_B, 5:RENC1_A, 4:USB_DNEG, 3:BUZZER, 2:USB_DPOS, 1:TELEM_TX, 0:TELEM_RX(pull-up off)
DDRF = 0x00; PORTF = 0x00; // 7-4:JTAG, 3:ADC_REF_1.2V input, 2-0:ADC_SPARE_2-0 DDRF = 0x00; PORTF = 0x00; // 7-4:JTAG, 3:ADC_REF_1.2V input, 2-0:ADC_SPARE_2-0
DDRG = 0b00010000; PORTG = 0xff; // 7-6:N/A, 5:GearSW, 4: Sim_Ctrl[out], 3:IDL1_Sw, 2:TCut_Sw, 1:RF_Power[in], 0: RudDr_Sw DDRG = 0b00010000; PORTG = 0xff; // 7-6:N/A, 5:GearSW, 4: Sim_Ctrl[out], 3:IDL1_Sw, 2:TCut_Sw, 1:RF_Power[in], 0: RudDr_Sw
DDRH = 0b00110000; PORTH = 0b11011111; // 7:0 Spare port [6:SOMO14D-BUSY 5:SOMO14D-DATA 4:SOMO14D-CLK] [2:VIB_OPTION -- setting to input for now] DDRH = 0b00110000; PORTH = 0b11011111; // 7:0 Spare port [6:SOMO14D-BUSY 5:SOMO14D-DATA 4:SOMO14D-CLK] [2:VIB_OPTION -- setting to input for now]
DDRJ = 0x00; PORTJ = 0xff; // 7-0:Trim switch inputs DDRJ = 0x00; PORTJ = 0xff; // 7-0:Trim switch inputs
DDRK = 0x00; PORTK = 0x00; // anain. No pull-ups! DDRK = 0x00; PORTK = 0x00; // anain. No pull-ups!
#ifdef REV0 #ifdef REV0
DDRL = 0x80; PORTL = 0x7f; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: User Button inputs DDRL = 0x80; PORTL = 0x7f; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: User Button inputs
#else #else
DDRL = 0x80; PORTL = 0xff; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: User Button inputs DDRL = 0x80; PORTL = 0xff; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: User Button inputs
#endif #endif
ADMUX=ADC_VREF_TYPE; ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering) ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering)
ADCSRB=(1<<MUX5); ADCSRB=(1<<MUX5);
/**** Set up timer/counter 0 ****/ /**** Set up timer/counter 0 ****/
/** Move old 64A Timer0 functions to Timer2 and use WGM on OC0(A) (PB7) for spkear tone output **/ /** Move old 64A Timer0 functions to Timer2 and use WGM on OC0(A) (PB7) for spkear tone output **/
// TCNT0 10ms = 16MHz/1024/156(.25) periodic timer (100ms interval) // TCNT0 10ms = 16MHz/1024/156(.25) periodic timer (100ms interval)
// cycles at 9.984ms but includes 1:4 duty cycle correction to /157 to average at 10.0ms // cycles at 9.984ms but includes 1:4 duty cycle correction to /157 to average at 10.0ms
TCCR2B = (0b111 << CS20); // Norm mode, clk/1024 (differs from ATmega64 chip) TCCR2B = (0b111 << CS20); // Norm mode, clk/1024 (differs from ATmega64 chip)
OCR2A = 156; OCR2A = 156;
TIMSK2 |= (1<<OCIE2A) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts TIMSK2 |= (1<<OCIE2A) | (1<<TOIE2); // Enable Output-Compare and Overflow interrrupts
// Set up Phase correct Waveform Gen. mode, at clk/64 = 250,000 counts/second // Set up Phase correct Waveform Gen. mode, at clk/64 = 250,000 counts/second
// (Higher speed allows for finer control of frquencies in the audio range.) // (Higher speed allows for finer control of frquencies in the audio range.)
// Used for audio tone generation // Used for audio tone generation
TCCR0B = (1<<WGM02) | (0b011 << CS00); TCCR0B = (1<<WGM02) | (0b011 << CS00);
TCCR0A = (0b01<<WGM00); TCCR0A = (0b01<<WGM00);
#if defined(SDCARD) #if defined(SDCARD)
// Initialise global unix timestamp with current time from RTC chip on SD card interface // Initialise global unix timestamp with current time from RTC chip on SD card interface
RTC rtc = {0,0,0,0,0,0,0}; RTC rtc = {0,0,0,0,0,0,0};
struct gtm utm; struct gtm utm;
rtc_gettime(&rtc); rtc_gettime(&rtc);
utm.tm_year = rtc.year - 1900; utm.tm_year = rtc.year - 1900;
utm.tm_mon = rtc.month - 1; utm.tm_mon = rtc.month - 1;
utm.tm_mday = rtc.mday; utm.tm_mday = rtc.mday;
utm.tm_hour = rtc.hour; utm.tm_hour = rtc.hour;
utm.tm_min = rtc.min; utm.tm_min = rtc.min;
utm.tm_sec = rtc.sec; utm.tm_sec = rtc.sec;
utm.tm_wday = rtc.wday - 1; utm.tm_wday = rtc.wday - 1;
g_unixTime = gmktime(&utm); g_unixTime = gmktime(&utm);
#endif #endif
/***************************************************/ /***************************************************/
/* Rotary encoder interrupt set-up (V4 board only) */ /* Rotary encoder interrupt set-up (V4 board only) */
// All external interrupts initialise to disabled. But maybe not after // All external interrupts initialise to disabled. But maybe not after
// a WDT or BOD event? So to be safe ... // a WDT or BOD event? So to be safe ...
EIMSK = 0; // disable ALL external interrupts. EIMSK = 0; // disable ALL external interrupts.
// encoder 1 // encoder 1
EICRB = (1<<ISC60) | (1<<ISC50); // 01 = interrupt on any edge EICRB = (1<<ISC60) | (1<<ISC50); // 01 = interrupt on any edge
EIFR = (3<<INTF5); // clear the int. flag in case it got set when changing modes EIFR = (3<<INTF5); // clear the int. flag in case it got set when changing modes
// encoder 2 // encoder 2
EICRA = (1<<ISC30) | (1<<ISC20); // do the same for encoder 1 EICRA = (1<<ISC30) | (1<<ISC20); // do the same for encoder 1
EIFR = (3<<INTF2); EIFR = (3<<INTF2);
#if defined(EXTRA_ROTARY_ENCODERS) #if defined(EXTRA_ROTARY_ENCODERS)
EIMSK = (3<<INT5); // enable the ONE rot. enc. ext. int. pairs. EIMSK = (3<<INT5); // enable the ONE rot. enc. ext. int. pairs.
#else #else
EIMSK = (3<<INT5) | (3<<INT2); // enable the two rot. enc. ext. int. pairs. EIMSK = (3<<INT5) | (3<<INT2); // enable the two rot. enc. ext. int. pairs.
#endif #endif
/***************************************************/ /***************************************************/
/* /*
* SOMO set-up (V4 board only) * SOMO set-up (V4 board only)
*/ */
OCR4A = 0x7d; OCR4A = 0x7d;
TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks) TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
/* Mixer interrupt */ /* Mixer interrupt */
OCR5A = 0x7d * 40; /* 20ms */ OCR5A = 0x7d * 40; /* 20ms */
TCCR5B = (1 << WGM52) | (3<<CS50); // CTC OCR1A, 16MHz / 64 (4us ticks) TCCR5B = (1 << WGM52) | (3<<CS50); // CTC OCR1A, 16MHz / 64 (4us ticks)
TIMSK5 |= (1<<OCIE5A); TIMSK5 |= (1<<OCIE5A);
#if defined(EXTRA_ROTARY_ENCODERS) #if defined(EXTRA_ROTARY_ENCODERS)
//configure uart1 here //configure uart1 here
DDRD &= ~(1 << 2); DDRD &= ~(1 << 2);
PORTD &= ~(1 << 2); PORTD &= ~(1 << 2);
#define EXTRA_ROTARY_ENCODERS_USART_BAUD 9600UL #define EXTRA_ROTARY_ENCODERS_USART_BAUD 9600UL
UBRR1 = F_CPU/(16*EXTRA_ROTARY_ENCODERS_USART_BAUD)-1; UBRR1 = F_CPU/(16*EXTRA_ROTARY_ENCODERS_USART_BAUD)-1;
//9 bit mode //9 bit mode
UCSR1C = (1<<USBS1)|(3<<UCSZ10); UCSR1C = (1<<USBS1)|(3<<UCSZ10);
UCSR1B = (1<<RXEN1)|(0<<TXEN1)|(1<<UCSZ12); UCSR1B = (1<<RXEN1)|(0<<TXEN1)|(1<<UCSZ12);
UCSR1B |= 1 << RXCIE1; //enable interrupt on rx UCSR1B |= 1 << RXCIE1; //enable interrupt on rx
#endif //EXTRA_ROTARY_ENCODERS #endif //EXTRA_ROTARY_ENCODERS
} }
#if defined(EXTRA_ROTARY_ENCODERS) #if defined(EXTRA_ROTARY_ENCODERS)
uint8_t vpotToChange = 0; uint8_t vpotToChange = 0;
@@ -146,21 +146,21 @@ ISR(USART1_RX_vect)
{ {
//receive data from extension board //receive data from extension board
//bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value //bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value
/* Get status and 9th bit, then data */ /* Get status and 9th bit, then data */
/* from buffer */ /* from buffer */
uint16_t resh = UCSR1B; uint16_t resh = UCSR1B;
uint16_t resl = UDR1; uint16_t resl = UDR1;
uint16_t res = 0; uint16_t res = 0;
/* Filter the 9th bit, then return */ /* Filter the 9th bit, then return */
resh = (resh >> 1) & 0x01; resh = (resh >> 1) & 0x01;
res = ((resh << 8) | resl); res = ((resh << 8) | resl);
if((res == 0x180) | (res == 0x1C0)){ //button REb filter if((res == 0x180) | (res == 0x1C0)){ //button REb filter
keys[BTN_REa].input((res & 0x1C0) == 0x1C0, BTN_REa); keys[BTN_REa].input((res & 0x1C0) == 0x1C0, BTN_REa);
} else if((res & 0x100) == 0x100){ //rotary filter } else if((res & 0x100) == 0x100){ //rotary filter
vpotToChange = res & 0xEF; vpotToChange = res & 0xEF;
vpot_mod_state = 1; vpot_mod_state = 1;
} }
else { else {
if(vpot_mod_state & (vpotToChange < NUM_ROTARY_ENCODERS)) if(vpot_mod_state & (vpotToChange < NUM_ROTARY_ENCODERS))
{ {
@@ -173,141 +173,141 @@ ISR(USART1_RX_vect)
} }
} }
#endif //EXTRA_ROTARY_ENCODERS #endif //EXTRA_ROTARY_ENCODERS
#endif #endif
uint8_t check_soft_power() uint8_t check_soft_power()
{ {
#if !defined(SIMU) && !defined(REV0) #if !defined(SIMU) && !defined(REV0)
if ((PING & 0b00000010) && (~PINL & 0b01000000)) if ((PING & 0b00000010) && (~PINL & 0b01000000))
return e_power_off; return e_power_off;
#endif #endif
return e_power_on; return e_power_on;
} }
void soft_power_off() void soft_power_off()
{ {
#ifndef REV0 #ifndef REV0
PORTL = 0x7f; PORTL = 0x7f;
#endif #endif
} }
#ifndef SIMU #ifndef SIMU
FORCEINLINE FORCEINLINE
#endif #endif
uint8_t keyDown() uint8_t keyDown()
{ {
return (~PINL) & 0x3F; return (~PINL) & 0x3F;
} }
bool keyState(EnumKeys enuk) bool keyState(EnumKeys enuk)
{ {
uint8_t result = 0 ; uint8_t result = 0 ;
if (enuk < (int)DIM(keys)) if (enuk < (int)DIM(keys))
return keys[enuk].state() ? 1 : 0; return keys[enuk].state() ? 1 : 0;
switch(enuk){ switch(enuk){
case SW_ElevDR: case SW_ElevDR:
result = PINC & (1<<INP_C_ElevDR); result = PINC & (1<<INP_C_ElevDR);
break; break;
case SW_AileDR: case SW_AileDR:
result = PINC & (1<<INP_C_AileDR); result = PINC & (1<<INP_C_AileDR);
break; break;
case SW_RuddDR: case SW_RuddDR:
result = PING & (1<<INP_G_RuddDR); result = PING & (1<<INP_G_RuddDR);
break; break;
// INP_G_ID1 INP_B_ID2 // INP_G_ID1 INP_B_ID2
// id0 0 1 // id0 0 1
// id1 1 1 // id1 1 1
// id2 1 0 // id2 1 0
case SW_ID0: case SW_ID0:
result = !(PING & (1<<INP_G_ID1)); result = !(PING & (1<<INP_G_ID1));
break; break;
case SW_ID1: case SW_ID1:
result = (PING & (1<<INP_G_ID1))&& (PINB & (1<<INP_B_ID2)); result = (PING & (1<<INP_G_ID1))&& (PINB & (1<<INP_B_ID2));
break; break;
case SW_ID2: case SW_ID2:
result = !(PINB & (1<<INP_B_ID2)); result = !(PINB & (1<<INP_B_ID2));
break; break;
case SW_Gear: case SW_Gear:
result = PING & (1<<INP_G_Gear); result = PING & (1<<INP_G_Gear);
break; break;
case SW_ThrCt: case SW_ThrCt:
result = PING & (1<<INP_G_ThrCt); result = PING & (1<<INP_G_ThrCt);
break; break;
case SW_Trainer: case SW_Trainer:
result = PINB & (1<<INP_B_Trainer); result = PINB & (1<<INP_B_Trainer);
break; break;
default: default:
break; break;
} }
return result; return result;
} }
#ifndef SIMU #ifndef SIMU
FORCEINLINE FORCEINLINE
#endif #endif
void readKeysAndTrims() void readKeysAndTrims()
{ {
/* Original keys were connected to PORTB as follows: /* Original keys were connected to PORTB as follows:
Bit Key Bit Key
7 other use 7 other use
6 LEFT 6 LEFT
5 RIGHT 5 RIGHT
4 UP 4 UP
3 DOWN 3 DOWN
2 EXIT 2 EXIT
1 MENU 1 MENU
0 other use 0 other use
*/ */
uint8_t enuk = KEY_MENU; uint8_t enuk = KEY_MENU;
#if !defined(EXTRA_ROTARY_ENCODERS) #if !defined(EXTRA_ROTARY_ENCODERS)
keys[BTN_REa].input(~PIND & 0x20, BTN_REa); keys[BTN_REa].input(~PIND & 0x20, BTN_REa);
#endif //!EXTRA_ROTARY_ENCODERS #endif //!EXTRA_ROTARY_ENCODERS
keys[BTN_REb].input(~PIND & 0x10, BTN_REb); keys[BTN_REb].input(~PIND & 0x10, BTN_REb);
uint8_t tin = ~PINL; uint8_t tin = ~PINL;
uint8_t in; uint8_t in;
in = (tin & 0x0f) << 3; in = (tin & 0x0f) << 3;
in |= (tin & 0x30) >> 3; in |= (tin & 0x30) >> 3;
for(int i=1; i<7; i++) for(int i=1; i<7; i++)
{ {
//INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6 //INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6
keys[enuk].input(in & (1<<i),(EnumKeys)enuk); keys[enuk].input(in & (1<<i),(EnumKeys)enuk);
++enuk; ++enuk;
} }
// Trim switches ... // Trim switches ...
static const pm_uchar crossTrim[] PROGMEM ={ static const pm_uchar crossTrim[] PROGMEM ={
1<<INP_J_TRM_LH_DWN, 1<<INP_J_TRM_LH_DWN,
1<<INP_J_TRM_LH_UP, 1<<INP_J_TRM_LH_UP,
1<<INP_J_TRM_LV_DWN, 1<<INP_J_TRM_LV_DWN,
1<<INP_J_TRM_LV_UP, 1<<INP_J_TRM_LV_UP,
1<<INP_J_TRM_RV_DWN, 1<<INP_J_TRM_RV_DWN,
1<<INP_J_TRM_RV_UP, 1<<INP_J_TRM_RV_UP,
1<<INP_J_TRM_RH_DWN, 1<<INP_J_TRM_RH_DWN,
1<<INP_J_TRM_RH_UP 1<<INP_J_TRM_RH_UP
}; };
in = ~PINJ; in = ~PINJ;
for (int i=0; i<8; i++) { for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7 // INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk); keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk);
++enuk; ++enuk;
} }
} }