TinyUVC 0.1.0
Header-only USB Video Class (UVC) device: turn an MCU into a USB webcam
Loading...
Searching...
No Matches
UVCPlatformDesktop.h
Go to the documentation of this file.
1#pragma once
7#include <chrono>
8#include <cstdlib>
9#include <thread>
10
11#include "../UVCDevice.h"
12#include "../desktop/TinyUSBSim.h"
13
14namespace tinyuvc {
15
19 uint16_t maxPacketSize = 64;
20};
21
23 static UVCDesktopSettings settings;
24 return settings;
25}
26
27namespace platform {
28
29inline bool begin(UVCDevice &) { return true; }
30inline void end(UVCDevice &) {}
31inline uint16_t maxPacketSize() { return desktopSettings().maxPacketSize; }
32
33inline void idle() {
34 UVCSimBus &b = simBus();
35 if (b.pump)
36 b.pump(b.pumpRef);
37 else
38 std::this_thread::sleep_for(std::chrono::milliseconds(1));
39}
40
41inline uint32_t millis() {
42 using namespace std::chrono;
43 static const auto start = steady_clock::now();
44 return (uint32_t)duration_cast<milliseconds>(steady_clock::now() - start).count();
45}
46
47inline uint32_t micros() {
48 using namespace std::chrono;
49 static const auto start = steady_clock::now();
50 return (uint32_t)duration_cast<microseconds>(steady_clock::now() - start).count();
51}
52
53inline uint8_t *allocBuffer(size_t size) {
54 return (uint8_t *)std::malloc((size + 63) & ~(size_t)63);
55}
56inline void freeBuffer(uint8_t *buf) { std::free(buf); }
57
60
61} // namespace platform
62} // namespace tinyuvc
USB Video Class (UVC 1.1) device - a USB webcam.
Definition UVCDevice.h:95
void freeBuffer(uint8_t *buf)
Definition UVCPlatformDesktop.h:56
bool begin(UVCDevice &)
Registers the UVC function with the USB stack (and starts it if needed)
Definition UVCPlatformDesktop.h:29
uint8_t * allocBuffer(size_t size)
Allocates the transfer buffer (DMA capable, aligned)
Definition UVCPlatformDesktop.h:53
void end(UVCDevice &)
Unregisters the UVC function, where the USB stack supports that.
Definition UVCPlatformDesktop.h:30
uint16_t maxPacketSize()
Max packet size of the bulk endpoint (64 full speed, 512 high speed)
Definition UVCPlatformDesktop.h:31
uint32_t millis()
Definition UVCPlatformDesktop.h:41
void idle()
Called while waiting: lets the USB stack make progress.
Definition UVCPlatformDesktop.h:33
uint32_t micros()
Definition UVCPlatformDesktop.h:47
TinyUVC: USB Video Class (UVC) device for Arduino and the desktop.
UVCDesktopSettings & desktopSettings()
Definition UVCPlatformDesktop.h:22
UVCSimBus & simBus()
Definition TinyUSBSim.h:138
Settings of the simulated USB bus.
Definition UVCPlatformDesktop.h:17
uint16_t maxPacketSize
64 = full speed (ESP32-S2/S3, RP2040, STM32 OTG_FS), 512 = high speed
Definition UVCPlatformDesktop.h:19
What the device side did, as seen by the simulated USB core.
Definition TinyUSBSim.h:106
void(* pump)(void *ref)
Definition TinyUSBSim.h:122
void * pumpRef
Definition TinyUSBSim.h:123
~AppLock()
Definition UVCPlatformDesktop.h:59
AppLock()
Definition UVCPlatformDesktop.h:58