File Coverage

blib/lib/RPi/Const.pm
Criterion Covered Total %
statement 45 46 97.8
branch n/a
condition n/a
subroutine 15 16 93.7
pod n/a
total 60 62 96.7


line stmt bran cond sub pod time code
1             package RPi::Const;
2              
3 12     12   992179 use strict;
  12         18  
  12         356  
4 12     12   93 use warnings;
  12         18  
  12         721  
5              
6             our $VERSION = '1.06';
7              
8             require Exporter;
9 12     12   56 use base qw( Exporter );
  12         17  
  12         1823  
10             our @EXPORT_OK = ();
11             our %EXPORT_TAGS = ( all => \@EXPORT_OK );
12              
13             use constant {
14 12         1937 PWM_MODE_MS => 0,
15             PWM_MODE_BAL => 1,
16 12     12   60 };
  12         60  
17              
18             { # PWM modes
19             my @const = qw(
20             PWM_MODE_MS
21             PWM_MODE_BAL
22             );
23              
24             push @EXPORT_OK, @const;
25             $EXPORT_TAGS{pwm_mode} = \@const;
26             }
27              
28             use constant {
29 12         1137 PWM_DEFAULT_MODE => 1, # balanced
30             PWM_DEFAULT_CLOCK => 32,
31             PWM_DEFAULT_RANGE => 1023,
32 12     12   80 };
  12         13  
33              
34             { # PWM defaults
35             my @const = qw(
36             PWM_DEFAULT_MODE
37             PWM_DEFAULT_CLOCK
38             PWM_DEFAULT_RANGE
39             );
40              
41             push @EXPORT_OK, @const;
42             $EXPORT_TAGS{pwm_defaults} = \@const;
43             }
44              
45             use constant {
46 12         1391 INPUT => 0,
47             OUTPUT => 1,
48             PWM_OUT => 2,
49             GPIO_CLOCK => 3,
50             SOFT_PWM_OUTPUT => 4,
51             SOFT_TONE_OUTPUT => 5,
52             PWM_TONE_OUTPUT => 6,
53 12     12   56 };
  12         22  
54              
55             { # pinmodes
56             my @const = qw(
57             INPUT
58             OUTPUT
59             PWM_OUT
60             GPIO_CLOCK
61             SOFT_PWM_OUTPUT
62             SOFT_TONE_OUTPUT
63             PWM_TONE_OUTPUT
64             );
65              
66             push @EXPORT_OK, @const;
67             $EXPORT_TAGS{pinmode} = \@const;
68             }
69              
70             use constant {
71 12         1076 ALT0 => 4,
72             ALT1 => 5,
73             ALT2 => 6,
74             ALT3 => 7,
75             ALT4 => 3,
76             ALT5 => 2,
77 12     12   50 };
  12         15  
78              
79             { # alt modes
80             my @const = qw(
81             ALT0
82             ALT1
83             ALT2
84             ALT3
85             ALT4
86             ALT5
87             );
88              
89             push @EXPORT_OK, @const;
90             $EXPORT_TAGS{altmode} = \@const;
91             }
92              
93             use constant {
94 12         915 PUD_OFF => 0,
95             PUD_DOWN => 1,
96             PUD_UP => 2,
97 12     12   73 };
  12         30  
98              
99             { # pull
100             my @const = qw(
101             PUD_UP
102             PUD_DOWN
103             PUD_OFF
104             );
105              
106             push @EXPORT_OK, @const;
107             $EXPORT_TAGS{pull} = \@const;
108             };
109              
110             use constant {
111 12         859 HIGH => 1,
112             LOW => 0,
113             ON => 1,
114             OFF => 0,
115 12     12   54 };
  12         17  
116            
117             { # state
118              
119             my @const = qw(
120             HIGH
121             LOW
122             ON
123             OFF
124             );
125              
126             push @EXPORT_OK, @const;
127             $EXPORT_TAGS{state} = \@const;
128             }
129              
130             use constant {
131 12         1374 EDGE_SETUP => 0,
132             EDGE_FALLING => 1,
133             EDGE_RISING => 2,
134             EDGE_BOTH => 3,
135 12     12   53 };
  12         22  
136            
137             { # interrupt
138              
139             my @const = qw(
140             EDGE_SETUP
141             EDGE_FALLING
142             EDGE_RISING
143             EDGE_BOTH
144             );
145              
146             push @EXPORT_OK, @const;
147             $EXPORT_TAGS{edge} = \@const;
148             }
149              
150             use constant {
151 12         1505 RPI_MODE_WPI => 0,
152             RPI_MODE_GPIO => 1,
153             RPI_MODE_GPIO_SYS => 2,
154             RPI_MODE_PHYS => 3,
155             RPI_MODE_UNINIT => -1,
156 12     12   55 };
  12         17  
157              
158             { # mode
159              
160             my @const = qw(
161             RPI_MODE_WPI
162             RPI_MODE_GPIO
163             RPI_MODE_GPIO_SYS
164             RPI_MODE_PHYS
165             RPI_MODE_UNINIT
166             );
167              
168             push @EXPORT_OK, @const;
169             $EXPORT_TAGS{mode} = \@const;
170             }
171              
172             use constant {
173 12         2529 MCP23017_IODIRA => 0x00,
174             MCP23017_IODIRB => 0x01,
175             MCP23017_IPOLA => 0x02,
176             MCP23017_IPOLB => 0x03,
177             MCP23017_GPINTENA => 0x04,
178             MCP23017_GPINTENB => 0x05,
179             MCP23017_DEFVALA => 0x06,
180             MCP23017_DEFVALB => 0x07,
181             MCP23017_INTCONA => 0x08,
182             MCP23017_INTCONB => 0x09,
183             MCP23017_IOCONA => 0x0A,
184             MCP23017_IOCONB => 0x0B,
185             MCP23017_GPPUA => 0x0C,
186             MCP23017_GPPUB => 0x0D,
187             MCP23017_INTFA => 0x0E,
188             MCP23017_INTFB => 0x0F,
189             MCP23017_INTCAPA => 0x10,
190             MCP23017_INTCAPB => 0x11,
191             MCP23017_GPIOA => 0x12,
192             MCP23017_GPIOB => 0x13,
193             MCP23017_OLATA => 0x14,
194             MCP23017_OLATB => 0x15,
195              
196             MCP23017_INPUT => 1,
197             MCP23017_OUTPUT => 0,
198 12     12   56 };
  12         14  
199              
200             { # MCP23017 GPIO Expander Registers
201              
202             my @const = qw(
203             MCP23017_IODIRA
204             MCP23017_IODIRB
205             MCP23017_IPOLA
206             MCP23017_IPOLB
207             MCP23017_GPINTENA
208             MCP23017_GPINTENB
209             MCP23017_DEFVALA
210             MCP23017_DEFVALB
211             MCP23017_INTCONA
212             MCP23017_INTCONB
213             MCP23017_IOCONA
214             MCP23017_IOCONB
215             MCP23017_GPPUA
216             MCP23017_GPPUB
217             MCP23017_INTFA
218             MCP23017_INTFB
219             MCP23017_INTCAPA
220             MCP23017_INTCAPB
221             MCP23017_GPIOA
222             MCP23017_GPIOB
223             MCP23017_OLATA
224             MCP23017_OLATB
225             MCP23017_INPUT
226             MCP23017_OUTPUT
227             );
228              
229             push @EXPORT_OK, @const;
230             $EXPORT_TAGS{mcp23017_registers} = \@const;
231             }
232              
233             use constant {
234             # Bank A pin numbers (pins 0-7)
235 12         1535 A0 => 0,
236             A1 => 1,
237             A2 => 2,
238             A3 => 3,
239             A4 => 4,
240             A5 => 5,
241             A6 => 6,
242             A7 => 7,
243              
244             # Bank B pin numbers (pins 8-15)
245             B0 => 8,
246             B1 => 9,
247             B2 => 10,
248             B3 => 11,
249             B4 => 12,
250             B5 => 13,
251             B6 => 14,
252             B7 => 15,
253 12     12   51 };
  12         12  
254              
255             { # MCP23017 named pin numbers (bank A pins 0-7, bank B pins 8-15)
256              
257             my @const = qw(
258             A0 A1 A2 A3 A4 A5 A6 A7
259             B0 B1 B2 B3 B4 B5 B6 B7
260             );
261              
262             push @EXPORT_OK, @const;
263             $EXPORT_TAGS{mcp23017_pins} = \@const;
264             }
265              
266             use constant {
267 12         880 WPI_PIN_BCM => 1,
268             WPI_PIN_WPI => 2,
269 12     12   50 };
  12         17  
270              
271             { # WPIPinType pin-numbering (wiringPiSetupPinType / wiringPiSetupGpioDevice)
272              
273             # WPI_PIN_PHYS is intentionally omitted - physical-pin setup is not
274             # supported anywhere in the RPi:: suite.
275              
276             my @const = qw(
277             WPI_PIN_BCM
278             WPI_PIN_WPI
279             );
280              
281             push @EXPORT_OK, @const;
282             $EXPORT_TAGS{wpi_pin} = \@const;
283             }
284              
285             use constant {
286 12         1753 INT_EDGE_SETUP => EDGE_SETUP,
287             INT_EDGE_FALLING => EDGE_FALLING,
288             INT_EDGE_RISING => EDGE_RISING,
289             INT_EDGE_BOTH => EDGE_BOTH,
290 12     12   112 };
  12         83  
291              
292             { # wiringPi-native edge names (mirror wiringPi's INT_EDGE_* #defines)
293              
294             my @const = qw(
295             INT_EDGE_SETUP
296             INT_EDGE_FALLING
297             INT_EDGE_RISING
298             INT_EDGE_BOTH
299             );
300              
301             push @EXPORT_OK, @const;
302             $EXPORT_TAGS{int_edge} = \@const;
303             }
304              
305 0     0     sub _vim{1;};
306             1;
307             __END__