Skip to content

Commit 8911e84

Browse files
committed
fixes for camera tests
1 parent 944ad9f commit 8911e84

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

libraries/Himax_HM01B0/himax.cpp

+23-9
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ uint8_t HIMAX_Open(void)
205205
{
206206
Wire.begin();
207207

208-
printf("Model: %x:%x\n", HIMAX_RegRead(MODEL_ID_H), HIMAX_RegRead(MODEL_ID_L));
208+
//printf("Model: %x:%x\n", HIMAX_RegRead(MODEL_ID_H), HIMAX_RegRead(MODEL_ID_L));
209209

210-
HIMAX_Reset();
211-
HIMAX_Boot();
210+
if (HIMAX_Reset()!=0) return -1;
211+
//HIMAX_Boot();
212212
//For debugging camera Configuration
213-
HIMAX_PrintReg();
213+
//HIMAX_PrintReg();
214+
HAL_Delay(200);
214215

215216
return 0;
216217
}
@@ -269,22 +270,23 @@ static uint8_t HIMAX_RegRead(uint16_t addr)
269270

270271
static uint8_t HIMAX_Reset()
271272
{
273+
uint32_t max_timeout=100;
272274
do {
273275
HIMAX_RegWrite(SW_RESET, HIMAX_RESET);
274-
delayMicroseconds(50);
275-
} while (HIMAX_RegRead(MODE_SELECT) != HIMAX_Standby);
276+
delay(1);
277+
} while (HIMAX_RegRead(MODE_SELECT) != HIMAX_Standby && ((--max_timeout)>0) );
276278

277-
return 0;
279+
return max_timeout>0 ? 0: -1 ;
278280
}
279281

280282
static uint8_t HIMAX_Boot()
281283
{
282284
uint32_t i;
283285

284286
for(i = 0; i < (sizeof(himax_default_regs) / sizeof(regval_list_t)); i++) {
285-
printf("%d\n", i);
287+
//printf("%d\n", i);
286288
HIMAX_RegWrite(himax_default_regs[i].reg_num, himax_default_regs[i].value);
287-
delayMicroseconds(50);
289+
//delay(1);
288290
}
289291

290292
HIMAX_RegWrite(PCLK_POLARITY, (0x20 | PCLK_FALLING_EDGE));
@@ -303,10 +305,22 @@ static void HIMAX_GrayScale(uint8_t value)
303305
void HIMAX_TestPattern(bool enable, bool walking)
304306
{
305307
uint8_t reg = 0;
308+
HIMAX_RegWrite(PCLK_POLARITY, (0x20 | PCLK_FALLING_EDGE));
309+
HIMAX_RegWrite(0x2100, 0 ); //AE
310+
HIMAX_RegWrite(0x1000, 0 ); //BLC
311+
HIMAX_RegWrite(0x1008, 0 ); //DPC
312+
HIMAX_RegWrite(0x0205, 0 ); //AGAIN
313+
HIMAX_RegWrite(0x020e, 1 ); //DGAINH
314+
HIMAX_RegWrite(0x020f, 0 ); //DGAINL
315+
306316
if (enable) {
307317
reg = 1 | (walking ? (1 << 4) : 0);
308318
}
309319
HIMAX_RegWrite(0x0601, reg );
320+
HIMAX_RegWrite(0x0104, 1 ); //group hold
321+
322+
HAL_Delay(100);
323+
310324
}
311325

312326
static void HIMAX_FrameRate()

libraries/Portenta_Camera/camera.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ uint32_t BSP_CAMERA_GetRotation(void)
180180
uint8_t BSP_CAMERA_Init(uint32_t Resolution)
181181
{
182182
DCMI_HandleTypeDef *phdcmi;
183-
uint8_t status = 0;
183+
uint8_t status = -1;
184184

185185
/* Get the DCMI handle structure */
186186
phdcmi = &hdcmi_discovery;
@@ -197,7 +197,7 @@ uint8_t BSP_CAMERA_Init(uint32_t Resolution)
197197

198198
/* Power up camera */
199199
BSP_CAMERA_PwrUp();
200-
HIMAX_Open();
200+
if (HIMAX_Open()!=0) return status;
201201

202202
/* DCMI Initialization */
203203
BSP_CAMERA_MspInit(&hdcmi_discovery, NULL);
@@ -212,15 +212,15 @@ uint8_t BSP_CAMERA_Init(uint32_t Resolution)
212212
*/
213213
//HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
214214

215-
HAL_DCMI_ConfigCROP(phdcmi, (QVGA_RES_X - CameraResX) / 2, (QVGA_RES_Y - CameraResY / 2), CameraResX, CameraResY);
215+
HAL_DCMI_ConfigCROP(phdcmi, (QVGA_RES_X - CameraResX) / 2, (QVGA_RES_Y - CameraResY / 2), CameraResX-1, CameraResY-1);
216216
HAL_DCMI_EnableCROP(phdcmi);
217217

218218
//HAL_DCMI_DisableCROP(phdcmi);
219219

220220
CameraCurrentResolution = Resolution;
221221

222222
/* Return CAMERA_OK status */
223-
status = 1;
223+
status = 0;
224224

225225
return status;
226226
}
@@ -532,24 +532,26 @@ int CameraClass::begin(int horizontalResolution, int verticalResolution)
532532

533533
/*## Camera Initialization and capture start ############################*/
534534
/* Initialize the Camera in QVGA mode */
535-
if(BSP_CAMERA_Init(CAMERA_R320x240) != 1)
535+
if(BSP_CAMERA_Init(CAMERA_R320x240) != 0)
536536
{
537-
return 0;
537+
return -1;
538538
}
539-
539+
return 0;
540540
}
541541

542-
int CameraClass::start(void)
542+
int CameraClass::start(uint32_t timeout)
543543
{
544544
HIMAX_Mode(HIMAX_Streaming);
545545

546546
/* Start the Camera Snapshot Capture */
547547
BSP_CAMERA_ContinuousStart((uint8_t *)LCD_FRAME_BUFFER);
548+
uint32_t time =millis();
548549

549550
/* Wait until camera frame is ready : DCMI Frame event */
550-
while(camera_frame_ready == 0)
551+
while((camera_frame_ready == 0) && ((timeout+time)>millis()))
551552
{
552553
}
554+
return camera_frame_ready ? 0: -1;
553555
}
554556

555557
uint8_t* CameraClass::grab(void)

libraries/Portenta_Camera/camera.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class CameraClass {
22
public:
33
int begin(int horizontalResolution, int verticalResolution);
44
uint8_t* snapshot();
5-
int start(void);
5+
int start(uint32_t timeout);
66
uint8_t* grab(void);
77
void testPattern(bool walking);
88
};

0 commit comments

Comments
 (0)