Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate lcd.c @ 7:9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Factor out LCD init (needs more work)
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 22 Jan 2012 17:10:51 +1030 |
parents | efa2c22266e3 |
children | 58d76cf522ff |
rev | line source |
---|---|
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 /* |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 * Example code (I think) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 * ~/projects/STM32Strive/奋斗STM32开发板例程/奋斗STM32开发板例程/奋斗STM32开发板MINI/STM32奋斗版ucOS II V2.86 uCGUI 3.9 DEMO-V2/STM32奋斗版ucOS II V2.86 uCGUI 3.9 DEMO |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 * |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 * Schematics |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
6 * Main board docs/Strive\ Mini\ STM32\ Schematic.pdf |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
7 * LCD board docs/Strive Mini LCD STM32 Schematic.pdf |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
8 * MCU reference manual docs/CD00171190.pdf |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
9 * MCU Data sheet (pinout) docs/CD00191185.pdf |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
10 * LCD controller data sheet docs/ili9325-v0.35.pdf |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
11 * LCD controller app notes docs/ILI9325AN_V0.22.pdf |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
12 * XXX: not sure what panel is connected |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 * |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 /* LCD board MCU |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 1 VCC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 2 TC_SCK PA5/SPI1_SCK |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 3 GND |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 4 TC_CS PB7/SPI1_CS3 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 5 RST PE1 FSMC_NBL1? (unlikely) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 6 TC_DIN PA7/SPI1_MOSI |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 7 nOE PD4/FSMC_nOE |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 8 TC_DOUT PA6/SPI1_MISO |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 9 nWR PD5/FSMC_nWE |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 10 TC_INT PB6 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 11 CS PD7/FSMC_NE1/FSMC_NCE2 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 12 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 13 RS PD11/FSMC_A16 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 14 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 15 D7 PE10/FSMC_D7 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 16 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 17 D6 PE9/FSMC_D6 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 18 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 19 D3 PD1/FSMC_D3 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 20 D13 PD8/FSMC_D13 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 21 D5 PE8/FSMC_D5 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 22 D12 PE15/FSMC_D12 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 23 D4 PE7/FSMC_D4 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 24 GND |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 25 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 26 D11 PE14/FSMC_D11 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 27 D2 PD0/FSMC_D2 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 28 D10 PE13/FSMC_D10 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 29 D1 PD15/FSMC_D1 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 30 D9 PE12/FSMC_D9 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 31 D0 PD14/FSMC_D0 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
47 32 D14 PD9/FSMC_D14 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 33 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 34 D8 PE11/FSMC_D8 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 35 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 36 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 37 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 38 LCD_PWM PD13/TIM4_CH2 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 39 NC |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 40 D15 PD10/FSMC_D15 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
58 #include <stdio.h> |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 #include "stm32f10x.h" |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 #include "lcd.h" |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
62 static void LCD_Doinit(void); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
63 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
64 #define Bank1_LCD_C ((uint32_t)0x60000000) /* Register Address */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
65 #define Bank1_LCD_D ((uint32_t)0x60020000) /* Data Address */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
66 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
67 void |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
68 LCD_WR_Reg(uint16_t index, uint16_t val) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
69 *(__IO uint16_t *)(Bank1_LCD_C) = index; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
70 *(__IO uint16_t *)(Bank1_LCD_D) = val; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
71 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
72 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
73 uint16_t |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
74 LCD_RD_Reg(uint16_t index) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
75 *(__IO uint16_t *)(Bank1_LCD_C) = index; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
76 return(*(__IO uint16_t *)(Bank1_LCD_D)); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
77 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
78 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
79 uint16_t |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
80 LCD_RD_Data(int first) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
81 uint16_t a = 0; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
82 if (first) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
83 a = *(__IO uint16_t *) (Bank1_LCD_D); /* Dummy */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
84 a = *(__IO uint16_t *) (Bank1_LCD_D); /* Read */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
85 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
86 return (a); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
87 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
88 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
89 void |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
90 LCD_WR_StartData(uint16_t x, uint16_t y) { |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
91 LCD_WR_Reg(0x20, x); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
92 LCD_WR_Reg(0x21, y); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
93 *(__IO uint16_t *)(Bank1_LCD_C) = 0x22; /* Start GRAM write */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
94 } |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
95 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
96 void |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
97 LCD_WR_Data(uint16_t val) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
98 *(__IO uint16_t *)(Bank1_LCD_D) = val; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
99 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
100 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
101 /* This is a bit rough and ready */ |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
102 void |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
103 Delay(__IO uint32_t nCount) { |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
104 __IO uint32_t i; |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
105 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
106 for(; nCount != 0; nCount--) |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
107 for (i = 0; i < 3900; i++) |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
108 ; |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
109 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
110 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
111 uint8_t |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
112 SPI_WriteByte(uint8_t out) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
113 uint8_t in = 0; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
114 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
115 /* Wait until the transmit buffer is empty */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
116 while (SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
117 ; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
118 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
119 /* Send the byte */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
120 SPI_I2S_SendData(SPI1, out); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
121 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
122 /* Wait until a data is received */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
123 while (SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE) == RESET) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
124 ; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
125 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
126 /* Get the received data */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
127 in = SPI_I2S_ReceiveData(SPI1); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
128 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
129 /* Return the shifted data */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
130 return (in); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
131 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
132 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
133 #define TP_SELECT() GPIO_ResetBits(GPIOB, GPIO_Pin_7) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
134 #define TP_DESELECT() GPIO_SetBits(GPIOB, GPIO_Pin_7) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
135 uint16_t |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
136 TPRead(uint8_t type) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
137 uint16_t x = 0; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
138 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
139 /* Select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
140 TP_SELECT(); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
141 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
142 /* Do conversion */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
143 Delay(10); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
144 SPI_WriteByte(type); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
145 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
146 /* Read result */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
147 Delay(10); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
148 x = SPI_WriteByte(0x00); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
149 x <<= 8; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
150 x |= SPI_WriteByte(0x00); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
151 Delay(10); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
152 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
153 /* De-select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
154 TP_DESELECT(); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
155 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
156 /* Right justify 12 bit result */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
157 x = x >> 3; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
158 return (x); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
159 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
160 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
161 #define FL_SELECT() GPIO_ResetBits(GPIOA, GPIO_Pin_4) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
162 #define FL_DESELECT() GPIO_SetBits(GPIOA, GPIO_Pin_4) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
163 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
164 #define FL_READ 0x03 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
165 #define FL_HSREAD 0x0b |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
166 #define FL_32KERASE 0x52 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
167 #define FL_64KERASE 0xd8 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
168 #define FL_CHIPERASE 0x60 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
169 #define FL_BYTEPROG 0x02 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
170 #define FL_AAIWP 0xad |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
171 #define FL_RDSR 0x05 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
172 #define FL_EWSR 0x50 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
173 #define FL_WRSR 0x01 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
174 #define FL_WREN 0x06 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
175 #define FL_WRDI 0x04 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
176 #define FL_RDID 0x90 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
177 #define FL_JEDECID 0x9f |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
178 #define FL_EBSY 0x70 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
179 #define FL_DBSY 0x80 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
180 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
181 uint16_t |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
182 FlashReadID(void) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
183 uint8_t fac, dev; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
184 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
185 FL_SELECT(); /* Select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
186 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
187 SPI_WriteByte(FL_RDID); /* Send command */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
188 SPI_WriteByte(0x00); /* Send address cycles (ID data starts at 0) */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
189 SPI_WriteByte(0x00); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
190 SPI_WriteByte(0x00); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
191 fac = SPI_WriteByte(0x00); /* Read ID */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
192 dev = SPI_WriteByte(0x00); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
193 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
194 FL_DESELECT(); /* De-select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
195 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
196 return fac << 8 | dev; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
197 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
198 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
199 uint8_t |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
200 FlashReadStatus(void) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
201 uint8_t status; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
202 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
203 FL_SELECT(); /* Select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
204 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
205 SPI_WriteByte(FL_RDSR); /* Send command */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
206 SPI_WriteByte(0x00); /* Send dummy byte for address cycle */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
207 status = SPI_WriteByte(0x00); /* Read status */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
208 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
209 FL_DESELECT(); /* De-select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
210 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
211 return status; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
212 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
213 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
214 void |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
215 FlashWriteStatus(uint8_t status) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
216 /* Enable status write */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
217 FL_SELECT(); /* Select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
218 SPI_WriteByte(FL_EWSR); /* Send command */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
219 SPI_WriteByte(0x00); /* Send data byte */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
220 FL_DESELECT(); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
221 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
222 /* Actually write status */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
223 FL_SELECT(); /* Re-select device for new command */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
224 SPI_WriteByte(FL_WRSR); /* Send command */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
225 SPI_WriteByte(status); /* Send data byte */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
226 FL_DESELECT(); /* De-select device */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
227 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
228 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 void |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 LCD_init(void) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
231 GPIO_InitTypeDef GPIO_InitStructure; |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
232 SPI_InitTypeDef SPI_InitStructure; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
233 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
234 FSMC_NORSRAMTimingInitTypeDef p; |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
235 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
236 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
237 /* Enable FSMC clock */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
238 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
239 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
240 /* Enable alternate function IO clock */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
241 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
242 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
243 /* Enable GPIOD clock */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
244 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
246 /* Enable GPIOD clock */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
247 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
248 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 /* Configures LCD Control lines (FSMC Pins) in alternate function Push-Pull mode. |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 * |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
251 * PD0(D2), PD1(D3), PD4(NOE), PD5(NWE), PD7(NE1/CS), PD8(D13), PD9(D14), |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 * PD10(D15), PD11(A16/RS) PD14(D0), PD15(D1) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
253 */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
254 GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
255 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
256 GPIO_Pin_14 | GPIO_Pin_15); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
259 GPIO_Init(GPIOD, &GPIO_InitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
260 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
261 /* PE7(D4), PE8(D5), PE9(D6), PE10(D7), PE11(D8), PE12(D9), PE13(D10), |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
262 * PE14(D11), PE15(D12) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
263 */ |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
264 GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
265 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
266 GPIO_Pin_15); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
267 GPIO_Init(GPIOE, &GPIO_InitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
268 |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
269 /* Configure backlight control (PD13/FSMC_A18 remapped to TIM4_CH2) */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
270 /* Enable TIM4 clock */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
271 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
272 |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
273 /* Enable timer function |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
274 * Note source clock is SYSCLK / 2 = 36MHz |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
275 */ |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
276 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
277 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
278 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
279 GPIO_Init(GPIOD, &GPIO_InitStructure); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
280 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
281 /* Remap TIM4_CH2 to PD13 */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
282 GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
283 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
284 /* Reset TIM4 */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
285 TIM_DeInit(TIM4); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
286 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
287 /* Time Base configuration */ |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
288 TIM_TimeBaseStructure.TIM_Period = 999; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
289 TIM_TimeBaseStructure.TIM_Prescaler = 0; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
290 TIM_TimeBaseStructure.TIM_ClockDivision = 0; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
291 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
292 |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
293 TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
294 |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
295 /* Init to full brightness */ |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
296 lcd_setpwm(1000); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
297 |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
298 /* Enable timer */ |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
299 TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable); |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
300 TIM_ARRPreloadConfig(TIM4, ENABLE); |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
301 TIM_Cmd(TIM4, ENABLE); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
302 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
303 /* Configure reset pin (PE1) as GPIO out PP */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
304 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
305 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
306 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
307 GPIO_Init(GPIOE, &GPIO_InitStructure); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
308 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
309 /* Configures the Parallel interface (FSMC) for LCD (Parallel mode) */ |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
310 /* Timing configuration */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
311 p.FSMC_AddressSetupTime = 5; |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
312 p.FSMC_AddressHoldTime = 5; |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
313 p.FSMC_DataSetupTime = 5; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
314 p.FSMC_BusTurnAroundDuration = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
315 p.FSMC_CLKDivision = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
316 p.FSMC_DataLatency = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
317 p.FSMC_AccessMode = FSMC_AccessMode_A; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
318 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
319 /* FSMC_Bank1_NORSRAM1 configured as follows: |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
320 - Data/Address MUX = Disable |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
321 - Memory Type = SRAM |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
322 - Data Width = 16bit |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
323 - Write Operation = Enable |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
324 - Extended Mode = Disable |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
325 - Asynchronous Wait = Disable */ |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
326 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
327 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
328 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
329 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
330 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
331 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
332 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
333 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
334 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
335 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
336 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
337 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
338 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
339 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
340 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
341 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
342 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
343 /* Enable FSMC_Bank1_NORSRAM1 */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
344 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
345 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
346 /* Configure touch screen controller |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
347 * |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
348 * Connected to SPI1 which is shared with the AT45DB161D. |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
349 * |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
350 * The touch screen is selected with PB7. |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
351 * The flash chip is selected with PA4. |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
352 */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
353 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
354 /* Enable SPI1 clock */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
355 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
356 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
357 /* Configure MOSI, MISO and SCLK as alternate function PP */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
358 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
359 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
360 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
361 GPIO_Init(GPIOA, &GPIO_InitStructure); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
362 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
363 /* Configure flash chip select pin (PA4) as GPIO out PP */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
364 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
365 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
366 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
367 GPIO_Init(GPIOA, &GPIO_InitStructure); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
368 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
369 /* Configure touch chip select pin (PB7) as GPIO out PP */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
370 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
371 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
372 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
373 GPIO_Init(GPIOB, &GPIO_InitStructure); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
374 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
375 /* De-select touch & flash */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
376 GPIO_SetBits(GPIOA, GPIO_Pin_4); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
377 GPIO_SetBits(GPIOB, GPIO_Pin_7); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
378 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
379 /* SPI1 Config */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
380 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
381 SPI_InitStructure.SPI_Mode = SPI_Mode_Master; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
382 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
383 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
384 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
385 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
386 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
387 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
388 SPI_InitStructure.SPI_CRCPolynomial = 7; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
389 SPI_Init(SPI1, &SPI_InitStructure); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
390 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
391 /* SPI1 enable */ |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
392 SPI_Cmd(SPI1, ENABLE); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
393 |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
394 LCD_Doinit(); |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
395 } |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
396 |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
397 void |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
398 lcd_setpwm(uint16_t val) { |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
399 TIM_OCInitTypeDef TIM_OCInitStructure; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
400 |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
401 /* Channel 2 configuration in PWM mode */ |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
402 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
403 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
404 TIM_OCInitStructure.TIM_Pulse = val; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
405 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
406 |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
407 TIM_OC2Init(TIM4, &TIM_OCInitStructure); |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
408 |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
409 } |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
410 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
411 static void |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
412 LCD_Doinit(void) { |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
413 uint16_t id; |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
414 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
415 /* Initialise LCD panel */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
416 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
417 /* Pull reset pin low */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
418 Delay(1); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
419 GPIO_ResetBits(GPIOE, GPIO_Pin_1); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
420 Delay(10); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
421 GPIO_SetBits(GPIOE, GPIO_Pin_1); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
422 Delay(50); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
423 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
424 id = LCD_RD_Reg(0x00); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
425 if (id != 0x9325) { |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
426 printf("LCD ID doesn't match, expected 0x9325 got 0x%x\r\n", id); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
427 return; |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
428 } |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
429 printf("LCD ID matches\r\n"); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
430 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
431 LCD_WR_Reg(0x00e3, 0x3008); /* Set internal timing (not documented) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
432 LCD_WR_Reg(0x00e7, 0x0012); /* Set internal timing (not documented) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
433 LCD_WR_Reg(0x00ef, 0x1231); /* Set internal timing (not documented) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
434 LCD_WR_Reg(0x0000, 0x0001); /* Start Oscillation */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
435 Delay(50); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
436 LCD_WR_Reg(0x0001, 0x0100); /* set SS (S720 -> S1) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
437 LCD_WR_Reg(0x0002, 0x0700); /* set line inversion (B/C + EOR) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
438 LCD_WR_Reg(0x0004, 0x0000); /* no resizing */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
439 LCD_WR_Reg(0x0008, 0x0202); /* set the back porch and front porch (2 lines each) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
440 LCD_WR_Reg(0x0009, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
441 LCD_WR_Reg(0x000a, 0x0000); /* FMARK function */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
442 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
443 LCD_WR_Reg(0x000c, 0x0000); /* RGB ctl - Internal clock, 18bit interface */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
444 LCD_WR_Reg(0x000d, 0x0000); /* Frame marker Position */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
445 LCD_WR_Reg(0x000f, 0x0000); /* RGB interface polarity */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
446 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
447 /* Power On sequence */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
448 LCD_WR_Reg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
449 LCD_WR_Reg(0x0011, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
450 LCD_WR_Reg(0x0012, 0x0000); /* VREG1OUT voltage */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
451 LCD_WR_Reg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
452 Delay(200); /* Dis-charge capacitor power voltage */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
453 LCD_WR_Reg(0x0010, 0x1690); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
454 LCD_WR_Reg(0x0011, 0x0227); /* R11h = 0x0221 at VCI = 3.3V, DC1[2:0], DC0[2:0], VC[2:0] */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
455 Delay(50); /* Delay 50ms */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
456 LCD_WR_Reg(0x0012, 0x001c); /* External reference voltage= Vci; */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
457 Delay(50); /* Delay 50ms */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
458 LCD_WR_Reg(0x0013, 0x1800); /* R13 = 1200 when R12 = 009D; VDV[4:0] for VCOM amplitude */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
459 LCD_WR_Reg(0x0029, 0x001c); /* R29 = 000C when R12 = 009D; VCM[5:0] for VCOMH */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
460 LCD_WR_Reg(0x002b, 0x000d); /* Frame Rate = 91Hz */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
461 Delay(50); /* Delay 50ms */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
462 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
463 /* Set GRAM area */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
464 LCD_WR_Reg(0x0050, 0x0000); /* Horizontal GRAM Start Address */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
465 LCD_WR_Reg(0x0051, 0x00ef); /* Horizontal GRAM End Address */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
466 LCD_WR_Reg(0x0052, 0x0000); /* Vertical GRAM Start Address */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
467 LCD_WR_Reg(0x0053, 0x013f); /* Vertical GRAM Start Address */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
468 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
469 LCD_WR_Reg(0x0060, 0xa700); /* Gate Scan Line, drive G320 -> G1 */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
470 LCD_WR_Reg(0x0061, 0x0003); /* VLE & REV */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
471 LCD_WR_Reg(0x006a, 0x0000); /* set scrolling line */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
472 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
473 /* Partial Display Control */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
474 LCD_WR_Reg(0x0080, 0x0000); /* Image 1 */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
475 LCD_WR_Reg(0x0081, 0x0000); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
476 LCD_WR_Reg(0x0082, 0x0000); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
477 LCD_WR_Reg(0x0083, 0x0000); /* Image 2 */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
478 LCD_WR_Reg(0x0084, 0x0000); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
479 LCD_WR_Reg(0x0085, 0x0000); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
480 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
481 /* Panel Control */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
482 LCD_WR_Reg(0x0090, 0x0010); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
483 LCD_WR_Reg(0x0092, 0x0000); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
484 LCD_WR_Reg(0x0093, 0x0003); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
485 LCD_WR_Reg(0x0095, 0x0110); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
486 LCD_WR_Reg(0x0097, 0x0000); /* Undocumented */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
487 LCD_WR_Reg(0x0098, 0x0000); /* Undocumented */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
488 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
489 LCD_WR_Reg(0x0007, 0x0133); /* Display on, 262k colour mode (vs 8) */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
490 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
491 LCD_WR_Reg(0x0003, 0x1030); /* set GRAM write direction and enable BGR, 64K colours, 1 transfers/pixel. */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
492 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
493 /* Adjust the Gamma Curve */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
494 LCD_WR_Reg(0x0030, 0x0006); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
495 LCD_WR_Reg(0x0031, 0x0101); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
496 LCD_WR_Reg(0x0032, 0x0003); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
497 LCD_WR_Reg(0x0035, 0x0106); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
498 LCD_WR_Reg(0x0036, 0x0b02); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
499 LCD_WR_Reg(0x0037, 0x0302); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
500 LCD_WR_Reg(0x0038, 0x0707); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
501 LCD_WR_Reg(0x0039, 0x0007); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
502 LCD_WR_Reg(0x003c, 0x0600); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
503 LCD_WR_Reg(0x003d, 0x020b); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
504 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
505 fputs("Testing\r\n", stdout); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
506 LCD_WR_StartData(0, 0); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
507 LCD_WR_Data(0xa5a5); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
508 LCD_WR_Data(0x5a5a); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
509 LCD_WR_StartData(0, 0); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
510 if ((id = LCD_RD_Data(1)) != 0xa5a5) |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
511 printf("Expected 0xa5a5 got 0x%04x\r\n", id); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
512 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
513 if ((id = LCD_RD_Data(0)) != 0x5a5a) |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
514 printf("Expected 0x5a5a got 0x%04x\r\n", id); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
515 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
516 fputs("Filling\r\n", stdout); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
517 /* Fill panel */ |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
518 LCD_WR_StartData(0, 0); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
519 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
520 #define RGB24_565(R, G, B) (((((R) >> 3) & 0x1f) << 11) | ((((G) >> 2) & 0x3f) << 5) | (((B) >> 3) & 0x1f)) |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
521 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
522 for (int x = 0; x < 320; x++) { |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
523 for (int y = 0; y < 240; y++) { |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
524 if (((x / 5) % 3) == 0) |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
525 LCD_WR_Data(RGB24_565(255, 0, 0)); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
526 else if (((x / 5) % 3) == 1) |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
527 LCD_WR_Data(RGB24_565(0, 255, 0)); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
528 else |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
529 LCD_WR_Data(RGB24_565(0, 0, 255)); |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
530 } |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
531 } |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
532 |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
533 } |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
534 |