Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:5bf7e3564c3b, committed 2012-06-17
- Comitter:
- esmiwa
- Date:
- Sun Jun 17 01:15:35 2012 +0000
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CameraC1098/CameraC1098.cpp Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,368 @@
+#include "mbed.h"
+#include "CameraC1098.h"
+//Camera() class
+CameraC1098::CameraC1098(PinName tx, PinName rx, Baud baud) : serial(tx, rx)
+{
+ serial.baud((int)baud);
+}
+//inherited class
+CameraC1098::~CameraC1098() {};
+//sync
+bool CameraC1098::sync()
+{
+ waitIdle();
+
+ for (int i = 0; i < SYNCMAX; i++) {
+ if (true == sendSync()) {
+ if (true == recvAckOrNck()) {
+ if (true == recvSync()) {
+ if (true == sendAck(0x0D, 0x00)) {
+ wait_ms(500);
+ return true;
+ }
+ }
+ }
+ }
+ wait_ms(10);
+ }
+ return false;
+}
+//initial
+bool CameraC1098::init(JpegResolution jr)
+{
+ waitIdle();
+ bool en;
+
+ en = sendInitial(jr);
+ if (true != en) {return en;}
+ waitRecv();
+ en = recvAckOrNck();
+ if (true != en) {return en;}
+ return true;
+}
+//new
+bool CameraC1098::setupPackageSize(uint16_t packageSize)
+{
+ static bool alreadySetupPackageSize = false;
+ bool en;
+ if (!alreadySetupPackageSize) {
+ en = sendSetPackageSize(packageSize);
+ if (true != en) {return en;}
+ waitRecv();
+ en = recvAckOrNck();
+ if (true != en) {return en;}
+ alreadySetupPackageSize = true;
+ }
+
+ return true;
+}
+//JpegSnapshotPicture
+bool CameraC1098::getJpegSnapshotPicture(void(*func)(char *buf, size_t siz))
+{
+ waitIdle();
+ bool en;
+
+ en = sendSnapshot(CompressedPicture, 1);
+ if (true != en) {return en;}
+ waitRecv();
+ en = recvAckOrNck();
+ if (true != en) {return en;}
+
+ en = sendGetPicture(SnapshotPicture);
+ if (true != en) {return en;}
+ waitRecv();
+ en = recvAckOrNck();
+ if (true != en) {return en;}
+ //snapshot picture Data
+ DataType dt;
+ uint32_t length = 0;
+ waitRecv();
+ en = recvData(&dt, &length);
+ if (true != en) {return en;}
+ en = sendAck(0x00, 0);
+ if (true != en) {return en;}
+
+ char databuf[packageSize - 6];
+ uint16_t pkg_total = length / (packageSize - 6);
+ for (int i = 0; i <= (int)pkg_total; i++) {
+ uint16_t checksum = 0;
+ // ID.
+ char idbuf[2];
+ waitRecv();
+ if (!recvBytes(idbuf, sizeof(idbuf))) {return false;}
+ checksum += idbuf[0];
+ checksum += idbuf[1];
+ uint16_t id = (idbuf[1] << 8) | (idbuf[0] << 0);
+ if (id != i) {return false;}
+ // Size of the data.
+ char dsbuf[2];
+ waitRecv();
+ if (!recvBytes(dsbuf, sizeof(dsbuf))) {return false;}
+ // Received the data.
+ checksum += dsbuf[0];
+ checksum += dsbuf[1];
+ uint16_t ds = (dsbuf[1] << 8) | (dsbuf[0] << 0);
+ waitRecv();
+ if (!recvBytes(&databuf[0], ds)) {return false;}
+ for (int j = 0; j < ds; j++) {checksum += databuf[j];}
+ // Verify code.
+ char vcbuf[2];
+ waitRecv();
+ if (!recvBytes(vcbuf, sizeof(vcbuf))) {return false;}
+ uint16_t vc = (vcbuf[1] << 8) | (vcbuf[0] << 0);
+ if (vc != (checksum & 0xff)) {return false;}
+ //Call a call back function.You can block this function while working.
+ func(databuf, ds);
+ //We should wait for camera working before reply a ACK.
+ wait_ms(50);
+ en = sendAck(0x00, 1 + i);
+ if (true != en) {return en;}
+ }
+ return true;
+}
+ //NEW change baud rate 14400 -> 115200bps
+ bool CameraC1098::getnewbaud()
+ {
+ newbaud();
+ return true;
+ }
+//sendInitial
+bool CameraC1098::sendInitial(JpegResolution jr)
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x01;
+ send[2] = 0x04;//115200bau
+ send[3] = 0x07;//JpegColor
+ send[4] = 0x00;//default
+ send[5] = (char)jr;
+
+ if (!sendBytes(send, sizeof(send))) {return false; }
+ return true;
+}
+//sendgetPictyure
+bool CameraC1098::sendGetPicture(PictureType pt) {
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x04;
+ send[2] = 0x01;//(char)pt;
+ send[3] = 0x00;
+ send[4] = 0x00;
+ send[5] = 0x00;
+
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+//sendSnapshot
+bool CameraC1098::sendSnapshot(SnapshotType st, uint16_t skipFrames)
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x05;
+ send[2] = 0x00;//(char)st;
+ send[3] = (skipFrames >> 0) & 0xff;
+ send[4] = (skipFrames >> 8) & 0xff;
+ send[5] = 0x00;
+
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+//sendSetOackagesize
+bool CameraC1098::sendSetPackageSize(uint16_t packageSize)
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x06;
+ send[2] = 0x08;
+ send[3] = (packageSize >> 0) & 0xff;
+ send[4] = (packageSize >> 8) & 0xff;
+ send[5] = 0x00;
+
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+//sendSetBaudrate
+//bool CameraC1098::sendSetBaudrate(Baud baud)
+//{
+// char send[COMMAND_LENGTH];
+// static struct baud_list {
+// Baud baud;
+// uint8_t div1st;
+// uint8_t div2nd;
+// } baudtable [] = {
+// { Baud7200, 0xff, 0x01 },
+// { Baud9600, 0xbf, 0x01 },
+// { Baud14400, 0x7f, 0x01 },
+// { Baud19200, 0x5f, 0x01 },
+// { Baud28800, 0x3f, 0x01 },
+// { Baud38400, 0x2f, 0x01 },
+// { Baud57600, 0x1f, 0x01 },
+// { Baud115200, 0x0f, 0x01 }
+// };
+//
+// uint8_t div1st = 0x00, div2nd = 0x00;
+// struct baud_list *p = &baudtable[0];
+// for (int i = 0; i < sizeof(baudtable) / sizeof(baudtable[0]); i++) {
+// if (p->baud == baud) {
+// div1st = p->div1st;
+// div2nd = p->div2nd;
+// }
+// p++;
+// }
+
+// send[0] = 0xAA;
+// send[1] = 0x07;
+// send[2] = div1st;
+// send[3] = div2nd;
+// send[4] = 0x00;
+// send[5] = 0x00;
+//
+// if (!sendBytes(send, sizeof(send))) {return false;}
+//
+// return true;
+//}
+//sendReset
+bool CameraC1098::sendReset(ResetType rt, bool specialReset)
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x08;
+ send[2] = (int)rt;
+ send[3] = 0x00;
+ send[4] = 0x00;
+ send[5] = 0x00;//specialReset ? 0xff : 0x00;
+ /*
+ * Special reset : If the parameter is 0xFF, the command is a special Reset command and the firmware responds to it immediately.
+ */
+
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+//sendPowerOff
+bool CameraC1098::sendPowerOff()
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x09;
+ send[2] = 0x00;
+ send[3] = 0x00;
+ send[4] = 0x00;
+ send[5] = 0x00;
+
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+//recvData
+bool CameraC1098::recvData(DataType *dt, uint32_t *length)
+{
+ char recv[COMMAND_LENGTH];
+ if (!recvBytes(recv, sizeof(recv))) {return false;}
+ if ((0xAA != recv[0]) || (0x0A != recv[1])) {return false;}
+ *dt = (DataType)recv[2];
+ *length = (recv[5] << 16) | (recv[4] << 8) | (recv[3] << 0);
+ return true;
+}
+//sendSync
+bool CameraC1098::sendSync()
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x0D;
+ send[2] = 0x00;
+ send[3] = 0x00;
+ send[4] = 0x00;
+ send[5] = 0x00;
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+//recvSync
+bool CameraC1098::recvSync()
+{
+ char recv[COMMAND_LENGTH];
+ if (!recvBytes(recv, sizeof(recv))) {return false;}
+ if ((0xAA != recv[0]) || (0x0D != recv[1])) {return false;}
+ return true;
+}
+// SendAck
+//@param commandId The command with that ID is acknowledged by this command.
+//@param packageId For acknowledging Data command, these two bytes represent the requested package ID. While for acknowledging other commands, these two bytes are set to 00h.
+bool CameraC1098::sendAck(uint8_t commandId, uint16_t packageId)
+{
+ char send[COMMAND_LENGTH];
+ send[0] = 0xAA;
+ send[1] = 0x0E;
+ send[2] = commandId;
+ send[3] = 0x00; // ACK counter is not used.
+ send[4] = (packageId >> 0) & 0xff;
+ send[5] = (packageId >> 8) & 0xff;
+
+ if (!sendBytes(send, sizeof(send))) {return false;}
+ return true;
+}
+// Receive ACK or NCK.
+bool CameraC1098::recvAckOrNck()
+{
+ char recv[COMMAND_LENGTH];
+ if (!recvBytes(recv, sizeof(recv))) {return false;}
+ if ((0xAA == recv[0]) && (0x0E == recv[1])) {return true;}
+ if ((0xAA == recv[0]) && (0x0F == recv[1])) {return true;}
+ return false;
+}
+//Send bytes to camera module.
+//@param buf Pointer to the data buffer.
+//@param len Length of the data buffer.
+bool CameraC1098::sendBytes(char *buf, size_t len, int timeout_us)
+{
+ for (uint32_t i = 0; i < (uint32_t)len; i++) {
+ int cnt = 0;
+ while (!serial.writeable()) {
+ wait_us(1);
+ cnt++;
+ if (timeout_us < cnt) {
+ return false;
+ }
+ }
+ serial.putc(buf[i]);
+ }
+ return true;
+}
+//Receive bytes from camera module.
+//@param buf Pointer to the data buffer.
+//@param len Length of the data buffer.
+bool CameraC1098::recvBytes(char *buf, size_t len, int timeout_us)
+{
+ for (uint32_t i = 0; i < (uint32_t)len; i++) {
+ int cnt = 0;
+ while (!serial.readable()) {
+ wait_us(1);
+ cnt++;
+ if (timeout_us < cnt) {
+ return false;
+ }
+ }
+ buf[i] = serial.getc();
+ }
+ return true;
+}
+//Wait received.
+bool CameraC1098::waitRecv()
+{
+ while (!serial.readable()) {
+ }
+ return true;
+}
+//Wait idle state.
+bool CameraC1098::waitIdle()
+{
+ while (serial.readable()) {
+ serial.getc();
+ }
+ return true;
+}
+ //NEW change baud rate 14400 -> 115200bps
+ bool CameraC1098::newbaud()
+ {
+ Baud baud=CameraC1098::Baud115200;
+ serial.baud((int)baud);
+ return true;
+ }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CameraC1098/CameraC1098.h Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,158 @@
+//CameraC1098.h
+//#include "mbed.h"
+#include "SerialBuffered.h"
+
+#ifndef _CAMERA_C1098_H_
+#define _CAMERA_C1098_H_
+
+// Class: CameraC1098
+class CameraC1098 {
+public:
+ /**
+ * Color type.
+ */
+ enum ColorType {
+ Jpeg = 0x07
+ };
+ /**
+ * JPEG resolution.
+ */
+ enum JpegResolution {
+ JpegResolution320x240 = 0x05,
+ JpegResolution640x480 = 0x07
+ };
+ /**
+ * Picture type.
+ */
+ enum PictureType {
+ SnapshotPicture = 0x01,
+ PreviewPicture = 0x02,
+ JpegPreviewPicture = 0x05
+ };
+ /**
+ * Snapshot type.
+ */
+ enum SnapshotType {
+ CompressedPicture = 0x00,
+ UncompressedPicture = 0x01
+ };
+ /**
+ * Baud rate.
+ */
+ enum Baud {
+ Baud14400 = 14400, //Default
+ Baud19200 = 19200,
+ Baud28800 = 28800,
+ Baud38400 = 38400,
+ Baud57600 = 57600,
+ Baud115200 = 115200, //Default
+ Baud230400 = 230400,
+ Baud460800 = 460800
+ };
+ /**
+ * Reset type.
+ */
+ enum ResetType {
+ ResetWholeSystem = 0x00,
+ ResetStateMachines = 0x01
+ };
+ /**
+ * Data type.
+ */
+ enum DataType {
+ DataTypeSnapshotPicture = 0x01,
+ DataTypePreviewPicture = 0x02,
+ DataTypeJpegPreviewPicture = 0x05
+ };
+ /**
+ * Constructor.
+ *
+ * @param tx A pin for transmit.
+ * @param rx A pin for receive.
+ * @param baud Baud rate. (Default is Baud115200.)
+ */
+ //CameraC1098(PinName tx, PinName rx, Baud baud = Baud19200);
+ CameraC1098(PinName tx, PinName rx, Baud baud = Baud115200);
+ /**
+ * Destructor.
+ */
+ ~CameraC1098();
+ /**
+ * Make a sync. for baud rate.
+ */
+ bool sync();
+ /**
+ * Initialize.
+ * @param jr JPEG resolution.
+ */
+ bool init(JpegResolution jr);
+ /**
+ *set packet size
+ */
+ bool setupPackageSize(uint16_t packageSize);
+ /**
+ * Get uncompressed snapshot picture.
+ *
+ * @param func A pointer to a callback function.
+ * Please do NOT block this callback function.
+ * Because the camera module transmit image datas continuously.
+ * @return Status of the error.
+ */
+ bool getUncompressedSnapshotPicture(void(*func)(size_t done, size_t total, char c));
+ /**
+ * Get uncompressed preview picture.
+ *
+ * @param func A pointer to a callback function.
+ * Please do NOT block this callback function.
+ * Because the camera module transmit image datas continuously.
+ * @return Status of the error.
+ */
+ bool getUncompressedPreviewPicture(void(*func)(size_t done, size_t total, char c));
+ /**
+ * Get JPEG snapshot picture.
+ *
+ * @param func A pointer to a callback function.
+ * You can block this function until saving the image datas.
+ * @return Status of the error.
+ */
+// bool getJpegSnapshotPicture(void(*func)(char *buf, size_t siz));
+ bool getJpegSnapshotPicture(void(*func)(char *buf, size_t siz));
+ /**
+ * Get JPEG preview picture.
+ *
+ * @param func A pointer to a callback function.
+ * You can block this function until saving the image datas.
+ * @return Status of the error.
+ */
+ bool getJpegPreviewPicture(void(*func)(char *buf, size_t siz));
+ //NEW
+ bool getnewbaud();
+
+private:
+ SerialBuffered serial;
+ static const int COMMAND_LENGTH = 6;
+ static const int SYNCMAX = 60;
+ static const int packageSize = 512;
+
+ bool sendInitial(JpegResolution jr);
+ bool sendGetPicture(PictureType pt);
+ bool sendSnapshot(SnapshotType st, uint16_t skipFrames);
+ bool sendSetPackageSize(uint16_t packageSize);
+// bool sendSetBaudrate(Baud baud);
+ bool sendReset(ResetType rt, bool specialReset);
+ bool sendPowerOff();
+ bool recvData(DataType *dt, uint32_t *length);
+ bool sendSync();
+ bool recvSync();
+ bool sendAck(uint8_t commandId, uint16_t packageId);
+ bool recvAckOrNck();
+
+ bool sendBytes(char *buf, size_t len, int timeout_us = 20000);
+ bool recvBytes(char *buf, size_t len, int timeout_us = 20000);
+ bool waitRecv();
+ bool waitIdle();
+ //NEW
+ bool newbaud();
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CameraC1098/SerialBuffered.cpp Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,99 @@
+#include "mbed.h"
+#include "SerialBuffered.h"
+
+/**
+ * Create a buffered serial class.
+ *
+ * @param tx A pin for transmit.
+ * @param rx A pin for receive.
+ */
+SerialBuffered::SerialBuffered(PinName tx, PinName rx) : Serial(tx, rx) {
+ indexContentStart = 0;
+ indexContentEnd = 0;
+ timeout = 1;
+ attach(this, &SerialBuffered::handleInterrupt);
+}
+
+/**
+ * Destroy.
+ */
+SerialBuffered::~SerialBuffered() {
+}
+
+/**
+ * Set timeout for getc().
+ *
+ * @param ms milliseconds. (-1:Disable timeout)
+ */
+void SerialBuffered::setTimeout(int ms) {
+ timeout = ms;
+}
+
+/**
+ * Read requested bytes.
+ *
+ * @param bytes A pointer to a buffer.
+ * @param requested Length.
+ *
+ * @return Readed byte length.
+ */
+size_t SerialBuffered::readBytes(uint8_t *bytes, size_t requested) {
+ int i = 0;
+ while (i < requested) {
+ int c = getc();
+ if (c < 0) {
+ break;
+ }
+ bytes[i] = c;
+ i++;
+ }
+ return i;
+}
+
+/**
+ * Get a character.
+ *
+ * @return A character. (-1:timeout)
+ */
+int SerialBuffered::getc() {
+ timer.reset();
+ timer.start();
+ while (indexContentStart == indexContentEnd) {
+ wait_ms(1);
+ if ((timeout > 0) && (timer.read_ms() > timeout)) {
+ /*
+ * Timeout occured.
+ */
+ // printf("Timeout occured.\n");
+ return EOF;
+ }
+ }
+ timer.stop();
+
+ uint8_t result = buffer[indexContentStart++];
+ indexContentStart = indexContentStart % BUFFERSIZE;
+
+ return result;
+}
+
+/**
+ * Returns 1 if there is a character available to read, 0 otherwise.
+ */
+int SerialBuffered::readable() {
+ return indexContentStart != indexContentEnd;
+}
+
+void SerialBuffered::handleInterrupt() {
+ while (Serial::readable()) {
+ if (indexContentStart == ((indexContentEnd + 1) % BUFFERSIZE)) {
+ /*
+ * Buffer overrun occured.
+ */
+ // printf("Buffer overrun occured.\n");
+ Serial::getc();
+ } else {
+ buffer[indexContentEnd++] = Serial::getc();
+ indexContentEnd = indexContentEnd % BUFFERSIZE;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CameraC1098/SerialBuffered.h Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,61 @@
+#ifndef _SERIAL_BUFFERED_H_
+#define _SERIAL_BUFFERED_H_
+
+/**
+ * Buffered serial class.
+ */
+class SerialBuffered : public Serial {
+public:
+ /**
+ * Create a buffered serial class.
+ *
+ * @param tx A pin for transmit.
+ * @param rx A pin for receive.
+ */
+ SerialBuffered(PinName tx, PinName rx);
+
+ /**
+ * Destroy.
+ */
+ virtual ~SerialBuffered();
+
+ /**
+ * Get a character.
+ *
+ * @return A character. (-1:timeout)
+ */
+ int getc();
+
+ /**
+ * Returns 1 if there is a character available to read, 0 otherwise.
+ */
+ int readable();
+
+ /**
+ * Set timeout for getc().
+ *
+ * @param ms milliseconds. (-1:Disable timeout)
+ */
+ void setTimeout(int ms);
+
+ /**
+ * Read requested bytes.
+ *
+ * @param bytes A pointer to a buffer.
+ * @param requested Length.
+ *
+ * @return Readed byte length.
+ */
+ size_t readBytes(uint8_t *bytes, size_t requested);
+
+private:
+ void handleInterrupt();
+ static const int BUFFERSIZE = 4096;
+ uint8_t buffer[BUFFERSIZE]; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
+ uint16_t indexContentStart; // index of first bytes of content
+ uint16_t indexContentEnd; // index of bytes after last byte of content
+ int timeout;
+ Timer timer;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FatFileSystem.lib Sun Jun 17 01:15:35 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/shintamainjp/code/FatFileSystem/#8c55801ce311
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Sun Jun 17 01:15:35 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/SomeRandomBloke/code/SDFileSystem/#9c5f0c655284
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD/TextLCD.cpp Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,159 @@
+/* mbed TextLCD Library, for a 4-bit LCD based on HD44780
+ * Copyright (c) 2007-2010, sford, http://mbed.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "TextLCD.h"
+#include "mbed.h"
+
+TextLCD::TextLCD(PinName rs, PinName e, PinName d0, PinName d1,
+ PinName d2, PinName d3, LCDType type) : _rs(rs),
+ _e(e), _d(d0, d1, d2, d3),
+ _type(type) {
+
+ _e = 1;
+ _rs = 0; // command mode
+
+ wait(0.015); // Wait 15ms to ensure powered up
+
+ // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+ for (int i=0; i<3; i++) {
+ writeByte(0x3);
+ wait(0.00164); // this command takes 1.64ms, so wait for it
+ }
+ writeByte(0x2); // 4-bit mode
+ wait(0.000040f); // most instructions take 40us
+
+ writeCommand(0x28); // Function set 001 BW N F - -
+ writeCommand(0x0C);
+ writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+ cls();
+}
+
+void TextLCD::character(int column, int row, int c) {
+ int a = address(column, row);
+ writeCommand(a);
+ writeData(c);
+}
+
+void TextLCD::cls() {
+ writeCommand(0x01); // cls, and set cursor to 0
+ wait(0.00164f); // This command takes 1.64 ms
+ locate(0, 0);
+}
+
+void TextLCD::locate(int column, int row) {
+ _column = column;
+ _row = row;
+}
+
+int TextLCD::_putc(int value) {
+ if (value == '\n') {
+ _column = 0;
+ _row++;
+ if (_row >= rows()) {
+ _row = 0;
+ }
+ } else {
+ character(_column, _row, value);
+ _column++;
+ if (_column >= columns()) {
+ _column = 0;
+ _row++;
+ if (_row >= rows()) {
+ _row = 0;
+ }
+ }
+ }
+ return value;
+}
+
+int TextLCD::_getc() {
+ return -1;
+}
+
+void TextLCD::writeByte(int value) {
+ _d = value >> 4;
+ wait(0.000040f); // most instructions take 40us
+ _e = 0;
+ wait(0.000040f);
+ _e = 1;
+ _d = value >> 0;
+ wait(0.000040f);
+ _e = 0;
+ wait(0.000040f); // most instructions take 40us
+ _e = 1;
+}
+
+void TextLCD::writeCommand(int command) {
+ _rs = 0;
+ writeByte(command);
+}
+
+void TextLCD::writeData(int data) {
+ _rs = 1;
+ writeByte(data);
+}
+
+int TextLCD::address(int column, int row) {
+ switch (_type) {
+ case LCD20x4:
+ switch (row) {
+ case 0:
+ return 0x80 + column;
+ case 1:
+ return 0xc0 + column;
+ case 2:
+ return 0x94 + column;
+ case 3:
+ return 0xd4 + column;
+ }
+ case LCD16x2B:
+ return 0x80 + (row * 40) + column;
+ case LCD16x2:
+ case LCD20x2:
+ default:
+ return 0x80 + (row * 0x40) + column;
+ }
+}
+
+int TextLCD::columns() {
+ switch (_type) {
+ case LCD20x4:
+ case LCD20x2:
+ return 20;
+ case LCD16x2:
+ case LCD16x2B:
+ default:
+ return 16;
+ }
+}
+
+int TextLCD::rows() {
+ switch (_type) {
+ case LCD20x4:
+ return 4;
+ case LCD16x2:
+ case LCD16x2B:
+ case LCD20x2:
+ default:
+ return 2;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD/TextLCD.h Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,111 @@
+/* mbed TextLCD Library, for a 4-bit LCD based on HD44780
+ * Copyright (c) 2007-2010, sford, http://mbed.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_TEXTLCD_H
+#define MBED_TEXTLCD_H
+
+#include "mbed.h"
+
+/** A TextLCD interface for driving 4-bit HD44780-based LCDs
+ *
+ * Currently supports 16x2, 20x2 and 20x4 panels
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "TextLCD.h"
+ *
+ * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3
+ *
+ * int main() {
+ * lcd.printf("Hello World!\n");
+ * }
+ * @endcode
+ */
+class TextLCD : public Stream {
+public:
+
+ /** LCD panel format */
+ enum LCDType {
+ LCD16x2 /**< 16x2 LCD panel (default) */
+ , LCD16x2B /**< 16x2 LCD panel alternate addressing */
+ , LCD20x2 /**< 20x2 LCD panel */
+ , LCD20x4 /**< 20x4 LCD panel */
+ };
+
+ /** Create a TextLCD interface
+ *
+ * @param rs Instruction/data control line
+ * @param e Enable line (clock)
+ * @param d0-d3 Data lines
+ * @param type Sets the panel size/addressing mode (default = LCD16x2)
+ */
+ TextLCD(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2);
+
+#if DOXYGEN_ONLY
+ /** Write a character to the LCD
+ *
+ * @param c The character to write to the display
+ */
+ int putc(int c);
+
+ /** Write a formated string to the LCD
+ *
+ * @param format A printf-style format string, followed by the
+ * variables to use in formating the string.
+ */
+ int printf(const char* format, ...);
+#endif
+
+ /** Locate to a screen column and row
+ *
+ * @param column The horizontal position from the left, indexed from 0
+ * @param row The vertical position from the top, indexed from 0
+ */
+ void locate(int column, int row);
+
+ /** Clear the screen and locate to 0,0 */
+ void cls();
+
+ int rows();
+ int columns();
+
+protected:
+
+ // Stream implementation functions
+ virtual int _putc(int value);
+ virtual int _getc();
+
+ int address(int column, int row);
+ void character(int column, int row, int c);
+ void writeByte(int value);
+ void writeCommand(int command);
+ void writeData(int data);
+
+ DigitalOut _rs, _e;
+ BusOut _d;
+ LCDType _type;
+
+ int _column;
+ int _row;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Jun 17 01:15:35 2012 +0000
@@ -0,0 +1,88 @@
+//main.cpp
+#include "mbed.h"
+#include "CameraC1098.h"
+#include "SDFileSystem.h"
+#include "TextLCD.h"
+
+// Definitions.
+#define USE_JPEG_HIGH_RESOLUTION 1
+#define USE_SD_CARD 0
+
+//Variables.
+static const int RAWIMG_X = 80;
+static const int RAWIMG_Y = 60;
+static char buf[RAWIMG_X * RAWIMG_Y * 2];
+static FILE *fp_jpeg;
+static const int packageSize = 512;
+int i=0;
+int shutter=0;
+//Modules.
+#if USE_SD_CARD //USE_SD_CDARD=0:Local, =1:SD
+SDFileSystem sd(p5, p6, p7, p8, "fs");
+#else
+LocalFileSystem fs("fs");
+#endif
+
+//CameraC1098
+CameraC1098 camera(p9, p10, CameraC1098::Baud14400);
+//ErrorNunber constracture
+bool err;
+//
+//CameraC1098::NoError = 0x00;
+
+//TextLCD
+TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
+//LED
+DigitalOut myled1(LED1);
+DigitalOut myled4(LED4);
+InterruptIn tact(p22);
+//setting camera
+void camera_set(void) {
+ err = camera.sync(); //syncronising
+ err = camera.init(CameraC1098::JpegResolution640x480); //initialising
+ err = camera.getnewbaud(); //change baudrate 14400 -> 115200bps
+}
+//setting packetsize
+void packagesize_set(void){
+ err = camera.setupPackageSize(packageSize);
+}
+//saving image data to fp_jpd
+void jpeg_callback(char *buf, size_t siz) { //*buf:image buffer size, siz:image size
+ for (int i = 0; i < (int)siz; i++) {
+ fprintf(fp_jpeg, "%c", buf[i]);
+ }
+}
+//getting Jpeg snapshot picture
+void snapshot_get(void)
+{
+ char fname[64];
+ snprintf(fname, sizeof(fname), "/fs/image%02d.jpg",i);
+ fp_jpeg = fopen(fname, "w");
+ err = camera.getJpegSnapshotPicture(jpeg_callback);
+ fclose(fp_jpeg);
+ }
+//shutter(p22)
+void getshutter(){
+ shutter=1;
+}
+//
+int main()
+{
+ tact.fall(&getshutter);
+ lcd.cls();lcd.printf("Camera C1098");
+ camera_set();
+ wait_ms(100);
+ packagesize_set();
+ lcd.cls();lcd.printf("camera OK");
+ while(1){
+ if(shutter==1){
+ myled1=1;lcd.cls();
+ snapshot_get();
+ shutter=0;
+ i++;
+ myled1=0;lcd.cls();lcd.printf("NEXT OK");
+ }
+ myled4=!myled4;
+ wait(0.25);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jun 17 01:15:35 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479