Skip to content

Commit c8c79e2

Browse files
authored
Merge pull request #107 from facchinm/restore_pincount
Restore and use PINCOUNT_fn() wrapper
2 parents cfbcc00 + a6843a2 commit c8c79e2

File tree

17 files changed

+44
-47
lines changed

17 files changed

+44
-47
lines changed

cores/arduino/Arduino.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ ioport_peripheral_t getPinConfig(bsp_io_port_pin_t pin);
6161
extern "C" {
6262
#endif
6363
extern const PinMuxCfg_t g_pin_cfg[];
64-
extern const size_t g_pin_cfg_size;
6564
#if defined(__cplusplus)
6665
}
6766
#endif

cores/arduino/Interrupts.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#if EXT_INTERRUPTS_HOWMANY > 0
2525

2626
extern const PinMuxCfg_t g_pin_cfg[];
27-
extern const size_t g_pin_cfg_size;
2827

2928
#define MAX_IRQ_CHANNEL (15)
3029

@@ -76,7 +75,7 @@ pin_size_t digitalPinToInterrupt(pin_size_t pin) { return pin; }
7675
static int pin2IrqChannel(int pin) {
7776
/* -------------------------------------------------------------------------- */
7877
/* verify index are good */
79-
if(pin < 0 || pin >= (int)(g_pin_cfg_size / sizeof(g_pin_cfg[0]))) {
78+
if(pin < 0 || pin >= PINS_COUNT) {
8079
return -1;
8180
}
8281
/* getting configuration from table */

cores/arduino/Serial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ bool UART::cfg_pins(int max_index) {
194194
/* -------------------------------------------------------------------------- */
195195
void UART::begin(unsigned long baudrate, uint16_t config) {
196196
/* -------------------------------------------------------------------------- */
197-
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
197+
int max_index = PINS_COUNT;
198198

199199
init_ok = cfg_pins(max_index);
200200

cores/arduino/pwm.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include "pwm.h"
33
#include "bsp_api.h"
44

5-
extern const PinMuxCfg_t g_pin_cfg[];
6-
extern const size_t g_pin_cfg_size;
7-
85
PwmOut::PwmOut(int pinNumber) :
96
_pin(pinNumber),
107
_enabled(false)
@@ -43,7 +40,7 @@ bool PwmOut::cfg_pin(int max_index) {
4340
/* default begin function, starts the timers with default pwm configuration (490Hz and 50%) */
4441
bool PwmOut::begin() {
4542
bool rv = true;
46-
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
43+
int max_index = PINS_COUNT;
4744
rv &= cfg_pin(max_index);
4845

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

7370
if(_enabled) {

cores/arduino/variant_helper.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#include "Arduino.h"
22
#include "variant.h"
33

4-
extern const PinMuxCfg_t g_pin_cfg[];
5-
extern const size_t g_pin_cfg_size;
6-
74
std::array<uint16_t, 3> getPinCfgs(const pin_size_t pin, PinCfgReq_t req) {
85

96
std::array<uint16_t, 3> ret = {0 , 0, 0};
10-
if (pin > g_pin_cfg_size) {
7+
if (pin > PINS_COUNT) {
118
return ret;
129
}
1310

libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool R7FA4M1_CAN::begin(CanBitRate const can_bitrate)
142142

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

148148
/* Configure the interrupts.

libraries/Arduino_CAN/src/R7FA6M5_CAN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool R7FA6M5_CAN::begin(CanBitRate const can_bitrate)
105105

106106
/* Configure the pins for CAN.
107107
*/
108-
int const max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
108+
int const max_index = PINS_COUNT;
109109
auto [cfg_init_ok, cfg_channel] = cfg_pins(max_index, _can_tx_pin, _can_rx_pin);
110110
init_ok &= cfg_init_ok;
111111
_canfd_cfg.channel = cfg_channel;

libraries/SPI/SPI.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525

2626
using namespace arduino;
2727

28-
/**************************************************************************************
29-
* EXTERN GLOBAL CONSTANTS
30-
**************************************************************************************/
31-
32-
extern const PinMuxCfg_t g_pin_cfg[];
33-
extern const size_t g_pin_cfg_size;
34-
3528
/**************************************************************************************
3629
* GLOBAL MEMBER VARIABLES
3730
**************************************************************************************/
@@ -73,7 +66,7 @@ void ArduinoSPI::begin()
7366
/* Configure the pins and auto-determine channel and
7467
* whether or not we are using a SCI.
7568
*/
76-
int const max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
69+
int const max_index = PINS_COUNT;
7770
auto [cfg_pins_ok, cfg_channel, cfg_is_sci] = cfg_pins(max_index, _miso_pin, _mosi_pin, _sck_pin, _periph_mode);
7871
init_ok &= cfg_pins_ok;
7972
_channel = cfg_channel;

libraries/Wire/Wire.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool TwoWire::cfg_pins(int max_index) {
275275
void TwoWire::begin(void) {
276276
/* -------------------------------------------------------------------------- */
277277
init_ok = true;
278-
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
278+
int max_index = PINS_COUNT;
279279

280280
init_ok &= cfg_pins(max_index);
281281

variants/MINIMA/pins_arduino.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
// Pin count
66
// ----
7+
#ifdef __cplusplus
8+
extern "C" unsigned int PINCOUNT_fn();
9+
#endif
710
#define PINS_COUNT (PINCOUNT_fn())
811
#define NUM_DIGITAL_PINS (22u)
912
#define NUM_ANALOG_INPUTS (6u)

variants/MINIMA/variant.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
5050
{ BSP_IO_PORT_00_PIN_13, P013 }, /* (22) RX LED */
5151
};
5252

53-
extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
53+
extern "C" {
54+
unsigned int PINCOUNT_fn() {
55+
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
56+
}
57+
}
5458

5559
int32_t getPinIndex(bsp_io_port_pin_t p) {
56-
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
60+
int max_index = PINS_COUNT;
5761
int rv = -1;
5862
for(int i = 0; i < max_index; i++) {
5963
if(g_pin_cfg[i].pin == p) {

variants/MUXTO/pins_arduino.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#pragma once
22

3-
#ifdef __cplusplus
4-
extern "C" unsigned int PINCOUNT_fn();
5-
extern "C" unsigned int I2C_COUNT_fn();
6-
extern "C" unsigned int SPI_COUNT_fn();
7-
extern "C" unsigned int UART_COUNT_fn();
8-
extern "C" unsigned int SCI_COUNT_fn();
9-
#endif
10-
113
#define PIN(X,Y) (X * 16 + Y)
124

135
// Pin count
146
// ----
7+
#ifdef __cplusplus
8+
extern "C" unsigned int PINCOUNT_fn();
9+
#endif
1510
#define PINS_COUNT (PINCOUNT_fn())
1611
#define NUM_DIGITAL_PINS (22u)
1712
#define NUM_ANALOG_INPUTS (6u)

variants/MUXTO/variant.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
6262
{ BSP_IO_PORT_02_PIN_06, P206 }, /* (27) D27 */
6363
};
6464

65-
extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
65+
extern "C" {
66+
unsigned int PINCOUNT_fn() {
67+
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
68+
}
69+
}
6670

6771
const ioport_pin_cfg_t bsp_pin_cfg_data[] = {
6872
{ ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN | (uint32_t) IOPORT_PERIPHERAL_USB_FS), BSP_IO_PORT_09_PIN_15 },

variants/PORTENTA_C33/pins_arduino.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#pragma once
22

3-
#ifdef __cplusplus
4-
extern "C" unsigned int PINCOUNT_fn();
5-
extern "C" unsigned int I2C_COUNT_fn();
6-
extern "C" unsigned int SPI_COUNT_fn();
7-
extern "C" unsigned int UART_COUNT_fn();
8-
extern "C" unsigned int SCI_COUNT_fn();
9-
#endif
10-
113
#define PIN(X,Y) (X * 16 + Y)
124

135
// Pin count
146
// ----
7+
#ifdef __cplusplus
8+
extern "C" unsigned int PINCOUNT_fn();
9+
#endif
1510
#define PINS_COUNT (PINCOUNT_fn())
1611
#define NUM_DIGITAL_PINS (121u)
1712
#define NUM_ANALOG_INPUTS (8u)

variants/PORTENTA_C33/variant.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
198198
{ BSP_IO_PORT_02_PIN_08, P208 }, /* D121 | QSPI IO3 */
199199
};
200200

201-
extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
201+
extern "C" {
202+
unsigned int PINCOUNT_fn() {
203+
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
204+
}
205+
}
202206

203207
int32_t getPinIndex(bsp_io_port_pin_t p) {
204-
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
208+
int max_index = PINS_COUNT;
205209
int rv = -1;
206210
for(int i = 0; i < max_index; i++) {
207211
if(g_pin_cfg[i].pin == p) {

variants/UNOWIFIR4/pins_arduino.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
// Pin count
66
// ----
7+
#ifdef __cplusplus
8+
extern "C" unsigned int PINCOUNT_fn();
9+
#endif
710
#define PINS_COUNT (PINCOUNT_fn())
811
#define NUM_DIGITAL_PINS (22u)
912
#define NUM_ANALOG_INPUTS (6u)

variants/UNOWIFIR4/variant.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
6969
{ BSP_IO_PORT_02_PIN_13, P213 }, /* (38) D38 */
7070
};
7171

72-
extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
72+
extern "C" {
73+
unsigned int PINCOUNT_fn() {
74+
return (sizeof(g_pin_cfg) / sizeof(g_pin_cfg[0]));
75+
}
76+
}
7377

7478
int32_t getPinIndex(bsp_io_port_pin_t p) {
75-
int max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
79+
int max_index = PINS_COUNT;
7680
int rv = -1;
7781
for(int i = 0; i < max_index; i++) {
7882
if(g_pin_cfg[i].pin == p) {

0 commit comments

Comments
 (0)