Fixed RTC type conversion warning.

This commit is contained in:
profi200 2022-04-26 03:02:31 +02:00
parent 5714b5eb16
commit b8b75d784c
No known key found for this signature in database
GPG Key ID: 17B42AE5911139F3
2 changed files with 19 additions and 10 deletions

View File

@ -95,3 +95,9 @@ static inline u32 nextPow2(u32 val)
// Everything else is undefined behavior.
return 1u<<(32u - __builtin_clzl(val - 1));
}
// https://stackoverflow.com/a/42340213
static inline u8 bcd2dec(const u8 bcd)
{
return bcd - 6u * (bcd>>4);
}

View File

@ -22,6 +22,7 @@
#include "drivers/lgy.h"
#include "drivers/pxi.h"
#include "ipc_handler.h"
#include "util.h"
#include "arm11/drivers/hid.h"
#include "arm11/drivers/interrupt.h"
#include "drivers/cache.h"
@ -94,12 +95,6 @@ static void powerDownFcramForLegacy(u8 mode)
while(pdn->fcram_cnt & PDN_FCRAM_CNT_CLK_EN_ACK); // Wait until clock is disabled.
}
// https://stackoverflow.com/a/42340213
static inline u8 bcd2dec(u8 bcd)
{
return bcd - 6 * (bcd>>4);
}
// https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto's_methods
static void calcDayOfWeek(GbaRtc *const rtc)
{
@ -112,6 +107,17 @@ static void calcDayOfWeek(GbaRtc *const rtc)
rtc->dow = (y + (y / 4u) - (y / 100u) + (y / 400u) + t[m - 1] + d) % 7u;
}
// Extra safety check just in case.
static_assert(sizeof(GbaRtc) >= sizeof(RtcTimeDate), "GbaRtc is not bigger or same size as RtcTimeDate!");
static void mcuTimeDateToGbaRtc(GbaRtc *const rtc)
{
// Lazy conversion.
MCU_getRtcTimeDate((RtcTimeDate*)rtc);
rtc->time = __builtin_bswap32(rtc->time)>>8;
rtc->date = __builtin_bswap32(rtc->date)>>8;
calcDayOfWeek(rtc);
}
Result LGY_prepareGbaMode(bool directBoot, u16 saveType, const char *const savePath)
{
u32 cmdBuf[4];
@ -124,10 +130,7 @@ Result LGY_prepareGbaMode(bool directBoot, u16 saveType, const char *const saveP
// Setup GBA Real-Time Clock.
GbaRtc rtc;
MCU_getRtcTimeDate((u8*)&rtc);
rtc.time = __builtin_bswap32(rtc.time)>>8;
rtc.date = __builtin_bswap32(rtc.date)>>8;
calcDayOfWeek(&rtc);
mcuTimeDateToGbaRtc(&rtc);
LGY_setGbaRtc(rtc);
// Setup FCRAM for GBA mode.