This is an digital video camera program using NKK\'s oLED swtich and 4D Systems\' uCam serial camera. It takes image from the uCam and displays on the IS-C15 switch. Some image processing demos are included. This program uses FatFileSytem, SDFileSystem, and TextLCD library. See http://www.youtube.com/watch?v=fqHTaCRHyQs for how it works. CQ出版社の「mbed/ARM活用事例」第10章シリアル接続カメラと有機ELディスプレイ内蔵スイッチで作るmbedディジタル・カメラの作例です。動作の様子は http://www.youtube.com/watch?v=fqHTaCRHyQs で見れます。

Dependencies:   TextLCD mbed SDFileSystem

Committer:
non
Date:
Thu Oct 13 02:41:04 2011 +0000
Revision:
2:0621feb3adf2
Parent:
0:07d02a20d1cc

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
non 0:07d02a20d1cc 1 /* mbed NKK IS-C15/C01 oLED switch library
non 0:07d02a20d1cc 2 * Copyright (c) 2011, Noriaki Mitsunaga
non 0:07d02a20d1cc 3 *
non 0:07d02a20d1cc 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
non 0:07d02a20d1cc 5 * of this software and associated documentation files (the "Software"), to deal
non 0:07d02a20d1cc 6 * in the Software without restriction, including without limitation the rights
non 0:07d02a20d1cc 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
non 0:07d02a20d1cc 8 * copies of the Software, and to permit persons to whom the Software is
non 0:07d02a20d1cc 9 * furnished to do so, subject to the following conditions:
non 0:07d02a20d1cc 10 *
non 0:07d02a20d1cc 11 * The above copyright notice and this permission notice shall be included in
non 0:07d02a20d1cc 12 * all copies or substantial portions of the Software.
non 0:07d02a20d1cc 13 *
non 0:07d02a20d1cc 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
non 0:07d02a20d1cc 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
non 0:07d02a20d1cc 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
non 0:07d02a20d1cc 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
non 0:07d02a20d1cc 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
non 0:07d02a20d1cc 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
non 0:07d02a20d1cc 20 * THE SOFTWARE.
non 0:07d02a20d1cc 21 */
non 0:07d02a20d1cc 22 #include "isc15.h"
non 0:07d02a20d1cc 23
non 0:07d02a20d1cc 24 ////////////////////////////////////////////////////////////////////////////////////////
non 0:07d02a20d1cc 25 // Some constants
non 0:07d02a20d1cc 26 ////////////////////////////////////////////////////////////////////////////////////////
non 0:07d02a20d1cc 27 const int DAT = 1;
non 0:07d02a20d1cc 28 const int CMD = 0;
non 0:07d02a20d1cc 29
non 0:07d02a20d1cc 30 ////////////////////////////////////////////////////////////////////////////////////////
non 0:07d02a20d1cc 31 // OLED's initial setup commands (IS15)
non 0:07d02a20d1cc 32 ////////////////////////////////////////////////////////////////////////////////////////
non 0:07d02a20d1cc 33 const unsigned char SetupColumnAddress[] = { 0x03, 0x15, 0x10, 0x4f };
non 0:07d02a20d1cc 34 const unsigned char SetupRowaddress[] = { 0x03, 0x75, 0x00, 0x2f };
non 0:07d02a20d1cc 35 const unsigned char SetContrastColorA[] = { 0x02, 0x81, 0x19 };
non 0:07d02a20d1cc 36 const unsigned char SetContrastColorB[] = { 0x02, 0x82, 0x14 };
non 0:07d02a20d1cc 37 const unsigned char SetContrastColorC[] = { 0x02, 0x83, 0x24 };
non 0:07d02a20d1cc 38 const unsigned char MasterCurrentControl[] = { 0x02, 0x87, 0x0f };
non 0:07d02a20d1cc 39 const unsigned char RemapColorDepth[] = { 0x02, 0xa0, 0x70 };
non 0:07d02a20d1cc 40 const unsigned char SetDisplayStartLine[] = { 0x02, 0xa1, 0x00 };
non 0:07d02a20d1cc 41 const unsigned char SetDisplayOffset[] = { 0x02, 0xa2, 0x10 };
non 0:07d02a20d1cc 42 const unsigned char SetDisplayMode[] = { 0x01, 0xa4 };
non 0:07d02a20d1cc 43 const unsigned char SetMultiplexRatio[] = { 0x02, 0xa8, 0x2f };
non 0:07d02a20d1cc 44 const unsigned char DimModeSetting[] = { 0x05, 0xab, 0x12, 0x0c, 0x14, 0x12 };
non 0:07d02a20d1cc 45 const unsigned char SetDisplayDim[] = { 0x01, 0xac };
non 0:07d02a20d1cc 46 const unsigned char SetDisplayOff[] = { 0x01, 0xae };
non 0:07d02a20d1cc 47 const unsigned char SetDisplayNormal[] = { 0x01, 0xaf };
non 0:07d02a20d1cc 48 const unsigned char SetMasterConfiguration[] = { 0x02, 0xad, 0x8e };
non 0:07d02a20d1cc 49 const unsigned char PhasePeriodAdjustment[] = { 0x02, 0xb1, 0x44 };
non 0:07d02a20d1cc 50 const unsigned char DisplayClockDivider[] = { 0x02, 0xb3, 0xa0 };
non 0:07d02a20d1cc 51 const unsigned char EnableLinearGrayScale[] = { 0x01, 0xb9 };
non 0:07d02a20d1cc 52 const unsigned char SetPrechargeLevel[] = { 0x02, 0xbb, 0x12 };
non 0:07d02a20d1cc 53 const unsigned char SetVcomh[] = { 0x03, 0xbe, 0x28 };
non 0:07d02a20d1cc 54
non 0:07d02a20d1cc 55 const unsigned char ColorDepth64k[] = { 0x02, 0xa0, 0x70 };
non 0:07d02a20d1cc 56 const unsigned char ColorDepth256[] = { 0x02, 0xa0, 0x30 };
non 0:07d02a20d1cc 57
non 0:07d02a20d1cc 58 // OLED's initial setup commands (for display only type (IS01) )
non 0:07d02a20d1cc 59 const unsigned char SetupColumnAddress_d[] = { 0x03, 0x15, 0x16, 0x49 }; //display
non 0:07d02a20d1cc 60 const unsigned char SetupRowaddress_d[] = { 0x03, 0x75, 0x00, 0x23 }; //display
non 0:07d02a20d1cc 61 const unsigned char SetContrastColorA_d[] = { 0x02, 0x81, 0x0f }; //display
non 0:07d02a20d1cc 62 const unsigned char SetContrastColorB_d[] = { 0x02, 0x82, 0x0e }; //display
non 0:07d02a20d1cc 63 const unsigned char SetContrastColorC_d[] = { 0x02, 0x83, 0x1b }; //display
non 0:07d02a20d1cc 64 const unsigned char SetDisplayOffset_d[] = { 0x02, 0xa2, 0x1c }; //display
non 0:07d02a20d1cc 65 const unsigned char SetMultiplexRatio_d[] = { 0x02, 0xa8, 0x23 }; //display
non 0:07d02a20d1cc 66 const unsigned char DimModeSetting_d[] = { 0x05, 0xab, 0x0b, 0x08, 0x0f, 0x12 }; //display
non 0:07d02a20d1cc 67 const unsigned char DisplayClockDivider_d[] = { 0x02, 0xb3, 0x30 }; //display
non 0:07d02a20d1cc 68 const unsigned char SetVcomh_d[] = { 0x03, 0xbe, 0x21 }; //display
non 0:07d02a20d1cc 69
non 0:07d02a20d1cc 70 //
non 0:07d02a20d1cc 71 // Change OLED's address setting
non 0:07d02a20d1cc 72 //
non 0:07d02a20d1cc 73 void ISC15::AdrInit( int DevType ) {
non 0:07d02a20d1cc 74 if (spi == NULL)
non 0:07d02a20d1cc 75 return;
non 0:07d02a20d1cc 76
non 0:07d02a20d1cc 77 if (DevType == ISC15_DEVICE_ISC15) {
non 0:07d02a20d1cc 78 SendCommand( SetupColumnAddress );
non 0:07d02a20d1cc 79 SendCommand( SetupRowaddress );
non 0:07d02a20d1cc 80 } else {
non 0:07d02a20d1cc 81 SendCommand( SetupColumnAddress_d );
non 0:07d02a20d1cc 82 SendCommand( SetupRowaddress_d );
non 0:07d02a20d1cc 83 }
non 0:07d02a20d1cc 84 }
non 0:07d02a20d1cc 85
non 0:07d02a20d1cc 86
non 0:07d02a20d1cc 87 //
non 0:07d02a20d1cc 88 // Display data on OLED
non 0:07d02a20d1cc 89 //
non 0:07d02a20d1cc 90 void ISC15::Disp( int Mode, const unsigned char *dat ) {
non 0:07d02a20d1cc 91 if (spi == NULL)
non 0:07d02a20d1cc 92 return;
non 0:07d02a20d1cc 93
non 0:07d02a20d1cc 94 AdrInit(DevType);
non 0:07d02a20d1cc 95 DspMode(Mode);
non 0:07d02a20d1cc 96 if (Mode == ISC15_DSPMODE_64K)
non 0:07d02a20d1cc 97 SendData(dat, ISC15_WIDTH*ISC15_HEIGHT*2);
non 0:07d02a20d1cc 98 else
non 0:07d02a20d1cc 99 SendData(dat, ISC15_WIDTH*ISC15_HEIGHT);
non 0:07d02a20d1cc 100 }
non 0:07d02a20d1cc 101
non 0:07d02a20d1cc 102 //
non 0:07d02a20d1cc 103 // Change OLED's color depth setting (64K or 256 colors)
non 0:07d02a20d1cc 104 //
non 0:07d02a20d1cc 105 void ISC15::DspMode( int DspMode ) {
non 0:07d02a20d1cc 106 if (spi == NULL)
non 0:07d02a20d1cc 107 return;
non 0:07d02a20d1cc 108
non 0:07d02a20d1cc 109 if ( DspMode == ISC15_DSPMODE_64K ) {
non 0:07d02a20d1cc 110 SendCommand( ColorDepth64k );
non 0:07d02a20d1cc 111 } else {
non 0:07d02a20d1cc 112 SendCommand( ColorDepth256 );
non 0:07d02a20d1cc 113 }
non 0:07d02a20d1cc 114 }
non 0:07d02a20d1cc 115
non 0:07d02a20d1cc 116 //
non 0:07d02a20d1cc 117 // Fill out display
non 0:07d02a20d1cc 118 //
non 0:07d02a20d1cc 119 void ISC15::Fill(unsigned char c) {
non 0:07d02a20d1cc 120 if (spi == NULL)
non 0:07d02a20d1cc 121 return;
non 0:07d02a20d1cc 122
non 0:07d02a20d1cc 123 AdrInit(DevType);
non 0:07d02a20d1cc 124 DspMode(0);
non 0:07d02a20d1cc 125
non 0:07d02a20d1cc 126 is_dc = DAT;
non 0:07d02a20d1cc 127 for (int i = ISC15_WIDTH*ISC15_HEIGHT; i>0; i --) {
non 0:07d02a20d1cc 128 is_cs = 0;
non 0:07d02a20d1cc 129 spi->write(c);
non 0:07d02a20d1cc 130 is_cs = 1;
non 0:07d02a20d1cc 131 }
non 0:07d02a20d1cc 132 }
non 0:07d02a20d1cc 133
non 0:07d02a20d1cc 134 //
non 0:07d02a20d1cc 135 // initial settings of OLED
non 0:07d02a20d1cc 136 //
non 0:07d02a20d1cc 137 void ISC15::Init( int DeviceType, SPI *s ) {
non 0:07d02a20d1cc 138 volatile unsigned char delay = 0x20;
non 0:07d02a20d1cc 139
non 0:07d02a20d1cc 140 DevType = DeviceType;
non 0:07d02a20d1cc 141 spi = s;
non 0:07d02a20d1cc 142
non 0:07d02a20d1cc 143 // reset OLED
non 0:07d02a20d1cc 144 is_vcc = 0;
non 0:07d02a20d1cc 145 is_reset = 0;
non 0:07d02a20d1cc 146 wait_us(3);
non 0:07d02a20d1cc 147 is_reset = 1;
non 0:07d02a20d1cc 148 is_vcc = 1;
non 0:07d02a20d1cc 149
non 0:07d02a20d1cc 150 // initial settings
non 0:07d02a20d1cc 151 AdrInit(DevType);
non 0:07d02a20d1cc 152
non 0:07d02a20d1cc 153 if (DevType == ISC15_DEVICE_ISC15) {
non 0:07d02a20d1cc 154 SendCommand( SetContrastColorA );
non 0:07d02a20d1cc 155 SendCommand( SetContrastColorB );
non 0:07d02a20d1cc 156 SendCommand( SetContrastColorC );
non 0:07d02a20d1cc 157 SendCommand( MasterCurrentControl );
non 0:07d02a20d1cc 158 SendCommand( SetDisplayStartLine );
non 0:07d02a20d1cc 159 SendCommand( SetDisplayOffset );
non 0:07d02a20d1cc 160 SendCommand( SetDisplayMode );
non 0:07d02a20d1cc 161 SendCommand( SetMultiplexRatio );
non 0:07d02a20d1cc 162 SendCommand( DimModeSetting );
non 0:07d02a20d1cc 163 SendCommand( SetMasterConfiguration );
non 0:07d02a20d1cc 164 SendCommand( PhasePeriodAdjustment );
non 0:07d02a20d1cc 165 SendCommand( DisplayClockDivider );
non 0:07d02a20d1cc 166 SendCommand( EnableLinearGrayScale );
non 0:07d02a20d1cc 167 SendCommand( SetPrechargeLevel );
non 0:07d02a20d1cc 168 SendCommand( SetVcomh );
non 0:07d02a20d1cc 169 } else {
non 0:07d02a20d1cc 170 SendCommand( SetContrastColorA_d );
non 0:07d02a20d1cc 171 SendCommand( SetContrastColorB_d );
non 0:07d02a20d1cc 172 SendCommand( SetContrastColorC_d );
non 0:07d02a20d1cc 173 SendCommand( MasterCurrentControl );
non 0:07d02a20d1cc 174 SendCommand( SetDisplayStartLine );
non 0:07d02a20d1cc 175 SendCommand( SetDisplayOffset_d );
non 0:07d02a20d1cc 176 SendCommand( SetDisplayMode );
non 0:07d02a20d1cc 177 SendCommand( SetMultiplexRatio_d );
non 0:07d02a20d1cc 178 SendCommand( DimModeSetting_d );
non 0:07d02a20d1cc 179 SendCommand( SetMasterConfiguration );
non 0:07d02a20d1cc 180 SendCommand( PhasePeriodAdjustment );
non 0:07d02a20d1cc 181 SendCommand( DisplayClockDivider_d );
non 0:07d02a20d1cc 182 SendCommand( EnableLinearGrayScale );
non 0:07d02a20d1cc 183 SendCommand( SetPrechargeLevel );
non 0:07d02a20d1cc 184 SendCommand( SetVcomh_d );
non 0:07d02a20d1cc 185 }
non 0:07d02a20d1cc 186
non 0:07d02a20d1cc 187 // display mode settings
non 0:07d02a20d1cc 188 DspMode( ISC15_DSPMODE_64K);
non 0:07d02a20d1cc 189
non 0:07d02a20d1cc 190 SendCommand( SetDisplayNormal );
non 0:07d02a20d1cc 191 }
non 0:07d02a20d1cc 192
non 0:07d02a20d1cc 193 //
non 0:07d02a20d1cc 194 // Send a command / data to OLED via SPI
non 0:07d02a20d1cc 195 //
non 0:07d02a20d1cc 196 void ISC15::Send( const unsigned char *p, int len ) {
non 0:07d02a20d1cc 197 if (spi == NULL)
non 0:07d02a20d1cc 198 return;
non 0:07d02a20d1cc 199
non 0:07d02a20d1cc 200 for (; len>0; len --, p ++) {
non 0:07d02a20d1cc 201 is_cs = 0;
non 0:07d02a20d1cc 202 spi->write(*p);
non 0:07d02a20d1cc 203 is_cs = 1;
non 0:07d02a20d1cc 204 }
non 0:07d02a20d1cc 205 }
non 0:07d02a20d1cc 206
non 0:07d02a20d1cc 207 //
non 0:07d02a20d1cc 208 // Send a command to OLED
non 0:07d02a20d1cc 209 //
non 0:07d02a20d1cc 210 void ISC15::SendCommand( const unsigned char *com ) {
non 0:07d02a20d1cc 211 if (spi == NULL)
non 0:07d02a20d1cc 212 return;
non 0:07d02a20d1cc 213
non 0:07d02a20d1cc 214 is_dc = CMD;
non 0:07d02a20d1cc 215 Send(com+1, *com);
non 0:07d02a20d1cc 216 }
non 0:07d02a20d1cc 217
non 0:07d02a20d1cc 218 //
non 0:07d02a20d1cc 219 // Send data to OLED
non 0:07d02a20d1cc 220 //
non 0:07d02a20d1cc 221 void ISC15::SendData( const unsigned char *dat, int len ) {
non 0:07d02a20d1cc 222 if (spi == NULL)
non 0:07d02a20d1cc 223 return;
non 0:07d02a20d1cc 224
non 0:07d02a20d1cc 225 is_dc = DAT;
non 0:07d02a20d1cc 226 Send(dat, len);
non 0:07d02a20d1cc 227 }