PageRenderTime 47ms CodeModel.GetById 22ms 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
Possible License(s): LGPL-3.0
  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. #ifndef board_mega2560_h
  37. #define board_mega2560_h
  38. #include "../common_avr/board_avr.h"
  39. #define GPIO_BUTTON_MENU pinl
  40. #define GPIO_BUTTON_EXIT pinl
  41. #define GPIO_BUTTON_RIGHT pinl
  42. #define GPIO_BUTTON_LEFT pinl
  43. #define GPIO_BUTTON_UP pinl
  44. #define GPIO_BUTTON_DOWN pinl
  45. #define PIN_BUTTON_MENU (1<<INP_L_KEY_MEN)
  46. #define PIN_BUTTON_EXIT (1<<INP_L_KEY_EXT)
  47. #define PIN_BUTTON_UP (1<<INP_L_KEY_UP)
  48. #define PIN_BUTTON_DOWN (1<<INP_L_KEY_DWN)
  49. #define PIN_BUTTON_RIGHT (1<<INP_L_KEY_RGT)
  50. #define PIN_BUTTON_LEFT (1<<INP_L_KEY_LFT)
  51. #define GPIO_TRIM_LH_L pinf
  52. #define GPIO_TRIM_LV_DN pinf
  53. #define GPIO_TRIM_RV_UP pinf
  54. #define GPIO_TRIM_RH_L pinf
  55. #define GPIO_TRIM_LH_R pinf
  56. #define GPIO_TRIM_LV_UP pinf
  57. #define GPIO_TRIM_RV_DN pinf
  58. #define GPIO_TRIM_RH_R pinf
  59. #define PIN_TRIM_LH_L (1<<INP_F_TRM_LH_DWN)
  60. #define PIN_TRIM_LV_DN (1<<INP_F_TRM_LV_DWN)
  61. #define PIN_TRIM_RV_UP (1<<INP_F_TRM_RV_UP)
  62. #define PIN_TRIM_RH_L (1<<INP_F_TRM_RH_DWN)
  63. #define PIN_TRIM_LH_R (1<<INP_F_TRM_LH_UP)
  64. #define PIN_TRIM_LV_UP (1<<INP_F_TRM_LV_UP)
  65. #define PIN_TRIM_RV_DN (1<<INP_F_TRM_RV_DWN)
  66. #define PIN_TRIM_RH_R (1<<INP_F_TRM_RH_UP)
  67. #define TIMER_16KHZ_VECT TIMER2_OVF_vect
  68. #define COUNTER_16KHZ TCNT2
  69. #define TIMER_10MS_VECT TIMER2_COMPA_vect
  70. #define TIMER_10MS_COMPVAL OCR2A
  71. #define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<<OCIE2A)
  72. #define RESUME_10MS_INTERRUPT() TIMSK2 |= (1<<OCIE2A)
  73. #define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
  74. #define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
  75. #define SLAVE_MODE() (PING & (1<<INP_G_RF_POW))
  76. #define JACK_PPM_OUT() PORTG |= (1<<OUT_G_SIM_CTL)
  77. #define JACK_PPM_IN() PORTG &= ~(1<<OUT_G_SIM_CTL)
  78. // SD driver
  79. #if !defined(SIMU)
  80. bool sdMounted();
  81. void sdMountPoll();
  82. void sdPoll10ms();
  83. #define sdDone()
  84. #define SD_IS_HC() (0)
  85. #define SD_GET_BLOCKNR() (0)
  86. #define SD_GET_SIZE_MB() (0)
  87. #define SD_GET_SPEED() (0)
  88. #endif
  89. #define SPEAKER_ON TCCR0A |= (1 << COM0A0)
  90. #define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
  91. #define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT)
  92. #define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT)
  93. #define IS_BACKLIGHT_ON() (PORTC & (1<<OUT_C_LIGHT))
  94. # define INP_L_SPARE6 7
  95. # define INP_L_SPARE5 6
  96. # define INP_L_KEY_EXT 5
  97. # define INP_L_KEY_MEN 4
  98. # define INP_L_KEY_LFT 3
  99. # define INP_L_KEY_RGT 2
  100. # define INP_L_KEY_UP 1
  101. # define INP_L_KEY_DWN 0
  102. # define INP_F_TRM_RH_UP 7
  103. # define INP_F_TRM_RH_DWN 6
  104. # define INP_F_TRM_RV_UP 5
  105. # define INP_F_TRM_RV_DWN 4
  106. # define INP_F_TRM_LV_UP 3
  107. # define INP_F_TRM_LV_DWN 2
  108. # define INP_F_TRM_LH_UP 1
  109. # define INP_F_TRM_LH_DWN 0
  110. # define INP_E_PPM_IN 7
  111. # define INP_E_ROT_ENC_1_B 6
  112. # define INP_E_ROT_ENC_1_A 5
  113. # define INP_E_USB_D_PLS 4
  114. # define OUT_E_BUZZER 3
  115. # define INP_E_USB_D_NEG 2
  116. # define INP_E_TELEM_RX 1
  117. # define OUT_E_TELEM_TX 0
  118. # define OUT_D_HAPTIC 7
  119. # define INP_D_SPARE4 6
  120. # define INP_D_ROT_ENC_2_PUSH 5
  121. # define INP_D_ROT_ENC_1_PUSH 4
  122. # define OUT_D_ROT_ENC_2_B 3
  123. # define INP_D_ROT_ENC_2_A 2
  124. # define INP_D_I2C_SCL 1
  125. # define INP_D_I2C_SDA 0
  126. # define INP_G_Gear 5
  127. # define INP_G_ThrCt 2
  128. # define OUT_G_SIM_CTL 4 //1 : phone-jack=ppm_in
  129. # define INP_C_ID1 0
  130. # define INP_G_RF_POW 1
  131. # define INP_G_RuddDR 0
  132. # define INP_C_AileDR 7
  133. # define INP_C_ElevDR 6
  134. # define OUT_C_LIGHT 2
  135. # define OUT_B_Speaker 7
  136. # define OUT_B_PPM 6
  137. # define INP_B_Trainer 5
  138. # define INP_C_ID2 1
  139. #if defined(VOICE)
  140. # define OUT_H_14DRESET 3
  141. # define OUT_H_14DCLK 4
  142. # define OUT_H_14DDATA 5
  143. # define INP_H_14DBUSY 6
  144. #endif
  145. // Keys driver
  146. #define TRIMS_PRESSED() (~PINJ)
  147. #define KEYS_PRESSED() (~PINL) // used only for DBLKEYS code.
  148. #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)))
  149. #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)))
  150. #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)))
  151. #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)))
  152. // LCD driver
  153. #define PORTA_LCD_DAT PORTA
  154. #define PORTC_LCD_CTRL PORTC
  155. #define OUT_C_LCD_E 7
  156. #define OUT_C_LCD_RnW 6
  157. #define OUT_C_LCD_A0 5
  158. #define OUT_C_LCD_RES 4
  159. #define OUT_C_LCD_CS1 3
  160. // Power driver
  161. uint8_t pwrCheck();
  162. void pwrOff();
  163. #define UNEXPECTED_SHUTDOWN() ((mcusr & (1 << WDRF)) || g_eeGeneral.unexpectedShutdown)
  164. // USB fake driver
  165. #define usbPlugged() false
  166. // Haptic driver
  167. #define hapticOff() // TODO hapticOn() cleaner ...
  168. #define HAPTIC_ON() PORTD &= ~(1 << OUT_D_HAPTIC)
  169. #define HAPTIC_OFF() PORTD |= (1 << OUT_D_HAPTIC)
  170. #endif