PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/krisp/opentx
C++ Header | 197 lines | 129 code | 27 blank | 41 comment | 5 complexity | 3d36ae648d0e829318f614724ebf223f MD5 | raw file
  1/*
  2 * Authors (alphabetical order)
  3 * - Andre Bernet <bernet.andre@gmail.com>
  4 * - Andreas Weitl
  5 * - Bertrand Songis <bsongis@gmail.com>
  6 * - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
  7 * - Cameron Weeks <th9xer@gmail.com>
  8 * - Erez Raviv
  9 * - Gabriel Birkus
 10 * - Jean-Pierre Parisy
 11 * - Karl Szmutny
 12 * - Michael Blandford
 13 * - Michal Hlavinka
 14 * - Pat Mackenzie
 15 * - Philip Moss
 16 * - Rob Thomson
 17 * - Romolo Manfredini <romolo.manfredini@gmail.com>
 18 * - Thomas Husterer
 19 *
 20 * opentx is based on code named
 21 * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
 22 * er9x by Erez Raviv: http://code.google.com/p/er9x/,
 23 * and the original (and ongoing) project by
 24 * Thomas Husterer, th9x: http://code.google.com/p/th9x/
 25 *
 26 * This program is free software; you can redistribute it and/or modify
 27 * it under the terms of the GNU General Public License version 2 as
 28 * published by the Free Software Foundation.
 29 *
 30 * This program is distributed in the hope that it will be useful,
 31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 33 * GNU General Public License for more details.
 34 *
 35 */
 36
 37#ifndef board_mega2560_h

 38#define board_mega2560_h

 39
 40#include "../common_avr/board_avr.h"

 41
 42#define GPIO_BUTTON_MENU         pinl

 43#define GPIO_BUTTON_EXIT         pinl

 44#define GPIO_BUTTON_RIGHT        pinl

 45#define GPIO_BUTTON_LEFT         pinl

 46#define GPIO_BUTTON_UP           pinl

 47#define GPIO_BUTTON_DOWN         pinl

 48#define PIN_BUTTON_MENU          (1<<INP_L_KEY_MEN)

 49#define PIN_BUTTON_EXIT          (1<<INP_L_KEY_EXT)

 50#define PIN_BUTTON_UP            (1<<INP_L_KEY_UP)

 51#define PIN_BUTTON_DOWN          (1<<INP_L_KEY_DWN)

 52#define PIN_BUTTON_RIGHT         (1<<INP_L_KEY_RGT)

 53#define PIN_BUTTON_LEFT          (1<<INP_L_KEY_LFT)

 54
 55#define GPIO_TRIM_LH_L           pinf

 56#define GPIO_TRIM_LV_DN          pinf

 57#define GPIO_TRIM_RV_UP          pinf

 58#define GPIO_TRIM_RH_L           pinf

 59#define GPIO_TRIM_LH_R           pinf

 60#define GPIO_TRIM_LV_UP          pinf

 61#define GPIO_TRIM_RV_DN          pinf

 62#define GPIO_TRIM_RH_R           pinf

 63#define PIN_TRIM_LH_L            (1<<INP_F_TRM_LH_DWN)

 64#define PIN_TRIM_LV_DN           (1<<INP_F_TRM_LV_DWN)

 65#define PIN_TRIM_RV_UP           (1<<INP_F_TRM_RV_UP)

 66#define PIN_TRIM_RH_L            (1<<INP_F_TRM_RH_DWN)

 67#define PIN_TRIM_LH_R            (1<<INP_F_TRM_LH_UP)

 68#define PIN_TRIM_LV_UP           (1<<INP_F_TRM_LV_UP)

 69#define PIN_TRIM_RV_DN           (1<<INP_F_TRM_RV_DWN)

 70#define PIN_TRIM_RH_R            (1<<INP_F_TRM_RH_UP)

 71
 72#define TIMER_16KHZ_VECT         TIMER2_OVF_vect

 73#define COUNTER_16KHZ            TCNT2

 74#define TIMER_10MS_VECT          TIMER2_COMPA_vect

 75#define TIMER_10MS_COMPVAL       OCR2A

 76#define PAUSE_10MS_INTERRUPT()   TIMSK2 &= ~(1<<OCIE2A)

 77#define RESUME_10MS_INTERRUPT()  TIMSK2 |= (1<<OCIE2A)

 78#define PAUSE_PPMIN_INTERRUPT()  TIMSK3 &= ~(1<<ICIE3)

 79#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)

 80
 81#define SLAVE_MODE()             (PING & (1<<INP_G_RF_POW))

 82#define JACK_PPM_OUT()           PORTG |= (1<<OUT_G_SIM_CTL)

 83#define JACK_PPM_IN()            PORTG &= ~(1<<OUT_G_SIM_CTL)

 84
 85// SD driver
 86#if !defined(SIMU)

 87bool sdMounted();
 88void sdMountPoll();
 89void sdPoll10ms();
 90#define sdDone()

 91
 92#define SD_IS_HC()               (0)

 93#define SD_GET_BLOCKNR()         (0)

 94#define SD_GET_SIZE_MB()         (0)

 95#define SD_GET_SPEED()           (0)

 96#endif

 97
 98#define SPEAKER_ON               TCCR0A |=  (1 << COM0A0)

 99#define SPEAKER_OFF              TCCR0A &= ~(1 << COM0A0)

100#define __BACKLIGHT_ON           PORTC |=  (1 << OUT_C_LIGHT)

101#define __BACKLIGHT_OFF          PORTC &= ~(1 << OUT_C_LIGHT)

102#define IS_BACKLIGHT_ON()        (PORTC & (1<<OUT_C_LIGHT))

103
104
105#  define INP_L_SPARE6    7

106#  define INP_L_SPARE5    6

107#  define INP_L_KEY_EXT   5

108#  define INP_L_KEY_MEN   4

109#  define INP_L_KEY_LFT   3

110#  define INP_L_KEY_RGT   2

111#  define INP_L_KEY_UP    1

112#  define INP_L_KEY_DWN   0

113
114#  define INP_F_TRM_RH_UP   7

115#  define INP_F_TRM_RH_DWN  6

116#  define INP_F_TRM_RV_UP   5

117#  define INP_F_TRM_RV_DWN  4

118#  define INP_F_TRM_LV_UP   3

119#  define INP_F_TRM_LV_DWN  2

120#  define INP_F_TRM_LH_UP   1

121#  define INP_F_TRM_LH_DWN  0

122
123#  define INP_E_PPM_IN      7

124#  define INP_E_ROT_ENC_1_B 6

125#  define INP_E_ROT_ENC_1_A 5

126#  define INP_E_USB_D_PLS   4

127#  define OUT_E_BUZZER      3

128#  define INP_E_USB_D_NEG   2

129#  define INP_E_TELEM_RX    1

130#  define OUT_E_TELEM_TX    0

131
132#  define OUT_D_HAPTIC         7

133#  define INP_D_SPARE4         6

134#  define INP_D_ROT_ENC_2_PUSH 5

135#  define INP_D_ROT_ENC_1_PUSH 4

136#  define OUT_D_ROT_ENC_2_B    3

137#  define INP_D_ROT_ENC_2_A    2

138#  define INP_D_I2C_SCL        1

139#  define INP_D_I2C_SDA        0

140
141#  define INP_G_Gear     5

142#  define INP_G_ThrCt    2

143#  define OUT_G_SIM_CTL  4 //1 : phone-jack=ppm_in
144
145#  define INP_C_ID1      0

146
147#  define INP_G_RF_POW   1

148#  define INP_G_RuddDR   0

149
150#  define INP_C_AileDR   7

151#  define INP_C_ElevDR   6

152#  define OUT_C_LIGHT    2

153
154#  define OUT_B_Speaker  7

155#  define OUT_B_PPM      6

156#  define INP_B_Trainer  5

157
158#  define INP_C_ID2      1

159
160#if defined(VOICE)

161#  define OUT_H_14DRESET 3

162#  define OUT_H_14DCLK   4

163#  define OUT_H_14DDATA  5

164#  define INP_H_14DBUSY  6

165#endif

166
167// Keys driver
168#define TRIMS_PRESSED() (~PINJ)

169#define KEYS_PRESSED()  (~PINL) // used only for DBLKEYS code.
170#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)))

171#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)))

172#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)))

173#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)))

174
175// LCD driver
176#define PORTA_LCD_DAT  PORTA

177#define PORTC_LCD_CTRL PORTC

178#define OUT_C_LCD_E     7

179#define OUT_C_LCD_RnW   6

180#define OUT_C_LCD_A0    5

181#define OUT_C_LCD_RES   4

182#define OUT_C_LCD_CS1   3

183
184// Power driver
185uint8_t pwrCheck();
186void pwrOff();
187#define UNEXPECTED_SHUTDOWN() ((mcusr & (1 << WDRF)) || g_eeGeneral.unexpectedShutdown)

188
189// USB fake driver
190#define usbPlugged()    false

191
192// Haptic driver
193#define hapticOff() // TODO hapticOn() cleaner ...
194#define HAPTIC_ON()   PORTD &= ~(1 << OUT_D_HAPTIC)

195#define HAPTIC_OFF()  PORTD |=  (1 << OUT_D_HAPTIC)

196
197#endif