@@ -0,0 +1,37 | |||
|
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 | #ifndef OPTIMISED_MATH_H | |
|
23 | #define OPTIMISED_MATH_H | |
|
24 | #include <arm_math.h> | |
|
25 | ||
|
26 | inline float32_t optimised_sqrt(float32_t value) | |
|
27 | { | |
|
28 | float32_t out; | |
|
29 | arm_sqrt_f32(value,&out); | |
|
30 | return out; | |
|
31 | } | |
|
32 | ||
|
33 | inline float optimised_sin(float32_t x) | |
|
34 | { | |
|
35 | return arm_sin_f32(x); | |
|
36 | } | |
|
37 | #endif |
@@ -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" |
@@ -0,0 +1,37 | |||
|
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 | #ifndef OPTIMISED_MATH_H | |
|
23 | #define OPTIMISED_MATH_H | |
|
24 | #include <arm_math.h> | |
|
25 | ||
|
26 | inline float32_t optimised_sqrt(float32_t value) | |
|
27 | { | |
|
28 | float32_t out; | |
|
29 | arm_sqrt_f32(value,&out); | |
|
30 | return out; | |
|
31 | } | |
|
32 | ||
|
33 | inline float optimised_sin(float32_t x) | |
|
34 | { | |
|
35 | return arm_sin_f32(x); | |
|
36 | } | |
|
37 | #endif |
@@ -0,0 +1,77 | |||
|
1 | # | |
|
2 | # qmake configuration for stm32f4 | |
|
3 | # | |
|
4 | # | |
|
5 | ||
|
6 | ||
|
7 | isEmpty(_stm32f4_conf){ | |
|
8 | _stm32f4_conf="oneshot" | |
|
9 | ||
|
10 | QMAKE_CFLAGS=-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 | |
|
11 | ||
|
12 | include(../../common/arm-none-eabi.conf) | |
|
13 | ||
|
14 | DEFINES += __OPTIMIZED_MATH | |
|
15 | DEFINES += \"assert_param(expr)=((void)0)\" | |
|
16 | INCLUDEPATH += $$PWD | |
|
17 | ||
|
18 | DEFINES += __FPU_PRESENT=1 | |
|
19 | DEFINES += ARM_MATH_CM4 | |
|
20 | ||
|
21 | DEFINES += BSP="\"\\\"$$BSP"\\\"\" | |
|
22 | ||
|
23 | CONFIG += cpu | |
|
24 | ||
|
25 | contains( TEMPLATE, app ) { | |
|
26 | OBJECTS_DIR=obj-$$UCMODEL | |
|
27 | DESTDIR=bin-$$UCMODEL | |
|
28 | unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin && python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:"$$DESTDIR/"$(QMAKE_TARGET).bin " $$DESTDIR/"$(QMAKE_TARGET).dfu" | |
|
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 | ||
|
31 | LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP | |
|
32 | LIBS += -lbsp | |
|
33 | ||
|
34 | ||
|
35 | QMAKE_LFLAGS= -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -T $$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/stm32_flash.ld | |
|
36 | ||
|
37 | INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP | |
|
38 | ||
|
39 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c | |
|
40 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c | |
|
41 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/startup.s | |
|
42 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c | |
|
43 | ||
|
44 | # OTHER_FILES += $$[QT_INSTALL_PREFIX]/ucfiles/stm32f4/$$CPU/stm32_flash.ld | |
|
45 | ||
|
46 | stflash.target = stflash | |
|
47 | stflash.commands = cd $$DESTDIR && sudo st-flash write $(QMAKE_TARGET).bin 0x08000000 | |
|
48 | dfu.target = dfu | |
|
49 | dfu.commands = cd $$DESTDIR && dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000 | |
|
50 | QMAKE_EXTRA_TARGETS += stflash dfu | |
|
51 | } | |
|
52 | ||
|
53 | contains( TEMPLATE, lib ) { | |
|
54 | CONFIG+=staticlib | |
|
55 | OBJECTS_DIR=obj-$$UCMODEL | |
|
56 | DESTDIR=bin-$$UCMODEL | |
|
57 | message( "You can only build static library for stm32f4" ) | |
|
58 | } | |
|
59 | ||
|
60 | include(../../common/libuc2libs.conf) | |
|
61 | ||
|
62 | } | |
|
63 | ||
|
64 | ||
|
65 | ||
|
66 | ||
|
67 | ||
|
68 | ||
|
69 | ||
|
70 | ||
|
71 | ||
|
72 | ||
|
73 | ||
|
74 | ||
|
75 | ||
|
76 | ||
|
77 |
@@ -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,524 +1,534 | |||
|
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@member.fsf.org |
|
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 | 61 | volatile uint8_t* lcd0_CMD=(volatile uint8_t*) 0x60000000; |
|
62 | 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 | 128 | // { |
|
129 | 129 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
130 | 130 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
131 | 131 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); |
|
132 | 132 | // uartmkstreamdev(uart,fd1); |
|
133 | 133 | // __opnfiles__[1] = fd1; |
|
134 | 134 | // } |
|
135 | 135 | // else |
|
136 | 136 | // { |
|
137 | 137 | // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); |
|
138 | 138 | // } |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | /* |
|
142 | 142 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
143 | 143 | D5 PE8 D6 PE9 D7 PE10 |
|
144 | 144 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
145 | 145 | FSMC_NOE PD4 RD |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | int bsp_FSMC_init() |
|
149 | 149 | { |
|
150 | 150 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
151 | 151 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
152 | 152 | |
|
153 | 153 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ |
|
154 | 154 | ,PD4,PD5,PD7,PE4}; |
|
155 | 155 | for(int i=0;i<12;i++) |
|
156 | 156 | { |
|
157 | 157 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
158 | 158 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
159 | 159 | gpiosetconfig(&LCD_DBx); |
|
160 | 160 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
164 | 164 | FSMC_NORSRAMTimingInitTypeDef p; |
|
165 | 165 | |
|
166 | 166 | /* Enable FSMC clock */ |
|
167 | 167 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
168 | 168 | |
|
169 | 169 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
170 | 170 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
171 | 171 | /* FSMC_Bank1_NORSRAM4 configuration */ |
|
172 | 172 | //p.FSMC_AddressSetupTime = 5; |
|
173 | 173 | //p.FSMC_AddressSetupTime = 1; |
|
174 | 174 | p.FSMC_AddressSetupTime = 3; |
|
175 | 175 | p.FSMC_AddressHoldTime = 3; |
|
176 | 176 | //p.FSMC_DataSetupTime = 9; |
|
177 | 177 | //ili9328 -> data setup time > 10ns |
|
178 | 178 | p.FSMC_DataSetupTime = 1; |
|
179 | 179 | if(getCpuFreq()>100*1000*1000) |
|
180 | 180 | p.FSMC_DataSetupTime = 2;// 11; |
|
181 | 181 | p.FSMC_BusTurnAroundDuration = 0; |
|
182 | 182 | p.FSMC_CLKDivision = 0; |
|
183 | 183 | p.FSMC_DataLatency = 0; |
|
184 | 184 | //ili9328 -> data hold time > 15ns |
|
185 | 185 | if(getCpuFreq()>66*1000*1000) |
|
186 | 186 | p.FSMC_DataLatency = 1; |
|
187 | 187 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
188 | 188 | |
|
189 | 189 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
|
190 | 190 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
191 | 191 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
192 | 192 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; |
|
193 | 193 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
194 | 194 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
195 | 195 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
196 | 196 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
197 | 197 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
198 | 198 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
199 | 199 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
200 | 200 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
201 | 201 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
202 | 202 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
203 | 203 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
204 | 204 | |
|
205 | 205 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
206 | 206 | |
|
207 | 207 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
|
208 | 208 | gpioset(LCD_RESET); |
|
209 | 209 | gpioclr(LCD_RESET); |
|
210 | 210 | delay_100us(500); |
|
211 | 211 | gpioset(LCD_RESET); |
|
212 | 212 | delay_100us(500); |
|
213 | 213 | lcd0.init(&lcd0); |
|
214 | 214 | gpioset(LCD_BACKL); |
|
215 | 215 | return 1; |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | void bsp_spi_init() |
|
219 | 219 | { |
|
220 | 220 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; |
|
221 | 221 | for(int i=0;i<3;i++) |
|
222 | 222 | { |
|
223 | 223 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); |
|
224 | 224 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
225 | 225 | gpiosetconfig(&SPI_DBx); |
|
226 | 226 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); |
|
227 | 227 | } |
|
228 | 228 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); |
|
229 | 229 | |
|
230 | 230 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; |
|
231 | 231 | for(int i=0;i<3;i++) |
|
232 | 232 | { |
|
233 | 233 | gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); |
|
234 | 234 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
235 | 235 | gpiosetconfig(&SPI_DBx); |
|
236 | 236 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); |
|
237 | 237 | } |
|
238 | 238 | spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); |
|
239 | 239 | |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | |
|
243 | 243 | void bsp_iic_init() |
|
244 | 244 | { |
|
245 | 245 | // i2copenandconfig(i2c2,0,10000,PF0,PF1); |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | |
|
249 | 249 | void bsp_Audio_init() |
|
250 | 250 | { |
|
251 | 251 | vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ); |
|
252 | 252 | if(audioCodec0.VERSION!=UNKNOWN) |
|
253 | 253 | { |
|
254 | 254 | printf("detected Audio codec "); |
|
255 | 255 | switch (audioCodec0.VERSION) { |
|
256 | 256 | case VS1001: |
|
257 | 257 | printf("VS1001\n"); |
|
258 | 258 | break; |
|
259 | 259 | case VS1011: |
|
260 | 260 | printf("VS1011\n"); |
|
261 | 261 | break; |
|
262 | 262 | case VS1002: |
|
263 | 263 | printf("VS1002\n"); |
|
264 | 264 | break; |
|
265 | 265 | case VS1003: |
|
266 | 266 | printf("VS1003\n"); |
|
267 | 267 | break; |
|
268 | 268 | case VS1053: |
|
269 | 269 | printf("VS1053\n"); |
|
270 | 270 | break; |
|
271 | 271 | case VS1033: |
|
272 | 272 | printf("VS1033\n"); |
|
273 | 273 | break; |
|
274 | 274 | case VS1103: |
|
275 | 275 | printf("VS1103\n"); |
|
276 | 276 | break; |
|
277 | 277 | default: |
|
278 | 278 | printf("Unknown device\n"); |
|
279 | 279 | break; |
|
280 | 280 | } |
|
281 | 281 | } |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | void bsp_SD_init() |
|
285 | 285 | { |
|
286 | 286 | if(bspsdcardpresent()) |
|
287 | 287 | { |
|
288 | 288 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); |
|
289 | 289 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); |
|
290 | 290 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) |
|
291 | 291 | { |
|
292 | 292 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) |
|
293 | 293 | { |
|
294 | 294 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) |
|
295 | 295 | printf("Can't open fat32 partition 1\n"); |
|
296 | 296 | } |
|
297 | 297 | else |
|
298 | 298 | { |
|
299 | 299 | printf("Can't open or read MBR\n"); |
|
300 | 300 | } |
|
301 | 301 | delay_100us(10000); |
|
302 | 302 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) |
|
303 | 303 | { |
|
304 | 304 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) |
|
305 | 305 | printf("Can't open fat32 partition 2\n"); |
|
306 | 306 | } |
|
307 | 307 | else |
|
308 | 308 | { |
|
309 | 309 | printf("Can't open or read MBR\n"); |
|
310 | 310 | } |
|
311 | 311 | delay_100us(10000); |
|
312 | 312 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) |
|
313 | 313 | { |
|
314 | 314 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) |
|
315 | 315 | printf("Can't open fat32 partition 3\n"); |
|
316 | 316 | } |
|
317 | 317 | else |
|
318 | 318 | { |
|
319 | 319 | printf("Can't open or read MBR\n"); |
|
320 | 320 | } |
|
321 | 321 | delay_100us(10000); |
|
322 | 322 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) |
|
323 | 323 | { |
|
324 | 324 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) |
|
325 | 325 | printf("Can't open fat32 partition 4\n"); |
|
326 | 326 | } |
|
327 | 327 | else |
|
328 | 328 | { |
|
329 | 329 | printf("Can't open or read MBR\n"); |
|
330 | 330 | } |
|
331 | 331 | } |
|
332 | 332 | else |
|
333 | 333 | { |
|
334 | 334 | printf("Can't initialize SDCARD\n"); |
|
335 | 335 | } |
|
336 | 336 | } |
|
337 | 337 | delay_100us(20000); |
|
338 | 338 | } |
|
339 | 339 | |
|
340 | 340 | void vs1052setXCS(char val) |
|
341 | 341 | { |
|
342 | 342 | gpiosetval(VS1053xCS,(int)val); |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | void vs1052setXDCS(char val) |
|
346 | 346 | { |
|
347 | 347 | //gpiosetval(LED1,(int)val); |
|
348 | 348 | gpiosetval(VS1053xDCS,(int)val); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void vs1052setRST(char val) |
|
352 | 352 | { |
|
353 | 353 | if(val) |
|
354 | 354 | gpioset(VS1053xRESET); |
|
355 | 355 | else |
|
356 | 356 | gpioclr(VS1053xRESET); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | int vs10XXDREQ() |
|
360 | 360 | { |
|
361 | 361 | return gpiogetval(VS1053DREQ); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | |
|
365 | 365 | void bsppowersdcard(char onoff) //always ON |
|
366 | 366 | { |
|
367 | 367 | |
|
368 | 368 | } |
|
369 | 369 | |
|
370 | 370 | char bspsdcardpresent() |
|
371 | 371 | { |
|
372 | 372 | return gpiogetval(SDCARD2CD); |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | char bspsdcardwriteprotected() |
|
376 | 376 | { |
|
377 | 377 | return 0; |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | void bspsdcardselect(char YESNO) |
|
381 | 381 | { |
|
382 | 382 | // gpiosetval(LED1,(int)YESNO); |
|
383 | 383 | if(YESNO) |
|
384 | 384 | gpioclr(SDCARD2CS); |
|
385 | 385 | else |
|
386 | 386 | gpioset(SDCARD2CS); |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | |
|
390 | 390 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
391 | 391 | { |
|
392 | 392 | uint8_t* pt8 = (uint8_t*)(void*)® |
|
393 | 393 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
394 | 394 | *lcd0_CMD=pt8[3]; |
|
395 | 395 | *lcd0_CMD=pt8[2]; |
|
396 | 396 | pt8 = (uint8_t*)(void*)&data; |
|
397 | 397 | *lcd0_DATA=pt8[3]; |
|
398 | 398 | *lcd0_DATA=pt8[2]; |
|
399 | 399 | #else |
|
400 | 400 | *lcd0_CMD=pt8[1]; |
|
401 | 401 | *lcd0_CMD=pt8[0]; |
|
402 | 402 | pt8 = (uint8_t*)(void*)&data; |
|
403 | 403 | *lcd0_DATA=pt8[1]; |
|
404 | 404 | *lcd0_DATA=pt8[0]; |
|
405 | 405 | #endif |
|
406 | 406 | |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
410 | 410 | { |
|
411 | 411 | uint8_t* pt8 = (uint8_t*)(void*)® |
|
412 | 412 | uint32_t DATA=0; |
|
413 | 413 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
414 | 414 | *lcd0_CMD=pt8[3]; |
|
415 | 415 | *lcd0_CMD=pt8[2]; |
|
416 | 416 | pt8 = (uint8_t*)(void*)&DATA; |
|
417 | 417 | pt8[3]=*lcd0_DATA; |
|
418 | 418 | pt8[2]=*lcd0_DATA; |
|
419 | 419 | #else |
|
420 | 420 | |
|
421 | 421 | *lcd0_CMD=pt8[1]; |
|
422 | 422 | *lcd0_CMD=pt8[0]; |
|
423 | 423 | pt8 = (uint8_t*)(void*)&DATA; |
|
424 | 424 | pt8[1]=*lcd0_DATA; |
|
425 | 425 | pt8[0]=*lcd0_DATA; |
|
426 | 426 | #endif |
|
427 | 427 | |
|
428 | 428 | return DATA; |
|
429 | 429 | } |
|
430 | 430 | |
|
431 | 431 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
432 | 432 | { |
|
433 | 433 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; |
|
434 | 434 | uint8_t* pt8 = (uint8_t*)(void*)® |
|
435 | 435 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
436 | 436 | *lcd0_CMD=pt8[3]; |
|
437 | 437 | *lcd0_CMD=pt8[2]; |
|
438 | 438 | pt8 = (uint8_t*)(void*)buffer; |
|
439 | 439 | for(int i=0;i<(int)count;i++) |
|
440 | 440 | { |
|
441 | 441 | *lcd0_DATA=pt8[(2*i) +1]; |
|
442 | 442 | *lcd0_DATA=pt8[2*i]; |
|
443 | 443 | } |
|
444 | 444 | #else |
|
445 | 445 | |
|
446 | 446 | *lcd0_CMD=pt8[1]; |
|
447 | 447 | *lcd0_CMD=pt8[0]; |
|
448 | 448 | pt8 = (uint8_t*)(void*)buffer; |
|
449 | 449 | for(int i=0;i<(int)count;i++) |
|
450 | 450 | { |
|
451 | 451 | |
|
452 | 452 | *lcd0_DATA=pt8[(2*i) +1]; |
|
453 | 453 | *lcd0_DATA=pt8[2*i]; |
|
454 | 454 | } |
|
455 | 455 | #endif |
|
456 | 456 | } |
|
457 | 457 | |
|
458 | 458 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
459 | 459 | { |
|
460 |
|
|
|
461 |
|
|
|
460 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
|
461 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
462 | 462 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
463 | 463 | *lcd0_CMD=pt8[3]; |
|
464 | 464 | *lcd0_CMD=pt8[2]; |
|
465 | 465 | pt8 = (uint8_t*)(void*)buffer; |
|
466 | 466 | for(int i=0;i<(int)count;i++) |
|
467 | 467 | { |
|
468 | 468 | pt8[(2*i) +1]=*lcd0_DATA; |
|
469 | 469 | __asm__("nop"); |
|
470 | 470 | __asm__("nop"); |
|
471 | 471 | __asm__("nop"); |
|
472 | 472 | __asm__("nop"); |
|
473 | 473 | __asm__("nop"); |
|
474 | 474 | pt8[2*i]=*lcd0_DATA; |
|
475 | 475 | } |
|
476 | 476 | #else |
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
|
|
|
486 |
|
|
|
487 |
|
|
|
488 | // pt8[2*i]=*lcd0_DATA; | |
|
489 | //pt8[(2*i) +1]=(uint8_t)0; | |
|
490 | //pt8[(2*i)]=(uint8_t)0; | |
|
491 | // } | |
|
477 | *lcd0_CMD=pt8[1]; | |
|
478 | *lcd0_CMD=pt8[0]; | |
|
479 | pt8 = (uint8_t*)(void*)buffer; | |
|
480 | for(int i=0;i<(int)count;i++) | |
|
481 | { | |
|
482 | pt8[(2*i) +1]=*lcd0_DATA; | |
|
483 | __asm__("nop"); | |
|
484 | __asm__("nop"); | |
|
485 | __asm__("nop"); | |
|
486 | __asm__("nop"); | |
|
487 | __asm__("nop"); | |
|
488 | __asm__("nop"); | |
|
489 | __asm__("nop"); | |
|
490 | __asm__("nop"); | |
|
491 | __asm__("nop"); | |
|
492 | __asm__("nop"); | |
|
493 | pt8[2*i]=*lcd0_DATA; | |
|
494 | __asm__("nop"); | |
|
495 | __asm__("nop"); | |
|
496 | __asm__("nop"); | |
|
497 | __asm__("nop"); | |
|
498 | __asm__("nop"); | |
|
499 | pt8[(2*i) +1]=(uint8_t)0; | |
|
500 | pt8[(2*i)]=(uint8_t)0; | |
|
501 | } | |
|
492 | 502 | #endif |
|
493 | 503 | } |
|
494 | 504 | |
|
495 | 505 | void bsp_GTerm_init() |
|
496 | 506 | { |
|
497 | 507 | if(__opnfiles__[1]==NULL) |
|
498 | 508 | { |
|
499 | 509 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
500 | 510 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); |
|
501 | 511 | __opnfiles__[1] = fd1; |
|
502 | 512 | } |
|
503 | 513 | else |
|
504 | 514 | { |
|
505 | 515 | |
|
506 | 516 | } |
|
507 | 517 | } |
|
508 | 518 | |
|
509 | 519 | |
|
510 | 520 | |
|
511 | 521 | |
|
512 | 522 | |
|
513 | 523 | |
|
514 | 524 | |
|
515 | 525 | |
|
516 | 526 | |
|
517 | 527 | |
|
518 | 528 | |
|
519 | 529 | |
|
520 | 530 | |
|
521 | 531 | |
|
522 | 532 | |
|
523 | 533 | |
|
524 | 534 |
@@ -1,14 +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=10000000 | |
|
8 | DEFINES += CPUFREQ=160000000 | |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | SOURCES += \ |
|
12 | 12 | main.c \ |
|
13 | 13 | test_lcd.c |
|
14 | 14 |
@@ -1,207 +1,204 | |||
|
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 | 17 | #include <ili9328.h> |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | extern streamdevice* __opnfiles__[]; |
|
21 | 21 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
22 | 22 | char buffer[512]; |
|
23 | 23 | |
|
24 | 24 | void randBoxesDemo() |
|
25 | 25 | { |
|
26 | 26 | int16_t x,y,w,h,t,r; |
|
27 | 27 | x=rand()%240; |
|
28 | 28 | y=rand()%320; |
|
29 | 29 | w=rand()%(240-x); |
|
30 | 30 | if(x>y) |
|
31 | 31 | r=(rand()%(y))%(320-y); |
|
32 | 32 | else |
|
33 | 33 | r=(rand()%(x))%(240-x); |
|
34 | 34 | h=rand()%(320-y); |
|
35 | 35 | t=rand()%(10); |
|
36 | 36 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
37 | 37 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
38 | 38 | //delay_100us(10); |
|
39 | 39 | //for(volatile int i=0;i<(1024*2);i++); |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | void randTextDemo() |
|
43 | 43 | { |
|
44 | 44 | int16_t x,y,w,h,t,r; |
|
45 | 45 | char buf[2]; |
|
46 | 46 | buf[1]='\0'; |
|
47 | 47 | x=rand()%240; |
|
48 | 48 | y=rand()%320; |
|
49 | 49 | if(x>y) |
|
50 | 50 | r=(rand()%(y))%(320-y); |
|
51 | 51 | else |
|
52 | 52 | r=(rand()%(x))%(240-x); |
|
53 | 53 | h=rand()%(320-y); |
|
54 | 54 | buf[0]=rand()%(255); |
|
55 | 55 | //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
56 | 56 | ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); |
|
57 | 57 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
58 | 58 | delay_100us(5000); |
|
59 | 59 | //for(volatile int i=0;i<(1024*2);i++); |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | void tryToplay2() |
|
63 | 63 | { |
|
64 | 64 | |
|
65 | 65 | extern blkdevice sdcard2blkdev; |
|
66 | 66 | int i=0,l=0; |
|
67 | 67 | |
|
68 | 68 | spisetspeed(audioCodec0.SPIdev,4000000); |
|
69 | 69 | printf("Streaming File\n"); |
|
70 | 70 | |
|
71 | 71 | //printf("New LBA=0x%X\n",nextLba); |
|
72 | 72 | |
|
73 | 73 | while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK) |
|
74 | 74 | { |
|
75 | 75 | |
|
76 | 76 | for(i=0;i<512;i+=32) |
|
77 | 77 | { |
|
78 | 78 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | void playFile(ucdirent* file,FAT32fs* part) |
|
84 | 84 | { |
|
85 | 85 | extern volatile vs10XXDev audioCodec0; |
|
86 | 86 | char direntName[]=" \n"; |
|
87 | 87 | uint32_t fileLba,nextLba; |
|
88 | 88 | int i=0; |
|
89 | 89 | fat32getdirentname(file,direntName); |
|
90 | gpioset(LCD_BACKL); | |
|
91 |
|
|
|
90 | //gpioset(LCD_BACKL); | |
|
91 | printf("%s\n",direntName); | |
|
92 | 92 | nextLba=fat32getdirentlba(file); |
|
93 | 93 | //printf("Streaming File\n"); |
|
94 | gpioclr(LCD_BACKL); | |
|
94 | //gpioclr(LCD_BACKL); | |
|
95 | 95 | do |
|
96 | 96 | { |
|
97 | 97 | fileLba = nextLba; |
|
98 | 98 | if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) |
|
99 | 99 | { |
|
100 | 100 | for(i=0;i<512;i+=32) |
|
101 | 101 | { |
|
102 | 102 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
103 | 103 | } |
|
104 | 104 | } |
|
105 | 105 | }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); |
|
106 | 106 | vs10XXsoftReset(&audioCodec0); |
|
107 | 107 | while (gpiogetval(BP3))delay_100us(1000); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void playAllparts() |
|
111 | 111 | { |
|
112 | 112 | extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; |
|
113 | 113 | ucdirent root; |
|
114 | 114 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) |
|
115 | 115 | { |
|
116 | 116 | printf("Reading on SDCARD2 part1\n"); |
|
117 | 117 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
118 | 118 | { |
|
119 | 119 | do{ |
|
120 | 120 | playFile(&root,&sdcard2FAT32part1); |
|
121 | 121 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
122 | 122 | } |
|
123 | 123 | } |
|
124 | 124 | gpioset(LED2); |
|
125 | 125 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) |
|
126 | 126 | { |
|
127 | 127 | printf("Reading on SDCARD2 part2\n"); |
|
128 | 128 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
129 | 129 | { |
|
130 | 130 | do{ |
|
131 | 131 | playFile(&root,&sdcard2FAT32part2); |
|
132 | 132 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
133 | 133 | } |
|
134 | 134 | } |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | int main() | |
|
137 | int main2() | |
|
138 | 138 | { |
|
139 | 139 | delay_100us(30000); |
|
140 | 140 | int i=0; |
|
141 | 141 | int color=0; |
|
142 | 142 | for(i=0;i<240;i++) |
|
143 | 143 | { |
|
144 | 144 | if(i>(240/3)) |
|
145 | 145 | { |
|
146 | 146 | color= (i<<5) + 0x1F; |
|
147 | 147 | } |
|
148 | 148 | else |
|
149 | 149 | { |
|
150 | 150 | color = i; |
|
151 | 151 | } |
|
152 | 152 | if(i>(2*240/3)) |
|
153 | 153 | { |
|
154 | 154 | color= (i<<10) + 0x3FF; |
|
155 | 155 | } |
|
156 | 156 | lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); |
|
157 | 157 | } |
|
158 | 158 | while(1)printf("test "); |
|
159 | 159 | // for(i=0;i<240;i++) |
|
160 | 160 | // { |
|
161 | 161 | // if(i>(240/3)) |
|
162 | 162 | // { |
|
163 | 163 | // color= (i<<5) + 0x1F; |
|
164 | 164 | // } |
|
165 | 165 | // else |
|
166 | 166 | // { |
|
167 | 167 | // color = i; |
|
168 | 168 | // } |
|
169 | 169 | // if(i>(2*240/3)) |
|
170 | 170 | // { |
|
171 | 171 | // color= (i<<10) + 0x3FF; |
|
172 | 172 | // } |
|
173 | 173 | // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); |
|
174 | 174 | // } |
|
175 | 175 | for(i=0;i<240;i++) |
|
176 | 176 | { |
|
177 | 177 | ili9328setFrame(&lcd0,i,0,1,100); |
|
178 | 178 | lcd0.interface->readGRAM(buffer,100); |
|
179 | 179 | lcd0.paint(&lcd0,buffer,i,200,1,100); |
|
180 | 180 | } |
|
181 | 181 | while(1); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 |
int main |
|
|
184 | int main() | |
|
185 | 185 | { |
|
186 | 186 | extern terminal_t terminal0; |
|
187 | 187 | extern volatile vs10XXDev audioCodec0; |
|
188 | lcd0.paintText(&lcd0,"hello",20,50,&ComicSansMS_18 ,0xF0F0); | |
|
189 | while (1) | |
|
190 | randTextDemo(); | |
|
191 | 188 | printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); |
|
192 | 189 | vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); |
|
193 | 190 | delay_100us(1000); |
|
194 | 191 | vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); |
|
195 | 192 | printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); |
|
196 | 193 | printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); |
|
197 | 194 | //terminal_clear(&terminal0); |
|
198 | gpioclr(LCD_BACKL); | |
|
195 | // gpioclr(LCD_BACKL); | |
|
199 | 196 | playAllparts(); |
|
200 | 197 | return 0; |
|
201 | 198 | } |
|
202 | 199 | |
|
203 | 200 | |
|
204 | 201 | |
|
205 | 202 | |
|
206 | 203 | |
|
207 | 204 |
@@ -1,56 +1,56 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <bsp.h> |
|
6 | 6 | #include <core.h> |
|
7 | 7 | #include <bsp.h> |
|
8 | 8 | #include <spi.h> |
|
9 | 9 | #include <fat32.h> |
|
10 | 10 | #include <ucdirent.h> |
|
11 | 11 | #include <string.h> |
|
12 | 12 | #include <unistd.h> |
|
13 | 13 | #include <terminal.h> |
|
14 | 14 | #include <stdarg.h> |
|
15 | 15 | #include <malloc.h> |
|
16 | 16 | |
|
17 | 17 | extern streamdevice* __opnfiles__[]; |
|
18 | 18 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
19 | 19 | char buffer[512]; |
|
20 | 20 | |
|
21 | 21 | void streamdevicePrint(streamdevice* dev, const char* format,...) |
|
22 | 22 | { |
|
23 | 23 | char** str_buffer; |
|
24 | 24 | int i; |
|
25 | 25 | va_list ap; |
|
26 | 26 | va_start(ap,format); |
|
27 | 27 | vasprintf(str_buffer,format,ap); |
|
28 | 28 | va_end(ap); |
|
29 | 29 | i=strlen(*str_buffer); |
|
30 | 30 | dev->ops->write(dev,(void*)*str_buffer,1,i); |
|
31 | 31 | free(*str_buffer); |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | void lcd_print() |
|
35 | 35 | { |
|
36 | 36 | lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F); |
|
37 | 37 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); |
|
38 | 38 | } |
|
39 | 39 | |
|
40 |
int libuc |
|
|
40 | int libuc_main() | |
|
41 | 41 | { |
|
42 | 42 | char in[255]; |
|
43 | 43 | lcd_print(); |
|
44 | 44 | printf("hello world\n"); |
|
45 | 45 | streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); |
|
46 | 46 | lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); |
|
47 | 47 | // while (scanf("%c",in)) |
|
48 | 48 | // { |
|
49 | 49 | sleep(5); |
|
50 | 50 | // } |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 |
@@ -1,19 +1,20 | |||
|
1 | 1 | TEMPLATE = lib |
|
2 | 2 | TARGET = sdcard |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | sdcard.c |
|
6 | 6 | |
|
7 | 7 | INCLUDEPATH += ../../../includes \ |
|
8 | 8 | ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
9 | 9 | ../../CPU/CMSIS/Include |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | UCMODEL=stm32f4 |
|
13 | 13 | |
|
14 | 14 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
15 | 15 | INSTALLS += target |
|
16 | 16 | |
|
17 | 17 | HEADERS += \ |
|
18 | ../../../includes/sdcard.h | |
|
18 | ../../../includes/sdcard.h \ | |
|
19 | ../../../includes/sdcard-spi.h | |
|
19 | 20 |
@@ -1,422 +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@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include <ili9328.h> |
|
23 | 23 | #include <stdio.h> |
|
24 | 24 | #include <stddef.h> |
|
25 | 25 | #include <core.h> |
|
26 | 26 | #include <math.h> |
|
27 | 27 | |
|
28 | 28 | #ifdef __OPTIMIZED_MATH |
|
29 | 29 | #include <optimised_math.h> |
|
30 | 30 | #endif |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ |
|
34 | 34 | for(int l=0;l<1;l++)\ |
|
35 | 35 | {\ |
|
36 | 36 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
37 | 37 | int rem=(W)%buffsize;\ |
|
38 | 38 | if(rem)LCD->interface->writeGRAM(buffer,rem);\ |
|
39 | 39 | for(int i=rem;i<(W);i+=buffsize)\ |
|
40 | 40 | {\ |
|
41 | 41 | LCD->interface->writeGRAM(buffer,buffsize);\ |
|
42 | 42 | }\ |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
46 | 46 | for(int l=0;l<1;l++)\ |
|
47 | 47 | {\ |
|
48 | 48 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
49 | 49 | int rem=(ContSz)%buffContsize;\ |
|
50 | 50 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
51 | 51 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
52 | 52 | {\ |
|
53 | 53 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
54 | 54 | }\ |
|
55 | 55 | if((2*ContSz)<W) \ |
|
56 | 56 | {\ |
|
57 | 57 | rem=(W-(2*ContSz))%buffIntsize;\ |
|
58 | 58 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
59 | 59 | for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\ |
|
60 | 60 | {\ |
|
61 | 61 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
62 | 62 | }\ |
|
63 | 63 | }\ |
|
64 | 64 | rem=(ContSz)%buffContsize;\ |
|
65 | 65 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
66 | 66 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
67 | 67 | {\ |
|
68 | 68 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
69 | 69 | }\ |
|
70 | 70 | }\ |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
74 | 74 | for(int l=0;l<1;l++)\ |
|
75 | 75 | {\ |
|
76 | 76 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
77 | 77 | int rem=(ContSz)%buffContsize;\ |
|
78 | 78 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
79 | 79 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
80 | 80 | {\ |
|
81 | 81 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
82 | 82 | }\ |
|
83 | 83 | if((2*ContSz)<H) \ |
|
84 | 84 | {\ |
|
85 | 85 | rem=(H-(2*ContSz))%buffIntsize;\ |
|
86 | 86 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
87 | 87 | for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\ |
|
88 | 88 | {\ |
|
89 | 89 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
90 | 90 | }\ |
|
91 | 91 | }\ |
|
92 | 92 | rem=(ContSz)%buffContsize;\ |
|
93 | 93 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
94 | 94 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
95 | 95 | {\ |
|
96 | 96 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
97 | 97 | }\ |
|
98 | 98 | }\ |
|
99 | 99 | |
|
100 | 100 | |
|
101 | 101 | #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
102 | 102 | for(int l=0;l<1;l++)\ |
|
103 | 103 | {\ |
|
104 | 104 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
105 | 105 | int rem=(ContSz)%buffContsize;\ |
|
106 | 106 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
107 | 107 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
108 | 108 | {\ |
|
109 | 109 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
110 | 110 | }\ |
|
111 | 111 | if(ContSz<H) \ |
|
112 | 112 | {\ |
|
113 | 113 | rem=(H-ContSz)%buffIntsize;\ |
|
114 | 114 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
115 | 115 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
116 | 116 | {\ |
|
117 | 117 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
118 | 118 | }\ |
|
119 | 119 | }\ |
|
120 | 120 | }\ |
|
121 | 121 | |
|
122 | 122 | |
|
123 | 123 | #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
124 | 124 | for(int l=0;l<1;l++)\ |
|
125 | 125 | {\ |
|
126 | 126 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
127 | 127 | int rem;\ |
|
128 | 128 | if(ContSz<H) \ |
|
129 | 129 | {\ |
|
130 | 130 | rem=(H-ContSz)%buffIntsize;\ |
|
131 | 131 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
132 | 132 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
133 | 133 | {\ |
|
134 | 134 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
135 | 135 | }\ |
|
136 | 136 | }\ |
|
137 | 137 | rem=(ContSz)%buffContsize;\ |
|
138 | 138 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
139 | 139 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
140 | 140 | {\ |
|
141 | 141 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
142 | 142 | }\ |
|
143 | 143 | }\ |
|
144 | 144 | |
|
145 | 145 | |
|
146 | 146 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) |
|
147 | 147 | { |
|
148 | 148 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); |
|
149 | 149 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | void ili9328refreshenable(struct LCD_t* LCD,int enable) |
|
153 | 153 | { |
|
154 | 154 | if(enable) |
|
155 | 155 | { |
|
156 | 156 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018); |
|
157 | 157 | } |
|
158 | 158 | else |
|
159 | 159 | { |
|
160 | 160 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008); |
|
161 | 161 | |
|
162 | 162 | } |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H) |
|
166 | 166 | { |
|
167 | 167 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X); |
|
168 | 168 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y); |
|
169 | 169 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X); |
|
170 | 170 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1)); |
|
171 | 171 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y); |
|
172 | 172 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1)); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) |
|
176 | 176 | { |
|
177 | 177 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height))) |
|
178 | 178 | { |
|
179 | 179 | ili9328setFrame(LCD,Xpos,Ypos,Width,Height); |
|
180 | 180 | LCD->interface->writeGRAM(buffer,Width*Height); |
|
181 | 181 | } |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
185 | 185 | { |
|
186 | 186 | //Based on the mid point circle algorithm from Wikipedia |
|
187 | 187 | //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm |
|
188 | 188 | uint16_t innerbuffer[16]; |
|
189 | 189 | uint16_t outterbuffer[16]; |
|
190 | 190 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
191 | 191 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
192 | 192 | if(contSz<r) |
|
193 | 193 | { |
|
194 | 194 | int error = -r,error_int = -r+contSz; |
|
195 | 195 | int x = r,x_int=r-contSz; |
|
196 | 196 | int y = 0,y_int=0; |
|
197 | 197 | while (x >= y) |
|
198 | 198 | { |
|
199 | 199 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
200 | 200 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
201 | 201 | ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
202 | 202 | ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
203 | 203 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
204 | 204 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
205 | 205 | error += y; |
|
206 | 206 | ++y; |
|
207 | 207 | error += y; |
|
208 | 208 | error_int += y_int; |
|
209 | 209 | ++y_int; |
|
210 | 210 | error_int += y_int; |
|
211 | 211 | if(error >= 0) |
|
212 | 212 | { |
|
213 | 213 | error -= x; |
|
214 | 214 | --x; |
|
215 | 215 | error -= x; |
|
216 | 216 | } |
|
217 | 217 | if(error_int >= 0) |
|
218 | 218 | { |
|
219 | 219 | error_int -= x_int; |
|
220 | 220 | --x_int; |
|
221 | 221 | error_int -= x_int; |
|
222 | 222 | } |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | |
|
226 | 226 | |
|
227 | 227 | } |
|
228 | 228 | |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 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) |
|
232 | 232 | { |
|
233 | 233 | if(contSz<r) |
|
234 | 234 | { |
|
235 | 235 | uint16_t innerbuffer[16]; |
|
236 | 236 | uint16_t outterbuffer[16]; |
|
237 | 237 | int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem; |
|
238 | 238 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
239 | 239 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
240 | 240 | /* Y = b +/- sqrt[r^2 - (x - a)^2] */ |
|
241 | 241 | for(int32_t line=-r;line<r;line++) |
|
242 | 242 | { |
|
243 | 243 | #ifdef __OPTIMIZED_MATH |
|
244 | 244 | Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) ); |
|
245 | 245 | Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) ); |
|
246 | 246 | #else |
|
247 | 247 | Val1 = sqrt( (double)(rr - ((line)*(line))) ); |
|
248 | 248 | Val2 = sqrt( (double)(rr2 - ((line)*(line))) ); |
|
249 | 249 | #endif |
|
250 | 250 | X1=Xpos - Val1; |
|
251 | 251 | contSz2= Val1-Val2; |
|
252 | 252 | ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1); |
|
253 | 253 | rem=(contSz2)%16; |
|
254 | 254 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
255 | 255 | for(int i=rem;i<(contSz2);i+=16) |
|
256 | 256 | { |
|
257 | 257 | LCD->interface->writeGRAM(outterbuffer,16); |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | W=2*Val1; |
|
261 | 261 | if(W>(2*contSz2)) |
|
262 | 262 | { |
|
263 | 263 | W-=2*contSz2; |
|
264 | 264 | rem=(W)%16; |
|
265 | 265 | if(rem)LCD->interface->writeGRAM(innerbuffer,rem); |
|
266 | 266 | for(int i=rem;i<(W);i+=16) |
|
267 | 267 | { |
|
268 | 268 | LCD->interface->writeGRAM(innerbuffer,16); |
|
269 | 269 | } |
|
270 | 270 | } |
|
271 | 271 | |
|
272 | 272 | rem=(contSz2)%16; |
|
273 | 273 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
274 | 274 | for(int i=rem;i<(contSz2);i+=16) |
|
275 | 275 | { |
|
276 | 276 | LCD->interface->writeGRAM(outterbuffer,16); |
|
277 | 277 | } |
|
278 | 278 | } |
|
279 | 279 | } |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | |
|
283 | 283 | |
|
284 | 284 | |
|
285 | 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) |
|
286 | 286 | { |
|
287 | 287 | ili9328setFrame(LCD,Xpos,Ypos,w,h); |
|
288 | 288 | uint16_t tmp[32]; |
|
289 | 289 | for(int i=0;i<32;i++)tmp[i]=fillColor; |
|
290 | 290 | for(int i=0;i<(h*w);i+=32) |
|
291 | 291 | { |
|
292 | 292 | LCD->interface->writeGRAM(tmp,32); |
|
293 | 293 | } |
|
294 | 294 | int rem=(w*h)%32; |
|
295 | 295 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
296 | 296 | if(contSz) |
|
297 | 297 | { |
|
298 | 298 | ili9328setFrame(LCD,Xpos,Ypos,w,contSz); |
|
299 | 299 | for(int i=0;i<32;i++)tmp[i]=contColor; |
|
300 | 300 | rem=(w*contSz)%32; |
|
301 | 301 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
302 | 302 | for(int i=rem;i<(w*contSz);i+=32) |
|
303 | 303 | { |
|
304 | 304 | LCD->interface->writeGRAM(tmp,32); |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz); |
|
308 | 308 | rem=(w*contSz)%32; |
|
309 | 309 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
310 | 310 | for(int i=rem;i<(w*contSz);i+=32) |
|
311 | 311 | { |
|
312 | 312 | LCD->interface->writeGRAM(tmp,32); |
|
313 | 313 | } |
|
314 | 314 | |
|
315 | 315 | ili9328setFrame(LCD,Xpos,Ypos,contSz,h); |
|
316 | 316 | rem=(h*contSz)%32; |
|
317 | 317 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
318 | 318 | for(int i=rem;i<(h*contSz);i+=32) |
|
319 | 319 | { |
|
320 | 320 | LCD->interface->writeGRAM(tmp,32); |
|
321 | 321 | } |
|
322 | 322 | |
|
323 | 323 | ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h); |
|
324 | 324 | rem=(h*contSz)%32; |
|
325 | 325 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
326 | 326 | for(int i=rem;i<(h*contSz);i+=32) |
|
327 | 327 | { |
|
328 | 328 | LCD->interface->writeGRAM(tmp,32); |
|
329 | 329 | } |
|
330 | 330 | } |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color) |
|
334 | 334 | { |
|
335 | 335 | int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0; |
|
336 | 336 | uint16_t tmp[w]; |
|
337 | 337 | uint16_t linenum=0,charnum=0; |
|
338 | 338 | uint8_t line=0; |
|
339 | 339 | while(*buffer!='\0') |
|
340 | 340 | { |
|
341 | 341 | if(*buffer<32)*buffer=32; |
|
342 | 342 | if(*buffer>127)*buffer=32; |
|
343 | 343 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1); |
|
344 | 344 | LCD->interface->readGRAM(tmp,w); |
|
345 | 345 | for(int i=0;i<(h*w);i++) |
|
346 | 346 | { |
|
347 | 347 | if( ((i%w)==0) ) //read current line to apply text pixmap |
|
348 | 348 | { |
|
349 | 349 | if(linenum++>0) |
|
350 | 350 | { |
|
351 | 351 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1); |
|
352 | 352 | LCD->interface->writeGRAM(tmp,w); |
|
353 | 353 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); |
|
354 | 354 | LCD->interface->readGRAM(tmp,w); |
|
355 | 355 | pix=0; |
|
356 | 356 | } |
|
357 | 357 | } |
|
358 | 358 | if((pix%8) == 0) |
|
359 | 359 | { |
|
360 | 360 | line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++]; |
|
361 | 361 | } |
|
362 | tmp[pix]=0; | |
|
362 | //tmp[pix]=0; | |
|
363 | 363 | if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; |
|
364 | 364 | pix++; |
|
365 | 365 | line>>=1; |
|
366 | 366 | } |
|
367 | 367 | linenum=0; |
|
368 | 368 | tableoffset=0; |
|
369 | 369 | charnum++; |
|
370 | 370 | buffer++; |
|
371 | 371 | } |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | int ili9328init(struct LCD_t* LCD) |
|
375 | 375 | { |
|
376 | 376 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) |
|
377 | 377 | { |
|
378 | 378 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) |
|
379 | 379 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) |
|
380 | 380 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) |
|
381 | 381 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302); |
|
382 | 382 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); |
|
383 | 383 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On |
|
384 | 384 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) |
|
385 | 385 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
386 | 386 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) |
|
387 | 387 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) |
|
388 | 388 | delay_100us(1000); |
|
389 | 389 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) |
|
390 | 390 | delay_100us(500); |
|
391 | 391 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
392 | 392 | delay_100us(500); |
|
393 | 393 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) |
|
394 | 394 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) |
|
395 | 395 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) |
|
396 | 396 | delay_100us(500); |
|
397 | 397 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 |
|
398 | 398 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 |
|
399 | 399 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 |
|
400 | 400 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 |
|
401 | 401 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 |
|
402 | 402 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 |
|
403 | 403 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 |
|
404 | 404 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 |
|
405 | 405 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 |
|
406 | 406 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 |
|
407 | 407 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) |
|
408 | 408 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h) |
|
409 | 409 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) |
|
410 | 410 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h) |
|
411 | 411 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) |
|
412 | 412 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE |
|
413 | 413 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) |
|
414 | 414 | // Display On |
|
415 | 415 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) |
|
416 | 416 | delay_100us(500); |
|
417 | 417 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); |
|
418 | 418 | } |
|
419 | 419 | return 0; |
|
420 | 420 | } |
|
421 | 421 | |
|
422 | 422 |
@@ -1,245 +1,237 | |||
|
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@member.fsf.org |
|
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 | 49 | terminal->horizontalSpace = 0; |
|
50 | 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 |
terminal->backgroundColor=0x |
|
|
54 | terminal->backgroundColor=0xF00F; | |
|
55 | 55 | terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10)); |
|
56 | 56 | strdev->_stream = (UHANDLE)terminal; |
|
57 | 57 | strdev->ops = &TERMINAL_OPS; |
|
58 | 58 | strdev->streamPt = 0; |
|
59 | 59 | terminal_clear(terminal); |
|
60 | 60 | terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); |
|
61 | 61 | terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1)); |
|
62 | 62 | terminal->firstLine = 0; |
|
63 | 63 | terminal->lastLine = 0; |
|
64 | 64 | terminal->empty = 1; |
|
65 | 65 | for(int i=1;i<=terminal->lineCount;i++) |
|
66 | 66 | { |
|
67 | 67 | terminal->buffer[i * terminal->columnCount]='\n'; |
|
68 | 68 | } |
|
69 | 69 | return 1; |
|
70 | 70 | } |
|
71 | 71 | return 0; |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height) |
|
75 | 75 | { |
|
76 | 76 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
77 | 77 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
78 | 78 | if(terminal->LCD->height<(Ypos+height)) |
|
79 | 79 | return; |
|
80 | 80 | if(terminal->LCD->width<(Xpos+width)) |
|
81 | 81 | return; |
|
82 | 82 | terminal->Xpos = Xpos; |
|
83 | 83 | terminal->Ypos = Ypos; |
|
84 | 84 | terminal->height = height; |
|
85 | 85 | terminal->width = width; |
|
86 | 86 | terminal->lineCount = terminal->height/charh; |
|
87 | 87 | terminal->columnCount = (terminal->width/charw)-1; |
|
88 | 88 | terminal_clear(terminal); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | void terminal_clear(terminal_t* terminal) |
|
93 | 93 | { |
|
94 | 94 | terminal->firstLine = 0; |
|
95 | 95 | terminal->lastLine = 0; |
|
96 | 96 | terminal->empty = 1; |
|
97 | 97 | terminal->line =0; |
|
98 | 98 | terminal->column=0; |
|
99 | 99 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor) |
|
103 | 103 | { |
|
104 | 104 | terminal->backgroundColor = backgrooundColor; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void terminal_settextColor(terminal_t* terminal, uint32_t textColor) |
|
108 | 108 | { |
|
109 | 109 | terminal->textColor = textColor; |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | void terminal_movecursor(terminal_t* terminal,int n) |
|
114 | 114 | { |
|
115 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
|
116 | int charh=terminal->font->Height + terminal->verticalSpace; | |
|
117 | 115 | terminal->column += n; |
|
118 | 116 | if(terminal->column>(terminal->columnCount)) |
|
119 | 117 | { |
|
120 | 118 | terminal->line += (terminal->column)/terminal->columnCount; |
|
121 | 119 | terminal->line = terminal->line % terminal->lineCount; |
|
122 | 120 | 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); | |
|
128 | 121 | } |
|
129 | //terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal,charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
|
130 | 122 | } |
|
131 | 123 | |
|
132 | 124 | void terminal_clearCurentLine(terminal_t* terminal) |
|
133 | 125 | { |
|
134 | 126 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
135 | 127 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
136 |
|
|
|
128 | terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
|
137 | 129 | } |
|
138 | 130 | |
|
139 | 131 | int terminal_writenc(terminal_t* terminal,char* data, int n) |
|
140 | 132 | { |
|
141 | 133 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
142 | 134 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
143 | 135 | int l=0; |
|
144 | 136 | char buffer[2]=" "; |
|
145 | 137 | while(l<n) |
|
146 | 138 | { |
|
147 | 139 | |
|
148 | 140 | buffer[0]=data[l]; |
|
149 | 141 | if(buffer[0]=='\n') |
|
150 | 142 | { |
|
151 | 143 | terminal->line= (terminal->line+1) % terminal->lineCount; |
|
152 | 144 | terminal->column = 0; |
|
153 | 145 | if(terminal->line==0) |
|
154 | 146 | terminal_clear(terminal); |
|
155 | 147 | else |
|
156 | 148 | terminal_clearCurentLine(terminal); |
|
157 | 149 | }else { |
|
158 | 150 | if(buffer[0]=='\t') |
|
159 | 151 | { |
|
160 | 152 | for(int i=0;i<1;i++)terminal_movecursor(terminal,1); |
|
161 | 153 | }else |
|
162 | 154 | if(terminal->column==0)terminal_clearCurentLine(terminal); |
|
163 | 155 | if(buffer[0]!='\r'){ |
|
164 | 156 | // 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); | |
|
157 | terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
|
166 | 158 | terminal_movecursor(terminal,1); |
|
167 | 159 | } |
|
168 | 160 | } |
|
169 | 161 | l++; |
|
170 | 162 | } |
|
171 | 163 | return n; |
|
172 | 164 | } |
|
173 | 165 | |
|
174 | 166 | void terminal_print_line(terminal_t* terminal,int line) |
|
175 | 167 | { |
|
176 | 168 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
177 | 169 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
178 | 170 | terminal_clearCurentLine(terminal); |
|
179 | 171 | terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor); |
|
180 | 172 | } |
|
181 | 173 | |
|
182 | 174 | int terminal_writenc2(terminal_t* terminal,char* data, int n) |
|
183 | 175 | { |
|
184 | 176 | int charw=terminal->font->Width + terminal->horizontalSpace; |
|
185 | 177 | int charh=terminal->font->Height + terminal->verticalSpace; |
|
186 | 178 | /* First copy to buffer*/ |
|
187 | 179 | int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column; |
|
188 | 180 | for(int i=0;i<n;i++) |
|
189 | 181 | { |
|
190 | 182 | terminal->empty=0; |
|
191 | 183 | terminal->buffer[offset] = data[i]; |
|
192 | 184 | if(data[i]=='\n') |
|
193 | 185 | { |
|
194 | 186 | offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1)); |
|
195 | 187 | } |
|
196 | 188 | else |
|
197 | 189 | { |
|
198 | 190 | offset++; |
|
199 | 191 | } |
|
200 | 192 | } |
|
201 | 193 | if(!terminal->empty) |
|
202 | 194 | { |
|
203 | 195 | for(int i=terminal->firstLine;i<=terminal->lastLine;i++) |
|
204 | 196 | { |
|
205 | 197 | terminal_print_line(terminal,i); |
|
206 | 198 | } |
|
207 | 199 | } |
|
208 | 200 | return n; |
|
209 | 201 | } |
|
210 | 202 | |
|
211 | 203 | |
|
212 | 204 | |
|
213 | 205 | int terminal_write(streamdevice* device,void* data,int size, int n) |
|
214 | 206 | { |
|
215 | 207 | return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n); |
|
216 | 208 | } |
|
217 | 209 | |
|
218 | 210 | int terminal_read(streamdevice* device,void* data,int size, int n) |
|
219 | 211 | { |
|
220 | 212 | return n*size; |
|
221 | 213 | } |
|
222 | 214 | |
|
223 | 215 | int terminal_setpos(streamdevice* device,int pos) |
|
224 | 216 | { |
|
225 | 217 | return 1; |
|
226 | 218 | } |
|
227 | 219 | |
|
228 | 220 | int terminal_close( streamdevice* device) |
|
229 | 221 | { |
|
230 | 222 | return 1; |
|
231 | 223 | } |
|
232 | 224 | |
|
233 | 225 | |
|
234 | 226 | |
|
235 | 227 | |
|
236 | 228 | |
|
237 | 229 | |
|
238 | 230 | |
|
239 | 231 | |
|
240 | 232 | |
|
241 | 233 | |
|
242 | 234 | |
|
243 | 235 | |
|
244 | 236 | |
|
245 | 237 |
@@ -1,66 +1,66 | |||
|
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 |
#ifndef SDCARD |
|
|
23 |
#define SDCARD |
|
|
22 | #ifndef SDCARD_SPI_H | |
|
23 | #define SDCARD_SPI_H | |
|
24 | 24 | #include <blkdevice.h> |
|
25 | 25 | #include <libucstrings.h> |
|
26 | 26 | #include <uhandle.h> |
|
27 | 27 | #include <sdcard.h> |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | extern void sdcardspimake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t ),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy)); |
|
31 | 31 | extern void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected); |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | #endif |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 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 |
@@ -1,7 +1,7 | |||
|
1 | 1 | |
|
2 | 2 | |
|
3 | 3 | int main(void) |
|
4 | 4 | { |
|
5 | 5 | bsp_init(); |
|
6 |
libuc |
|
|
6 | libuc_main(); | |
|
7 | 7 | } |
@@ -1,34 +1,32 | |||
|
1 | 1 | # |
|
2 | 2 | # Microcontroler switch |
|
3 | 3 | # |
|
4 | 4 | # |
|
5 | 5 | contains( TEMPLATE, app ) { |
|
6 | 6 | !isEmpty( BSP ) { |
|
7 | 7 | include(./boards/$$BSP/bsp.pri) |
|
8 | 8 | } |
|
9 | 9 | } |
|
10 | 10 | |
|
11 | #contains( TEMPLATE, lib ) { | |
|
12 | 11 |
|
|
13 |
|
|
|
12 | include(./$$UCMODEL/cpu.pri) | |
|
13 | include(./$$UCMODEL/qmake.conf) | |
|
14 | 14 | } |
|
15 | #} | |
|
16 | 15 | |
|
17 | 16 | |
|
18 | 17 | |
|
19 | 18 | |
|
20 | 19 | |
|
21 | 20 | |
|
22 | 21 | |
|
23 | 22 | |
|
24 | 23 | |
|
25 | 24 | |
|
26 | 25 | |
|
27 | 26 | |
|
28 | 27 | |
|
29 | 28 | |
|
30 | 29 | |
|
31 | 30 | |
|
32 | 31 | |
|
33 | 32 | |
|
34 |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now