##// END OF EJS Templates
Added Simulator target to run code on x86 and debug functions....
jeandet -
r63:68dfbccdd813 dev_alexis
parent child
Show More
@@ -0,0 +1,19
1 TEMPLATE = lib
2
3 TARGET=bsp
4
5
6
7 BSP = SIMULATOR
8
9 UCMODEL=simulator
10
11 SOURCES += bsp.c
12
13 HEADERS += bsp.h
14
15
16 BSPFILE = bsp.pri
17
18
19
@@ -0,0 +1,282
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #include "bsp.h"
23 #include <streamdevices.h>
24 #include <malloc.h>
25 #include <stdio.h>
26
27
28 uint32_t OSC0 =8000000;
29 uint32_t INTOSC =16000000;
30 uint32_t RTCOSC =32768;
31 uint32_t currentCpuFreq=0;
32 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
33
34
35 LCD_IF_t lcdIF0={
36 .init = &SDLCD_init,
37 .writereg = &SDLCD_writereg,
38 .readreg = &SDLCD_readreg,
39 .writeGRAM = &SDLCD_writeGRAM,
40 .readGRAM = &SDLCD_readGRAM
41 };
42
43 LCD_t lcd0={
44 .interface = &lcdIF0,
45 .init = &ili9328init,
46 .paint = &ili9328paint,
47 .paintText = &ili9328paintText,
48 .paintFilRect = &ili9328paintFilRect,
49 .refreshenable = &ili9328refreshenable,
50 .width= 240,
51 .height = 320
52 };
53
54 terminal_t terminal0;
55
56 volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000;
57 volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0);
58
59 float VREF0 =(float)3.3;
60 volatile vs10XXDev audioCodec0;
61
62 sdcardDev sdcard2;
63 blkdevice sdcard2blkdev;
64 dikpartition sdcard2Part1;
65 FAT32fs sdcard2FAT32part1;
66 dikpartition sdcard2Part2;
67 FAT32fs sdcard2FAT32part2;
68 dikpartition sdcard2Part3;
69 FAT32fs sdcard2FAT32part3;
70 dikpartition sdcard2Part4;
71 FAT32fs sdcard2FAT32part4;
72
73 int bsp_init()
74 {
75 int i=0;
76 for(i=0;i<__MAX_OPENED_FILES__;i++)
77 {
78 __opnfiles__[i] = NULL;
79 }
80 bsp_GPIO_init();
81 bsp_uart_init();
82 bsp_iic_init();
83 bsp_FSMC_init();
84 bsp_GTerm_init();
85 bsp_spi_init();
86 bsp_SD_init();
87 bsp_Audio_init();
88 printf("\r=====================\n\r");
89 printf( "=====================\n\r");
90 printf(BSP);
91 printf(" initialised\n\r");
92 printf( "=====================\n\r");
93 return 1;
94 }
95
96 void bsp_GPIO_init()
97 {
98
99 }
100
101 void bsp_uart_init()
102 {
103
104 }
105
106 /*
107 D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7
108 D5 PE8 D6 PE9 D7 PE10
109 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S
110 FSMC_NOE PD4 RD
111 */
112
113 int bsp_FSMC_init()
114 {
115
116 return 1;
117 }
118
119 void bsp_spi_init()
120 {
121
122 }
123
124
125 void bsp_iic_init()
126 {
127
128 }
129
130
131 void bsp_Audio_init()
132 {
133
134 }
135
136 void bsp_SD_init()
137 {
138
139 }
140
141 void vs1052setXCS(char val)
142 {
143 }
144
145 void vs1052setXDCS(char val)
146 {
147 }
148
149 void vs1052setRST(char val)
150 {
151 }
152
153 int vs10XXDREQ()
154 {
155 return 1;
156 }
157
158
159 void bsppowersdcard(char onoff) //always ON
160 {
161
162 }
163
164 char bspsdcardpresent()
165 {
166 return 1;
167 }
168
169 char bspsdcardwriteprotected()
170 {
171 return 0;
172 }
173
174 void bspsdcardselect(char YESNO)
175 {
176
177 }
178
179
180 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
181 {
182
183 }
184
185 uint32_t bsp_lcd0_read_reg(uint32_t reg)
186 {
187 return 0;
188 }
189
190 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
191 {
192
193 }
194
195 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
196 {
197
198 }
199
200 void bsp_GTerm_init()
201 {
202 SDLCD_mkscreen(240,320,16,LCDILI9328);
203
204 if(__opnfiles__[1]==NULL)
205 {
206 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
207 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1);
208 __opnfiles__[1] = fd1;
209 }
210 else
211 {
212
213 }
214 }
215
216
217
218
219
220
221
222 void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
223 {
224 int bpp = surface->format->BytesPerPixel;
225 /* Here p is the address to the pixel we want to set */
226 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
227 switch(bpp) {
228 case 1:
229 *p = pixel;
230 break;
231 case 2:
232 *(Uint16 *)p = pixel;
233 break;
234 case 3:
235 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
236 p[0] = (pixel >> 16) & 0xff;
237 p[1] = (pixel >> 8) & 0xff;
238 p[2] = pixel & 0xff;
239 } else {
240 p[0] = pixel & 0xff;
241 p[1] = (pixel >> 8) & 0xff;
242 p[2] = (pixel >> 16) & 0xff;
243 }
244 break;
245 case 4:
246 *(Uint32 *)p = pixel;
247 break;
248 }
249 }
250
251 Uint32 getpixel(SDL_Surface *surface, int x, int y)
252 {
253 int bpp = surface->format->BytesPerPixel;
254 /* Here p is the address to the pixel we want to retrieve */
255 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
256 switch(bpp) {
257 case 1:
258 return *p;
259 case 2:
260 return *(Uint16 *)p;
261 case 3:
262 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
263 return p[0] << 16 | p[1] << 8 | p[2];
264 else
265 return p[0] | p[1] << 8 | p[2] << 16;
266 case 4:
267 return *(Uint32 *)p;
268 default:
269 return 0;
270 }
271 /* shouldn’t happen, but avoids warnings */
272 }
273
274
275
276
277
278
279
280
281
282
@@ -0,0 +1,139
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #ifndef BSP_H
23 #define BSP_H
24 #include <gpio.h>
25 #include <spi.h>
26 #include <ili9328.h>
27 #include <genericLCD_Controler.h>
28 #include <sdcard-spi.h>
29 #include <terminal.h>
30 #include <sdcard.h>
31 #include <mbr.h>
32 #include <VS10XX.h>
33 #include <fat32.h>
34 #include <SDL.h>
35 #include <stdint.h>
36 #include <SDLCD.h>
37
38
39 #define __MAX_OPENED_FILES__ 4
40 #define __FS_ROOT_SIZE__ 4
41
42
43 #define LED1 PC15
44 #define LED2 PC14
45
46 #define BP3 PA0
47
48 #define LCD_RESET PD10
49 #define LCD_BACKL PE11
50
51 #define VS1053SPI spi1
52 #define VS1053xCS PA3
53 #define VS1053xRESET PA2
54 #define VS1053xDCS PA4
55 #define VS1053DREQ PA1
56 #define VS1053MISO PA6
57 #define VS1053MOSI PA7
58 #define VS1053SCK PA5
59
60
61
62 #define SDCARD2SPI spi3
63 #define SDCARD2CS PB8
64 #define SDCARD2CD PB9
65 #define SDCARD2MISO PB4
66 #define SDCARD2MOSI PB5
67 #define SDCARD2SCK PB3
68
69 extern float VREF0;
70
71 extern uint32_t currentCpuFreq;
72 extern LCD_t lcd0;
73
74 extern volatile vs10XXDev audioCodec0;
75
76 extern sdcardDev sdcard2;
77 extern blkdevice sdcard2blkdev;
78 extern dikpartition sdcard2Part1;
79 extern FAT32fs sdcard2FAT32part1;
80 extern dikpartition sdcard2Part2;
81 extern FAT32fs sdcard2FAT32part2;
82 extern dikpartition sdcard2Part3;
83 extern FAT32fs sdcard2FAT32part3;
84 extern dikpartition sdcard2Part4;
85 extern FAT32fs sdcard2FAT32part4;
86
87 extern int bsp_init();
88
89 extern void bsp_GPIO_init();
90 extern void bsp_uart_init();
91 extern void bsp_iic_init();
92 extern void bsp_spi_init();
93 extern void bsp_SD_init();
94 extern void bsp_Audio_init();
95 extern void bsp_GTerm_init();
96 extern int bsp_FSMC_init();
97
98 /* VS1053 */
99 extern void vs1052setXCS(char val);
100 extern void vs1052setXDCS(char val);
101 extern void vs1052setRST(char val);
102 extern int vs10XXDREQ();
103
104 /* SD CARD */
105 void bsppowersdcard(char onoff);
106 char bspsdcardpresent();
107 void bspsdcardselect(char YESNO);
108 char bspsdcardwriteprotected();
109
110
111 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data);
112 uint32_t bsp_lcd0_read_reg(uint32_t reg);
113 void bsp_lcd0_writeGRAM(void *buffer, uint32_t count);
114 void bsp_lcd0_readGRAM(void *buffer, uint32_t count);
115
116
117 extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
118 extern Uint32 getpixel(SDL_Surface *surface, int x, int y);
119
120 #endif
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
@@ -0,0 +1,6
1 CPU=simultor
2 DEFINES+=BSP=\\\"SIMULATOR\\\"
3
4 UCMODEL=simulator
5
6 LIBS+=-lSDLCD
@@ -0,0 +1,23
1 #include <stdio.h>
2 #include <fat32.h>
3 #include <gpio.h>
4 #include <uart.h>
5 #include <stm32f4xx.h>
6 #include <bsp.h>
7 #include <core.h>
8 #include <VS10XX.h>
9 #include <bsp.h>
10 #include <spi.h>
11 #include <sdcard.h>
12 #include <sdcard-spi.h>
13 #include <fat32.h>
14 #include <ucdirent.h>
15 #include <string.h>
16 #include <terminal.h>
17 #include <ili9328.h>
18
19
20 void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color)
21 {
22 LCD->paintFilRect(LCD,x,y,w,h,0,0,color);
23 }
@@ -0,0 +1,13
1 TEMPLATE = app
2 CONFIG += cpu
3
4
5 UCMODEL=simulator
6 BSP = SIMULATOR
7
8 DEFINES += CPUFREQ=100000000
9
10 SOURCES += \
11 main.c \
12 test_lcd.c
13
@@ -0,0 +1,55
1 #include <stdio.h>
2 #include <fat32.h>
3 #include <gpio.h>
4 #include <uart.h>
5 #include <bsp.h>
6 #include <core.h>
7 #include <bsp.h>
8 #include <spi.h>
9 #include <fat32.h>
10 #include <ucdirent.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <terminal.h>
14 #include <stdarg.h>
15 #include <malloc.h>
16
17 extern streamdevice* __opnfiles__[];
18 extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color);
19 char buffer[512];
20
21 void streamdevicePrint(streamdevice* dev, const char* format,...)
22 {
23 char** str_buffer;
24 int i;
25 va_list ap;
26 va_start(ap,format);
27 vasprintf(str_buffer,format,ap);
28 va_end(ap);
29 i=strlen(*str_buffer);
30 dev->ops->write(dev,(void*)*str_buffer,1,i);
31 free(*str_buffer);
32 }
33
34 void lcd_print()
35 {
36 lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F);
37 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5);
38 }
39
40 int libuc2_main_task()
41 {
42 char in[255];
43 lcd_print();
44 printf("hello world\n");
45 streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n ",1234567,8.96);
46 // while (scanf("%c",in))
47 // {
48 sleep(3);
49 // }
50 }
51
52
53
54
55
@@ -0,0 +1,21
1 #include <stdio.h>
2 #include <fat32.h>
3 #include <gpio.h>
4 #include <uart.h>
5 #include <bsp.h>
6 #include <core.h>
7 #include <VS10XX.h>
8 #include <bsp.h>
9 #include <spi.h>
10 #include <sdcard.h>
11 #include <sdcard-spi.h>
12 #include <fat32.h>
13 #include <ucdirent.h>
14 #include <string.h>
15 #include <ili9328.h>
16
17
18 void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color)
19 {
20 // LCD->paintFilRect(LCD,x,y,w,h,0,0,color);
21 }
@@ -0,0 +1,15
1 TEMPLATE = lib
2 TARGET = CS43L22
3
4 SOURCES += CS43L22.c
5
6 INCLUDEPATH += ../../../includes \
7 ../../CPU/CMSIS/Include
8
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
15
@@ -0,0 +1,14
1 TEMPLATE = lib
2 TARGET = vs10XX
3
4 SOURCES += VS10XX.c
5
6
7 HEADERS += ../../../includes/VS10XX.h
8 INCLUDEPATH += ../../../includes
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
@@ -0,0 +1,14
1 TEMPLATE = lib
2 TARGET = vs10XX
3
4 SOURCES += VS10XX.c
5
6
7 HEADERS += ../../../includes/VS10XX.h
8 INCLUDEPATH += ../../../includes
9
10 UCMODEL=stm32f4
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
@@ -0,0 +1,14
1 TEMPLATE = lib
2
3 SOURCES += 24LC0X.c
4 HEADERS += ../../../includes/24LC0X.h \
5 ../../../../includes/24LC0X.h
6
7 INCLUDEPATH += ../../../includes \
8 ../../CPU/CMSIS/Include
9
10
11 UCMODEL=simulator
12
13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
14 INSTALLS += target
@@ -0,0 +1,15
1 TEMPLATE = lib
2
3 SOURCES += 24LC0X.c
4 HEADERS += ../../../includes/24LC0X.h \
5 ../../../../includes/24LC0X.h
6
7 INCLUDEPATH += ../../../includes \
8 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 ../../CPU/CMSIS/Include
10
11
12 UCMODEL=stm32f4
13
14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 INSTALLS += target
@@ -0,0 +1,13
1 TEMPLATE = lib
2
3 SOURCES += N25Q128.c
4 HEADERS += ../../../includes/N25Q128.h
5
6 INCLUDEPATH += ../../../includes \
7 ../../CPU/CMSIS/Include
8
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
@@ -0,0 +1,13
1 TEMPLATE = lib
2
3 SOURCES += N25Q128.c
4 HEADERS += ../../../includes/N25Q128.h
5
6 INCLUDEPATH += ../../../includes \
7 ../../CPU/CMSIS/Include
8
9
10 UCMODEL=stm32f4
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
@@ -0,0 +1,15
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = ucdirent
4
5 SOURCES += \
6 ucdirent.c
7
8 INCLUDEPATH += ../../includes
9
10
11 UCMODEL=simulator
12
13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
14 INSTALLS += target
15
@@ -0,0 +1,17
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = fat32
4
5 SOURCES += \
6 fat32.c
7
8 INCLUDEPATH += ../../../includes
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
15 HEADERS += \
16 ../../../includes/fat32.h
17
@@ -0,0 +1,17
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = mbr
4
5 SOURCES += \
6 mbr.c
7
8 INCLUDEPATH += ../../../includes
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
15 HEADERS += \
16 ../../../includes/mbr.h
17
@@ -0,0 +1,18
1 TEMPLATE = lib
2 TARGET = ili9328
3
4 SOURCES += \
5 ili9328.c
6
7
8 INCLUDEPATH += ../../../../includes \
9 ../../../../includes/GRAPHIC/CONTROLERS \
10 ../../../../includes/GRAPHIC/GUI/FONTS \
11 ../../../../includes/GRAPHIC/GUI/Widgets
12
13
14 UCMODEL=simulator
15
16 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
17 INSTALLS += target
18
@@ -0,0 +1,18
1 TEMPLATE = lib
2 TARGET = ssd2119
3
4 SOURCES += \
5 ssd2119.c
6
7
8 INCLUDEPATH += ../../../../includes \
9 ../../../../includes/GRAPHIC/CONTROLERS \
10 ../../../../includes/GRAPHIC/GUI/FONTS \
11 ../../../../includes/GRAPHIC/GUI/Widgets
12
13
14 UCMODEL=simulator
15
16 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
17 INSTALLS += target
18
@@ -0,0 +1,18
1 TEMPLATE = lib
2 TARGET = fonts
3
4 SOURCES += \
5 fonts8pts.c
6
7
8 INCLUDEPATH += ../../../../includes \
9 ../../../../includes/GRAPHIC/CONTROLERS \
10 ../../../../includes/GRAPHIC/GUI/FONTS \
11 ../../../../includes/GRAPHIC/GUI/Widgets
12
13
14 UCMODEL=simulator
15
16 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
17 INSTALLS += target
18
@@ -0,0 +1,20
1 TEMPLATE = lib
2 TARGET = terminal
3
4 SOURCES += \
5 Terminal.c
6
7
8 INCLUDEPATH += ../../../../includes \
9 ../../../../includes/GRAPHIC/CONTROLERS \
10 ../../../../includes/GRAPHIC/GUI/FONTS \
11 ../../../../includes/GRAPHIC/GUI/Widgets
12
13 HEADERS += \
14 ../../../../../includes/GRAPHIC/GUI/Widgets/terminal.h
15
16 UCMODEL=simulator
17
18 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
19 INSTALLS += target
20
@@ -0,0 +1,23
1 TEMPLATE = lib
2 TARGET = STMPE811
3
4 SOURCES += \
5 STMPE811.c
6
7 INCLUDEPATH += ../../../../includes \
8 ../../../../includes/GRAPHIC/CONTROLERS \
9 ../../../../includes/GRAPHIC/TC_CONTROLERS \
10 ../../../../includes/GRAPHIC/GUI/FONTS \
11 ../../../../includes/GRAPHIC/GUI/Widgets
12
13
14 UCMODEL=simulator
15
16 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
17 INSTALLS += target
18
19 HEADERS += \
20 ../../../../includes/GRAPHIC/TC_CONTROLERS/STMPE811.h \
21 ../../../../includes/GRAPHIC/TC_CONTROLERS/genericTC_Controler.h
22
23
@@ -0,0 +1,14
1 TEMPLATE = lib
2 TARGET = ina226
3
4 SOURCES += ina226.c
5
6 INCLUDEPATH += ../../../includes \
7 ../../CPU/CMSIS/Include
8
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
@@ -0,0 +1,126
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #include <core.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <gpio.h>
27 #include <unistd.h>
28
29 extern uint32_t OSC0;
30 extern uint32_t INTOSC;
31 extern uint32_t RTCOSC;
32
33 volatile uint32_t tickCounter=0;
34
35
36 void SysTick_Handler(void)
37 {
38 tickCounter+=1;
39 // if((tickCounter&0xFFF)==0x800)
40 // gpiosetval(PC15,!gpiogetval(PC15));
41 }
42
43 void delay_us(uint32_t value)
44 {
45 usleep(value);
46 }
47
48 void delay_100us(uint32_t value)
49 {
50 usleep(value*100);
51 }
52
53 uint32_t getAPB1Freq()
54 {
55 return 0;
56 }
57
58 uint32_t getAPB2Freq()
59 {
60 return 0;
61 }
62
63
64 uint32_t getCpuFreq()
65 {
66 return 0;
67 }
68
69 void reset_AHB1()
70 {
71 }
72
73 void reset_AHB2()
74 {
75
76 }
77
78 void reset_APB1()
79 {
80
81 }
82
83 void reset_APB2()
84 {
85
86 }
87
88
89
90
91
92 int optimizePLLcfg(uint32_t freq, uint32_t srcfreq,uint32_t PLLM,uint32_t* PLLP, uint32_t* PLLN,uint8_t* AHBPRindx)
93 {
94
95 return 1;
96 }
97
98
99 int setPll(uint32_t freq)
100 {
101
102 return freq;
103 }
104
105 void configureSysTick()
106 {
107
108 }
109
110 int setCpuFreq(uint32_t freq)
111 {
112
113 return 0;
114 }
115
116
117 void enable_FPU()
118 {
119
120 }
121
122
123
124
125
126
@@ -0,0 +1,13
1 TEMPLATE = lib
2 SOURCES += \
3 core.c \
4 threads.c \
5 irq_handlers.c
6
7 INCLUDEPATH += ../../includes
8
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
@@ -0,0 +1,452
1 #include <stdio.h>
2
3 void NMI_Handler(void)
4 {
5 printf("NMI_Handler\n");
6 }
7
8 void HardFault_Handler(void)
9 {
10 printf("HardFault_Handler\n");
11 }
12
13 void MemManage_Handler(void)
14 {
15 printf("MemManage_Handler\n");
16 }
17
18 void BusFault_Handler(void)
19 {
20 printf("BusFault_Handler\n");
21 }
22
23 void UsageFault_Handler(void)
24 {
25 printf("UsageFault_Handler\n");
26 }
27
28 void SVC_Handler(void)
29 {
30 printf("SVC_Handler\n");
31 }
32
33 void DebugMon_Handler(void)
34 {
35 printf("DebugMon_Handler\n");
36 }
37
38 void PendSV_Handler(void)
39 {
40 printf("PendSV_Handler\n");
41 }
42
43 void WWDG_IRQHandler(void)
44 {
45 printf("WWDG_IRQHandler\n");
46 }
47
48 void PVD_IRQHandler(void)
49 {
50 printf("PVD_IRQHandler\n");
51 }
52
53 void TAMP_STAMP_IRQHandler(void)
54 {
55 printf("TAMP_STAMP_IRQHandler\n");
56 }
57
58 void RTC_WKUP_IRQHandler(void)
59 {
60 printf("RTC_WKUP_IRQHandler\n");
61 }
62
63 void FLASH_IRQHandler(void)
64 {
65 printf("FLASH_IRQHandler\n");
66 }
67
68 void RCC_IRQHandler(void)
69 {
70 printf("RCC_IRQHandler\n");
71 }
72
73 void EXTI0_IRQHandler(void)
74 {
75 printf("EXTI0_IRQHandler\n");
76 }
77
78 void EXTI1_IRQHandler(void)
79 {
80 printf("EXTI1_IRQHandler\n");
81 }
82
83 void EXTI2_IRQHandler(void)
84 {
85 printf("EXTI2_IRQHandler\n");
86 }
87
88 void EXTI3_IRQHandler(void)
89 {
90 printf("EXTI3_IRQHandler\n");
91 }
92
93 void EXTI4_IRQHandler(void)
94 {
95 printf("EXTI4_IRQHandler\n");
96 }
97
98 void DMA1_Stream0_IRQHandler(void)
99 {
100 printf("DMA1_Stream0_IRQHandler\n");
101 }
102
103 void DMA1_Stream1_IRQHandler(void)
104 {
105 printf("DMA1_Stream1_IRQHandler\n");
106 }
107
108 void DMA1_Stream2_IRQHandler(void)
109 {
110 printf("DMA1_Stream2_IRQHandler\n");
111 }
112
113 void DMA1_Stream3_IRQHandler(void)
114 {
115 printf("DMA1_Stream3_IRQHandler\n");
116 }
117
118 void DMA1_Stream4_IRQHandler(void)
119 {
120 printf("DMA1_Stream4_IRQHandler\n");
121 }
122
123 void DMA1_Stream5_IRQHandler(void)
124 {
125 printf("DMA1_Stream5_IRQHandler\n");
126 }
127
128 void DMA1_Stream6_IRQHandler(void)
129 {
130 printf("DMA1_Stream6_IRQHandler\n");
131 }
132
133 void ADC_IRQHandler(void)
134 {
135 printf("ADC_IRQHandler\n");
136 }
137
138 void CAN1_TX_IRQHandler(void)
139 {
140 printf("CAN1_TX_IRQHandler\n");
141 }
142
143 void CAN1_RX0_IRQHandler(void)
144 {
145 printf("CAN1_RX0_IRQHandler\n");
146 }
147
148 void CAN1_RX1_IRQHandler(void)
149 {
150 printf("CAN1_RX1_IRQHandler\n");
151 }
152
153 void CAN1_SCE_IRQHandler(void)
154 {
155 printf("CAN1_SCE_IRQHandler\n");
156 }
157
158 void EXTI9_5_IRQHandler(void)
159 {
160 printf("EXTI9_5_IRQHandler\n");
161 }
162
163 void TIM1_BRK_TIM9_IRQHandler(void)
164 {
165 printf("TIM1_BRK_TIM9_IRQHandler\n");
166 }
167
168 void TIM1_UP_TIM10_IRQHandler(void)
169 {
170 printf("TIM1_UP_TIM10_IRQHandler\n");
171 }
172
173 void TIM1_TRG_COM_TIM11_IRQHandlerIM11(void)
174 {
175 printf("TIM1_TRG_COM_TIM11_IRQHandlerIM11");
176 }
177
178 void TIM1_CC_IRQHandler(void)
179 {
180 printf("TIM1_CC_IRQHandler\n");
181 }
182
183 void TIM2_IRQHandler(void)
184 {
185 printf("TIM2_IRQHandler\n");
186 }
187
188 void TIM3_IRQHandler(void)
189 {
190 printf("TIM3_IRQHandler\n");
191 }
192
193 void TIM4_IRQHandler(void)
194 {
195 printf("TIM4_IRQHandler\n");
196 }
197
198 void I2C1_EV_IRQHandler(void)
199 {
200 printf("I2C1_EV_IRQHandler\n");
201 }
202
203 void I2C1_ER_IRQHandler(void)
204 {
205 printf("I2C1_ER_IRQHandler\n");
206 }
207
208 void I2C2_EV_IRQHandler(void)
209 {
210 printf("I2C2_EV_IRQHandler\n");
211 }
212
213 void I2C2_ER_IRQHandler(void)
214 {
215 printf("I2C2_ER_IRQHandler\n");
216 }
217
218 void SPI1_IRQHandler(void)
219 {
220 printf("SPI1_IRQHandler\n");
221 }
222
223 void SPI2_IRQHandler(void)
224 {
225 printf("SPI2_IRQHandler\n");
226 }
227
228 void USART1_IRQHandler(void)
229 {
230 printf("USART1_IRQHandler\n");
231 }
232
233 void USART2_IRQHandler(void)
234 {
235 printf("USART2_IRQHandler\n");
236 }
237
238 void USART3_IRQHandler(void)
239 {
240 printf("USART3_IRQHandler\n");
241 }
242
243 void EXTI15_10_IRQHandler(void)
244 {
245 printf("EXTI15_10_IRQHandler\n");
246 }
247
248 void RTC_Alarm_IRQHandler(void)
249 {
250 printf("RTC_Alarm_IRQHandler\n");
251 }
252
253 void OTG_FS_WKUP_IRQHandler(void)
254 {
255 printf("OTG_FS_WKUP_IRQHandler\n");
256 }
257
258 void TIM8_BRK_TIM12_IRQHandler(void)
259 {
260 printf("TIM8_BRK_TIM12_IRQHandler\n");
261 }
262
263 void TIM8_UP_TIM13_IRQHandler(void)
264 {
265 printf("TIM8_UP_TIM13_IRQHandler\n");
266 }
267
268 void TIM8_TRG_COM_TIM14_IRQHandlerIM14(void)
269 {
270 printf("TIM8_TRG_COM_TIM14_IRQHandlerIM14");
271 }
272
273 void TIM8_CC_IRQHandler(void)
274 {
275 printf("TIM8_CC_IRQHandler\n");
276 }
277
278 void DMA1_Stream7_IRQHandler(void)
279 {
280 printf("DMA1_Stream7_IRQHandler\n");
281 }
282
283 void FSMC_IRQHandler(void)
284 {
285 printf("FSMC_IRQHandler\n");
286 }
287
288 void SDIO_IRQHandler(void)
289 {
290 printf("SDIO_IRQHandler\n");
291 }
292
293 void TIM5_IRQHandler(void)
294 {
295 printf("TIM5_IRQHandler\n");
296 }
297
298 void SPI3_IRQHandler(void)
299 {
300 printf("SPI3_IRQHandler\n");
301 }
302
303 void UART4_IRQHandler(void)
304 {
305 printf("UART4_IRQHandler\n");
306 }
307
308 void UART5_IRQHandler(void)
309 {
310 printf("UART5_IRQHandler\n");
311 }
312
313 void TIM6_DAC_IRQHandler(void)
314 {
315 printf("TIM6_DAC_IRQHandler\n");
316 }
317
318 void TIM7_IRQHandler(void)
319 {
320 printf("TIM7_IRQHandler\n");
321 }
322
323 void DMA2_Stream0_IRQHandler(void)
324 {
325 printf("DMA2_Stream0_IRQHandler\n");
326 }
327
328 void DMA2_Stream1_IRQHandler(void)
329 {
330 printf("DMA2_Stream1_IRQHandler\n");
331 }
332
333 void DMA2_Stream2_IRQHandler(void)
334 {
335 printf("DMA2_Stream2_IRQHandler\n");
336 }
337
338 void DMA2_Stream3_IRQHandler(void)
339 {
340 printf("DMA2_Stream3_IRQHandler\n");
341 }
342
343 void DMA2_Stream4_IRQHandler(void)
344 {
345 printf("DMA2_Stream4_IRQHandler\n");
346 }
347
348 void ETH_IRQHandler(void)
349 {
350 printf("ETH_IRQHandler\n");
351 }
352
353 void ETH_WKUP_IRQHandler(void)
354 {
355 printf("ETH_WKUP_IRQHandler\n");
356 }
357
358 void CAN2_TX_IRQHandler(void)
359 {
360 printf("CAN2_TX_IRQHandler\n");
361 }
362
363 void CAN2_RX0_IRQHandler(void)
364 {
365 printf("CAN2_RX0_IRQHandler\n");
366 }
367
368 void CAN2_RX1_IRQHandler(void)
369 {
370 printf("CAN2_RX1_IRQHandler\n");
371 }
372
373 void CAN2_SCE_IRQHandler(void)
374 {
375 printf("CAN2_SCE_IRQHandler\n");
376 }
377
378 void OTG_FS_IRQHandler(void)
379 {
380 printf("OTG_FS_IRQHandler\n");
381 }
382
383 void DMA2_Stream5_IRQHandler(void)
384 {
385 printf("DMA2_Stream5_IRQHandler\n");
386 }
387
388 void DMA2_Stream6_IRQHandler(void)
389 {
390 printf("DMA2_Stream6_IRQHandler\n");
391 }
392
393 void DMA2_Stream7_IRQHandler(void)
394 {
395 printf("DMA2_Stream7_IRQHandler\n");
396 }
397
398 void USART6_IRQHandler(void)
399 {
400 printf("USART6_IRQHandler\n");
401 }
402
403 void I2C3_EV_IRQHandler(void)
404 {
405 printf("I2C3_EV_IRQHandler\n");
406 }
407
408 void I2C3_ER_IRQHandler(void)
409 {
410 printf("I2C3_ER_IRQHandler\n");
411 }
412
413 void OTG_HS_EP1_OUT_IRQHandler(void)
414 {
415 printf("OTG_HS_EP1_OUT_IRQHandler\n");
416 }
417
418 void OTG_HS_EP1_IN_IRQHandler(void)
419 {
420 printf("OTG_HS_EP1_IN_IRQHandler\n");
421 }
422
423 void OTG_HS_WKUP_IRQHandler(void)
424 {
425 printf("OTG_HS_WKUP_IRQHandler\n");
426 }
427
428 void OTG_HS_IRQHandler(void)
429 {
430 printf("OTG_HS_IRQHandler\n");
431 }
432
433 void DCMI_IRQHandler(void)
434 {
435 printf("DCMI_IRQHandler\n");
436 }
437
438 void CRYP_IRQHandler(void)
439 {
440 printf("CRYP_IRQHandler\n");
441 }
442
443 void HASH_RNG_IRQHandler(void)
444 {
445 printf("HASH_RNG_IRQHandler\n");
446 }
447
448 void FPU_IRQHandler(void)
449 {
450 printf("FPU_IRQHandler\n");
451 }
452
@@ -0,0 +1,81
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23
24 #define __THREAD_PRIVATE__
25 #include <thread.h>
26
27 /*
28 For CM4 cf lazy Stacking and context switching form ARM
29 List of automatically saved registers:
30 R0
31 R1
32 R2
33 R3
34 R4
35 R5
36 R6
37 R7
38 R8
39 R9
40 R10
41 R11
42 R12
43 R13(SP)
44 R14(LR)
45 R15(PC)
46 xPSR
47 S0 to S15 (if enabled)
48
49 List of registers to save:
50 S16 to S31
51 */
52
53
54 void __cpusavecontext(void* dataspace)
55 {
56
57 }
58
59 void __cpurestorecontext(void* dataspace)
60 {
61
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@@ -0,0 +1,10
1
2
3
4
5
6
7
8
9
10
@@ -0,0 +1,14
1
2
3 LIBS += -L$$[QT_INSTALL_LIBS]/$$UCMODEL
4 LIBS += -lcpu
5
6
7
8
9
10
11
12
13
14
@@ -0,0 +1,25
1 TEMPLATE = lib
2
3 UCMODEL=simulator
4
5 prifile.files = cpu.pri startup.c fs.c
6 prifile.path = $$[QT_INSTALL_PREFIX]/mkspecs/features/$$UCMODEL
7
8 INCLUDEPATH += ../../includes
9
10 SOURCES += cpu.c
11
12
13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
14 INSTALLS += target prifile
15
16
17
18
19
20
21
22
23
24
25
@@ -0,0 +1,25
1 #include <stdint.h>
2 #include <streamdevices.h>
3 #include <stdio.h>
4 #include <bsp.h>
5
6 const int32_t __max_opened_files__ = __MAX_OPENED_FILES__;
7 volatile streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
8 const int32_t __fs_root_size__ = __FS_ROOT_SIZE__;
9 int32_t __fs_root__[__FS_ROOT_SIZE__];
10
11
12 /*
13 void __init_fs()
14 {
15 int i=0;
16 for(i=0;i<__fs_root_size__;i++)
17 {
18 __fs_root__[i]=(int32_t)NULL;
19 }
20 for(i=0;i<__max_opened_files__ ;i++)
21 {
22 __opnfiles__[i]._stream=NULL;
23 }
24 }
25 */
@@ -0,0 +1,7
1
2
3 int main(void)
4 {
5 bsp_init();
6 libuc2_main_task();
7 }
@@ -0,0 +1,119
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22 #include <gpio.h>
23
24
25
26 gpio_t gpioopen(uint32_t gpio)
27 {
28 gpio &= -1^GPIOSPEEDMASK;
29 gpio |= gpiolowspeed;
30 gpio &= -1^GPIODIRMASK;
31 gpio |= gpioindir;
32 gpio &= -1^GPIOOUTTYPEMASK;
33 gpio |= gpiopushpulltype;
34 gpio &= -1^GPIOPULLTYPEMASK;
35 gpio |= gpionopulltype;
36 return gpio;
37 }
38
39
40 void gpioclose(gpio_t gpio)
41 {
42 }
43
44 void gpiosetconfig(gpio_t* gpio)
45 {
46 gpiosetdir(gpio, (*gpio & GPIODIRMASK));
47 gpiosetspeed(gpio, (*gpio & GPIOSPEEDMASK));
48 gpiosetouttype(gpio, (*gpio & GPIOOUTTYPEMASK));
49 gpiosetpulltype(gpio, (*gpio & GPIOPULLTYPEMASK));
50 }
51
52 extern void gpiosetspeed(gpio_t* gpio,gpiospeed_t speed)
53 {
54
55 }
56
57
58 void gpiosetdir(gpio_t* gpio,gpiodir_t dir)
59 {
60
61
62 }
63
64
65 void gpiosetouttype(gpio_t* gpio, gpioouttype_t outtype)
66 {
67
68 }
69
70
71 void gpiosetpulltype(gpio_t* gpio,gpiopulltype_t pulltype)
72 {
73
74 }
75
76 void gpioset(gpio_t gpio)
77 {
78
79 }
80
81
82 void gpioclr(gpio_t gpio)
83 {
84
85 }
86
87 void gpiosetval(gpio_t gpio,int val)
88 {
89
90 }
91
92 int gpiogetval(gpio_t gpio)
93 {
94 return 0;
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@@ -0,0 +1,12
1 TEMPLATE = lib
2 SOURCES += gpio.c
3
4 INCLUDEPATH += ../../includes
5
6
7 UCMODEL=simulator
8
9 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
10 INSTALLS += target
11
12
@@ -0,0 +1,132
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2012, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23 #include <i2c.h>
24 #include <gpio.h>
25
26
27 int i2ctimeout=1000*1000;
28
29
30 i2c_t i2copen(int count)
31 {
32 return -1;
33 }
34
35 i2c_t i2copenandconfig(int count,uint32_t cfg,uint32_t speed,uint32_t SDA,uint32_t SCL)
36 {
37 i2c_t dev = i2copen(count);
38 if(dev!=-1)
39 {
40 i2cclose(dev);
41 i2csetpins(dev,SDA,SCL);
42 i2copen(count);
43 i2csetspeed(dev,speed);
44 i2cenable(count);
45 }
46 return dev;
47 }
48
49 int i2cclose(i2c_t dev)
50 {
51 return 1;
52 }
53
54 int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL)
55 {
56 if((dev<i2c4)&&(dev>=i2c1))
57 {
58 return 0;
59 }
60 return -1;
61 }
62
63 int i2cenable(i2c_t dev)
64 {
65 if((dev<i2c4)&&(dev>=i2c1))
66 {
67
68 return 0;
69 }
70 return -1;
71 }
72
73 int i2cdisable(i2c_t dev)
74 {
75 if((dev<i2c4)&&(dev>=i2c1))
76 {
77
78 return 0;
79 }
80 return -1;
81 }
82
83
84 int i2csetspeed(i2c_t dev,uint32_t speed)
85 {
86 if((dev<i2c4)&&(dev>=i2c1))
87 {
88 return 0;
89 }
90 return -1;
91 }
92
93 int i2cbusy(i2c_t dev)
94 {
95 if((dev<i2c4)&&(dev>=i2c1))
96 {
97 return 0; /* Dev isn't busy */
98 }
99 return -1; /* Error, dev is out of range */
100 }
101
102 int i2cwrite(i2c_t dev,char address,char* data,int count)
103 {
104 if((dev<i2c4)&&(dev>=i2c1))
105 {
106
107 return 0;
108 }
109 return -1;
110 }
111
112 int i2cread(i2c_t dev,char address,char* data,int count)
113 {
114 if((dev<i2c4)&&(dev>=i2c1))
115 {
116 return 0;
117 }
118 return -1;
119 }
120
121
122 int i2cStatusCheck(i2c_t dev,int32_t flagMask)
123 {
124 int32_t flag;
125 if((dev<i2c4)&&(dev>=i2c1))
126 {
127 return 0;
128 }
129 return -1;
130 }
131
132
@@ -0,0 +1,12
1 TEMPLATE = lib
2 SOURCES += i2c.c
3
4 INCLUDEPATH += ../../includes
5
6
7 UCMODEL=simulator
8
9 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
10 INSTALLS += target
11
12
@@ -0,0 +1,15
1 TEMPLATE = lib
2 TARGET = sdcard
3 SOURCES += fakesdcard.c
4
5 INCLUDEPATH += ../../includes
6 HEADERS += \
7 ../../includes/sdcard.h
8
9
10 UCMODEL=simulator
11
12 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 INSTALLS += target
14
15
@@ -0,0 +1,115
1 #include <stdio.h>
2 #include <sdcard.h>
3 #include <sdcard-spi.h>
4
5 FILE* sdcardimg;
6
7
8 void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy))
9 {
10
11 }
12
13
14 int sdcardselect (blkdevice* _this)
15 {
16 return 1;
17 }
18
19
20 void sdcarddeselect (blkdevice* _this)
21 {
22
23 }
24
25 int sdcardwait_ready (sdcardDev* sdcard)
26 {
27 return 1;
28 }
29
30 void sdcardpower (blkdevice* _this)
31 {
32
33 }
34
35 char sdcarddetect (blkdevice* _this)
36 {
37 return 1;
38 }
39
40 char sdcardwriteprotected (blkdevice* _this)
41 {
42 return 0;
43 }
44
45
46
47 int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token)
48 {
49 return 1;
50 }
51
52 int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr)
53 {
54 return 1;
55 }
56
57 char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg)
58 {
59 return 1;
60 }
61
62 DSTATUS sdcarddisk_status (blkdevice* _this)
63 {}
64
65 DSTATUS sdcarddisk_initialize (blkdevice* _this)
66 {}
67
68 DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count)
69 {
70 int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET);
71 if(count*512== fread(buff,1,count*512,sdcardimg))
72 return RES_OK;
73 return RES_ERROR;
74 }
75
76 DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count)
77 {
78 fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET);
79 fwrite(buff,1,count*512,sdcardimg);
80 return RES_OK;
81 }
82
83 DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff)
84 {}
85
86
87 void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected)
88 {
89 sdcardimg=fopen("sdcard.bin","rb");
90 // sdcardimg=fopen("usbkey.bin","rb");
91 if(sdcardimg!=NULL)printf("ok sdcard openned\n");
92 else printf("Nok sdcard not openned\n");
93 dev->phy=NULL;
94 dev->select= (blkdevselect_t)select;
95 dev->power = (blkdevpower_t)power;
96 dev->detect = (blkdevdetect_t)detect;
97 dev->writeprotected = (blkdevwriteprotected_t)writeprotected;
98 dev->write = sdcarddisk_write;
99 dev->read = sdcarddisk_read;
100 dev->ioctl = sdcarddisk_ioctl;
101 dev->initialize = sdcarddisk_initialize;
102 dev->status = sdcarddisk_status;
103 printf("sdcard opened\n");
104 }
105
106
107
108
109
110
111
112
113
114
115
@@ -0,0 +1,237
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23 #include <SDL.h>
24 #include <malloc.h>
25 #include "SDLCD.h"
26
27 SDL_Surface *screen;
28 SDL_Overlay *bmp;
29
30 int SDLCD_Xpos=0;
31 int SDLCD_Ypos=0;
32 int SDLCD_XWinStrt=0;
33 int SDLCD_YWinStrt=0;
34 int SDLCD_XWinEnd=0;
35 int SDLCD_YWinEnd=0;
36
37 void* SDLCD_buffer;
38 int SDLCD_bpp;
39 void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
40
41 void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype)
42 {
43 int i=0;
44 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) {
45 fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
46 exit(1);
47 }
48 screen = SDL_SetVideoMode(resx, resy, bpp, 0);
49 if(!screen) {
50 fprintf(stderr, "SDL: could not set video mode - exiting\n");
51 exit(1);
52 }
53 if ( SDL_MUSTLOCK(screen) ) {
54 if ( SDL_LockSurface(screen) < 0 ) {
55 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
56 return;
57 }
58 }
59 if ( SDL_MUSTLOCK(screen) ) {
60 SDL_UnlockSurface(screen);
61 }
62 SDL_UpdateRect(screen, 0, 0, resx, resy);
63 SDLCD_buffer = malloc(resx*resy*bpp/8);
64 SDLCD_bpp = bpp;
65 for(i=0;i<(resx*resy);i++)
66 {
67 SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF);
68 }
69 }
70
71
72
73 int SDLCD_init()
74 {
75
76 }
77
78 void SDLCD_writereg(uint32_t reg,uint32_t data)
79 {
80 switch (reg) {
81 case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET:
82 SDLCD_Xpos = data;
83 break;
84 case ILI9328_REGISTER_VERTICALGRAMADDRESSSET:
85 SDLCD_Ypos = data;
86 break;
87 case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION:
88 SDLCD_XWinStrt = data;
89 break;
90 case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION:
91 SDLCD_XWinEnd = data;
92 break;
93 case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION:
94 SDLCD_YWinStrt = data;
95 break;
96 case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION:
97 SDLCD_YWinEnd = data;
98 break;
99 default:
100 break;
101 }
102 }
103
104 uint32_t SDLCD_readreg(uint32_t reg)
105 {
106 return 0;
107 }
108
109
110 void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
111 {
112 int bpp = surface->format->BytesPerPixel;
113 /* Here p is the address to the pixel we want to set */
114 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
115 switch(bpp) {
116 case 1:
117 *p = pixel;
118 break;
119 case 2:
120 *(Uint16 *)p = pixel;
121 break;
122 case 3:
123 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
124 p[0] = (pixel >> 16) & 0xff;
125 p[1] = (pixel >> 8) & 0xff;
126 p[2] = pixel & 0xff;
127 } else {
128 p[0] = pixel & 0xff;
129 p[1] = (pixel >> 8) & 0xff;
130 p[2] = (pixel >> 16) & 0xff;
131 }
132 break;
133 case 4:
134 *(Uint32 *)p = pixel;
135 break;
136 }
137 }
138
139 Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y)
140 {
141 int bpp = surface->format->BytesPerPixel;
142 /* Here p is the address to the pixel we want to retrieve */
143 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
144 switch(bpp) {
145 case 1:
146 return *p;
147 case 2:
148 return *(Uint16 *)p;
149 case 3:
150 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
151 return p[0] << 16 | p[1] << 8 | p[2];
152 else
153 return p[0] | p[1] << 8 | p[2] << 16;
154 case 4:
155 return *(Uint32 *)p;
156 default:
157 return 0;
158 }
159 /* shouldn’t happen, but avoids warnings */
160 }
161
162 void SDLCD_writeGRAM(void* buffer,uint32_t count)
163 {
164 int i=0;
165 u_int16_t* ptr=(u_int16_t*)SDLCD_buffer;
166 u_int16_t* inptr=(u_int16_t*)buffer;
167 if ( SDL_MUSTLOCK(screen) ) {
168 if ( SDL_LockSurface(screen) < 0 ) {
169 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
170 return;
171 }
172 }
173 for(i=0;i<count;i++)
174 {
175 SDLCD_putpixel(screen,SDLCD_Xpos,SDLCD_Ypos,inptr[i]);
176 SDLCD_Xpos+=1;
177 ptr[i]=inptr[i];
178 if(SDLCD_Xpos>=SDLCD_XWinEnd)
179 {
180 SDLCD_Xpos=SDLCD_XWinStrt;
181 SDLCD_Ypos+=1;
182 }
183 if(SDLCD_Ypos>=SDLCD_YWinEnd)
184 {
185 SDLCD_Ypos=SDLCD_YWinStrt;
186 }
187 }
188 if ( SDL_MUSTLOCK(screen) ) {
189 SDL_UnlockSurface(screen);
190 }
191 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
192 }
193
194 void SDLCD_readGRAM(void* buffer,uint32_t count)
195 {
196 int i=0;
197 u_int16_t* ptr=(u_int16_t*)SDLCD_buffer;
198 u_int16_t* inptr=(u_int16_t*)buffer;
199 for(i=0;i<count;i++)
200 {
201 inptr[i]=SDLCD_getpixel(screen,SDLCD_Xpos,SDLCD_Ypos);
202 SDLCD_Xpos+=1;
203 ptr[i]=inptr[i];
204 if(SDLCD_Xpos>=SDLCD_XWinEnd)
205 {
206 SDLCD_Xpos=SDLCD_XWinStrt;
207 SDLCD_Ypos+=1;
208 }
209 if(SDLCD_Ypos>=SDLCD_YWinEnd)
210 {
211 SDLCD_Ypos=SDLCD_YWinStrt;
212 }
213 }
214
215 }
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
@@ -0,0 +1,46
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23 #include <SDL.h>
24 #include <ili9328.h>
25 #include <stdint.h>
26
27 #define LCDILI9328 9328
28
29 extern SDL_Surface *screen;
30 extern SDL_Overlay *bmp;
31
32 extern void SDLCD_mkscreen(int resx,int resy,int bbp,int lcdtype);
33 extern int SDLCD_init();
34 extern void SDLCD_writereg(uint32_t reg,uint32_t data);
35 extern uint32_t SDLCD_readreg(uint32_t reg);
36 extern void SDLCD_writeGRAM(void* buffer,uint32_t count);
37 extern void SDLCD_readGRAM(void* buffer,uint32_t count);
38
39
40
41
42
43
44
45
46
@@ -0,0 +1,18
1 TEMPLATE = lib
2 SOURCES += SDLCD.c
3
4 HEADERS += ./SDLCD.h
5
6 INCLUDEPATH += ../../includes
7
8 SDLCDHEADERS.files += \
9 ./SDLCD.h
10
11 SDLCDHEADERS.path = $$[QT_INSTALL_HEADERS]/simulator
12
13 UCMODEL=simulator
14
15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 INSTALLS += target SDLCDHEADERS
17
18
@@ -0,0 +1,255
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2011, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23 #include <spi.h>
24 #include <gpio.h>
25
26
27
28 spi_t spiopen(int count)
29 {
30
31 return -1;
32 }
33
34 spi_t spiopenandconfig(int count, uint32_t cfg, uint32_t speed, uint32_t MOSIpin, uint32_t MISOpin, uint32_t SCKpin, uint32_t SCSpin)
35 {
36 spi_t dev = spiopen(count);
37 if(dev!=-1)
38 {
39 spidisable(dev);
40 spisetpins(dev,MOSIpin, MISOpin, SCKpin, SCSpin);
41 spienable(dev);
42 spisetconfig(dev,cfg,speed);
43 }
44 return dev;
45 }
46
47
48 int spiclose(spi_t spidev)
49 {
50 if((spidev<3)&&(spidev>=0))
51 {
52
53 return 1;
54 }
55 return -1;
56 }
57
58 int spisetpins(spi_t spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin)
59 {
60 if((spidev<3)&&(spidev>=0))
61 {
62
63 return 1;
64 }
65 return -1;
66 }
67
68
69 int spienable(spi_t spidev)
70 {
71 if((spidev<3)&&(spidev>=0))
72 {
73 return 1;
74 }
75 return -1;
76 }
77
78
79 int spidisable(spi_t spidev)
80 {
81 if((spidev<3)&&(spidev>=0))
82 {
83 return 1;
84 }
85 return -1;
86 }
87
88 int spisetconfig(spi_t spidev, uint32_t config, uint32_t speed)
89 {
90 if((spidev<3)&&(spidev>=0))
91 {
92 return 0;
93 }
94 return 1;
95 }
96
97 int spisetspeed(spi_t spidev, uint32_t speed)
98 {
99 if((spidev<3)&&(spidev>=0))
100 {
101 return 1;
102 }
103 return -1;
104 }
105
106 uint32_t spigetspeed(spi_t spidev)
107 {
108 if((spidev<3)&&(spidev>=0))
109 {
110
111 return 0;
112 }
113 return -1;
114 }
115
116 int spisetdatabits(spi_t spidev,spibits_t bitscnt)
117 {
118 if((spidev<3)&&(spidev>=0))
119 {
120 return 0;
121 }
122 return -1;
123 }
124
125 int spisetbitorder(spi_t spidev,spibitorder_t order)
126 {
127 if((spidev<3)&&(spidev>=0))
128 {
129 return 1;
130 }
131 return -1;
132 }
133
134 int spisetclkinhlevel(spi_t spidev,spiclkinhlvl_t level)
135 {
136 if((spidev<3)&&(spidev>=0))
137 {
138 return 1;
139 }
140 return -1;
141 }
142
143 int spisetclkphase(spi_t spidev,spiclkphase_t phase)
144 {
145 if((spidev<3)&&(spidev>=0))
146 {
147 return 1;
148 }
149 return -1;
150 }
151
152 int spiputw(spi_t spidev,uint16_t data)
153 {
154 if((spidev<3)&&(spidev>=0))
155 {
156 return 0;
157 }
158 return -1;
159 }
160 uint16_t spigetw(spi_t spidev)
161 {
162 if((spidev<3)&&(spidev>=0))
163 {
164 return 0;
165 }
166 return -1;
167 }
168
169 int spiputs(spi_t spidev,char* s)
170 {
171 while (*s) spiputw(spidev,*s++);
172 return 1;
173 }
174
175 int spigets(spi_t spidev,char* s)
176 {
177 do
178 {
179 (*s) = spigetw(spidev);
180 }
181 while(*s++);
182 return 1;
183 }
184
185 int spiputnw(spi_t spidev,uint16_t* w,int n)
186 {
187 while(n!=0)
188 {
189 spiputw(spidev,*w++);
190 n--;
191 }
192 return 1;
193 }
194
195 int spigetnw(spi_t spidev,uint16_t* w,int n)
196 {
197 while(n!=0)
198 {
199 *w++=spigetw(spidev);
200 n--;
201 }
202 return 1;
203 }
204
205 int spiputnc(spi_t spidev,char* c,int n)
206 {
207 while(n!=0)
208 {
209 spiputw(spidev,*c++);
210 n--;
211 }
212 return 1;
213 }
214
215 int spigetnc(spi_t spidev,char* c,int n)
216 {
217 while(n!=0)
218 {
219 *c++=spigetw(spidev);
220 n--;
221 }
222 return 1;
223 }
224
225 int spiavailiabledata(spi_t spidev)
226 {
227 return 0;
228 }
229
230
231 int spitransactionfinished(spi_t spidev)
232 {
233 if((spidev<3)&&(spidev>=0))
234 {
235 return 1;
236 }
237 return 0;
238 }
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
@@ -0,0 +1,14
1 TEMPLATE = lib
2 SOURCES += spi.c
3
4 HEADERS += ../../includes/spi.h
5
6 INCLUDEPATH += ../../includes
7
8
9 UCMODEL=simulator
10
11 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
12 INSTALLS += target
13
14
@@ -0,0 +1,226
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
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
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
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
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
22
23 #include <uart.h>
24 #include <gpio.h>
25 #include <stdio.h>
26
27
28
29 int _uartstrsetpos(streamdevice* device,int pos);
30 int _uartstrread(streamdevice* device,void* data,int size, int n);
31 int _uartstrwrite(streamdevice* device,void* data,int size, int n);
32
33 streamdevice_ops UART_OPS=
34 {
35 .write = &_uartstrwrite,
36 .read = &_uartstrread,
37 .setpos= &_uartstrsetpos,
38 .close = NULL
39 };
40
41 uart_t uartopen(int count)
42 {
43 return -1;
44 }
45
46 uart_t uartopenandconfig(int count, uint32_t cfg, uint32_t speed, uint32_t TXpin, uint32_t RXpin, uint32_t RTSpin, uint32_t CTSpin)
47 {
48 uart_t dev= uartopen(count);
49 uartsetconfig(dev,cfg,speed);
50 uartsetpins(dev,TXpin,RXpin,RTSpin,CTSpin);
51 return dev;
52 }
53
54
55 int uartclose(uart_t uart)
56 {
57 return 1;
58 }
59
60 int uartsetpins(uart_t uart,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin)
61 {
62 if(uart >5)return -1;
63 if(uart <0)return -1;
64 return 1;
65 }
66
67 int uartsetconfig(uart_t uart, uint32_t cfg, uint32_t speed)
68 {
69 int res=1;
70 uartdisable(uart);
71 uartsetspeed(uart,speed);
72 uartsetparity(uart,cfg & UARTPARITYMASK);
73 uartsetdatabits(uart,cfg & UARTBITSMASK);
74 uartsetstopbits(uart,cfg & UARTSTOPBITSMASK);
75 uartenable(uart);
76 return res;
77 }
78
79 int uartenable(uart_t uart)
80 {
81 if((uart<6)&&(uart>=0))
82 {
83 return 1;
84 }
85 return -1;
86 }
87
88 int uartdisable(uart_t uart)
89 {
90 if((uart<6)&&(uart>=0))
91 {
92 return 1;
93 }
94 return -1;
95 }
96
97 int uartsetspeed(uart_t uart,uint32_t speed)
98 {
99 if((uart<6)&&(uart>=0))
100 {
101 return 1;
102 }
103 return -1;
104 }
105
106 int uartsetparity(uart_t uart,uartparity_t parity)
107 {
108 if((uart<6)&&(uart>=0))
109 {
110 return 1;
111 }
112 return -1;
113 }
114
115 int uartsetdatabits(uart_t uart,uartbits_t databits)
116 {
117 if((uart<6)&&(uart>=0))
118 {
119 return 1;
120 }
121 return -1;
122 }
123
124 int uartsetstopbits(uart_t uart,uartstopbits_t stopbits)
125 {
126 if((uart<6)&&(uart>=0))
127 {
128 return 1;
129 }
130 return -1;
131 }
132
133 int uartputc(uart_t uart,char c)
134 {
135 if((uart<6)&&(uart>=0))
136 {
137 return 1;
138 }
139 return -1;
140 }
141
142 char uartgetc(uart_t uart)
143 {
144 if((uart<6)&&(uart>=0))
145 {
146 return 0;
147 }
148 return -1;
149 }
150
151 int uartputs(uart_t uart,char* s)
152 {
153 while (*s) uartputc(uart,*s++);
154 return 1;
155 }
156
157 int uartgets(uart_t uart,char* s)
158 {
159 do
160 {
161 (*s) = uartgetc(uart);
162 }
163 while(*s++);
164 return 1;
165 }
166
167 int uartputnc(uart_t uart,char* c,int n)
168 {
169 int l=0;
170 while(l<n)
171 {
172 uartputc(uart,*c++);
173 l++;
174 }
175 return n;
176 }
177
178 int uartgetnc(uart_t uart,char* c,int n)
179 {
180 int l=0;
181 while(l<n)
182 {
183 *c++=uartgetc(uart);
184 l++;
185 }
186 return n;
187 }
188
189 int uartavailiabledata(uart_t uart)
190 {
191 if((uart<6)&&(uart>=0))
192 {
193 return 1;
194 }
195 return -1;
196 }
197
198
199 int _uartstrwrite(streamdevice* device,void* data,int size, int n)
200 {
201 return uartputnc((uart_t) device->_stream,(char*) data,size*n);
202 }
203
204 int _uartstrread(streamdevice* device,void* data,int size, int n)
205 {
206 return uartgetnc((uart_t) device->_stream,(char*) data,size*n);
207 }
208
209 int _uartstrsetpos(streamdevice* device,int pos)
210 {
211 return 1;
212 }
213
214 int uartmkstreamdev(uart_t uart,streamdevice* strdev)
215 {
216 strdev->_stream = (UHANDLE)uart;
217 strdev->ops = &UART_OPS;
218 strdev->streamPt = 0;
219 return 1;
220 }
221
222
223
224
225
226
@@ -0,0 +1,12
1 TEMPLATE = lib
2 SOURCES += uart.c
3
4 INCLUDEPATH += ../../includes
5
6
7 UCMODEL=simulator
8
9 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
10 INSTALLS += target
11
12
@@ -0,0 +1,14
1 TEMPLATE = subdirs
2 CONFIG += ordered
3 SUBDIRS = CORE/core.pro \
4 CPU/cpu.pro \
5 GPIO/gpio.pro \
6 UART/uart.pro \
7 SPI/spi.pro \
8 I2C/i2c.pro \
9 SDCARD \
10 SDLCD
11
12
13
14
@@ -0,0 +1,452
1 #include <stdio.h>
2
3 void NMI_Handler(void)
4 {
5 printf("NMI_Handler\n");
6 }
7
8 void HardFault_Handler(void)
9 {
10 printf("HardFault_Handler\n");
11 }
12
13 void MemManage_Handler(void)
14 {
15 printf("MemManage_Handler\n");
16 }
17
18 void BusFault_Handler(void)
19 {
20 printf("BusFault_Handler\n");
21 }
22
23 void UsageFault_Handler(void)
24 {
25 printf("UsageFault_Handler\n");
26 }
27
28 void SVC_Handler(void)
29 {
30 printf("SVC_Handler\n");
31 }
32
33 void DebugMon_Handler(void)
34 {
35 printf("DebugMon_Handler\n");
36 }
37
38 void PendSV_Handler(void)
39 {
40 printf("PendSV_Handler\n");
41 }
42
43 void WWDG_IRQHandler(void)
44 {
45 printf("WWDG_IRQHandler\n");
46 }
47
48 void PVD_IRQHandler(void)
49 {
50 printf("PVD_IRQHandler\n");
51 }
52
53 void TAMP_STAMP_IRQHandler(void)
54 {
55 printf("TAMP_STAMP_IRQHandler\n");
56 }
57
58 void RTC_WKUP_IRQHandler(void)
59 {
60 printf("RTC_WKUP_IRQHandler\n");
61 }
62
63 void FLASH_IRQHandler(void)
64 {
65 printf("FLASH_IRQHandler\n");
66 }
67
68 void RCC_IRQHandler(void)
69 {
70 printf("RCC_IRQHandler\n");
71 }
72
73 void EXTI0_IRQHandler(void)
74 {
75 printf("EXTI0_IRQHandler\n");
76 }
77
78 void EXTI1_IRQHandler(void)
79 {
80 printf("EXTI1_IRQHandler\n");
81 }
82
83 void EXTI2_IRQHandler(void)
84 {
85 printf("EXTI2_IRQHandler\n");
86 }
87
88 void EXTI3_IRQHandler(void)
89 {
90 printf("EXTI3_IRQHandler\n");
91 }
92
93 void EXTI4_IRQHandler(void)
94 {
95 printf("EXTI4_IRQHandler\n");
96 }
97
98 void DMA1_Stream0_IRQHandler(void)
99 {
100 printf("DMA1_Stream0_IRQHandler\n");
101 }
102
103 void DMA1_Stream1_IRQHandler(void)
104 {
105 printf("DMA1_Stream1_IRQHandler\n");
106 }
107
108 void DMA1_Stream2_IRQHandler(void)
109 {
110 printf("DMA1_Stream2_IRQHandler\n");
111 }
112
113 void DMA1_Stream3_IRQHandler(void)
114 {
115 printf("DMA1_Stream3_IRQHandler\n");
116 }
117
118 void DMA1_Stream4_IRQHandler(void)
119 {
120 printf("DMA1_Stream4_IRQHandler\n");
121 }
122
123 void DMA1_Stream5_IRQHandler(void)
124 {
125 printf("DMA1_Stream5_IRQHandler\n");
126 }
127
128 void DMA1_Stream6_IRQHandler(void)
129 {
130 printf("DMA1_Stream6_IRQHandler\n");
131 }
132
133 void ADC_IRQHandler(void)
134 {
135 printf("ADC_IRQHandler\n");
136 }
137
138 void CAN1_TX_IRQHandler(void)
139 {
140 printf("CAN1_TX_IRQHandler\n");
141 }
142
143 void CAN1_RX0_IRQHandler(void)
144 {
145 printf("CAN1_RX0_IRQHandler\n");
146 }
147
148 void CAN1_RX1_IRQHandler(void)
149 {
150 printf("CAN1_RX1_IRQHandler\n");
151 }
152
153 void CAN1_SCE_IRQHandler(void)
154 {
155 printf("CAN1_SCE_IRQHandler\n");
156 }
157
158 void EXTI9_5_IRQHandler(void)
159 {
160 printf("EXTI9_5_IRQHandler\n");
161 }
162
163 void TIM1_BRK_TIM9_IRQHandler(void)
164 {
165 printf("TIM1_BRK_TIM9_IRQHandler\n");
166 }
167
168 void TIM1_UP_TIM10_IRQHandler(void)
169 {
170 printf("TIM1_UP_TIM10_IRQHandler\n");
171 }
172
173 void TIM1_TRG_COM_TIM11_IRQHandlerIM11(void)
174 {
175 printf("TIM1_TRG_COM_TIM11_IRQHandlerIM11");
176 }
177
178 void TIM1_CC_IRQHandler(void)
179 {
180 printf("TIM1_CC_IRQHandler\n");
181 }
182
183 void TIM2_IRQHandler(void)
184 {
185 printf("TIM2_IRQHandler\n");
186 }
187
188 void TIM3_IRQHandler(void)
189 {
190 printf("TIM3_IRQHandler\n");
191 }
192
193 void TIM4_IRQHandler(void)
194 {
195 printf("TIM4_IRQHandler\n");
196 }
197
198 void I2C1_EV_IRQHandler(void)
199 {
200 printf("I2C1_EV_IRQHandler\n");
201 }
202
203 void I2C1_ER_IRQHandler(void)
204 {
205 printf("I2C1_ER_IRQHandler\n");
206 }
207
208 void I2C2_EV_IRQHandler(void)
209 {
210 printf("I2C2_EV_IRQHandler\n");
211 }
212
213 void I2C2_ER_IRQHandler(void)
214 {
215 printf("I2C2_ER_IRQHandler\n");
216 }
217
218 void SPI1_IRQHandler(void)
219 {
220 printf("SPI1_IRQHandler\n");
221 }
222
223 void SPI2_IRQHandler(void)
224 {
225 printf("SPI2_IRQHandler\n");
226 }
227
228 void USART1_IRQHandler(void)
229 {
230 printf("USART1_IRQHandler\n");
231 }
232
233 void USART2_IRQHandler(void)
234 {
235 printf("USART2_IRQHandler\n");
236 }
237
238 void USART3_IRQHandler(void)
239 {
240 printf("USART3_IRQHandler\n");
241 }
242
243 void EXTI15_10_IRQHandler(void)
244 {
245 printf("EXTI15_10_IRQHandler\n");
246 }
247
248 void RTC_Alarm_IRQHandler(void)
249 {
250 printf("RTC_Alarm_IRQHandler\n");
251 }
252
253 void OTG_FS_WKUP_IRQHandler(void)
254 {
255 printf("OTG_FS_WKUP_IRQHandler\n");
256 }
257
258 void TIM8_BRK_TIM12_IRQHandler(void)
259 {
260 printf("TIM8_BRK_TIM12_IRQHandler\n");
261 }
262
263 void TIM8_UP_TIM13_IRQHandler(void)
264 {
265 printf("TIM8_UP_TIM13_IRQHandler\n");
266 }
267
268 void TIM8_TRG_COM_TIM14_IRQHandlerIM14(void)
269 {
270 printf("TIM8_TRG_COM_TIM14_IRQHandlerIM14");
271 }
272
273 void TIM8_CC_IRQHandler(void)
274 {
275 printf("TIM8_CC_IRQHandler\n");
276 }
277
278 void DMA1_Stream7_IRQHandler(void)
279 {
280 printf("DMA1_Stream7_IRQHandler\n");
281 }
282
283 void FSMC_IRQHandler(void)
284 {
285 printf("FSMC_IRQHandler\n");
286 }
287
288 void SDIO_IRQHandler(void)
289 {
290 printf("SDIO_IRQHandler\n");
291 }
292
293 void TIM5_IRQHandler(void)
294 {
295 printf("TIM5_IRQHandler\n");
296 }
297
298 void SPI3_IRQHandler(void)
299 {
300 printf("SPI3_IRQHandler\n");
301 }
302
303 void UART4_IRQHandler(void)
304 {
305 printf("UART4_IRQHandler\n");
306 }
307
308 void UART5_IRQHandler(void)
309 {
310 printf("UART5_IRQHandler\n");
311 }
312
313 void TIM6_DAC_IRQHandler(void)
314 {
315 printf("TIM6_DAC_IRQHandler\n");
316 }
317
318 void TIM7_IRQHandler(void)
319 {
320 printf("TIM7_IRQHandler\n");
321 }
322
323 void DMA2_Stream0_IRQHandler(void)
324 {
325 printf("DMA2_Stream0_IRQHandler\n");
326 }
327
328 void DMA2_Stream1_IRQHandler(void)
329 {
330 printf("DMA2_Stream1_IRQHandler\n");
331 }
332
333 void DMA2_Stream2_IRQHandler(void)
334 {
335 printf("DMA2_Stream2_IRQHandler\n");
336 }
337
338 void DMA2_Stream3_IRQHandler(void)
339 {
340 printf("DMA2_Stream3_IRQHandler\n");
341 }
342
343 void DMA2_Stream4_IRQHandler(void)
344 {
345 printf("DMA2_Stream4_IRQHandler\n");
346 }
347
348 void ETH_IRQHandler(void)
349 {
350 printf("ETH_IRQHandler\n");
351 }
352
353 void ETH_WKUP_IRQHandler(void)
354 {
355 printf("ETH_WKUP_IRQHandler\n");
356 }
357
358 void CAN2_TX_IRQHandler(void)
359 {
360 printf("CAN2_TX_IRQHandler\n");
361 }
362
363 void CAN2_RX0_IRQHandler(void)
364 {
365 printf("CAN2_RX0_IRQHandler\n");
366 }
367
368 void CAN2_RX1_IRQHandler(void)
369 {
370 printf("CAN2_RX1_IRQHandler\n");
371 }
372
373 void CAN2_SCE_IRQHandler(void)
374 {
375 printf("CAN2_SCE_IRQHandler\n");
376 }
377
378 void OTG_FS_IRQHandler(void)
379 {
380 printf("OTG_FS_IRQHandler\n");
381 }
382
383 void DMA2_Stream5_IRQHandler(void)
384 {
385 printf("DMA2_Stream5_IRQHandler\n");
386 }
387
388 void DMA2_Stream6_IRQHandler(void)
389 {
390 printf("DMA2_Stream6_IRQHandler\n");
391 }
392
393 void DMA2_Stream7_IRQHandler(void)
394 {
395 printf("DMA2_Stream7_IRQHandler\n");
396 }
397
398 void USART6_IRQHandler(void)
399 {
400 printf("USART6_IRQHandler\n");
401 }
402
403 void I2C3_EV_IRQHandler(void)
404 {
405 printf("I2C3_EV_IRQHandler\n");
406 }
407
408 void I2C3_ER_IRQHandler(void)
409 {
410 printf("I2C3_ER_IRQHandler\n");
411 }
412
413 void OTG_HS_EP1_OUT_IRQHandler(void)
414 {
415 printf("OTG_HS_EP1_OUT_IRQHandler\n");
416 }
417
418 void OTG_HS_EP1_IN_IRQHandler(void)
419 {
420 printf("OTG_HS_EP1_IN_IRQHandler\n");
421 }
422
423 void OTG_HS_WKUP_IRQHandler(void)
424 {
425 printf("OTG_HS_WKUP_IRQHandler\n");
426 }
427
428 void OTG_HS_IRQHandler(void)
429 {
430 printf("OTG_HS_IRQHandler\n");
431 }
432
433 void DCMI_IRQHandler(void)
434 {
435 printf("DCMI_IRQHandler\n");
436 }
437
438 void CRYP_IRQHandler(void)
439 {
440 printf("CRYP_IRQHandler\n");
441 }
442
443 void HASH_RNG_IRQHandler(void)
444 {
445 printf("HASH_RNG_IRQHandler\n");
446 }
447
448 void FPU_IRQHandler(void)
449 {
450 printf("FPU_IRQHandler\n");
451 }
452
@@ -0,0 +1,41
1 #
2 # qmake configuration for simulator
3 #
4
5 CONFIG +=
6 QMAKE_CC = gcc
7 QMAKE_CFLAGS += -g -O0
8 QMAKE_CFLAGS_DEPS += -M
9 QMAKE_CFLAGS_WARN_ON += -Wall
10 QMAKE_CFLAGS_WARN_OFF += -w
11 QMAKE_CFLAGS_RELEASE += -O2
12 QMAKE_CFLAGS_DEBUG +=
13
14 QMAKE_CXX = g++
15 QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s
16 QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS
17 QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON
18 QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF
19 QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
20 QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG
21 QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
22 QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB
23 QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC
24 QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS
25
26 QMAKE_LINK = gcc
27 QMAKE_LINK_SHLIB = gcc
28 QMAKE_LINK_C = gcc
29 QMAKE_LINK_C_SHLIB = gcc
30 QMAKE_LFLAGS += -g -O0
31 QMAKE_LFLAGS_RELEASE +=
32 QMAKE_LFLAGS_DEBUG +=
33 QMAKE_LFLAGS_APP +=
34 QMAKE_LFLAGS_SHLIB +=
35 QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB
36 QMAKE_LFLAGS_THREAD +=
37
38 QMAKE_AR = ar -ru
39 QMAKE_LIB = ar -ru
40 QMAKE_RANLIB =
41
@@ -0,0 +1,16
1
2
3 LIBS += -L$$[QT_INSTALL_LIBS]/$$UCMODEL
4 LIBS += -lcpu
5
6
7
8
9
10
11
12
13
14
15
16
@@ -0,0 +1,7
1
2
3 int main(void)
4 {
5 bsp_init();
6 libuc2_main_task();
7 }
@@ -0,0 +1,57
1 #
2 # qmake configuration for stm32f4
3 #
4 #
5
6
7 isEmpty(_simulator_conf){
8 _simulator_conf="oneshot"
9
10 QMAKE_CFLAGS= -std=c99
11
12 include(../common/simulator.conf)
13
14 DEFINES += \"assert_param(expr)=((void)0)\"
15 INCLUDEPATH += $$PWD /usr/include/SDL
16
17 DEFINES += BSP="\"\\\"$$BSP"\\\"\"
18
19 CONFIG += cpu
20
21 contains( TEMPLATE, app ) {
22 OBJECTS_DIR=obj-$$UCMODEL
23 DESTDIR=bin-$$UCMODEL
24 LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP
25 LIBS += -lbsp -lSDLCD -lSDL -lz -lm
26 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/simulator/startup.c
27 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/simulator/fs.c
28
29
30 INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP
31
32 }
33
34 contains( TEMPLATE, lib ) {
35 OBJECTS_DIR=obj-$$UCMODEL
36 DESTDIR=bin-$$UCMODEL
37 CONFIG+=staticlib
38 }
39
40 include(../common/libuc2libs.conf)
41
42 }
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@@ -0,0 +1,42
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the qmake spec of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 //#include "../linux-g++/qplatformdefs.h"
@@ -1,68 +1,65
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@member.fsf.org
21 #-------------------------------------------------------------------------------
21 #-------------------------------------------------------------------------------
22
22
23 ________
23 ________
24 licence:
24 licence:
25 ~~~~~~~~
25 ~~~~~~~~
26 Please note that all the files included inside the libuc2 are not written by me and for the libuc2. They are covered by their
26 Please note that all the files included inside the libuc2 are not written by me and for the libuc2. They are covered by their
27 own licence. If you reconize any of your code and you whant it to be removed from this library tell me.
27 own licence. If you reconize any of your code and you whant it to be removed from this library tell me.
28
28
29 ____________
29 ____________
30 Intallation:
30 Intallation:
31 ~~~~~~~~~~~~
31 ~~~~~~~~~~~~
32 To install the libuc2 you just need to copy the libuc2 folder where you whant then you need to:
32 To install the libuc2 you just need to copy the libuc2 folder where you whant then you need to:
33 -add the libuc2 binary folder to the PATH, with linux you can append this to the end of your /etc/bashrc file:
34 PATH=$PATH:/opt/libuc2/bin
35 replace /opt/ by the path where is installed the libuc2.
36 -set the libuc2 environement varriable, with linux you can append this to the end of your /etc/bashrc file:
33 -set the libuc2 environement varriable, with linux you can append this to the end of your /etc/bashrc file:
37 libuc2=/opt/libuc2
34 libuc2=/opt/libuc2
38 replace /opt/ by the path where is installed the libuc2.
35 replace /opt/ by the path where is installed the libuc2.
39
36
40 ______________
37 ______________
41 Contributions:
38 Contributions:
42 ~~~~~~~~~~~~~~
39 ~~~~~~~~~~~~~~
43 Feel free to modify everything in the libuc2, if you think that some of your improvement should be integrated in the
40 Feel free to modify everything in the libuc2, if you think that some of your improvement should be integrated in the
44 libuc2 you can send them to me at alexis.jeandet@lpp.polytechnique.fr or alexis.jeandet@gmail.fr.
41 libuc2 you can send them to me at alexis.jeandet@member.fsf.org or alexis.jeandet@gmail.fr.
45
42
46 ______________
43 ______________
47 Documentation:
44 Documentation:
48 ~~~~~~~~~~~~~~
45 ~~~~~~~~~~~~~~
49 You can find some documentation in the Doc folder. But as the libuc, the documentation is not already finished.
46 You can find some documentation in the Doc folder. But as the libuc, the documentation is not already finished.
50
47
51
48
52
49
53
50
54
51
55
52
56
53
57
54
58
55
59
56
60
57
61
58
62
59
63
60
64
61
65
62
66
63
67
64
68
65
@@ -1,506 +1,523
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 #include <core.h>
31 #include <core.h>
32 #include <terminal.h>
32 #include <terminal.h>
33
33
34 uint32_t OSC0 =8000000;
34 uint32_t OSC0 =8000000;
35 uint32_t INTOSC =16000000;
35 uint32_t INTOSC =16000000;
36 uint32_t RTCOSC =32768;
36 uint32_t RTCOSC =32768;
37 uint32_t currentCpuFreq=0;
37 uint32_t currentCpuFreq=0;
38 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
38 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
39
39
40 LCD_IF_t lcdIF0={
40 LCD_IF_t lcdIF0={
41 .init = &bsp_FSMC_init,
41 .init = &bsp_FSMC_init,
42 .writereg = &bsp_lcd0_write_reg,
42 .writereg = &bsp_lcd0_write_reg,
43 .readreg = &bsp_lcd0_read_reg,
43 .readreg = &bsp_lcd0_read_reg,
44 .writeGRAM = &bsp_lcd0_writeGRAM,
44 .writeGRAM = &bsp_lcd0_writeGRAM,
45 .readGRAM = &bsp_lcd0_readGRAM
45 .readGRAM = &bsp_lcd0_readGRAM
46 };
46 };
47
47
48 LCD_t lcd0={
48 LCD_t lcd0={
49 .interface = &lcdIF0,
49 .interface = &lcdIF0,
50 .init = &ili9328init,
50 .init = &ili9328init,
51 .paint = &ili9328paint,
51 .paint = &ili9328paint,
52 .paintText = &ili9328paintText,
52 .paintText = &ili9328paintText,
53 .paintFilRect = &ili9328paintFilRect,
53 .paintFilRect = &ili9328paintFilRect,
54 .refreshenable = &ili9328refreshenable,
54 .refreshenable = &ili9328refreshenable,
55 .width= 240,
55 .width= 240,
56 .height = 320
56 .height = 320
57 };
57 };
58
58
59 terminal_t terminal0;
59 terminal_t terminal0;
60
60
61 volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000;
61 volatile uint8_t* lcd0_CMD=(volatile uint8_t*) 0x60000000;
62 volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0);
62 volatile uint8_t* lcd0_DATA=(volatile uint8_t*)(0x61FFFFF0);
63
63
64 float VREF0 =(float)3.3;
64 float VREF0 =(float)3.3;
65 volatile vs10XXDev audioCodec0;
65 volatile vs10XXDev audioCodec0;
66
66
67 sdcardDev sdcard2;
67 sdcardDev sdcard2;
68 blkdevice sdcard2blkdev;
68 blkdevice sdcard2blkdev;
69 dikpartition sdcard2Part1;
69 dikpartition sdcard2Part1;
70 FAT32fs sdcard2FAT32part1;
70 FAT32fs sdcard2FAT32part1;
71 dikpartition sdcard2Part2;
71 dikpartition sdcard2Part2;
72 FAT32fs sdcard2FAT32part2;
72 FAT32fs sdcard2FAT32part2;
73 dikpartition sdcard2Part3;
73 dikpartition sdcard2Part3;
74 FAT32fs sdcard2FAT32part3;
74 FAT32fs sdcard2FAT32part3;
75 dikpartition sdcard2Part4;
75 dikpartition sdcard2Part4;
76 FAT32fs sdcard2FAT32part4;
76 FAT32fs sdcard2FAT32part4;
77
77
78 int bsp_init()
78 int bsp_init()
79 {
79 {
80 int i=0;
80 int i=0;
81 for(i=0;i<__MAX_OPENED_FILES__;i++)
81 for(i=0;i<__MAX_OPENED_FILES__;i++)
82 {
82 {
83 __opnfiles__[i] = NULL;
83 __opnfiles__[i] = NULL;
84 }
84 }
85 bsp_GPIO_init();
85 bsp_GPIO_init();
86 bsp_uart_init();
86 bsp_uart_init();
87 bsp_iic_init();
87 bsp_iic_init();
88 bsp_FSMC_init();
88 bsp_FSMC_init();
89 bsp_GTerm_init();
89 bsp_GTerm_init();
90 bsp_spi_init();
90 bsp_spi_init();
91 bsp_SD_init();
91 bsp_SD_init();
92 bsp_Audio_init();
92 bsp_Audio_init();
93 printf("\r=====================\n\r");
93 printf("\r=====================\n\r");
94 printf( "=====================\n\r");
94 printf( "=====================\n\r");
95 printf(BSP);
95 printf(BSP);
96 printf(" initialised\n\r");
96 printf(" initialised\n\r");
97 printf( "=====================\n\r");
97 printf( "=====================\n\r");
98 return 1;
98 return 1;
99 }
99 }
100
100
101 void bsp_GPIO_init()
101 void bsp_GPIO_init()
102 {
102 {
103 gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS};
103 gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS};
104 for(int i=0;i<8;i++)
104 for(int i=0;i<8;i++)
105 {
105 {
106 gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]);
106 gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]);
107 GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype;
107 GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype;
108 gpiosetconfig(&GPIO_init);
108 gpiosetconfig(&GPIO_init);
109 }
109 }
110 gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3};
110 gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3};
111 for(int i=0;i<3;i++)
111 for(int i=0;i<3;i++)
112 {
112 {
113 gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]);
113 gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]);
114 GPIO_init |= gpiohighspeed | gpioindir;
114 GPIO_init |= gpiohighspeed | gpioindir;
115 gpiosetconfig(&GPIO_init);
115 gpiosetconfig(&GPIO_init);
116 }
116 }
117 gpioclr(VS1053xRESET);
117 gpioclr(VS1053xRESET);
118 gpioset(VS1053xCS);
118 gpioset(VS1053xCS);
119 gpioset(VS1053xDCS);
119 gpioset(VS1053xDCS);
120 gpioset(SDCARD2CS);
120 gpioset(SDCARD2CS);
121 gpioclr(LCD_RESET);
121 gpioclr(LCD_RESET);
122 gpioclr(LCD_BACKL);
122 gpioclr(LCD_BACKL);
123 }
123 }
124
124
125 void bsp_uart_init()
125 void bsp_uart_init()
126 {
126 {
127
127 // if(__opnfiles__[1]==NULL)
128 // {
129 // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t));
130 // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
131 // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1);
132 // uartmkstreamdev(uart,fd1);
133 // __opnfiles__[1] = fd1;
134 // }
135 // else
136 // {
137 // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1);
138 // }
128 }
139 }
129
140
130 /*
141 /*
131 D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7
142 D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7
132 D5 PE8 D6 PE9 D7 PE10
143 D5 PE8 D6 PE9 D7 PE10
133 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S
144 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S
134 FSMC_NOE PD4 RD
145 FSMC_NOE PD4 RD
135 */
146 */
136
147
137 int bsp_FSMC_init()
148 int bsp_FSMC_init()
138 {
149 {
139 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
150 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
140 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
151 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
141
152
142 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
153 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
143 ,PD4,PD5,PD7,PE4};
154 ,PD4,PD5,PD7,PE4};
144 for(int i=0;i<12;i++)
155 for(int i=0;i<12;i++)
145 {
156 {
146 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
157 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
147 LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
158 LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
148 gpiosetconfig(&LCD_DBx);
159 gpiosetconfig(&LCD_DBx);
149 GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC);
160 GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC);
150 }
161 }
151
162
152 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
163 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
153 FSMC_NORSRAMTimingInitTypeDef p;
164 FSMC_NORSRAMTimingInitTypeDef p;
154
165
155 /* Enable FSMC clock */
166 /* Enable FSMC clock */
156 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
167 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
157
168
158 /*-- FSMC Configuration ------------------------------------------------------*/
169 /*-- FSMC Configuration ------------------------------------------------------*/
159 /*----------------------- SRAM Bank 3 ----------------------------------------*/
170 /*----------------------- SRAM Bank 3 ----------------------------------------*/
160 /* FSMC_Bank1_NORSRAM4 configuration */
171 /* FSMC_Bank1_NORSRAM4 configuration */
161 //p.FSMC_AddressSetupTime = 5;
172 //p.FSMC_AddressSetupTime = 5;
162 //p.FSMC_AddressSetupTime = 1;
173 //p.FSMC_AddressSetupTime = 1;
163 p.FSMC_AddressSetupTime = 3;
174 p.FSMC_AddressSetupTime = 3;
164 p.FSMC_AddressHoldTime = 3;
175 p.FSMC_AddressHoldTime = 3;
165 //p.FSMC_DataSetupTime = 9;
176 //p.FSMC_DataSetupTime = 9;
166 //ili9328 -> data setup time > 10ns
177 //ili9328 -> data setup time > 10ns
167 p.FSMC_DataSetupTime = 1;
178 p.FSMC_DataSetupTime = 1;
168 if(getCpuFreq()>100*1000*1000)
179 if(getCpuFreq()>100*1000*1000)
169 p.FSMC_DataSetupTime = 2;// 11;
180 p.FSMC_DataSetupTime = 2;// 11;
170 p.FSMC_BusTurnAroundDuration = 0;
181 p.FSMC_BusTurnAroundDuration = 0;
171 p.FSMC_CLKDivision = 0;
182 p.FSMC_CLKDivision = 0;
172 p.FSMC_DataLatency = 0;
183 p.FSMC_DataLatency = 0;
173 //ili9328 -> data hold time > 15ns
184 //ili9328 -> data hold time > 15ns
174 if(getCpuFreq()>66*1000*1000)
185 if(getCpuFreq()>66*1000*1000)
175 p.FSMC_DataLatency = 0;
186 p.FSMC_DataLatency = 1;
176 p.FSMC_AccessMode = FSMC_AccessMode_A;
187 p.FSMC_AccessMode = FSMC_AccessMode_A;
177
188
178 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
189 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
179 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
190 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
180 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
191 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
181 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
192 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
182 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
193 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
183 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
194 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
184 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
195 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
185 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
196 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
186 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
197 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
187 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
198 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
188 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
199 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
189 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
200 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
190 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
201 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
191 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
202 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
192 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
203 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
193
204
194 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
205 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
195
206
196 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
207 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
197 gpioset(LCD_RESET);
208 gpioset(LCD_RESET);
198 gpioclr(LCD_RESET);
209 gpioclr(LCD_RESET);
199 delay_100us(500);
210 delay_100us(500);
200 gpioset(LCD_RESET);
211 gpioset(LCD_RESET);
201 delay_100us(500);
212 delay_100us(500);
202 lcd0.init(&lcd0);
213 lcd0.init(&lcd0);
203 gpioset(LCD_BACKL);
214 gpioset(LCD_BACKL);
204 return 1;
215 return 1;
205 }
216 }
206
217
207 void bsp_spi_init()
218 void bsp_spi_init()
208 {
219 {
209 gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO};
220 gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO};
210 for(int i=0;i<3;i++)
221 for(int i=0;i<3;i++)
211 {
222 {
212 gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]);
223 gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]);
213 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
224 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
214 gpiosetconfig(&SPI_DBx);
225 gpiosetconfig(&SPI_DBx);
215 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1);
226 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1);
216 }
227 }
217 spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1);
228 spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1);
218
229
219 gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO};
230 gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO};
220 for(int i=0;i<3;i++)
231 for(int i=0;i<3;i++)
221 {
232 {
222 gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]);
233 gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]);
223 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
234 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
224 gpiosetconfig(&SPI_DBx);
235 gpiosetconfig(&SPI_DBx);
225 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3);
236 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3);
226 }
237 }
227 spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1);
238 spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1);
228
239
229 }
240 }
230
241
231
242
232 void bsp_iic_init()
243 void bsp_iic_init()
233 {
244 {
234 // i2copenandconfig(i2c2,0,10000,PF0,PF1);
245 // i2copenandconfig(i2c2,0,10000,PF0,PF1);
235 }
246 }
236
247
237
248
238 void bsp_Audio_init()
249 void bsp_Audio_init()
239 {
250 {
240 vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ);
251 vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ);
241 if(audioCodec0.VERSION!=UNKNOWN)
252 if(audioCodec0.VERSION!=UNKNOWN)
242 {
253 {
243 printf("detected Audio codec ");
254 printf("detected Audio codec ");
244 switch (audioCodec0.VERSION) {
255 switch (audioCodec0.VERSION) {
245 case VS1001:
256 case VS1001:
246 printf("VS1001\n");
257 printf("VS1001\n");
247 break;
258 break;
248 case VS1011:
259 case VS1011:
249 printf("VS1011\n");
260 printf("VS1011\n");
250 break;
261 break;
251 case VS1002:
262 case VS1002:
252 printf("VS1002\n");
263 printf("VS1002\n");
253 break;
264 break;
254 case VS1003:
265 case VS1003:
255 printf("VS1003\n");
266 printf("VS1003\n");
256 break;
267 break;
257 case VS1053:
268 case VS1053:
258 printf("VS1053\n");
269 printf("VS1053\n");
259 break;
270 break;
260 case VS1033:
271 case VS1033:
261 printf("VS1033\n");
272 printf("VS1033\n");
262 break;
273 break;
263 case VS1103:
274 case VS1103:
264 printf("VS1103\n");
275 printf("VS1103\n");
265 break;
276 break;
266 default:
277 default:
267 printf("Unknown device\n");
278 printf("Unknown device\n");
268 break;
279 break;
269 }
280 }
270 }
281 }
271 }
282 }
272
283
273 void bsp_SD_init()
284 void bsp_SD_init()
274 {
285 {
275 if(bspsdcardpresent())
286 if(bspsdcardpresent())
276 {
287 {
277 sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed);
288 sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed);
278 sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected);
289 sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected);
279 if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT)
290 if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT)
280 {
291 {
281 if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr)
292 if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr)
282 {
293 {
283 if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1))
294 if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1))
284 printf("Can't open fat32 partition 1\n");
295 printf("Can't open fat32 partition 1\n");
285 }
296 }
286 else
297 else
287 {
298 {
288 printf("Can't open or read MBR\n");
299 printf("Can't open or read MBR\n");
289 }
300 }
290
301
291 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
302 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
292 {
303 {
293 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
304 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
294 printf("Can't open fat32 partition 2\n");
305 printf("Can't open fat32 partition 2\n");
295 }
306 }
296 else
307 else
297 {
308 {
298 printf("Can't open or read MBR\n");
309 printf("Can't open or read MBR\n");
299 }
310 }
300
311
301 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
312 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
302 {
313 {
303 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
314 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
304 printf("Can't open fat32 partition 3\n");
315 printf("Can't open fat32 partition 3\n");
305 }
316 }
306 else
317 else
307 {
318 {
308 printf("Can't open or read MBR\n");
319 printf("Can't open or read MBR\n");
309 }
320 }
310
321
311 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
322 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
312 {
323 {
313 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
324 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
314 printf("Can't open fat32 partition 4\n");
325 printf("Can't open fat32 partition 4\n");
315 }
326 }
316 else
327 else
317 {
328 {
318 printf("Can't open or read MBR\n");
329 printf("Can't open or read MBR\n");
319 }
330 }
320 }
331 }
321 else
332 else
322 {
333 {
323 printf("Can't initialize SDCARD\n");
334 printf("Can't initialize SDCARD\n");
324 }
335 }
325 }
336 }
326 }
337 }
327
338
328 void vs1052setXCS(char val)
339 void vs1052setXCS(char val)
329 {
340 {
330 gpiosetval(VS1053xCS,(int)val);
341 gpiosetval(VS1053xCS,(int)val);
331 }
342 }
332
343
333 void vs1052setXDCS(char val)
344 void vs1052setXDCS(char val)
334 {
345 {
335 //gpiosetval(LED1,(int)val);
346 //gpiosetval(LED1,(int)val);
336 gpiosetval(VS1053xDCS,(int)val);
347 gpiosetval(VS1053xDCS,(int)val);
337 }
348 }
338
349
339 void vs1052setRST(char val)
350 void vs1052setRST(char val)
340 {
351 {
341 if(val)
352 if(val)
342 gpioset(VS1053xRESET);
353 gpioset(VS1053xRESET);
343 else
354 else
344 gpioclr(VS1053xRESET);
355 gpioclr(VS1053xRESET);
345 }
356 }
346
357
347 int vs10XXDREQ()
358 int vs10XXDREQ()
348 {
359 {
349 return gpiogetval(VS1053DREQ);
360 return gpiogetval(VS1053DREQ);
350 }
361 }
351
362
352
363
353 void bsppowersdcard(char onoff) //always ON
364 void bsppowersdcard(char onoff) //always ON
354 {
365 {
355
366
356 }
367 }
357
368
358 char bspsdcardpresent()
369 char bspsdcardpresent()
359 {
370 {
360 return gpiogetval(SDCARD2CD);
371 return gpiogetval(SDCARD2CD);
361 }
372 }
362
373
363 char bspsdcardwriteprotected()
374 char bspsdcardwriteprotected()
364 {
375 {
365 return 0;
376 return 0;
366 }
377 }
367
378
368 void bspsdcardselect(char YESNO)
379 void bspsdcardselect(char YESNO)
369 {
380 {
370 // gpiosetval(LED1,(int)YESNO);
381 // gpiosetval(LED1,(int)YESNO);
371 if(YESNO)
382 if(YESNO)
372 gpioclr(SDCARD2CS);
383 gpioclr(SDCARD2CS);
373 else
384 else
374 gpioset(SDCARD2CS);
385 gpioset(SDCARD2CS);
375 }
386 }
376
387
377
388
378 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
389 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
379 {
390 {
380 uint8_t* pt8 = (uint8_t*)(void*)&reg;
391 uint8_t* pt8 = (uint8_t*)(void*)&reg;
381 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
392 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
382 *lcd0_CMD=pt8[3];
393 *lcd0_CMD=pt8[3];
383 *lcd0_CMD=pt8[2];
394 *lcd0_CMD=pt8[2];
384 pt8 = (uint8_t*)(void*)&data;
395 pt8 = (uint8_t*)(void*)&data;
385 *lcd0_DATA=pt8[3];
396 *lcd0_DATA=pt8[3];
386 *lcd0_DATA=pt8[2];
397 *lcd0_DATA=pt8[2];
387 #else
398 #else
388 *lcd0_CMD=pt8[1];
399 *lcd0_CMD=pt8[1];
389 *lcd0_CMD=pt8[0];
400 *lcd0_CMD=pt8[0];
390 pt8 = (uint8_t*)(void*)&data;
401 pt8 = (uint8_t*)(void*)&data;
391 *lcd0_DATA=pt8[1];
402 *lcd0_DATA=pt8[1];
392 *lcd0_DATA=pt8[0];
403 *lcd0_DATA=pt8[0];
393 #endif
404 #endif
394
405
395 }
406 }
396
407
397 uint32_t bsp_lcd0_read_reg(uint32_t reg)
408 uint32_t bsp_lcd0_read_reg(uint32_t reg)
398 {
409 {
399 uint8_t* pt8 = (uint8_t*)(void*)&reg;
410 uint8_t* pt8 = (uint8_t*)(void*)&reg;
400 uint32_t DATA=0;
411 uint32_t DATA=0;
401 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
412 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
402 *lcd0_CMD=pt8[3];
413 *lcd0_CMD=pt8[3];
403 *lcd0_CMD=pt8[2];
414 *lcd0_CMD=pt8[2];
404 pt8 = (uint8_t*)(void*)&DATA;
415 pt8 = (uint8_t*)(void*)&DATA;
405 pt8[3]=*lcd0_DATA;
416 pt8[3]=*lcd0_DATA;
406 pt8[2]=*lcd0_DATA;
417 pt8[2]=*lcd0_DATA;
407 #else
418 #else
408
419
409 *lcd0_CMD=pt8[1];
420 *lcd0_CMD=pt8[1];
410 *lcd0_CMD=pt8[0];
421 *lcd0_CMD=pt8[0];
411 pt8 = (uint8_t*)(void*)&DATA;
422 pt8 = (uint8_t*)(void*)&DATA;
412 pt8[1]=*lcd0_DATA;
423 pt8[1]=*lcd0_DATA;
413 pt8[0]=*lcd0_DATA;
424 pt8[0]=*lcd0_DATA;
414 #endif
425 #endif
415
426
416 return DATA;
427 return DATA;
417 }
428 }
418
429
419 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
430 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
420 {
431 {
421 uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
432 uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
422 uint8_t* pt8 = (uint8_t*)(void*)&reg;
433 uint8_t* pt8 = (uint8_t*)(void*)&reg;
423 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
434 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
424 *lcd0_CMD=pt8[3];
435 *lcd0_CMD=pt8[3];
425 *lcd0_CMD=pt8[2];
436 *lcd0_CMD=pt8[2];
426 pt8 = (uint8_t*)(void*)buffer;
437 pt8 = (uint8_t*)(void*)buffer;
427 for(int i=0;i<(int)count;i++)
438 for(int i=0;i<(int)count;i++)
428 {
439 {
429 *lcd0_DATA=pt8[(2*i) +1];
440 *lcd0_DATA=pt8[(2*i) +1];
430 *lcd0_DATA=pt8[2*i];
441 *lcd0_DATA=pt8[2*i];
431 }
442 }
432 #else
443 #else
433
444
434 *lcd0_CMD=pt8[1];
445 *lcd0_CMD=pt8[1];
435 *lcd0_CMD=pt8[0];
446 *lcd0_CMD=pt8[0];
436 pt8 = (uint8_t*)(void*)buffer;
447 pt8 = (uint8_t*)(void*)buffer;
437 for(int i=0;i<(int)count;i++)
448 for(int i=0;i<(int)count;i++)
438 {
449 {
439
450
440 *lcd0_DATA=pt8[(2*i) +1];
451 *lcd0_DATA=pt8[(2*i) +1];
441 *lcd0_DATA=pt8[2*i];
452 *lcd0_DATA=pt8[2*i];
442 }
453 }
443 #endif
454 #endif
444 }
455 }
445
456
446 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
457 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
447 {
458 {
448 uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
459 // uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
449 uint8_t* pt8 = (uint8_t*)(void*)&reg;
460 // int8_t* pt8 = (int8_t*)(void*)&reg;
450 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
461 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
451 *lcd0_CMD=pt8[3];
462 *lcd0_CMD=pt8[3];
452 *lcd0_CMD=pt8[2];
463 *lcd0_CMD=pt8[2];
453 pt8 = (uint8_t*)(void*)buffer;
464 pt8 = (uint8_t*)(void*)buffer;
454 pt8[0] = *lcd0_DATA;
455 pt8[0] = *lcd0_DATA;
456 for(int i=0;i<(int)count;i++)
465 for(int i=0;i<(int)count;i++)
457 {
466 {
458 pt8[(2*i) +1]=*lcd0_DATA;
467 pt8[(2*i) +1]=*lcd0_DATA;
468 __asm__("nop");
469 __asm__("nop");
470 __asm__("nop");
471 __asm__("nop");
472 __asm__("nop");
459 pt8[2*i]=*lcd0_DATA;
473 pt8[2*i]=*lcd0_DATA;
460 }
474 }
461 #else
475 #else
462
476 // lcd0_CMD=pt8[1];
463 *lcd0_CMD=pt8[1];
477 // lcd0_CMD=pt8[0];
464 *lcd0_CMD=pt8[0];
478 // pt8 = (int8_t*)(void*)buffer;
465 pt8 = (uint8_t*)(void*)buffer;
479 // for(int i=0;i<(int)count;i++)
466 pt8[0] = *lcd0_DATA;
480 // {
467 pt8[0] = *lcd0_DATA;
481 // pt8[(2*i) +1]=*lcd0_DATA;
468 for(int i=0;i<(int)count;i++)
482 // __asm__("nop");
469 {
483 // __asm__("nop");
470 pt8[(2*i) +1]=*lcd0_DATA;
484 // __asm__("nop");
471 pt8[2*i]=*lcd0_DATA;
485 // __asm__("nop");
472 }
486 // __asm__("nop");
487 // pt8[2*i]=*lcd0_DATA;
488 //pt8[(2*i) +1]=(uint8_t)0;
489 //pt8[(2*i)]=(uint8_t)0;
490 // }
473 #endif
491 #endif
474 }
492 }
475
493
476 void bsp_GTerm_init()
494 void bsp_GTerm_init()
477 {
495 {
478 if(__opnfiles__[1]==NULL)
496 if(__opnfiles__[1]==NULL)
479 {
497 {
480 //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t));
481 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
498 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
482 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1);
499 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1);
483 __opnfiles__[1] = fd1;
500 __opnfiles__[1] = fd1;
484 }
501 }
485 else
502 else
486 {
503 {
487
504
488 }
505 }
489 }
506 }
490
507
491
508
492
509
493
510
494
511
495
512
496
513
497
514
498
515
499
516
500
517
501
518
502
519
503
520
504
521
505
522
506
523
@@ -1,3 +1,3
1 CPU=stm32f4xxxG
1 CPU=stm32f4xxxG
2 DEFINES+=BSP=\\\"SOLAR_LFR_PSU\\\"
2 DEFINES+=BSP=\\\"STM32F4Discovery\\\"
3 UCMODEL=stm32f4
3 UCMODEL=stm32f4
@@ -1,17 +1,18
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3 SUBDIRS += STM32F4Discovery \
3 SUBDIRS += STM32F4Discovery \
4 M4Stick \
4 M4Stick \
5 M4StickV2 \
5 M4StickV2 \
6 SOLAR_LFR_PSU \
6 SOLAR_LFR_PSU \
7 BEAGLESYNTH \
7 BEAGLESYNTH \
8 STM32F4Eval \
8 STM32F4Eval \
9 STM32F4Discovery-EXT \
9 STM32F4Discovery-EXT \
10 OPLAYER
10 OPLAYER \
11 SIMULATOR
11
12
12
13
13
14
14
15
15
16
16
17
17
18
@@ -1,12 +1,14
1 TEMPLATE = app
1 TEMPLATE = app
2 CONFIG += cpu
2 CONFIG += cpu
3
3
4
4
5 UCMODEL=stm32f4
5 UCMODEL=stm32f4
6 BSP = OPLAYER
6 BSP = OPLAYER
7
7
8 DEFINES += CPUFREQ=160000000
8 DEFINES += CPUFREQ=180000000
9
9
10
10 SOURCES += \
11 SOURCES += \
11 main.c
12 main.c \
13 test_lcd.c
12
14
@@ -1,182 +1,206
1 #include <stdio.h>
1 #include <stdio.h>
2 #include <fat32.h>
2 #include <fat32.h>
3 #include <gpio.h>
3 #include <gpio.h>
4 #include <uart.h>
4 #include <uart.h>
5 #include <stm32f4xx.h>
5 #include <stm32f4xx.h>
6 #include <bsp.h>
6 #include <bsp.h>
7 #include <core.h>
7 #include <core.h>
8 #include <VS10XX.h>
8 #include <VS10XX.h>
9 #include <bsp.h>
9 #include <bsp.h>
10 #include <spi.h>
10 #include <spi.h>
11 #include <sdcard.h>
11 #include <sdcard.h>
12 #include <sdcard-spi.h>
12 #include <sdcard-spi.h>
13 #include <fat32.h>
13 #include <fat32.h>
14 #include <ucdirent.h>
14 #include <ucdirent.h>
15 #include <string.h>
15 #include <string.h>
16 #include <terminal.h>
16 #include <terminal.h>
17 #include <ili9328.h>
17
18
18
19
19 extern streamdevice* __opnfiles__[];
20 extern streamdevice* __opnfiles__[];
21 extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color);
20 char buffer[512];
22 char buffer[512];
21
23
22 void randBoxesDemo()
24 void randBoxesDemo()
23 {
25 {
24 int16_t x,y,w,h,t,r;
26 int16_t x,y,w,h,t,r;
25 x=rand()%240;
27 x=rand()%240;
26 y=rand()%320;
28 y=rand()%320;
27 w=rand()%(240-x);
29 w=rand()%(240-x);
28 if(x>y)
30 if(x>y)
29 r=(rand()%(y))%(320-y);
31 r=(rand()%(y))%(320-y);
30 else
32 else
31 r=(rand()%(x))%(240-x);
33 r=(rand()%(x))%(240-x);
32 h=rand()%(320-y);
34 h=rand()%(320-y);
33 t=rand()%(10);
35 t=rand()%(10);
34 ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
36 ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
35 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
37 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
36 //delay_100us(10);
38 //delay_100us(10);
37 //for(volatile int i=0;i<(1024*2);i++);
39 //for(volatile int i=0;i<(1024*2);i++);
38 }
40 }
39 void tryToplay1()
40 {
41
41
42 extern FAT32fs sdcard2FAT32part1;
42 void randTextDemo()
43 extern volatile vs10XXDev audioCodec0;
43 {
44 ucdirent root;
44 int16_t x,y,w,h,t,r;
45 char direntName[]=" \n";
45 char buf[2];
46 uint32_t fileLba,nextLba;
46 buf[1]='\0';
47 int i=0;
47 x=rand()%240;
48 spisetspeed(audioCodec0.SPIdev,2000000);
48 y=rand()%320;
49 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root))
49 if(x>y)
50 {
50 r=(rand()%(y))%(320-y);
51 if(DIRENT_noErr==fat32getrootfirstent(&root))
51 else
52 {
52 r=(rand()%(x))%(240-x);
53 do{
53 h=rand()%(320-y);
54 fat32getdirentname(&root,direntName);
54 buf[0]=rand()%(255);
55 printf("%s\n",direntName);
55 //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
56 nextLba=fat32getdirentlba(&root);
56 ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand());
57 printf("Streaming File\n");
57 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
58 do
58 delay_100us(5000);
59 {
59 //for(volatile int i=0;i<(1024*2);i++);
60 fileLba = nextLba;
61 if(sdcard2FAT32part1.part->phy->read(sdcard2FAT32part1.part->phy,buffer,fileLba,1)==RES_OK)
62 {
63 for(i=0;i<512;i+=32)
64 {
65 vs10XXstream32bytes(&audioCodec0,buffer+i);
66 }
67 }
68 }while ((fat32nextsectorlba(&sdcard2FAT32part1,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3)));
69 //vs10XXsoftReset(&audioCodec0);
70 while (gpiogetval(BP3))delay_100us(1000);
71 printf("looking for next file\n");
72 }while (DIRENT_noErr==fat32nextdirent(&root));
73 }
74 }
75 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root))
76 {
77 if(DIRENT_noErr==fat32getrootfirstent(&root))
78 {
79 fat32getdirentname(&root,direntName);
80 printf("%s\n",direntName);
81 nextLba=fat32getdirentlba(&root);
82 printf("Streaming File\n");
83 do
84 {
85 fileLba = nextLba;
86 if(sdcard2FAT32part2.part->phy->read(sdcard2FAT32part2.part->phy,buffer,fileLba,1)==RES_OK)
87 {
88 for(i=0;i<512;i+=32)
89 {
90 vs10XXstream32bytes(&audioCodec0,buffer+i);
91 }
92 }
93 }while ((fat32nextsectorlba(&sdcard2FAT32part2,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3)));
94 while (gpiogetval(BP3))delay_100us(1000);
95 }
96 }
97 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part3,&root))
98 {
99 if(DIRENT_noErr==fat32getrootfirstent(&root))
100 {
101 fat32getdirentname(&root,direntName);
102 printf("%s\n",direntName);
103 nextLba=fat32getdirentlba(&root);
104 printf("Streaming File\n");
105 do
106 {
107 fileLba = nextLba;
108 if(sdcard2FAT32part3.part->phy->read(sdcard2FAT32part3.part->phy,buffer,fileLba,1)==RES_OK)
109 {
110 for(i=0;i<512;i+=32)
111 {
112 vs10XXstream32bytes(&audioCodec0,buffer+i);
113 }
114 }
115 }while ((fat32nextsectorlba(&sdcard2FAT32part3,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3)));
116 while (gpiogetval(BP3))delay_100us(1000);
117 }
118 }
119 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part4,&root))
120 {
121 if(DIRENT_noErr==fat32getrootfirstent(&root))
122 {
123 fat32getdirentname(&root,direntName);
124 printf("%s\n",direntName);
125 nextLba=fat32getdirentlba(&root);
126 printf("Streaming File\n");
127 do
128 {
129 fileLba = nextLba;
130 if(sdcard2FAT32part4.part->phy->read(sdcard2FAT32part4.part->phy,buffer,fileLba,1)==RES_OK)
131 {
132 for(i=0;i<512;i+=32)
133 {
134 vs10XXstream32bytes(&audioCodec0,buffer+i);
135 }
136 }
137 }while ((fat32nextsectorlba(&sdcard2FAT32part4,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3)));
138 while (gpiogetval(BP3))delay_100us(1000);
139 }
140 }
141 }
60 }
61
142 void tryToplay2()
62 void tryToplay2()
143 {
63 {
144
64
145 extern blkdevice sdcard2blkdev;
65 extern blkdevice sdcard2blkdev;
146 int i=0,l=0;
66 int i=0,l=0;
147
67
148 spisetspeed(audioCodec0.SPIdev,4000000);
68 spisetspeed(audioCodec0.SPIdev,4000000);
149 printf("Streaming File\n");
69 printf("Streaming File\n");
150
70
151 //printf("New LBA=0x%X\n",nextLba);
71 //printf("New LBA=0x%X\n",nextLba);
152
72
153 while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK)
73 while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK)
154 {
74 {
155
75
156 for(i=0;i<512;i+=32)
76 for(i=0;i<512;i+=32)
157 {
77 {
158 vs10XXstream32bytes(&audioCodec0,buffer+i);
78 vs10XXstream32bytes(&audioCodec0,buffer+i);
159 }
79 }
160 }
80 }
161 }
81 }
162
82
83 void playFile(ucdirent* file,FAT32fs* part)
84 {
85 extern volatile vs10XXDev audioCodec0;
86 char direntName[]=" \n";
87 uint32_t fileLba,nextLba;
88 int i=0;
89 fat32getdirentname(file,direntName);
90 gpioset(LCD_BACKL);
91 //printf("%s\n",direntName);
92 nextLba=fat32getdirentlba(file);
93 //printf("Streaming File\n");
94 gpioclr(LCD_BACKL);
95 do
96 {
97 fileLba = nextLba;
98 if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK)
99 {
100 for(i=0;i<512;i+=32)
101 {
102 vs10XXstream32bytes(&audioCodec0,buffer+i);
103 }
104 }
105 }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3)));
106 vs10XXsoftReset(&audioCodec0);
107 while (gpiogetval(BP3))delay_100us(1000);
108 }
109
110 void playAllparts()
111 {
112 extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4;
113 ucdirent root;
114 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root))
115 {
116 printf("Reading on SDCARD2 part1\n");
117 if(DIRENT_noErr==fat32getrootfirstent(&root))
118 {
119 do{
120 playFile(&root,&sdcard2FAT32part1);
121 }while (DIRENT_noErr==fat32nextdirent(&root));
122 }
123 }
124 gpioset(LED2);
125 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root))
126 {
127 printf("Reading on SDCARD2 part2\n");
128 if(DIRENT_noErr==fat32getrootfirstent(&root))
129 {
130 do{
131 playFile(&root,&sdcard2FAT32part2);
132 }while (DIRENT_noErr==fat32nextdirent(&root));
133 }
134 }
135 }
136
163 int main()
137 int main()
164 {
138 {
139 int i=0;
140 int color=0;
141 for(i=0;i<240;i++)
142 {
143 if(i>(240/3))
144 {
145 color= (i<<5) + 0x1F;
146 }
147 else
148 {
149 color = i;
150 }
151 if(i>(2*240/3))
152 {
153 color= (i<<10) + 0x3FF;
154 }
155 lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color);
156 }
157 while(1)printf("test ");
158 // for(i=0;i<240;i++)
159 // {
160 // if(i>(240/3))
161 // {
162 // color= (i<<5) + 0x1F;
163 // }
164 // else
165 // {
166 // color = i;
167 // }
168 // if(i>(2*240/3))
169 // {
170 // color= (i<<10) + 0x3FF;
171 // }
172 // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color);
173 // }
174 for(i=0;i<240;i++)
175 {
176 ili9328setFrame(&lcd0,i,0,1,100);
177 lcd0.interface->readGRAM(buffer,100);
178 lcd0.paint(&lcd0,buffer,i,200,1,100);
179 }
180 while(1);
181 }
182
183 int main2()
184 {
165 extern terminal_t terminal0;
185 extern terminal_t terminal0;
166 extern volatile vs10XXDev audioCodec0;
186 extern volatile vs10XXDev audioCodec0;
187 lcd0.paintText(&lcd0,"hello",20,50,&ComicSansMS_18 ,0xF0F0);
188 while (1)
189 randTextDemo();
167 printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL));
190 printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL));
168 vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000);
191 vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000);
169 vs10XXcmdwrite(&audioCodec0,VSVOL,0x2222);
192 delay_100us(1000);
193 vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020);
170 printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF));
194 printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF));
171 printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE));
195 printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE));
172 terminal_clear(&terminal0);
196 //terminal_clear(&terminal0);
173 // tryToplay2();
197 gpioclr(LCD_BACKL);
174 tryToplay1();
198 playAllparts();
175 return 0;
199 return 0;
176 }
200 }
177
201
178
202
179
203
180
204
181
205
182
206
@@ -1,21 +1,22
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3 SUBDIRS += QtTest/test.pro \
3 SUBDIRS += QtTest/test.pro \
4 SOLAR_PSU_HELLO/hello.pro \
4 SOLAR_PSU_HELLO/hello.pro \
5 SDCARD \
5 SDCARD \
6 STM32F4IT \
6 STM32F4IT \
7 M4StickV2 \
7 M4StickV2 \
8 lcdHello \
8 lcdHello \
9 BeagleSynthHello \
9 BeagleSynthHello \
10 lcdTerminal \
10 lcdTerminal \
11 BeagleSynthHelloSupMon \
11 BeagleSynthHelloSupMon \
12 TEST_CMSIS_FFT \
12 TEST_CMSIS_FFT \
13 N25Q128_test \
13 N25Q128_test \
14 ssd2119Tests
14 ssd2119Tests \
15 TEST_SIMULATOR
15
16
16
17
17
18
18
19
19
20
20
21
21
22
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./CS43L22_STM32F4.pro
4 SUBDIRS += ./CS43L22_STM32F4.pro \
5 ./CS43L22_SIMULATOR.pro
@@ -1,17 +1,16
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = CS43L22
2 TARGET = CS43L22
4
3
5 SOURCES += CS43L22.c
4 SOURCES += CS43L22.c
6
5
7 INCLUDEPATH += ../../../includes \
6 INCLUDEPATH += ../../../includes \
8 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
7 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 ../../CPU/CMSIS/Include
8 ../../CPU/CMSIS/Include
10
9
11
10
12 UCMODEL=stm32f4
11 UCMODEL=stm32f4
13
12
14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 INSTALLS += target
14 INSTALLS += target
16
15
17
16
@@ -1,15 +1,3
1 TEMPLATE = lib
1 TEMPLATE = subdirs
2 OBJECTS_DIR = obj
2 SUBDIRS += ./VS10XX_STM32F4.pro \
3 TARGET = vs10XX
3 ./VS10XX_SIMULATOR.pro
4
5 SOURCES += VS10XX.c
6
7
8 HEADERS += ../../../includes/VS10XX.h
9 INCLUDEPATH += ../../../includes
10
11 UCMODEL=stm32f4
12
13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
14 INSTALLS += target
15
@@ -1,16 +1,3
1 TEMPLATE = lib
1 TEMPLATE = subdirs
2 OBJECTS_DIR = obj
2 SUBDIRS += ./24LC0X_STM32F4.pro \
3
3 ./24LC0X_SIMULATOR.pro
4 SOURCES += 24LC0X.c
5 HEADERS += ../../../includes/24LC0X.h \
6 ../../../../includes/24LC0X.h
7
8 INCLUDEPATH += ../../../includes \
9 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../../CPU/CMSIS/Include
11
12
13 UCMODEL=stm32f4
14
15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 INSTALLS += target
@@ -1,15 +1,5
1 TEMPLATE = lib
1 TEMPLATE = subdirs
2 OBJECTS_DIR = obj
3
4 SOURCES += N25Q128.c
5 HEADERS += ../../../includes/N25Q128.h
6
7 INCLUDEPATH += ../../../includes \
8 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 ../../CPU/CMSIS/Include
10
2
11
3
12 UCMODEL=stm32f4
4 SUBDIRS += ./N25Q128_SIMULATOR.pro \
13
5 ./N25Q128_STM32F4.pro
14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 INSTALLS += target
@@ -1,5 +1,6
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./dirent_STM32F4.pro
4 SUBDIRS += ./dirent_STM32F4.pro \
5 ./dirent_SIMULATOR.pro
5
6
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./fat32_STM32F4.pro
4 SUBDIRS += ./fat32_STM32F4.pro \
5 ./fat32_SIMULATOR.pro
@@ -1,336 +1,383
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 #define FAT32_PRIVATE
22 #define FAT32_PRIVATE
23 #include <fat32.h>
23 #include <fat32.h>
24 #include <stdio.h>
24 #include <stdio.h>
25 #include <stdint.h>
25 #include <stdint.h>
26 #include <hexviewer.h>
26 #include <hexviewer.h>
27
27
28 char fat32buff[512];
28 char fat32buff[512]__attribute__ ((aligned (4)));
29 uint32_t lastSecAddrs=-1;
29 uint32_t lastSecAddrs=-1;
30 FAT32fs* lastFATFS=0;
30 FAT32fs* lastFATFS=0;
31
31
32 int fat32open(FAT32fs* fs,dikpartition* part)
32 int fat32open(FAT32fs* fs,dikpartition* part)
33 {
33 {
34 char sector[512];
34 fs->valide = 0;
35 fs->part = part;
35 if(part->valide==0)return FATBadpart;
36 if(!isFat32(fs->part->TypeCode))return FATBadpart;
36 char sector[512];
37 if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
37 fs->part = part;
38 if(!isFat32(fs->part->TypeCode))return FATBadpart;
39 if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
38 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff);
40 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff);
39 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff);
41 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff);
40 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off);
42 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off);
41 fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff);
43 fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff);
42 fs->BPB_SecPerClus = sector[BPB_SecPerClusoff];
44 fs->BPB_SecPerClus = sector[BPB_SecPerClusoff];
43 fs->BPB_NumFATs = sector[BPB_NumFATsoff];
45 fs->BPB_NumFATs = sector[BPB_NumFATsoff];
44 fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt;
46 fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt;
45 fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 );
47 fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 );
46 return FATnoErr;
48 fs->valide=1;
49 return FATnoErr;
47 }
50 }
48
51
49
52
50 int fat32mkdirent(FAT32fs* fs,ucdirent* dirent)
53 int fat32mkdirent(FAT32fs* fs,ucdirent* dirent)
51 {
54 {
52 if(fs==0) return DIRENT_BabArg;
55 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
53 if(dirent==0) return DIRENT_BabArg;
56 if(dirent==0) return DIRENT_BabArg;
54 dirent->fs = (UHANDLE)fs;
57 dirent->fs = (UHANDLE)fs;
55 dirent->getrootfirstent = &fat32getrootfirstent;
58 dirent->getrootfirstent = &fat32getrootfirstent;
56 dirent->nextdirent = &fat32nextdirent;
59 dirent->nextdirent = &fat32nextdirent;
57 return DIRENT_noErr;
60 return DIRENT_noErr;
58 }
61 }
59
62
60
63
61 int fat32getrootfirstent(ucdirent* entry)
64 int fat32getrootfirstent(ucdirent* entry)
62 {
65 {
63 if(entry==0) return DIRENT_BabArg;
66 if(entry==0) return DIRENT_BabArg;
64 entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba;
67 entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba;
65 entry->Currententry = 0;
68 entry->Currententry = 0;
66 return fat32nextdirent(entry);
69 return fat32nextdirent(entry);
67 }
70 }
68
71
69
72
70 int fat32getVolName(FAT32fs* fs,char* Name)
73 int fat32getVolName(FAT32fs* fs,char* Name)
71 {
74 {
72 if(fs==0) return DIRENT_BabArg;
75 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
73 if(Name==0) return DIRENT_BabArg;
76 if(Name==0) return DIRENT_BabArg;
74 int i=0;
77 int i=0;
75 ucdirent entry;
78 ucdirent entry;
76 if(DIRENT_noErr==fat32mkdirent(fs,&entry))
79 if(DIRENT_noErr==fat32mkdirent(fs,&entry))
77 {
80 {
78 entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba;
81 entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba;
79 entry.Currententry = -1;
82 entry.Currententry = -1;
80 if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr;
83 if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr;
81 for(i=0;i<16;i++)
84 for(i=0;i<16;i++)
82 {
85 {
83 Name[i] = entry.DIR_Name[i];
86 Name[i] = entry.DIR_Name[i];
84 }
87 }
85 return DIRENT_noErr;
88 return DIRENT_noErr;
86 }
89 }
87 return DIRENT_ReadErr;
90 return DIRENT_ReadErr;
88 }
91 }
89
92
90
93
91 int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry)
94 int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry)
92 {
95 {
93 if(firstentry==0) return DIRENT_BabArg;
96 if(firstentry==0) return DIRENT_BabArg;
94 if(currententry==0) return DIRENT_BabArg;
97 if(currententry==0) return DIRENT_BabArg;
95 fat32mkdirent(((FAT32fs*)currententry->fs),firstentry);
98 fat32mkdirent(((FAT32fs*)currententry->fs),firstentry);
96 firstentry->CurrentSec = fat32getdirentlba(currententry);
99 firstentry->CurrentSec = fat32getdirentlba(currententry);
97 firstentry->Currententry = -1;
100 firstentry->Currententry = -1;
98 return fat32nextdirent(firstentry);
101 return fat32nextdirent(firstentry);
99 }
102 }
100
103
101
104
102 int fat32nextdirent(ucdirent* entry)
105 int fat32nextdirent(ucdirent* entry)
103 {
106 {
104 uint32_t n=0,res=DIRENT_noErr,k,j;
107 uint32_t n=0,res=DIRENT_noErr,k,j;
105 k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/
108 k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/
106 j=entry->CurrentSec;// /*Restart at last sector*/
109 j=entry->CurrentSec;// /*Restart at last sector*/
107 do
110 do
108 {
111 {
112 //printf("reading new secotr\n",k);
109 fat32sectorreadout(((FAT32fs*)entry->fs),j);
113 fat32sectorreadout(((FAT32fs*)entry->fs),j);
110 for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/
114 //printf("done\n",k);
111 {
115 /*512 Bytes per sector and 32 bytes per entry*/
116 for(k=k;k<(512);k+=32)
117 {
112 if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/
118 if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/
113 {
119 {
120 //printf("Fount dir entry = %d, 0x%X\n",0xff & ((int)fat32buff[DIR_Nameoff+k]),0xff & ((int)fat32buff[DIR_Attroff+k]));
114 if(fat32buff[DIR_Nameoff+k]==(char)0)
121 if(fat32buff[DIR_Nameoff+k]==(char)0)
122 {
123 //printf("end of directory reached\n",k);
115 return DIRENT_EndOfDir; /*0x00 = end of dir*/
124 return DIRENT_EndOfDir; /*0x00 = end of dir*/
116 else
125 }
117 if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY)))
126 else
118 {
127 {
119 for(n=0;n<16;n++)entry->DIR_Name[n] = '\0';
128 uint8_t attribute=fat32buff[DIR_Attroff + k];
120 for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k];
129 if( (attribute==ATTR_DIRECTORY)
121 entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k];
130 ||(attribute==ATTR_ARCHIVE)
131 ||(attribute==ATTR_READ_ONLY)
132 ||(attribute==ATTR_READ_ONLY))
133 {
134 for(n=0;n<16;n++)entry->DIR_Name[n] = '\0';
135 for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k];
136 entry->DIR_Attr = attribute;
122 entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k];
137 entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k];
123 entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k));
138 entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k));
124 entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k));
139 entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k));
125 entry->DIR_LstAccDate = fat32extract16b(fat32buff,(DIR_LstAccDateoff + k));
140 entry->DIR_LstAccDate = fat32extract16b(fat32buff,(DIR_LstAccDateoff + k));
126 entry->DIR_FstClusHI = fat32extract16b(fat32buff, (DIR_FstClusHIoff + k));
141 entry->DIR_FstClusHI = fat32extract16b(fat32buff, (DIR_FstClusHIoff + k));
127 entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k));
142 entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k));
128 entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k));
143 entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k));
129 entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k));
144 entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k));
130 entry->CurrentSec = j;
145 entry->CurrentSec = j;
131 entry->Currententry = (unsigned char)(k/32);
146 entry->Currententry = (uint8_t)(0xFF&(k>>5));
132 return DIRENT_noErr;
147 return DIRENT_noErr;
133 }
148 }
134 }
149 }
135
150 }
136 }
151 }
137 j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k);
152 //printf("asking for next sector\n");
138 if(j!=DIRENT_noErr)
153 //printf("current = 0x%X\n",j);
139 {
154 j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k);
140 if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/
155 //printf("got it 0x%x\n",k);
141 return j;
156 if(j!=DIRENT_noErr)
142 }
157 {
143 j=k;
158 if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/
144 k=0;
159 return j;
145 }while(res==DIRENT_noErr);
160 }
146 return res;
161 j=k;
162 k=0;
163 }while(res==DIRENT_noErr);
164 return res;
147 }
165 }
148
166
149
167
150 int fat32getdirentname(ucdirent* entry,char* nameBuffer)
168 int fat32getdirentname(ucdirent* entry,char* nameBuffer)
151 {
169 {
152 uint32_t j;
170 uint32_t j;
153 int k,n,i;
171 int k,n,i;
154 int res=DIRENT_noErr;
172 int res=DIRENT_noErr;
155 char longName=0;
173 char longName=0;
156 k=(((signed char)entry->Currententry))*32;
174 k=(((signed char)entry->Currententry))*32;
157 j=entry->CurrentSec;
175 j=entry->CurrentSec;
158 fat32sectorreadout(((FAT32fs*)entry->fs),j);
176 fat32sectorreadout(((FAT32fs*)entry->fs),j);
159 longName |= fat32buff[DIR_Nameoff + 6 + k]=='~';
177 longName |= fat32buff[DIR_Nameoff + 6 + k]=='~';
160 if(k>=32)
178 if(k>=32)
161 {
179 {
162 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
180 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
163 }
181 }
164 else
182 else
165 {
183 {
166 uint32_t j_old=j;
184 uint32_t j_old=j;
167 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
185 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
168 fat32sectorreadout(((FAT32fs*)entry->fs),j);
186 fat32sectorreadout(((FAT32fs*)entry->fs),j);
169 k=512;
187 k=512;
170 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
188 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
171 if(!longName)
189 if(!longName)
172 {
190 {
173 k=0;
191 k=0;
174 j=j_old;
192 j=j_old;
175 fat32sectorreadout(((FAT32fs*)entry->fs),j);
193 fat32sectorreadout(((FAT32fs*)entry->fs),j);
176 k=0;
194 k=0;
177 }
195 }
178 }
196 }
179 if(longName) //long Name? or lower case name
197 if(longName) //long Name? or lower case name
180 {
198 {
181 i=0;
199 i=0;
182 do{
200 do{
183 if(k==0)
201 if(k==0)
184 {
202 {
185 //get previous sector
203 //get previous sector
186 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
204 if(fat32prevsectorlba2((FAT32fs*)entry->fs,entry, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
187 fat32sectorreadout(((FAT32fs*)entry->fs),j);
205 fat32sectorreadout(((FAT32fs*)entry->fs),j);
188 k=512-32;
206 k=512-32;
189 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
207 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
190 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
208 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
191 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
209 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
192 }
210 }
193 else
211 else
194 {
212 {
195 k-=32;
213 k-=32;
196 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
214 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
197 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
215 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
198 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
216 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
199 }
217 }
200 }while((fat32buff[k]&0x40)!=0x40);
218 }while((fat32buff[k]&0x40)!=0x40);
201 nameBuffer[i]='\0';
219 nameBuffer[i]='\0';
202 }
220 }
203 else
221 else
204 {
222 {
205 i=0;
223 i=0;
206 for(n=0;n<8;n++)
224 for(n=0;n<8;n++)
207 {
225 {
208 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
226 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
209 if(nameBuffer[i]!=0x20)i++;
227 if(nameBuffer[i]!=0x20)i++;
210 }
228 }
211 if((((fat32buff[DIR_Nameoff + k +11])&ATTR_DIRECTORY)!=ATTR_DIRECTORY)&&(fat32buff[8+DIR_Nameoff + k]!=0x20))
229 if((((fat32buff[DIR_Nameoff + k +11])&ATTR_DIRECTORY)!=ATTR_DIRECTORY)&&(fat32buff[8+DIR_Nameoff + k]!=0x20))
212 nameBuffer[i++]='.';
230 nameBuffer[i++]='.';
213 for(n=8;n<11;n++)
231 for(n=8;n<11;n++)
214 {
232 {
215 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
233 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
216 if(nameBuffer[i]!=0x20)i++;
234 if(nameBuffer[i]!=0x20)i++;
217 }
235 }
218
236
219 nameBuffer[i]='\0';
237 nameBuffer[i]='\0';
220 }
238 }
221 return res;
239 return res;
222 }
240 }
223
241
224
242
225 uint32_t fat32getdirentlba(ucdirent* entry)
243 uint32_t fat32getdirentlba(ucdirent* entry)
226 {
244 {
227 uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16);
245 uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16);
228 uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum);
246 uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum);
229 return lba;
247 return lba;
230 }
248 }
231
249
232
250
233 int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
251 int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
234 {
252 {
235
253
236 if(((lastsector_lba + 1 - fs->cluster_begin_lba) & ((uint32_t)(fs->BPB_SecPerClus)-1))!=0) /*Is it the last sector of the cluster?*/
254 if(((lastsector_lba + 1 - fs->cluster_begin_lba) & ((uint32_t)(fs->BPB_SecPerClus)-1))!=0) /*Is it the last sector of the cluster?*/
237 {
255 {
238 *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/
256 *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/
239 return DIRENT_noErr;
257 return DIRENT_noErr;
240 }
258 }
241
259
242 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
260 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
243 uint32_t fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
261 uint32_t fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
244 fat32sectorreadout(fs,fatsec);
262 fat32sectorreadout(fs,fatsec);
245 int i= fat32clusterinfatoff(clusternum);
263 int i= fat32clusterinfatoff(clusternum);
246 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
264 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
247 if(*nextsector_lba==0xFFFFFFF7)
265 if(*nextsector_lba==0xFFFFFFF7)
248 {
266 {
249
250 printf("DIRENT_BadSect\n");
251 return DIRENT_BadSect;
267 return DIRENT_BadSect;
252 }
268 }
253 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
269 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
254 {
270 {
255 printf("DIRENT_LastSect\n");
256 return DIRENT_LastSect;
271 return DIRENT_LastSect;
257 }
272 }
258 *nextsector_lba = clusterlba(fs,*nextsector_lba);
273 *nextsector_lba = clusterlba(fs,*nextsector_lba);
259 return DIRENT_noErr;
274 return DIRENT_noErr;
260 }
275 }
261
276
262
277
263 int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
278 int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
264 {
279 {
265 uint32_t i=0,fatsec=0;
280 uint32_t i=0,fatsec=0;
266 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
281 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
267 {
282 {
268 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
283 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
269 return DIRENT_noErr;
284 return DIRENT_noErr;
270 }
285 }
271 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
286
287 uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
272 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
288 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
273 do
289 while(fatsec>=fs->fat_begin_lba)
274 {
290 {
275
276 fat32sectorreadout(fs,fatsec);
291 fat32sectorreadout(fs,fatsec);
277 fatsec--;
292 fatsec--;
278 for(i=511;i>3;i-=4)
293 for(i=508;i>2;i-=4)
279 {
294 {
280 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i-3);
295 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
281 if (*nextsector_lba ==clusternum)
296 if (*nextsector_lba ==clusternum)
282 {
297 {
283 *nextsector_lba = clusterlba(fs,*nextsector_lba);
298 *nextsector_lba = clusterlba(fs,*nextsector_lba);
284 return DIRENT_noErr;
299 return DIRENT_noErr;
285 }
300 }
286
287 }
301 }
288
302 }
289 }while(fatsec>=fs->fat_begin_lba);
290
303
291 clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
304 clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
292 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
305 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
293 do
306 do
294 {
307 {
295
308
296 fat32sectorreadout(fs,fatsec);
309 fat32sectorreadout(fs,fatsec);
297 fatsec++;
310 fatsec++;
298 for(i=0;i<512;i+=4)
311 for(i=0;i<512;i+=4)
299 {
312 {
300 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
313 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
301 if (*nextsector_lba ==clusternum)
314 if (*nextsector_lba ==clusternum)
302 {
315 {
303 *nextsector_lba = clusterlba(fs,*nextsector_lba);
316 *nextsector_lba = clusterlba(fs,*nextsector_lba);
304 return DIRENT_noErr;
317 return DIRENT_noErr;
305 }
318 }
306
319
307 }
320 }
321 }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32));
322 return DIRENT_ReadErr;
323 }
308
324
309 }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32));
325
326 int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba)
327 {
328 uint32_t i=0,fatsec=0;
329 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
330 {
331 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
332 return DIRENT_noErr;
333 }
334
335 uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
336 uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(fat32getdirentlba(entry)));
337 fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/
338 *nextsector_lba = fat32getdirentlba(entry);
339 while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32))
340 {
341 uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(*nextsector_lba));
342 fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/
343 fat32sectorreadout(fs,fatsec);
344 i= fat32clusterinfatoff(currentClusternum);
345 if(i==clusternum)
346 {
347 return DIRENT_noErr;
348 }
349 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
350 if(*nextsector_lba==0xFFFFFFF7)
351 {
352 return DIRENT_BadSect;
353 }
354 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
355 {
356 return DIRENT_LastSect;
357 }
358 }
310 return DIRENT_ReadErr;
359 return DIRENT_ReadErr;
311 }
360 }
312
361
313
362
314
363
315
364
316
365
317
366
318
367
319
368
320
369
321
370
322
371
323
372
324
373
325
374
326
375
327
376
328
377
329
378
330
379
331
380
332
381
333
382
334
383
335
336
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./mbr_STM32F4.pro
4 SUBDIRS += ./mbr_STM32F4.pro \
5 ./mbr_SIMULATOR.pro
@@ -1,83 +1,86
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 "mbr.h"
22 #include <mbr.h>
23 #include <stdio.h>
23 #include <stdio.h>
24
24
25
25
26 int mbropen(blkdevice* phy,dikpartition* part,char partNum)
26 int mbropen(blkdevice* phy,dikpartition* part,char partNum)
27 {
27 {
28 printf("enter MBR open function\n");
28 printf("enter MBR open function\n");
29 char mbr[512];
29 char mbr[512];
30 if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg;
30 if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg;
31 part->phy = phy;
31 part->phy = phy;
32 if(phy->read(phy,mbr,0,1)!=RES_OK)
32 if(phy->read(phy,mbr,0,1)!=RES_OK)
33 {
33 {
34 printf("can't read MBR!\n");
34 printf("can't read MBR!\n");
35 printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]);
35 printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]);
36 part->valide = 0;
36 return MBRReadErr;
37 return MBRReadErr;
37 }
38 }
38 if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA))
39 if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA))
39 {
40 {
40 part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16];
41 part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16];
41 part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24);
42 part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24);
42 part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24);
43 part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24);
43 printf("MBR Ok\n");
44 printf("MBR Ok\n");
45 part->valide = 1;
44 return MBRnoErr;
46 return MBRnoErr;
45 }
47 }
46 printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]);
48 printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]);
49 part->valide = 0;
47 return MBRBadMbr;
50 return MBRBadMbr;
48
51
49 }
52 }
50
53
51
54
52
55
53
56
54
57
55
58
56
59
57
60
58
61
59
62
60
63
61
64
62
65
63
66
64
67
65
68
66
69
67
70
68
71
69
72
70
73
71
74
72
75
73
76
74
77
75
78
76
79
77
80
78
81
79
82
80
83
81
84
82
85
83
86
@@ -1,17 +1,20
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
2 OBJECTS_DIR = obj
3 TARGET = mbr
3 TARGET = mbr
4
4
5 SOURCES += \
5 SOURCES += \
6 mbr.c
6 mbr.c
7
7
8 INCLUDEPATH += ../../../includes \
8 INCLUDEPATH += ../../../includes \
9 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../../CPU/CMSIS/Include
10 ../../CPU/CMSIS/Include
11
11
12
12
13 UCMODEL=stm32f4
13 UCMODEL=stm32f4
14
14
15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 INSTALLS += target
16 INSTALLS += target
17
17
18 HEADERS += \
19 ../../../includes/mbr.h
20
@@ -1,20 +1,19
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = sdcard
2 TARGET = sdcard
4
3
5 SOURCES += \
4 SOURCES += \
6 sdcard.c
5 sdcard.c
7
6
8 INCLUDEPATH += ../../../includes \
7 INCLUDEPATH += ../../../includes \
9 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
8 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../../CPU/CMSIS/Include
9 ../../CPU/CMSIS/Include
11
10
12
11
13 UCMODEL=stm32f4
12 UCMODEL=stm32f4
14
13
15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 INSTALLS += target
15 INSTALLS += target
17
16
18 HEADERS += \
17 HEADERS += \
19 ../../../includes/sdcard.h
18 ../../../includes/sdcard.h
20
19
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./ili9328_STM32F4.pro
4 SUBDIRS += ./ili9328_STM32F4.pro \
5 ./ili9328_SIMULATOR.pro
@@ -1,420 +1,422
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 #include <core.h>
25 #include <core.h>
26 #include <math.h>
26 #include <math.h>
27
27
28 #ifdef __OPTIMIZED_MATH
28 #ifdef __OPTIMIZED_MATH
29 #include <optimised_math.h>
29 #include <optimised_math.h>
30 #endif
30 #endif
31
31
32 #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++);
33
32
34 #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \
33 #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \
35 for(int l=0;l<1;l++)\
34 for(int l=0;l<1;l++)\
36 {\
35 {\
37 ili9328setFrame(LCD,X,Y,W,1);\
36 ili9328setFrame(LCD,X,Y,W,1);\
38 int rem=(W)%buffsize;\
37 int rem=(W)%buffsize;\
39 if(rem)LCD->interface->writeGRAM(buffer,rem);\
38 if(rem)LCD->interface->writeGRAM(buffer,rem);\
40 for(int i=rem;i<(W);i+=buffsize)\
39 for(int i=rem;i<(W);i+=buffsize)\
41 {\
40 {\
42 LCD->interface->writeGRAM(buffer,buffsize);\
41 LCD->interface->writeGRAM(buffer,buffsize);\
43 }\
42 }\
44 }
43 }
45
44
46 #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
45 #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
47 for(int l=0;l<1;l++)\
46 for(int l=0;l<1;l++)\
48 {\
47 {\
49 ili9328setFrame(LCD,X,Y,W,1);\
48 ili9328setFrame(LCD,X,Y,W,1);\
50 int rem=(ContSz)%buffContsize;\
49 int rem=(ContSz)%buffContsize;\
51 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
50 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
52 for(int i=rem;i<(ContSz);i+=buffContsize)\
51 for(int i=rem;i<(ContSz);i+=buffContsize)\
53 {\
52 {\
54 LCD->interface->writeGRAM(bufferCont,buffContsize);\
53 LCD->interface->writeGRAM(bufferCont,buffContsize);\
55 }\
54 }\
56 if((2*ContSz)<W) \
55 if((2*ContSz)<W) \
57 {\
56 {\
58 rem=(W-(2*ContSz))%buffIntsize;\
57 rem=(W-(2*ContSz))%buffIntsize;\
59 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
58 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
60 for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\
59 for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\
61 {\
60 {\
62 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
61 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
63 }\
62 }\
64 }\
63 }\
65 rem=(ContSz)%buffContsize;\
64 rem=(ContSz)%buffContsize;\
66 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
65 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
67 for(int i=rem;i<(ContSz);i+=buffContsize)\
66 for(int i=rem;i<(ContSz);i+=buffContsize)\
68 {\
67 {\
69 LCD->interface->writeGRAM(bufferCont,buffContsize);\
68 LCD->interface->writeGRAM(bufferCont,buffContsize);\
70 }\
69 }\
71 }\
70 }\
72
71
73
72
74 #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
73 #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
75 for(int l=0;l<1;l++)\
74 for(int l=0;l<1;l++)\
76 {\
75 {\
77 ili9328setFrame(LCD,X,Y,1,H);\
76 ili9328setFrame(LCD,X,Y,1,H);\
78 int rem=(ContSz)%buffContsize;\
77 int rem=(ContSz)%buffContsize;\
79 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
78 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
80 for(int i=rem;i<(ContSz);i+=buffContsize)\
79 for(int i=rem;i<(ContSz);i+=buffContsize)\
81 {\
80 {\
82 LCD->interface->writeGRAM(bufferCont,buffContsize);\
81 LCD->interface->writeGRAM(bufferCont,buffContsize);\
83 }\
82 }\
84 if((2*ContSz)<H) \
83 if((2*ContSz)<H) \
85 {\
84 {\
86 rem=(H-(2*ContSz))%buffIntsize;\
85 rem=(H-(2*ContSz))%buffIntsize;\
87 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
86 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
88 for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\
87 for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\
89 {\
88 {\
90 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
89 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
91 }\
90 }\
92 }\
91 }\
93 rem=(ContSz)%buffContsize;\
92 rem=(ContSz)%buffContsize;\
94 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
93 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
95 for(int i=rem;i<(ContSz);i+=buffContsize)\
94 for(int i=rem;i<(ContSz);i+=buffContsize)\
96 {\
95 {\
97 LCD->interface->writeGRAM(bufferCont,buffContsize);\
96 LCD->interface->writeGRAM(bufferCont,buffContsize);\
98 }\
97 }\
99 }\
98 }\
100
99
101
100
102 #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
101 #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
103 for(int l=0;l<1;l++)\
102 for(int l=0;l<1;l++)\
104 {\
103 {\
105 ili9328setFrame(LCD,X,Y,1,H);\
104 ili9328setFrame(LCD,X,Y,1,H);\
106 int rem=(ContSz)%buffContsize;\
105 int rem=(ContSz)%buffContsize;\
107 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
106 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
108 for(int i=rem;i<(ContSz);i+=buffContsize)\
107 for(int i=rem;i<(ContSz);i+=buffContsize)\
109 {\
108 {\
110 LCD->interface->writeGRAM(bufferCont,buffContsize);\
109 LCD->interface->writeGRAM(bufferCont,buffContsize);\
111 }\
110 }\
112 if(ContSz<H) \
111 if(ContSz<H) \
113 {\
112 {\
114 rem=(H-ContSz)%buffIntsize;\
113 rem=(H-ContSz)%buffIntsize;\
115 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
114 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
116 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
115 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
117 {\
116 {\
118 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
117 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
119 }\
118 }\
120 }\
119 }\
121 }\
120 }\
122
121
123
122
124 #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
123 #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
125 for(int l=0;l<1;l++)\
124 for(int l=0;l<1;l++)\
126 {\
125 {\
127 ili9328setFrame(LCD,X,Y,1,H);\
126 ili9328setFrame(LCD,X,Y,1,H);\
128 int rem;\
127 int rem;\
129 if(ContSz<H) \
128 if(ContSz<H) \
130 {\
129 {\
131 rem=(H-ContSz)%buffIntsize;\
130 rem=(H-ContSz)%buffIntsize;\
132 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
131 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
133 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
132 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
134 {\
133 {\
135 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
134 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
136 }\
135 }\
137 }\
136 }\
138 rem=(ContSz)%buffContsize;\
137 rem=(ContSz)%buffContsize;\
139 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
138 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
140 for(int i=rem;i<(ContSz);i+=buffContsize)\
139 for(int i=rem;i<(ContSz);i+=buffContsize)\
141 {\
140 {\
142 LCD->interface->writeGRAM(bufferCont,buffContsize);\
141 LCD->interface->writeGRAM(bufferCont,buffContsize);\
143 }\
142 }\
144 }\
143 }\
145
144
146
145
147 void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress)
146 void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress)
148 {
147 {
149 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress);
148 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress);
150 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress);
149 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress);
151 }
150 }
152
151
153 void ili9328refreshenable(struct LCD_t* LCD,int enable)
152 void ili9328refreshenable(struct LCD_t* LCD,int enable)
154 {
153 {
155 if(enable)
154 if(enable)
156 {
155 {
157 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018);
156 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018);
158 }
157 }
159 else
158 else
160 {
159 {
161 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008);
160 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008);
162
161
163 }
162 }
164 }
163 }
165
164
166 void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H)
165 void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H)
167 {
166 {
168 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X);
167 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X);
169 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y);
168 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y);
170 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X);
169 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X);
171 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1));
170 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1));
172 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y);
171 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y);
173 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1));
172 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1));
174 }
173 }
175
174
176 void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height)
175 void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height)
177 {
176 {
178 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height)))
177 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height)))
179 {
178 {
180 ili9328setFrame(LCD,Xpos,Ypos,Width,Height);
179 ili9328setFrame(LCD,Xpos,Ypos,Width,Height);
181 LCD->interface->writeGRAM(buffer,Width*Height);
180 LCD->interface->writeGRAM(buffer,Width*Height);
182 }
181 }
183 }
182 }
184
183
185 void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
184 void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
186 {
185 {
187 //Based on the mid point circle algorithm from Wikipedia
186 //Based on the mid point circle algorithm from Wikipedia
188 //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
187 //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
189 uint16_t innerbuffer[16];
188 uint16_t innerbuffer[16];
190 uint16_t outterbuffer[16];
189 uint16_t outterbuffer[16];
191 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
190 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
192 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
191 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
193 if(contSz<r)
192 if(contSz<r)
194 {
193 {
195 int error = -r,error_int = -r+contSz;
194 int error = -r,error_int = -r+contSz;
196 int x = r,x_int=r-contSz;
195 int x = r,x_int=r-contSz;
197 int y = 0,y_int=0;
196 int y = 0,y_int=0;
198 while (x >= y)
197 while (x >= y)
199 {
198 {
200 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16);
199 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);
200 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);
201 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);
202 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);
203 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);
204 ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
206 error += y;
205 error += y;
207 ++y;
206 ++y;
208 error += y;
207 error += y;
209 error_int += y_int;
208 error_int += y_int;
210 ++y_int;
209 ++y_int;
211 error_int += y_int;
210 error_int += y_int;
212 if(error >= 0)
211 if(error >= 0)
213 {
212 {
214 error -= x;
213 error -= x;
215 --x;
214 --x;
216 error -= x;
215 error -= x;
217 }
216 }
218 if(error_int >= 0)
217 if(error_int >= 0)
219 {
218 {
220 error_int -= x_int;
219 error_int -= x_int;
221 --x_int;
220 --x_int;
222 error_int -= x_int;
221 error_int -= x_int;
223 }
222 }
224 }
223 }
225
224
226
225
227
226
228 }
227 }
229
228
230 }
229 }
231
230
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)
231 void ili9328paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor)
233 {
232 {
234 if(contSz<r)
233 if(contSz<r)
235 {
234 {
236 uint16_t innerbuffer[16];
235 uint16_t innerbuffer[16];
237 uint16_t outterbuffer[16];
236 uint16_t outterbuffer[16];
238 int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem;
237 int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem;
239 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
238 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
240 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
239 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
241 /* Y = b +/- sqrt[r^2 - (x - a)^2] */
240 /* Y = b +/- sqrt[r^2 - (x - a)^2] */
242 for(int32_t line=-r;line<r;line++)
241 for(int32_t line=-r;line<r;line++)
243 {
242 {
244 #ifdef __OPTIMIZED_MATH
243 #ifdef __OPTIMIZED_MATH
245 Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) );
244 Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) );
246 Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) );
245 Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) );
247 #else
246 #else
248 Val1 = sqrt( (double)(rr - ((line)*(line))) );
247 Val1 = sqrt( (double)(rr - ((line)*(line))) );
249 Val2 = sqrt( (double)(rr2 - ((line)*(line))) );
248 Val2 = sqrt( (double)(rr2 - ((line)*(line))) );
250 #endif
249 #endif
251 X1=Xpos - Val1;
250 X1=Xpos - Val1;
252 contSz2= Val1-Val2;
251 contSz2= Val1-Val2;
253 ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1);
252 ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1);
254 rem=(contSz2)%16;
253 rem=(contSz2)%16;
255 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
254 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
256 for(int i=rem;i<(contSz2);i+=16)
255 for(int i=rem;i<(contSz2);i+=16)
257 {
256 {
258 LCD->interface->writeGRAM(outterbuffer,16);
257 LCD->interface->writeGRAM(outterbuffer,16);
259 }
258 }
260
259
261 W=2*Val1;
260 W=2*Val1;
262 if(W>(2*contSz2))
261 if(W>(2*contSz2))
263 {
262 {
264 W-=2*contSz2;
263 W-=2*contSz2;
265 rem=(W)%16;
264 rem=(W)%16;
266 if(rem)LCD->interface->writeGRAM(innerbuffer,rem);
265 if(rem)LCD->interface->writeGRAM(innerbuffer,rem);
267 for(int i=rem;i<(W);i+=16)
266 for(int i=rem;i<(W);i+=16)
268 {
267 {
269 LCD->interface->writeGRAM(innerbuffer,16);
268 LCD->interface->writeGRAM(innerbuffer,16);
270 }
269 }
271 }
270 }
272
271
273 rem=(contSz2)%16;
272 rem=(contSz2)%16;
274 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
273 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
275 for(int i=rem;i<(contSz2);i+=16)
274 for(int i=rem;i<(contSz2);i+=16)
276 {
275 {
277 LCD->interface->writeGRAM(outterbuffer,16);
276 LCD->interface->writeGRAM(outterbuffer,16);
278 }
277 }
279 }
278 }
280 }
279 }
281 }
280 }
282
281
283
282
284
283
285
284
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)
285 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)
287 {
286 {
288 ili9328setFrame(LCD,Xpos,Ypos,w,h);
287 ili9328setFrame(LCD,Xpos,Ypos,w,h);
289 uint16_t tmp[32];
288 uint16_t tmp[32];
290 for(int i=0;i<32;i++)tmp[i]=fillColor;
289 for(int i=0;i<32;i++)tmp[i]=fillColor;
291 for(int i=0;i<(h*w);i+=32)
290 for(int i=0;i<(h*w);i+=32)
292 {
291 {
293 LCD->interface->writeGRAM(tmp,32);
292 LCD->interface->writeGRAM(tmp,32);
294 }
293 }
295 int rem=(w*h)%32;
294 int rem=(w*h)%32;
296 if(rem)LCD->interface->writeGRAM(tmp,rem);
295 if(rem)LCD->interface->writeGRAM(tmp,rem);
297 if(contSz)
296 if(contSz)
298 {
297 {
299 ili9328setFrame(LCD,Xpos,Ypos,w,contSz);
298 ili9328setFrame(LCD,Xpos,Ypos,w,contSz);
300 for(int i=0;i<32;i++)tmp[i]=contColor;
299 for(int i=0;i<32;i++)tmp[i]=contColor;
301 rem=(w*contSz)%32;
300 rem=(w*contSz)%32;
302 if(rem)LCD->interface->writeGRAM(tmp,rem);
301 if(rem)LCD->interface->writeGRAM(tmp,rem);
303 for(int i=rem;i<(w*contSz);i+=32)
302 for(int i=rem;i<(w*contSz);i+=32)
304 {
303 {
305 LCD->interface->writeGRAM(tmp,32);
304 LCD->interface->writeGRAM(tmp,32);
306 }
305 }
307
306
308 ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz);
307 ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz);
309 rem=(w*contSz)%32;
308 rem=(w*contSz)%32;
310 if(rem)LCD->interface->writeGRAM(tmp,rem);
309 if(rem)LCD->interface->writeGRAM(tmp,rem);
311 for(int i=rem;i<(w*contSz);i+=32)
310 for(int i=rem;i<(w*contSz);i+=32)
312 {
311 {
313 LCD->interface->writeGRAM(tmp,32);
312 LCD->interface->writeGRAM(tmp,32);
314 }
313 }
315
314
316 ili9328setFrame(LCD,Xpos,Ypos,contSz,h);
315 ili9328setFrame(LCD,Xpos,Ypos,contSz,h);
317 rem=(h*contSz)%32;
316 rem=(h*contSz)%32;
318 if(rem)LCD->interface->writeGRAM(tmp,rem);
317 if(rem)LCD->interface->writeGRAM(tmp,rem);
319 for(int i=rem;i<(h*contSz);i+=32)
318 for(int i=rem;i<(h*contSz);i+=32)
320 {
319 {
321 LCD->interface->writeGRAM(tmp,32);
320 LCD->interface->writeGRAM(tmp,32);
322 }
321 }
323
322
324 ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h);
323 ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h);
325 rem=(h*contSz)%32;
324 rem=(h*contSz)%32;
326 if(rem)LCD->interface->writeGRAM(tmp,rem);
325 if(rem)LCD->interface->writeGRAM(tmp,rem);
327 for(int i=rem;i<(h*contSz);i+=32)
326 for(int i=rem;i<(h*contSz);i+=32)
328 {
327 {
329 LCD->interface->writeGRAM(tmp,32);
328 LCD->interface->writeGRAM(tmp,32);
330 }
329 }
331 }
330 }
332 }
331 }
333
332
334 void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color)
333 void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color)
335 {
334 {
336 int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0;
335 int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0;
337 uint16_t tmp[w];
336 uint16_t tmp[w];
338 uint16_t linenum=0,charnum=0;
337 uint16_t linenum=0,charnum=0;
339 uint8_t line=0;
338 uint8_t line=0;
340 while(*buffer!='\0')
339 while(*buffer!='\0')
341 {
340 {
341 if(*buffer<32)*buffer=32;
342 if(*buffer>127)*buffer=32;
342 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1);
343 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1);
343 LCD->interface->readGRAM(tmp,w);
344 LCD->interface->readGRAM(tmp,w);
344 for(int i=0;i<(h*w);i++)
345 for(int i=0;i<(h*w);i++)
345 {
346 {
346 if( ((i%w)==0) ) //read current line to apply text pixmap
347 if( ((i%w)==0) ) //read current line to apply text pixmap
347 {
348 {
348 if(linenum++>0)
349 if(linenum++>0)
349 {
350 {
350 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1);
351 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1);
351 LCD->interface->writeGRAM(tmp,w);
352 LCD->interface->writeGRAM(tmp,w);
352 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1);
353 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1);
353 LCD->interface->readGRAM(tmp,w);
354 LCD->interface->readGRAM(tmp,w);
354 pix=0;
355 pix=0;
355 }
356 }
356 }
357 }
357 if((pix%8) == 0)
358 if((pix%8) == 0)
358 {
359 {
359 line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++];
360 line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++];
360 }
361 }
362 tmp[pix]=0;
361 if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color;
363 if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color;
362 pix++;
364 pix++;
363 line>>=1;
365 line>>=1;
364 }
366 }
365 linenum=0;
367 linenum=0;
366 tableoffset=0;
368 tableoffset=0;
367 charnum++;
369 charnum++;
368 buffer++;
370 buffer++;
369 }
371 }
370 }
372 }
371
373
372 int ili9328init(struct LCD_t* LCD)
374 int ili9328init(struct LCD_t* LCD)
373 {
375 {
374 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL))
376 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL))
375 {
377 {
376 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h)
378 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h)
377 LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h)
379 LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h)
378 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h)
380 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h)
379 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302);
381 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302);
380 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000);
382 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000);
381 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On
383 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On
382 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h)
384 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h)
383 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
385 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
384 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h)
386 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h)
385 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h)
387 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h)
386 delay_100us(1000);
388 delay_100us(1000);
387 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h)
389 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h)
388 delay_100us(500);
390 delay_100us(500);
389 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
391 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
390 delay_100us(500);
392 delay_100us(500);
391 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h)
393 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h)
392 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h)
394 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h)
393 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h)
395 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h)
394 delay_100us(500);
396 delay_100us(500);
395 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1
397 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1
396 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2
398 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2
397 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3
399 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3
398 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4
400 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4
399 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5
401 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5
400 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6
402 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6
401 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7
403 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7
402 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8
404 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8
403 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9
405 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9
404 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10
406 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10
405 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h)
407 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h)
406 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h)
408 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h)
407 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h)
409 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h)
408 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h)
410 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h)
409 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h)
411 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h)
410 LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
412 LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
411 LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h)
413 LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h)
412 // Display On
414 // Display On
413 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h)
415 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h)
414 delay_100us(500);
416 delay_100us(500);
415 LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF);
417 LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF);
416 }
418 }
417 return 0;
419 return 0;
418 }
420 }
419
421
420
422
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./ssd2119_STM32F4.pro
4 SUBDIRS += ./ssd2119_STM32F4.pro \
5 ./ssd2119_SIMULATOR.pro
@@ -1,22 +1,21
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = ssd2119
2 TARGET = ssd2119
4
3
5 SOURCES += \
4 SOURCES += \
6 ssd2119.c
5 ssd2119.c
7
6
8 DEFINES -= __OPTIMIZED_MATH
7 DEFINES -= __OPTIMIZED_MATH
9
8
10 INCLUDEPATH += ../../../../includes \
9 INCLUDEPATH += ../../../../includes \
11 ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \
12 ../../../CPU/CMSIS/Include \
11 ../../../CPU/CMSIS/Include \
13 ../../../../includes/GRAPHIC/CONTROLERS \
12 ../../../../includes/GRAPHIC/CONTROLERS \
14 ../../../../includes/GRAPHIC/GUI/FONTS \
13 ../../../../includes/GRAPHIC/GUI/FONTS \
15 ../../../../includes/GRAPHIC/GUI/Widgets
14 ../../../../includes/GRAPHIC/GUI/Widgets
16
15
17
16
18 UCMODEL=stm32f4
17 UCMODEL=stm32f4
19
18
20 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
19 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
21 INSTALLS += target
20 INSTALLS += target
22
21
@@ -1,9 +1,10
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += ./FONTS_STM32F4.pro
2 SUBDIRS += ./FONTS_STM32F4.pro \
3 ./FONTS_SIMULATOR.pro
3
4
4
5
5
6
6
7
7
8
8
9
9
10
@@ -1,187 +1,245
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the libuc, microcontroler library
2 -- This file is a part of the libuc, microcontroler library
3 -- Copyright (C) 2013, Alexis Jeandet
3 -- Copyright (C) 2013, Alexis Jeandet
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
18 -------------------------------------------------------------------------------
19 -- Author : Alexis Jeandet
19 -- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@gmail.com
20 -- Mail : alexis.jeandet@gmail.com
21 -------------------------------------------------------------------------------*/
21 -------------------------------------------------------------------------------*/
22 #include <widget.h>
22 #include <widget.h>
23 #include <terminal.h>
23 #include <terminal.h>
24 #include <stdint.h>
24 #include <stdint.h>
25 #include <stdio.h>
25 #include <stdio.h>
26 #include <gpio.h>
26 #include <gpio.h>
27 #include <core.h>
27 #include <core.h>
28
28 #include <malloc.h>
29
29
30 #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos)
30 #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos)
31 #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight)
31 #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight)
32
32
33 streamdevice_ops TERMINAL_OPS=
33 streamdevice_ops TERMINAL_OPS=
34 {
34 {
35 .write = &terminal_write,
35 .write = &terminal_write,
36 .read = &terminal_read,
36 .read = &terminal_read,
37 .setpos= &terminal_setpos,
37 .setpos= &terminal_setpos,
38 .close = NULL
38 .close = NULL
39 };
39 };
40
40
41 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev)
41 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev)
42 {
42 {
43 if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL))
43 if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL))
44 {
44 {
45 terminal->LCD=LCD;
45 terminal->LCD=LCD;
46 terminal->font=font;
46 terminal->font=font;
47 terminal->line = 0;
47 terminal->line = 0;
48 terminal->column = 0;
48 terminal->column = 0;
49 terminal->horizontalSpace=0;
49 terminal->horizontalSpace = 0;
50 terminal->verticalSpace=0;
50 terminal->verticalSpace = 0;
51 int charw=terminal->font->Width + terminal->horizontalSpace;
51 int charw=terminal->font->Width + terminal->horizontalSpace;
52 int charh=terminal->font->Height + terminal->verticalSpace;
52 int charh=terminal->font->Height + terminal->verticalSpace;
53 terminal->textColor=0xFFFF;
53 terminal->textColor=0xFFFF;
54 terminal->backgroundColor=0x0000;
54 terminal->backgroundColor=0x0000;
55 terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10));
55 terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10));
56
57 strdev->_stream = (UHANDLE)terminal;
56 strdev->_stream = (UHANDLE)terminal;
58 strdev->ops = &TERMINAL_OPS;
57 strdev->ops = &TERMINAL_OPS;
59 strdev->streamPt = 0;
58 strdev->streamPt = 0;
60 terminal_clear(terminal);
59 terminal_clear(terminal);
61 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
60 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
61 terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1));
62 terminal->firstLine = 0;
63 terminal->lastLine = 0;
64 terminal->empty = 1;
65 for(int i=1;i<=terminal->lineCount;i++)
66 {
67 terminal->buffer[i * terminal->columnCount]='\n';
68 }
62 return 1;
69 return 1;
63 }
70 }
64 return 0;
71 return 0;
65 }
72 }
66
73
67 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height)
74 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height)
68 {
75 {
69 int charw=terminal->font->Width + terminal->horizontalSpace;
76 int charw=terminal->font->Width + terminal->horizontalSpace;
70 int charh=terminal->font->Height + terminal->verticalSpace;
77 int charh=terminal->font->Height + terminal->verticalSpace;
71 if(terminal->LCD->height<(Ypos+height))
78 if(terminal->LCD->height<(Ypos+height))
72 return;
79 return;
73 if(terminal->LCD->width<(Xpos+width))
80 if(terminal->LCD->width<(Xpos+width))
74 return;
81 return;
75 terminal->Xpos = Xpos;
82 terminal->Xpos = Xpos;
76 terminal->Ypos = Ypos;
83 terminal->Ypos = Ypos;
77 terminal->height = height;
84 terminal->height = height;
78 terminal->width = width;
85 terminal->width = width;
79 terminal->lineCount = terminal->height/charh;
86 terminal->lineCount = terminal->height/charh;
80 terminal->columnCount = (terminal->width/charw)-1;
87 terminal->columnCount = (terminal->width/charw)-1;
81 terminal_clear(terminal);
88 terminal_clear(terminal);
82 }
89 }
83
90
84
91
85 void terminal_clear(terminal_t* terminal)
92 void terminal_clear(terminal_t* terminal)
86 {
93 {
94 terminal->firstLine = 0;
95 terminal->lastLine = 0;
96 terminal->empty = 1;
97 terminal->line =0;
98 terminal->column=0;
87 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor);
99 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor);
88 }
100 }
89
101
90 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor)
102 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor)
91 {
103 {
92 terminal->backgroundColor = backgrooundColor;
104 terminal->backgroundColor = backgrooundColor;
93 }
105 }
94
106
95 void terminal_settextColor(terminal_t* terminal, uint32_t textColor)
107 void terminal_settextColor(terminal_t* terminal, uint32_t textColor)
96 {
108 {
97 terminal->textColor = textColor;
109 terminal->textColor = textColor;
98 }
110 }
99
111
100
112
101 void terminal_movecursor(terminal_t* terminal,int n)
113 void terminal_movecursor(terminal_t* terminal,int n)
102 {
114 {
103 int charw=terminal->font->Width + terminal->horizontalSpace;
115 int charw=terminal->font->Width + terminal->horizontalSpace;
104 int charh=terminal->font->Height + terminal->verticalSpace;
116 int charh=terminal->font->Height + terminal->verticalSpace;
105 terminal->column += n;
117 terminal->column += n;
106 if(terminal->column>terminal->columnCount)
118 if(terminal->column>(terminal->columnCount))
107 {
119 {
108 terminal->line += (terminal->column)/terminal->columnCount;
120 terminal->line += (terminal->column)/terminal->columnCount;
109 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal,charh)-charh,charw*(terminal->columnCount-terminal->column),charh,terminal->backgroundColor,0,terminal->backgroundColor);
110 terminal->line = terminal->line % terminal->lineCount;
121 terminal->line = terminal->line % terminal->lineCount;
111 terminal->column = terminal->column % terminal->columnCount;
122 terminal->column = (terminal->column % terminal->columnCount)-1;
123 int x=CHARXPOS(terminal, charw);
124 int y=CHARYPOS(terminal,charh)-charh;
125 int w=charw*(terminal->columnCount-terminal->column);
126 int h=charh;
127 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal,charh)-charh,charw*(terminal->columnCount-terminal->column-1),charh,terminal->backgroundColor,0,terminal->backgroundColor);
112 }
128 }
113 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal,charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
129 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal,charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
114 }
130 }
115
131
116 void terminal_clearCurentLine(terminal_t* terminal)
132 void terminal_clearCurentLine(terminal_t* terminal)
117 {
133 {
118 int charw=terminal->font->Width + terminal->horizontalSpace;
134 int charw=terminal->font->Width + terminal->horizontalSpace;
119 int charh=terminal->font->Height + terminal->verticalSpace;
135 int charh=terminal->font->Height + terminal->verticalSpace;
120 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor);
136 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor);
121 }
137 }
122
138
123 int terminal_writenc(terminal_t* terminal,char* data, int n)
139 int terminal_writenc(terminal_t* terminal,char* data, int n)
124 {
140 {
125 int charw=terminal->font->Width + terminal->horizontalSpace;
141 int charw=terminal->font->Width + terminal->horizontalSpace;
126 int charh=terminal->font->Height + terminal->verticalSpace;
142 int charh=terminal->font->Height + terminal->verticalSpace;
127 int l=0;
143 int l=0;
128 char buffer[2]=" ";
144 char buffer[2]=" ";
129 while(l<n)
145 while(l<n)
130 {
146 {
131
147
132 buffer[0]=data[l];
148 buffer[0]=data[l];
133 if(buffer[0]=='\n')
149 if(buffer[0]=='\n')
134 {
150 {
135 terminal->line= (terminal->line+1) % terminal->lineCount;
151 terminal->line= (terminal->line+1) % terminal->lineCount;
136 terminal->column = 0;
152 terminal->column = 0;
137 terminal_clearCurentLine(terminal);
153 if(terminal->line==0)
154 terminal_clear(terminal);
155 else
156 terminal_clearCurentLine(terminal);
138 }else {
157 }else {
139 if(buffer[0]=='\t')
158 if(buffer[0]=='\t')
140 {
159 {
141 for(int i=0;i<1;i++)terminal_movecursor(terminal,1);
160 for(int i=0;i<1;i++)terminal_movecursor(terminal,1);
142 }else
161 }else
143 if(terminal->column==0)terminal_clearCurentLine(terminal);
162 if(terminal->column==0)terminal_clearCurentLine(terminal);
144 if(buffer[0]!='\r'){
163 if(buffer[0]!='\r'){
145 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
164 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
146 terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor);
165 terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor);
147 terminal_movecursor(terminal,1);
166 terminal_movecursor(terminal,1);
148 }
167 }
149 }
168 }
150 l++;
169 l++;
151 }
170 }
152 return n;
171 return n;
153 }
172 }
154
173
174 void terminal_print_line(terminal_t* terminal,int line)
175 {
176 int charw=terminal->font->Width + terminal->horizontalSpace;
177 int charh=terminal->font->Height + terminal->verticalSpace;
178 terminal_clearCurentLine(terminal);
179 terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor);
180 }
181
182 int terminal_writenc2(terminal_t* terminal,char* data, int n)
183 {
184 int charw=terminal->font->Width + terminal->horizontalSpace;
185 int charh=terminal->font->Height + terminal->verticalSpace;
186 /* First copy to buffer*/
187 int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column;
188 for(int i=0;i<n;i++)
189 {
190 terminal->empty=0;
191 terminal->buffer[offset] = data[i];
192 if(data[i]=='\n')
193 {
194 offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1));
195 }
196 else
197 {
198 offset++;
199 }
200 }
201 if(!terminal->empty)
202 {
203 for(int i=terminal->firstLine;i<=terminal->lastLine;i++)
204 {
205 terminal_print_line(terminal,i);
206 }
207 }
208 return n;
209 }
210
211
212
155 int terminal_write(streamdevice* device,void* data,int size, int n)
213 int terminal_write(streamdevice* device,void* data,int size, int n)
156 {
214 {
157 return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n);
215 return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n);
158 }
216 }
159
217
160 int terminal_read(streamdevice* device,void* data,int size, int n)
218 int terminal_read(streamdevice* device,void* data,int size, int n)
161 {
219 {
162 return n*size;
220 return n*size;
163 }
221 }
164
222
165 int terminal_setpos(streamdevice* device,int pos)
223 int terminal_setpos(streamdevice* device,int pos)
166 {
224 {
167 return 1;
225 return 1;
168 }
226 }
169
227
170 int terminal_close( streamdevice* device)
228 int terminal_close( streamdevice* device)
171 {
229 {
172 return 1;
230 return 1;
173 }
231 }
174
232
175
233
176
234
177
235
178
236
179
237
180
238
181
239
182
240
183
241
184
242
185
243
186
244
187
245
@@ -1,3 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += ./Terminal_STM32F4.pro
2 SUBDIRS += ./Terminal_STM32F4.pro \
3 ./Terminal_SIMULATOR.pro
3
4
5
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./STMPE811_STM32F4.pro
4 SUBDIRS += ./STMPE811_STM32F4.pro \
5 ./STMPE811_SIMULATOR.pro
@@ -1,28 +1,27
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = STMPE811
2 TARGET = STMPE811
4
3
5 SOURCES += \
4 SOURCES += \
6 STMPE811.c
5 STMPE811.c
7
6
8 DEFINES -= __OPTIMIZED_MATH
7 DEFINES -= __OPTIMIZED_MATH
9
8
10 INCLUDEPATH += ../../../../includes \
9 INCLUDEPATH += ../../../../includes \
11 ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \
12 ../../../CPU/CMSIS/Include \
11 ../../../CPU/CMSIS/Include \
13 ../../../../includes/GRAPHIC/CONTROLERS \
12 ../../../../includes/GRAPHIC/CONTROLERS \
14 ../../../../includes/GRAPHIC/TC_CONTROLERS \
13 ../../../../includes/GRAPHIC/TC_CONTROLERS \
15 ../../../../includes/GRAPHIC/GUI/FONTS \
14 ../../../../includes/GRAPHIC/GUI/FONTS \
16 ../../../../includes/GRAPHIC/GUI/Widgets
15 ../../../../includes/GRAPHIC/GUI/Widgets
17
16
18
17
19 UCMODEL=stm32f4
18 UCMODEL=stm32f4
20
19
21 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
20 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
22 INSTALLS += target
21 INSTALLS += target
23
22
24 HEADERS += \
23 HEADERS += \
25 ../../../../includes/GRAPHIC/TC_CONTROLERS/STMPE811.h \
24 ../../../../includes/GRAPHIC/TC_CONTROLERS/STMPE811.h \
26 ../../../../includes/GRAPHIC/TC_CONTROLERS/genericTC_Controler.h
25 ../../../../includes/GRAPHIC/TC_CONTROLERS/genericTC_Controler.h
27
26
28
27
@@ -1,4 +1,5
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += ./ina226_STM32F4.pro
4 SUBDIRS += ./ina226_STM32F4.pro \
5 ./ina226_SIMULATOR.pro
@@ -1,16 +1,15
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = ina226
2 TARGET = ina226
4
3
5 SOURCES += ina226.c
4 SOURCES += ina226.c
6
5
7 INCLUDEPATH += ../../../includes \
6 INCLUDEPATH += ../../../includes \
8 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
7 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 ../../CPU/CMSIS/Include
8 ../../CPU/CMSIS/Include
10
9
11
10
12 UCMODEL=stm32f4
11 UCMODEL=stm32f4
13
12
14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 INSTALLS += target
14 INSTALLS += target
16
15
@@ -1,68 +1,72
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 TERMINAL_H
22 #ifndef TERMINAL_H
23 #define TERMINAL_H
23 #define TERMINAL_H
24 #include <stdint.h>
24 #include <stdint.h>
25 #include <widget.h>
25 #include <widget.h>
26 #include <streamdevices.h>
26 #include <streamdevices.h>
27 #include <genericLCD_Controler.h>
27 #include <genericLCD_Controler.h>
28 #include <fonts.h>
28 #include <fonts.h>
29
29
30 typedef struct terminal_t
30 typedef struct terminal_t
31 {
31 {
32 uint16_t line;
32 uint16_t line;
33 uint16_t column;
33 uint16_t column;
34 uint16_t lineCount;
34 uint16_t lineCount;
35 uint16_t columnCount;
35 uint16_t columnCount;
36 uint16_t firstLine;
37 uint16_t lastLine;
36 uint16_t Xpos;
38 uint16_t Xpos;
37 uint16_t Ypos;
39 uint16_t Ypos;
38 uint16_t width;
40 uint16_t width;
39 uint16_t height;
41 uint16_t height;
40 uint32_t backgroundColor;
42 uint32_t backgroundColor;
41 uint32_t textColor;
43 uint32_t textColor;
42 int8_t verticalSpace;
44 int8_t verticalSpace;
43 int8_t horizontalSpace;
45 int8_t horizontalSpace;
46 int8_t empty;
44 LCD_t* LCD;
47 LCD_t* LCD;
45 sFONT* font;
48 sFONT* font;
49 char* buffer;
46 }terminal_t;
50 }terminal_t;
47
51
48 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev);
52 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev);
49 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height);
53 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height);
50 void terminal_clear(terminal_t* terminal);
54 void terminal_clear(terminal_t* terminal);
51 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor);
55 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor);
52 void terminal_settextColor(terminal_t* terminal, uint32_t textColor);
56 void terminal_settextColor(terminal_t* terminal, uint32_t textColor);
53 void terminal_movecursor(terminal_t* terminal,int n);
57 void terminal_movecursor(terminal_t* terminal,int n);
54 void terminal_clearCurentLine(terminal_t* terminal);
58 void terminal_clearCurentLine(terminal_t* terminal);
55 int terminal_write(streamdevice* device,void* data,int size, int n);
59 int terminal_write(streamdevice* device,void* data,int size, int n);
56 int terminal_read(streamdevice* device,void* data,int size, int n);
60 int terminal_read(streamdevice* device,void* data,int size, int n);
57 int terminal_setpos(streamdevice* device,int pos);
61 int terminal_setpos(streamdevice* device,int pos);
58 int terminal_close(streamdevice* device);
62 int terminal_close(streamdevice* device);
59
63
60
64
61
65
62
66
63
67
64
68
65
69
66
70
67
71
68 #endif
72 #endif
@@ -1,176 +1,196
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 FAT32_H
22 #ifndef FAT32_H
23 #define FAT32_H
23 #define FAT32_H
24 #include <mbr.h>
24 #include <mbr.h>
25 #include <libucfs.h>
25 #include <libucfs.h>
26 #include <ucdirent.h>
26 #include <ucdirent.h>
27 #include <stdint.h>
27 #include <stdint.h>
28 #include <stdint-gcc.h>
28 #include <stdint-gcc.h>
29 /*BPB (Boot Sector) Offsets */
29 /*BPB (Boot Sector) Offsets */
30
30
31 #define BS_jmpBootoff 0
31 #define BS_jmpBootoff 0
32 #define BS_OEMNameoff 3
32 #define BS_OEMNameoff 3
33 #define BPB_BytsPerSecoff 11
33 #define BPB_BytsPerSecoff 11
34 #define BPB_SecPerClusoff 13
34 #define BPB_SecPerClusoff 13
35 #define BPB_RsvdSecCntoff 14
35 #define BPB_RsvdSecCntoff 14
36 #define BPB_NumFATsoff 16
36 #define BPB_NumFATsoff 16
37 #define BPB_RootEntCntoff 17
37 #define BPB_RootEntCntoff 17
38 #define BPB_TotSec16off 19
38 #define BPB_TotSec16off 19
39 #define BPB_Mediaoff 21
39 #define BPB_Mediaoff 21
40 #define BPB_FATSz16off 22
40 #define BPB_FATSz16off 22
41 #define BPB_SecPerTrkoff 24
41 #define BPB_SecPerTrkoff 24
42 #define BPB_NumHeadsoff 26
42 #define BPB_NumHeadsoff 26
43 #define BPB_HiddSecoff 28
43 #define BPB_HiddSecoff 28
44 #define BPB_TotSec32off 32
44 #define BPB_TotSec32off 32
45 /*FAT16*/
45 /*FAT16*/
46 #define BS_DrvNumFAT16off 36
46 #define BS_DrvNumFAT16off 36
47 #define BS_Reserved1FAT16off 37
47 #define BS_Reserved1FAT16off 37
48 #define BS_BootSigFAT16off 38
48 #define BS_BootSigFAT16off 38
49 #define BS_VolIDFAT16off 39
49 #define BS_VolIDFAT16off 39
50 #define BS_VolLabFAT16off 43
50 #define BS_VolLabFAT16off 43
51 #define BS_FilSysTypeFAT16off 54
51 #define BS_FilSysTypeFAT16off 54
52 /*FAT32*/
52 /*FAT32*/
53 #define BPB_FATSz32off 36
53 #define BPB_FATSz32off 36
54 #define BPB_ExtFlagsoff 40
54 #define BPB_ExtFlagsoff 40
55 #define BPB_FSVeroff 42
55 #define BPB_FSVeroff 42
56 #define BPB_RootClusoff 44
56 #define BPB_RootClusoff 44
57 #define BPB_FSInfooff 48
57 #define BPB_FSInfooff 48
58 #define BPB_BkBootSecoff 50
58 #define BPB_BkBootSecoff 50
59 #define BPB_Reservedoff 52
59 #define BPB_Reservedoff 52
60 #define BS_DrvNumFAT32off 64
60 #define BS_DrvNumFAT32off 64
61 #define BS_Reserved1FAT32off 65
61 #define BS_Reserved1FAT32off 65
62 #define BS_BootSigFAT32off 66
62 #define BS_BootSigFAT32off 66
63 #define BS_VolIDFAT32off 67
63 #define BS_VolIDFAT32off 67
64 #define BS_VolLabFAT32off 71
64 #define BS_VolLabFAT32off 71
65 #define BS_FilSysTypeFAT32off 82
65 #define BS_FilSysTypeFAT32off 82
66
66
67
67
68 #define DIR_Nameoff 0
68 #define DIR_Nameoff 0
69 #define DIR_Attroff 0xb
69 #define DIR_Attroff 0xb
70 #define DIR_FstClusHIoff 0x14
70 #define DIR_FstClusHIoff 0x14
71 #define DIR_FstClusLOoff 0x1A
71 #define DIR_FstClusLOoff 0x1A
72 #define DIR_FileSizeoff 0x1c
72 #define DIR_FileSizeoff 0x1c
73 #define DIR_CrtTimeTenthoff 13
73 #define DIR_CrtTimeTenthoff 13
74 #define DIR_CrtTimeoff 14
74 #define DIR_CrtTimeoff 14
75 #define DIR_CrtDateoff 16
75 #define DIR_CrtDateoff 16
76 #define DIR_LstAccDateoff 18
76 #define DIR_LstAccDateoff 18
77 #define DIR_WrtTimeoff 22
77 #define DIR_WrtTimeoff 22
78 #define DIR_WrtDateoff 24
78 #define DIR_WrtDateoff 24
79
79
80
80
81
81
82 #define FATBadpart 1
82 #define FATBadpart 1
83 #define FATBabArg 2
83 #define FATBabArg 2
84 #define FATReadErr 3
84 #define FATReadErr 3
85 #define FATnoErr 0
85 #define FATnoErr 0
86
86
87 /*
88 TODO :
89 intergrate a per BLKDEV or per partition buffer.
90 */
87 typedef struct FAT32fs
91 typedef struct FAT32fs
88 {
92 {
89 uint16_t BPB_BytsPerSec;
93 uint16_t BPB_BytsPerSec;
90 uint16_t BPB_RsvdSecCnt;
94 uint16_t BPB_RsvdSecCnt;
91 uint32_t BPB_FATSz32;
95 uint32_t BPB_FATSz32;
92 uint32_t BPB_RootClus;
96 uint32_t BPB_RootClus;
93 uint32_t fat_begin_lba;
97 uint32_t fat_begin_lba;
94 uint32_t cluster_begin_lba;
98 uint32_t cluster_begin_lba;
95 uint8_t BPB_SecPerClus;
99 uint8_t BPB_SecPerClus;
96 uint8_t BPB_NumFATs;
100 uint8_t BPB_NumFATs;
101 char valide;
97 dikpartition* part;
102 dikpartition* part;
98 }FAT32fs;
103 }FAT32fs;
99
104
100
105
101 #define castUI64(val) ((uint64_t)(val))
106 #define castUI64(val) ((uint64_t)(val))
102 #define castUI32(val) ((uint32_t)(val))
107 #define castUI32(val) ((uint32_t)(val))
103 #define castUI16(val) ((uint16_t)(val))
108 #define castUI16(val) ((uint16_t)(val))
104 #define castUI8(val) ((uint8_t)(val))
109 #define castUI8(val) ((uint8_t)(val))
105
110
106 #define castI64(val) ((int64_t)(val))
111 #define castI64(val) ((int64_t)(val))
107 #define castI32(val) ((int32_t)(val))
112 #define castI32(val) ((int32_t)(val))
108 #define castI16(val) ((int16_t)(val))
113 #define castI16(val) ((int16_t)(val))
109 #define castI8(val) ((int8_t)(val))
114 #define castI8(val) ((int8_t)(val))
110
115
111 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
116 /*
112 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
117 TODO :
118 Should add global function for casting with endianness care.
119 have a look at REV, REV16, REVSH, and RBIT ARMV7m asm
120 */
121
122 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
123 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
124 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
125 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
126 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
127 #else
128 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
129 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
130 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
131 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
132 #endif
133
113
134
114 /* Get the first sector lba of given cluster number*/
135 /* Get the first sector lba of given cluster number*/
115 #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus)
136 #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus)
116
137
117 //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba)
138 //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba)
118 #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba)
139 #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba)
119 #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4)
140 #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4)
120
141
121 /*Get cluster index in FAT Table from sector address*/
142 /*Get cluster index in FAT Table from sector address*/
122 #define fat32masksectorlba(sectorlba,fs) (sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1)))
143 #define fat32masksectorlba(sectorlba,fs) (sectorlba)//(sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1)))
123 #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2))
144 #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2))
124
145
125 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
126 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
127
146
128 #ifdef FAT32_PRIVATE
147 #ifdef FAT32_PRIVATE
129 #define fat32sectorreadout(fs,fatsec) \
148 #define fat32sectorreadout(fs,fatsec) \
130 if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \
149 if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \
131 {\
150 {\
132 if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \
151 if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \
133 {\
152 {\
134 return DIRENT_ReadErr;\
153 return DIRENT_ReadErr;\
135 }\
154 }\
136 }\
155 }\
137 lastSecAddrs=(fatsec);\
156 lastSecAddrs=(fatsec);\
138 lastFATFS=(fs);
157 lastFATFS=(fs);
139 #endif
158 #endif
140
159
141 extern int fat32open(FAT32fs* fs,dikpartition* part);
160 extern int fat32open(FAT32fs* fs,dikpartition* part);
142 extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent);
161 extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent);
143 extern int fat32getVolName(FAT32fs* fs,char* Name);
162 extern int fat32getVolName(FAT32fs* fs,char* Name);
144 extern int fat32getrootfirstent(ucdirent* entry);
163 extern int fat32getrootfirstent(ucdirent* entry);
145 extern int fat32nextdirent(ucdirent* entry);
164 extern int fat32nextdirent(ucdirent* entry);
146 extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba);
165 extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba);
147 extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba);
166 extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba);
167 extern int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba);
148 extern uint32_t fat32getdirentlba(ucdirent* entry);
168 extern uint32_t fat32getdirentlba(ucdirent* entry);
149 extern int fat32getdirentname(ucdirent* entry,char* nameBuffer);
169 extern int fat32getdirentname(ucdirent* entry,char* nameBuffer);
150
170
151 #endif
171 #endif
152
172
153
173
154
174
155
175
156
176
157
177
158
178
159
179
160
180
161
181
162
182
163
183
164
184
165
185
166
186
167
187
168
188
169
189
170
190
171
191
172
192
173
193
174
194
175
195
176
196
@@ -1,71 +1,72
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 MBR_H
22 #ifndef MBR_H
23 #define MBR_H
23 #define MBR_H
24 #include <uhandle.h>
24 #include <uhandle.h>
25 #include <blkdevice.h>
25 #include <blkdevice.h>
26
26
27 #define BootFlagoffset 0
27 #define BootFlagoffset 0
28 #define TypeCodeoffset 4
28 #define TypeCodeoffset 4
29 #define LBABeginoffset 8
29 #define LBABeginoffset 8
30 #define NumOfSecoffset 12
30 #define NumOfSecoffset 12
31
31
32 #define MBRBadMbr 1
32 #define MBRBadMbr 1
33 #define MBRBabArg 2
33 #define MBRBabArg 2
34 #define MBRReadErr 3
34 #define MBRReadErr 3
35 #define MBRnoErr 0
35 #define MBRnoErr 0
36
36
37 #define isFat32(TypeCode) (((TypeCode)==0x0b)||((TypeCode)==0x0c))
37 #define isFat32(TypeCode) (((TypeCode)==0x0b)||((TypeCode)==0x0c))
38
38
39 typedef struct dikpartition
39 typedef struct dikpartition
40 {
40 {
41 char TypeCode;
41 char TypeCode;
42 char valide;
42 unsigned int LBABegin;
43 unsigned int LBABegin;
43 unsigned int NumOfSec;
44 unsigned int NumOfSec;
44 blkdevice* phy;
45 blkdevice* phy;
45 }dikpartition;
46 }dikpartition;
46
47
47
48
48 int mbropen(blkdevice* phy,dikpartition* part,char partNum);
49 int mbropen(blkdevice* phy,dikpartition* part,char partNum);
49
50
50
51
51 #endif
52 #endif
52
53
53
54
54
55
55
56
56
57
57
58
58
59
59
60
60
61
61
62
62
63
63
64
64
65
65
66
66
67
67
68
68
69
69
70
70
71
71
72
@@ -1,16 +1,17
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4 SUBDIRS += stm32f4
4 SUBDIRS += stm32f4
5
5
6 SUBDIRS += common
6 SUBDIRS += common
7 SUBDIRS += simulator
7
8
8 headers.files = includes/*.h \
9 headers.files = includes/*.h \
9 includes/GRAPHIC/CONTROLERS/*.h \
10 includes/GRAPHIC/CONTROLERS/*.h \
10 includes/GRAPHIC/TC_CONTROLERS/*.h \
11 includes/GRAPHIC/TC_CONTROLERS/*.h \
11 includes/GRAPHIC/GUI/FONTS/*.h \
12 includes/GRAPHIC/GUI/FONTS/*.h \
12 includes/GRAPHIC/GUI/Widgets/*.h
13 includes/GRAPHIC/GUI/Widgets/*.h
13
14
14 headers.path = $$[QT_INSTALL_HEADERS]
15 headers.path = $$[QT_INSTALL_HEADERS]
15 INSTALLS += headers
16 INSTALLS += headers
16
17
@@ -1,375 +1,378
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 <core.h>
22 #include <core.h>
23 #include <stm32f4xx_rcc.h>
23 #include <stm32f4xx_rcc.h>
24 #include <stdint.h>
24 #include <stdint.h>
25 #include <stdlib.h>
25 #include <stdlib.h>
26 #include <stdio.h>
26 #include <stdio.h>
27 #include <core_cm4.h>
27 #include <core_cm4.h>
28 #include <gpio.h>
28
29
29 extern uint32_t OSC0;
30 extern uint32_t OSC0;
30 extern uint32_t INTOSC;
31 extern uint32_t INTOSC;
31 extern uint32_t RTCOSC;
32 extern uint32_t RTCOSC;
32
33
33 volatile uint32_t tickCounter=0;
34 volatile uint32_t tickCounter=0;
34
35
35
36
36 void SysTick_Handler(void)
37 void SysTick_Handler(void)
37 {
38 {
38 tickCounter+=1;
39 tickCounter+=1;
40 if((tickCounter&0xFFF)==0x800)
41 gpiosetval(PC15,!gpiogetval(PC15));
39 }
42 }
40
43
41 void delay_us(uint32_t value)
44 void delay_us(uint32_t value)
42 {
45 {
43 extern uint32_t currentCpuFreq;
46 extern uint32_t currentCpuFreq;
44 if(value)
47 if(value)
45 {
48 {
46 uint32_t tickperus=currentCpuFreq/(1000*10);
49 uint32_t tickperus=currentCpuFreq/(1000*10);
47 uint32_t tickCounterSnap = SysTick->VAL+((value%100)*tickperus);
50 uint32_t tickCounterSnap = SysTick->VAL+((value%100)*tickperus);
48 uint32_t targetVal=tickCounterSnap +(value/100);
51 uint32_t targetVal=tickCounterSnap +(value/100);
49 if(targetVal < tickCounterSnap)
52 if(targetVal < tickCounterSnap)
50 {
53 {
51 while(tickCounter > targetVal);
54 while(tickCounter > targetVal);
52 }
55 }
53 while((tickCounter < targetVal) | (SysTick->VAL<tickCounterSnap));
56 while((tickCounter < targetVal) | (SysTick->VAL<tickCounterSnap));
54 }
57 }
55 }
58 }
56
59
57 void delay_100us(uint32_t value)
60 void delay_100us(uint32_t value)
58 {
61 {
59 if(value)
62 if(value)
60 {
63 {
61 uint32_t tickCounterSnap = tickCounter;
64 uint32_t tickCounterSnap = tickCounter;
62 uint32_t SysTickSnap = SysTick->VAL;
65 uint32_t SysTickSnap = SysTick->VAL;
63 uint32_t targetVal=tickCounterSnap +(value);
66 uint32_t targetVal=tickCounterSnap +(value);
64 if(targetVal < tickCounterSnap)
67 if(targetVal < tickCounterSnap)
65 {
68 {
66 while(tickCounter > targetVal);
69 while(tickCounter > targetVal);
67 }
70 }
68 while((tickCounter < targetVal) | (SysTick->VAL<SysTickSnap));
71 while((tickCounter < targetVal) | (SysTick->VAL<SysTickSnap));
69 }
72 }
70 }
73 }
71
74
72 uint32_t getAPB1Freq()
75 uint32_t getAPB1Freq()
73 {
76 {
74 RCC_ClocksTypeDef RCC_ClocksStatus;
77 RCC_ClocksTypeDef RCC_ClocksStatus;
75 RCC_GetClocksFreq(&RCC_ClocksStatus);
78 RCC_GetClocksFreq(&RCC_ClocksStatus);
76 return RCC_ClocksStatus.PCLK1_Frequency;
79 return RCC_ClocksStatus.PCLK1_Frequency;
77 }
80 }
78
81
79 uint32_t getAPB2Freq()
82 uint32_t getAPB2Freq()
80 {
83 {
81 RCC_ClocksTypeDef RCC_ClocksStatus;
84 RCC_ClocksTypeDef RCC_ClocksStatus;
82 RCC_GetClocksFreq(&RCC_ClocksStatus);
85 RCC_GetClocksFreq(&RCC_ClocksStatus);
83 return RCC_ClocksStatus.PCLK2_Frequency;
86 return RCC_ClocksStatus.PCLK2_Frequency;
84 }
87 }
85
88
86
89
87 uint32_t getCpuFreq()
90 uint32_t getCpuFreq()
88 {
91 {
89 uint32_t cpufreq = OSC0;
92 uint32_t cpufreq = OSC0;
90 uint32_t PLLN,PLLM,PLLP;
93 uint32_t PLLN,PLLM,PLLP;
91
94
92 if((RCC->CFGR & 0xC) == 8) //PLL used as sys clk
95 if((RCC->CFGR & 0xC) == 8) //PLL used as sys clk
93 {
96 {
94 uint32_t pllinput=INTOSC;
97 uint32_t pllinput=INTOSC;
95 if((RCC->PLLCFGR & (1<<22)) == (1<<22))
98 if((RCC->PLLCFGR & (1<<22)) == (1<<22))
96 {
99 {
97 pllinput=OSC0;
100 pllinput=OSC0;
98 }
101 }
99 PLLN = (RCC->PLLCFGR>>6) & 0x1FF;
102 PLLN = (RCC->PLLCFGR>>6) & 0x1FF;
100 PLLM = RCC->PLLCFGR & 0x3F;
103 PLLM = RCC->PLLCFGR & 0x3F;
101 PLLP = 1<<(((RCC->PLLCFGR>>16) & 3 )+1);
104 PLLP = 1<<(((RCC->PLLCFGR>>16) & 3 )+1);
102 cpufreq = (pllinput * PLLN )/(PLLM*PLLP);
105 cpufreq = (pllinput * PLLN )/(PLLM*PLLP);
103 }
106 }
104 else if((RCC->CFGR & 0xC) == 0) //HSI used as sys clk
107 else if((RCC->CFGR & 0xC) == 0) //HSI used as sys clk
105 {
108 {
106 cpufreq=INTOSC;
109 cpufreq=INTOSC;
107 }
110 }
108 if((RCC->CFGR & (1<<7))==1<<7)
111 if((RCC->CFGR & (1<<7))==1<<7)
109 {
112 {
110 return cpufreq>>((RCC->CFGR & (7<<4))>>4);
113 return cpufreq>>((RCC->CFGR & (7<<4))>>4);
111 }
114 }
112 return cpufreq;
115 return cpufreq;
113 }
116 }
114
117
115 void reset_AHB1()
118 void reset_AHB1()
116 {
119 {
117 RCC->AHB1RSTR = -1;
120 RCC->AHB1RSTR = -1;
118 RCC->AHB1RSTR = 0;
121 RCC->AHB1RSTR = 0;
119 }
122 }
120
123
121 void reset_AHB2()
124 void reset_AHB2()
122 {
125 {
123 RCC->AHB2RSTR = -1;
126 RCC->AHB2RSTR = -1;
124 RCC->AHB2RSTR = 0;
127 RCC->AHB2RSTR = 0;
125 }
128 }
126
129
127 void reset_APB1()
130 void reset_APB1()
128 {
131 {
129 RCC->APB1RSTR = -1;
132 RCC->APB1RSTR = -1;
130 RCC->APB1RSTR = 0;
133 RCC->APB1RSTR = 0;
131 }
134 }
132
135
133 void reset_APB2()
136 void reset_APB2()
134 {
137 {
135 RCC->APB2RSTR = -1;
138 RCC->APB2RSTR = -1;
136 RCC->APB2RSTR = 0;
139 RCC->APB2RSTR = 0;
137 }
140 }
138
141
139
142
140
143
141 /*
144 /*
142 | 2.7->3.6V
145 | 2.7->3.6V
143 -------------------------
146 -------------------------
144 0WS | 0<HCLK<=30
147 0WS | 0<HCLK<=30
145 1WS | 30<HCLK<=60
148 1WS | 30<HCLK<=60
146 2WS | 60<HCLK<=90
149 2WS | 60<HCLK<=90
147 3WS | 90<HCLK<=120
150 3WS | 90<HCLK<=120
148 4WS | 120<HCLK<=150
151 4WS | 120<HCLK<=150
149 5WS | 150<HCLK<=168
152 5WS | 150<HCLK<=168
150
153
151 f(VCO clock) = f(PLL clock input) × (PLLN / PLLM) [1]
154 f(VCO clock) = f(PLL clock input) × (PLLN / PLLM) [1]
152 64MHz <= f(VCO clock) <= 432MHz [2]
155 64MHz <= f(VCO clock) <= 432MHz [2]
153
156
154 f(VCO clock input) must be between 1MHz and 2MHz and as close to 2MHz as possible!! [3]
157 f(VCO clock input) must be between 1MHz and 2MHz and as close to 2MHz as possible!! [3]
155
158
156 f(PLL general clock output) = f(VCO clock) / PLLP [4]
159 f(PLL general clock output) = f(VCO clock) / PLLP [4]
157
160
158 CPU<168MHz AHB1<168MHz AHB2<168MHz APB1<42MHz APB2<84MHz [5]
161 CPU<168MHz AHB1<168MHz AHB2<168MHz APB1<42MHz APB2<84MHz [5]
159
162
160 ! 63<=PLLN<=432 [6]
163 ! 63<=PLLN<=432 [6]
161 ! 2<=PLLM<=63 [7]
164 ! 2<=PLLM<=63 [7]
162 ! PLLP=2,4,6,8 [8]
165 ! PLLP=2,4,6,8 [8]
163 4<=PLLM*PLLP<=504
166 4<=PLLM*PLLP<=504
164
167
165 F= f(PLL clock input) * A/B with
168 F= f(PLL clock input) * A/B with
166 63<=A<=432
169 63<=A<=432
167 4<=B<=504
170 4<=B<=504
168
171
169 */
172 */
170
173
171
174
172 int optimizePLLcfg(uint32_t freq, uint32_t srcfreq,uint32_t PLLM,uint32_t* PLLP, uint32_t* PLLN,uint8_t* AHBPRindx)
175 int optimizePLLcfg(uint32_t freq, uint32_t srcfreq,uint32_t PLLM,uint32_t* PLLP, uint32_t* PLLN,uint8_t* AHBPRindx)
173 {
176 {
174 uint32_t AHBPRtbl[9]={1,2,4,8,16,64,128,256,512};
177 uint32_t AHBPRtbl[9]={1,2,4,8,16,64,128,256,512};
175 uint32_t AHBPR=0,AHBPR_r=0,PLLN_r=0,PLLP_r=0;
178 uint32_t AHBPR=0,AHBPR_r=0,PLLN_r=0,PLLP_r=0;
176 uint32_t Fplli=0;
179 uint32_t Fplli=0;
177 int32_t f_error=100000000;
180 int32_t f_error=100000000;
178 int32_t f_errornw=100000000;
181 int32_t f_errornw=100000000;
179 Fplli = srcfreq / PLLM;
182 Fplli = srcfreq / PLLM;
180 //not efficient but should find the best parameters
183 //not efficient but should find the best parameters
181 for((*AHBPRindx)=0;(*AHBPRindx)<9;(*AHBPRindx)++) //lowest priority
184 for((*AHBPRindx)=0;(*AHBPRindx)<9;(*AHBPRindx)++) //lowest priority
182 {
185 {
183 AHBPR = AHBPRtbl[(*AHBPRindx)];
186 AHBPR = AHBPRtbl[(*AHBPRindx)];
184 for(*PLLP=2;*PLLP<9;*PLLP+=2)
187 for(*PLLP=2;*PLLP<9;*PLLP+=2)
185 {
188 {
186 *PLLN = (freq*(*PLLP)*AHBPR)/Fplli;
189 *PLLN = (freq*(*PLLP)*AHBPR)/Fplli;
187 if(((*PLLN)>62) && ((*PLLN)<433) && ((Fplli * (*PLLN)) < 433000000))
190 if(((*PLLN)>62) && ((*PLLN)<433) && ((Fplli * (*PLLN)) < 433000000))
188 {
191 {
189 f_errornw = abs((int32_t)((int32_t)((Fplli*(*PLLN))/((*PLLP)*AHBPR))-freq));
192 f_errornw = abs((int32_t)((int32_t)((Fplli*(*PLLN))/((*PLLP)*AHBPR))-freq));
190 if( ( (f_error)>(f_errornw) ) || ( (*AHBPRindx==0)&&(*PLLP==2)&&(*PLLN==63) ) )
193 if( ( (f_error)>(f_errornw) ) || ( (*AHBPRindx==0)&&(*PLLP==2)&&(*PLLN==63) ) )
191 {
194 {
192 f_error=f_errornw;
195 f_error=f_errornw;
193 PLLN_r = *PLLN;
196 PLLN_r = *PLLN;
194 PLLP_r = *PLLP;
197 PLLP_r = *PLLP;
195 AHBPR_r=*AHBPRindx;
198 AHBPR_r=*AHBPRindx;
196 if(f_error==0)
199 if(f_error==0)
197 {
200 {
198 *PLLN = PLLN_r;
201 *PLLN = PLLN_r;
199 *PLLP = PLLP_r;
202 *PLLP = PLLP_r;
200 *AHBPRindx = AHBPR_r;
203 *AHBPRindx = AHBPR_r;
201 return 1;
204 return 1;
202 }
205 }
203 }
206 }
204 }
207 }
205 }
208 }
206 }
209 }
207 *PLLN = PLLN_r;
210 *PLLN = PLLN_r;
208 *PLLP = PLLP_r;
211 *PLLP = PLLP_r;
209 *AHBPRindx = AHBPR_r;
212 *AHBPRindx = AHBPR_r;
210 return 1;
213 return 1;
211 }
214 }
212
215
213
216
214 int setPll(uint32_t freq)
217 int setPll(uint32_t freq)
215 {
218 {
216 extern uint32_t OSC0;
219 extern uint32_t OSC0;
217 extern uint32_t INTOSC;
220 extern uint32_t INTOSC;
218 uint32_t srcfreq = INTOSC;
221 uint32_t srcfreq = INTOSC;
219 uint8_t AHBPRindx;
222 uint8_t AHBPRindx;
220 uint32_t AHBPRtbl[9]={1,2,4,8,16,64,128,256,512};
223 uint32_t AHBPRtbl[9]={1,2,4,8,16,64,128,256,512};
221 uint32_t PLLN=0,PLLM=0,PLLP=0,AHBPR=0;
224 uint32_t PLLN=0,PLLM=0,PLLP=0,AHBPR=0;
222 uint32_t Fplli=0;
225 uint32_t Fplli=0;
223 if((RCC->PLLCFGR & (1<<22))==(1<<22))
226 if((RCC->PLLCFGR & (1<<22))==(1<<22))
224 {
227 {
225 srcfreq = OSC0;
228 srcfreq = OSC0;
226 }
229 }
227 PLLM = srcfreq / 1500000; // [3]
230 PLLM = srcfreq / 1500000; // [3]
228 Fplli = srcfreq / PLLM;
231 Fplli = srcfreq / PLLM;
229 optimizePLLcfg(freq,srcfreq,PLLM,&PLLP,&PLLN,&AHBPRindx);
232 optimizePLLcfg(freq,srcfreq,PLLM,&PLLP,&PLLN,&AHBPRindx);
230 srcfreq = (Fplli*PLLN)/(PLLP*AHBPRtbl[AHBPRindx]); //Put real clk freq in srcfreq for return value
233 srcfreq = (Fplli*PLLN)/(PLLP*AHBPRtbl[AHBPRindx]); //Put real clk freq in srcfreq for return value
231 //now switch to HSIs
234 //now switch to HSIs
232 if((RCC->CR & 1)==0)RCC->CR |= 1; //turn ON HSI
235 if((RCC->CR & 1)==0)RCC->CR |= 1; //turn ON HSI
233 while((RCC->CR & 2)!=2); //wait for HSI Ready
236 while((RCC->CR & 2)!=2); //wait for HSI Ready
234 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
237 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
235 RCC->CFGR |= RCC_CFGR_SW_HSI; //set HSI as main clk
238 RCC->CFGR |= RCC_CFGR_SW_HSI; //set HSI as main clk
236 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_HSI);
239 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_HSI);
237 RCC->CR &= ~(1<<24); //Turn OFF PLL
240 RCC->CR &= ~(1<<24); //Turn OFF PLL
238 RCC->PLLCFGR &= ~0x37FFF; //clear PLLP PLLM PLLN
241 RCC->PLLCFGR &= ~0x37FFF; //clear PLLP PLLM PLLN
239 RCC->PLLCFGR |= PLLM + (PLLN<<6) + (((PLLP>>1) -1)<<16);
242 RCC->PLLCFGR |= PLLM + (PLLN<<6) + (((PLLP>>1) -1)<<16);
240 RCC->CR |= RCC_CR_PLLON; //Turn ON PLL
243 RCC->CR |= RCC_CR_PLLON; //Turn ON PLL
241 while((RCC->CR & (1<<25))!=(1<<25)); //wait for PLL Ready
244 while((RCC->CR & (1<<25))!=(1<<25)); //wait for PLL Ready
242 if(AHBPRindx!=0)AHBPRindx|=0x8;
245 if(AHBPRindx!=0)AHBPRindx|=0x8;
243 RCC->CFGR &= ~(0xF<<4);
246 RCC->CFGR &= ~(0xF<<4);
244 RCC->CFGR |= (uint32_t)(AHBPRindx<<4);
247 RCC->CFGR |= (uint32_t)(AHBPRindx<<4);
245 AHBPR=0;
248 AHBPR=0;
246 while((srcfreq>>AHBPR)>42000000)AHBPR++; //[5] //Thune APB1 prescaler to keep APB1 CLK below 42MHz
249 while((srcfreq>>AHBPR)>42000000)AHBPR++; //[5] //Thune APB1 prescaler to keep APB1 CLK below 42MHz
247 if(AHBPR!=0)
250 if(AHBPR!=0)
248 {
251 {
249 AHBPR-=1;
252 AHBPR-=1;
250 AHBPR|=0x4;
253 AHBPR|=0x4;
251 }
254 }
252 RCC->CFGR &= ~(0x7<<10);
255 RCC->CFGR &= ~(0x7<<10);
253 RCC->CFGR |= (uint32_t)(AHBPR<<10);
256 RCC->CFGR |= (uint32_t)(AHBPR<<10);
254 AHBPR=0;
257 AHBPR=0;
255 while((srcfreq>>AHBPR)>84000000)AHBPR++; //[5] //Thune APB2 prescaler to keep APB2 CLK below 42MHz
258 while((srcfreq>>AHBPR)>84000000)AHBPR++; //[5] //Thune APB2 prescaler to keep APB2 CLK below 42MHz
256 if(AHBPR!=0)
259 if(AHBPR!=0)
257 {
260 {
258 AHBPR-=1;
261 AHBPR-=1;
259 AHBPR|=0x4;
262 AHBPR|=0x4;
260 }
263 }
261 RCC->CFGR &= ~(0x7<<13);
264 RCC->CFGR &= ~(0x7<<13);
262 RCC->CFGR |= (uint32_t)(AHBPR<<13);
265 RCC->CFGR |= (uint32_t)(AHBPR<<13);
263 FLASH->ACR |= FLASH_ACR_LATENCY_7WS;
266 FLASH->ACR |= FLASH_ACR_LATENCY_7WS;
264 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));//Switch to PLL as main clk source
267 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));//Switch to PLL as main clk source
265 RCC->CFGR |= RCC_CFGR_SW_PLL;
268 RCC->CFGR |= RCC_CFGR_SW_PLL;
266 /* Wait untill the main PLL is used as system clock source */
269 /* Wait untill the main PLL is used as system clock source */
267 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
270 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
268 if(srcfreq>150000000)
271 if(srcfreq>150000000)
269 {
272 {
270 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_5WS;
273 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_5WS;
271 }
274 }
272 if((srcfreq<150000000) && (srcfreq>=120000000))
275 if((srcfreq<150000000) && (srcfreq>=120000000))
273 {
276 {
274 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_4WS;
277 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_4WS;
275 }
278 }
276 if((srcfreq<120000000) && (srcfreq>=90000000))
279 if((srcfreq<120000000) && (srcfreq>=90000000))
277 {
280 {
278 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_3WS;
281 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_3WS;
279 }
282 }
280 if((srcfreq<90000000) && (srcfreq>=60000000))
283 if((srcfreq<90000000) && (srcfreq>=60000000))
281 {
284 {
282 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_2WS;
285 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_2WS;
283 }
286 }
284 if((srcfreq<60000000) && (srcfreq>=30000000))
287 if((srcfreq<60000000) && (srcfreq>=30000000))
285 {
288 {
286 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_1WS;
289 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_1WS;
287 }
290 }
288 if(srcfreq<30000000)
291 if(srcfreq<30000000)
289 {
292 {
290 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_0WS;
293 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_0WS;
291 }
294 }
292 return srcfreq;
295 return srcfreq;
293 }
296 }
294
297
295 void configureSysTick()
298 void configureSysTick()
296 {
299 {
297 extern uint32_t currentCpuFreq;
300 extern uint32_t currentCpuFreq;
298 uint32_t us=currentCpuFreq/(1000*10);
301 uint32_t us=currentCpuFreq/(1000*10);
299 SysTick_Config(us);
302 SysTick_Config(us);
300 }
303 }
301
304
302 int setCpuFreq(uint32_t freq)
305 int setCpuFreq(uint32_t freq)
303 {
306 {
304 extern uint32_t OSC0;
307 extern uint32_t OSC0;
305 extern uint32_t INTOSC;
308 extern uint32_t INTOSC;
306 uint8_t i=0;
309 uint8_t i=0;
307 uint32_t curentFeq = getCpuFreq();
310 uint32_t curentFeq = getCpuFreq();
308 if(curentFeq==freq)return curentFeq;
311 if(curentFeq==freq)return curentFeq;
309 if((freq>2000000) && (freq<=250000000)) //be carefull with 250MHz!!!
312 if((freq>2000000) && (freq<=250000000)) //be carefull with 250MHz!!!
310 {
313 {
311 if((RCC->CFGR & 0xC) == 8) //PLL used as sys clk
314 if((RCC->CFGR & 0xC) == 8) //PLL used as sys clk
312 {
315 {
313 return setPll(freq);
316 return setPll(freq);
314 }
317 }
315 else if((RCC->CFGR & 0xC) == 0) //HSI used as sys clk
318 else if((RCC->CFGR & 0xC) == 0) //HSI used as sys clk
316 {
319 {
317 if((INTOSC%freq)==0) //now check if we can directly divide HSI
320 if((INTOSC%freq)==0) //now check if we can directly divide HSI
318 {
321 {
319 if(freq==INTOSC)
322 if(freq==INTOSC)
320 {
323 {
321 RCC->CFGR &= ~(0xF<<4);
324 RCC->CFGR &= ~(0xF<<4);
322 return freq;
325 return freq;
323 }
326 }
324 for(i=1;i<8;i++)
327 for(i=1;i<8;i++)
325 {
328 {
326 if((freq<<i)==INTOSC)
329 if((freq<<i)==INTOSC)
327 {
330 {
328 RCC->CFGR &= ~(0xF<<4);
331 RCC->CFGR &= ~(0xF<<4);
329 RCC->CFGR |= ((0x8|i)<<4);
332 RCC->CFGR |= ((0x8|i)<<4);
330 return freq;
333 return freq;
331 }
334 }
332 }
335 }
333 }
336 }
334 else
337 else
335 return setPll(freq);
338 return setPll(freq);
336 }
339 }
337 else //HSE used as sys clk
340 else //HSE used as sys clk
338 {
341 {
339 if((OSC0%freq)==0) //now check if we can directly divide HSI
342 if((OSC0%freq)==0) //now check if we can directly divide HSI
340 {
343 {
341 if(freq==OSC0)
344 if(freq==OSC0)
342 {
345 {
343 RCC->CFGR &= ~(0xF<<4);
346 RCC->CFGR &= ~(0xF<<4);
344 return freq;
347 return freq;
345 }
348 }
346 for(i=1;i<8;i++)
349 for(i=1;i<8;i++)
347 {
350 {
348 if((freq<<i)==OSC0)
351 if((freq<<i)==OSC0)
349 {
352 {
350 RCC->CFGR &= ~(0xF<<4);
353 RCC->CFGR &= ~(0xF<<4);
351 RCC->CFGR |= ((0x8|i)<<4);
354 RCC->CFGR |= ((0x8|i)<<4);
352 return freq;
355 return freq;
353 }
356 }
354 }
357 }
355 }
358 }
356 else
359 else
357 return setPll(freq);
360 return setPll(freq);
358 }
361 }
359 }
362 }
360 return 0;
363 return 0;
361 }
364 }
362
365
363
366
364 void enable_FPU()
367 void enable_FPU()
365 {
368 {
366 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
369 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
367 __asm__("dsb");
370 __asm__("dsb");
368 __asm__("isb");
371 __asm__("isb");
369 }
372 }
370
373
371
374
372
375
373
376
374
377
375
378
@@ -1,16 +1,17
1 TEMPLATE = lib
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
2 OBJECTS_DIR = obj
3
3
4 SOURCES += \
4 SOURCES += \
5 core.c \
5 core.c \
6 threads.c
6 threads.c \
7 irq_handlers.c
7
8
8 INCLUDEPATH += ../../includes \
9 INCLUDEPATH += ../../includes \
9 ../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 ../CPU/CMSIS/Include
11 ../CPU/CMSIS/Include
11
12
12
13
13 UCMODEL=stm32f4
14 UCMODEL=stm32f4
14
15
15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 INSTALLS += target
17 INSTALLS += target
@@ -1,63 +1,63
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 #ifndef CPUFREQ
15 #ifndef CPUFREQ
16 #define CPUFREQ (16*1000*1000)
16 #define CPUFREQ (16*1000*1000)
17 #endif
17 #endif
18 currentCpuFreq = CPUFREQ;
18 currentCpuFreq = CPUFREQ;
19 enable_FPU();
19 enable_FPU();
20 RCC->CR |= (uint32_t)0x00000001;
20 RCC->CR |= (uint32_t)0x00000001;
21 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
21 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
22 reset_AHB1();
22 reset_AHB1();
23 reset_AHB2();
23 reset_AHB2();
24 reset_APB1();
24 reset_APB1();
25 reset_APB2();
25 reset_APB2();
26 RCC->CR |= (uint32_t)0x00000001;
26 RCC->CR |= (uint32_t)0x00000001;
27 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
27 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
28 RCC->CFGR = 0x00000000;
28 RCC->CFGR = 0x00000000;
29 RCC->CIR = 0x00000000;
29 RCC->CIR = 0x00000000;
30 SCB->VTOR = FLASH_BASE;
30 SCB->VTOR = FLASH_BASE;
31 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
31 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
32 PWR->CR |= PWR_CR_PMODE;
32 PWR->CR |= PWR_CR_PMODE;
33 currentCpuFreq=setCpuFreq(currentCpuFreq);
33 currentCpuFreq=setCpuFreq(currentCpuFreq);
34 currentCpuFreq=getCpuFreq();
34 currentCpuFreq=getCpuFreq();
35 configureSysTick();
35 configureSysTick();
36 bsp_init();
36 bsp_init();
37 printf("SysTick Configured to reach 100us period\n\r");
37 printf("SysTick Configured to reach 100us period\n\r");
38 RCC_ClocksTypeDef RCC_ClocksStatus;
38 RCC_ClocksTypeDef RCC_ClocksStatus;
39 RCC_GetClocksFreq(&RCC_ClocksStatus);
39 RCC_GetClocksFreq(&RCC_ClocksStatus);
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);
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);
41 printf("Enter Main\n\r");
41 printf("Enter Main\n\r");
42 int res=main();
42 int res=main();
43 printf("\n\rprogram exited with code ");
43 printf("\n\rprogram exited with code ");
44 printf("%u",res);
44 printf("%u",res);
45 printf("\n\r");
45 printf("\n\r");
46 while(1)
46 while(1)
47 {
47 {
48 delay_100us(10000);
48 delay_100us(10000);
49 gpioset(LED1);
49 gpioset(LED2);
50 delay_100us(10000);
50 delay_100us(10000);
51 gpioclr(LED1);
51 gpioclr(LED2);
52 }
52 }
53 }
53 }
54
54
55
55
56
56
57
57
58
58
59
59
60
60
61
61
62
62
63
63
@@ -1,171 +1,171
1 /*
1 /*
2 *****************************************************************************
2 *****************************************************************************
3 **
3 **
4 ** File : stm32_flash.ld
4 ** File : stm32_flash.ld
5 **
5 **
6 ** Abstract : Linker script for STM32F407VG Device with
6 ** Abstract : Linker script for STM32F407VG Device with
7 ** 1024KByte FLASH, 192KByte RAM
7 ** 1024KByte FLASH, 192KByte RAM
8 **
8 **
9 ** Set heap size, stack size and stack location according
9 ** Set heap size, stack size and stack location according
10 ** to application requirements.
10 ** to application requirements.
11 **
11 **
12 ** Set memory bank area and size if external memory is used.
12 ** Set memory bank area and size if external memory is used.
13 **
13 **
14 ** Target : STMicroelectronics STM32
14 ** Target : STMicroelectronics STM32
15 **
15 **
16 ** Environment : Atollic TrueSTUDIO(R)
16 ** Environment : Atollic TrueSTUDIO(R)
17 **
17 **
18 ** Distribution: The file is distributed �as is,� without any warranty
18 ** Distribution: The file is distributed �as is,� without any warranty
19 ** of any kind.
19 ** of any kind.
20 **
20 **
21 ** (c)Copyright Atollic AB.
21 ** (c)Copyright Atollic AB.
22 ** You may use this file as-is or modify it according to the needs of your
22 ** You may use this file as-is or modify it according to the needs of your
23 ** project. Distribution of this file (unmodified or modified) is not
23 ** project. Distribution of this file (unmodified or modified) is not
24 ** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
24 ** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
25 ** rights to distribute the assembled, compiled & linked contents of this
25 ** rights to distribute the assembled, compiled & linked contents of this
26 ** file as part of an application binary file, provided that it is built
26 ** file as part of an application binary file, provided that it is built
27 ** using the Atollic TrueSTUDIO(R) toolchain.
27 ** using the Atollic TrueSTUDIO(R) toolchain.
28 **
28 **
29 *****************************************************************************
29 *****************************************************************************
30 */
30 */
31
31
32 /* Entry Point */
32 /* Entry Point */
33 ENTRY(Reset_Handler)
33 ENTRY(Reset_Handler)
34
34
35 /* Highest address of the user mode stack */
35 /* Highest address of the user mode stack */
36 _estack = 0x20020000; /* end of 128K RAM on AHB bus*/
36 _estack = 0x20020000; /* end of 128K RAM on AHB bus*/
37
37
38 /* Generate a link error if heap and stack don't fit into RAM */
38 /* Generate a link error if heap and stack don't fit into RAM */
39 _Min_Heap_Size = 0; /* required amount of heap */
39 _Min_Heap_Size = 0x2000; /* required amount of heap */
40 _Min_Stack_Size = 0x1000; /* required amount of stack */
40 _Min_Stack_Size = 0x2000; /* required amount of stack */
41
41
42 /* Specify the memory areas */
42 /* Specify the memory areas */
43 MEMORY
43 MEMORY
44 {
44 {
45 FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024k
45 FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024k
46 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112k
46 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112k
47 CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64k
47 CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64k
48 MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
48 MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
49 }
49 }
50
50
51 /* Define output sections */
51 /* Define output sections */
52 SECTIONS
52 SECTIONS
53 {
53 {
54 /* The startup code goes first into FLASH */
54 /* The startup code goes first into FLASH */
55 .isr_vector :
55 .isr_vector :
56 {
56 {
57 . = ALIGN(4);
57 . = ALIGN(4);
58 KEEP(*(.isr_vector)) /* Startup code */
58 KEEP(*(.isr_vector)) /* Startup code */
59 . = ALIGN(4);
59 . = ALIGN(4);
60 } >FLASH
60 } >FLASH
61
61
62 /* The program code and other data goes into FLASH */
62 /* The program code and other data goes into FLASH */
63 .text :
63 .text :
64 {
64 {
65 . = ALIGN(4);
65 . = ALIGN(4);
66 *(.text) /* .text sections (code) */
66 *(.text) /* .text sections (code) */
67 *(.text*) /* .text* sections (code) */
67 *(.text*) /* .text* sections (code) */
68 *(.rodata) /* .rodata sections (constants, strings, etc.) */
68 *(.rodata) /* .rodata sections (constants, strings, etc.) */
69 *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
69 *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
70 *(.glue_7) /* glue arm to thumb code */
70 *(.glue_7) /* glue arm to thumb code */
71 *(.glue_7t) /* glue thumb to arm code */
71 *(.glue_7t) /* glue thumb to arm code */
72 *(.eh_frame)
72 *(.eh_frame)
73
73
74 KEEP (*(.init))
74 KEEP (*(.init))
75 KEEP (*(.fini))
75 KEEP (*(.fini))
76
76
77 . = ALIGN(4);
77 . = ALIGN(4);
78 _etext = .; /* define a global symbols at end of code */
78 _etext = .; /* define a global symbols at end of code */
79 } >FLASH
79 } >FLASH
80
80
81
81
82 .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
82 .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
83 .ARM : {
83 .ARM : {
84 __exidx_start = .;
84 __exidx_start = .;
85 *(.ARM.exidx*)
85 *(.ARM.exidx*)
86 __exidx_end = .;
86 __exidx_end = .;
87 } >FLASH
87 } >FLASH
88
88
89 .preinit_array :
89 .preinit_array :
90 {
90 {
91 PROVIDE_HIDDEN (__preinit_array_start = .);
91 PROVIDE_HIDDEN (__preinit_array_start = .);
92 KEEP (*(.preinit_array*))
92 KEEP (*(.preinit_array*))
93 PROVIDE_HIDDEN (__preinit_array_end = .);
93 PROVIDE_HIDDEN (__preinit_array_end = .);
94 } >FLASH
94 } >FLASH
95 .init_array :
95 .init_array :
96 {
96 {
97 PROVIDE_HIDDEN (__init_array_start = .);
97 PROVIDE_HIDDEN (__init_array_start = .);
98 KEEP (*(SORT(.init_array.*)))
98 KEEP (*(SORT(.init_array.*)))
99 KEEP (*(.init_array*))
99 KEEP (*(.init_array*))
100 PROVIDE_HIDDEN (__init_array_end = .);
100 PROVIDE_HIDDEN (__init_array_end = .);
101 } >FLASH
101 } >FLASH
102 .fini_array :
102 .fini_array :
103 {
103 {
104 PROVIDE_HIDDEN (__fini_array_start = .);
104 PROVIDE_HIDDEN (__fini_array_start = .);
105 KEEP (*(.fini_array*))
105 KEEP (*(.fini_array*))
106 KEEP (*(SORT(.fini_array.*)))
106 KEEP (*(SORT(.fini_array.*)))
107 PROVIDE_HIDDEN (__fini_array_end = .);
107 PROVIDE_HIDDEN (__fini_array_end = .);
108 } >FLASH
108 } >FLASH
109
109
110 /* used by the startup to initialize data */
110 /* used by the startup to initialize data */
111 _sidata = .;
111 _sidata = .;
112
112
113 /* Initialized data sections goes into RAM, load LMA copy after code */
113 /* Initialized data sections goes into RAM, load LMA copy after code */
114 .data : AT ( _sidata )
114 .data : AT ( _sidata )
115 {
115 {
116 . = ALIGN(4);
116 . = ALIGN(4);
117 _sdata = .; /* create a global symbol at data start */
117 _sdata = .; /* create a global symbol at data start */
118 *(.data) /* .data sections */
118 *(.data) /* .data sections */
119 *(.data*) /* .data* sections */
119 *(.data*) /* .data* sections */
120
120
121 . = ALIGN(4);
121 . = ALIGN(4);
122 _edata = .; /* define a global symbol at data end */
122 _edata = .; /* define a global symbol at data end */
123 } >RAM
123 } >RAM
124
124
125 /* Uninitialized data section */
125 /* Uninitialized data section */
126 . = ALIGN(4);
126 . = ALIGN(4);
127 .bss :
127 .bss :
128 {
128 {
129 /* This is used by the startup in order to initialize the .bss secion */
129 /* This is used by the startup in order to initialize the .bss secion */
130 _sbss = .; /* define a global symbol at bss start */
130 _sbss = .; /* define a global symbol at bss start */
131 __bss_start__ = _sbss;
131 __bss_start__ = _sbss;
132 *(.bss)
132 *(.bss)
133 *(.bss*)
133 *(.bss*)
134 *(COMMON)
134 *(COMMON)
135
135
136 . = ALIGN(4);
136 . = ALIGN(4);
137 _ebss = .; /* define a global symbol at bss end */
137 _ebss = .; /* define a global symbol at bss end */
138 __bss_end__ = _ebss;
138 __bss_end__ = _ebss;
139 } >RAM
139 } >RAM
140
140
141 /* User_heap_stack section, used to check that there is enough RAM left */
141 /* User_heap_stack section, used to check that there is enough RAM left */
142 ._user_heap_stack :
142 ._user_heap_stack :
143 {
143 {
144 . = ALIGN(4);
144 . = ALIGN(4);
145 PROVIDE ( end = . );
145 PROVIDE ( end = . );
146 PROVIDE ( _end = . );
146 PROVIDE ( _end = . );
147 . = . + _Min_Heap_Size;
147 . = . + _Min_Heap_Size;
148 . = . + _Min_Stack_Size;
148 . = . + _Min_Stack_Size;
149 . = ALIGN(4);
149 . = ALIGN(4);
150 } >RAM
150 } >RAM
151
151
152 /* MEMORY_bank1 section, code must be located here explicitly */
152 /* MEMORY_bank1 section, code must be located here explicitly */
153 /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
153 /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
154 .memory_b1_text :
154 .memory_b1_text :
155 {
155 {
156 *(.mb1text) /* .mb1text sections (code) */
156 *(.mb1text) /* .mb1text sections (code) */
157 *(.mb1text*) /* .mb1text* sections (code) */
157 *(.mb1text*) /* .mb1text* sections (code) */
158 *(.mb1rodata) /* read-only data (constants) */
158 *(.mb1rodata) /* read-only data (constants) */
159 *(.mb1rodata*)
159 *(.mb1rodata*)
160 } >MEMORY_B1
160 } >MEMORY_B1
161
161
162 /* Remove information from the standard libraries */
162 /* Remove information from the standard libraries */
163 /DISCARD/ :
163 /DISCARD/ :
164 {
164 {
165 libc.a ( * )
165 libc.a ( * )
166 libm.a ( * )
166 libm.a ( * )
167 libgcc.a ( * )
167 libgcc.a ( * )
168 }
168 }
169
169
170 .ARM.attributes 0 : { *(.ARM.attributes) }
170 .ARM.attributes 0 : { *(.ARM.attributes) }
171 }
171 }
@@ -1,261 +1,282
1 #include <stdlib.h>
1 #include <stdlib.h>
2 #include <errno.h>
2 #include <errno.h>
3 #include <string.h>
3 #include <string.h>
4 #include <sys/stat.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
5 #include <sys/types.h>
6 #include <sys/times.h>
6 #include <sys/times.h>
7 #include <streamdevices.h>
7 #include <streamdevices.h>
8 #include <string.h>
8 #include <string.h>
9 #include <stdio.h>
9 #include <stdio.h>
10 #include <gpio.h>
10 #include <gpio.h>
11 #include <uart.h>
11 #include <uart.h>
12 #include <stdint.h>
12 #include <stdint.h>
13 #include <bsp.h>
13
14
14 #undef errno
15 #undef errno
15
16
16
17
17
18
18 #ifdef __cplusplus
19 #ifdef __cplusplus
19 extern "C" {
20 extern "C" {
20 #endif
21 #endif
21 extern int errno;
22 extern int errno;
22 extern int32_t __max_opened_files__;
23 extern int32_t __max_opened_files__;
23 extern streamdevice* __opnfiles__[];
24 extern streamdevice* __opnfiles__[];
24 extern int32_t* __fs_root__;
25 extern int32_t* __fs_root__;
25 extern int32_t __fs_root_size__;
26 extern int32_t __fs_root_size__;
26
27
27 char *__env[1] = { 0 };
28 char *__env[1] = { 0 };
28 char **environ = __env;
29 char **environ = __env;
29
30
30 int _exit()
31 int _exit()
31 {
32 {
32 while(1);
33 while(1)
34 {
35 delay_100us(10000);
36 gpioset(LED2);
37 delay_100us(10000);
38 gpioclr(LED2);
39 }
33 }
40 }
34
41
35 int _close(int file)
42 int _close(int file)
36 {
43 {
37 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
44 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
38 {
45 {
39 return __opnfiles__[file]->ops->close( __opnfiles__[file]);
46 return __opnfiles__[file]->ops->close( __opnfiles__[file]);
40 }
47 }
41 return 0;
48 return 0;
42 }
49 }
43
50
44
51
45 int _write(int file, char *ptr, int len)
52 int _write(int file, char *ptr, int len)
46 {
53 {
47 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
54 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
48 {
55 {
49 if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len;
56 if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len;
50 }
57 }
51 return 0;
58 return len;
52 }
59 }
53
60
54 int _execve(char *name, char **argv, char **env) {
61 int _execve(char *name, char **argv, char **env) {
55 errno = ENOMEM;
62 errno = ENOMEM;
56 return -1;
63 return -1;
57 }
64 }
58
65
59
66
60 int _fork(void) {
67 int _fork(void) {
61 errno = EAGAIN;
68 errno = EAGAIN;
62 return -1;
69 return -1;
63 }
70 }
64
71
65 int _fstat(int file, struct stat *st) {
72 int _fstat(int file, struct stat *st) {
66 st->st_mode = S_IFCHR;
73 st->st_mode = S_IFCHR;
67 return 0;
74 return 0;
68 }
75 }
69
76
70
77
71 int _getpid(void) {
78 int _getpid(void) {
72 return 1;
79 return 1;
73 }
80 }
74
81
75
82
76 int _isatty(int file) {
83 int _isatty(int file) {
77 return 1;
84 return 1;
78 }
85 }
79
86
80
87
81 int _kill(int pid, int sig) {
88 int _kill(int pid, int sig) {
82 errno = EINVAL;
89 errno = EINVAL;
83 return -1;
90 return -1;
84 }
91 }
85
92
86
93
87 int _link(char *old, char *_new) {
94 int _link(char *old, char *_new) {
88 errno = EMLINK;
95 errno = EMLINK;
89 return -1;
96 return -1;
90 }
97 }
91
98
92
99
93 int _lseek(int file, int ptr, int dir) {
100 int _lseek(int file, int ptr, int dir) {
94 return 0;
101 return 0;
95 }
102 }
96
103
97 #include <gpio.h>
104 #include <gpio.h>
98
105
99 int _open(const char *name, int flags, int mode)
106 int _open(const char *name, int flags, int mode)
100 {
107 {
101 if(!strncmp("UART", name, 4) && ((name[4] & 0x30)==0x30))
108 if(!strncmp("UART", name, 4) && ((name[4] & 0x30)==0x30))
102 {
109 {
103 //uart_t* uart1 = malloc(sizeof(uart_t));
110 //uart_t* uart1 = malloc(sizeof(uart_t));
104 streamdevice* fd1 = malloc(sizeof(streamdevice));
111 streamdevice* fd1 = malloc(sizeof(streamdevice));
105 uart_t uart=uartopen((name[4] & 0xF)-1);
112 uart_t uart=uartopen((name[4] & 0xF)-1);
106 if(uart!=-1);
113 if(uart!=-1);
107 {
114 {
108 uartmkstreamdev(uart,fd1);
115 uartmkstreamdev(uart,fd1);
109 int i=2;
116 int i=2;
110 while((i<__max_opened_files__) && (__opnfiles__[i]!=NULL))i++;
117 while((i<__max_opened_files__) && (__opnfiles__[i]!=NULL))i++;
111 if(i!=__max_opened_files__)
118 if(i!=__max_opened_files__)
112 {
119 {
113 __opnfiles__[i] = fd1;
120 __opnfiles__[i] = fd1;
114 return i;
121 return i;
115 }
122 }
116 else printf("Too much files opened\n\r");
123 else printf("Too much files opened\n\r");
117 }
124 }
118 }
125 }
119 return -1;
126 return -1;
120 }
127 }
121
128
122 int _read(int file, char *ptr, int len) {
129 int _read(int file, char *ptr, int len) {
123 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
130 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
124 {
131 {
125 if(__opnfiles__[file]->ops->read(__opnfiles__[file],ptr,1,len)) return len;
132 if(__opnfiles__[file]->ops->read(__opnfiles__[file],ptr,1,len)) return len;
126 }
133 }
127 return 0;
134 return 0;
128 }
135 }
129
136
130
137
131
138
132 caddr_t _sbrk(int incr) {
139 caddr_t _sbrk(int incr) {
133 register char * stack_ptr __asm__ ("sp");
140 register char * stack_ptr __asm__ ("sp");
134 extern char _end; /* Defined by the linker */
141 extern char _end; /* Defined by the linker */
135 static char *heap_end;
142 static char *heap_end;
136 char *prev_heap_end;
143 char *prev_heap_end;
137 if (heap_end == 0) {
144 if (heap_end == 0) {
138 heap_end = &_end;
145 heap_end = &_end;
139 }
146 }
140 prev_heap_end = heap_end;
147 prev_heap_end = heap_end;
141 if (heap_end + incr > stack_ptr) {
148 if (heap_end + incr > stack_ptr) {
142 _write (1, "Heap and stack collision\n", 25);
149 printf("Heap and stack collision\n");
143 abort ();
150 //abort ();
151 while(1)
152 {
153 delay_100us(10000);
154 gpioset(LED2);
155 delay_100us(10000);
156 gpioclr(LED2);
157 }
144 }
158 }
145 heap_end += incr;
159 heap_end += incr;
146 return (caddr_t) prev_heap_end;
160 return (caddr_t) prev_heap_end;
147 }
161 }
148
162
149
163
150
164
151 int _stat(char *file, struct stat *st) {
165 int _stat(char *file, struct stat *st) {
152 st->st_mode = S_IFCHR;
166 st->st_mode = S_IFCHR;
153 return 0;
167 return 0;
154 }
168 }
155
169
156
170
157 int _times(struct tms *buf) {
171 int _times(struct tms *buf) {
158 return -1;
172 return -1;
159 }
173 }
160
174
161
175
162 int _unlink(char *name) {
176 int _unlink(char *name) {
163 errno = ENOENT;
177 errno = ENOENT;
164 return -1;
178 return -1;
165 }
179 }
166
180
167 int _wait(int *status) {
181 int _wait(int *status) {
168 errno = ECHILD;
182 errno = ECHILD;
169 return -1;
183 return -1;
170 }
184 }
171
185
172
186
173 int _read_r (struct _reent *r, int file, char * ptr, int len)
187 int _read_r (struct _reent *r, int file, char * ptr, int len)
174 {
188 {
175 r = r;
189 r = r;
176 file = file;
190 file = file;
177 ptr = ptr;
191 ptr = ptr;
178 len = len;
192 len = len;
179 _read(file,ptr,len);
193 _read(file,ptr,len);
180 errno = EINVAL;
194 errno = EINVAL;
181 return -1;
195 return -1;
182 }
196 }
183
197
184 /***************************************************************************/
198 /***************************************************************************/
185
199
186 int _lseek_r (struct _reent *r, int file, int ptr, int dir)
200 int _lseek_r (struct _reent *r, int file, int ptr, int dir)
187 {
201 {
188 r = r;
202 r = r;
189 file = file;
203 file = file;
190 ptr = ptr;
204 ptr = ptr;
191 dir = dir;
205 dir = dir;
192
206
193 return 0;
207 return 0;
194 }
208 }
195
209
196 /***************************************************************************/
210 /***************************************************************************/
197
211
198 int _write_r (struct _reent *r, int file, char * ptr, int len)
212 int _write_r (struct _reent *r, int file, char * ptr, int len)
199 {
213 {
200 return _write(file, ptr, len);
214 return _write(file, ptr, len);
201 }
215 }
202
216
203 /***************************************************************************/
217 /***************************************************************************/
204
218
205 int _close_r (struct _reent *r, int file)
219 int _close_r (struct _reent *r, int file)
206 {
220 {
207 return 0;
221 return 0;
208 }
222 }
209
223
210 /***************************************************************************/
224 /***************************************************************************/
211
225
212 caddr_t _sbrk_r (struct _reent *r, int incr)
226 caddr_t _sbrk_r (struct _reent *r, int incr)
213 {
227 {
214 register char * stack_ptr __asm__ ("sp");
228 register char * stack_ptr __asm__ ("sp");
215 extern char _end; /* Defined by the linker */
229 extern char _end; /* Defined by the linker */
216 static char *heap_end;
230 static char *heap_end;
217 char *prev_heap_end;
231 char *prev_heap_end;
218 if (heap_end == 0) {
232 if (heap_end == 0) {
219 heap_end = &_end;
233 heap_end = &_end;
220 }
234 }
221 prev_heap_end = heap_end;
235 prev_heap_end = heap_end;
222 if (heap_end + incr > stack_ptr) {
236 if (heap_end + incr > stack_ptr) {
223 _write (1, "Heap and stack collision\n", 25);
237 printf( "Heap and stack collision\n");
224 abort ();
238 //abort ();
239 while(1)
240 {
241 delay_100us(10000);
242 gpioset(LED2);
243 delay_100us(10000);
244 gpioclr(LED2);
245 }
225 }
246 }
226 heap_end += incr;
247 heap_end += incr;
227 return (caddr_t) prev_heap_end;
248 return (caddr_t) prev_heap_end;
228 }
249 }
229
250
230 /***************************************************************************/
251 /***************************************************************************/
231
252
232 int _fstat_r (struct _reent *r, int file, struct stat * st)
253 int _fstat_r (struct _reent *r, int file, struct stat * st)
233 {
254 {
234 r = r;
255 r = r;
235 file = file;
256 file = file;
236
257
237 memset (st, 0, sizeof (* st));
258 memset (st, 0, sizeof (* st));
238 st->st_mode = S_IFCHR;
259 st->st_mode = S_IFCHR;
239 return 0;
260 return 0;
240 }
261 }
241
262
242 /***************************************************************************/
263 /***************************************************************************/
243 int _open_r(struct _reent *r,const char *name, int flags, int mode)
264 int _open_r(struct _reent *r,const char *name, int flags, int mode)
244 {
265 {
245 return _open(name, flags, mode);
266 return _open(name, flags, mode);
246 }
267 }
247
268
248 int _isatty_r(struct _reent *r, int fd)
269 int _isatty_r(struct _reent *r, int fd)
249 {
270 {
250 r = r;
271 r = r;
251 fd = fd;
272 fd = fd;
252
273
253 return 1;
274 return 1;
254 }
275 }
255
276
256
277
257 #ifdef __cplusplus
278 #ifdef __cplusplus
258 }
279 }
259 #endif
280 #endif
260
281
261
282
@@ -1,41 +1,41
1 #
1 #
2 # qmake configuration for arm-none-eabi
2 # qmake configuration for arm-none-eabi
3 #
3 #
4
4
5 CONFIG +=
5 CONFIG +=
6 QMAKE_CC = arm-none-eabi-gcc
6 QMAKE_CC = arm-none-eabi-gcc
7 QMAKE_CFLAGS +=
7 QMAKE_CFLAGS +=
8 QMAKE_CFLAGS_DEPS += -M
8 QMAKE_CFLAGS_DEPS += -M
9 QMAKE_CFLAGS_WARN_ON += -Wall
9 QMAKE_CFLAGS_WARN_ON += -Wall
10 QMAKE_CFLAGS_WARN_OFF += -w
10 QMAKE_CFLAGS_WARN_OFF += -w
11 QMAKE_CFLAGS_RELEASE += -O2
11 QMAKE_CFLAGS_RELEASE += -O3
12 QMAKE_CFLAGS_DEBUG += -g -O0
12 QMAKE_CFLAGS_DEBUG += -g -O0
13
13
14 QMAKE_CXX = arm-none-eabi-g++
14 QMAKE_CXX = arm-none-eabi-g++
15 QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s
15 QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s
16 QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS
16 QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS
17 QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON
17 QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON
18 QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF
18 QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF
19 QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
19 QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
20 QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG
20 QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG
21 QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
21 QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
22 QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB
22 QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB
23 QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC
23 QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC
24 QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS
24 QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS
25
25
26 QMAKE_LINK = arm-none-eabi-gcc
26 QMAKE_LINK = arm-none-eabi-gcc
27 QMAKE_LINK_SHLIB = arm-none-eabi-gcc
27 QMAKE_LINK_SHLIB = arm-none-eabi-gcc
28 QMAKE_LINK_C = arm-none-eabi-gcc
28 QMAKE_LINK_C = arm-none-eabi-gcc
29 QMAKE_LINK_C_SHLIB = arm-none-eabi-gcc
29 QMAKE_LINK_C_SHLIB = arm-none-eabi-gcc
30 QMAKE_LFLAGS +=
30 QMAKE_LFLAGS +=
31 QMAKE_LFLAGS_RELEASE +=
31 QMAKE_LFLAGS_RELEASE += -O3
32 QMAKE_LFLAGS_DEBUG +=
32 QMAKE_LFLAGS_DEBUG +=
33 QMAKE_LFLAGS_APP +=
33 QMAKE_LFLAGS_APP +=
34 QMAKE_LFLAGS_SHLIB +=
34 QMAKE_LFLAGS_SHLIB +=
35 QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB
35 QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB
36 QMAKE_LFLAGS_THREAD +=
36 QMAKE_LFLAGS_THREAD +=
37
37
38 QMAKE_AR = arm-none-eabi-ar -ru
38 QMAKE_AR = arm-none-eabi-ar -ru
39 QMAKE_LIB = arm-none-eabi-ar -ru
39 QMAKE_LIB = arm-none-eabi-ar -ru
40 QMAKE_RANLIB =
40 QMAKE_RANLIB =
41
41
@@ -1,75 +1,77
1 #
1 #
2 # qmake configuration for stm32f4
2 # qmake configuration for stm32f4
3 #
3 #
4 #
4 #
5
5
6
6
7 isEmpty(_stm32f4_conf){
7 isEmpty(_stm32f4_conf){
8 _stm32f4_conf="oneshot"
8 _stm32f4_conf="oneshot"
9
9
10 QMAKE_CFLAGS=-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99
10 QMAKE_CFLAGS=-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99
11
11
12 include(../common/arm-none-eabi.conf)
12 include(../common/arm-none-eabi.conf)
13
13
14 DEFINES += __OPTIMIZED_MATH
14 DEFINES += __OPTIMIZED_MATH
15 DEFINES += \"assert_param(expr)=((void)0)\"
15 DEFINES += \"assert_param(expr)=((void)0)\"
16 INCLUDEPATH += $$PWD
16 INCLUDEPATH += $$PWD
17
17
18 DEFINES += __FPU_PRESENT=1
18 DEFINES += __FPU_PRESENT=1
19 DEFINES += ARM_MATH_CM4
19 DEFINES += ARM_MATH_CM4
20
20
21 DEFINES += BSP="\"\\\"$$BSP"\\\"\"
21 DEFINES += BSP="\"\\\"$$BSP"\\\"\"
22
22
23 CONFIG += cpu
23 CONFIG += cpu
24
24
25 contains( TEMPLATE, app ) {
25 contains( TEMPLATE, app ) {
26 OBJECTS_DIR=obj
26 OBJECTS_DIR=obj-$$UCMODEL
27 DESTDIR=bin
27 DESTDIR=bin-$$UCMODEL
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"
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 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"
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 LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP
31 LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP
32 LIBS += -lbsp
32 LIBS += -lbsp
33
33
34
34
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
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 INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP
37 INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP
38
38
39 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c
39 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c
40 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c
40 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c
41 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/startup.s
41 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/startup.s
42 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c
42 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c
43
43
44 # OTHER_FILES += $$[QT_INSTALL_PREFIX]/ucfiles/stm32f4/$$CPU/stm32_flash.ld
44 # OTHER_FILES += $$[QT_INSTALL_PREFIX]/ucfiles/stm32f4/$$CPU/stm32_flash.ld
45
45
46 stflash.target = stflash
46 stflash.target = stflash
47 stflash.commands = cd $$DESTDIR && sudo st-flash write $(QMAKE_TARGET).bin 0x08000000
47 stflash.commands = cd $$DESTDIR && sudo st-flash write $(QMAKE_TARGET).bin 0x08000000
48 dfu.target = dfu
48 dfu.target = dfu
49 dfu.commands = cd $$DESTDIR && sudo dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000
49 dfu.commands = cd $$DESTDIR && dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000
50 QMAKE_EXTRA_TARGETS += stflash dfu
50 QMAKE_EXTRA_TARGETS += stflash dfu
51 }
51 }
52
52
53 contains( TEMPLATE, lib ) {
53 contains( TEMPLATE, lib ) {
54 CONFIG+=staticlib
54 CONFIG+=staticlib
55 OBJECTS_DIR=obj-$$UCMODEL
56 DESTDIR=bin-$$UCMODEL
55 message( "You can only build static library for stm32f4" )
57 message( "You can only build static library for stm32f4" )
56 }
58 }
57
59
58 include(../common/libuc2libs.conf)
60 include(../common/libuc2libs.conf)
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
74
76
75
77
General Comments 0
You need to be logged in to leave comments. Login now