aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/SAMA/SAMA5D2x/sama_lcdc.h
blob: 4a92370248edee92ac8eb5aa4c14b6e28a86be67 (plain)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
    ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

/**
 * @file    SAMA5D2x/sama_lcdc.h
 * @brief   SAMA LCDC support macros and structures.
 *
 * @addtogroup SAMA5D2x_LCDC
 * @{
 */

#ifndef SAMA_LCDC_LLD_H
#define SAMA_LCDC_LLD_H

/**
 * @brief   Using the LCDC driver.
 */
#if !defined(SAMA_USE_LCDC) || defined(__DOXYGEN__)
#define SAMA_USE_LCDC                          FALSE
#endif

#if (SAMA_USE_LCDC) || defined(__DOXYGEN__)

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

/**
 * @name    LCDC ID LAYERS
 * @{
 */
/* LCD controller ID, no display, configuration ONLY */
#define LCDD_CONTROLLER     0

/* LCD base layer, display fixed size image */
#define LCDD_BASE           1

/* LCD Overlay 1 */
#define LCDD_OVR1           2

/* LCD Overlay 2 */
#define LCDD_OVR2           4

/* LCD HighEndOverlay, support resize */
#define LCDD_HEO            3

/* LCD Cursor, max size 128x128 */
#define LCDD_CUR            6
/** @} */

/**
 * @name    BPP MODE
 * @{
 */
#define   LCDC_CFG_RGBMODE_12BPP_RGB_444          (0x0u << 4)
#define   LCDC_CFG_RGBMODE_16BPP_ARGB_4444        (0x1u << 4)
#define   LCDC_CFG_RGBMODE_16BPP_RGBA_4444        (0x2u << 4)
#define   LCDC_CFG_RGBMODE_16BPP_RGB_565          (0x3u << 4)
#define   LCDC_CFG_RGBMODE_16BPP_TRGB_1555        (0x4u << 4)
#define   LCDC_CFG_RGBMODE_18BPP_RGB_666          (0x5u << 4)
#define   LCDC_CFG_RGBMODE_18BPP_RGB_666PACKED    (0x6u << 4)
#define   LCDC_CFG_RGBMODE_19BPP_TRGB_1666        (0x7u << 4)
#define   LCDC_CFG_RGBMODE_19BPP_TRGB_PACKED      (0x8u << 4)
#define   LCDC_CFG_RGBMODE_24BPP_RGB_888          (0x9u << 4)
#define   LCDC_CFG_RGBMODE_24BPP_RGB_888_PACKED   (0xAu << 4)
#define   LCDC_CFG_RGBMODE_25BPP_TRGB_1888        (0xBu << 4)
#define   LCDC_CFG_RGBMODE_32BPP_ARGB_8888        (0xCu << 4)
#define   LCDC_CFG_RGBMODE_32BPP_RGBA_8888        (0xDu << 4)
/** @} */

/*===========================================================================*/
/* Driver pre-compile time settings.                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Derived constants and error checks.                                       */
/*===========================================================================*/
/**
 * @brief   LCDC_USE_WAIT.
 */
#if !defined(LCDC_USE_WAIT) || defined(__DOXYGEN__)
#define LCDC_USE_WAIT                         FALSE
#endif

/**
 * @brief   LCDC_USE_MUTUAL_EXCLUSION.
 */
#if !defined(LCDC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
#define LCDC_USE_MUTUAL_EXCLUSION             FALSE
#endif

/*===========================================================================*/
/* Driver data structures and types.                                         */
/*===========================================================================*/

/**
 * @brief   Driver state machine possible states.
 */
typedef enum {
  LCDC_UNINIT   = 0,                /**< Not initialized.*/
  LCDC_STOP     = 1,                /**< Stopped.*/
  LCDC_READY    = 2,                /**< Ready.*/
  LCDC_ACTIVE   = 3,                /**< Executing commands.*/
} lcdcstate_t;

/**
 * @brief   Type of a structure representing an LCDC driver.
 */
typedef struct LCDCDriver LCDCDriver;

/**
 * @brief   LCD display layer information.
 */
typedef struct {
  /**
   * @brief   Display image buffer.
   */
  void                      *buffer;
  /**
   * @brief   Display image width.
   */
  uint16_t                  width;
  /**
   * @brief   Display image height.
   */
  uint16_t                  height;
  /**
   * @brief   Display image x position.
   */
  uint16_t                  x_pos;
  /**
   * @brief   Display image y_pos.
   */
  uint16_t                  y_pos;
  /**
   * @brief   Horizontal image Size in Memory.
   */
  uint16_t                  w_img;
  /**
   * @brief   Vertical image Size in Memory.
   */
  uint16_t                  h_img;
  /**
   * @brief   BPP mode.
   */
  uint8_t                   bpp;
  /**
   * @brief   Layer ID.
   */
  uint8_t                   layer_id;
} LCDCLayerConfig;

/**
 * @brief   Driver LCD configuration structure.
 */
typedef struct {
  /**
   * @brief   Display image width.
   */
  uint16_t                  width;
  /**
   * @brief   Display image height.
   */
  uint16_t                  height;
  /**
   * @brief   Frame rate in Hz.
   */
  uint8_t                   framerate;
  /**
   * @brief   Vertical front porch in number of lines.
   */
  uint8_t                   timing_vfp;
  /**
   * @brief   Vertical back porch in number of lines.
   */
  uint8_t                   timing_vbp;
  /**
   * @brief   Vertical pulse width in number of lines.
   */
  uint8_t                   timing_vpw;
  /**
   * @brief   Horizontal front porch in LCDDOTCLK cycles.
   */
  uint8_t                   timing_hfp;
  /**
   * @brief   Horizontal back porch in LCDDOTCLK cycles.
   */
  uint8_t                   timing_hbp;
  /**
   * @brief   Horizontal pulse width in LCDDOTCLK cycles.
   */
  uint8_t                   timing_hpw;
  /**
   * @brief lenght of LCDCLayerConfig array
   * @note  Number of layers to configure
   */
  size_t                    length;
  /**
   * @brief pointer to LCDCLayerConfig array
   */
  LCDCLayerConfig           *listp;
} LCDCConfig;

/**
 * @brief   Structure representing an LCDC driver.
 */
struct LCDCDriver {
  /**
   * @brief   Driver state.
   */
  lcdcstate_t               state;
  /**
   * @brief   Current configuration lcd data.
   */
  const LCDCConfig          *config;
  /**
   * @brief   Pointer to the LCDC registers block.
   */
  Lcdc                      *lcdc;
  /* Multithreading stuff.*/
#if (LCDC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
  thread_t          *thread;
#endif  /* LCDC_USE_WAIT */
#if (LCDC_USE_MUTUAL_EXCLUSION == TRUE)
#if (CH_CFG_USE_MUTEXES == TRUE)
  mutex_t           lock;
#elif (CH_CFG_USE_SEMAPHORES == TRUE)
  semaphore_t       lock;
#endif
#endif  /* LCDC_USE_MUTUAL_EXCLUSION */
};

/*===========================================================================*/
/* Driver macros.                                                            */
/*===========================================================================*/

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

extern LCDCDriver LCDCD0;

#ifdef __cplusplus
extern "C" {
#endif
  void lcdcObjectInit(LCDCDriver *lcdcp);
  void lcdcInit(void);
  void lcdcStart(LCDCDriver *lcdcp, const LCDCConfig *configp);
  void lcdcStop(LCDCDriver *lcdcp);
  void lcdcShowLayer(LCDCDriver *lcdcp, uint8_t id, bool enable);
  void lcdcSetBacklight(uint32_t level);
#if (LCDC_USE_MUTUAL_EXCLUSION)
  void lcdcAcquireBusS(LCDCDriver *lcdcp);
  void lcdcAcquireBus(LCDCDriver *lcdcp);
  void lcdcReleaseBusS(LCDCDriver *lcdcp);
  void lcdcReleaseBus(LCDCDriver *lcdcp);
#endif  /* LCDC_USE_MUTUAL_EXCLUSION */

#ifdef __cplusplus
}
#endif

#endif /* SAMA_USE_LCDC */

#endif /* SAMA_LCDC_LLD_H */

/** @} */