add lib_dnr lib_roleswitch

This commit is contained in:
Steven Dan
2026-01-27 22:43:20 +08:00
parent ed84aad10d
commit c505cf84a9
8 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
module_roleswitch
*****************
scope:
General Use
description:
Roleswitch helper functions
keywords:
Apple, USB, roleswitch, MFI
boards:
XK-USB-AUDIO-U8-2C

View File

@@ -0,0 +1,11 @@
#define USB_IN_FLAG 0x11AA
#define COAX_IN_FLAG 0x22BB
#define OPT_IN_FLAG 0x33CC
#define UAC1_IN_FLAG 0x44DD
#define BT_IN_FLAG 0x55EE
#define I2S_IN_FLAG 0x66FF
void SetRoleSwitchFlag(unsigned flagVal);
unsigned GetRoleSwitchFlag();

View File

@@ -0,0 +1,6 @@
set(LIB_NAME lib_roleswitch)
set(LIB_VERSION 0.0.1)
set(LIB_INCLUDES include)
set(LIB_COMPILER_FLAGS -Os)
XMOS_REGISTER_MODULE()

View File

@@ -0,0 +1,22 @@
#if defined(__XS2A__)
/* Note range 0x7FFC8 - 0x7FFFF guarenteed to be untouched by tools */
#define FLAG_ADDRESS 0x7ffc8
#else
/* Note range 0xFFFC8 - 0xFFFFF guarenteed to be untouched by tools */
#define FLAG_ADDRESS 0xfffc8
#endif
/* Store Flag to fixed address */
void SetRoleSwitchFlag(unsigned x)
{
asm volatile("stw %0, %1[0]" :: "r"(x), "r"(FLAG_ADDRESS));
}
/* Load flag from fixed address */
unsigned GetRoleSwitchFlag()
{
unsigned x;
asm volatile("ldw %0, %1[0]" : "=r"(x) : "r"(FLAG_ADDRESS));
return x;
}