##// END OF EJS Templates
Finished mid-point circle algorithm for ili9328 controler
jeandet -
r48:1f8d622aedf1 dev_alexis
parent child
Show More
@@ -0,0 +1,121
1 #!/usr/bin/python
2
3 # Written by Antonio Galea - 2010/11/18
4 # Distributed under Gnu LGPL 3.0
5 # see http://www.gnu.org/licenses/lgpl-3.0.txt
6
7 import sys,struct,zlib,os
8 from optparse import OptionParser
9
10 DEFAULT_DEVICE="0x0483:0xdf11"
11
12 def named(tuple,names):
13 return dict(zip(names.split(),tuple))
14 def consume(fmt,data,names):
15 n = struct.calcsize(fmt)
16 return named(struct.unpack(fmt,data[:n]),names),data[n:]
17 def cstring(string):
18 return string.split('\0',1)[0]
19 def compute_crc(data):
20 return 0xFFFFFFFF & -zlib.crc32(data) -1
21
22 def parse(file,dump_images=False):
23 print 'File: "%s"' % file
24 data = open(file,'rb').read()
25 crc = compute_crc(data[:-4])
26 prefix, data = consume('<5sBIB',data,'signature version size targets')
27 print '%(signature)s v%(version)d, image size: %(size)d, targets: %(targets)d' % prefix
28 for t in range(prefix['targets']):
29 tprefix, data = consume('<6sBI255s2I',data,'signature altsetting named name size elements')
30 tprefix['num'] = t
31 if tprefix['named']:
32 tprefix['name'] = cstring(tprefix['name'])
33 else:
34 tprefix['name'] = ''
35 print '%(signature)s %(num)d, alt setting: %(altsetting)s, name: "%(name)s", size: %(size)d, elements: %(elements)d' % tprefix
36 tsize = tprefix['size']
37 target, data = data[:tsize], data[tsize:]
38 for e in range(tprefix['elements']):
39 eprefix, target = consume('<2I',target,'address size')
40 eprefix['num'] = e
41 print ' %(num)d, address: 0x%(address)08x, size: %(size)d' % eprefix
42 esize = eprefix['size']
43 image, target = target[:esize], target[esize:]
44 if dump_images:
45 out = '%s.target%d.image%d.bin' % (file,t,e)
46 open(out,'wb').write(image)
47 print ' DUMPED IMAGE TO "%s"' % out
48 if len(target):
49 print "target %d: PARSE ERROR" % t
50 suffix = named(struct.unpack('<4H3sBI',data[:16]),'device product vendor dfu ufd len crc')
51 print 'usb: %(vendor)04x:%(product)04x, device: 0x%(device)04x, dfu: 0x%(dfu)04x, %(ufd)s, %(len)d, 0x%(crc)08x' % suffix
52 if crc != suffix['crc']:
53 print "CRC ERROR: computed crc32 is 0x%08x" % crc
54 data = data[16:]
55 if data:
56 print "PARSE ERROR"
57
58 def build(file,targets,device=DEFAULT_DEVICE):
59 data = ''
60 for t,target in enumerate(targets):
61 tdata = ''
62 for image in target:
63 tdata += struct.pack('<2I',image['address'],len(image['data']))+image['data']
64 tdata = struct.pack('<6sBI255s2I','Target',0,1,'ST...',len(tdata),len(target)) + tdata
65 data += tdata
66 data = struct.pack('<5sBIB','DfuSe',1,len(data)+11,len(targets)) + data
67 v,d=map(lambda x: int(x,0) & 0xFFFF, device.split(':',1))
68 data += struct.pack('<4H3sB',0,d,v,0x011a,'UFD',16)
69 crc = compute_crc(data)
70 data += struct.pack('<I',crc)
71 open(file,'wb').write(data)
72
73 if __name__=="__main__":
74 usage = """
75 %prog [-d|--dump] infile.dfu
76 %prog {-b|--build} address:file.bin [-b address:file.bin ...] [{-D|--device}=vendor:device] outfile.dfu"""
77 parser = OptionParser(usage=usage)
78 parser.add_option("-b", "--build", action="append", dest="binfiles",
79 help="build a DFU file from given BINFILES", metavar="BINFILES")
80 parser.add_option("-D", "--device", action="store", dest="device",
81 help="build for DEVICE, defaults to %s" % DEFAULT_DEVICE, metavar="DEVICE")
82 parser.add_option("-d", "--dump", action="store_true", dest="dump_images",
83 default=False, help="dump contained images to current directory")
84 (options, args) = parser.parse_args()
85
86 if options.binfiles and len(args)==1:
87 target = []
88 for arg in options.binfiles:
89 try:
90 address,binfile = arg.split(':',1)
91 except ValueError:
92 print "Address:file couple '%s' invalid." % arg
93 sys.exit(1)
94 try:
95 address = int(address,0) & 0xFFFFFFFF
96 except ValueError:
97 print "Address %s invalid." % address
98 sys.exit(1)
99 if not os.path.isfile(binfile):
100 print "Unreadable file '%s'." % binfile
101 sys.exit(1)
102 target.append({ 'address': address, 'data': open(binfile,'rb').read() })
103 outfile = args[0]
104 device = DEFAULT_DEVICE
105 if options.device:
106 device=options.device
107 try:
108 v,d=map(lambda x: int(x,0) & 0xFFFF, device.split(':',1))
109 except:
110 print "Invalid device '%s'." % device
111 sys.exit(1)
112 build(outfile,[target],device)
113 elif len(args)==1:
114 infile = args[0]
115 if not os.path.isfile(infile):
116 print "Unreadable file '%s'." % infile
117 sys.exit(1)
118 parse(infile, dump_images=options.dump_images)
119 else:
120 parser.print_help()
121 sys.exit(1)
@@ -1,12 +1,10
1 1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= qt
2 CONFIG += cpu
3
4 UCMODEL=stm32f4
4 5
5 6 BSP=M4StickV2
6 7
7 include($$(libuc2)/bsp/cfg/$${BSP}/bsp.pri)
8 #include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri)
9
10 8 SOURCES += \
11 9 main.c
12 10
@@ -1,11 +1,10
1 1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= qt
2 CONFIG += cpu
3
4 UCMODEL=stm32f4
4 5
5 6 BSP = SOLAR_LFR_PSU
6 include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri)
7 #include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri)
8 7
9 8 SOURCES += \
10 9 main.c
11 10
@@ -1,11 +1,10
1 1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= qt
2 CONFIG += cpu
4 3
4 UCMODEL=stm32f4
5 5 BSP = STM32F4Discovery
6 include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri)
7 6
8 7 SOURCES += \
9 8 main.c
10 9
11 10
@@ -1,14 +1,10
1 1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= qt
2 CONFIG += cpu
4 3
4
5 UCMODEL=stm32f4
5 6 BSP = BEAGLESYNTH
6 #BSP = SOLAR_LFR_PSU
7 #BSP=M4Stick
8 #BSP=M4StickV2
9 #include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri)
10 #include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri)
11 7
12 8 SOURCES += \
13 9 main.c
14 10
@@ -1,11 +1,11
1 1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= qt
2 CONFIG += cpu
3
4 UCMODEL=stm32f4
4 5
5 6 BSP = STM32F4Discovery
6 include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri)
7 7
8 8 SOURCES += \
9 9 main.c
10 10
11 11
@@ -1,16 +1,16
1 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3 SUBDIRS += QtTest/test.pro \
4 4 SOLAR_PSU_HELLO/hello.pro \
5 5 SDCARD \
6 6 STM32F4IT \
7 7 M4StickV2 \
8 8 lcdHello \
9 # BeagleSynthHello \
9 BeagleSynthHello
10 10
11 11
12 12
13 13
14 14
15 15
16 16
@@ -1,12 +1,13
1 1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= qt
2 CONFIG += cpu
3
4
5 UCMODEL=stm32f4
4 6
5 7 BSP = STM32F4Eval
6 #BSP = SOLAR_LFR_PSU
7 include($$(libuc2)/bsp/cfg/$$BSP/bsp.pri)
8 #include($$(libuc2)/rules/stm32f4-arm-none-eabi-gcc/rules.pri)
8
9 DEFINES += CPUFREQ=160000000
9 10
10 11 SOURCES += \
11 12 main.c
12 13
@@ -1,92 +1,92
1 1 #include <stdio.h>
2 2 #include <fat32.h>
3 3 #include <gpio.h>
4 4 #include <uart.h>
5 5 #include <stm32f4xx.h>
6 6 #include <math.h>
7 7 #include <bsp.h>
8 8 #include <i2c.h>
9 9 #include <CS43L22.h>
10 10 #include <ina226.h>
11 11 #include <fonts.h>
12 12 #include <stdlib.h>
13 13 #include <core.h>
14 14
15 15
16 16 extern streamdevice* __opnfiles__[];
17 17
18 18 #define LCD_COLOR_WHITE 0xFFFF
19 19 #define LCD_COLOR_BLACK 0x0000
20 20 #define LCD_COLOR_GREY 0xF7DE
21 21 #define LCD_COLOR_BLUE 0x001F
22 22 #define LCD_COLOR_BLUE2 0x051F
23 23 #define LCD_COLOR_RED 0xF800
24 24 #define LCD_COLOR_MAGENTA 0xF81F
25 25 #define LCD_COLOR_GREEN 0x07E0
26 26 #define LCD_COLOR_CYAN 0x7FFF
27 27 #define LCD_COLOR_YELLOW 0xFFE0
28 28
29 29
30
31
32
30 33 void monkDemo()
31 34 {
32 while(1)
35 //while(1)
33 36 {
34 37 lcd0.paintText(&lcd0," ",10,Monk_24.Height+10,&Monk_24,LCD_COLOR_BLACK);
35 38 lcd0.paintText(&lcd0," ",230-Monk_24.Width,310,&Monk_24,LCD_COLOR_BLUE);
36 for(volatile int i=0;i<(1024*1024*16);i++);
37 lcd0.paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_WHITE,1,LCD_COLOR_WHITE);
38 for(volatile int i=0;i<(1024*1024*4);i++);
39 //for(volatile int i=0;i<(1024*1024*16);i++);
40 //lcd0.paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_WHITE,1,LCD_COLOR_WHITE);
41 //for(volatile int i=0;i<(1024*1024*4);i++);
39 42 }
40 43 }
41 44
42 45
43 46 void randBoxesDemo()
44 47 {
45 48 int16_t x,y,w,h,t,r;
46 49 x=rand()%240;
47 50 y=rand()%320;
48 51 w=rand()%(240-x);
49 52 if(x>y)
50 53 r=(rand()%(y))%(320-y);
51 54 else
52 55 r=(rand()%(x))%(240-x);
53 56 h=rand()%(320-y);
54 57 t=rand()%(10);
55 58 //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
56 ili9328paintFilCircMidPoint(&lcd0,x,y,r,rand(),t,rand());
59 ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
57 60 }
58 61
59 62 int main()
60 63 {
61 //volatile int16_t* regtest=(volatile int16_t*) 0x80000000;
62 //volatile int16_t* regtest2=(volatile int16_t*)(0x80000001);
63 //*regtest=(int16_t)0;
64 //printf("LCD ID=%x\n\r",0xFFFF&(*regtest2));
65 printf("Sys Tick=%d\n\r",SysTick->VAL);
66 printf("Sys Tick=%d\n\r",SysTick->VAL);
67 printf("Sys Tick=%d\n\r",SysTick->VAL);
68 printf("Sys Tick=%d\n\r",SysTick->VAL);
69 ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_WHITE);
70 // while(1)randBoxesDemo();//monkDemo();
71 ili9328paintFilCircMidPoint(&lcd0,120,160,100,LCD_COLOR_BLUE2,10,LCD_COLOR_GREEN);
64 uint16_t innerbuffer[16];
65 uint16_t outterbuffer[16];
66 for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE;
67 for(int i=0;i<16;i++)outterbuffer[i]=LCD_COLOR_RED;
68 ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_CYAN,5,LCD_COLOR_WHITE);
69 ili9328paintFilCirc(&lcd0,100,150,40,LCD_COLOR_RED,5,LCD_COLOR_BLUE);
70 ili9328paintFilCirc(&lcd0,120,160,120,LCD_COLOR_RED,1,LCD_COLOR_BLUE);
71 //ili9328paintFilCirc(&lcd0,150,240,80,LCD_COLOR_RED,2,LCD_COLOR_BLUE);
72 72 while(1)
73 73 {
74 74 delay_100us(5000);
75 75 gpioset(LED1);
76 76 gpioclr(LED2);
77 77 delay_100us(5000);
78 78 gpioclr(LED1);
79 79 gpioset(LED2);
80 80 }
81 81 printf("hello world\n\r");
82 82 return 0;
83 83 }
84 84
85 85
86 86
87 87
88 88
89 89
90 90
91 91
92 92
@@ -1,375 +1,420
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #include <ili9328.h>
23 23 #include <stdio.h>
24 24 #include <stddef.h>
25 25 #include <core.h>
26 26 #include <math.h>
27 27
28 28 #ifdef __OPTIMIZED_MATH
29 29 #include <optimised_math.h>
30 30 #endif
31 31
32 32 #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++);
33 33
34 34 #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \
35 35 for(int l=0;l<1;l++)\
36 36 {\
37 37 ili9328setFrame(LCD,X,Y,W,1);\
38 38 int rem=(W)%buffsize;\
39 39 if(rem)LCD->interface->writeGRAM(buffer,rem);\
40 40 for(int i=rem;i<(W);i+=buffsize)\
41 41 {\
42 42 LCD->interface->writeGRAM(buffer,buffsize);\
43 43 }\
44 44 }
45 45
46 46 #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
47 47 for(int l=0;l<1;l++)\
48 48 {\
49 49 ili9328setFrame(LCD,X,Y,W,1);\
50 50 int rem=(ContSz)%buffContsize;\
51 51 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
52 52 for(int i=rem;i<(ContSz);i+=buffContsize)\
53 53 {\
54 54 LCD->interface->writeGRAM(bufferCont,buffContsize);\
55 55 }\
56 56 if((2*ContSz)<W) \
57 57 {\
58 58 rem=(W-(2*ContSz))%buffIntsize;\
59 59 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
60 60 for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\
61 61 {\
62 62 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
63 63 }\
64 64 }\
65 65 rem=(ContSz)%buffContsize;\
66 66 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
67 67 for(int i=rem;i<(ContSz);i+=buffContsize)\
68 68 {\
69 69 LCD->interface->writeGRAM(bufferCont,buffContsize);\
70 70 }\
71 71 }\
72 72
73 73
74 74 #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
75 75 for(int l=0;l<1;l++)\
76 76 {\
77 77 ili9328setFrame(LCD,X,Y,1,H);\
78 78 int rem=(ContSz)%buffContsize;\
79 79 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
80 80 for(int i=rem;i<(ContSz);i+=buffContsize)\
81 81 {\
82 82 LCD->interface->writeGRAM(bufferCont,buffContsize);\
83 83 }\
84 84 if((2*ContSz)<H) \
85 85 {\
86 86 rem=(H-(2*ContSz))%buffIntsize;\
87 87 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
88 88 for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\
89 89 {\
90 90 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
91 91 }\
92 92 }\
93 93 rem=(ContSz)%buffContsize;\
94 94 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
95 95 for(int i=rem;i<(ContSz);i+=buffContsize)\
96 96 {\
97 97 LCD->interface->writeGRAM(bufferCont,buffContsize);\
98 98 }\
99 99 }\
100 100
101 101
102 #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
103 for(int l=0;l<1;l++)\
104 {\
105 ili9328setFrame(LCD,X,Y,1,H);\
106 int rem=(ContSz)%buffContsize;\
107 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
108 for(int i=rem;i<(ContSz);i+=buffContsize)\
109 {\
110 LCD->interface->writeGRAM(bufferCont,buffContsize);\
111 }\
112 if(ContSz<H) \
113 {\
114 rem=(H-ContSz)%buffIntsize;\
115 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
116 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
117 {\
118 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
119 }\
120 }\
121 }\
122
123
124 #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
125 for(int l=0;l<1;l++)\
126 {\
127 ili9328setFrame(LCD,X,Y,1,H);\
128 int rem;\
129 if(ContSz<H) \
130 {\
131 rem=(H-ContSz)%buffIntsize;\
132 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
133 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
134 {\
135 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
136 }\
137 }\
138 rem=(ContSz)%buffContsize;\
139 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
140 for(int i=rem;i<(ContSz);i+=buffContsize)\
141 {\
142 LCD->interface->writeGRAM(bufferCont,buffContsize);\
143 }\
144 }\
102 145
103 146
104 147 void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress)
105 148 {
106 149 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress);
107 150 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress);
108 151 }
109 152
110 153 void ili9328refreshenable(struct LCD_t* LCD,int enable)
111 154 {
112 155 if(enable)
113 156 {
114 157 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018);
115 158 }
116 159 else
117 160 {
118 161 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008);
119 162
120 163 }
121 164 }
122 165
123 166 void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H)
124 167 {
125 168 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X);
126 169 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y);
127 170 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X);
128 171 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1));
129 172 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y);
130 173 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1));
131 174 }
132 175
133 176 void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height)
134 177 {
135 178 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height)))
136 179 {
137 180 ili9328setFrame(LCD,Xpos,Ypos,Width,Height);
138 181 LCD->interface->writeGRAM(buffer,Width*Height);
139 182 }
140 183 }
141 184
142 void ili9328paintFilCircMidPoint(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
185 void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
143 186 {
144 187 //Based on the mid point circle algorithm from Wikipedia
145 188 //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
146 uint16_t tmp1[16];
147 uint16_t tmp2[16];
148 for(int i=0;i<16;i++)tmp1[i]=fillColor;
149 for(int i=0;i<16;i++)tmp2[i]=contColor;
189 uint16_t innerbuffer[16];
190 uint16_t outterbuffer[16];
191 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
192 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
150 193 if(contSz<r)
151 194 {
152 195 int error = -r,error_int = -r+contSz;
153 196 int x = r,x_int=r-contSz;
154 197 int y = 0,y_int=0;
155 198 while (x >= y)
156 199 {
157 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),tmp1,16,tmp2,16);
158 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),tmp2,16,tmp1,16);
159 ilipaintVLineWithCont(LCD,(Xpos+y),(Ypos-x),(2*y),(x-x_int),tmp1,16,tmp2,16);
160 //ilipaintVSymLineWithCont(LCD,(Xpos-y),(Ypos+x),(2*y),(x-x_int),tmp2,16,tmp1,16);
200 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16);
201 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16);
202 ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
203 ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
204 ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
205 ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
161 206 error += y;
162 207 ++y;
163 208 error += y;
164 209 error_int += y_int;
165 210 ++y_int;
166 211 error_int += y_int;
167 212 if(error >= 0)
168 213 {
169 214 error -= x;
170 215 --x;
171 216 error -= x;
172 217 }
173 218 if(error_int >= 0)
174 219 {
175 220 error_int -= x_int;
176 221 --x_int;
177 222 error_int -= x_int;
178 223 }
179 224 }
180 225
181 226
182 227
183 228 }
184 229
185 230 }
186 231
187 void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
232 void ili9328paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
188 233 {
189 234 if(contSz<r)
190 235 {
191 uint16_t tmp1[16];
192 uint16_t tmp2[16];
236 uint16_t innerbuffer[16];
237 uint16_t outterbuffer[16];
193 238 int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem;
194 for(int i=0;i<16;i++)tmp1[i]=fillColor;
195 for(int i=0;i<16;i++)tmp2[i]=contColor;
239 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
240 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
196 241 /* Y = b +/- sqrt[r^2 - (x - a)^2] */
197 242 for(int32_t line=-r;line<r;line++)
198 243 {
199 244 #ifdef __OPTIMIZED_MATH
200 245 Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) );
201 246 Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) );
202 247 #else
203 248 Val1 = sqrt( (double)(rr - ((line)*(line))) );
204 249 Val2 = sqrt( (double)(rr2 - ((line)*(line))) );
205 250 #endif
206 251 X1=Xpos - Val1;
207 252 contSz2= Val1-Val2;
208 253 ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1);
209 254 rem=(contSz2)%16;
210 if(rem)LCD->interface->writeGRAM(tmp2,rem);
255 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
211 256 for(int i=rem;i<(contSz2);i+=16)
212 257 {
213 LCD->interface->writeGRAM(tmp2,16);
258 LCD->interface->writeGRAM(outterbuffer,16);
214 259 }
215 260
216 261 W=2*Val1;
217 262 if(W>(2*contSz2))
218 263 {
219 264 W-=2*contSz2;
220 265 rem=(W)%16;
221 if(rem)LCD->interface->writeGRAM(tmp1,rem);
266 if(rem)LCD->interface->writeGRAM(innerbuffer,rem);
222 267 for(int i=rem;i<(W);i+=16)
223 268 {
224 LCD->interface->writeGRAM(tmp1,16);
269 LCD->interface->writeGRAM(innerbuffer,16);
225 270 }
226 271 }
227 272
228 273 rem=(contSz2)%16;
229 if(rem)LCD->interface->writeGRAM(tmp2,rem);
274 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
230 275 for(int i=rem;i<(contSz2);i+=16)
231 276 {
232 LCD->interface->writeGRAM(tmp2,16);
277 LCD->interface->writeGRAM(outterbuffer,16);
233 278 }
234 279 }
235 280 }
236 281 }
237 282
238 283
239 284
240 285
241 286 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)
242 287 {
243 288 ili9328setFrame(LCD,Xpos,Ypos,w,h);
244 289 uint16_t tmp[32];
245 290 for(int i=0;i<32;i++)tmp[i]=fillColor;
246 291 for(int i=0;i<(h*w);i+=32)
247 292 {
248 293 LCD->interface->writeGRAM(tmp,32);
249 294 }
250 295 int rem=(w*h)%32;
251 296 if(rem)LCD->interface->writeGRAM(tmp,rem);
252 297 if(contSz)
253 298 {
254 299 ili9328setFrame(LCD,Xpos,Ypos,w,contSz);
255 300 for(int i=0;i<32;i++)tmp[i]=contColor;
256 301 rem=(w*contSz)%32;
257 302 if(rem)LCD->interface->writeGRAM(tmp,rem);
258 303 for(int i=rem;i<(w*contSz);i+=32)
259 304 {
260 305 LCD->interface->writeGRAM(tmp,32);
261 306 }
262 307
263 308 ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz);
264 309 rem=(w*contSz)%32;
265 310 if(rem)LCD->interface->writeGRAM(tmp,rem);
266 311 for(int i=rem;i<(w*contSz);i+=32)
267 312 {
268 313 LCD->interface->writeGRAM(tmp,32);
269 314 }
270 315
271 316 ili9328setFrame(LCD,Xpos,Ypos,contSz,h);
272 317 rem=(h*contSz)%32;
273 318 if(rem)LCD->interface->writeGRAM(tmp,rem);
274 319 for(int i=rem;i<(h*contSz);i+=32)
275 320 {
276 321 LCD->interface->writeGRAM(tmp,32);
277 322 }
278 323
279 324 ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h);
280 325 rem=(h*contSz)%32;
281 326 if(rem)LCD->interface->writeGRAM(tmp,rem);
282 327 for(int i=rem;i<(h*contSz);i+=32)
283 328 {
284 329 LCD->interface->writeGRAM(tmp,32);
285 330 }
286 331 }
287 332 }
288 333
289 334 void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color)
290 335 {
291 336 int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0;
292 337 uint16_t tmp[w];
293 338 uint16_t linenum=0,charnum=0;
294 339 uint8_t line=0;
295 340 while(*buffer)
296 341 {
297 342 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1);
298 343 LCD->interface->readGRAM(tmp,w);
299 344 for(int i=0;i<(h*w);i++)
300 345 {
301 346 if( ((i%w)==0) ) //read current line to apply text pixmap
302 347 {
303 348 if(linenum++>0)
304 349 {
305 350 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1);
306 351 LCD->interface->writeGRAM(tmp,w);
307 352 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1);
308 353 LCD->interface->readGRAM(tmp,w);
309 354 pix=0;
310 355 }
311 356 }
312 357 if((pix%8) == 0)
313 358 {
314 359 line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++];
315 360 }
316 361 if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color;
317 362 pix++;
318 363 line>>=1;
319 364 }
320 365 linenum=0;
321 366 tableoffset=0;
322 367 charnum++;
323 368 buffer++;
324 369 }
325 370 }
326 371
327 372 int ili9328init(struct LCD_t* LCD)
328 373 {
329 374 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL))
330 375 {
331 376 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h)
332 377 LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h)
333 378 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h)
334 379 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0202);
335 380 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000);
336 381 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On
337 382 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h)
338 383 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
339 384 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h)
340 385 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h)
341 386 delay_100us(10);
342 387 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h)
343 388 delay_100us(10);
344 389 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
345 390 delay_100us(10);
346 391 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h)
347 392 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h)
348 393 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h)
349 394 delay_100us(500);
350 395 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1
351 396 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2
352 397 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3
353 398 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4
354 399 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5
355 400 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6
356 401 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7
357 402 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8
358 403 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9
359 404 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10
360 405 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h)
361 406 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h)
362 407 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h)
363 408 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h)
364 409 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h)
365 410 LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
366 411 LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h)
367 412 // Display On
368 413 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h)
369 414 delay_100us(500);
370 415 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x0038);
371 416 }
372 417 return 0;
373 418 }
374 419
375 420
@@ -1,60 +1,63
1 1 #include "stm32f4xx.h"
2 2 #include <stdint.h>
3 3 #include <stdlib.h>
4 4 #include <stdio.h>
5 5 #include <bsp.h>
6 6 #include <stm32f4xx_rcc.h>
7 7 #include <core.h>
8 8 extern int main();
9 9
10 10
11 11
12 12 void cpu_init()
13 13 {
14 14 extern uint32_t currentCpuFreq;
15 currentCpuFreq = 16*1000*1000;
15 #ifndef CPUFREQ
16 #define CPUFREQ (16*1000*1000)
17 #endif
18 currentCpuFreq = CPUFREQ;
16 19 enable_FPU();
17 20 RCC->CR |= (uint32_t)0x00000001;
18 21 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
19 22 reset_AHB1();
20 23 reset_AHB2();
21 24 reset_APB1();
22 25 reset_APB2();
23 26 RCC->CR |= (uint32_t)0x00000001;
24 27 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
25 28 RCC->CFGR = 0x00000000;
26 29 RCC->CIR = 0x00000000;
27 30 SCB->VTOR = FLASH_BASE;
28 31 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
29 32 PWR->CR |= PWR_CR_PMODE;
30 33 currentCpuFreq=setCpuFreq(currentCpuFreq);
31 34 currentCpuFreq=getCpuFreq();
32 35 configureSysTick();
33 36 bsp_init();
34 37 printf("SysTick Configured to reach 100us period\n\r");
35 38 RCC_ClocksTypeDef RCC_ClocksStatus;
36 39 RCC_GetClocksFreq(&RCC_ClocksStatus);
37 40 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);
38 41 printf("Enter Main\n\r");
39 42 int res=main();
40 43 printf("\n\rprogram exited with code ");
41 44 printf("%u",res);
42 45 printf("\n\r");
43 46 while(1)
44 47 {
45 48 delay_100us(10000);
46 49 gpioset(LED1);
47 50 delay_100us(10000);
48 51 gpioclr(LED1);
49 52 }
50 53 }
51 54
52 55
53 56
54 57
55 58
56 59
57 60
58 61
59 62
60 63
@@ -1,6 +1,11
1 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3 SUBDIRS += lib \
4 4 bsp\
5 5 examples
6 6
7 binfiles.files = bin/dfu.py
8 binfiles.path = $$[QT_INSTALL_BINS]
9
10 INSTALLS+=binfiles
11
@@ -1,73 +1,75
1 1 #
2 2 # qmake configuration for stm32f4
3 3 #
4 4 #
5 5
6 6
7 7 isEmpty(_stm32f4_conf){
8 8 _stm32f4_conf="oneshot"
9 9
10 10 QMAKE_CFLAGS=-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99
11 11
12 12 include(../common/arm-none-eabi.conf)
13 13
14 14 DEFINES += __OPTIMIZED_MATH
15 15 DEFINES += \"assert_param(expr)=((void)0)\"
16 16 INCLUDEPATH += $$PWD
17 17
18 18 DEFINES += __FPU_PRESENT=1
19 19 DEFINES += ARM_MATH_CM4
20 20
21 21 DEFINES += BSP="\"\\\"$$BSP"\\\"\"
22 22
23 23 CONFIG += cpu
24 24
25 25 contains( TEMPLATE, app ) {
26 26 OBJECTS_DIR=obj
27 27 DESTDIR=bin
28 unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin"
28 unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin && python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:"$$DESTDIR/"$(QMAKE_TARGET).bin " $$DESTDIR/"$(QMAKE_TARGET).dfu"
29 29 win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin"
30 30
31 31 LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP
32 32 LIBS += -lbsp
33 33
34 34
35 35 QMAKE_LFLAGS= -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -T $$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/stm32_flash.ld
36 36
37 37 INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP
38 38
39 39 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c
40 40 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c
41 41 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/startup.s
42 42 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c
43 43
44 44 # OTHER_FILES += $$[QT_INSTALL_PREFIX]/ucfiles/stm32f4/$$CPU/stm32_flash.ld
45 45
46 46 stflash.target = stflash
47 47 stflash.commands = cd $$DESTDIR && sudo st-flash write $(QMAKE_TARGET).bin 0x08000000
48 QMAKE_EXTRA_TARGETS += stflash
48 dfu-util.target = dfu-util
49 dfu-util.commands = cd $$DESTDIR && sudo dfu-util -i 0 -a 0 -d 0483:df11 -D $(QMAKE_TARGET).dfu
50 QMAKE_EXTRA_TARGETS += stflash dfu-util
49 51 }
50 52
51 53 contains( TEMPLATE, lib ) {
52 54 CONFIG+=staticlib
53 55 message( "You can only build static library for stm32f4" )
54 56 }
55 57
56 58 include(../common/libuc2libs.conf)
57 59
58 60 }
59 61
60 62
61 63
62 64
63 65
64 66
65 67
66 68
67 69
68 70
69 71
70 72
71 73
72 74
73 75
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now