@@ -1,99 +1,105 | |||||
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 BSP_H |
|
22 | #ifndef BSP_H | |
23 | #define BSP_H |
|
23 | #define BSP_H | |
24 | #include <stm32f4xx.h> |
|
24 | #include <stm32f4xx.h> | |
25 | #include <stm32f4xx_gpio.h> |
|
25 | #include <stm32f4xx_gpio.h> | |
26 | #include <stm32f4xx_rcc.h> |
|
26 | #include <stm32f4xx_rcc.h> | |
27 | #include <gpio.h> |
|
27 | #include <gpio.h> | |
28 | #include <ili9328.h> |
|
28 | #include <ili9328.h> | |
29 | #include <genericLCD_Controler.h> |
|
29 | #include <genericLCD_Controler.h> | |
30 |
|
30 | |||
31 | #define __MAX_OPENED_FILES__ 4 |
|
31 | #define __MAX_OPENED_FILES__ 4 | |
32 | #define __FS_ROOT_SIZE__ 4 |
|
32 | #define __FS_ROOT_SIZE__ 4 | |
33 | /* |
|
33 | /* | |
34 | #ifndef PD8 |
|
34 | #ifndef PD8 | |
35 | #define PD8 |
|
35 | #define PD8 | |
36 | #endif |
|
36 | #endif | |
37 | #ifndef PD9 |
|
37 | #ifndef PD9 | |
38 | #define PD9 |
|
38 | #define PD9 | |
39 | #endif |
|
39 | #endif | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | #define LED1 PF6 |
|
43 | #define LED1 PF6 | |
44 | #define LED2 PF7 |
|
44 | #define LED2 PF7 | |
45 | #define LED3 PF8 |
|
45 | #define LED3 PF8 | |
46 |
|
46 | |||
47 | #define PSU_DISABLE PH2 |
|
47 | #define PSU_DISABLE PH2 | |
48 | #define PSU_ALERT_5V PF2 |
|
48 | #define PSU_ALERT_5V PF2 | |
49 | #define PSU_ALERT_1_5V PF3 |
|
49 | #define PSU_ALERT_1_5V PF3 | |
50 | #define PSU_ALERT_3_3V PF4 |
|
50 | #define PSU_ALERT_3_3V PF4 | |
51 |
|
51 | |||
52 | #define LCD_RESET PE2 |
|
52 | #define LCD_RESET PE2 | |
53 |
|
53 | |||
54 | extern float VREF0; |
|
54 | extern float VREF0; | |
55 |
|
55 | |||
56 | extern uint32_t currentCpuFreq; |
|
56 | extern uint32_t currentCpuFreq; | |
57 | extern LCD_t lcd0; |
|
57 | extern LCD_t lcd0; | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | extern int bsp_init(); |
|
60 | extern int bsp_init(); | |
61 |
|
61 | |||
62 | extern void bsp_GPIO_init(); |
|
62 | extern void bsp_GPIO_init(); | |
63 | extern void bsp_uart_init(); |
|
63 | extern void bsp_uart_init(); | |
64 | extern void bsp_iic_init(); |
|
64 | extern void bsp_iic_init(); | |
65 | extern void bsp_spi_init(); |
|
65 | extern void bsp_spi_init(); | |
66 | extern void bsp_SD_init(); |
|
66 | extern void bsp_SD_init(); | |
67 |
extern |
|
67 | extern int bsp_FSMC_init(); | |
68 |
|
68 | |||
69 | /* VS1053 */ |
|
69 | /* VS1053 */ | |
70 | extern void clearXCS(); |
|
70 | extern void clearXCS(); | |
71 | extern void setXCS(); |
|
71 | extern void setXCS(); | |
72 | extern int vs10XXDREQ(); |
|
72 | extern int vs10XXDREQ(); | |
73 |
|
73 | |||
74 | /* SD CARD */ |
|
74 | /* SD CARD */ | |
75 | void bsppowersdcard(char onoff); |
|
75 | void bsppowersdcard(char onoff); | |
76 | char bspsdcardpresent(); |
|
76 | char bspsdcardpresent(); | |
77 | void bspsdcardselect(char YESNO); |
|
77 | void bspsdcardselect(char YESNO); | |
78 | char bspsdcardwriteprotected(); |
|
78 | char bspsdcardwriteprotected(); | |
79 |
|
79 | |||
|
80 | ||||
|
81 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data); | |||
|
82 | uint32_t bsp_lcd0_read_reg(uint32_t reg); | |||
|
83 | void bsp_lcd0_writeGRAM(void *buffer, uint32_t count); | |||
|
84 | void bsp_lcd0_readGRAM(void *buffer, uint32_t count); | |||
|
85 | ||||
80 | #endif |
|
86 | #endif | |
81 |
|
87 | |||
82 |
|
88 | |||
83 |
|
89 | |||
84 |
|
90 | |||
85 |
|
91 | |||
86 |
|
92 | |||
87 |
|
93 | |||
88 |
|
94 | |||
89 |
|
95 | |||
90 |
|
96 | |||
91 |
|
97 | |||
92 |
|
98 | |||
93 |
|
99 | |||
94 |
|
100 | |||
95 |
|
101 | |||
96 |
|
102 | |||
97 |
|
103 | |||
98 |
|
104 | |||
99 |
|
105 |
@@ -1,269 +1,278 | |||||
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 | uint32_t OSC0 =8000000; |
|
31 | uint32_t OSC0 =8000000; | |
32 | uint32_t INTOSC =16000000; |
|
32 | uint32_t INTOSC =16000000; | |
33 | uint32_t RTCOSC =32768; |
|
33 | uint32_t RTCOSC =32768; | |
34 | uint32_t currentCpuFreq=0; |
|
34 | uint32_t currentCpuFreq=0; | |
35 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
35 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
36 | LCD_t lcd0; |
|
36 | ||
37 |
LCD_IF_t lcdIF0 |
|
37 | LCD_IF_t lcdIF0={ | |
|
38 | .init = &bsp_FSMC_init, | |||
|
39 | .writereg = &bsp_lcd0_write_reg, | |||
|
40 | .readreg = &bsp_lcd0_read_reg, | |||
|
41 | .writeGRAM = &bsp_lcd0_writeGRAM, | |||
|
42 | .readGRAM = &bsp_lcd0_readGRAM | |||
|
43 | }; | |||
|
44 | ||||
|
45 | LCD_t lcd0={ | |||
|
46 | .interface = &lcdIF0, | |||
|
47 | .init = &ili9328init, | |||
|
48 | .paint = &ili9328paint, | |||
|
49 | .refreshenable = &ili9328refreshenable, | |||
|
50 | .width= 240, | |||
|
51 | .height = 320 | |||
|
52 | }; | |||
38 |
|
53 | |||
39 | volatile int16_t* lcd0_CMD=(volatile int16_t*) 0x60000000; |
|
54 | volatile int16_t* lcd0_CMD=(volatile int16_t*) 0x60000000; | |
40 | volatile int16_t* lcd0_DATA=(volatile int16_t*)(0x61FFFFF0); |
|
55 | volatile int16_t* lcd0_DATA=(volatile int16_t*)(0x61FFFFF0); | |
41 |
|
56 | |||
42 | float VREF0 =(float)3.3; |
|
57 | float VREF0 =(float)3.3; | |
43 |
|
58 | |||
44 | int bsp_init() |
|
59 | int bsp_init() | |
45 | { |
|
60 | { | |
46 | int i=0; |
|
61 | int i=0; | |
47 | for(i=0;i<32;i++) |
|
62 | for(i=0;i<32;i++) | |
48 | { |
|
63 | { | |
49 | __opnfiles__[i] = NULL; |
|
64 | __opnfiles__[i] = NULL; | |
50 | } |
|
65 | } | |
51 | bsp_GPIO_init(); |
|
66 | bsp_GPIO_init(); | |
52 | bsp_uart_init(); |
|
67 | bsp_uart_init(); | |
53 | bsp_iic_init(); |
|
68 | bsp_iic_init(); | |
54 | bsp_FSMC_init(); |
|
69 | bsp_FSMC_init(); | |
55 | printf("\r================================================================\n\r"); |
|
70 | printf("\r================================================================\n\r"); | |
56 | printf("================================================================\n\r"); |
|
71 | printf("================================================================\n\r"); | |
57 | printf(BSP); |
|
72 | printf(BSP); | |
58 | printf(" initialised\n\r"); |
|
73 | printf(" initialised\n\r"); | |
59 | printf("================================================================\n\r"); |
|
74 | printf("================================================================\n\r"); | |
60 | return 1; |
|
75 | return 1; | |
61 | } |
|
76 | } | |
62 |
|
77 | |||
63 | void bsp_GPIO_init() |
|
78 | void bsp_GPIO_init() | |
64 | { |
|
79 | { | |
65 | gpio_t gpio1 = gpioopen(LED1); |
|
80 | gpio_t gpio1 = gpioopen(LED1); | |
66 | gpio_t gpio2 = gpioopen(LED2); |
|
81 | gpio_t gpio2 = gpioopen(LED2); | |
67 | gpio_t gpio3 = gpioopen(LED3); |
|
82 | gpio_t gpio3 = gpioopen(LED3); | |
68 | gpio_t gpio4 = gpioopen(PSU_DISABLE); |
|
83 | gpio_t gpio4 = gpioopen(PSU_DISABLE); | |
69 | gpio_t gpio5 = gpioopen(PSU_ALERT_5V); |
|
84 | gpio_t gpio5 = gpioopen(PSU_ALERT_5V); | |
70 | gpio_t gpio6 = gpioopen(PSU_ALERT_1_5V); |
|
85 | gpio_t gpio6 = gpioopen(PSU_ALERT_1_5V); | |
71 | gpio_t gpio7 = gpioopen(PSU_ALERT_3_3V); |
|
86 | gpio_t gpio7 = gpioopen(PSU_ALERT_3_3V); | |
72 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
87 | gpiosetspeed(&gpio1,gpiohighspeed); | |
73 | gpiosetspeed(&gpio2,gpiohighspeed); |
|
88 | gpiosetspeed(&gpio2,gpiohighspeed); | |
74 | gpiosetspeed(&gpio3,gpiohighspeed); |
|
89 | gpiosetspeed(&gpio3,gpiohighspeed); | |
75 | gpiosetspeed(&gpio4,gpiohighspeed); |
|
90 | gpiosetspeed(&gpio4,gpiohighspeed); | |
76 | gpiosetspeed(&gpio5,gpiohighspeed); |
|
91 | gpiosetspeed(&gpio5,gpiohighspeed); | |
77 | gpiosetspeed(&gpio6,gpiohighspeed); |
|
92 | gpiosetspeed(&gpio6,gpiohighspeed); | |
78 | gpiosetspeed(&gpio7,gpiohighspeed); |
|
93 | gpiosetspeed(&gpio7,gpiohighspeed); | |
79 | gpioclr(PSU_DISABLE); |
|
94 | gpioclr(PSU_DISABLE); | |
80 | gpiosetdir(&gpio1,gpiooutdir); |
|
95 | gpiosetdir(&gpio1,gpiooutdir); | |
81 | gpiosetdir(&gpio3,gpiooutdir); |
|
96 | gpiosetdir(&gpio3,gpiooutdir); | |
82 | gpiosetdir(&gpio2,gpiooutdir); |
|
97 | gpiosetdir(&gpio2,gpiooutdir); | |
83 | gpiosetdir(&gpio4,gpiooutdir); |
|
98 | gpiosetdir(&gpio4,gpiooutdir); | |
84 | gpiosetdir(&gpio5,gpioindir); |
|
99 | gpiosetdir(&gpio5,gpioindir); | |
85 | gpiosetdir(&gpio6,gpioindir); |
|
100 | gpiosetdir(&gpio6,gpioindir); | |
86 | gpiosetdir(&gpio7,gpioindir); |
|
101 | gpiosetdir(&gpio7,gpioindir); | |
87 | gpioclr(PSU_DISABLE); |
|
102 | gpioclr(PSU_DISABLE); | |
88 | } |
|
103 | } | |
89 |
|
104 | |||
90 | void bsp_uart_init() |
|
105 | void bsp_uart_init() | |
91 | { |
|
106 | { | |
92 | if(__opnfiles__[1]==NULL) |
|
107 | if(__opnfiles__[1]==NULL) | |
93 | { |
|
108 | { | |
94 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
109 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
95 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
110 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
96 | uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
111 | uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |
97 | uartmkstreamdev(uart,fd1); |
|
112 | uartmkstreamdev(uart,fd1); | |
98 | __opnfiles__[1] = fd1; |
|
113 | __opnfiles__[1] = fd1; | |
99 | } |
|
114 | } | |
100 | else |
|
115 | else | |
101 | { |
|
116 | { | |
102 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
117 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |
103 | } |
|
118 | } | |
104 | } |
|
119 | } | |
105 |
|
120 | |||
106 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data); |
|
121 | ||
107 | uint32_t bsp_lcd0_read_reg(uint32_t reg); |
|
|||
108 | void bsp_lcd0_writeGRAM(void *buffer, uint32_t count); |
|
|||
109 | void bsp_lcd0_readGRAM(void *buffer, uint32_t count); |
|
|||
110 |
|
122 | |||
111 |
|
|
123 | int bsp_FSMC_init() | |
112 | { |
|
124 | { | |
113 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
125 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
114 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
126 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
115 |
|
127 | |||
116 | gpio_t gpio1 = gpioopen(LCD_RESET); |
|
128 | gpio_t gpio1 = gpioopen(LCD_RESET); | |
117 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
129 | gpiosetspeed(&gpio1,gpiohighspeed); | |
118 | gpiosetdir(&gpio1,gpiooutdir); |
|
130 | gpiosetdir(&gpio1,gpiooutdir); | |
119 | gpioclr(LCD_RESET); |
|
131 | gpioclr(LCD_RESET); | |
120 |
|
132 | |||
121 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15\ |
|
133 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15\ | |
122 | ,PD8,PD9,PD10,PD4,PD5,PD7,PE4}; |
|
134 | ,PD8,PD9,PD10,PD4,PD5,PD7,PE4}; | |
123 | for(int i=0;i<20;i++) |
|
135 | for(int i=0;i<20;i++) | |
124 | { |
|
136 | { | |
125 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
137 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); | |
126 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
138 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
127 | gpiosetconfig(&LCD_DBx); |
|
139 | gpiosetconfig(&LCD_DBx); | |
128 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
140 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); | |
129 | } |
|
141 | } | |
130 |
|
142 | |||
131 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
143 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; | |
132 | FSMC_NORSRAMTimingInitTypeDef p; |
|
144 | FSMC_NORSRAMTimingInitTypeDef p; | |
133 |
|
145 | |||
134 | /* Enable FSMC clock */ |
|
146 | /* Enable FSMC clock */ | |
135 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
147 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); | |
136 |
|
148 | |||
137 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
149 | /*-- FSMC Configuration ------------------------------------------------------*/ | |
138 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
150 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ | |
139 | /* FSMC_Bank1_NORSRAM4 configuration */ |
|
151 | /* FSMC_Bank1_NORSRAM4 configuration */ | |
140 | //p.FSMC_AddressSetupTime = 5; |
|
152 | //p.FSMC_AddressSetupTime = 5; | |
141 |
p.FSMC_AddressSetupTime = |
|
153 | p.FSMC_AddressSetupTime = 2; | |
142 | p.FSMC_AddressHoldTime = 0; |
|
154 | p.FSMC_AddressHoldTime = 0; | |
143 | //p.FSMC_DataSetupTime = 9; |
|
155 | //p.FSMC_DataSetupTime = 9; | |
144 |
p.FSMC_DataSetupTime = |
|
156 | p.FSMC_DataSetupTime = 4; | |
145 | p.FSMC_BusTurnAroundDuration = 0; |
|
157 | p.FSMC_BusTurnAroundDuration = 0; | |
146 | p.FSMC_CLKDivision = 0; |
|
158 | p.FSMC_CLKDivision = 0; | |
147 | p.FSMC_DataLatency = 0; |
|
159 | p.FSMC_DataLatency = 0; | |
148 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
160 | p.FSMC_AccessMode = FSMC_AccessMode_A; | |
149 | /* Color LCD configuration ------------------------------------ |
|
161 | /* Color LCD configuration ------------------------------------ | |
150 | LCD configured as follow: |
|
162 | LCD configured as follow: | |
151 | - Data/Address MUX = Disable |
|
163 | - Data/Address MUX = Disable | |
152 | - Memory Type = SRAM |
|
164 | - Memory Type = SRAM | |
153 | - Data Width = 16bit |
|
165 | - Data Width = 16bit | |
154 | - Write Operation = Enable |
|
166 | - Write Operation = Enable | |
155 | - Extended Mode = Enable |
|
167 | - Extended Mode = Enable | |
156 | - Asynchronous Wait = Disable */ |
|
168 | - Asynchronous Wait = Disable */ | |
157 |
|
169 | |||
158 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
|
170 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; | |
159 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
171 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; | |
160 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
172 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; | |
161 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
173 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; | |
162 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
174 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; | |
163 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
175 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; | |
164 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
176 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; | |
165 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
177 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; | |
166 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
178 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; | |
167 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
179 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; | |
168 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
180 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; | |
169 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
181 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; | |
170 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
182 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; | |
171 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
183 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; | |
172 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
184 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; | |
173 |
|
185 | |||
174 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
186 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); | |
175 |
|
187 | |||
176 | /* Enable FSMC NOR/SRAM Bank1 */ |
|
188 | /* Enable FSMC NOR/SRAM Bank1 */ | |
177 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
|
189 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); | |
178 | lcdIF0.writereg=&bsp_lcd0_write_reg; |
|
|||
179 | lcdIF0.readGRAM=&bsp_lcd0_readGRAM; |
|
|||
180 | lcdIF0.readreg=&bsp_lcd0_read_reg; |
|
|||
181 | lcdIF0.writeGRAM=&bsp_lcd0_writeGRAM; |
|
|||
182 | lcd0.interface=&lcdIF0; |
|
|||
183 | lcd0.init=&ili9328init; |
|
|||
184 | lcd0.paint=&ili9328paint; |
|
|||
185 | gpioset(LCD_RESET); |
|
190 | gpioset(LCD_RESET); | |
186 | lcd0.init(&lcd0); |
|
191 | lcd0.init(&lcd0); | |
|
192 | return 1; | |||
187 | } |
|
193 | } | |
188 |
|
194 | |||
189 | void bsp_spi_init() |
|
195 | void bsp_spi_init() | |
190 | { |
|
196 | { | |
191 |
|
197 | |||
192 | } |
|
198 | } | |
193 |
|
199 | |||
194 |
|
200 | |||
195 | void bsp_iic_init() |
|
201 | void bsp_iic_init() | |
196 | { |
|
202 | { | |
197 | i2copenandconfig(i2c2,0,400000,PF0,PF1); |
|
203 | i2copenandconfig(i2c2,0,400000,PF0,PF1); | |
198 | } |
|
204 | } | |
199 |
|
205 | |||
200 | void bsp_SD_init() |
|
206 | void bsp_SD_init() | |
201 | { |
|
207 | { | |
202 |
|
208 | |||
203 | } |
|
209 | } | |
204 |
|
210 | |||
205 | void vs10XXclearXCS(){} |
|
211 | void vs10XXclearXCS(){} | |
206 | void vs10XXsetXCS(){} |
|
212 | void vs10XXsetXCS(){} | |
207 | int vs10XXDREQ() |
|
213 | int vs10XXDREQ() | |
208 | { |
|
214 | { | |
209 | return 1; |
|
215 | return 1; | |
210 | } |
|
216 | } | |
211 |
|
217 | |||
212 |
|
218 | |||
213 | void bsppowersdcard(char onoff) //always ON |
|
219 | void bsppowersdcard(char onoff) //always ON | |
214 | { |
|
220 | { | |
215 |
|
221 | |||
216 | } |
|
222 | } | |
217 |
|
223 | |||
218 | char bspsdcardpresent() |
|
224 | char bspsdcardpresent() | |
219 | { |
|
225 | { | |
220 | return 0; |
|
226 | return 0; | |
221 | } |
|
227 | } | |
222 |
|
228 | |||
223 | char bspsdcardwriteprotected() |
|
229 | char bspsdcardwriteprotected() | |
224 | { |
|
230 | { | |
225 | return 0; |
|
231 | return 0; | |
226 | } |
|
232 | } | |
227 |
|
233 | |||
228 | void bspsdcardselect(char YESNO) |
|
234 | void bspsdcardselect(char YESNO) | |
229 | { |
|
235 | { | |
230 |
|
236 | |||
231 | } |
|
237 | } | |
232 |
|
238 | |||
233 |
|
239 | |||
234 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
240 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
235 | { |
|
241 | { | |
|
242 | printf("Write %X @ %d\n\r",data,reg); | |||
236 | *lcd0_CMD=(uint16_t)reg; |
|
243 | *lcd0_CMD=(uint16_t)reg; | |
237 | *lcd0_DATA=(uint16_t)data; |
|
244 | *lcd0_DATA=(uint16_t)data; | |
238 | } |
|
245 | } | |
239 |
|
246 | |||
240 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
247 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
241 | { |
|
248 | { | |
242 | *lcd0_CMD=(uint16_t)reg; |
|
249 | *lcd0_CMD=(uint16_t)reg; | |
243 | return (uint16_t)*lcd0_DATA; |
|
250 | return (uint16_t)*lcd0_DATA; | |
244 | } |
|
251 | } | |
245 |
|
252 | |||
246 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
253 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
247 | { |
|
254 | { | |
|
255 | printf("Write to GRAM %d pixels from 0x%X\t\n\r",count,(int)buffer); | |||
248 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
256 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; | |
249 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
257 | uint16_t* castedBuff=(uint16_t*)buffer; | |
250 |
for( |
|
258 | for(int i=0;i<(int)count;i++) | |
251 | { |
|
259 | { | |
252 | *lcd0_DATA=castedBuff[i]; |
|
260 | *lcd0_DATA=castedBuff[i]; | |
253 | } |
|
261 | } | |
|
262 | printf("[Done]\n\r"); | |||
254 | } |
|
263 | } | |
255 |
|
264 | |||
256 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
265 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
257 | { |
|
266 | { | |
258 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
267 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; | |
259 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
268 | uint16_t* castedBuff=(uint16_t*)buffer; | |
260 | castedBuff[0]=*lcd0_DATA; |
|
269 | castedBuff[0]=*lcd0_DATA; | |
261 |
for( |
|
270 | for(int i=0;i<(int)count;i++) | |
262 | { |
|
271 | { | |
263 | castedBuff[i]=*lcd0_DATA; |
|
272 | castedBuff[i]=*lcd0_DATA; | |
264 | } |
|
273 | } | |
265 | } |
|
274 | } | |
266 |
|
275 | |||
267 |
|
276 | |||
268 |
|
277 | |||
269 |
|
278 |
@@ -1,93 +1,88 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 | #include <fat32.h> |
|
2 | #include <fat32.h> | |
3 | #include <gpio.h> |
|
3 | #include <gpio.h> | |
4 | #include <uart.h> |
|
4 | #include <uart.h> | |
5 | #include <stm32f4xx.h> |
|
5 | #include <stm32f4xx.h> | |
6 | #include <bsp.h> |
|
6 | #include <bsp.h> | |
7 | #include <i2c.h> |
|
7 | #include <i2c.h> | |
8 | #include <CS43L22.h> |
|
8 | #include <CS43L22.h> | |
9 | #include <ina226.h> |
|
9 | #include <ina226.h> | |
10 | #include <fonts.h> |
|
10 | #include <fonts.h> | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | extern streamdevice* __opnfiles__[]; |
|
13 | extern streamdevice* __opnfiles__[]; | |
14 |
|
14 | |||
15 | int main() |
|
15 | int main() | |
16 | { |
|
16 | { | |
17 | INA226_t ina5VSens,ina33VSens,ina15VSens; |
|
17 | INA226_t ina5VSens,ina33VSens,ina15VSens; | |
18 | gpioset(PSU_DISABLE); |
|
18 | gpioset(PSU_DISABLE); | |
19 | volatile int16_t* regtest=(volatile int16_t*)0x60000000; |
|
19 | volatile int16_t* regtest=(volatile int16_t*)0x60000000; | |
20 | volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0); |
|
20 | volatile int16_t* regtest2=(volatile int16_t*)(0x61FFFFF0); | |
21 | //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000); |
|
21 | //ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000); | |
22 | //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000); |
|
22 | //ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000); | |
23 | *regtest=(int16_t)0; |
|
23 | *regtest=(int16_t)0; | |
24 | printf("LCD ID=%x\n\r",0xFFFF&(*regtest2)); |
|
24 | printf("LCD ID=%x\n\r",0xFFFF&(*regtest2)); | |
25 |
|
25 | //lcd0.refreshenable(&lcd0,1); | ||
26 | while(1) |
|
26 | while(1) | |
27 | { |
|
27 | { | |
28 | /* *regtest=(int16_t)ILI9328_REGISTER_ENTRYMODE; |
|
28 | //ili9328setFrame(&lcd0,0,0,240,320); | |
29 | *regtest2=(int16_t)0x1008;*/ |
|
29 | //ili9328setGRAMaddress(&lcd0,0,0); | |
30 | ili9328setFrame(&lcd0,0,0,240,320); |
|
30 | *regtest=(int16_t)0x20; | |
|
31 | *regtest2=(int16_t)0x0; | |||
|
32 | *regtest=(int16_t)0x21; | |||
|
33 | *regtest2=(int16_t)0x0; | |||
31 | *regtest=(int16_t)0x22; |
|
34 | *regtest=(int16_t)0x22; | |
32 |
for( |
|
35 | for(int i=0;i<(320*240);i++) | |
33 | { |
|
36 | { | |
34 | *regtest2=(int16_t)0x001F; |
|
37 | *regtest2=(int16_t)0x001F; | |
35 | //for(volatile int l=0;l<(1024);l++); |
|
|||
36 |
|
||||
37 | } |
|
38 | } | |
38 | /* *regtest=(int16_t)ILI9328_REGISTER_ENTRYMODE; |
|
|||
39 | *regtest2=(int16_t)0x1018;*/ |
|
|||
40 | for(volatile int i=0;i<(320*240*100);i++); |
|
39 | for(volatile int i=0;i<(320*240*100);i++); | |
41 | /* *regtest=(int16_t)ILI9328_REGISTER_ENTRYMODE; |
|
40 | //uint16_t test[100]; | |
42 | *regtest2=(int16_t)0x1008;*/ |
|
41 | //ili9328setFrame(&lcd0,10,10,10,10); | |
43 | //ili9328setGRAMaddress(&lcd0,60,80); |
|
42 | //*regtest=(int16_t)0x22; | |
44 | uint16_t test[80*80]; |
|
43 | //for(int i=0;i<(10*10);i++) | |
45 | ili9328setFrame(&lcd0,10,10,100,100); |
|
44 | //{ | |
46 |
*regtest=(int16_t) |
|
45 | // *regtest2=(int16_t)(0xF800); | |
47 | for(volatile int i=0;i<(100*100);i++) |
|
46 | //test[i]=(int16_t)0xF800; | |
48 | { |
|
47 | //for(volatile int l=0;l<(1024);l++); | |
49 | *regtest2=(int16_t)(0xF800); |
|
|||
50 | //test[i]=(int16_t)0xF800; |
|
|||
51 | //for(volatile int l=0;l<(1024);l++); |
|
|||
52 |
|
48 | |||
53 | } |
|
49 | //} | |
|
50 | //bsp_lcd0_writeGRAM(test,10*10); | |||
54 | //lcd0.paint(&lcd0,test,100,100,80,80); |
|
51 | //lcd0.paint(&lcd0,test,100,100,80,80); | |
55 | /**regtest=(int16_t)ILI9328_REGISTER_ENTRYMODE; |
|
52 | //for(volatile int i=0;i<(320*240*100);i++); | |
56 | *regtest2=(int16_t)0x1018;*/ |
|
|||
57 | for(volatile int i=0;i<(320*240*100);i++); |
|
|||
58 | } |
|
53 | } | |
59 |
|
54 | |||
60 | 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)) |
|
55 | 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)) | |
61 | { |
|
56 | { | |
62 | printf("Can't open 3.3V monitor\n\r"); |
|
57 | printf("Can't open 3.3V monitor\n\r"); | |
63 | } |
|
58 | } | |
64 |
|
59 | |||
65 | int current5V,current33V,current15V; |
|
60 | int current5V,current33V,current15V; | |
66 | printf("\t5V\t3.3V\n\r"); |
|
61 | printf("\t5V\t3.3V\n\r"); | |
67 | while(1) |
|
62 | while(1) | |
68 | { |
|
63 | { | |
69 | for(volatile int i=0;i<1024*1024;i++); |
|
64 | for(volatile int i=0;i<1024*1024;i++); | |
70 | gpioset(LED1); |
|
65 | gpioset(LED1); | |
71 | gpioclr(LED2); |
|
66 | gpioclr(LED2); | |
72 | for(volatile int i=0;i<1024*1024;i++); |
|
67 | for(volatile int i=0;i<1024*1024;i++); | |
73 | gpioclr(LED1); |
|
68 | gpioclr(LED1); | |
74 | gpioset(LED2); |
|
69 | gpioset(LED2); | |
75 | //current5V = ina226getCurrent(&ina5VSens); |
|
70 | //current5V = ina226getCurrent(&ina5VSens); | |
76 | current33V = ina226getCurrent(&ina33VSens); |
|
71 | current33V = ina226getCurrent(&ina33VSens); | |
77 | //current15V = ina226getCurrent(&ina15VSens); |
|
72 | //current15V = ina226getCurrent(&ina15VSens); | |
78 | //current = ina226getReg(&Psens1,INA226_Current_Reg); |
|
73 | //current = ina226getReg(&Psens1,INA226_Current_Reg); | |
79 | //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000); |
|
74 | //printf("%duA %dmA\t%duA %dmA\n\r",current5V,current5V/1000,current33V,current33V/1000); | |
80 | printf("%duA %dmA\n\r",current33V,current33V/1000); |
|
75 | printf("%duA %dmA\n\r",current33V,current33V/1000); | |
81 | } |
|
76 | } | |
82 | printf("hello world\n\r"); |
|
77 | printf("hello world\n\r"); | |
83 | return 0; |
|
78 | return 0; | |
84 | } |
|
79 | } | |
85 |
|
80 | |||
86 |
|
81 | |||
87 |
|
82 | |||
88 |
|
83 | |||
89 |
|
84 | |||
90 |
|
85 | |||
91 |
|
86 | |||
92 |
|
87 | |||
93 |
|
88 |
@@ -1,53 +1,54 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2012, Alexis Jeandet |
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef GENERICLCD_CONTROLER_H |
|
22 | #ifndef GENERICLCD_CONTROLER_H | |
23 | #define GENERICLCD_CONTROLER_H |
|
23 | #define GENERICLCD_CONTROLER_H | |
24 |
|
24 | |||
25 | #include <uhandle.h> |
|
25 | #include <uhandle.h> | |
26 | #include <stdint.h> |
|
26 | #include <stdint.h> | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | typedef struct LCD_IF_t |
|
29 | typedef struct LCD_IF_t | |
30 | { |
|
30 | { | |
31 | int (*init)(); |
|
31 | int (*init)(); | |
32 | void (*writereg)(uint32_t reg,uint32_t data); |
|
32 | void (*writereg)(uint32_t reg,uint32_t data); | |
33 | uint32_t (*readreg)(uint32_t reg); |
|
33 | uint32_t (*readreg)(uint32_t reg); | |
34 | void (*writeGRAM)(void* buffer,uint32_t count); |
|
34 | void (*writeGRAM)(void* buffer,uint32_t count); | |
35 | void (*readGRAM)(void* buffer,uint32_t count); |
|
35 | void (*readGRAM)(void* buffer,uint32_t count); | |
36 | }LCD_IF_t; |
|
36 | }LCD_IF_t; | |
37 |
|
37 | |||
38 | typedef struct LCD_t |
|
38 | typedef struct LCD_t | |
39 | { |
|
39 | { | |
40 | LCD_IF_t* interface; |
|
40 | LCD_IF_t* interface; | |
41 | int (*init)(struct LCD_t* LCD); |
|
41 | int (*init)(struct LCD_t* LCD); | |
42 | void (*paint)(struct LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); |
|
42 | void (*paint)(struct LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); | |
|
43 | void (*refreshenable)(struct LCD_t* LCD,int enable); | |||
43 | uint16_t width; |
|
44 | uint16_t width; | |
44 | uint16_t height; |
|
45 | uint16_t height; | |
45 | }LCD_t; |
|
46 | }LCD_t; | |
46 |
|
47 | |||
47 |
|
48 | |||
48 | #endif /*GENERICLCD_CONTROLER_H*/ |
|
49 | #endif /*GENERICLCD_CONTROLER_H*/ | |
49 |
|
50 | |||
50 |
|
51 | |||
51 |
|
52 | |||
52 |
|
53 | |||
53 |
|
54 |
@@ -1,91 +1,92 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2012, Alexis Jeandet |
|
3 | -- Copyright (C) 2012, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Alexis Jeandet |
|
19 | -- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@gmail.com |
|
20 | -- Mail : alexis.jeandet@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | #ifndef ILI9328_H |
|
22 | #ifndef ILI9328_H | |
23 | #define ILI9328_H |
|
23 | #define ILI9328_H | |
24 |
|
24 | |||
25 | #include <uhandle.h> |
|
25 | #include <uhandle.h> | |
26 | #include <genericLCD_Controler.h> |
|
26 | #include <genericLCD_Controler.h> | |
27 | #include <stdint.h> |
|
27 | #include <stdint.h> | |
28 |
|
28 | |||
29 | extern int ili9328init(struct LCD_t* LCD); |
|
29 | extern int ili9328init(struct LCD_t* LCD); | |
30 |
extern void ili9328setFrame(LCD_t* LCD,uint16_t |
|
30 | extern void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H); | |
31 | extern void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress); |
|
31 | extern void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress); | |
32 | extern void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); |
|
32 | extern void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); | |
|
33 | extern void ili9328refreshenable(struct LCD_t* LCD,int enable); | |||
33 |
|
34 | |||
34 | #define ILI9328_REGISTER_DRIVERCODEREAD ((uint32_t) 0x0000 ) |
|
35 | #define ILI9328_REGISTER_DRIVERCODEREAD ((uint32_t) 0x0000 ) | |
35 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 ((uint32_t) 0x0001 ) |
|
36 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 ((uint32_t) 0x0001 ) | |
36 | #define ILI9328_REGISTER_LCDDRIVINGCONTROL ((uint32_t) 0x0002 ) |
|
37 | #define ILI9328_REGISTER_LCDDRIVINGCONTROL ((uint32_t) 0x0002 ) | |
37 | #define ILI9328_REGISTER_ENTRYMODE ((uint32_t) 0x0003 ) |
|
38 | #define ILI9328_REGISTER_ENTRYMODE ((uint32_t) 0x0003 ) | |
38 | #define ILI9328_REGISTER_RESIZECONTROL ((uint32_t) 0x0004 ) |
|
39 | #define ILI9328_REGISTER_RESIZECONTROL ((uint32_t) 0x0004 ) | |
39 | #define ILI9328_REGISTER_DISPLAYCONTROL1 ((uint32_t) 0x0007 ) |
|
40 | #define ILI9328_REGISTER_DISPLAYCONTROL1 ((uint32_t) 0x0007 ) | |
40 | #define ILI9328_REGISTER_DISPLAYCONTROL2 ((uint32_t) 0x0008 ) |
|
41 | #define ILI9328_REGISTER_DISPLAYCONTROL2 ((uint32_t) 0x0008 ) | |
41 | #define ILI9328_REGISTER_DISPLAYCONTROL3 ((uint32_t) 0x0009 ) |
|
42 | #define ILI9328_REGISTER_DISPLAYCONTROL3 ((uint32_t) 0x0009 ) | |
42 | #define ILI9328_REGISTER_DISPLAYCONTROL4 ((uint32_t) 0x000A ) |
|
43 | #define ILI9328_REGISTER_DISPLAYCONTROL4 ((uint32_t) 0x000A ) | |
43 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 ((uint32_t) 0x000C ) |
|
44 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 ((uint32_t) 0x000C ) | |
44 | #define ILI9328_REGISTER_FRAMEMAKERPOSITION ((uint32_t) 0x000D ) |
|
45 | #define ILI9328_REGISTER_FRAMEMAKERPOSITION ((uint32_t) 0x000D ) | |
45 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 ((uint32_t) 0x000F ) |
|
46 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 ((uint32_t) 0x000F ) | |
46 | #define ILI9328_REGISTER_POWERCONTROL1 ((uint32_t) 0x0010 ) |
|
47 | #define ILI9328_REGISTER_POWERCONTROL1 ((uint32_t) 0x0010 ) | |
47 | #define ILI9328_REGISTER_POWERCONTROL2 ((uint32_t) 0x0011 ) |
|
48 | #define ILI9328_REGISTER_POWERCONTROL2 ((uint32_t) 0x0011 ) | |
48 | #define ILI9328_REGISTER_POWERCONTROL3 ((uint32_t) 0x0012 ) |
|
49 | #define ILI9328_REGISTER_POWERCONTROL3 ((uint32_t) 0x0012 ) | |
49 | #define ILI9328_REGISTER_POWERCONTROL4 ((uint32_t) 0x0013 ) |
|
50 | #define ILI9328_REGISTER_POWERCONTROL4 ((uint32_t) 0x0013 ) | |
50 | #define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET ((uint32_t) 0x0020 ) |
|
51 | #define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET ((uint32_t) 0x0020 ) | |
51 | #define ILI9328_REGISTER_VERTICALGRAMADDRESSSET ((uint32_t) 0x0021 ) |
|
52 | #define ILI9328_REGISTER_VERTICALGRAMADDRESSSET ((uint32_t) 0x0021 ) | |
52 | #define ILI9328_REGISTER_WRITEDATATOGRAM ((uint32_t) 0x0022 ) |
|
53 | #define ILI9328_REGISTER_WRITEDATATOGRAM ((uint32_t) 0x0022 ) | |
53 | #define ILI9328_REGISTER_POWERCONTROL7 ((uint32_t) 0x0029 ) |
|
54 | #define ILI9328_REGISTER_POWERCONTROL7 ((uint32_t) 0x0029 ) | |
54 | #define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL ((uint32_t) 0x002B ) |
|
55 | #define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL ((uint32_t) 0x002B ) | |
55 | #define ILI9328_REGISTER_GAMMACONTROL1 ((uint32_t) 0x0030 ) |
|
56 | #define ILI9328_REGISTER_GAMMACONTROL1 ((uint32_t) 0x0030 ) | |
56 | #define ILI9328_REGISTER_GAMMACONTROL2 ((uint32_t) 0x0031 ) |
|
57 | #define ILI9328_REGISTER_GAMMACONTROL2 ((uint32_t) 0x0031 ) | |
57 | #define ILI9328_REGISTER_GAMMACONTROL3 ((uint32_t) 0x0032 ) |
|
58 | #define ILI9328_REGISTER_GAMMACONTROL3 ((uint32_t) 0x0032 ) | |
58 | #define ILI9328_REGISTER_GAMMACONTROL4 ((uint32_t) 0x0035 ) |
|
59 | #define ILI9328_REGISTER_GAMMACONTROL4 ((uint32_t) 0x0035 ) | |
59 | #define ILI9328_REGISTER_GAMMACONTROL5 ((uint32_t) 0x0036 ) |
|
60 | #define ILI9328_REGISTER_GAMMACONTROL5 ((uint32_t) 0x0036 ) | |
60 | #define ILI9328_REGISTER_GAMMACONTROL6 ((uint32_t) 0x0037 ) |
|
61 | #define ILI9328_REGISTER_GAMMACONTROL6 ((uint32_t) 0x0037 ) | |
61 | #define ILI9328_REGISTER_GAMMACONTROL7 ((uint32_t) 0x0038 ) |
|
62 | #define ILI9328_REGISTER_GAMMACONTROL7 ((uint32_t) 0x0038 ) | |
62 | #define ILI9328_REGISTER_GAMMACONTROL8 ((uint32_t) 0x0039 ) |
|
63 | #define ILI9328_REGISTER_GAMMACONTROL8 ((uint32_t) 0x0039 ) | |
63 | #define ILI9328_REGISTER_GAMMACONTROL9 ((uint32_t) 0x003C ) |
|
64 | #define ILI9328_REGISTER_GAMMACONTROL9 ((uint32_t) 0x003C ) | |
64 | #define ILI9328_REGISTER_GAMMACONTROL10 ((uint32_t) 0x003D ) |
|
65 | #define ILI9328_REGISTER_GAMMACONTROL10 ((uint32_t) 0x003D ) | |
65 | #define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 ) |
|
66 | #define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 ) | |
66 | #define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) 0x0051 ) |
|
67 | #define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) 0x0051 ) | |
67 | #define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) 0x0052 ) |
|
68 | #define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) 0x0052 ) | |
68 | #define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION ((uint32_t) 0x0053 ) |
|
69 | #define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION ((uint32_t) 0x0053 ) | |
69 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 ((uint32_t) 0x0060 ) |
|
70 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 ((uint32_t) 0x0060 ) | |
70 | #define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL ((uint32_t) 0x0061 ) |
|
71 | #define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL ((uint32_t) 0x0061 ) | |
71 | #define ILI9328_REGISTER_VERTICALSCROLLCONTROL ((uint32_t) 0x006A ) |
|
72 | #define ILI9328_REGISTER_VERTICALSCROLLCONTROL ((uint32_t) 0x006A ) | |
72 | #define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION ((uint32_t) 0x0080 ) |
|
73 | #define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION ((uint32_t) 0x0080 ) | |
73 | #define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE ((uint32_t) 0x0081 ) |
|
74 | #define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE ((uint32_t) 0x0081 ) | |
74 | #define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE ((uint32_t) 0x0082 ) |
|
75 | #define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE ((uint32_t) 0x0082 ) | |
75 | #define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION ((uint32_t) 0x0083 ) |
|
76 | #define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION ((uint32_t) 0x0083 ) | |
76 | #define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE ((uint32_t) 0x0084 ) |
|
77 | #define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE ((uint32_t) 0x0084 ) | |
77 | #define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE ((uint32_t) 0x0085 ) |
|
78 | #define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE ((uint32_t) 0x0085 ) | |
78 | #define ILI9328_REGISTER_PANELINTERFACECONTROL1 ((uint32_t) 0x0090 ) |
|
79 | #define ILI9328_REGISTER_PANELINTERFACECONTROL1 ((uint32_t) 0x0090 ) | |
79 | #define ILI9328_REGISTER_PANELINTERFACECONTROL2 ((uint32_t) 0x0092 ) |
|
80 | #define ILI9328_REGISTER_PANELINTERFACECONTROL2 ((uint32_t) 0x0092 ) | |
80 | #define ILI9328_REGISTER_PANELINTERFACECONTROL4 ((uint32_t) 0x0095 ) |
|
81 | #define ILI9328_REGISTER_PANELINTERFACECONTROL4 ((uint32_t) 0x0095 ) | |
81 | #define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL ((uint32_t) 0x00A1 ) |
|
82 | #define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL ((uint32_t) 0x00A1 ) | |
82 | #define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE ((uint32_t) 0x00A2 ) |
|
83 | #define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE ((uint32_t) 0x00A2 ) | |
83 | #define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY ((uint32_t) 0x00A5 ) |
|
84 | #define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY ((uint32_t) 0x00A5 ) | |
84 |
|
85 | |||
85 |
|
86 | |||
86 | #endif |
|
87 | #endif | |
87 |
|
88 | |||
88 |
|
89 | |||
89 |
|
90 | |||
90 |
|
91 | |||
91 |
|
92 |
@@ -1,103 +1,120 | |||||
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 |
|
25 | |||
26 | #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++); |
|
26 | #define _delay_(del) for(volatile int _d_e_l_=0;_d_e_l_<(del);_d_e_l_++); | |
27 |
|
27 | |||
28 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) |
|
28 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) | |
29 | { |
|
29 | { | |
30 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); |
|
30 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); | |
31 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); |
|
31 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void ili9328setFrame(LCD_t* LCD,uint16_t HaddressStart,uint16_t VaddressStart,uint16_t HaddressStop,uint16_t VaddressStop) |
|
34 | void ili9328refreshenable(struct LCD_t* LCD,int enable) | |
35 | { |
|
35 | { | |
36 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,HaddressStart); |
|
36 | if(enable) | |
37 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,VaddressStart); |
|
37 | { | |
38 |
LCD->interface->writereg(ILI9328_REGISTER_ |
|
38 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018); | |
39 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,VaddressStop); |
|
39 | } | |
|
40 | else | |||
|
41 | { | |||
|
42 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008); | |||
|
43 | ||||
|
44 | } | |||
|
45 | } | |||
|
46 | ||||
|
47 | void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H) | |||
|
48 | { | |||
|
49 | printf("setFrame X=%d Y=%d W=%d H=%d\n\r",(int)X,(int)Y,(int)W,(int)H); | |||
|
50 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,X); | |||
|
51 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Y); | |||
|
52 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,X); | |||
|
53 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,X); | |||
|
54 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,W+X); | |||
|
55 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,Y); | |||
|
56 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,Y+H); | |||
40 | } |
|
57 | } | |
41 |
|
58 | |||
42 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) |
|
59 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) | |
43 | { |
|
60 | { | |
44 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width<(Xpos+Width)) && (LCD->height<(Ypos+Height))) |
|
61 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width<(Xpos+Width)) && (LCD->height<(Ypos+Height))) | |
45 | { |
|
62 | { | |
46 | printf("paint\n\r"); |
|
63 | printf("paint\n\r"); | |
47 |
ili9328setFrame(LCD,Xpos,Ypos, |
|
64 | ili9328setFrame(LCD,Xpos,Ypos,Width,Height); | |
48 | ili9328setGRAMaddress(LCD,Xpos,Ypos); |
|
65 | //ili9328setGRAMaddress(LCD,Xpos,Ypos); | |
49 | LCD->interface->writeGRAM(buffer,Width*Height); |
|
66 | LCD->interface->writeGRAM(buffer,Width*Height); | |
50 | } |
|
67 | } | |
51 | } |
|
68 | } | |
52 |
|
69 | |||
53 | int ili9328init(struct LCD_t* LCD) |
|
70 | int ili9328init(struct LCD_t* LCD) | |
54 | { |
|
71 | { | |
55 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) |
|
72 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) | |
56 | { |
|
73 | { | |
57 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) |
|
74 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) | |
58 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) |
|
75 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) | |
59 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) |
|
76 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) | |
60 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302); |
|
77 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302); | |
61 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); |
|
78 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); | |
62 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On |
|
79 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On | |
63 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) |
|
80 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) | |
64 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
81 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) | |
65 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) |
|
82 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) | |
66 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) |
|
83 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) | |
67 | _delay_(1000000); |
|
84 | _delay_(1000000); | |
68 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) |
|
85 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) | |
69 | _delay_(500000); |
|
86 | _delay_(500000); | |
70 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
87 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) | |
71 | _delay_(500000); |
|
88 | _delay_(500000); | |
72 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) |
|
89 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) | |
73 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) |
|
90 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) | |
74 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) |
|
91 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) | |
75 | _delay_(500000); |
|
92 | _delay_(500000); | |
76 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 |
|
93 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 | |
77 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 |
|
94 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 | |
78 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 |
|
95 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 | |
79 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 |
|
96 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 | |
80 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 |
|
97 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 | |
81 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 |
|
98 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 | |
82 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 |
|
99 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 | |
83 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 |
|
100 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 | |
84 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 |
|
101 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 | |
85 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 |
|
102 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 | |
86 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) |
|
103 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) | |
87 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h) |
|
104 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, 240 - 1); // Window Horizontal RAM Address End (R51h) | |
88 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) |
|
105 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) | |
89 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h) |
|
106 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, 320 - 1); // Window Vertical RAM Address End (R53h) | |
90 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) |
|
107 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) | |
91 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE |
|
108 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE | |
92 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) |
|
109 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) | |
93 | // Display On |
|
110 | // Display On | |
94 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) |
|
111 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) | |
95 | _delay_(500000); |
|
112 | _delay_(500000); | |
96 |
LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x10 |
|
113 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1018); | |
97 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); |
|
114 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); | |
98 | //ili9328WriteCmd(ILI9328_REGISTER_WRITEDATATOGRAM); |
|
115 | //ili9328WriteCmd(ILI9328_REGISTER_WRITEDATATOGRAM); | |
99 | } |
|
116 | } | |
100 | return 0; |
|
117 | return 0; | |
101 | } |
|
118 | } | |
102 |
|
119 | |||
103 |
|
120 |
General Comments 0
You need to be logged in to leave comments.
Login now