mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
New port: FiiO M3K
Most credit goes to: Roman Skylarov Additional integration and refactoring by myself. *** COMPLETELY UNTESTED *** Change-Id: Ia64c36d92e0214c6b15f7a868df286f8113ea27b
This commit is contained in:
parent
4231c2c83f
commit
aabc8aca47
84 changed files with 2188 additions and 20 deletions
|
|
@ -21,16 +21,20 @@
|
|||
#ifndef _BACKLIGHT_TARGET_H_
|
||||
#define _BACKLIGHT_TARGET_H_
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/* See backlight.c */
|
||||
bool backlight_hw_init(void);
|
||||
void backlight_hw_on(void);
|
||||
void backlight_hw_off(void);
|
||||
void backlight_hw_brightness(int brightness);
|
||||
|
||||
|
||||
#ifdef HAVE_BUTTON_LIGHT
|
||||
void buttonlight_hw_on(void);
|
||||
void buttonlight_hw_off(void);
|
||||
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
|
||||
void buttonlight_hw_brightness(int brightness);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
0
firmware/target/hosted/fiio/adc-target.h
Normal file
0
firmware/target/hosted/fiio/adc-target.h
Normal file
308
firmware/target/hosted/fiio/button-fiio.c
Normal file
308
firmware/target/hosted/fiio/button-fiio.c
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2017 Marcin Bukat
|
||||
* Copyright (C) 2019 Roman Stolyarov
|
||||
*
|
||||
* 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 <poll.h>
|
||||
//#include <dir.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/input.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sysfs.h"
|
||||
#include "button.h"
|
||||
#include "button-target.h"
|
||||
#include "panic.h"
|
||||
|
||||
#include "kernel.h"
|
||||
#include "backlight.h"
|
||||
#include "backlight-target.h"
|
||||
|
||||
static int key_enter_delay = 0;
|
||||
static int key_right_delay = 0;
|
||||
static int key_left_delay = 0;
|
||||
static int key_power_delay = 0;
|
||||
static int key_home_delay = 0;
|
||||
static int key_backspace_delay = 0;
|
||||
static int key_leftbrace_delay = 0;
|
||||
static int key_rightbrace_delay = 0;
|
||||
static int key_up_delay = 0;
|
||||
static int key_down_delay = 0;
|
||||
static int key_f12_delay = 0;
|
||||
|
||||
#define NR_POLL_DESC 2
|
||||
static struct pollfd poll_fds[NR_POLL_DESC];
|
||||
|
||||
#define DEF_DELAY 5
|
||||
|
||||
static int button_map_on(int keycode)
|
||||
{
|
||||
switch(keycode)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
key_enter_delay = DEF_DELAY;
|
||||
return BUTTON_PLAY;
|
||||
case KEY_F10:
|
||||
key_enter_delay = 0;
|
||||
return BUTTON_PLAY;
|
||||
|
||||
case KEY_RIGHT:
|
||||
key_right_delay = DEF_DELAY;
|
||||
return BUTTON_VOL_DOWN;
|
||||
case KEY_F7:
|
||||
key_right_delay = 0;
|
||||
return BUTTON_VOL_DOWN;
|
||||
|
||||
case KEY_LEFT:
|
||||
key_left_delay = DEF_DELAY;
|
||||
return BUTTON_VOL_UP;
|
||||
case KEY_F6:
|
||||
key_left_delay = 0;
|
||||
return BUTTON_VOL_UP;
|
||||
|
||||
case KEY_POWER:
|
||||
key_power_delay = DEF_DELAY;
|
||||
return BUTTON_POWER;
|
||||
case KEY_F8:
|
||||
key_power_delay = 0;
|
||||
return BUTTON_POWER;
|
||||
|
||||
case KEY_HOME:
|
||||
key_home_delay = DEF_DELAY;
|
||||
return BUTTON_OPTION;
|
||||
case KEY_F9:
|
||||
key_home_delay = 0;
|
||||
return BUTTON_OPTION;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
key_backspace_delay = DEF_DELAY;
|
||||
return BUTTON_HOME;
|
||||
case KEY_NUMLOCK:
|
||||
key_backspace_delay = 0;
|
||||
return BUTTON_HOME;
|
||||
|
||||
case KEY_LEFTBRACE:
|
||||
key_leftbrace_delay = DEF_DELAY;
|
||||
return BUTTON_PREV;
|
||||
case KEY_F5:
|
||||
key_leftbrace_delay = 0;
|
||||
return BUTTON_PREV;
|
||||
|
||||
case KEY_RIGHTBRACE:
|
||||
key_rightbrace_delay = DEF_DELAY;
|
||||
return BUTTON_NEXT;
|
||||
case KEY_F4:
|
||||
key_rightbrace_delay = 0;
|
||||
return BUTTON_NEXT;
|
||||
|
||||
case KEY_UP:
|
||||
if (!key_up_delay) key_up_delay = DEF_DELAY;
|
||||
return BUTTON_UP;
|
||||
|
||||
case KEY_DOWN:
|
||||
if (!key_down_delay) key_down_delay = DEF_DELAY;
|
||||
return BUTTON_DOWN;
|
||||
|
||||
case KEY_F12:
|
||||
key_f12_delay = DEF_DELAY;
|
||||
//return BUTTON_UNLOCK;
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int button_map_off(int keycode)
|
||||
{
|
||||
switch(keycode)
|
||||
{
|
||||
case KEY_F10:
|
||||
return BUTTON_PLAY;
|
||||
|
||||
case KEY_F7:
|
||||
return BUTTON_VOL_DOWN;
|
||||
|
||||
case KEY_F6:
|
||||
return BUTTON_VOL_UP;
|
||||
|
||||
case KEY_F8:
|
||||
return BUTTON_POWER;
|
||||
|
||||
case KEY_F9:
|
||||
return BUTTON_OPTION;
|
||||
|
||||
case KEY_NUMLOCK:
|
||||
return BUTTON_HOME;
|
||||
|
||||
case KEY_F5:
|
||||
return BUTTON_PREV;
|
||||
|
||||
case KEY_F4:
|
||||
return BUTTON_NEXT;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int button_map_timer(void)
|
||||
{
|
||||
int map = 0;
|
||||
|
||||
if (key_enter_delay)
|
||||
{
|
||||
if (--key_enter_delay == 0) map |= BUTTON_PLAY;
|
||||
}
|
||||
if (key_right_delay)
|
||||
{
|
||||
if (--key_right_delay == 0) map |= BUTTON_VOL_DOWN;
|
||||
}
|
||||
if (key_left_delay)
|
||||
{
|
||||
if (--key_left_delay == 0) map |= BUTTON_VOL_UP;
|
||||
}
|
||||
if (key_power_delay)
|
||||
{
|
||||
if (--key_power_delay == 0) map |= BUTTON_POWER;
|
||||
}
|
||||
if (key_home_delay)
|
||||
{
|
||||
if (--key_home_delay == 0) map |= BUTTON_OPTION;
|
||||
}
|
||||
if (key_backspace_delay)
|
||||
{
|
||||
if (--key_backspace_delay == 0) map |= BUTTON_HOME;
|
||||
}
|
||||
if (key_leftbrace_delay)
|
||||
{
|
||||
if (--key_leftbrace_delay == 0) map |= BUTTON_PREV;
|
||||
}
|
||||
if (key_rightbrace_delay)
|
||||
{
|
||||
if (--key_rightbrace_delay == 0) map |= BUTTON_NEXT;
|
||||
}
|
||||
if (key_up_delay)
|
||||
{
|
||||
if (--key_up_delay == 0) map |= BUTTON_UP;
|
||||
}
|
||||
if (key_down_delay)
|
||||
{
|
||||
if (--key_down_delay == 0) map |= BUTTON_DOWN;
|
||||
}
|
||||
if (key_f12_delay)
|
||||
{
|
||||
if (--key_f12_delay == 0) map |= 0; //BUTTON_UNLOCK
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void button_init_device(void)
|
||||
{
|
||||
const char * const input_devs[] = {
|
||||
"/dev/input/event0",
|
||||
"/dev/input/event1",
|
||||
};
|
||||
|
||||
for(int i = 0; i < NR_POLL_DESC; i++)
|
||||
{
|
||||
int fd = open(input_devs[i], O_RDWR);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
panicf("Cannot open input device: %s\n", input_devs[i]);
|
||||
}
|
||||
|
||||
poll_fds[i].fd = fd;
|
||||
poll_fds[i].events = POLLIN;
|
||||
poll_fds[i].revents = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int button_read_device(void)
|
||||
{
|
||||
static int button_bitmap = 0;
|
||||
static int map;
|
||||
struct input_event event;
|
||||
|
||||
/* check if there are any events pending and process them */
|
||||
while(poll(poll_fds, NR_POLL_DESC, 0))
|
||||
{
|
||||
for(int i = 0; i < NR_POLL_DESC; i++)
|
||||
{
|
||||
/* read only if non-blocking */
|
||||
if(poll_fds[i].revents & POLLIN)
|
||||
{
|
||||
int size = read(poll_fds[i].fd, &event, sizeof(event));
|
||||
if(size == (int)sizeof(event))
|
||||
{
|
||||
if(event.type == EV_KEY)
|
||||
{
|
||||
int keycode = event.code;
|
||||
|
||||
/* event.value == 1 means press
|
||||
* event.value == 0 means release
|
||||
*/
|
||||
bool press = event.value ? true : false;
|
||||
|
||||
if(press)
|
||||
{
|
||||
map = button_map_on(keycode);
|
||||
if(map) button_bitmap |= map;
|
||||
}
|
||||
else
|
||||
{
|
||||
map = button_map_off(keycode);
|
||||
if(map) button_bitmap &= ~map;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map = button_map_timer();
|
||||
if(map) button_bitmap &= ~map;
|
||||
|
||||
return button_bitmap;
|
||||
}
|
||||
|
||||
bool headphones_inserted(void)
|
||||
{
|
||||
int status = 0;
|
||||
const char * const sysfs_hs_switch = "/sys/class/misc/axp173/headset_state";
|
||||
|
||||
sysfs_get_int(sysfs_hs_switch, &status);
|
||||
if (status) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void button_close_device(void)
|
||||
{
|
||||
/* close descriptors */
|
||||
for(int i = 0; i < NR_POLL_DESC; i++)
|
||||
{
|
||||
close(poll_fds[i].fd);
|
||||
}
|
||||
}
|
||||
50
firmware/target/hosted/fiio/button-target.h
Normal file
50
firmware/target/hosted/fiio/button-target.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2019 by Roman Stolyarov
|
||||
*
|
||||
* 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_
|
||||
|
||||
/* Main unit's buttons */
|
||||
#define BUTTON_POWER 0x00000001
|
||||
#define BUTTON_HOME 0x00000002
|
||||
#define BUTTON_OPTION 0x00000004
|
||||
#define BUTTON_PREV 0x00000008
|
||||
#define BUTTON_NEXT 0x00000010
|
||||
#define BUTTON_PLAY 0x00000020
|
||||
#define BUTTON_VOL_UP 0x00000040
|
||||
#define BUTTON_VOL_DOWN 0x00000080
|
||||
#define BUTTON_UP 0x00000100
|
||||
#define BUTTON_DOWN 0x00000200
|
||||
|
||||
#define BUTTON_LEFT 0
|
||||
#define BUTTON_RIGHT 0
|
||||
|
||||
#define BUTTON_MAIN (BUTTON_POWER | BUTTON_HOME | BUTTON_OPTION | BUTTON_PREV | \
|
||||
BUTTON_NEXT | BUTTON_PLAY | BUTTON_VOL_UP | BUTTON_VOL_DOWN | \
|
||||
BUTTON_UP | BUTTON_DOWN)
|
||||
|
||||
#define BUTTON_LEFT BUTTON_PREV
|
||||
#define BUTTON_RIGHT BUTTON_NEXT
|
||||
|
||||
/* Software power-off */
|
||||
#define POWEROFF_BUTTON BUTTON_POWER
|
||||
#define POWEROFF_COUNT 25
|
||||
|
||||
#endif /* _BUTTON_TARGET_H_ */
|
||||
|
||||
57
firmware/target/hosted/fiio/buttonlight-fiio.c
Normal file
57
firmware/target/hosted/fiio/buttonlight-fiio.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___
|
||||
* 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 <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"
|
||||
|
||||
static const char * const sysfs_kb_brightness =
|
||||
"/sys/class/jz_pwm_dev/jz_pwm_dev4/duty_ratio";
|
||||
|
||||
static const char * const sysfs_kb_power =
|
||||
"/sys/class/jz_pwm_dev/jz_pwm_dev4/enable";
|
||||
|
||||
void buttonlight_hw_on(void)
|
||||
{
|
||||
sysfs_set_int(sysfs_kb_power, 1);
|
||||
}
|
||||
|
||||
void buttonlight_hw_off(void)
|
||||
{
|
||||
sysfs_set_int(sysfs_kb_power, 0);
|
||||
}
|
||||
|
||||
void buttonlight_hw_brightness(int brightness)
|
||||
{
|
||||
if (brightness > MAX_BRIGHTNESS_SETTING)
|
||||
brightness = MAX_BRIGHTNESS_SETTING;
|
||||
if (brightness < MIN_BRIGHTNESS_SETTING)
|
||||
brightness = MIN_BRIGHTNESS_SETTING;
|
||||
|
||||
sysfs_set_int(sysfs_kb_brightness, brightness);
|
||||
}
|
||||
1
firmware/target/hosted/fiio/debug-fiio.c
Normal file
1
firmware/target/hosted/fiio/debug-fiio.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
#include "../agptek/debug-agptek.c"
|
||||
49
firmware/target/hosted/fiio/fiio.make
Normal file
49
firmware/target/hosted/fiio/fiio.make
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# __________ __ ___.
|
||||
# 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) -Os -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) -Os -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
|
||||
32
firmware/target/hosted/fiio/lcd-target.h
Normal file
32
firmware/target/hosted/fiio/lcd-target.h
Normal 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__
|
||||
|
||||
/* needs special ioctl() to redraw updated framebuffer content */
|
||||
#define LCD_OPTIMIZED_UPDATE
|
||||
#define LCD_OPTIMIZED_UPDATE_RECT
|
||||
|
||||
extern fb_data *framebuffer; /* see lcd-fiio.c */
|
||||
#define LCD_FRAMEBUF_ADDR(col, row) (framebuffer + (row)*LCD_WIDTH + (col))
|
||||
|
||||
extern void lcd_set_active(bool active);
|
||||
#endif /* __LCD_TARGET_H__ */
|
||||
78
firmware/target/hosted/fiio/power-fiio.c
Normal file
78
firmware/target/hosted/fiio/power-fiio.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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 <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "power.h"
|
||||
#include "panic.h"
|
||||
#include "sysfs.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include "power-fiio.h"
|
||||
|
||||
const char * const sysfs_bat_voltage =
|
||||
"/sys/class/power_supply/battery/voltage_now";
|
||||
|
||||
const char * const sysfs_bat_capacity =
|
||||
"/sys/class/power_supply/battery/capacity";
|
||||
|
||||
const char * const sysfs_bat_status =
|
||||
"/sys/class/power_supply/battery/status";
|
||||
|
||||
const char * const sysfs_pow_supply =
|
||||
"/sys/class/power_supply/ac/online";
|
||||
|
||||
unsigned int fiio_power_input_status(void)
|
||||
{
|
||||
int present = 0;
|
||||
sysfs_get_int(sysfs_pow_supply, &present);
|
||||
|
||||
usb_enable(present ? true : false);
|
||||
|
||||
return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
|
||||
}
|
||||
|
||||
bool fiio_power_charging_status(void)
|
||||
{
|
||||
char buf[12] = {0};
|
||||
sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
|
||||
|
||||
return (strncmp(buf, "Charging", 8) == 0);
|
||||
}
|
||||
|
||||
unsigned int fiio_power_get_battery_voltage(void)
|
||||
{
|
||||
int battery_voltage;
|
||||
sysfs_get_int(sysfs_bat_voltage, &battery_voltage);
|
||||
|
||||
return battery_voltage;
|
||||
}
|
||||
|
||||
unsigned int fiio_power_get_battery_capacity(void)
|
||||
{
|
||||
int battery_capacity;
|
||||
sysfs_get_int(sysfs_bat_capacity, &battery_capacity);
|
||||
|
||||
return battery_capacity * 20;
|
||||
}
|
||||
31
firmware/target/hosted/fiio/power-fiio.h
Normal file
31
firmware/target/hosted/fiio/power-fiio.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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_FIIO_H_
|
||||
#define _POWER_FIIO_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "config.h"
|
||||
|
||||
unsigned int fiio_power_input_status(void);
|
||||
bool fiio_power_charging_status(void);
|
||||
unsigned int fiio_power_get_battery_voltage(void);
|
||||
unsigned int fiio_power_get_battery_capacity(void);
|
||||
#endif /* _POWER_FIIO_H_ */
|
||||
|
||||
68
firmware/target/hosted/fiio/powermgmt-fiio.c
Normal file
68
firmware/target/hosted/fiio/powermgmt-fiio.c
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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-fiio.h"
|
||||
|
||||
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
|
||||
{
|
||||
3470
|
||||
};
|
||||
|
||||
/* the OF shuts down at this voltage */
|
||||
const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
|
||||
{
|
||||
3400
|
||||
};
|
||||
|
||||
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
|
||||
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
|
||||
{
|
||||
{ 3400, 3639, 3697, 3723, 3757, 3786, 3836, 3906, 3980, 4050, 4159 }
|
||||
};
|
||||
|
||||
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
|
||||
const unsigned short const percent_to_volt_charge[11] =
|
||||
{
|
||||
3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
|
||||
};
|
||||
|
||||
unsigned int power_input_status(void)
|
||||
{
|
||||
/* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
|
||||
return fiio_power_input_status();
|
||||
}
|
||||
|
||||
int _battery_voltage(void)
|
||||
{
|
||||
return fiio_power_get_battery_voltage();
|
||||
}
|
||||
|
||||
#if 0
|
||||
int _battery_level(void)
|
||||
{
|
||||
return fiio_power_get_battery_capacity();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool charging_state(void)
|
||||
{
|
||||
return fiio_power_charging_status();
|
||||
}
|
||||
205
firmware/target/hosted/fiio/system-fiio.c
Normal file
205
firmware/target/hosted/fiio/system-fiio.c
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <ucontext.h>
|
||||
#include <backtrace.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "mv.h"
|
||||
#include "font.h"
|
||||
#include "power.h"
|
||||
#include "button.h"
|
||||
#include "backlight-target.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#include "panic.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* to make thread-internal.h happy */
|
||||
uintptr_t *stackbegin;
|
||||
uintptr_t *stackend;
|
||||
|
||||
static void sig_handler(int sig, siginfo_t *siginfo, void *context)
|
||||
{
|
||||
/* safe guard variable - we call backtrace() only on first
|
||||
* UIE call. This prevent endless loop if backtrace() touches
|
||||
* memory regions which cause abort
|
||||
*/
|
||||
static bool triggered = false;
|
||||
|
||||
lcd_set_backdrop(NULL);
|
||||
lcd_set_drawmode(DRMODE_SOLID);
|
||||
lcd_set_foreground(LCD_BLACK);
|
||||
lcd_set_background(LCD_WHITE);
|
||||
unsigned line = 0;
|
||||
|
||||
lcd_setfont(FONT_SYSFIXED);
|
||||
lcd_set_viewport(NULL);
|
||||
lcd_clear_display();
|
||||
|
||||
/* get context info */
|
||||
ucontext_t *uc = (ucontext_t *)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);
|
||||
|
||||
if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP)
|
||||
lcd_putsf(0, line++, "address 0x%08x", siginfo->si_addr);
|
||||
|
||||
if(!triggered)
|
||||
{
|
||||
triggered = true;
|
||||
rb_backtrace(pc, sp, &line);
|
||||
}
|
||||
|
||||
#ifdef ROCKBOX_HAS_LOGF
|
||||
lcd_putsf(0, line++, "logf:");
|
||||
logf_panic_dump(&line);
|
||||
#endif
|
||||
|
||||
lcd_update();
|
||||
|
||||
system_exception_wait(); /* If this returns, try to reboot */
|
||||
|
||||
backlight_hw_off();
|
||||
system_reboot();
|
||||
while (1); /* halt */
|
||||
}
|
||||
|
||||
static int axp_hw;
|
||||
|
||||
void power_off(void)
|
||||
{
|
||||
backlight_hw_off();
|
||||
|
||||
axp_hw = open("/dev/axp173", O_RDWR);
|
||||
if(axp_hw < 0)
|
||||
panicf("Cannot open '/dev/axp173'");
|
||||
|
||||
if(ioctl(axp_hw, 0x20003323, 0) < 0)
|
||||
{
|
||||
panicf("Call AXP173_SHUTDOWN fail");
|
||||
}
|
||||
|
||||
close(axp_hw);
|
||||
}
|
||||
|
||||
void system_init(void)
|
||||
{
|
||||
int *s;
|
||||
/* fake stack, to make thread-internal.h happy */
|
||||
stackbegin = stackend = (uintptr_t*)&s;
|
||||
/* catch some signals for easier debugging */
|
||||
struct sigaction sa;
|
||||
sigfillset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sa.sa_sigaction = &sig_handler;
|
||||
sigaction(SIGILL, &sa, NULL);
|
||||
sigaction(SIGABRT, &sa, NULL);
|
||||
sigaction(SIGFPE, &sa, NULL);
|
||||
sigaction(SIGSEGV, &sa, NULL);
|
||||
sigaction(SIGPIPE, &sa, NULL);
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
sigaction(SIGBUS, &sa, NULL);
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
}
|
||||
|
||||
void system_reboot(void)
|
||||
{
|
||||
backlight_hw_off();
|
||||
system("/sbin/reboot");
|
||||
while (1); /* halt */
|
||||
}
|
||||
|
||||
void system_exception_wait(void)
|
||||
{
|
||||
backlight_hw_on();
|
||||
backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
|
||||
/* wait until button press and release */
|
||||
while(button_read_device() != 0) {}
|
||||
while(button_read_device() == 0) {}
|
||||
while(button_read_device() != 0) {}
|
||||
while(button_read_device() == 0) {}
|
||||
}
|
||||
|
||||
bool hostfs_removable(IF_MD_NONVOID(int drive))
|
||||
{
|
||||
#ifdef HAVE_MULTIDRIVE
|
||||
if (drive > 0) /* Active LOW */
|
||||
return true;
|
||||
else
|
||||
#endif
|
||||
return false; /* internal: always present */
|
||||
}
|
||||
|
||||
bool hostfs_present(IF_MD_NONVOID(int drive))
|
||||
{
|
||||
#ifdef HAVE_MULTIDRIVE
|
||||
if (drive > 0) /* Active LOW */
|
||||
return true; //FIXME
|
||||
else
|
||||
#endif
|
||||
return true; /* internal: always present */
|
||||
}
|
||||
|
||||
#ifdef HAVE_MULTIDRIVE
|
||||
int volume_drive(int drive)
|
||||
{
|
||||
return drive;
|
||||
}
|
||||
#endif /* HAVE_MULTIDRIVE */
|
||||
|
||||
#ifdef CONFIG_STORAGE_MULTI
|
||||
int hostfs_driver_type(int drive)
|
||||
{
|
||||
return drive > 0 ? STORAGE_SD_NUM : STORAGE_HOSTFS_NUM;
|
||||
}
|
||||
#endif /* CONFIG_STORAGE_MULTI */
|
||||
|
||||
int hostfs_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hostfs_flush(void)
|
||||
{
|
||||
sync();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_HOTSWAP
|
||||
bool volume_removable(int volume)
|
||||
{
|
||||
/* don't support more than one partition yet, so volume == drive */
|
||||
return hostfs_removable(volume);
|
||||
}
|
||||
|
||||
bool volume_present(int volume)
|
||||
{
|
||||
/* don't support more than one partition yet, so volume == drive */
|
||||
return hostfs_present(volume);
|
||||
}
|
||||
#endif
|
||||
|
||||
28
firmware/target/hosted/fiio/system-target.h
Normal file
28
firmware/target/hosted/fiio/system-target.h
Normal file
|
|
@ -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__ */
|
||||
81
firmware/target/hosted/fiio/usb-fiio.c
Normal file
81
firmware/target/hosted/fiio/usb-fiio.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2018 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 <stdlib.h>
|
||||
#include <sys/mount.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "disk.h"
|
||||
#include "usb.h"
|
||||
#include "sysfs.h"
|
||||
#include "power.h"
|
||||
#include "power-fiio.h"
|
||||
|
||||
const char * const sysfs_usb_online =
|
||||
"/sys/class/power_supply/usb/online";
|
||||
|
||||
int usb_detect(void)
|
||||
{
|
||||
int present = 0;
|
||||
sysfs_get_int(sysfs_usb_online, &present);
|
||||
|
||||
return present ? USB_INSERTED : USB_EXTRACTED;
|
||||
}
|
||||
|
||||
void usb_enable(bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/libcomposite.ko");
|
||||
system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/usb_f_mass_storage.ko");
|
||||
system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/g_mass_storage.ko file=/dev/mmcblk0 removable=1");
|
||||
}
|
||||
else
|
||||
{
|
||||
system ("rmmod g_mass_storage");
|
||||
system ("rmmod usb_f_mass_storage");
|
||||
system ("rmmod libcomposite");
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void usb_init_device(void)
|
||||
{
|
||||
system ("insmod /lib/modules/3.10.14/kernel/driver/staging/dwc2/dwc2.ko");
|
||||
usb_enable(true);
|
||||
}
|
||||
|
|
@ -36,9 +36,14 @@
|
|||
#include "rbpaths.h"
|
||||
#include "logf.h"
|
||||
|
||||
#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR))
|
||||
#define PIVOT_ROOT HOME_DIR
|
||||
#if !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR))
|
||||
#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20))
|
||||
#define PIVOT_ROOT "/mnt/sd_0"
|
||||
#elif defined(FIIO_M3K)
|
||||
#define PIVOT_ROOT "/mnt" // XXX check this!
|
||||
#else
|
||||
#endif
|
||||
#endif // !(BOOTLOADER|WPS|SIM)
|
||||
|
||||
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
||||
static const char rbhome[] = "/sdcard";
|
||||
|
|
@ -52,7 +57,7 @@ static const char rbhome[] = HOME_DIR;
|
|||
|
||||
#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \
|
||||
defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER) || \
|
||||
defined(XDUOO_X3II) || defined(XDUOO_X20)) && \
|
||||
defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K) || defined(FIIO_M3K_PRO)) && \
|
||||
!defined(__PCTOOL__)
|
||||
/* Special dirs are user-accessible (and user-writable) dirs which take priority
|
||||
* over the ones where Rockbox is installed to. Classic example would be
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue