1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 00:12:03 +00:00

htc: skeleton some more of main

This commit is contained in:
Michael Scire 2021-02-07 18:34:12 -08:00 committed by SciresM
parent fc060d3777
commit 83c1c175ba
9 changed files with 268 additions and 0 deletions

View file

@ -53,6 +53,10 @@
#include <stratosphere/gpio.hpp> #include <stratosphere/gpio.hpp>
#include <stratosphere/hid.hpp> #include <stratosphere/hid.hpp>
#include <stratosphere/hos.hpp> #include <stratosphere/hos.hpp>
#include <stratosphere/htc.hpp>
#include <stratosphere/htcfs.hpp>
#include <stratosphere/htclow.hpp>
#include <stratosphere/htcs.hpp>
#include <stratosphere/i2c.hpp> #include <stratosphere/i2c.hpp>
#include <stratosphere/kvdb.hpp> #include <stratosphere/kvdb.hpp>
#include <stratosphere/ldr.hpp> #include <stratosphere/ldr.hpp>

View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once

View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once

View file

@ -0,0 +1,18 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once
#include <stratosphere/htclow/htclow_types.hpp>
#include <stratosphere/htclow/htclow_manager_holder.hpp>

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/htclow/htclow_types.hpp>
namespace ams::htclow {
class HtclowManager;
namespace HtclowManagerHolder {
void AddReference();
void Release();
HtclowManager *GetHtclowManager();
void SetDefaultDriver(htclow::impl::DriverType driver_type);
}
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::htclow {
namespace impl {
enum class DriverType {
Socket = 2,
Usb = 3,
HostBridge = 4,
PlainChannel = 5,
};
}
}

View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#pragma once

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
#include <stratosphere.hpp>
namespace ams::htclow::HtclowManagerHolder {
namespace {
constinit os::SdkMutex g_holder_mutex;
constinit int g_holder_reference_count = 0;
mem::StandardAllocator g_allocator;
constinit HtclowManager *g_manager = nullptr;
constinit htclow::impl::DriverType g_default_driver_type = htclow::impl::DriverType::Socket;
alignas(os::MemoryPageSize) u8 g_heap_buffer[928_KB];
}
void AddReference() {
std::scoped_lock lk(g_holder_mutex);
if ((g_holder_reference_count++) == 0) {
/* Initialize the allocator for the manager. */
g_allocator.Initialize(g_heap_buffer, sizeof(g_heap_buffer));
/* TODO: Allocate the manager. */
/* g_manager = g_allocator.Allocate(sizeof(HtclowManager), alignof(HtclowManager)); */
/* TODO: Construct the manager. */
/* std::construct_at(g_manager, std::addressof(g_allocator)); */
/* TODO: Open the driver. */
/* R_ABORT_UNLESS(g_manager->OpenDriver(g_default_driver_type)); */
}
AMS_ASSERT(g_holder_reference_count > 0);
}
void Release() {
std::scoped_lock lk(g_holder_mutex);
AMS_ASSERT(g_holder_reference_count > 0);
if ((--g_holder_reference_count) == 0) {
/* TODO: Disconnect. */
/* g_manager->Disconnect(); */
/* TODO: Close the driver. */
/* g_manager->CloseDriver(); */
/* TODO: Destroy the manager. */
/* std::destroy_at(g_manager); */
/* g_allocator.Free(g_manager); */
/* g_manager = nullptr; */
/* Finalize the allocator. */
g_allocator.Finalize();
}
}
HtclowManager *GetHtclowManager() {
return g_manager;
}
void SetDefaultDriver(htclow::impl::DriverType driver_type) {
g_default_driver_type = driver_type;
}
}

View file

@ -132,12 +132,54 @@ void __libnx_free(void *mem) {
AMS_ABORT("__libnx_free was called"); AMS_ABORT("__libnx_free was called");
} }
namespace ams::htc {
namespace {
constexpr htclow::impl::DriverType DefaultHtclowDriverType = htclow::impl::DriverType::Usb;
htclow::impl::DriverType GetHtclowDriverType() {
/* Get the transport type. */
char transport[0x10];
if (settings::fwdbg::GetSettingsItemValue(transport, sizeof(transport), "bsp0", "tm_transport") == 0) {
return DefaultHtclowDriverType;
}
/* Make the transport type case insensitive. */
transport[util::size(transport) - 1] = '\x00';
for (size_t i = 0; i < util::size(transport); ++i) {
transport[i] = std::tolower(static_cast<unsigned char>(transport[i]));
}
/* Select the transport. */
if (std::strstr(transport, "usb")) {
return htclow::impl::DriverType::Usb;
} else if (std::strstr(transport, "hb")) {
return htclow::impl::DriverType::HostBridge;
} else if (std::strstr(transport, "plainchannel")) {
return htclow::impl::DriverType::PlainChannel;
} else {
return DefaultHtclowDriverType;
}
}
}
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
/* Set thread name. */ /* Set thread name. */
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(htc, Main)); os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(htc, Main));
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(htc, Main)); AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(htc, Main));
/* Get and set the default driver type. */
const auto driver_type = htc::GetHtclowDriverType();
htclow::HtclowManagerHolder::SetDefaultDriver(driver_type);
/* Initialize the htclow manager. */
htclow::HtclowManagerHolder::AddReference();
/* TODO */ /* TODO */
/* Cleanup */ /* Cleanup */