| 1 | package VIC::PIC::Any; | ||||||||||
| 2 | 34 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 34 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 34 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 34 | our $VERSION = '0.29'; | |||||||||
| 7 | 34 | $VERSION = eval $VERSION; | |||||||||
| 8 | |||||||||||
| 9 | 34 | ▶ | use VIC::PIC::Gpsim; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # use this to map various PICs to their classes | ||||||||||
| 12 | # allows for the same class to be used for different pics | ||||||||||
| 13 | 34 | use constant PICS => { | |||||||||
| 14 | # PIC12 | ||||||||||
| 15 | P12F683 => 'P12F683', | ||||||||||
| 16 | # PIC16 | ||||||||||
| 17 | P16F690 => 'P16F690', | ||||||||||
| 18 | P16F631 => 'P16F631', | ||||||||||
| 19 | P16F677 => 'P16F677', | ||||||||||
| 20 | P16F685 => 'P16F685', | ||||||||||
| 21 | P16F687 => 'P16F687', | ||||||||||
| 22 | P16F689 => 'P16F689', | ||||||||||
| 23 | P16F627A => 'P16F627A', | ||||||||||
| 24 | P16F628A => 'P16F628A', | ||||||||||
| 25 | P16F648A => 'P16F648A', | ||||||||||
| 26 | # PIC18 | ||||||||||
| 27 | P18F242 => 'P18F242', | ||||||||||
| 28 | P18F252 => 'P18F252', | ||||||||||
| 29 | P18F442 => 'P18F442', | ||||||||||
| 30 | P18F452 => 'P18F452', | ||||||||||
| 31 | P18F13K50 => 'P18F13K50', | ||||||||||
| 32 | P18F14K50 => 'P18F14K50', | ||||||||||
| 33 | P18LF13K50 => 'P18LF13K50', | ||||||||||
| 34 | P18LF14K50 => 'P18LF14K50', | ||||||||||
| 35 | 34 | ▶ | }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 34 | use constant PICREGEX => { | |||||||||
| 38 | # PIC18 | ||||||||||
| 39 | 34 | ▶ | }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | |||||||||||
| 41 | 34 | use constant SIMS => { | |||||||||
| 42 | gpsim => 'Gpsim', | ||||||||||
| 43 | 34 | ▶ | }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | sub _get_pic_type { | ||||||||||
| 46 | 70 | ▶ | my $type = shift; | ||||||||
|
Subroutine
_get_pic_type: called CC=4 SCAR=15.5
| |||||||||||
| 47 | 70 | $type =~ s/^PIC/P/gi; | |||||||||
| 48 | 70 | my $ctype = PICS->{uc $type}; | |||||||||
| 49 | 70 | ▶ | unless (defined $ctype) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 1 | foreach my $regex (keys %{+PICREGEX}) { | |||||||||
| 51 | 0 | ▶ | if ($type =~ $regex) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | $ctype = PICREGEX->{$regex}; | |||||||||
| 53 | 0 | last; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | 70 | return $ctype; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub new { | ||||||||||
| 61 | 51 | ▶ | my ($class, $type) = @_; | ||||||||
|
Subroutine
new: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||
| 62 | 51 | ▶ | if (uc $type eq 'ANY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | die "You need to specify the type of the chip on the commandline to use 'Any'\n"; | |||||||||
| 64 | 0 | return; | |||||||||
| 65 | } | ||||||||||
| 66 | 51 | my $ctype = &_get_pic_type($type); | |||||||||
| 67 | 51 | ▶ | return unless defined $ctype; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 51 | $class =~ s/::Any/::$ctype/g; | |||||||||
| 69 | 51 | ▶ | eval "require $class;" or croak "Unable to load $class: $@"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 51 | return $class->new(type => lc $ctype); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub new_simulator { | ||||||||||
| 74 | 36 | ▶ | my ($class, %hh) = @_; | ||||||||
|
Subroutine
new_simulator: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||
| 75 | 36 | my $stype = 'Gpsim'; | |||||||||
| 76 | 36 | ▶ | if (exists $hh{type}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 3 | $stype = SIMS->{lc $hh{type}}; | |||||||||
| 78 | 3 | ▶ | unless (defined $stype) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | carp "No simulator of type $hh{type}"; | |||||||||
| 80 | 0 | return; | |||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | 36 | $class =~ s/::Any/::$stype/g; | |||||||||
| 84 | 36 | $hh{type} = lc $stype; | |||||||||
| 85 | 36 | return $class->new(%hh); | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | sub supported_chips { | ||||||||||
| 89 | 3 | ▶ | my @chips = sort(keys %{+PICS}); | ||||||||
|
Subroutine
supported_chips: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 90 | 3 | push @chips, sort(values %{+PICREGEX}); | |||||||||
| 91 | 3 | ▶ | return wantarray ? @chips : \@chips; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | sub supported_simulators { | ||||||||||
| 95 | 2 | ▶ | my @sims = sort(keys %{+SIMS}); | ||||||||
|
Subroutine
supported_simulators: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 96 | 2 | ▶ | return wantarray ? @sims : \@sims; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | sub is_simulator_supported { | ||||||||||
| 100 | 0 | ▶ | my $ss = shift; | ||||||||
|
Subroutine
is_simulator_supported: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 101 | 0 | my @sims = &supported_simulators(); | |||||||||
| 102 | 0 | ▶ | return (grep {/$ss/} @sims) ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | sub is_chip_supported { | ||||||||||
| 106 | 19 | ▶ | my $chip = shift; | ||||||||
|
Subroutine
is_chip_supported: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 107 | 19 | my $ret = &_get_pic_type(uc $chip); | |||||||||
| 108 | 19 | ▶ | return (defined $ret) ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | sub list_chip_features { | ||||||||||
| 112 | 0 | ▶ | my $chip = shift; | ||||||||
|
Subroutine
list_chip_features: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 113 | 0 | my $ctype = &_get_pic_type($chip); | |||||||||
| 114 | 0 | ▶ | unless (defined $ctype) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 0 | carp "Chip $chip is not supported\n"; | |||||||||
| 116 | 0 | return; | |||||||||
| 117 | } | ||||||||||
| 118 | 0 | my $obj = __PACKAGE__->new($chip); | |||||||||
| 119 | 0 | my $roles = $obj->list_roles(); | |||||||||
| 120 | return { | ||||||||||
| 121 | 0 | roles => $roles, | |||||||||
| 122 | memory => $obj->memory, | ||||||||||
| 123 | }; | ||||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | sub print_pinout { | ||||||||||
| 127 | 0 | ▶ | my $chip = shift; | ||||||||
|
Subroutine
print_pinout: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 128 | 0 | my $ctype = &_get_pic_type($chip); | |||||||||
| 129 | 0 | ▶ | unless (defined $ctype) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 0 | carp "Chip $chip is not supported\n"; | |||||||||
| 131 | 0 | return; | |||||||||
| 132 | } | ||||||||||
| 133 | 0 | my $obj = __PACKAGE__->new($chip); | |||||||||
| 134 | 0 | return $obj->print_pinout; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 34 | 1; | |||||||||
| 138 | |||||||||||
| 139 | =encoding utf8 | ||||||||||
| 140 | |||||||||||
| 141 | =head1 NAME | ||||||||||
| 142 | |||||||||||
| 143 | VIC::PIC::Any | ||||||||||
| 144 | |||||||||||
| 145 | =head1 SYNOPSIS | ||||||||||
| 146 | |||||||||||
| 147 | A wrapper class that returns the appropriate object for the given PIC | ||||||||||
| 148 | microcontroller name. This is used internally by VIC. | ||||||||||
| 149 | |||||||||||
| 150 | =head1 DESCRIPTION | ||||||||||
| 151 | |||||||||||
| 152 | =over | ||||||||||
| 153 | |||||||||||
| 154 | =item B<new PICNAME> | ||||||||||
| 155 | |||||||||||
| 156 | Returns an object for the given microcontroller name such as 'P16F690'. | ||||||||||
| 157 | |||||||||||
| 158 | =back | ||||||||||
| 159 | |||||||||||
| 160 | =head1 AUTHOR | ||||||||||
| 161 | |||||||||||
| 162 | Vikas N Kumar <vikas@cpan.org> | ||||||||||
| 163 | |||||||||||
| 164 | =head1 COPYRIGHT | ||||||||||
| 165 | |||||||||||
| 166 | Copyright (c) 2014. Vikas N Kumar | ||||||||||
| 167 | |||||||||||
| 168 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 169 | under the same terms as Perl itself. | ||||||||||
| 170 | |||||||||||
| 171 | See http://www.perl.com/perl/misc/Artistic.html | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||