Rockbox for the HiBy R3 Pro II/R1

Original author Melissa Autumn (https://codeberg.org/oopsallnaps/rockbox-hibyos) with contributions from Marc Aarts.

Adaptation to Rockbox standards by Marc Aarts

Change-Id: I09e5af7ba0a75c648e4b9fd424badc2d3665c943
This commit is contained in:
Marc Aarts 2025-12-22 08:11:25 +01:00 committed by Solomon Peachy
parent eee6c31b4a
commit 1183b1ab1b
118 changed files with 2858 additions and 107 deletions

View file

@ -156,6 +156,26 @@ target/hosted/lcd-linuxfb.c
target/hosted/power-linux.c
#endif
#if defined(HIBY_R3PROII) && !defined(SIMULATOR)
target/hosted/hiby/usb-hiby-gadget.c
target/hosted/hiby/r3proii/button-r3proii.c
target/hosted/hiby/r3proii/powermgmt-r3proii.c
#ifndef BOOTLOADER
target/hosted/hiby/r3proii/led-r3proii.c
target/hosted/hiby/hibylinux_codec.c
#endif
#endif
#if defined(HIBY_R1) && !defined(SIMULATOR)
target/hosted/hiby/usb-hiby-gadget.c
target/hosted/hiby/r1/button-r1.c
target/hosted/hiby/r1/powermgmt-r1.c
#ifndef BOOTLOADER
target/hosted/hiby/r1/led-r1.c
target/hosted/hiby/hibylinux_codec.c
#endif
#endif
#if defined(AGPTEK_ROCKER) && !defined(SIMULATOR)
target/hosted/agptek/button-agptek.c
target/hosted/agptek/debug-agptek.c
@ -184,10 +204,13 @@ target/hosted/xduoo/xduoolinux_codec.c
#endif
#if defined(HIBY_LINUX) && !defined(SIMULATOR)
target/hosted/usb-hiby.c
target/hosted/button-devinput.c
#endif
#if defined(HIBY_LINUX) && !defined(HIBY_R3PROII) && !defined(HIBY_R1) && !defined(SIMULATOR)
target/hosted/usb-hiby.c
#endif
#if defined(FIIO_M3K_LINUX) && !defined(SIMULATOR)
target/hosted/fiio/buttonlight-fiio.c
target/hosted/fiio/button-fiio.c

View file

@ -243,6 +243,8 @@ struct sound_settings_info
#include "erosqlinux_codec.h"
#elif defined(HAVE_TLV320AIC3104)
#include "tlv320aic3104_codec.h"
#elif defined(HAVE_HIBY_LINUX_CODEC)
#include "hibylinux_codec.h"
#endif
#if defined(HAVE_X1000_ICODEC_REC) && !defined(HAVE_X1000_ICODEC_PLAY)

View file

@ -166,6 +166,7 @@
#define SURFANS_F28_PAD 76
#define RG_NANO_PAD 77
#define CTRU_PAD 78
#define HIBY_R3PROII_PAD 79
/* CONFIG_REMOTE_KEYPAD */
#define H100_REMOTE 1
@ -618,6 +619,10 @@ Lyre prototype 1 */
#include "config/rgnano.h"
#elif defined(CTRU)
#include "config/ctru.h"
#elif defined(HIBY_R3PROII)
#include "config/hibyr3proii.h"
#elif defined(HIBY_R1)
#include "config/hibyr1.h"
#else
#error "unknown hardware platform!"
#endif

View file

@ -5,8 +5,10 @@
#ifndef SIMULATOR
#define CONFIG_PLATFORM (PLATFORM_HOSTED)
#ifndef PIVOT_ROOT
#define PIVOT_ROOT "/mnt/sd_0"
#endif
#endif
#define HAVE_FPU
@ -41,9 +43,13 @@
#define CONFIG_LCD LCD_INGENIC_LINUX
#ifndef LCD_DEPTH
#define LCD_DEPTH 32
#endif
#ifndef LCD_PIXELFORMAT
/* Check that but should not matter */
#define LCD_PIXELFORMAT XRGB8888
#endif
#define HAVE_BACKLIGHT
#define HAVE_BACKLIGHT_BRIGHTNESS
@ -51,13 +57,23 @@
/* Main LCD backlight brightness range and defaults: the backlight driver
* has levels from 0 to 255. But 0 is off so start at 1.
*/
#ifndef MIN_BRIGHTNESS_SETTING
#define MIN_BRIGHTNESS_SETTING 1
#endif
#ifndef MAX_BRIGHTNESS_SETTING
#define MAX_BRIGHTNESS_SETTING 255
#endif
#ifndef BRIGHTNESS_STEP
#define BRIGHTNESS_STEP 5
#endif
#ifndef DEFAULT_BRIGHTNESS_SETTING
#define DEFAULT_BRIGHTNESS_SETTING 255
#endif
/* Which backlight fading type? */
#if !defined(CONFIG_BACKLIGHT_FADING)
#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
#endif
/* define this if you have a real-time clock */
#define CONFIG_RTC RTC_HOSTED
@ -81,12 +97,18 @@
#define NUM_DRIVES 2
#define HAVE_HOTSWAP
#define HAVE_HOTSWAP_STORAGE_AS_MAIN
#ifndef MULTIDRIVE_DIR
#define MULTIDRIVE_DIR "/mnt/usb"
#endif
#define MULTIDRIVE_DEV "/sys/block/sda"
#define ROOTDRIVE_DEV "/sys/block/mmcblk0"
/* More common stuff */
#ifndef BATTERY_DEV_NAME
#ifndef EROS_Q
#define BATTERY_DEV_NAME "battery"
#endif
#endif
#ifndef POWER_DEV_NAME
#define POWER_DEV_NAME "usb"
#endif

View file

@ -0,0 +1,90 @@
/*
* This config file is for the HiBy R1
*/
/* For Rolo and boot loader */
#define MODEL_NUMBER 124
#define MODEL_NAME "HIBY R1"
#define PIVOT_ROOT "/data/mnt/sd_0"
#define MULTIDRIVE_DIR "/data/mnt/usb"
/* LCD dimensions */
/* sqrt(width^2 + height^2) / 4 = 233 */
#define LCD_WIDTH 480
#define LCD_HEIGHT 800
#define LCD_DPI 233
#define HAVE_LCD_SLEEP
#define LCD_SLEEP_TIMEOUT (2*HZ)
#define LCD_DEPTH 16 /* 65536 colours */
#define LCD_PIXELFORMAT RGB565 /* rgb565 */
#define CPU_FREQ 1008000000
#ifndef SIMULATOR
#define HAVE_GENERAL_PURPOSE_LED
#endif
/* define this if you have access to the quickscreen */
#define HAVE_QUICKSCREEN
#define HAVE_HOTKEY
#define HAVE_HEADPHONE_DETECTION
#define NO_BUTTON_LR
#ifndef BOOTLOADER
#define HAVE_BUTTON_DATA
#define HAVE_TOUCHSCREEN
#endif
#ifndef CONFIG_BACKLIGHT_FADING
#undef CONFIG_BACKLIGHT_FADING
#endif
/* KeyPad configuration for plugins */
#define CONFIG_KEYPAD HIBY_R3PROII_PAD
/* define this if the target has volume keys which can be used in the lists */
#define HAVE_VOLUME_IN_LIST
/* Battery */
#define BATTERY_TYPES_COUNT 1
/* Audio codec */
#define HAVE_HIBY_LINUX_CODEC
/* We don't have hardware controls */
#define HAVE_SW_TONE_CONTROLS
/* HW codec is flexible */
#define HW_SAMPR_CAPS SAMPR_CAP_ALL_192
/* Battery */
#define CONFIG_BATTERY_MEASURE (VOLTAGE_MEASURE|PERCENTAGE_MEASURE|TIME_MEASURE)
#define BATTERY_CAPACITY_DEFAULT 100 /* default battery capacity */
#define BATTERY_CAPACITY_MIN 100 /* min. capacity selectable */
#define BATTERY_CAPACITY_MAX 100 /* max. capacity selectable */
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
/* Special backlight paths */
#define BACKLIGHT_HIBY
#define MIN_BRIGHTNESS_SETTING 1
#define MAX_BRIGHTNESS_SETTING 100
#define BRIGHTNESS_STEP 5
#define DEFAULT_BRIGHTNESS_SETTING 100
/* ROLO */
#define BOOTFILE_EXT "r1"
#define BOOTFILE "rockbox." BOOTFILE_EXT
#define BOOTDIR "/.rockbox"
/* USB */
#define USB_VID_STR "32BB"
#define USB_PID_STR "0101"
/* Generic HiBy stuff */
#include "hibylinux.h"

View file

@ -0,0 +1,94 @@
/*
* This config file is for the HiBy R3 Pro II based on the x1600E soc
*/
/* For Rolo and boot loader */
#define MODEL_NUMBER 123
#define MODEL_NAME "HIBY R3 PRO II"
#define PIVOT_ROOT "/data/mnt/sd_0"
#define MULTIDRIVE_DIR "/data/mnt/usb"
/* LCD dimensions */
/* sqrt(width^2 + height^2) / 4 = 216 */
#define LCD_WIDTH 480
#define LCD_HEIGHT 720
#define LCD_DPI 216
#define HAVE_LCD_SLEEP
#define LCD_SLEEP_TIMEOUT (2*HZ)
#define LCD_DEPTH 16 /* 65536 colours */
#define LCD_PIXELFORMAT RGB565 /* rgb565 */
#define CPU_FREQ 1008000000
#ifndef SIMULATOR
#define HAVE_GENERAL_PURPOSE_LED
#endif
/* define this if you have access to the quickscreen */
#define HAVE_QUICKSCREEN
#define HAVE_HOTKEY
#define HAVE_HEADPHONE_DETECTION
#define NO_BUTTON_LR
#ifndef BOOTLOADER
#define HAVE_BUTTON_DATA
#define HAVE_TOUCHSCREEN
#endif
#ifndef CONFIG_BACKLIGHT_FADING
#undef CONFIG_BACKLIGHT_FADING
#endif
/* KeyPad configuration for plugins */
#define CONFIG_KEYPAD HIBY_R3PROII_PAD
/* define this if the target has volume keys which can be used in the lists */
#define HAVE_VOLUME_IN_LIST
/* Battery doesn't update its charging status, but the charger does. */
#define POWER_DEV_NAME "mp2731-charger"
#define BATTERY_DEV_NAME "mp2731-charger"
/* Battery */
#define BATTERY_TYPES_COUNT 1
/* Audio codec */
#define HAVE_HIBY_LINUX_CODEC
/* We don't have hardware controls */
#define HAVE_SW_TONE_CONTROLS
/* HW codec is flexible */
#define HW_SAMPR_CAPS SAMPR_CAP_ALL_192
/* Battery */
#define CONFIG_BATTERY_MEASURE (VOLTAGE_MEASURE|PERCENTAGE_MEASURE|TIME_MEASURE)
#define BATTERY_CAPACITY_DEFAULT 100 /* default battery capacity */
#define BATTERY_CAPACITY_MIN 100 /* min. capacity selectable */
#define BATTERY_CAPACITY_MAX 100 /* max. capacity selectable */
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
/* Special backlight paths */
#define BACKLIGHT_HIBY
#define MIN_BRIGHTNESS_SETTING 1
#define MAX_BRIGHTNESS_SETTING 100
#define BRIGHTNESS_STEP 5
#define DEFAULT_BRIGHTNESS_SETTING 100
/* ROLO */
#define BOOTFILE_EXT "r3proii"
#define BOOTFILE "rockbox." BOOTFILE_EXT
#define BOOTDIR "/.rockbox"
/* USB */
#define USB_VID_STR "32BB"
#define USB_PID_STR "0101"
/* Generic HiBy stuff */
#include "hibylinux.h"

View file

@ -0,0 +1,17 @@
#ifndef __HIBYLINUX_CODEC__
#define __HIBYLINUX_CODEC__
#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP)
AUDIOHW_SETTING(VOLUME, "dB", 1, 5, -102*10, 0, -30*10)
#endif
//#define AUDIOHW_MUTE_ON_STOP
#define AUDIOHW_MUTE_ON_SRATE_CHANGE
//#define AUDIOHW_NEEDS_INITIAL_UNMUTE
AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0)
#define AUDIOHW_HAVE_SHORT2_ROLL_OFF
void audiohw_mute(int mute);
void hiby_set_output(int ps);
int hiby_get_outputs(void);

View file

@ -0,0 +1,35 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __LED_GENERAL_PURPOSE_H__
#define __LED_GENERAL_PURPOSE_H__
#ifdef HAVE_GENERAL_PURPOSE_LED
extern void led_hw_set_mode(bool mode);
extern void led_hw_brightness(int brightness);
extern void led_hw_on(void);
extern void led_hw_off(void);
extern void led_hw_charging(void);
extern void led_hw_charged(void);
#endif /* HAVE_GENERAL_PURPOSE_LED */
#endif

View file

@ -87,7 +87,8 @@
#if defined(APPLICATION) && \
!(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(CTRU))
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(CTRU))
#define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data"
#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR

View file

@ -76,9 +76,14 @@
#define IS_SYSEVENT(ev) ((ev & SYS_EVENT) == SYS_EVENT)
#define MAX_NUM_QUEUES 32
#if defined(HAVE_TOUCHSCREEN) /* Multitouch generates more events */
#define QUEUE_LENGTH 32 /* MUST be a power of 2 */
#else
#define QUEUE_LENGTH 16 /* MUST be a power of 2 */
#endif
#define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1)
struct queue_event
{
long id;

View file

@ -8,6 +8,7 @@
*
* Copyright (C) 2017 Marcin Bukat
* Copyright (C) 2019 by Roman Stolyarov
* Copyright (C) 2025 by Melissa Autumn
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -31,12 +32,18 @@
#include "panic.h"
#include "lcd.h"
#ifdef BACKLIGHT_RG_NANO
#if defined(BACKLIGHT_RG_NANO)
static const char * const sysfs_bl_brightness =
"/sys/class/backlight/backlight/brightness";
static const char * const sysfs_bl_power =
"/sys/class/backlight/backlight/bl_power";
#elif defined(BACKLIGHT_HIBY)
static const char * const sysfs_bl_brightness =
"/sys/class/backlight/backlight_pwm0/brightness";
static const char * const sysfs_bl_power =
"/sys/class/backlight/backlight_pwm0/bl_power";
#else
static const char * const sysfs_bl_brightness =
"/sys/class/backlight/pwm-backlight.0/brightness";
@ -60,25 +67,30 @@ bool backlight_hw_init(void)
static int last_bl = -1;
/* Ref: https://www.kernel.org/doc/html/latest/gpu/backlight.html#c.backlight_properties */
#define BACKLIGHT_POWER_ON 0
#define BACKLIGHT_POWER_REDUCED 1
#define BACKLIGHT_POWER_OFF 4
void backlight_hw_on(void)
{
if (last_bl != 1) {
if (last_bl != BACKLIGHT_POWER_ON) {
#ifdef HAVE_LCD_ENABLE
lcd_enable(true);
#endif
sysfs_set_int(sysfs_bl_power, 0);
last_bl = 1;
last_bl = BACKLIGHT_POWER_ON;
sysfs_set_int(sysfs_bl_power, last_bl);
}
}
void backlight_hw_off(void)
{
if (last_bl != 0) {
sysfs_set_int(sysfs_bl_power, 1);
if (last_bl != BACKLIGHT_POWER_REDUCED) {
last_bl = BACKLIGHT_POWER_REDUCED;
sysfs_set_int(sysfs_bl_power, last_bl);
#ifdef HAVE_LCD_ENABLE
lcd_enable(false);
#endif
last_bl = 0;
}
}
@ -92,3 +104,21 @@ void backlight_hw_brightness(int brightness)
sysfs_set_int(sysfs_bl_brightness, brightness);
}
#ifdef HAVE_LCD_SLEEP
void lcd_awake(void)
{
/* Nothing to do */
}
void lcd_sleep(void)
{
if (last_bl != BACKLIGHT_POWER_OFF) {
last_bl = BACKLIGHT_POWER_OFF;
sysfs_set_int(sysfs_bl_power, last_bl);
#ifdef HAVE_LCD_ENABLE
lcd_enable(false);
#endif
}
}
#endif

View file

@ -109,27 +109,21 @@ static enum
#define EVENT_VALUE_TOUCHSCREEN_PRESS 1
#define EVENT_VALUE_TOUCHSCREEN_RELEASE -1
static int ts_enabled = 0;
static int ts_enabled = 1;
void touchscreen_enable_device(bool en)
{
ts_enabled = en;
}
static bool handle_touchscreen_event(__u16 code, __s32 value)
static void handle_touchscreen_event(__u16 code, __s32 value)
{
bool read_more = false;
switch(code)
{
case ABS_X:
case ABS_MT_POSITION_X:
{
_last_x = value;
/* x -> next will be y. */
read_more = true;
break;
}
@ -142,22 +136,17 @@ static bool handle_touchscreen_event(__u16 code, __s32 value)
case ABS_MT_TRACKING_ID:
{
if(value == EVENT_VALUE_TOUCHSCREEN_PRESS)
if(value == EVENT_VALUE_TOUCHSCREEN_RELEASE)
{
_last_touch_state = TOUCHSCREEN_STATE_DOWN;
/* Press -> next will be x. */
read_more = true;
_last_touch_state = TOUCHSCREEN_STATE_UP;
}
else
{
_last_touch_state = TOUCHSCREEN_STATE_UP;
_last_touch_state = TOUCHSCREEN_STATE_DOWN;
}
break;
}
}
return read_more;
}
#endif
@ -227,7 +216,7 @@ int button_read_device(BDATA)
#if defined(HAVE_TOUCHSCREEN) && defined(BUTTON_TOUCH)
/* Some touchscreens give us actual touch/untouch as a "key" */
if (bmap & BUTTON_TOUCH) {
handle_touchscreen_event(ABS_MT_TRACKING_ID, 0);
handle_touchscreen_event(ABS_MT_TRACKING_ID, EVENT_VALUE_TOUCHSCREEN_RELEASE);
bmap &= ~BUTTON_TOUCH;
}
#endif

View file

View file

@ -0,0 +1,158 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
*
* Copyright (c) 2018 Marcin Bukat
* Copyright (c) 2025 Solomon Peachy
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
//#define LOGF_ENABLE
#include "config.h"
#include "audio.h"
#include "audiohw.h"
#include "button.h"
#include "system.h"
#include "kernel.h"
#include "panic.h"
#include "sysfs.h"
#include "alsa-controls.h"
#include "pcm-alsa.h"
#include "logf.h"
int hiby_has_valid_output(void);
static int hw_init = 0;
static long int vol_l_hw = 255;
static long int vol_r_hw = 255;
static long int last_ps = -1;
static int muted = -1;
void audiohw_mute(int mute)
{
if (hw_init < 0 || muted == mute)
return;
muted = mute;
alsa_controls_set_bool("Mute Output", !!mute);
}
int hiby_has_valid_output(void) {
long int ps = 0; // Muted, if nothing is plugged in!
int status = 0;
if (!hw_init) return ps;
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
sysfs_get_int(sysfs_hs_switch, &status);
if (status) ps = 2; // headset
sysfs_get_int(sysfs_bal_switch, &status);
if (status) ps = 3; // balanced output
return ps;
}
int hiby_get_outputs(void){
long int ps = hiby_has_valid_output();
hiby_set_output(ps);
return ps;
}
void hiby_set_output(int ps)
{
if (!hw_init || muted) return;
if (last_ps != ps)
{
logf("set out %d/%d", ps, last_ps);
/* Output port switch */
last_ps = ps;
alsa_controls_set_ints("Output Port Switch", 1, &last_ps);
audiohw_set_volume(vol_l_hw, vol_r_hw);
}
}
void audiohw_preinit(void)
{
logf("hw preinit");
alsa_controls_init("default");
hw_init = 1;
audiohw_mute(false); /* No need ? */
alsa_controls_set_bool("DOP_EN", 0); //isDSD
}
void audiohw_postinit(void)
{
logf("hw postinit");
}
void audiohw_close(void)
{
logf("hw close");
hw_init = 0;
alsa_controls_close();
}
void audiohw_set_frequency(int fsel)
{
(void)fsel;
}
void audiohw_set_volume(int vol_l, int vol_r)
{
logf("hw vol %d %d", vol_l, vol_r);
long l,r;
vol_l_hw = vol_l;
vol_r_hw = vol_r;
l = -vol_l/5;
r = -vol_r/5;
if (!hw_init)
return;
alsa_controls_set_ints("Left Playback Volume", 1, &l);
alsa_controls_set_ints("Right Playback Volume", 1, &r);
}
void audiohw_set_filter_roll_off(int value)
{
logf("rolloff %d", value);
/* 0 = Sharp;
* 1 = Slow;
* 2 = Short Sharp
* 3 = Short Slow
* 4 = Super Slow */
long int value_hw = value;
alsa_controls_set_ints("Digital Filter", 1, &value_hw);
}

View file

@ -0,0 +1,32 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2016 Amaury Pouly
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __LCD_TARGET_H__
#define __LCD_TARGET_H__
/* hibyos needs special ioctl() to redraw updated framebuffer content */
#define LCD_OPTIMIZED_UPDATE
#define LCD_OPTIMIZED_UPDATE_RECT
extern fb_data *framebuffer;
#define LCD_FRAMEBUF_ADDR(col, row) (framebuffer + (row)*LCD_WIDTH + (col))
extern void lcd_set_active(bool active);
#endif /* __LCD_TARGET_H__ */

View file

@ -0,0 +1,81 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2017 Marcin Bukat
* Copyright (C) 2025 by Melissa Autumn/Marc Aarts
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <linux/input.h>
#include "sysfs.h"
#include "button.h"
#include "button-target.h"
#include "hibylinux_codec.h"
#include "touchscreen.h"
#ifdef HAVE_BACKLIGHT
#include "backlight.h"
#endif /* HAVE_BACKLIGHT */
/*
* /dev/input/event0: md-gpio-keys (power/next)
* /dev/input/event1: hyn_ts (touchscreen)
* /dev/input/event2: jz adc keyboard (play/volume+/volume-)
* /dev/input/event3: earpods_adc
*/
int button_map(int keycode)
{
switch(keycode)
{
case KEY_VOLUMEDOWN:
return BUTTON_VOL_DOWN;
case KEY_VOLUMEUP:
return BUTTON_VOL_UP;
case KEY_PLAYPAUSE:
return BUTTON_PLAY;
case KEY_NEXTSONG:
return BUTTON_NEXT;
case KEY_PREVIOUSSONG:
return BUTTON_PREV;
case KEY_POWER:
return BUTTON_POWER;
case BTN_TOUCH:
{
#ifdef HAVE_BACKLIGHT
if (is_backlight_on(true)) {
return BUTTON_TOUCH;
}
// Ignore
return 0;
#else
return BUTTON_TOUCH
#endif
}
default:
return 0;
}
}
bool headphones_inserted(void)
{
#ifdef BOOTLOADER
int ps = 0;
#else
int ps = hiby_get_outputs();
#endif
return (ps == 2);
}

View file

@ -0,0 +1,60 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _BUTTON_TARGET_H_
#define _BUTTON_TARGET_H_
#include <stdbool.h>
#include "config.h"
/* Main unit's buttons */
#define BUTTON_POWER 0x00000001
#define BUTTON_PREV 0x00000002 /* there is no PREV */
#define BUTTON_NEXT 0x00000004
#define BUTTON_PLAY 0x00000008
#define BUTTON_VOL_UP 0x00000010
#define BUTTON_VOL_DOWN 0x00000020
#define BUTTON_MAIN 0x0000003f
#define BUTTON_TOUCH 0x00000040
/* Touchscreen virtual buttons */
#define BUTTON_TOPLEFT 0x00001000
#define BUTTON_TOPMIDDLE 0x00002000
#define BUTTON_TOPRIGHT 0x00004000
#define BUTTON_MIDLEFT 0x00008000
#define BUTTON_CENTER 0x00010000
#define BUTTON_MIDRIGHT 0x00020000
#define BUTTON_BOTTOMLEFT 0x00040000
#define BUTTON_BOTTOMMIDDLE 0x00080000
#define BUTTON_BOTTOMRIGHT 0x00100000
/* Software power-off */
#define POWEROFF_BUTTON BUTTON_POWER
#define POWEROFF_COUNT 25
/* For the simulator/sdl plugins/xworld */
#ifndef BOOTLOADER
#define BUTTON_LEFT BUTTON_NEXT
#define BUTTON_RIGHT BUTTON_PREV
#endif
int button_map(int keycode);
#endif /* _BUTTON_TARGET_H_ */

View file

@ -0,0 +1,140 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "config.h"
#include "backlight-target.h"
#include "sysfs.h"
#include "panic.h"
#include "lcd.h"
#include "settings.h"
#include "power.h"
static const char * const sysfs_blue_led =
"/sys/class/leds/blue/brightness";
static const char * const sysfs_red_led =
"/sys/class/leds/red/brightness";
static const char * const sysfs_red_trigger =
"/sys/class/leds/red/trigger";
/* Ref: https://guide.hiby.com/en/docs/products/audio_player/hiby_r1/guide#led-indicator
Note: The red breathing effect seems to be just the "breathing" led trigger.
By default red is turned off and blue is set to 50 brightness.
*/
enum R1_LEDS {
LED_INVALID = -1,
LED_OFF = 0,
LED_BLUE,
LED_RED,
};
#define DEFAULT_BRIGHTNESS 50
int _last_brightness = DEFAULT_BRIGHTNESS;
int _last_led = LED_INVALID;
void _set_led(enum R1_LEDS led) {
if (_last_led != led) {
_last_led = led;
if (_last_brightness == 0) {
_last_brightness = DEFAULT_BRIGHTNESS;
}
switch(led) {
case LED_OFF:
sysfs_set_int(sysfs_blue_led, 0);
sysfs_set_int(sysfs_red_led, 0);
break;
case LED_BLUE:
sysfs_set_int(sysfs_blue_led, _last_brightness);
sysfs_set_int(sysfs_red_led, 0);
break;
case LED_RED:
sysfs_set_int(sysfs_blue_led, 0);
sysfs_set_int(sysfs_red_led, _last_brightness);
sysfs_set_string(sysfs_red_trigger, "breathing");
break;
default:
break;
}
}
}
#ifdef HAVE_GENERAL_PURPOSE_LED
void led_hw_brightness(int brightness)
{
if (brightness != _last_brightness) {
_last_brightness = brightness;
_set_led(_last_led);
}
}
void led_hw_charged(void)
{
if (global_settings.use_led_indicators) {
_set_led(LED_BLUE);
}
}
void led_hw_charging(void)
{
_set_led(LED_RED);
}
void led_hw_off(void)
{
// Don't turn off led if charging
if (!charging_state()) {
_set_led(LED_OFF);
}
}
void led_hw_on(void)
{
if (charging_state()) {
led_hw_charging();
} else {
if (global_settings.use_led_indicators) {
_set_led(LED_BLUE);
}
else {
led_hw_off();
}
}
}
void led_hw_set_mode(bool mode)
{
if (mode) {
led_hw_on();
}
else {
led_hw_off();
}
}
#endif

View file

@ -0,0 +1,39 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2017 Marcin Bukat
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "powermgmt.h"
#include "power.h"
unsigned short battery_level_disksafe = 3470;
/* the OF shuts down at this voltage */
unsigned short battery_level_shutoff = 3400;
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
unsigned short percent_to_volt_discharge[11] =
{
3400, 3675, 3715, 3750, 3775, 3810, 3850, 4028, 4125, 4237, 4376
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
unsigned short percent_to_volt_charge[11] =
{
3485, 3780, 3836, 3857, 3890, 3930, 3986, 4028, 4125, 4237, 4376
};

View file

@ -0,0 +1,81 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2017 Marcin Bukat
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <linux/input.h>
#include "sysfs.h"
#include "button.h"
#include "button-target.h"
#include "hibylinux_codec.h"
#include "touchscreen.h"
#ifdef HAVE_BACKLIGHT
#include "backlight.h"
#endif /* HAVE_BACKLIGHT */
/*
* /dev/input/event0: gpios (power/next)
* /dev/input/event1: touchscreen
* /dev/input/event2: adc (prev/play/left/right)
* /dev/input/event3: ????
*/
int button_map(int keycode)
{
switch(keycode)
{
case KEY_VOLUMEDOWN:
return BUTTON_VOL_DOWN;
case KEY_VOLUMEUP:
return BUTTON_VOL_UP;
case KEY_PLAYPAUSE:
return BUTTON_PLAY;
case KEY_NEXTSONG:
return BUTTON_NEXT;
case KEY_PREVIOUSSONG:
return BUTTON_PREV;
case KEY_POWER:
return BUTTON_POWER;
case BTN_TOUCH:
{
#ifdef HAVE_BACKLIGHT
if (is_backlight_on(true)) {
return BUTTON_TOUCH;
}
// Ignore
return 0;
#else
return BUTTON_TOUCH
#endif
}
default:
return 0;
}
}
bool headphones_inserted(void)
{
#ifdef BOOTLOADER
int ps = 0;
#else
int ps = hiby_get_outputs();
#endif
return (ps == 2 || ps == 3);
}

View file

@ -0,0 +1,60 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _BUTTON_TARGET_H_
#define _BUTTON_TARGET_H_
#include <stdbool.h>
#include "config.h"
/* Main unit's buttons */
#define BUTTON_POWER 0x00000001
#define BUTTON_PREV 0x00000002
#define BUTTON_NEXT 0x00000004
#define BUTTON_PLAY 0x00000008
#define BUTTON_VOL_UP 0x00000010
#define BUTTON_VOL_DOWN 0x00000020
#define BUTTON_MAIN 0x0000003f
#define BUTTON_TOUCH 0x00000040
/* Touchscreen virtual buttons */
#define BUTTON_TOPLEFT 0x00001000
#define BUTTON_TOPMIDDLE 0x00002000
#define BUTTON_TOPRIGHT 0x00004000
#define BUTTON_MIDLEFT 0x00008000
#define BUTTON_CENTER 0x00010000
#define BUTTON_MIDRIGHT 0x00020000
#define BUTTON_BOTTOMLEFT 0x00040000
#define BUTTON_BOTTOMMIDDLE 0x00080000
#define BUTTON_BOTTOMRIGHT 0x00100000
/* Software power-off */
#define POWEROFF_BUTTON BUTTON_POWER
#define POWEROFF_COUNT 25
/* For the simulator/sdl plugins/xworld */
#ifndef BOOTLOADER
#define BUTTON_LEFT BUTTON_NEXT
#define BUTTON_RIGHT BUTTON_PREV
#endif
int button_map(int keycode);
#endif /* _BUTTON_TARGET_H_ */

View file

@ -0,0 +1,132 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "config.h"
#include "backlight-target.h"
#include "sysfs.h"
#include "panic.h"
#include "lcd.h"
#include "settings.h"
#include "power.h"
static const char * const sysfs_led_type =
"/sys/class/leds/sgm31324-leds/led_pattern";
/* Ref: https://guide.hiby.com/en/docs/products/audio_player/hiby_r3proii/guide#led-indicator-light
Defined in leds_sgm31324_add.sh (off is defined in driver)
...
echo regs="00000000540001010706" > sgm31324
echo regs="000000004500380B0000" > sgm31324
echo regs="00000000540000060600" > sgm31324
echo regs="00000000450040040000" > sgm31324
echo regs="00000000000000000006" > sgm31324
echo regs="001E7D0042BB2F000006" > sgm31324
echo regs="000E7D0042663F000006" > sgm31324
echo regs="00000000440000050006" > sgm31324
echo regs="00000000540000000D06" > sgm31324
echo regs="0000000051001C000506" > sgm31324
echo regs="00000000000000000006" > sgm31324
...
*/
enum R3PROII_LED_PATTERNS {
LED_PATTERN_INVALID = -1,
LED_PATTERN_OFF = 0,
LED_PATTERN_LIGHT_BLUE,
LED_PATTERN_YELLOW,
LED_PATTERN_CYAN,
LED_PATTERN_ORANGE,
LED_PATTERN_UNK_1, /* This might do something, but it seems to just be off */
LED_PATTERN_NORMAL_RED_BLINK,
LED_PATTERN_FAST_RED_BLINK,
LED_PATTERN_GREEN,
LED_PATTERN_BLUE, /* A slightly more blue blue */
LED_PATTERN_PINK,
LED_PATTERN_WHITE,
};
int _last_buttonlight = LED_PATTERN_INVALID;
void _set_pattern(enum R3PROII_LED_PATTERNS pattern) {
if (_last_buttonlight != pattern) {
_last_buttonlight = pattern;
sysfs_set_int(sysfs_led_type, _last_buttonlight);
}
}
#ifdef HAVE_GENERAL_PURPOSE_LED
void led_hw_brightness(int brightness)
{
(void)brightness;
}
void led_hw_charged(void)
{
if (global_settings.use_led_indicators) {
_set_pattern(LED_PATTERN_GREEN);
}
}
void led_hw_charging(void)
{
_set_pattern(LED_PATTERN_NORMAL_RED_BLINK);
}
void led_hw_off(void)
{
// Don't turn off led if charging
if (_last_buttonlight != LED_PATTERN_NORMAL_RED_BLINK) {
_set_pattern(LED_PATTERN_OFF);
}
}
void led_hw_on(void)
{
if (charging_state()) {
led_hw_charging();
} else {
if (global_settings.use_led_indicators) {
_set_pattern(LED_PATTERN_LIGHT_BLUE);
}
else {
led_hw_off();
}
}
}
void led_hw_set_mode(bool mode)
{
if (mode) {
led_hw_on();
}
else {
led_hw_off();
}
}
#endif

View file

@ -0,0 +1,42 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2017 Marcin Bukat
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "powermgmt.h"
#include "power.h"
/* FIXME: Haven't adjusted these values besides max voltage */
// max voltage is 4370
unsigned short battery_level_disksafe = 3470;
/* the OF shuts down at this voltage */
unsigned short battery_level_shutoff = 3400;
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
unsigned short percent_to_volt_discharge[11] =
{
3400, 3675, 3715, 3750, 3775, 3810, 3850, 4028, 4125, 4237, 4376
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
unsigned short percent_to_volt_charge[11] =
{
3485, 3780, 3836, 3857, 3890, 3930, 3986, 4028, 4125, 4237, 4376
};

View file

@ -0,0 +1,29 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2017 Marcin Bukat
* Copyright (C) 2016 Amaury Pouly
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __SYSTEM_TARGET_H__
#define __SYSTEM_TARGET_H__
#include "kernel-unix.h"
#include "system-hosted.h"
#define NEED_GENERIC_BYTESWAPS
#endif /* __SYSTEM_TARGET_H__ */

View file

@ -0,0 +1,323 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2018 by Marcin Bukat
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <dirent.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "dir.h"
#include "disk.h"
#include "usb.h"
#include "sysfs.h"
#include "power.h"
#include "usb-hiby-gadget.h"
#ifdef HAVE_GENERAL_PURPOSE_LED
#include "led-general-purpose.h"
#endif
#define LOGF_ENABLE
#include "logf.h"
#include <stdio.h>
static int _usb_mode = -1;
static bool _usb_init = false;
static bool is_adb_running = false;
void enable_adb(void);
void enable_mass_storage(void);
void enable_charging(void);
void enable_usb_audio(void);
void disable_adb(void);
void disable_mass_storage(void);
void disable_usb_audio(void);
#ifdef HAVE_MULTIDRIVE
void cleanup_rbhome(void);
void startup_rbhome(void);
#endif
void hiby_set_usb_mode(int mode) {
logf(">>>>>>>>>>>>>>>>> hiby_set_usb_mode(%d)\n", mode);
if (!_usb_init) {
logf("Need to init usb!\n");
usb_init_device();
}
switch(mode) {
case USB_MODE_MASS_STORAGE:
logf("Enabling Mass Storage\n");
enable_mass_storage();
break;
case USB_MODE_CHARGE:
logf("Enabling Charge\n");
enable_charging();
break;
default:
break;
}
_usb_mode = mode;
}
/* TODO: implement usb detection properly */
int usb_detect(void)
{
#ifdef HAVE_GENERAL_PURPOSE_LED
led_hw_on();
#endif
return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
{
logf(">>>>>>>>>>>>>>>>> usb_enable(%d)\n", on);
logf("usb enable %d %d\n", on, _usb_mode);
/* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell
* without entering ums mode
*/
//if (_usb_mode != USB_MODE_ADB) {
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/UDC", on ? "13500000.otg_new" : "");
//}
}
/* This is called by usb thread after usb extract in order to return
* regular FS access
*
* returns the # of successful mounts
*/
int disk_mount_all(void)
{
logf(">>>>>>>>>>>>>>>>> disk_mount_all()\n");
#ifdef HAVE_MULTIDRIVE
startup_rbhome();
#endif
return 1;
}
/* This is called by usb thread after all threads ACKs usb inserted message
*
* returns the # of successful unmounts
*/
int disk_unmount_all(void)
{
// We're always mounted as rockbox lives on the sdcard
logf(">>>>>>>>>>>>>>>>> disk_unmount_all()\n");
#ifdef HAVE_MULTIDRIVE
cleanup_rbhome();
#endif
#ifdef HAVE_MULTIDRIVE
startup_rbhome();
#endif
return 1;
}
void enable_charging(void) {
logf(">>>>>>>>>>>>>>>>> enable_charging()\n");
disable_mass_storage();
disable_adb();
}
#if 1
void enable_adb(void) {
logf(">>>>>>>>>>>>>>>>> set_adb()\n");
// Disable mass storage if it was running
disable_mass_storage();
// Remove any lingering adb daemon
system("killall -9 adbd");
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409");
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo/functions/ffs.adb");
// Now we'll override configuration and MaxPower
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", "adb");
sysfs_set_int("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/MaxPower", 120);
// And link up the adb function to the usb gadget config
system("ln -s /sys/kernel/config/usb_gadget/adb_demo/functions/ffs.adb /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/");
int is_mounted = !system("mountpoint -q /dev/usb-ffs/adb");
if (!is_mounted) {
system("mkdir -p /dev/usb-ffs/adb");
/* This seems to fail, but adb will still work and then it will be mounted. Not sure what's up here... */
system("mount -t functionfs adb /dev/usb-ffs/adb");
}
// Boot adb daemon
system("/usr/bin/adbd &");
}
void disable_adb(void) {
// Remove any lingering adb daemon
system("killall -9 adbd");
// Remove the adb link to config
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/ffs.adb", F_OK) == 0) {
system("rm /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/ffs.adb");
}
// Remove the adb function
if (access("/sys/kernel/config/usb_gadget/adb_demo/functions/ffs.adb", F_OK) == 0) {
system("rm -rf /sys/kernel/config/usb_gadget/adb_demo/functions/ffs.adb");
}
// Reset the MaxPower to its default value
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/MaxPower", F_OK) == 0) {
sysfs_set_int("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/MaxPower", 120);
}
// Disable storage or adb configs
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", F_OK) == 0) {
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", "");
}
// Unmount adb
if (!system("mountpoint -q /dev/usb-ffs/adb")) {
system("unmount /dev/usb-ffs/adb");
}
}
#else
void enable_adb(void) {}
void disable_adb(void) {}
#endif
void enable_mass_storage(void) {
logf(">>>>>>>>>>>>>>>>> set_mass_storage()\n");
// Disable adb if it's running
disable_adb();
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo/functions/mass_storage.0/lun.0");
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409");
if (is_adb_running) {
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", "adb,storage");
} else {
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", "storage");
}
sysfs_set_int("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/MaxPower", 120);
system("ln -s /sys/kernel/config/usb_gadget/adb_demo/functions/mass_storage.0 /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/");
char mount_device[32] = "/dev/mmcblk0p1";
// If partition 1 doesn't exist we'll try the main device
if (access(mount_device, F_OK) != 0) {
memset(mount_device, 0, sizeof(mount_device));
strcpy(mount_device, "/dev/mmcblk0");
}
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/functions/mass_storage.0/lun.0/file", mount_device);
}
void disable_mass_storage(void) {
// Remove the mass_storage.0 link to config
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/mass_storage.0", F_OK) == 0) {
system("rm /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/mass_storage.0");
}
// Remove the mass_storage.0 function
if (access("/sys/kernel/config/usb_gadget/adb_demo/functions/mass_storage.0", F_OK) == 0) {
system("rm -rf /sys/kernel/config/usb_gadget/adb_demo/functions/mass_storage.0");
}
// Reset the MaxPower to its default value
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/MaxPower", F_OK) == 0) {
sysfs_set_int("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/MaxPower", 120);
}
// Disable storage or adb configs
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", F_OK) == 0) {
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", "");
}
}
#if defined(HAVE_USB_AUDIO)
void enable_usb_audio(void) {
}
void disable_usb_audio(void) {
}
#else
void enable_usb_audio(void) {}
void disable_usb_audio(void) {}
#endif
void usb_init_device(void)
{
logf(">>>>>>>>>>>>>>>>> usb_init_device()\n");
if (_usb_init) {
logf("usb is already init, skipping!\n");
return;
}
char functions[128] = {0};
/* Before we can do anything here we need to mount configfs */
int is_mounted = !system("mountpoint -q /sys/kernel/config");
if (!is_mounted && system("mount -t configfs none /sys/kernel/config")) {
logf("mount configfs failed, can't do usb functionality! ErrNo: %d\n", errno);
return;
}
_usb_init = true;
system("ls -la /sys/kernel/config/usb_gadget");
/* os_mkdir doesn't seem to work here for whatever reason */
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo");
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo/strings/0x409");
system("ls -la /sys/kernel/config/usb_gadget/adb_demo");
system("ls -la /sys/kernel/config/usb_gadget/adb_demo/configs/");
system("mkdir -p /sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409");
/* Check if ADB was activated in bootloader */
logf("checking if adb is already on\n");
if (access("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", F_OK) == 0) {
logf("found usb config string!\n");
sysfs_get_string("/sys/kernel/config/usb_gadget/adb_demo/configs/c.1/strings/0x409/configuration", functions, sizeof(functions));
is_adb_running = (strstr(functions, "adb") == NULL) ? false : true;
}
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/strings/0x409/manufacturer", "Rockbox.org");
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/strings/0x409/product", "Rockbox media player");
sysfs_set_string("/sys/kernel/config/usb_gadget/adb_demo/strings/0x409/serialnumber", "0123456789ABCDEF");
}

View file

@ -0,0 +1,30 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 by Melissa Autumn
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __USB_HIBY_H__
#define __USB_HIBY_H__
#include <stdbool.h>
/**
* Handle the setting and unsetting of adb usb mode
*/
void hiby_set_usb_mode(int mode);
#endif /* __USB_HIBY_H__ */

View file

@ -39,6 +39,7 @@
# define BATTERY_VOLTAGE_PATH BATTERY_SYSFS_PATH "/voltage_now"
# define BATTERY_CURRENT_PATH BATTERY_SYSFS_PATH "/current_now"
# define BATTERY_LEVEL_PATH BATTERY_SYSFS_PATH "/capacity"
# define BATTERY_TTE_PATH BATTERY_SYSFS_PATH "/time_to_empty_now"
#endif
/* Voltage is normally in microvolts */
@ -116,6 +117,16 @@ int _battery_level(void)
return (level * BATTERY_LEVEL_SCALE_MUL) / BATTERY_LEVEL_SCALE_DIV;
}
#endif
#if (CONFIG_BATTERY_MEASURE & TIME_MEASURE)
int _battery_time(void)
{
int battery_tte = 0;
sysfs_get_int(BATTERY_TTE_PATH, &battery_tte);
return battery_tte;
}
#endif
#endif
unsigned int power_input_status(void)

View file

@ -544,6 +544,20 @@
#define UI_LCD_POSY 78
#elif defined(HIBY_R3PROII)
#define UI_TITLE "Hiby R3 Pro II"
#define UI_WIDTH 645
#define UI_HEIGHT 924
#define UI_LCD_POSX 79
#define UI_LCD_POSY 63
#elif defined(HIBY_R1)
#define UI_TITLE "Hiby R1"
#define UI_WIDTH 634
#define UI_HEIGHT 1016
#define UI_LCD_POSX 77
#define UI_LCD_POSY 74
#elif defined(SIMULATOR)
#error no UI defines
#endif

View file

@ -62,10 +62,11 @@ static void sig_handler(int sig, siginfo_t *siginfo, void *context)
unsigned long pc = uc->uc_mcontext.pc;
unsigned long sp = uc->uc_mcontext.gregs[29];
lcd_putsf(0, line++, "%s at %08x", strsignal(sig), pc);
lcd_putsf(0, line++, "%s at %08lx", strsignal(sig), pc);
if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP)
if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP) {
lcd_putsf(0, line++, "address %p", siginfo->si_addr);
}
if(!triggered)
{
@ -82,7 +83,10 @@ static void sig_handler(int sig, siginfo_t *siginfo, void *context)
system_exception_wait(); /* If this returns, try to reboot */
system_reboot();
while (1); /* halt */
while (1) {
// Make sure we're not throttling the cpu
usleep(1000);
}
}
void power_off(void)
@ -90,7 +94,10 @@ void power_off(void)
backlight_hw_off();
sync();
system("/sbin/poweroff");
while (1); /* halt */
while (1) {
// Make sure we're not throttling the cpu
usleep(1000);
}
}
void system_init(void)
@ -117,7 +124,10 @@ void system_reboot(void)
{
backlight_hw_off();
system("/sbin/reboot");
while (1); /* halt */
while (1) {
// Make sure we're not throttling the cpu
usleep(1000);
}
}
void system_exception_wait(void)

View file

@ -51,6 +51,10 @@
#include "gui/skin_engine/skin_engine.h"
#endif
#if defined(HIBY_R3PROII) || defined(HIBY_R1)
#include "usb-hiby-gadget.h"
#endif
#if defined(IPOD_ACCESSORY_PROTOCOL)
#include "iap.h"
#endif
@ -161,6 +165,8 @@ void usb_set_mode(int mode)
usb_mode = mode;
#if defined(DX50) || defined(DX90)
ibasso_set_usb_mode(mode);
#elif defined(HIBY_R3PROII) || defined(HIBY_R1)
hiby_set_usb_mode(mode);
#endif
}
#endif