refactor plat.h, add gamma

This commit is contained in:
notaz 2012-11-05 00:02:03 +02:00
parent 6ce097ba2f
commit a1b30e1a4a
2 changed files with 133 additions and 65 deletions

View file

@ -105,50 +105,26 @@ static void scan_for_filters(void)
}
closedir(dir);
plat_target.filters = mfilters;
plat_target.hwfilters = mfilters;
}
static void set_lcdrate(int is_pal)
static int do_system(const char *cmd)
{
static int old_pal = -1;
char buf[128];
int ret;
if (is_pal == old_pal)
return;
ret = system(cmd);
if (ret >= 0)
ret = 0;
snprintf(buf, sizeof(buf), "%s/op_lcdrate.sh %d",
pnd_script_base, is_pal ? 50 : 60);
system(buf);
old_pal = is_pal;
return ret;
}
static void set_filter(int which)
{
static int old_filter = -1;
char buf[128];
int i;
if (plat_target.filters == NULL || which == old_filter)
return;
for (i = 0; i < which; i++)
if (plat_target.filters[i] == NULL)
return;
if (plat_target.filters[i] == NULL)
return;
snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s",
pnd_script_base, plat_target.filters[i]);
system(buf);
old_filter = which;
}
static int cpu_clock_get(void)
static int read_int_from_file(const char *fname)
{
int ret = -1;
FILE *f;
int ret = 0;
f = fopen("/proc/pandora/cpu_mhz_max", "r");
f = fopen(fname, "r");
if (f) {
fscanf(f, "%d", &ret);
fclose(f);
@ -156,37 +132,85 @@ static int cpu_clock_get(void)
return ret;
}
static int lcdrate_set(int is_pal)
{
static int old_pal = -1;
char buf[128];
if (is_pal == old_pal)
return 0;
old_pal = is_pal;
snprintf(buf, sizeof(buf), "%s/op_lcdrate.sh %d",
pnd_script_base, is_pal ? 50 : 60);
return do_system(buf);
}
static int hwfilter_set(int which)
{
static int old_filter = -1;
char buf[128];
int i;
if (plat_target.hwfilters == NULL)
return -1;
if (which == old_filter)
return 0;
for (i = 0; i <= which; i++)
if (plat_target.hwfilters[i] == NULL)
return -1;
old_filter = which;
snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s",
pnd_script_base, plat_target.hwfilters[which]);
return do_system(buf);
}
static int cpu_clock_get(void)
{
return read_int_from_file("/proc/pandora/cpu_mhz_max");
}
static int cpu_clock_set(int cpu_clock)
{
char buf[128];
if (cpu_clock != 0 && cpu_clock != cpu_clock_get()) {
snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
pnd_script_base, cpu_clock);
system(buf);
}
return 0;
if (cpu_clock < 14)
return -1;
if (cpu_clock == cpu_clock_get())
return 0;
snprintf(buf, sizeof(buf),
"unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
pnd_script_base, cpu_clock);
return do_system(buf);
}
static int get_bat_capacity(void)
static int bat_capacity_get(void)
{
FILE *f;
int ret = 0;
f = fopen("/sys/class/power_supply/bq27500-0/capacity", "r");
if (f) {
fscanf(f, "%d", &ret);
fclose(f);
}
return ret;
return read_int_from_file("/sys/class/power_supply/bq27500-0/capacity");
}
static int gamma_set(int val, int black_level)
{
char buf[128];
snprintf(buf, sizeof(buf), "%s/op_gamma.sh -b %d %.2f",
pnd_script_base, black_level, (float)val / 100.0f);
return do_system(buf);
}
struct plat_target plat_target = {
cpu_clock_get,
cpu_clock_set,
get_bat_capacity,
set_filter,
NULL,
set_lcdrate,
bat_capacity_get,
hwfilter_set,
lcdrate_set,
gamma_set,
};
int plat_target_init(void)

66
plat.h
View file

@ -9,11 +9,12 @@ extern "C" {
struct plat_target {
int (*cpu_clock_get)(void);
int (*cpu_clock_set)(int clock);
int (*get_bat_capacity)(void);
void (*set_filter)(int which);
char **filters;
void (*set_lcdrate)(int is_pal);
void (*step_volume)(int is_up);
int (*bat_capacity_get)(void);
int (*hwfilter_set)(int which);
int (*lcdrate_set)(int is_pal);
int (*gamma_set)(int val, int black_level);
int (*step_volume)(int is_up);
char **hwfilters;
};
extern struct plat_target plat_target;
@ -21,16 +22,59 @@ int plat_target_init(void);
void plat_target_finish(void);
void plat_target_setup_input(void);
static __inline void plat_target_set_filter(int which)
/* CPU clock in MHz */
static __inline int plat_target_cpu_clock_get(void)
{
if (plat_target.set_filter)
plat_target.set_filter(which);
if (plat_target.cpu_clock_get)
return plat_target.cpu_clock_get();
return -1;
}
static __inline void plat_target_set_lcdrate(int is_pal)
static __inline int plat_target_cpu_clock_set(int mhz)
{
if (plat_target.set_lcdrate)
plat_target.set_lcdrate(is_pal);
if (plat_target.cpu_clock_set)
return plat_target.cpu_clock_set(mhz);
return -1;
}
/* battery capacity (0-100) */
static __inline int plat_target_bat_capacity_get(void)
{
if (plat_target.bat_capacity_get)
return plat_target.bat_capacity_get();
return -1;
}
/* set some hardware-specific video filter, 0 for none */
static __inline int plat_target_hwfilter_set(int which)
{
if (plat_target.hwfilter_set)
return plat_target.hwfilter_set(which);
return -1;
}
/* set device LCD rate, is_pal 0 for NTSC, 1 for PAL compatible */
static __inline int plat_target_lcdrate_set(int is_pal)
{
if (plat_target.lcdrate_set)
return plat_target.lcdrate_set(is_pal);
return -1;
}
/* set device LCD rate, is_pal 0 for NTSC, 1 for PAL compatible */
static __inline int plat_target_gamma_set(int val, int black_level)
{
if (plat_target.gamma_set)
return plat_target.gamma_set(val, black_level);
return -1;
}
/* step sound volume up or down */
static __inline int plat_target_step_volume(int is_up)
{
if (plat_target.step_volume)
return plat_target.step_volume(is_up);
return -1;
}
/* menu: enter (switch bpp, etc), begin/end drawing */