Initial Commit

This commit is contained in:
2026-03-05 20:18:29 +01:00
commit 5a4d3ee8e0
901 changed files with 296682 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
#include "hid.h"
#include <input/joycon.h>
#include <utils/btn.h>
#include "../gfx/gfx.h"
#include <utils/types.h>
#include <utils/util.h>
#include "../utils/utils.h"
#include "../tegraexplorer/tools.h"
#include <display/di.h>
#include "../config.h"
static Input_t inputs = {0};
u16 LbaseX = 0, LbaseY = 0, RbaseX = 0, RbaseY = 0;
void hidInit(){
jc_init_hw();
}
extern hekate_config h_cfg;
Input_t *hidRead(){
jc_gamepad_rpt_t *controller = joycon_poll();
inputs.buttons = 0;
u8 left_connected = 0;
u8 right_connected = 0;
if (controller != NULL){
if (controller->home && !h_cfg.t210b01)
RebootToPayloadOrRcm();
if (controller->cap)
TakeScreenshot();
inputs.buttons = controller->buttons;
left_connected = controller->conn_l;
right_connected = controller->conn_r;
}
u8 btn = btn_read();
inputs.volp = (btn & BTN_VOL_UP) ? 1 : 0;
inputs.volm = (btn & BTN_VOL_DOWN) ? 1 : 0;
inputs.power = (btn & BTN_POWER) ? 1 : 0;
if (left_connected){
if ((LbaseX == 0 || LbaseY == 0) || controller->l3){
LbaseX = controller->lstick_x;
LbaseY = controller->lstick_y;
}
inputs.up = (controller->up || inputs.volp || (controller->lstick_y > LbaseY + 500)) ? 1 : 0;
inputs.down = (controller->down || inputs.volm || (controller->lstick_y < LbaseY - 500)) ? 1 : 0;
inputs.left = (controller->left || (controller->lstick_x < LbaseX - 500)) ? 1 : 0;
inputs.right = (controller->right || (controller->lstick_x > LbaseX + 500)) ? 1 : 0;
}
else {
inputs.up = inputs.volp;
inputs.down = inputs.volm;
}
if (right_connected){
if ((RbaseX == 0 || RbaseY == 0) || controller->r3){
RbaseX = controller->rstick_x;
RbaseY = controller->rstick_y;
}
inputs.rUp = (controller->rstick_y > RbaseY + 500) ? 1 : 0;
inputs.rDown = (controller->rstick_y < RbaseY - 500) ? 1 : 0;
inputs.rLeft = (controller->rstick_x < RbaseX - 500) ? 1 : 0;
inputs.rRight = (controller->rstick_x > RbaseX + 500) ? 1 : 0;
}
inputs.a = inputs.a || inputs.power;
return &inputs;
}
Input_t *hidWaitMask(u32 mask){
Input_t *in = hidRead();
while (in->buttons & mask)
hidRead();
while (!(in->buttons & mask)){
hidRead();
}
return in;
}
Input_t *hidWait(){
Input_t *in = hidRead();
while (in->buttons)
hidRead();
while (!(in->buttons))
hidRead();
return in;
}
bool hidConnected(){
jc_gamepad_rpt_t *controller = joycon_poll();
return (controller->conn_l && controller->conn_r) ? 1 : 0;
}

View File

@@ -0,0 +1,77 @@
#pragma once
#include <utils/types.h>
//#define BIT(n) (1U << n)
#define JoyY BIT(0)
#define JoyX BIT(1)
#define JoyB BIT(2)
#define JoyA BIT(3)
#define JoyRB BIT(6)
#define JoyMenu BIT(12)
#define JoyLDown BIT(16)
#define JoyLUp BIT(17)
#define JoyLRight BIT(18)
#define JoyLLeft BIT(19)
#define JoyLB BIT(22)
#define BtnPow BIT(24)
#define BtnVolP BIT(25)
#define BtnVolM BIT(26)
#define JoyRDown BIT(27)
#define JoyRUp BIT(28)
#define JoyRRight BIT(29)
#define JoyRLeft BIT(30)
#define WAITBUTTONS (JoyY | JoyX | JoyB | JoyA | JoyLDown | JoyLUp | JoyLRight | JoyLLeft)
typedef struct _inputs {
union {
struct {
// Joy-Con (R).
u32 y:1;
u32 x:1;
u32 b:1;
u32 a:1;
u32 sr_r:1;
u32 sl_r:1;
u32 r:1;
u32 zr:1;
// Shared
u32 minus:1;
u32 plus:1;
u32 r3:1;
u32 l3:1;
u32 home:1;
u32 cap:1;
u32 pad:1;
u32 wired:1;
// Joy-Con (L).
u32 down:1;
u32 up:1;
u32 right:1;
u32 left:1;
u32 sr_l:1;
u32 sl_l:1;
u32 l:1;
u32 zl:1;
u32 power:1;
u32 volp:1;
u32 volm:1;
u32 rDown:1;
u32 rUp:1;
u32 rRight:1;
u32 rLeft:1;
};
u32 buttons;
};
} Input_t;
void hidInit();
Input_t *hidRead();
Input_t *hidWait();
Input_t *hidWaitMask(u32 mask);
bool hidConnected();