2016-06-07 13:53:24 +02:00
|
|
|
/*
|
|
|
|
* utils.c
|
|
|
|
*/
|
|
|
|
|
2016-03-19 17:30:56 +01:00
|
|
|
#include "utils.h"
|
|
|
|
#include "draw.h"
|
2016-09-26 23:15:26 +02:00
|
|
|
#include "screen.h"
|
|
|
|
#include "cache.h"
|
2016-03-19 17:30:56 +01:00
|
|
|
#include "i2c.h"
|
|
|
|
|
2016-06-07 13:53:24 +02:00
|
|
|
u32 waitInput(void)
|
|
|
|
{
|
2016-11-14 17:27:10 +01:00
|
|
|
u32 key,
|
|
|
|
oldKey = HID_PAD;
|
2016-03-19 17:30:56 +01:00
|
|
|
|
2016-11-22 22:45:14 +01:00
|
|
|
while(true)
|
2016-06-07 13:53:24 +02:00
|
|
|
{
|
2016-03-19 17:30:56 +01:00
|
|
|
key = HID_PAD;
|
|
|
|
|
2016-11-22 22:45:14 +01:00
|
|
|
if(!key)
|
2016-06-07 13:53:24 +02:00
|
|
|
{
|
2016-11-22 22:45:14 +01:00
|
|
|
oldKey = 0;
|
|
|
|
continue;
|
2016-03-19 17:30:56 +01:00
|
|
|
}
|
2016-11-22 22:45:14 +01:00
|
|
|
|
|
|
|
if(key == oldKey) continue;
|
|
|
|
|
|
|
|
//Make sure the key is pressed
|
|
|
|
u32 i;
|
|
|
|
for(i = 0; i < 0x13000 && key == HID_PAD; i++);
|
|
|
|
if(i == 0x13000) break;
|
2016-06-07 13:53:24 +02:00
|
|
|
}
|
2016-03-19 17:30:56 +01:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2016-09-28 01:57:18 +02:00
|
|
|
void mcuReboot(void)
|
|
|
|
{
|
2016-09-29 13:01:51 +02:00
|
|
|
clearScreens();
|
2016-09-28 01:57:18 +02:00
|
|
|
|
|
|
|
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
|
|
|
flushEntireDCache();
|
|
|
|
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
|
|
|
while(true);
|
|
|
|
}
|
|
|
|
|
2016-10-02 17:18:49 +02:00
|
|
|
void inputSequence(void)
|
|
|
|
{
|
|
|
|
posY = drawString("If you would like to continue, press:", 10, posY, COLOR_WHITE);
|
|
|
|
posY = drawString("Up, Down, Left, Right, B, A, START, SELECT", 10, posY, COLOR_WHITE);
|
|
|
|
|
|
|
|
u32 unlockSequence[] = { BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_B, BUTTON_A, BUTTON_START, BUTTON_SELECT },
|
|
|
|
sequenceSize = sizeof(unlockSequence) / sizeof(u32);
|
|
|
|
|
|
|
|
for(u32 correctPresses = 0; correctPresses < sequenceSize; correctPresses++)
|
|
|
|
{
|
|
|
|
if(waitInput() != unlockSequence[correctPresses])
|
|
|
|
shutdown(1, "Button sequence not entered correctly");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 13:53:24 +02:00
|
|
|
void shutdown(u32 mode, const char *message)
|
|
|
|
{
|
2016-09-29 13:01:51 +02:00
|
|
|
if(mode != 0)
|
2016-06-07 13:53:24 +02:00
|
|
|
{
|
2016-06-08 14:41:52 +02:00
|
|
|
posY = drawString(message, 10, posY + SPACING_Y, mode == 1 ? COLOR_RED : COLOR_GREEN);
|
|
|
|
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
|
2016-03-25 04:47:07 +01:00
|
|
|
waitInput();
|
2016-03-19 17:30:56 +01:00
|
|
|
}
|
2016-09-26 23:15:26 +02:00
|
|
|
|
2016-09-29 13:01:51 +02:00
|
|
|
clearScreens();
|
2016-09-28 01:57:18 +02:00
|
|
|
|
|
|
|
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
2016-09-26 23:15:26 +02:00
|
|
|
flushEntireDCache();
|
2016-09-28 01:57:18 +02:00
|
|
|
|
2016-09-26 23:15:26 +02:00
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0);
|
|
|
|
while(true);
|
2016-03-19 17:30:56 +01:00
|
|
|
}
|