Add MCU::HWC::GetBatteryLevel

This commit is contained in:
wheremyfoodat 2023-08-19 17:50:55 +03:00
parent c544dd1567
commit 6d7ab14480
3 changed files with 16 additions and 3 deletions

View file

@ -1,4 +1,5 @@
#pragma once
#include "config.hpp"
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
@ -10,11 +11,13 @@ namespace MCU {
Memory& mem;
MAKE_LOG_FUNCTION(log, mcuLogger)
const EmulatorConfig& config;
// Service commands
void getBatteryLevel(u32 messagePointer);
public:
HWCService(Memory& mem) : mem(mem) {}
HWCService(Memory& mem, const EmulatorConfig& config) : mem(mem), config(config) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -4,6 +4,7 @@
namespace MCU::HWCCommands {
enum : u32 {
GetBatteryLevel = 0x00050000,
};
}
@ -12,6 +13,15 @@ void MCU::HWCService::reset() {}
void MCU::HWCService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case HWCCommands::GetBatteryLevel: getBatteryLevel(messagePointer); break;
default: Helpers::panic("MCU::HWC service requested. Command: %08X\n", command);
}
}
void MCU::HWCService::getBatteryLevel(u32 messagePointer) {
log("MCU::HWC::GetBatteryLevel\n");
mem.write32(messagePointer, IPC::responseHeader(0x5, 2, 0));
mem.write32(messagePointer + 4, Result::Success);
mem.write8(messagePointer + 8, config.batteryPercentage);
}

View file

@ -8,8 +8,8 @@
ServiceManager::ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel, const EmulatorConfig& config)
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), act(mem), apt(mem, kernel), cam(mem, kernel), cecd(mem, kernel), cfg(mem),
dlp_srvr(mem), dsp(mem, kernel), hid(mem, kernel), http(mem), ir_user(mem, kernel), frd(mem), fs(mem, kernel),
gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem), ldr(mem), mcu_hwc(mem), mic(mem), nfc(mem, kernel), nim(mem), ndm(mem), ptm(mem, config),
soc(mem), ssl(mem), y2r(mem, kernel) {}
gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem), ldr(mem), mcu_hwc(mem, config), mic(mem), nfc(mem, kernel), nim(mem), ndm(mem),
ptm(mem, config), soc(mem), ssl(mem), y2r(mem, kernel) {}
static constexpr int MAX_NOTIFICATION_COUNT = 16;