twl_wrapsdk/build/libraries/camera/ARM7/convert_micron.pl
yutaka 26024f0a5a renewal of camera library (framework only)
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@185 4ee2a332-4b2b-5046-8439-1ba90f034370
2007-07-10 10:54:13 +00:00

211 lines
5.3 KiB
Perl
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/perl --
use strict;
my $file_head_format =<<'EOF';
/*---------------------------------------------------------------------------*
Project: TwlSDK - libraties - camera
File: %1$s
Copyright 2007 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Log: $
$NoKeywords: $
*---------------------------------------------------------------------------*/
#include <nitro/os/common/thread.h>
#include <twl/camera/ARM7/i2c_micron.h>
//#define PRINT_DEBUG
#ifdef PRINT_DEBUG
#include <nitro/os/common/printf.h>
#define DBG_PRINTF OS_TPrintf
#else
#define DBG_PRINTF( ... ) ((void)0)
#define DBG_CHAR( c ) ((void)0)
#endif
EOF
my $file_foot_format =<<'EOF';
EOF
my $declare_format =<<'EOF';
BOOL CAMERAi_M_%s( CameraSelect camera );
EOF
my $func_head_format =<<'EOF';
BOOL CAMERAi_M_%s( CameraSelect camera )
{
EOF
my $func_foot_format =<<'EOF';
return TRUE;
}
EOF
my $call_format =<<'EOF';
if (CAMERAi_M_%1$s(camera) == FALSE) {%2$s
DBG_PRINTF("Failed to call CAMERAi_M_%1$s! (%%d)\n", __LINE__);
return FALSE;
}
EOF
my $reg_format =<<'EOF';
if (CAMERAi_M_WriteRegister(camera, %s, %s) == FALSE) {%s
DBG_PRINTF("Failed to write a register! (%%d)\n", __LINE__);
return FALSE;
}
EOF
my $set_format =<<'EOF';
if (CAMERAi_M_SetFlags(camera, %s, %s) == FALSE) {%s
DBG_PRINTF("Failed to set a register! (%%d)\n", __LINE__);
return FALSE;
}
EOF
my $clear_format =<<'EOF';
if (CAMERAi_M_ClearFlags(camera, %s, %s) == FALSE) {%s
DBG_PRINTF("Failed to clear a register! (%%d)\n", __LINE__);
return FALSE;
}
EOF
my $sleep_format =<<'EOF';
OS_Sleep(%s);%s
EOF
my $poolreg_format =<<'EOF';
i = %5$s;%6$s
while (1)
{
u16 data;
if (CAMERAi_M_ReadRegisters(camera, %1$s, &data, 1) == FALSE) {
DBG_PRINTF("Failed to read a register! (%%d)\n", __LINE__);
return FALSE;
}
if ((data & %2$s) %3$s)
{
if (--i)
{
OS_Sleep(%4$s);
continue;
}
DBG_PRINTF("Failed to poll a register! (%%d)\n", __LINE__);
return FALSE;
}
break;
}
EOF
my @functions = ({name => "", data => "", declare => ""}); # API
sub name_conv {
$_ = $_[0];
s/\>/To/g;
s/[\s\.\:\+\-\=\*\/]+/_/g;
return $_;
}
sub func_conv {
my($key, $value, $comment) = @_;
$comment = " " . $comment; # insert spaces
if ($key eq "LOAD") {
return sprintf($call_format, name_conv($value), $comment);
}
elsif ($key eq "REG") {
my($reg, $val) = split /\s*\,\s*/, $value;
return sprintf($reg_format, $reg, $val, $comment);
}
elsif ($key eq "BITFIELD") {
my($reg, $mask, $which) = split /\s*\,\s*/, $value;
if ($which) {
return sprintf($set_format, $reg, $mask, $comment);
} else {
return sprintf($clear_format, $reg, $mask, $comment);
}
}
elsif ($key eq "DELAY") {
return sprintf($sleep_format, $value, $comment);
}
elsif ($key eq "POLL_REG") {
my($reg, $mask, $cond, $delay, $timeout) = split /\s*\,\s*/, $value;
$delay =~ s/DELAY\s*=\s*//;
$timeout =~ s/TIMEOUT\s*=\s*//;
${$functions[$#functions]}{declare} = " int i;\r\n";
return sprintf($poolreg_format, $reg, $mask, $cond, $delay, $timeout, $comment);
}
return " // " . $key . "=" . $value . $comment . "\r\n";
}
die "USAGE: convert.pl [INFILE] > [OUTFILE]\n" if ($#ARGV != 0);
my $infile = $ARGV[0];
(my $outfile = $infile) =~ s/\.ini$/.autogen.c/;
open IN, $infile or die "Cannot open the file!\n";
my @packets; # <20>p<EFBFBD>P<EFBFBD>b<EFBFBD>g<EFBFBD>w<EFBFBD>b<EFBFBD>_<EFBFBD>{<7B>p<EFBFBD>P<EFBFBD>b<EFBFBD>g<EFBFBD>̒<EFBFBD><CC92>g<EFBFBD>̏W<CC8F>܂<EFBFBD>
my @data; # <20>f<EFBFBD>[<5B>^<5E>Q
my $first = -1; # <20><EFBFBD>A<EFBFBD>h<EFBFBD><68><EFBFBD>X
my $current = -1; # <20><><EFBFBD>҃A<D283>h<EFBFBD><68><EFBFBD>X
while (<IN>) {
my $comment = "";
s/[\r\n]+$//; # delete \r and/or \n
s|\;|//|; # replace first ; to //
if (s|(//.*)||) {
$comment = $1;
}
if (/\s*\[(.+)\]/) {
push @functions, {name => name_conv($1), data => "", declare => ""};
}
elsif (/\s*(.+?)\s*\=\s*(.+?)\s*$/) {
${$functions[$#functions]}{data} .= func_conv($1, $2, $comment);
}
elsif (/\S+/) {
print "UNKNOWN STATEMENT: <<", $_, ">>\n";
${$functions[$#functions]}{data} .= $_ . $comment . "\r\n";
}
elsif ($comment) {
${$functions[$#functions]}{data} .= $comment . "\r\n";
}
}
close(IN);
#use Data::Dumper;
#print Dumper(\@functions);
#exit(1);
# output
printf $file_head_format, $outfile;
foreach my $func ( @functions ) {
if ($$func{name}) {
if ($$func{data} !~ /camera/) {
$$func{declare} = "#pragma unused(camera)\r\n";
}
printf $declare_format, $$func{name};
}
}
printf "\r\n";
foreach my $func ( @functions ) {
if ($$func{name}) {
printf $func_head_format, $$func{name};
print $$func{declare}, "\r\n" if ($$func{declare});
}
print $$func{data};
if ($$func{name}) {
printf $func_foot_format;
}
}
printf $file_foot_format;