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