Use ctrulib functions for mcu/battery level
This commit is contained in:
parent
a74d9c6d3e
commit
188400c5a9
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <3ds.h>
|
|
||||||
|
|
||||||
Handle mcuhwcHandle;
|
|
||||||
|
|
||||||
Result mcuInit(void);
|
|
||||||
Result mcuExit(void);
|
|
||||||
Result mcuReadRegister(u8 reg, u8* data, u32 size);
|
|
||||||
Result mcuWriteRegister(u8 reg, u8* data, u32 size);
|
|
||||||
Result mcuGetLEDState(u8* out);
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Luma3DS
|
|
||||||
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mcu.h"
|
|
||||||
|
|
||||||
Result mcuInit(void)
|
|
||||||
{
|
|
||||||
return srvGetServiceHandle(&mcuhwcHandle, "mcu::HWC");
|
|
||||||
}
|
|
||||||
|
|
||||||
Result mcuExit(void)
|
|
||||||
{
|
|
||||||
return svcCloseHandle(mcuhwcHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result mcuReadRegister(u8 reg, u8* data, u32 size)
|
|
||||||
{
|
|
||||||
u32* ipc = getThreadCommandBuffer();
|
|
||||||
ipc[0] = 0x10082;
|
|
||||||
ipc[1] = reg;
|
|
||||||
ipc[2] = size;
|
|
||||||
ipc[3] = size << 4 | 0xC;
|
|
||||||
ipc[4] = (u32)data;
|
|
||||||
Result ret = svcSendSyncRequest(mcuhwcHandle);
|
|
||||||
if(ret < 0) return ret;
|
|
||||||
return ipc[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
Result mcuWriteRegister(u8 reg, u8* data, u32 size)
|
|
||||||
{
|
|
||||||
u32* ipc = getThreadCommandBuffer();
|
|
||||||
ipc[0] = 0x20082;
|
|
||||||
ipc[1] = reg;
|
|
||||||
ipc[2] = size;
|
|
||||||
ipc[3] = size << 4 | 0xA;
|
|
||||||
ipc[4] = (u32)data;
|
|
||||||
Result ret = svcSendSyncRequest(mcuhwcHandle);
|
|
||||||
if(ret < 0) return ret;
|
|
||||||
return ipc[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
Result mcuGetLEDState(u8* out)
|
|
||||||
{
|
|
||||||
return mcuReadRegister(0x28, out, 1);
|
|
||||||
}
|
|
@ -28,7 +28,6 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "mcu.h"
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "ifile.h"
|
#include "ifile.h"
|
||||||
#include "menus.h"
|
#include "menus.h"
|
||||||
@ -124,26 +123,6 @@ u32 waitCombo(void)
|
|||||||
return waitComboWithTimeout(0);
|
return waitComboWithTimeout(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _MCUHWC_GetBatteryLevel(u8 *out)
|
|
||||||
{
|
|
||||||
#define TRY(expr) if(R_FAILED(res = (expr))) { mcuExit(); return res; }
|
|
||||||
Result res;
|
|
||||||
|
|
||||||
TRY(mcuInit());
|
|
||||||
|
|
||||||
u32 *cmdbuf = getThreadCommandBuffer();
|
|
||||||
cmdbuf[0] = 0x50000;
|
|
||||||
|
|
||||||
TRY(svcSendSyncRequest(mcuhwcHandle));
|
|
||||||
|
|
||||||
*out = (u8) cmdbuf[2];
|
|
||||||
|
|
||||||
svcCloseHandle(mcuhwcHandle);
|
|
||||||
return cmdbuf[1];
|
|
||||||
|
|
||||||
#undef TRY
|
|
||||||
}
|
|
||||||
|
|
||||||
static MyThread menuThread;
|
static MyThread menuThread;
|
||||||
static u8 ALIGN(8) menuThreadStack[THREAD_STACK_SIZE];
|
static u8 ALIGN(8) menuThreadStack[THREAD_STACK_SIZE];
|
||||||
static u8 batteryLevel = 255;
|
static u8 batteryLevel = 255;
|
||||||
@ -215,8 +194,12 @@ static void menuDraw(Menu *menu, u32 selected)
|
|||||||
u32 version, commitHash;
|
u32 version, commitHash;
|
||||||
bool isRelease;
|
bool isRelease;
|
||||||
|
|
||||||
if(R_FAILED(_MCUHWC_GetBatteryLevel(&batteryLevel)))
|
if(R_SUCCEEDED(mcuHwcInit()))
|
||||||
|
{
|
||||||
|
if(R_FAILED(mcuHwcGetBatteryLevel(&batteryLevel)))
|
||||||
batteryLevel = 255;
|
batteryLevel = 255;
|
||||||
|
mcuHwcExit();
|
||||||
|
}
|
||||||
|
|
||||||
svcGetSystemInfo(&out, 0x10000, 0);
|
svcGetSystemInfo(&out, 0x10000, 0);
|
||||||
version = (u32)out;
|
version = (u32)out;
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#include "menus/miscellaneous.h"
|
#include "menus/miscellaneous.h"
|
||||||
#include "input_redirection.h"
|
#include "input_redirection.h"
|
||||||
#include "mcu.h"
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "hbloader.h"
|
#include "hbloader.h"
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#include "menus/sysconfig.h"
|
#include "menus/sysconfig.h"
|
||||||
#include "mcu.h"
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
@ -65,12 +64,12 @@ void SysConfigMenu_ToggleLEDs(void)
|
|||||||
|
|
||||||
if(pressed & BUTTON_A)
|
if(pressed & BUTTON_A)
|
||||||
{
|
{
|
||||||
mcuInit();
|
mcuHwcInit();
|
||||||
u8 result;
|
u8 result;
|
||||||
mcuGetLEDState(&result);
|
mcuHwcReadRegister(0x28, &result, 1);
|
||||||
u8 value = ~result;
|
result = ~result;
|
||||||
mcuWriteRegister(40, &value, 1);
|
mcuHwcWriteRegister(40, &result, 1);
|
||||||
mcuExit();
|
mcuHwcExit();
|
||||||
}
|
}
|
||||||
else if(pressed & BUTTON_B)
|
else if(pressed & BUTTON_B)
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user