2016-06-10 21:48:22 +02:00
|
|
|
/*
|
2016-07-05 16:05:53 +02:00
|
|
|
* This file is part of Luma3DS
|
2019-02-25 02:04:32 +01:00
|
|
|
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
2016-06-10 21:48:22 +02:00
|
|
|
*
|
2016-07-05 16:05:53 +02:00
|
|
|
* 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/>.
|
|
|
|
*
|
2017-06-05 02:02:04 +02:00
|
|
|
* 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.
|
2016-07-05 16:05:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-09-08 23:07:03 +02:00
|
|
|
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others
|
|
|
|
* Screen deinit code by tiniVi
|
2016-06-10 21:48:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "screen.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "i2c.h"
|
2016-11-14 15:39:26 +01:00
|
|
|
#include "utils.h"
|
2016-06-10 21:48:22 +02:00
|
|
|
|
2019-02-26 20:19:52 +01:00
|
|
|
bool needToSetupScreens = true;
|
|
|
|
|
2017-06-06 02:12:18 +02:00
|
|
|
struct fb fbs[2] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.top_left = (u8 *)0x18300000,
|
|
|
|
.top_right = (u8 *)0x18300000,
|
|
|
|
.bottom = (u8 *)0x18346500,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.top_left = (u8 *)0x18400000,
|
|
|
|
.top_right = (u8 *)0x18400000,
|
|
|
|
.bottom = (u8 *)0x18446500,
|
|
|
|
},
|
|
|
|
};
|
2017-05-24 15:18:31 +02:00
|
|
|
|
2016-07-19 20:03:35 +02:00
|
|
|
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
|
2016-06-10 21:48:22 +02:00
|
|
|
|
2017-05-23 21:47:20 +02:00
|
|
|
static volatile Arm11Operation *operation = (volatile Arm11Operation *)0x1FF80004;
|
2017-05-23 02:44:04 +02:00
|
|
|
|
|
|
|
static void invokeArm11Function(Arm11Operation op)
|
2016-06-10 21:48:22 +02:00
|
|
|
{
|
2017-05-23 13:33:32 +02:00
|
|
|
while(*operation != ARM11_READY);
|
2017-05-23 02:44:04 +02:00
|
|
|
*operation = op;
|
2018-06-14 18:13:57 +02:00
|
|
|
while(*operation != ARM11_READY);
|
2016-06-10 21:48:22 +02:00
|
|
|
}
|
2017-01-24 21:59:02 +01:00
|
|
|
|
2017-05-23 02:44:04 +02:00
|
|
|
void prepareArm11ForFirmlaunch(void)
|
2016-06-10 21:48:22 +02:00
|
|
|
{
|
2017-05-23 02:44:04 +02:00
|
|
|
invokeArm11Function(PREPARE_ARM11_FOR_FIRMLAUNCH);
|
2016-06-10 21:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void deinitScreens(void)
|
|
|
|
{
|
2017-05-23 02:44:04 +02:00
|
|
|
if(ARESCREENSINITIALIZED) invokeArm11Function(DEINIT_SCREENS);
|
2016-06-10 21:48:22 +02:00
|
|
|
}
|
|
|
|
|
2016-07-18 15:06:35 +02:00
|
|
|
void updateBrightness(u32 brightnessIndex)
|
2016-06-10 21:48:22 +02:00
|
|
|
{
|
2017-05-23 02:44:04 +02:00
|
|
|
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[brightnessIndex];
|
|
|
|
invokeArm11Function(UPDATE_BRIGHTNESS);
|
2016-06-10 21:48:22 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 14:48:28 +02:00
|
|
|
void swapFramebuffers(bool isAlternate)
|
|
|
|
{
|
2017-05-23 02:44:04 +02:00
|
|
|
*(volatile bool *)ARM11_PARAMETERS_ADDRESS = isAlternate;
|
|
|
|
invokeArm11Function(SWAP_FRAMEBUFFERS);
|
2016-09-22 14:48:28 +02:00
|
|
|
}
|
|
|
|
|
2016-11-15 14:08:58 +01:00
|
|
|
void clearScreens(bool isAlternate)
|
2016-09-13 16:22:26 +02:00
|
|
|
{
|
2017-05-23 02:44:04 +02:00
|
|
|
struct fb *fbTemp = isAlternate ? &fbs[1] : &fbs[0];
|
2016-07-18 15:06:35 +02:00
|
|
|
|
2017-05-23 02:44:04 +02:00
|
|
|
*(volatile struct fb *)ARM11_PARAMETERS_ADDRESS = *fbTemp;
|
|
|
|
invokeArm11Function(CLEAR_SCREENS);
|
|
|
|
}
|
2016-06-10 21:48:22 +02:00
|
|
|
|
2016-08-15 03:51:48 +02:00
|
|
|
void initScreens(void)
|
2016-06-10 21:48:22 +02:00
|
|
|
{
|
2019-02-26 20:19:52 +01:00
|
|
|
if(needToSetupScreens)
|
2016-08-15 15:25:44 +02:00
|
|
|
{
|
2019-02-26 20:19:52 +01:00
|
|
|
if(!ARESCREENSINITIALIZED || bootType == FIRMLAUNCH)
|
2016-09-22 14:48:28 +02:00
|
|
|
{
|
2017-06-06 02:12:18 +02:00
|
|
|
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)];
|
2017-08-13 17:36:31 +02:00
|
|
|
memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs));
|
2017-06-06 02:12:18 +02:00
|
|
|
invokeArm11Function(INIT_SCREENS);
|
2016-09-22 14:48:28 +02:00
|
|
|
|
|
|
|
//Turn on backlight
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
|
|
|
|
}
|
2017-08-16 15:49:57 +02:00
|
|
|
else updateBrightness(MULTICONFIG(BRIGHTNESS));
|
|
|
|
|
|
|
|
memcpy((void *)ARM11_PARAMETERS_ADDRESS, fbs, sizeof(fbs));
|
|
|
|
invokeArm11Function(SETUP_FRAMEBUFFERS);
|
2016-09-22 14:48:28 +02:00
|
|
|
|
2017-07-09 19:06:42 +02:00
|
|
|
clearScreens(true);
|
2019-02-26 20:19:52 +01:00
|
|
|
needToSetupScreens = false;
|
2016-08-15 15:25:44 +02:00
|
|
|
}
|
2016-09-22 14:48:28 +02:00
|
|
|
|
2016-11-15 14:08:58 +01:00
|
|
|
clearScreens(false);
|
2016-09-23 14:34:20 +02:00
|
|
|
swapFramebuffers(false);
|
2017-01-15 22:23:20 +01:00
|
|
|
}
|