From 82f3d0c18fcb1984617699d369fb14b4a882d8f4 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 1 May 2025 21:58:50 -0400 Subject: [PATCH] WIP hosted port to the Surfans F28 * Only bootloader builds * Plugins disabled * No keymaps to anything else * No simulator * Touchscreen not wired up yet * Audio still untested Bugs: * rotary encoder does nothing in bootloader (might be bootloader bug, might be something else) Other stuff pulled in: * Unify all of the (identical!) hibyos makefiles * Rename the "bootloader" to more generic name Change-Id: I6d8a3b58de726db8e89cf193c90960a070a575c2 --- apps/bitmaps/native/SOURCES | 2 +- apps/features.txt | 2 +- bootloader/SOURCES | 2 +- bootloader/{rocker_linux.c => hibyos_linux.c} | 9 + firmware/SOURCES | 9 + firmware/drivers/audio/surfanslinux_codec.c | 200 ++++++++++++++++++ firmware/export/audiohw.h | 2 + firmware/export/config.h | 5 +- firmware/export/config/hibylinux.h | 2 +- firmware/export/config/surfansf28.h | 68 ++++++ firmware/export/surfanslinux_codec.h | 17 ++ firmware/target/hosted/aigo/erosq.make | 49 ----- .../{agptek/rocker.make => hibyos.make} | 0 firmware/target/hosted/surfans/adc-target.h | 0 firmware/target/hosted/surfans/button-f28.c | 64 ++++++ .../target/hosted/surfans/button-target.h | 52 +++++ firmware/target/hosted/surfans/debug-f28.c | 89 ++++++++ firmware/target/hosted/surfans/lcd-target.h | 32 +++ firmware/target/hosted/surfans/power-f28.c | 41 ++++ firmware/target/hosted/surfans/power-f28.h | 27 +++ .../target/hosted/surfans/powermgmt-f28.c | 47 ++++ .../target/hosted/surfans/system-target.h | 28 +++ firmware/target/hosted/xduoo/button-xduoo.c | 4 +- firmware/target/hosted/xduoo/xduoo.make | 49 ----- tools/configure | 35 ++- tools/hiby_patcher.pl | 2 + tools/root.make | 20 +- 27 files changed, 730 insertions(+), 127 deletions(-) rename bootloader/{rocker_linux.c => hibyos_linux.c} (98%) create mode 100644 firmware/drivers/audio/surfanslinux_codec.c create mode 100644 firmware/export/config/surfansf28.h create mode 100644 firmware/export/surfanslinux_codec.h delete mode 100644 firmware/target/hosted/aigo/erosq.make rename firmware/target/hosted/{agptek/rocker.make => hibyos.make} (100%) create mode 100644 firmware/target/hosted/surfans/adc-target.h create mode 100644 firmware/target/hosted/surfans/button-f28.c create mode 100644 firmware/target/hosted/surfans/button-target.h create mode 100644 firmware/target/hosted/surfans/debug-f28.c create mode 100644 firmware/target/hosted/surfans/lcd-target.h create mode 100644 firmware/target/hosted/surfans/power-f28.c create mode 100644 firmware/target/hosted/surfans/power-f28.h create mode 100644 firmware/target/hosted/surfans/powermgmt-f28.c create mode 100644 firmware/target/hosted/surfans/system-target.h delete mode 100644 firmware/target/hosted/xduoo/xduoo.make diff --git a/apps/bitmaps/native/SOURCES b/apps/bitmaps/native/SOURCES index c31f6605df..d8ed1dc4db 100644 --- a/apps/bitmaps/native/SOURCES +++ b/apps/bitmaps/native/SOURCES @@ -46,7 +46,7 @@ toolsicon.130x130x16.bmp hibyicon.70x70x16.bmp rockboxicon.70x70x16.bmp toolsicon.70x70x16.bmp -#elif (defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(EROS_Q)) +#elif (defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(EROS_Q) || defined(SURFANS_F28)) hibyicon.130x130x16.bmp rockboxicon.130x130x16.bmp toolsicon.130x130x16.bmp diff --git a/apps/features.txt b/apps/features.txt index 066fddf55f..fd09a49d95 100644 --- a/apps/features.txt +++ b/apps/features.txt @@ -182,7 +182,7 @@ depth_3d #endif /* This should be AUDIOHW_HAVE_FILTER_ROLL_OFF but that is only defined later */ -#if defined(DX50) || defined(HAVE_DF1704_CODEC) || defined(HAVE_PCM1792_CODEC) || defined(HAVE_CS4398) || defined(HAVE_WM8740) || defined(HAVE_ES9018)|| defined(HAVE_EROS_QN_CODEC) || defined(HAVE_XDUOO_LINUX_CODEC) || defined(HAVE_FIIO_LINUX_CODEC) || defined(HAVE_AK4376) || defined(HAVE_ES9218) +#if defined(DX50) || defined(HAVE_DF1704_CODEC) || defined(HAVE_PCM1792_CODEC) || defined(HAVE_CS4398) || defined(HAVE_WM8740) || defined(HAVE_ES9018)|| defined(HAVE_EROS_QN_CODEC) || defined(HAVE_XDUOO_LINUX_CODEC) || defined(HAVE_FIIO_LINUX_CODEC) || defined(HAVE_AK4376) || defined(HAVE_ES9218) || defined(HAVE_SURFANS_LINUX_CODEC) filter_roll_off #endif diff --git a/bootloader/SOURCES b/bootloader/SOURCES index fb3cc1e6c3..ca48bfa7ba 100644 --- a/bootloader/SOURCES +++ b/bootloader/SOURCES @@ -77,7 +77,7 @@ mpio_hd200_hd300.c #elif defined(SONY_NWZ_LINUX) nwz_linux.c #elif defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) -rocker_linux.c +hibyos_linux.c #elif defined(RK27_GENERIC) || defined(HM60X) || defined(HM801) \ || defined(MA9) || defined(MA9C) || defined(MA8) || defined(MA8C) \ || defined(IHIFI760) || defined(IHIFI960) || defined(IHIFI800) \ diff --git a/bootloader/rocker_linux.c b/bootloader/hibyos_linux.c similarity index 98% rename from bootloader/rocker_linux.c rename to bootloader/hibyos_linux.c index b9dc9f9406..1b59910af7 100644 --- a/bootloader/rocker_linux.c +++ b/bootloader/hibyos_linux.c @@ -90,6 +90,15 @@ #define BUTTON_DOWN BUTTON_SCROLL_FWD #define BUTTON_SELECT BUTTON_PLAY #include "bitmaps/hibyicon.h" +#elif defined(SURFANS_F28) +#define ICON_WIDTH 130 +#define ICON_HEIGHT 130 +#define ICON_NAME bm_hibyicon +#define OF_NAME "HIBY PLAYER" +#define BUTTON_UP BUTTON_PREV +#define BUTTON_DOWN BUTTON_NEXT +#define BUTTON_SELECT BUTTON_PLAY +#include "bitmaps/hibyicon.h" #else #error "must define ICON_WIDTH/HEIGHT" #endif diff --git a/firmware/SOURCES b/firmware/SOURCES index cd10ae2f98..7358eb9fb7 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -151,6 +151,13 @@ target/hosted/agptek/power-agptek.c target/hosted/agptek/powermgmt-agptek.c #endif +#if defined(SURFANS_F28) && !defined(SIMULATOR) +target/hosted/surfans/button-f28.c +target/hosted/surfans/debug-f28.c +target/hosted/surfans/power-f28.c +target/hosted/surfans/powermgmt-f28.c +#endif + #if (defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR) target/hosted/xduoo/button-xduoo.c target/hosted/xduoo/debug-xduoo.c @@ -543,6 +550,8 @@ target/hosted/alsa-controls.c target/hosted/pcm-alsa.c #elif defined(HAVE_ROCKER_CODEC) && !defined(SIMULATOR) drivers/audio/rocker_codec.c +#elif defined(HAVE_SURFANS_LINUX_CODEC) && !defined(SIMULATOR) +drivers/audio/surfanslinux_codec.c #elif defined(HAVE_XDUOO_LINUX_CODEC) && !defined(SIMULATOR) drivers/audio/xduoolinux_codec.c #elif defined(HAVE_FIIO_LINUX_CODEC) && !defined(SIMULATOR) diff --git a/firmware/drivers/audio/surfanslinux_codec.c b/firmware/drivers/audio/surfanslinux_codec.c new file mode 100644 index 0000000000..786c41e36e --- /dev/null +++ b/firmware/drivers/audio/surfanslinux_codec.c @@ -0,0 +1,200 @@ +/*************************************************************************** + * __________ __ ___. + * 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" + +/* + +f28: + +**** List of PLAYBACK Hardware Devices **** +card 0: tyinx1 [tyin_x1], device 0: tyin_x1-es9018_k2m-i2s es9018_k2m-hifi-0 [] + Subdevices: 1/1 + Subdevice #0: subdevice #0 +card 0: tyinx1 [tyin_x1], device 1: tyin_x1-es9018_k2m-pcm es9018_k2m-hifi-1 [] + Subdevices: 1/1 + Subdevice #0: subdevice #0 +card 1: saspdif [sa_spdif], device 0: SA SPDIF Dummy spdif dump dai-0 [] + Subdevices: 1/1 + Subdevice #0: subdevice #0 + +Mixer controls: + +numid=3,iface=MIXER,name='ES9018_K2M Digital Filter' + ; type=INTEGER,access=rw------,values=1,min=0,max=4,step=0 + : values=0 +numid=5,iface=MIXER,name='Hardware Mute' + ; type=BOOLEAN,access=rw------,values=1 + : values=off +numid=1,iface=MIXER,name='Left Playback Volume' + ; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0 + : values=0 +numid=4,iface=MIXER,name='Output Port Switch' + ; type=INTEGER,access=rw------,values=1,min=0,max=5,step=0 + : values=0 +numid=2,iface=MIXER,name='Right Playback Volume' + ; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0 + : values=0 +numid=6,iface=MIXER,name='isDSD' + ; type=BOOLEAN,access=rw------,values=1 + : values=off + +*/ + +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) +{ + logf("mute %d", mute); + + if (!hw_init || muted == mute) + return; + + muted = mute; + + if(mute) + { + long int ps0 = 0; + alsa_controls_set_ints("Output Port Switch", 1, &ps0); + } + else + { + last_ps = 0; + surfans_get_outputs(); + } +} + +int surfans_get_outputs(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 + + surfans_set_output(ps); + + return ps; +} + +void surfans_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 */ +} + +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 */ +#if defined(XDUOO_X20) + long int value_hw = value; + alsa_controls_set_ints("ES9018_K2M Digital Filter", 1, &value_hw); +#else + (void)value; +#endif +} diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index b9cf87557d..cbe6c3ee5a 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h @@ -232,6 +232,8 @@ struct sound_settings_info #include "codec-dx90.h" #elif defined(HAVE_ROCKER_CODEC) #include "rocker_codec.h" +#elif defined(HAVE_SURFANS_LINUX_CODEC) +#include "surfanslinux_codec.h" #elif defined(HAVE_XDUOO_LINUX_CODEC) #include "xduoolinux_codec.h" #elif defined(HAVE_FIIO_LINUX_CODEC) diff --git a/firmware/export/config.h b/firmware/export/config.h index e5af82983e..9196141fe5 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -165,6 +165,7 @@ #define FIIO_M3K_PAD 73 #define SHANLING_Q1_PAD 74 #define ECHO_R1_PAD 75 +#define SURFANS_F28_PAD 76 /* CONFIG_REMOTE_KEYPAD */ #define H100_REMOTE 1 @@ -206,7 +207,7 @@ * use the charging hardware. */ /* CONFIG_BATTERY_MEASURE bits */ -/* If both VOLTAGE_MEASURE and PERCENTAGE_MEASURE are defined, +/* If both VOLTAGE_MEASURE and PERCENTAGE_MEASURE are defined, * _battery_level() (percentage) will be preferred, unless _battery_level() * returns -1, then voltage will be used from _voltage_level(). */ #define VOLTAGE_MEASURE 1 /* Target can report battery voltage @@ -616,6 +617,8 @@ Lyre prototype 1 */ #include "config/erosqnative.h" #elif defined(ECHO_R1) #include "config/echor1.h" +#elif defined(SURFANS_F28) +#include "config/surfansf28.h" #else //#error "unknown hwardware platform!" #endif diff --git a/firmware/export/config/hibylinux.h b/firmware/export/config/hibylinux.h index 2da7633389..6853139899 100644 --- a/firmware/export/config/hibylinux.h +++ b/firmware/export/config/hibylinux.h @@ -54,7 +54,7 @@ #define MIN_BRIGHTNESS_SETTING 1 #define MAX_BRIGHTNESS_SETTING 255 #define BRIGHTNESS_STEP 5 -#define DEFAULT_BRIGHTNESS_SETTING 70 +#define DEFAULT_BRIGHTNESS_SETTING 255 /* Which backlight fading type? */ #define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING diff --git a/firmware/export/config/surfansf28.h b/firmware/export/config/surfansf28.h new file mode 100644 index 0000000000..e1bc3d6952 --- /dev/null +++ b/firmware/export/config/surfansf28.h @@ -0,0 +1,68 @@ +/* + * This config file is for the Surfans F28 + */ + +/* For Rolo and boot loader */ +#define MODEL_NUMBER 120 + +#define MODEL_NAME "Surfans F28" + +/* LCD dimensions */ +#define LCD_WIDTH 320 +#define LCD_HEIGHT 480 +/* sqrt(320^2 + 480^2) / 3.5 = 165 */ +#define LCD_DPI 165 + +/* define this if you have access to the quickscreen */ +//#define HAVE_QUICKSCREEN +//#define HAVE_HOTKEY + +#define HAVE_BUTTON_DATA +#define HAVE_TOUCHSCREEN +#define HAVE_HEADPHONE_DETECTION + +/* KeyPad configuration for plugins */ +#define CONFIG_KEYPAD SURFANS_F28_PAD + +/* define this if the target has volume keys which can be used in the lists */ +#define HAVE_VOLUME_IN_LIST + +#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE + +/* Define this to the CPU frequency */ +#define CPU_FREQ 1008000000 + +/* Battery */ +#define BATTERY_TYPES_COUNT 1 + +/* Audio codec */ +#define HAVE_SURFANS_LINUX_CODEC +#define HAVE_ALSA_32BIT + +/* 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 BATTERY_CAPACITY_DEFAULT 1500 /* default battery capacity */ +#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */ +#define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable */ +#define BATTERY_CAPACITY_INC 0 /* capacity increment */ + +#define CURRENT_NORMAL 100 // 1.7mA * 60s +#define CURRENT_BACKLIGHT 180 +#define CURRENT_MAX_CHG 500 // bursts higher if needed + +/* ROLO */ +#define BOOTFILE_EXT "f28" +#define BOOTFILE "rockbox." BOOTFILE_EXT +#define BOOTDIR "/.rockbox" + +/* USB */ +#define USB_VID_STR "18D1" +#define USB_PID_STR "0D02" + +/* Generic HiBy stuff */ +#include "hibylinux.h" diff --git a/firmware/export/surfanslinux_codec.h b/firmware/export/surfanslinux_codec.h new file mode 100644 index 0000000000..e0e38deb19 --- /dev/null +++ b/firmware/export/surfanslinux_codec.h @@ -0,0 +1,17 @@ +#ifndef __SURFANSLINUX_CODEC__ +#define __SURFANSLINUX_CODEC__ + +#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP) +AUDIOHW_SETTING(VOLUME, "dB", 1, 5, -102*10, 0, -30*10) +#endif + +// We want this, but the codec takes over a second to unmute! +//#define AUDIOHW_MUTE_ON_STOP + +//#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 surfans_set_output(int ps); +int surfans_get_outputs(void); diff --git a/firmware/target/hosted/aigo/erosq.make b/firmware/target/hosted/aigo/erosq.make deleted file mode 100644 index 117ecb8eac..0000000000 --- a/firmware/target/hosted/aigo/erosq.make +++ /dev/null @@ -1,49 +0,0 @@ -# __________ __ ___. -# Open \______ \ ____ ____ | | _\_ |__ _______ ___ -# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / -# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < -# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ -# \/ \/ \/ \/ \/ -# $Id$ -# - -INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR) - -SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS) - -# bootloader build is sligtly different -ifneq (,$(findstring bootloader,$(APPSDIR))) - -SRC += $(call preprocess, $(APPSDIR)/SOURCES) -CLEANOBJS += $(BUILDDIR)/bootloader.* - -endif #bootloader - -.SECONDEXPANSION: # $$(OBJ) is not populated until after this - -ifneq (,$(findstring bootloader,$(APPSDIR))) -# bootloader build - -$(BUILDDIR)/bootloader.elf : $$(OBJ) $(FIRMLIB) $(CORE_LIBS) - $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -o $@ $(OBJ) \ - -L$(BUILDDIR)/firmware -lfirmware \ - -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \ - $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,--gc-sections -Wl,-Map,$(BUILDDIR)/bootloader.map - -$(BUILDDIR)/$(BINARY): $(BUILDDIR)/bootloader.elf - $(call PRINTS,OC $(@F))$(call objcopy,$^,$@) - -else -# rockbox app build - -$(BUILDDIR)/rockbox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) - $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -o $@ $(OBJ) \ - -L$(BUILDDIR)/firmware -lfirmware \ - -L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \ - -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \ - $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map - -$(BUILDDIR)/$(BINARY): $(BUILDDIR)/rockbox.elf - $(call PRINTS,OC $(@F))$(call objcopy,$^,$@) - -endif diff --git a/firmware/target/hosted/agptek/rocker.make b/firmware/target/hosted/hibyos.make similarity index 100% rename from firmware/target/hosted/agptek/rocker.make rename to firmware/target/hosted/hibyos.make diff --git a/firmware/target/hosted/surfans/adc-target.h b/firmware/target/hosted/surfans/adc-target.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/firmware/target/hosted/surfans/button-f28.c b/firmware/target/hosted/surfans/button-f28.c new file mode 100644 index 0000000000..039f0466f5 --- /dev/null +++ b/firmware/target/hosted/surfans/button-f28.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___ + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 Marcin Bukat + * + * 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 + +#include "sysfs.h" +#include "button.h" +#include "button-target.h" +#include "surfanslinux_codec.h" + +/* + /dev/input/event0: rotary encoder (left/right) + /dev/input/event1: adc (prev/play) + /dev/input/event2: touchscreen + /dev/input/event3: gpios (power/next) +*/ + +int button_map(int keycode) +{ + switch(keycode) + { + case KEY_LEFT: + return BUTTON_LEFT; + case KEY_RIGHT: + return BUTTON_RIGHT; + case KEY_PLAYPAUSE: + return BUTTON_PLAY; + case KEY_NEXTSONG: + return BUTTON_NEXT; + case KEY_PREVIOUSSONG: + return BUTTON_PREV; + case KEY_POWER: + return BUTTON_POWER; + default: + return 0; + } +} + +bool headphones_inserted(void) +{ +#ifdef BOOTLOADER + int ps = 0; +#else + int ps = surfans_get_outputs(); +#endif + + return (ps == 2 || ps == 3); +} diff --git a/firmware/target/hosted/surfans/button-target.h b/firmware/target/hosted/surfans/button-target.h new file mode 100644 index 0000000000..5b42827281 --- /dev/null +++ b/firmware/target/hosted/surfans/button-target.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 by Marcin Bukat + * + * 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 +#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_LEFT 0x00000010 +#define BUTTON_RIGHT 0x00000020 +#define BUTTON_MAIN 0x0000003f + +/* 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 + +int button_map(int keycode); + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/hosted/surfans/debug-f28.c b/firmware/target/hosted/surfans/debug-f28.c new file mode 100644 index 0000000000..9dd386598f --- /dev/null +++ b/firmware/target/hosted/surfans/debug-f28.c @@ -0,0 +1,89 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2020 by 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. + * + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "font.h" +#include "lcd.h" +#include "kernel.h" +#include "button.h" + +#ifndef BOOTLOADER + +#include "pcm-alsa.h" + +static int line = 0; + +extern int hwver; + +bool dbg_hw_info(void) +{ + int btn = 0; + + /* Try to read the bootloader */ + char verstr[40]; + memset(verstr, 0, sizeof(verstr)); + int fd = open("/etc/rockbox-bl-info.txt", O_RDONLY); + if(fd >= 0) + { + read(fd, verstr, sizeof(verstr) -1); + close(fd); + } + + lcd_setfont(FONT_SYSFIXED); + + while(btn ^ BUTTON_POWER) { + lcd_clear_display(); + line = 0; + + if (verstr[0]) { + lcd_putsf(0, line++, "Boot ver: %s", verstr); + } + +#ifdef EROS_Q + lcd_putsf(0, line++, "hwver: %d", hwver); +#endif + + lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate()); + lcd_putsf(0, line++, "pcm xruns: %d", pcm_alsa_get_xruns()); +#ifdef HAVE_HEADPHONE_DETECTION + lcd_putsf(0, line++, "hp: %d", headphones_inserted()); +#endif +#ifdef HAVE_LINEOUT_DETECTION + lcd_putsf(0, line++, "lo: %d", lineout_inserted()); +#endif + + int bdata; + btn = button_read_device(&bdata); + lcd_putsf(0, line++, "btn: %d", btn); + + lcd_update(); + sleep(HZ/16); + } + return true; +} + +#endif /* !BOOTLOADER */ diff --git a/firmware/target/hosted/surfans/lcd-target.h b/firmware/target/hosted/surfans/lcd-target.h new file mode 100644 index 0000000000..f7ed743aef --- /dev/null +++ b/firmware/target/hosted/surfans/lcd-target.h @@ -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__ + +/* Agptek needs special ioctl() to redraw updated framebuffer content */ +#define LCD_OPTIMIZED_UPDATE +#define LCD_OPTIMIZED_UPDATE_RECT + +extern fb_data *framebuffer; /* see lcd-agptek.c */ +#define LCD_FRAMEBUF_ADDR(col, row) (framebuffer + (row)*LCD_WIDTH + (col)) + +extern void lcd_set_active(bool active); +#endif /* __LCD_TARGET_H__ */ diff --git a/firmware/target/hosted/surfans/power-f28.c b/firmware/target/hosted/surfans/power-f28.c new file mode 100644 index 0000000000..3a52820d0f --- /dev/null +++ b/firmware/target/hosted/surfans/power-f28.c @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 by Marcin Bukat + * + * 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 +#include +#include +#include +#include + +#include "system.h" +#include "power-f28.h" +#include "power.h" +#include "panic.h" +#include "sysfs.h" + +const char * const sysfs_bat_voltage = + "/sys/class/power_supply/battery/voltage_now"; + +unsigned int f28_power_get_battery_voltage(void) +{ + int battery_voltage; + sysfs_get_int(sysfs_bat_voltage, &battery_voltage); + + return battery_voltage/1000; +} diff --git a/firmware/target/hosted/surfans/power-f28.h b/firmware/target/hosted/surfans/power-f28.h new file mode 100644 index 0000000000..ab787f2cf4 --- /dev/null +++ b/firmware/target/hosted/surfans/power-f28.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 by Marcin Bukat + * + * 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 _POWER_F28_H_ +#define _POWER_F28_H_ + +#include +#include "config.h" + +unsigned int f28_power_get_battery_voltage(void); +#endif /* _POWER_F28_H_ */ diff --git a/firmware/target/hosted/surfans/powermgmt-f28.c b/firmware/target/hosted/surfans/powermgmt-f28.c new file mode 100644 index 0000000000..0cbdb80220 --- /dev/null +++ b/firmware/target/hosted/surfans/powermgmt-f28.c @@ -0,0 +1,47 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 Marcin Bukat + * + * 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" +#include "power-f28.h" + +// XXX all of this... blabla +// max voltage is 4360 apparently + +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, 3915, 3985, 4060, 4155 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +unsigned short percent_to_volt_charge[11] = +{ + 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 +}; + +int _battery_voltage(void) +{ + return f28_power_get_battery_voltage(); +} diff --git a/firmware/target/hosted/surfans/system-target.h b/firmware/target/hosted/surfans/system-target.h new file mode 100644 index 0000000000..830f19fde4 --- /dev/null +++ b/firmware/target/hosted/surfans/system-target.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 Marcin Bukat + * 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 __SYSTEM_TARGET_H__ +#define __SYSTEM_TARGET_H__ + +#include "kernel-unix.h" +#include "system-hosted.h" + +#define NEED_GENERIC_BYTESWAPS +#endif /* __SYSTEM_TARGET_H__ */ diff --git a/firmware/target/hosted/xduoo/button-xduoo.c b/firmware/target/hosted/xduoo/button-xduoo.c index c06b60bd9f..1a1712ec8c 100644 --- a/firmware/target/hosted/xduoo/button-xduoo.c +++ b/firmware/target/hosted/xduoo/button-xduoo.c @@ -77,7 +77,7 @@ bool headphones_inserted(void) #ifdef BOOTLOADER int ps = 0; #else - int ps = xduoo_get_outputs(); + int ps = surfans_get_outputs(); #endif return (ps == 2 || ps == 3); @@ -88,7 +88,7 @@ bool lineout_inserted(void) #ifdef BOOTLOADER int ps = 0; #else - int ps = xduoo_get_outputs(); + int ps = surfans_get_outputs(); #endif return (ps == 1); } diff --git a/firmware/target/hosted/xduoo/xduoo.make b/firmware/target/hosted/xduoo/xduoo.make deleted file mode 100644 index 117ecb8eac..0000000000 --- a/firmware/target/hosted/xduoo/xduoo.make +++ /dev/null @@ -1,49 +0,0 @@ -# __________ __ ___. -# Open \______ \ ____ ____ | | _\_ |__ _______ ___ -# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / -# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < -# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ -# \/ \/ \/ \/ \/ -# $Id$ -# - -INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR) - -SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS) - -# bootloader build is sligtly different -ifneq (,$(findstring bootloader,$(APPSDIR))) - -SRC += $(call preprocess, $(APPSDIR)/SOURCES) -CLEANOBJS += $(BUILDDIR)/bootloader.* - -endif #bootloader - -.SECONDEXPANSION: # $$(OBJ) is not populated until after this - -ifneq (,$(findstring bootloader,$(APPSDIR))) -# bootloader build - -$(BUILDDIR)/bootloader.elf : $$(OBJ) $(FIRMLIB) $(CORE_LIBS) - $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -o $@ $(OBJ) \ - -L$(BUILDDIR)/firmware -lfirmware \ - -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \ - $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,--gc-sections -Wl,-Map,$(BUILDDIR)/bootloader.map - -$(BUILDDIR)/$(BINARY): $(BUILDDIR)/bootloader.elf - $(call PRINTS,OC $(@F))$(call objcopy,$^,$@) - -else -# rockbox app build - -$(BUILDDIR)/rockbox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) - $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -o $@ $(OBJ) \ - -L$(BUILDDIR)/firmware -lfirmware \ - -L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \ - -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \ - $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map - -$(BUILDDIR)/$(BINARY): $(BUILDDIR)/rockbox.elf - $(call PRINTS,OC $(@F))$(call objcopy,$^,$@) - -endif diff --git a/tools/configure b/tools/configure index a8911ba995..358679054e 100755 --- a/tools/configure +++ b/tools/configure @@ -1730,8 +1730,8 @@ cat <