Hide non-API pinPeripheral method
This commit is contained in:
parent
7cd5344e85
commit
97f1cf6af5
12 changed files with 139 additions and 140 deletions
|
|
@ -21,10 +21,9 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "variant.h"
|
||||
#include "../Arduino.h"
|
||||
#include "USB_host.h"
|
||||
#include "samd21_host.h"
|
||||
#include "sam.h"
|
||||
#include "wiring_digital.h"
|
||||
|
||||
#define HOST_DEFINED
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
|
||||
#include "Uart.h"
|
||||
#include "WVariant.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "Arduino.h"
|
||||
#include "wiring_private.h"
|
||||
|
||||
Uart::Uart(SERCOM *_s, uint8_t _pinRX, uint8_t _pinTX, SercomRXPad _padRX, SercomUartTXPad _padTX)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "WInterrupts.h"
|
||||
#include "variant.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "variant.h"
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "wiring.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "variant.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@
|
|||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// moved to wiring_digital.h
|
||||
//#define LOW (0x0)
|
||||
//#define HIGH (0x1)
|
||||
#define LOW (0x0)
|
||||
#define HIGH (0x1)
|
||||
|
||||
//#define INPUT (0x0)
|
||||
//#define OUTPUT (0x1)
|
||||
//#define INPUT_PULLUP (0x2)
|
||||
#define INPUT (0x0)
|
||||
#define OUTPUT (0x1)
|
||||
#define INPUT_PULLUP (0x2)
|
||||
#define INPUT_PULLDOWN (0x3)
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define HALF_PI 1.5707963267948966192313216916398
|
||||
|
|
|
|||
|
|
@ -16,110 +16,12 @@
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "wiring_digital.h"
|
||||
#include "WVariant.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
|
||||
{
|
||||
// Handle the case the pin isn't usable as PIO
|
||||
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
|
||||
{
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
switch ( ulPeripheral )
|
||||
{
|
||||
case PIO_DIGITAL:
|
||||
case PIO_INPUT:
|
||||
case PIO_INPUT_PULLUP:
|
||||
case PIO_OUTPUT:
|
||||
// Disable peripheral muxing, done in pinMode
|
||||
// PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PMUXEN = 0 ;
|
||||
|
||||
// Configure pin mode, if requested
|
||||
if ( ulPeripheral == PIO_INPUT )
|
||||
{
|
||||
pinMode( ulPin, INPUT ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ulPeripheral == PIO_INPUT_PULLUP )
|
||||
{
|
||||
pinMode( ulPin, INPUT_PULLUP ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ulPeripheral == PIO_OUTPUT )
|
||||
{
|
||||
pinMode( ulPin, OUTPUT ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// PIO_DIGITAL, do we have to do something as all cases are covered?
|
||||
}
|
||||
}
|
||||
}
|
||||
break ;
|
||||
|
||||
case PIO_ANALOG:
|
||||
case PIO_SERCOM:
|
||||
case PIO_SERCOM_ALT:
|
||||
case PIO_TIMER:
|
||||
case PIO_TIMER_ALT:
|
||||
case PIO_EXTINT:
|
||||
case PIO_COM:
|
||||
case PIO_AC_CLK:
|
||||
#if 0
|
||||
// Is the pio pin in the lower 16 ones?
|
||||
// The WRCONFIG register allows update of only 16 pin max out of 32
|
||||
if ( g_APinDescription[ulPin].ulPin < 16 )
|
||||
{
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
|
||||
PORT_WRCONFIG_WRPINCFG |
|
||||
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_HWSEL |
|
||||
PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
|
||||
PORT_WRCONFIG_WRPINCFG |
|
||||
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
|
||||
}
|
||||
#else
|
||||
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
|
||||
{
|
||||
uint32_t temp ;
|
||||
|
||||
// Get whole current setup for both odd and even pins and remove odd one
|
||||
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
|
||||
// Set new muxing
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXO( ulPeripheral ) ;
|
||||
// Enable port mux
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ;
|
||||
}
|
||||
else // even pin
|
||||
{
|
||||
uint32_t temp ;
|
||||
|
||||
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXE( ulPeripheral ) ;
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ; // Enable port mux
|
||||
}
|
||||
#endif
|
||||
break ;
|
||||
|
||||
case PIO_NOT_A_PIN:
|
||||
return -1l ;
|
||||
break ;
|
||||
}
|
||||
|
||||
return 0l ;
|
||||
}
|
||||
|
||||
void pinMode( uint32_t ulPin, uint32_t ulMode )
|
||||
{
|
||||
// Handle the case the pin isn't usable as PIO
|
||||
|
|
|
|||
|
|
@ -23,24 +23,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INPUT (0x0ul)
|
||||
#define OUTPUT (0x1ul)
|
||||
#define INPUT_PULLUP (0x2ul)
|
||||
#define INPUT_PULLDOWN (0x4ul)
|
||||
|
||||
#define LOW (0x0ul)
|
||||
#define HIGH (0x1ul)
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
/**
|
||||
* \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.
|
||||
*
|
||||
* \param ulPin The number of the pin whose mode you wish to set
|
||||
* \param ulPeripheral See WVariant.h for type decription
|
||||
*/
|
||||
extern int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral ) ;
|
||||
|
||||
/**
|
||||
* \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details.
|
||||
*
|
||||
|
|
|
|||
118
cores/arduino/wiring_private.c
Normal file
118
cores/arduino/wiring_private.c
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
Copyright (c) 2015 Arduino LLC. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "WVariant.h"
|
||||
#include "wiring_private.h"
|
||||
|
||||
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
|
||||
{
|
||||
// Handle the case the pin isn't usable as PIO
|
||||
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
|
||||
{
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
switch ( ulPeripheral )
|
||||
{
|
||||
case PIO_DIGITAL:
|
||||
case PIO_INPUT:
|
||||
case PIO_INPUT_PULLUP:
|
||||
case PIO_OUTPUT:
|
||||
// Disable peripheral muxing, done in pinMode
|
||||
// PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PMUXEN = 0 ;
|
||||
|
||||
// Configure pin mode, if requested
|
||||
if ( ulPeripheral == PIO_INPUT )
|
||||
{
|
||||
pinMode( ulPin, INPUT ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ulPeripheral == PIO_INPUT_PULLUP )
|
||||
{
|
||||
pinMode( ulPin, INPUT_PULLUP ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ulPeripheral == PIO_OUTPUT )
|
||||
{
|
||||
pinMode( ulPin, OUTPUT ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// PIO_DIGITAL, do we have to do something as all cases are covered?
|
||||
}
|
||||
}
|
||||
}
|
||||
break ;
|
||||
|
||||
case PIO_ANALOG:
|
||||
case PIO_SERCOM:
|
||||
case PIO_SERCOM_ALT:
|
||||
case PIO_TIMER:
|
||||
case PIO_TIMER_ALT:
|
||||
case PIO_EXTINT:
|
||||
case PIO_COM:
|
||||
case PIO_AC_CLK:
|
||||
#if 0
|
||||
// Is the pio pin in the lower 16 ones?
|
||||
// The WRCONFIG register allows update of only 16 pin max out of 32
|
||||
if ( g_APinDescription[ulPin].ulPin < 16 )
|
||||
{
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
|
||||
PORT_WRCONFIG_WRPINCFG |
|
||||
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_HWSEL |
|
||||
PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
|
||||
PORT_WRCONFIG_WRPINCFG |
|
||||
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
|
||||
}
|
||||
#else
|
||||
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
|
||||
{
|
||||
uint32_t temp ;
|
||||
|
||||
// Get whole current setup for both odd and even pins and remove odd one
|
||||
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
|
||||
// Set new muxing
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXO( ulPeripheral ) ;
|
||||
// Enable port mux
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ;
|
||||
}
|
||||
else // even pin
|
||||
{
|
||||
uint32_t temp ;
|
||||
|
||||
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXE( ulPeripheral ) ;
|
||||
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ; // Enable port mux
|
||||
}
|
||||
#endif
|
||||
break ;
|
||||
|
||||
case PIO_NOT_A_PIN:
|
||||
return -1l ;
|
||||
break ;
|
||||
}
|
||||
|
||||
return 0l ;
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +31,8 @@ extern "C" {
|
|||
|
||||
#include "wiring_constants.h"
|
||||
|
||||
int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@
|
|||
*/
|
||||
|
||||
#include "SPI.h"
|
||||
#include "wiring_digital.h"
|
||||
#include "assert.h"
|
||||
#include "variant.h"
|
||||
#include <Arduino.h>
|
||||
#include <wiring_private.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define SPI_IMODE_NONE 0
|
||||
#define SPI_IMODE_EXTINT 1
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ extern "C" {
|
|||
#include <string.h>
|
||||
}
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <wiring_private.h>
|
||||
|
||||
#include "Wire.h"
|
||||
#include "variant.h"
|
||||
#include "wiring_digital.h"
|
||||
|
||||
TwoWire::TwoWire(SERCOM * s)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue