1 | /*
|
---|
2 | * TOPPERS/ASP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Advanced Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2008-2011 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
8 | * Copyright (C) 2015-2017 by TOPPERS PROJECT Educational Working Group.
|
---|
9 | *
|
---|
10 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
11 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
12 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
13 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
14 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
15 | * スコード中に含まれていること.
|
---|
16 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
17 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
18 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
19 | * の無保証規定を掲載すること.
|
---|
20 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
21 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
22 | * と.
|
---|
23 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
24 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
25 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
26 | * 報告すること.
|
---|
27 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
28 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
29 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
30 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
31 | * 免責すること.
|
---|
32 | *
|
---|
33 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
34 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
35 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
36 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
37 | * の責任を負わない.
|
---|
38 | *
|
---|
39 | * @(#) $Id$
|
---|
40 | */
|
---|
41 | /*
|
---|
42 | * STM32F746-LTDC用デバイスドライバ
|
---|
43 | */
|
---|
44 | #include "kernel_impl.h"
|
---|
45 | #include <t_syslog.h>
|
---|
46 | #include <t_stdlib.h>
|
---|
47 | #include <sil.h>
|
---|
48 | #include <target_syssvc.h>
|
---|
49 | #include "kernel_cfg.h"
|
---|
50 | #include "device.h"
|
---|
51 | #include "ltdc.h"
|
---|
52 |
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * SIL関数のマクロ定義
|
---|
56 | */
|
---|
57 | #define sil_orw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) | (b))
|
---|
58 | #define sil_andw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) & ~(b))
|
---|
59 | #define sil_modw_mem(a, b, c) sil_wrw_mem((a), (sil_rew_mem(a) & (~b)) | (c))
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * AF 9セクション定義
|
---|
63 | */
|
---|
64 | #define GPIO_AF9_CAN1 0x09 /* CAN1 Alternate Function mapping */
|
---|
65 | #define GPIO_AF9_CAN2 0x09 /* CAN2 Alternate Function mapping */
|
---|
66 | #define GPIO_AF9_TIM12 0x09 /* TIM12 Alternate Function mapping */
|
---|
67 | #define GPIO_AF9_TIM13 0x09 /* TIM13 Alternate Function mapping */
|
---|
68 | #define GPIO_AF9_TIM14 0x09 /* TIM14 Alternate Function mapping */
|
---|
69 | #define GPIO_AF9_QUADSPI 0x09 /* QUADSPI Alternate Function mapping */
|
---|
70 | #define GPIO_AF9_LTDC 0x09 /* LCD-TFT Alternate Function mapping */
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * AF 14セクション定義
|
---|
74 | */
|
---|
75 | #define GPIO_AF14_LTDC 0x0E /* LCD-TFT alternate functionマップ値 */
|
---|
76 |
|
---|
77 | #define PLLSAI_TIMEOUT_VALUE (100*1000)
|
---|
78 |
|
---|
79 | #define RCC_PLLSAICFGR_PLLSAIQ_POS 24
|
---|
80 | #define RCC_PLLSAICFGR_PLLSAIP_POS 16
|
---|
81 |
|
---|
82 | #ifdef TOPPERS_STM32F7_DISCOVERY
|
---|
83 | static const GPIO_Init_Table ltdc_gpio_table[] = {
|
---|
84 | {TADR_GPIOG_BASE, (GPIO_PIN_12) },
|
---|
85 | {TADR_GPIOE_BASE, (GPIO_PIN_4) },
|
---|
86 | {TADR_GPIOI_BASE, (GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15 ) },
|
---|
87 | {TADR_GPIOJ_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | \
|
---|
88 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \
|
---|
89 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15) },
|
---|
90 | {TADR_GPIOK_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7) }
|
---|
91 | };
|
---|
92 |
|
---|
93 | #define NUM_LTDC_GPIO_ITEM (sizeof(ltdc_gpio_table)/sizeof(GPIO_Init_Table))
|
---|
94 |
|
---|
95 | /*
|
---|
96 | * LTDC GPIOの初期化
|
---|
97 | */
|
---|
98 | static void
|
---|
99 | ltdc_gpio_init(void)
|
---|
100 | {
|
---|
101 | GPIO_Init_t GPIO_Init_Data;
|
---|
102 | int i, pin;
|
---|
103 | volatile uint32_t tmp;
|
---|
104 |
|
---|
105 | /* LTDCクロック許可 */
|
---|
106 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB2ENR), RCC_APB2ENR_LTDCEN);
|
---|
107 | tmp = sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB2ENR));
|
---|
108 |
|
---|
109 | /* LTDC用GPIOのクロック設定 */
|
---|
110 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR),
|
---|
111 | RCC_AHB1ENR_GPIOEEN | RCC_AHB1ENR_GPIOGEN
|
---|
112 | | RCC_AHB1ENR_GPIOIEN | RCC_AHB1ENR_GPIOJEN
|
---|
113 | | RCC_AHB1ENR_GPIOKEN);
|
---|
114 | tmp = sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR));
|
---|
115 | (void)(tmp);
|
---|
116 |
|
---|
117 | /* LTDC用GPIOの初期化パラメータ設定 */
|
---|
118 | GPIO_Init_Data.mode = GPIO_MODE_AF;
|
---|
119 | GPIO_Init_Data.pull = GPIO_NOPULL;
|
---|
120 | GPIO_Init_Data.otype = GPIO_OTYPE_PP;
|
---|
121 | GPIO_Init_Data.speed = GPIO_SPEED_FAST;
|
---|
122 | GPIO_Init_Data.alternate = GPIO_AF9_LTDC;
|
---|
123 |
|
---|
124 | for(i = 0 ; i < NUM_LTDC_GPIO_ITEM ; i++){
|
---|
125 | for(pin = 0 ; pin < 16 ; pin++){
|
---|
126 | if((ltdc_gpio_table[i].pinmap & 1<<pin) != 0)
|
---|
127 | gpio_setup(ltdc_gpio_table[i].base, &GPIO_Init_Data, pin);
|
---|
128 | }
|
---|
129 | GPIO_Init_Data.alternate = GPIO_AF14_LTDC;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* LCD表示用GPIOの設定 */
|
---|
133 | GPIO_Init_Data.mode = GPIO_MODE_OUTPUT;
|
---|
134 | gpio_setup(TADR_GPIOI_BASE, &GPIO_Init_Data, PINPOSITION12);
|
---|
135 | gpio_setup(TADR_GPIOK_BASE, &GPIO_Init_Data, PINPOSITION3);
|
---|
136 |
|
---|
137 | /* 表示許可LCD_DISPピンをアサート */
|
---|
138 | sil_wrw_mem((uint32_t *)(TADR_GPIOI_BASE+TOFF_GPIO_BSRR), GPIO_PIN_12);
|
---|
139 |
|
---|
140 | /* バックライトLCD_BL_CTRLピンをアサート */
|
---|
141 | sil_wrw_mem((uint32_t *)(TADR_GPIOK_BASE+TOFF_GPIO_BSRR), GPIO_PIN_3);
|
---|
142 | }
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | /*
|
---|
146 | * LTDCのレイヤーのハードウェア初期設定する
|
---|
147 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
148 | * parameter2 pLayerCfg レイヤーの初期設定構造体のポインタ
|
---|
149 | * parameter3 LaerIdx レイヤー番号
|
---|
150 | * return 正常ならばE_OK
|
---|
151 | */
|
---|
152 | static void
|
---|
153 | LTDC_SetConfig(LTDC_Handle_t *phandle, LTDC_LayerCfg_t *pLayerCfg, uint32_t LayerIdx)
|
---|
154 | {
|
---|
155 | uint32_t layer = TADR_LTDC_LAYER1+LayerIdx*LTDC_WINDOW_SIZE;
|
---|
156 | uint32_t bpcr = sil_rew_mem((uint32_t *)(phandle->base+TOFF_LTDC_BPCR));
|
---|
157 | uint32_t tmp = 0;
|
---|
158 |
|
---|
159 | /* 水平方向スタートストップ位置設定 */
|
---|
160 | tmp = (pLayerCfg->WindowX1 + ((bpcr & LTDC_BPCR_AHBP) >> 16)) << 16;
|
---|
161 | tmp |= (pLayerCfg->WindowX0 + ((bpcr & LTDC_BPCR_AHBP) >> 16) + 1);
|
---|
162 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_WHPCR), tmp);
|
---|
163 |
|
---|
164 | /* 垂直方向スタートストップ位置設定 */
|
---|
165 | tmp = (pLayerCfg->WindowY1 + (bpcr & LTDC_BPCR_AVBP)) << 16;
|
---|
166 | tmp |= (pLayerCfg->WindowY0 + (bpcr & LTDC_BPCR_AVBP) + 1);
|
---|
167 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_WVPCR), tmp);
|
---|
168 |
|
---|
169 | /* ピクセルフォーマットの指定 */
|
---|
170 | sil_modw_mem((uint32_t *)(layer+TOFF_LTDCW_PFCR), LTDC_PFCR_PF, pLayerCfg->PixelFormat);
|
---|
171 |
|
---|
172 | /* デフォルトのカラー値を設定 */
|
---|
173 | tmp = pLayerCfg->Backcolor.Blue;
|
---|
174 | tmp |= pLayerCfg->Backcolor.Green << 8;
|
---|
175 | tmp |= pLayerCfg->Backcolor.Red << 16;
|
---|
176 | tmp |= pLayerCfg->Alpha0 << 24;
|
---|
177 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_DCCR), tmp);
|
---|
178 |
|
---|
179 | /* アルファ値を設定 */
|
---|
180 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_CACR), pLayerCfg->Alpha);
|
---|
181 |
|
---|
182 | /* ブランディングファクターを設定 */
|
---|
183 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_BFCR), (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2));
|
---|
184 |
|
---|
185 | /* フレームバッファアドレスを設定 */
|
---|
186 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_CFBAR), pLayerCfg->FBStartAdress);
|
---|
187 |
|
---|
188 | /* バイト中のカラーフレームピッチの設定 */
|
---|
189 | if(pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
|
---|
190 | tmp = 4;
|
---|
191 | else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
|
---|
192 | tmp = 3;
|
---|
193 | else if((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) ||
|
---|
194 | (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565) ||
|
---|
195 | (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) ||
|
---|
196 | (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
|
---|
197 | tmp = 2;
|
---|
198 | else
|
---|
199 | tmp = 1;
|
---|
200 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_CFBLR), (((pLayerCfg->ImageWidth * tmp) << 16) | (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp) + 3)));
|
---|
201 |
|
---|
202 | /* フレームバッファライン数を設定 */
|
---|
203 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_CFBLNR), pLayerCfg->ImageHeight);
|
---|
204 |
|
---|
205 | /* LTDCレイヤーを許可 */
|
---|
206 | sil_orw_mem((uint32_t *)(layer+TOFF_LTDCW_CR), LTDC_CR_LEN);
|
---|
207 | }
|
---|
208 |
|
---|
209 | /*
|
---|
210 | * LTDCのウインドウのアルファ値を設定する
|
---|
211 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
212 | * parameter2 Alpha ウインドウアルファ値
|
---|
213 | * parameter3 LaerIdx レイヤー番号
|
---|
214 | * return 正常ならばE_OK
|
---|
215 | */
|
---|
216 | ER
|
---|
217 | ltdc_setalpha(LTDC_Handle_t *phandle, uint32_t Alpha, uint32_t LayerIdx)
|
---|
218 | {
|
---|
219 | LTDC_LayerCfg_t *pLayerCfg;
|
---|
220 |
|
---|
221 | if(LayerIdx >= MAX_LAYER)
|
---|
222 | return E_PAR;
|
---|
223 | if(Alpha > 511)
|
---|
224 | return E_PAR;
|
---|
225 |
|
---|
226 | /* レイヤーコンフィギュレーション領域のポインタ取得 */
|
---|
227 | pLayerCfg = &phandle->LayerCfg[LayerIdx];
|
---|
228 | /* ウインドウアルファ値設定 */
|
---|
229 | pLayerCfg->Alpha = Alpha;
|
---|
230 | /* LTDCレイヤー設定 */
|
---|
231 | LTDC_SetConfig(phandle, pLayerCfg, LayerIdx);
|
---|
232 | /* リロード */
|
---|
233 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
234 | return E_OK;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /*
|
---|
238 | * LTDCのフレームバッファアドレスを設定する
|
---|
239 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
240 | * parameter2 Alpha アドレス値
|
---|
241 | * parameter3 LaerIdx レイヤー番号
|
---|
242 | * return 正常ならばE_OK
|
---|
243 | */
|
---|
244 | ER
|
---|
245 | ltdc_setaddress(LTDC_Handle_t *phandle, uint32_t Address, uint32_t LayerIdx)
|
---|
246 | {
|
---|
247 | LTDC_LayerCfg_t *pLayerCfg;
|
---|
248 |
|
---|
249 | if(LayerIdx >= MAX_LAYER)
|
---|
250 | return E_PAR;
|
---|
251 |
|
---|
252 | /* レイヤーコンフィギュレーション領域のポインタ取得 */
|
---|
253 | pLayerCfg = &phandle->LayerCfg[LayerIdx];
|
---|
254 | /* フレームバッファアドレス設定 */
|
---|
255 | pLayerCfg->FBStartAdress = Address;
|
---|
256 | /* LTDCレイヤー設定 */
|
---|
257 | LTDC_SetConfig(phandle, pLayerCfg, LayerIdx);
|
---|
258 | /* リロード */
|
---|
259 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
260 | return E_OK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | /*
|
---|
264 | * LTDCのウインドウサイズ位置を設定する
|
---|
265 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
266 | * parameter2 XSize ウインドウXサイズ
|
---|
267 | * parameter3 YSize ウインドウYサイズ
|
---|
268 | * parameter4 LaerIdx レイヤー番号
|
---|
269 | * return 正常ならばE_OK
|
---|
270 | */
|
---|
271 | ER
|
---|
272 | ltdc_setwindowsize(LTDC_Handle_t *phandle, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
|
---|
273 | {
|
---|
274 | LTDC_LayerCfg_t *pLayerCfg;
|
---|
275 |
|
---|
276 | /* レイヤーコンフィギュレーション領域のポインタ取得 */
|
---|
277 | pLayerCfg = &phandle->LayerCfg[LayerIdx];
|
---|
278 | if(LayerIdx >= MAX_LAYER)
|
---|
279 | return E_PAR;
|
---|
280 | if(XSize > 8191 || YSize > 8191)
|
---|
281 | return E_PAR;
|
---|
282 |
|
---|
283 | /* ウインドウX位置設定 */
|
---|
284 | pLayerCfg->WindowX0 = 0;
|
---|
285 | pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
|
---|
286 | /* ウインドウY位置設定 */
|
---|
287 | pLayerCfg->WindowY0 = 0;
|
---|
288 | pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
|
---|
289 | /* ウインドウXサイズ設定 */
|
---|
290 | pLayerCfg->ImageWidth = XSize;
|
---|
291 | /* ウインドウYサイズ */
|
---|
292 | pLayerCfg->ImageHeight = YSize;
|
---|
293 | /* LTDCレイヤー設定 */
|
---|
294 | LTDC_SetConfig(phandle, pLayerCfg, LayerIdx);
|
---|
295 | /* リロード */
|
---|
296 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
297 | return E_OK;
|
---|
298 | }
|
---|
299 |
|
---|
300 | /*
|
---|
301 | * LTDCのウインドウ位置を設定する
|
---|
302 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
303 | * parameter2 X0 ウインドウX位置
|
---|
304 | * parameter3 Y0 ウインドウY位置
|
---|
305 | * parameter4 LaerIdx レイヤー番号
|
---|
306 | * return 正常ならばE_OK
|
---|
307 | */
|
---|
308 | ER
|
---|
309 | ltdc_setwindowposition(LTDC_Handle_t *phandle, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
|
---|
310 | {
|
---|
311 | LTDC_LayerCfg_t *pLayerCfg;
|
---|
312 |
|
---|
313 | /* レイヤーコンフィギュレーション領域のポインタ取得 */
|
---|
314 | pLayerCfg = &phandle->LayerCfg[LayerIdx];
|
---|
315 | if(LayerIdx >= MAX_LAYER)
|
---|
316 | return E_PAR;
|
---|
317 | if(X0 > 4095 || (X0+pLayerCfg->ImageWidth) > 65535)
|
---|
318 | return E_PAR;
|
---|
319 | if(Y0 > 4095 || (Y0+pLayerCfg->ImageHeight) > 65535)
|
---|
320 | return E_PAR;
|
---|
321 |
|
---|
322 | /* ウインドウX位置設定 */
|
---|
323 | pLayerCfg->WindowX0 = X0;
|
---|
324 | pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
|
---|
325 | /* ウインドウY位置設定 */
|
---|
326 | pLayerCfg->WindowY0 = Y0;
|
---|
327 | pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
|
---|
328 | /* LTDCレイヤー設定 */
|
---|
329 | LTDC_SetConfig(phandle, pLayerCfg, LayerIdx);
|
---|
330 | /* リロード */
|
---|
331 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
332 | return E_OK;
|
---|
333 | }
|
---|
334 |
|
---|
335 | /*
|
---|
336 | * カラーキーングの初期設定を行う
|
---|
337 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
338 | * parameter2 RGBvalue カラーキーイング番号
|
---|
339 | * parameter3 LaerIdx レイヤー番号
|
---|
340 | * return 正常ならばE_OK
|
---|
341 | */
|
---|
342 | ER
|
---|
343 | ltdc_configcolorkeying(LTDC_Handle_t *phandle, uint32_t RGBValue, uint32_t LayerIdx)
|
---|
344 | {
|
---|
345 | uint32_t layer = TADR_LTDC_LAYER1+LayerIdx*LTDC_WINDOW_SIZE;
|
---|
346 |
|
---|
347 | if(LayerIdx >= MAX_LAYER)
|
---|
348 | return E_PAR;
|
---|
349 |
|
---|
350 | /* カラーキーイング番号設定 */
|
---|
351 | sil_andw_mem((uint32_t *)(layer+TOFF_LTDCW_CKCR), (LTDC_CKCR_CKBLUE | LTDC_CKCR_CKGREEN | LTDC_CKCR_CKRED));
|
---|
352 | sil_wrw_mem((uint32_t *)(layer+TOFF_LTDCW_CKCR), RGBValue);
|
---|
353 | /* リロード */
|
---|
354 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
355 | return E_OK;
|
---|
356 | }
|
---|
357 |
|
---|
358 | /*
|
---|
359 | * カラーキーングを有効にする
|
---|
360 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
361 | * parameter2 LaerIdx レイヤー番号
|
---|
362 | * return 正常ならばE_OK
|
---|
363 | */
|
---|
364 | ER
|
---|
365 | ltdc_enablecolorkeying(LTDC_Handle_t *phandle, uint32_t LayerIdx)
|
---|
366 | {
|
---|
367 | if(LayerIdx >= MAX_LAYER)
|
---|
368 | return E_PAR;
|
---|
369 |
|
---|
370 | /* COLKENビットをオン */
|
---|
371 | sil_orw_mem((uint32_t *)(TADR_LTDC_LAYER1+LayerIdx*LTDC_WINDOW_SIZE+TOFF_LTDCW_CR), LTDC_CR_COLKEN);
|
---|
372 | /* リロード */
|
---|
373 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
374 | return E_OK;
|
---|
375 | }
|
---|
376 |
|
---|
377 | /*
|
---|
378 | * カラーキーングを無効にする
|
---|
379 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
380 | * parameter2 LaerIdx レイヤー番号
|
---|
381 | * return 正常ならばE_OK
|
---|
382 | */
|
---|
383 | ER
|
---|
384 | ltdc_disablecolorkeying(LTDC_Handle_t *phandle, uint32_t LayerIdx)
|
---|
385 | {
|
---|
386 | if(LayerIdx >= MAX_LAYER)
|
---|
387 | return E_PAR;
|
---|
388 |
|
---|
389 | /* COLKENビットをオフ */
|
---|
390 | sil_andw_mem((uint32_t *)(TADR_LTDC_LAYER1+LayerIdx*LTDC_WINDOW_SIZE+TOFF_LTDCW_CR), LTDC_CR_COLKEN);
|
---|
391 | /* リロード */
|
---|
392 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
393 | return E_OK;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /*
|
---|
397 | * LTDCのレイヤー設定をおこなう
|
---|
398 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
399 | * patameter2 pLayerCfg レイヤー設定構造体へのポインタ
|
---|
400 | * parameter3 LaerIdx レイヤー番号
|
---|
401 | * return 正常ならばE_OK
|
---|
402 | */
|
---|
403 | ER
|
---|
404 | ltdc_configlayer(LTDC_Handle_t *phandle, LTDC_LayerCfg_t *pLayerCfg, uint32_t LayerIdx)
|
---|
405 | {
|
---|
406 | if(LayerIdx >= MAX_LAYER)
|
---|
407 | return E_PAR;
|
---|
408 | /* レイヤーコンフィグレーション設定をコピー */
|
---|
409 | phandle->LayerCfg[LayerIdx] = *pLayerCfg;
|
---|
410 | /* LTDCレイヤー設定 */
|
---|
411 | LTDC_SetConfig(phandle, pLayerCfg, LayerIdx);
|
---|
412 | /* リロード */
|
---|
413 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
414 | return E_OK;
|
---|
415 | }
|
---|
416 |
|
---|
417 | /*
|
---|
418 | * LTDCラインイベント設定
|
---|
419 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
420 | * patameter2 Line ライン位置
|
---|
421 | * return 正常ならばE_OK
|
---|
422 | */
|
---|
423 | ER
|
---|
424 | ltdc_lineevent(LTDC_Handle_t *phandle, uint32_t Line)
|
---|
425 | {
|
---|
426 | /* Change LTDC peripheral state */
|
---|
427 | phandle->state = LTDC_STATE_BUSY;
|
---|
428 |
|
---|
429 | /* Enable the Line interrupt */
|
---|
430 | sil_orw_mem((uint32_t *)(phandle->base+TOFF_LTDC_IER), LTDC_IER_LIE);
|
---|
431 |
|
---|
432 | /* Sets the Line Interrupt position */
|
---|
433 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_LIPCR), Line);
|
---|
434 |
|
---|
435 | /* Change the LTDC state*/
|
---|
436 | phandle->state = LTDC_STATE_READY;
|
---|
437 | return E_OK;
|
---|
438 | }
|
---|
439 |
|
---|
440 | /*
|
---|
441 | * LTDCレジスタリロード設定
|
---|
442 | * parameter1 phandle LTDCの初期設定構造体へのポインタ
|
---|
443 | * patameter2 ReloadType リロードタイプ
|
---|
444 | * return 正常ならばE_OK
|
---|
445 | */
|
---|
446 | ER
|
---|
447 | ltdc_reload(LTDC_Handle_t *phandle, uint32_t ReloadType)
|
---|
448 | {
|
---|
449 | /* Change LTDC peripheral state */
|
---|
450 | phandle->state = LTDC_STATE_BUSY;
|
---|
451 |
|
---|
452 | /* Enable the Reload interrupt */
|
---|
453 | sil_orw_mem((uint32_t *)(phandle->base+TOFF_LTDC_IER), LTDC_IER_RRIE);
|
---|
454 |
|
---|
455 | /* Apply Reload type */
|
---|
456 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SRCR), ReloadType);
|
---|
457 |
|
---|
458 | /* Change the LTDC state*/
|
---|
459 | phandle->state = LTDC_STATE_READY;
|
---|
460 | return E_OK;
|
---|
461 | }
|
---|
462 |
|
---|
463 | /*
|
---|
464 | * LTDCの初期設定を行う
|
---|
465 | * parameter1 phandle LTDCのハンドラへのポインタ
|
---|
466 | * return 正常ならE_OK
|
---|
467 | */
|
---|
468 | ER
|
---|
469 | ltdc_init(LTDC_Handle_t *phandle)
|
---|
470 | {
|
---|
471 | uint32_t timecount = 0;
|
---|
472 | uint32_t tmpreg0 = 0;
|
---|
473 | uint32_t tmpreg1 = 0;
|
---|
474 |
|
---|
475 | /*
|
---|
476 | * PLLSAIクロック停止
|
---|
477 | */
|
---|
478 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CR), RCC_CR_PLLSAION);
|
---|
479 |
|
---|
480 | timecount = 0;
|
---|
481 | while((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CR)) & (RCC_CR_PLLSAIRDY)) == RCC_CR_PLLSAIRDY){
|
---|
482 | if( timecount > PLLSAI_TIMEOUT_VALUE){
|
---|
483 | return E_TMOUT; /* タイムアウト発生 */
|
---|
484 | }
|
---|
485 | sil_dly_nse(1000);
|
---|
486 | timecount++;
|
---|
487 | }
|
---|
488 |
|
---|
489 | /*
|
---|
490 | * PLLSAIP/PLLSAIQ設定
|
---|
491 | */
|
---|
492 | tmpreg0 = ((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_PLLSAICFGR)) & RCC_PLLSAICFGR_PLLSAIQ) >> RCC_PLLSAICFGR_PLLSAIQ_POS);
|
---|
493 | tmpreg1 = ((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_PLLSAICFGR)) & RCC_PLLSAICFGR_PLLSAIP) >> RCC_PLLSAICFGR_PLLSAIP_POS);
|
---|
494 | sil_wrw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_PLLSAICFGR), (phandle->Init.pllsain << 6) | (tmpreg1 << 16) | (tmpreg0 << 24) | (phandle->Init.pllsair << 28));
|
---|
495 | sil_modw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_DCKCFGR1), RCC_DCKCFGR1_PLLSAIDIVR, phandle->Init.saidivr);
|
---|
496 |
|
---|
497 | /*
|
---|
498 | * PLLSAIクロック許可
|
---|
499 | */
|
---|
500 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CR), RCC_CR_PLLSAION);
|
---|
501 |
|
---|
502 | /*
|
---|
503 | * PLLSAIレディ待ち
|
---|
504 | */
|
---|
505 | timecount = 0;
|
---|
506 | while((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CR)) & (RCC_CR_PLLSAIRDY)) != RCC_CR_PLLSAIRDY){
|
---|
507 | if( timecount > PLLSAI_TIMEOUT_VALUE){
|
---|
508 | return E_TMOUT; /* タイムアウト発生 */
|
---|
509 | }
|
---|
510 | sil_dly_nse(1000);
|
---|
511 | timecount++;
|
---|
512 | }
|
---|
513 |
|
---|
514 | #ifdef TOPPERS_STM32F7_DISCOVERY
|
---|
515 | /*
|
---|
516 | * LTDCの初期設定
|
---|
517 | */
|
---|
518 | /* GPIO設定 */
|
---|
519 | ltdc_gpio_init();
|
---|
520 | #endif
|
---|
521 |
|
---|
522 | /* HS/VS/DE/PCの極性設定 */
|
---|
523 | sil_modw_mem((uint32_t *)(phandle->base+TOFF_LTDC_GCR), (LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL),
|
---|
524 | (phandle->Init.HSPolarity | phandle->Init.VSPolarity | phandle->Init.DEPolarity | phandle->Init.PCPolarity));
|
---|
525 | /* 同調サイズ設定 */
|
---|
526 | sil_modw_mem((uint32_t *)(phandle->base+TOFF_LTDC_SSCR), (LTDC_SSCR_VSH | LTDC_SSCR_HSW),
|
---|
527 | ((phandle->Init.HorizontalSync << 16) | phandle->Init.VerticalSync));
|
---|
528 | /* バックポーチ設定 */
|
---|
529 | sil_modw_mem((uint32_t *)(phandle->base+TOFF_LTDC_BPCR), (LTDC_BPCR_AVBP | LTDC_BPCR_AHBP),
|
---|
530 | ((phandle->Init.AccumulatedHBP << 16) | phandle->Init.AccumulatedVBP));
|
---|
531 | /* アクティブ幅設定 */
|
---|
532 | sil_modw_mem((uint32_t *)(phandle->base+TOFF_LTDC_AWCR), (LTDC_AWCR_AAH | LTDC_AWCR_AAW),
|
---|
533 | ((phandle->Init.AccumulatedActiveW << 16) | phandle->Init.AccumulatedActiveH));
|
---|
534 | /* トータル幅設定 */
|
---|
535 | sil_modw_mem((uint32_t *)(phandle->base+TOFF_LTDC_TWCR), (LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW),
|
---|
536 | ((phandle->Init.TotalWidth << 16) | phandle->Init.TotalHeigh));
|
---|
537 | /* バックグラウンドカラー設定 */
|
---|
538 | sil_modw_mem((uint32_t *)(phandle->base+TOFF_LTDC_BCCR), (LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED),
|
---|
539 | ((phandle->Init.Backcolor.Red << 16) | (phandle->Init.Backcolor.Green << 8) | phandle->Init.Backcolor.Blue));
|
---|
540 | /* エラーリセット */
|
---|
541 | sil_orw_mem((uint32_t *)(phandle->base+TOFF_LTDC_IER), (LTDC_IER_TERRIE | LTDC_IER_FUIE));
|
---|
542 | /* LTDC実行設定 */
|
---|
543 | sil_orw_mem((uint32_t *)(phandle->base+TOFF_LTDC_GCR), LTDC_GCR_LTDCEN);
|
---|
544 | phandle->state = LTDC_STATE_READY;
|
---|
545 | return E_OK;
|
---|
546 | }
|
---|
547 |
|
---|
548 | /*
|
---|
549 | * LTDC割込みハンドラ
|
---|
550 | */
|
---|
551 | void
|
---|
552 | ltdc_irqhandler(LTDC_Handle_t *phandle)
|
---|
553 | {
|
---|
554 | uint32_t isr = sil_rew_mem((uint32_t *)(phandle->base+TOFF_LTDC_ISR));
|
---|
555 |
|
---|
556 | /*
|
---|
557 | * 割込みマスクとクリア
|
---|
558 | */
|
---|
559 | sil_andw_mem((uint32_t *)(phandle->base+TOFF_LTDC_IER), isr);
|
---|
560 | sil_wrw_mem((uint32_t *)(phandle->base+TOFF_LTDC_ICR), isr);
|
---|
561 |
|
---|
562 | /*
|
---|
563 | * 転送エラーチェック
|
---|
564 | */
|
---|
565 | if((isr & LTDC_ISR_TERRIF) != 0){
|
---|
566 | /* Update error code */
|
---|
567 | phandle->errorcode |= LTDC_ERROR_TE;
|
---|
568 | phandle->state = LTDC_STATE_ERROR;
|
---|
569 | if(phandle->errorcallback != NULL)
|
---|
570 | phandle->errorcallback(phandle);
|
---|
571 | }
|
---|
572 |
|
---|
573 | /*
|
---|
574 | * FIFOアンダーランエラーチェック
|
---|
575 | */
|
---|
576 | if((isr & LTDC_ISR_FUIF) != 0){
|
---|
577 | /* Update error code */
|
---|
578 | phandle->errorcode |= LTDC_ERROR_FU;
|
---|
579 | phandle->state = LTDC_STATE_ERROR;
|
---|
580 | if(phandle->errorcallback != NULL)
|
---|
581 | phandle->errorcallback(phandle);
|
---|
582 | }
|
---|
583 |
|
---|
584 | /*
|
---|
585 | * ラインイベントチェック
|
---|
586 | */
|
---|
587 | if((isr & LTDC_IER_LIE) != 0){
|
---|
588 | /* Change LTDC state */
|
---|
589 | phandle->state = LTDC_STATE_READY;
|
---|
590 | if(phandle->linecallback != NULL)
|
---|
591 | phandle->linecallback(phandle);
|
---|
592 | }
|
---|
593 |
|
---|
594 | /*
|
---|
595 | * リロードイベントチェック
|
---|
596 | */
|
---|
597 | if((isr & LTDC_ISR_RRIF) != 0){
|
---|
598 | /* Change LTDC state */
|
---|
599 | phandle->state = LTDC_STATE_READY;
|
---|
600 | if(phandle->reloadcallback != NULL)
|
---|
601 | phandle->reloadcallback(phandle);
|
---|
602 | }
|
---|
603 | }
|
---|
604 |
|
---|