PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HW_ATmega1280.h 5.0KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // *** Hardwarespecific functions ***
  2. void UTFT::_hw_special_init()
  3. {
  4. }
  5. void UTFT::LCD_Writ_Bus(char VH,char VL, byte mode)
  6. {
  7. switch (mode)
  8. {
  9. case 1:
  10. if (display_serial_mode==SERIAL_4PIN)
  11. {
  12. if (VH==1)
  13. sbi(P_SDA, B_SDA);
  14. else
  15. cbi(P_SDA, B_SDA);
  16. pulse_low(P_SCL, B_SCL);
  17. }
  18. else
  19. {
  20. if (VH==1)
  21. sbi(P_RS, B_RS);
  22. else
  23. cbi(P_RS, B_RS);
  24. }
  25. if (VL & 0x80)
  26. sbi(P_SDA, B_SDA);
  27. else
  28. cbi(P_SDA, B_SDA);
  29. pulse_low(P_SCL, B_SCL);
  30. if (VL & 0x40)
  31. sbi(P_SDA, B_SDA);
  32. else
  33. cbi(P_SDA, B_SDA);
  34. pulse_low(P_SCL, B_SCL);
  35. if (VL & 0x20)
  36. sbi(P_SDA, B_SDA);
  37. else
  38. cbi(P_SDA, B_SDA);
  39. pulse_low(P_SCL, B_SCL);
  40. if (VL & 0x10)
  41. sbi(P_SDA, B_SDA);
  42. else
  43. cbi(P_SDA, B_SDA);
  44. pulse_low(P_SCL, B_SCL);
  45. if (VL & 0x08)
  46. sbi(P_SDA, B_SDA);
  47. else
  48. cbi(P_SDA, B_SDA);
  49. pulse_low(P_SCL, B_SCL);
  50. if (VL & 0x04)
  51. sbi(P_SDA, B_SDA);
  52. else
  53. cbi(P_SDA, B_SDA);
  54. pulse_low(P_SCL, B_SCL);
  55. if (VL & 0x02)
  56. sbi(P_SDA, B_SDA);
  57. else
  58. cbi(P_SDA, B_SDA);
  59. pulse_low(P_SCL, B_SCL);
  60. if (VL & 0x01)
  61. sbi(P_SDA, B_SDA);
  62. else
  63. cbi(P_SDA, B_SDA);
  64. pulse_low(P_SCL, B_SCL);
  65. break;
  66. case 8:
  67. #if defined(USE_UNO_SHIELD_ON_MEGA)
  68. PORTG &= ~0x20;
  69. PORTG |= (VH & 0x10)<<1;
  70. PORTH &= ~0x18;
  71. PORTH |= (VH & 0xC0)>>3;
  72. PORTE &= ~0x3B;
  73. PORTE |= (VH & 0x03) + ((VH & 0x0C)<<2) + ((VH & 0x20)>>2);
  74. pulse_low(P_WR, B_WR);
  75. PORTG &= ~0x20;
  76. PORTG |= (VL & 0x10)<<1;
  77. PORTH &= ~0x18;
  78. PORTH |= (VL & 0xC0)>>3;
  79. PORTE &= ~0x3B;
  80. PORTE |= (VL & 0x03) + ((VL & 0x0C)<<2) + ((VL & 0x20)>>2);
  81. pulse_low(P_WR, B_WR);
  82. #else
  83. PORTA = VH;
  84. pulse_low(P_WR, B_WR);
  85. PORTA = VL;
  86. pulse_low(P_WR, B_WR);
  87. #endif
  88. break;
  89. case 16:
  90. PORTA = VH;
  91. PORTC = VL;
  92. pulse_low(P_WR, B_WR);
  93. break;
  94. case LATCHED_16:
  95. PORTG &= ~0x20;
  96. PORTG |= (VH & 0x10)<<1;
  97. PORTH &= ~0x18;
  98. PORTH |= (VH & 0xC0)>>3;
  99. PORTE &= ~0x3B;
  100. PORTE |= (VH & 0x03) + ((VH & 0x0C)<<2) + ((VH & 0x20)>>2);
  101. cbi(P_ALE, B_ALE);
  102. pulse_high(P_ALE, B_ALE);
  103. cbi(P_CS, B_CS);
  104. PORTG &= ~0x20;
  105. PORTG |= (VL & 0x10)<<1;
  106. PORTH &= ~0x18;
  107. PORTH |= (VL & 0xC0)>>3;
  108. PORTE &= ~0x3B;
  109. PORTE |= (VL & 0x03) + ((VL & 0x0C)<<2) + ((VL & 0x20)>>2);
  110. pulse_low(P_WR, B_WR);
  111. sbi(P_CS, B_CS);
  112. break;
  113. }
  114. }
  115. void UTFT::_set_direction_registers(byte mode)
  116. {
  117. #if defined(USE_UNO_SHIELD_ON_MEGA)
  118. DDRH = 0x18;
  119. DDRG = 0x20;
  120. DDRE = 0x3B;
  121. #else
  122. if (mode!=LATCHED_16)
  123. {
  124. DDRA = 0xFF;
  125. if (mode==16)
  126. DDRC = 0xFF;
  127. }
  128. else
  129. {
  130. DDRH = 0x18;
  131. DDRG = 0x20;
  132. DDRE = 0x3B;
  133. }
  134. #endif
  135. }
  136. void UTFT::_fast_fill_16(int ch, int cl, long pix)
  137. {
  138. #if defined(USE_UNO_SHIELD_ON_MEGA)
  139. if (ch==cl)
  140. _fast_fill_8(ch, pix);
  141. else
  142. {
  143. for (int i=0; i<pix; i++)
  144. {
  145. PORTG &= ~0x20;
  146. PORTG |= (ch & 0x10)<<1;
  147. PORTH &= ~0x18;
  148. PORTH |= (ch & 0xC0)>>3;
  149. PORTE &= ~0x3B;
  150. PORTE |= (ch & 0x03) + ((ch & 0x0C)<<2) + ((ch & 0x20)>>2);
  151. pulse_low(P_WR, B_WR);
  152. PORTG &= ~0x20;
  153. PORTG |= (cl & 0x10)<<1;
  154. PORTH &= ~0x18;
  155. PORTH |= (cl & 0xC0)>>3;
  156. PORTE &= ~0x3B;
  157. PORTE |= (cl & 0x03) + ((cl & 0x0C)<<2) + ((cl & 0x20)>>2);
  158. pulse_low(P_WR, B_WR);
  159. }
  160. }
  161. #else
  162. long blocks;
  163. PORTA = ch;
  164. PORTC = cl;
  165. blocks = pix/16;
  166. for (int i=0; i<blocks; i++)
  167. {
  168. pulse_low(P_WR, B_WR);
  169. pulse_low(P_WR, B_WR);
  170. pulse_low(P_WR, B_WR);
  171. pulse_low(P_WR, B_WR);
  172. pulse_low(P_WR, B_WR);
  173. pulse_low(P_WR, B_WR);
  174. pulse_low(P_WR, B_WR);
  175. pulse_low(P_WR, B_WR);
  176. pulse_low(P_WR, B_WR);
  177. pulse_low(P_WR, B_WR);
  178. pulse_low(P_WR, B_WR);
  179. pulse_low(P_WR, B_WR);
  180. pulse_low(P_WR, B_WR);
  181. pulse_low(P_WR, B_WR);
  182. pulse_low(P_WR, B_WR);
  183. pulse_low(P_WR, B_WR);
  184. }
  185. if ((pix % 16) != 0)
  186. for (int i=0; i<(pix % 16)+1; i++)
  187. {
  188. pulse_low(P_WR, B_WR);
  189. }
  190. #endif
  191. }
  192. void UTFT::_fast_fill_8(int ch, long pix)
  193. {
  194. long blocks;
  195. #if defined(USE_UNO_SHIELD_ON_MEGA)
  196. PORTG &= ~0x20;
  197. PORTG |= (ch & 0x10)<<1;
  198. PORTH &= ~0x18;
  199. PORTH |= (ch & 0xC0)>>3;
  200. PORTE &= ~0x3B;
  201. PORTE |= (ch & 0x03) + ((ch & 0x0C)<<2) + ((ch & 0x20)>>2);
  202. #else
  203. PORTA = ch;
  204. #endif
  205. blocks = pix/16;
  206. for (int i=0; i<blocks; i++)
  207. {
  208. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  209. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  210. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  211. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  212. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  213. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  214. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  215. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  216. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  217. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  218. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  219. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  220. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  221. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  222. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  223. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  224. }
  225. if ((pix % 16) != 0)
  226. for (int i=0; i<(pix % 16)+1; i++)
  227. {
  228. pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
  229. }
  230. }