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