@@ -1,555 +1,543 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include "bsp.h" |
|
23 | 23 | #include <streamdevices.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include <gpio.h> |
|
26 | 26 | #include <uart.h> |
|
27 | 27 | #include <stdio.h> |
|
28 | 28 | #include <stm32f4xx_gpio.h> |
|
29 | 29 | #include <stm32f4xx_fsmc.h> |
|
30 | 30 | #include <i2c.h> |
|
31 | 31 | #include <core.h> |
|
32 | 32 | #include <terminal.h> |
|
33 | 33 | |
|
34 | 34 | uint32_t OSC0 =8000000; |
|
35 | 35 | uint32_t INTOSC =16000000; |
|
36 | 36 | uint32_t RTCOSC =32768; |
|
37 | 37 | uint32_t currentCpuFreq=0; |
|
38 | 38 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
39 | 39 | |
|
40 | 40 | LCD_IF_t lcdIF0={ |
|
41 | 41 | .init = &bsp_FSMC_init, |
|
42 | 42 | .writereg = &bsp_lcd0_write_reg, |
|
43 | 43 | .readreg = &bsp_lcd0_read_reg, |
|
44 | 44 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
45 | 45 | .readGRAM = &bsp_lcd0_readGRAM |
|
46 | 46 | }; |
|
47 | 47 | |
|
48 | 48 | LCD_t lcd0={ |
|
49 | 49 | .interface = &lcdIF0, |
|
50 | 50 | .init = &ili9328init, |
|
51 | 51 | .paint = &ili9328paint, |
|
52 | 52 | .paintText = &ili9328paintText, |
|
53 | 53 | .paintFilRect = &ili9328paintFilRect, |
|
54 | 54 | .getPix = &ili9328getPix, |
|
55 | 55 | .refreshenable = &ili9328refreshenable, |
|
56 | 56 | .width= 240, |
|
57 | 57 | .height = 320 |
|
58 | 58 | }; |
|
59 | 59 | |
|
60 | 60 | terminal_t terminal0; |
|
61 | 61 | |
|
62 |
volatile |
|
|
63 |
volatile |
|
|
62 | volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000; | |
|
63 | volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0; | |
|
64 | 64 | |
|
65 | 65 | float VREF0 =(float)3.3; |
|
66 | 66 | volatile vs10XXDev audioCodec0; |
|
67 | 67 | |
|
68 | 68 | sdcardDev sdcard2; |
|
69 | 69 | blkdevice sdcard2blkdev; |
|
70 | 70 | dikpartition sdcard2Part1; |
|
71 | 71 | FAT32fs sdcard2FAT32part1; |
|
72 | 72 | dikpartition sdcard2Part2; |
|
73 | 73 | FAT32fs sdcard2FAT32part2; |
|
74 | 74 | dikpartition sdcard2Part3; |
|
75 | 75 | FAT32fs sdcard2FAT32part3; |
|
76 | 76 | dikpartition sdcard2Part4; |
|
77 | 77 | FAT32fs sdcard2FAT32part4; |
|
78 | 78 | |
|
79 | 79 | int bsp_init() |
|
80 | 80 | { |
|
81 | 81 | int i=0; |
|
82 | 82 | for(i=0;i<__MAX_OPENED_FILES__;i++) |
|
83 | 83 | { |
|
84 | 84 | __opnfiles__[i] = NULL; |
|
85 | 85 | } |
|
86 | 86 | bsp_GPIO_init(); |
|
87 | 87 | bsp_uart_init(); |
|
88 | 88 | bsp_iic_init(); |
|
89 | 89 | bsp_FSMC_init(); |
|
90 | 90 | bsp_GTerm_init(); |
|
91 | 91 | bsp_spi_init(); |
|
92 | 92 | bsp_SD_init(); |
|
93 | 93 | bsp_Audio_init(); |
|
94 | 94 | printf("\r=====================\n\r"); |
|
95 | 95 | printf( "=====================\n\r"); |
|
96 | 96 | printf(BSP); |
|
97 | 97 | printf(" initialised\n\r"); |
|
98 | 98 | printf( "=====================\n\r"); |
|
99 | 99 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
100 | 100 | printf( "BIG ENDIAN MACHINE\n\r"); |
|
101 | 101 | #else |
|
102 | 102 | printf( "LITLE ENDIAN MACHINE\n\r"); |
|
103 | 103 | #endif |
|
104 | 104 | return 1; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void bsp_GPIO_init() |
|
108 | 108 | { |
|
109 | 109 | gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS}; |
|
110 | 110 | for(int i=0;i<8;i++) |
|
111 | 111 | { |
|
112 | 112 | gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]); |
|
113 | 113 | GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype; |
|
114 | 114 | gpiosetconfig(&GPIO_init); |
|
115 | 115 | } |
|
116 | 116 | gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3}; |
|
117 | 117 | for(int i=0;i<3;i++) |
|
118 | 118 | { |
|
119 | 119 | gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]); |
|
120 | 120 | GPIO_init |= gpiohighspeed | gpioindir; |
|
121 | 121 | gpiosetconfig(&GPIO_init); |
|
122 | 122 | } |
|
123 | 123 | gpioclr(VS1053xRESET); |
|
124 | 124 | gpioset(VS1053xCS); |
|
125 | 125 | gpioset(VS1053xDCS); |
|
126 | 126 | gpioset(SDCARD2CS); |
|
127 | 127 | gpioclr(LCD_RESET); |
|
128 | 128 | gpioclr(LCD_BACKL); |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void bsp_uart_init() |
|
132 | 132 | { |
|
133 | 133 | // if(__opnfiles__[1]==NULL) |
|
134 | 134 | // { |
|
135 | 135 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
136 | 136 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
137 | 137 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); |
|
138 | 138 | // uartmkstreamdev(uart,fd1); |
|
139 | 139 | // __opnfiles__[1] = fd1; |
|
140 | 140 | // } |
|
141 | 141 | // else |
|
142 | 142 | // { |
|
143 | 143 | // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); |
|
144 | 144 | // } |
|
145 | 145 | } |
|
146 | 146 | |
|
147 | 147 | /* |
|
148 | 148 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
149 | 149 | D5 PE8 D6 PE9 D7 PE10 |
|
150 | 150 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
151 | 151 | FSMC_NOE PD4 RD |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | int bsp_FSMC_init() |
|
155 | 155 | { |
|
156 | 156 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
157 | 157 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
158 | 158 | |
|
159 | 159 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ |
|
160 | 160 | ,PD4,PD5,PD7,PE4}; |
|
161 | 161 | for(int i=0;i<12;i++) |
|
162 | 162 | { |
|
163 | 163 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
164 | 164 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
165 | 165 | gpiosetconfig(&LCD_DBx); |
|
166 | 166 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
170 | 170 | FSMC_NORSRAMTimingInitTypeDef p,readtim; |
|
171 | 171 | |
|
172 | 172 | /* Enable FSMC clock */ |
|
173 | 173 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
174 | 174 | |
|
175 | 175 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
176 | 176 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
177 | 177 | /* FSMC_Bank1_NORSRAM4 configuration */ |
|
178 |
p.FSMC_AddressSetupTime = |
|
|
179 |
p.FSMC_AddressHoldTime = |
|
|
178 | p.FSMC_AddressSetupTime = 3; | |
|
179 | p.FSMC_AddressHoldTime = 3; | |
|
180 | 180 | //ili9328 -> data setup time > 10ns |
|
181 |
p.FSMC_DataSetupTime = |
|
|
181 | p.FSMC_DataSetupTime = 1; | |
|
182 | 182 | if(getCpuFreq()>100*1000*1000) |
|
183 |
p.FSMC_DataSetupTime = |
|
|
184 |
p.FSMC_BusTurnAroundDuration = 0 |
|
|
183 | p.FSMC_DataSetupTime = 2;// 11; | |
|
184 | p.FSMC_BusTurnAroundDuration = 0; | |
|
185 | 185 | p.FSMC_CLKDivision = 0; |
|
186 |
p.FSMC_DataLatency = 0 |
|
|
186 | p.FSMC_DataLatency = 0; | |
|
187 | 187 | //ili9328 -> data hold time > 15ns |
|
188 | 188 | if(getCpuFreq()>66*1000*1000) |
|
189 |
p.FSMC_DataLatency = 0 |
|
|
189 | p.FSMC_DataLatency = 0; | |
|
190 | 190 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
191 | 191 | |
|
192 | readtim.FSMC_AddressSetupTime = 0xf; | |
|
193 | readtim.FSMC_AddressHoldTime = 0xf; | |
|
194 | //p.FSMC_DataSetupTime = 9; | |
|
195 | readtim.FSMC_DataSetupTime = 0xf ;// 11; | |
|
196 | if(getCpuFreq()>100*1000*1000) | |
|
197 | readtim.FSMC_DataSetupTime = 0xf;// 11; | |
|
198 | readtim.FSMC_BusTurnAroundDuration = 0xf; | |
|
199 | readtim.FSMC_CLKDivision = 0; | |
|
200 | readtim.FSMC_DataLatency = 0xf; | |
|
201 | if(getCpuFreq()>66*1000*1000) | |
|
202 | readtim.FSMC_DataLatency = 0xf; | |
|
203 | readtim.FSMC_AccessMode = FSMC_AccessMode_A; | |
|
204 | ||
|
205 | 192 | |
|
206 | 193 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
|
207 | 194 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
208 | 195 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
209 | 196 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; |
|
210 | 197 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
211 | 198 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
212 | 199 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
213 | 200 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
214 | 201 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
215 | 202 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
216 | 203 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
217 | 204 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
218 | 205 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
219 |
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = & |
|
|
206 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; | |
|
220 | 207 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
221 | 208 | |
|
222 | 209 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
223 | 210 | |
|
224 | 211 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
|
225 | 212 | gpioset(LCD_RESET); |
|
226 | 213 | gpioclr(LCD_RESET); |
|
227 | 214 | delay_100us(500); |
|
228 | 215 | gpioset(LCD_RESET); |
|
229 | 216 | delay_100us(500); |
|
230 | 217 | lcd0.init(&lcd0); |
|
231 | 218 | gpioset(LCD_BACKL); |
|
232 | 219 | return 1; |
|
233 | 220 | } |
|
234 | 221 | |
|
235 | 222 | void bsp_spi_init() |
|
236 | 223 | { |
|
237 | 224 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; |
|
238 | 225 | for(int i=0;i<3;i++) |
|
239 | 226 | { |
|
240 | 227 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); |
|
241 | 228 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
242 | 229 | gpiosetconfig(&SPI_DBx); |
|
243 | 230 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); |
|
244 | 231 | } |
|
245 | 232 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); |
|
246 | 233 | |
|
247 | 234 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; |
|
248 | 235 | for(int i=0;i<3;i++) |
|
249 | 236 | { |
|
250 | 237 | gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); |
|
251 | 238 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
252 | 239 | gpiosetconfig(&SPI_DBx); |
|
253 | 240 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); |
|
254 | 241 | } |
|
255 | 242 | spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); |
|
256 | 243 | |
|
257 | 244 | } |
|
258 | 245 | |
|
259 | 246 | |
|
260 | 247 | void bsp_iic_init() |
|
261 | 248 | { |
|
262 | 249 | // i2copenandconfig(i2c2,0,10000,PF0,PF1); |
|
263 | 250 | } |
|
264 | 251 | |
|
265 | 252 | |
|
266 | 253 | void bsp_Audio_init() |
|
267 | 254 | { |
|
268 | 255 | vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ); |
|
269 | 256 | if(audioCodec0.VERSION!=UNKNOWN) |
|
270 | 257 | { |
|
271 | 258 | printf("detected Audio codec "); |
|
272 | 259 | switch (audioCodec0.VERSION) { |
|
273 | 260 | case VS1001: |
|
274 | 261 | printf("VS1001\n"); |
|
275 | 262 | break; |
|
276 | 263 | case VS1011: |
|
277 | 264 | printf("VS1011\n"); |
|
278 | 265 | break; |
|
279 | 266 | case VS1002: |
|
280 | 267 | printf("VS1002\n"); |
|
281 | 268 | break; |
|
282 | 269 | case VS1003: |
|
283 | 270 | printf("VS1003\n"); |
|
284 | 271 | break; |
|
285 | 272 | case VS1053: |
|
286 | 273 | printf("VS1053\n"); |
|
287 | 274 | break; |
|
288 | 275 | case VS1033: |
|
289 | 276 | printf("VS1033\n"); |
|
290 | 277 | break; |
|
291 | 278 | case VS1103: |
|
292 | 279 | printf("VS1103\n"); |
|
293 | 280 | break; |
|
294 | 281 | default: |
|
295 | 282 | printf("Unknown device\n"); |
|
296 | 283 | break; |
|
297 | 284 | } |
|
298 | 285 | } |
|
299 | 286 | } |
|
300 | 287 | |
|
301 | 288 | void bsp_SD_init() |
|
302 | 289 | { |
|
303 | 290 | if(bspsdcardpresent()) |
|
304 | 291 | { |
|
305 | 292 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); |
|
306 | 293 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); |
|
307 | 294 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) |
|
308 | 295 | { |
|
309 | 296 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) |
|
310 | 297 | { |
|
311 | 298 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) |
|
312 | 299 | printf("Can't open fat32 partition 1\n"); |
|
313 | 300 | } |
|
314 | 301 | else |
|
315 | 302 | { |
|
316 | 303 | printf("Can't open or read MBR\n"); |
|
317 | 304 | } |
|
318 | 305 | delay_100us(1000); |
|
319 | 306 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) |
|
320 | 307 | { |
|
321 | 308 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) |
|
322 | 309 | printf("Can't open fat32 partition 2\n"); |
|
323 | 310 | } |
|
324 | 311 | else |
|
325 | 312 | { |
|
326 | 313 | printf("Can't open or read MBR\n"); |
|
327 | 314 | } |
|
328 | 315 | delay_100us(1000); |
|
329 | 316 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) |
|
330 | 317 | { |
|
331 | 318 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) |
|
332 | 319 | printf("Can't open fat32 partition 3\n"); |
|
333 | 320 | } |
|
334 | 321 | else |
|
335 | 322 | { |
|
336 | 323 | printf("Can't open or read MBR\n"); |
|
337 | 324 | } |
|
338 | 325 | delay_100us(1000); |
|
339 | 326 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) |
|
340 | 327 | { |
|
341 | 328 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) |
|
342 | 329 | printf("Can't open fat32 partition 4\n"); |
|
343 | 330 | } |
|
344 | 331 | else |
|
345 | 332 | { |
|
346 | 333 | printf("Can't open or read MBR\n"); |
|
347 | 334 | } |
|
348 | 335 | } |
|
349 | 336 | else |
|
350 | 337 | { |
|
351 | 338 | printf("Can't initialize SDCARD\n"); |
|
352 | 339 | } |
|
353 | 340 | } |
|
354 | 341 | delay_100us(2000); |
|
355 | 342 | } |
|
356 | 343 | |
|
357 | 344 | void vs1052setXCS(char val) |
|
358 | 345 | { |
|
359 | 346 | gpiosetval(VS1053xCS,(int)val); |
|
360 | 347 | } |
|
361 | 348 | |
|
362 | 349 | void vs1052setXDCS(char val) |
|
363 | 350 | { |
|
364 | 351 | //gpiosetval(LED1,(int)val); |
|
365 | 352 | gpiosetval(VS1053xDCS,(int)val); |
|
366 | 353 | } |
|
367 | 354 | |
|
368 | 355 | void vs1052setRST(char val) |
|
369 | 356 | { |
|
370 | 357 | if(val) |
|
371 | 358 | gpioset(VS1053xRESET); |
|
372 | 359 | else |
|
373 | 360 | gpioclr(VS1053xRESET); |
|
374 | 361 | } |
|
375 | 362 | |
|
376 | 363 | int vs10XXDREQ() |
|
377 | 364 | { |
|
378 | 365 | return gpiogetval(VS1053DREQ); |
|
379 | 366 | } |
|
380 | 367 | |
|
381 | 368 | |
|
382 | 369 | void bsppowersdcard(char onoff) //always ON |
|
383 | 370 | { |
|
384 | 371 | |
|
385 | 372 | } |
|
386 | 373 | |
|
387 | 374 | char bspsdcardpresent() |
|
388 | 375 | { |
|
389 | 376 | return gpiogetval(SDCARD2CD); |
|
390 | 377 | } |
|
391 | 378 | |
|
392 | 379 | char bspsdcardwriteprotected() |
|
393 | 380 | { |
|
394 | 381 | return 0; |
|
395 | 382 | } |
|
396 | 383 | |
|
397 | 384 | void bspsdcardselect(char YESNO) |
|
398 | 385 | { |
|
399 | 386 | // gpiosetval(LED1,(int)YESNO); |
|
400 | 387 | if(YESNO) |
|
401 | 388 | gpioclr(SDCARD2CS); |
|
402 | 389 | else |
|
403 | 390 | gpioset(SDCARD2CS); |
|
404 | 391 | } |
|
405 | 392 | |
|
406 | 393 | |
|
407 | 394 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
408 | 395 | { |
|
409 | 396 | uint8_t* pt8 = (uint8_t*)(void*)(®); |
|
410 | *lcd0_CMD=(uint8_t)0; | |
|
411 | *lcd0_CMD=(uint8_t)0; | |
|
412 | *lcd0_CMD=(uint8_t)0; | |
|
413 | *lcd0_CMD=(uint8_t)0; | |
|
414 | 397 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
415 | 398 | *lcd0_CMD=pt8[3]; |
|
416 | 399 | *lcd0_CMD=pt8[2]; |
|
417 | 400 | pt8 = (uint8_t*)(void*)&data; |
|
418 | 401 | *lcd0_DATA=pt8[3]; |
|
419 | 402 | *lcd0_DATA=pt8[2]; |
|
420 | 403 | #else |
|
404 | ||
|
421 | 405 | *lcd0_CMD=pt8[1]; |
|
422 | 406 | *lcd0_CMD=pt8[0]; |
|
423 | 407 | pt8 = (uint8_t*)(void*)&data; |
|
424 | 408 | *lcd0_DATA=pt8[1]; |
|
425 | 409 | *lcd0_DATA=pt8[0]; |
|
426 | 410 | #endif |
|
427 | 411 | |
|
428 | 412 | } |
|
429 | 413 | |
|
430 | 414 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
431 | 415 | { |
|
432 | 416 | uint8_t* pt8 = (uint8_t*)(void*)(®); |
|
433 | 417 | uint32_t DATA=0; |
|
434 | *lcd0_CMD=(uint8_t)0; | |
|
435 | *lcd0_CMD=(uint8_t)0; | |
|
436 | *lcd0_CMD=(uint8_t)0; | |
|
437 | *lcd0_CMD=(uint8_t)0; | |
|
418 | ||
|
438 | 419 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
439 | 420 | *lcd0_CMD=pt8[3]; |
|
440 | 421 | *lcd0_CMD=pt8[2]; |
|
441 | 422 | pt8 = (uint8_t*)(void*)&DATA; |
|
442 | 423 | pt8[3]=*lcd0_DATA; |
|
443 | 424 | pt8[2]=*lcd0_DATA; |
|
444 | 425 | #else |
|
445 | 426 | |
|
446 | 427 | *lcd0_CMD=pt8[1]; |
|
447 | 428 | *lcd0_CMD=pt8[0]; |
|
448 | 429 | pt8 = (uint8_t*)(void*)&DATA; |
|
449 | 430 | pt8[1]=*lcd0_DATA; |
|
450 | 431 | pt8[0]=*lcd0_DATA; |
|
451 | 432 | #endif |
|
452 | 433 | |
|
453 | 434 | return DATA; |
|
454 | 435 | } |
|
455 | 436 | |
|
456 | 437 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
457 | 438 | { |
|
458 | 439 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; |
|
459 | 440 | uint8_t* pt8 = (uint8_t*)(void*)(®); |
|
460 | *lcd0_CMD=(uint8_t)0; | |
|
461 | *lcd0_CMD=(uint8_t)0; | |
|
462 | *lcd0_CMD=(uint8_t)0; | |
|
463 | *lcd0_CMD=(uint8_t)0; | |
|
464 | 441 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
465 | 442 | *lcd0_CMD=pt8[3]; |
|
466 | 443 | *lcd0_CMD=pt8[2]; |
|
467 | 444 | pt8 = (uint8_t*)(void*)buffer; |
|
468 | 445 | for(int i=0;i<(int)count;i++) |
|
469 | 446 | { |
|
470 | 447 | *lcd0_DATA=pt8[(2*i) +1]; |
|
471 | 448 | *lcd0_DATA=pt8[2*i]; |
|
472 | 449 | } |
|
473 | 450 | #else |
|
474 | 451 | |
|
475 | 452 | *lcd0_CMD=pt8[1]; |
|
476 | 453 | *lcd0_CMD=pt8[0]; |
|
477 | 454 | pt8 = (uint8_t*)(void*)buffer; |
|
478 | 455 | for(int i=0;i<(int)count;i++) |
|
479 | 456 | { |
|
480 | 457 | |
|
481 | 458 | *lcd0_DATA=pt8[(2*i) +1]; |
|
482 | 459 | *lcd0_DATA=pt8[2*i]; |
|
483 | 460 | } |
|
484 | 461 | #endif |
|
485 | 462 | } |
|
486 | 463 | |
|
487 | 464 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
488 | 465 | { |
|
489 |
|
|
|
490 |
volatile uint8_t* pt8 |
|
|
491 | *lcd0_CMD=(uint8_t)0; | |
|
492 | *lcd0_CMD=(uint8_t)0; | |
|
493 | *lcd0_CMD=(uint8_t)0; | |
|
494 | *lcd0_CMD=(uint8_t)0; | |
|
495 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
466 | //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
|
467 | volatile uint8_t* pt8 ;// = (uint8_t*)(void*)® | |
|
468 | /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
496 | 469 | *lcd0_CMD=pt8[3]; |
|
497 | 470 | *lcd0_CMD=pt8[2]; |
|
498 | 471 | pt8 = (uint8_t*)(void*)buffer; |
|
499 | 472 | for(int i=0;i<(int)count;i++) |
|
500 | 473 | { |
|
501 | 474 | pt8[(2*i) +1]=*lcd0_DATA; |
|
502 | 475 | pt8[2*i]=*lcd0_DATA; |
|
503 | 476 | } |
|
504 | 477 | #else |
|
478 | *lcd0_CMD=(uint8_t)0; | |
|
479 | *lcd0_CMD=(uint8_t)0; | |
|
480 | *lcd0_CMD=(uint8_t)0; | |
|
481 | *lcd0_CMD=(uint8_t)0; | |
|
505 | 482 | *lcd0_CMD=pt8[1]; |
|
506 | 483 | *lcd0_CMD=pt8[0]; |
|
507 |
|
|
|
484 | pt8 = (uint8_t*)buffer;*/ | |
|
508 | 485 | /* |
|
509 | 486 |
|
|
510 | 487 |
|
|
511 | pt8[0]=*lcd0_DATA; | |
|
488 | /* pt8[0]=*lcd0_DATA; | |
|
512 | 489 | pt8[1]=*lcd0_DATA; |
|
513 | 490 |
|
|
514 | 491 | for(int i=0;i<(int)count;i++) |
|
515 | 492 | { |
|
516 | 493 | pt8[(2*i) +1]=*lcd0_DATA; |
|
517 | 494 | pt8[2*i]=*lcd0_DATA; |
|
518 | 495 | pt8[(2*i) +1]=*lcd0_DATA; |
|
519 | 496 | pt8[2*i]=*lcd0_DATA; |
|
520 | // pt8[(2*i) +1]=(uint8_t)0; | |
|
521 | // pt8[(2*i)]=(uint8_t)0; | |
|
522 | 497 | } |
|
523 |
|
|
|
498 | #endif*/ | |
|
499 | ||
|
500 | *lcd0_CMD=(uint8_t)0; | |
|
501 | *lcd0_CMD=(uint8_t)0x22; | |
|
502 | pt8 = (uint8_t*)buffer; | |
|
503 | pt8[1]=*lcd0_DATA; | |
|
504 | pt8[0]=*lcd0_DATA; | |
|
505 | for(int i=0;i<(int)count;i++) | |
|
506 | { | |
|
507 | //pt8[(2*i) +1]=0; | |
|
508 | //pt8[2*i]=0; | |
|
509 | pt8[(2*i)+1]= *lcd0_DATA; | |
|
510 | pt8[2*i]= *lcd0_DATA; | |
|
511 | } | |
|
524 | 512 | } |
|
525 | 513 | |
|
526 | 514 | void bsp_GTerm_init() |
|
527 | 515 | { |
|
528 | 516 | if(__opnfiles__[1]==NULL) |
|
529 | 517 | { |
|
530 | 518 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
531 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); | |
|
519 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); | |
|
532 | 520 | __opnfiles__[1] = fd1; |
|
533 | 521 | } |
|
534 | 522 | else |
|
535 | 523 | { |
|
536 | 524 | |
|
537 | 525 | } |
|
538 | 526 | } |
|
539 | 527 | |
|
540 | 528 | |
|
541 | 529 | |
|
542 | 530 | |
|
543 | 531 | |
|
544 | 532 | |
|
545 | 533 | |
|
546 | 534 | |
|
547 | 535 | |
|
548 | 536 | |
|
549 | 537 | |
|
550 | 538 | |
|
551 | 539 | |
|
552 | 540 | |
|
553 | 541 | |
|
554 | 542 | |
|
555 | 543 |
@@ -1,365 +1,363 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include "bsp.h" |
|
23 | 23 | #include <streamdevices.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include <gpio.h> |
|
26 | 26 | #include <uart.h> |
|
27 | 27 | #include <stdio.h> |
|
28 | 28 | #include <stm32f4xx_gpio.h> |
|
29 | 29 | #include <stm32f4xx_fsmc.h> |
|
30 | 30 | #include <i2c.h> |
|
31 | 31 | #include <core.h> |
|
32 | 32 | #include <terminal.h> |
|
33 | 33 | uint32_t OSC0 =8000000; |
|
34 | 34 | uint32_t INTOSC =16000000; |
|
35 | 35 | uint32_t RTCOSC =32768; |
|
36 | 36 | uint32_t currentCpuFreq=0; |
|
37 | 37 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
38 | 38 | |
|
39 | 39 | LCD_IF_t lcdIF0={ |
|
40 | 40 | .init = &bsp_FSMC_init, |
|
41 | 41 | .writereg = &bsp_lcd0_write_reg, |
|
42 | 42 | .readreg = &bsp_lcd0_read_reg, |
|
43 | 43 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
44 | 44 | .readGRAM = &bsp_lcd0_readGRAM |
|
45 | 45 | }; |
|
46 | 46 | |
|
47 | 47 | LCD_t lcd0={ |
|
48 | 48 | .interface = &lcdIF0, |
|
49 | 49 | .init = &ili9328init, |
|
50 | 50 | .paint = &ili9328paint, |
|
51 | 51 | .paintText = &ili9328paintText, |
|
52 | 52 | .paintFilRect = &ili9328paintFilRect, |
|
53 | 53 | .getPix = &ili9328getPix, |
|
54 | 54 | .refreshenable = &ili9328refreshenable, |
|
55 | 55 | .width= 240, |
|
56 | 56 | .height = 320 |
|
57 | 57 | }; |
|
58 | 58 | |
|
59 | 59 | terminal_t terminal0; |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | volatile int16_t* lcd0_CMD=(volatile int16_t*) (0x60000000 | 0x08000000); |
|
63 | 63 | volatile int16_t* lcd0_DATA=((volatile int16_t*)(0x60000000 | 0x08000002)); |
|
64 | 64 | |
|
65 | 65 | float VREF0 =(float)3.3; |
|
66 | 66 | |
|
67 | 67 | int bsp_init() |
|
68 | 68 | { |
|
69 | 69 | int i=0; |
|
70 | 70 | for(i=0;i<32;i++) |
|
71 | 71 | { |
|
72 | 72 | __opnfiles__[i] = NULL; |
|
73 | 73 | } |
|
74 | 74 | bsp_GPIO_init(); |
|
75 | 75 | bsp_uart_init(); |
|
76 | 76 | bsp_iic_init(); |
|
77 | 77 | bsp_FSMC_init(); |
|
78 | 78 | bsp_GTerm_init(); |
|
79 | 79 | printf("\r=====================\n\r"); |
|
80 | 80 | printf( "=====================\n\r"); |
|
81 | 81 | printf(BSP); |
|
82 | 82 | printf(" initialised\n\r"); |
|
83 | 83 | printf( "=====================\n\r"); |
|
84 | 84 | return 1; |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | void bsp_GPIO_init() |
|
88 | 88 | { |
|
89 | 89 | gpio_t gpio1 = gpioopen(LED1); |
|
90 | 90 | gpio_t gpio2 = gpioopen(LED2); |
|
91 | 91 | gpio_t gpio3 = gpioopen(LED3); |
|
92 | 92 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
93 | 93 | gpiosetspeed(&gpio2,gpiohighspeed); |
|
94 | 94 | gpiosetspeed(&gpio3,gpiohighspeed); |
|
95 | 95 | gpiosetdir(&gpio1,gpiooutdir); |
|
96 | 96 | gpiosetdir(&gpio2,gpiooutdir); |
|
97 | 97 | gpiosetdir(&gpio3,gpiooutdir); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | void bsp_uart_init() |
|
101 | 101 | { |
|
102 | 102 | //if(__opnfiles__[1]==NULL) |
|
103 | 103 | //{ |
|
104 | 104 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
105 | 105 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
106 | 106 | // uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
107 | 107 | //uartmkstreamdev(uart,fd1); |
|
108 | 108 | //__opnfiles__[1] = fd1; |
|
109 | 109 | //} |
|
110 | 110 | //else |
|
111 | 111 | //{ |
|
112 | 112 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
113 | 113 | //} |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | /* |
|
117 | 117 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
118 | 118 | D5 PE8 D6 PE9 D7 PE10 D8 PE11 D9 PE12 |
|
119 | 119 | D10 PE13 D11 PE14 D12 PE15 D13 PD8 D14 PD9 |
|
120 | 120 | D15 PD10 |
|
121 | 121 | A0 PF0 = RS FSMC_NE3 PG10 CS FSMC_NWE PD5 W/S |
|
122 | 122 | FSMC_NOE PD4 RD |
|
123 | 123 | */ |
|
124 | 124 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
|
125 | 125 | /* |
|
126 | 126 | +-------------------+--------------------+------------------+------------------+ |
|
127 | 127 | + SRAM pins assignment + |
|
128 | 128 | +-------------------+--------------------+------------------+------------------+ |
|
129 | 129 | | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | |
|
130 | 130 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | |
|
131 | 131 | | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | |
|
132 | 132 | | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | |
|
133 | 133 | | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | |
|
134 | 134 | | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | |
|
135 | 135 | | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | |
|
136 | 136 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ |
|
137 | 137 | | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | |
|
138 | 138 | | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | |
|
139 | 139 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ |
|
140 | 140 | | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | |
|
141 | 141 | | | PE15 <-> FSMC_D12 | |
|
142 | 142 | +-------------------+--------------------+ |
|
143 | 143 | */ |
|
144 | 144 | int bsp_FSMC_init() |
|
145 | 145 | { |
|
146 | 146 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
147 | 147 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
148 | 148 | |
|
149 | 149 | gpio_t LCD_DBxList[]={ |
|
150 | 150 | PD0 ,PD1 ,PD4 ,PD5 ,PD8 ,PD9 ,PD10,PD11,PD12,PD13,PD14,PD15, |
|
151 | 151 | PE0 ,PE1 ,PE3 ,PE4 ,PE7 ,PE8 ,PE9 ,PE10,PE11,PE12,PE13,PE14, |
|
152 | 152 | PE15,PF0 ,PF1 ,PF2 ,PF3 ,PF4 ,PF5 ,PF12,PF13,PF14,PF15,PG0 , |
|
153 | 153 | PG1 ,PG2 ,PG3 ,PG4 ,PG5 ,PG9 ,PG10 |
|
154 | 154 | }; |
|
155 | 155 | |
|
156 | 156 | for(int i=0;i<43;i++) |
|
157 | 157 | { |
|
158 | 158 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
159 | 159 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
160 | 160 | gpiosetconfig(&LCD_DBx); |
|
161 | 161 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
165 | 165 | FSMC_NORSRAMTimingInitTypeDef p,readtim; |
|
166 | 166 | |
|
167 | 167 | /* Enable FSMC clock */ |
|
168 | 168 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
169 | 169 | |
|
170 | 170 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
171 | 171 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
172 | 172 | /* FSMC_Bank1_NORSRAM3 configuration */ |
|
173 | 173 | p.FSMC_AddressSetupTime = 0xf; |
|
174 | 174 | p.FSMC_AddressHoldTime = 0xf; |
|
175 | 175 | //ili9328 -> data setup time > 10ns |
|
176 | 176 | p.FSMC_DataSetupTime = 0xf; |
|
177 | 177 | if(getCpuFreq()>100*1000*1000) |
|
178 | 178 | p.FSMC_DataSetupTime = 0xf;// 11; |
|
179 | 179 | p.FSMC_BusTurnAroundDuration = 0xf; |
|
180 | 180 | p.FSMC_CLKDivision = 0; |
|
181 | 181 | p.FSMC_DataLatency = 0xf; |
|
182 | 182 | //ili9328 -> data hold time > 15ns |
|
183 | 183 | if(getCpuFreq()>66*1000*1000) |
|
184 | 184 | p.FSMC_DataLatency = 0xf; |
|
185 | 185 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
186 | 186 | |
|
187 | 187 | readtim.FSMC_AddressSetupTime = 0xf; |
|
188 | 188 | readtim.FSMC_AddressHoldTime = 0xf; |
|
189 | 189 | //p.FSMC_DataSetupTime = 9; |
|
190 | 190 | readtim.FSMC_DataSetupTime = 0xf ;// 11; |
|
191 | 191 | if(getCpuFreq()>100*1000*1000) |
|
192 | 192 | readtim.FSMC_DataSetupTime = 0xf;// 11; |
|
193 | 193 | readtim.FSMC_BusTurnAroundDuration = 0xf; |
|
194 | 194 | readtim.FSMC_CLKDivision = 0; |
|
195 | 195 | readtim.FSMC_DataLatency = 0xf; |
|
196 | 196 | if(getCpuFreq()>66*1000*1000) |
|
197 | 197 | readtim.FSMC_DataLatency = 0xf; |
|
198 | 198 | readtim.FSMC_AccessMode = FSMC_AccessMode_A; |
|
199 | 199 | /* Color LCD configuration ------------------------------------ |
|
200 | 200 | LCD configured as follow: |
|
201 | 201 | - Data/Address MUX = Disable |
|
202 | 202 | - Memory Type = SRAM |
|
203 | 203 | - Data Width = 16bit |
|
204 | 204 | - Write Operation = Enable |
|
205 | 205 | - Extended Mode = Enable |
|
206 | 206 | - Asynchronous Wait = Disable */ |
|
207 | 207 | |
|
208 | 208 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; |
|
209 | 209 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
210 | 210 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
211 | 211 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
212 | 212 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
213 | 213 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
214 | 214 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
215 | 215 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
216 | 216 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
217 | 217 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
218 | 218 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
219 | 219 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
220 | 220 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
221 | 221 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readtim; |
|
222 | 222 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
223 | 223 | |
|
224 | 224 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
225 | 225 | |
|
226 | 226 | /* Enable FSMC NOR/SRAM Bank1 */ |
|
227 | 227 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); |
|
228 | 228 | |
|
229 | 229 | |
|
230 | 230 | p.FSMC_AddressSetupTime = getCpuFreq()/50000000; |
|
231 | 231 | p.FSMC_AddressHoldTime = 0; |
|
232 | 232 | p.FSMC_DataSetupTime = getCpuFreq()/25000000; |
|
233 | 233 | p.FSMC_BusTurnAroundDuration = 1; |
|
234 | 234 | p.FSMC_CLKDivision = 0; |
|
235 | 235 | p.FSMC_DataLatency = 0; |
|
236 | 236 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
237 | 237 | |
|
238 | 238 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; |
|
239 | 239 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
240 | 240 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; |
|
241 | 241 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
242 | 242 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
243 | 243 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
244 | 244 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
245 | 245 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
246 | 246 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
247 | 247 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
248 | 248 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
249 | 249 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
250 | 250 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
251 | 251 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
252 | 252 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
253 | 253 | |
|
254 | 254 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
255 | 255 | |
|
256 | 256 | /*!< Enable FSMC Bank1_SRAM2 Bank */ |
|
257 | 257 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); |
|
258 | 258 | lcd0.init(&lcd0); |
|
259 | 259 | return 1; |
|
260 | 260 | } |
|
261 | 261 | |
|
262 | 262 | void bsp_spi_init() |
|
263 | 263 | { |
|
264 | 264 | |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | |
|
268 | 268 | void bsp_iic_init() |
|
269 | 269 | { |
|
270 | 270 | i2copenandconfig(i2c1,0,10000,PB9,PB6); |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void bsp_SD_init() |
|
274 | 274 | { |
|
275 | 275 | gpio_t SDIO_DBxList[]={PC8 ,PC9 ,PC10 ,PC11 ,PC12,PD2}; |
|
276 | 276 | for(int i=0;i<6;i++) |
|
277 | 277 | { |
|
278 | 278 | gpio_t SDIO_DBx = gpioopen(SDIO_DBxList[i]); |
|
279 | 279 | SDIO_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
280 | 280 | gpiosetconfig(&SDIO_DBx); |
|
281 | 281 | GPIO_PinAFConfig(GPIOGETPORT(SDIO_DBx), (uint8_t)(SDIO_DBx & 0xF), GPIO_AF_SDIO); |
|
282 | 282 | } |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | void vs10XXclearXCS(){} |
|
286 | 286 | void vs10XXsetXCS(){} |
|
287 | 287 | int vs10XXDREQ() |
|
288 | 288 | { |
|
289 | 289 | return 1; |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | |
|
293 | 293 | void bsppowersdcard(char onoff) //always ON |
|
294 | 294 | { |
|
295 | 295 | |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | char bspsdcardpresent() |
|
299 | 299 | { |
|
300 | 300 | return 0; |
|
301 | 301 | } |
|
302 | 302 | |
|
303 | 303 | char bspsdcardwriteprotected() |
|
304 | 304 | { |
|
305 | 305 | return 0; |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | void bspsdcardselect(char YESNO) |
|
309 | 309 | { |
|
310 | 310 | |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | |
|
314 | 314 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
315 | 315 | { |
|
316 | 316 | *lcd0_CMD=(uint16_t)reg; |
|
317 | 317 | *lcd0_DATA=(uint16_t)data; |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
321 | 321 | { |
|
322 | 322 | *lcd0_CMD=(uint16_t)reg; |
|
323 | 323 | return (uint16_t)*lcd0_DATA; |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
327 | 327 | { |
|
328 | 328 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
329 | 329 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
330 | 330 | for(int i=0;i<(int)count;i++) |
|
331 | 331 | { |
|
332 | 332 | *lcd0_DATA=castedBuff[i]; |
|
333 | 333 | } |
|
334 | 334 | } |
|
335 | 335 | |
|
336 | 336 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
337 | 337 | { |
|
338 | 338 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
339 | 339 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
340 | 340 | castedBuff[0]=*lcd0_DATA; |
|
341 | 341 | for(int i=0;i<(int)count;i++) |
|
342 | 342 | { |
|
343 | 343 | castedBuff[i]=*lcd0_DATA; |
|
344 | 344 | } |
|
345 | 345 | } |
|
346 | 346 | |
|
347 | 347 | void bsp_GTerm_init() |
|
348 | 348 | { |
|
349 | 349 | if(__opnfiles__[1]==NULL) |
|
350 | 350 | { |
|
351 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
|
352 | 351 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
353 | ||
|
354 | 352 | ili9328paintFilRect(&lcd0,0,0,240,320,0x7FFF,5,0); |
|
355 | 353 | terminal_init(&terminal0,&lcd0,&ComicSansMS_8,fd1); |
|
356 | 354 | __opnfiles__[1] = fd1; |
|
357 | 355 | } |
|
358 | 356 | else |
|
359 | 357 | { |
|
360 | 358 | |
|
361 | 359 | } |
|
362 | 360 | } |
|
363 | 361 | |
|
364 | 362 | |
|
365 | 363 |
@@ -1,15 +1,15 | |||
|
1 | 1 | TEMPLATE = app |
|
2 | 2 | CONFIG += cpu |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | UCMODEL=stm32f4 |
|
6 | 6 | BSP = OPLAYER |
|
7 | 7 | #BSP = STM32F4Discovery-ILI9328-8bits |
|
8 | 8 | |
|
9 |
DEFINES += CPUFREQ= |
|
|
9 | DEFINES += CPUFREQ=100000000 | |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | SOURCES += \ |
|
13 | 13 | main.c \ |
|
14 | 14 | test_lcd.c |
|
15 | 15 |
@@ -1,213 +1,229 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <stm32f4xx.h> |
|
6 | 6 | #include <bsp.h> |
|
7 | 7 | #include <core.h> |
|
8 | 8 | #include <VS10XX.h> |
|
9 | 9 | #include <bsp.h> |
|
10 | 10 | #include <spi.h> |
|
11 | 11 | #include <sdcard.h> |
|
12 | 12 | #include <sdcard-spi.h> |
|
13 | 13 | #include <fat32.h> |
|
14 | 14 | #include <ucdirent.h> |
|
15 | 15 | #include <string.h> |
|
16 | 16 | #include <terminal.h> |
|
17 | 17 | #include <ili9328.h> |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | extern streamdevice* __opnfiles__[]; |
|
21 | 21 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
22 | 22 | extern void test_all_colors(LCD_t* LCD); |
|
23 | 23 | extern void test_small_lines(LCD_t* LCD); |
|
24 | extern void test_lines(LCD_t* LCD); | |
|
25 | extern void test_address(LCD_t* LCD); | |
|
24 | 26 | void test_uniform_rw(LCD_t* LCD); |
|
25 | 27 | char buffer[512]; |
|
26 | 28 | |
|
27 | 29 | void randBoxesDemo() |
|
28 | 30 | { |
|
29 | 31 | int16_t x,y,w,h,t,r; |
|
30 | 32 | x=rand()%240; |
|
31 | 33 | y=rand()%320; |
|
32 | 34 | w=rand()%(240-x); |
|
33 | 35 | if(x>y) |
|
34 | 36 | r=(rand()%(y))%(320-y); |
|
35 | 37 | else |
|
36 | 38 | r=(rand()%(x))%(240-x); |
|
37 | 39 | h=rand()%(320-y); |
|
38 | 40 | t=rand()%(10); |
|
39 | 41 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
40 | 42 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
41 | 43 | //delay_100us(10); |
|
42 | 44 | //for(volatile int i=0;i<(1024*2);i++); |
|
43 | 45 | } |
|
44 | 46 | |
|
45 | 47 | void randTextDemo() |
|
46 | 48 | { |
|
47 | 49 | int16_t x,y,w,h,t,r; |
|
48 | 50 | char buf[2]; |
|
49 | 51 | buf[1]='\0'; |
|
50 | 52 | x=rand()%240; |
|
51 | 53 | y=rand()%320; |
|
52 | 54 | if(x>y) |
|
53 | 55 | r=(rand()%(y))%(320-y); |
|
54 | 56 | else |
|
55 | 57 | r=(rand()%(x))%(240-x); |
|
56 | 58 | h=rand()%(320-y); |
|
57 | 59 | buf[0]=rand()%(255); |
|
58 | 60 | //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
59 | 61 | ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); |
|
60 | 62 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
61 | 63 | delay_100us(5000); |
|
62 | 64 | //for(volatile int i=0;i<(1024*2);i++); |
|
63 | 65 | } |
|
64 | 66 | |
|
65 | 67 | void tryToplay2() |
|
66 | 68 | { |
|
67 | 69 | |
|
68 | 70 | extern blkdevice sdcard2blkdev; |
|
69 | 71 | int i=0,l=0; |
|
70 | 72 | |
|
71 | 73 | spisetspeed(audioCodec0.SPIdev,4000000); |
|
72 | 74 | printf("Streaming File\n"); |
|
73 | 75 | |
|
74 | 76 | //printf("New LBA=0x%X\n",nextLba); |
|
75 | 77 | |
|
76 | 78 | while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK) |
|
77 | 79 | { |
|
78 | 80 | |
|
79 | 81 | for(i=0;i<512;i+=32) |
|
80 | 82 | { |
|
81 | 83 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
82 | 84 | } |
|
83 | 85 | } |
|
84 | 86 | } |
|
85 | 87 | |
|
86 | 88 | void playFile(ucdirent* file,FAT32fs* part) |
|
87 | 89 | { |
|
88 | 90 | extern volatile vs10XXDev audioCodec0; |
|
89 | 91 | char direntName[]=" \n"; |
|
90 | 92 | uint32_t fileLba,nextLba; |
|
91 | 93 | int i=0; |
|
92 | 94 | fat32getdirentname(file,direntName); |
|
93 | 95 | //gpioset(LCD_BACKL); |
|
94 | 96 | printf("%s\n",direntName); |
|
95 | 97 | nextLba=fat32getdirentlba(file); |
|
96 | 98 | //printf("Streaming File\n"); |
|
97 | 99 | //gpioclr(LCD_BACKL); |
|
98 | 100 | do |
|
99 | 101 | { |
|
100 | 102 | fileLba = nextLba; |
|
101 | 103 | if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) |
|
102 | 104 | { |
|
103 | 105 | for(i=0;i<512;i+=32) |
|
104 | 106 | { |
|
105 | 107 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
106 | 108 | } |
|
107 | 109 | } |
|
108 | 110 | }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); |
|
109 | 111 | vs10XXsoftReset(&audioCodec0); |
|
110 | 112 | while (gpiogetval(BP3))delay_100us(1000); |
|
111 | 113 | } |
|
112 | 114 | |
|
113 | 115 | void playAllparts() |
|
114 | 116 | { |
|
115 | 117 | extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; |
|
116 | 118 | ucdirent root; |
|
117 | 119 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) |
|
118 | 120 | { |
|
119 | 121 | printf("Reading on SDCARD2 part1\n"); |
|
120 | 122 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
121 | 123 | { |
|
122 | 124 | do{ |
|
123 | 125 | playFile(&root,&sdcard2FAT32part1); |
|
124 | 126 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
125 | 127 | } |
|
126 | 128 | } |
|
127 | 129 | gpioset(LED2); |
|
128 | 130 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) |
|
129 | 131 | { |
|
130 | 132 | printf("Reading on SDCARD2 part2\n"); |
|
131 | 133 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
132 | 134 | { |
|
133 | 135 | do{ |
|
134 | 136 | playFile(&root,&sdcard2FAT32part2); |
|
135 | 137 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
136 | 138 | } |
|
137 | 139 | } |
|
138 | 140 | } |
|
139 | 141 | |
|
140 | 142 | int main() |
|
141 | 143 | { |
|
142 | 144 | delay_100us(30000); |
|
143 | 145 | int i=0; |
|
144 | 146 | int color=0; |
|
145 | 147 |
|
|
146 | test_small_lines(&lcd0); | |
|
147 | test_uniform_rw(&lcd0); | |
|
148 | // test_small_lines(&lcd0); | |
|
149 | // test_uniform_rw(&lcd0); | |
|
148 | 150 | |
|
149 | 151 | printf("LCD ID REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_DRIVERCODEREAD)); |
|
150 | while(1); | |
|
152 | printf("LCD ENTRY MODE REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_ENTRYMODE)); | |
|
153 | uint16_t test[16]; | |
|
154 | for(int i=0;i<16;i++) | |
|
155 | { | |
|
156 | test[i]=0xF00F; | |
|
157 | } | |
|
158 | lcd0.paint(&lcd0,test,10,100,4,4); | |
|
159 | lcd0.getPix(&lcd0,test,10,100,4,4); | |
|
160 | for(int i=0;i<16;i++) | |
|
161 | { | |
|
162 | printf("@%d=0x%X\n",i,test[i]); | |
|
163 | } | |
|
164 | // test_lines(&lcd0); | |
|
165 | ||
|
166 | while(1)test_address(&lcd0); | |
|
151 | 167 | for(i=0;i<240;i++) |
|
152 | 168 | { |
|
153 | 169 | if(i>(240/3)) |
|
154 | 170 | { |
|
155 | 171 | color= (i<<5) + 0x1F; |
|
156 | 172 | } |
|
157 | 173 | else |
|
158 | 174 | { |
|
159 | 175 | color = i; |
|
160 | 176 | } |
|
161 | 177 | if(i>(2*240/3)) |
|
162 | 178 | { |
|
163 | 179 | color= (i<<10) + 0x3FF; |
|
164 | 180 | } |
|
165 | 181 | lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); |
|
166 | 182 | } |
|
167 | 183 | while(1)printf("test "); |
|
168 | 184 | // for(i=0;i<240;i++) |
|
169 | 185 | // { |
|
170 | 186 | // if(i>(240/3)) |
|
171 | 187 | // { |
|
172 | 188 | // color= (i<<5) + 0x1F; |
|
173 | 189 | // } |
|
174 | 190 | // else |
|
175 | 191 | // { |
|
176 | 192 | // color = i; |
|
177 | 193 | // } |
|
178 | 194 | // if(i>(2*240/3)) |
|
179 | 195 | // { |
|
180 | 196 | // color= (i<<10) + 0x3FF; |
|
181 | 197 | // } |
|
182 | 198 | // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); |
|
183 | 199 | // } |
|
184 | 200 | for(i=0;i<240;i++) |
|
185 | 201 | { |
|
186 | 202 | ili9328setFrame(&lcd0,i,0,1,100); |
|
187 | 203 | lcd0.interface->readGRAM(buffer,100); |
|
188 | 204 | lcd0.paint(&lcd0,buffer,i,200,1,100); |
|
189 | 205 | } |
|
190 | 206 | while(1); |
|
191 | 207 | } |
|
192 | 208 | |
|
193 | 209 | int main2() |
|
194 | 210 | { |
|
195 | 211 | extern terminal_t terminal0; |
|
196 | 212 | extern volatile vs10XXDev audioCodec0; |
|
197 | 213 | printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); |
|
198 | 214 | vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); |
|
199 | 215 | delay_100us(1000); |
|
200 | 216 | vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); |
|
201 | 217 | printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); |
|
202 | 218 | printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); |
|
203 | 219 | //terminal_clear(&terminal0); |
|
204 | 220 | // gpioclr(LCD_BACKL); |
|
205 | 221 | playAllparts(); |
|
206 | 222 | return 0; |
|
207 | 223 | } |
|
208 | 224 | |
|
209 | 225 | |
|
210 | 226 | |
|
211 | 227 | |
|
212 | 228 | |
|
213 | 229 |
@@ -1,70 +1,115 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <stm32f4xx.h> |
|
6 | 6 | #include <bsp.h> |
|
7 | 7 | #include <core.h> |
|
8 | 8 | #include <VS10XX.h> |
|
9 | 9 | #include <bsp.h> |
|
10 | 10 | #include <spi.h> |
|
11 | 11 | #include <sdcard.h> |
|
12 | 12 | #include <sdcard-spi.h> |
|
13 | 13 | #include <fat32.h> |
|
14 | 14 | #include <ucdirent.h> |
|
15 | 15 | #include <string.h> |
|
16 | 16 | #include <terminal.h> |
|
17 | 17 | #include <ili9328.h> |
|
18 | 18 | |
|
19 | ||
|
19 | uint16_t buff[50*50]; | |
|
20 | 20 | void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) |
|
21 | 21 | { |
|
22 | 22 | LCD->paintFilRect(LCD,x,y,w,h,0,0,color); |
|
23 | 23 | } |
|
24 | 24 | |
|
25 | 25 | void test_small_lines(LCD_t* LCD) |
|
26 | 26 | { |
|
27 | 27 | int i=0; |
|
28 | 28 | for(i=0;i<LCD->height;i+=2) |
|
29 | 29 | { |
|
30 | 30 | LCD->paintFilRect(LCD,0,i,LCD->width,1,0,0,0xaa00); |
|
31 | 31 | } |
|
32 | 32 | for(i=1;i<LCD->height;i+=2) |
|
33 | 33 | { |
|
34 | 34 | LCD->paintFilRect(LCD,0,i,LCD->width,1,0,0,0x5500); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void test_uniform_rw(LCD_t* LCD) |
|
40 | 40 | { |
|
41 | 41 | uint16_t buffer[50*50]; |
|
42 | 42 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height/2,0,0,0xfaa0); |
|
43 | 43 | delay_100us(10000); |
|
44 | 44 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xfaa0); |
|
45 | 45 | ili9328setFrame(LCD,10,100,50,50); |
|
46 | 46 | while(1) |
|
47 | 47 | { |
|
48 | 48 | // LCD->interface->readGRAM((void*)buffer,50*50); |
|
49 | 49 | LCD->getPix(LCD,buffer,10,100,50,50); |
|
50 | 50 | LCD->paint(LCD,buffer,10,100,50,50); |
|
51 | 51 | delay_100us(10000); |
|
52 | 52 | //ili9328setFrame(LCD,10,100,50,50); |
|
53 | 53 | //LCD->interface->writeGRAM((void*)buffer,50*50); |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | void test_all_colors(LCD_t* LCD) |
|
59 | 59 | { |
|
60 | 60 | uint16_t color=0; |
|
61 | 61 | char colorch[]=" "; |
|
62 | 62 | while(1) |
|
63 | 63 | { |
|
64 | 64 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,color); |
|
65 | 65 | sprintf(colorch,"0x%x",0xFFFF & ((int)color)); |
|
66 | 66 | LCD->paintText(LCD,colorch,10,100,&ComicSansMS_18,color^-1); |
|
67 | 67 | //delay_100us(10); |
|
68 | 68 | color+=1; |
|
69 | 69 | } |
|
70 | 70 | } |
|
71 | ||
|
72 | void test_address(LCD_t* LCD) | |
|
73 | { | |
|
74 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); | |
|
75 | uint16_t color[1]; | |
|
76 | for(int y=0;y<320;y++) | |
|
77 | { | |
|
78 | for(int x=0;x<240;x++) | |
|
79 | { | |
|
80 | color[0]=x*y; | |
|
81 | LCD->paint(LCD,color,x,y,1,1); | |
|
82 | //delay_100us(100); | |
|
83 | } | |
|
84 | } | |
|
85 | LCD->getPix(LCD,buff,50,50,50,50); | |
|
86 | delay_100us(5000); | |
|
87 | for(int i=0;i<50*50;i++) | |
|
88 | { | |
|
89 | buff[i]=i; | |
|
90 | } | |
|
91 | LCD->paint(LCD,buff,50,50,50,50); | |
|
92 | delay_100us(5000); | |
|
93 | } | |
|
94 | ||
|
95 | void test_lines(LCD_t* LCD) | |
|
96 | { | |
|
97 | uint16_t color[2];//=0x0FF0; | |
|
98 | int x=0; | |
|
99 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); | |
|
100 | for(int l=0;l<0xFFFF;l++) | |
|
101 | { | |
|
102 | color[0]=l; | |
|
103 | color[1]=l; | |
|
104 | for(int i=0;i<320;i++) | |
|
105 | { | |
|
106 | x=i*240/320; | |
|
107 | LCD->paint(LCD,color,x,i,2,1); | |
|
108 | } | |
|
109 | for(int i=0;i<320;i++) | |
|
110 | { | |
|
111 | x=239-(i*240/320); | |
|
112 | LCD->paint(LCD,color,x,i,2,1); | |
|
113 | } | |
|
114 | } | |
|
115 | } |
@@ -1,482 +1,535 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2012, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #define _PRVATE_ILI9328_ |
|
23 | 23 | #include <ili9328.h> |
|
24 | 24 | #include <stdio.h> |
|
25 | 25 | #include <stddef.h> |
|
26 | 26 | #include <core.h> |
|
27 | 27 | #include <math.h> |
|
28 | 28 | #include <stdint.h> |
|
29 | #include <malloc.h> | |
|
29 | 30 | |
|
30 | 31 | #ifdef __OPTIMIZED_MATH |
|
31 | 32 | #include <optimised_math.h> |
|
32 | 33 | #endif |
|
33 | 34 | |
|
34 | 35 | |
|
35 | 36 | #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ |
|
36 | 37 | for(int l=0;l<1;l++)\ |
|
37 | 38 | {\ |
|
38 | 39 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
39 | 40 | int rem=(W)%buffsize;\ |
|
40 | 41 | if(rem)LCD->interface->writeGRAM(buffer,rem);\ |
|
41 | 42 | for(int i=rem;i<(W);i+=buffsize)\ |
|
42 | 43 | {\ |
|
43 | 44 | LCD->interface->writeGRAM(buffer,buffsize);\ |
|
44 | 45 | }\ |
|
45 | 46 | } |
|
46 | 47 | |
|
47 | 48 | #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
48 | 49 | for(int l=0;l<1;l++)\ |
|
49 | 50 | {\ |
|
50 | 51 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
51 | 52 | int rem=(ContSz)%buffContsize;\ |
|
52 | 53 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
53 | 54 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
54 | 55 | {\ |
|
55 | 56 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
56 | 57 | }\ |
|
57 | 58 | if((2*ContSz)<W) \ |
|
58 | 59 | {\ |
|
59 | 60 | rem=(W-(2*ContSz))%buffIntsize;\ |
|
60 | 61 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
61 | 62 | for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\ |
|
62 | 63 | {\ |
|
63 | 64 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
64 | 65 | }\ |
|
65 | 66 | }\ |
|
66 | 67 | rem=(ContSz)%buffContsize;\ |
|
67 | 68 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
68 | 69 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
69 | 70 | {\ |
|
70 | 71 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
71 | 72 | }\ |
|
72 | 73 | }\ |
|
73 | 74 | |
|
74 | 75 | |
|
75 | 76 | #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
76 | 77 | for(int l=0;l<1;l++)\ |
|
77 | 78 | {\ |
|
78 | 79 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
79 | 80 | int rem=(ContSz)%buffContsize;\ |
|
80 | 81 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
81 | 82 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
82 | 83 | {\ |
|
83 | 84 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
84 | 85 | }\ |
|
85 | 86 | if((2*ContSz)<H) \ |
|
86 | 87 | {\ |
|
87 | 88 | rem=(H-(2*ContSz))%buffIntsize;\ |
|
88 | 89 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
89 | 90 | for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\ |
|
90 | 91 | {\ |
|
91 | 92 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
92 | 93 | }\ |
|
93 | 94 | }\ |
|
94 | 95 | rem=(ContSz)%buffContsize;\ |
|
95 | 96 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
96 | 97 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
97 | 98 | {\ |
|
98 | 99 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
99 | 100 | }\ |
|
100 | 101 | }\ |
|
101 | 102 | |
|
102 | 103 | |
|
103 | 104 | #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
104 | 105 | for(int l=0;l<1;l++)\ |
|
105 | 106 | {\ |
|
106 | 107 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
107 | 108 | int rem=(ContSz)%buffContsize;\ |
|
108 | 109 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
109 | 110 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
110 | 111 | {\ |
|
111 | 112 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
112 | 113 | }\ |
|
113 | 114 | if(ContSz<H) \ |
|
114 | 115 | {\ |
|
115 | 116 | rem=(H-ContSz)%buffIntsize;\ |
|
116 | 117 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
117 | 118 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
118 | 119 | {\ |
|
119 | 120 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
120 | 121 | }\ |
|
121 | 122 | }\ |
|
122 | 123 | }\ |
|
123 | 124 | |
|
124 | 125 | |
|
125 | 126 | #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
126 | 127 | for(int l=0;l<1;l++)\ |
|
127 | 128 | {\ |
|
128 | 129 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
129 | 130 | int rem;\ |
|
130 | 131 | if(ContSz<H) \ |
|
131 | 132 | {\ |
|
132 | 133 | rem=(H-ContSz)%buffIntsize;\ |
|
133 | 134 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
134 | 135 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
135 | 136 | {\ |
|
136 | 137 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
137 | 138 | }\ |
|
138 | 139 | }\ |
|
139 | 140 | rem=(ContSz)%buffContsize;\ |
|
140 | 141 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
141 | 142 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
142 | 143 | {\ |
|
143 | 144 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
144 | 145 | }\ |
|
145 | 146 | }\ |
|
146 | 147 | |
|
147 | 148 | |
|
148 | 149 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) |
|
149 | 150 | { |
|
150 | 151 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); |
|
151 | 152 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); |
|
152 | 153 | } |
|
153 | 154 | |
|
154 | 155 | void ili9328refreshenable(struct LCD_t* LCD,int enable) |
|
155 | 156 | { |
|
156 | 157 | if(enable) |
|
157 | 158 | { |
|
158 | 159 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018); |
|
159 | 160 | } |
|
160 | 161 | else |
|
161 | 162 | { |
|
162 | 163 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008); |
|
163 | 164 | |
|
164 | 165 | } |
|
165 | 166 | } |
|
166 | 167 | |
|
167 | 168 | void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H) |
|
168 | 169 | { |
|
169 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X); | |
|
170 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y); | |
|
170 | if((X>239) || (Y>319) || ((X+W)>240) || ((Y+H)>320)) | |
|
171 | { | |
|
172 | while (1); | |
|
173 | } | |
|
171 | 174 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X); |
|
172 | 175 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1)); |
|
173 | 176 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y); |
|
174 | 177 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1)); |
|
178 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X); | |
|
179 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y); | |
|
175 | 180 | } |
|
176 | 181 | |
|
177 | 182 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) |
|
178 | 183 | { |
|
179 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height))) | |
|
184 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>=(Xpos+Width)) && (LCD->height>=(Ypos+Height))) | |
|
180 | 185 | { |
|
181 | 186 | ili9328setFrame(LCD,Xpos,Ypos,Width,Height); |
|
182 | 187 | LCD->interface->writeGRAM(buffer,Width*Height); |
|
183 | 188 | } |
|
184 | 189 | } |
|
185 | 190 | |
|
186 | 191 | void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
187 | 192 | { |
|
188 | 193 | //Based on the mid point circle algorithm from Wikipedia |
|
189 | 194 | //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm |
|
190 | 195 | uint16_t innerbuffer[16]; |
|
191 | 196 | uint16_t outterbuffer[16]; |
|
192 | 197 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
193 | 198 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
194 | 199 | if(contSz<r) |
|
195 | 200 | { |
|
196 | 201 | int error = -r,error_int = -r+contSz; |
|
197 | 202 | int x = r,x_int=r-contSz; |
|
198 | 203 | int y = 0,y_int=0; |
|
199 | 204 | while (x >= y) |
|
200 | 205 | { |
|
201 | 206 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
202 | 207 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
203 | 208 | ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
204 | 209 | ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
205 | 210 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
206 | 211 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
207 | 212 | error += y; |
|
208 | 213 | ++y; |
|
209 | 214 | error += y; |
|
210 | 215 | error_int += y_int; |
|
211 | 216 | ++y_int; |
|
212 | 217 | error_int += y_int; |
|
213 | 218 | if(error >= 0) |
|
214 | 219 | { |
|
215 | 220 | error -= x; |
|
216 | 221 | --x; |
|
217 | 222 | error -= x; |
|
218 | 223 | } |
|
219 | 224 | if(error_int >= 0) |
|
220 | 225 | { |
|
221 | 226 | error_int -= x_int; |
|
222 | 227 | --x_int; |
|
223 | 228 | error_int -= x_int; |
|
224 | 229 | } |
|
225 | 230 | } |
|
226 | 231 | |
|
227 | 232 | |
|
228 | 233 | |
|
229 | 234 | } |
|
230 | 235 | |
|
231 | 236 | } |
|
232 | 237 | |
|
233 | 238 | void ili9328paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
234 | 239 | { |
|
235 | 240 | if(contSz<r) |
|
236 | 241 | { |
|
237 | 242 | uint16_t innerbuffer[16]; |
|
238 | 243 | uint16_t outterbuffer[16]; |
|
239 | 244 | int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem; |
|
240 | 245 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
241 | 246 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
242 | 247 | /* Y = b +/- sqrt[r^2 - (x - a)^2] */ |
|
243 | 248 | for(int32_t line=-r;line<r;line++) |
|
244 | 249 | { |
|
245 | 250 | #ifdef __OPTIMIZED_MATH |
|
246 | 251 | Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) ); |
|
247 | 252 | Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) ); |
|
248 | 253 | #else |
|
249 | 254 | Val1 = sqrt( (double)(rr - ((line)*(line))) ); |
|
250 | 255 | Val2 = sqrt( (double)(rr2 - ((line)*(line))) ); |
|
251 | 256 | #endif |
|
252 | 257 | X1=Xpos - Val1; |
|
253 | 258 | contSz2= Val1-Val2; |
|
254 | 259 | ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1); |
|
255 | 260 | rem=(contSz2)%16; |
|
256 | 261 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
257 | 262 | for(int i=rem;i<(contSz2);i+=16) |
|
258 | 263 | { |
|
259 | 264 | LCD->interface->writeGRAM(outterbuffer,16); |
|
260 | 265 | } |
|
261 | 266 | |
|
262 | 267 | W=2*Val1; |
|
263 | 268 | if(W>(2*contSz2)) |
|
264 | 269 | { |
|
265 | 270 | W-=2*contSz2; |
|
266 | 271 | rem=(W)%16; |
|
267 | 272 | if(rem)LCD->interface->writeGRAM(innerbuffer,rem); |
|
268 | 273 | for(int i=rem;i<(W);i+=16) |
|
269 | 274 | { |
|
270 | 275 | LCD->interface->writeGRAM(innerbuffer,16); |
|
271 | 276 | } |
|
272 | 277 | } |
|
273 | 278 | |
|
274 | 279 | rem=(contSz2)%16; |
|
275 | 280 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
276 | 281 | for(int i=rem;i<(contSz2);i+=16) |
|
277 | 282 | { |
|
278 | 283 | LCD->interface->writeGRAM(outterbuffer,16); |
|
279 | 284 | } |
|
280 | 285 | } |
|
281 | 286 | } |
|
282 | 287 | } |
|
283 | 288 | |
|
284 | 289 | |
|
285 | 290 | |
|
286 | 291 | |
|
287 | 292 | void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
288 | 293 | { |
|
289 | 294 | ili9328setFrame(LCD,Xpos,Ypos,w,h); |
|
290 | 295 | uint16_t tmp[32]; |
|
291 | 296 | for(int i=0;i<32;i++)tmp[i]=fillColor; |
|
292 | 297 | for(int i=0;i<(h*w);i+=32) |
|
293 | 298 | { |
|
294 | 299 | LCD->interface->writeGRAM(tmp,32); |
|
295 | 300 | } |
|
296 | 301 | int rem=(w*h)%32; |
|
297 | 302 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
298 | 303 | if(contSz) |
|
299 | 304 | { |
|
300 | 305 | ili9328setFrame(LCD,Xpos,Ypos,w,contSz); |
|
301 | 306 | for(int i=0;i<32;i++)tmp[i]=contColor; |
|
302 | 307 | rem=(w*contSz)%32; |
|
303 | 308 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
304 | 309 | for(int i=rem;i<(w*contSz);i+=32) |
|
305 | 310 | { |
|
306 | 311 | LCD->interface->writeGRAM(tmp,32); |
|
307 | 312 | } |
|
308 | 313 | |
|
309 | 314 | ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz); |
|
310 | 315 | rem=(w*contSz)%32; |
|
311 | 316 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
312 | 317 | for(int i=rem;i<(w*contSz);i+=32) |
|
313 | 318 | { |
|
314 | 319 | LCD->interface->writeGRAM(tmp,32); |
|
315 | 320 | } |
|
316 | 321 | |
|
317 | 322 | ili9328setFrame(LCD,Xpos,Ypos,contSz,h); |
|
318 | 323 | rem=(h*contSz)%32; |
|
319 | 324 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
320 | 325 | for(int i=rem;i<(h*contSz);i+=32) |
|
321 | 326 | { |
|
322 | 327 | LCD->interface->writeGRAM(tmp,32); |
|
323 | 328 | } |
|
324 | 329 | |
|
325 | 330 | ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h); |
|
326 | 331 | rem=(h*contSz)%32; |
|
327 | 332 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
328 | 333 | for(int i=rem;i<(h*contSz);i+=32) |
|
329 | 334 | { |
|
330 | 335 | LCD->interface->writeGRAM(tmp,32); |
|
331 | 336 | } |
|
332 | 337 | } |
|
333 | 338 | } |
|
334 | 339 | |
|
335 | 340 | void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color) |
|
336 | 341 | { |
|
337 | 342 | int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0; |
|
338 | 343 | uint16_t tmp[w]; |
|
339 | 344 | uint16_t linenum=0,charnum=0; |
|
340 | 345 | uint8_t line=0; |
|
341 | 346 | while(*buffer!='\0') |
|
342 | 347 | { |
|
343 | 348 | if(*buffer<32)*buffer=32; |
|
344 | 349 | if(*buffer>127)*buffer=32; |
|
345 | 350 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1); |
|
346 | 351 | // LCD->interface->readGRAM(tmp,w); |
|
347 | 352 | ili9328getPix(LCD,tmp,Xpos+(charnum*w),Ypos-h,w,1); |
|
348 | 353 | for(int i=0;i<(h*w);i++) |
|
349 | 354 | { |
|
350 | 355 | if( ((i%w)==0) ) //read current line to apply text pixmap |
|
351 | 356 | { |
|
352 | 357 | if(linenum++>0) |
|
353 | 358 | { |
|
354 | 359 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1); |
|
355 | 360 | LCD->interface->writeGRAM(tmp,w); |
|
356 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); | |
|
361 | //ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); | |
|
357 | 362 | // LCD->interface->readGRAM(tmp,w); |
|
358 | 363 | ili9328getPix(LCD,tmp,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); |
|
359 | 364 | pix=0; |
|
360 | 365 | } |
|
361 | 366 | } |
|
362 | 367 | if((pix%8) == 0) |
|
363 | 368 | { |
|
364 | 369 | line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++]; |
|
365 | 370 | } |
|
366 | 371 | //tmp[pix]=0; |
|
367 | 372 | if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; |
|
368 | 373 | pix++; |
|
369 | 374 | line>>=1; |
|
370 | 375 | } |
|
371 | 376 | linenum=0; |
|
372 | 377 | tableoffset=0; |
|
373 | 378 | charnum++; |
|
374 | 379 | buffer++; |
|
375 | 380 | } |
|
376 | 381 | } |
|
377 | 382 | |
|
383 | ||
|
384 | void ili9328paintChar(LCD_t* LCD,char buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color) | |
|
385 | { | |
|
386 | int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0; | |
|
387 | uint16_t tmp[w]; | |
|
388 | uint16_t tmp2[w]; | |
|
389 | uint16_t linenum=0,charnum=0; | |
|
390 | uint8_t line=0; | |
|
391 | if(buffer<32)buffer=32; | |
|
392 | if(buffer>127)buffer=32; | |
|
393 | ili9328setFrame(LCD,Xpos,Ypos-h,w,1); | |
|
394 | // LCD->interface->readGRAM(tmp,w); | |
|
395 | ili9328getPix(LCD,tmp2,Xpos,Ypos-h,w,1); | |
|
396 | for(int i=0;i<w;i++) | |
|
397 | { | |
|
398 | tmp[i]=0; | |
|
399 | } | |
|
400 | for(int i=0;i<(h*w);i++) | |
|
401 | { | |
|
402 | if( ((i%w)==0) ) //read current line to apply text pixmap | |
|
403 | { | |
|
404 | if(linenum++>0) | |
|
405 | { | |
|
406 | ili9328setFrame(LCD,Xpos,Ypos + linenum -h,w,1); | |
|
407 | LCD->interface->writeGRAM(tmp,w); | |
|
408 | //ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); | |
|
409 | // LCD->interface->readGRAM(tmp,w); | |
|
410 | ili9328getPix(LCD,tmp2,Xpos,Ypos + linenum + 1-h,w,1); | |
|
411 | for(int i=0;i<w;i++) | |
|
412 | { | |
|
413 | tmp[i]=0; | |
|
414 | } | |
|
415 | pix=0; | |
|
416 | } | |
|
417 | } | |
|
418 | if((pix%8) == 0) | |
|
419 | { | |
|
420 | line=font->table[(((buffer)-32)*h*bpl)+tableoffset++]; | |
|
421 | } | |
|
422 | //tmp[pix]=0; | |
|
423 | if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; | |
|
424 | pix++; | |
|
425 | line>>=1; | |
|
426 | } | |
|
427 | ||
|
428 | } | |
|
429 | ||
|
378 | 430 | int ili9328init(struct LCD_t* LCD) |
|
379 | 431 | { |
|
380 | 432 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) |
|
381 | 433 | { |
|
382 | 434 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) |
|
383 | 435 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) |
|
384 |
LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x |
|
|
436 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x0230); // Entry Mode (R03h) | |
|
437 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0xC000); | |
|
385 | 438 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302); |
|
386 | 439 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); |
|
387 | 440 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On |
|
388 | 441 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) |
|
389 | 442 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
390 | 443 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) |
|
391 | 444 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) |
|
392 | 445 | delay_100us(1000); |
|
393 | 446 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) |
|
394 | 447 | delay_100us(500); |
|
395 | 448 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
396 | 449 | delay_100us(500); |
|
397 | 450 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) |
|
398 | 451 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) |
|
399 | 452 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) |
|
400 | 453 | delay_100us(500); |
|
401 | 454 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 |
|
402 | 455 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 |
|
403 | 456 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 |
|
404 | 457 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 |
|
405 | 458 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 |
|
406 | 459 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 |
|
407 | 460 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 |
|
408 | 461 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 |
|
409 | 462 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 |
|
410 | 463 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 |
|
411 | 464 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) |
|
412 | 465 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h) |
|
413 | 466 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) |
|
414 | 467 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h) |
|
415 | 468 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) |
|
416 | 469 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE |
|
417 | 470 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) |
|
418 | 471 | // Display On |
|
419 | 472 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) |
|
420 | 473 | delay_100us(500); |
|
421 | 474 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); |
|
422 | 475 | } |
|
423 | 476 | return 0; |
|
424 | 477 | } |
|
425 | 478 | |
|
426 | 479 | void ili9328cpFrame(LCD_t* LCD,void* buffer,int x,int y,int w, int h) |
|
427 | 480 | { |
|
428 | 481 | #define __set__Address__(_x_,_y_) LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,_x_); \ |
|
429 | 482 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,_y_) |
|
430 | 483 | |
|
431 | 484 | uint16_t* castedBuff = (uint16_t*)buffer; |
|
432 | 485 | int cx=x,cy=y; |
|
433 | 486 | for(int i=0;i<(w*h);i++) |
|
434 | 487 | { |
|
435 | 488 | __set__Address__(cx,cy); |
|
436 | 489 | LCD->interface->readGRAM((void*)(&castedBuff[i]),1); |
|
437 | 490 | cx+=1; |
|
438 | 491 | if(cx>=(w+x)) |
|
439 | 492 | { |
|
440 | 493 | cx=x; |
|
441 | 494 | cy+=1; |
|
442 | 495 | } |
|
443 | 496 | } |
|
444 | 497 | } |
|
445 | 498 | |
|
446 | 499 | |
|
447 | 500 | |
|
448 | 501 | void ili9328getPix(struct LCD_t* LCD,uint16_t* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h) |
|
449 | 502 | { |
|
450 | 503 | #define __set__Address__(_x_,_y_) LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,_x_); \ |
|
451 | 504 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,_y_) |
|
452 | 505 | |
|
453 | uint16_t* castedBuff = (uint16_t*)buffer; | |
|
454 | 506 | int cx=Xpos,cy=Ypos; |
|
507 | ili9328setFrame(LCD,Xpos,Ypos,w,h); | |
|
455 | 508 | for(int i=0;i<(w*h);i++) |
|
456 | 509 | { |
|
457 | 510 | __set__Address__(cx,cy); |
|
458 |
LCD->interface->readGRAM((void*)(& |
|
|
511 | LCD->interface->readGRAM((void*)(&buffer[i]),1); | |
|
459 | 512 | cx+=1; |
|
460 | 513 | if(cx>=(w+Xpos)) |
|
461 | 514 | { |
|
462 | 515 | cx=Xpos; |
|
463 | 516 | cy+=1; |
|
464 | 517 | } |
|
465 | 518 | } |
|
466 | 519 | |
|
467 | 520 | } |
|
468 | 521 | |
|
469 | 522 | |
|
470 | 523 | |
|
471 | 524 | |
|
472 | 525 | |
|
473 | 526 | |
|
474 | 527 | |
|
475 | 528 | |
|
476 | 529 | |
|
477 | 530 | |
|
478 | 531 | |
|
479 | 532 | |
|
480 | 533 | |
|
481 | 534 | |
|
482 | 535 |
@@ -1,21 +1,20 | |||
|
1 | 1 | TEMPLATE = lib |
|
2 | OBJECTS_DIR = obj | |
|
3 | 2 | TARGET = fonts |
|
4 | 3 | |
|
5 | 4 | SOURCES += \ |
|
6 | 5 | fonts8pts.c |
|
7 | 6 | |
|
8 | 7 | |
|
9 | 8 | INCLUDEPATH += ../../../../includes \ |
|
10 | 9 | ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
11 | 10 | ../../../CPU/CMSIS/Include \ |
|
12 | 11 | ../../../../includes/GRAPHIC/CONTROLERS \ |
|
13 | 12 | ../../../../includes/GRAPHIC/GUI/FONTS \ |
|
14 | 13 | ../../../../includes/GRAPHIC/GUI/Widgets |
|
15 | 14 | |
|
16 | 15 | |
|
17 | 16 | UCMODEL=stm32f4 |
|
18 | 17 | |
|
19 | 18 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
20 | 19 | INSTALLS += target |
|
21 | 20 |
@@ -1,237 +1,239 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2013, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include <widget.h> |
|
23 | 23 | #include <terminal.h> |
|
24 | 24 | #include <stdint.h> |
|
25 | 25 | #include <stdio.h> |
|
26 | 26 | #include <gpio.h> |
|
27 | 27 | #include <core.h> |
|
28 | 28 | #include <malloc.h> |
|
29 | 29 | |
|
30 | 30 | #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos) |
|
31 | 31 | #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight) |
|
32 | 32 | |
|
33 | 33 | streamdevice_ops TERMINAL_OPS= |
|
34 | 34 | { |
|
35 | 35 | .write = &terminal_write, |
|
36 | 36 | .read = &terminal_read, |
|
37 | 37 | .setpos= &terminal_setpos, |
|
38 | 38 | .close = NULL |
|
39 | 39 | }; |
|
40 | 40 | |
|
41 | 41 | int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev) |
|
42 | 42 | { |
|
43 | 43 | if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL)) |
|
44 | 44 | { |
|
45 | 45 | terminal->LCD=LCD; |
|
46 | 46 | terminal->font=font; |
|
47 | 47 | terminal->line = 0; |
|
48 | 48 | terminal->column = 0; |
|
49 | 49 | terminal->horizontalSpace = 0; |
|
50 | 50 | terminal->verticalSpace = 0; |
|
51 | 51 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
52 | 52 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
53 | 53 | terminal->textColor=0xFFFF; |
|
54 | 54 | terminal->backgroundColor=0xF00F; |
|
55 | 55 | terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10)); |
|
56 | 56 | strdev->_stream = (UHANDLE)terminal; |
|
57 | 57 | strdev->ops = &TERMINAL_OPS; |
|
58 | 58 | strdev->streamPt = 0; |
|
59 | 59 | terminal_clear(terminal); |
|
60 | 60 | terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
61 | 61 | terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1)); |
|
62 | 62 | terminal->firstLine = 0; |
|
63 | 63 | terminal->lastLine = 0; |
|
64 | 64 | terminal->empty = 1; |
|
65 | 65 | for(int i=1;i<=terminal->lineCount;i++) |
|
66 | 66 | { |
|
67 | 67 | terminal->buffer[i * terminal->columnCount]='\n'; |
|
68 | 68 | } |
|
69 | 69 | return 1; |
|
70 | 70 | } |
|
71 | 71 | return 0; |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height) |
|
75 | 75 | { |
|
76 | 76 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
77 | 77 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
78 | 78 | if(terminal->LCD->height<(Ypos+height)) |
|
79 | 79 | return; |
|
80 | 80 | if(terminal->LCD->width<(Xpos+width)) |
|
81 | 81 | return; |
|
82 | 82 | terminal->Xpos = Xpos; |
|
83 | 83 | terminal->Ypos = Ypos; |
|
84 | 84 | terminal->height = height; |
|
85 | 85 | terminal->width = width; |
|
86 | 86 | terminal->lineCount = terminal->height/charh; |
|
87 | 87 | terminal->columnCount = (terminal->width/charw)-1; |
|
88 | 88 | terminal_clear(terminal); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | void terminal_clear(terminal_t* terminal) |
|
93 | 93 | { |
|
94 | 94 | terminal->firstLine = 0; |
|
95 | 95 | terminal->lastLine = 0; |
|
96 | 96 | terminal->empty = 1; |
|
97 | 97 | terminal->line =0; |
|
98 | 98 | terminal->column=0; |
|
99 | 99 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor) |
|
103 | 103 | { |
|
104 | 104 | terminal->backgroundColor = backgrooundColor; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void terminal_settextColor(terminal_t* terminal, uint32_t textColor) |
|
108 | 108 | { |
|
109 | 109 | terminal->textColor = textColor; |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | void terminal_movecursor(terminal_t* terminal,int n) |
|
114 | 114 | { |
|
115 | 115 | terminal->column += n; |
|
116 | 116 | if(terminal->column>(terminal->columnCount)) |
|
117 | 117 | { |
|
118 | 118 | terminal->line += (terminal->column)/terminal->columnCount; |
|
119 | 119 | terminal->line = terminal->line % terminal->lineCount; |
|
120 | 120 | terminal->column = (terminal->column % terminal->columnCount)-1; |
|
121 | 121 | } |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | void terminal_clearCurentLine(terminal_t* terminal) |
|
125 | 125 | { |
|
126 | 126 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
127 | 127 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
128 | 128 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | int terminal_writenc(terminal_t* terminal,char* data, int n) |
|
132 | 132 | { |
|
133 | 133 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
134 | 134 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
135 | 135 | int l=0; |
|
136 | 136 | char buffer[2]=" "; |
|
137 | 137 | while(l<n) |
|
138 | 138 | { |
|
139 | 139 | |
|
140 | 140 | buffer[0]=data[l]; |
|
141 | 141 | if(buffer[0]=='\n') |
|
142 | 142 | { |
|
143 | 143 | terminal->line= (terminal->line+1) % terminal->lineCount; |
|
144 | 144 | terminal->column = 0; |
|
145 | 145 | if(terminal->line==0) |
|
146 | 146 | terminal_clear(terminal); |
|
147 | 147 | else |
|
148 | 148 | terminal_clearCurentLine(terminal); |
|
149 | 149 | }else { |
|
150 | 150 | if(buffer[0]=='\t') |
|
151 | 151 | { |
|
152 | 152 | for(int i=0;i<1;i++)terminal_movecursor(terminal,1); |
|
153 | 153 | }else |
|
154 | 154 | if(terminal->column==0)terminal_clearCurentLine(terminal); |
|
155 | 155 | if(buffer[0]!='\r'){ |
|
156 | 156 | // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
157 | terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
|
157 | // terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
|
158 | #include <ili9328.h> | |
|
159 | ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
|
158 | 160 | terminal_movecursor(terminal,1); |
|
159 | 161 | } |
|
160 | 162 | } |
|
161 | 163 | l++; |
|
162 | 164 | } |
|
163 | 165 | return n; |
|
164 | 166 | } |
|
165 | 167 | |
|
166 | 168 | void terminal_print_line(terminal_t* terminal,int line) |
|
167 | 169 | { |
|
168 | 170 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
169 | 171 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
170 | 172 | terminal_clearCurentLine(terminal); |
|
171 | 173 | terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); |
|
172 | 174 | } |
|
173 | 175 | |
|
174 | 176 | int terminal_writenc2(terminal_t* terminal,char* data, int n) |
|
175 | 177 | { |
|
176 | 178 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
177 | 179 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
178 | 180 | /* First copy to buffer*/ |
|
179 | 181 | int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column; |
|
180 | 182 | for(int i=0;i<n;i++) |
|
181 | 183 | { |
|
182 | 184 | terminal->empty=0; |
|
183 | 185 | terminal->buffer[offset] = data[i]; |
|
184 | 186 | if(data[i]=='\n') |
|
185 | 187 | { |
|
186 | 188 | offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1)); |
|
187 | 189 | } |
|
188 | 190 | else |
|
189 | 191 | { |
|
190 | 192 | offset++; |
|
191 | 193 | } |
|
192 | 194 | } |
|
193 | 195 | if(!terminal->empty) |
|
194 | 196 | { |
|
195 | 197 | for(int i=terminal->firstLine;i<=terminal->lastLine;i++) |
|
196 | 198 | { |
|
197 | 199 | terminal_print_line(terminal,i); |
|
198 | 200 | } |
|
199 | 201 | } |
|
200 | 202 | return n; |
|
201 | 203 | } |
|
202 | 204 | |
|
203 | 205 | |
|
204 | 206 | |
|
205 | 207 | int terminal_write(streamdevice* device,void* data,int size, int n) |
|
206 | 208 | { |
|
207 | 209 | return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n); |
|
208 | 210 | } |
|
209 | 211 | |
|
210 | 212 | int terminal_read(streamdevice* device,void* data,int size, int n) |
|
211 | 213 | { |
|
212 | 214 | return n*size; |
|
213 | 215 | } |
|
214 | 216 | |
|
215 | 217 | int terminal_setpos(streamdevice* device,int pos) |
|
216 | 218 | { |
|
217 | 219 | return 1; |
|
218 | 220 | } |
|
219 | 221 | |
|
220 | 222 | int terminal_close( streamdevice* device) |
|
221 | 223 | { |
|
222 | 224 | return 1; |
|
223 | 225 | } |
|
224 | 226 | |
|
225 | 227 | |
|
226 | 228 | |
|
227 | 229 | |
|
228 | 230 | |
|
229 | 231 | |
|
230 | 232 | |
|
231 | 233 | |
|
232 | 234 | |
|
233 | 235 | |
|
234 | 236 | |
|
235 | 237 | |
|
236 | 238 | |
|
237 | 239 |
@@ -1,23 +1,22 | |||
|
1 | 1 | TEMPLATE = lib |
|
2 | OBJECTS_DIR = obj | |
|
3 | 2 | TARGET = terminal |
|
4 | 3 | |
|
5 | 4 | SOURCES += \ |
|
6 | 5 | Terminal.c |
|
7 | 6 | |
|
8 | 7 | |
|
9 | 8 | INCLUDEPATH += ../../../../includes \ |
|
10 | 9 | ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
11 | 10 | ../../../CPU/CMSIS/Include \ |
|
12 | 11 | ../../../../includes/GRAPHIC/CONTROLERS \ |
|
13 | 12 | ../../../../includes/GRAPHIC/GUI/FONTS \ |
|
14 | 13 | ../../../../includes/GRAPHIC/GUI/Widgets |
|
15 | 14 | |
|
16 | 15 | HEADERS += \ |
|
17 | 16 | ../../../../../includes/GRAPHIC/GUI/Widgets/terminal.h |
|
18 | 17 | |
|
19 | 18 | UCMODEL=stm32f4 |
|
20 | 19 | |
|
21 | 20 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
22 | 21 | INSTALLS += target |
|
23 | 22 |
@@ -1,101 +1,102 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2012, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@gmail.com |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #ifndef ILI9328_H |
|
23 | 23 | #define ILI9328_H |
|
24 | 24 | |
|
25 | 25 | #include <uhandle.h> |
|
26 | 26 | #include <genericLCD_Controler.h> |
|
27 | 27 | #include <stdint.h> |
|
28 | 28 | #include <fonts.h> |
|
29 | 29 | |
|
30 | 30 | extern int ili9328init(struct LCD_t* LCD); |
|
31 | 31 | extern void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H); |
|
32 | 32 | extern void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress); |
|
33 | 33 | extern void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); |
|
34 | 34 | extern void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT *font,uint32_t color); |
|
35 | 35 | extern void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
36 | 36 | extern void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
37 | 37 | extern void ili9328paintFilCircMidPoint(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
38 | 38 | extern void ili9328getPix(struct LCD_t* LCD,uint16_t* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h); |
|
39 | 39 | extern void ili9328refreshenable(struct LCD_t* LCD,int enable); |
|
40 | extern void ili9328paintChar(LCD_t* LCD,char buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color); | |
|
40 | 41 | |
|
41 | 42 | #define ILI9328_REGISTER_DRIVERCODEREAD ((uint32_t) 0x0000 ) |
|
42 | 43 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 ((uint32_t) 0x0001 ) |
|
43 | 44 | #define ILI9328_REGISTER_LCDDRIVINGCONTROL ((uint32_t) 0x0002 ) |
|
44 | 45 | #define ILI9328_REGISTER_ENTRYMODE ((uint32_t) 0x0003 ) |
|
45 | 46 | #define ILI9328_REGISTER_RESIZECONTROL ((uint32_t) 0x0004 ) |
|
46 | 47 | #define ILI9328_REGISTER_DISPLAYCONTROL1 ((uint32_t) 0x0007 ) |
|
47 | 48 | #define ILI9328_REGISTER_DISPLAYCONTROL2 ((uint32_t) 0x0008 ) |
|
48 | 49 | #define ILI9328_REGISTER_DISPLAYCONTROL3 ((uint32_t) 0x0009 ) |
|
49 | 50 | #define ILI9328_REGISTER_DISPLAYCONTROL4 ((uint32_t) 0x000A ) |
|
50 | 51 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 ((uint32_t) 0x000C ) |
|
51 | 52 | #define ILI9328_REGISTER_FRAMEMAKERPOSITION ((uint32_t) 0x000D ) |
|
52 | 53 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 ((uint32_t) 0x000F ) |
|
53 | 54 | #define ILI9328_REGISTER_POWERCONTROL1 ((uint32_t) 0x0010 ) |
|
54 | 55 | #define ILI9328_REGISTER_POWERCONTROL2 ((uint32_t) 0x0011 ) |
|
55 | 56 | #define ILI9328_REGISTER_POWERCONTROL3 ((uint32_t) 0x0012 ) |
|
56 | 57 | #define ILI9328_REGISTER_POWERCONTROL4 ((uint32_t) 0x0013 ) |
|
57 | 58 | #define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET ((uint32_t) 0x0020 ) |
|
58 | 59 | #define ILI9328_REGISTER_VERTICALGRAMADDRESSSET ((uint32_t) 0x0021 ) |
|
59 | 60 | #define ILI9328_REGISTER_WRITEDATATOGRAM ((uint32_t) 0x0022 ) |
|
60 | 61 | #define ILI9328_REGISTER_POWERCONTROL7 ((uint32_t) 0x0029 ) |
|
61 | 62 | #define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL ((uint32_t) 0x002B ) |
|
62 | 63 | #define ILI9328_REGISTER_GAMMACONTROL1 ((uint32_t) 0x0030 ) |
|
63 | 64 | #define ILI9328_REGISTER_GAMMACONTROL2 ((uint32_t) 0x0031 ) |
|
64 | 65 | #define ILI9328_REGISTER_GAMMACONTROL3 ((uint32_t) 0x0032 ) |
|
65 | 66 | #define ILI9328_REGISTER_GAMMACONTROL4 ((uint32_t) 0x0035 ) |
|
66 | 67 | #define ILI9328_REGISTER_GAMMACONTROL5 ((uint32_t) 0x0036 ) |
|
67 | 68 | #define ILI9328_REGISTER_GAMMACONTROL6 ((uint32_t) 0x0037 ) |
|
68 | 69 | #define ILI9328_REGISTER_GAMMACONTROL7 ((uint32_t) 0x0038 ) |
|
69 | 70 | #define ILI9328_REGISTER_GAMMACONTROL8 ((uint32_t) 0x0039 ) |
|
70 | 71 | #define ILI9328_REGISTER_GAMMACONTROL9 ((uint32_t) 0x003C ) |
|
71 | 72 | #define ILI9328_REGISTER_GAMMACONTROL10 ((uint32_t) 0x003D ) |
|
72 | 73 | #define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 ) |
|
73 | 74 | #define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) 0x0051 ) |
|
74 | 75 | #define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) 0x0052 ) |
|
75 | 76 | #define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION ((uint32_t) 0x0053 ) |
|
76 | 77 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 ((uint32_t) 0x0060 ) |
|
77 | 78 | #define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL ((uint32_t) 0x0061 ) |
|
78 | 79 | #define ILI9328_REGISTER_VERTICALSCROLLCONTROL ((uint32_t) 0x006A ) |
|
79 | 80 | #define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION ((uint32_t) 0x0080 ) |
|
80 | 81 | #define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE ((uint32_t) 0x0081 ) |
|
81 | 82 | #define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE ((uint32_t) 0x0082 ) |
|
82 | 83 | #define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION ((uint32_t) 0x0083 ) |
|
83 | 84 | #define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE ((uint32_t) 0x0084 ) |
|
84 | 85 | #define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE ((uint32_t) 0x0085 ) |
|
85 | 86 | #define ILI9328_REGISTER_PANELINTERFACECONTROL1 ((uint32_t) 0x0090 ) |
|
86 | 87 | #define ILI9328_REGISTER_PANELINTERFACECONTROL2 ((uint32_t) 0x0092 ) |
|
87 | 88 | #define ILI9328_REGISTER_PANELINTERFACECONTROL4 ((uint32_t) 0x0095 ) |
|
88 | 89 | #define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL ((uint32_t) 0x00A1 ) |
|
89 | 90 | #define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE ((uint32_t) 0x00A2 ) |
|
90 | 91 | #define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY ((uint32_t) 0x00A5 ) |
|
91 | 92 | |
|
92 | 93 | #ifdef _PRVATE_ILI9328_ |
|
93 | 94 | void ili9328cpFrame(LCD_t* LCD,void* buffer,int x,int y,int w, int h); |
|
94 | 95 | #endif |
|
95 | 96 | |
|
96 | 97 | #endif |
|
97 | 98 | |
|
98 | 99 | |
|
99 | 100 | |
|
100 | 101 | |
|
101 | 102 |
@@ -1,310 +1,316 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2013, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | |
|
23 | 23 | #include <SDL.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include "SDLCD.h" |
|
26 | 26 | |
|
27 | 27 | SDL_Surface *screen; |
|
28 | 28 | SDL_Overlay *bmp; |
|
29 | 29 | |
|
30 | 30 | int SDLCD_Xpos=0; |
|
31 | 31 | int SDLCD_Ypos=0; |
|
32 | 32 | int SDLCD_XWinStrt=0; |
|
33 | 33 | int SDLCD_YWinStrt=0; |
|
34 | 34 | int SDLCD_XWinEnd=0; |
|
35 | 35 | int SDLCD_YWinEnd=0; |
|
36 | 36 | |
|
37 | 37 | void* SDLCD_buffer; |
|
38 | 38 | int SDLCD_bpp; |
|
39 | 39 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); |
|
40 | 40 | |
|
41 | 41 | void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) |
|
42 | 42 | { |
|
43 | 43 | int i=0; |
|
44 | 44 | if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) { |
|
45 | 45 | fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); |
|
46 | 46 | exit(1); |
|
47 | 47 | } |
|
48 | 48 | screen = SDL_SetVideoMode(resx, resy, bpp, 0); |
|
49 | 49 | if(!screen) { |
|
50 | 50 | fprintf(stderr, "SDL: could not set video mode - exiting\n"); |
|
51 | 51 | exit(1); |
|
52 | 52 | } |
|
53 | 53 | if ( SDL_MUSTLOCK(screen) ) { |
|
54 | 54 | if ( SDL_LockSurface(screen) < 0 ) { |
|
55 | 55 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
56 | 56 | return; |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | if ( SDL_MUSTLOCK(screen) ) { |
|
60 | 60 | SDL_UnlockSurface(screen); |
|
61 | 61 | } |
|
62 | 62 | SDL_UpdateRect(screen, 0, 0, resx, resy); |
|
63 | 63 | SDLCD_buffer = malloc(resx*resy*bpp/8); |
|
64 | 64 | SDLCD_bpp = bpp; |
|
65 | 65 | for(i=0;i<(resx*resy);i++) |
|
66 | 66 | { |
|
67 | 67 | SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); |
|
68 | 68 | } |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | int SDLCD_init() |
|
74 | 74 | { |
|
75 | 75 | |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void SDLCD_writereg(uint32_t reg,uint32_t data) |
|
79 | 79 | { |
|
80 | 80 | switch (reg) { |
|
81 | 81 | case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET: |
|
82 | if((data>=screen->w) || (data<0))printf("Warning printing out of bounds HORIZONTALGRAMADDRESSSET=%d",data); | |
|
82 | if((data>=screen->w) || (data<0)) | |
|
83 | printf("Warning printing out of bounds HORIZONTALGRAMADDRESSSET=%d",data); | |
|
83 | 84 | SDLCD_Xpos = data; |
|
84 | 85 | break; |
|
85 | 86 | case ILI9328_REGISTER_VERTICALGRAMADDRESSSET: |
|
86 | if((data>=screen->h) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALGRAMADDRESSSET=%d",data); | |
|
87 | if((data>=screen->h) || (data<0)) | |
|
88 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALGRAMADDRESSSET=%d",data); | |
|
87 | 89 | SDLCD_Ypos = data; |
|
88 | 90 | break; |
|
89 | 91 | case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION: |
|
90 | if((data>=screen->w) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION=%d",data); | |
|
92 | if((data>=screen->w) || (data<0)) | |
|
93 | printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION=%d",data); | |
|
91 | 94 | SDLCD_XWinStrt = data; |
|
92 | 95 | break; |
|
93 | 96 | case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION: |
|
94 | if((data>=screen->w) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION=%d",data); | |
|
97 | if((data>=screen->w) || (data<0)) | |
|
98 | printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION=%d",data); | |
|
95 | 99 | SDLCD_XWinEnd = data; |
|
96 | 100 | break; |
|
97 | 101 | case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION: |
|
98 | if((data>=screen->h) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION=%d",data); | |
|
102 | if((data>=screen->h) || (data<0)) | |
|
103 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION=%d",data); | |
|
99 | 104 | SDLCD_YWinStrt = data; |
|
100 | 105 | break; |
|
101 | 106 | case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION: |
|
102 | if((data>=screen->h) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSENDPOSITION=%d",data); | |
|
107 | if((data>=screen->h) || (data<0)) | |
|
108 | printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSENDPOSITION=%d",data); | |
|
103 | 109 | SDLCD_YWinEnd = data; |
|
104 | 110 | break; |
|
105 | 111 | default: |
|
106 | 112 | break; |
|
107 | 113 | } |
|
108 | 114 | } |
|
109 | 115 | |
|
110 | 116 | uint32_t SDLCD_readreg(uint32_t reg) |
|
111 | 117 | { |
|
112 | 118 | return 0; |
|
113 | 119 | } |
|
114 | 120 | |
|
115 | 121 | |
|
116 | 122 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
117 | 123 | { |
|
118 | 124 | int bpp = surface->format->BytesPerPixel; |
|
119 | 125 | /* Here p is the address to the pixel we want to set */ |
|
120 | 126 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
121 | 127 | switch(bpp) { |
|
122 | 128 | case 1: |
|
123 | 129 | *p = pixel; |
|
124 | 130 | break; |
|
125 | 131 | case 2: |
|
126 | 132 | *(Uint16 *)p = pixel; |
|
127 | 133 | break; |
|
128 | 134 | case 3: |
|
129 | 135 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { |
|
130 | 136 | p[0] = (pixel >> 16) & 0xff; |
|
131 | 137 | p[1] = (pixel >> 8) & 0xff; |
|
132 | 138 | p[2] = pixel & 0xff; |
|
133 | 139 | } else { |
|
134 | 140 | p[0] = pixel & 0xff; |
|
135 | 141 | p[1] = (pixel >> 8) & 0xff; |
|
136 | 142 | p[2] = (pixel >> 16) & 0xff; |
|
137 | 143 | } |
|
138 | 144 | break; |
|
139 | 145 | case 4: |
|
140 | 146 | *(Uint32 *)p = pixel; |
|
141 | 147 | break; |
|
142 | 148 | } |
|
143 | 149 | } |
|
144 | 150 | |
|
145 | 151 | void SDLCD_putpixel_16bpp(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
146 | 152 | { |
|
147 | 153 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; |
|
148 | 154 | *(Uint16 *)p = pixel; |
|
149 | 155 | } |
|
150 | 156 | |
|
151 | 157 | Uint32 SDLCD_getpixel_16bpp(SDL_Surface *surface, int x, int y) |
|
152 | 158 | { |
|
153 | 159 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; |
|
154 | 160 | return *(Uint16 *)p; |
|
155 | 161 | } |
|
156 | 162 | |
|
157 | 163 | Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y) |
|
158 | 164 | { |
|
159 | 165 | int bpp = surface->format->BytesPerPixel; |
|
160 | 166 | /* Here p is the address to the pixel we want to retrieve */ |
|
161 | 167 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
162 | 168 | switch(bpp) { |
|
163 | 169 | case 1: |
|
164 | 170 | return *p; |
|
165 | 171 | case 2: |
|
166 | 172 | return *(Uint16 *)p; |
|
167 | 173 | case 3: |
|
168 | 174 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
169 | 175 | return p[0] << 16 | p[1] << 8 | p[2]; |
|
170 | 176 | else |
|
171 | 177 | return p[0] | p[1] << 8 | p[2] << 16; |
|
172 | 178 | case 4: |
|
173 | 179 | return *(Uint32 *)p; |
|
174 | 180 | default: |
|
175 | 181 | return 0; |
|
176 | 182 | } |
|
177 | 183 | /* shouldnβt happen, but avoids warnings */ |
|
178 | 184 | } |
|
179 | 185 | |
|
180 | 186 | void SDLCD_writeGRAM(void* buffer,uint32_t count) |
|
181 | 187 | { |
|
182 | 188 | int i=0; |
|
183 | 189 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
184 | 190 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
185 | 191 | if ( SDL_MUSTLOCK(screen) ) { |
|
186 | 192 | if ( SDL_LockSurface(screen) < 0 ) { |
|
187 | 193 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
188 | 194 | return; |
|
189 | 195 | } |
|
190 | 196 | } |
|
191 | 197 | for(i=0;i<count;i++) |
|
192 | 198 | { |
|
193 | 199 | SDLCD_putpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos,inptr[i]); |
|
194 | 200 | SDLCD_Xpos+=1; |
|
195 | 201 | ptr[i]=inptr[i]; |
|
196 | 202 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
197 | 203 | { |
|
198 | 204 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
199 | 205 | SDLCD_Ypos+=1; |
|
200 | 206 | } |
|
201 | 207 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
202 | 208 | { |
|
203 | 209 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
204 | 210 | } |
|
205 | 211 | } |
|
206 | 212 | if ( SDL_MUSTLOCK(screen) ) { |
|
207 | 213 | SDL_UnlockSurface(screen); |
|
208 | 214 | } |
|
209 | 215 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
210 | 216 | SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); |
|
211 | 217 | } |
|
212 | 218 | |
|
213 | 219 | void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) |
|
214 | 220 | { |
|
215 | 221 | int i=0; |
|
216 | 222 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
217 | 223 | if ( SDL_MUSTLOCK(screen) ) { |
|
218 | 224 | if ( SDL_LockSurface(screen) < 0 ) { |
|
219 | 225 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
220 | 226 | return; |
|
221 | 227 | } |
|
222 | 228 | } |
|
223 | 229 | for(i=0;i<count;i++) |
|
224 | 230 | { |
|
225 | 231 | *(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos)=inptr[i]; |
|
226 | 232 | SDLCD_Xpos+=1; |
|
227 | 233 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
228 | 234 | { |
|
229 | 235 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
230 | 236 | SDLCD_Ypos+=1; |
|
231 | 237 | } |
|
232 | 238 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
233 | 239 | { |
|
234 | 240 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
235 | 241 | } |
|
236 | 242 | } |
|
237 | 243 | if ( SDL_MUSTLOCK(screen) ) { |
|
238 | 244 | SDL_UnlockSurface(screen); |
|
239 | 245 | } |
|
240 | 246 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
241 | 247 | SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); |
|
242 | 248 | } |
|
243 | 249 | |
|
244 | 250 | void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count) |
|
245 | 251 | { |
|
246 | 252 | int i=0; |
|
247 | 253 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
248 | 254 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
249 | 255 | for(i=0;i<count;i++) |
|
250 | 256 | { |
|
251 | 257 | inptr[i]=*(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos); |
|
252 | 258 | SDLCD_Xpos+=1; |
|
253 | 259 | ptr[i]=inptr[i]; |
|
254 | 260 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
255 | 261 | { |
|
256 | 262 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
257 | 263 | SDLCD_Ypos+=1; |
|
258 | 264 | } |
|
259 | 265 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
260 | 266 | { |
|
261 | 267 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
262 | 268 | } |
|
263 | 269 | } |
|
264 | 270 | |
|
265 | 271 | } |
|
266 | 272 | |
|
267 | 273 | void SDLCD_readGRAM(void* buffer,uint32_t count) |
|
268 | 274 | { |
|
269 | 275 | int i=0; |
|
270 | 276 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
271 | 277 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
272 | 278 | for(i=0;i<count;i++) |
|
273 | 279 | { |
|
274 | 280 | inptr[i]=SDLCD_getpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos); |
|
275 | 281 | SDLCD_Xpos+=1; |
|
276 | 282 | ptr[i]=inptr[i]; |
|
277 | 283 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
278 | 284 | { |
|
279 | 285 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
280 | 286 | SDLCD_Ypos+=1; |
|
281 | 287 | } |
|
282 | 288 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
283 | 289 | { |
|
284 | 290 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
285 | 291 | } |
|
286 | 292 | } |
|
287 | 293 | |
|
288 | 294 | } |
|
289 | 295 | |
|
290 | 296 | |
|
291 | 297 | |
|
292 | 298 | |
|
293 | 299 | |
|
294 | 300 | |
|
295 | 301 | |
|
296 | 302 | |
|
297 | 303 | |
|
298 | 304 | |
|
299 | 305 | |
|
300 | 306 | |
|
301 | 307 | |
|
302 | 308 | |
|
303 | 309 | |
|
304 | 310 | |
|
305 | 311 | |
|
306 | 312 | |
|
307 | 313 | |
|
308 | 314 | |
|
309 | 315 | |
|
310 | 316 |
General Comments 0
You need to be logged in to leave comments.
Login now