1  /*************************************************************************//**
2  * @file dmd_ssd2119.h
3  * @brief Dot matrix display driver for LCD controller SSD2119
4  * @author Energy Micro AS
5  ******************************************************************************
6  * @section License
7  * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
8  ******************************************************************************
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not
15  *    claim that you wrote the original software.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  *    misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  * 4. The source and compiled code may only be used on Energy Micro "EFM32"
20  *    microcontrollers and "EFR4" radios.
21  *
22  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
23  * obligation to support this Software. Energy Micro AS is providing the
24  * Software "AS IS", with no express or implied warranties of any kind,
25  * including, but not limited to, any implied warranties of merchantability
26  * or fitness for any particular purpose or warranties against infringement
27  * of any proprietary rights of a third party.
28  *
29  * Energy Micro AS will not be liable for any consequential, incidental, or
30  * special damages, or any other relief, or for any claim by any third party,
31  * arising from your use of this Software.
32  *
33  *****************************************************************************/
34 
35 #ifndef __DMD_SSD2119_H
36 #define __DMD_SSD2119_H
37 
38 #include <stdint.h>
39 #include "graphics/em_types.h"
40 /* TODO: remove this and replace with include types and ecodes */
41 #define ECODE_DMD_BASE    0x00000000
42 
43 
44 /* Error codes */
45 /** Successful call */
46 #define DMD_OK                                  0x00000000
47 /** Driver not initialized correctly */
48 #define DMD_ERROR_DRIVER_NOT_INITIALIZED        (ECODE_DMD_BASE | 0x0001)
49 /** Driver is already initialized */
50 #define DMD_ERROR_DRIVER_ALREADY_INITIALIZED    (ECODE_DMD_BASE | 0x0002)
51 /** Length of data is larger than size of clip */
52 #define DMD_ERROR_TOO_MUCH_DATA                 (ECODE_DMD_BASE | 0x0003)
53 /** Pixel is outside current clipping area */
54 #define DMD_ERROR_PIXEL_OUT_OF_BOUNDS           (ECODE_DMD_BASE | 0x0004)
55 /** Clipping area is empty */
56 #define DMD_ERROR_EMPTY_CLIPPING_AREA           (ECODE_DMD_BASE | 0x0005)
57 /** Wrong device code */
58 #define DMD_ERROR_WRONG_DEVICE_CODE             (ECODE_DMD_BASE | 0x0006)
59 /** Memory error */
60 #define DMD_ERROR_MEMORY_ERROR                  (ECODE_DMD_BASE | 0x0007)
61 /** Error code expected, but didn't happen */
62 #define DMD_ERROR_NO_ERROR_CODE                 (ECODE_DMD_BASE | 0x0008)
63 /** Test run failed */
64 #define DMD_ERROR_TEST_FAILED                   (ECODE_DMD_BASE | 0x0009)
65 
66 
67 /** Frame update frequency of display */
68 #define DMD_FRAME_FREQUENCY    80
69 /** Horizontal size of the display */
70 #define DMD_HORIZONTAL_SIZE    320
71 /** Vertical size of the display */
72 #define DMD_VERTICAL_SIZE      240
73 
74 /* Tests */
75 /** Device code test */
76 #define DMD_TEST_DEVICE_CODE         0x00000001
77 /** Memory test */
78 #define DMD_TEST_MEMORY              0x00000002
79 /** Parameter checks test */
80 #define DMD_TEST_PARAMETER_CHECKS    0x00000004
81 /** Color test */
82 #define DMD_TEST_COLORS              0x00000008
83 /** Clipping test */
84 #define DMD_TEST_CLIPPING            0x00000010
85 
86 #define DMD_MEMORY_TEST_WIDTH        4
87 #define DMD_MEMORY_TEST_HEIGHT       3
88 
89 /** @struct __DMD_DisplayGeometry
90  *  @brief Dimensions of the display
91  */
92 typedef struct __DMD_DisplayGeometry
93 {
94   /** Horizontal size of the display, in pixels */
95   uint16_t xSize;
96   /** Vertical size of the display, in pixels */
97   uint16_t ySize;
98   /** X coordinate of the top left corner of the clipping area */
99   uint16_t xClipStart;
100   /** Y coordinate of the top left corner of the clipping area */
101   uint16_t yClipStart;
102   /** Width of the clipping area */
103   uint16_t clipWidth;
104   /** Height of the clipping area */
105   uint16_t clipHeight;
106 } DMD_DisplayGeometry; /**< Typedef for display dimensions */
107 
108 /** @struct __DMD_MemoryError
109  *  @brief Information about a memory error
110  */
111 typedef struct __DMD_MemoryError
112 {
113   /** X coordinate of the address where the error happened */
114   uint16_t x;
115   /** Y coordinate of the address where the error happened */
116   uint16_t y;
117   /** The color that was written to the memory address */
118   uint8_t  writtenColor[3];
119   /** The color that was read from the memory address */
120   uint8_t  readColor[3];
121 } DMD_MemoryError; /**< Typedef for memory error information */
122 
123 /* Module prototypes */
124 EMSTATUS DMD_init(uint32_t cmdRegAddr, uint32_t dataRegAddr);
125 EMSTATUS DMD_getDisplayGeometry(DMD_DisplayGeometry **geometry);
126 EMSTATUS DMD_setClippingArea(uint16_t xStart, uint16_t yStart,
127                              uint16_t width, uint16_t height);
128 EMSTATUS DMD_writeData(uint16_t x, uint16_t y,
129                        const uint8_t data[], uint32_t numPixels);
130 EMSTATUS DMD_writeDataRLE(uint16_t x, uint16_t y, uint16_t xlen, uint16_t ylen,
131                           const uint8_t *data);
132 EMSTATUS DMD_writeDataRLEFade(uint16_t x, uint16_t y, uint16_t xlen, uint16_t ylen,
133                   const uint8_t *data,
134                   int red, int green, int blue, int weight);
135 EMSTATUS DMD_readData(uint16_t x, uint16_t y,
136                       uint8_t data[], uint32_t numPixels);
137 EMSTATUS DMD_writeColor(uint16_t x, uint16_t y, uint8_t red,
138                         uint8_t green, uint8_t blue, uint32_t numPixels);
139 EMSTATUS DMD_writePixel(uint16_t x, uint16_t y, uint16_t color,
140                         uint32_t numPixels);
141 EMSTATUS DMD_readPixel(uint16_t x, uint16_t y, uint16_t *color);
142 EMSTATUS DMD_sleep(void);
143 EMSTATUS DMD_wakeUp(void);
144 
145 /* Test functions */
146 EMSTATUS DMD_testParameterChecks(void);
147 EMSTATUS DMD_testMemory(uint16_t x, uint16_t y,
148                         uint32_t useClipWrite, uint32_t useClipRead,
149                         DMD_MemoryError *memoryError);
150 EMSTATUS DMD_testMemory2(uint16_t x, uint16_t y,
151                          uint32_t useClipWrite);
152 EMSTATUS DMD_testDeviceCode(void);
153 EMSTATUS DMD_testColors(uint32_t delay);
154 EMSTATUS DMD_testClipping(void);
155 EMSTATUS DMD_runTests(uint32_t tests, uint32_t *result);
156 
157 EMSTATUS DMD_flipDisplay(int horizontal, int vertical);
158 
159 #endif
160