Skip to content

Flip IOPORT_CFG_PMOS to _NMOS as needed #358

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

Closed
wants to merge 21 commits into from
Closed
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
33 changes: 15 additions & 18 deletions cores/arduino/Interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#if EXT_INTERRUPTS_HOWMANY > 0

extern const PinMuxCfg_t g_pin_cfg[];

#define MAX_IRQ_CHANNEL (15)
constexpr int MAX_IRQ_CHANNEL = 15;

using IrqFuncVoid_f = void (*)();
using IrqFuncParam_f = void (*)(void *);
Expand All @@ -43,13 +42,11 @@ class IrqPool {
public:
IrqPool() {}
~IrqPool() {
for(int i = 0; i < MAX_IRQ_CHANNEL; i++) {
if(irqs[i] != nullptr){
delete irqs[i];
irqs[i] = nullptr;
}
for (auto& irq : irqs) {
delete irq;
irq = nullptr;
}
}
}
CIrq *get(int index, bool make) {
if(index < MAX_IRQ_CHANNEL) {
if(irqs[index] == nullptr && make) {
Expand Down Expand Up @@ -95,7 +92,7 @@ static void IrqCallback(external_irq_callback_args_t * p_args) {
void * param = (void *)p_args->p_context;
uint32_t ch = p_args->channel;

CIrq *irq_context = nullptr;
auto *irq_context = nullptr;

if(ch < MAX_IRQ_CHANNEL) {
irq_context = IrqChannel.get(ch,false);
Expand All @@ -118,8 +115,8 @@ static void IrqCallback(external_irq_callback_args_t * p_args) {
void detachInterrupt(pin_size_t pinNumber) {
/* -------------------------------------------------------------------------- */

CIrq *irq_context = nullptr;
int ch = pin2IrqChannel(pinNumber);
auto *irq_context = nullptr;
const int ch = pin2IrqChannel(pinNumber);

if(ch >= 0 && ch < MAX_IRQ_CHANNEL) {
irq_context = IrqChannel.get(ch,false);
Expand All @@ -137,8 +134,8 @@ void detachInterrupt(pin_size_t pinNumber) {
void attachInterruptParam(pin_size_t pinNumber, voidFuncPtrParam func, PinStatus mode, void* param) {
/* -------------------------------------------------------------------------- */

CIrq *irq_context = nullptr;
int ch = pin2IrqChannel(pinNumber);
auto *irq_context = nullptr;
const int ch = pin2IrqChannel(pinNumber);

if(ch >= 0 && ch < MAX_IRQ_CHANNEL) {
irq_context = IrqChannel.get(ch,true);
Expand Down Expand Up @@ -190,12 +187,12 @@ void attachInterruptParam(pin_size_t pinNumber, voidFuncPtrParam func, PinStatus
}

void attachInterrupt(pin_size_t pinNumber, voidFuncPtr func, PinStatus mode) {
attachInterruptParam(pinNumber, (voidFuncPtrParam)func, mode, NULL);
attachInterruptParam(pinNumber, (voidFuncPtrParam)func, mode, nullptr);
}

int attachIrq2Link(uint32_t pinNumber, PinStatus mode) {
CIrq *irq_context = nullptr;
int ch = pin2IrqChannel(pinNumber);
auto *irq_context = nullptr;
const int ch = pin2IrqChannel(pinNumber);

if(ch >= 0 && ch < MAX_IRQ_CHANNEL) {
irq_context = IrqChannel.get(ch,true);
Expand Down Expand Up @@ -248,8 +245,8 @@ int attachIrq2Link(uint32_t pinNumber, PinStatus mode) {
int detachIrq2Link(pin_size_t pinNumber) {
/* -------------------------------------------------------------------------- */

CIrq *irq_context = nullptr;
int ch = pin2IrqChannel(pinNumber);
auto *irq_context = nullptr;
const int ch = pin2IrqChannel(pinNumber);

if(ch >= 0 && ch < MAX_IRQ_CHANNEL) {
irq_context = IrqChannel.get(ch,false);
Expand Down
22 changes: 12 additions & 10 deletions cores/arduino/Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Tone {
}

void start(void) {
if ((frequency != 0) && (channel != -1)) {
if (frequency != 0 && channel != -1) {
tone_timer.start();
}
if (duration != 0) {
Expand All @@ -37,14 +37,14 @@ class Tone {

void toggle() {
digitalWrite(pin, status);
status = !!!status;
status = !status;
if (millis() > limit) {
stop();
}
}

void stop(void) {
if ((frequency != 0) && (channel != -1)) {
if (frequency != 0 && channel != -1) {
tone_timer.stop();
}
digitalWrite(pin, LOW);
Expand All @@ -66,17 +66,19 @@ class Tone {
}
}
}
};
}

FspTimer Tone::tone_timer;
int Tone::channel = -1;
static Tone* active_tone = NULL;
static Tone* active_tone = nullptr;

void tone_timer_callback(timer_callback_args_t __attribute__((unused)) *args) {
active_tone->toggle();
if (active_tone) {
active_tone->toggle();
}
}

void tone(pin_size_t pin, unsigned int frequency, unsigned long duration) {
void tone(pin_size_t pin, unsigned int frequency, unsigned long duration = 0) {
if (active_tone) {
if (active_tone->pin == pin && active_tone->frequency == frequency && active_tone->duration == 0) {
// infinite duration notes do not need to be restarted
Expand All @@ -87,12 +89,12 @@ void tone(pin_size_t pin, unsigned int frequency, unsigned long duration) {
Tone* t = new Tone(pin, frequency, duration);
active_tone = t;
t->start();
};
}

void noTone(pin_size_t __attribute__((unused)) pin) {
if (active_tone) {
active_tone->stop();
delete active_tone;
active_tone = NULL;
active_tone = nullptr;
}
};
}
42 changes: 23 additions & 19 deletions cores/arduino/digital.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
#include "Arduino.h"

void pinMode(pin_size_t pin, const PinMode mode) {
switch (mode) {
case INPUT:
case INPUT_PULLDOWN: // TODO: document the INPUT_PULLDOWN is unavailable
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT);
break;
case INPUT_PULLUP:
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE);
break;
case OUTPUT:
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
break;
case OUTPUT_OPENDRAIN:
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE);
break;
}
switch (mode) {
case INPUT:
case INPUT_PULLDOWN: // TODO: document that INPUT_PULLDOWN is unavailable
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT);
break;
case INPUT_PULLUP:
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE);
break;
case OUTPUT:
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT);
break;
case OUTPUT_OPENDRAIN:
#if defined(ARDUINO_UNO)
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_NMOS_ENABLE);
#else
R_IOPORT_PinCfg(NULL, g_pin_cfg[pin].pin, IOPORT_CFG_PORT_DIRECTION_OUTPUT | IOPORT_CFG_PMOS_ENABLE);
#endif
break;
}
}

void digitalWrite(pin_size_t pin, PinStatus val) {
R_IOPORT_PinWrite(NULL, g_pin_cfg[pin].pin, val == LOW ? BSP_IO_LEVEL_LOW : BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(NULL, g_pin_cfg[pin].pin, val == LOW ? BSP_IO_LEVEL_LOW : BSP_IO_LEVEL_HIGH);
}

PinStatus digitalRead(pin_size_t pin) {
bsp_io_level_t ret;
R_IOPORT_PinRead(NULL, g_pin_cfg[pin].pin, &ret);
return (ret == BSP_IO_LEVEL_LOW ? LOW : HIGH);
bsp_io_level_t ret;
R_IOPORT_PinRead(NULL, g_pin_cfg[pin].pin, &ret);
return (ret == BSP_IO_LEVEL_LOW ? LOW : HIGH);
}
7 changes: 6 additions & 1 deletion libraries/RTC/src/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ bool RTCTime::setYear(int _y) {
if (_y >= TM_YEAR_OFFSET) {
_y -= TM_YEAR_OFFSET;
}
if (_y < 0 || _y > 99) { // Valid range for RTC is 2000-2099
return false;
}
year = _y;
stime.tm_year = _y;
//stime.tm_yday = day + yday(year, Month2tm(month));
Expand Down Expand Up @@ -345,6 +348,9 @@ bool RTCTime::setSaveLight(SaveLight sl) {
bool RTCTime::setUnixTime(time_t time) {
struct tm *t;
t = localtime(&time);
if (t->tm_year < 100 || t->tm_year > 199) {
return false;
}
setTM(*t);
return true;
}
Expand Down Expand Up @@ -715,4 +721,3 @@ bool RTClock::setTimeIfNotRunning(RTCTime &t) {
RTClock RTC;
#endif


13 changes: 12 additions & 1 deletion libraries/WiFiS3/src/WiFiTypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#ifndef WIFI_S3_TYPES_H
#define WIFI_S3_TYPES_H

#define WL_SSID_MAX_LENGTH 32
#define WL_WPA_KEY_MAX_LENGTH 63
#define WL_WEP_KEY_MAX_LENGTH 13
#define WL_MAC_ADDR_LENGTH 6
#define WL_IPV4_LENGTH 4
#define WL_NETWORKS_LIST_MAXNUM 10
#define MAX_SOCK_NUM 4
#define SOCK_NOT_AVAIL 255
#define NA_STATE -1
#define WL_MAX_ATTEMPT_CONNECTION 10

typedef enum {
WL_NO_SHIELD = 255,
WL_NO_MODULE = WL_NO_SHIELD,
Expand Down Expand Up @@ -31,4 +42,4 @@ enum wl_enc_type {
ENC_TYPE_UNKNOWN = 255
};

#endif
#endif
Loading