#include "sys/alt_stdio.h" #include "system.h" void _wait(loop_count) // _wait(600) is 1ms, usleep(700) is 1ms int loop_count; { volatile int sum, data; sum = 0; for (data = 0; data < loop_count; data++) { sum = (data << 8); } return; } void SCCBSendBit(int data) { *(volatile unsigned long *)(SCL_BASE + 1*4) = 1; // clock dir is output *(volatile unsigned long *)SCL_BASE = 0; *(volatile unsigned long *)(SDA_BASE + 1*4) = 1; // data dir is output *(volatile unsigned long *)SDA_BASE = 0; _wait(5); if(data == 0) { *(volatile unsigned long *)SDA_BASE = 0; } else { *(volatile unsigned long *)SDA_BASE = 1; } _wait(1); *(volatile unsigned long *)SCL_BASE = 1; _wait(5); *(volatile unsigned long *)SCL_BASE = 0; } int SCCBReceiveBit() { unsigned long res; *(volatile unsigned long *)(SCL_BASE + 1*4) = 1; // clock dir is output *(volatile unsigned long *)SCL_BASE = 0; *(volatile unsigned long *)(SDA_BASE + 1*4) = 0; // data dir is input _wait(5); *(volatile unsigned long *)SCL_BASE = 1; _wait(5); res = *(volatile unsigned long *)SDA_BASE; _wait(5); *(volatile unsigned long *)SCL_BASE = 0; return res; } int SCCBSendByte(int data) { unsigned long mask = 1<<7; int i; for(i = 0; i < 8; i++) { SCCBSendBit(data & mask); mask = mask >> 1; } return SCCBReceiveBit(); } unsigned short SCCBReceiveByte() { unsigned short res = 0; int i; for(i = 0; i < 8; i++) { res = res << 1; if(SCCBReceiveBit()) { res |= 0x01; } } SCCBSendBit(1); return res; } void SCCBStart() { _wait(5); *(volatile unsigned long *)(SDA_BASE + 1*4) = 1; // data dir is output *(volatile unsigned long *)SDA_BASE = 1; *(volatile unsigned long *)(SCL_BASE + 1*4) = 1; // clock dir is output *(volatile unsigned long *)SCL_BASE = 1; _wait(5); *(volatile unsigned long *)SDA_BASE = 0; _wait(5); *(volatile unsigned long *)SCL_BASE = 0; } void SCCBStop() { _wait(5); *(volatile unsigned long *)(SDA_BASE + 1*4) = 1; // data dir is output *(volatile unsigned long *)SDA_BASE = 0; *(volatile unsigned long *)(SCL_BASE + 1*4) = 1; // clock dir is output *(volatile unsigned long *)SCL_BASE = 1; _wait(5); *(volatile unsigned long *)SDA_BASE = 1; _wait(5); // *(volatile unsigned long *)SCL_BASE = 0; *(volatile unsigned long *)(SDA_BASE + 1*4) = 0; // data dir is input *(volatile unsigned long *)(SCL_BASE + 1*4) = 0; // clock dir is input _wait(10); } void SCCBWrite(int addr, int data) { int devID = 0x78; SCCBStart(); SCCBSendByte(devID); SCCBSendByte((addr >> 8) & 0xFF); // for OV5642 SCCBSendByte(addr & 0xFF); SCCBSendByte(data); SCCBStop(); } unsigned short SCCBRead(int addr) { unsigned short res; int devID = 0x78; SCCBStart(); SCCBSendByte(devID); SCCBSendByte(addr); SCCBStart(); SCCBSendByte(devID|0x01); res = SCCBReceiveByte(); SCCBStop(); return res; } int main() { SCCBWrite( 0x3103, 0x93); SCCBWrite( 0x3008, 0x82); SCCBWrite( 0x3017, 0x7f); SCCBWrite( 0x3018, 0xfc); SCCBWrite( 0x3810, 0xc2); SCCBWrite( 0x3615, 0xf0); SCCBWrite( 0x3000, 0x00); SCCBWrite( 0x3001, 0x00); SCCBWrite( 0x3002, 0x00); SCCBWrite( 0x3003, 0x00); SCCBWrite( 0x3000, 0xf8); SCCBWrite( 0x3001, 0x48); SCCBWrite( 0x3002, 0x5c); SCCBWrite( 0x3003, 0x02); SCCBWrite( 0x3004, 0x07); SCCBWrite( 0x3005, 0xb7); SCCBWrite( 0x3006, 0x43); SCCBWrite( 0x3007, 0x37); SCCBWrite( 0x3011, 0x08); SCCBWrite( 0x3010, 0x10); SCCBWrite( 0x460c, 0x22); SCCBWrite( 0x3815, 0x04); SCCBWrite( 0x370d, 0x06); SCCBWrite( 0x370c, 0xa0); SCCBWrite( 0x3602, 0xfc); SCCBWrite( 0x3612, 0xff); SCCBWrite( 0x3634, 0xc0); SCCBWrite( 0x3613, 0x00); SCCBWrite( 0x3605, 0x7c); SCCBWrite( 0x3621, 0x09); SCCBWrite( 0x3622, 0x00); SCCBWrite( 0x3604, 0x40); SCCBWrite( 0x3603, 0xa7); SCCBWrite( 0x3603, 0x27); SCCBWrite( 0x4000, 0x21); SCCBWrite( 0x401d, 0x02); SCCBWrite( 0x3600, 0x54); SCCBWrite( 0x3605, 0x04); SCCBWrite( 0x3606, 0x3f); SCCBWrite( 0x3c01, 0x00); SCCBWrite( 0x5000, 0x4f); SCCBWrite( 0x5020, 0x04); SCCBWrite( 0x5181, 0x79); SCCBWrite( 0x5182, 0x00); SCCBWrite( 0x5185, 0x22); SCCBWrite( 0x5197, 0x01); SCCBWrite( 0x5001, 0xff); SCCBWrite( 0x5500, 0x0a); SCCBWrite( 0x5504, 0x00); SCCBWrite( 0x5505, 0x7f); SCCBWrite( 0x5080, 0x08); SCCBWrite( 0x300e, 0x18); SCCBWrite( 0x4610, 0x00); SCCBWrite( 0x471d, 0x05); SCCBWrite( 0x4708, 0x06); SCCBWrite( 0x3710, 0x10); SCCBWrite( 0x3632, 0x41); SCCBWrite( 0x3702, 0x40); SCCBWrite( 0x3620, 0x37); SCCBWrite( 0x3631, 0x01); SCCBWrite( 0x3808, 0x02); SCCBWrite( 0x3809, 0x80); SCCBWrite( 0x380a, 0x01); SCCBWrite( 0x380b, 0xe0); SCCBWrite( 0x380e, 0x07); SCCBWrite( 0x380f, 0xd0); SCCBWrite( 0x501f, 0x00); SCCBWrite( 0x5000, 0x4f); SCCBWrite(0x501e ,0x2a);// SCCBWrite(0x5002 ,0xf8); /////// SCCBWrite(0x501f ,0x01);//00);//1); yuv422 SCCBWrite( 0x4300, 0x61);//30); // yuv422, 61 for rgb565 SCCBWrite( 0x3503, 0x07); SCCBWrite( 0x3501, 0x73); SCCBWrite( 0x3502, 0x80); SCCBWrite( 0x350b, 0x00); SCCBWrite( 0x3503, 0x07); SCCBWrite( 0x3824, 0x11); SCCBWrite( 0x3501, 0x1e); SCCBWrite( 0x3502, 0x80); SCCBWrite( 0x350b, 0x7f); SCCBWrite( 0x380c, 0x0c); SCCBWrite( 0x380d, 0x80); SCCBWrite( 0x380e, 0x03); SCCBWrite( 0x380f, 0xe8); SCCBWrite( 0x3a0d, 0x04); SCCBWrite( 0x3a0e, 0x03); SCCBWrite( 0x3818, 0xa1);// no mirror, vertical flip c1); SCCBWrite( 0x3705, 0xdb); SCCBWrite( 0x370a, 0x81); SCCBWrite( 0x3801, 0x80); SCCBWrite( 0x3621, 0xe7);// no mirror c7); SCCBWrite( 0x3801, 0x50); SCCBWrite( 0x3803, 0x08); SCCBWrite( 0x3827, 0x08); SCCBWrite( 0x3810, 0xc0); SCCBWrite( 0x3804, 0x05); SCCBWrite( 0x3805, 0x00); SCCBWrite( 0x5682, 0x05); SCCBWrite( 0x5683, 0x00); SCCBWrite( 0x3806, 0x03); SCCBWrite( 0x3807, 0xc0); SCCBWrite( 0x5686, 0x03); SCCBWrite( 0x5687, 0xc0); SCCBWrite( 0x3a00, 0x78); SCCBWrite( 0x3a1a, 0x04); SCCBWrite( 0x3a13, 0x30); SCCBWrite( 0x3a18, 0x00); SCCBWrite( 0x3a19, 0x7c); SCCBWrite( 0x3a08, 0x12); SCCBWrite( 0x3a09, 0xc0); SCCBWrite( 0x3a0a, 0x0f); SCCBWrite( 0x3a0b, 0xa0); SCCBWrite( 0x3004, 0xff); SCCBWrite( 0x350c, 0x07); SCCBWrite( 0x350d, 0xd0); SCCBWrite( 0x3500, 0x00); SCCBWrite( 0x3501, 0x00); SCCBWrite( 0x3502, 0x00); SCCBWrite( 0x350a, 0x00); SCCBWrite( 0x350b, 0x00); SCCBWrite( 0x3503, 0x00); SCCBWrite( 0x528a, 0x02); SCCBWrite( 0x528b, 0x04); SCCBWrite( 0x528c, 0x08); SCCBWrite( 0x528d, 0x08); SCCBWrite( 0x528e, 0x08); SCCBWrite( 0x528f, 0x10); SCCBWrite( 0x5290, 0x10); SCCBWrite( 0x5292, 0x00); SCCBWrite( 0x5293, 0x02); SCCBWrite( 0x5294, 0x00); SCCBWrite( 0x5295, 0x02); SCCBWrite( 0x5296, 0x00); SCCBWrite( 0x5297, 0x02); SCCBWrite( 0x5298, 0x00); SCCBWrite( 0x5299, 0x02); SCCBWrite( 0x529a, 0x00); SCCBWrite( 0x529b, 0x02); SCCBWrite( 0x529c, 0x00); SCCBWrite( 0x529d, 0x02); SCCBWrite( 0x529e, 0x00); SCCBWrite( 0x529f, 0x02); SCCBWrite( 0x3a0f, 0x3c); SCCBWrite( 0x3a10, 0x30); SCCBWrite( 0x3a1b, 0x3c); SCCBWrite( 0x3a1e, 0x30); SCCBWrite( 0x3a11, 0x70); SCCBWrite( 0x3a1f, 0x10); SCCBWrite( 0x3030, 0x0b); SCCBWrite( 0x3a02, 0x00); SCCBWrite( 0x3a03, 0x7d); SCCBWrite( 0x3a04, 0x00); SCCBWrite( 0x3a14, 0x00); SCCBWrite( 0x3a15, 0x7d); SCCBWrite( 0x3a16, 0x00); SCCBWrite( 0x3a08, 0x09); SCCBWrite( 0x3a09, 0x60); SCCBWrite( 0x3a0a, 0x07); SCCBWrite( 0x3a0b, 0xd0); SCCBWrite( 0x3a0d, 0x08); SCCBWrite( 0x3a0e, 0x06); SCCBWrite( 0x5193, 0x70); SCCBWrite( 0x3620, 0x57); SCCBWrite( 0x3703, 0x98); SCCBWrite( 0x3704, 0x1c); SCCBWrite( 0x589b, 0x04); SCCBWrite( 0x589a, 0xc5); SCCBWrite( 0x528a, 0x00); SCCBWrite( 0x528b, 0x02); SCCBWrite( 0x528c, 0x08); SCCBWrite( 0x528d, 0x10); SCCBWrite( 0x528e, 0x20); SCCBWrite( 0x528f, 0x28); SCCBWrite( 0x5290, 0x30); SCCBWrite( 0x5292, 0x00); SCCBWrite( 0x5293, 0x00); SCCBWrite( 0x5294, 0x00); SCCBWrite( 0x5295, 0x02); SCCBWrite( 0x5296, 0x00); SCCBWrite( 0x5297, 0x08); SCCBWrite( 0x5298, 0x00); SCCBWrite( 0x5299, 0x10); SCCBWrite( 0x529a, 0x00); SCCBWrite( 0x529b, 0x20); SCCBWrite( 0x529c, 0x00); SCCBWrite( 0x529d, 0x28); SCCBWrite( 0x529e, 0x00); SCCBWrite( 0x529f, 0x30); SCCBWrite( 0x5282, 0x00); SCCBWrite( 0x5300, 0x00); SCCBWrite( 0x5301, 0x20); SCCBWrite( 0x5302, 0x00); SCCBWrite( 0x5303, 0x7c); SCCBWrite( 0x530c, 0x00); SCCBWrite( 0x530d, 0x0c); SCCBWrite( 0x530e, 0x20); SCCBWrite( 0x530f, 0x80); SCCBWrite( 0x5310, 0x20); SCCBWrite( 0x5311, 0x80); SCCBWrite( 0x5308, 0x20); SCCBWrite( 0x5309, 0x40); SCCBWrite( 0x5304, 0x00); SCCBWrite( 0x5305, 0x30); SCCBWrite( 0x5306, 0x00); SCCBWrite( 0x5307, 0x80); SCCBWrite( 0x5314, 0x08); SCCBWrite( 0x5315, 0x20); SCCBWrite( 0x5319, 0x30); SCCBWrite( 0x5316, 0x10); SCCBWrite( 0x5317, 0x08); SCCBWrite( 0x5318, 0x02); SCCBWrite( 0x5380, 0x01); SCCBWrite( 0x5381, 0x00); SCCBWrite( 0x5382, 0x00); SCCBWrite( 0x5383, 0x4e); SCCBWrite( 0x5384, 0x00); SCCBWrite( 0x5385, 0x0f); SCCBWrite( 0x5386, 0x00); SCCBWrite( 0x5387, 0x00); SCCBWrite( 0x5388, 0x01); SCCBWrite( 0x5389, 0x15); SCCBWrite( 0x538a, 0x00); SCCBWrite( 0x538b, 0x31); SCCBWrite( 0x538c, 0x00); SCCBWrite( 0x538d, 0x00); SCCBWrite( 0x538e, 0x00); SCCBWrite( 0x538f, 0x0f); SCCBWrite( 0x5390, 0x00); SCCBWrite( 0x5391, 0xab); SCCBWrite( 0x5392, 0x00); SCCBWrite( 0x5393, 0xa2); SCCBWrite( 0x5394, 0x08); SCCBWrite( 0x5480, 0x14); SCCBWrite( 0x5481, 0x21); SCCBWrite( 0x5482, 0x36); SCCBWrite( 0x5483, 0x57); SCCBWrite( 0x5484, 0x65); SCCBWrite( 0x5485, 0x71); SCCBWrite( 0x5486, 0x7d); SCCBWrite( 0x5487, 0x87); SCCBWrite( 0x5488, 0x91); SCCBWrite( 0x5489, 0x9a); SCCBWrite( 0x548a, 0xaa); SCCBWrite( 0x548b, 0xb8); SCCBWrite( 0x548c, 0xcd); SCCBWrite( 0x548d, 0xdd); SCCBWrite( 0x548e, 0xea); SCCBWrite( 0x548f, 0x10); SCCBWrite( 0x5490, 0x05); SCCBWrite( 0x5491, 0x00); SCCBWrite( 0x5492, 0x04); SCCBWrite( 0x5493, 0x20); SCCBWrite( 0x5494, 0x03); SCCBWrite( 0x5495, 0x60); SCCBWrite( 0x5496, 0x02); SCCBWrite( 0x5497, 0xb8); SCCBWrite( 0x5498, 0x02); SCCBWrite( 0x5499, 0x86); SCCBWrite( 0x549a, 0x02); SCCBWrite( 0x549b, 0x5b); SCCBWrite( 0x549c, 0x02); SCCBWrite( 0x549d, 0x3b); SCCBWrite( 0x549e, 0x02); SCCBWrite( 0x549f, 0x1c); SCCBWrite( 0x54a0, 0x02); SCCBWrite( 0x54a1, 0x04); SCCBWrite( 0x54a2, 0x01); SCCBWrite( 0x54a3, 0xed); SCCBWrite( 0x54a4, 0x01); SCCBWrite( 0x54a5, 0xc5); SCCBWrite( 0x54a6, 0x01); SCCBWrite( 0x54a7, 0xa5); SCCBWrite( 0x54a8, 0x01); SCCBWrite( 0x54a9, 0x6c); SCCBWrite( 0x54aa, 0x01); SCCBWrite( 0x54ab, 0x41); SCCBWrite( 0x54ac, 0x01); SCCBWrite( 0x54ad, 0x20); SCCBWrite( 0x54ae, 0x00); SCCBWrite( 0x54af, 0x16); SCCBWrite( 0x3406, 0x00); SCCBWrite( 0x5192, 0x04); SCCBWrite( 0x5191, 0xf8); SCCBWrite( 0x5193, 0x70); SCCBWrite( 0x5194, 0xf0); SCCBWrite( 0x5195, 0xf0); SCCBWrite( 0x518d, 0x3d); SCCBWrite( 0x518f, 0x54); SCCBWrite( 0x518e, 0x3d); SCCBWrite( 0x5190, 0x54); SCCBWrite( 0x518b, 0xc0); SCCBWrite( 0x518c, 0xbd); SCCBWrite( 0x5187, 0x18); SCCBWrite( 0x5188, 0x18); SCCBWrite( 0x5189, 0x6e); SCCBWrite( 0x518a, 0x68); SCCBWrite( 0x5186, 0x1c); SCCBWrite( 0x5181, 0x50); SCCBWrite( 0x5184, 0x25); SCCBWrite( 0x5182, 0x11); SCCBWrite( 0x5183, 0x14); SCCBWrite( 0x5184, 0x25); SCCBWrite( 0x5185, 0x24); SCCBWrite( 0x5025, 0x82); SCCBWrite( 0x3a0f, 0x7e); SCCBWrite( 0x3a10, 0x72); SCCBWrite( 0x3a1b, 0x80); SCCBWrite( 0x3a1e, 0x70); SCCBWrite( 0x3a11, 0xd0); SCCBWrite( 0x3a1f, 0x40); SCCBWrite( 0x5583, 0x80);//40); SCCBWrite( 0x5584, 0x80);//40); SCCBWrite( 0x5580, 0x02); SCCBWrite( 0x5580, 0x04);// from 02); // 2023/06/28 for contrast +4 SCCBWrite( 0x5587, 0x30);// added // 2023/06/28 for contrast 30:+4, 28:+2 SCCBWrite( 0x5588, 0x30);// added // 2023/06/28 for contrast 30:+4, 28:+2 SCCBWrite( 0x558a, 0x00);// added // 2023/06/28 for contrast +4 SCCBWrite( 0x5580, 0x04);// from 02); // 2023/06/28 for brightness -4 SCCBWrite( 0x5589, 0x30);// added // 2023/06/28 for brightness 40:-4, 30:-3 SCCBWrite( 0x558a, 0x08);// added // 2023/06/28 for brightness -4 SCCBWrite( 0x3633, 0x07); SCCBWrite( 0x3702, 0x10); SCCBWrite( 0x3703, 0xb2); SCCBWrite( 0x3704, 0x18); SCCBWrite( 0x370b, 0x40); SCCBWrite( 0x370d, 0x02); SCCBWrite( 0x3620, 0x52); *(volatile unsigned long *)THRESH_BASE = 0x0032; while (1) { } return 0; }