BayEOSArduino Library
HW_SAM3X8E.h
1 // *** Hardwarespecific functions ***
2 void UTFT::_hw_special_init()
3 {
4  //REG_PIOA_OWER = 0xFFFFFFFF;
5  //REG_PIOB_OWER = 0xFFFFFFFF;
6  //REG_PIOC_OWER = 0xFFFFFFFF;
7 }
8 
9 void UTFT::LCD_Writ_Bus(char VH,char VL, byte mode)
10 {
11  switch (mode)
12  {
13  case 1:
14  if (display_serial_mode==SERIAL_4PIN)
15  {
16  if (VH==1)
17  sbi(P_SDA, B_SDA);
18  else
19  cbi(P_SDA, B_SDA);
20  pulse_low(P_SCL, B_SCL);
21  }
22  else
23  {
24  if (VH==1)
25  sbi(P_RS, B_RS);
26  else
27  cbi(P_RS, B_RS);
28  }
29 
30  if (VL & 0x80)
31  sbi(P_SDA, B_SDA);
32  else
33  cbi(P_SDA, B_SDA);
34  pulse_low(P_SCL, B_SCL);
35  if (VL & 0x40)
36  sbi(P_SDA, B_SDA);
37  else
38  cbi(P_SDA, B_SDA);
39  pulse_low(P_SCL, B_SCL);
40  if (VL & 0x20)
41  sbi(P_SDA, B_SDA);
42  else
43  cbi(P_SDA, B_SDA);
44  pulse_low(P_SCL, B_SCL);
45  if (VL & 0x10)
46  sbi(P_SDA, B_SDA);
47  else
48  cbi(P_SDA, B_SDA);
49  pulse_low(P_SCL, B_SCL);
50  if (VL & 0x08)
51  sbi(P_SDA, B_SDA);
52  else
53  cbi(P_SDA, B_SDA);
54  pulse_low(P_SCL, B_SCL);
55  if (VL & 0x04)
56  sbi(P_SDA, B_SDA);
57  else
58  cbi(P_SDA, B_SDA);
59  pulse_low(P_SCL, B_SCL);
60  if (VL & 0x02)
61  sbi(P_SDA, B_SDA);
62  else
63  cbi(P_SDA, B_SDA);
64  pulse_low(P_SCL, B_SCL);
65  if (VL & 0x01)
66  sbi(P_SDA, B_SDA);
67  else
68  cbi(P_SDA, B_SDA);
69  pulse_low(P_SCL, B_SCL);
70  break;
71  case 8:
72 #ifdef CTE_DUE_SHIELD
73  REG_PIOC_CODR=0xFF000;
74  REG_PIOC_SODR=(VH<<12) & 0xFF000;
75  pulse_low(P_WR, B_WR);
76  REG_PIOC_CODR=0xFF000;
77  REG_PIOC_SODR=(VL<<12) & 0xFF000;
78  pulse_low(P_WR, B_WR);
79 #else
80  //Clear port registers
81  REG_PIOA_CODR=0xc000; //PA14,PA15
82  REG_PIOB_CODR=0x4000000; //PB26
83  REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
84 
85  //DB08 on PIN22 -> PIO_PB26
86  REG_PIOB_SODR=(VH<<26) & 0x4000000;
87  //DB09 on PIN23 -> PIO_PA14
88  REG_PIOA_SODR=(VH<<13) & 0x4000;
89  //DB10 on PIN24 -> PIO_PA15
90  REG_PIOA_SODR=(VH<<13) & 0x8000;
91  //DB11 on PIN25 -> PIO_PD0
92  REG_PIOD_SODR=(VH>>3) & 0x01;
93  //DB12 on PIN26 -> PIO_PD1
94  REG_PIOD_SODR=(VH>>3) & 0x02;
95  //DB13 on PIN27 -> PIO_PD2
96  REG_PIOD_SODR=(VH>>3) & 0x04;
97  //DB14 on PIN28 -> PIO_PD3
98  REG_PIOD_SODR=(VH>>3) & 0x08;
99  //DB15 on PIN29 -> PIO_PD6
100  REG_PIOD_SODR=(VH>>1) & 0x40;
101  pulse_low(P_WR, B_WR);
102 
103  REG_PIOA_CODR=0xc000; //PA14,PA15
104  REG_PIOB_CODR=0x4000000; //PB26
105  REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
106  //DB08 on PIN22 -> PIO_PB26
107  REG_PIOB_SODR=(VL<<26) & 0x4000000;
108  //DB09 on PIN23 -> PIO_PA14
109  REG_PIOA_SODR=(VL<<13) & 0x4000;
110  //DB10 on PIN24 -> PIO_PA15
111  REG_PIOA_SODR=(VL<<13) & 0x8000;
112  //DB11 on PIN25 -> PIO_PD0
113  REG_PIOD_SODR=(VL>>3) & 0x01;
114  //DB12 on PIN26 -> PIO_PD1
115  REG_PIOD_SODR=(VL>>3) & 0x02;
116  //DB13 on PIN27 -> PIO_PD2
117  REG_PIOD_SODR=(VL>>3) & 0x04;
118  //DB14 on PIN28 -> PIO_PD3
119  REG_PIOD_SODR=(VL>>3) & 0x08;
120  //DB15 on PIN29 -> PIO_PD6
121  REG_PIOD_SODR=(VL>>1) & 0x40;
122  pulse_low(P_WR, B_WR);
123 #endif
124  break;
125  case 16:
126 #ifdef CTE_DUE_SHIELD
127  REG_PIOC_CODR=0xFF1FE;
128  REG_PIOC_SODR=(VL<<1) & 0x1FE;
129  REG_PIOC_SODR=(VH<<12) & 0xFF000;
130 #else
131  //Clear port registers
132  REG_PIOA_CODR=0xc080; //PA7,PA14,PA15
133  REG_PIOB_CODR=0x4000000; //PB26
134  REG_PIOC_CODR=0x3e; //PC1 - PC5
135  REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
136 
137  //DB00 on PIN37 -> PIO_PC5
138  REG_PIOC_SODR=(VL<<5) & 0x20;
139  //DB01 on PIN36 -> PIO_PC4
140  REG_PIOC_SODR=(VL<<3) & 0x10;
141  //DB02 on PIN35 -> PIO_PC3
142  REG_PIOC_SODR=(VL<<1) & 0x08;
143  //DB03 on PIN34 -> PIO_PC2
144  REG_PIOC_SODR=(VL>>1) & 0x04;
145  //DB04 on PIN33 -> PIO_PC1
146  REG_PIOC_SODR=(VL>>3) & 0x02;
147  //DB05 on PIN32 -> PIO_PD10
148  REG_PIOD_SODR=(VL<<5) & 0x400;
149  //DB06 on PIN31 -> PIO_PA7
150  REG_PIOA_SODR=(VL<<1) & 0x80;
151  //DB07 on PIN30 -> PIO_PD9
152  REG_PIOD_SODR=(VL<<2) & 0x200;
153  //DB08 on PIN22 -> PIO_PB26
154  REG_PIOB_SODR=(VH<<26) & 0x4000000;
155  //DB09 on PIN23 -> PIO_PA14
156  REG_PIOA_SODR=(VH<<13) & 0x4000;
157  //DB10 on PIN24 -> PIO_PA15
158  REG_PIOA_SODR=(VH<<13) & 0x8000;
159  //DB11 on PIN25 -> PIO_PD0
160  REG_PIOD_SODR=(VH>>3) & 0x01;
161  //DB12 on PIN26 -> PIO_PD1
162  REG_PIOD_SODR=(VH>>3) & 0x02;
163  //DB13 on PIN27 -> PIO_PD2
164  REG_PIOD_SODR=(VH>>3) & 0x04;
165  //DB14 on PIN28 -> PIO_PD3
166  REG_PIOD_SODR=(VH>>3) & 0x08;
167  //DB15 on PIN29 -> PIO_PD6
168  REG_PIOD_SODR=(VH>>1) & 0x40;
169 #endif
170  pulse_low(P_WR, B_WR);
171  break;
172  case LATCHED_16:
173  asm("nop"); // Mode is unsupported
174  break;
175  }
176 }
177 
178 void UTFT::_set_direction_registers(byte mode)
179 {
180  if (mode!=LATCHED_16)
181  {
182 #ifdef CTE_DUE_SHIELD
183  if (mode==16)
184  {
185  REG_PIOC_OER=0x000FF1FE;
186  }
187  else
188  REG_PIOC_OER=0x000FF000;
189 #else
190  REG_PIOA_OER=0x0000c000; //PA14,PA15 enable
191  REG_PIOB_OER=0x40000000; //PB26 enable
192  REG_PIOD_OER=0x00000064f; //PD0-3,PD6,PD9-10 enable
193  if (mode==16)
194  {
195  REG_PIOA_OER=0x00000080; //PA7 enable
196  REG_PIOC_OER=0x0000003e; //PC1 - PC5 enable
197  }
198 #endif
199  }
200  else
201  {
202  asm("nop"); // Mode is unsupported
203  }
204 }
205 
206 void UTFT::_fast_fill_16(int ch, int cl, long pix)
207 {
208  long blocks;
209 
210 #ifdef CTE_DUE_SHIELD
211  REG_PIOC_CODR=0xFF1FE;
212  REG_PIOC_SODR=(cl<<1) & 0x1FE;
213  REG_PIOC_SODR=(ch<<12) & 0xFF000;
214 #else
215  //Clear port registers
216  REG_PIOA_CODR=0xc080; //PA7,PA14,PA15
217  REG_PIOB_CODR=0x4000000; //PB26
218  REG_PIOC_CODR=0x3e; //PC1 - PC5
219  REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
220 
221  //DB00 on PIN37 -> PIO_PC5
222  REG_PIOC_SODR=(cl<<5) & 0x20;
223  //DB01 on PIN36 -> PIO_PC4
224  REG_PIOC_SODR=(cl<<3) & 0x10;
225  //DB02 on PIN35 -> PIO_PC3
226  REG_PIOC_SODR=(cl<<1) & 0x08;
227  //DB03 on PIN34 -> PIO_PC2
228  REG_PIOC_SODR=(cl>>1) & 0x04;
229  //DB04 on PIN33 -> PIO_PC1
230  REG_PIOC_SODR=(cl>>3) & 0x02;
231  //DB05 on PIN32 -> PIO_PD10
232  REG_PIOD_SODR=(cl<<5) & 0x400;
233  //DB06 on PIN31 -> PIO_PA7
234  REG_PIOA_SODR=(cl<<1) & 0x80;
235  //DB07 on PIN30 -> PIO_PD9
236  REG_PIOD_SODR=(cl<<2) & 0x200;
237  //DB08 on PIN22 -> PIO_PB26
238  REG_PIOB_SODR=(ch<<26) & 0x4000000;
239  //DB09 on PIN23 -> PIO_PA14
240  REG_PIOA_SODR=(ch<<13) & 0x4000;
241  //DB10 on PIN24 -> PIO_PA15
242  REG_PIOA_SODR=(ch<<13) & 0x8000;
243  //DB11 on PIN25 -> PIO_PD0
244  REG_PIOD_SODR=(ch>>3) & 0x01;
245  //DB12 on PIN26 -> PIO_PD1
246  REG_PIOD_SODR=(ch>>3) & 0x02;
247  //DB13 on PIN27 -> PIO_PD2
248  REG_PIOD_SODR=(ch>>3) & 0x04;
249  //DB14 on PIN28 -> PIO_PD3
250  REG_PIOD_SODR=(ch>>3) & 0x08;
251  //DB15 on PIN29 -> PIO_PD6
252  REG_PIOD_SODR=(ch>>1) & 0x40;
253 #endif
254 
255  blocks = pix/16;
256  for (int i=0; i<blocks; i++)
257  {
258  pulse_low(P_WR, B_WR);
259  pulse_low(P_WR, B_WR);
260  pulse_low(P_WR, B_WR);
261  pulse_low(P_WR, B_WR);
262  pulse_low(P_WR, B_WR);
263  pulse_low(P_WR, B_WR);
264  pulse_low(P_WR, B_WR);
265  pulse_low(P_WR, B_WR);
266  pulse_low(P_WR, B_WR);
267  pulse_low(P_WR, B_WR);
268  pulse_low(P_WR, B_WR);
269  pulse_low(P_WR, B_WR);
270  pulse_low(P_WR, B_WR);
271  pulse_low(P_WR, B_WR);
272  pulse_low(P_WR, B_WR);
273  pulse_low(P_WR, B_WR);
274  }
275  if ((pix % 16) != 0)
276  for (int i=0; i<(pix % 16); i++)
277  {
278  pulse_low(P_WR, B_WR);
279  }
280 }
281 
282 void UTFT::_fast_fill_8(int ch, long pix)
283 {
284  long blocks;
285 
286 #ifdef CTE_DUE_SHIELD
287  REG_PIOC_CODR=0xFF000;
288  REG_PIOC_SODR=(ch<<12) & 0xFF000;
289 #else
290  //Clear port registers
291  REG_PIOA_CODR=0xc000; //PA14,PA15
292  REG_PIOB_CODR=0x4000000; //PB26
293  REG_PIOD_CODR=0x64f; //PD0-3,PD6,PD9-10
294 
295  //DB08 on PIN22 -> PIO_PB26
296  REG_PIOB_SODR=(ch<<26) & 0x4000000;
297  //DB09 on PIN23 -> PIO_PA14
298  REG_PIOA_SODR=(ch<<13) & 0x4000;
299  //DB10 on PIN24 -> PIO_PA15
300  REG_PIOA_SODR=(ch<<13) & 0x8000;
301  //DB11 on PIN25 -> PIO_PD0
302  REG_PIOD_SODR=(ch>>3) & 0x01;
303  //DB12 on PIN26 -> PIO_PD1
304  REG_PIOD_SODR=(ch>>3) & 0x02;
305  //DB13 on PIN27 -> PIO_PD2
306  REG_PIOD_SODR=(ch>>3) & 0x04;
307  //DB14 on PIN28 -> PIO_PD3
308  REG_PIOD_SODR=(ch>>3) & 0x08;
309  //DB15 on PIN29 -> PIO_PD6
310  REG_PIOD_SODR=(ch>>1) & 0x40;
311 #endif
312 
313  blocks = pix/16;
314  for (int i=0; i<blocks; i++)
315  {
316  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
317  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
318  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
319  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
320  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
321  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
322  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
323  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
324  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
325  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
326  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
327  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
328  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
329  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
330  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
331  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
332  }
333  if ((pix % 16) != 0)
334  for (int i=0; i<(pix % 16); i++)
335  {
336  pulse_low(P_WR, B_WR);pulse_low(P_WR, B_WR);
337  }
338 }