示例#1
0
文件: main.c 项目: 1i7/snippets
int main(void)
{
    uint8_t addr1, addr2; /* i2c addresses */
    uint16_t x, y;
    char buf[128]; /* temporary string buffer for various stuff */

    /* uart stuff */
    char rcvbuf[32], c;
    uint8_t rcvbufpos = 0;

    init_board();
    ov7670_init();

    printf("Camtest says hi!\n");
    printf("System clock: [%d]\n", SystemCoreClock);

    UART0_PrintString("Camtest says hi!\r\n");
    while (1) {
        c = UART0_Getchar();
        if (c == EOF) {
            continue;
        } else if ((c >= 32) && (c <= 126)) {
            rcvbuf[rcvbufpos++] = c;
        } else if (c == 13) {
            rcvbuf[rcvbufpos++] = 0;
            rcvbufpos = 0;
            if (strcmp(rcvbuf, "getimage") == 0) {
                ov7670_readframe();
                UART0_PrintString("OK\r\n");
            } else if (strlen(rcvbuf) >= 9 &&
                    strncmp(rcvbuf, "getline ", 8) == 0) {
                y = atoi(rcvbuf + 8);
                for (x = 0; x < 160; x ++) {
                    UART0_Sendchar(qqvgaframe1[x + (y * 160)]);
                    UART0_Sendchar(qqvgaframe2[x + (y * 160)]);
                }
            } else if (strlen(rcvbuf) == 9 &&
                    strncmp(rcvbuf, "regr 0x", 7) == 0) {
                addr1 = strtoul(rcvbuf + 7, NULL, 16);
                sprintf(buf, "0x%.2x 0x%.2x\r\n", addr1, ov7670_get(addr1));
                printf("%s", buf);
                UART0_PrintString(buf);
            } else if (strlen(rcvbuf) == 14 &&
                    strncmp(rcvbuf, "regw 0x", 7) == 0) {
                strncpy(buf, rcvbuf + 7, 2);
                buf[2] = 0;
                addr1 = strtoul((char *) buf, NULL, 16);
                addr2 = strtoul(rcvbuf + 12, NULL, 16);
                ov7670_set(addr1, addr2);
                sprintf(buf, "0x%.2x 0x%.2x\r\n", addr1, addr2);
                UART0_PrintString(buf);
            } else {
                UART0_PrintString("ERR\r\n");
                printf("Unknown command: [%s]\n", rcvbuf);
            }
        }
    }

    return 0;
}
示例#2
0
uint8_t ov7670_init(void)
{
    if (ov7670_get(REG_PID) != 0x76) {
        return 0;
    }

    ov7670_set(REG_COM7, 0x80); /* reset to default values */
    ov7670_set(REG_CLKRC, 0x80);
    ov7670_set(REG_COM11, 0x0A);
    ov7670_set(REG_TSLB, 0x04);
    ov7670_set(REG_TSLB, 0x04);
    ov7670_set(REG_COM7, 0x04); /* output format: rgb */

    ov7670_set(REG_RGB444, 0x00); /* disable RGB444 */
    ov7670_set(REG_COM15, 0xD0); /* set RGB565 */

    /* not even sure what all these do, gonna check the oscilloscope and go
     * from there... */
    ov7670_set(REG_HSTART, 0x16);
    ov7670_set(REG_HSTOP, 0x04);
    ov7670_set(REG_HREF, 0x24);
    ov7670_set(REG_VSTART, 0x02);
    ov7670_set(REG_VSTOP, 0x7a);
    ov7670_set(REG_VREF, 0x0a);
    ov7670_set(REG_COM10, 0x02);
    ov7670_set(REG_COM3, 0x04);
    ov7670_set(REG_MVFP, 0x3f);

    /* 160x120, i think */
    //ov7670_set(REG_COM14, 0x1a); // divide by 4
    //ov7670_set(0x72, 0x22); // downsample by 4
    //ov7670_set(0x73, 0xf2); // divide by 4

    /* 320x240: */
    ov7670_set(REG_COM14, 0x19);
    ov7670_set(0x72, 0x11);
    ov7670_set(0x73, 0xf1);

    // test pattern
    //ov7670_set(0x70, 0xf0);
    //ov7670_set(0x71, 0xf0);

    // COLOR SETTING
    ov7670_set(0x4f, 0x80);
    ov7670_set(0x50, 0x80);
    ov7670_set(0x51, 0x00);
    ov7670_set(0x52, 0x22);
    ov7670_set(0x53, 0x5e);
    ov7670_set(0x54, 0x80);
    ov7670_set(0x56, 0x40);
    ov7670_set(0x58, 0x9e);
    ov7670_set(0x59, 0x88);
    ov7670_set(0x5a, 0x88);
    ov7670_set(0x5b, 0x44);
    ov7670_set(0x5c, 0x67);
    ov7670_set(0x5d, 0x49);
    ov7670_set(0x5e, 0x0e);
    ov7670_set(0x69, 0x00);
    ov7670_set(0x6a, 0x40);
    ov7670_set(0x6b, 0x0a);
    ov7670_set(0x6c, 0x0a);
    ov7670_set(0x6d, 0x55);
    ov7670_set(0x6e, 0x11);
    ov7670_set(0x6f, 0x9f);

    ov7670_set(0xb0, 0x84);

    return 1;
}
示例#3
0
int ov7670_init() {
	int hstart = 456, hstop = 24, vstart = 14, vstop = 494;
	unsigned char v;

	if (ov7670_get(REG_PID) != 0x76) {
		return 1;
	}
	ov7670_set(REG_COM7, COM7_RESET); /* reset to default values */
	ov7670_set(REG_CLKRC, 0x01);
	ov7670_set(REG_COM7, COM7_FMT_VGA | COM7_YUV); /* output format: YUCV */

	ov7670_set(REG_HSTART, (hstart >> 3) & 0xff);
	ov7670_set(REG_HSTOP, (hstop >> 3) & 0xff);
	v = ov7670_get(REG_HREF);
	v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7);
	ov7670_set(REG_HREF, v);

	ov7670_set(REG_VSTART, (vstart >> 2) & 0xff);
	ov7670_set(REG_VSTOP, (vstop >> 2) & 0xff);
	v = ov7670_get(REG_VREF);
	v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3);
	ov7670_set(REG_VREF, v);

	ov7670_set(REG_COM3, COM3_SCALEEN | COM3_DCWEN);
	ov7670_set(REG_COM14, COM14_DCWEN | 0x01);
	ov7670_set(0x73, 0xf1);
	ov7670_set(0xa2, 0x52);
	ov7670_set(0x7b, 0x1c);
	ov7670_set(0x7c, 0x28);
	ov7670_set(0x7d, 0x3c);
	ov7670_set(0x7f, 0x69);
	ov7670_set(REG_COM9, 0x38);
	ov7670_set(0xa1, 0x0b);
	ov7670_set(0x74, 0x19);
	ov7670_set(0x9a, 0x80);
	ov7670_set(0x43, 0x14);
	ov7670_set(REG_COM13, 0xc0);
	ov7670_set(0x70, 0x3A);
	ov7670_set(0x71, 0x35);
	ov7670_set(0x72, 0x11);

	/* Gamma curve values */
	ov7670_set(0x7a, 0x20);
	ov7670_set(0x7b, 0x10);
	ov7670_set(0x7c, 0x1e);
	ov7670_set(0x7d, 0x35);
	ov7670_set(0x7e, 0x5a);
	ov7670_set(0x7f, 0x69);
	ov7670_set(0x80, 0x76);
	ov7670_set(0x81, 0x80);
	ov7670_set(0x82, 0x88);
	ov7670_set(0x83, 0x8f);
	ov7670_set(0x84, 0x96);
	ov7670_set(0x85, 0xa3);
	ov7670_set(0x86, 0xaf);
	ov7670_set(0x87, 0xc4);
	ov7670_set(0x88, 0xd7);
	ov7670_set(0x89, 0xe8);

	/* AGC and AEC parameters.  Note we start by disabling those features,
	 then turn them only after tweaking the values. */
	ov7670_set(REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT);
	ov7670_set(REG_GAIN, 0);
	ov7670_set(REG_AECH, 0);
	ov7670_set(REG_COM4, 0x40); /* magic reserved bit */
	ov7670_set(REG_COM9, 0x18); /* 4x gain + magic rsvd bit */
	ov7670_set(REG_BD50MAX, 0x05);
	ov7670_set(REG_BD60MAX, 0x07);
	ov7670_set(REG_AEW, 0x95);
	ov7670_set(REG_AEB, 0x33);
	ov7670_set(REG_VPT, 0xe3);
	ov7670_set(REG_HAECC1, 0x78);
	ov7670_set(REG_HAECC2, 0x68);
	ov7670_set(0xa1, 0x03); /* magic */
	ov7670_set(REG_HAECC3, 0xd8);
	ov7670_set(REG_HAECC4, 0xd8);
	ov7670_set(REG_HAECC5, 0xf0);
	ov7670_set(REG_HAECC6, 0x90);
	ov7670_set(REG_HAECC7, 0x94);
	ov7670_set(REG_COM8,
			COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT | COM8_AGC | COM8_AEC);

	/* Almost all of these are magic "reserved" values.  */
	ov7670_set(REG_COM5, 0x61);
	ov7670_set(REG_COM6, 0x4b);
	ov7670_set(0x16, 0x02);
	ov7670_set(REG_MVFP, 0x07);
	ov7670_set(0x21, 0x02);
	ov7670_set(0x22, 0x91);
	ov7670_set(0x29, 0x07);
	ov7670_set(0x33, 0x0b);
	ov7670_set(0x35, 0x0b);
	ov7670_set(0x37, 0x1d);
	ov7670_set(0x38, 0x71);
	ov7670_set(0x39, 0x2a);
	ov7670_set(REG_COM12, 0x78);
	ov7670_set(0x4d, 0x40);
	ov7670_set(0x4e, 0x20);
	ov7670_set(REG_GFIX, 0);
	ov7670_set(0x6b, 0x4a);
	ov7670_set(0x74, 0x10);
	ov7670_set(0x8d, 0x4f);
	ov7670_set(0x8e, 0);
	ov7670_set(0x8f, 0);
	ov7670_set(0x90, 0);
	ov7670_set(0x91, 0);
	ov7670_set(0x96, 0);
	ov7670_set(0x9a, 0);
	ov7670_set(0xb0, 0x84);
	ov7670_set(0xb1, 0x0c);
	ov7670_set(0xb2, 0x0e);
	ov7670_set(0xb3, 0x82);
	ov7670_set(0xb8, 0x0a);

	/* Matrix coefficients */
	ov7670_set(0x4f, 0x80);
	ov7670_set(0x50, 0x80);
	ov7670_set(0x51, 0);
	ov7670_set(0x52, 0x22);
	ov7670_set(0x53, 0x5e);
	ov7670_set(0x54, 0x80);
	ov7670_set(0x58, 0x9e);

	/* More reserved magic, some of which tweaks white balance */
	ov7670_set(0x43, 0x0a);
	ov7670_set(0x44, 0xf0);
	ov7670_set(0x45, 0x34);
	ov7670_set(0x46, 0x58);
	ov7670_set(0x47, 0x28);
	ov7670_set(0x48, 0x3a);
	ov7670_set(0x59, 0x88);
	ov7670_set(0x5a, 0x88);
	ov7670_set(0x5b, 0x44);
	ov7670_set(0x5c, 0x67);
	ov7670_set(0x5d, 0x49);
	ov7670_set(0x5e, 0x0e);
	ov7670_set(0x6c, 0x0a);
	ov7670_set(0x6d, 0x55);
	ov7670_set(0x6e, 0x11);
	ov7670_set(0x6f, 0x9f); /* "9e for advance AWB" */
	ov7670_set(0x6a, 0x40);
	ov7670_set(REG_BLUE, 0x40);
	ov7670_set(REG_RED, 0x60);
	ov7670_set(REG_COM8,
			COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT | COM8_AGC | COM8_AEC
					| COM8_AWB);
	return 0;
}