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