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)

0 commit comments

Comments
 (0)