##// 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 2 #-- This file is a part of the libuc, microcontroler library
3 3 #-- Copyright (C) 2012, Alexis Jeandet
4 4 #--
5 5 #-- This program is free software; you can redistribute it and/or modify
6 6 #-- it under the terms of the GNU General Public License as published by
7 7 #-- the Free Software Foundation; either version 3 of the License, or
8 8 #-- (at your option) any later version.
9 9 #--
10 10 #-- This program is distributed in the hope that it will be useful,
11 11 #-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 #-- GNU General Public License for more details.
14 14 #--
15 15 #-- You should have received a copy of the GNU General Public License
16 16 #-- along with this program; if not, write to the Free Software
17 17 #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 #-------------------------------------------------------------------------------
19 19 #-- Author : Alexis Jeandet
20 #-- Mail : alexis.jeandet@gmail.com
20 #-- Mail : alexis.jeandet@member.fsf.org
21 21 #-------------------------------------------------------------------------------
22 22
23 23 ________
24 24 licence:
25 25 ~~~~~~~~
26 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 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 30 Intallation:
31 31 ~~~~~~~~~~~~
32 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 33 -set the libuc2 environement varriable, with linux you can append this to the end of your /etc/bashrc file:
37 34 libuc2=/opt/libuc2
38 35 replace /opt/ by the path where is installed the libuc2.
39 36
40 37 ______________
41 38 Contributions:
42 39 ~~~~~~~~~~~~~~
43 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 44 Documentation:
48 45 ~~~~~~~~~~~~~~
49 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 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2011, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #include "bsp.h"
23 23 #include <streamdevices.h>
24 24 #include <malloc.h>
25 25 #include <gpio.h>
26 26 #include <uart.h>
27 27 #include <stdio.h>
28 28 #include <stm32f4xx_gpio.h>
29 29 #include <stm32f4xx_fsmc.h>
30 30 #include <i2c.h>
31 31 #include <core.h>
32 32 #include <terminal.h>
33 33
34 34 uint32_t OSC0 =8000000;
35 35 uint32_t INTOSC =16000000;
36 36 uint32_t RTCOSC =32768;
37 37 uint32_t currentCpuFreq=0;
38 38 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
39 39
40 40 LCD_IF_t lcdIF0={
41 41 .init = &bsp_FSMC_init,
42 42 .writereg = &bsp_lcd0_write_reg,
43 43 .readreg = &bsp_lcd0_read_reg,
44 44 .writeGRAM = &bsp_lcd0_writeGRAM,
45 45 .readGRAM = &bsp_lcd0_readGRAM
46 46 };
47 47
48 48 LCD_t lcd0={
49 49 .interface = &lcdIF0,
50 50 .init = &ili9328init,
51 51 .paint = &ili9328paint,
52 52 .paintText = &ili9328paintText,
53 53 .paintFilRect = &ili9328paintFilRect,
54 54 .refreshenable = &ili9328refreshenable,
55 55 .width= 240,
56 56 .height = 320
57 57 };
58 58
59 59 terminal_t terminal0;
60 60
61 volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000;
62 volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0);
61 volatile uint8_t* lcd0_CMD=(volatile uint8_t*) 0x60000000;
62 volatile uint8_t* lcd0_DATA=(volatile uint8_t*)(0x61FFFFF0);
63 63
64 64 float VREF0 =(float)3.3;
65 65 volatile vs10XXDev audioCodec0;
66 66
67 67 sdcardDev sdcard2;
68 68 blkdevice sdcard2blkdev;
69 69 dikpartition sdcard2Part1;
70 70 FAT32fs sdcard2FAT32part1;
71 71 dikpartition sdcard2Part2;
72 72 FAT32fs sdcard2FAT32part2;
73 73 dikpartition sdcard2Part3;
74 74 FAT32fs sdcard2FAT32part3;
75 75 dikpartition sdcard2Part4;
76 76 FAT32fs sdcard2FAT32part4;
77 77
78 78 int bsp_init()
79 79 {
80 80 int i=0;
81 81 for(i=0;i<__MAX_OPENED_FILES__;i++)
82 82 {
83 83 __opnfiles__[i] = NULL;
84 84 }
85 85 bsp_GPIO_init();
86 86 bsp_uart_init();
87 87 bsp_iic_init();
88 88 bsp_FSMC_init();
89 89 bsp_GTerm_init();
90 90 bsp_spi_init();
91 91 bsp_SD_init();
92 92 bsp_Audio_init();
93 93 printf("\r=====================\n\r");
94 94 printf( "=====================\n\r");
95 95 printf(BSP);
96 96 printf(" initialised\n\r");
97 97 printf( "=====================\n\r");
98 98 return 1;
99 99 }
100 100
101 101 void bsp_GPIO_init()
102 102 {
103 103 gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS};
104 104 for(int i=0;i<8;i++)
105 105 {
106 106 gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]);
107 107 GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype;
108 108 gpiosetconfig(&GPIO_init);
109 109 }
110 110 gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3};
111 111 for(int i=0;i<3;i++)
112 112 {
113 113 gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]);
114 114 GPIO_init |= gpiohighspeed | gpioindir;
115 115 gpiosetconfig(&GPIO_init);
116 116 }
117 117 gpioclr(VS1053xRESET);
118 118 gpioset(VS1053xCS);
119 119 gpioset(VS1053xDCS);
120 120 gpioset(SDCARD2CS);
121 121 gpioclr(LCD_RESET);
122 122 gpioclr(LCD_BACKL);
123 123 }
124 124
125 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 142 D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7
132 143 D5 PE8 D6 PE9 D7 PE10
133 144 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S
134 145 FSMC_NOE PD4 RD
135 146 */
136 147
137 148 int bsp_FSMC_init()
138 149 {
139 150 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
140 151 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
141 152
142 153 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
143 154 ,PD4,PD5,PD7,PE4};
144 155 for(int i=0;i<12;i++)
145 156 {
146 157 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
147 158 LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
148 159 gpiosetconfig(&LCD_DBx);
149 160 GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC);
150 161 }
151 162
152 163 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
153 164 FSMC_NORSRAMTimingInitTypeDef p;
154 165
155 166 /* Enable FSMC clock */
156 167 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
157 168
158 169 /*-- FSMC Configuration ------------------------------------------------------*/
159 170 /*----------------------- SRAM Bank 3 ----------------------------------------*/
160 171 /* FSMC_Bank1_NORSRAM4 configuration */
161 172 //p.FSMC_AddressSetupTime = 5;
162 173 //p.FSMC_AddressSetupTime = 1;
163 174 p.FSMC_AddressSetupTime = 3;
164 175 p.FSMC_AddressHoldTime = 3;
165 176 //p.FSMC_DataSetupTime = 9;
166 177 //ili9328 -> data setup time > 10ns
167 178 p.FSMC_DataSetupTime = 1;
168 179 if(getCpuFreq()>100*1000*1000)
169 180 p.FSMC_DataSetupTime = 2;// 11;
170 181 p.FSMC_BusTurnAroundDuration = 0;
171 182 p.FSMC_CLKDivision = 0;
172 183 p.FSMC_DataLatency = 0;
173 184 //ili9328 -> data hold time > 15ns
174 185 if(getCpuFreq()>66*1000*1000)
175 p.FSMC_DataLatency = 0;
186 p.FSMC_DataLatency = 1;
176 187 p.FSMC_AccessMode = FSMC_AccessMode_A;
177 188
178 189 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
179 190 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
180 191 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
181 192 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
182 193 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
183 194 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
184 195 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
185 196 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
186 197 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
187 198 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
188 199 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
189 200 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
190 201 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
191 202 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
192 203 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
193 204
194 205 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
195 206
196 207 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
197 208 gpioset(LCD_RESET);
198 209 gpioclr(LCD_RESET);
199 210 delay_100us(500);
200 211 gpioset(LCD_RESET);
201 212 delay_100us(500);
202 213 lcd0.init(&lcd0);
203 214 gpioset(LCD_BACKL);
204 215 return 1;
205 216 }
206 217
207 218 void bsp_spi_init()
208 219 {
209 220 gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO};
210 221 for(int i=0;i<3;i++)
211 222 {
212 223 gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]);
213 224 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
214 225 gpiosetconfig(&SPI_DBx);
215 226 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1);
216 227 }
217 228 spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1);
218 229
219 230 gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO};
220 231 for(int i=0;i<3;i++)
221 232 {
222 233 gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]);
223 234 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
224 235 gpiosetconfig(&SPI_DBx);
225 236 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3);
226 237 }
227 238 spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1);
228 239
229 240 }
230 241
231 242
232 243 void bsp_iic_init()
233 244 {
234 245 // i2copenandconfig(i2c2,0,10000,PF0,PF1);
235 246 }
236 247
237 248
238 249 void bsp_Audio_init()
239 250 {
240 251 vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ);
241 252 if(audioCodec0.VERSION!=UNKNOWN)
242 253 {
243 254 printf("detected Audio codec ");
244 255 switch (audioCodec0.VERSION) {
245 256 case VS1001:
246 257 printf("VS1001\n");
247 258 break;
248 259 case VS1011:
249 260 printf("VS1011\n");
250 261 break;
251 262 case VS1002:
252 263 printf("VS1002\n");
253 264 break;
254 265 case VS1003:
255 266 printf("VS1003\n");
256 267 break;
257 268 case VS1053:
258 269 printf("VS1053\n");
259 270 break;
260 271 case VS1033:
261 272 printf("VS1033\n");
262 273 break;
263 274 case VS1103:
264 275 printf("VS1103\n");
265 276 break;
266 277 default:
267 278 printf("Unknown device\n");
268 279 break;
269 280 }
270 281 }
271 282 }
272 283
273 284 void bsp_SD_init()
274 285 {
275 286 if(bspsdcardpresent())
276 287 {
277 288 sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed);
278 289 sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected);
279 290 if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT)
280 291 {
281 292 if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr)
282 293 {
283 294 if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1))
284 295 printf("Can't open fat32 partition 1\n");
285 296 }
286 297 else
287 298 {
288 299 printf("Can't open or read MBR\n");
289 300 }
290 301
291 302 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
292 303 {
293 304 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
294 305 printf("Can't open fat32 partition 2\n");
295 306 }
296 307 else
297 308 {
298 309 printf("Can't open or read MBR\n");
299 310 }
300 311
301 312 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
302 313 {
303 314 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
304 315 printf("Can't open fat32 partition 3\n");
305 316 }
306 317 else
307 318 {
308 319 printf("Can't open or read MBR\n");
309 320 }
310 321
311 322 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
312 323 {
313 324 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
314 325 printf("Can't open fat32 partition 4\n");
315 326 }
316 327 else
317 328 {
318 329 printf("Can't open or read MBR\n");
319 330 }
320 331 }
321 332 else
322 333 {
323 334 printf("Can't initialize SDCARD\n");
324 335 }
325 336 }
326 337 }
327 338
328 339 void vs1052setXCS(char val)
329 340 {
330 341 gpiosetval(VS1053xCS,(int)val);
331 342 }
332 343
333 344 void vs1052setXDCS(char val)
334 345 {
335 346 //gpiosetval(LED1,(int)val);
336 347 gpiosetval(VS1053xDCS,(int)val);
337 348 }
338 349
339 350 void vs1052setRST(char val)
340 351 {
341 352 if(val)
342 353 gpioset(VS1053xRESET);
343 354 else
344 355 gpioclr(VS1053xRESET);
345 356 }
346 357
347 358 int vs10XXDREQ()
348 359 {
349 360 return gpiogetval(VS1053DREQ);
350 361 }
351 362
352 363
353 364 void bsppowersdcard(char onoff) //always ON
354 365 {
355 366
356 367 }
357 368
358 369 char bspsdcardpresent()
359 370 {
360 371 return gpiogetval(SDCARD2CD);
361 372 }
362 373
363 374 char bspsdcardwriteprotected()
364 375 {
365 376 return 0;
366 377 }
367 378
368 379 void bspsdcardselect(char YESNO)
369 380 {
370 381 // gpiosetval(LED1,(int)YESNO);
371 382 if(YESNO)
372 383 gpioclr(SDCARD2CS);
373 384 else
374 385 gpioset(SDCARD2CS);
375 386 }
376 387
377 388
378 389 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
379 390 {
380 391 uint8_t* pt8 = (uint8_t*)(void*)&reg;
381 392 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
382 393 *lcd0_CMD=pt8[3];
383 394 *lcd0_CMD=pt8[2];
384 395 pt8 = (uint8_t*)(void*)&data;
385 396 *lcd0_DATA=pt8[3];
386 397 *lcd0_DATA=pt8[2];
387 398 #else
388 399 *lcd0_CMD=pt8[1];
389 400 *lcd0_CMD=pt8[0];
390 401 pt8 = (uint8_t*)(void*)&data;
391 402 *lcd0_DATA=pt8[1];
392 403 *lcd0_DATA=pt8[0];
393 404 #endif
394 405
395 406 }
396 407
397 408 uint32_t bsp_lcd0_read_reg(uint32_t reg)
398 409 {
399 410 uint8_t* pt8 = (uint8_t*)(void*)&reg;
400 411 uint32_t DATA=0;
401 412 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
402 413 *lcd0_CMD=pt8[3];
403 414 *lcd0_CMD=pt8[2];
404 415 pt8 = (uint8_t*)(void*)&DATA;
405 416 pt8[3]=*lcd0_DATA;
406 417 pt8[2]=*lcd0_DATA;
407 418 #else
408 419
409 420 *lcd0_CMD=pt8[1];
410 421 *lcd0_CMD=pt8[0];
411 422 pt8 = (uint8_t*)(void*)&DATA;
412 423 pt8[1]=*lcd0_DATA;
413 424 pt8[0]=*lcd0_DATA;
414 425 #endif
415 426
416 427 return DATA;
417 428 }
418 429
419 430 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
420 431 {
421 432 uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
422 433 uint8_t* pt8 = (uint8_t*)(void*)&reg;
423 434 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
424 435 *lcd0_CMD=pt8[3];
425 436 *lcd0_CMD=pt8[2];
426 437 pt8 = (uint8_t*)(void*)buffer;
427 438 for(int i=0;i<(int)count;i++)
428 439 {
429 440 *lcd0_DATA=pt8[(2*i) +1];
430 441 *lcd0_DATA=pt8[2*i];
431 442 }
432 443 #else
433 444
434 445 *lcd0_CMD=pt8[1];
435 446 *lcd0_CMD=pt8[0];
436 447 pt8 = (uint8_t*)(void*)buffer;
437 448 for(int i=0;i<(int)count;i++)
438 449 {
439 450
440 451 *lcd0_DATA=pt8[(2*i) +1];
441 452 *lcd0_DATA=pt8[2*i];
442 453 }
443 454 #endif
444 455 }
445 456
446 457 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
447 458 {
448 uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
449 uint8_t* pt8 = (uint8_t*)(void*)&reg;
459 // uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
460 // int8_t* pt8 = (int8_t*)(void*)&reg;
450 461 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
451 462 *lcd0_CMD=pt8[3];
452 463 *lcd0_CMD=pt8[2];
453 464 pt8 = (uint8_t*)(void*)buffer;
454 pt8[0] = *lcd0_DATA;
455 pt8[0] = *lcd0_DATA;
456 465 for(int i=0;i<(int)count;i++)
457 466 {
458 467 pt8[(2*i) +1]=*lcd0_DATA;
468 __asm__("nop");
469 __asm__("nop");
470 __asm__("nop");
471 __asm__("nop");
472 __asm__("nop");
459 473 pt8[2*i]=*lcd0_DATA;
460 474 }
461 475 #else
462
463 *lcd0_CMD=pt8[1];
464 *lcd0_CMD=pt8[0];
465 pt8 = (uint8_t*)(void*)buffer;
466 pt8[0] = *lcd0_DATA;
467 pt8[0] = *lcd0_DATA;
468 for(int i=0;i<(int)count;i++)
469 {
470 pt8[(2*i) +1]=*lcd0_DATA;
471 pt8[2*i]=*lcd0_DATA;
472 }
476 // lcd0_CMD=pt8[1];
477 // lcd0_CMD=pt8[0];
478 // pt8 = (int8_t*)(void*)buffer;
479 // for(int i=0;i<(int)count;i++)
480 // {
481 // pt8[(2*i) +1]=*lcd0_DATA;
482 // __asm__("nop");
483 // __asm__("nop");
484 // __asm__("nop");
485 // __asm__("nop");
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 491 #endif
474 492 }
475 493
476 494 void bsp_GTerm_init()
477 495 {
478 496 if(__opnfiles__[1]==NULL)
479 497 {
480 //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t));
481 498 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
482 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1);
499 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1);
483 500 __opnfiles__[1] = fd1;
484 501 }
485 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 1 CPU=stm32f4xxxG
2 DEFINES+=BSP=\\\"SOLAR_LFR_PSU\\\"
2 DEFINES+=BSP=\\\"STM32F4Discovery\\\"
3 3 UCMODEL=stm32f4
@@ -1,17 +1,18
1 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3 SUBDIRS += STM32F4Discovery \
4 4 M4Stick \
5 5 M4StickV2 \
6 6 SOLAR_LFR_PSU \
7 7 BEAGLESYNTH \
8 8 STM32F4Eval \
9 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 1 TEMPLATE = app
2 2 CONFIG += cpu
3 3
4 4
5 5 UCMODEL=stm32f4
6 6 BSP = OPLAYER
7 7
8 DEFINES += CPUFREQ=160000000
8 DEFINES += CPUFREQ=180000000
9
9 10
10 11 SOURCES += \
11 main.c
12 main.c \
13 test_lcd.c
12 14
@@ -1,182 +1,206
1 1 #include <stdio.h>
2 2 #include <fat32.h>
3 3 #include <gpio.h>
4 4 #include <uart.h>
5 5 #include <stm32f4xx.h>
6 6 #include <bsp.h>
7 7 #include <core.h>
8 8 #include <VS10XX.h>
9 9 #include <bsp.h>
10 10 #include <spi.h>
11 11 #include <sdcard.h>
12 12 #include <sdcard-spi.h>
13 13 #include <fat32.h>
14 14 #include <ucdirent.h>
15 15 #include <string.h>
16 16 #include <terminal.h>
17 #include <ili9328.h>
17 18
18 19
19 20 extern streamdevice* __opnfiles__[];
21 extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color);
20 22 char buffer[512];
21 23
22 24 void randBoxesDemo()
23 25 {
24 26 int16_t x,y,w,h,t,r;
25 27 x=rand()%240;
26 28 y=rand()%320;
27 29 w=rand()%(240-x);
28 30 if(x>y)
29 31 r=(rand()%(y))%(320-y);
30 32 else
31 33 r=(rand()%(x))%(240-x);
32 34 h=rand()%(320-y);
33 35 t=rand()%(10);
34 36 ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
35 37 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
36 38 //delay_100us(10);
37 39 //for(volatile int i=0;i<(1024*2);i++);
38 40 }
39 void tryToplay1()
40 {
41 41
42 extern FAT32fs sdcard2FAT32part1;
43 extern volatile vs10XXDev audioCodec0;
44 ucdirent root;
45 char direntName[]=" \n";
46 uint32_t fileLba,nextLba;
47 int i=0;
48 spisetspeed(audioCodec0.SPIdev,2000000);
49 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root))
50 {
51 if(DIRENT_noErr==fat32getrootfirstent(&root))
52 {
53 do{
54 fat32getdirentname(&root,direntName);
55 printf("%s\n",direntName);
56 nextLba=fat32getdirentlba(&root);
57 printf("Streaming File\n");
58 do
59 {
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 }
42 void randTextDemo()
43 {
44 int16_t x,y,w,h,t,r;
45 char buf[2];
46 buf[1]='\0';
47 x=rand()%240;
48 y=rand()%320;
49 if(x>y)
50 r=(rand()%(y))%(320-y);
51 else
52 r=(rand()%(x))%(240-x);
53 h=rand()%(320-y);
54 buf[0]=rand()%(255);
55 //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
56 ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand());
57 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
58 delay_100us(5000);
59 //for(volatile int i=0;i<(1024*2);i++);
141 60 }
61
142 62 void tryToplay2()
143 63 {
144 64
145 65 extern blkdevice sdcard2blkdev;
146 66 int i=0,l=0;
147 67
148 68 spisetspeed(audioCodec0.SPIdev,4000000);
149 69 printf("Streaming File\n");
150 70
151 71 //printf("New LBA=0x%X\n",nextLba);
152 72
153 73 while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK)
154 74 {
155 75
156 76 for(i=0;i<512;i+=32)
157 77 {
158 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 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 185 extern terminal_t terminal0;
166 186 extern volatile vs10XXDev audioCodec0;
187 lcd0.paintText(&lcd0,"hello",20,50,&ComicSansMS_18 ,0xF0F0);
188 while (1)
189 randTextDemo();
167 190 printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL));
168 191 vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000);
169 vs10XXcmdwrite(&audioCodec0,VSVOL,0x2222);
192 delay_100us(1000);
193 vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020);
170 194 printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF));
171 195 printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE));
172 terminal_clear(&terminal0);
173 // tryToplay2();
174 tryToplay1();
196 //terminal_clear(&terminal0);
197 gpioclr(LCD_BACKL);
198 playAllparts();
175 199 return 0;
176 200 }
177 201
178 202
179 203
180 204
181 205
182 206
@@ -1,21 +1,22
1 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3 SUBDIRS += QtTest/test.pro \
4 4 SOLAR_PSU_HELLO/hello.pro \
5 5 SDCARD \
6 6 STM32F4IT \
7 7 M4StickV2 \
8 8 lcdHello \
9 9 BeagleSynthHello \
10 10 lcdTerminal \
11 11 BeagleSynthHelloSupMon \
12 12 TEST_CMSIS_FFT \
13 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 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3
4 SUBDIRS += ./CS43L22_STM32F4.pro
4 SUBDIRS += ./CS43L22_STM32F4.pro \
5 ./CS43L22_SIMULATOR.pro
@@ -1,17 +1,16
1 1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 2 TARGET = CS43L22
4 3
5 4 SOURCES += CS43L22.c
6 5
7 6 INCLUDEPATH += ../../../includes \
8 7 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 8 ../../CPU/CMSIS/Include
10 9
11 10
12 11 UCMODEL=stm32f4
13 12
14 13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 14 INSTALLS += target
16 15
17 16
@@ -1,15 +1,3
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 TARGET = vs10XX
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 TEMPLATE = subdirs
2 SUBDIRS += ./VS10XX_STM32F4.pro \
3 ./VS10XX_SIMULATOR.pro
@@ -1,16 +1,3
1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3
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 TEMPLATE = subdirs
2 SUBDIRS += ./24LC0X_STM32F4.pro \
3 ./24LC0X_SIMULATOR.pro
@@ -1,15 +1,5
1 TEMPLATE = lib
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
1 TEMPLATE = subdirs
10 2
11 3
12 UCMODEL=stm32f4
13
14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 INSTALLS += target
4 SUBDIRS += ./N25Q128_SIMULATOR.pro \
5 ./N25Q128_STM32F4.pro
@@ -1,5 +1,6
1 1 TEMPLATE = subdirs
2 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 1 TEMPLATE = subdirs
2 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 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #define FAT32_PRIVATE
23 23 #include <fat32.h>
24 24 #include <stdio.h>
25 25 #include <stdint.h>
26 26 #include <hexviewer.h>
27 27
28 char fat32buff[512];
28 char fat32buff[512]__attribute__ ((aligned (4)));
29 29 uint32_t lastSecAddrs=-1;
30 30 FAT32fs* lastFATFS=0;
31 31
32 32 int fat32open(FAT32fs* fs,dikpartition* part)
33 33 {
34 char sector[512];
35 fs->part = part;
36 if(!isFat32(fs->part->TypeCode))return FATBadpart;
37 if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
34 fs->valide = 0;
35 if(part->valide==0)return FATBadpart;
36 char sector[512];
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 40 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff);
39 41 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff);
40 42 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off);
41 43 fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff);
42 fs->BPB_SecPerClus = sector[BPB_SecPerClusoff];
43 fs->BPB_NumFATs = sector[BPB_NumFATsoff];
44 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 );
46 return FATnoErr;
44 fs->BPB_SecPerClus = sector[BPB_SecPerClusoff];
45 fs->BPB_NumFATs = sector[BPB_NumFATsoff];
46 fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt;
47 fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 );
48 fs->valide=1;
49 return FATnoErr;
47 50 }
48 51
49 52
50 53 int fat32mkdirent(FAT32fs* fs,ucdirent* dirent)
51 54 {
52 if(fs==0) return DIRENT_BabArg;
53 if(dirent==0) return DIRENT_BabArg;
54 dirent->fs = (UHANDLE)fs;
55 dirent->getrootfirstent = &fat32getrootfirstent;
56 dirent->nextdirent = &fat32nextdirent;
57 return DIRENT_noErr;
55 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
56 if(dirent==0) return DIRENT_BabArg;
57 dirent->fs = (UHANDLE)fs;
58 dirent->getrootfirstent = &fat32getrootfirstent;
59 dirent->nextdirent = &fat32nextdirent;
60 return DIRENT_noErr;
58 61 }
59 62
60 63
61 64 int fat32getrootfirstent(ucdirent* entry)
62 65 {
63 if(entry==0) return DIRENT_BabArg;
64 entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba;
65 entry->Currententry = 0;
66 return fat32nextdirent(entry);
66 if(entry==0) return DIRENT_BabArg;
67 entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba;
68 entry->Currententry = 0;
69 return fat32nextdirent(entry);
67 70 }
68 71
69 72
70 73 int fat32getVolName(FAT32fs* fs,char* Name)
71 74 {
72 if(fs==0) return DIRENT_BabArg;
73 if(Name==0) return DIRENT_BabArg;
74 int i=0;
75 ucdirent entry;
76 if(DIRENT_noErr==fat32mkdirent(fs,&entry))
77 {
78 entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba;
79 entry.Currententry = -1;
80 if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr;
81 for(i=0;i<16;i++)
82 {
83 Name[i] = entry.DIR_Name[i];
84 }
85 return DIRENT_noErr;
86 }
87 return DIRENT_ReadErr;
75 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
76 if(Name==0) return DIRENT_BabArg;
77 int i=0;
78 ucdirent entry;
79 if(DIRENT_noErr==fat32mkdirent(fs,&entry))
80 {
81 entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba;
82 entry.Currententry = -1;
83 if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr;
84 for(i=0;i<16;i++)
85 {
86 Name[i] = entry.DIR_Name[i];
87 }
88 return DIRENT_noErr;
89 }
90 return DIRENT_ReadErr;
88 91 }
89 92
90 93
91 94 int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry)
92 95 {
93 if(firstentry==0) return DIRENT_BabArg;
94 if(currententry==0) return DIRENT_BabArg;
96 if(firstentry==0) return DIRENT_BabArg;
97 if(currententry==0) return DIRENT_BabArg;
95 98 fat32mkdirent(((FAT32fs*)currententry->fs),firstentry);
96 firstentry->CurrentSec = fat32getdirentlba(currententry);
97 firstentry->Currententry = -1;
98 return fat32nextdirent(firstentry);
99 firstentry->CurrentSec = fat32getdirentlba(currententry);
100 firstentry->Currententry = -1;
101 return fat32nextdirent(firstentry);
99 102 }
100 103
101 104
102 105 int fat32nextdirent(ucdirent* entry)
103 106 {
104 107 uint32_t n=0,res=DIRENT_noErr,k,j;
105 108 k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/
106 109 j=entry->CurrentSec;// /*Restart at last sector*/
107 do
108 {
110 do
111 {
112 //printf("reading new secotr\n",k);
109 113 fat32sectorreadout(((FAT32fs*)entry->fs),j);
110 for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/
111 {
114 //printf("done\n",k);
115 /*512 Bytes per sector and 32 bytes per entry*/
116 for(k=k;k<(512);k+=32)
117 {
112 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 121 if(fat32buff[DIR_Nameoff+k]==(char)0)
122 {
123 //printf("end of directory reached\n",k);
115 124 return DIRENT_EndOfDir; /*0x00 = end of dir*/
116 else
117 if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY)))
118 {
119 for(n=0;n<16;n++)entry->DIR_Name[n] = '\0';
120 for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k];
121 entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k];
125 }
126 else
127 {
128 uint8_t attribute=fat32buff[DIR_Attroff + k];
129 if( (attribute==ATTR_DIRECTORY)
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 137 entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k];
123 138 entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k));
124 139 entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k));
125 140 entry->DIR_LstAccDate = fat32extract16b(fat32buff,(DIR_LstAccDateoff + k));
126 141 entry->DIR_FstClusHI = fat32extract16b(fat32buff, (DIR_FstClusHIoff + k));
127 142 entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k));
128 143 entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k));
129 144 entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k));
130 entry->CurrentSec = j;
131 entry->Currententry = (unsigned char)(k/32);
132 return DIRENT_noErr;
133 }
134 }
135
136 }
137 j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k);
138 if(j!=DIRENT_noErr)
139 {
140 if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/
141 return j;
142 }
143 j=k;
144 k=0;
145 }while(res==DIRENT_noErr);
146 return res;
145 entry->CurrentSec = j;
146 entry->Currententry = (uint8_t)(0xFF&(k>>5));
147 return DIRENT_noErr;
148 }
149 }
150 }
151 }
152 //printf("asking for next sector\n");
153 //printf("current = 0x%X\n",j);
154 j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k);
155 //printf("got it 0x%x\n",k);
156 if(j!=DIRENT_noErr)
157 {
158 if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/
159 return j;
160 }
161 j=k;
162 k=0;
163 }while(res==DIRENT_noErr);
164 return res;
147 165 }
148 166
149 167
150 168 int fat32getdirentname(ucdirent* entry,char* nameBuffer)
151 169 {
152 170 uint32_t j;
153 171 int k,n,i;
154 172 int res=DIRENT_noErr;
155 173 char longName=0;
156 174 k=(((signed char)entry->Currententry))*32;
157 175 j=entry->CurrentSec;
158 176 fat32sectorreadout(((FAT32fs*)entry->fs),j);
159 177 longName |= fat32buff[DIR_Nameoff + 6 + k]=='~';
160 178 if(k>=32)
161 179 {
162 180 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
163 181 }
164 182 else
165 183 {
166 184 uint32_t j_old=j;
167 185 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
168 186 fat32sectorreadout(((FAT32fs*)entry->fs),j);
169 187 k=512;
170 188 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
171 189 if(!longName)
172 190 {
173 191 k=0;
174 192 j=j_old;
175 193 fat32sectorreadout(((FAT32fs*)entry->fs),j);
176 194 k=0;
177 195 }
178 196 }
179 197 if(longName) //long Name? or lower case name
180 198 {
181 199 i=0;
182 200 do{
183 201 if(k==0)
184 202 {
185 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 205 fat32sectorreadout(((FAT32fs*)entry->fs),j);
188 206 k=512-32;
189 207 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
190 208 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
191 209 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
192 210 }
193 211 else
194 212 {
195 213 k-=32;
196 214 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
197 215 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
198 216 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
199 217 }
200 218 }while((fat32buff[k]&0x40)!=0x40);
201 219 nameBuffer[i]='\0';
202 220 }
203 221 else
204 222 {
205 223 i=0;
206 224 for(n=0;n<8;n++)
207 225 {
208 226 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
209 227 if(nameBuffer[i]!=0x20)i++;
210 228 }
211 229 if((((fat32buff[DIR_Nameoff + k +11])&ATTR_DIRECTORY)!=ATTR_DIRECTORY)&&(fat32buff[8+DIR_Nameoff + k]!=0x20))
212 230 nameBuffer[i++]='.';
213 231 for(n=8;n<11;n++)
214 232 {
215 233 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
216 234 if(nameBuffer[i]!=0x20)i++;
217 235 }
218 236
219 237 nameBuffer[i]='\0';
220 238 }
221 239 return res;
222 240 }
223 241
224 242
225 243 uint32_t fat32getdirentlba(ucdirent* entry)
226 244 {
227 245 uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16);
228 246 uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum);
229 return lba;
247 return lba;
230 248 }
231 249
232 250
233 251 int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
234 252 {
235 253
236 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 256 *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/
239 return DIRENT_noErr;
257 return DIRENT_noErr;
240 258 }
241 259
242 260 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
243 261 uint32_t fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
244 262 fat32sectorreadout(fs,fatsec);
245 263 int i= fat32clusterinfatoff(clusternum);
246 264 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
247 265 if(*nextsector_lba==0xFFFFFFF7)
248 266 {
249
250 printf("DIRENT_BadSect\n");
251 267 return DIRENT_BadSect;
252 268 }
253 269 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
254 270 {
255 printf("DIRENT_LastSect\n");
256 271 return DIRENT_LastSect;
257 272 }
258 *nextsector_lba = clusterlba(fs,*nextsector_lba);
259 return DIRENT_noErr;
273 *nextsector_lba = clusterlba(fs,*nextsector_lba);
274 return DIRENT_noErr;
260 275 }
261 276
262 277
263 278 int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
264 279 {
265 280 uint32_t i=0,fatsec=0;
266 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 283 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
269 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 288 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
273 do
289 while(fatsec>=fs->fat_begin_lba)
274 290 {
275
276 291 fat32sectorreadout(fs,fatsec);
277 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 296 if (*nextsector_lba ==clusternum)
282 297 {
283 298 *nextsector_lba = clusterlba(fs,*nextsector_lba);
284 299 return DIRENT_noErr;
285 300 }
286
287 301 }
288
289 }while(fatsec>=fs->fat_begin_lba);
302 }
290 303
291 304 clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
292 305 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
293 306 do
294 307 {
295 308
296 309 fat32sectorreadout(fs,fatsec);
297 310 fatsec++;
298 311 for(i=0;i<512;i+=4)
299 312 {
300 313 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
301 314 if (*nextsector_lba ==clusternum)
302 315 {
303 316 *nextsector_lba = clusterlba(fs,*nextsector_lba);
304 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 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 1 TEMPLATE = subdirs
2 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 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 #include "mbr.h"
22 #include <mbr.h>
23 23 #include <stdio.h>
24 24
25 25
26 26 int mbropen(blkdevice* phy,dikpartition* part,char partNum)
27 27 {
28 28 printf("enter MBR open function\n");
29 29 char mbr[512];
30 30 if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg;
31 31 part->phy = phy;
32 32 if(phy->read(phy,mbr,0,1)!=RES_OK)
33 33 {
34 34 printf("can't read MBR!\n");
35 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 37 return MBRReadErr;
37 38 }
38 39 if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA))
39 40 {
40 41 part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16];
41 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 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 44 printf("MBR Ok\n");
45 part->valide = 1;
44 46 return MBRnoErr;
45 47 }
46 48 printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]);
49 part->valide = 0;
47 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 1 TEMPLATE = lib
2 2 OBJECTS_DIR = obj
3 3 TARGET = mbr
4 4
5 5 SOURCES += \
6 6 mbr.c
7 7
8 8 INCLUDEPATH += ../../../includes \
9 9 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 10 ../../CPU/CMSIS/Include
11 11
12 12
13 13 UCMODEL=stm32f4
14 14
15 15 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 16 INSTALLS += target
17 17
18 HEADERS += \
19 ../../../includes/mbr.h
20
@@ -1,20 +1,19
1 1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 2 TARGET = sdcard
4 3
5 4 SOURCES += \
6 5 sdcard.c
7 6
8 7 INCLUDEPATH += ../../../includes \
9 8 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 9 ../../CPU/CMSIS/Include
11 10
12 11
13 12 UCMODEL=stm32f4
14 13
15 14 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 15 INSTALLS += target
17 16
18 17 HEADERS += \
19 18 ../../../includes/sdcard.h
20 19
@@ -1,4 +1,5
1 1 TEMPLATE = subdirs
2 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 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #include <ili9328.h>
23 23 #include <stdio.h>
24 24 #include <stddef.h>
25 25 #include <core.h>
26 26 #include <math.h>
27 27
28 28 #ifdef __OPTIMIZED_MATH
29 29 #include <optimised_math.h>
30 30 #endif
31 31
32 #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++);
33 32
34 33 #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \
35 34 for(int l=0;l<1;l++)\
36 35 {\
37 36 ili9328setFrame(LCD,X,Y,W,1);\
38 37 int rem=(W)%buffsize;\
39 38 if(rem)LCD->interface->writeGRAM(buffer,rem);\
40 39 for(int i=rem;i<(W);i+=buffsize)\
41 40 {\
42 41 LCD->interface->writeGRAM(buffer,buffsize);\
43 42 }\
44 43 }
45 44
46 45 #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
47 46 for(int l=0;l<1;l++)\
48 47 {\
49 48 ili9328setFrame(LCD,X,Y,W,1);\
50 49 int rem=(ContSz)%buffContsize;\
51 50 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
52 51 for(int i=rem;i<(ContSz);i+=buffContsize)\
53 52 {\
54 53 LCD->interface->writeGRAM(bufferCont,buffContsize);\
55 54 }\
56 55 if((2*ContSz)<W) \
57 56 {\
58 57 rem=(W-(2*ContSz))%buffIntsize;\
59 58 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
60 59 for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\
61 60 {\
62 61 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
63 62 }\
64 63 }\
65 64 rem=(ContSz)%buffContsize;\
66 65 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
67 66 for(int i=rem;i<(ContSz);i+=buffContsize)\
68 67 {\
69 68 LCD->interface->writeGRAM(bufferCont,buffContsize);\
70 69 }\
71 70 }\
72 71
73 72
74 73 #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
75 74 for(int l=0;l<1;l++)\
76 75 {\
77 76 ili9328setFrame(LCD,X,Y,1,H);\
78 77 int rem=(ContSz)%buffContsize;\
79 78 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
80 79 for(int i=rem;i<(ContSz);i+=buffContsize)\
81 80 {\
82 81 LCD->interface->writeGRAM(bufferCont,buffContsize);\
83 82 }\
84 83 if((2*ContSz)<H) \
85 84 {\
86 85 rem=(H-(2*ContSz))%buffIntsize;\
87 86 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
88 87 for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\
89 88 {\
90 89 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
91 90 }\
92 91 }\
93 92 rem=(ContSz)%buffContsize;\
94 93 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
95 94 for(int i=rem;i<(ContSz);i+=buffContsize)\
96 95 {\
97 96 LCD->interface->writeGRAM(bufferCont,buffContsize);\
98 97 }\
99 98 }\
100 99
101 100
102 101 #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
103 102 for(int l=0;l<1;l++)\
104 103 {\
105 104 ili9328setFrame(LCD,X,Y,1,H);\
106 105 int rem=(ContSz)%buffContsize;\
107 106 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
108 107 for(int i=rem;i<(ContSz);i+=buffContsize)\
109 108 {\
110 109 LCD->interface->writeGRAM(bufferCont,buffContsize);\
111 110 }\
112 111 if(ContSz<H) \
113 112 {\
114 113 rem=(H-ContSz)%buffIntsize;\
115 114 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
116 115 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
117 116 {\
118 117 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
119 118 }\
120 119 }\
121 120 }\
122 121
123 122
124 123 #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \
125 124 for(int l=0;l<1;l++)\
126 125 {\
127 126 ili9328setFrame(LCD,X,Y,1,H);\
128 127 int rem;\
129 128 if(ContSz<H) \
130 129 {\
131 130 rem=(H-ContSz)%buffIntsize;\
132 131 if(rem)LCD->interface->writeGRAM(bufferInt,rem);\
133 132 for(int i=rem;i<(H-ContSz);i+=buffIntsize)\
134 133 {\
135 134 LCD->interface->writeGRAM(bufferInt,buffIntsize);\
136 135 }\
137 136 }\
138 137 rem=(ContSz)%buffContsize;\
139 138 if(rem)LCD->interface->writeGRAM(bufferCont,rem);\
140 139 for(int i=rem;i<(ContSz);i+=buffContsize)\
141 140 {\
142 141 LCD->interface->writeGRAM(bufferCont,buffContsize);\
143 142 }\
144 143 }\
145 144
146 145
147 146 void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress)
148 147 {
149 148 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress);
150 149 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress);
151 150 }
152 151
153 152 void ili9328refreshenable(struct LCD_t* LCD,int enable)
154 153 {
155 154 if(enable)
156 155 {
157 156 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018);
158 157 }
159 158 else
160 159 {
161 160 //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008);
162 161
163 162 }
164 163 }
165 164
166 165 void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H)
167 166 {
168 167 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X);
169 168 LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y);
170 169 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X);
171 170 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1));
172 171 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y);
173 172 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1));
174 173 }
175 174
176 175 void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height)
177 176 {
178 177 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height)))
179 178 {
180 179 ili9328setFrame(LCD,Xpos,Ypos,Width,Height);
181 180 LCD->interface->writeGRAM(buffer,Width*Height);
182 181 }
183 182 }
184 183
185 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 186 //Based on the mid point circle algorithm from Wikipedia
188 187 //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
189 188 uint16_t innerbuffer[16];
190 189 uint16_t outterbuffer[16];
191 190 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
192 191 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
193 192 if(contSz<r)
194 193 {
195 194 int error = -r,error_int = -r+contSz;
196 195 int x = r,x_int=r-contSz;
197 196 int y = 0,y_int=0;
198 197 while (x >= y)
199 198 {
200 199 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16);
201 200 ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16);
202 201 ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
203 202 ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
204 203 ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
205 204 ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16);
206 205 error += y;
207 206 ++y;
208 207 error += y;
209 208 error_int += y_int;
210 209 ++y_int;
211 210 error_int += y_int;
212 211 if(error >= 0)
213 212 {
214 213 error -= x;
215 214 --x;
216 215 error -= x;
217 216 }
218 217 if(error_int >= 0)
219 218 {
220 219 error_int -= x_int;
221 220 --x_int;
222 221 error_int -= x_int;
223 222 }
224 223 }
225 224
226 225
227 226
228 227 }
229 228
230 229 }
231 230
232 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 233 if(contSz<r)
235 234 {
236 235 uint16_t innerbuffer[16];
237 236 uint16_t outterbuffer[16];
238 237 int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem;
239 238 for(int i=0;i<16;i++)innerbuffer[i]=fillColor;
240 239 for(int i=0;i<16;i++)outterbuffer[i]=contColor;
241 240 /* Y = b +/- sqrt[r^2 - (x - a)^2] */
242 241 for(int32_t line=-r;line<r;line++)
243 242 {
244 243 #ifdef __OPTIMIZED_MATH
245 244 Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) );
246 245 Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) );
247 246 #else
248 247 Val1 = sqrt( (double)(rr - ((line)*(line))) );
249 248 Val2 = sqrt( (double)(rr2 - ((line)*(line))) );
250 249 #endif
251 250 X1=Xpos - Val1;
252 251 contSz2= Val1-Val2;
253 252 ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1);
254 253 rem=(contSz2)%16;
255 254 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
256 255 for(int i=rem;i<(contSz2);i+=16)
257 256 {
258 257 LCD->interface->writeGRAM(outterbuffer,16);
259 258 }
260 259
261 260 W=2*Val1;
262 261 if(W>(2*contSz2))
263 262 {
264 263 W-=2*contSz2;
265 264 rem=(W)%16;
266 265 if(rem)LCD->interface->writeGRAM(innerbuffer,rem);
267 266 for(int i=rem;i<(W);i+=16)
268 267 {
269 268 LCD->interface->writeGRAM(innerbuffer,16);
270 269 }
271 270 }
272 271
273 272 rem=(contSz2)%16;
274 273 if(rem)LCD->interface->writeGRAM(outterbuffer,rem);
275 274 for(int i=rem;i<(contSz2);i+=16)
276 275 {
277 276 LCD->interface->writeGRAM(outterbuffer,16);
278 277 }
279 278 }
280 279 }
281 280 }
282 281
283 282
284 283
285 284
286 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 287 ili9328setFrame(LCD,Xpos,Ypos,w,h);
289 288 uint16_t tmp[32];
290 289 for(int i=0;i<32;i++)tmp[i]=fillColor;
291 290 for(int i=0;i<(h*w);i+=32)
292 291 {
293 292 LCD->interface->writeGRAM(tmp,32);
294 293 }
295 294 int rem=(w*h)%32;
296 295 if(rem)LCD->interface->writeGRAM(tmp,rem);
297 296 if(contSz)
298 297 {
299 298 ili9328setFrame(LCD,Xpos,Ypos,w,contSz);
300 299 for(int i=0;i<32;i++)tmp[i]=contColor;
301 300 rem=(w*contSz)%32;
302 301 if(rem)LCD->interface->writeGRAM(tmp,rem);
303 302 for(int i=rem;i<(w*contSz);i+=32)
304 303 {
305 304 LCD->interface->writeGRAM(tmp,32);
306 305 }
307 306
308 307 ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz);
309 308 rem=(w*contSz)%32;
310 309 if(rem)LCD->interface->writeGRAM(tmp,rem);
311 310 for(int i=rem;i<(w*contSz);i+=32)
312 311 {
313 312 LCD->interface->writeGRAM(tmp,32);
314 313 }
315 314
316 315 ili9328setFrame(LCD,Xpos,Ypos,contSz,h);
317 316 rem=(h*contSz)%32;
318 317 if(rem)LCD->interface->writeGRAM(tmp,rem);
319 318 for(int i=rem;i<(h*contSz);i+=32)
320 319 {
321 320 LCD->interface->writeGRAM(tmp,32);
322 321 }
323 322
324 323 ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h);
325 324 rem=(h*contSz)%32;
326 325 if(rem)LCD->interface->writeGRAM(tmp,rem);
327 326 for(int i=rem;i<(h*contSz);i+=32)
328 327 {
329 328 LCD->interface->writeGRAM(tmp,32);
330 329 }
331 330 }
332 331 }
333 332
334 333 void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color)
335 334 {
336 335 int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0;
337 336 uint16_t tmp[w];
338 337 uint16_t linenum=0,charnum=0;
339 338 uint8_t line=0;
340 339 while(*buffer!='\0')
341 340 {
341 if(*buffer<32)*buffer=32;
342 if(*buffer>127)*buffer=32;
342 343 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1);
343 344 LCD->interface->readGRAM(tmp,w);
344 345 for(int i=0;i<(h*w);i++)
345 346 {
346 347 if( ((i%w)==0) ) //read current line to apply text pixmap
347 348 {
348 349 if(linenum++>0)
349 350 {
350 351 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1);
351 352 LCD->interface->writeGRAM(tmp,w);
352 353 ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1);
353 354 LCD->interface->readGRAM(tmp,w);
354 355 pix=0;
355 356 }
356 357 }
357 358 if((pix%8) == 0)
358 359 {
359 360 line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++];
360 361 }
362 tmp[pix]=0;
361 363 if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color;
362 364 pix++;
363 365 line>>=1;
364 366 }
365 367 linenum=0;
366 368 tableoffset=0;
367 369 charnum++;
368 370 buffer++;
369 371 }
370 372 }
371 373
372 374 int ili9328init(struct LCD_t* LCD)
373 375 {
374 376 if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL))
375 377 {
376 378 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h)
377 379 LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h)
378 380 LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h)
379 381 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302);
380 382 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000);
381 383 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On
382 384 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h)
383 385 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
384 386 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h)
385 387 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h)
386 388 delay_100us(1000);
387 389 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h)
388 390 delay_100us(500);
389 391 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h)
390 392 delay_100us(500);
391 393 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h)
392 394 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h)
393 395 LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h)
394 396 delay_100us(500);
395 397 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1
396 398 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2
397 399 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3
398 400 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4
399 401 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5
400 402 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6
401 403 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7
402 404 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8
403 405 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9
404 406 LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10
405 407 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h)
406 408 LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h)
407 409 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h)
408 410 LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h)
409 411 LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h)
410 412 LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE
411 413 LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h)
412 414 // Display On
413 415 LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h)
414 416 delay_100us(500);
415 417 LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF);
416 418 }
417 419 return 0;
418 420 }
419 421
420 422
@@ -1,4 +1,5
1 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3
4 SUBDIRS += ./ssd2119_STM32F4.pro
4 SUBDIRS += ./ssd2119_STM32F4.pro \
5 ./ssd2119_SIMULATOR.pro
@@ -1,22 +1,21
1 1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 2 TARGET = ssd2119
4 3
5 4 SOURCES += \
6 5 ssd2119.c
7 6
8 7 DEFINES -= __OPTIMIZED_MATH
9 8
10 9 INCLUDEPATH += ../../../../includes \
11 10 ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \
12 11 ../../../CPU/CMSIS/Include \
13 12 ../../../../includes/GRAPHIC/CONTROLERS \
14 13 ../../../../includes/GRAPHIC/GUI/FONTS \
15 14 ../../../../includes/GRAPHIC/GUI/Widgets
16 15
17 16
18 17 UCMODEL=stm32f4
19 18
20 19 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
21 20 INSTALLS += target
22 21
@@ -1,9 +1,10
1 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 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2013, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #include <widget.h>
23 23 #include <terminal.h>
24 24 #include <stdint.h>
25 25 #include <stdio.h>
26 26 #include <gpio.h>
27 27 #include <core.h>
28
28 #include <malloc.h>
29 29
30 30 #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos)
31 31 #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight)
32 32
33 33 streamdevice_ops TERMINAL_OPS=
34 34 {
35 35 .write = &terminal_write,
36 36 .read = &terminal_read,
37 37 .setpos= &terminal_setpos,
38 38 .close = NULL
39 39 };
40 40
41 41 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev)
42 42 {
43 43 if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL))
44 44 {
45 45 terminal->LCD=LCD;
46 46 terminal->font=font;
47 47 terminal->line = 0;
48 48 terminal->column = 0;
49 terminal->horizontalSpace=0;
50 terminal->verticalSpace=0;
49 terminal->horizontalSpace = 0;
50 terminal->verticalSpace = 0;
51 51 int charw=terminal->font->Width + terminal->horizontalSpace;
52 52 int charh=terminal->font->Height + terminal->verticalSpace;
53 53 terminal->textColor=0xFFFF;
54 54 terminal->backgroundColor=0x0000;
55 55 terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10));
56
57 56 strdev->_stream = (UHANDLE)terminal;
58 57 strdev->ops = &TERMINAL_OPS;
59 58 strdev->streamPt = 0;
60 59 terminal_clear(terminal);
61 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 69 return 1;
63 70 }
64 71 return 0;
65 72 }
66 73
67 74 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height)
68 75 {
69 76 int charw=terminal->font->Width + terminal->horizontalSpace;
70 77 int charh=terminal->font->Height + terminal->verticalSpace;
71 78 if(terminal->LCD->height<(Ypos+height))
72 79 return;
73 80 if(terminal->LCD->width<(Xpos+width))
74 81 return;
75 82 terminal->Xpos = Xpos;
76 83 terminal->Ypos = Ypos;
77 84 terminal->height = height;
78 85 terminal->width = width;
79 86 terminal->lineCount = terminal->height/charh;
80 87 terminal->columnCount = (terminal->width/charw)-1;
81 88 terminal_clear(terminal);
82 89 }
83 90
84 91
85 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 99 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor);
88 100 }
89 101
90 102 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor)
91 103 {
92 104 terminal->backgroundColor = backgrooundColor;
93 105 }
94 106
95 107 void terminal_settextColor(terminal_t* terminal, uint32_t textColor)
96 108 {
97 109 terminal->textColor = textColor;
98 110 }
99 111
100 112
101 113 void terminal_movecursor(terminal_t* terminal,int n)
102 114 {
103 115 int charw=terminal->font->Width + terminal->horizontalSpace;
104 116 int charh=terminal->font->Height + terminal->verticalSpace;
105 117 terminal->column += n;
106 if(terminal->column>terminal->columnCount)
118 if(terminal->column>(terminal->columnCount))
107 119 {
108 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 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 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 132 void terminal_clearCurentLine(terminal_t* terminal)
117 133 {
118 134 int charw=terminal->font->Width + terminal->horizontalSpace;
119 135 int charh=terminal->font->Height + terminal->verticalSpace;
120 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 139 int terminal_writenc(terminal_t* terminal,char* data, int n)
124 140 {
125 141 int charw=terminal->font->Width + terminal->horizontalSpace;
126 142 int charh=terminal->font->Height + terminal->verticalSpace;
127 143 int l=0;
128 144 char buffer[2]=" ";
129 145 while(l<n)
130 146 {
131 147
132 148 buffer[0]=data[l];
133 149 if(buffer[0]=='\n')
134 150 {
135 151 terminal->line= (terminal->line+1) % terminal->lineCount;
136 152 terminal->column = 0;
137 terminal_clearCurentLine(terminal);
153 if(terminal->line==0)
154 terminal_clear(terminal);
155 else
156 terminal_clearCurentLine(terminal);
138 157 }else {
139 158 if(buffer[0]=='\t')
140 159 {
141 160 for(int i=0;i<1;i++)terminal_movecursor(terminal,1);
142 161 }else
143 162 if(terminal->column==0)terminal_clearCurentLine(terminal);
144 if(buffer[0]!='\r'){
145 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);
147 terminal_movecursor(terminal,1);
148 }
163 if(buffer[0]!='\r'){
164 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
165 terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor);
166 terminal_movecursor(terminal,1);
167 }
149 168 }
150 169 l++;
151 170 }
152 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 213 int terminal_write(streamdevice* device,void* data,int size, int n)
156 214 {
157 215 return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n);
158 216 }
159 217
160 218 int terminal_read(streamdevice* device,void* data,int size, int n)
161 219 {
162 220 return n*size;
163 221 }
164 222
165 223 int terminal_setpos(streamdevice* device,int pos)
166 224 {
167 225 return 1;
168 226 }
169 227
170 228 int terminal_close( streamdevice* device)
171 229 {
172 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 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 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3
4 SUBDIRS += ./STMPE811_STM32F4.pro
4 SUBDIRS += ./STMPE811_STM32F4.pro \
5 ./STMPE811_SIMULATOR.pro
@@ -1,28 +1,27
1 1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 2 TARGET = STMPE811
4 3
5 4 SOURCES += \
6 5 STMPE811.c
7 6
8 7 DEFINES -= __OPTIMIZED_MATH
9 8
10 9 INCLUDEPATH += ../../../../includes \
11 10 ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \
12 11 ../../../CPU/CMSIS/Include \
13 12 ../../../../includes/GRAPHIC/CONTROLERS \
14 13 ../../../../includes/GRAPHIC/TC_CONTROLERS \
15 14 ../../../../includes/GRAPHIC/GUI/FONTS \
16 15 ../../../../includes/GRAPHIC/GUI/Widgets
17 16
18 17
19 18 UCMODEL=stm32f4
20 19
21 20 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
22 21 INSTALLS += target
23 22
24 23 HEADERS += \
25 24 ../../../../includes/GRAPHIC/TC_CONTROLERS/STMPE811.h \
26 25 ../../../../includes/GRAPHIC/TC_CONTROLERS/genericTC_Controler.h
27 26
28 27
@@ -1,4 +1,5
1 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3
4 SUBDIRS += ./ina226_STM32F4.pro
4 SUBDIRS += ./ina226_STM32F4.pro \
5 ./ina226_SIMULATOR.pro
@@ -1,16 +1,15
1 1 TEMPLATE = lib
2 OBJECTS_DIR = obj
3 2 TARGET = ina226
4 3
5 4 SOURCES += ina226.c
6 5
7 6 INCLUDEPATH += ../../../includes \
8 7 ../../CPU/STM32F4xx_StdPeriph_Driver/inc \
9 8 ../../CPU/CMSIS/Include
10 9
11 10
12 11 UCMODEL=stm32f4
13 12
14 13 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
15 14 INSTALLS += target
16 15
@@ -1,68 +1,72
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #ifndef TERMINAL_H
23 23 #define TERMINAL_H
24 24 #include <stdint.h>
25 25 #include <widget.h>
26 26 #include <streamdevices.h>
27 27 #include <genericLCD_Controler.h>
28 28 #include <fonts.h>
29 29
30 30 typedef struct terminal_t
31 31 {
32 32 uint16_t line;
33 33 uint16_t column;
34 34 uint16_t lineCount;
35 35 uint16_t columnCount;
36 uint16_t firstLine;
37 uint16_t lastLine;
36 38 uint16_t Xpos;
37 39 uint16_t Ypos;
38 40 uint16_t width;
39 41 uint16_t height;
40 42 uint32_t backgroundColor;
41 43 uint32_t textColor;
42 44 int8_t verticalSpace;
43 45 int8_t horizontalSpace;
46 int8_t empty;
44 47 LCD_t* LCD;
45 48 sFONT* font;
49 char* buffer;
46 50 }terminal_t;
47 51
48 52 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev);
49 53 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height);
50 54 void terminal_clear(terminal_t* terminal);
51 55 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor);
52 56 void terminal_settextColor(terminal_t* terminal, uint32_t textColor);
53 57 void terminal_movecursor(terminal_t* terminal,int n);
54 58 void terminal_clearCurentLine(terminal_t* terminal);
55 59 int terminal_write(streamdevice* device,void* data,int size, int n);
56 60 int terminal_read(streamdevice* device,void* data,int size, int n);
57 61 int terminal_setpos(streamdevice* device,int pos);
58 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 72 #endif
@@ -1,176 +1,196
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #ifndef FAT32_H
23 23 #define FAT32_H
24 24 #include <mbr.h>
25 25 #include <libucfs.h>
26 26 #include <ucdirent.h>
27 27 #include <stdint.h>
28 28 #include <stdint-gcc.h>
29 29 /*BPB (Boot Sector) Offsets */
30 30
31 #define BS_jmpBootoff 0
32 #define BS_OEMNameoff 3
33 #define BPB_BytsPerSecoff 11
34 #define BPB_SecPerClusoff 13
35 #define BPB_RsvdSecCntoff 14
36 #define BPB_NumFATsoff 16
37 #define BPB_RootEntCntoff 17
38 #define BPB_TotSec16off 19
39 #define BPB_Mediaoff 21
40 #define BPB_FATSz16off 22
41 #define BPB_SecPerTrkoff 24
42 #define BPB_NumHeadsoff 26
43 #define BPB_HiddSecoff 28
44 #define BPB_TotSec32off 32
31 #define BS_jmpBootoff 0
32 #define BS_OEMNameoff 3
33 #define BPB_BytsPerSecoff 11
34 #define BPB_SecPerClusoff 13
35 #define BPB_RsvdSecCntoff 14
36 #define BPB_NumFATsoff 16
37 #define BPB_RootEntCntoff 17
38 #define BPB_TotSec16off 19
39 #define BPB_Mediaoff 21
40 #define BPB_FATSz16off 22
41 #define BPB_SecPerTrkoff 24
42 #define BPB_NumHeadsoff 26
43 #define BPB_HiddSecoff 28
44 #define BPB_TotSec32off 32
45 45 /*FAT16*/
46 #define BS_DrvNumFAT16off 36
46 #define BS_DrvNumFAT16off 36
47 47 #define BS_Reserved1FAT16off 37
48 #define BS_BootSigFAT16off 38
49 #define BS_VolIDFAT16off 39
50 #define BS_VolLabFAT16off 43
48 #define BS_BootSigFAT16off 38
49 #define BS_VolIDFAT16off 39
50 #define BS_VolLabFAT16off 43
51 51 #define BS_FilSysTypeFAT16off 54
52 52 /*FAT32*/
53 #define BPB_FATSz32off 36
54 #define BPB_ExtFlagsoff 40
55 #define BPB_FSVeroff 42
56 #define BPB_RootClusoff 44
57 #define BPB_FSInfooff 48
58 #define BPB_BkBootSecoff 50
59 #define BPB_Reservedoff 52
60 #define BS_DrvNumFAT32off 64
61 #define BS_Reserved1FAT32off 65
62 #define BS_BootSigFAT32off 66
63 #define BS_VolIDFAT32off 67
64 #define BS_VolLabFAT32off 71
65 #define BS_FilSysTypeFAT32off 82
53 #define BPB_FATSz32off 36
54 #define BPB_ExtFlagsoff 40
55 #define BPB_FSVeroff 42
56 #define BPB_RootClusoff 44
57 #define BPB_FSInfooff 48
58 #define BPB_BkBootSecoff 50
59 #define BPB_Reservedoff 52
60 #define BS_DrvNumFAT32off 64
61 #define BS_Reserved1FAT32off 65
62 #define BS_BootSigFAT32off 66
63 #define BS_VolIDFAT32off 67
64 #define BS_VolLabFAT32off 71
65 #define BS_FilSysTypeFAT32off 82
66 66
67 67
68 68 #define DIR_Nameoff 0
69 69 #define DIR_Attroff 0xb
70 70 #define DIR_FstClusHIoff 0x14
71 71 #define DIR_FstClusLOoff 0x1A
72 72 #define DIR_FileSizeoff 0x1c
73 73 #define DIR_CrtTimeTenthoff 13
74 74 #define DIR_CrtTimeoff 14
75 75 #define DIR_CrtDateoff 16
76 76 #define DIR_LstAccDateoff 18
77 77 #define DIR_WrtTimeoff 22
78 78 #define DIR_WrtDateoff 24
79 79
80 80
81 81
82 #define FATBadpart 1
83 #define FATBabArg 2
84 #define FATReadErr 3
85 #define FATnoErr 0
82 #define FATBadpart 1
83 #define FATBabArg 2
84 #define FATReadErr 3
85 #define FATnoErr 0
86 86
87 /*
88 TODO :
89 intergrate a per BLKDEV or per partition buffer.
90 */
87 91 typedef struct FAT32fs
88 92 {
89 93 uint16_t BPB_BytsPerSec;
90 94 uint16_t BPB_RsvdSecCnt;
91 95 uint32_t BPB_FATSz32;
92 96 uint32_t BPB_RootClus;
93 97 uint32_t fat_begin_lba;
94 98 uint32_t cluster_begin_lba;
95 99 uint8_t BPB_SecPerClus;
96 100 uint8_t BPB_NumFATs;
101 char valide;
97 102 dikpartition* part;
98 103 }FAT32fs;
99 104
100 105
101 106 #define castUI64(val) ((uint64_t)(val))
102 107 #define castUI32(val) ((uint32_t)(val))
103 108 #define castUI16(val) ((uint16_t)(val))
104 109 #define castUI8(val) ((uint8_t)(val))
105 110
106 111 #define castI64(val) ((int64_t)(val))
107 112 #define castI32(val) ((int32_t)(val))
108 113 #define castI16(val) ((int16_t)(val))
109 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))))
112 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
116 /*
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 135 /* Get the first sector lba of given cluster number*/
115 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 138 //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba)
118 139 #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba)
119 140 #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4)
120 141
121 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 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 147 #ifdef FAT32_PRIVATE
129 148 #define fat32sectorreadout(fs,fatsec) \
130 149 if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \
131 150 {\
132 151 if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \
133 152 {\
134 153 return DIRENT_ReadErr;\
135 154 }\
136 155 }\
137 156 lastSecAddrs=(fatsec);\
138 157 lastFATFS=(fs);
139 158 #endif
140 159
141 160 extern int fat32open(FAT32fs* fs,dikpartition* part);
142 161 extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent);
143 162 extern int fat32getVolName(FAT32fs* fs,char* Name);
144 163 extern int fat32getrootfirstent(ucdirent* entry);
145 164 extern int fat32nextdirent(ucdirent* entry);
146 165 extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba);
147 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 168 extern uint32_t fat32getdirentlba(ucdirent* entry);
149 169 extern int fat32getdirentname(ucdirent* entry,char* nameBuffer);
150 170
151 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 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #ifndef MBR_H
23 23 #define MBR_H
24 24 #include <uhandle.h>
25 25 #include <blkdevice.h>
26 26
27 27 #define BootFlagoffset 0
28 28 #define TypeCodeoffset 4
29 29 #define LBABeginoffset 8
30 30 #define NumOfSecoffset 12
31 31
32 32 #define MBRBadMbr 1
33 33 #define MBRBabArg 2
34 34 #define MBRReadErr 3
35 35 #define MBRnoErr 0
36 36
37 37 #define isFat32(TypeCode) (((TypeCode)==0x0b)||((TypeCode)==0x0c))
38 38
39 39 typedef struct dikpartition
40 40 {
41 41 char TypeCode;
42 char valide;
42 43 unsigned int LBABegin;
43 44 unsigned int NumOfSec;
44 45 blkdevice* phy;
45 46 }dikpartition;
46 47
47 48
48 49 int mbropen(blkdevice* phy,dikpartition* part,char partNum);
49 50
50 51
51 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 1 TEMPLATE = subdirs
2 2 CONFIG += ordered
3 3
4 4 SUBDIRS += stm32f4
5 5
6 6 SUBDIRS += common
7 SUBDIRS += simulator
7 8
8 9 headers.files = includes/*.h \
9 10 includes/GRAPHIC/CONTROLERS/*.h \
10 11 includes/GRAPHIC/TC_CONTROLERS/*.h \
11 12 includes/GRAPHIC/GUI/FONTS/*.h \
12 13 includes/GRAPHIC/GUI/Widgets/*.h
13 14
14 15 headers.path = $$[QT_INSTALL_HEADERS]
15 16 INSTALLS += headers
16 17
@@ -1,375 +1,378
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2011, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@gmail.com
21 21 -------------------------------------------------------------------------------*/
22 22 #include <core.h>
23 23 #include <stm32f4xx_rcc.h>
24 24 #include <stdint.h>
25 25 #include <stdlib.h>
26 26 #include <stdio.h>
27 27 #include <core_cm4.h>
28 #include <gpio.h>
28 29
29 30 extern uint32_t OSC0;
30 31 extern uint32_t INTOSC;
31 32 extern uint32_t RTCOSC;
32 33
33 34 volatile uint32_t tickCounter=0;
34 35
35 36
36 37 void SysTick_Handler(void)
37 38 {
38 39 tickCounter+=1;
40 if((tickCounter&0xFFF)==0x800)
41 gpiosetval(PC15,!gpiogetval(PC15));
39 42 }
40 43
41 44 void delay_us(uint32_t value)
42 45 {
43 46 extern uint32_t currentCpuFreq;
44 47 if(value)
45 48 {
46 49 uint32_t tickperus=currentCpuFreq/(1000*10);
47 50 uint32_t tickCounterSnap = SysTick->VAL+((value%100)*tickperus);
48 51 uint32_t targetVal=tickCounterSnap +(value/100);
49 52 if(targetVal < tickCounterSnap)
50 53 {
51 54 while(tickCounter > targetVal);
52 55 }
53 56 while((tickCounter < targetVal) | (SysTick->VAL<tickCounterSnap));
54 57 }
55 58 }
56 59
57 60 void delay_100us(uint32_t value)
58 61 {
59 62 if(value)
60 63 {
61 64 uint32_t tickCounterSnap = tickCounter;
62 65 uint32_t SysTickSnap = SysTick->VAL;
63 66 uint32_t targetVal=tickCounterSnap +(value);
64 67 if(targetVal < tickCounterSnap)
65 68 {
66 69 while(tickCounter > targetVal);
67 70 }
68 71 while((tickCounter < targetVal) | (SysTick->VAL<SysTickSnap));
69 72 }
70 73 }
71 74
72 75 uint32_t getAPB1Freq()
73 76 {
74 77 RCC_ClocksTypeDef RCC_ClocksStatus;
75 78 RCC_GetClocksFreq(&RCC_ClocksStatus);
76 79 return RCC_ClocksStatus.PCLK1_Frequency;
77 80 }
78 81
79 82 uint32_t getAPB2Freq()
80 83 {
81 84 RCC_ClocksTypeDef RCC_ClocksStatus;
82 85 RCC_GetClocksFreq(&RCC_ClocksStatus);
83 86 return RCC_ClocksStatus.PCLK2_Frequency;
84 87 }
85 88
86 89
87 90 uint32_t getCpuFreq()
88 91 {
89 92 uint32_t cpufreq = OSC0;
90 93 uint32_t PLLN,PLLM,PLLP;
91 94
92 95 if((RCC->CFGR & 0xC) == 8) //PLL used as sys clk
93 96 {
94 97 uint32_t pllinput=INTOSC;
95 98 if((RCC->PLLCFGR & (1<<22)) == (1<<22))
96 99 {
97 100 pllinput=OSC0;
98 101 }
99 102 PLLN = (RCC->PLLCFGR>>6) & 0x1FF;
100 103 PLLM = RCC->PLLCFGR & 0x3F;
101 104 PLLP = 1<<(((RCC->PLLCFGR>>16) & 3 )+1);
102 105 cpufreq = (pllinput * PLLN )/(PLLM*PLLP);
103 106 }
104 107 else if((RCC->CFGR & 0xC) == 0) //HSI used as sys clk
105 108 {
106 109 cpufreq=INTOSC;
107 110 }
108 111 if((RCC->CFGR & (1<<7))==1<<7)
109 112 {
110 113 return cpufreq>>((RCC->CFGR & (7<<4))>>4);
111 114 }
112 115 return cpufreq;
113 116 }
114 117
115 118 void reset_AHB1()
116 119 {
117 120 RCC->AHB1RSTR = -1;
118 121 RCC->AHB1RSTR = 0;
119 122 }
120 123
121 124 void reset_AHB2()
122 125 {
123 126 RCC->AHB2RSTR = -1;
124 127 RCC->AHB2RSTR = 0;
125 128 }
126 129
127 130 void reset_APB1()
128 131 {
129 132 RCC->APB1RSTR = -1;
130 133 RCC->APB1RSTR = 0;
131 134 }
132 135
133 136 void reset_APB2()
134 137 {
135 138 RCC->APB2RSTR = -1;
136 139 RCC->APB2RSTR = 0;
137 140 }
138 141
139 142
140 143
141 144 /*
142 145 | 2.7->3.6V
143 146 -------------------------
144 147 0WS | 0<HCLK<=30
145 148 1WS | 30<HCLK<=60
146 149 2WS | 60<HCLK<=90
147 150 3WS | 90<HCLK<=120
148 151 4WS | 120<HCLK<=150
149 152 5WS | 150<HCLK<=168
150 153
151 154 f(VCO clock) = f(PLL clock input) × (PLLN / PLLM) [1]
152 155 64MHz <= f(VCO clock) <= 432MHz [2]
153 156
154 157 f(VCO clock input) must be between 1MHz and 2MHz and as close to 2MHz as possible!! [3]
155 158
156 159 f(PLL general clock output) = f(VCO clock) / PLLP [4]
157 160
158 161 CPU<168MHz AHB1<168MHz AHB2<168MHz APB1<42MHz APB2<84MHz [5]
159 162
160 163 ! 63<=PLLN<=432 [6]
161 164 ! 2<=PLLM<=63 [7]
162 165 ! PLLP=2,4,6,8 [8]
163 166 4<=PLLM*PLLP<=504
164 167
165 168 F= f(PLL clock input) * A/B with
166 169 63<=A<=432
167 170 4<=B<=504
168 171
169 172 */
170 173
171 174
172 175 int optimizePLLcfg(uint32_t freq, uint32_t srcfreq,uint32_t PLLM,uint32_t* PLLP, uint32_t* PLLN,uint8_t* AHBPRindx)
173 176 {
174 177 uint32_t AHBPRtbl[9]={1,2,4,8,16,64,128,256,512};
175 178 uint32_t AHBPR=0,AHBPR_r=0,PLLN_r=0,PLLP_r=0;
176 179 uint32_t Fplli=0;
177 180 int32_t f_error=100000000;
178 181 int32_t f_errornw=100000000;
179 182 Fplli = srcfreq / PLLM;
180 183 //not efficient but should find the best parameters
181 184 for((*AHBPRindx)=0;(*AHBPRindx)<9;(*AHBPRindx)++) //lowest priority
182 185 {
183 186 AHBPR = AHBPRtbl[(*AHBPRindx)];
184 187 for(*PLLP=2;*PLLP<9;*PLLP+=2)
185 188 {
186 189 *PLLN = (freq*(*PLLP)*AHBPR)/Fplli;
187 190 if(((*PLLN)>62) && ((*PLLN)<433) && ((Fplli * (*PLLN)) < 433000000))
188 191 {
189 192 f_errornw = abs((int32_t)((int32_t)((Fplli*(*PLLN))/((*PLLP)*AHBPR))-freq));
190 193 if( ( (f_error)>(f_errornw) ) || ( (*AHBPRindx==0)&&(*PLLP==2)&&(*PLLN==63) ) )
191 194 {
192 195 f_error=f_errornw;
193 196 PLLN_r = *PLLN;
194 197 PLLP_r = *PLLP;
195 198 AHBPR_r=*AHBPRindx;
196 199 if(f_error==0)
197 200 {
198 201 *PLLN = PLLN_r;
199 202 *PLLP = PLLP_r;
200 203 *AHBPRindx = AHBPR_r;
201 204 return 1;
202 205 }
203 206 }
204 207 }
205 208 }
206 209 }
207 210 *PLLN = PLLN_r;
208 211 *PLLP = PLLP_r;
209 212 *AHBPRindx = AHBPR_r;
210 213 return 1;
211 214 }
212 215
213 216
214 217 int setPll(uint32_t freq)
215 218 {
216 219 extern uint32_t OSC0;
217 220 extern uint32_t INTOSC;
218 221 uint32_t srcfreq = INTOSC;
219 222 uint8_t AHBPRindx;
220 223 uint32_t AHBPRtbl[9]={1,2,4,8,16,64,128,256,512};
221 224 uint32_t PLLN=0,PLLM=0,PLLP=0,AHBPR=0;
222 225 uint32_t Fplli=0;
223 226 if((RCC->PLLCFGR & (1<<22))==(1<<22))
224 227 {
225 228 srcfreq = OSC0;
226 229 }
227 230 PLLM = srcfreq / 1500000; // [3]
228 231 Fplli = srcfreq / PLLM;
229 232 optimizePLLcfg(freq,srcfreq,PLLM,&PLLP,&PLLN,&AHBPRindx);
230 233 srcfreq = (Fplli*PLLN)/(PLLP*AHBPRtbl[AHBPRindx]); //Put real clk freq in srcfreq for return value
231 234 //now switch to HSIs
232 235 if((RCC->CR & 1)==0)RCC->CR |= 1; //turn ON HSI
233 236 while((RCC->CR & 2)!=2); //wait for HSI Ready
234 237 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
235 238 RCC->CFGR |= RCC_CFGR_SW_HSI; //set HSI as main clk
236 239 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_HSI);
237 240 RCC->CR &= ~(1<<24); //Turn OFF PLL
238 241 RCC->PLLCFGR &= ~0x37FFF; //clear PLLP PLLM PLLN
239 242 RCC->PLLCFGR |= PLLM + (PLLN<<6) + (((PLLP>>1) -1)<<16);
240 243 RCC->CR |= RCC_CR_PLLON; //Turn ON PLL
241 244 while((RCC->CR & (1<<25))!=(1<<25)); //wait for PLL Ready
242 245 if(AHBPRindx!=0)AHBPRindx|=0x8;
243 246 RCC->CFGR &= ~(0xF<<4);
244 247 RCC->CFGR |= (uint32_t)(AHBPRindx<<4);
245 248 AHBPR=0;
246 249 while((srcfreq>>AHBPR)>42000000)AHBPR++; //[5] //Thune APB1 prescaler to keep APB1 CLK below 42MHz
247 250 if(AHBPR!=0)
248 251 {
249 252 AHBPR-=1;
250 253 AHBPR|=0x4;
251 254 }
252 255 RCC->CFGR &= ~(0x7<<10);
253 256 RCC->CFGR |= (uint32_t)(AHBPR<<10);
254 257 AHBPR=0;
255 258 while((srcfreq>>AHBPR)>84000000)AHBPR++; //[5] //Thune APB2 prescaler to keep APB2 CLK below 42MHz
256 259 if(AHBPR!=0)
257 260 {
258 261 AHBPR-=1;
259 262 AHBPR|=0x4;
260 263 }
261 264 RCC->CFGR &= ~(0x7<<13);
262 265 RCC->CFGR |= (uint32_t)(AHBPR<<13);
263 266 FLASH->ACR |= FLASH_ACR_LATENCY_7WS;
264 267 RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));//Switch to PLL as main clk source
265 268 RCC->CFGR |= RCC_CFGR_SW_PLL;
266 269 /* Wait untill the main PLL is used as system clock source */
267 270 while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
268 271 if(srcfreq>150000000)
269 272 {
270 273 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_5WS;
271 274 }
272 275 if((srcfreq<150000000) && (srcfreq>=120000000))
273 276 {
274 277 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_4WS;
275 278 }
276 279 if((srcfreq<120000000) && (srcfreq>=90000000))
277 280 {
278 281 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_3WS;
279 282 }
280 283 if((srcfreq<90000000) && (srcfreq>=60000000))
281 284 {
282 285 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_2WS;
283 286 }
284 287 if((srcfreq<60000000) && (srcfreq>=30000000))
285 288 {
286 289 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_1WS;
287 290 }
288 291 if(srcfreq<30000000)
289 292 {
290 293 FLASH->ACR &= (~7)|FLASH_ACR_LATENCY_0WS;
291 294 }
292 295 return srcfreq;
293 296 }
294 297
295 298 void configureSysTick()
296 299 {
297 300 extern uint32_t currentCpuFreq;
298 301 uint32_t us=currentCpuFreq/(1000*10);
299 302 SysTick_Config(us);
300 303 }
301 304
302 305 int setCpuFreq(uint32_t freq)
303 306 {
304 307 extern uint32_t OSC0;
305 308 extern uint32_t INTOSC;
306 309 uint8_t i=0;
307 310 uint32_t curentFeq = getCpuFreq();
308 311 if(curentFeq==freq)return curentFeq;
309 312 if((freq>2000000) && (freq<=250000000)) //be carefull with 250MHz!!!
310 313 {
311 314 if((RCC->CFGR & 0xC) == 8) //PLL used as sys clk
312 315 {
313 316 return setPll(freq);
314 317 }
315 318 else if((RCC->CFGR & 0xC) == 0) //HSI used as sys clk
316 319 {
317 320 if((INTOSC%freq)==0) //now check if we can directly divide HSI
318 321 {
319 322 if(freq==INTOSC)
320 323 {
321 324 RCC->CFGR &= ~(0xF<<4);
322 325 return freq;
323 326 }
324 327 for(i=1;i<8;i++)
325 328 {
326 329 if((freq<<i)==INTOSC)
327 330 {
328 331 RCC->CFGR &= ~(0xF<<4);
329 332 RCC->CFGR |= ((0x8|i)<<4);
330 333 return freq;
331 334 }
332 335 }
333 336 }
334 337 else
335 338 return setPll(freq);
336 339 }
337 340 else //HSE used as sys clk
338 341 {
339 342 if((OSC0%freq)==0) //now check if we can directly divide HSI
340 343 {
341 344 if(freq==OSC0)
342 345 {
343 346 RCC->CFGR &= ~(0xF<<4);
344 347 return freq;
345 348 }
346 349 for(i=1;i<8;i++)
347 350 {
348 351 if((freq<<i)==OSC0)
349 352 {
350 353 RCC->CFGR &= ~(0xF<<4);
351 354 RCC->CFGR |= ((0x8|i)<<4);
352 355 return freq;
353 356 }
354 357 }
355 358 }
356 359 else
357 360 return setPll(freq);
358 361 }
359 362 }
360 363 return 0;
361 364 }
362 365
363 366
364 367 void enable_FPU()
365 368 {
366 369 SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
367 370 __asm__("dsb");
368 371 __asm__("isb");
369 372 }
370 373
371 374
372 375
373 376
374 377
375 378
@@ -1,16 +1,17
1 1 TEMPLATE = lib
2 2 OBJECTS_DIR = obj
3 3
4 4 SOURCES += \
5 5 core.c \
6 threads.c
6 threads.c \
7 irq_handlers.c
7 8
8 9 INCLUDEPATH += ../../includes \
9 10 ../CPU/STM32F4xx_StdPeriph_Driver/inc \
10 11 ../CPU/CMSIS/Include
11 12
12 13
13 14 UCMODEL=stm32f4
14 15
15 16 target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL
16 17 INSTALLS += target
@@ -1,63 +1,63
1 1 #include "stm32f4xx.h"
2 2 #include <stdint.h>
3 3 #include <stdlib.h>
4 4 #include <stdio.h>
5 5 #include <bsp.h>
6 6 #include <stm32f4xx_rcc.h>
7 7 #include <core.h>
8 8 extern int main();
9 9
10 10
11 11
12 12 void cpu_init()
13 13 {
14 14 extern uint32_t currentCpuFreq;
15 15 #ifndef CPUFREQ
16 16 #define CPUFREQ (16*1000*1000)
17 17 #endif
18 18 currentCpuFreq = CPUFREQ;
19 19 enable_FPU();
20 20 RCC->CR |= (uint32_t)0x00000001;
21 21 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
22 22 reset_AHB1();
23 23 reset_AHB2();
24 24 reset_APB1();
25 25 reset_APB2();
26 26 RCC->CR |= (uint32_t)0x00000001;
27 27 FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
28 28 RCC->CFGR = 0x00000000;
29 29 RCC->CIR = 0x00000000;
30 30 SCB->VTOR = FLASH_BASE;
31 31 RCC->APB1ENR |= RCC_APB1ENR_PWREN;
32 32 PWR->CR |= PWR_CR_PMODE;
33 33 currentCpuFreq=setCpuFreq(currentCpuFreq);
34 34 currentCpuFreq=getCpuFreq();
35 35 configureSysTick();
36 36 bsp_init();
37 37 printf("SysTick Configured to reach 100us period\n\r");
38 38 RCC_ClocksTypeDef RCC_ClocksStatus;
39 39 RCC_GetClocksFreq(&RCC_ClocksStatus);
40 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 41 printf("Enter Main\n\r");
42 42 int res=main();
43 43 printf("\n\rprogram exited with code ");
44 44 printf("%u",res);
45 45 printf("\n\r");
46 46 while(1)
47 47 {
48 48 delay_100us(10000);
49 gpioset(LED1);
49 gpioset(LED2);
50 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 4 ** File : stm32_flash.ld
5 5 **
6 6 ** Abstract : Linker script for STM32F407VG Device with
7 7 ** 1024KByte FLASH, 192KByte RAM
8 8 **
9 9 ** Set heap size, stack size and stack location according
10 10 ** to application requirements.
11 11 **
12 12 ** Set memory bank area and size if external memory is used.
13 13 **
14 14 ** Target : STMicroelectronics STM32
15 15 **
16 16 ** Environment : Atollic TrueSTUDIO(R)
17 17 **
18 18 ** Distribution: The file is distributed �as is,� without any warranty
19 19 ** of any kind.
20 20 **
21 21 ** (c)Copyright Atollic AB.
22 22 ** You may use this file as-is or modify it according to the needs of your
23 23 ** project. Distribution of this file (unmodified or modified) is not
24 24 ** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the
25 25 ** rights to distribute the assembled, compiled & linked contents of this
26 26 ** file as part of an application binary file, provided that it is built
27 27 ** using the Atollic TrueSTUDIO(R) toolchain.
28 28 **
29 29 *****************************************************************************
30 30 */
31 31
32 32 /* Entry Point */
33 33 ENTRY(Reset_Handler)
34 34
35 35 /* Highest address of the user mode stack */
36 36 _estack = 0x20020000; /* end of 128K RAM on AHB bus*/
37 37
38 38 /* Generate a link error if heap and stack don't fit into RAM */
39 _Min_Heap_Size = 0; /* required amount of heap */
40 _Min_Stack_Size = 0x1000; /* required amount of stack */
39 _Min_Heap_Size = 0x2000; /* required amount of heap */
40 _Min_Stack_Size = 0x2000; /* required amount of stack */
41 41
42 42 /* Specify the memory areas */
43 43 MEMORY
44 44 {
45 45 FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024k
46 46 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112k
47 47 CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64k
48 48 MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
49 49 }
50 50
51 51 /* Define output sections */
52 52 SECTIONS
53 53 {
54 54 /* The startup code goes first into FLASH */
55 55 .isr_vector :
56 56 {
57 57 . = ALIGN(4);
58 58 KEEP(*(.isr_vector)) /* Startup code */
59 59 . = ALIGN(4);
60 60 } >FLASH
61 61
62 62 /* The program code and other data goes into FLASH */
63 63 .text :
64 64 {
65 65 . = ALIGN(4);
66 66 *(.text) /* .text sections (code) */
67 67 *(.text*) /* .text* sections (code) */
68 68 *(.rodata) /* .rodata sections (constants, strings, etc.) */
69 69 *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
70 70 *(.glue_7) /* glue arm to thumb code */
71 71 *(.glue_7t) /* glue thumb to arm code */
72 72 *(.eh_frame)
73 73
74 74 KEEP (*(.init))
75 75 KEEP (*(.fini))
76 76
77 77 . = ALIGN(4);
78 78 _etext = .; /* define a global symbols at end of code */
79 79 } >FLASH
80 80
81 81
82 82 .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
83 83 .ARM : {
84 84 __exidx_start = .;
85 85 *(.ARM.exidx*)
86 86 __exidx_end = .;
87 87 } >FLASH
88 88
89 89 .preinit_array :
90 90 {
91 91 PROVIDE_HIDDEN (__preinit_array_start = .);
92 92 KEEP (*(.preinit_array*))
93 93 PROVIDE_HIDDEN (__preinit_array_end = .);
94 94 } >FLASH
95 95 .init_array :
96 96 {
97 97 PROVIDE_HIDDEN (__init_array_start = .);
98 98 KEEP (*(SORT(.init_array.*)))
99 99 KEEP (*(.init_array*))
100 100 PROVIDE_HIDDEN (__init_array_end = .);
101 101 } >FLASH
102 102 .fini_array :
103 103 {
104 104 PROVIDE_HIDDEN (__fini_array_start = .);
105 105 KEEP (*(.fini_array*))
106 106 KEEP (*(SORT(.fini_array.*)))
107 107 PROVIDE_HIDDEN (__fini_array_end = .);
108 108 } >FLASH
109 109
110 110 /* used by the startup to initialize data */
111 111 _sidata = .;
112 112
113 113 /* Initialized data sections goes into RAM, load LMA copy after code */
114 114 .data : AT ( _sidata )
115 115 {
116 116 . = ALIGN(4);
117 117 _sdata = .; /* create a global symbol at data start */
118 118 *(.data) /* .data sections */
119 119 *(.data*) /* .data* sections */
120 120
121 121 . = ALIGN(4);
122 122 _edata = .; /* define a global symbol at data end */
123 123 } >RAM
124 124
125 125 /* Uninitialized data section */
126 126 . = ALIGN(4);
127 127 .bss :
128 128 {
129 129 /* This is used by the startup in order to initialize the .bss secion */
130 130 _sbss = .; /* define a global symbol at bss start */
131 131 __bss_start__ = _sbss;
132 132 *(.bss)
133 133 *(.bss*)
134 134 *(COMMON)
135 135
136 136 . = ALIGN(4);
137 137 _ebss = .; /* define a global symbol at bss end */
138 138 __bss_end__ = _ebss;
139 139 } >RAM
140 140
141 141 /* User_heap_stack section, used to check that there is enough RAM left */
142 142 ._user_heap_stack :
143 143 {
144 144 . = ALIGN(4);
145 145 PROVIDE ( end = . );
146 146 PROVIDE ( _end = . );
147 147 . = . + _Min_Heap_Size;
148 148 . = . + _Min_Stack_Size;
149 149 . = ALIGN(4);
150 150 } >RAM
151 151
152 152 /* MEMORY_bank1 section, code must be located here explicitly */
153 153 /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
154 154 .memory_b1_text :
155 155 {
156 156 *(.mb1text) /* .mb1text sections (code) */
157 157 *(.mb1text*) /* .mb1text* sections (code) */
158 158 *(.mb1rodata) /* read-only data (constants) */
159 159 *(.mb1rodata*)
160 160 } >MEMORY_B1
161 161
162 162 /* Remove information from the standard libraries */
163 163 /DISCARD/ :
164 164 {
165 165 libc.a ( * )
166 166 libm.a ( * )
167 167 libgcc.a ( * )
168 168 }
169 169
170 170 .ARM.attributes 0 : { *(.ARM.attributes) }
171 171 }
@@ -1,261 +1,282
1 1 #include <stdlib.h>
2 2 #include <errno.h>
3 3 #include <string.h>
4 4 #include <sys/stat.h>
5 5 #include <sys/types.h>
6 6 #include <sys/times.h>
7 7 #include <streamdevices.h>
8 8 #include <string.h>
9 9 #include <stdio.h>
10 10 #include <gpio.h>
11 11 #include <uart.h>
12 12 #include <stdint.h>
13 #include <bsp.h>
13 14
14 15 #undef errno
15 16
16 17
17 18
18 19 #ifdef __cplusplus
19 20 extern "C" {
20 21 #endif
21 22 extern int errno;
22 23 extern int32_t __max_opened_files__;
23 24 extern streamdevice* __opnfiles__[];
24 25 extern int32_t* __fs_root__;
25 26 extern int32_t __fs_root_size__;
26 27
27 28 char *__env[1] = { 0 };
28 29 char **environ = __env;
29 30
30 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 42 int _close(int file)
36 43 {
37 44 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
38 45 {
39 46 return __opnfiles__[file]->ops->close( __opnfiles__[file]);
40 47 }
41 48 return 0;
42 49 }
43 50
44 51
45 52 int _write(int file, char *ptr, int len)
46 53 {
47 54 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
48 55 {
49 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 61 int _execve(char *name, char **argv, char **env) {
55 62 errno = ENOMEM;
56 63 return -1;
57 64 }
58 65
59 66
60 67 int _fork(void) {
61 68 errno = EAGAIN;
62 69 return -1;
63 70 }
64 71
65 72 int _fstat(int file, struct stat *st) {
66 73 st->st_mode = S_IFCHR;
67 74 return 0;
68 75 }
69 76
70 77
71 78 int _getpid(void) {
72 79 return 1;
73 80 }
74 81
75 82
76 83 int _isatty(int file) {
77 84 return 1;
78 85 }
79 86
80 87
81 88 int _kill(int pid, int sig) {
82 89 errno = EINVAL;
83 90 return -1;
84 91 }
85 92
86 93
87 94 int _link(char *old, char *_new) {
88 95 errno = EMLINK;
89 96 return -1;
90 97 }
91 98
92 99
93 100 int _lseek(int file, int ptr, int dir) {
94 101 return 0;
95 102 }
96 103
97 104 #include <gpio.h>
98 105
99 106 int _open(const char *name, int flags, int mode)
100 107 {
101 108 if(!strncmp("UART", name, 4) && ((name[4] & 0x30)==0x30))
102 109 {
103 110 //uart_t* uart1 = malloc(sizeof(uart_t));
104 111 streamdevice* fd1 = malloc(sizeof(streamdevice));
105 112 uart_t uart=uartopen((name[4] & 0xF)-1);
106 113 if(uart!=-1);
107 114 {
108 115 uartmkstreamdev(uart,fd1);
109 116 int i=2;
110 117 while((i<__max_opened_files__) && (__opnfiles__[i]!=NULL))i++;
111 118 if(i!=__max_opened_files__)
112 119 {
113 120 __opnfiles__[i] = fd1;
114 121 return i;
115 122 }
116 123 else printf("Too much files opened\n\r");
117 124 }
118 125 }
119 126 return -1;
120 127 }
121 128
122 129 int _read(int file, char *ptr, int len) {
123 130 if(file<__max_opened_files__ && __opnfiles__[file]!=NULL)
124 131 {
125 132 if(__opnfiles__[file]->ops->read(__opnfiles__[file],ptr,1,len)) return len;
126 133 }
127 134 return 0;
128 135 }
129 136
130 137
131 138
132 139 caddr_t _sbrk(int incr) {
133 140 register char * stack_ptr __asm__ ("sp");
134 141 extern char _end; /* Defined by the linker */
135 142 static char *heap_end;
136 143 char *prev_heap_end;
137 144 if (heap_end == 0) {
138 145 heap_end = &_end;
139 146 }
140 147 prev_heap_end = heap_end;
141 148 if (heap_end + incr > stack_ptr) {
142 _write (1, "Heap and stack collision\n", 25);
143 abort ();
149 printf("Heap and stack collision\n");
150 //abort ();
151 while(1)
152 {
153 delay_100us(10000);
154 gpioset(LED2);
155 delay_100us(10000);
156 gpioclr(LED2);
157 }
144 158 }
145 159 heap_end += incr;
146 160 return (caddr_t) prev_heap_end;
147 161 }
148 162
149 163
150 164
151 165 int _stat(char *file, struct stat *st) {
152 166 st->st_mode = S_IFCHR;
153 167 return 0;
154 168 }
155 169
156 170
157 171 int _times(struct tms *buf) {
158 172 return -1;
159 173 }
160 174
161 175
162 176 int _unlink(char *name) {
163 177 errno = ENOENT;
164 178 return -1;
165 179 }
166 180
167 181 int _wait(int *status) {
168 182 errno = ECHILD;
169 183 return -1;
170 184 }
171 185
172 186
173 187 int _read_r (struct _reent *r, int file, char * ptr, int len)
174 188 {
175 189 r = r;
176 190 file = file;
177 191 ptr = ptr;
178 192 len = len;
179 193 _read(file,ptr,len);
180 194 errno = EINVAL;
181 195 return -1;
182 196 }
183 197
184 198 /***************************************************************************/
185 199
186 200 int _lseek_r (struct _reent *r, int file, int ptr, int dir)
187 201 {
188 202 r = r;
189 203 file = file;
190 204 ptr = ptr;
191 205 dir = dir;
192 206
193 207 return 0;
194 208 }
195 209
196 210 /***************************************************************************/
197 211
198 212 int _write_r (struct _reent *r, int file, char * ptr, int len)
199 213 {
200 214 return _write(file, ptr, len);
201 215 }
202 216
203 217 /***************************************************************************/
204 218
205 219 int _close_r (struct _reent *r, int file)
206 220 {
207 221 return 0;
208 222 }
209 223
210 224 /***************************************************************************/
211 225
212 226 caddr_t _sbrk_r (struct _reent *r, int incr)
213 227 {
214 228 register char * stack_ptr __asm__ ("sp");
215 229 extern char _end; /* Defined by the linker */
216 230 static char *heap_end;
217 231 char *prev_heap_end;
218 232 if (heap_end == 0) {
219 233 heap_end = &_end;
220 234 }
221 235 prev_heap_end = heap_end;
222 236 if (heap_end + incr > stack_ptr) {
223 _write (1, "Heap and stack collision\n", 25);
224 abort ();
237 printf( "Heap and stack collision\n");
238 //abort ();
239 while(1)
240 {
241 delay_100us(10000);
242 gpioset(LED2);
243 delay_100us(10000);
244 gpioclr(LED2);
245 }
225 246 }
226 247 heap_end += incr;
227 248 return (caddr_t) prev_heap_end;
228 249 }
229 250
230 251 /***************************************************************************/
231 252
232 253 int _fstat_r (struct _reent *r, int file, struct stat * st)
233 254 {
234 255 r = r;
235 256 file = file;
236 257
237 258 memset (st, 0, sizeof (* st));
238 259 st->st_mode = S_IFCHR;
239 260 return 0;
240 261 }
241 262
242 263 /***************************************************************************/
243 264 int _open_r(struct _reent *r,const char *name, int flags, int mode)
244 265 {
245 266 return _open(name, flags, mode);
246 267 }
247 268
248 269 int _isatty_r(struct _reent *r, int fd)
249 270 {
250 271 r = r;
251 272 fd = fd;
252 273
253 274 return 1;
254 275 }
255 276
256 277
257 278 #ifdef __cplusplus
258 279 }
259 280 #endif
260 281
261 282
@@ -1,41 +1,41
1 1 #
2 2 # qmake configuration for arm-none-eabi
3 3 #
4 4
5 5 CONFIG +=
6 6 QMAKE_CC = arm-none-eabi-gcc
7 QMAKE_CFLAGS +=
7 QMAKE_CFLAGS +=
8 8 QMAKE_CFLAGS_DEPS += -M
9 9 QMAKE_CFLAGS_WARN_ON += -Wall
10 10 QMAKE_CFLAGS_WARN_OFF += -w
11 QMAKE_CFLAGS_RELEASE += -O2
11 QMAKE_CFLAGS_RELEASE += -O3
12 12 QMAKE_CFLAGS_DEBUG += -g -O0
13 13
14 14 QMAKE_CXX = arm-none-eabi-g++
15 15 QMAKE_CXXFLAGS += $$QMAKE_CFLAGS s
16 16 QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS
17 17 QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON
18 18 QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF
19 19 QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
20 20 QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG
21 21 QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
22 22 QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB
23 23 QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC
24 24 QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS
25 25
26 26 QMAKE_LINK = arm-none-eabi-gcc
27 27 QMAKE_LINK_SHLIB = arm-none-eabi-gcc
28 28 QMAKE_LINK_C = arm-none-eabi-gcc
29 29 QMAKE_LINK_C_SHLIB = arm-none-eabi-gcc
30 30 QMAKE_LFLAGS +=
31 QMAKE_LFLAGS_RELEASE +=
31 QMAKE_LFLAGS_RELEASE += -O3
32 32 QMAKE_LFLAGS_DEBUG +=
33 33 QMAKE_LFLAGS_APP +=
34 34 QMAKE_LFLAGS_SHLIB +=
35 35 QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB
36 36 QMAKE_LFLAGS_THREAD +=
37 37
38 38 QMAKE_AR = arm-none-eabi-ar -ru
39 39 QMAKE_LIB = arm-none-eabi-ar -ru
40 40 QMAKE_RANLIB =
41 41
@@ -1,75 +1,77
1 1 #
2 2 # qmake configuration for stm32f4
3 3 #
4 4 #
5 5
6 6
7 7 isEmpty(_stm32f4_conf){
8 8 _stm32f4_conf="oneshot"
9 9
10 10 QMAKE_CFLAGS=-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99
11 11
12 12 include(../common/arm-none-eabi.conf)
13 13
14 14 DEFINES += __OPTIMIZED_MATH
15 15 DEFINES += \"assert_param(expr)=((void)0)\"
16 16 INCLUDEPATH += $$PWD
17 17
18 18 DEFINES += __FPU_PRESENT=1
19 19 DEFINES += ARM_MATH_CM4
20 20
21 21 DEFINES += BSP="\"\\\"$$BSP"\\\"\"
22 22
23 23 CONFIG += cpu
24 24
25 25 contains( TEMPLATE, app ) {
26 OBJECTS_DIR=obj
27 DESTDIR=bin
26 OBJECTS_DIR=obj-$$UCMODEL
27 DESTDIR=bin-$$UCMODEL
28 28 unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin && python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:"$$DESTDIR/"$(QMAKE_TARGET).bin " $$DESTDIR/"$(QMAKE_TARGET).dfu"
29 29 win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin"
30 30
31 31 LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP
32 32 LIBS += -lbsp
33 33
34 34
35 35 QMAKE_LFLAGS= -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -T $$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/stm32_flash.ld
36 36
37 37 INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP
38 38
39 39 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c
40 40 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c
41 41 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/startup.s
42 42 SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c
43 43
44 44 # OTHER_FILES += $$[QT_INSTALL_PREFIX]/ucfiles/stm32f4/$$CPU/stm32_flash.ld
45 45
46 46 stflash.target = stflash
47 47 stflash.commands = cd $$DESTDIR && sudo st-flash write $(QMAKE_TARGET).bin 0x08000000
48 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 50 QMAKE_EXTRA_TARGETS += stflash dfu
51 51 }
52 52
53 53 contains( TEMPLATE, lib ) {
54 54 CONFIG+=staticlib
55 OBJECTS_DIR=obj-$$UCMODEL
56 DESTDIR=bin-$$UCMODEL
55 57 message( "You can only build static library for stm32f4" )
56 58 }
57 59
58 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