File indexing completed on 2025-05-11 08:22:58
0001
0002
0003
0004
0005
0006
0007
0008 #include "fsl_dcic.h"
0009
0010
0011
0012
0013
0014
0015 #ifndef FSL_COMPONENT_ID
0016 #define FSL_COMPONENT_ID "platform.drivers.dcic"
0017 #endif
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 static uint32_t DCIC_GetInstance(const DCIC_Type *base);
0029
0030 static void DCIC_ResetRegister(DCIC_Type *base);
0031
0032
0033
0034
0035
0036 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
0037
0038 static const clock_ip_name_t s_dcicClocks[] = DCIC_CLOCKS;
0039 #endif
0040
0041
0042
0043
0044 static uint32_t DCIC_GetInstance(const DCIC_Type *base)
0045 {
0046 static DCIC_Type *const s_dcicBases[] = DCIC_BASE_PTRS;
0047
0048 uint32_t instance;
0049
0050
0051 for (instance = 0; instance < ARRAY_SIZE(s_dcicBases); instance++)
0052 {
0053 if (s_dcicBases[instance] == base)
0054 {
0055 break;
0056 }
0057 }
0058
0059 assert(instance < ARRAY_SIZE(s_dcicBases));
0060
0061 return instance;
0062 }
0063
0064 #define DCIC_DCCIC_RESET_VALUE (DCIC_DCICC_VSYNC_POL_MASK | DCIC_DCICC_HSYNC_POL_MASK | DCIC_DCICC_DE_POL_MASK)
0065 #define DCIC_DCICIC_RESET_VALUE (DCIC_DCICIC_FI_MASK_MASK | DCIC_DCICIC_EI_MASK_MASK)
0066
0067 static void DCIC_ResetRegister(DCIC_Type *base)
0068 {
0069 uint32_t i;
0070
0071 base->DCICC = DCIC_DCCIC_RESET_VALUE;
0072 base->DCICIC = DCIC_DCICIC_RESET_VALUE;
0073
0074
0075 for (i = 0; i < DCIC_REGION_COUNT; i++)
0076 {
0077 base->REGION[i].DCICRC = 0UL;
0078 base->REGION[i].DCICRS = 0UL;
0079 base->REGION[i].DCICRRS = 0UL;
0080 }
0081
0082
0083 base->DCICS = (DCIC_DCICS_EI_STAT_MASK | DCIC_DCICS_FI_STAT_MASK | DCIC_DCICS_ROI_MATCH_STAT_MASK);
0084 }
0085
0086
0087
0088
0089
0090
0091
0092 void DCIC_Init(DCIC_Type *base, const dcic_config_t *config)
0093 {
0094 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && (0 != FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
0095
0096 (void)CLOCK_EnableClock(s_dcicClocks[DCIC_GetInstance(base)]);
0097 #endif
0098
0099 DCIC_ResetRegister(base);
0100
0101 base->DCICC = config->polarityFlags;
0102
0103 DCIC_EnableMismatchExternalSignal(base, config->enableExternalSignal);
0104 DCIC_EnableInterrupts(base, config->enableInterrupts);
0105 }
0106
0107
0108
0109
0110
0111
0112 void DCIC_Deinit(DCIC_Type *base)
0113 {
0114 base->DCICC = 0U;
0115
0116 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && (0 != FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
0117
0118 (void)CLOCK_DisableClock(s_dcicClocks[DCIC_GetInstance(base)]);
0119 #endif
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 void DCIC_GetDefaultConfig(dcic_config_t *config)
0135 {
0136 assert(NULL != config);
0137
0138 config->polarityFlags = (uint8_t)kDCIC_VsyncActiveLow | (uint8_t)kDCIC_HsyncActiveLow |
0139 (uint8_t)kDCIC_DataEnableActiveLow | (uint8_t)kDCIC_DriveDataOnFallingClkEdge;
0140 config->enableExternalSignal = false;
0141 config->enableInterrupts = 0;
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 void DCIC_EnableRegion(DCIC_Type *base, uint8_t regionIdx, const dcic_region_config_t *config)
0159 {
0160 assert(regionIdx < DCIC_REGION_COUNT);
0161 assert(NULL != config);
0162
0163 if (regionIdx < DCIC_REGION_COUNT)
0164 {
0165 base->REGION[regionIdx].DCICRRS = config->refCrc;
0166
0167 base->REGION[regionIdx].DCICRS = (((uint32_t)config->lowerRightX << DCIC_DCICRS_END_OFFSET_X_SHIFT) |
0168 ((uint32_t)config->lowerRightY << DCIC_DCICRS_END_OFFSET_Y_SHIFT));
0169
0170 base->REGION[regionIdx].DCICRC = (((uint32_t)config->upperLeftX << DCIC_DCICRC_START_OFFSET_X_SHIFT) |
0171 ((uint32_t)config->upperLeftY << DCIC_DCICRC_START_OFFSET_Y_SHIFT) |
0172 (config->lock ? DCIC_DCICRC_ROI_FREEZE_MASK : 0UL) | DCIC_DCICRC_ROI_EN_MASK);
0173 }
0174 }