Skip to content

Commit

Permalink
Integrate interrupt events to unlock camera fps (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathaeuz committed May 10, 2021
1 parent c073613 commit 0e4e2df
Showing 1 changed file with 63 additions and 17 deletions.
80 changes: 63 additions & 17 deletions camera/video/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ int main() {
printf("CAMU_SetSize: 0x%08X\n", (unsigned int) CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A));
printf("CAMU_SetOutputFormat: 0x%08X\n", (unsigned int) CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A));

// TODO: For some reason frame grabbing times out above 10fps. Figure out why this is.
printf("CAMU_SetFrameRate: 0x%08X\n", (unsigned int) CAMU_SetFrameRate(SELECT_OUT1_OUT2, FRAME_RATE_10));
printf("CAMU_SetFrameRate: 0x%08X\n", (unsigned int) CAMU_SetFrameRate(SELECT_OUT1_OUT2, FRAME_RATE_30));

printf("CAMU_SetNoiseFilter: 0x%08X\n", (unsigned int) CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true));
printf("CAMU_SetAutoExposure: 0x%08X\n", (unsigned int) CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true));
Expand All @@ -142,8 +141,13 @@ int main() {

printf("CAMU_Activate: 0x%08X\n", (unsigned int) CAMU_Activate(SELECT_OUT1_OUT2));

Handle camReceiveEvent = 0;
Handle camReceiveEvent2 = 0;
Handle camReceiveEvent[4] = {0};
bool captureInterrupted = false;
s32 index = 0;

// events 0 and 1 for interruption
printf("CAMU_GetBufferErrorInterruptEvent: 0x%08X\n", (unsigned int) CAMU_GetBufferErrorInterruptEvent(&camReceiveEvent[0], PORT_CAM1));
printf("CAMU_GetBufferErrorInterruptEvent: 0x%08X\n", (unsigned int) CAMU_GetBufferErrorInterruptEvent(&camReceiveEvent[1], PORT_CAM2));

printf("CAMU_ClearBuffer: 0x%08X\n", (unsigned int) CAMU_ClearBuffer(PORT_BOTH));
printf("CAMU_SynchronizeVsyncTiming: 0x%08X\n", (unsigned int) CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2));
Expand All @@ -160,20 +164,58 @@ int main() {

// Main loop
while (aptMainLoop()) {
// Read which buttons are currently pressed or not
hidScanInput();
kDown = hidKeysDown();

// If START button is pressed, break loop and quit
if (kDown & KEY_START) {
break;
if (!captureInterrupted) {
// Read which buttons are currently pressed or not
hidScanInput();
kDown = hidKeysDown();

// If START button is pressed, break loop and quit
if (kDown & KEY_START) {
break;
}
}

// events 2 and 3 for capture
if (camReceiveEvent[2] == 0) {
printf("CAMU_SetReceiving: 0x%08X\n", (unsigned int) CAMU_SetReceiving(&camReceiveEvent[2], buf, PORT_CAM1, SCREEN_SIZE, (s16)bufSize));
}
if (camReceiveEvent[3] == 0) {
CAMU_SetReceiving(&camReceiveEvent[3], buf + SCREEN_SIZE, PORT_CAM2, SCREEN_SIZE, (s16)bufSize);
}

if (captureInterrupted) {
printf("CAMU_StartCapture: 0x%08X\n", (unsigned int) CAMU_StartCapture(PORT_BOTH));
captureInterrupted = false;
}

printf("CAMU_SetReceiving: 0x%08X\n", (unsigned int) CAMU_SetReceiving(&camReceiveEvent, buf, PORT_CAM1, SCREEN_SIZE, (s16) bufSize));
CAMU_SetReceiving(&camReceiveEvent2, buf + SCREEN_SIZE, PORT_CAM2, SCREEN_SIZE, (s16) bufSize);
printf("svcWaitSynchronizationN: 0x%08X\n", (unsigned int) svcWaitSynchronizationN(&index, camReceiveEvent, 4, false, WAIT_TIMEOUT));
switch (index) {
case 0:
printf("svcCloseHandle: 0x%08X\n", (unsigned int) svcCloseHandle(camReceiveEvent[2]));
camReceiveEvent[2] = 0;

printf("svcWaitSynchronization: 0x%08X\n", (unsigned int) svcWaitSynchronization(camReceiveEvent, WAIT_TIMEOUT));
svcWaitSynchronization(camReceiveEvent2, WAIT_TIMEOUT);
captureInterrupted = true;
continue; //skip screen update
break;
case 1:
svcCloseHandle(camReceiveEvent[3]);
camReceiveEvent[3] = 0;

captureInterrupted = true;
continue; //skip screen update
break;
case 2:
printf("svcCloseHandle: 0x%08X\n", (unsigned int) svcCloseHandle(camReceiveEvent[2]));
camReceiveEvent[2] = 0;
break;
case 3:
svcCloseHandle(camReceiveEvent[3]);
camReceiveEvent[3] = 0;
break;
default:
break;
}

if(CONFIG_3D_SLIDERSTATE > 0.0f) {
gfxSet3D(true);
Expand All @@ -184,9 +226,6 @@ int main() {
writePictureToFramebufferRGB565(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), buf, 0, 0, WIDTH, HEIGHT);
}

printf("svcCloseHandle: 0x%08X\n", (unsigned int) svcCloseHandle(camReceiveEvent));
svcCloseHandle(camReceiveEvent2);

// Flush and swap framebuffers
gfxFlushBuffers();
gspWaitForVBlank();
Expand All @@ -195,6 +234,13 @@ int main() {

printf("CAMU_StopCapture: 0x%08X\n", (unsigned int) CAMU_StopCapture(PORT_BOTH));

// Close camera event handles
for (int i = 0; i < 4; i++) {
if (camReceiveEvent[i] != 0) {
svcCloseHandle(camReceiveEvent[i]);
}
}

printf("CAMU_Activate: 0x%08X\n", (unsigned int) CAMU_Activate(SELECT_NONE));

// Exit
Expand Down

0 comments on commit 0e4e2df

Please sign in to comment.