2019-07-18 13:42:00 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
############################################################################
|
|
|
|
# __________ __ ___.
|
|
|
|
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
# \/ \/ \/ \/ \/
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 by William Wilgus
|
|
|
|
#
|
|
|
|
# All files in this archive are subject to the GNU General Public License.
|
|
|
|
# See the file COPYING in the source tree root for full license agreement.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
#rockbox to lua define generator, add names of constants to the array to include
|
|
|
|
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
if ($#ARGV + 1 != 1) {
|
|
|
|
warn "no definition type defined";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $def_type = $ARGV[0];
|
|
|
|
#warn "$def_type\n";
|
|
|
|
my $lua_table;
|
|
|
|
my @rockbox_defines;
|
|
|
|
|
|
|
|
if ($def_type eq "rb_defines") {
|
|
|
|
$lua_table = "rb";
|
|
|
|
@rockbox_defines = (
|
|
|
|
'^HZ$',
|
|
|
|
'^LCD_(DEPTH|HEIGHT|WIDTH)$',
|
|
|
|
'^MODEL_NAME$',
|
|
|
|
'^SCREEN_MAIN$',
|
|
|
|
'^LCD_DEFAULT_(FG|BG)$',
|
|
|
|
'^LCD_REMOTE_(DEPTH|HEIGHT|WIDTH)$',
|
|
|
|
'^LCD_.+(BRIGHT|DARK)COLOR',
|
|
|
|
'^SCREEN_REMOTE$',
|
|
|
|
'^FONT_SYSFIXED$',
|
|
|
|
'^FONT_UI$',
|
|
|
|
'^PLAYBACK_EVENT_.*',
|
|
|
|
'^PLAYLIST_(INSERT|PREPEND|REPLACE)',
|
|
|
|
'^TOUCHSCREEN_(POINT|BUTTON)$',
|
|
|
|
'^SYS_CHARGER_(DIS|)CONNECTED$',
|
2021-04-24 03:55:16 +00:00
|
|
|
'^SYS_(TIMEOUT|POWEROFF|BATTERY_UPDATE)$',
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
'^SYS_USB_(DIS|)CONNECTED$',
|
|
|
|
'^HOME_DIR$',
|
2021-10-22 02:26:27 +00:00
|
|
|
'^PLUGIN(_OK|_USB_CONNECTED|_POWEROFF|_GOTO_WPS|_GOTO_PLUGIN)$',
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
'^PLUGIN_DIR$',
|
|
|
|
'^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$',
|
|
|
|
'^ROCKBOX_DIR$',
|
2021-04-10 03:11:31 +00:00
|
|
|
'^STYLE_(NONE|DEFAULT|INVERT|COLORBAR|GRADIENT|COLORED)',
|
Add custom action mapping to core
results of an idea I discussed in IRC
changed the way the lookup in the remap file works..
entries consist of 3 int [action, button, prebtn]
context look up table is at the beginning
action_code contains the (context | CONTEXT_REMAPPED)
button_code contains the index of the first remapped action for the matched context
[0] CORE_CONTEXT_REMAP(ctx1) offset1=(3), count=(1)
[1] CORE_CONTEXT_REMAP(ctx2, offset2=(5), count=(1)
[2] sentinel, 0, 0
[3] act0, btn, 0
[4] sentinel 0, 0
[5] act1, btn, 0
[6] sentinel, 0, 0
Note:
last entry of each group is always the sentinel [CONTEXT_STOPSEARCHING, BUTTON_NONE, BUTTON_NONE]
contexts must match exactly -- re-mapped contexts run before the built in w/ fall through contexts
ie. you can't remap std_context and expect it to match std_context actions from the WPS context.
-- Done --
Code for reading core remap entries
-- Done --
import of core remap entires from disk
-- Done --
plugin to set new key mapping (the hard part)
The plugin is started and FULLY functional
you can add actions and contexts
you can change context, action, button, prebtn
delete keymap files
load keymapfiles
save user keymaps
test keymaps before applying them
loading keymaps to core still requires restart
-----------------------------------------------------------------------------------------------
Change-Id: Ib8b88c5ae91af4d540e1829de5db32669cd68203
2021-04-03 01:34:29 +00:00
|
|
|
'^CORE_KEYMAP_FILE$',
|
|
|
|
'CONTEXT_(STOPSEARCHING|REMOTE|CUSTOM|CUSTOM2|PLUGIN|REMAPPED)$',
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
'^VIEWERS_DATA_DIR$');
|
|
|
|
}
|
|
|
|
elsif ($def_type eq "sound_defines") {
|
|
|
|
$lua_table = "rb.sound_settings";
|
|
|
|
@rockbox_defines = (
|
|
|
|
'^(?!.*LAST_SETTING)SOUND_');
|
|
|
|
}
|
2019-07-18 13:42:00 +00:00
|
|
|
|
|
|
|
my @captured_defines;
|
|
|
|
my @names_seen;
|
|
|
|
my @all_defines;
|
|
|
|
|
|
|
|
############# precompile regex for speed #############
|
|
|
|
my $def_regex = qr/#define\s+([^\s\r\n]+)\s+([^\r\n]+)/;
|
|
|
|
my $quot_regex = qr/.*([\"\']).*/;
|
|
|
|
my $num_regex = qr/.*([\+\-\*\\|&\d]).*/;
|
2019-07-18 14:41:38 +00:00
|
|
|
my $configh_regex = qr/^\s*#define\s*__CONFIG_H__\s*$/;
|
|
|
|
my $config_h = "?";
|
|
|
|
my $exclude_regex = qr/^#define\s*_?POSIX.*/;
|
|
|
|
my $exclude_enum_regex = qr/^#define\s*(_SC_|_PC_|_CS_).*/;
|
2019-07-18 13:42:00 +00:00
|
|
|
print <<EOF
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#define stringify(s) #s
|
|
|
|
|
|
|
|
/* auto generated defines */
|
|
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
;
|
|
|
|
|
|
|
|
while(my $line = <STDIN>)
|
|
|
|
{
|
2019-07-18 14:41:38 +00:00
|
|
|
if($config_h eq "?" && $line =~ $configh_regex) { $config_h = $line; }
|
|
|
|
next if($config_h eq "?"); #don't capture till we get to the config file
|
|
|
|
next if($line =~ $exclude_regex);
|
|
|
|
|
2019-07-18 13:42:00 +00:00
|
|
|
if($line =~ $def_regex) #does it begin with #define?
|
|
|
|
{
|
|
|
|
push(@all_defines, $line); #save all defines for possible ambiguous macros
|
|
|
|
$name = $1;
|
|
|
|
next if $name =~ /^(ATTRIBUTE_|print|__).*/; #don't add reserved
|
|
|
|
$value = $2;
|
|
|
|
|
|
|
|
if(grep($name =~ $_, @rockbox_defines))
|
|
|
|
{
|
|
|
|
push(@names_seen, $name);
|
|
|
|
push(@captured_defines, {'name' => $name, 'value' => $value});
|
|
|
|
print $line
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$name =~ s{(\(.*\))}{}gx; #remove (...) on function type macros
|
|
|
|
#ifndef guard so we don't clash with the host
|
|
|
|
printf "#ifndef %s\n%s#endif\n\n", $name, $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif($line =~ /^(?!.*;)enum.*{/) #enum {
|
|
|
|
{
|
2019-07-18 14:41:38 +00:00
|
|
|
next if($line =~ /enum\s*__.*/); #don't add reserved
|
2019-07-18 13:42:00 +00:00
|
|
|
print $line;
|
|
|
|
next if($line =~ /.*};.*/);
|
|
|
|
do_enum($line)
|
|
|
|
}
|
|
|
|
elsif($line =~ /^(?!.*[;\(\)])enum.*/) #enum
|
|
|
|
{
|
2019-07-18 14:41:38 +00:00
|
|
|
next if($line =~ /enum\s*__.*/); #don't add reserved
|
2019-07-18 13:42:00 +00:00
|
|
|
#need to be careful might be a function returning enum
|
|
|
|
my $lastline = $line;
|
|
|
|
next if($line =~ /.*};.*/);
|
|
|
|
($line = <STDIN>);
|
|
|
|
if($line =~ /.*{.*/)
|
|
|
|
{
|
|
|
|
print $lastline;
|
|
|
|
print $line;
|
|
|
|
}
|
|
|
|
else { next; }
|
|
|
|
do_enum($line)
|
|
|
|
}
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
elsif($line =~ /^enum.*{[^;]+};.*/) #enum {
|
|
|
|
{
|
|
|
|
next if($line =~ /enum\s*__.*/); #don't add reserved
|
|
|
|
next if(do_enum($line));
|
|
|
|
|
|
|
|
}
|
2019-07-18 13:42:00 +00:00
|
|
|
}
|
2019-07-18 14:41:38 +00:00
|
|
|
#warn "total defines: ".scalar @all_defines;
|
|
|
|
#warn "captured defines: ".scalar @captured_defines;
|
2019-07-18 13:42:00 +00:00
|
|
|
#Sort the functions
|
|
|
|
my @sorted_defines = sort { @$a{'name'} cmp @$b{'name'} } @captured_defines;
|
|
|
|
|
|
|
|
printf "int main(void)\n{\n";
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
printf "\tprintf(\"--[[Autogenerated rockbox constants]]\\n\\n\");\n\n";
|
|
|
|
printf "\tprintf(\"%s = %s or {}\\n\");\n", $lua_table, $lua_table;
|
2019-07-18 13:42:00 +00:00
|
|
|
# Print the C array
|
|
|
|
foreach my $define (@sorted_defines)
|
|
|
|
{
|
|
|
|
if(@$define{'value'} =~ /^0[xX][0-9a-fA-F]+$/) #hex number
|
|
|
|
{
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
printf "\tprintf(\"%s[\\\"%%s\\\"] = 0x%%x\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
|
2019-07-18 13:42:00 +00:00
|
|
|
}
|
|
|
|
elsif(@$define{'value'} =~ /^[0-9]+$/) #number
|
|
|
|
{
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
printf "\tprintf(\"%s[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
|
2019-07-18 13:42:00 +00:00
|
|
|
}
|
|
|
|
else #might be a string but we don't know since the macro isn't expanded far enough
|
|
|
|
{
|
|
|
|
my $max_depth = 10;
|
|
|
|
my $var = @$define{'value'};
|
|
|
|
while($max_depth > 0) #follow the chain of #defines until we can see what type
|
|
|
|
{
|
|
|
|
$max_depth--;
|
|
|
|
$var = "\\\s*#define\\s+$var\\s+.*";
|
|
|
|
#warn $var;
|
|
|
|
if(my ($x) = grep($_ =~ /($var)/, @all_defines)) #check all the defines
|
|
|
|
{
|
|
|
|
#warn $x;
|
|
|
|
if($x =~ $def_regex)
|
|
|
|
{
|
|
|
|
$var = $2;
|
|
|
|
#warn $var;
|
|
|
|
last if ($var =~ $quot_regex);
|
|
|
|
last if ($var =~ $num_regex);
|
|
|
|
next
|
|
|
|
}
|
|
|
|
#warn "end ".$var;
|
|
|
|
last
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$var = @$define{'value'};
|
|
|
|
last
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($var =~$quot_regex) #has a quote it is a string
|
|
|
|
{
|
|
|
|
#guard with empty literals "" so gcc throws an error if it isn't a string
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
printf "\tprintf(\"%s[\\\"%%s\\\"] = \\\"%%s\\\"\\n\", stringify(%s), \"\" %s \"\");\n", $lua_table, @$define{'name'}, @$define{'name'};
|
2019-07-18 13:42:00 +00:00
|
|
|
}
|
|
|
|
elsif ($var =~$num_regex) #it must be a number
|
|
|
|
{
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
printf "\tprintf(\"%s[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
|
2019-07-18 13:42:00 +00:00
|
|
|
}
|
|
|
|
else { warn "Skipping ".@$define{'name'}." indeterminate macro type\n"; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print <<EOF
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOF
|
|
|
|
;
|
|
|
|
|
|
|
|
sub do_enum {
|
|
|
|
my ($line) = @_;
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
if($line =~ /.*enum.*{(.*)};.*/) #single line enums
|
|
|
|
{
|
|
|
|
print $line;
|
|
|
|
$value = "0"; #enums are always integers
|
|
|
|
my $enum = $1;
|
|
|
|
$enum =~ s/\s+//g;;
|
|
|
|
my @values = split(',', $enum);
|
|
|
|
|
|
|
|
foreach my $name(@values) {
|
|
|
|
if(grep($name =~ $_, @rockbox_defines))
|
|
|
|
{
|
|
|
|
push(@names_seen, $name);
|
|
|
|
push(@captured_defines, {'name' => $name, 'value' => $value});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2019-07-18 13:42:00 +00:00
|
|
|
|
|
|
|
while($line = <STDIN>)
|
|
|
|
{
|
2019-07-18 14:41:38 +00:00
|
|
|
next if($line =~ $exclude_enum_regex);
|
2019-07-18 13:42:00 +00:00
|
|
|
if($line =~ /.*};.*/)
|
|
|
|
{
|
|
|
|
print $line;
|
|
|
|
last
|
|
|
|
}
|
|
|
|
elsif($line =~ /([^\s,\t]+)\s*=?.*,?/)
|
|
|
|
{
|
|
|
|
$name = $1;
|
|
|
|
#printf "%s WHATTT?", $name;
|
|
|
|
$value = "0"; #enums are always integers
|
|
|
|
}
|
|
|
|
print $line;
|
|
|
|
if(grep($name =~ $_, @rockbox_defines))
|
|
|
|
{
|
|
|
|
push(@names_seen, $name);
|
|
|
|
push(@captured_defines, {'name' => $name, 'value' => $value});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
lua add sound_current, consolidate sound_ functions
add defines for sound functions
SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
defines depend on target
require "sound_defines" to add them to rb.sound_settings[]
consolidates:
sound_set, sound_current, sound_default, sound_min, sound_max,
sound_unit, sound_pitch, sound_val2phys to a single function
rb.sound("name", setting, [value])
require "sound.lua" for old functionality
Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 15:17:40 +00:00
|
|
|
return 0;
|
2019-07-18 13:42:00 +00:00
|
|
|
}
|