Added usb video example

This commit is contained in:
Gericom
2025-12-14 10:47:56 +01:00
parent 3bb550c12e
commit 8b47512f92
29 changed files with 1883 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
#pragma once
typedef enum
{
CAMERA_IPC_CMD_INIT_FRONT,
CAMERA_IPC_CMD_INIT_BACK,
CAMERA_IPC_CMD_ACTIVATE,
CAMERA_IPC_CMD_DEACTIVATE,
CAMERA_IPC_CMD_SWITCH
} CameraIpcCommand;

View File

@@ -0,0 +1,4 @@
#pragma once
#define IPC_CHANNEL_CAMERA 16
#define IPC_CHANNEL_CAPTURE 17

View File

@@ -0,0 +1,11 @@
#include "common.h"
#include <libtwl/ipc/ipcFifoSystem.h>
#include "IpcService.h"
void IpcService::Start()
{
ipc_setChannelHandler(_ipcChannel, [] (u32 channel, u32 data, void* arg)
{
static_cast<IpcService*>(arg)->OnMessageReceived(data);
}, this);
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <libtwl/ipc/ipcFifoSystem.h>
class IpcService
{
const u32 _ipcChannel;
protected:
explicit IpcService(u32 ipcChannel)
: _ipcChannel(ipcChannel) { }
void SendResponseMessage(u32 data) const
{
ipc_sendFifoMessage(_ipcChannel, data);
}
public:
virtual void Start();
virtual void OnMessageReceived(u32 data) = 0;
};

View File

@@ -0,0 +1,33 @@
#include "common.h"
#include "ThreadIpcService.h"
void ThreadIpcService::ThreadMain()
{
while (true)
{
rtos_waitEvent(&_event, false, true);
if (_messageValid)
{
_messageValid = false;
HandleMessage(_message);
}
}
}
void ThreadIpcService::Start()
{
rtos_createEvent(&_event);
rtos_createThread(&_thread, 5, [] (void* arg)
{
static_cast<ThreadIpcService*>(arg)->ThreadMain();
}, this, _stack, _stackSize);
rtos_wakeupThread(&_thread);
IpcService::Start();
}
void ThreadIpcService::OnMessageReceived(u32 data)
{
_message = data;
_messageValid = true;
rtos_signalEvent(&_event);
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include <libtwl/rtos/rtosThread.h>
#include <libtwl/rtos/rtosEvent.h>
#include "IpcService.h"
class ThreadIpcService : public IpcService
{
rtos_thread_t _thread;
rtos_event_t _event;
u32* _stack;
u32 _stackSize;
u8 _priority;
bool _messageValid = false;
u32 _message;
void ThreadMain();
public:
ThreadIpcService(u32 ipcChannel, u8 priority, u32* stack, u32 stackSize)
: IpcService(ipcChannel), _stack(stack), _stackSize(stackSize), _priority(priority) { }
void Start() override;
void OnMessageReceived(u32 data) override;
virtual void HandleMessage(u32 data);
};