Skip to content

Commit

Permalink
Merge pull request #107 from facchinm/restore_pincount
Browse files Browse the repository at this point in the history
Restore and use PINCOUNT_fn() wrapper
  • Loading branch information
facchinm authored Aug 25, 2023
2 parents cfbcc00 + a6843a2 commit c8c79e2
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 47 deletions.
1 change: 0 additions & 1 deletion cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ ioport_peripheral_t getPinConfig(bsp_io_port_pin_t pin);
extern "C" {
#endif
extern const PinMuxCfg_t g_pin_cfg[];
extern const size_t g_pin_cfg_size;
#if defined(__cplusplus)
}
#endif
Expand Down
3 changes: 1 addition & 2 deletions cores/arduino/Interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#if EXT_INTERRUPTS_HOWMANY > 0

extern const PinMuxCfg_t g_pin_cfg[];
extern const size_t g_pin_cfg_size;

#define MAX_IRQ_CHANNEL (15)

Expand Down Expand Up @@ -76,7 +75,7 @@ pin_size_t digitalPinToInterrupt(pin_size_t pin) { return pin; }
static int pin2IrqChannel(int pin) {
/* -------------------------------------------------------------------------- */
/* verify index are good */
if(pin < 0 || pin >= (int)(g_pin_cfg_size / sizeof(g_pin_cfg[0]))) {
if(pin < 0 || pin >= PINS_COUNT) {
return -1;
}
/* getting configuration from table */
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool UART::cfg_pins(int max_index) {
/* -------------------------------------------------------------------------- */
void UART::begin(unsigned long baudrate, uint16_t config) {
/* -------------------------------------------------------------------------- */
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;

init_ok = cfg_pins(max_index);

Expand Down
7 changes: 2 additions & 5 deletions cores/arduino/pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "pwm.h"
#include "bsp_api.h"

extern const PinMuxCfg_t g_pin_cfg[];
extern const size_t g_pin_cfg_size;

PwmOut::PwmOut(int pinNumber) :
_pin(pinNumber),
_enabled(false)
Expand Down Expand Up @@ -43,7 +40,7 @@ bool PwmOut::cfg_pin(int max_index) {
/* default begin function, starts the timers with default pwm configuration (490Hz and 50%) */
bool PwmOut::begin() {
bool rv = true;
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;
rv &= cfg_pin(max_index);

if(rv) {
Expand All @@ -67,7 +64,7 @@ bool PwmOut::begin() {
bool PwmOut::begin(uint32_t period_width, uint32_t pulse_width, bool raw /*= false */, timer_source_div_t sd /*= TIMER_SOURCE_DIV_1*/) {
/* -------------------------------------------------------------------------- */
_enabled = true;
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;
_enabled &= cfg_pin(max_index);

if(_enabled) {
Expand Down
5 changes: 1 addition & 4 deletions cores/arduino/variant_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include "Arduino.h"
#include "variant.h"

extern const PinMuxCfg_t g_pin_cfg[];
extern const size_t g_pin_cfg_size;

std::array<uint16_t, 3> getPinCfgs(const pin_size_t pin, PinCfgReq_t req) {

std::array<uint16_t, 3> ret = {0 , 0, 0};
if (pin > g_pin_cfg_size) {
if (pin > PINS_COUNT) {
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bool R7FA4M1_CAN::begin(CanBitRate const can_bitrate)

/* Configure the pins for CAN.
*/
int const max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int const max_index = PINS_COUNT;
init_ok &= cfg_pins(max_index, _can_tx_pin, _can_rx_pin);

/* Configure the interrupts.
Expand Down
2 changes: 1 addition & 1 deletion libraries/Arduino_CAN/src/R7FA6M5_CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool R7FA6M5_CAN::begin(CanBitRate const can_bitrate)

/* Configure the pins for CAN.
*/
int const max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int const max_index = PINS_COUNT;
auto [cfg_init_ok, cfg_channel] = cfg_pins(max_index, _can_tx_pin, _can_rx_pin);
init_ok &= cfg_init_ok;
_canfd_cfg.channel = cfg_channel;
Expand Down
9 changes: 1 addition & 8 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@

using namespace arduino;

/**************************************************************************************
* EXTERN GLOBAL CONSTANTS
**************************************************************************************/

extern const PinMuxCfg_t g_pin_cfg[];
extern const size_t g_pin_cfg_size;

/**************************************************************************************
* GLOBAL MEMBER VARIABLES
**************************************************************************************/
Expand Down Expand Up @@ -73,7 +66,7 @@ void ArduinoSPI::begin()
/* Configure the pins and auto-determine channel and
* whether or not we are using a SCI.
*/
int const max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int const max_index = PINS_COUNT;
auto [cfg_pins_ok, cfg_channel, cfg_is_sci] = cfg_pins(max_index, _miso_pin, _mosi_pin, _sck_pin, _periph_mode);
init_ok &= cfg_pins_ok;
_channel = cfg_channel;
Expand Down
2 changes: 1 addition & 1 deletion libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool TwoWire::cfg_pins(int max_index) {
void TwoWire::begin(void) {
/* -------------------------------------------------------------------------- */
init_ok = true;
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;

init_ok &= cfg_pins(max_index);

Expand Down
3 changes: 3 additions & 0 deletions variants/MINIMA/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

// Pin count
// ----
#ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
#endif
#define PINS_COUNT (PINCOUNT_fn())
#define NUM_DIGITAL_PINS (22u)
#define NUM_ANALOG_INPUTS (6u)
Expand Down
8 changes: 6 additions & 2 deletions variants/MINIMA/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
{ BSP_IO_PORT_00_PIN_13, P013 }, /* (22) RX LED */
};

extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
extern "C" {
unsigned int PINCOUNT_fn() {
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
}
}

int32_t getPinIndex(bsp_io_port_pin_t p) {
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;
int rv = -1;
for(int i = 0; i < max_index; i++) {
if(g_pin_cfg[i].pin == p) {
Expand Down
11 changes: 3 additions & 8 deletions variants/MUXTO/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
extern "C" unsigned int I2C_COUNT_fn();
extern "C" unsigned int SPI_COUNT_fn();
extern "C" unsigned int UART_COUNT_fn();
extern "C" unsigned int SCI_COUNT_fn();
#endif

#define PIN(X,Y) (X * 16 + Y)

// Pin count
// ----
#ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
#endif
#define PINS_COUNT (PINCOUNT_fn())
#define NUM_DIGITAL_PINS (22u)
#define NUM_ANALOG_INPUTS (6u)
Expand Down
6 changes: 5 additions & 1 deletion variants/MUXTO/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
{ BSP_IO_PORT_02_PIN_06, P206 }, /* (27) D27 */
};

extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
extern "C" {
unsigned int PINCOUNT_fn() {
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
}
}

const ioport_pin_cfg_t bsp_pin_cfg_data[] = {
{ ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN | (uint32_t) IOPORT_PERIPHERAL_USB_FS), BSP_IO_PORT_09_PIN_15 },
Expand Down
11 changes: 3 additions & 8 deletions variants/PORTENTA_C33/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
extern "C" unsigned int I2C_COUNT_fn();
extern "C" unsigned int SPI_COUNT_fn();
extern "C" unsigned int UART_COUNT_fn();
extern "C" unsigned int SCI_COUNT_fn();
#endif

#define PIN(X,Y) (X * 16 + Y)

// Pin count
// ----
#ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
#endif
#define PINS_COUNT (PINCOUNT_fn())
#define NUM_DIGITAL_PINS (121u)
#define NUM_ANALOG_INPUTS (8u)
Expand Down
8 changes: 6 additions & 2 deletions variants/PORTENTA_C33/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
{ BSP_IO_PORT_02_PIN_08, P208 }, /* D121 | QSPI IO3 */
};

extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
extern "C" {
unsigned int PINCOUNT_fn() {
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
}
}

int32_t getPinIndex(bsp_io_port_pin_t p) {
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;
int rv = -1;
for(int i = 0; i < max_index; i++) {
if(g_pin_cfg[i].pin == p) {
Expand Down
3 changes: 3 additions & 0 deletions variants/UNOWIFIR4/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

// Pin count
// ----
#ifdef __cplusplus
extern "C" unsigned int PINCOUNT_fn();
#endif
#define PINS_COUNT (PINCOUNT_fn())
#define NUM_DIGITAL_PINS (22u)
#define NUM_ANALOG_INPUTS (6u)
Expand Down
8 changes: 6 additions & 2 deletions variants/UNOWIFIR4/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
{ BSP_IO_PORT_02_PIN_13, P213 }, /* (38) D38 */
};

extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
extern "C" {
unsigned int PINCOUNT_fn() {
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
}
}

int32_t getPinIndex(bsp_io_port_pin_t p) {
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
int max_index = PINS_COUNT;
int rv = -1;
for(int i = 0; i < max_index; i++) {
if(g_pin_cfg[i].pin == p) {
Expand Down

0 comments on commit c8c79e2

Please sign in to comment.