Skip to content
Open
Prev Previous commit
Wiring related files need to be updated for the MKR-RGB Shield to wor…
…k --- jcw
  • Loading branch information
jwestmoreland committed Oct 23, 2020
commit 955a927fd3f71fe455acbed38645fc1ec634c9b8
1 change: 0 additions & 1 deletion cores/arduino/WVariant.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//** just starting suggestion at this point --- jcw - 9/10/20
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

Expand Down
98 changes: 89 additions & 9 deletions cores/arduino/wiring_private.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//** just starting suggestion at this point --- jcw - 9/10/20

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

Expand All @@ -18,16 +17,75 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "Arduino.h"
#include "api/Common.h"
#include "wiring_private.h"
#include "WVariant.h"
// #include <Arduino.h>
// #include "gpio_object.h"
// #include "Wire.h"
// #include "api/Common.h"
#include <wiring_private.h>
// #include "device.h"
// #include "pinmap.h"
// #include "WVariant.h"
// #include "pinmode_arduino.h"
#include "pins_arduino.h"
#include "mbed.h"


static uint8_t pin = 4;
// static gpio_t gpio;
// gpio_t gpio;

// extern PinDescription g_APinDescription[];
#if 0
PinDescription g_APinDescription[] = {
// D0 - D7
{ PH_15, NULL, NULL, NULL }, // D0
{ PK_1, NULL, NULL, NULL }, // D1
{ PJ_11, NULL, NULL, NULL }, // D2
{ PG_7, NULL, NULL, NULL }, // D3
{ PC_7, NULL, NULL, NULL }, // D4
{ PC_6, NULL, NULL, NULL }, // D5
{ PA_8, NULL, NULL, NULL }, // D6
{ PI_0, NULL, NULL, NULL }, // D7

// D8 - D14
{ PC_3, NULL, NULL, NULL }, // D8
{ PI_1, NULL, NULL, NULL }, // D9
{ PC_2, NULL, NULL, NULL }, // D10
{ PH_8, NULL, NULL, NULL }, // D11
{ PH_7, NULL, NULL, NULL }, // D12
{ PA_10, NULL, NULL, NULL }, // D13
{ PA_9, NULL, NULL, NULL }, // D14

// A0 - A6
{ PA_0C, NULL, NULL, NULL }, // A0 ADC2_INP0
{ PA_1C, NULL, NULL, NULL }, // A1 ADC2_INP1
{ PC_2C, NULL, NULL, NULL }, // A2 ADC3_INP0
{ PC_3C, NULL, NULL, NULL }, // A3 ADC3_INP1
{ PC_2_ALT0, NULL, NULL, NULL }, // A4 ADC1_INP12
{ PC_3_ALT0, NULL, NULL, NULL }, // A5 ADC1_INP13
{ PA_4, NULL, NULL, NULL }, // A6 ADC1_INP18

// LEDS
{ PK_5, NULL, NULL, NULL }, // LEDR
{ PK_6, NULL, NULL, NULL }, // LEDG
{ PK_7, NULL, NULL, NULL }, // LEDB
};
#endif


extern struct PinDescription g_APinDescription;
// extern void pinMode(pin_size_t pinNumber, PinMode pinMode);

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 )
// if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
// if ( g_APinDescription[ulPin].gpio == PIO_NOT_A_PIN )
// if ( g_APinDescription[pin].gpio == PIO_NOT_A_PIN )
// if ( g_APinDescription[pin] == PIO_NOT_A_PIN )
// {
// return -1 ;
// }
Expand All @@ -44,19 +102,24 @@ int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
// Configure pin mode, if requested
if ( ulPeripheral == PIO_INPUT )
{
pin_mode( ulPin, INPUT ) ; // pinMode( ulPin, INPUT ) ;
pin_mode( ulPin, INPUT ) ; // pinMode( ulPin, INPUT ) ;

// pinMode( ulPin, INPUT ) ; // pinMode( ulPin, INPUT ) ;
}
else
{
if ( ulPeripheral == PIO_INPUT_PULLUP )
{
pin_mode( ulPin, INPUT_PULLUP ) ; // pinMode( ulPin, INPUT_PULLUP ) ;
pin_mode( ulPin, INPUT_PULLUP ) ; // pinMode( ulPin, INPUT_PULLUP ) ;
// pinMode( ulPin, INPUT_PULLUP ) ; // pinMode( ulPin, INPUT_PULLUP ) ;
}
else
{
if ( ulPeripheral == PIO_OUTPUT )
{
pin_mode( ulPin, OUTPUT ) ; // pinMode( ulPin, OUTPUT ) ;
pin_mode( ulPin, OUTPUT ) ; // pinMode( ulPin, OUTPUT ) ;
// gpio_init_out(&gpio, ulPin);
// pinMode( ulPin, OUTPUT ) ; // pinMode( ulPin, OUTPUT ) ;
}
else
{
Expand Down Expand Up @@ -123,3 +186,20 @@ int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
return 0l ;
}



void shiftOutMatrix(pin_size_t dataPin, uint8_t clockPin, BitOrder bitOrder, uint32_t val)
{
uint32_t i;

for (i = 0; i < 32; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)) ? HIGH : LOW);
else
digitalWrite(dataPin, !!(val & (1 << (31 - i))) ? HIGH : LOW);

digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

19 changes: 16 additions & 3 deletions cores/arduino/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,31 @@
#include <stdio.h>
#include <stdarg.h>

// #include "gpio_object.h"

#include "Arduino.h"
#include "WVariant.h"
#ifdef __cplusplus
extern "C"{
#endif
// #include "wiring_constants.h"
#include "api/Common.h" // H7 equivalent
/// #include "api/Common.h" // H7 equivalent
typedef void (*voidFuncPtr)(void);

#if 0
typedef struct {
uint32_t mask;
__IO uint32_t *reg_in;
__IO uint32_t *reg_set;
__IO uint32_t *reg_clr;
PinName pin;
GPIO_TypeDef *gpio;
uint32_t ll_pin;
} gpio_t;
#endif
// gpio_t gpio;

int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral );

void shiftOutMatrix(pin_size_t dataPin, uint8_t clockPin, BitOrder bitOrder, uint32_t val);
#ifdef __cplusplus
} // extern "C"
#endif
Expand Down