initial (partial) commit

This commit is contained in:
Shaun Inman 2023-01-01 21:48:35 -05:00
commit ec15d449e1
11 changed files with 2789 additions and 0 deletions

49
src/common/defines.h Normal file
View file

@ -0,0 +1,49 @@
#ifndef __DEFS_H__
#define __DEFS_H__
#define CODE_UP 0x5A
#define CODE_DOWN 0x5B
#define CODE_LEFT 0x5C
#define CODE_RIGHT 0x5D
#define CODE_A 0x5E
#define CODE_B 0x5F
#define CODE_X 0x60
#define CODE_Y 0x61
#define CODE_START 0x62
#define CODE_SELECT 0x63
#define CODE_L1 0x64
#define CODE_R1 0x65
#define CODE_L2 0x66
#define CODE_R2 0x67
#define CODE_MENU 0x68
#define CODE_VOL_UP 0x6C
#define CODE_VOL_DN 0x6D
#define CODE_POWER 0x74
#define VOLUME_MIN 0
#define VOLUME_MAX 20
#define BRIGHTNESS_MIN 0
#define BRIGHTNESS_MAX 10
#define SDCARD_PATH "/mnt/sdcard"
#define SYSTEM_PATH SDCARD_PATH "/.system/" PLATFORM
#define USERDATA_PATH SDCARD_PATH "/.userdata/" PLATFORM
#define MAX_PATH 512
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_DEPTH 16
#define SCREEN_PITCH 1280
#define SCREEN_BPP 2
#define SCREEN_BUFFER_COUNT 3
///////////////////////////////
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
#define MAX(a, b) (a) > (b) ? (a) : (b)
#define MIN(a, b) (a) < (b) ? (a) : (b)
#endif // __DEFS_H__

1041
src/common/scaler_neon.c Executable file

File diff suppressed because it is too large Load diff

54
src/common/scaler_neon.h Executable file
View file

@ -0,0 +1,54 @@
#ifndef __SCALER_NEON_H__
#define __SCALER_NEON_H__
#include <stdint.h>
//
// arm NEON / C integer scalers for miyoomini
// args/ src : src offset address of top left corner
// dst : dst offset address of top left corner
// sw : src width pixels
// sh : src height pixels
// sp : src pitch (stride) bytes if 0, (src width * [2|4]) is used
// dp : dst pitch (stride) bytes if 0, (src width * [2|4] * multiplier) is used
//
// ** NOTE **
// since 32bit aligned addresses need to be processed for NEON scalers,
// x-offset and stride pixels must be even# in the case of 16bpp,
// if odd#, then handled by the C scaler
//
typedef void (*scale_neon_t)(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
// NEON scalers
void scale1x_n16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale1x_n32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale2x_n16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale2x_n32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale3x_n16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale3x_n32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale4x_n16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale4x_n32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale5x_n16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale5x_n32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale6x_n16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale6x_n32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
// C scalers
void scale1x_c16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale1x_c32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale2x_c16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale2x_c32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale3x_c16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale3x_c32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale4x_c16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale4x_c32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
// c16b/c32b: faster when -Ofast/-O3 and aligned width, however dp must be 4xN
void scale4x_c16b(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale4x_c32b(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale5x_c16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale5x_c32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale6x_c16(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
void scale6x_c32(void* __restrict src, void* __restrict dst, uint32_t sw, uint32_t sh, uint32_t sp, uint32_t dp);
#endif

3
src/keymon/credits.txt Normal file
View file

@ -0,0 +1,3 @@
based on eggs custom keymon for Trimui:
https://www.dropbox.com/sh/5e9xwvp672vt8cr/AABUIdw1vLYp9h0waoCUqHPOa/source?dl=0&subfolder_nav_tracking=1
modified to use libmsettings

143
src/keymon/keymon.c Normal file
View file

@ -0,0 +1,143 @@
// miyoomini/keymon.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <msettings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include "defines.h"
// for ev.value
#define RELEASED 0
#define PRESSED 1
#define REPEAT 2
#define INPUT_COUNT 2
static int inputs[INPUT_COUNT];
static struct input_event ev;
static int jack_fd;
static pthread_t jack_pt;
// TODO: HDMI?
#define JACK_STATE_PATH "/sys/class/switch/h2w/state"
#define HDMI_STATE_PATH "/sys/class/switch/hdmi/state"
static void* watchJack(void *arg) {
uint32_t has_headphones;
uint32_t had_headphones;
FILE *file = fopen(JACK_STATE_PATH, "r");
fscanf(file, "%i", &has_headphones);
had_headphones = has_headphones;
SetJack(has_headphones);
while(1) {
sleep(1);
rewind(file);
fscanf(file, "%i", &has_headphones);
if (had_headphones!=has_headphones) {
had_headphones = has_headphones;
SetJack(has_headphones);
}
}
return 0;
}
int main (int argc, char *argv[]) {
InitSettings();
pthread_create(&jack_pt, NULL, &watchJack, NULL);
char path[32];
for (int i=0; i<INPUT_COUNT; i++) {
sprintf(path, "/dev/input/event%i", i);
inputs[i] = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
}
register uint32_t input;
register uint32_t val;
register uint32_t menu_pressed = 0;
register uint32_t power_pressed = 0;
uint32_t repeat_volume = 0;
// TODO: enable key repeat (not supported natively)
while (1) {
for (int i=0; i<INPUT_COUNT; i++) {
input = inputs[i];
while(read(input, &ev, sizeof(ev))==sizeof(ev)) {
val = ev.value;
if (( ev.type != EV_KEY ) || ( val > REPEAT )) continue;
switch (ev.code) {
case CODE_MENU:
if ( val != REPEAT ) menu_pressed = val;
break;
case CODE_POWER:
if ( val != REPEAT ) power_pressed = val;
break;
case CODE_VOL_DN:
if ( val == REPEAT ) {
// Adjust repeat speed to 1/2
val = repeat_volume;
repeat_volume ^= PRESSED;
} else {
repeat_volume = 0;
}
if ( val == PRESSED ) {
if (menu_pressed) {
val = GetBrightness();
if (val>BRIGHTNESS_MIN) SetBrightness(--val);
}
else {
val = GetVolume();
if (val>VOLUME_MIN) SetVolume(--val);
}
}
break;
case CODE_VOL_UP:
if ( val == REPEAT ) {
// Adjust repeat speed to 1/2
val = repeat_volume;
repeat_volume ^= PRESSED;
} else {
repeat_volume = 0;
}
if ( val == PRESSED ) {
if (menu_pressed) {
val = GetBrightness();
if (val<BRIGHTNESS_MAX) SetBrightness(++val);
}
else {
val = GetVolume();
if (val<VOLUME_MAX) SetVolume(++val);
}
}
break;
default:
break;
}
// TODO: not necessary, has reset button
// but the system call will be good for long-press shutdown
// if (menu_pressed && power_pressed) {
// menu_pressed = power_pressed = 0;
// // NOTE: we don't have access to a working reboot inside chroot
// // so use /proc/sysrq-trigger to (s)ync, (u)nmount, and then power (o)ff
// system("echo s > /proc/sysrq-trigger; echo u > /proc/sysrq-trigger; echo o > /proc/sysrq-trigger");
// while (1) pause();
// }
}
}
usleep(16666); // 60fps
}
}

14
src/keymon/makefile Executable file
View file

@ -0,0 +1,14 @@
ifeq (,$(CROSS_COMPILE))
$(error missing CROSS_COMPILE for this toolchain)
endif
TARGET = keymon.elf
CC = $(CROSS_COMPILE)gcc
CFLAGS = -Os -lmsettings -lpthread -lrt -ldl -Wl,--gc-sections -s
CFLAGS += -I. -I../common -DPLATFORM=\"$(UNION_PLATFORM)\"
all:
$(CC) keymon.c -o $(TARGET) $(CFLAGS)
clean:
rm -rf $(TARGET)

32
src/libmsettings/makefile Normal file
View file

@ -0,0 +1,32 @@
ifeq (,$(CROSS_COMPILE))
$(error missing CROSS_COMPILE for this toolchain)
endif
ifeq (,$(PREFIX))
$(error missing PREFIX for this toolchain)
endif
TARGET=msettings
.PHONY: build
.PHONY: clean
CC = $(CROSS_COMPILE)gcc
SYSROOT := $(shell $(CC) --print-sysroot)
INCLUDEDIR = $(SYSROOT)/usr/include
CFLAGS = -I$(INCLUDEDIR)
LDFLAGS = -ldl -lrt -s
OPTM=-Ofast
build:
$(CC) -c -Werror -fpic "$(TARGET).c" -Wl,--no-as-needed $(LDFLAGS)
$(CC) -shared -o "lib$(TARGET).so" "$(TARGET).o" $(LDFLAGS)
cp "$(TARGET).h" "$(PREFIX)/include"
cp "lib$(TARGET).so" "$(PREFIX)/lib"
clean:
rm -f *.o
rm -f "lib$(TARGET).so"
rm -f $(PREFIX)/include/$(TARGET).h
rm -f $(PREFIX)/lib/lib$(TARGET).so

View file

@ -0,0 +1,142 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <string.h>
#include "msettings.h"
///////////////////////////////////////
typedef struct Settings {
int version; // future proofing
int brightness;
int headphones;
int speaker;
int unused[3]; // for future use
int jack; // NOTE: doesn't really need to be persisted but still needs to be shared
} Settings;
static Settings DefaultSettings = {
.version = 1,
.brightness = 2,
.headphones = 4,
.speaker = 8,
.jack = 0,
};
static Settings* settings;
#define SHM_KEY "/SharedSettings"
// static char SettingsPath[256];
static char* SettingsPath = "/mnt/sdcard/.userdata/rg35xx/msettings.bin";
static int shm_fd = -1;
static int is_host = 0;
static int shm_size = sizeof(Settings);
void InitSettings(void) {
// sprintf(SettingsPath, "%s/msettings.bin", getenv("USERDATA_PATH"));
shm_fd = shm_open(SHM_KEY, O_RDWR | O_CREAT | O_EXCL, 0644); // see if it exists
if (shm_fd==-1 && errno==EEXIST) { // already exists
puts("Settings client");
shm_fd = shm_open(SHM_KEY, O_RDWR, 0644);
settings = mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
}
else { // host
puts("Settings host");
is_host = 1;
// we created it so set initial size and populate
ftruncate(shm_fd, shm_size);
settings = mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
int fd = open(SettingsPath, O_RDONLY);
if (fd>=0) {
read(fd, settings, shm_size);
// TODO: use settings->version for future proofing
close(fd);
}
else {
// load defaults
memcpy(settings, &DefaultSettings, shm_size);
}
}
printf("brightness: %i\nspeaker: %i \n", settings->brightness, settings->speaker);
SetVolume(GetVolume());
SetBrightness(GetBrightness());
}
void QuitSettings(void) {
munmap(settings, shm_size);
if (is_host) shm_unlink(SHM_KEY);
}
static inline void SaveSettings(void) {
int fd = open(SettingsPath, O_CREAT|O_WRONLY, 0644);
if (fd>=0) {
write(fd, settings, shm_size);
close(fd);
sync();
}
}
int GetBrightness(void) { // 0-10
return settings->brightness;
}
void SetBrightness(int value) {
int raw;
switch (value) {
case 0: raw=8; break;
case 1: raw=16; break;
case 2: raw=32; break;
case 3: raw=64; break;
case 4: raw=128; break;
case 5: raw=192; break;
case 6: raw=256; break;
case 7: raw=384; break;
case 8: raw=512; break;
case 9: raw=768; break;
case 10: raw=1024; break;
}
SetRawBrightness(raw);
settings->brightness = value;
SaveSettings();
}
int GetVolume(void) { // 0-20
return settings->jack ? settings->headphones : settings->speaker;
}
void SetVolume(int value) {
if (settings->jack) settings->headphones = value;
else settings->speaker = value;
int raw = value * 2;
SetRawVolume(raw);
SaveSettings();
}
void SetRawBrightness(int val) { // 0 - 1024
int fd = open("/sys/class/backlight/backlight.2/brightness", O_WRONLY);
if (fd>=0) {
dprintf(fd,"%d",val);
close(fd);
}
}
void SetRawVolume(int val) { // 0 - 40
int fd = open("/sys/class/volume/value", O_WRONLY);
if (fd>=0) {
dprintf(fd,"%d",val);
close(fd);
}
}
int GetJack(void) {
// return /sys/class/switch/h2w/state==1`
// access("/dev/dsp1", F_OK)==0
return settings->jack;
}
void SetJack(int value) { // monitored and set by thread in keymon
settings->jack = value;
SetVolume(GetVolume());
}

View file

@ -0,0 +1,19 @@
#ifndef __msettings_h__
#define __msettings_h__
void InitSettings(void);
void QuitSettings(void);
int GetBrightness(void);
int GetVolume(void);
void SetRawBrightness(int value); // 0-1024
void SetRawVolume(int value); // 0-40
void SetBrightness(int value); // 0-10
void SetVolume(int value); // 0-20
int GetJack(void);
void SetJack(int value); // 0-1
#endif // __msettings_h__

1277
src/minarch/main.c Normal file

File diff suppressed because it is too large Load diff

15
src/minarch/makefile Normal file
View file

@ -0,0 +1,15 @@
ifeq (,$(CROSS_COMPILE))
$(error missing CROSS_COMPILE for this toolchain)
endif
TARGET = minarch.elf
CC = $(CROSS_COMPILE)gcc
CFLAGS = -marm -mtune=cortex-a9 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -fomit-frame-pointer
CFLAGS += -I. -I../common -I./libretro-common/include -DPLATFORM=\"$(UNION_PLATFORM)\" -Ofast
LDFLAGS = -ldl -lSDL -lSDL_image -lSDL_ttf -lmsettings
all:
$(CC) main.c ../common/scaler_neon.c -o $(TARGET) $(CFLAGS) $(LDFLAGS)
clean:
rm -f $(TARGET)