OV528 Camera Module Library
CameraOV528.h@1:06afc809909b, 2017-07-07 (annotated)
- Committer:
- jplunkett
- Date:
- Fri Jul 07 20:40:26 2017 +0000
- Revision:
- 1:06afc809909b
- Parent:
- 0:3f9d7ef7266c
- Child:
- 2:7a563410b23d
Updated library
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:06afc809909b | 25 | virtual int powerup(void) = 0; |
jplunkett | 1:06afc809909b | 26 | virtual int powerdown(void) = 0; |
jplunkett | 1:06afc809909b | 27 | virtual int 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 | 1:06afc809909b | 53 | virtual int powerup(void); |
jplunkett | 1:06afc809909b | 54 | virtual int powerup(uint32_t baud); |
jplunkett | 1:06afc809909b | 55 | virtual int powerdown(void); |
jplunkett | 1:06afc809909b | 56 | virtual int 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 | 1:06afc809909b | 64 | void attach_debug_function(void (*func)(const char* fmt, ...)); |
jplunkett | 1:06afc809909b | 65 | int camera_error(const char* message); |
jplunkett | 1:06afc809909b | 66 | |
jplunkett | 0:3f9d7ef7266c | 67 | private: |
jplunkett | 0:3f9d7ef7266c | 68 | |
jplunkett | 0:3f9d7ef7266c | 69 | bool _init_sequence(); |
jplunkett | 0:3f9d7ef7266c | 70 | void _set_baud(uint32_t baud); |
jplunkett | 0:3f9d7ef7266c | 71 | void _set_package_size(uint32_t size); |
jplunkett | 0:3f9d7ef7266c | 72 | void _set_fmt_and_res(Format fmt, Resolution res); |
jplunkett | 1:06afc809909b | 73 | int _read_picture_block(); |
jplunkett | 0:3f9d7ef7266c | 74 | |
jplunkett | 0:3f9d7ef7266c | 75 | void _rx_irq(void); |
jplunkett | 0:3f9d7ef7266c | 76 | |
jplunkett | 0:3f9d7ef7266c | 77 | bool _send(const uint8_t *data, uint32_t size, uint32_t timeout_ms=500); |
jplunkett | 0:3f9d7ef7266c | 78 | uint32_t _read(uint8_t * data, uint32_t size, uint32_t timeout_ms=500); |
jplunkett | 0:3f9d7ef7266c | 79 | void _flush_rx(void); |
jplunkett | 0:3f9d7ef7266c | 80 | |
jplunkett | 0:3f9d7ef7266c | 81 | 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 | 82 | void _send_ack(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4); |
jplunkett | 0:3f9d7ef7266c | 83 | |
jplunkett | 0:3f9d7ef7266c | 84 | RawSerial _serial; |
jplunkett | 0:3f9d7ef7266c | 85 | |
jplunkett | 0:3f9d7ef7266c | 86 | bool _init_done; |
jplunkett | 0:3f9d7ef7266c | 87 | Resolution _resolution; |
jplunkett | 0:3f9d7ef7266c | 88 | Format _format; |
jplunkett | 0:3f9d7ef7266c | 89 | uint32_t _baud; |
jplunkett | 0:3f9d7ef7266c | 90 | |
jplunkett | 0:3f9d7ef7266c | 91 | Resolution _dev_resolution; |
jplunkett | 0:3f9d7ef7266c | 92 | Format _dev_format; |
jplunkett | 0:3f9d7ef7266c | 93 | uint32_t _dev_baud; |
jplunkett | 0:3f9d7ef7266c | 94 | |
jplunkett | 0:3f9d7ef7266c | 95 | uint32_t picture_length; |
jplunkett | 0:3f9d7ef7266c | 96 | uint32_t picture_data_id; |
jplunkett | 0:3f9d7ef7266c | 97 | uint32_t picture_data_id_count; |
jplunkett | 0:3f9d7ef7266c | 98 | uint8_t picture_buffer[128]; |
jplunkett | 0:3f9d7ef7266c | 99 | uint32_t picture_buffer_size_limit; |
jplunkett | 0:3f9d7ef7266c | 100 | uint32_t picture_buffer_pos; |
jplunkett | 0:3f9d7ef7266c | 101 | uint32_t picture_buffer_size; |
jplunkett | 0:3f9d7ef7266c | 102 | |
jplunkett | 0:3f9d7ef7266c | 103 | uint8_t _read_buf[sizeof(picture_buffer) + 1]; |
jplunkett | 0:3f9d7ef7266c | 104 | uint32_t _read_buf_head; |
jplunkett | 0:3f9d7ef7266c | 105 | uint32_t _read_buf_tail; |
jplunkett | 0:3f9d7ef7266c | 106 | uint32_t _read_wake_pos; |
jplunkett | 0:3f9d7ef7266c | 107 | Semaphore _read_sem; |
jplunkett | 1:06afc809909b | 108 | |
jplunkett | 1:06afc809909b | 109 | void (*log_func)(const char* fmt, ...); |
jplunkett | 0:3f9d7ef7266c | 110 | }; |
jplunkett | 0:3f9d7ef7266c | 111 | |
jplunkett | 0:3f9d7ef7266c | 112 | #endif |