forked from analogdevicesinc/ai8x-synthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
73 lines (58 loc) · 1.74 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
###################################################################################################
# Copyright (C) 2019 Maxim Integrated Products, Inc. All Rights Reserved.
#
# Maxim Integrated Products, Inc. Default Copyright Notice:
# https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
#
# Written by RM
###################################################################################################
"""
Simulated camera data
"""
VSYNC_LEADIN = 10
VSYNC_HIGH = 5000
VSYNC_LOW = 2000
RETRACE = 318
FINAL = 10
def write(f, vsync, href, d, stretch=0):
"""
Write `vsync`/`href` and data `d` to CSV file `f`.
"""
f.write(f'{vsync},{href},0,{d:02x}\n')
f.write(f'{vsync},{href},1,{d:02x}\n')
f.write(f'{vsync},{href},1,{d:02x}\n')
for _ in range(stretch):
f.write(f'{vsync},{href},0,{d:02x}\n')
f.write(f'{vsync},{href},0,{d:02x}\n')
f.write(f'{vsync},{href},0,{d:02x}\n')
def header(f, leader=VSYNC_LEADIN, high=VSYNC_HIGH, low=VSYNC_LOW):
"""
Write header (VSYNC low/high/low) to CSV file `f`.
"""
f.write('vsync,href,pclk,d\n')
# Lead-in VSYNC low
for _ in range(leader):
write(f, 0, 0, 0)
# VSYNC high
for _ in range(high):
write(f, 1, 0, 0)
# VSYNC low
for _ in range(low):
write(f, 0, 0, 0)
def finish_row(f, retrace=RETRACE):
"""
Finish row by (HREF low) for CSV file `f`.
"""
for _ in range(retrace):
write(f, 0, 0, 0)
def finish_image(f, num=FINAL):
"""
Finish image (VSYNC low/HREF low) for CSV file `f`.
"""
for _ in range(num):
write(f, 0, 0, 0)
def pixel(f, val):
"""
Write pixel data `val` (HREF high) to CSV file `f`.
"""
write(f, 0, 1, val, stretch=1)