STM32 V5 source code
guowenxue
2018-05-16 8a8715e9d87d63c5908f8e00d1b5fe3595e41c41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* ----------------------------------------------------------------------------
 *         SAM Software Package License
 * ----------------------------------------------------------------------------
 * Copyright (c) 2011, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */
 
/**
 * \file
 *
 * Interface of R61509V driver.
 *
 */
 
#ifndef __LCD_R61509V_H
#define __LCD_R61509V_H
 
/*----------------------------------------------------------------------------
 *        Headers
 *----------------------------------------------------------------------------*/
 
 
#include <stdint.h>
typedef uint16_t LcdColor_t ;
 
 
/*----------------------------------------------------------------------------
 *        Definitions
 *----------------------------------------------------------------------------*/
 
 /* LCDµÄCSÁ¬µÄPD7(NE1),ËùÒÔÎÒÃÇʹÓõÄÊÇNorflashµÄBank1,µØÖ··¶Î§Îª0X60000000~0X63FFFFFF
 * LCDµÄRS(¼Ä´æÆ÷/Êý¾ÝÑ¡Ôñ½Å)Á¬PD11(FSMC_A16),ÕâÑùµ±A16Ϊ¸ßµçƽʱ¾ÍÊÇÊý¾Ý¼Ä´æÆ÷£¬µÍµçƽÔòΪÃüÁî¼Ä´æÆ÷
 * ËùÒÔÊý¾Ý¼Ä´æÆ÷µÄµØÖ·Îª: 0x6000 0000 |= 1<<16 ==> 0x6001 0000(¸ÃֵΪ8λģʽϵÄ×Ö½ÚµØÖ·)
 * ÓÉÓÚÎÒÃDzÉÓõÄÊÇ16λÊý¾ÝÏߣ¬FSMC[24:0]ÓëHADDR[25:1](AHBµØÖ·)¶ÔÆë£¬ÕâÑùHADDRÒª×óÒÆÒ»Î»²ÅÊÇFSMCµÄ·ÃÎʵØÖ·;    
 * Òò´ËΪÁ˰ÑFSMCÖеÄFSMC_A16ÖÃ1£¬Êµ¼ÊÉÏÒª¶ÔÓ¦µ½HADDRµØÖ·µÄHADDR_A17£¬¼´0x6002 0000
 */
#define Bank1_LCD_DAT    ((uint32_t)0x60020000)  //ÏÔÊ¾ÇøÊý¾ÝµØÖ·      
#define Bank1_LCD_CMD    ((uint32_t)0x60000000)     //ÏÔÊ¾ÇøÖ¸ÁîµØÖ·
 
#define LCD_RST   (1<<0)                   // PE1-LCD-RST 
#define LCD_RST_SET(x) GPIOE->ODR=(GPIOE->ODR&~LCD_RST)|(x ? LCD_RST : 0)
 
#define BOARD_LCD_WIDTH  240
#define BOARD_LCD_HEIGHT 400
 
#define MODE_BGR         0
#define MODE_RGB         1
 
/* color definition */
#define COLOR_RED                 0XF800
#define COLOR_GREEN            0X07E0
#define COLOR_BLUE             0X001F  
#define COLOR_BRED             0XF81F
#define COLOR_GRED             0XFFE0
#define COLOR_GBLUE            0X07FF
#define COLOR_BLACK            0X0000
#define COLOR_WHITE            0XFFFF
#define COLOR_PURPUE           0XA294
 
 
/* R61509V ID code */
#define R61509V_DEVICE_CODE    0xB509  /* The device code ¡°B509¡±H is read out when this register is read forcibly.  */
 
/* R61509V LCD Registers */
#define R61509V_R000H    0x000    /* Device Code Read                 */
#define R61509V_R001H    0x001    /* Driver Output Control 1          */
#define R61509V_R001H_SS                ((uint16_t)0x0100)
#define R61509V_R001H_SM                ((uint16_t)0x0400)
#define R61509V_R002H    0x002    /* LCD Drive Waveform Contro        */
#define R61509V_R003H    0x003    /* Entry Mode                       */
#define R61509V_R003H_AM                ((uint16_t)0x0008) /* AM Control the GRAM update direction */
#define R61509V_R003H_ID0               ((uint16_t)0x0010) /* I/D[1:0] Control the address counter  */
#define R61509V_R003H_ID1               ((uint16_t)0x0020)
#define R61509V_R003H_ORG               ((uint16_t)0x0080)
#define R61509V_R003H_BGR               ((uint16_t)0x1000)
#define R61509V_R003H_DFM               ((uint16_t)0x4000)
#define R61509V_R003H_TRI               ((uint16_t)0x8000)
#define R61509V_R007H    0x007    /* Display Control 1                */
#define R61509V_R007H_BASEE             ((uint16_t)0x0100)
#define R61509V_R007H_PTDE              ((uint16_t)0x1000)
 
#define R61509V_R008H    0x008    /* Display Control 2                */
#define R61509V_R009H    0x009    /* Display Control 3                */
 
#define R61509V_R010H    0x010    /* Panel Interface Control  1       */
#define R61509V_R011H    0x011    /* Panel Interface Control  2       */
#define R61509V_R012H    0x012    /* Panel Interface Control  3       */
#define R61509V_R013H    0x013    /* Panel Interface Control  4       */
#define R61509V_R014H    0x014    /* Panel Interface Control  5       */
 
#define R61509V_R00CH    0x00C    /* External Display Interface Control 1  */
#define R61509V_R00FH    0x00F    /* External Display Interface Control 2  */
#define R61509V_R090H    0x090    /* Frame Marker Control */
 
#define R61509V_R100H    0x100    /* Power Control Control 1 */
#define R61509V_R101H    0x101    /* Power Control Control 2 */
#define R61509V_R102H    0x102    /* Power Control Control 3 */
#define R61509V_R102H_PON               ((uint16_t)0x0010)
#define R61509V_R102H_PSON              ((uint16_t)0x0020)
#define R61509V_R103H    0x103    /* Power Control Control 4 */
 
#define R61509V_R200H    0x200    /* Horizontal GRAM Address Set  */
#define R61509V_R201H    0x201    /* Vertical  GRAM Address Set   */
#define R61509V_R202H    0x202    /* GRAM Data Write/Read         */
 
#define R61509V_R210H    0x210    /* Window Horizontal Address Start Position */
#define R61509V_R211H    0x211    /* Window Horizontal Address End Position   */
#define R61509V_R212H    0x212    /* Window Vertical Address Start Position   */
#define R61509V_R213H    0x213    /* Window Vertical Address End Position     */
 
#define R61509V_R300H    0x300    /* Gamma Control 1  */
#define R61509V_R301H    0x301    /* Gamma Control 2  */
#define R61509V_R302H    0x302    /* Gamma Control 3  */
#define R61509V_R303H    0x303    /* Gamma Control 4  */
#define R61509V_R304H    0x304    /* Gamma Control 5  */
#define R61509V_R305H    0x305    /* Gamma Control 6  */
#define R61509V_R306H    0x306    /* Gamma Control 7  */
#define R61509V_R307H    0x307    /* Gamma Control 8  */
#define R61509V_R308H    0x308    /* Gamma Control 9  */
#define R61509V_R309H    0x309    /* Gamma Control 10 */
 
#define R61509V_R280H    0x280    /* NVM Data Read / write */
 
#define R61509V_R400H    0x400    /* Base Image Number of Line   */
#define R61509V_R400H_GS                ((uint16_t)0x8000)
#define R61509V_R401H    0x401    /* Base Image Display Control */
#define R61509V_R404H    0x404    /* Base Image Vertical Scroll Control    */
 
#define R61509V_R500H    0x500    /* Partial Image 1 Display Position  */
#define R61509V_R501H    0x501    /* RAM Address 1(Start Line Address) */
#define R61509V_R502H    0x502    /* RAM Address 2(End Line Address)   */
 
 
 
/*----------------------------------------------------------------------------
 *        Types
 *----------------------------------------------------------------------------*/
 
typedef volatile uint16_t REG16;
 
/*----------------------------------------------------------------------------
 *        Marcos
 *----------------------------------------------------------------------------*/
 
/** LCD index register address */
#define LCD_IR() (*((REG16 *)(Bank1_LCD_CMD)))
 
/** LCD data address */
#define LCD_D()  (*((REG16 *)(Bank1_LCD_DAT)))
 
#ifdef __cplusplus
 extern "C" {
#endif
/*----------------------------------------------------------------------------
 *        Exported functions
 *----------------------------------------------------------------------------*/
extern void LCD_WriteReg( uint16_t reg, uint16_t data );
extern uint16_t LCD_ReadReg( uint16_t reg );
extern void LCD_WriteRAM_Prepare( void );
extern void LCD_WriteRAM( LcdColor_t dwColor );
extern void LCD_ReadRAM_Prepare( void );
extern void LCD_WriteRAMWord( uint16_t wColor );
extern uint32_t LCD_ReadRAM( void );
extern uint32_t LCD_Initialize( void );
extern void LCD_On( void );
extern void LCD_Off( void );
extern void LCD_PowerDown( void );
extern uint32_t LCD_SetColor(uint32_t dwRgb24Bits);
extern void LCD_SetCursor( uint16_t x, uint16_t y );
extern void LCD_SetWindow( uint32_t dwX, uint32_t dwY, uint32_t dwWidth, uint32_t dwHeight );
extern void LCD_SetDisplayLandscape( uint32_t dwRGB );
extern void LCD_SetDisplayPortrait( uint16_t wRGB );
extern void LCD_VerticalScroll( uint16_t wY );
extern void LCD_SetPartialImage1( uint32_t dwDisplayPos, uint32_t dwStart, uint32_t dwEnd );
extern uint32_t LCD_DrawPixel( uint32_t x, uint32_t y );
extern void LCD_TestPattern( uint32_t dwRGB );
extern uint32_t LCD_DrawFilledRectangle( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 );
extern uint32_t LCD_DrawPicture( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2, const LcdColor_t *pBuffer );
extern uint32_t LCD_DrawLine ( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 );
extern uint32_t LCD_DrawCircle( uint32_t dwX, uint32_t dwY, uint32_t dwR );
extern uint32_t LCD_DrawFilledCircle( uint32_t dwX, uint32_t dwY, uint32_t dwRadius);
extern uint32_t LCD_DrawRectangle( uint32_t dwX1, uint32_t dwY1, uint32_t dwX2, uint32_t dwY2 );
extern void LCD_SetBacklight (uint32_t level);
#ifdef __cplusplus
}
#endif
#endif /* #ifndef R61509V */