Hepta_Cam&GPS
Dependents: HEPTA2_assembly_0720 HEPTA2_ALL HEPTA2_ALL_ver0803_02
Fork of HeptaSerial by
CameraC1098.h@1:d16a4c3a272a, 2017-07-19 (annotated)
- Committer:
- hepta2ume
- Date:
- Wed Jul 19 09:07:30 2017 +0000
- Revision:
- 1:d16a4c3a272a
- Parent:
- 0:5a6468b4164d
hepta_cam
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:5a6468b4164d | 1 | /** |
sunifu | 0:5a6468b4164d | 2 | * C1098-SS device driver class (Version 1.0) |
sunifu | 0:5a6468b4164d | 3 | * Reference documents: C1098-SS User Manual v1.0 2012.5.6 |
sunifu | 0:5a6468b4164d | 4 | * |
sunifu | 0:5a6468b4164d | 5 | * CameraC328Library |
sunifu | 0:5a6468b4164d | 6 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
sunifu | 0:5a6468b4164d | 7 | * http://shinta.main.jp/ |
sunifu | 0:5a6468b4164d | 8 | * |
sunifu | 0:5a6468b4164d | 9 | * CameraC1098-SS Library |
sunifu | 0:5a6468b4164d | 10 | * Copyright (C) 2012 Tadao Iida |
sunifu | 0:5a6468b4164d | 11 | */ |
sunifu | 0:5a6468b4164d | 12 | |
sunifu | 0:5a6468b4164d | 13 | #include "mbed.h" |
sunifu | 0:5a6468b4164d | 14 | #include "SerialBuffered.h" |
sunifu | 0:5a6468b4164d | 15 | |
sunifu | 0:5a6468b4164d | 16 | #ifndef _CAMERA_C1098_H_ |
sunifu | 0:5a6468b4164d | 17 | #define _CAMERA_C1098_H_ |
sunifu | 0:5a6468b4164d | 18 | |
sunifu | 0:5a6468b4164d | 19 | /* |
sunifu | 0:5a6468b4164d | 20 | * Class: CameraC1098 |
sunifu | 0:5a6468b4164d | 21 | */ |
sunifu | 0:5a6468b4164d | 22 | |
sunifu | 0:5a6468b4164d | 23 | class CameraC1098 { |
sunifu | 0:5a6468b4164d | 24 | public: |
sunifu | 0:5a6468b4164d | 25 | |
sunifu | 0:5a6468b4164d | 26 | /** |
sunifu | 0:5a6468b4164d | 27 | * @enum JPEG resolution. |
sunifu | 0:5a6468b4164d | 28 | */ |
sunifu | 0:5a6468b4164d | 29 | enum JpegResolution { |
sunifu | 0:5a6468b4164d | 30 | JpegResolution80x64 = 0x01, // unofficial |
sunifu | 0:5a6468b4164d | 31 | JpegResolution160x128 = 0x03, // unofficial |
sunifu | 0:5a6468b4164d | 32 | JpegResolution320x240 = 0x05, // QVGA |
sunifu | 0:5a6468b4164d | 33 | JpegResolution640x480 = 0x07 // VGA |
sunifu | 0:5a6468b4164d | 34 | }; |
sunifu | 0:5a6468b4164d | 35 | |
sunifu | 0:5a6468b4164d | 36 | /** |
sunifu | 0:5a6468b4164d | 37 | * @enum Error number. |
sunifu | 0:5a6468b4164d | 38 | */ |
sunifu | 0:5a6468b4164d | 39 | enum ErrorNumber { |
sunifu | 0:5a6468b4164d | 40 | NoError = 0x00, |
sunifu | 0:5a6468b4164d | 41 | UnexpectedReply = 0x04, |
sunifu | 0:5a6468b4164d | 42 | ParameterError = 0x0b, |
sunifu | 0:5a6468b4164d | 43 | SendRegisterTimeout = 0x0c, |
sunifu | 0:5a6468b4164d | 44 | CommandIdError = 0x0d, |
sunifu | 0:5a6468b4164d | 45 | CommandHeaderError = 0xf0, |
sunifu | 0:5a6468b4164d | 46 | SetTransferPackageSizeWrong = 0x11 |
sunifu | 0:5a6468b4164d | 47 | }; |
sunifu | 0:5a6468b4164d | 48 | |
sunifu | 0:5a6468b4164d | 49 | /** |
sunifu | 0:5a6468b4164d | 50 | * @enum Baud rate. |
sunifu | 0:5a6468b4164d | 51 | */ |
sunifu | 0:5a6468b4164d | 52 | enum Baud { |
sunifu | 0:5a6468b4164d | 53 | Baud460800 = 0x02, |
sunifu | 0:5a6468b4164d | 54 | Baud230400 = 0x03, |
sunifu | 0:5a6468b4164d | 55 | Baud115200 = 0x04, |
sunifu | 0:5a6468b4164d | 56 | Baud57600 = 0x05, |
sunifu | 0:5a6468b4164d | 57 | Baud28800 = 0x06, |
sunifu | 0:5a6468b4164d | 58 | Baud14400 = 0x07 // Default. |
sunifu | 0:5a6468b4164d | 59 | }; |
sunifu | 0:5a6468b4164d | 60 | |
sunifu | 0:5a6468b4164d | 61 | /** |
sunifu | 0:5a6468b4164d | 62 | * @enum Reset type. |
sunifu | 0:5a6468b4164d | 63 | */ |
sunifu | 0:5a6468b4164d | 64 | enum ResetType { |
sunifu | 0:5a6468b4164d | 65 | Nomal = 0x00, |
sunifu | 0:5a6468b4164d | 66 | High = 0xff |
sunifu | 0:5a6468b4164d | 67 | }; |
sunifu | 0:5a6468b4164d | 68 | |
sunifu | 0:5a6468b4164d | 69 | /** Constructor. |
sunifu | 0:5a6468b4164d | 70 | * |
sunifu | 0:5a6468b4164d | 71 | * @param tx A pin for transmit. |
sunifu | 0:5a6468b4164d | 72 | * @param rx A pin for receive. |
sunifu | 0:5a6468b4164d | 73 | * @param baud Baud rate. (Default is 14400.) |
sunifu | 0:5a6468b4164d | 74 | */ |
sunifu | 0:5a6468b4164d | 75 | CameraC1098(PinName tx, PinName rx, int baud = 14400); |
sunifu | 0:5a6468b4164d | 76 | |
sunifu | 0:5a6468b4164d | 77 | /** Destructor. |
sunifu | 0:5a6468b4164d | 78 | * |
sunifu | 0:5a6468b4164d | 79 | */ |
sunifu | 0:5a6468b4164d | 80 | ~CameraC1098(); |
sunifu | 0:5a6468b4164d | 81 | |
sunifu | 0:5a6468b4164d | 82 | /** sync |
sunifu | 0:5a6468b4164d | 83 | * Make a sync. for baud rate. |
sunifu | 0:5a6468b4164d | 84 | */ |
sunifu | 0:5a6468b4164d | 85 | ErrorNumber sync(); |
sunifu | 0:5a6468b4164d | 86 | |
sunifu | 0:5a6468b4164d | 87 | /** Initialize. |
sunifu | 0:5a6468b4164d | 88 | * |
sunifu | 0:5a6468b4164d | 89 | * |
sunifu | 0:5a6468b4164d | 90 | * @param baud Camera Interface Speed. |
sunifu | 0:5a6468b4164d | 91 | * @param jr JPEG resolution. |
sunifu | 0:5a6468b4164d | 92 | */ |
sunifu | 0:5a6468b4164d | 93 | ErrorNumber init(Baud baud, JpegResolution jr); |
sunifu | 0:5a6468b4164d | 94 | |
sunifu | 0:5a6468b4164d | 95 | /** getJpegSnapshotPicture |
sunifu | 0:5a6468b4164d | 96 | * Get JPEG snapshot picture. |
sunifu | 0:5a6468b4164d | 97 | * |
sunifu | 0:5a6468b4164d | 98 | * @param func A pointer to a callback function. |
sunifu | 0:5a6468b4164d | 99 | * You can block this function until saving the image datas. |
sunifu | 0:5a6468b4164d | 100 | * @return Status of the error. |
sunifu | 0:5a6468b4164d | 101 | */ |
hepta2ume | 1:d16a4c3a272a | 102 | ErrorNumber getJpegSnapshotPicture(); |
hepta2ume | 1:d16a4c3a272a | 103 | ErrorNumber getJpegSnapshotPicture_data(); |
sunifu | 0:5a6468b4164d | 104 | |
sunifu | 0:5a6468b4164d | 105 | /** setmbedBaud |
sunifu | 0:5a6468b4164d | 106 | * mbed Interface Speed. |
sunifu | 0:5a6468b4164d | 107 | * |
sunifu | 0:5a6468b4164d | 108 | * @param baud mbed Interface Speed. |
sunifu | 0:5a6468b4164d | 109 | */ |
sunifu | 0:5a6468b4164d | 110 | void setmbedBaud(Baud baud); |
hepta2ume | 1:d16a4c3a272a | 111 | void Sync(void); |
hepta2ume | 1:d16a4c3a272a | 112 | void initialize(Baud baud,JpegResolution jr); |
hepta2ume | 1:d16a4c3a272a | 113 | void test_jpeg_snapshot_picture(void); |
hepta2ume | 1:d16a4c3a272a | 114 | void test_jpeg_snapshot_data(void); |
hepta2ume | 1:d16a4c3a272a | 115 | void jpeg_callback(char *buf, size_t siz); |
sunifu | 0:5a6468b4164d | 116 | private: |
sunifu | 0:5a6468b4164d | 117 | SerialBuffered serial; |
sunifu | 0:5a6468b4164d | 118 | static const int COMMAND_LENGTH = 6; |
sunifu | 0:5a6468b4164d | 119 | static const int SYNCMAX = 60; |
sunifu | 0:5a6468b4164d | 120 | static const int packageSize = 256; |
hepta2ume | 1:d16a4c3a272a | 121 | static const int CAPTURE_FRAMES = 3; |
hepta2ume | 1:d16a4c3a272a | 122 | |
sunifu | 0:5a6468b4164d | 123 | ErrorNumber sendInitial(Baud band, JpegResolution jr); |
sunifu | 0:5a6468b4164d | 124 | ErrorNumber sendGetPicture(void); |
sunifu | 0:5a6468b4164d | 125 | ErrorNumber sendSnapshot(void); |
sunifu | 0:5a6468b4164d | 126 | ErrorNumber sendSetPackageSize(uint16_t packageSize); |
sunifu | 0:5a6468b4164d | 127 | ErrorNumber sendReset(ResetType specialReset); |
sunifu | 0:5a6468b4164d | 128 | ErrorNumber recvData(uint32_t *length); |
sunifu | 0:5a6468b4164d | 129 | ErrorNumber sendSync(); |
sunifu | 0:5a6468b4164d | 130 | ErrorNumber recvSync(); |
sunifu | 0:5a6468b4164d | 131 | ErrorNumber sendAck(uint8_t commandId, uint16_t packageId); |
sunifu | 0:5a6468b4164d | 132 | ErrorNumber recvAckOrNck(); |
sunifu | 0:5a6468b4164d | 133 | |
sunifu | 0:5a6468b4164d | 134 | bool sendBytes(char *buf, size_t len, int timeout_us = 20000); |
sunifu | 0:5a6468b4164d | 135 | bool recvBytes(char *buf, size_t len, int timeout_us = 20000); |
sunifu | 0:5a6468b4164d | 136 | bool waitRecv(); |
sunifu | 0:5a6468b4164d | 137 | bool waitIdle(); |
sunifu | 0:5a6468b4164d | 138 | }; |
sunifu | 0:5a6468b4164d | 139 | |
sunifu | 0:5a6468b4164d | 140 | #endif |