Agptek Rocker: Initial commit

Change-Id: I26b51106c7b1c36a603fba6d521e917d79b5a95b
This commit is contained in:
Marcin Bukat 2017-04-27 11:36:40 +02:00
parent beef52c5f0
commit d55680993d
50 changed files with 2343 additions and 74 deletions

View file

@ -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 <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"
static const char * const sysfs_bl_brightness =
"/sys/class/backlight/pwm-backlight.0/brightness";
static const char * const sysfs_bl_power =
"/sys/class/backlight/pwm-backlight.0/bl_power";
bool backlight_hw_init(void)
{
backlight_hw_on();
backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
return true;
}
void backlight_hw_on(void)
{
sysfs_set_int(sysfs_bl_power, 0);
}
void backlight_hw_off(void)
{
sysfs_set_int(sysfs_bl_power, 1);
}
void backlight_hw_brightness(int brightness)
{
/* cap range, just in case */
if (brightness > MAX_BRIGHTNESS_SETTING)
brightness = MAX_BRIGHTNESS_SETTING;
if (brightness < MIN_BRIGHTNESS_SETTING)
brightness = MIN_BRIGHTNESS_SETTING;
sysfs_set_int(sysfs_bl_brightness, brightness);
}

View file

@ -0,0 +1,36 @@
/***************************************************************************
* __________ __ ___
* 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.
*
****************************************************************************/
#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);
#endif

View file

@ -0,0 +1,149 @@
/***************************************************************************
* __________ __ ___
* 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 <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"
#define NR_POLL_DESC 2
static struct pollfd poll_fds[NR_POLL_DESC];
static int button_map(int keycode)
{
switch(keycode)
{
case KEY_LEFT:
return BUTTON_LEFT;
case KEY_RIGHT:
return BUTTON_RIGHT;
case KEY_UP:
return BUTTON_UP;
case KEY_DOWN:
return BUTTON_DOWN;
case KEY_PLAYPAUSE:
return BUTTON_SELECT;
case KEY_VOLUMEUP:
return BUTTON_VOLUP;
case KEY_VOLUMEDOWN:
return BUTTON_VOLDOWN;
case KEY_POWER:
return BUTTON_POWER;
default:
return 0;
}
}
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;
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))
{
int keycode = event.code;
/* event.value == 0x10000 means press
* event.value == 0 means release
*/
bool press = event.value ? true : false;
/* map linux event code to rockbox button bitmap */
if(press)
{
button_bitmap |= button_map(keycode);
}
else
{
button_bitmap &= ~button_map(keycode);
}
}
}
}
}
return button_bitmap;
}
bool headphones_inserted(void)
{
int status = 0;
const char * const sysfs_hp_switch = "/sys/devices/switch/headset/status";
sysfs_get_int(sysfs_hp_switch, &status);
return status ? true : false;
}
void button_close_device(void)
{
/* close descriptors */
for(int i = 0; i < NR_POLL_DESC; i++)
{
close(poll_fds[i].fd);
}
}

View file

@ -0,0 +1,43 @@
/***************************************************************************
* __________ __ ___.
* 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 <stdbool.h>
#include "config.h"
/* Main unit's buttons */
#define BUTTON_LEFT 0x00000001
#define BUTTON_RIGHT 0x00000002
#define BUTTON_UP 0x00000004
#define BUTTON_DOWN 0x00000008
#define BUTTON_SELECT 0x00000010
#define BUTTON_VOLDOWN 0x00000020
#define BUTTON_VOLUP 0x00000040
#define BUTTON_POWER 0x00000080
#define BUTTON_MAIN 0x000000ff
/* Software power-off */
#define POWEROFF_BUTTON BUTTON_POWER
#define POWEROFF_COUNT 10
#endif /* _BUTTON_TARGET_H_ */

View file

@ -0,0 +1,6 @@
#include <stdbool.h>
bool debug_hw_info(void)
{
return false;
}

View file

@ -0,0 +1,111 @@
/***************************************************************************
* __________ __ ___.
* 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 <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "lcd.h"
#include "lcd-target.h"
#include "backlight-target.h"
#include "panic.h"
static int fd = -1;
static struct fb_var_screeninfo vinfo;
fb_data *framebuffer = 0; /* global variable, see lcd-target.h */
void lcd_init_device(void)
{
const char * const fb_dev = "/dev/fb0";
fd = open(fb_dev, O_RDWR);
if(fd < 0)
{
panicf("Cannot open framebuffer: %s\n", fb_dev);
}
/* get fixed and variable information */
struct fb_fix_screeninfo finfo;
if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0)
{
panicf("Cannot read framebuffer fixed information");
}
if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
{
panicf("Cannot read framebuffer variable information");
}
#if 0
/* check resolution and framebuffer size */
if(vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT || vinfo.bits_per_pixel != LCD_DEPTH)
{
panicf("Unexpected framebuffer resolution: %dx%dx%d\n", vinfo.xres,
vinfo.yres, vinfo.bits_per_pixel);
}
#endif
/* Note: we use a framebuffer size of width*height*bbp. We cannot trust the
* values returned by the driver for line_length */
/* map framebuffer */
framebuffer = mmap(0, FRAMEBUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if((void *)framebuffer == MAP_FAILED)
{
panicf("Cannot map framebuffer");
}
}
static void redraw(void)
{
ioctl(fd, FBIOPAN_DISPLAY, &vinfo);
}
extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
int width, int height);
void lcd_update(void)
{
/* Copy the Rockbox framebuffer to the second framebuffer */
lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), FBADDR(0,0),
LCD_WIDTH*LCD_HEIGHT, 1);
redraw();
}
void lcd_update_rect(int x, int y, int width, int height)
{
fb_data *dst = LCD_FRAMEBUF_ADDR(x, y);
fb_data * src = FBADDR(x,y);
/* Copy part of the Rockbox framebuffer to the second framebuffer */
if (width < LCD_WIDTH)
{
/* Not full width - do line-by-line */
lcd_copy_buffer_rect(dst, src, width, height);
}
else
{
/* Full width - copy as one line */
lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
}
redraw();
}

View file

@ -0,0 +1,26 @@
/***************************************************************************
* __________ __ ___.
* 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__
extern fb_data *framebuffer; /* see lcd-nwz.c */
#define LCD_FRAMEBUF_ADDR(col, row) (framebuffer + (row)*LCD_WIDTH + (col))
#endif /* __LCD_TARGET_H__ */

View file

@ -0,0 +1,59 @@
/***************************************************************************
* __________ __ ___.
* 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-agptek.h"
#include "power.h"
#include "panic.h"
#include "sysfs.h"
const char * const sysfs_bat_voltage =
"/sys/class/power_supply/battery/voltage_now";
const char * const sysfs_bat_status =
"/sys/class/power_supply/battery/status";
unsigned int agptek_power_get_status(void)
{
char buf[12] = {0};
sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
if (strncmp(buf, "Charging", 8) == 0)
{
return POWER_INPUT_USB_CHARGER;
}
else
{
return POWER_INPUT_NONE;
}
}
unsigned int agptek_power_get_battery_voltage(void)
{
int battery_voltage;
sysfs_get_int(sysfs_bat_voltage, &battery_voltage);
return battery_voltage/1000;
}

View file

@ -0,0 +1,29 @@
/***************************************************************************
* __________ __ ___.
* 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_AGPTEK_H_
#define _POWER_AGPTEK_H_
#include <stdbool.h>
#include "config.h"
unsigned int agptek_power_get_status(void);
unsigned int agptek_power_get_battery_voltage(void);
#endif /* _POWER_AGPTEK_H_ */

View file

@ -0,0 +1,63 @@
/***************************************************************************
* __________ __ ___.
* 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-agptek.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
* NOTE: not calibrated simple linear scale for now
*/
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{
{ 3400, 3480, 3560, 3640, 3720, 3800, 3880, 3960, 4040, 4120, 4200 }
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
const unsigned short const percent_to_volt_charge[11] =
{
3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200
};
unsigned int power_input_status(void)
{
/* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
return agptek_power_get_status();
}
int _battery_voltage(void)
{
return agptek_power_get_battery_voltage();
}
bool charging_state(void)
{
return agptek_power_get_status() == POWER_INPUT_USB_CHARGER;
}

View file

@ -0,0 +1,48 @@
# __________ __ ___.
# 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
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)/rockbox.rocker : $(BUILDDIR)/rockbox.elf
$(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
endif

View file

@ -0,0 +1,186 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50
* Copyright (C) 2014 by Mario Basister: iBasso DX90 port
* Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features
* Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features
*
* 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 <stdio.h>
#include <string.h>
#include "config.h"
#include "debug.h"
#include "sysfs.h"
static FILE* open_read(const char *file_name)
{
FILE *f = fopen(file_name, "r");
if(f == NULL)
{
DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name);
}
return f;
}
static FILE* open_write(const char* file_name)
{
FILE *f = fopen(file_name, "w");
if(f == NULL)
{
DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
}
return f;
}
bool sysfs_get_int(const char *path, int *value)
{
*value = -1;
FILE *f = open_read(path);
if(f == NULL)
{
return false;
}
bool success = true;
if(fscanf(f, "%d", value) == EOF)
{
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
success = false;
}
fclose(f);
return success;
}
bool sysfs_set_int(const char *path, int value)
{
FILE *f = open_write(path);
if(f == NULL)
{
return false;
}
bool success = true;
if(fprintf(f, "%d", value) < 1)
{
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
success = false;
}
fclose(f);
return success;
}
bool sysfs_get_char(const char *path, char *value)
{
*value = '\0';
FILE *f = open_read(path);
if(f == NULL)
{
return false;
}
bool success = true;
if(fscanf(f, "%c", value) == EOF)
{
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
success = false;
}
fclose(f);
return success;
}
bool sysfs_set_char(const char *path, char value)
{
FILE *f = open_write(path);
if(f == NULL)
{
return false;
}
bool success = true;
if(fprintf(f, "%c", value) < 1)
{
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
success = false;
}
fclose(f);
return success;
}
bool sysfs_get_string(const char *path, char *value, int size)
{
value[0] = '\0';
FILE *f = open_read(path);
if(f == NULL)
{
return false;
}
bool success = true;
if(fgets(value, size, f) == NULL)
{
DEBUGF("ERROR %s: Read failed for %s.", __func__, path);
success = false;
}
else
{
size_t length = strlen(value);
if((length > 0) && value[length - 1] == '\n')
{
value[length - 1] = '\0';
}
}
fclose(f);
return success;
}
bool sysfs_set_string(const char *path, char *value)
{
FILE *f = open_write(path);
if(f == NULL)
{
return false;
}
bool success = true;
if(fprintf(f, "%s", value) < 1)
{
DEBUGF("ERROR %s: Write failed for %s.", __func__, path);
success = false;
}
fclose(f);
return success;
}

View file

@ -0,0 +1,31 @@
/***************************************************************************
* __________ __ ___
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50
* Copyright (C) 2014 by Mario Basister: iBasso DX90 port
* Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features
* Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features
*
* 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 <stdbool.h>
bool sysfs_get_int(const char *path, int *value);
bool sysfs_set_int(const char *path, int value);
bool sysfs_get_char(const char *path, char *value);
bool sysfs_set_char(const char *path, char value);
bool sysfs_get_string(const char *path, char *value, int size);
bool sysfs_set_string(const char *path, char *value);

View file

@ -0,0 +1,184 @@
/***************************************************************************
* __________ __ ___.
* 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"
/* 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 */
system_reboot();
while (1); /* halt */
}
void power_off(void)
{
system("/sbin/poweroff");
}
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)
{
system("/sbin/reboot");
}
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

View 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__ */