@@ -0,0 +1,69 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #include <STMPE811.h> | |||
|
24 | ||||
|
25 | int stmpe811init(STMPE811_t *dev, i2c_t i2cdev, uint8_t A0) | |||
|
26 | { | |||
|
27 | ||||
|
28 | dev->devAddress = 0x82; | |||
|
29 | if(A0) dev->devAddress = 0x88; | |||
|
30 | dev->i2cdev = i2cdev; | |||
|
31 | return 1; | |||
|
32 | } | |||
|
33 | ||||
|
34 | int stmpe811getID(STMPE811_t *dev) | |||
|
35 | { | |||
|
36 | if(dev != NULL) | |||
|
37 | { | |||
|
38 | char DATA[2]; | |||
|
39 | DATA[0]=STMPE811_REGISTER_CHIP_ID; | |||
|
40 | i2cwrite(dev->i2cdev,dev->devAddress,DATA,1); | |||
|
41 | i2cread(dev->i2cdev,dev->devAddress,DATA,2); | |||
|
42 | uint16_t val=DATA[0]; | |||
|
43 | val=(val<<8)+DATA[1]; | |||
|
44 | return val; | |||
|
45 | } | |||
|
46 | return -1; | |||
|
47 | } | |||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 | ||||
|
57 | ||||
|
58 | ||||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 |
@@ -0,0 +1,28 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | OBJECTS_DIR = obj | |||
|
3 | TARGET = STMPE811 | |||
|
4 | ||||
|
5 | SOURCES += \ | |||
|
6 | STMPE811.c | |||
|
7 | ||||
|
8 | DEFINES -= __OPTIMIZED_MATH | |||
|
9 | ||||
|
10 | INCLUDEPATH += ../../../../includes \ | |||
|
11 | ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \ | |||
|
12 | ../../../CPU/CMSIS/Include \ | |||
|
13 | ../../../../includes/GRAPHIC/CONTROLERS \ | |||
|
14 | ../../../../includes/GRAPHIC/TC_CONTROLERS \ | |||
|
15 | ../../../../includes/GRAPHIC/GUI/FONTS \ | |||
|
16 | ../../../../includes/GRAPHIC/GUI/Widgets | |||
|
17 | ||||
|
18 | ||||
|
19 | UCMODEL=stm32f4 | |||
|
20 | ||||
|
21 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL | |||
|
22 | INSTALLS += target | |||
|
23 | ||||
|
24 | HEADERS += \ | |||
|
25 | ../../../../includes/GRAPHIC/TC_CONTROLERS/STMPE811.h \ | |||
|
26 | ../../../../includes/GRAPHIC/TC_CONTROLERS/genericTC_Controler.h | |||
|
27 | ||||
|
28 |
@@ -0,0 +1,115 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef STMPE811_H | |||
|
23 | #define STMPE811_H | |||
|
24 | #include <stdio.h> | |||
|
25 | #include <uhandle.h> | |||
|
26 | #include <genericTC_Controler.h> | |||
|
27 | #include <stdint.h> | |||
|
28 | #include <fonts.h> | |||
|
29 | #include <i2c.h> | |||
|
30 | ||||
|
31 | typedef struct STMPE811_t | |||
|
32 | { | |||
|
33 | i2c_t i2cdev; | |||
|
34 | uint8_t devAddress; | |||
|
35 | }STMPE811_t; | |||
|
36 | ||||
|
37 | ||||
|
38 | extern int stmpe811init(STMPE811_t *dev, i2c_t i2cdev, uint8_t A0); | |||
|
39 | extern int stmpe811getID(STMPE811_t *dev); | |||
|
40 | ||||
|
41 | ||||
|
42 | ||||
|
43 | #define STMPE811_REGISTER_CHIP_ID ((uint32_t) 0x0000 ) | |||
|
44 | #define STMPE811_REGISTER_ID_VER ((uint32_t) 0x0002 ) | |||
|
45 | #define STMPE811_REGISTER_SYS_CTRL1 ((uint32_t) 0x0003 ) | |||
|
46 | #define STMPE811_REGISTER_SYS_CTRL2 ((uint32_t) 0x0004 ) | |||
|
47 | #define STMPE811_REGISTER_SPI_CFG ((uint32_t) 0x0008 ) | |||
|
48 | #define STMPE811_REGISTER_INT_CTRL ((uint32_t) 0x0009 ) | |||
|
49 | #define STMPE811_REGISTER_INT_EN ((uint32_t) 0x000A ) | |||
|
50 | #define STMPE811_REGISTER_INT_STA ((uint32_t) 0x000B ) | |||
|
51 | #define STMPE811_REGISTER_GPIO_EN ((uint32_t) 0x000C ) | |||
|
52 | #define STMPE811_REGISTER_GPIO_INT_STA ((uint32_t) 0x000D ) | |||
|
53 | #define STMPE811_REGISTER_ADC_INT_EN ((uint32_t) 0x000E ) | |||
|
54 | #define STMPE811_REGISTER_ADC_INT_STA ((uint32_t) 0x000F ) | |||
|
55 | #define STMPE811_REGISTER_GPIO_SET_PIN ((uint32_t) 0x0010 ) | |||
|
56 | #define STMPE811_REGISTER_GPIO_CLR_PIN ((uint32_t) 0x0011 ) | |||
|
57 | #define STMPE811_REGISTER_GPIO_MP_STA ((uint32_t) 0x0012 ) | |||
|
58 | #define STMPE811_REGISTER_GPIO_DIR ((uint32_t) 0x0013 ) | |||
|
59 | #define STMPE811_REGISTER_GPIO_ED ((uint32_t) 0x0014 ) | |||
|
60 | #define STMPE811_REGISTER_GPIO_RE ((uint32_t) 0x0015 ) | |||
|
61 | #define STMPE811_REGISTER_GPIO_FE ((uint32_t) 0x0016 ) | |||
|
62 | #define STMPE811_REGISTER_GPIO_AF ((uint32_t) 0x0017 ) | |||
|
63 | #define STMPE811_REGISTER_ADC_CTRL1 ((uint32_t) 0x0020 ) | |||
|
64 | #define STMPE811_REGISTER_ADC_CTRL2 ((uint32_t) 0x0021 ) | |||
|
65 | #define STMPE811_REGISTER_ADC_CAPT ((uint32_t) 0x0022 ) | |||
|
66 | #define STMPE811_REGISTER_ADC_DATA_CH0 ((uint32_t) 0x0030 ) | |||
|
67 | #define STMPE811_REGISTER_ADC_DATA_CH1 ((uint32_t) 0x0032 ) | |||
|
68 | #define STMPE811_REGISTER_ADC_DATA_CH2 ((uint32_t) 0x0034 ) | |||
|
69 | #define STMPE811_REGISTER_ADC_DATA_CH3 ((uint32_t) 0x0036 ) | |||
|
70 | #define STMPE811_REGISTER_ADC_DATA_CH4 ((uint32_t) 0x0038 ) | |||
|
71 | #define STMPE811_REGISTER_ADC_DATA_CH5 ((uint32_t) 0x003A ) | |||
|
72 | #define STMPE811_REGISTER_ADC_DATA_CH6 ((uint32_t) 0x003C ) | |||
|
73 | #define STMPE811_REGISTER_ADC_DATA_CH7 ((uint32_t) 0x003E ) | |||
|
74 | #define STMPE811_REGISTER_TSC_CTRL ((uint32_t) 0x0040 ) | |||
|
75 | #define STMPE811_REGISTER_TSC_CFG ((uint32_t) 0x0041 ) | |||
|
76 | #define STMPE811_REGISTER_WDW_TR_X ((uint32_t) 0x0042 ) | |||
|
77 | #define STMPE811_REGISTER_WDW_TR_Y ((uint32_t) 0x0044 ) | |||
|
78 | #define STMPE811_REGISTER_WDW_BL_X ((uint32_t) 0x0046 ) | |||
|
79 | #define STMPE811_REGISTER_WDW_BL_Y ((uint32_t) 0x0048 ) | |||
|
80 | #define STMPE811_REGISTER_FIFO_TH ((uint32_t) 0x004A ) | |||
|
81 | #define STMPE811_REGISTER_FIFO_STA ((uint32_t) 0x004B ) | |||
|
82 | #define STMPE811_REGISTER_FIFO_SIZE ((uint32_t) 0x004C ) | |||
|
83 | #define STMPE811_REGISTER_TSC_DATA_X ((uint32_t) 0x004D ) | |||
|
84 | #define STMPE811_REGISTER_TSC_DATA_Y ((uint32_t) 0x004F ) | |||
|
85 | #define STMPE811_REGISTER_TSC_DATA_Z ((uint32_t) 0x0051 ) | |||
|
86 | #define STMPE811_REGISTER_TSC_DATA_XYZ ((uint32_t) 0x0052 ) | |||
|
87 | #define STMPE811_REGISTER_TSC_FRACTION_Z ((uint32_t) 0x0056 ) | |||
|
88 | #define STMPE811_REGISTER_TSC_DATA ((uint32_t) 0x0057 ) | |||
|
89 | #define STMPE811_REGISTER_TSC_I_DRIVE ((uint32_t) 0x0058 ) | |||
|
90 | #define STMPE811_REGISTER_TSC_SHIELD ((uint32_t) 0x0059 ) | |||
|
91 | #define STMPE811_REGISTER_TEMP_CTRL ((uint32_t) 0x0060 ) | |||
|
92 | #define STMPE811_REGISTER_TEMP_DATA ((uint32_t) 0x0061 ) | |||
|
93 | #define STMPE811_REGISTER_TEMP_TH ((uint32_t) 0x0062 ) | |||
|
94 | ||||
|
95 | ||||
|
96 | #endif | |||
|
97 | ||||
|
98 | ||||
|
99 | ||||
|
100 | ||||
|
101 | ||||
|
102 | ||||
|
103 | ||||
|
104 | ||||
|
105 | ||||
|
106 | ||||
|
107 | ||||
|
108 | ||||
|
109 | ||||
|
110 | ||||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | ||||
|
115 |
@@ -0,0 +1,37 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | #ifndef GENERICTC_CONTROLER_H | |||
|
23 | #define GENERICTC_CONTROLER_H | |||
|
24 | ||||
|
25 | #include <uhandle.h> | |||
|
26 | #include <stdint.h> | |||
|
27 | #include <fonts.h> | |||
|
28 | ||||
|
29 | ||||
|
30 | ||||
|
31 | ||||
|
32 | #endif /*GENERICTC_CONTROLER_H*/ | |||
|
33 | ||||
|
34 | ||||
|
35 | ||||
|
36 | ||||
|
37 |
@@ -0,0 +1,81 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | ||||
|
24 | #define __THREAD_PRIVATE__ | |||
|
25 | #include <thread.h> | |||
|
26 | ||||
|
27 | /* | |||
|
28 | For CM4 cf lazy Stacking and context switching form ARM | |||
|
29 | List of automatically saved registers: | |||
|
30 | R0 | |||
|
31 | R1 | |||
|
32 | R2 | |||
|
33 | R3 | |||
|
34 | R4 | |||
|
35 | R5 | |||
|
36 | R6 | |||
|
37 | R7 | |||
|
38 | R8 | |||
|
39 | R9 | |||
|
40 | R10 | |||
|
41 | R11 | |||
|
42 | R12 | |||
|
43 | R13(SP) | |||
|
44 | R14(LR) | |||
|
45 | R15(PC) | |||
|
46 | xPSR | |||
|
47 | S0 to S15 (if enabled) | |||
|
48 | ||||
|
49 | List of registers to save: | |||
|
50 | S16 to S31 | |||
|
51 | */ | |||
|
52 | ||||
|
53 | ||||
|
54 | void __cpusavecontext(void* dataspace) | |||
|
55 | { | |||
|
56 | ||||
|
57 | } | |||
|
58 | ||||
|
59 | void __cpurestorecontext(void* dataspace) | |||
|
60 | { | |||
|
61 | ||||
|
62 | } | |||
|
63 | ||||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | ||||
|
68 | ||||
|
69 | ||||
|
70 | ||||
|
71 | ||||
|
72 | ||||
|
73 | ||||
|
74 | ||||
|
75 | ||||
|
76 | ||||
|
77 | ||||
|
78 | ||||
|
79 | ||||
|
80 | ||||
|
81 |
@@ -1,345 +1,345 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include "bsp.h" |
|
22 | #include "bsp.h" | |
23 | #include <streamdevices.h> |
|
23 | #include <streamdevices.h> | |
24 | #include <malloc.h> |
|
24 | #include <malloc.h> | |
25 | #include <gpio.h> |
|
25 | #include <gpio.h> | |
26 | #include <uart.h> |
|
26 | #include <uart.h> | |
27 | #include <stdio.h> |
|
27 | #include <stdio.h> | |
28 | #include <stm32f4xx_gpio.h> |
|
28 | #include <stm32f4xx_gpio.h> | |
29 | #include <stm32f4xx_fsmc.h> |
|
29 | #include <stm32f4xx_fsmc.h> | |
30 | #include <i2c.h> |
|
30 | #include <i2c.h> | |
31 | #include <core.h> |
|
31 | #include <core.h> | |
32 | #include <terminal.h> |
|
32 | #include <terminal.h> | |
33 | uint32_t OSC0 =8000000; |
|
33 | uint32_t OSC0 =8000000; | |
34 | uint32_t INTOSC =16000000; |
|
34 | uint32_t INTOSC =16000000; | |
35 | uint32_t RTCOSC =32768; |
|
35 | uint32_t RTCOSC =32768; | |
36 | uint32_t currentCpuFreq=0; |
|
36 | uint32_t currentCpuFreq=0; | |
37 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
37 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
38 |
|
38 | |||
39 | LCD_IF_t lcdIF0={ |
|
39 | LCD_IF_t lcdIF0={ | |
40 | .init = &bsp_FSMC_init, |
|
40 | .init = &bsp_FSMC_init, | |
41 | .writereg = &bsp_lcd0_write_reg, |
|
41 | .writereg = &bsp_lcd0_write_reg, | |
42 | .readreg = &bsp_lcd0_read_reg, |
|
42 | .readreg = &bsp_lcd0_read_reg, | |
43 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
43 | .writeGRAM = &bsp_lcd0_writeGRAM, | |
44 | .readGRAM = &bsp_lcd0_readGRAM |
|
44 | .readGRAM = &bsp_lcd0_readGRAM | |
45 | }; |
|
45 | }; | |
46 |
|
46 | |||
47 | LCD_t lcd0={ |
|
47 | LCD_t lcd0={ | |
48 | .interface = &lcdIF0, |
|
48 | .interface = &lcdIF0, | |
49 | .init = &ili9328init, |
|
49 | .init = &ili9328init, | |
50 | .paint = &ili9328paint, |
|
50 | .paint = &ili9328paint, | |
51 | .paintText = &ili9328paintText, |
|
51 | .paintText = &ili9328paintText, | |
52 | .paintFilRect = &ili9328paintFilRect, |
|
52 | .paintFilRect = &ili9328paintFilRect, | |
53 | .refreshenable = &ili9328refreshenable, |
|
53 | .refreshenable = &ili9328refreshenable, | |
54 | .width= 240, |
|
54 | .width= 240, | |
55 | .height = 320 |
|
55 | .height = 320 | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | terminal_t terminal0; |
|
58 | terminal_t terminal0; | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | volatile int16_t* lcd0_CMD=(volatile int16_t*) (0x60000000 | 0x08000000); |
|
61 | volatile int16_t* lcd0_CMD=(volatile int16_t*) (0x60000000 | 0x08000000); | |
62 | volatile int16_t* lcd0_DATA=((volatile int16_t*)(0x60000000 | 0x08000002)); |
|
62 | volatile int16_t* lcd0_DATA=((volatile int16_t*)(0x60000000 | 0x08000002)); | |
63 |
|
63 | |||
64 | float VREF0 =(float)3.3; |
|
64 | float VREF0 =(float)3.3; | |
65 |
|
65 | |||
66 | int bsp_init() |
|
66 | int bsp_init() | |
67 | { |
|
67 | { | |
68 | int i=0; |
|
68 | int i=0; | |
69 | for(i=0;i<32;i++) |
|
69 | for(i=0;i<32;i++) | |
70 | { |
|
70 | { | |
71 | __opnfiles__[i] = NULL; |
|
71 | __opnfiles__[i] = NULL; | |
72 | } |
|
72 | } | |
73 | bsp_GPIO_init(); |
|
73 | bsp_GPIO_init(); | |
74 | bsp_uart_init(); |
|
74 | bsp_uart_init(); | |
75 | bsp_iic_init(); |
|
75 | bsp_iic_init(); | |
76 | bsp_FSMC_init(); |
|
76 | bsp_FSMC_init(); | |
77 | bsp_GTerm_init(); |
|
77 | bsp_GTerm_init(); | |
78 | printf("\r=====================\n\r"); |
|
78 | printf("\r=====================\n\r"); | |
79 | printf( "=====================\n\r"); |
|
79 | printf( "=====================\n\r"); | |
80 | printf(BSP); |
|
80 | printf(BSP); | |
81 | printf(" initialised\n\r"); |
|
81 | printf(" initialised\n\r"); | |
82 | printf( "=====================\n\r"); |
|
82 | printf( "=====================\n\r"); | |
83 | return 1; |
|
83 | return 1; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void bsp_GPIO_init() |
|
86 | void bsp_GPIO_init() | |
87 | { |
|
87 | { | |
88 | gpio_t gpio1 = gpioopen(LED1); |
|
88 | gpio_t gpio1 = gpioopen(LED1); | |
89 | gpio_t gpio2 = gpioopen(LED2); |
|
89 | gpio_t gpio2 = gpioopen(LED2); | |
90 | gpio_t gpio3 = gpioopen(LED3); |
|
90 | gpio_t gpio3 = gpioopen(LED3); | |
91 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
91 | gpiosetspeed(&gpio1,gpiohighspeed); | |
92 | gpiosetspeed(&gpio2,gpiohighspeed); |
|
92 | gpiosetspeed(&gpio2,gpiohighspeed); | |
93 | gpiosetspeed(&gpio3,gpiohighspeed); |
|
93 | gpiosetspeed(&gpio3,gpiohighspeed); | |
94 | gpiosetdir(&gpio1,gpiooutdir); |
|
94 | gpiosetdir(&gpio1,gpiooutdir); | |
95 | gpiosetdir(&gpio2,gpiooutdir); |
|
95 | gpiosetdir(&gpio2,gpiooutdir); | |
96 | gpiosetdir(&gpio3,gpiooutdir); |
|
96 | gpiosetdir(&gpio3,gpiooutdir); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void bsp_uart_init() |
|
99 | void bsp_uart_init() | |
100 | { |
|
100 | { | |
101 | //if(__opnfiles__[1]==NULL) |
|
101 | //if(__opnfiles__[1]==NULL) | |
102 | //{ |
|
102 | //{ | |
103 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
103 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
104 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
104 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
105 | // uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
105 | // uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |
106 | //uartmkstreamdev(uart,fd1); |
|
106 | //uartmkstreamdev(uart,fd1); | |
107 | //__opnfiles__[1] = fd1; |
|
107 | //__opnfiles__[1] = fd1; | |
108 | //} |
|
108 | //} | |
109 | //else |
|
109 | //else | |
110 | //{ |
|
110 | //{ | |
111 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
111 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |
112 | //} |
|
112 | //} | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | /* |
|
115 | /* | |
116 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
116 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 | |
117 | D5 PE8 D6 PE9 D7 PE10 D8 PE11 D9 PE12 |
|
117 | D5 PE8 D6 PE9 D7 PE10 D8 PE11 D9 PE12 | |
118 | D10 PE13 D11 PE14 D12 PE15 D13 PD8 D14 PD9 |
|
118 | D10 PE13 D11 PE14 D12 PE15 D13 PD8 D14 PD9 | |
119 | D15 PD10 |
|
119 | D15 PD10 | |
120 | A0 PF0 = RS FSMC_NE3 PG10 CS FSMC_NWE PD5 W/S |
|
120 | A0 PF0 = RS FSMC_NE3 PG10 CS FSMC_NWE PD5 W/S | |
121 | FSMC_NOE PD4 RD |
|
121 | FSMC_NOE PD4 RD | |
122 | */ |
|
122 | */ | |
123 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
|
123 | /*-- GPIOs Configuration -----------------------------------------------------*/ | |
124 | /* |
|
124 | /* | |
125 | +-------------------+--------------------+------------------+------------------+ |
|
125 | +-------------------+--------------------+------------------+------------------+ | |
126 | + SRAM pins assignment + |
|
126 | + SRAM pins assignment + | |
127 | +-------------------+--------------------+------------------+------------------+ |
|
127 | +-------------------+--------------------+------------------+------------------+ | |
128 | | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | |
|
128 | | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | | |
129 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | |
|
129 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | | |
130 | | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | |
|
130 | | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | | |
131 | | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | |
|
131 | | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | | |
132 | | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | |
|
132 | | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | | |
133 | | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | |
|
133 | | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | | |
134 | | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | |
|
134 | | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | | |
135 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ |
|
135 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ | |
136 | | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | |
|
136 | | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | | |
137 | | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | |
|
137 | | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | | |
138 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ |
|
138 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ | |
139 | | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | |
|
139 | | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | | |
140 | | | PE15 <-> FSMC_D12 | |
|
140 | | | PE15 <-> FSMC_D12 | | |
141 | +-------------------+--------------------+ |
|
141 | +-------------------+--------------------+ | |
142 | */ |
|
142 | */ | |
143 | int bsp_FSMC_init() |
|
143 | int bsp_FSMC_init() | |
144 | { |
|
144 | { | |
145 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
145 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
146 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
146 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
147 |
|
147 | |||
148 | gpio_t LCD_DBxList[]={ |
|
148 | gpio_t LCD_DBxList[]={ | |
149 | PD0 ,PD1 ,PD4 ,PD5 ,PD8 ,PD9 ,PD10,PD11,PD12,PD13,PD14,PD15, |
|
149 | PD0 ,PD1 ,PD4 ,PD5 ,PD8 ,PD9 ,PD10,PD11,PD12,PD13,PD14,PD15, | |
150 | PE0 ,PE1 ,PE3 ,PE4 ,PE7 ,PE8 ,PE9 ,PE10,PE11,PE12,PE13,PE14, |
|
150 | PE0 ,PE1 ,PE3 ,PE4 ,PE7 ,PE8 ,PE9 ,PE10,PE11,PE12,PE13,PE14, | |
151 | PE15,PF0 ,PF1 ,PF2 ,PF3 ,PF4 ,PF5 ,PF12,PF13,PF14,PF15,PG0 , |
|
151 | PE15,PF0 ,PF1 ,PF2 ,PF3 ,PF4 ,PF5 ,PF12,PF13,PF14,PF15,PG0 , | |
152 | PG1 ,PG2 ,PG3 ,PG4 ,PG5 ,PG9 ,PG10 |
|
152 | PG1 ,PG2 ,PG3 ,PG4 ,PG5 ,PG9 ,PG10 | |
153 | }; |
|
153 | }; | |
154 |
|
154 | |||
155 | for(int i=0;i<43;i++) |
|
155 | for(int i=0;i<43;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_NORSRAM3 configuration */ |
|
171 | /* FSMC_Bank1_NORSRAM3 configuration */ | |
172 | p.FSMC_AddressSetupTime = 1; |
|
172 | p.FSMC_AddressSetupTime = 1; | |
173 | p.FSMC_AddressHoldTime = 0; |
|
173 | p.FSMC_AddressHoldTime = 0; | |
174 | p.FSMC_DataSetupTime = getCpuFreq()/14545450 ;// 11; |
|
174 | p.FSMC_DataSetupTime = getCpuFreq()/14545450 ;// 11; | |
175 | p.FSMC_BusTurnAroundDuration = 0; |
|
175 | p.FSMC_BusTurnAroundDuration = 0; | |
176 | p.FSMC_CLKDivision = 0; |
|
176 | p.FSMC_CLKDivision = 0; | |
177 | p.FSMC_DataLatency = 0; |
|
177 | p.FSMC_DataLatency = 0; | |
178 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
178 | p.FSMC_AccessMode = FSMC_AccessMode_A; | |
179 | /* Color LCD configuration ------------------------------------ |
|
179 | /* Color LCD configuration ------------------------------------ | |
180 | LCD configured as follow: |
|
180 | LCD configured as follow: | |
181 | - Data/Address MUX = Disable |
|
181 | - Data/Address MUX = Disable | |
182 | - Memory Type = SRAM |
|
182 | - Memory Type = SRAM | |
183 | - Data Width = 16bit |
|
183 | - Data Width = 16bit | |
184 | - Write Operation = Enable |
|
184 | - Write Operation = Enable | |
185 | - Extended Mode = Enable |
|
185 | - Extended Mode = Enable | |
186 | - Asynchronous Wait = Disable */ |
|
186 | - Asynchronous Wait = Disable */ | |
187 |
|
187 | |||
188 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; |
|
188 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; | |
189 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
189 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; | |
190 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
190 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; | |
191 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
191 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; | |
192 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
192 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; | |
193 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
193 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; | |
194 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
194 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; | |
195 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
195 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; | |
196 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
196 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; | |
197 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
197 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; | |
198 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
198 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; | |
199 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
199 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; | |
200 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
200 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; | |
201 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
201 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; | |
202 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
202 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; | |
203 |
|
203 | |||
204 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
204 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); | |
205 |
|
205 | |||
206 | /* Enable FSMC NOR/SRAM Bank1 */ |
|
206 | /* Enable FSMC NOR/SRAM Bank1 */ | |
207 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); |
|
207 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | p.FSMC_AddressSetupTime = getCpuFreq()/50000000; |
|
210 | p.FSMC_AddressSetupTime = getCpuFreq()/50000000; | |
211 | p.FSMC_AddressHoldTime = 0; |
|
211 | p.FSMC_AddressHoldTime = 0; | |
212 | p.FSMC_DataSetupTime = getCpuFreq()/25000000; |
|
212 | p.FSMC_DataSetupTime = getCpuFreq()/25000000; | |
213 | p.FSMC_BusTurnAroundDuration = 1; |
|
213 | p.FSMC_BusTurnAroundDuration = 1; | |
214 | p.FSMC_CLKDivision = 0; |
|
214 | p.FSMC_CLKDivision = 0; | |
215 | p.FSMC_DataLatency = 0; |
|
215 | p.FSMC_DataLatency = 0; | |
216 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
216 | p.FSMC_AccessMode = FSMC_AccessMode_A; | |
217 |
|
217 | |||
218 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; |
|
218 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; | |
219 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
219 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; | |
220 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; |
|
220 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; | |
221 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
221 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; | |
222 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
222 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; | |
223 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
223 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; | |
224 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
224 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; | |
225 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
225 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; | |
226 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
226 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; | |
227 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
227 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; | |
228 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
228 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; | |
229 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
229 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; | |
230 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
230 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; | |
231 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
231 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; | |
232 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
232 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; | |
233 |
|
233 | |||
234 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
234 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); | |
235 |
|
235 | |||
236 | /*!< Enable FSMC Bank1_SRAM2 Bank */ |
|
236 | /*!< Enable FSMC Bank1_SRAM2 Bank */ | |
237 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); |
|
237 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); | |
238 | lcd0.init(&lcd0); |
|
238 | lcd0.init(&lcd0); | |
239 | return 1; |
|
239 | return 1; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void bsp_spi_init() |
|
242 | void bsp_spi_init() | |
243 | { |
|
243 | { | |
244 |
|
244 | |||
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 |
|
247 | |||
248 | void bsp_iic_init() |
|
248 | void bsp_iic_init() | |
249 | { |
|
249 | { | |
250 |
i2copenandconfig(i2c1,0,10000 |
|
250 | i2copenandconfig(i2c1,0,10000,PB9,PB6); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void bsp_SD_init() |
|
253 | void bsp_SD_init() | |
254 | { |
|
254 | { | |
255 | gpio_t SDIO_DBxList[]={PC8 ,PC9 ,PC10 ,PC11 ,PC12,PD2}; |
|
255 | gpio_t SDIO_DBxList[]={PC8 ,PC9 ,PC10 ,PC11 ,PC12,PD2}; | |
256 | for(int i=0;i<6;i++) |
|
256 | for(int i=0;i<6;i++) | |
257 | { |
|
257 | { | |
258 | gpio_t SDIO_DBx = gpioopen(SDIO_DBxList[i]); |
|
258 | gpio_t SDIO_DBx = gpioopen(SDIO_DBxList[i]); | |
259 | SDIO_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
259 | SDIO_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
260 | gpiosetconfig(&SDIO_DBx); |
|
260 | gpiosetconfig(&SDIO_DBx); | |
261 | GPIO_PinAFConfig(GPIOGETPORT(SDIO_DBx), (uint8_t)(SDIO_DBx & 0xF), GPIO_AF_SDIO); |
|
261 | GPIO_PinAFConfig(GPIOGETPORT(SDIO_DBx), (uint8_t)(SDIO_DBx & 0xF), GPIO_AF_SDIO); | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void vs10XXclearXCS(){} |
|
265 | void vs10XXclearXCS(){} | |
266 | void vs10XXsetXCS(){} |
|
266 | void vs10XXsetXCS(){} | |
267 | int vs10XXDREQ() |
|
267 | int vs10XXDREQ() | |
268 | { |
|
268 | { | |
269 | return 1; |
|
269 | return 1; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 |
|
272 | |||
273 | void bsppowersdcard(char onoff) //always ON |
|
273 | void bsppowersdcard(char onoff) //always ON | |
274 | { |
|
274 | { | |
275 |
|
275 | |||
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | char bspsdcardpresent() |
|
278 | char bspsdcardpresent() | |
279 | { |
|
279 | { | |
280 | return 0; |
|
280 | return 0; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | char bspsdcardwriteprotected() |
|
283 | char bspsdcardwriteprotected() | |
284 | { |
|
284 | { | |
285 | return 0; |
|
285 | return 0; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void bspsdcardselect(char YESNO) |
|
288 | void bspsdcardselect(char YESNO) | |
289 | { |
|
289 | { | |
290 |
|
290 | |||
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 |
|
293 | |||
294 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
294 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
295 | { |
|
295 | { | |
296 | *lcd0_CMD=(uint16_t)reg; |
|
296 | *lcd0_CMD=(uint16_t)reg; | |
297 | *lcd0_DATA=(uint16_t)data; |
|
297 | *lcd0_DATA=(uint16_t)data; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
300 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
301 | { |
|
301 | { | |
302 | *lcd0_CMD=(uint16_t)reg; |
|
302 | *lcd0_CMD=(uint16_t)reg; | |
303 | return (uint16_t)*lcd0_DATA; |
|
303 | return (uint16_t)*lcd0_DATA; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
306 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
307 | { |
|
307 | { | |
308 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
308 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; | |
309 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
309 | uint16_t* castedBuff=(uint16_t*)buffer; | |
310 | for(int i=0;i<(int)count;i++) |
|
310 | for(int i=0;i<(int)count;i++) | |
311 | { |
|
311 | { | |
312 | *lcd0_DATA=castedBuff[i]; |
|
312 | *lcd0_DATA=castedBuff[i]; | |
313 | } |
|
313 | } | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
316 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
317 | { |
|
317 | { | |
318 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
318 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; | |
319 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
319 | uint16_t* castedBuff=(uint16_t*)buffer; | |
320 | castedBuff[0]=*lcd0_DATA; |
|
320 | castedBuff[0]=*lcd0_DATA; | |
321 | for(int i=0;i<(int)count;i++) |
|
321 | for(int i=0;i<(int)count;i++) | |
322 | { |
|
322 | { | |
323 | castedBuff[i]=*lcd0_DATA; |
|
323 | castedBuff[i]=*lcd0_DATA; | |
324 | } |
|
324 | } | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | void bsp_GTerm_init() |
|
327 | void bsp_GTerm_init() | |
328 | { |
|
328 | { | |
329 | if(__opnfiles__[1]==NULL) |
|
329 | if(__opnfiles__[1]==NULL) | |
330 | { |
|
330 | { | |
331 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
331 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
332 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
332 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
333 |
|
333 | |||
334 | ili9328paintFilRect(&lcd0,0,0,240,320,0x7FFF,5,0); |
|
334 | ili9328paintFilRect(&lcd0,0,0,240,320,0x7FFF,5,0); | |
335 | terminal_init(&terminal0,&lcd0,&ComicSansMS_8,fd1); |
|
335 | terminal_init(&terminal0,&lcd0,&ComicSansMS_8,fd1); | |
336 | __opnfiles__[1] = fd1; |
|
336 | __opnfiles__[1] = fd1; | |
337 | } |
|
337 | } | |
338 | else |
|
338 | else | |
339 | { |
|
339 | { | |
340 |
|
340 | |||
341 | } |
|
341 | } | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 |
|
344 | |||
345 |
|
345 |
@@ -1,23 +1,23 | |||||
1 | TEMPLATE = app |
|
1 | TEMPLATE = app | |
2 | CONFIG += cpu |
|
2 | CONFIG += cpu | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | UCMODEL=stm32f4 |
|
5 | UCMODEL=stm32f4 | |
6 |
DEFINES += CPUFREQ= |
|
6 | DEFINES += CPUFREQ=80000000 | |
7 |
|
7 | |||
8 | BSP = BEAGLESYNTH |
|
8 | BSP = BEAGLESYNTH | |
9 | #BSP = SOLAR_LFR_PSU |
|
9 | #BSP = SOLAR_LFR_PSU | |
10 | #BSP = STM32F4Eval |
|
10 | #BSP = STM32F4Eval | |
11 |
|
11 | |||
12 | SOURCES += \ |
|
12 | SOURCES += \ | |
13 | main.c |
|
13 | main.c | |
14 |
|
14 | |||
15 |
|
15 | |||
16 |
|
16 | |||
17 |
|
17 | |||
18 |
|
18 | |||
19 | #beagleCp.target = beagleCp |
|
19 | #beagleCp.target = beagleCp | |
20 | #beagleCp.commands = cd bin && scp $(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin |
|
20 | #beagleCp.commands = cd bin && scp $(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin | |
21 | #beagleCp131.target = beagleCp131 |
|
21 | #beagleCp131.target = beagleCp131 | |
22 | #beagleCp131.commands = cd bin && scp $(QMAKE_TARGET).bin root@129.104.27.131://opt/stm32flashAje/hello.bin |
|
22 | #beagleCp131.commands = cd bin && scp $(QMAKE_TARGET).bin root@129.104.27.131://opt/stm32flashAje/hello.bin | |
23 | #QMAKE_EXTRA_TARGETS += beagleCp beagleCp131 |
|
23 | #QMAKE_EXTRA_TARGETS += beagleCp beagleCp131 |
@@ -1,83 +1,123 | |||||
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 <math.h> |
|
6 | #include <math.h> | |
7 | #include <bsp.h> |
|
7 | #include <bsp.h> | |
8 | #include <i2c.h> |
|
8 | #include <i2c.h> | |
9 | #include <CS43L22.h> |
|
9 | #include <CS43L22.h> | |
10 | #include <ina226.h> |
|
10 | #include <ina226.h> | |
11 | #include <fonts.h> |
|
11 | #include <fonts.h> | |
12 | #include <stdlib.h> |
|
12 | #include <stdlib.h> | |
13 | #include <core.h> |
|
13 | #include <core.h> | |
14 | #include <malloc.h> |
|
14 | #include <malloc.h> | |
15 |
|
15 | |||
16 |
|
16 | |||
17 | extern streamdevice* __opnfiles__[]; |
|
17 | extern streamdevice* __opnfiles__[]; | |
18 |
|
18 | |||
19 | #define LCD_COLOR_WHITE 0xFFFF |
|
19 | #define LCD_COLOR_WHITE 0xFFFF | |
20 | #define LCD_COLOR_BLACK 0x0000 |
|
20 | #define LCD_COLOR_BLACK 0x0000 | |
21 | #define LCD_COLOR_GREY 0xF7DE |
|
21 | #define LCD_COLOR_GREY 0xF7DE | |
22 | #define LCD_COLOR_BLUE 0x001F |
|
22 | #define LCD_COLOR_BLUE 0x001F | |
23 | #define LCD_COLOR_BLUE2 0x051F |
|
23 | #define LCD_COLOR_BLUE2 0x051F | |
24 | #define LCD_COLOR_RED 0xF800 |
|
24 | #define LCD_COLOR_RED 0xF800 | |
25 | #define LCD_COLOR_MAGENTA 0xF81F |
|
25 | #define LCD_COLOR_MAGENTA 0xF81F | |
26 | #define LCD_COLOR_GREEN 0x07E0 |
|
26 | #define LCD_COLOR_GREEN 0x07E0 | |
27 | #define LCD_COLOR_CYAN 0x7FFF |
|
27 | #define LCD_COLOR_CYAN 0x7FFF | |
28 | #define LCD_COLOR_YELLOW 0xFFE0 |
|
28 | #define LCD_COLOR_YELLOW 0xFFE0 | |
29 |
|
29 | |||
30 | #ifndef PSU_DISABLE |
|
30 | #ifndef PSU_DISABLE | |
31 | #define PSU_DISABLE LED1 |
|
31 | #define PSU_DISABLE LED1 | |
32 | #endif |
|
32 | #endif | |
33 |
|
33 | |||
34 | void setUartAsStdout() |
|
34 | void setUartAsStdout() | |
35 | { |
|
35 | { | |
36 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
36 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
37 | uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
37 | uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |
38 | uartmkstreamdev(uart,fd1); |
|
38 | uartmkstreamdev(uart,fd1); | |
39 | __opnfiles__[1] = fd1; |
|
39 | __opnfiles__[1] = fd1; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
|
42 | void printSupplyStatus(int cur5v,int cur33v,int cur15v, int volt5v, int volt33v, int volt15v) | |||
|
43 | { | |||
|
44 | char buffer[64]; | |||
|
45 | int i=0; | |||
|
46 | int power5V=(cur5v*(volt5v/1000))/1000,power33V=(cur33v*(volt33v/1000))/1000,power15V=(cur15v*(volt15v/1000))/1000; | |||
|
47 | #define clearBuff for(i=0;i<64;i++)buffer[i]='\0' | |||
|
48 | ||||
|
49 | ili9328paintFilRect(&lcd0,5,5,230,7*(ComicSansMS_18.Height+10)+50,LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); | |||
|
50 | ili9328paintFilRect(&lcd0,5,7*(ComicSansMS_18.Height+10)+50,230,320 - (7*(ComicSansMS_18.Height+10)+50),LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); | |||
|
51 | clearBuff; | |||
|
52 | sprintf(buffer,"%.3fV %dmA",volt5v/1000000.0,cur5v); | |||
|
53 | ili9328paintText(&lcd0,buffer,10,0*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
54 | clearBuff; | |||
|
55 | sprintf(buffer,"%dmW",power5V); | |||
|
56 | ili9328paintText(&lcd0,buffer,10,1*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
57 | clearBuff; | |||
|
58 | sprintf(buffer,"%.3fV %dmA",volt33v/1000000.0,cur33v); | |||
|
59 | ili9328paintText(&lcd0,buffer,10,2*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
60 | clearBuff; | |||
|
61 | sprintf(buffer,"%dmW",power33V); | |||
|
62 | ili9328paintText(&lcd0,buffer,10,3*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
63 | clearBuff; | |||
|
64 | sprintf(buffer,"%.3fV %dmA",volt15v/1000000.0,cur15v); | |||
|
65 | ili9328paintText(&lcd0,buffer,10,4*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
66 | clearBuff; | |||
|
67 | sprintf(buffer,"%dmW",power15V); | |||
|
68 | ili9328paintText(&lcd0,buffer,10,5*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
69 | ||||
|
70 | clearBuff; | |||
|
71 | sprintf(buffer,"Total = %dmW",power5V+power33V+power15V); | |||
|
72 | ili9328paintText(&lcd0,buffer,10,320-10-20,&ComicSansMS_18,LCD_COLOR_BLACK); | |||
|
73 | ||||
|
74 | } | |||
|
75 | ||||
42 | int main() |
|
76 | int main() | |
43 | { |
|
77 | { | |
44 | delay_100us(20000); |
|
78 | delay_100us(20000); | |
45 | INA226_t ina5VSens,ina33VSens,ina15VSens; |
|
79 | INA226_t ina5VSens,ina33VSens,ina15VSens; | |
46 | gpioset(PSU_DISABLE);//enable psu! |
|
80 | gpioset(PSU_DISABLE);//enable psu! | |
47 | setUartAsStdout(); |
|
81 | setUartAsStdout(); | |
48 | //ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); |
|
82 | //ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); | |
49 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) |
|
83 | ||
|
84 | ili9328paintFilRect(&lcd0,5,5,230,310,LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); | |||
|
85 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000)) | |||
50 | { |
|
86 | { | |
51 | printf("Can't open 3.3V monitor\n\r"); |
|
87 | printf("Can't open 3.3V monitor\n\r"); | |
52 | } |
|
88 | } | |
53 |
if(-1==ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0, |
|
89 | if(-1==ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) | |
54 | { |
|
90 | { | |
55 | printf("Can't open 5V monitor\n\r"); |
|
91 | printf("Can't open 5V monitor\n\r"); | |
56 | } |
|
92 | } | |
57 | if(-1==ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000)) |
|
93 | if(-1==ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000)) | |
58 | { |
|
94 | { | |
59 | printf("Can't open 1.5V monitor\n\r"); |
|
95 | printf("Can't open 1.5V monitor\n\r"); | |
60 | } |
|
96 | } | |
61 | int current5V,current33V,current15V; |
|
97 | int current5V,current33V,current15V,volt5v, volt33v, volt15v; | |
62 | while(1) |
|
98 | while(1) | |
63 | { |
|
99 | { | |
64 | current5V = ina226getCurrent(&ina5VSens); |
|
100 | current5V = ina226getCurrent(&ina5VSens); | |
65 | current33V = ina226getCurrent(&ina33VSens); |
|
101 | current33V = ina226getCurrent(&ina33VSens); | |
66 | current15V = ina226getCurrent(&ina15VSens); |
|
102 | current15V = ina226getCurrent(&ina15VSens); | |
67 | printf("%dmA\n\r",current15V/1000); |
|
103 | volt5v = ina226getBusVoltage(&ina5VSens); | |
68 | printf("%dmA\n\r",current33V/1000); |
|
104 | volt33v = ina226getBusVoltage(&ina33VSens); | |
69 | printf("%dmA\n\r",current5V/1000); |
|
105 | volt15v = ina226getBusVoltage(&ina15VSens); | |
|
106 | printf("%fV\t%dmA\n\r",volt15v/1000000.0,current15V/1000); | |||
|
107 | printf("%fV\t%dmA\n\r",volt33v/1000000.0,current33V/1000); | |||
|
108 | printf("%fV\t%dmA\n\r",volt5v/1000000.0,current5V/1000); | |||
|
109 | printSupplyStatus(current5V/1000,current33V/1000,current15V/1000,volt5v, volt33v, volt15v); | |||
70 | delay_100us(10000); |
|
110 | delay_100us(10000); | |
71 | } |
|
111 | } | |
72 | printf("Exit\n\r"); |
|
112 | printf("Exit\n\r"); | |
73 | return 0; |
|
113 | return 0; | |
74 | } |
|
114 | } | |
75 |
|
115 | |||
76 |
|
116 | |||
77 |
|
117 | |||
78 |
|
118 | |||
79 |
|
119 | |||
80 |
|
120 | |||
81 |
|
121 | |||
82 |
|
122 | |||
83 |
|
123 |
@@ -1,81 +1,94 | |||||
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 <math.h> |
|
6 | #include <math.h> | |
7 | #include <bsp.h> |
|
7 | #include <bsp.h> | |
8 | #include <i2c.h> |
|
8 | #include <i2c.h> | |
9 | #include <CS43L22.h> |
|
9 | #include <CS43L22.h> | |
|
10 | #include <STMPE811.h> | |||
10 | #include <ina226.h> |
|
11 | #include <ina226.h> | |
11 | #include <fonts.h> |
|
12 | #include <fonts.h> | |
12 | #include <stdlib.h> |
|
13 | #include <stdlib.h> | |
13 | #include <core.h> |
|
14 | #include <core.h> | |
14 | #include <terminal.h> |
|
15 | #include <terminal.h> | |
15 |
|
16 | |||
16 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
17 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
17 |
|
18 | |||
18 | #define LCD_COLOR_WHITE 0xFFFF |
|
19 | #define LCD_COLOR_WHITE 0xFFFF | |
19 | #define LCD_COLOR_BLACK 0x0000 |
|
20 | #define LCD_COLOR_BLACK 0x0000 | |
20 | #define LCD_COLOR_GREY 0xF7DE |
|
21 | #define LCD_COLOR_GREY 0xF7DE | |
21 | #define LCD_COLOR_BLUE 0x001F |
|
22 | #define LCD_COLOR_BLUE 0x001F | |
22 | #define LCD_COLOR_BLUE2 0x051F |
|
23 | #define LCD_COLOR_BLUE2 0x051F | |
23 | #define LCD_COLOR_RED 0xF800 |
|
24 | #define LCD_COLOR_RED 0xF800 | |
24 | #define LCD_COLOR_MAGENTA 0xF81F |
|
25 | #define LCD_COLOR_MAGENTA 0xF81F | |
25 | #define LCD_COLOR_GREEN 0x07E0 |
|
26 | #define LCD_COLOR_GREEN 0x07E0 | |
26 | #define LCD_COLOR_CYAN 0x7FFF |
|
27 | #define LCD_COLOR_CYAN 0x7FFF | |
27 | #define LCD_COLOR_YELLOW 0xFFE0 |
|
28 | #define LCD_COLOR_YELLOW 0xFFE0 | |
28 |
|
29 | |||
29 | void testAudioDAC() |
|
30 | void testAudioDAC() | |
30 | { |
|
31 | { | |
31 | CS43L22_t dac; |
|
32 | CS43L22_t dac; | |
32 | cs43l22open(&dac,i2c1,0); |
|
33 | cs43l22open(&dac,i2c1,0); | |
33 | uint8_t ID= cs43l22getID(&dac); |
|
34 | uint8_t ID= cs43l22getID(&dac); | |
34 | printf("dac ID = %d\n\r",ID); |
|
35 | printf("dac ID = %d\n\r",ID); | |
35 | } |
|
36 | } | |
36 |
|
37 | |||
|
38 | void testIOEXPender() | |||
|
39 | { | |||
|
40 | STMPE811_t ioexp1,ioexp2; | |||
|
41 | char data[2]={0,0}; | |||
|
42 | i2cwrite(i2c1,0x50,data,1); | |||
|
43 | ||||
|
44 | //i2cread(i2c1,0x88,data,2); | |||
|
45 | // stmpe811init(&ioexp1,i2c1,0); | |||
|
46 | // stmpe811init(&ioexp2,i2c1,1); | |||
|
47 | // printf("Scan for IOEXPANDER:\n\r ID1=%d\n\rID2=%d",stmpe811getID(&ioexp1),stmpe811getID(&ioexp2)); | |||
|
48 | } | |||
|
49 | ||||
37 | int main() |
|
50 | int main() | |
38 | { |
|
51 | { | |
39 | delay_100us(10000); |
|
52 | delay_100us(10000); | |
40 | uint16_t innerbuffer[16]; |
|
53 | uint16_t innerbuffer[16]; | |
41 | uint16_t outterbuffer[16]; |
|
54 | uint16_t outterbuffer[16]; | |
42 | for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; |
|
55 | for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; | |
43 | for(int i=0;i<16;i++)outterbuffer[i]=LCD_COLOR_RED; |
|
56 | for(int i=0;i<16;i++)outterbuffer[i]=LCD_COLOR_RED; | |
44 | ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_CYAN,5,LCD_COLOR_BLACK); |
|
57 | ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_CYAN,5,LCD_COLOR_BLACK); | |
45 |
|
58 | |||
46 | streamdevice* fd1=__opnfiles__[1]; |
|
59 | streamdevice* fd1=__opnfiles__[1]; | |
47 | streamdevice fd2; |
|
60 | streamdevice fd2; | |
48 | int i=0; |
|
61 | int i=0; | |
49 | terminal_t terminal0,terminal1; |
|
62 | terminal_t terminal0,terminal1; | |
50 | terminal_init(&terminal0,&lcd0,&ComicSansMS_18,fd1); |
|
63 | terminal_init(&terminal0,&lcd0,&ComicSansMS_18,fd1); | |
51 | terminal_init(&terminal1,&lcd0,&ComicSansMS_18,&fd2); |
|
64 | //terminal_init(&terminal1,&lcd0,&ComicSansMS_18,&fd2); | |
52 |
terminal_setgeometry(&terminal0,5,5,terminal0.LCD->width-10,(terminal0.LCD->height |
|
65 | terminal_setgeometry(&terminal0,5,5,terminal0.LCD->width-10,(terminal0.LCD->height)-10); | |
53 | terminal_setbackgroundColor(&terminal1,0xFFFF); |
|
66 | //terminal_setbackgroundColor(&terminal1,0xFFFF); | |
54 | terminal_settextColor(&terminal1,0x0000); |
|
67 | //terminal_settextColor(&terminal1,0x0000); | |
55 | terminal_setgeometry(&terminal1,5,(terminal0.LCD->height/2)+5,terminal0.LCD->width-10,(terminal0.LCD->height/2)-10); |
|
68 | //terminal_setgeometry(&terminal1,5,(terminal0.LCD->height/2)+5,terminal0.LCD->width-10,(terminal0.LCD->height/2)-10); | |
56 | printf("Line cnt :\n \t%d\n",terminal0.lineCount); |
|
69 | printf("Line cnt :\n \t%d\n",terminal0.lineCount); | |
57 | printf("Column cnt :\n \t%d\n",terminal0.columnCount); |
|
70 | printf("Column cnt :\n \t%d\n",terminal0.columnCount); | |
58 | printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); |
|
71 | printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); | |
59 | //testAudioDAC(); |
|
72 | //testAudioDAC(); | |
60 | i2cwrite(i2c1,0x4a," ",1); |
|
73 | testIOEXPender(); | |
61 | while(1) |
|
74 | while(1) | |
62 | { |
|
75 | { | |
63 | i%=1000; |
|
76 | i%=1000; | |
64 | //terminal->write(&terminal," Hi",1, 2); |
|
77 | //terminal->write(&terminal," Hi",1, 2); | |
65 | //delay_100us(1000); |
|
78 | //delay_100us(1000); | |
66 | gpioset(LED1); |
|
79 | gpioset(LED1); | |
67 | //delay_100us(1000); |
|
80 | //delay_100us(1000); | |
68 | gpioclr(LED1); |
|
81 | gpioclr(LED1); | |
69 | } |
|
82 | } | |
70 | printf("hello world\n\r"); |
|
83 | printf("hello world\n\r"); | |
71 | return 0; |
|
84 | return 0; | |
72 | } |
|
85 | } | |
73 |
|
86 | |||
74 |
|
87 | |||
75 |
|
88 | |||
76 |
|
89 | |||
77 |
|
90 | |||
78 |
|
91 | |||
79 |
|
92 | |||
80 |
|
93 | |||
81 |
|
94 |
@@ -1,103 +1,103 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include <24LC0X.h> |
|
22 | #include <24LC0X.h> | |
23 | #include <i2c.h> |
|
23 | #include <i2c.h> | |
24 | #include <core.h> |
|
24 | #include <core.h> | |
25 | /* |
|
25 | /* | |
26 | struct 24LC0X_str |
|
26 | struct 24LC0X_str | |
27 | { |
|
27 | { | |
28 | i2cDev iicdev; |
|
28 | i2cDev iicdev; | |
29 | unsigned char devAddress; |
|
29 | unsigned char devAddress; | |
30 | unsigned char size; |
|
30 | unsigned char size; | |
31 | }; |
|
31 | }; | |
32 | */ |
|
32 | */ | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | void eeprom24lc0xopen(eeprom24lc0xDev* dev, i2c_t iicdev, unsigned char A0_A1_A2_val, unsigned int size) |
|
35 | void eeprom24lc0xopen(eeprom24lc0xDev* dev, i2c_t iicdev, unsigned char A0_A1_A2_val, unsigned int size) | |
36 | { |
|
36 | { | |
37 | dev->iicdev = iicdev; |
|
37 | dev->iicdev = iicdev; | |
38 | dev->devAddress = 0x50 | (A0_A1_A2_val & 0x7); |
|
38 | dev->devAddress = 0x50 | (A0_A1_A2_val & 0x7); | |
39 | if(size == 2048) dev->size = 2; |
|
39 | if(size == 2048) dev->size = 2; | |
40 | if(size == 1024) dev->size = 1; |
|
40 | if(size == 1024) dev->size = 1; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page) |
|
43 | void eeprom24lc0xpagewrite(eeprom24lc0xDev* dev,unsigned char address,unsigned char* page) | |
44 | { |
|
44 | { | |
45 | int cmdcnt=1,datacnt=8; |
|
45 | int cmdcnt=1,datacnt=8; | |
46 | //i2cwrite(dev.iicdev,address,page) |
|
46 | //i2cwrite(dev.iicdev,address,page) | |
47 | //i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,page,&datacnt); |
|
47 | //i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,page,&datacnt); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page) |
|
51 | void eeprom24lc0xpageread(eeprom24lc0xDev* dev,unsigned char address,unsigned char* page) | |
52 | { |
|
52 | { | |
53 | int cmdcnt=1,datacnt=8; |
|
53 | int cmdcnt=1,datacnt=8; | |
54 | /*i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); |
|
54 | /*i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); | |
55 | i2cread(dev.iicdev,dev.devAddress,page,&datacnt);*/ |
|
55 | i2cread(dev.iicdev,dev.devAddress,page,&datacnt);*/ | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void eeprom24lc0xbytewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char data) |
|
58 | void eeprom24lc0xbytewrite(eeprom24lc0xDev* dev,unsigned char address,unsigned char data) | |
59 | { |
|
59 | { | |
60 | int cmdcnt=1,datacnt=1; |
|
60 | int cmdcnt=1,datacnt=1; | |
61 | //i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,&data,&datacnt); |
|
61 | //i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,&data,&datacnt); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev dev,unsigned char address) |
|
65 | unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev* dev,unsigned char address) | |
66 | { |
|
66 | { | |
67 | int cmdcnt=1,datacnt=1; |
|
67 | int cmdcnt=1,datacnt=1; | |
68 | unsigned char data = 0; |
|
68 | unsigned char data = 0; | |
69 | /* i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); |
|
69 | /* i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); | |
70 | i2cread(dev.iicdev,dev.devAddress,&data,&datacnt);*/ |
|
70 | i2cread(dev.iicdev,dev.devAddress,&data,&datacnt);*/ | |
71 | return data; |
|
71 | return data; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | void eeprom24lc0xreadn(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count) |
|
75 | void eeprom24lc0xreadn(eeprom24lc0xDev* dev,unsigned char address,unsigned char* data, unsigned int count) | |
76 | { |
|
76 | { | |
77 | int cmdcnt=1,datacnt=count; |
|
77 | int cmdcnt=1,datacnt=count; | |
78 | /* i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); |
|
78 | /* i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); | |
79 | i2cread(dev.iicdev,dev.devAddress,data,&datacnt);*/ |
|
79 | i2cread(dev.iicdev,dev.devAddress,data,&datacnt);*/ | |
80 |
|
80 | |||
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void eeprom24lc0xwriten(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count) |
|
83 | void eeprom24lc0xwriten(eeprom24lc0xDev* dev,unsigned char address,unsigned char* data, unsigned int count) | |
84 | { |
|
84 | { | |
85 | int cmdcnt=1,datacnt=8; |
|
85 | int cmdcnt=1,datacnt=8; | |
86 | while(count >8) |
|
86 | while(count >8) | |
87 | { |
|
87 | { | |
88 | cmdcnt=1;datacnt=8; |
|
88 | cmdcnt=1;datacnt=8; | |
89 | // while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=8;} |
|
89 | // while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=8;} | |
90 | count-=8; |
|
90 | count-=8; | |
91 | address+=8; |
|
91 | address+=8; | |
92 | data+=8; |
|
92 | data+=8; | |
93 | } |
|
93 | } | |
94 | cmdcnt=1;datacnt=count; |
|
94 | cmdcnt=1;datacnt=count; | |
95 | // while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=count;} |
|
95 | // while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=count;} | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 |
|
98 | |||
99 |
|
99 | |||
100 |
|
100 | |||
101 |
|
101 | |||
102 |
|
102 | |||
103 |
|
103 |
@@ -1,15 +1,16 | |||||
1 | TEMPLATE = lib |
|
1 | TEMPLATE = lib | |
2 | OBJECTS_DIR = obj |
|
2 | OBJECTS_DIR = obj | |
3 |
|
3 | |||
4 | SOURCES += 24LC0X.c |
|
4 | SOURCES += 24LC0X.c | |
5 | HEADERS += ../../../includes/24LC0X.h |
|
5 | HEADERS += ../../../includes/24LC0X.h \ | |
|
6 | ../../../../includes/24LC0X.h | |||
6 |
|
7 | |||
7 | INCLUDEPATH += ../../../includes \ |
|
8 | INCLUDEPATH += ../../../includes \ | |
8 | ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
9 | ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ | |
9 | ../../CPU/CMSIS/Include |
|
10 | ../../CPU/CMSIS/Include | |
10 |
|
11 | |||
11 |
|
12 | |||
12 | UCMODEL=stm32f4 |
|
13 | UCMODEL=stm32f4 | |
13 |
|
14 | |||
14 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
15 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL | |
15 | INSTALLS += target |
|
16 | INSTALLS += target |
@@ -1,420 +1,420 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2012, Alexis Jeandet |
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #include <ili9328.h> |
|
22 | #include <ili9328.h> | |
23 | #include <stdio.h> |
|
23 | #include <stdio.h> | |
24 | #include <stddef.h> |
|
24 | #include <stddef.h> | |
25 | #include <core.h> |
|
25 | #include <core.h> | |
26 | #include <math.h> |
|
26 | #include <math.h> | |
27 |
|
27 | |||
28 | #ifdef __OPTIMIZED_MATH |
|
28 | #ifdef __OPTIMIZED_MATH | |
29 | #include <optimised_math.h> |
|
29 | #include <optimised_math.h> | |
30 | #endif |
|
30 | #endif | |
31 |
|
31 | |||
32 | #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++); |
|
32 | #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++); | |
33 |
|
33 | |||
34 | #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ |
|
34 | #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ | |
35 | for(int l=0;l<1;l++)\ |
|
35 | for(int l=0;l<1;l++)\ | |
36 | {\ |
|
36 | {\ | |
37 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
37 | ili9328setFrame(LCD,X,Y,W,1);\ | |
38 | int rem=(W)%buffsize;\ |
|
38 | int rem=(W)%buffsize;\ | |
39 | if(rem)LCD->interface->writeGRAM(buffer,rem);\ |
|
39 | if(rem)LCD->interface->writeGRAM(buffer,rem);\ | |
40 | for(int i=rem;i<(W);i+=buffsize)\ |
|
40 | for(int i=rem;i<(W);i+=buffsize)\ | |
41 | {\ |
|
41 | {\ | |
42 | LCD->interface->writeGRAM(buffer,buffsize);\ |
|
42 | LCD->interface->writeGRAM(buffer,buffsize);\ | |
43 | }\ |
|
43 | }\ | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
46 | #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ | |
47 | for(int l=0;l<1;l++)\ |
|
47 | for(int l=0;l<1;l++)\ | |
48 | {\ |
|
48 | {\ | |
49 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
49 | ili9328setFrame(LCD,X,Y,W,1);\ | |
50 | int rem=(ContSz)%buffContsize;\ |
|
50 | int rem=(ContSz)%buffContsize;\ | |
51 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
51 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
52 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
52 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
53 | {\ |
|
53 | {\ | |
54 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
54 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
55 | }\ |
|
55 | }\ | |
56 | if((2*ContSz)<W) \ |
|
56 | if((2*ContSz)<W) \ | |
57 | {\ |
|
57 | {\ | |
58 | rem=(W-(2*ContSz))%buffIntsize;\ |
|
58 | rem=(W-(2*ContSz))%buffIntsize;\ | |
59 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
59 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
60 | for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\ |
|
60 | for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\ | |
61 | {\ |
|
61 | {\ | |
62 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
62 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
63 | }\ |
|
63 | }\ | |
64 | }\ |
|
64 | }\ | |
65 | rem=(ContSz)%buffContsize;\ |
|
65 | rem=(ContSz)%buffContsize;\ | |
66 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
66 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
67 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
67 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
68 | {\ |
|
68 | {\ | |
69 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
69 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
70 | }\ |
|
70 | }\ | |
71 | }\ |
|
71 | }\ | |
72 |
|
72 | |||
73 |
|
73 | |||
74 | #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
74 | #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ | |
75 | for(int l=0;l<1;l++)\ |
|
75 | for(int l=0;l<1;l++)\ | |
76 | {\ |
|
76 | {\ | |
77 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
77 | ili9328setFrame(LCD,X,Y,1,H);\ | |
78 | int rem=(ContSz)%buffContsize;\ |
|
78 | int rem=(ContSz)%buffContsize;\ | |
79 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
79 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
80 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
80 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
81 | {\ |
|
81 | {\ | |
82 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
82 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
83 | }\ |
|
83 | }\ | |
84 | if((2*ContSz)<H) \ |
|
84 | if((2*ContSz)<H) \ | |
85 | {\ |
|
85 | {\ | |
86 | rem=(H-(2*ContSz))%buffIntsize;\ |
|
86 | rem=(H-(2*ContSz))%buffIntsize;\ | |
87 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
87 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
88 | for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\ |
|
88 | for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\ | |
89 | {\ |
|
89 | {\ | |
90 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
90 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
91 | }\ |
|
91 | }\ | |
92 | }\ |
|
92 | }\ | |
93 | rem=(ContSz)%buffContsize;\ |
|
93 | rem=(ContSz)%buffContsize;\ | |
94 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
94 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
95 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
95 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
96 | {\ |
|
96 | {\ | |
97 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
97 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
98 | }\ |
|
98 | }\ | |
99 | }\ |
|
99 | }\ | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
102 | #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ | |
103 | for(int l=0;l<1;l++)\ |
|
103 | for(int l=0;l<1;l++)\ | |
104 | {\ |
|
104 | {\ | |
105 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
105 | ili9328setFrame(LCD,X,Y,1,H);\ | |
106 | int rem=(ContSz)%buffContsize;\ |
|
106 | int rem=(ContSz)%buffContsize;\ | |
107 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
107 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
108 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
108 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
109 | {\ |
|
109 | {\ | |
110 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
110 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
111 | }\ |
|
111 | }\ | |
112 | if(ContSz<H) \ |
|
112 | if(ContSz<H) \ | |
113 | {\ |
|
113 | {\ | |
114 | rem=(H-ContSz)%buffIntsize;\ |
|
114 | rem=(H-ContSz)%buffIntsize;\ | |
115 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
115 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
116 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
116 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ | |
117 | {\ |
|
117 | {\ | |
118 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
118 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
119 | }\ |
|
119 | }\ | |
120 | }\ |
|
120 | }\ | |
121 | }\ |
|
121 | }\ | |
122 |
|
122 | |||
123 |
|
123 | |||
124 | #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
124 | #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ | |
125 | for(int l=0;l<1;l++)\ |
|
125 | for(int l=0;l<1;l++)\ | |
126 | {\ |
|
126 | {\ | |
127 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
127 | ili9328setFrame(LCD,X,Y,1,H);\ | |
128 | int rem;\ |
|
128 | int rem;\ | |
129 | if(ContSz<H) \ |
|
129 | if(ContSz<H) \ | |
130 | {\ |
|
130 | {\ | |
131 | rem=(H-ContSz)%buffIntsize;\ |
|
131 | rem=(H-ContSz)%buffIntsize;\ | |
132 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
132 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
133 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
133 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ | |
134 | {\ |
|
134 | {\ | |
135 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
135 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
136 | }\ |
|
136 | }\ | |
137 | }\ |
|
137 | }\ | |
138 | rem=(ContSz)%buffContsize;\ |
|
138 | rem=(ContSz)%buffContsize;\ | |
139 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
139 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
140 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
140 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
141 | {\ |
|
141 | {\ | |
142 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
142 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
143 | }\ |
|
143 | }\ | |
144 | }\ |
|
144 | }\ | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) |
|
147 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) | |
148 | { |
|
148 | { | |
149 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); |
|
149 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); | |
150 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); |
|
150 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void ili9328refreshenable(struct LCD_t* LCD,int enable) |
|
153 | void ili9328refreshenable(struct LCD_t* LCD,int enable) | |
154 | { |
|
154 | { | |
155 | if(enable) |
|
155 | if(enable) | |
156 | { |
|
156 | { | |
157 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018); |
|
157 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018); | |
158 | } |
|
158 | } | |
159 | else |
|
159 | else | |
160 | { |
|
160 | { | |
161 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008); |
|
161 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008); | |
162 |
|
162 | |||
163 | } |
|
163 | } | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H) |
|
166 | void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H) | |
167 | { |
|
167 | { | |
168 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X); |
|
168 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X); | |
169 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y); |
|
169 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y); | |
170 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X); |
|
170 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X); | |
171 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1)); |
|
171 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1)); | |
172 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y); |
|
172 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y); | |
173 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1)); |
|
173 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1)); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) |
|
176 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) | |
177 | { |
|
177 | { | |
178 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height))) |
|
178 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height))) | |
179 | { |
|
179 | { | |
180 | ili9328setFrame(LCD,Xpos,Ypos,Width,Height); |
|
180 | ili9328setFrame(LCD,Xpos,Ypos,Width,Height); | |
181 | LCD->interface->writeGRAM(buffer,Width*Height); |
|
181 | LCD->interface->writeGRAM(buffer,Width*Height); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
185 | void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) | |
186 | { |
|
186 | { | |
187 | //Based on the mid point circle algorithm from Wikipedia |
|
187 | //Based on the mid point circle algorithm from Wikipedia | |
188 | //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm |
|
188 | //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm | |
189 | uint16_t innerbuffer[16]; |
|
189 | uint16_t innerbuffer[16]; | |
190 | uint16_t outterbuffer[16]; |
|
190 | uint16_t outterbuffer[16]; | |
191 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
191 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; | |
192 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
192 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; | |
193 | if(contSz<r) |
|
193 | if(contSz<r) | |
194 | { |
|
194 | { | |
195 | int error = -r,error_int = -r+contSz; |
|
195 | int error = -r,error_int = -r+contSz; | |
196 | int x = r,x_int=r-contSz; |
|
196 | int x = r,x_int=r-contSz; | |
197 | int y = 0,y_int=0; |
|
197 | int y = 0,y_int=0; | |
198 | while (x >= y) |
|
198 | while (x >= y) | |
199 | { |
|
199 | { | |
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 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
201 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); | |
202 | ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
202 | ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); | |
203 | ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
203 | ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); | |
204 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
204 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); | |
205 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
205 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); | |
206 | error += y; |
|
206 | error += y; | |
207 | ++y; |
|
207 | ++y; | |
208 | error += y; |
|
208 | error += y; | |
209 | error_int += y_int; |
|
209 | error_int += y_int; | |
210 | ++y_int; |
|
210 | ++y_int; | |
211 | error_int += y_int; |
|
211 | error_int += y_int; | |
212 | if(error >= 0) |
|
212 | if(error >= 0) | |
213 | { |
|
213 | { | |
214 | error -= x; |
|
214 | error -= x; | |
215 | --x; |
|
215 | --x; | |
216 | error -= x; |
|
216 | error -= x; | |
217 | } |
|
217 | } | |
218 | if(error_int >= 0) |
|
218 | if(error_int >= 0) | |
219 | { |
|
219 | { | |
220 | error_int -= x_int; |
|
220 | error_int -= x_int; | |
221 | --x_int; |
|
221 | --x_int; | |
222 | error_int -= x_int; |
|
222 | error_int -= x_int; | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 |
|
226 | |||
227 |
|
227 | |||
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | void ili9328paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
232 | void ili9328paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) | |
233 | { |
|
233 | { | |
234 | if(contSz<r) |
|
234 | if(contSz<r) | |
235 | { |
|
235 | { | |
236 | uint16_t innerbuffer[16]; |
|
236 | uint16_t innerbuffer[16]; | |
237 | uint16_t outterbuffer[16]; |
|
237 | uint16_t outterbuffer[16]; | |
238 | int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem; |
|
238 | int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem; | |
239 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
239 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; | |
240 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
240 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; | |
241 | /* Y = b +/- sqrt[r^2 - (x - a)^2] */ |
|
241 | /* Y = b +/- sqrt[r^2 - (x - a)^2] */ | |
242 | for(int32_t line=-r;line<r;line++) |
|
242 | for(int32_t line=-r;line<r;line++) | |
243 | { |
|
243 | { | |
244 | #ifdef __OPTIMIZED_MATH |
|
244 | #ifdef __OPTIMIZED_MATH | |
245 | Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) ); |
|
245 | Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) ); | |
246 | Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) ); |
|
246 | Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) ); | |
247 | #else |
|
247 | #else | |
248 | Val1 = sqrt( (double)(rr - ((line)*(line))) ); |
|
248 | Val1 = sqrt( (double)(rr - ((line)*(line))) ); | |
249 | Val2 = sqrt( (double)(rr2 - ((line)*(line))) ); |
|
249 | Val2 = sqrt( (double)(rr2 - ((line)*(line))) ); | |
250 | #endif |
|
250 | #endif | |
251 | X1=Xpos - Val1; |
|
251 | X1=Xpos - Val1; | |
252 | contSz2= Val1-Val2; |
|
252 | contSz2= Val1-Val2; | |
253 | ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1); |
|
253 | ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1); | |
254 | rem=(contSz2)%16; |
|
254 | rem=(contSz2)%16; | |
255 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
255 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); | |
256 | for(int i=rem;i<(contSz2);i+=16) |
|
256 | for(int i=rem;i<(contSz2);i+=16) | |
257 | { |
|
257 | { | |
258 | LCD->interface->writeGRAM(outterbuffer,16); |
|
258 | LCD->interface->writeGRAM(outterbuffer,16); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | W=2*Val1; |
|
261 | W=2*Val1; | |
262 | if(W>(2*contSz2)) |
|
262 | if(W>(2*contSz2)) | |
263 | { |
|
263 | { | |
264 | W-=2*contSz2; |
|
264 | W-=2*contSz2; | |
265 | rem=(W)%16; |
|
265 | rem=(W)%16; | |
266 | if(rem)LCD->interface->writeGRAM(innerbuffer,rem); |
|
266 | if(rem)LCD->interface->writeGRAM(innerbuffer,rem); | |
267 | for(int i=rem;i<(W);i+=16) |
|
267 | for(int i=rem;i<(W);i+=16) | |
268 | { |
|
268 | { | |
269 | LCD->interface->writeGRAM(innerbuffer,16); |
|
269 | LCD->interface->writeGRAM(innerbuffer,16); | |
270 | } |
|
270 | } | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | rem=(contSz2)%16; |
|
273 | rem=(contSz2)%16; | |
274 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
274 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); | |
275 | for(int i=rem;i<(contSz2);i+=16) |
|
275 | for(int i=rem;i<(contSz2);i+=16) | |
276 | { |
|
276 | { | |
277 | LCD->interface->writeGRAM(outterbuffer,16); |
|
277 | LCD->interface->writeGRAM(outterbuffer,16); | |
278 | } |
|
278 | } | |
279 | } |
|
279 | } | |
280 | } |
|
280 | } | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 |
|
283 | |||
284 |
|
284 | |||
285 |
|
285 | |||
286 | void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
286 | void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor) | |
287 | { |
|
287 | { | |
288 | ili9328setFrame(LCD,Xpos,Ypos,w,h); |
|
288 | ili9328setFrame(LCD,Xpos,Ypos,w,h); | |
289 | uint16_t tmp[32]; |
|
289 | uint16_t tmp[32]; | |
290 | for(int i=0;i<32;i++)tmp[i]=fillColor; |
|
290 | for(int i=0;i<32;i++)tmp[i]=fillColor; | |
291 | for(int i=0;i<(h*w);i+=32) |
|
291 | for(int i=0;i<(h*w);i+=32) | |
292 | { |
|
292 | { | |
293 | LCD->interface->writeGRAM(tmp,32); |
|
293 | LCD->interface->writeGRAM(tmp,32); | |
294 | } |
|
294 | } | |
295 | int rem=(w*h)%32; |
|
295 | int rem=(w*h)%32; | |
296 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
296 | if(rem)LCD->interface->writeGRAM(tmp,rem); | |
297 | if(contSz) |
|
297 | if(contSz) | |
298 | { |
|
298 | { | |
299 | ili9328setFrame(LCD,Xpos,Ypos,w,contSz); |
|
299 | ili9328setFrame(LCD,Xpos,Ypos,w,contSz); | |
300 | for(int i=0;i<32;i++)tmp[i]=contColor; |
|
300 | for(int i=0;i<32;i++)tmp[i]=contColor; | |
301 | rem=(w*contSz)%32; |
|
301 | rem=(w*contSz)%32; | |
302 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
302 | if(rem)LCD->interface->writeGRAM(tmp,rem); | |
303 | for(int i=rem;i<(w*contSz);i+=32) |
|
303 | for(int i=rem;i<(w*contSz);i+=32) | |
304 | { |
|
304 | { | |
305 | LCD->interface->writeGRAM(tmp,32); |
|
305 | LCD->interface->writeGRAM(tmp,32); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz); |
|
308 | ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz); | |
309 | rem=(w*contSz)%32; |
|
309 | rem=(w*contSz)%32; | |
310 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
310 | if(rem)LCD->interface->writeGRAM(tmp,rem); | |
311 | for(int i=rem;i<(w*contSz);i+=32) |
|
311 | for(int i=rem;i<(w*contSz);i+=32) | |
312 | { |
|
312 | { | |
313 | LCD->interface->writeGRAM(tmp,32); |
|
313 | LCD->interface->writeGRAM(tmp,32); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | ili9328setFrame(LCD,Xpos,Ypos,contSz,h); |
|
316 | ili9328setFrame(LCD,Xpos,Ypos,contSz,h); | |
317 | rem=(h*contSz)%32; |
|
317 | rem=(h*contSz)%32; | |
318 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
318 | if(rem)LCD->interface->writeGRAM(tmp,rem); | |
319 | for(int i=rem;i<(h*contSz);i+=32) |
|
319 | for(int i=rem;i<(h*contSz);i+=32) | |
320 | { |
|
320 | { | |
321 | LCD->interface->writeGRAM(tmp,32); |
|
321 | LCD->interface->writeGRAM(tmp,32); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h); |
|
324 | ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h); | |
325 | rem=(h*contSz)%32; |
|
325 | rem=(h*contSz)%32; | |
326 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
326 | if(rem)LCD->interface->writeGRAM(tmp,rem); | |
327 | for(int i=rem;i<(h*contSz);i+=32) |
|
327 | for(int i=rem;i<(h*contSz);i+=32) | |
328 | { |
|
328 | { | |
329 | LCD->interface->writeGRAM(tmp,32); |
|
329 | LCD->interface->writeGRAM(tmp,32); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color) |
|
334 | void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color) | |
335 | { |
|
335 | { | |
336 | int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0; |
|
336 | int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0; | |
337 | uint16_t tmp[w]; |
|
337 | uint16_t tmp[w]; | |
338 | uint16_t linenum=0,charnum=0; |
|
338 | uint16_t linenum=0,charnum=0; | |
339 | uint8_t line=0; |
|
339 | uint8_t line=0; | |
340 | while(*buffer) |
|
340 | while(*buffer!='\0') | |
341 | { |
|
341 | { | |
342 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1); |
|
342 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1); | |
343 | LCD->interface->readGRAM(tmp,w); |
|
343 | LCD->interface->readGRAM(tmp,w); | |
344 | for(int i=0;i<(h*w);i++) |
|
344 | for(int i=0;i<(h*w);i++) | |
345 | { |
|
345 | { | |
346 | if( ((i%w)==0) ) //read current line to apply text pixmap |
|
346 | if( ((i%w)==0) ) //read current line to apply text pixmap | |
347 | { |
|
347 | { | |
348 | if(linenum++>0) |
|
348 | if(linenum++>0) | |
349 | { |
|
349 | { | |
350 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1); |
|
350 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1); | |
351 | LCD->interface->writeGRAM(tmp,w); |
|
351 | LCD->interface->writeGRAM(tmp,w); | |
352 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); |
|
352 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); | |
353 | LCD->interface->readGRAM(tmp,w); |
|
353 | LCD->interface->readGRAM(tmp,w); | |
354 | pix=0; |
|
354 | pix=0; | |
355 | } |
|
355 | } | |
356 | } |
|
356 | } | |
357 | if((pix%8) == 0) |
|
357 | if((pix%8) == 0) | |
358 | { |
|
358 | { | |
359 | line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++]; |
|
359 | line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++]; | |
360 | } |
|
360 | } | |
361 | if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; |
|
361 | if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; | |
362 | pix++; |
|
362 | pix++; | |
363 | line>>=1; |
|
363 | line>>=1; | |
364 | } |
|
364 | } | |
365 | linenum=0; |
|
365 | linenum=0; | |
366 | tableoffset=0; |
|
366 | tableoffset=0; | |
367 | charnum++; |
|
367 | charnum++; | |
368 | buffer++; |
|
368 | buffer++; | |
369 | } |
|
369 | } | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | int ili9328init(struct LCD_t* LCD) |
|
372 | int ili9328init(struct LCD_t* LCD) | |
373 | { |
|
373 | { | |
374 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) |
|
374 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) | |
375 | { |
|
375 | { | |
376 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) |
|
376 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) | |
377 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) |
|
377 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) | |
378 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) |
|
378 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) | |
379 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0202); |
|
379 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0202); | |
380 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); |
|
380 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); | |
381 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On |
|
381 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On | |
382 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) |
|
382 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) | |
383 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
383 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) | |
384 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) |
|
384 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) | |
385 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) |
|
385 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) | |
386 | delay_100us(10); |
|
386 | delay_100us(10); | |
387 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) |
|
387 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) | |
388 | delay_100us(10); |
|
388 | delay_100us(10); | |
389 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
389 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) | |
390 | delay_100us(10); |
|
390 | delay_100us(10); | |
391 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) |
|
391 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) | |
392 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) |
|
392 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) | |
393 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) |
|
393 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) | |
394 | delay_100us(500); |
|
394 | delay_100us(500); | |
395 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 |
|
395 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 | |
396 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 |
|
396 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 | |
397 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 |
|
397 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 | |
398 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 |
|
398 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 | |
399 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 |
|
399 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 | |
400 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 |
|
400 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 | |
401 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 |
|
401 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 | |
402 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 |
|
402 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 | |
403 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 |
|
403 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 | |
404 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 |
|
404 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 | |
405 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) |
|
405 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) | |
406 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h) |
|
406 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h) | |
407 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) |
|
407 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) | |
408 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h) |
|
408 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h) | |
409 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) |
|
409 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) | |
410 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE |
|
410 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE | |
411 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) |
|
411 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) | |
412 | // Display On |
|
412 | // Display On | |
413 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) |
|
413 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) | |
414 | delay_100us(500); |
|
414 | delay_100us(500); | |
415 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x0038); |
|
415 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x0038); | |
416 | } |
|
416 | } | |
417 | return 0; |
|
417 | return 0; | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 |
|
420 |
@@ -1,10 +1,11 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += CONTROLERS \ |
|
2 | SUBDIRS += CONTROLERS \ | |
|
3 | TC_CONTROLERS \ | |||
3 | GUI |
|
4 | GUI | |
4 |
|
5 | |||
5 |
|
6 | |||
6 |
|
7 | |||
7 |
|
8 | |||
8 |
|
9 | |||
9 |
|
10 | |||
10 |
|
11 |
@@ -1,14 +1,21 | |||||
1 | TEMPLATE = lib |
|
1 | TEMPLATE = lib | |
2 | OBJECTS_DIR = obj |
|
2 | OBJECTS_DIR = obj | |
3 |
|
3 | |||
4 | SOURCES += thread.c |
|
4 | SOURCES += thread.c | |
5 |
|
5 | |||
6 | INCLUDEPATH += ../../includes \ |
|
6 | INCLUDEPATH += ../../includes \ | |
7 | ../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
7 | ../CPU/STM32F4xx_StdPeriph_Driver/inc \ | |
8 | ../CPU/CMSIS/Include |
|
8 | ../CPU/CMSIS/Include | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | UCMODEL=stm32f4 |
|
11 | UCMODEL=stm32f4 | |
12 |
|
12 | |||
13 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
13 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL | |
14 | INSTALLS += target |
|
14 | INSTALLS += target | |
|
15 | ||||
|
16 | HEADERS += \ | |||
|
17 | ../../includes/thread.h | |||
|
18 | ||||
|
19 | ||||
|
20 | ||||
|
21 |
@@ -1,56 +1,56 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2011, Alexis Jeandet |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef B24LC0X_H |
|
22 | #ifndef B24LC0X_H | |
23 | #define B24LC0X_H |
|
23 | #define B24LC0X_H | |
24 |
|
24 | |||
25 | #include <i2c.h> |
|
25 | #include <i2c.h> | |
26 | #include <uhandle.h> |
|
26 | #include <uhandle.h> | |
27 |
|
27 | |||
28 | typedef struct eeprom24lc0xDev |
|
28 | typedef struct eeprom24lc0xDev | |
29 | { |
|
29 | { | |
30 | i2c_t iicdev; |
|
30 | i2c_t iicdev; | |
31 | unsigned char devAddress; |
|
31 | unsigned char devAddress; | |
32 | unsigned char size; |
|
32 | unsigned char size; | |
33 | }eeprom24lc0xDev; |
|
33 | }eeprom24lc0xDev; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 |
|
36 | |||
37 | extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2c_t iicdev,unsigned char A0_A1_A2_val,unsigned int size); |
|
37 | extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2c_t iicdev,unsigned char A0_A1_A2_val,unsigned int size); | |
38 |
|
38 | |||
39 | extern void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); |
|
39 | extern void eeprom24lc0xpagewrite(eeprom24lc0xDev* dev,unsigned char address,unsigned char* page); | |
40 | extern void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); |
|
40 | extern void eeprom24lc0xpageread(eeprom24lc0xDev* dev,unsigned char address,unsigned char* page); | |
41 | extern void eeprom24lc0xbytewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char data); |
|
41 | extern void eeprom24lc0xbytewrite(eeprom24lc0xDev* dev,unsigned char address,unsigned char data); | |
42 | extern unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev dev,unsigned char address); |
|
42 | extern unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev* dev,unsigned char address); | |
43 | extern void eeprom24lc0xreadn(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count); |
|
43 | extern void eeprom24lc0xreadn(eeprom24lc0xDev* dev,unsigned char address,unsigned char* data, unsigned int count); | |
44 | extern void eeprom24lc0xwriten(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count); |
|
44 | extern void eeprom24lc0xwriten(eeprom24lc0xDev* dev,unsigned char address,unsigned char* data, unsigned int count); | |
45 |
|
45 | |||
46 |
|
46 | |||
47 |
|
47 | |||
48 |
|
48 | |||
49 | #endif |
|
49 | #endif | |
50 |
|
50 | |||
51 |
|
51 | |||
52 |
|
52 | |||
53 |
|
53 | |||
54 |
|
54 | |||
55 |
|
55 | |||
56 |
|
56 |
@@ -1,62 +1,71 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2013, Alexis Jeandet |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef THREAD_H |
|
22 | #ifndef THREAD_H | |
23 | #define THREAD_H |
|
23 | #define THREAD_H | |
24 | #include <stdint.h> |
|
24 | #include <stdint.h> | |
25 | #include <uhandle.h> |
|
25 | #include <uhandle.h> | |
26 | #include <streamdevices.h> |
|
26 | #include <streamdevices.h> | |
27 |
|
27 | |||
28 | #ifdef __cplusplus |
|
28 | #ifdef __cplusplus | |
29 | extern "C" { |
|
29 | extern "C" { | |
30 | #endif |
|
30 | #endif | |
31 |
|
31 | |||
|
32 | /* | |||
|
33 | This structure holds the thread context. To do so, you need to keep a track of the programm counter, | |||
|
34 | to change the stack pointer for each thread and to save all registers needing to be saved. Since the | |||
|
35 | number of regiter to be saved vary from one processor to an other, it's easier to save them in the | |||
|
36 | owner thread stack; | |||
|
37 | */ | |||
32 | typedef struct thread_t |
|
38 | typedef struct thread_t | |
33 | { |
|
39 | { | |
34 | int (*func)(void*); |
|
40 | int (*func)(void*); | |
35 | void* __stack__; |
|
41 | void* __stack__; | |
36 | int __stackSize__; |
|
42 | void* __programmCounter__; | |
37 |
|
|
43 | void* __registers__; | |
38 | int __programcounter__; |
|
|||
39 | }thread_t; |
|
44 | }thread_t; | |
40 |
|
45 | |||
41 |
|
46 | |||
42 | int threadcreate(thread_t* thread,void* stack,int stackSize); |
|
47 | extern int threadcreate(thread_t* thread,void* stack,int stackSize); | |
43 | int threadstart(thread_t* thread); |
|
48 | extern int threadstart(thread_t* thread); | |
44 | int threadstop(thread_t* thread); |
|
49 | extern int threadstop(thread_t* thread); | |
45 |
|
50 | |||
|
51 | #ifdef __THREAD_PRIVATE__ | |||
|
52 | extern void __cpusavecontext(void* dataspace); | |||
|
53 | extern void __cpurestorecontext(void* dataspace); | |||
|
54 | #endif | |||
46 |
|
55 | |||
47 | #ifdef __cplusplus |
|
56 | #ifdef __cplusplus | |
48 | } |
|
57 | } | |
49 | #endif |
|
58 | #endif | |
50 | #endif //THREAD_H |
|
59 | #endif //THREAD_H | |
51 |
|
60 | |||
52 |
|
61 | |||
53 |
|
62 | |||
54 |
|
63 | |||
55 |
|
64 | |||
56 |
|
65 | |||
57 |
|
66 | |||
58 |
|
67 | |||
59 |
|
68 | |||
60 |
|
69 | |||
61 |
|
70 | |||
62 |
|
71 |
@@ -1,15 +1,16 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | CONFIG += ordered |
|
2 | CONFIG += ordered | |
3 |
|
3 | |||
4 | SUBDIRS += stm32f4 |
|
4 | SUBDIRS += stm32f4 | |
5 |
|
5 | |||
6 | SUBDIRS += common |
|
6 | SUBDIRS += common | |
7 |
|
7 | |||
8 | headers.files = includes/*.h \ |
|
8 | headers.files = includes/*.h \ | |
9 | includes/GRAPHIC/CONTROLERS/*.h \ |
|
9 | includes/GRAPHIC/CONTROLERS/*.h \ | |
|
10 | includes/GRAPHIC/TC_CONTROLERS/*.h \ | |||
10 | includes/GRAPHIC/GUI/FONTS/*.h \ |
|
11 | includes/GRAPHIC/GUI/FONTS/*.h \ | |
11 | includes/GRAPHIC/GUI/Widgets/*.h |
|
12 | includes/GRAPHIC/GUI/Widgets/*.h | |
12 |
|
13 | |||
13 | headers.path = $$[QT_INSTALL_HEADERS] |
|
14 | headers.path = $$[QT_INSTALL_HEADERS] | |
14 | INSTALLS += headers |
|
15 | INSTALLS += headers | |
15 |
|
16 |
@@ -1,15 +1,16 | |||||
1 | TEMPLATE = lib |
|
1 | TEMPLATE = lib | |
2 | OBJECTS_DIR = obj |
|
2 | OBJECTS_DIR = obj | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | core.c |
|
5 | core.c \ | |
|
6 | threads.c | |||
6 |
|
7 | |||
7 | INCLUDEPATH += ../../includes \ |
|
8 | INCLUDEPATH += ../../includes \ | |
8 | ../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
9 | ../CPU/STM32F4xx_StdPeriph_Driver/inc \ | |
9 | ../CPU/CMSIS/Include |
|
10 | ../CPU/CMSIS/Include | |
10 |
|
11 | |||
11 |
|
12 | |||
12 | UCMODEL=stm32f4 |
|
13 | UCMODEL=stm32f4 | |
13 |
|
14 | |||
14 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
15 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL | |
15 | INSTALLS += target |
|
16 | INSTALLS += target |
@@ -1,388 +1,386 | |||||
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 |
|
22 | |||
23 | #include <i2c.h> |
|
23 | #include <i2c.h> | |
24 | #include <stm32f4xx_usart.h> |
|
24 | #include <stm32f4xx_usart.h> | |
25 | #include <stm32f4xx_rcc.h> |
|
25 | #include <stm32f4xx_rcc.h> | |
26 | #include <stm32f4xx_gpio.h> |
|
26 | #include <stm32f4xx_gpio.h> | |
27 | #include <gpio.h> |
|
27 | #include <gpio.h> | |
28 | #include <core.h> |
|
28 | #include <core.h> | |
29 |
|
29 | |||
30 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
30 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
31 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
31 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
32 |
|
32 | |||
33 | int i2ctimeout=1000*1000; |
|
33 | int i2ctimeout=1000*1000; | |
34 |
|
34 | |||
35 | I2C_TypeDef* _i2c_dev_table[3]={I2C1,I2C2,I2C3}; |
|
35 | I2C_TypeDef* _i2c_dev_table[3]={I2C1,I2C2,I2C3}; | |
36 |
|
36 | |||
37 | i2c_t i2copen(int count) |
|
37 | i2c_t i2copen(int count) | |
38 | { |
|
38 | { | |
39 | #define _INIT_DEV(_RCC_) \ |
|
39 | #define _INIT_DEV(_RCC_) \ | |
40 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); \ |
|
40 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); \ | |
41 | RCC_APB1PeriphResetCmd(_RCC_, ENABLE); \ |
|
41 | RCC_APB1PeriphResetCmd(_RCC_, ENABLE); \ | |
42 | RCC_APB1PeriphResetCmd(_RCC_, DISABLE); |
|
42 | RCC_APB1PeriphResetCmd(_RCC_, DISABLE); | |
43 |
|
43 | |||
44 | switch(count) |
|
44 | switch(count) | |
45 | { |
|
45 | { | |
46 | case i2c1: |
|
46 | case i2c1: | |
47 | _INIT_DEV(RCC_APB1Periph_I2C1); |
|
47 | _INIT_DEV(RCC_APB1Periph_I2C1); | |
48 | return i2c1; |
|
48 | return i2c1; | |
49 | break; |
|
49 | break; | |
50 | case i2c2: |
|
50 | case i2c2: | |
51 | _INIT_DEV(RCC_APB1Periph_I2C2); |
|
51 | _INIT_DEV(RCC_APB1Periph_I2C2); | |
52 | return i2c2; |
|
52 | return i2c2; | |
53 | break; |
|
53 | break; | |
54 | case i2c3: |
|
54 | case i2c3: | |
55 | _INIT_DEV(RCC_APB1Periph_I2C3); |
|
55 | _INIT_DEV(RCC_APB1Periph_I2C3); | |
56 | return i2c3; |
|
56 | return i2c3; | |
57 | break; |
|
57 | break; | |
58 | default: |
|
58 | default: | |
59 | break; |
|
59 | break; | |
60 | } |
|
60 | } | |
61 | return -1; |
|
61 | return -1; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | i2c_t i2copenandconfig(int count,uint32_t cfg,uint32_t speed,uint32_t SDA,uint32_t SCL) |
|
64 | i2c_t i2copenandconfig(int count,uint32_t cfg,uint32_t speed,uint32_t SDA,uint32_t SCL) | |
65 | { |
|
65 | { | |
66 | i2c_t dev = i2copen(count); |
|
66 | i2c_t dev = i2copen(count); | |
67 | if(dev!=-1) |
|
67 | if(dev!=-1) | |
68 | { |
|
68 | { | |
69 | i2cclose(dev); |
|
69 | i2cclose(dev); | |
70 | i2csetpins(dev,SDA,SCL); |
|
70 | i2csetpins(dev,SDA,SCL); | |
71 | i2copen(count); |
|
71 | i2copen(count); | |
72 | //i2cenable(count); |
|
|||
73 | //I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
|||
74 | i2csetspeed(dev,speed); |
|
72 | i2csetspeed(dev,speed); | |
75 | i2cenable(count); |
|
73 | i2cenable(count); | |
76 | } |
|
74 | } | |
77 | return dev; |
|
75 | return dev; | |
78 | } |
|
76 | } | |
79 |
|
77 | |||
80 | int i2cclose(i2c_t dev) |
|
78 | int i2cclose(i2c_t dev) | |
81 | { |
|
79 | { | |
82 | switch(dev) |
|
80 | switch(dev) | |
83 | { |
|
81 | { | |
84 | case i2c1: |
|
82 | case i2c1: | |
85 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE); |
|
83 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE); | |
86 | break; |
|
84 | break; | |
87 | case i2c2: |
|
85 | case i2c2: | |
88 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE); |
|
86 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE); | |
89 | break; |
|
87 | break; | |
90 | case i2c3: |
|
88 | case i2c3: | |
91 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C3, ENABLE); |
|
89 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C3, ENABLE); | |
92 | break; |
|
90 | break; | |
93 | default: |
|
91 | default: | |
94 | break; |
|
92 | break; | |
95 | } |
|
93 | } | |
96 | return 1; |
|
94 | return 1; | |
97 | } |
|
95 | } | |
98 |
|
96 | |||
99 | int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL) |
|
97 | int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL) | |
100 | { |
|
98 | { | |
101 | if((dev<i2c4)&&(dev>=i2c1)) |
|
99 | if((dev<i2c4)&&(dev>=i2c1)) | |
102 | { |
|
100 | { | |
103 | gpio_t SDApin,SCLpin; |
|
101 | gpio_t SDApin,SCLpin; | |
104 | SDApin = gpioopen(SDA); |
|
102 | SDApin = gpioopen(SDA); | |
105 | SCLpin = gpioopen(SCL); |
|
103 | SCLpin = gpioopen(SCL); | |
106 | SDApin |= gpiolowspeed | gpioaf | gpioopendraintype | gpionopulltype; |
|
104 | SDApin |= gpiolowspeed | gpioaf | gpioopendraintype | gpionopulltype; | |
107 | SCLpin |= gpiolowspeed | gpiooutdir | gpioopendraintype | gpionopulltype; |
|
105 | SCLpin |= gpiolowspeed | gpiooutdir | gpioopendraintype | gpionopulltype; | |
108 | gpiosetconfig(&SCLpin); |
|
106 | gpiosetconfig(&SCLpin); | |
109 | for(int i=0;i<32;i++) |
|
107 | for(int i=0;i<32;i++) | |
110 | { |
|
108 | { | |
111 | gpioclr(SCLpin); |
|
109 | gpioclr(SCLpin); | |
112 | for(int l=0;l<200;l++) |
|
110 | for(int l=0;l<200;l++) | |
113 | {__asm__("nop");} |
|
111 | {__asm__("nop");} | |
114 | gpioset(SCLpin); |
|
112 | gpioset(SCLpin); | |
115 | for(int l=0;l<200;l++) |
|
113 | for(int l=0;l<200;l++) | |
116 | {__asm__("nop");} |
|
114 | {__asm__("nop");} | |
117 | } |
|
115 | } | |
118 | SCLpin = gpioopen(SCL); |
|
116 | SCLpin = gpioopen(SCL); | |
119 | SCLpin |= gpiolowspeed | gpioaf | gpioopendraintype | gpionopulltype; |
|
117 | SCLpin |= gpiolowspeed | gpioaf | gpioopendraintype | gpionopulltype; | |
120 | gpiosetconfig(&SDApin); |
|
118 | gpiosetconfig(&SDApin); | |
121 | gpiosetconfig(&SCLpin); |
|
119 | gpiosetconfig(&SCLpin); | |
122 | uint8_t gpioAFi2cx = GPIO_AF_I2C1; |
|
120 | uint8_t gpioAFi2cx = GPIO_AF_I2C1; | |
123 | switch(dev) |
|
121 | switch(dev) | |
124 | { |
|
122 | { | |
125 | case i2c1: |
|
123 | case i2c1: | |
126 | gpioAFi2cx = GPIO_AF_I2C1; |
|
124 | gpioAFi2cx = GPIO_AF_I2C1; | |
127 | break; |
|
125 | break; | |
128 | case i2c2: |
|
126 | case i2c2: | |
129 | gpioAFi2cx = GPIO_AF_I2C2; |
|
127 | gpioAFi2cx = GPIO_AF_I2C2; | |
130 | break; |
|
128 | break; | |
131 | case i2c3: |
|
129 | case i2c3: | |
132 | gpioAFi2cx = GPIO_AF_I2C3; |
|
130 | gpioAFi2cx = GPIO_AF_I2C3; | |
133 | break; |
|
131 | break; | |
134 | default: |
|
132 | default: | |
135 | break; |
|
133 | break; | |
136 | } |
|
134 | } | |
137 | GPIO_PinAFConfig(GPIOGETPORT(SDApin), (uint8_t)(SDApin & 0xF), gpioAFi2cx); |
|
135 | GPIO_PinAFConfig(GPIOGETPORT(SDApin), (uint8_t)(SDApin & 0xF), gpioAFi2cx); | |
138 | GPIO_PinAFConfig(GPIOGETPORT(SCLpin), (uint8_t)(SCLpin & 0xF), gpioAFi2cx); |
|
136 | GPIO_PinAFConfig(GPIOGETPORT(SCLpin), (uint8_t)(SCLpin & 0xF), gpioAFi2cx); | |
139 | return 0; |
|
137 | return 0; | |
140 | } |
|
138 | } | |
141 | return -1; |
|
139 | return -1; | |
142 | } |
|
140 | } | |
143 |
|
141 | |||
144 | int i2cenable(i2c_t dev) |
|
142 | int i2cenable(i2c_t dev) | |
145 | { |
|
143 | { | |
146 | if((dev<i2c4)&&(dev>=i2c1)) |
|
144 | if((dev<i2c4)&&(dev>=i2c1)) | |
147 | { |
|
145 | { | |
148 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
146 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
149 | _dev_->CR1 |=1 ; |
|
147 | _dev_->CR1 |=1 ; | |
150 | return 0; |
|
148 | return 0; | |
151 | } |
|
149 | } | |
152 | return -1; |
|
150 | return -1; | |
153 | } |
|
151 | } | |
154 |
|
152 | |||
155 | int i2cdisable(i2c_t dev) |
|
153 | int i2cdisable(i2c_t dev) | |
156 | { |
|
154 | { | |
157 | if((dev<i2c4)&&(dev>=i2c1)) |
|
155 | if((dev<i2c4)&&(dev>=i2c1)) | |
158 | { |
|
156 | { | |
159 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
157 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
160 | _dev_->CR1 &= ~1; |
|
158 | _dev_->CR1 &= ~1; | |
161 | return 0; |
|
159 | return 0; | |
162 | } |
|
160 | } | |
163 | return -1; |
|
161 | return -1; | |
164 | } |
|
162 | } | |
165 |
|
163 | |||
166 |
|
164 | |||
167 | int i2csetspeed(i2c_t dev,uint32_t speed) |
|
165 | int i2csetspeed(i2c_t dev,uint32_t speed) | |
168 | { |
|
166 | { | |
169 | if((dev<i2c4)&&(dev>=i2c1)) |
|
167 | if((dev<i2c4)&&(dev>=i2c1)) | |
170 | { |
|
168 | { | |
171 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
169 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
172 | int32_t APB1Freq=getAPB1Freq()/1000000; |
|
170 | int32_t APB1Freq=getAPB1Freq()/1000000; | |
173 | if((APB1Freq>1)&&(APB1Freq<43)) |
|
171 | if((APB1Freq>1)&&(APB1Freq<43)) | |
174 | { |
|
172 | { | |
175 |
|
173 | |||
176 | uint16_t tmpreg=_dev_->CR2; |
|
174 | uint16_t tmpreg=_dev_->CR2; | |
177 | tmpreg &= ~(0x1f); |
|
175 | tmpreg &= ~(0x1f); | |
178 | tmpreg |= APB1Freq; |
|
176 | tmpreg |= APB1Freq; | |
179 | _dev_->CR2=tmpreg; |
|
177 | _dev_->CR2=tmpreg; | |
180 | i2cdisable(dev); |
|
178 | i2cdisable(dev); | |
181 | tmpreg=_dev_->CCR; |
|
179 | tmpreg=_dev_->CCR; | |
182 | APB1Freq=getAPB1Freq(); |
|
180 | APB1Freq=getAPB1Freq(); | |
183 | if(speed>100000) //100kHz= standard mode, 400kHz= fast mode |
|
181 | if(speed>100000) //100kHz= standard mode, 400kHz= fast mode | |
184 | { |
|
182 | { | |
185 | if(speed<=400000) |
|
183 | if(speed<=400000) | |
186 | { |
|
184 | { | |
187 | tmpreg |= 1<<15; |
|
185 | tmpreg |= 1<<15; | |
188 | tmpreg &= ~(1<<14); |
|
186 | tmpreg &= ~(1<<14); | |
189 | tmpreg &= ~(0xfff); |
|
187 | tmpreg &= ~(0xfff); | |
190 | tmpreg |= 0xfff & (APB1Freq/(3*speed)); |
|
188 | tmpreg |= 0xfff & (APB1Freq/(3*speed)); | |
191 | } |
|
189 | } | |
192 | } |
|
190 | } | |
193 | else |
|
191 | else | |
194 | { |
|
192 | { | |
195 | tmpreg &= ~(1<<15); |
|
193 | tmpreg &= ~(1<<15); | |
196 | tmpreg &= ~(0xfff); |
|
194 | tmpreg &= ~(0xfff); | |
197 | tmpreg |= 0xfff & (APB1Freq/(2*speed)); |
|
195 | tmpreg |= 0xfff & (APB1Freq/(2*speed)); | |
198 | } |
|
196 | } | |
199 | _dev_->CCR=tmpreg; |
|
197 | _dev_->CCR=tmpreg; | |
200 | tmpreg=_dev_->TRISE; |
|
198 | tmpreg=_dev_->TRISE; | |
201 | tmpreg &= ~(0x3f); |
|
199 | tmpreg &= ~(0x3f); | |
202 | tmpreg |= (APB1Freq/1000000)+1; |
|
200 | tmpreg |= (APB1Freq/1000000)+1; | |
203 | _dev_->TRISE = tmpreg; |
|
201 | _dev_->TRISE = tmpreg; | |
204 | i2cenable(dev); |
|
202 | i2cenable(dev); | |
205 | return 0; |
|
203 | return 0; | |
206 | } |
|
204 | } | |
207 | } |
|
205 | } | |
208 | return -1; |
|
206 | return -1; | |
209 | } |
|
207 | } | |
210 |
|
208 | |||
211 | int i2cbusy(i2c_t dev) |
|
209 | int i2cbusy(i2c_t dev) | |
212 | { |
|
210 | { | |
213 | if((dev<i2c4)&&(dev>=i2c1)) |
|
211 | if((dev<i2c4)&&(dev>=i2c1)) | |
214 | { |
|
212 | { | |
215 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
213 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
216 | if((_dev_->SR2 & 2) ==2) return 1; /* Dev is busy */ |
|
214 | if((_dev_->SR2 & 2) ==2) return 1; /* Dev is busy */ | |
217 | return 0; /* Dev isn't busy */ |
|
215 | return 0; /* Dev isn't busy */ | |
218 | } |
|
216 | } | |
219 | return -1; /* Error, dev is out of range */ |
|
217 | return -1; /* Error, dev is out of range */ | |
220 | } |
|
218 | } | |
221 |
|
219 | |||
222 | int i2cwrite(i2c_t dev,char address,char* data,int count) |
|
220 | int i2cwrite(i2c_t dev,char address,char* data,int count) | |
223 | { |
|
221 | { | |
224 | if((dev<i2c4)&&(dev>=i2c1)) |
|
222 | if((dev<i2c4)&&(dev>=i2c1)) | |
225 | { |
|
223 | { | |
226 | int timeout=i2ctimeout; |
|
224 | int timeout=i2ctimeout; | |
227 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
225 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
228 | while(i2cbusy(dev)) |
|
226 | while(i2cbusy(dev)) | |
229 | { |
|
227 | { | |
230 | if(0==(timeout--)) |
|
228 | if(0==(timeout--)) | |
231 | { |
|
229 | { | |
232 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
230 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
233 | return -1; |
|
231 | return -1; | |
234 | } |
|
232 | } | |
235 | } |
|
233 | } | |
236 | _dev_->CR1 |= 1<<8; |
|
234 | _dev_->CR1 |= 1<<8; | |
237 | timeout=i2ctimeout; |
|
235 | timeout=i2ctimeout; | |
238 | while(!i2cStatusCheck(dev,((uint32_t)0x00030001))) |
|
236 | while(!i2cStatusCheck(dev,((uint32_t)0x00030001))) | |
239 | { |
|
237 | { | |
240 | if(0==(timeout--)) |
|
238 | if(0==(timeout--)) | |
241 | { |
|
239 | { | |
242 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
240 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
243 | return -1; |
|
241 | return -1; | |
244 | } |
|
242 | } | |
245 | } |
|
243 | } | |
246 | _dev_->DR= address<<1; |
|
244 | _dev_->DR= address<<1; | |
247 | timeout=i2ctimeout; |
|
245 | timeout=i2ctimeout; | |
248 | while(!i2cStatusCheck(dev, ((uint32_t)0x00070082))) |
|
246 | while(!i2cStatusCheck(dev, ((uint32_t)0x00070082))) | |
249 | { |
|
247 | { | |
250 | if(0==(timeout--)) |
|
248 | if(0==(timeout--)) | |
251 | { |
|
249 | { | |
252 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
250 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
253 | return -1; |
|
251 | return -1; | |
254 | } |
|
252 | } | |
255 | } |
|
253 | } | |
256 | address=_dev_->SR2; |
|
254 | address=_dev_->SR2; | |
257 | for(int i=0;i<count;i++) |
|
255 | for(int i=0;i<count;i++) | |
258 | { |
|
256 | { | |
259 | timeout=i2ctimeout; |
|
257 | timeout=i2ctimeout; | |
260 | while(!i2cStatusCheck(dev,((uint32_t)0x00070080))) |
|
258 | while(!i2cStatusCheck(dev,((uint32_t)0x00070080))) | |
261 | { |
|
259 | { | |
262 | if(0==(timeout--)) |
|
260 | if(0==(timeout--)) | |
263 | { |
|
261 | { | |
264 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
262 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
265 | return -1; |
|
263 | return -1; | |
266 | } |
|
264 | } | |
267 | } |
|
265 | } | |
268 | _dev_->DR= data[i]; |
|
266 | _dev_->DR= data[i]; | |
269 | } |
|
267 | } | |
270 | timeout=i2ctimeout; |
|
268 | timeout=i2ctimeout; | |
271 | while(!i2cStatusCheck(dev,1<<7)) |
|
269 | while(!i2cStatusCheck(dev,1<<7)) | |
272 | { |
|
270 | { | |
273 | if(0==(timeout--)) |
|
271 | if(0==(timeout--)) | |
274 | { |
|
272 | { | |
275 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
273 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
276 | return -1; |
|
274 | return -1; | |
277 | } |
|
275 | } | |
278 | } |
|
276 | } | |
279 | timeout=i2ctimeout; |
|
277 | timeout=i2ctimeout; | |
280 | while(!i2cStatusCheck(dev,1<<2)) |
|
278 | while(!i2cStatusCheck(dev,1<<2)) | |
281 | { |
|
279 | { | |
282 | if(0==(timeout--)) |
|
280 | if(0==(timeout--)) | |
283 | { |
|
281 | { | |
284 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
282 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
285 | return -1; |
|
283 | return -1; | |
286 | } |
|
284 | } | |
287 | } |
|
285 | } | |
288 | _dev_->CR1 |= 1<<9; |
|
286 | _dev_->CR1 |= 1<<9; | |
289 | return count; |
|
287 | return count; | |
290 | } |
|
288 | } | |
291 | return -1; |
|
289 | return -1; | |
292 | } |
|
290 | } | |
293 |
|
291 | |||
294 | int i2cread(i2c_t dev,char address,char* data,int count) |
|
292 | int i2cread(i2c_t dev,char address,char* data,int count) | |
295 | { |
|
293 | { | |
296 | if((dev<i2c4)&&(dev>=i2c1)) |
|
294 | if((dev<i2c4)&&(dev>=i2c1)) | |
297 | { |
|
295 | { | |
298 | int i=0; |
|
296 | int i=0; | |
299 | int timeout=i2ctimeout; |
|
297 | int timeout=i2ctimeout; | |
300 | while(i2cbusy(dev)) |
|
298 | while(i2cbusy(dev)) | |
301 | { |
|
299 | { | |
302 | if(0==(timeout--)) |
|
300 | if(0==(timeout--)) | |
303 | { |
|
301 | { | |
304 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
302 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
305 | return -1; |
|
303 | return -1; | |
306 | } |
|
304 | } | |
307 | } |
|
305 | } | |
308 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
306 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
309 | _dev_->CR1 |= (1<<8) + (1<<10); |
|
307 | _dev_->CR1 |= (1<<8) + (1<<10); | |
310 | timeout=i2ctimeout; |
|
308 | timeout=i2ctimeout; | |
311 | while(!i2cStatusCheck(dev,0x00030001)) |
|
309 | while(!i2cStatusCheck(dev,0x00030001)) | |
312 | { |
|
310 | { | |
313 | if(0==(timeout--)) |
|
311 | if(0==(timeout--)) | |
314 | { |
|
312 | { | |
315 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
313 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
316 | return -1; |
|
314 | return -1; | |
317 | } |
|
315 | } | |
318 | } |
|
316 | } | |
319 | _dev_->DR= (address<<1) + 1; |
|
317 | _dev_->DR= (address<<1) + 1; | |
320 | while(!i2cStatusCheck(dev,0x000002)) |
|
318 | while(!i2cStatusCheck(dev,0x000002)) | |
321 | { |
|
319 | { | |
322 | if(0==(timeout--)) |
|
320 | if(0==(timeout--)) | |
323 | { |
|
321 | { | |
324 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
322 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
325 | return -1; |
|
323 | return -1; | |
326 | } |
|
324 | } | |
327 | } |
|
325 | } | |
328 | if(count==1) |
|
326 | if(count==1) | |
329 | { |
|
327 | { | |
330 | _dev_->CR1 &= ~(1<<10); |
|
328 | _dev_->CR1 &= ~(1<<10); | |
331 | } |
|
329 | } | |
332 | address=_dev_->SR2; |
|
330 | address=_dev_->SR2; | |
333 | for(i=0;i<(count-1);i++) |
|
331 | for(i=0;i<(count-1);i++) | |
334 | { |
|
332 | { | |
335 | timeout=i2ctimeout; |
|
333 | timeout=i2ctimeout; | |
336 | while(!i2cStatusCheck(dev,0x0000040)) |
|
334 | while(!i2cStatusCheck(dev,0x0000040)) | |
337 | { |
|
335 | { | |
338 | if(0==(timeout--)) |
|
336 | if(0==(timeout--)) | |
339 | { |
|
337 | { | |
340 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
338 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
341 | return -1; |
|
339 | return -1; | |
342 | } |
|
340 | } | |
343 | } |
|
341 | } | |
344 | data[i]=_dev_->DR; |
|
342 | data[i]=_dev_->DR; | |
345 | } |
|
343 | } | |
346 | _dev_->CR1 &= ~(1<<10); |
|
344 | _dev_->CR1 &= ~(1<<10); | |
347 | _dev_->CR1 |= 1<<9; |
|
345 | _dev_->CR1 |= 1<<9; | |
348 | timeout=i2ctimeout; |
|
346 | timeout=i2ctimeout; | |
349 | while(!i2cStatusCheck(dev,0x0000040)) |
|
347 | while(!i2cStatusCheck(dev,0x0000040)) | |
350 | { |
|
348 | { | |
351 | if(0==(timeout--)) |
|
349 | if(0==(timeout--)) | |
352 | { |
|
350 | { | |
353 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
351 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
354 | return -1; |
|
352 | return -1; | |
355 | } |
|
353 | } | |
356 | } |
|
354 | } | |
357 | data[i]=_dev_->DR; |
|
355 | data[i]=_dev_->DR; | |
358 | timeout=i2ctimeout; |
|
356 | timeout=i2ctimeout; | |
359 | while(_dev_->CR1 & ((uint16_t)0x0200)) |
|
357 | while(_dev_->CR1 & ((uint16_t)0x0200)) | |
360 | { |
|
358 | { | |
361 | if(0==(timeout--)) |
|
359 | if(0==(timeout--)) | |
362 | { |
|
360 | { | |
363 | printf("Exited on timeout @ line %d\n\r",__LINE__); |
|
361 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |
364 | return -1; |
|
362 | return -1; | |
365 | } |
|
363 | } | |
366 | } |
|
364 | } | |
367 | _dev_->CR1 |= 1<<10; |
|
365 | _dev_->CR1 |= 1<<10; | |
368 | return count; |
|
366 | return count; | |
369 | } |
|
367 | } | |
370 | return -1; |
|
368 | return -1; | |
371 | } |
|
369 | } | |
372 |
|
370 | |||
373 |
|
371 | |||
374 | int i2cStatusCheck(i2c_t dev,int32_t flagMask) |
|
372 | int i2cStatusCheck(i2c_t dev,int32_t flagMask) | |
375 | { |
|
373 | { | |
376 | int32_t flag; |
|
374 | int32_t flag; | |
377 | if((dev<i2c4)&&(dev>=i2c1)) |
|
375 | if((dev<i2c4)&&(dev>=i2c1)) | |
378 | { |
|
376 | { | |
379 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
377 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
380 | flag= _dev_->SR1 + (_dev_->SR2<<16); |
|
378 | flag= _dev_->SR1 + (_dev_->SR2<<16); | |
381 | if(flagMask==(flag & flagMask)) |
|
379 | if(flagMask==(flag & flagMask)) | |
382 | return 1; |
|
380 | return 1; | |
383 | return 0; |
|
381 | return 0; | |
384 | } |
|
382 | } | |
385 | return -1; |
|
383 | return -1; | |
386 | } |
|
384 | } | |
387 |
|
385 | |||
388 |
|
386 |
@@ -1,13 +1,14 | |||||
1 |
|
1 | |||
2 | INCLUDEPATH += $$[QT_INSTALL_HEADERS] \ |
|
2 | INCLUDEPATH += $$[QT_INSTALL_HEADERS] \ | |
3 | $$[QT_INSTALL_HEADERS]/GRAPHIC/CONTROLERS \ |
|
3 | $$[QT_INSTALL_HEADERS]/GRAPHIC/CONTROLERS \ | |
|
4 | $$[QT_INSTALL_HEADERS]/GRAPHIC/TC_CONTROLERS \ | |||
4 | $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/FONTS \ |
|
5 | $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/FONTS \ | |
5 | $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/Widgets \ |
|
6 | $$[QT_INSTALL_HEADERS]/GRAPHIC/GUI/Widgets \ | |
6 | $$[QT_INSTALL_HEADERS]/$$ARCH |
|
7 | $$[QT_INSTALL_HEADERS]/$$ARCH | |
7 |
|
8 | |||
8 |
|
9 | |||
9 | LIBS += -L$$[QT_INSTALL_LIBS]/$$ARCH -lterminal -lCS43L22 -lina226 -lili9328 -lfonts -lsdcard -lfat32 -lmbr -luart -li2c -lgpio -lspi -lcpu -lcore -lm |
|
10 | LIBS += -L$$[QT_INSTALL_LIBS]/$$ARCH -lterminal -lCS43L22 -lina226 -lili9328 -lSTMPE811 -lfonts -lsdcard -lfat32 -lmbr -luart -li2c -lgpio -lspi -lcpu -lcore -lm | |
10 |
|
11 | |||
11 |
|
12 | |||
12 |
|
13 | |||
13 |
|
14 |
General Comments 0
You need to be logged in to leave comments.
Login now