Skip to content

Commit 97f1cf6

Browse files
committed
Hide non-API pinPeripheral method
1 parent 7cd5344 commit 97f1cf6

File tree

12 files changed

+139
-140
lines changed

12 files changed

+139
-140
lines changed

cores/arduino/USB/samd21_host.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
#include <stdint.h>
2222
#include <string.h>
2323

24-
#include "variant.h"
24+
#include "../Arduino.h"
2525
#include "USB_host.h"
2626
#include "samd21_host.h"
27-
#include "sam.h"
2827
#include "wiring_digital.h"
2928

3029
#define HOST_DEFINED

cores/arduino/Uart.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
#include "Uart.h"
20-
#include "WVariant.h"
21-
#include "wiring_digital.h"
20+
#include "Arduino.h"
21+
#include "wiring_private.h"
2222

2323
Uart::Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX)
2424
{

cores/arduino/WInterrupts.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#include "WInterrupts.h"
20-
#include "variant.h"
21-
#include "wiring_digital.h"
19+
#include "Arduino.h"
2220

2321
#include <string.h>
2422

cores/arduino/wiring.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#include "variant.h"
20-
#include "wiring_analog.h"
21-
#include "wiring_digital.h"
22-
#include "wiring.h"
19+
#include "Arduino.h"
2320

2421
#ifdef __cplusplus
2522
extern "C" {

cores/arduino/wiring_analog.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#include "wiring_analog.h"
20-
#include "wiring_digital.h"
21-
#include "variant.h"
19+
#include "Arduino.h"
2220

2321
#ifdef __cplusplus
2422
extern "C" {

cores/arduino/wiring_constants.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
extern "C"{
2424
#endif // __cplusplus
2525

26-
// moved to wiring_digital.h
27-
//#define LOW (0x0)
28-
//#define HIGH (0x1)
26+
#define LOW (0x0)
27+
#define HIGH (0x1)
2928

30-
//#define INPUT (0x0)
31-
//#define OUTPUT (0x1)
32-
//#define INPUT_PULLUP (0x2)
29+
#define INPUT (0x0)
30+
#define OUTPUT (0x1)
31+
#define INPUT_PULLUP (0x2)
32+
#define INPUT_PULLDOWN (0x3)
3333

3434
#define PI 3.1415926535897932384626433832795
3535
#define HALF_PI 1.5707963267948966192313216916398

cores/arduino/wiring_digital.c

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -16,110 +16,12 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#include "wiring_digital.h"
20-
#include "WVariant.h"
19+
#include "Arduino.h"
2120

2221
#ifdef __cplusplus
2322
extern "C" {
2423
#endif
2524

26-
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
27-
{
28-
// Handle the case the pin isn't usable as PIO
29-
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
30-
{
31-
return -1 ;
32-
}
33-
34-
switch ( ulPeripheral )
35-
{
36-
case PIO_DIGITAL:
37-
case PIO_INPUT:
38-
case PIO_INPUT_PULLUP:
39-
case PIO_OUTPUT:
40-
// Disable peripheral muxing, done in pinMode
41-
// PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PMUXEN = 0 ;
42-
43-
// Configure pin mode, if requested
44-
if ( ulPeripheral == PIO_INPUT )
45-
{
46-
pinMode( ulPin, INPUT ) ;
47-
}
48-
else
49-
{
50-
if ( ulPeripheral == PIO_INPUT_PULLUP )
51-
{
52-
pinMode( ulPin, INPUT_PULLUP ) ;
53-
}
54-
else
55-
{
56-
if ( ulPeripheral == PIO_OUTPUT )
57-
{
58-
pinMode( ulPin, OUTPUT ) ;
59-
}
60-
else
61-
{
62-
// PIO_DIGITAL, do we have to do something as all cases are covered?
63-
}
64-
}
65-
}
66-
break ;
67-
68-
case PIO_ANALOG:
69-
case PIO_SERCOM:
70-
case PIO_SERCOM_ALT:
71-
case PIO_TIMER:
72-
case PIO_TIMER_ALT:
73-
case PIO_EXTINT:
74-
case PIO_COM:
75-
case PIO_AC_CLK:
76-
#if 0
77-
// Is the pio pin in the lower 16 ones?
78-
// The WRCONFIG register allows update of only 16 pin max out of 32
79-
if ( g_APinDescription[ulPin].ulPin < 16 )
80-
{
81-
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
82-
PORT_WRCONFIG_WRPINCFG |
83-
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin ) ;
84-
}
85-
else
86-
{
87-
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_HWSEL |
88-
PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
89-
PORT_WRCONFIG_WRPINCFG |
90-
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
91-
}
92-
#else
93-
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
94-
{
95-
uint32_t temp ;
96-
97-
// Get whole current setup for both odd and even pins and remove odd one
98-
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
99-
// Set new muxing
100-
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXO( ulPeripheral ) ;
101-
// Enable port mux
102-
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ;
103-
}
104-
else // even pin
105-
{
106-
uint32_t temp ;
107-
108-
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
109-
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXE( ulPeripheral ) ;
110-
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ; // Enable port mux
111-
}
112-
#endif
113-
break ;
114-
115-
case PIO_NOT_A_PIN:
116-
return -1l ;
117-
break ;
118-
}
119-
120-
return 0l ;
121-
}
122-
12325
void pinMode( uint32_t ulPin, uint32_t ulMode )
12426
{
12527
// Handle the case the pin isn't usable as PIO

cores/arduino/wiring_digital.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,8 @@
2323
extern "C" {
2424
#endif
2525

26-
#define INPUT (0x0ul)
27-
#define OUTPUT (0x1ul)
28-
#define INPUT_PULLUP (0x2ul)
29-
#define INPUT_PULLDOWN (0x4ul)
30-
31-
#define LOW (0x0ul)
32-
#define HIGH (0x1ul)
33-
3426
#include "WVariant.h"
3527

36-
/**
37-
* \brief Configures the specified pin to belong to a device peripheral or to behave either as a an input or an output. See the description of board for details.
38-
*
39-
* \param ulPin The number of the pin whose mode you wish to set
40-
* \param ulPeripheral See WVariant.h for type decription
41-
*/
42-
extern int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral ) ;
43-
4428
/**
4529
* \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details.
4630
*

cores/arduino/wiring_private.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "WVariant.h"
20+
#include "wiring_private.h"
21+
22+
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
23+
{
24+
// Handle the case the pin isn't usable as PIO
25+
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
26+
{
27+
return -1 ;
28+
}
29+
30+
switch ( ulPeripheral )
31+
{
32+
case PIO_DIGITAL:
33+
case PIO_INPUT:
34+
case PIO_INPUT_PULLUP:
35+
case PIO_OUTPUT:
36+
// Disable peripheral muxing, done in pinMode
37+
// PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PMUXEN = 0 ;
38+
39+
// Configure pin mode, if requested
40+
if ( ulPeripheral == PIO_INPUT )
41+
{
42+
pinMode( ulPin, INPUT ) ;
43+
}
44+
else
45+
{
46+
if ( ulPeripheral == PIO_INPUT_PULLUP )
47+
{
48+
pinMode( ulPin, INPUT_PULLUP ) ;
49+
}
50+
else
51+
{
52+
if ( ulPeripheral == PIO_OUTPUT )
53+
{
54+
pinMode( ulPin, OUTPUT ) ;
55+
}
56+
else
57+
{
58+
// PIO_DIGITAL, do we have to do something as all cases are covered?
59+
}
60+
}
61+
}
62+
break ;
63+
64+
case PIO_ANALOG:
65+
case PIO_SERCOM:
66+
case PIO_SERCOM_ALT:
67+
case PIO_TIMER:
68+
case PIO_TIMER_ALT:
69+
case PIO_EXTINT:
70+
case PIO_COM:
71+
case PIO_AC_CLK:
72+
#if 0
73+
// Is the pio pin in the lower 16 ones?
74+
// The WRCONFIG register allows update of only 16 pin max out of 32
75+
if ( g_APinDescription[ulPin].ulPin < 16 )
76+
{
77+
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
78+
PORT_WRCONFIG_WRPINCFG |
79+
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin ) ;
80+
}
81+
else
82+
{
83+
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_HWSEL |
84+
PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
85+
PORT_WRCONFIG_WRPINCFG |
86+
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
87+
}
88+
#else
89+
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
90+
{
91+
uint32_t temp ;
92+
93+
// Get whole current setup for both odd and even pins and remove odd one
94+
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
95+
// Set new muxing
96+
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXO( ulPeripheral ) ;
97+
// Enable port mux
98+
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ;
99+
}
100+
else // even pin
101+
{
102+
uint32_t temp ;
103+
104+
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
105+
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXE( ulPeripheral ) ;
106+
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ; // Enable port mux
107+
}
108+
#endif
109+
break ;
110+
111+
case PIO_NOT_A_PIN:
112+
return -1l ;
113+
break ;
114+
}
115+
116+
return 0l ;
117+
}
118+

cores/arduino/wiring_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ extern "C" {
3131

3232
#include "wiring_constants.h"
3333

34+
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral );
35+
3436
#ifdef __cplusplus
3537
} // extern "C"
3638

0 commit comments

Comments
 (0)