-
Notifications
You must be signed in to change notification settings - Fork 2
/
helloworld.c
153 lines (118 loc) · 3.6 KB
/
helloworld.c
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* helloworld.c
*
* Created on: Feb 2, 2021
* Author: jcds
*/
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "sleep.h"
#include "s2mm_PL/init.h"
#include "capture.h"
int main() {
u32 mode = 0;
u32 width = 3840;
u32 height = 2160;
u32 frame_rate = 60;
u32 bpp = 2;
u32 size = width * height * bpp;
int frameid = 0;
u32 gpiobits = 0;
FATFS fatfs;
XIntc intc;
XScuGic apugic;
XGpioPs emio;
XGpio gpio;
XV_FrmbufWr_l2 frmbufwr_0, frmbufwr_1;
XVprocSs csc_0, scaler_0, csc_1, scaler_1;
XV_gamma_lut gammalut_0, gammalut_1;
XV_demosaic demosaic_0, demosaic_1;
XCsiSs csi_0, csi_1;
struct stimx274 imx274_0, imx274_1;
char fname0[16];
char fname1[16];
int status;
// Initialize -------------------------------------------------------------
init_platform();
print("Hello World\n\r");
xil_printf("init SD\n\r");
status = init_sd(&fatfs);
if (status != XST_SUCCESS) {
xil_printf("init SD failed\n\r");
return 0;
}
status = common_init(&intc, &apugic, &emio, &gpio);
if (status != XST_SUCCESS) { return 0; }
status = dual_iic_init(&imx274_0.iic_ex, &imx274_1.iic_ex, &intc);
if (status != XST_SUCCESS) { return 0; }
status = dual_frmbufwr_init(&frmbufwr_0, &frmbufwr_1, &emio, &intc, width, height, frame_rate);
if (status != XST_SUCCESS) { return 0; }
status = dual_procss_init(&csc_0, &scaler_0, &csc_1, &scaler_1, &emio, width, height, frame_rate);
if (status != XST_SUCCESS) { return 0; }
status = dual_gammalut_init(&gammalut_0, &gammalut_1, &emio, width, height);
if (status != XST_SUCCESS) { return 0; }
status = dual_demosaic_init(&demosaic_0, &demosaic_1, &emio, width, height);
if (status != XST_SUCCESS) { return 0; }
status = dual_csi_init(&csi_0, &csi_1, &intc);
if (status != XST_SUCCESS) { return 0; }
xil_printf("intc_start\n\r");
status = intc_start(&intc);
if (status != 0) {
xil_printf("intc_start failed! (%d)\n\r", status);
return 0;
}
frmbufwr_start(&frmbufwr_0);
frmbufwr_start(&frmbufwr_1);
status = procss_start(&csc_0, &scaler_0);
if (status != 0) {
xil_printf("procss_start 0 failed! (%d)\n\r", status);
return 0;
}
status = procss_start(&csc_1, &scaler_1);
if (status != 0) {
xil_printf("procss_start 1 failed! (%d)\n\r", status);
return 0;
}
gammalut_start(&gammalut_0);
gammalut_start(&gammalut_1);
demosaic_start(&demosaic_0);
demosaic_start(&demosaic_1);
xil_printf("imx274 reset\n\r");
dual_imx274_reset(&emio, 1);
xil_printf("imx274 init\n\r");
sensor_init(&imx274_0, mode, frame_rate, 16636 * 1, 5632);
sensor_init(&imx274_1, mode, frame_rate, 16636 * 0.5, 5632);
xil_printf("csi_activate 0\n\r");
status = csi_start(&csi_0);
if (status != XST_SUCCESS) {
xil_printf("csi_activate 0 failed!\n\r");
return 0;
}
xil_printf("csi_activate 1\n\r");
status = csi_start(&csi_1);
if (status != XST_SUCCESS) {
xil_printf("csi_activate 1 failed!\n\r");
return 0;
}
// Main loop --------------------------------------------------------------
xil_printf("Ready to capture!\n\r");
xil_printf("Press any of SW14, SW15, SW16, SW17, or SW18 to take a picture.\n\r");
for (;;) {
gpiobits = (gpiobits << 5) | gpio_read_capture(&gpio);
if ((~(gpiobits >> 5) & gpiobits) & 0x1F) {
xil_printf("Capturing...\n\r");
sprintf(fname0, "0:/i0f%d.raw", frameid);
sprintf(fname1, "0:/i1f%d.raw", frameid);
frameid = (frameid + 1) & 0x7FFF;
capture_images(&frmbufwr_0, &frmbufwr_1, fname0, fname1, size);
sleep(1);
gpiobits = 0;
}
else {
usleep(17*1000);
}
}
cleanup_platform();
return 0;
}