1 /******************************************************************************
2 *
3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4 * Analog Devices, Inc.),
5 * Copyright (C) 2023-2024 Analog Devices, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************************/
20
21 /* **** Includes **** */
22 #include <string.h>
23 #include "mxc_errors.h"
24 #include "mxc_assert.h"
25 #include "mxc_sys.h"
26 #include "clcd_reva.h"
27 #include "clcd.h"
28 #include "mxc_lock.h"
29
30 /* **** Definitions **** */
31
32 /* **** Globals **** */
33
34 /* ************************************************************************** */
MXC_CLCD_RevA_Init(mxc_clcd_reva_regs_t * clcd,mxc_clcd_cfg_t * cfg)35 int MXC_CLCD_RevA_Init(mxc_clcd_reva_regs_t *clcd, mxc_clcd_cfg_t *cfg)
36 {
37 int error;
38
39 // Clear registers
40 clcd->ctrl = 0;
41 clcd->vtim_0 = 0;
42 clcd->vtim_1 = 0;
43 clcd->clk = 0;
44 clcd->htim = 0;
45 if ((error = MXC_CLCD_ConfigPanel(cfg)) != E_NO_ERROR) {
46 return error;
47 }
48 // Disable and clear interrupts
49 clcd->int_en = 0;
50 clcd->stat = clcd->stat;
51
52 return E_NO_ERROR;
53 }
54
55 /* ************************************************************************* */
MXC_CLCD_RevA_Shutdown(mxc_clcd_reva_regs_t * clcd)56 int MXC_CLCD_RevA_Shutdown(mxc_clcd_reva_regs_t *clcd)
57 {
58 // Disable and clear interrupts
59 clcd->int_en = 0;
60 clcd->stat = clcd->stat;
61
62 // Clear registers
63 clcd->ctrl = 0;
64 clcd->vtim_0 = 0;
65 clcd->vtim_1 = 0;
66 clcd->clk = 0;
67 clcd->htim = 0;
68
69 return E_NO_ERROR;
70 }
71
72 /* ************************************************************************* */
MXC_CLCD_RevA_ConfigPanel(mxc_clcd_reva_regs_t * clcd,mxc_clcd_cfg_t * cfg)73 int MXC_CLCD_RevA_ConfigPanel(mxc_clcd_reva_regs_t *clcd, mxc_clcd_cfg_t *cfg)
74 {
75 int i;
76
77 clcd->clk = ((MXC_S_CLCD_REVA_CLK_EDGE_RISEEDGE) | (MXC_S_CLCD_REVA_CLK_HPOL_ACTIVEHI) |
78 (MXC_F_CLCD_REVA_CLK_VPOL) | (MXC_S_CLCD_REVA_CLK_DPOL_ACTIVEHI) |
79 ((PeripheralClock / cfg->frequency - 1) << MXC_F_CLCD_REVA_CLK_CLKDIV_POS));
80
81 clcd->vtim_0 = (cfg->vbackporch << MXC_F_CLCD_REVA_VTIM_0_VBACKPORCH_POS) | (cfg->height - 1);
82 clcd->vtim_1 = (cfg->vfrontporch << MXC_F_CLCD_REVA_VTIM_1_VFRONTPORCH_POS) |
83 ((cfg->vsyncwidth - 1) << MXC_F_CLCD_REVA_VTIM_1_VSYNCWIDTH_POS);
84
85 clcd->htim = ((cfg->hfrontporch - 1) << MXC_F_CLCD_REVA_HTIM_HFRONTPORCH_POS) |
86 ((cfg->hbackporch - 1) << MXC_F_CLCD_REVA_HTIM_HBACKPORCH_POS) |
87 ((cfg->hsyncwidth - 1) << MXC_F_CLCD_REVA_HTIM_HSYNCWIDTH_POS) |
88 (((cfg->width >> 4) - 1) << MXC_F_CLCD_REVA_HTIM_HSIZE_POS);
89
90 clcd->ctrl |= cfg->bpp;
91
92 for (i = 0; i < cfg->paletteSize; i++) {
93 clcd->palette[i] = cfg->palette[i];
94 }
95 return E_NO_ERROR;
96 }
97
98 /* ************************************************************************* */
MXC_CLCD_RevA_Enable(mxc_clcd_reva_regs_t * clcd)99 int MXC_CLCD_RevA_Enable(mxc_clcd_reva_regs_t *clcd)
100 {
101 clcd->ctrl |= MXC_S_CLCD_REVA_CTRL_LCDEN_ENABLE | (8 << MXC_F_CLCD_REVA_CTRL_DISPTYPE_POS) |
102 MXC_F_CLCD_REVA_CTRL_PEN;
103
104 return E_NO_ERROR;
105 }
106
107 /* ************************************************************************* */
MXC_CLCD_RevA_Disable(mxc_clcd_reva_regs_t * clcd)108 int MXC_CLCD_RevA_Disable(mxc_clcd_reva_regs_t *clcd)
109 {
110 clcd->ctrl &= (~MXC_S_CLCD_REVA_CTRL_LCDEN_ENABLE);
111
112 return E_NO_ERROR;
113 }
114
115 /* ************************************************************************* */
MXC_CLCD_RevA_SetFrameAddr(mxc_clcd_reva_regs_t * clcd,void * addr)116 int MXC_CLCD_RevA_SetFrameAddr(mxc_clcd_reva_regs_t *clcd, void *addr)
117 {
118 clcd->ctrl &= (~MXC_S_CLCD_REVA_CTRL_LCDEN_ENABLE);
119 clcd->fr = (uint32_t)addr;
120 clcd->ctrl |= (MXC_S_CLCD_REVA_CTRL_LCDEN_ENABLE);
121
122 return E_NO_ERROR;
123 }
124