forked from michaelerule/Uno9341TFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMega_TFT.h
96 lines (77 loc) · 3.12 KB
/
Mega_TFT.h
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
/*
Control lines are all on PORTC, and data lines are on PORTB and PORTD.
Communication is faster if we write to PORTC directly. There is one unused
GPIO pin that will be clobbered in this operation, so projects using this
pin should plan accordingly. The reset line is also on PORTC so care must
be taken not to trigger it.
On the 9341, the 8-bit data bus is split with the top six bits on PORTB
and the lower two bits on PORTD. The lower two bits on PORTB are digital
pins 0 and 1, used for the RX and TX serial lines. As far as I can tell,
when the UART is enabled on the AtMega, these pins are decoupled from
PORTB, or at least I have found that setting these pins in the display
driver does not seem to interfere with serial communication. Likewise,
upper bits on PORTD are used to communicate with the touch screen and SD
card slot and for whatever reason sending spurious data on these lines does
not seem to interfere with these functions. If interference is observed,
simply set critical pins to input mode (high impedence) while running
display driver code. Because of this lack of interference, we can send
data using the succinct PORTB=PORTD=data.
Bits are as follows on PORTC (there is no PC7 on AtMega*8)
PC6: Reset (keep high)
PC5: Not used, set to 1 by TFT control code
PC4: RESET LINE keep high
PC3: CS line keep low while driving, leave high to disable interface
PC2: Data send bit. 1 for sending data, 0 for sending command
PC1: Write clock bit. Triggered on rising edge, I think.
PC0: Chip select line. 1 for enabel. Left high by driver code.
#define READY_COMMAND PORTC=0b1110001
#define SEND_COMMAND PORTC=0b1110011
#define READY_DATA PORTC=0b1110101
#define SEND_DATA PORTC=0b1110111
#define READY_READ PORTC=0b1110110
#define REQUEST_READ PORTC=0b1110010
*/
/* #define RS_PIN 4
#define CS_PIN 3
#define CD_PIN 2
#define WR_PIN 1
#define RD_PIN 0
#define CONTROLPORT PORTC */
#define RS_PIN 4
#define CS_PIN 3
#define CD_PIN 2
#define WR_PIN 1
#define RD_PIN 0
#define CONTROLPORT PORTF
#define FRAME_ID_BIT 3
#define QUICK_READ_MASK 0b11111100
#define READ_BYTE (PINA&B11111111)
//////////////////////////////////////////////////////////////////////////
// Formerly pin_magic.h
#define WRITE_BUS(b) {\
PORTA=(b);\
}
#define WRITE_BUS_FAST(b) {\
PORTA=(b);\
}
#define setWriteDir() {\
DDRA |= B11111111;\
}
#define setReadDir() {\
DDRA &= ~B11111111;\
}
//////////////////////////////////////////////////////////////////////////
// Color reading and writing
#define QUICK_READ PINA
//////////////////////////////////////////////////////////////////////////
// Permutations between color bit order and port bit order.
// In the Leonardo these are complex, and are computed ahead of time
// to speed up IO.
// On the Uno, these permutations can be replaced by the identity map.
// Send color data from 565 format into the permuted representation
// for faster IO
#define BIT_TO_PORT_PERMUTATION(b) b
#define PORT_TO_BIT_PERMUTATION(b) b
#define WRITE_PERMUTED_BUS(d) WRITE_BUS(d)
#define IDENTITY(b) BIT_TO_PORT_PERMUTATION(PORT_TO_BIT_PERMUTATION(b))
#define PERMUTED_QUICK_READ QUICK_READ