opentx /radio/src/targets/mega2560/board_mega2560.h

Language C/C++ Header Lines 198
MD5 Hash 3d36ae648d0e829318f614724ebf223f
Repository https://github.com/krisp/opentx.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * 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

#include "../common_avr/board_avr.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 ...
#define HAPTIC_ON()   PORTD &= ~(1 << OUT_D_HAPTIC)
#define HAPTIC_OFF()  PORTD |=  (1 << OUT_D_HAPTIC)

#endif
Back to Top