| NUC472_NUC442_BSP V3.04.000 The Board Support Package for NUC472/NUC442

cap.c
Go to the documentation of this file.
1/**************************************************************************/
13#include "NUC472_442.h"
22int32_t g_CAP_i32ErrCode = 0;
63 void CAP_Open(uint32_t u32InFormat, uint32_t u32OutFormet)
64{
65 ICAP->PAR = (ICAP->PAR & ~0x000007BF) | u32InFormat;
66 ICAP->CTL = (ICAP->CTL & ~0x00000060) | u32OutFormet;
67}
68
84 void CAP_SetCroppingWindow(uint32_t u32VStart,uint32_t u32HStart, uint32_t u32Height, uint32_t u32Width)
85{
86 ICAP->CWSP = (ICAP->CWSP & ~(CAP_CWSP_CWSADDRV_Msk | CAP_CWSP_CWSADDRH_Msk))
87 | (((u32VStart << 16) | u32HStart));
88
89 ICAP->CWS = (ICAP->CWS & ~(CAP_CWS_CWH_Msk | CAP_CWS_CWW_Msk))
90 | ((u32Height << 16)| u32Width);
91}
92
93
103 void CAP_SetPacketBuf(uint32_t u32Address )
104{
105 ICAP->PKTBA0 = u32Address;
106 ICAP->CTL |= CAP_CTL_UPDATE_Msk;
107}
108
122 void CAP_SetPlanarBuf(uint32_t u32YAddr, uint32_t u32UAddr, uint32_t u32VAddr)
123{
124 ICAP->YBA = u32YAddr;
125 ICAP->UBA = u32UAddr;
126 ICAP->VBA = u32VAddr;
127 ICAP->CTL |= CAP_CTL_UPDATE_Msk;
128}
129
130
136 void CAP_Close(void)
137{
138 ICAP->CTL &= ~CAP_CTL_CAPEN;
139}
140
141
157 void CAP_EnableInt(uint32_t u32IntMask)
158{
159 ICAP->INT = (ICAP->INT & ~(CAP_INT_VIEN_Msk | CAP_INT_MEIEN_Msk | CAP_INT_ADDRMIEN_Msk | CAP_INT_MDIEN_Msk ) )
160 | u32IntMask;
161}
162
178 void CAP_DisableInt(uint32_t u32IntMask)
179{
180 ICAP->INT = (ICAP->INT & ~(u32IntMask) ) ;
181}
182
188 void CAP_Start(void)
189{
190 ICAP->CTL |= CAP_CTL_CAPEN;
191}
192
203 void CAP_Stop(uint32_t u32FrameComplete)
204{
205 uint32_t u32Delay = SystemCoreClock * 2; /* 2 second */
206
207 if(u32FrameComplete==FALSE)
208 ICAP->CTL &= ~CAP_CTL_CAPEN;
209 else
210 {
211 ICAP->CTL |= CAP_CTL_SHUTTER_Msk;
212 while(!CAP_IS_STOPPED()){
213 u32Delay--;
214 if(u32Delay == 0){
215 g_CAP_i32ErrCode = CAP_TIMEOUT_ERR;
216 break;
217 }
218 }
219 }
220}
221
236 void CAP_SetPacketScaling(uint32_t u32VNumerator, uint32_t u32VDenominator, uint32_t u32HNumerator, uint32_t u32HDenominator)
237{
238 uint32_t u32NumeratorL, u32NumeratorH;
239 uint32_t u32DenominatorL, u32DenominatorH;
240
241 u32NumeratorL = u32VNumerator&0xFF;
242 u32NumeratorH=u32VNumerator>>8;
243 u32DenominatorL = u32VDenominator&0xFF;
244 u32DenominatorH = u32VDenominator>>8;
245 ICAP->PKTSL = (ICAP->PKTSL & ~(CAP_PKTSL_PKTSVNL_Msk | CAP_PKTSL_PKTSVML_Msk))
246 | ((u32NumeratorL << 24)| (u32DenominatorL << 16));
247 ICAP->PKTSM = (ICAP->PKTSM & ~(CAP_PKTSM_PKTSVNH_Msk | CAP_PKTSM_PKTSVMH_Msk))
248 | ((u32NumeratorH << 24) | (u32DenominatorH << 16));
249
250 u32NumeratorL = u32HNumerator&0xFF;
251 u32NumeratorH=u32HNumerator>>8;
252 u32DenominatorL = u32HDenominator&0xFF;
253 u32DenominatorH = u32HDenominator>>8;
254 ICAP->PKTSL = (ICAP->PKTSL & ~(CAP_PKTSL_PKTSHNL_Msk | CAP_PKTSL_PKTSHML_Msk))
255 | ((u32NumeratorL << 8)| u32DenominatorL);
256 ICAP->PKTSM = (ICAP->PKTSM & ~(CAP_PKTSM_PKTSHNH_Msk | CAP_PKTSM_PKTSHMH_Msk))
257 | ((u32NumeratorH << 8) | u32DenominatorH);
258}
259
274 void CAP_SetPlanarScaling(uint32_t u32VNumerator, uint32_t u32VDenominator, uint32_t u32HNumerator, uint32_t u32HDenominator)
275{
276 uint32_t u32NumeratorL, u32NumeratorH;
277 uint32_t u32DenominatorL, u32DenominatorH;
278
279 u32NumeratorL = u32VNumerator&0xFF;
280 u32NumeratorH = u32VNumerator>>8;
281 u32DenominatorL = u32VDenominator&0xFF;
282 u32DenominatorH = u32VDenominator>>8;
283 ICAP->PLNSL = (ICAP->PLNSL & ~(CAP_PLNSL_PLNSVNL_Msk | CAP_PLNSL_PLNSVML_Msk))
284 | ((u32NumeratorL << 24)| (u32DenominatorL << 16));
285 ICAP->PLNSM = (ICAP->PLNSM & ~(CAP_PLNSM_PLNSVNH_Msk | CAP_PLNSM_PLNSVMH_Msk))
286 | ((u32NumeratorH << 24)| (u32DenominatorH << 16));
287
288 u32NumeratorL = u32HNumerator&0xFF;
289 u32NumeratorH = u32HNumerator>>8;
290 u32DenominatorL = u32HDenominator&0xFF;
291 u32DenominatorH = u32HDenominator>>8;
292 ICAP->PLNSL = (ICAP->PLNSL & ~(CAP_PLNSL_PLNSHNL_Msk | CAP_PLNSL_PLNSHML_Msk))
293 | ((u32NumeratorL << 8)| u32DenominatorL);
294 ICAP->PLNSM = (ICAP->PLNSM & ~(CAP_PLNSM_PLNSHNH_Msk | CAP_PLNSM_PLNSHMH_Msk))
295 | ((u32NumeratorH << 8)| u32DenominatorH);
296}
297
307 void CAP_SetPacketStride(uint32_t u32Stride )
308{
309 ICAP->STRIDE = (ICAP->STRIDE & ~CAP_STRIDE_PKTSTRIDE_Msk) | u32Stride;
310}
311
321 void CAP_SetPlanarStride(uint32_t u32Stride )
322{
323 ICAP->STRIDE = (ICAP->STRIDE & ~CAP_STRIDE_PLNSTRIDE_Msk) | u32Stride<<CAP_STRIDE_PLNSTRIDE_Pos;
324}
325
326
350 void CAP_EnableMotionDet(uint32_t u32Freq, uint32_t u32BlockSize, uint32_t u32Format, uint32_t u32Threshold, uint32_t u32YDetAddr, uint32_t u32DetAddr)
351{
352 ICAP->MD = (ICAP->MD & ~(CAP_MD_MDSM_Msk | CAP_MD_MDBS_Msk | CAP_MD_MDEN_Msk)) |
353 ((CAP_MD_MDEN_Msk | (u32BlockSize?CAP_MD_MDBS_Msk:0)) |
354 (u32Format?CAP_MD_MDSM_Msk:0));
355
356 ICAP->MD = (ICAP->MD & ~CAP_MD_MDDF_Msk) | (u32Freq<<CAP_MD_MDDF_Pos);
357 ICAP->MD = (ICAP->MD & ~CAP_MD_MDTHR_Msk) | (u32Threshold<<CAP_MD_MDTHR_Pos);
358
359 ICAP->MDYADDR = u32YDetAddr;
360 ICAP->MDADDR = u32DetAddr;
361}
362
370 void CAP_DisableMotionDet(void)
371{
372 ICAP->MD &= ~CAP_MD_MDEN_Msk;
373}
374 /* end of group NUC472_442_CAP_EXPORTED_FUNCTIONS */
376 /* end of group NUC472_442_CAP_Driver */
378 /* end of group NUC472_442_Device_Driver */
380
381/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
NUC472_442.h
NUC472/NUC442 peripheral access layer header file. This file contains all the peripheral register's d...
CAP_PKTSM_PKTSVMH_Msk
#define CAP_PKTSM_PKTSVMH_Msk
Definition: NUC472_442.h:2368
CAP_CWS_CWW_Msk
#define CAP_CWS_CWW_Msk
Definition: NUC472_442.h:2302
CAP_INT_MDIEN_Msk
#define CAP_INT_MDIEN_Msk
Definition: NUC472_442.h:2257
CAP_CWSP_CWSADDRV_Msk
#define CAP_CWSP_CWSADDRV_Msk
Definition: NUC472_442.h:2299
CAP_PKTSL_PKTSVNL_Msk
#define CAP_PKTSL_PKTSVNL_Msk
Definition: NUC472_442.h:2317
CAP_CTL_UPDATE_Msk
#define CAP_CTL_UPDATE_Msk
Definition: NUC472_442.h:2197
CAP_PLNSM_PLNSHMH_Msk
#define CAP_PLNSM_PLNSHMH_Msk
Definition: NUC472_442.h:2374
CAP_CWS_CWH_Msk
#define CAP_CWS_CWH_Msk
Definition: NUC472_442.h:2305
CAP_CWSP_CWSADDRH_Msk
#define CAP_CWSP_CWSADDRH_Msk
Definition: NUC472_442.h:2296
CAP_INT_MEIEN_Msk
#define CAP_INT_MEIEN_Msk
Definition: NUC472_442.h:2251
CAP_MD_MDEN_Msk
#define CAP_MD_MDEN_Msk
Definition: NUC472_442.h:2269
CAP_PLNSM_PLNSVMH_Msk
#define CAP_PLNSM_PLNSVMH_Msk
Definition: NUC472_442.h:2380
CAP_INT_VIEN_Msk
#define CAP_INT_VIEN_Msk
Definition: NUC472_442.h:2248
CAP_PKTSL_PKTSHML_Msk
#define CAP_PKTSL_PKTSHML_Msk
Definition: NUC472_442.h:2308
CAP_MD_MDTHR_Pos
#define CAP_MD_MDTHR_Pos
Definition: NUC472_442.h:2280
CAP_MD_MDSM_Msk
#define CAP_MD_MDSM_Msk
Definition: NUC472_442.h:2275
CAP_PLNSM_PLNSHNH_Msk
#define CAP_PLNSM_PLNSHNH_Msk
Definition: NUC472_442.h:2377
CAP_PLNSL_PLNSHNL_Msk
#define CAP_PLNSL_PLNSHNL_Msk
Definition: NUC472_442.h:2323
CAP_PLNSM_PLNSVNH_Msk
#define CAP_PLNSM_PLNSVNH_Msk
Definition: NUC472_442.h:2383
CAP_MD_MDDF_Pos
#define CAP_MD_MDDF_Pos
Definition: NUC472_442.h:2277
CAP_STRIDE_PLNSTRIDE_Pos
#define CAP_STRIDE_PLNSTRIDE_Pos
Definition: NUC472_442.h:2340
CAP_PKTSM_PKTSHNH_Msk
#define CAP_PKTSM_PKTSHNH_Msk
Definition: NUC472_442.h:2365
CAP_PLNSL_PLNSVML_Msk
#define CAP_PLNSL_PLNSVML_Msk
Definition: NUC472_442.h:2326
CAP_PKTSL_PKTSHNL_Msk
#define CAP_PKTSL_PKTSHNL_Msk
Definition: NUC472_442.h:2311
CAP_PKTSM_PKTSHMH_Msk
#define CAP_PKTSM_PKTSHMH_Msk
Definition: NUC472_442.h:2362
CAP_PKTSM_PKTSVNH_Msk
#define CAP_PKTSM_PKTSVNH_Msk
Definition: NUC472_442.h:2371
CAP_INT_ADDRMIEN_Msk
#define CAP_INT_ADDRMIEN_Msk
Definition: NUC472_442.h:2254
CAP_MD_MDBS_Msk
#define CAP_MD_MDBS_Msk
Definition: NUC472_442.h:2272
CAP_PKTSL_PKTSVML_Msk
#define CAP_PKTSL_PKTSVML_Msk
Definition: NUC472_442.h:2314
CAP_PLNSL_PLNSHML_Msk
#define CAP_PLNSL_PLNSHML_Msk
Definition: NUC472_442.h:2320
CAP_CTL_SHUTTER_Msk
#define CAP_CTL_SHUTTER_Msk
Definition: NUC472_442.h:2194
CAP_PLNSL_PLNSVNL_Msk
#define CAP_PLNSL_PLNSVNL_Msk
Definition: NUC472_442.h:2329
g_CAP_i32ErrCode
int32_t g_CAP_i32ErrCode
Definition: cap.c:22
CAP_CTL_CAPEN
#define CAP_CTL_CAPEN
Definition: cap.h:36
CAP_TIMEOUT_ERR
#define CAP_TIMEOUT_ERR
Definition: cap.h:95
CAP_Stop
void CAP_Stop(uint32_t u32FrameComplete)
Stop Image Capture Interface.
Definition: cap.c:203
CAP_DisableMotionDet
void CAP_DisableMotionDet(void)
Enable Motion Detection Function.
Definition: cap.c:370
CAP_SetPlanarScaling
void CAP_SetPlanarScaling(uint32_t u32VNumerator, uint32_t u32VDenominator, uint32_t u32HNumerator, uint32_t u32HDenominator)
Set Planar Scaling Vertical and Horizontal Factor Register.
Definition: cap.c:274
CAP_EnableMotionDet
void CAP_EnableMotionDet(uint32_t u32Freq, uint32_t u32BlockSize, uint32_t u32Format, uint32_t u32Threshold, uint32_t u32YDetAddr, uint32_t u32DetAddr)
Enable Motion Detection Function.
Definition: cap.c:350
CAP_EnableInt
void CAP_EnableInt(uint32_t u32IntMask)
Set CAP Interrupt.
Definition: cap.c:157
CAP_SetPlanarBuf
void CAP_SetPlanarBuf(uint32_t u32YAddr, uint32_t u32UAddr, uint32_t u32VAddr)
Set System Memory Planar Y, U and V Base Address Registers.
Definition: cap.c:122
CAP_DisableInt
void CAP_DisableInt(uint32_t u32IntMask)
Disable CAP Interrupt.
Definition: cap.c:178
CAP_SetCroppingWindow
void CAP_SetCroppingWindow(uint32_t u32VStart, uint32_t u32HStart, uint32_t u32Height, uint32_t u32Width)
Set Cropping Window Starting Address and Size.
Definition: cap.c:84
CAP_IS_STOPPED
#define CAP_IS_STOPPED()
Is CAP module Enable.
Definition: cap.h:113
CAP_SetPacketStride
void CAP_SetPacketStride(uint32_t u32Stride)
Set Packet Frame Output Pixel Stride Width.
Definition: cap.c:307
CAP_Start
void CAP_Start(void)
Start Image Capture Interface.
Definition: cap.c:188
CAP_Open
void CAP_Open(uint32_t u32InFormat, uint32_t u32OutFormet)
Open engine clock and sensor clock.
Definition: cap.c:63
CAP_Close
void CAP_Close(void)
Close Image Capture Interface.
Definition: cap.c:136
CAP_SetPlanarStride
void CAP_SetPlanarStride(uint32_t u32Stride)
Set Planar Frame Output Pixel Stride Width.
Definition: cap.c:321
CAP_SetPacketBuf
void CAP_SetPacketBuf(uint32_t u32Address)
Set System Memory Packet Base Address0 Register.
Definition: cap.c:103
CAP_SetPacketScaling
void CAP_SetPacketScaling(uint32_t u32VNumerator, uint32_t u32VDenominator, uint32_t u32HNumerator, uint32_t u32HDenominator)
Set Packet Scaling Vertical and Horizontal Factor Register.
Definition: cap.c:236
ICAP
#define ICAP
Definition: NUC472_442.h:28823
FALSE
#define FALSE
Boolean false, define to use in API parameters or return value.
Definition: NUC472_442.h:29022
SystemCoreClock
uint32_t SystemCoreClock
Definition: system_NUC472_442.c:17