Skip to content

Commit ce7ee58

Browse files
committed
camera: Update camera module
1 parent a25e3c2 commit ce7ee58

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

ports/cxd56/common-hal/camera/Camera.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,43 @@ typedef struct {
4242

4343
STATIC camera_dev_t camera_dev = {"/dev/video", -1};
4444

45+
typedef struct {
46+
uint16_t width;
47+
uint16_t height;
48+
} image_size_t;
49+
50+
STATIC const image_size_t image_size_table[] = {
51+
{ VIDEO_HSIZE_QVGA, VIDEO_VSIZE_QVGA },
52+
{ VIDEO_HSIZE_VGA, VIDEO_VSIZE_VGA },
53+
{ VIDEO_HSIZE_HD, VIDEO_VSIZE_HD },
54+
{ VIDEO_HSIZE_QUADVGA, VIDEO_VSIZE_QUADVGA },
55+
{ VIDEO_HSIZE_FULLHD, VIDEO_VSIZE_FULLHD },
56+
{ VIDEO_HSIZE_3M, VIDEO_VSIZE_3M },
57+
{ VIDEO_HSIZE_5M, VIDEO_VSIZE_5M },
58+
};
59+
4560
static bool camera_check_width_and_height(uint16_t width, uint16_t height) {
46-
if ((width == VIDEO_HSIZE_QVGA && height == VIDEO_VSIZE_QVGA) ||
47-
(width == VIDEO_HSIZE_VGA && height == VIDEO_VSIZE_VGA) ||
48-
(width == VIDEO_HSIZE_HD && height == VIDEO_VSIZE_HD) ||
49-
(width == VIDEO_HSIZE_QUADVGA && height == VIDEO_VSIZE_QUADVGA) ||
50-
(width == VIDEO_HSIZE_FULLHD && height == VIDEO_VSIZE_FULLHD) ||
51-
(width == VIDEO_HSIZE_3M && height == VIDEO_VSIZE_3M) ||
52-
(width == VIDEO_HSIZE_5M && height == VIDEO_VSIZE_5M)) {
53-
return true;
54-
} else {
55-
return false;
61+
for (int i = 0; i < MP_ARRAY_SIZE(image_size_table); i++) {
62+
if (image_size_table[i].width == width && image_size_table[i].height == height) {
63+
return true;
64+
}
5665
}
66+
return false;
5767
}
5868

5969
static bool camera_check_buffer_length(uint16_t width, uint16_t height, camera_imageformat_t format, size_t length) {
6070
if (format == IMAGEFORMAT_JPG) {
6171
// In SPRESENSE SDK, JPEG compression quality=80 by default.
6272
// In such setting, the maximum actual measured size of JPEG image
6373
// is about width * height * 2 / 9.
64-
return length >= (size_t)(width * height * 2 / 9) ? true : false;
74+
return length >= (size_t)(width * height * 2 / 9);
6575
} else {
6676
return false;
6777
}
6878
}
6979

7080
static bool camera_check_format(camera_imageformat_t format) {
71-
if (format == IMAGEFORMAT_JPG) {
72-
return true;
73-
} else {
74-
return false;
75-
}
81+
return format == IMAGEFORMAT_JPG;
7682
}
7783

7884
static void camera_set_format(enum v4l2_buf_type type, uint32_t pixformat, uint16_t width, uint16_t height) {

ports/cxd56/supervisor/port.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "common-hal/pwmio/PWMOut.h"
4747
#include "common-hal/busio/UART.h"
4848

49-
#define HEAP_SIZE (1000 * 1024)
49+
#define SPRESENSE_MEM_ALIGN (32)
5050

5151
uint32_t* heap;
5252
uint32_t heap_size;
@@ -57,8 +57,10 @@ safe_mode_t port_init(void) {
5757
// Wait until RTC is available
5858
while (g_rtc_enabled == false);
5959

60-
heap = memalign(32, HEAP_SIZE);
61-
heap_size = HEAP_SIZE / sizeof(uint32_t);
60+
heap = memalign(SPRESENSE_MEM_ALIGN, 128 * 1024);
61+
uint32_t size = CONFIG_RAM_START + CONFIG_RAM_SIZE - (uint32_t)heap - 2 * SPRESENSE_MEM_ALIGN;
62+
heap = realloc(heap, size);
63+
heap_size = size / sizeof(uint32_t);
6264

6365
if (board_requests_safe_mode()) {
6466
return USER_SAFE_MODE;

shared-bindings/camera/Camera.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//|
5353
//| buffer = bytearray(512 * 1024)
5454
//| file = open("/sd/image.jpg","wb")
55-
//| size = cam.take_picture()
55+
//| size = cam.take_picture(buffer, camera.ImageFormat.JPG)
5656
//| file.write(buffer, size)
5757
//| file.close()"""
5858
//|
@@ -99,7 +99,7 @@ STATIC void check_for_deinit(camera_obj_t *self) {
9999
//| def take_picture(self, buf: WriteableBuffer, format: ImageFormat) -> int:
100100
//| """Take picture and save to ``buf`` in the given ``format``
101101
//|
102-
//| :return: the size of the picture taken
102+
//| :return: the number of bytes written into buf
103103
//| :rtype: int"""
104104
//| ...
105105
//|

shared-bindings/camera/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ STATIC const mp_rom_map_elem_t camera_module_globals_table[] = {
3939
{ MP_ROM_QSTR(MP_QSTR_Camera), MP_ROM_PTR(&camera_type) },
4040

4141
// Enum-like Classes.
42-
{ MP_ROM_QSTR(MP_QSTR_ImageSize), MP_ROM_PTR(&camera_imageformat_type) },
42+
{ MP_ROM_QSTR(MP_QSTR_ImageFormat), MP_ROM_PTR(&camera_imageformat_type) },
4343
};
4444

4545
STATIC MP_DEFINE_CONST_DICT(camera_module_globals, camera_module_globals_table);

0 commit comments

Comments
 (0)