USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
fritz291
Date:
Fri Jun 26 19:30:55 2015 +0000
Revision:
26:53970cabf56d
Parent:
13:8774c07f12a5
Fixed small error in testAT function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 13:8774c07f12a5 1 // decodeMJPEG.cpp 2012/12/8
va009039 13:8774c07f12a5 2 // decode motion-jpeg to jpeg
va009039 13:8774c07f12a5 3 #include "mbed.h"
va009039 13:8774c07f12a5 4 #include "decodeMJPEG.h"
va009039 13:8774c07f12a5 5
va009039 13:8774c07f12a5 6 #define MARK_SOF0 0xc0
va009039 13:8774c07f12a5 7 #define MARK_DHT 0xc4
va009039 13:8774c07f12a5 8 #define MARK_RST0 0xd0
va009039 13:8774c07f12a5 9 #define MARK_RST7 0xd7
va009039 13:8774c07f12a5 10 #define MARK_SOI 0xd8
va009039 13:8774c07f12a5 11 #define MARK_EOI 0xd9
va009039 13:8774c07f12a5 12 #define MARK_SOS 0xda
va009039 13:8774c07f12a5 13 #define MARK_DQT 0xdb
va009039 13:8774c07f12a5 14 #define MARK_DRI 0xdd
va009039 13:8774c07f12a5 15 #define MARK_APP 0xe0
va009039 13:8774c07f12a5 16
va009039 13:8774c07f12a5 17 #define SEQ_INIT 0
va009039 13:8774c07f12a5 18 #define SEQ_SOI 1
va009039 13:8774c07f12a5 19 #define SEQ_FRAME 2
va009039 13:8774c07f12a5 20 #define SEQ_MARK 3
va009039 13:8774c07f12a5 21 #define SEQ_SEG_LEN 4
va009039 13:8774c07f12a5 22 #define SEQ_SEG_LEN2 5
va009039 13:8774c07f12a5 23 #define SEQ_SEG_BODY 6
va009039 13:8774c07f12a5 24 #define SEQ_SOS 7
va009039 13:8774c07f12a5 25 #define SEQ_SOS2 8
va009039 13:8774c07f12a5 26
va009039 13:8774c07f12a5 27 static const uint8_t dht[] = {
va009039 13:8774c07f12a5 28 0xFF,0xC4,0x01,0xA2,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,
va009039 13:8774c07f12a5 29 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
va009039 13:8774c07f12a5 30 0x0B,0x01,0x00,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,
va009039 13:8774c07f12a5 31 0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x10,0x00,
va009039 13:8774c07f12a5 32 0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7D,0x01,
va009039 13:8774c07f12a5 33 0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,
va009039 13:8774c07f12a5 34 0x71,0x14,0x32,0x81,0x91,0xA1,0x08,0x23,0x42,0xB1,0xC1,0x15,0x52,0xD1,0xF0,0x24,
va009039 13:8774c07f12a5 35 0x33,0x62,0x72,0x82,0x09,0x0A,0x16,0x17,0x18,0x19,0x1A,0x25,0x26,0x27,0x28,0x29,
va009039 13:8774c07f12a5 36 0x2A,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,
va009039 13:8774c07f12a5 37 0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
va009039 13:8774c07f12a5 38 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,
va009039 13:8774c07f12a5 39 0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,
va009039 13:8774c07f12a5 40 0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xC2,0xC3,0xC4,0xC5,0xC6,
va009039 13:8774c07f12a5 41 0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xE1,0xE2,0xE3,
va009039 13:8774c07f12a5 42 0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
va009039 13:8774c07f12a5 43 0xFA,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01,
va009039 13:8774c07f12a5 44 0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,
va009039 13:8774c07f12a5 45 0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xA1,0xB1,0xC1,0x09,0x23,0x33,
va009039 13:8774c07f12a5 46 0x52,0xF0,0x15,0x62,0x72,0xD1,0x0A,0x16,0x24,0x34,0xE1,0x25,0xF1,0x17,0x18,0x19,
va009039 13:8774c07f12a5 47 0x1A,0x26,0x27,0x28,0x29,0x2A,0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,
va009039 13:8774c07f12a5 48 0x47,0x48,0x49,0x4A,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,
va009039 13:8774c07f12a5 49 0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x82,0x83,0x84,0x85,
va009039 13:8774c07f12a5 50 0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,
va009039 13:8774c07f12a5 51 0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,
va009039 13:8774c07f12a5 52 0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,
va009039 13:8774c07f12a5 53 0xD9,0xDA,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF2,0xF3,0xF4,0xF5,0xF6,
va009039 13:8774c07f12a5 54 0xF7,0xF8,0xF9,0xFA,
va009039 13:8774c07f12a5 55 };
va009039 13:8774c07f12a5 56
va009039 13:8774c07f12a5 57 decodeMJPEG::decodeMJPEG()
va009039 13:8774c07f12a5 58 {
va009039 13:8774c07f12a5 59 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 60 }
va009039 13:8774c07f12a5 61
va009039 13:8774c07f12a5 62 void decodeMJPEG::inputPacket(const uint8_t* buf, int len)
va009039 13:8774c07f12a5 63 {
va009039 13:8774c07f12a5 64 for(int i = 12; i < len; i++) {
va009039 13:8774c07f12a5 65 input(buf[i]);
va009039 13:8774c07f12a5 66 }
va009039 13:8774c07f12a5 67 }
va009039 13:8774c07f12a5 68
va009039 13:8774c07f12a5 69 void decodeMJPEG::input(uint8_t c)
va009039 13:8774c07f12a5 70 {
va009039 13:8774c07f12a5 71 switch(m_seq) {
va009039 13:8774c07f12a5 72 case SEQ_INIT:
va009039 13:8774c07f12a5 73 if (c == 0xff) {
va009039 13:8774c07f12a5 74 m_seq = SEQ_SOI;
va009039 13:8774c07f12a5 75 }
va009039 13:8774c07f12a5 76 break;
va009039 13:8774c07f12a5 77 case SEQ_SOI:
va009039 13:8774c07f12a5 78 if (c == MARK_SOI) {
va009039 13:8774c07f12a5 79 outputJPEG(0xff, JPEG_START); // start
va009039 13:8774c07f12a5 80 outputJPEG(c);
va009039 13:8774c07f12a5 81 m_bDHT = false;
va009039 13:8774c07f12a5 82 m_seq = SEQ_FRAME;
va009039 13:8774c07f12a5 83 } else {
va009039 13:8774c07f12a5 84 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 85 }
va009039 13:8774c07f12a5 86 break;
va009039 13:8774c07f12a5 87 case SEQ_FRAME:
va009039 13:8774c07f12a5 88 if (c == 0xff) {
va009039 13:8774c07f12a5 89 m_seq = SEQ_MARK;
va009039 13:8774c07f12a5 90 } else {
va009039 13:8774c07f12a5 91 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 92 }
va009039 13:8774c07f12a5 93 break;
va009039 13:8774c07f12a5 94 case SEQ_MARK:
va009039 13:8774c07f12a5 95 if (c == MARK_SOI || c == MARK_EOI || c == 0x00) {
va009039 13:8774c07f12a5 96 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 97 break;
va009039 13:8774c07f12a5 98 }
va009039 13:8774c07f12a5 99 m_mark = c;
va009039 13:8774c07f12a5 100 m_seq = SEQ_SEG_LEN;
va009039 13:8774c07f12a5 101 break;
va009039 13:8774c07f12a5 102 case SEQ_SEG_LEN:
va009039 13:8774c07f12a5 103 m_seg_len = c;
va009039 13:8774c07f12a5 104 m_seq = SEQ_SEG_LEN2;
va009039 13:8774c07f12a5 105 break;
va009039 13:8774c07f12a5 106 case SEQ_SEG_LEN2:
va009039 13:8774c07f12a5 107 m_seg_len <<= 8;
va009039 13:8774c07f12a5 108 m_seg_len |= c;
va009039 13:8774c07f12a5 109 m_seg_len -= 2;
va009039 13:8774c07f12a5 110 m_seg_pos = 0;
va009039 13:8774c07f12a5 111 m_seq = SEQ_SEG_BODY;
va009039 13:8774c07f12a5 112 if (m_mark == MARK_SOS) {
va009039 13:8774c07f12a5 113 if (m_bDHT == false) {
va009039 13:8774c07f12a5 114 for(int i = 0; i < sizeof(dht); i++) {
va009039 13:8774c07f12a5 115 outputJPEG(dht[i]);
va009039 13:8774c07f12a5 116 }
va009039 13:8774c07f12a5 117 }
va009039 13:8774c07f12a5 118 m_output_desable = false;
va009039 13:8774c07f12a5 119 } else if (m_mark == MARK_DHT) {
va009039 13:8774c07f12a5 120 m_bDHT = true;
va009039 13:8774c07f12a5 121 m_output_desable = false;
va009039 13:8774c07f12a5 122 } else {
va009039 13:8774c07f12a5 123 m_output_desable = false;
va009039 13:8774c07f12a5 124 }
va009039 13:8774c07f12a5 125 if (!m_output_desable) {
va009039 13:8774c07f12a5 126 outputJPEG(0xff);
va009039 13:8774c07f12a5 127 outputJPEG(m_mark);
va009039 13:8774c07f12a5 128 outputJPEG((m_seg_len+2) >> 8);
va009039 13:8774c07f12a5 129 outputJPEG((m_seg_len+2) & 0xff);
va009039 13:8774c07f12a5 130 }
va009039 13:8774c07f12a5 131 break;
va009039 13:8774c07f12a5 132 case SEQ_SEG_BODY:
va009039 13:8774c07f12a5 133 if (!m_output_desable) {
va009039 13:8774c07f12a5 134 outputJPEG(c);
va009039 13:8774c07f12a5 135 }
va009039 13:8774c07f12a5 136 if (++m_seg_pos < m_seg_len) {
va009039 13:8774c07f12a5 137 break;
va009039 13:8774c07f12a5 138 }
va009039 13:8774c07f12a5 139 if (m_mark == MARK_SOS) {
va009039 13:8774c07f12a5 140 m_seq = SEQ_SOS;
va009039 13:8774c07f12a5 141 break;
va009039 13:8774c07f12a5 142 }
va009039 13:8774c07f12a5 143 m_seq = SEQ_FRAME;
va009039 13:8774c07f12a5 144 break;
va009039 13:8774c07f12a5 145 case SEQ_SOS:
va009039 13:8774c07f12a5 146 if (c == 0xff) {
va009039 13:8774c07f12a5 147 m_seq = SEQ_SOS2;
va009039 13:8774c07f12a5 148 break;
va009039 13:8774c07f12a5 149 }
va009039 13:8774c07f12a5 150 outputJPEG(c);
va009039 13:8774c07f12a5 151 break;
va009039 13:8774c07f12a5 152 case SEQ_SOS2:
va009039 13:8774c07f12a5 153 if (c == 0x00) {
va009039 13:8774c07f12a5 154 outputJPEG(0xff);
va009039 13:8774c07f12a5 155 outputJPEG(0x00);
va009039 13:8774c07f12a5 156 m_seq = SEQ_SOS;
va009039 13:8774c07f12a5 157 break;
va009039 13:8774c07f12a5 158 } else if (c >= MARK_RST0 && c <= MARK_RST7) {
va009039 13:8774c07f12a5 159 outputJPEG(0xff);
va009039 13:8774c07f12a5 160 outputJPEG(c);
va009039 13:8774c07f12a5 161 m_seq = SEQ_SOS;
va009039 13:8774c07f12a5 162 break;
va009039 13:8774c07f12a5 163 } else if (c == MARK_EOI) {
va009039 13:8774c07f12a5 164 outputJPEG(0xff);
va009039 13:8774c07f12a5 165 outputJPEG(c, JPEG_END);
va009039 13:8774c07f12a5 166 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 167 break;
va009039 13:8774c07f12a5 168 } else if (c == MARK_SOI) {
va009039 13:8774c07f12a5 169 outputJPEG(0xff);
va009039 13:8774c07f12a5 170 outputJPEG(c);
va009039 13:8774c07f12a5 171 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 172 break;
va009039 13:8774c07f12a5 173 }
va009039 13:8774c07f12a5 174 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 175 break;
va009039 13:8774c07f12a5 176 default:
va009039 13:8774c07f12a5 177 m_seq = SEQ_INIT;
va009039 13:8774c07f12a5 178 break;
va009039 13:8774c07f12a5 179 }
va009039 13:8774c07f12a5 180 }