This repository has been archived on 2022-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Luma3DS-3GX/source/screen.c

120 lines
3.4 KiB
C
Raw Normal View History

/*
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-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/>.
*
* 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
*/
#include "screen.h"
#include "config.h"
#include "memory.h"
#include "i2c.h"
#include "utils.h"
bool needToSetupScreens = true;
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,
},
};
2016-07-19 20:03:35 +02:00
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
2017-05-23 21:47:20 +02:00
static volatile Arm11Operation *operation = (volatile Arm11Operation *)0x1FF80004;
static void invokeArm11Function(Arm11Operation op)
{
2017-05-23 13:33:32 +02:00
while(*operation != ARM11_READY);
*operation = op;
2018-06-14 18:13:57 +02:00
while(*operation != ARM11_READY);
}
2017-01-24 21:59:02 +01:00
void prepareArm11ForFirmlaunch(void)
{
invokeArm11Function(PREPARE_ARM11_FOR_FIRMLAUNCH);
}
void deinitScreens(void)
{
if(ARESCREENSINITIALIZED) invokeArm11Function(DEINIT_SCREENS);
}
void updateBrightness(u32 brightnessIndex)
{
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[brightnessIndex];
invokeArm11Function(UPDATE_BRIGHTNESS);
}
void swapFramebuffers(bool isAlternate)
{
*(volatile bool *)ARM11_PARAMETERS_ADDRESS = isAlternate;
invokeArm11Function(SWAP_FRAMEBUFFERS);
}
2016-11-15 14:08:58 +01:00
void clearScreens(bool isAlternate)
{
struct fb *fbTemp = isAlternate ? &fbs[1] : &fbs[0];
*(volatile struct fb *)ARM11_PARAMETERS_ADDRESS = *fbTemp;
invokeArm11Function(CLEAR_SCREENS);
}
void initScreens(void)
{
if(needToSetupScreens)
{
if(!ARESCREENSINITIALIZED || bootType == FIRMLAUNCH)
{
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)];
memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs));
invokeArm11Function(INIT_SCREENS);
//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);
clearScreens(true);
needToSetupScreens = false;
}
2016-11-15 14:08:58 +01:00
clearScreens(false);
swapFramebuffers(false);
2017-01-15 22:23:20 +01:00
}