Skip to content

check mux mode when using digitalWrite #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <stdbool.h>
#include <math.h>

#include "pins_arduino.h"

#include "binary.h"
//#include "itoa.h"

Expand Down Expand Up @@ -97,6 +99,8 @@ extern PinDescription g_APinDescription[] ;

extern uint32_t pwmPeriod[4];

extern uint8_t pinmuxMode[NUM_DIGITAL_PINS];

#ifdef __cplusplus
} // extern "C"

Expand Down
12 changes: 8 additions & 4 deletions cores/arduino/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ void analogWrite(uint8_t pin, uint32_t val)
/* start the PWM output */
offset = ((p->ulPwmChan * QRK_PWM_N_REGS_LEN) + QRK_PWM_N_CONTROL);
SET_MMIO_MASK(QRK_PWM_BASE_ADDR + offset, QRK_PWM_CONTROL_ENABLE);

/* Disable pull-up and set pin mux for PWM output */
SET_PIN_PULLUP(p->ulSocPin, 0);
SET_PIN_MODE(p->ulSocPin, PWM_MUX_MODE);

if(pinmuxMode[pin] != PWM_MUX_MODE)
{
/* Disable pull-up and set pin mux for PWM output */
SET_PIN_PULLUP(p->ulSocPin, 0);
SET_PIN_MODE(p->ulSocPin, PWM_MUX_MODE);
pinmuxMode[pin] = PWM_MUX_MODE;
}
}
}
uint32_t analogRead(uint32_t pin)
Expand Down
12 changes: 11 additions & 1 deletion cores/arduino/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@ void pinMode( uint8_t pin, uint8_t mode )
/* Set SoC pin mux configuration */
SET_PIN_PULLUP(p->ulSocPin, (mode == INPUT_PULLUP) ? 1 : 0);
SET_PIN_MODE(p->ulSocPin, GPIO_MUX_MODE);
if(pinmuxMode[pin] != GPIO_MUX_MODE)
{
pinmuxMode[pin] = GPIO_MUX_MODE;
}
}

void digitalWrite( uint8_t pin, uint8_t val )
{
if (pin >= NUM_DIGITAL_PINS) return;

PinDescription *p = &g_APinDescription[pin];


if(pinmuxMode[pin] != GPIO_MUX_MODE)
{
pinmuxMode[pin] = GPIO_MUX_MODE;
SET_PIN_MODE(p->ulSocPin, GPIO_MUX_MODE);
}

if (p->ulGPIOType == SS_GPIO) {
uint32_t reg = p->ulGPIOBase + SS_GPIO_SWPORTA_DR;
if (val)
Expand Down
4 changes: 2 additions & 2 deletions libraries/CurieSoftwareSerial/src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ void SoftwareSerial::begin(long speed)
{
_isSOCGpio = true;
}
//toggling a pin takes about 62 ticks
_tx_delay = _bit_delay - 62;
//toggling a pin takes about 68 ticks
_tx_delay = _bit_delay - 68;
//reading a pin takes about 70 ticks
_rx_delay_intrabit = _bit_delay - 70;
//it takes about 272 ticks from when the start bit is received to when the ISR is called
Expand Down
4 changes: 3 additions & 1 deletion libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ void SPIClass::begin()
SET_PIN_MODE(g_APinDescription[MOSI].ulSocPin, SPI_MUX_MODE);
SET_PIN_MODE(g_APinDescription[MISO].ulSocPin, SPI_MUX_MODE);
SET_PIN_MODE(g_APinDescription[SCK].ulSocPin, SPI_MUX_MODE);

pinmuxMode[MISO] = SPI_MUX_MODE;
pinmuxMode[MOSI] = SPI_MUX_MODE;
pinmuxMode[SCK] = SPI_MUX_MODE;
}
initialized++; /* reference count */
interrupt_unlock(flags);
Expand Down
3 changes: 3 additions & 0 deletions variants/arduino_101/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ PinDescription g_APinDescription[]=
} ;

uint32_t pwmPeriod[] = {PWM_PERIOD, PWM_PERIOD/2, PWM_PERIOD/2, PWM_PERIOD};

uint8_t pinmuxMode[];
#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -173,6 +175,7 @@ void variantGpioInit(void)
for (uint8_t pin = 0; pin < NUM_DIGITAL_PINS; pin++) {
PinDescription *p = &g_APinDescription[pin];
SET_PIN_MODE(p->ulSocPin, p->ulPinMode);
pinmuxMode[pin] = GPIO_MUX_MODE;
}
}

Expand Down