Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
enum class SwitchProOutputReportKind : uint8_t {
|
|
Ignore,
|
|
Noop,
|
|
Rumble,
|
|
Feature,
|
|
Configuration,
|
|
};
|
|
|
|
inline SwitchProOutputReportKind switch_pro_classify_output_report(
|
|
const uint8_t* report,
|
|
std::size_t length) {
|
|
if (report == nullptr || length < 2 || length > 64) {
|
|
return SwitchProOutputReportKind::Ignore;
|
|
}
|
|
|
|
switch (report[0]) {
|
|
case 0x00:
|
|
return SwitchProOutputReportKind::Noop;
|
|
case 0x01:
|
|
return length >= 16
|
|
? SwitchProOutputReportKind::Feature
|
|
: SwitchProOutputReportKind::Ignore;
|
|
case 0x10:
|
|
case 0x21:
|
|
return length >= 10
|
|
? SwitchProOutputReportKind::Rumble
|
|
: SwitchProOutputReportKind::Ignore;
|
|
case 0x80:
|
|
return SwitchProOutputReportKind::Configuration;
|
|
default:
|
|
return SwitchProOutputReportKind::Ignore;
|
|
}
|
|
}
|
|
|
|
inline bool switch_pro_spi_read_size_fits(std::size_t size) {
|
|
return size <= 64 - 20;
|
|
}
|
|
|
|
inline std::size_t switch_pro_fill_flash_read(
|
|
uint8_t* destination,
|
|
std::size_t destination_capacity,
|
|
const uint8_t* source,
|
|
std::size_t source_size,
|
|
std::size_t source_offset,
|
|
std::size_t requested) {
|
|
if (destination == nullptr) {
|
|
return 0;
|
|
}
|
|
|
|
const std::size_t produced = requested < destination_capacity
|
|
? requested
|
|
: destination_capacity;
|
|
for (std::size_t index = 0; index < produced; ++index) {
|
|
destination[index] = 0xFF;
|
|
}
|
|
|
|
if (source != nullptr && source_offset < source_size) {
|
|
const std::size_t available = source_size - source_offset;
|
|
const std::size_t copied = available < produced ? available : produced;
|
|
for (std::size_t index = 0; index < copied; ++index) {
|
|
destination[index] = source[source_offset + index];
|
|
}
|
|
}
|
|
|
|
return produced;
|
|
}
|