##// END OF EJS Templates
added text painter on ili9328
jeandet@pc-de-jeandet3.LAB-LPP.LOCAL -
r37:b6a4710d362a dev_alexis
parent child
Show More
@@ -1,3 +1,7
1 CPU=stm32f4xxxG
1 CPU=stm32f4xxxG
2 DEFINES+=BSP=\\\"BEAGLESYNTH\\\"
2 DEFINES+=BSP=\\\"BEAGLESYNTH\\\"
3 include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri)
3 include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri)
4
5 beagleCp.target = beagleCp
6 beagleCp.commands = scp $$DESTDIR/$(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin
7 QMAKE_EXTRA_TARGETS += beagleCp
@@ -1,278 +1,275
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@gmail.com
20 -- Mail : alexis.jeandet@gmail.com
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 uint32_t OSC0 =8000000;
31 uint32_t OSC0 =8000000;
32 uint32_t INTOSC =16000000;
32 uint32_t INTOSC =16000000;
33 uint32_t RTCOSC =32768;
33 uint32_t RTCOSC =32768;
34 uint32_t currentCpuFreq=0;
34 uint32_t currentCpuFreq=0;
35 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
35 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
36
36
37 LCD_IF_t lcdIF0={
37 LCD_IF_t lcdIF0={
38 .init = &bsp_FSMC_init,
38 .init = &bsp_FSMC_init,
39 .writereg = &bsp_lcd0_write_reg,
39 .writereg = &bsp_lcd0_write_reg,
40 .readreg = &bsp_lcd0_read_reg,
40 .readreg = &bsp_lcd0_read_reg,
41 .writeGRAM = &bsp_lcd0_writeGRAM,
41 .writeGRAM = &bsp_lcd0_writeGRAM,
42 .readGRAM = &bsp_lcd0_readGRAM
42 .readGRAM = &bsp_lcd0_readGRAM
43 };
43 };
44
44
45 LCD_t lcd0={
45 LCD_t lcd0={
46 .interface = &lcdIF0,
46 .interface = &lcdIF0,
47 .init = &ili9328init,
47 .init = &ili9328init,
48 .paint = &ili9328paint,
48 .paint = &ili9328paint,
49 .refreshenable = &ili9328refreshenable,
49 .refreshenable = &ili9328refreshenable,
50 .width= 240,
50 .width= 240,
51 .height = 320
51 .height = 320
52 };
52 };
53
53
54 volatile int16_t* lcd0_CMD=(volatile int16_t*) 0x60000000;
54 volatile int16_t* lcd0_CMD=(volatile int16_t*) 0x60000000;
55 volatile int16_t* lcd0_DATA=(volatile int16_t*)(0x61FFFFF0);
55 volatile int16_t* lcd0_DATA=(volatile int16_t*)(0x61FFFFF0);
56
56
57 float VREF0 =(float)3.3;
57 float VREF0 =(float)3.3;
58
58
59 int bsp_init()
59 int bsp_init()
60 {
60 {
61 int i=0;
61 int i=0;
62 for(i=0;i<32;i++)
62 for(i=0;i<32;i++)
63 {
63 {
64 __opnfiles__[i] = NULL;
64 __opnfiles__[i] = NULL;
65 }
65 }
66 bsp_GPIO_init();
66 bsp_GPIO_init();
67 bsp_uart_init();
67 bsp_uart_init();
68 bsp_iic_init();
68 bsp_iic_init();
69 bsp_FSMC_init();
69 bsp_FSMC_init();
70 printf("\r================================================================\n\r");
70 printf("\r================================================================\n\r");
71 printf("================================================================\n\r");
71 printf("================================================================\n\r");
72 printf(BSP);
72 printf(BSP);
73 printf(" initialised\n\r");
73 printf(" initialised\n\r");
74 printf("================================================================\n\r");
74 printf("================================================================\n\r");
75 return 1;
75 return 1;
76 }
76 }
77
77
78 void bsp_GPIO_init()
78 void bsp_GPIO_init()
79 {
79 {
80 gpio_t gpio1 = gpioopen(LED1);
80 gpio_t gpio1 = gpioopen(LED1);
81 gpio_t gpio2 = gpioopen(LED2);
81 gpio_t gpio2 = gpioopen(LED2);
82 gpio_t gpio3 = gpioopen(LED3);
82 gpio_t gpio3 = gpioopen(LED3);
83 gpio_t gpio4 = gpioopen(PSU_DISABLE);
83 gpio_t gpio4 = gpioopen(PSU_DISABLE);
84 gpio_t gpio5 = gpioopen(PSU_ALERT_5V);
84 gpio_t gpio5 = gpioopen(PSU_ALERT_5V);
85 gpio_t gpio6 = gpioopen(PSU_ALERT_1_5V);
85 gpio_t gpio6 = gpioopen(PSU_ALERT_1_5V);
86 gpio_t gpio7 = gpioopen(PSU_ALERT_3_3V);
86 gpio_t gpio7 = gpioopen(PSU_ALERT_3_3V);
87 gpiosetspeed(&gpio1,gpiohighspeed);
87 gpiosetspeed(&gpio1,gpiohighspeed);
88 gpiosetspeed(&gpio2,gpiohighspeed);
88 gpiosetspeed(&gpio2,gpiohighspeed);
89 gpiosetspeed(&gpio3,gpiohighspeed);
89 gpiosetspeed(&gpio3,gpiohighspeed);
90 gpiosetspeed(&gpio4,gpiohighspeed);
90 gpiosetspeed(&gpio4,gpiohighspeed);
91 gpiosetspeed(&gpio5,gpiohighspeed);
91 gpiosetspeed(&gpio5,gpiohighspeed);
92 gpiosetspeed(&gpio6,gpiohighspeed);
92 gpiosetspeed(&gpio6,gpiohighspeed);
93 gpiosetspeed(&gpio7,gpiohighspeed);
93 gpiosetspeed(&gpio7,gpiohighspeed);
94 gpioclr(PSU_DISABLE);
94 gpioclr(PSU_DISABLE);
95 gpiosetdir(&gpio1,gpiooutdir);
95 gpiosetdir(&gpio1,gpiooutdir);
96 gpiosetdir(&gpio3,gpiooutdir);
96 gpiosetdir(&gpio3,gpiooutdir);
97 gpiosetdir(&gpio2,gpiooutdir);
97 gpiosetdir(&gpio2,gpiooutdir);
98 gpiosetdir(&gpio4,gpiooutdir);
98 gpiosetdir(&gpio4,gpiooutdir);
99 gpiosetdir(&gpio5,gpioindir);
99 gpiosetdir(&gpio5,gpioindir);
100 gpiosetdir(&gpio6,gpioindir);
100 gpiosetdir(&gpio6,gpioindir);
101 gpiosetdir(&gpio7,gpioindir);
101 gpiosetdir(&gpio7,gpioindir);
102 gpioclr(PSU_DISABLE);
102 gpioclr(PSU_DISABLE);
103 }
103 }
104
104
105 void bsp_uart_init()
105 void bsp_uart_init()
106 {
106 {
107 if(__opnfiles__[1]==NULL)
107 if(__opnfiles__[1]==NULL)
108 {
108 {
109 //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t));
109 //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t));
110 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
110 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
111 uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1);
111 uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1);
112 uartmkstreamdev(uart,fd1);
112 uartmkstreamdev(uart,fd1);
113 __opnfiles__[1] = fd1;
113 __opnfiles__[1] = fd1;
114 }
114 }
115 else
115 else
116 {
116 {
117 uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1);
117 uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1);
118 }
118 }
119 }
119 }
120
120
121
121
122
122
123 int bsp_FSMC_init()
123 int bsp_FSMC_init()
124 {
124 {
125 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
125 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
126 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
126 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
127
127
128 gpio_t gpio1 = gpioopen(LCD_RESET);
128 gpio_t gpio1 = gpioopen(LCD_RESET);
129 gpiosetspeed(&gpio1,gpiohighspeed);
129 gpiosetspeed(&gpio1,gpiohighspeed);
130 gpiosetdir(&gpio1,gpiooutdir);
130 gpiosetdir(&gpio1,gpiooutdir);
131 gpioclr(LCD_RESET);
131 gpioclr(LCD_RESET);
132
132
133 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15\
133 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15\
134 ,PD8,PD9,PD10,PD4,PD5,PD7,PE4};
134 ,PD8,PD9,PD10,PD4,PD5,PD7,PE4};
135 for(int i=0;i<20;i++)
135 for(int i=0;i<20;i++)
136 {
136 {
137 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
137 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
138 LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
138 LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
139 gpiosetconfig(&LCD_DBx);
139 gpiosetconfig(&LCD_DBx);
140 GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC);
140 GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC);
141 }
141 }
142
142
143 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
143 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
144 FSMC_NORSRAMTimingInitTypeDef p;
144 FSMC_NORSRAMTimingInitTypeDef p;
145
145
146 /* Enable FSMC clock */
146 /* Enable FSMC clock */
147 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
147 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
148
148
149 /*-- FSMC Configuration ------------------------------------------------------*/
149 /*-- FSMC Configuration ------------------------------------------------------*/
150 /*----------------------- SRAM Bank 3 ----------------------------------------*/
150 /*----------------------- SRAM Bank 3 ----------------------------------------*/
151 /* FSMC_Bank1_NORSRAM4 configuration */
151 /* FSMC_Bank1_NORSRAM4 configuration */
152 //p.FSMC_AddressSetupTime = 5;
152 //p.FSMC_AddressSetupTime = 5;
153 p.FSMC_AddressSetupTime = 2;
153 p.FSMC_AddressSetupTime = 1;
154 p.FSMC_AddressHoldTime = 0;
154 p.FSMC_AddressHoldTime = 0;
155 //p.FSMC_DataSetupTime = 9;
155 //p.FSMC_DataSetupTime = 9;
156 p.FSMC_DataSetupTime = 4;
156 p.FSMC_DataSetupTime = 11;
157 p.FSMC_BusTurnAroundDuration = 0;
157 p.FSMC_BusTurnAroundDuration = 0;
158 p.FSMC_CLKDivision = 0;
158 p.FSMC_CLKDivision = 0;
159 p.FSMC_DataLatency = 0;
159 p.FSMC_DataLatency = 0;
160 p.FSMC_AccessMode = FSMC_AccessMode_A;
160 p.FSMC_AccessMode = FSMC_AccessMode_A;
161 /* Color LCD configuration ------------------------------------
161 /* Color LCD configuration ------------------------------------
162 LCD configured as follow:
162 LCD configured as follow:
163 - Data/Address MUX = Disable
163 - Data/Address MUX = Disable
164 - Memory Type = SRAM
164 - Memory Type = SRAM
165 - Data Width = 16bit
165 - Data Width = 16bit
166 - Write Operation = Enable
166 - Write Operation = Enable
167 - Extended Mode = Enable
167 - Extended Mode = Enable
168 - Asynchronous Wait = Disable */
168 - Asynchronous Wait = Disable */
169
169
170 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
170 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
171 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
171 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
172 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
172 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
173 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
173 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
174 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
174 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
175 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
175 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
176 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
176 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
177 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
177 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
178 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
178 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
179 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
179 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
180 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
180 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
181 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
181 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
182 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
182 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
183 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
183 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
184 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
184 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
185
185
186 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
186 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
187
187
188 /* Enable FSMC NOR/SRAM Bank1 */
188 /* Enable FSMC NOR/SRAM Bank1 */
189 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
189 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
190 gpioset(LCD_RESET);
190 gpioset(LCD_RESET);
191 lcd0.init(&lcd0);
191 lcd0.init(&lcd0);
192 return 1;
192 return 1;
193 }
193 }
194
194
195 void bsp_spi_init()
195 void bsp_spi_init()
196 {
196 {
197
197
198 }
198 }
199
199
200
200
201 void bsp_iic_init()
201 void bsp_iic_init()
202 {
202 {
203 i2copenandconfig(i2c2,0,400000,PF0,PF1);
203 i2copenandconfig(i2c2,0,400000,PF0,PF1);
204 }
204 }
205
205
206 void bsp_SD_init()
206 void bsp_SD_init()
207 {
207 {
208
208
209 }
209 }
210
210
211 void vs10XXclearXCS(){}
211 void vs10XXclearXCS(){}
212 void vs10XXsetXCS(){}
212 void vs10XXsetXCS(){}
213 int vs10XXDREQ()
213 int vs10XXDREQ()
214 {
214 {
215 return 1;
215 return 1;
216 }
216 }
217
217
218
218
219 void bsppowersdcard(char onoff) //always ON
219 void bsppowersdcard(char onoff) //always ON
220 {
220 {
221
221
222 }
222 }
223
223
224 char bspsdcardpresent()
224 char bspsdcardpresent()
225 {
225 {
226 return 0;
226 return 0;
227 }
227 }
228
228
229 char bspsdcardwriteprotected()
229 char bspsdcardwriteprotected()
230 {
230 {
231 return 0;
231 return 0;
232 }
232 }
233
233
234 void bspsdcardselect(char YESNO)
234 void bspsdcardselect(char YESNO)
235 {
235 {
236
236
237 }
237 }
238
238
239
239
240 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
240 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
241 {
241 {
242 printf("Write %X @ %d\n\r",data,reg);
243 *lcd0_CMD=(uint16_t)reg;
242 *lcd0_CMD=(uint16_t)reg;
244 *lcd0_DATA=(uint16_t)data;
243 *lcd0_DATA=(uint16_t)data;
245 }
244 }
246
245
247 uint32_t bsp_lcd0_read_reg(uint32_t reg)
246 uint32_t bsp_lcd0_read_reg(uint32_t reg)
248 {
247 {
249 *lcd0_CMD=(uint16_t)reg;
248 *lcd0_CMD=(uint16_t)reg;
250 return (uint16_t)*lcd0_DATA;
249 return (uint16_t)*lcd0_DATA;
251 }
250 }
252
251
253 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
252 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
254 {
253 {
255 printf("Write to GRAM %d pixels from 0x%X\t\n\r",count,(int)buffer);
256 *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM;
254 *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM;
257 uint16_t* castedBuff=(uint16_t*)buffer;
255 uint16_t* castedBuff=(uint16_t*)buffer;
258 for(int i=0;i<(int)count;i++)
256 for(int i=0;i<(int)count;i++)
259 {
257 {
260 *lcd0_DATA=castedBuff[i];
258 *lcd0_DATA=castedBuff[i];
261 }
259 }
262 printf("[Done]\n\r");
263 }
260 }
264
261
265 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
262 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
266 {
263 {
267 *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM;
264 *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM;
268 uint16_t* castedBuff=(uint16_t*)buffer;
265 uint16_t* castedBuff=(uint16_t*)buffer;
269 castedBuff[0]=*lcd0_DATA;
266 castedBuff[0]=*lcd0_DATA;
270 for(int i=0;i<(int)count;i++)
267 for(int i=0;i<(int)count;i++)
271 {
268 {
272 castedBuff[i]=*lcd0_DATA;
269 castedBuff[i]=*lcd0_DATA;
273 }
270 }
274 }
271 }
275
272
276
273
277
274
278
275
@@ -1,88 +1,86
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 <i2c.h>
7 #include <i2c.h>
8 #include <CS43L22.h>
8 #include <CS43L22.h>
9 #include <ina226.h>
9 #include <ina226.h>
10 #include <fonts.h>
10 #include <fonts.h>
11
11
12
12
13 extern streamdevice* __opnfiles__[];
13 extern streamdevice* __opnfiles__[];
14
14
15 #define LCD_COLOR_WHITE 0xFFFF
16 #define LCD_COLOR_BLACK 0x0000
17 #define LCD_COLOR_GREY 0xF7DE
18 #define LCD_COLOR_BLUE 0x001F
19 #define LCD_COLOR_BLUE2 0x051F
20 #define LCD_COLOR_RED 0xF800
21 #define LCD_COLOR_MAGENTA 0xF81F
22 #define LCD_COLOR_GREEN 0x07E0
23 #define LCD_COLOR_CYAN 0x7FFF
24 #define LCD_COLOR_YELLOW 0xFFE0
25
26
15 int main()
27 int main()
16 {
28 {
17 INA226_t ina5VSens,ina33VSens,ina15VSens;
29 INA226_t ina5VSens,ina33VSens,ina15VSens;
18 gpioset(PSU_DISABLE);
30 gpioset(PSU_DISABLE);
19 volatile int16_t* regtest=(volatile int16_t*)0x60000000;
31 volatile int16_t* regtest=(volatile int16_t*)0x60000000;
20 volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0);
32 volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0);
21 //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000);
33 //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000);
22 //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000);
34 //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000);
23 *regtest=(int16_t)0;
35 *regtest=(int16_t)0;
24 printf("LCD ID=%x\n\r",0xFFFF&(*regtest2));
36 printf("LCD ID=%x\n\r",0xFFFF&(*regtest2));
25 //lcd0.refreshenable(&lcd0,1);
37 uint16_t x=90,y=0;
38 ili9328paintFilRect(&lcd0,0,0,240,320,0x01F,0x01F);
39 // ili9328paintText(&lcd0,"Hello",14,38,&Font16x24,0);
40 ili9328paintText(&lcd0,"Hello",10,34,&Font16x24,0xF800);
26 while(1)
41 while(1)
27 {
42 {
28 //ili9328setFrame(&lcd0,0,0,240,320);
43 ili9328paintText(&lcd0," World !",90,y+24,&Font16x24,0xF800);
29 //ili9328setGRAMaddress(&lcd0,0,0);
44 ili9328paintFilRect(&lcd0,x,y,20,20,0x01F,0xF800);
30 *regtest=(int16_t)0x20;
45 for(volatile int i=0;i<(320*500);i++);
31 *regtest2=(int16_t)0x0;
46 ili9328paintFilRect(&lcd0,90,y,150,24,0x01F,0x01F);
32 *regtest=(int16_t)0x21;
47 ili9328paintFilRect(&lcd0,x,y,20,20,0x01F,0x01F);
33 *regtest2=(int16_t)0x0;
48 y+=10;
34 *regtest=(int16_t)0x22;
49 if(y>290){y=0;x+=20;}
35 for(int i=0;i<(320*240);i++)
50 if(x>220){x=90;}
36 {
37 *regtest2=(int16_t)0x001F;
38 }
39 for(volatile int i=0;i<(320*240*100);i++);
40 //uint16_t test[100];
41 //ili9328setFrame(&lcd0,10,10,10,10);
42 //*regtest=(int16_t)0x22;
43 //for(int i=0;i<(10*10);i++)
44 //{
45 // *regtest2=(int16_t)(0xF800);
46 //test[i]=(int16_t)0xF800;
47 //for(volatile int l=0;l<(1024);l++);
48
49 //}
50 //bsp_lcd0_writeGRAM(test,10*10);
51 //lcd0.paint(&lcd0,test,100,100,80,80);
52 //for(volatile int i=0;i<(320*240*100);i++);
53 }
51 }
54
52
55 if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000))
53 if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000))
56 {
54 {
57 printf("Can't open 3.3V monitor\n\r");
55 printf("Can't open 3.3V monitor\n\r");
58 }
56 }
59
57
60 int current5V,current33V,current15V;
58 int current5V,current33V,current15V;
61 printf("\t5V\t3.3V\n\r");
59 printf("\t5V\t3.3V\n\r");
62 while(1)
60 while(1)
63 {
61 {
64 for(volatile int i=0;i<1024*1024;i++);
62 for(volatile int i=0;i<1024*1024;i++);
65 gpioset(LED1);
63 gpioset(LED1);
66 gpioclr(LED2);
64 gpioclr(LED2);
67 for(volatile int i=0;i<1024*1024;i++);
65 for(volatile int i=0;i<1024*1024;i++);
68 gpioclr(LED1);
66 gpioclr(LED1);
69 gpioset(LED2);
67 gpioset(LED2);
70 //current5V = ina226getCurrent(&ina5VSens);
68 //current5V = ina226getCurrent(&ina5VSens);
71 current33V = ina226getCurrent(&ina33VSens);
69 current33V = ina226getCurrent(&ina33VSens);
72 //current15V = ina226getCurrent(&ina15VSens);
70 //current15V = ina226getCurrent(&ina15VSens);
73 //current = ina226getReg(&Psens1,INA226_Current_Reg);
71 //current = ina226getReg(&Psens1,INA226_Current_Reg);
74 //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000);
72 //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000);
75 printf("%duA %dmA\n\r",current33V,current33V/1000);
73 printf("%duA %dmA\n\r",current33V,current33V/1000);
76 }
74 }
77 printf("hello world\n\r");
75 printf("hello world\n\r");
78 return 0;
76 return 0;
79 }
77 }
80
78
81
79
82
80
83
81
84
82
85
83
86
84
87
85
88
86
@@ -1,92 +1,95
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
29
29 extern int ili9328init(struct LCD_t* LCD);
30 extern int ili9328init(struct LCD_t* LCD);
30 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);
31 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);
32 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);
35 extern void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint32_t fillColor);
33 extern void ili9328refreshenable(struct LCD_t* LCD,int enable);
36 extern void ili9328refreshenable(struct LCD_t* LCD,int enable);
34
37
35 #define ILI9328_REGISTER_DRIVERCODEREAD ((uint32_t) 0x0000 )
38 #define ILI9328_REGISTER_DRIVERCODEREAD ((uint32_t) 0x0000 )
36 #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 ((uint32_t) 0x0001 )
39 #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 ((uint32_t) 0x0001 )
37 #define ILI9328_REGISTER_LCDDRIVINGCONTROL ((uint32_t) 0x0002 )
40 #define ILI9328_REGISTER_LCDDRIVINGCONTROL ((uint32_t) 0x0002 )
38 #define ILI9328_REGISTER_ENTRYMODE ((uint32_t) 0x0003 )
41 #define ILI9328_REGISTER_ENTRYMODE ((uint32_t) 0x0003 )
39 #define ILI9328_REGISTER_RESIZECONTROL ((uint32_t) 0x0004 )
42 #define ILI9328_REGISTER_RESIZECONTROL ((uint32_t) 0x0004 )
40 #define ILI9328_REGISTER_DISPLAYCONTROL1 ((uint32_t) 0x0007 )
43 #define ILI9328_REGISTER_DISPLAYCONTROL1 ((uint32_t) 0x0007 )
41 #define ILI9328_REGISTER_DISPLAYCONTROL2 ((uint32_t) 0x0008 )
44 #define ILI9328_REGISTER_DISPLAYCONTROL2 ((uint32_t) 0x0008 )
42 #define ILI9328_REGISTER_DISPLAYCONTROL3 ((uint32_t) 0x0009 )
45 #define ILI9328_REGISTER_DISPLAYCONTROL3 ((uint32_t) 0x0009 )
43 #define ILI9328_REGISTER_DISPLAYCONTROL4 ((uint32_t) 0x000A )
46 #define ILI9328_REGISTER_DISPLAYCONTROL4 ((uint32_t) 0x000A )
44 #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 ((uint32_t) 0x000C )
47 #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 ((uint32_t) 0x000C )
45 #define ILI9328_REGISTER_FRAMEMAKERPOSITION ((uint32_t) 0x000D )
48 #define ILI9328_REGISTER_FRAMEMAKERPOSITION ((uint32_t) 0x000D )
46 #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 ((uint32_t) 0x000F )
49 #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 ((uint32_t) 0x000F )
47 #define ILI9328_REGISTER_POWERCONTROL1 ((uint32_t) 0x0010 )
50 #define ILI9328_REGISTER_POWERCONTROL1 ((uint32_t) 0x0010 )
48 #define ILI9328_REGISTER_POWERCONTROL2 ((uint32_t) 0x0011 )
51 #define ILI9328_REGISTER_POWERCONTROL2 ((uint32_t) 0x0011 )
49 #define ILI9328_REGISTER_POWERCONTROL3 ((uint32_t) 0x0012 )
52 #define ILI9328_REGISTER_POWERCONTROL3 ((uint32_t) 0x0012 )
50 #define ILI9328_REGISTER_POWERCONTROL4 ((uint32_t) 0x0013 )
53 #define ILI9328_REGISTER_POWERCONTROL4 ((uint32_t) 0x0013 )
51 #define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET ((uint32_t) 0x0020 )
54 #define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET ((uint32_t) 0x0020 )
52 #define ILI9328_REGISTER_VERTICALGRAMADDRESSSET ((uint32_t) 0x0021 )
55 #define ILI9328_REGISTER_VERTICALGRAMADDRESSSET ((uint32_t) 0x0021 )
53 #define ILI9328_REGISTER_WRITEDATATOGRAM ((uint32_t) 0x0022 )
56 #define ILI9328_REGISTER_WRITEDATATOGRAM ((uint32_t) 0x0022 )
54 #define ILI9328_REGISTER_POWERCONTROL7 ((uint32_t) 0x0029 )
57 #define ILI9328_REGISTER_POWERCONTROL7 ((uint32_t) 0x0029 )
55 #define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL ((uint32_t) 0x002B )
58 #define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL ((uint32_t) 0x002B )
56 #define ILI9328_REGISTER_GAMMACONTROL1 ((uint32_t) 0x0030 )
59 #define ILI9328_REGISTER_GAMMACONTROL1 ((uint32_t) 0x0030 )
57 #define ILI9328_REGISTER_GAMMACONTROL2 ((uint32_t) 0x0031 )
60 #define ILI9328_REGISTER_GAMMACONTROL2 ((uint32_t) 0x0031 )
58 #define ILI9328_REGISTER_GAMMACONTROL3 ((uint32_t) 0x0032 )
61 #define ILI9328_REGISTER_GAMMACONTROL3 ((uint32_t) 0x0032 )
59 #define ILI9328_REGISTER_GAMMACONTROL4 ((uint32_t) 0x0035 )
62 #define ILI9328_REGISTER_GAMMACONTROL4 ((uint32_t) 0x0035 )
60 #define ILI9328_REGISTER_GAMMACONTROL5 ((uint32_t) 0x0036 )
63 #define ILI9328_REGISTER_GAMMACONTROL5 ((uint32_t) 0x0036 )
61 #define ILI9328_REGISTER_GAMMACONTROL6 ((uint32_t) 0x0037 )
64 #define ILI9328_REGISTER_GAMMACONTROL6 ((uint32_t) 0x0037 )
62 #define ILI9328_REGISTER_GAMMACONTROL7 ((uint32_t) 0x0038 )
65 #define ILI9328_REGISTER_GAMMACONTROL7 ((uint32_t) 0x0038 )
63 #define ILI9328_REGISTER_GAMMACONTROL8 ((uint32_t) 0x0039 )
66 #define ILI9328_REGISTER_GAMMACONTROL8 ((uint32_t) 0x0039 )
64 #define ILI9328_REGISTER_GAMMACONTROL9 ((uint32_t) 0x003C )
67 #define ILI9328_REGISTER_GAMMACONTROL9 ((uint32_t) 0x003C )
65 #define ILI9328_REGISTER_GAMMACONTROL10 ((uint32_t) 0x003D )
68 #define ILI9328_REGISTER_GAMMACONTROL10 ((uint32_t) 0x003D )
66 #define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 )
69 #define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 )
67 #define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) 0x0051 )
70 #define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) 0x0051 )
68 #define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) 0x0052 )
71 #define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) 0x0052 )
69 #define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION ((uint32_t) 0x0053 )
72 #define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION ((uint32_t) 0x0053 )
70 #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 ((uint32_t) 0x0060 )
73 #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 ((uint32_t) 0x0060 )
71 #define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL ((uint32_t) 0x0061 )
74 #define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL ((uint32_t) 0x0061 )
72 #define ILI9328_REGISTER_VERTICALSCROLLCONTROL ((uint32_t) 0x006A )
75 #define ILI9328_REGISTER_VERTICALSCROLLCONTROL ((uint32_t) 0x006A )
73 #define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION ((uint32_t) 0x0080 )
76 #define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION ((uint32_t) 0x0080 )
74 #define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE ((uint32_t) 0x0081 )
77 #define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE ((uint32_t) 0x0081 )
75 #define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE ((uint32_t) 0x0082 )
78 #define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE ((uint32_t) 0x0082 )
76 #define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION ((uint32_t) 0x0083 )
79 #define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION ((uint32_t) 0x0083 )
77 #define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE ((uint32_t) 0x0084 )
80 #define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE ((uint32_t) 0x0084 )
78 #define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE ((uint32_t) 0x0085 )
81 #define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE ((uint32_t) 0x0085 )
79 #define ILI9328_REGISTER_PANELINTERFACECONTROL1 ((uint32_t) 0x0090 )
82 #define ILI9328_REGISTER_PANELINTERFACECONTROL1 ((uint32_t) 0x0090 )
80 #define ILI9328_REGISTER_PANELINTERFACECONTROL2 ((uint32_t) 0x0092 )
83 #define ILI9328_REGISTER_PANELINTERFACECONTROL2 ((uint32_t) 0x0092 )
81 #define ILI9328_REGISTER_PANELINTERFACECONTROL4 ((uint32_t) 0x0095 )
84 #define ILI9328_REGISTER_PANELINTERFACECONTROL4 ((uint32_t) 0x0095 )
82 #define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL ((uint32_t) 0x00A1 )
85 #define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL ((uint32_t) 0x00A1 )
83 #define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE ((uint32_t) 0x00A2 )
86 #define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE ((uint32_t) 0x00A2 )
84 #define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY ((uint32_t) 0x00A5 )
87 #define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY ((uint32_t) 0x00A5 )
85
88
86
89
87 #endif
90 #endif
88
91
89
92
90
93
91
94
92
95
@@ -1,120 +1,164
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 #include <ili9328.h>
22 #include <ili9328.h>
23 #include <stdio.h>
23 #include <stdio.h>
24 #include <stddef.h>
24 #include <stddef.h>
25
25
26 #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++);
26 #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++);
27
27
28 void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress)
28 void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress)
29 {
29 {
30 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress);
30 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress);
31 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress);
31 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress);
32 }
32 }
33
33
34 void ili9328refreshenable(struct LCD_t* LCD,int enable)
34 void ili9328refreshenable(struct LCD_t* LCD,int enable)
35 {
35 {
36 if(enable)
36 if(enable)
37 {
37 {
38 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018);
38 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018);
39 }
39 }
40 else
40 else
41 {
41 {
42 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008);
42 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008);
43
43
44 }
44 }
45 }
45 }
46
46
47 void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H)
47 void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H)
48 {
48 {
49 printf("setFrame X=%d Y=%d W=%d H=%d\n\r",(int)X,(int)Y,(int)W,(int)H);
49 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X);
50 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,X);
50 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y);
51 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Y);
51 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X);
52 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,X);
52 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1));
53 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,X);
53 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y);
54 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,W+X);
54 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1));
55 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,Y);
56 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,Y+H);
57 }
55 }
58
56
59 void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height)
57 void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height)
60 {
58 {
61 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width<(Xpos+Width)) && (LCD->height<(Ypos+Height)))
59 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height)))
60 {
61 ili9328setFrame(LCD,Xpos,Ypos,Width,Height);
62 LCD->interface->writeGRAM(buffer,Width*Height);
63 }
64 }
65
66 void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint32_t fillColor)
67 {
68 ili9328setFrame(LCD,Xpos,Ypos,w,h);
69 uint16_t tmp[32];
70 for(int i=0;i<32;i++)tmp[i]=fillColor;
71 for(int i=0;i<(h*w);i+=32)
72 {
73 LCD->interface->writeGRAM(tmp,32);
74 }
75 int rem=(w*h)%32;
76 if(rem)LCD->interface->writeGRAM(tmp,rem);
77 }
78
79 void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color)
80 {
81 int w=font->Width,h=font->Height,pix=0,tableoffset=0;
82 uint16_t tmp[w];
83 uint16_t line=0,linenum=0,charnum=0;
84 while(*buffer)
62 {
85 {
63 printf("paint\n\r");
86 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1);
64 ili9328setFrame(LCD,Xpos,Ypos,Width,Height);
87 LCD->interface->readGRAM(tmp,w);
65 //ili9328setGRAMaddress(LCD,Xpos,Ypos);
88 for(int i=0;i<(h*w);i++)
66 LCD->interface->writeGRAM(buffer,Width*Height);
89 {
90 if( ((i%w)==0) ) //read current line to apply text pixmap
91 {
92 if(linenum++>0)
93 {
94 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1);
95 LCD->interface->writeGRAM(tmp,w);
96 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1);
97 LCD->interface->readGRAM(tmp,w);
98 pix=0;
99 }
100 }
101 if((i%16) == 0)
102 {
103 line=font->table[(((*buffer)-32)*h)+tableoffset++];
104 }
105 if((line & 0x0001)==1)tmp[pix]=(uint16_t)color;
106 pix++;
107 line>>=1;
108 }
109 linenum=0;
110 tableoffset=0;
111 charnum++;
112 buffer++;
67 }
113 }
68 }
114 }
69
115
70 int ili9328init(struct LCD_t* LCD)
116 int ili9328init(struct LCD_t* LCD)
71 {
117 {
72 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL))
118 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL))
73 {
119 {
74 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h)
120 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h)
75 LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h)
121 LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h)
76 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h)
122 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h)
77 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302);
123 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0202);
78 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000);
124 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000);
79 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On
125 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On
80 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h)
126 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h)
81 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
127 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
82 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h)
128 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h)
83 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h)
129 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h)
84 _delay_(1000000);
130 _delay_(1000000);
85 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h)
131 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h)
86 _delay_(500000);
132 _delay_(500000);
87 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
133 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
88 _delay_(500000);
134 _delay_(500000);
89 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h)
135 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h)
90 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h)
136 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h)
91 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h)
137 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h)
92 _delay_(500000);
138 _delay_(500000);
93 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1
139 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1
94 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2
140 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2
95 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3
141 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3
96 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4
142 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4
97 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5
143 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5
98 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6
144 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6
99 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7
145 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7
100 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8
146 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8
101 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9
147 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9
102 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10
148 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10
103 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h)
149 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h)
104 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h)
150 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h)
105 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h)
151 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h)
106 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h)
152 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h)
107 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h)
153 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h)
108 LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
154 LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
109 LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h)
155 LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h)
110 // Display On
156 // Display On
111 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h)
157 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h)
112 _delay_(500000);
158 _delay_(500000);
113 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1018);
159 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x0038);
114 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100);
115 //ili9328WriteCmd(ILI9328_REGISTER_WRITEDATATOGRAM);
116 }
160 }
117 return 0;
161 return 0;
118 }
162 }
119
163
120
164
@@ -1,57 +1,57
1 #include "stm32f4xx.h"
1 #include "stm32f4xx.h"
2 #include <stdint.h>
2 #include <stdint.h>
3 #include <stdlib.h>
3 #include <stdlib.h>
4 #include <stdio.h>
4 #include <stdio.h>
5 #include <bsp.h>
5 #include <bsp.h>
6 #include <stm32f4xx_rcc.h>
6 #include <stm32f4xx_rcc.h>
7 #include <core.h>
7 #include <core.h>
8 extern int main();
8 extern int main();
9
9
10
10
11
11
12 void cpu_init()
12 void cpu_init()
13 {
13 {
14 extern uint32_t currentCpuFreq;
14 extern uint32_t currentCpuFreq;
15 currentCpuFreq = 140000000;
15 currentCpuFreq = 160000000;
16 enable_FPU();
16 enable_FPU();
17 RCC->CR |= (uint32_t)0x00000001;
17 RCC->CR |= (uint32_t)0x00000001;
18 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
18 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
19 reset_AHB1();
19 reset_AHB1();
20 reset_AHB2();
20 reset_AHB2();
21 reset_APB1();
21 reset_APB1();
22 reset_APB2();
22 reset_APB2();
23 RCC->CR |= (uint32_t)0x00000001;
23 RCC->CR |= (uint32_t)0x00000001;
24 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
24 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
25 RCC->CFGR = 0x00000000;
25 RCC->CFGR = 0x00000000;
26 RCC->CIR = 0x00000000;
26 RCC->CIR = 0x00000000;
27 SCB->VTOR = FLASH_BASE;
27 SCB->VTOR = FLASH_BASE;
28 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
28 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
29 PWR->CR |= PWR_CR_PMODE;
29 PWR->CR |= PWR_CR_PMODE;
30 currentCpuFreq=setCpuFreq(currentCpuFreq);
30 currentCpuFreq=setCpuFreq(currentCpuFreq);
31 bsp_init();
31 bsp_init();
32 RCC_ClocksTypeDef RCC_ClocksStatus;
32 RCC_ClocksTypeDef RCC_ClocksStatus;
33 RCC_GetClocksFreq(&RCC_ClocksStatus);
33 RCC_GetClocksFreq(&RCC_ClocksStatus);
34 printf("PLL Configured got:\n\r SYS=%uHz\n\r CPU=%uHz\n\r APB1=%uHz\n\r APB2=%uHz\n\r",(unsigned int)RCC_ClocksStatus.SYSCLK_Frequency,(unsigned int)RCC_ClocksStatus.HCLK_Frequency,(unsigned int)RCC_ClocksStatus.PCLK1_Frequency,(unsigned int)RCC_ClocksStatus.PCLK2_Frequency);
34 printf("PLL Configured got:\n\r SYS=%uHz\n\r CPU=%uHz\n\r APB1=%uHz\n\r APB2=%uHz\n\r",(unsigned int)RCC_ClocksStatus.SYSCLK_Frequency,(unsigned int)RCC_ClocksStatus.HCLK_Frequency,(unsigned int)RCC_ClocksStatus.PCLK1_Frequency,(unsigned int)RCC_ClocksStatus.PCLK2_Frequency);
35 printf("Enter Main\n\r");
35 printf("Enter Main\n\r");
36 int res=main();
36 int res=main();
37 printf("\n\rprogram exited with code ");
37 printf("\n\rprogram exited with code ");
38 printf("%u",res);
38 printf("%u",res);
39 printf("\n\r");
39 printf("\n\r");
40 while(1)
40 while(1)
41 {
41 {
42 for(volatile int i=0;i<1024*64;i++);
42 for(volatile int i=0;i<1024*64;i++);
43 gpioset(PD14);
43 gpioset(PD14);
44 for(volatile int i=0;i<1024*64;i++);
44 for(volatile int i=0;i<1024*64;i++);
45 gpioclr(PD14);
45 gpioclr(PD14);
46 }
46 }
47 }
47 }
48
48
49
49
50
50
51
51
52
52
53
53
54
54
55
55
56
56
57
57
General Comments 0
You need to be logged in to leave comments. Login now