##// 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,10 +1,9
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
@@ -1,9 +1,8
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
@@ -1,13 +1,9
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
@@ -1,9 +1,9
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
@@ -6,7 +6,7 SUBDIRS += QtTest/test.pro \
6 6 STM32F4IT \
7 7 M4StickV2 \
8 8 lcdHello \
9 # BeagleSynthHello \
9 BeagleSynthHello
10 10
11 11
12 12
@@ -1,11 +1,12
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
@@ -27,15 +27,18 extern streamdevice* __opnfiles__[];
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
@@ -53,22 +56,19 void randBoxesDemo()
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);
@@ -99,6 +99,49
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)
@@ -139,14 +182,14 void ili9328paint(LCD_t* LCD,void* buffe
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;
@@ -154,10 +197,12 void ili9328paintFilCircMidPoint(LCD_t*
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;
@@ -184,15 +229,15 void ili9328paintFilCircMidPoint(LCD_t*
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 {
@@ -207,10 +252,10 void ili9328paintFilCirc(LCD_t* LCD,uint
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;
@@ -218,18 +263,18 void ili9328paintFilCirc(LCD_t* LCD,uint
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 }
@@ -12,7 +12,10 extern int main();
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;
@@ -4,3 +4,8 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
@@ -25,7 +25,7 CONFIG += cpu
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
@@ -45,7 +45,9 contains( TEMPLATE, app ) {
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 ) {
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now