Skip to content
Open
Prev Previous commit
Next Next commit
For PR to add pinPeripheral() function - note wiring_private.c stubbe…
…d right now, will be fixed to make compatible with H7 --- jcw
  • Loading branch information
jwestmoreland committed Sep 10, 2020
commit bbab0643a4665a97767849d758ce59f30e2b640e
64 changes: 64 additions & 0 deletions cores/arduino/WVariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//** just starting suggestion at this point --- jcw - 9/10/20
/*
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
*/

#pragma once

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum _EPioType
{
PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */
PIO_EXTINT=0, /* The pin is controlled by the associated signal of peripheral A. */
PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */
PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
PIO_DIGITAL, /* The pin is controlled by PORT. */
PIO_INPUT, /* The pin is controlled by PORT and is an input. */
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */

PIO_PWM=PIO_TIMER,
PIO_PWM_ALT=PIO_TIMER_ALT,
} EPioType ;

/**
* Pin Attributes to be OR-ed
*/
#define PIN_ATTR_NONE (0UL<<0)
#define PIN_ATTR_COMBO (1UL<<0)
#define PIN_ATTR_ANALOG (1UL<<1)
#define PIN_ATTR_DIGITAL (1UL<<2)
#define PIN_ATTR_PWM (1UL<<3)
#define PIN_ATTR_TIMER (1UL<<4)
#define PIN_ATTR_TIMER_ALT (1UL<<5)
#define PIN_ATTR_EXTINT (1UL<<6)


#ifdef __cplusplus
} // extern "C"
#endif

8 changes: 4 additions & 4 deletions cores/arduino/wiring_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ extern "C"{
#define SERIAL 0x0
#define DISPLAY 0x1

enum BitOrder {
LSBFIRST = 0,
MSBFIRST = 1
};
// enum BitOrder {
//LSBFIRST = 0,
//MSBFIRST = 1
// };

// moved to WInterrupts.h
//// LOW 0
Expand Down
23 changes: 16 additions & 7 deletions cores/arduino/wiring_private.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//** just starting suggestion at this point --- jcw - 9/10/20

// This file is stubbed - will fix incompatibilies with Portenta
// pinMode() calls need to be fixed for a start...
///**XXX** - marks what needs to be fixed


/*
Copyright (c) 2015 Arduino LLC. All right reserved.

Expand All @@ -19,14 +25,15 @@

#include "Arduino.h"
#include "wiring_private.h"
#include "WVariant.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 ;
}
//**XXX*** STIB UNTIL FIXED --- if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
/// {
/// return -1 ;
/// }

switch ( ulPeripheral )
{
Expand All @@ -40,19 +47,19 @@ int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
// Configure pin mode, if requested
if ( ulPeripheral == PIO_INPUT )
{
pinMode( ulPin, INPUT ) ;
///***XXX^^^ stub until fixed pinMode( ulPin, INPUT ) ;
}
else
{
if ( ulPeripheral == PIO_INPUT_PULLUP )
{
pinMode( ulPin, INPUT_PULLUP ) ;
///***XXX^^^ stub until fixed pinMode( ulPin, INPUT_PULLUP ) ;
}
else
{
if ( ulPeripheral == PIO_OUTPUT )
{
pinMode( ulPin, OUTPUT ) ;
///***XXX^^^ stub until fixed pinMode( ulPin, OUTPUT ) ;
}
else
{
Expand Down Expand Up @@ -87,6 +94,7 @@ int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
}
#else
#if 0 ///***XXX^^^ stub until fixed - should be #if 1 here <-
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
{
uint32_t temp ;
Expand All @@ -106,6 +114,7 @@ int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
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
#endif
break ;

Expand Down
4 changes: 2 additions & 2 deletions cores/arduino/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stdarg.h>

#include "Arduino.h"

#include "WVariant.h"
#ifdef __cplusplus
extern "C"{
#endif
Expand All @@ -42,5 +42,5 @@ int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral );
#ifdef __cplusplus
} // extern "C"
#endif
// #include "HardwareSerial.h"

#endif