OV528 Camera Module Library

Committer:
jplunkett
Date:
Fri Jul 07 16:52:18 2017 +0000
Revision:
0:3f9d7ef7266c
Child:
1:06afc809909b
Camera OV528 Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jplunkett 0:3f9d7ef7266c 1 /* Copyright (c) 2016 ARM Limited
jplunkett 0:3f9d7ef7266c 2 *
jplunkett 0:3f9d7ef7266c 3 * Licensed under the Apache License, Version 2.0 (the "License");
jplunkett 0:3f9d7ef7266c 4 * you may not use this file except in compliance with the License.
jplunkett 0:3f9d7ef7266c 5 * You may obtain a copy of the License at
jplunkett 0:3f9d7ef7266c 6 *
jplunkett 0:3f9d7ef7266c 7 * http://www.apache.org/licenses/LICENSE-2.0
jplunkett 0:3f9d7ef7266c 8 *
jplunkett 0:3f9d7ef7266c 9 * Unless required by applicable law or agreed to in writing, software
jplunkett 0:3f9d7ef7266c 10 * distributed under the License is distributed on an "AS IS" BASIS,
jplunkett 0:3f9d7ef7266c 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jplunkett 0:3f9d7ef7266c 12 * See the License for the specific language governing permissions and
jplunkett 0:3f9d7ef7266c 13 * limitations under the License.
jplunkett 0:3f9d7ef7266c 14 */
jplunkett 0:3f9d7ef7266c 15 #ifndef MBED_CAMERAOV528_H
jplunkett 0:3f9d7ef7266c 16 #define MBED_CAMERAOV528_H
jplunkett 0:3f9d7ef7266c 17
jplunkett 0:3f9d7ef7266c 18 #include "mbed.h"
jplunkett 0:3f9d7ef7266c 19 #include "rtos.h"
jplunkett 0:3f9d7ef7266c 20
jplunkett 0:3f9d7ef7266c 21 class Camera {
jplunkett 0:3f9d7ef7266c 22 public:
jplunkett 0:3f9d7ef7266c 23 Camera(void) {};
jplunkett 0:3f9d7ef7266c 24 virtual ~Camera(void) {};
jplunkett 0:3f9d7ef7266c 25 virtual void powerup(void) = 0;
jplunkett 0:3f9d7ef7266c 26 virtual void powerdown(void) = 0;
jplunkett 0:3f9d7ef7266c 27 virtual void take_picture(void) = 0;
jplunkett 0:3f9d7ef7266c 28 virtual uint32_t get_picture_size(void) = 0;
jplunkett 0:3f9d7ef7266c 29 virtual uint32_t read_picture_data(uint8_t *data, uint32_t size) = 0;
jplunkett 0:3f9d7ef7266c 30 };
jplunkett 0:3f9d7ef7266c 31
jplunkett 0:3f9d7ef7266c 32 class CameraOV528 : public Camera {
jplunkett 0:3f9d7ef7266c 33
jplunkett 0:3f9d7ef7266c 34 public:
jplunkett 0:3f9d7ef7266c 35 enum Resolution {
jplunkett 0:3f9d7ef7266c 36 // RES_80x60 = 0x01, // Does not work
jplunkett 0:3f9d7ef7266c 37 RES_160x120 = 0x03,
jplunkett 0:3f9d7ef7266c 38 RES_320x240 = 0x05,
jplunkett 0:3f9d7ef7266c 39 RES_640x480 = 0x07,
jplunkett 0:3f9d7ef7266c 40 };
jplunkett 0:3f9d7ef7266c 41
jplunkett 0:3f9d7ef7266c 42 enum Format {
jplunkett 0:3f9d7ef7266c 43 // FMT_2_BIT_GRAY_SCALE = 1, //Does not work
jplunkett 0:3f9d7ef7266c 44 // FMT_4_BIT_GRAY_SCALE = 2,
jplunkett 0:3f9d7ef7266c 45 // FMT_8_BIT_GRAY_SCALE = 3,
jplunkett 0:3f9d7ef7266c 46 // FMT_2_BIT_COLOR = 5,
jplunkett 0:3f9d7ef7266c 47 // FMT_16_BIT = 6,
jplunkett 0:3f9d7ef7266c 48 FMT_JPEG = 7,
jplunkett 0:3f9d7ef7266c 49 };
jplunkett 0:3f9d7ef7266c 50
jplunkett 0:3f9d7ef7266c 51 CameraOV528(PinName rx, PinName tx);
jplunkett 0:3f9d7ef7266c 52 virtual ~CameraOV528(void);
jplunkett 0:3f9d7ef7266c 53 virtual void powerup(void);
jplunkett 0:3f9d7ef7266c 54 virtual void powerup(uint32_t baud);
jplunkett 0:3f9d7ef7266c 55 virtual void powerdown(void);
jplunkett 0:3f9d7ef7266c 56 virtual void take_picture(void);
jplunkett 0:3f9d7ef7266c 57 virtual uint32_t get_picture_size(void);
jplunkett 0:3f9d7ef7266c 58 virtual uint32_t read_picture_data(uint8_t *data, uint32_t size);
jplunkett 0:3f9d7ef7266c 59
jplunkett 0:3f9d7ef7266c 60 void set_resolution(Resolution resolution);
jplunkett 0:3f9d7ef7266c 61 void set_format(Format format);
jplunkett 0:3f9d7ef7266c 62 void set_baud(uint32_t baud);
jplunkett 0:3f9d7ef7266c 63
jplunkett 0:3f9d7ef7266c 64 private:
jplunkett 0:3f9d7ef7266c 65
jplunkett 0:3f9d7ef7266c 66 bool _init_sequence();
jplunkett 0:3f9d7ef7266c 67 void _set_baud(uint32_t baud);
jplunkett 0:3f9d7ef7266c 68 void _set_package_size(uint32_t size);
jplunkett 0:3f9d7ef7266c 69 void _set_fmt_and_res(Format fmt, Resolution res);
jplunkett 0:3f9d7ef7266c 70 void _read_picture_block();
jplunkett 0:3f9d7ef7266c 71
jplunkett 0:3f9d7ef7266c 72 void _rx_irq(void);
jplunkett 0:3f9d7ef7266c 73
jplunkett 0:3f9d7ef7266c 74 bool _send(const uint8_t *data, uint32_t size, uint32_t timeout_ms=500);
jplunkett 0:3f9d7ef7266c 75 uint32_t _read(uint8_t * data, uint32_t size, uint32_t timeout_ms=500);
jplunkett 0:3f9d7ef7266c 76 void _flush_rx(void);
jplunkett 0:3f9d7ef7266c 77
jplunkett 0:3f9d7ef7266c 78 bool _send_cmd(uint8_t cmd, uint8_t p1=0, uint8_t p2=0, uint8_t p3=0, uint8_t p4=0);
jplunkett 0:3f9d7ef7266c 79 void _send_ack(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4);
jplunkett 0:3f9d7ef7266c 80
jplunkett 0:3f9d7ef7266c 81 RawSerial _serial;
jplunkett 0:3f9d7ef7266c 82
jplunkett 0:3f9d7ef7266c 83 bool _init_done;
jplunkett 0:3f9d7ef7266c 84 Resolution _resolution;
jplunkett 0:3f9d7ef7266c 85 Format _format;
jplunkett 0:3f9d7ef7266c 86 uint32_t _baud;
jplunkett 0:3f9d7ef7266c 87
jplunkett 0:3f9d7ef7266c 88 Resolution _dev_resolution;
jplunkett 0:3f9d7ef7266c 89 Format _dev_format;
jplunkett 0:3f9d7ef7266c 90 uint32_t _dev_baud;
jplunkett 0:3f9d7ef7266c 91
jplunkett 0:3f9d7ef7266c 92 uint32_t picture_length;
jplunkett 0:3f9d7ef7266c 93 uint32_t picture_data_id;
jplunkett 0:3f9d7ef7266c 94 uint32_t picture_data_id_count;
jplunkett 0:3f9d7ef7266c 95 uint8_t picture_buffer[128];
jplunkett 0:3f9d7ef7266c 96 uint32_t picture_buffer_size_limit;
jplunkett 0:3f9d7ef7266c 97 uint32_t picture_buffer_pos;
jplunkett 0:3f9d7ef7266c 98 uint32_t picture_buffer_size;
jplunkett 0:3f9d7ef7266c 99
jplunkett 0:3f9d7ef7266c 100 uint8_t _read_buf[sizeof(picture_buffer) + 1];
jplunkett 0:3f9d7ef7266c 101 uint32_t _read_buf_head;
jplunkett 0:3f9d7ef7266c 102 uint32_t _read_buf_tail;
jplunkett 0:3f9d7ef7266c 103 uint32_t _read_wake_pos;
jplunkett 0:3f9d7ef7266c 104 Semaphore _read_sem;
jplunkett 0:3f9d7ef7266c 105 };
jplunkett 0:3f9d7ef7266c 106
jplunkett 0:3f9d7ef7266c 107 #endif