Skip to content

Commit b7e3990

Browse files
gon1332nashif
authored andcommitted
samples: camera: Add hardware reset command
There is a possibility that the module would hang. Just to be sure, issue a harware reset before taking a snapshot. Signed-off-by: Ioannis Konstantelias <[email protected]>
1 parent b62b2a2 commit b7e3990

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

samples/camera/README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Requirements
1616
************
1717

1818
The demo assumes that a uCAM-III is connected to the UART_2 TX/RX of a Nucleo
19-
L496ZG. Also, the camera module should be powered by the 5V pin.
19+
L496ZG. The RST pin is connected to the PA3 pin of Nucleo. Also, the camera
20+
module should be powered by the 5V pin.
2021

2122
Building and Running
2223
********************

samples/camera/src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ static int camera_take_snapshot(u8_t *data, u32_t *size)
4444
{
4545
int ret;
4646

47+
/* Hardware reset the camera before every shot */
48+
ucam3_reset();
49+
4750
/* Synchronize with the camera */
4851
ret = ucam3_sync();
4952
if (ret) {

samples/camera/src/ucam3.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <misc/byteorder.h>
1111
#include <string.h>
1212
#include <stdbool.h>
13+
#include <gpio.h>
1314

1415
#define CAM_UART_NAME DT_UART_STM32_USART_2_NAME
1516

@@ -34,6 +35,8 @@ static struct {
3435
} cam_data;
3536

3637
static struct tty_serial cam;
38+
static struct device *reset;
39+
3740

3841
typedef enum {
3942
ACK_INITIAL,
@@ -107,11 +110,8 @@ static void print_cmd(uint8_t *cmd, int size)
107110

108111
void ucam3_reset(void)
109112
{
110-
uint8_t b;
111-
112-
while (tty_read(&cam, &b, 1) > 0) {
113-
continue;
114-
}
113+
gpio_pin_write(reset, 3, 0);
114+
gpio_pin_write(reset, 3, 1);
115115
}
116116

117117
int ucam3_sync(void)
@@ -529,5 +529,13 @@ int ucam3_create(void)
529529
tty_set_rx_buf(&cam, cam_rxbuf, sizeof(cam_rxbuf));
530530
tty_set_rx_timeout(&cam, 250);
531531

532+
reset = device_get_binding("GPIOA");
533+
if (!reset) {
534+
return -1;
535+
}
536+
537+
gpio_pin_configure(reset, 3, GPIO_DIR_OUT);
538+
// ucam3_reset();
539+
532540
return 0;
533541
}

samples/camera/src/ucam3.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ extern int ucam3_get_picture(u8_t *data, u32_t *size);
135135
/**
136136
* @brief Reset the uCAM-III
137137
*
138-
* Initialize the serial interface with the camera module.
138+
* Hardware reset the module.
139139
*
140-
* @retval 0 on success, otherwise -1
140+
* @retval none
141141
*/
142142
extern void ucam3_reset(void);
143143

0 commit comments

Comments
 (0)