Directory transmitter renamed to radio
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
MEGA2560 board
|
||||
|
||||
|
||||
======================= DESCRIPTION =======================
|
||||
|
||||
DIY radio wih :
|
||||
- Arduino MEGA2560 or compatible
|
||||
- Artronic LCD 128x64 ST7565R (and, in a second time : Digole LCD 128x64 ST9720)
|
||||
- Aurora9 gimballs
|
||||
- home made wood (or fiberglass) case
|
||||
- Gruvin9x features (soft-off, SD-Card, etc.) with some pins reassignment
|
||||
|
||||
Drawings (case, additional cards, wiring) and components listing will follow
|
||||
|
||||
|
||||
========================= STATUS ==========================
|
||||
LCD driver ST7565R : works
|
||||
Pins assignment : done (io_mega2560.h)
|
||||
Additional cards :
|
||||
- LCD driver (3.3V + backlight) : works
|
||||
- PPM + power management : in test
|
||||
- gimballs Op Amp : in test
|
||||
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#ifndef SIMU
|
||||
inline void boardInit() // Done 2013.10.09 : trims, keyboard, LCD, ID1+2 SW warning PORTF-3 (1.2V ADC_ref)
|
||||
{
|
||||
// Set up I/O port data directions and initial states
|
||||
DDRA = 0b11111111; PORTA = 0b00000000; // LCD data
|
||||
DDRB = 0b11000111; PORTB = 0b00111111; // 7:SPKR, 6:PPM_OUT, 5:TrainSW, 4:xxxxx, SDCARD[3:MISO 2:MOSI 1:SCK 0:CS]
|
||||
DDRC = 0b11111100; PORTC = 0b00000011; // LCD[7,6,5,4,3], 2:BackLight, 1:ID2_Sw, 0:ID1_Sw
|
||||
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)
|
||||
//DDRF = 0b00000000; PORTF = 0b00000000; // 7-4:JTAG, 3:ADC_REF_1.2V input, 2-0:ADC_SPARE_2-0
|
||||
DDRF = 0b00000000; PORTF = 0b11111111; // 7-0:Trim switch inputs
|
||||
|
||||
DDRG = 0b00010000; PORTG = 0b00111111; // 7-6:N/A, 5:GearSW, 4: Sim_Ctrl[out], 3:xxxxx, 2:TCut_Sw, 1:RF_Power[in], 0: RudDr_Sw
|
||||
DDRH = 0b10111000; PORTH = 0b11010111; // [7:0 DSM/PPM TX-caddy control. 1=PPM, 0=DSM ]
|
||||
// [6:SOMO14D-BUSY 5:SOMO14D-DATA 4:SOMO14D-CLK 3:SOMO14D-RESET]
|
||||
// [2:VIB_OPTION -- setting to input for now]
|
||||
// [1:TxD 0:RxD Spare serial port]
|
||||
//DDRJ = 0b00000000; PORTJ = 0b11111111; // 7-0:Trim switch inputs
|
||||
DDRK = 0b00000000; PORTK = 0b00000000; // Analogic input (no pull-ups)
|
||||
DDRL = 0b10000000; PORTL = 0b11111111; // 7: Hold_PWR_On (1=On, default Off), 6:Jack_Presence_TTL, 5-0: Keyboard inputs
|
||||
|
||||
ADMUX=ADC_VREF_TYPE;
|
||||
ADCSRA=0x85; // ADC enabled, pre-scaler division=32 (no interrupt, no auto-triggering)
|
||||
ADCSRB=(1<<MUX5);
|
||||
|
||||
/**** Set up timer/counter 0 ****/
|
||||
/** 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)
|
||||
// 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)
|
||||
OCR2A = 156;
|
||||
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
|
||||
// (Higher speed allows for finer control of frquencies in the audio range.)
|
||||
// Used for audio tone generation
|
||||
TCCR0B = (1<<WGM02) | (0b011 << CS00);
|
||||
TCCR0A = (0b01<<WGM00);
|
||||
|
||||
/***************************************************/
|
||||
/* Rotary encoder interrupt set-up */
|
||||
EIMSK = 0; // disable ALL external interrupts.
|
||||
// encoder 1
|
||||
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
|
||||
// encoder 2
|
||||
EICRA = (1<<ISC30) | (1<<ISC20); // do the same for encoder 1
|
||||
EIFR = (3<<INTF2);
|
||||
EIMSK = (3<<INT5) | (3<<INT2); // enable the two rot. enc. ext. int. pairs.
|
||||
/***************************************************/
|
||||
|
||||
#if defined (VOICE)
|
||||
/*
|
||||
* SOMO set-up (V4 board only)
|
||||
*/
|
||||
OCR4A = 0x1F4; //2ms
|
||||
TCCR4B = (1 << WGM42) | (0b011 << CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
|
||||
TIMSK4 |= (1<<OCIE4A); // Start the interrupt so the unit reset can occur
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif // !SIMU
|
||||
|
||||
uint8_t pwrCheck()
|
||||
{
|
||||
#if !defined(SIMU) && !defined(REV0)
|
||||
if ((PING & 0b00000010) && (~PINL & 0b01000000))
|
||||
return e_power_off;
|
||||
#endif
|
||||
return e_power_on;
|
||||
}
|
||||
|
||||
void pwrOff()
|
||||
{
|
||||
#ifndef REV0
|
||||
PORTL = 0x7f;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ROTARY_ENCODERS <= 2
|
||||
#define ROTENC_DOWN() ((~PIND & 0x20) || (~PIND & 0x10))
|
||||
#else
|
||||
#define ROTENC_DOWN() (0)
|
||||
#endif
|
||||
|
||||
FORCEINLINE uint8_t keyDown()
|
||||
{
|
||||
return ((~PINL) & 0x3F) || ROTENC_DOWN();
|
||||
}
|
||||
|
||||
bool switchState(EnumKeys enuk)
|
||||
{
|
||||
uint8_t result = 0 ;
|
||||
|
||||
if (enuk < (int)DIM(keys))
|
||||
return keys[enuk].state() ? 1 : 0;
|
||||
|
||||
switch(enuk){
|
||||
//case SW_ELE:
|
||||
// result = PINC & (1<<INP_C_ElevDR);
|
||||
// break;
|
||||
|
||||
//case SW_AIL:
|
||||
// result = PINC & (1<<INP_C_AileDR);
|
||||
// break;
|
||||
|
||||
case SW_RUD:
|
||||
result = PING & (1<<INP_G_RuddDR);
|
||||
break;
|
||||
|
||||
// INP_G_ID1 INP_B_ID2
|
||||
// id0 0 1
|
||||
// id1 1 1
|
||||
// id2 1 0
|
||||
case SW_ID0:
|
||||
result = !(PINC & (1<<INP_C_ID1));
|
||||
break;
|
||||
|
||||
case SW_ID1:
|
||||
result = (PINC & (1<<INP_C_ID1))&& (PINC & (1<<INP_C_ID2));
|
||||
break;
|
||||
|
||||
case SW_ID2:
|
||||
result = !(PINC & (1<<INP_C_ID2));
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case SW_ID3:
|
||||
result = (calibratedStick[POT1+EXTRA_3POS-1] < 0);
|
||||
break;
|
||||
|
||||
case SW_ID4:
|
||||
result = (calibratedStick[POT1+EXTRA_3POS-1] == 0);
|
||||
break;
|
||||
|
||||
case SW_ID5:
|
||||
result = (calibratedStick[POT1+EXTRA_3POS-1] > 0);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SW_GEA:
|
||||
result = PING & (1<<INP_G_Gear);
|
||||
break;
|
||||
|
||||
case SW_THR:
|
||||
result = PING & (1<<INP_G_ThrCt);
|
||||
break;
|
||||
|
||||
case SW_TRN:
|
||||
result = PINB & (1<<INP_B_Trainer);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FORCEINLINE void readKeysAndTrims()
|
||||
{
|
||||
/* Original keys were connected to PORTB as follows:
|
||||
|
||||
Bit Key
|
||||
7 other use
|
||||
6 LEFT
|
||||
5 RIGHT
|
||||
4 UP
|
||||
3 DOWN
|
||||
2 EXIT
|
||||
1 MENU
|
||||
0 other use
|
||||
*/
|
||||
|
||||
uint8_t enuk = KEY_MENU;
|
||||
|
||||
keys[BTN_REa].input(~PIND & 0x20, BTN_REa);
|
||||
keys[BTN_REb].input(~PIND & 0x10, BTN_REb);
|
||||
|
||||
uint8_t tin = ~PINL;
|
||||
uint8_t in;
|
||||
in = (tin & 0x0f) << 3;
|
||||
in |= (tin & 0x30) >> 3;
|
||||
|
||||
for (int i=1; i<7; i++)
|
||||
{
|
||||
//INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6
|
||||
keys[enuk].input(in & (1<<i),(EnumKeys)enuk);
|
||||
++enuk;
|
||||
}
|
||||
|
||||
// Trim switches ...
|
||||
static const pm_uchar crossTrim[] PROGMEM ={
|
||||
1<<INP_F_TRM_LH_DWN,
|
||||
1<<INP_F_TRM_LH_UP,
|
||||
1<<INP_F_TRM_LV_DWN,
|
||||
1<<INP_F_TRM_LV_UP,
|
||||
1<<INP_F_TRM_RV_DWN,
|
||||
1<<INP_F_TRM_RV_UP,
|
||||
1<<INP_F_TRM_RH_DWN,
|
||||
1<<INP_F_TRM_RH_UP
|
||||
};
|
||||
|
||||
in = ~PINF;
|
||||
|
||||
for (int i=0; i<8; i++) {
|
||||
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
|
||||
keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk);
|
||||
++enuk;
|
||||
}
|
||||
}
|
||||
|
||||
ISR(INT2_vect)
|
||||
{
|
||||
uint8_t input = (PIND & 0x0C);
|
||||
if (input == 0 || input == 0x0C) incRotaryEncoder(0, -1);
|
||||
}
|
||||
|
||||
ISR(INT3_vect)
|
||||
{
|
||||
uint8_t input = (PIND & 0x0C);
|
||||
if (input == 0 || input == 0x0C) incRotaryEncoder(0, +1);
|
||||
}
|
||||
|
||||
ISR(INT5_vect)
|
||||
{
|
||||
uint8_t input = (PINE & 0x60);
|
||||
if (input == 0 || input == 0x60) incRotaryEncoder(1, +1);
|
||||
}
|
||||
|
||||
ISR(INT6_vect)
|
||||
{
|
||||
uint8_t input = (PINE & 0x60);
|
||||
if (input == 0 || input == 0x60) incRotaryEncoder(1, -1);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* 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_mega2560_h
|
||||
#define board_mega2560_h
|
||||
|
||||
#define GPIO_BUTTON_MENU pinl
|
||||
#define GPIO_BUTTON_EXIT pinl
|
||||
#define GPIO_BUTTON_RIGHT pinl
|
||||
#define GPIO_BUTTON_LEFT pinl
|
||||
#define GPIO_BUTTON_UP pinl
|
||||
#define GPIO_BUTTON_DOWN pinl
|
||||
#define PIN_BUTTON_MENU (1<<INP_L_KEY_MEN)
|
||||
#define PIN_BUTTON_EXIT (1<<INP_L_KEY_EXT)
|
||||
#define PIN_BUTTON_UP (1<<INP_L_KEY_UP)
|
||||
#define PIN_BUTTON_DOWN (1<<INP_L_KEY_DWN)
|
||||
#define PIN_BUTTON_RIGHT (1<<INP_L_KEY_RGT)
|
||||
#define PIN_BUTTON_LEFT (1<<INP_L_KEY_LFT)
|
||||
|
||||
#define GPIO_TRIM_LH_L pinf
|
||||
#define GPIO_TRIM_LV_DN pinf
|
||||
#define GPIO_TRIM_RV_UP pinf
|
||||
#define GPIO_TRIM_RH_L pinf
|
||||
#define GPIO_TRIM_LH_R pinf
|
||||
#define GPIO_TRIM_LV_UP pinf
|
||||
#define GPIO_TRIM_RV_DN pinf
|
||||
#define GPIO_TRIM_RH_R pinf
|
||||
#define PIN_TRIM_LH_L (1<<INP_F_TRM_LH_DWN)
|
||||
#define PIN_TRIM_LV_DN (1<<INP_F_TRM_LV_DWN)
|
||||
#define PIN_TRIM_RV_UP (1<<INP_F_TRM_RV_UP)
|
||||
#define PIN_TRIM_RH_L (1<<INP_F_TRM_RH_DWN)
|
||||
#define PIN_TRIM_LH_R (1<<INP_F_TRM_LH_UP)
|
||||
#define PIN_TRIM_LV_UP (1<<INP_F_TRM_LV_UP)
|
||||
#define PIN_TRIM_RV_DN (1<<INP_F_TRM_RV_DWN)
|
||||
#define PIN_TRIM_RH_R (1<<INP_F_TRM_RH_UP)
|
||||
|
||||
#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 SLAVE_MODE() (PING & (1<<INP_G_RF_POW))
|
||||
#define JACK_PPM_OUT() PORTG |= (1<<OUT_G_SIM_CTL)
|
||||
#define JACK_PPM_IN() PORTG &= ~(1<<OUT_G_SIM_CTL)
|
||||
|
||||
// SD driver
|
||||
#if !defined(SIMU)
|
||||
bool sdMounted();
|
||||
void sdMountPoll();
|
||||
void sdPoll10ms();
|
||||
#define sdDone()
|
||||
|
||||
#define SD_IS_HC() (0)
|
||||
#define SD_GET_BLOCKNR() (0)
|
||||
#define SD_GET_SIZE_MB() (0)
|
||||
#define SD_GET_SPEED() (0)
|
||||
#endif
|
||||
|
||||
#define SPEAKER_ON TCCR0A |= (1 << COM0A0)
|
||||
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
|
||||
#define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT)
|
||||
#define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT)
|
||||
#define IS_BACKLIGHT_ON() (PORTC & (1<<OUT_C_LIGHT))
|
||||
|
||||
|
||||
# define INP_L_SPARE6 7
|
||||
# define INP_L_SPARE5 6
|
||||
# define INP_L_KEY_EXT 5
|
||||
# define INP_L_KEY_MEN 4
|
||||
# define INP_L_KEY_LFT 3
|
||||
# define INP_L_KEY_RGT 2
|
||||
# define INP_L_KEY_UP 1
|
||||
# define INP_L_KEY_DWN 0
|
||||
|
||||
# define INP_F_TRM_RH_UP 7
|
||||
# define INP_F_TRM_RH_DWN 6
|
||||
# define INP_F_TRM_RV_UP 5
|
||||
# define INP_F_TRM_RV_DWN 4
|
||||
# define INP_F_TRM_LV_UP 3
|
||||
# define INP_F_TRM_LV_DWN 2
|
||||
# define INP_F_TRM_LH_UP 1
|
||||
# define INP_F_TRM_LH_DWN 0
|
||||
|
||||
# define INP_E_PPM_IN 7
|
||||
# define INP_E_ROT_ENC_1_B 6
|
||||
# define INP_E_ROT_ENC_1_A 5
|
||||
# define INP_E_USB_D_PLS 4
|
||||
# define OUT_E_BUZZER 3
|
||||
# define INP_E_USB_D_NEG 2
|
||||
# define INP_E_TELEM_RX 1
|
||||
# define OUT_E_TELEM_TX 0
|
||||
|
||||
# define OUT_D_HAPTIC 7
|
||||
# define INP_D_SPARE4 6
|
||||
# define INP_D_ROT_ENC_2_PUSH 5
|
||||
# define INP_D_ROT_ENC_1_PUSH 4
|
||||
# define OUT_D_ROT_ENC_2_B 3
|
||||
# define INP_D_ROT_ENC_2_A 2
|
||||
# define INP_D_I2C_SCL 1
|
||||
# define INP_D_I2C_SDA 0
|
||||
|
||||
# define INP_G_Gear 5
|
||||
# define INP_G_ThrCt 2
|
||||
# define OUT_G_SIM_CTL 4 //1 : phone-jack=ppm_in
|
||||
|
||||
# define INP_C_ID1 0
|
||||
|
||||
# define INP_G_RF_POW 1
|
||||
# define INP_G_RuddDR 0
|
||||
|
||||
# define INP_C_AileDR 7
|
||||
# define INP_C_ElevDR 6
|
||||
# define OUT_C_LIGHT 2
|
||||
|
||||
# define OUT_B_Speaker 7
|
||||
# define OUT_B_PPM 6
|
||||
# define INP_B_Trainer 5
|
||||
|
||||
# define INP_C_ID2 1
|
||||
|
||||
#if defined(VOICE)
|
||||
# define OUT_H_14DRESET 3
|
||||
# define OUT_H_14DCLK 4
|
||||
# define OUT_H_14DDATA 5
|
||||
# define INP_H_14DBUSY 6
|
||||
#endif
|
||||
|
||||
// Keys driver
|
||||
#define TRIMS_PRESSED() (~PINJ)
|
||||
#define KEYS_PRESSED() (~PINL) // used only for DBLKEYS code.
|
||||
#define DBLKEYS_PRESSED_RGT_LFT(i) ((in & ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_LFT))) == ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_LFT)))
|
||||
#define DBLKEYS_PRESSED_UP_DWN(i) ((in & ((1<<INP_L_KEY_UP) + (1<<INP_L_KEY_DWN))) == ((1<<INP_L_KEY_UP) + (1<<INP_L_KEY_DWN)))
|
||||
#define DBLKEYS_PRESSED_RGT_UP(i) ((in & ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_UP))) == ((1<<INP_L_KEY_RGT) + (1<<INP_L_KEY_UP)))
|
||||
#define DBLKEYS_PRESSED_LFT_DWN(i) ((in & ((1<<INP_L_KEY_LFT) + (1<<INP_L_KEY_DWN))) == ((1<<INP_L_KEY_LFT) + (1<<INP_L_KEY_DWN)))
|
||||
|
||||
// LCD driver
|
||||
#define PORTA_LCD_DAT PORTA
|
||||
#define PORTC_LCD_CTRL PORTC
|
||||
#define OUT_C_LCD_E 7
|
||||
#define OUT_C_LCD_RnW 6
|
||||
#define OUT_C_LCD_A0 5
|
||||
#define OUT_C_LCD_RES 4
|
||||
#define OUT_C_LCD_CS1 3
|
||||
|
||||
// Power driver
|
||||
uint8_t pwrCheck();
|
||||
void pwrOff();
|
||||
#define UNEXPECTED_SHUTDOWN() ((mcusr & (1 << WDRF)) || g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
// USB fake driver
|
||||
#define usbPlugged() false
|
||||
|
||||
// Haptic driver
|
||||
#define hapticOff() // TODO hapticOn() cleaner ...
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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 _HAL_
|
||||
#define _HAL_
|
||||
|
||||
/*
|
||||
* GPIOS
|
||||
*/
|
||||
|
||||
// Keys
|
||||
#define GPIO_BUTTON_MENU GPIOL->IDR // only one port : to simplify ? //
|
||||
#define GPIO_BUTTON_EXIT GPIOL->IDR
|
||||
#define GPIO_BUTTON_RIGHT GPIOL->IDR
|
||||
#define GPIO_BUTTON_LEFT GPIOL->IDR
|
||||
#define GPIO_BUTTON_UP GPIOL->IDR
|
||||
#define GPIO_BUTTON_DOWN GPIOL->IDR
|
||||
#define PIN_BUTTON_MENU GPIO_Pin_4
|
||||
#define PIN_BUTTON_EXIT GPIO_Pin_5
|
||||
#define PIN_BUTTON_RIGHT GPIO_Pin_2
|
||||
#define PIN_BUTTON_LEFT GPIO_Pin_3
|
||||
#define PIN_BUTTON_UP GPIO_Pin_1
|
||||
#define PIN_BUTTON_DOWN GPIO_Pin_0
|
||||
|
||||
// Trims
|
||||
#define GPIO_TRIM_LH_L GPIOK->IDR // only one port : to simplify ? //
|
||||
#define GPIO_TRIM_LH_R GPIOK->IDR
|
||||
#define GPIO_TRIM_LV_DN GPIOK->IDR
|
||||
#define GPIO_TRIM_LV_UP GPIOK->IDR
|
||||
#define GPIO_TRIM_RH_L GPIOK->IDR
|
||||
#define GPIO_TRIM_RH_R GPIOK->IDR
|
||||
#define GPIO_TRIM_RV_DN GPIOK->IDR
|
||||
#define GPIO_TRIM_RV_UP GPIOK->IDR
|
||||
#define PIN_TRIM_LH_L GPIO_Pin_0
|
||||
#define PIN_TRIM_LH_R GPIO_Pin_1
|
||||
#define PIN_TRIM_LV_DN GPIO_Pin_2
|
||||
#define PIN_TRIM_LV_UP GPIO_Pin_3
|
||||
#define PIN_TRIM_RH_L GPIO_Pin_4
|
||||
#define PIN_TRIM_RH_R GPIO_Pin_5
|
||||
#define PIN_TRIM_RV_DN GPIO_Pin_5
|
||||
#define PIN_TRIM_RV_UP GPIO_Pin_6
|
||||
|
||||
// Switchs
|
||||
#define GPIO_PIN_SW_A GPIOC->IDR // A, B, C... to rename to ID1/2... ? //
|
||||
#define GPIO_PIN_SW_B GPIOC->IDR
|
||||
#define GPIO_PIN_SW_C GPIOD->IDR
|
||||
#define GPIO_PIN_SW_D GPIOG->IDR
|
||||
#define GPIO_PIN_SW_E GPIOG->IDR
|
||||
#define GPIO_PIN_SW_F GPIOG->IDR
|
||||
#define GPIO_PIN_SW_G GPIOL->IDR
|
||||
#define GPIO_PIN_SW_H GPIOL->IDR
|
||||
#define PIN_SW_A GPIO_Pin_1
|
||||
#define PIN_SW_B GPIO_Pin_0
|
||||
#define PIN_SW_C GPIO_Pin_7
|
||||
#define PIN_SW_D GPIO_Pin_2
|
||||
#define PIN_SW_E GPIO_Pin_1
|
||||
#define PIN_SW_F GPIO_Pin_0
|
||||
#define PIN_SW_G GPIO_Pin_6
|
||||
#define PIN_SW_H GPIO_Pin_7
|
||||
|
||||
// Rotary encoders
|
||||
#define GPIO_PIN_ROT_ENC_1_A GPIOH->IDR
|
||||
#define GPIO_PIN_ROT_ENC_1_B GPIOJ->IDR
|
||||
#define GPIO_PIN_ROT_ENC_1_PUSH GPIOJ->IDR
|
||||
#define GPIO_PIN_ROT_ENC_2_A GPIOD->IDR
|
||||
#define GPIO_PIN_ROT_ENC_2_B GPIOD->IDR
|
||||
#define GPIO_PIN_ROT_ENC_2_PUSH GPIOH->IDR
|
||||
#define PIN_ROT_ENC_1_A GPIO_Pin_1
|
||||
#define PIN_ROT_ENC_1_B GPIO_Pin_0
|
||||
#define PIN_ROT_ENC_1_PUSH GPIO_Pin_1
|
||||
#define PIN_ROT_ENC_2_A GPIO_Pin_0
|
||||
#define PIN_ROT_ENC_2_B GPIO_Pin_3
|
||||
#define PIN_ROT_ENC_2_PUSH GPIO_Pin_2
|
||||
|
||||
// ADC
|
||||
#define GPIO_PIN_ADC GPIOK->IDR
|
||||
#define PIN_STK_J1 GPIO_Pin_0
|
||||
#define PIN_STK_J2 GPIO_Pin_1
|
||||
#define PIN_STK_J3 GPIO_Pin_2
|
||||
#define PIN_STK_J4 GPIO_Pin_3
|
||||
#define PIN_POT_1 GPIO_Pin_4
|
||||
#define PIN_POT_2 GPIO_Pin_5
|
||||
#define PIN_POT_3 GPIO_Pin_6
|
||||
#define PIN_MVOLT GPIO_Pin_7
|
||||
|
||||
// Accessories
|
||||
#define GPIO_PIN_PPM_IN GPIOB->IDR
|
||||
#define GPIO_PIN_PPM_OUT GPIOB->IDR
|
||||
#define GPIO_PIN_SIM_CTL GPIOB->IDR
|
||||
#define GPIO_PIN_TELEM_RX GPIOE->IDR
|
||||
#define GPIO_PIN_TELEM_TX GPIOE->IDR
|
||||
#define GPIO_PIN_SPEAKER GPIOE->IDR
|
||||
#define GPIO_PIN_BUZZER GPIOB->IDR
|
||||
#define GPIO_PIN_JACK_PRES GPIOH->IDR
|
||||
#define GPIO_PIN_HOLD_PWR GPIOH->IDR
|
||||
#define PIN_PPM_IN GPIO_Pin_7
|
||||
#define PIN_PPM_OUT GPIO_Pin_6
|
||||
#define PIN_SIM_CTL GPIO_Pin_5
|
||||
#define PIN_TELEM_RX GPIO_Pin_0
|
||||
#define PIN_TELEM_TX GPIO_Pin_1
|
||||
#define PIN_SPEAKER GPIO_Pin_3
|
||||
#define PIN_BUZZER GPIO_Pin_4
|
||||
#define PIN_JACK_PRES GPIO_Pin_5
|
||||
#define PIN_HOLD_PWR GPIO_Pin_4
|
||||
|
||||
// LCD
|
||||
#define GPIO_LCD_DAT GPIOA->IDR
|
||||
#define GPIO_LCD_CTRL GPIOC->IDR
|
||||
#define PIN_LCD_E GPIO_Pin_7
|
||||
#define PIN_LCD_RnW GPIO_Pin_6
|
||||
#define PIN_LCD_A0 GPIO_Pin_5
|
||||
#define PIN_LCD_RES GPIO_Pin_4
|
||||
#define PIN_LCD_CS1 GPIO_Pin_3
|
||||
#define PIN_LCD_LIGHT GPIO_Pin_2
|
||||
|
||||
// SD
|
||||
#define GPIO_SD GPIOB->IDR
|
||||
#define PIN_SD_MISO GPIO_Pin_3
|
||||
#define PIN_SD_MOSI GPIO_Pin_2
|
||||
#define PIN_SD_SCK GPIO_Pin_1
|
||||
#define PIN_SD_CS GPIO_Pin_0
|
||||
#define SD_IS_HC() (0) // ?
|
||||
#define SD_GET_BLOCKNR() (0) // ?
|
||||
#define SD_GET_SIZE_MB() (0) // ?
|
||||
#define SD_GET_SPEED() (0) // ?
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#define delay_1us() _delay_us(1)
|
||||
void delay_1_5us(int ms)
|
||||
{
|
||||
for(int i=0; i<ms; i++) delay_1us();
|
||||
}
|
||||
|
||||
void lcdSendCtl(uint8_t val)
|
||||
{
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
|
||||
#ifdef 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);
|
||||
#ifdef 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
|
||||
|
||||
inline void lcdInit()
|
||||
{
|
||||
// /home/thus/txt/datasheets/lcd/KS0713.pdf
|
||||
// ~/txt/flieger/ST7565RV17.pdf from http://www.glyn.de/content.asp?wdid=132&sid=
|
||||
|
||||
LCD_LOCK();
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD_RES
|
||||
delay_1us();
|
||||
delay_1us();// f520 call 0xf4ce delay_1us() ; 0x0xf4ce
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); // f524 sbi 0x15, 2 IOADR-PORTC_LCD_CTRL; 21 1
|
||||
delay_1_5us(1500);
|
||||
lcdSendCtl(0xE2); //Initialize the internal functions
|
||||
lcdSendCtl(0xAE); //DON = 0: display OFF
|
||||
lcdSendCtl(0xA0); //ADC = 0: normal direction
|
||||
lcdSendCtl(0xA6); //REV = 0: non-reverse display
|
||||
lcdSendCtl(0xA4); //EON = 0: normal display. non-entire
|
||||
lcdSendCtl(0xA2); //Select LCD bias=0
|
||||
lcdSendCtl(0xC8); //SHL = 1: inverse direction
|
||||
lcdSendCtl(0x2F); //Control power circuit operation VC=VR=VF=1
|
||||
lcdSendCtl(0x25); //Select int resistance ratio R2 R1 R0 =5
|
||||
lcdSendCtl(0x81); //Set reference voltage Mode
|
||||
lcdSendCtl(0x22); //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
|
||||
lcdSendCtl(0xAF); //DON = 1: display ON
|
||||
lcdSendCtl(0x60); //sets the display start line to zero
|
||||
g_eeGeneral.contrast = 0x22;
|
||||
LCD_UNLOCK();
|
||||
}
|
||||
|
||||
void lcdSetRefVolt(uint8_t val)
|
||||
{
|
||||
LCD_LOCK();
|
||||
lcdSendCtl(0x81);
|
||||
lcdSendCtl(val);
|
||||
LCD_UNLOCK();
|
||||
}
|
||||
|
||||
void lcdRefresh()
|
||||
{
|
||||
LCD_LOCK();
|
||||
uint8_t *p=displayBuf;
|
||||
for(uint8_t y=0; y < 8; y++) {
|
||||
lcdSendCtl(0x01);
|
||||
lcdSendCtl(0x10); //column addr 0
|
||||
lcdSendCtl( y | 0xB0); //page addr y
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
|
||||
#ifdef 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 (xcoord_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);
|
||||
}
|
||||
LCD_UNLOCK();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* RTC controls */
|
||||
|
||||
#include "../opentx.h"
|
||||
#include "../FatFs/integer.h"
|
||||
|
||||
typedef struct {
|
||||
WORD year; /* 2000..2099 */
|
||||
BYTE month; /* 1..12 */
|
||||
BYTE mday; /* 1.. 31 */
|
||||
BYTE wday; /* 1..7 */
|
||||
BYTE hour; /* 0..23 */
|
||||
BYTE min; /* 0..59 */
|
||||
BYTE sec; /* 0..59 */
|
||||
} RTC;
|
||||
|
||||
void rtc_gettime(struct gtm * utm)
|
||||
{
|
||||
RTC rtc = {0,0,0,0,0,0,0};
|
||||
|
||||
// TODO g9x_rtc_gettime(&rtc);
|
||||
|
||||
utm->tm_year = rtc.year - 1900;
|
||||
utm->tm_mon = rtc.month - 1;
|
||||
utm->tm_mday = rtc.mday;
|
||||
utm->tm_hour = rtc.hour;
|
||||
utm->tm_min = rtc.min;
|
||||
utm->tm_sec = rtc.sec;
|
||||
utm->tm_wday = rtc.wday - 1;
|
||||
}
|
||||
|
||||
void rtcSetTime(struct gtm * t)
|
||||
{
|
||||
g_rtcTime = gmktime(t); // update local timestamp and get wday calculated
|
||||
g_ms100 = 0; // start of next second begins now
|
||||
|
||||
#if 0
|
||||
RTC rtc;
|
||||
rtc.year = t->tm_year + 1900;
|
||||
rtc.month = t->tm_mon + 1;
|
||||
rtc.mday = t->tm_mday;
|
||||
rtc.hour = t->tm_hour;
|
||||
rtc.min = t->tm_min;
|
||||
rtc.sec = t->tm_sec;
|
||||
rtc.wday = t->tm_wday + 1;
|
||||
g9x_rtcSetTime(&rtc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtcInit (void)
|
||||
{
|
||||
// TODO
|
||||
|
||||
struct gtm utm;
|
||||
rtc_gettime(&utm);
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user