Skip to content

Commit afa7630

Browse files
authored
Merge pull request #11632 from mprse/explicit_pinmap_gold_2
Add explicit pin-map support for extra targets
2 parents 4e8222a + d38c7d6 commit afa7630

File tree

55 files changed

+2606
-1495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2606
-1495
lines changed

drivers/AnalogIn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class AnalogIn {
7272
* @param pinmap reference to structure which holds static pinmap.
7373
*/
7474
AnalogIn(const PinMap &pinmap);
75+
AnalogIn(const PinMap &&) = delete; // prevent passing of temporary objects
7576

7677
/** Create an AnalogIn, connected to the specified pin
7778
*

drivers/AnalogOut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class AnalogOut {
7070
*
7171
* @param pinmap reference to structure which holds static pinmap.
7272
*/
73+
AnalogOut(const PinMap &&) = delete; // prevent passing of temporary objects
7374
AnalogOut(const PinMap &pinmap)
7475
{
7576
analogout_init_direct(&_dac, &pinmap);

drivers/CAN.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ class CAN : private NonCopyable<CAN> {
170170
*/
171171
CAN(PinName rd, PinName td, int hz);
172172

173+
/** Initialize CAN interface
174+
*
175+
* @param pinmap reference to structure which holds static pinmap
176+
* @param td the transmit pin
177+
* @param hz the bus frequency in hertz
178+
*/
179+
CAN(const can_pinmap_t &pinmap);
180+
CAN(const can_pinmap_t &&) = delete; // prevent passing of temporary objects
181+
182+
/** Initialize CAN interface and set the frequency
183+
*
184+
* @param pinmap reference to structure which holds static pinmap
185+
* @param td the transmit pin
186+
* @param hz the bus frequency in hertz
187+
*/
188+
CAN(const can_pinmap_t &pinmap, int hz);
189+
CAN(const can_pinmap_t &&, int) = delete; // prevent passing of temporary objects
190+
173191
virtual ~CAN();
174192

175193
/** Set the frequency of the CAN interface
@@ -343,4 +361,3 @@ class CAN : private NonCopyable<CAN> {
343361
#endif
344362

345363
#endif // MBED_CAN_H
346-

drivers/I2C.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class I2C : private NonCopyable<I2C> {
106106
* @param explicit_pinmap reference to structure which holds static pinmap.
107107
*/
108108
I2C(const i2c_pinmap_t &explicit_pinmap);
109+
I2C(const i2c_pinmap_t &&) = delete; // prevent passing of temporary objects
109110

110111
/** Set the frequency of the I2C interface
111112
*

drivers/I2CSlave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class I2CSlave {
9191
* @param explicit_pinmap reference to structure which holds static pinmap.
9292
*/
9393
I2CSlave(const i2c_pinmap_t &explicit_pinmap);
94+
I2CSlave(const i2c_pinmap_t &&) = delete; // prevent passing of temporary objects
9495

9596
/** Set the frequency of the I2C interface.
9697
*

drivers/PwmOut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class PwmOut {
6666
* @param pinmap reference to structure which holds static pinmap.
6767
*/
6868
PwmOut(const PinMap &pinmap);
69+
PwmOut(const PinMap &&) = delete; // prevent passing of temporary objects
6970

7071
~PwmOut();
7172

drivers/QSPI.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ class QSPI : private NonCopyable<QSPI> {
102102
*
103103
*/
104104
QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel = NC, int mode = 0);
105+
106+
/** Create a QSPI master connected to the specified pins
107+
*
108+
* io0-io3 is used to specify the Pins used for Quad SPI mode
109+
*
110+
* @param pinmap reference to structure which holds static pinmap
111+
* @param mode Clock polarity and phase mode (0 - 3) of SPI
112+
* (Default: Mode=0 uses CPOL=0, CPHA=0, Mode=1 uses CPOL=1, CPHA=1)
113+
*
114+
*/
115+
QSPI(const qspi_pinmap_t &pinmap, int mode = 0);
116+
QSPI(const qspi_pinmap_t &&, int = 0) = delete; // prevent passing of temporary objects
117+
105118
virtual ~QSPI()
106119
{
107120
}
@@ -222,13 +235,16 @@ class QSPI : private NonCopyable<QSPI> {
222235
int _mode; //SPI mode
223236
bool _initialized;
224237
PinName _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs; //IO lines, clock and chip select
238+
const qspi_pinmap_t *_explicit_pinmap;
239+
bool (QSPI::* _init_func)(void);
225240

226241
private:
227242
/* Private acquire function without locking/unlocking
228243
* Implemented in order to avoid duplicate locking and boost performance
229244
*/
230245
bool _acquire(void);
231246
bool _initialize();
247+
bool _initialize_direct();
232248

233249
/*
234250
* This function builds the qspi command struct to be send to Hal

drivers/SPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class SPI : private NonCopyable<SPI> {
143143
* @param explicit_pinmap reference to structure which holds static pinmap.
144144
*/
145145
SPI(const spi_pinmap_t &explicit_pinmap);
146+
SPI(const spi_pinmap_t &&) = delete; // prevent passing of temporary objects
146147

147148
/** Create a SPI master connected to the specified pins.
148149
*
@@ -157,6 +158,7 @@ class SPI : private NonCopyable<SPI> {
157158
* @param ssel SPI Chip Select pin.
158159
*/
159160
SPI(const spi_pinmap_t &explicit_pinmap, PinName ssel);
161+
SPI(const spi_pinmap_t &&, PinName) = delete; // prevent passing of temporary objects
160162

161163
virtual ~SPI();
162164

drivers/SPISlave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class SPISlave : private NonCopyable<SPISlave> {
7878
* @param explicit_pinmap reference to structure which holds static pinmap.
7979
*/
8080
SPISlave(const spi_pinmap_t &pinmap);
81+
SPISlave(const spi_pinmap_t &&) = delete; // prevent passing of temporary objects
8182

8283
/** Configure the data transmission format.
8384
*

drivers/Serial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
8383
* Either tx or rx may be specified as NC (Not Connected) if unused
8484
*/
8585
Serial(const serial_pinmap_t &explicit_pinmap, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
86+
Serial(const serial_pinmap_t &&, const char * = NULL, int = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) = delete; // prevent passing of temporary objects
8687

8788
/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
8889
*
@@ -104,6 +105,7 @@ class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
104105
* Either tx or rx may be specified as NC (Not Connected) if unused
105106
*/
106107
Serial(const serial_pinmap_t &explicit_pinmap, int baud);
108+
Serial(const serial_pinmap_t &&, int) = delete; // prevent passing of temporary objects
107109

108110
/* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
109111
* the calls from the SerialBase instead for backwards compatibility. This problem is

drivers/source/CAN.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,28 @@ namespace mbed {
2525
CAN::CAN(PinName rd, PinName td) : _can(), _irq()
2626
{
2727
// No lock needed in constructor
28-
29-
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
30-
_irq[i] = NULL;
31-
}
32-
3328
can_init(&_can, rd, td);
3429
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
3530
}
3631

3732
CAN::CAN(PinName rd, PinName td, int hz) : _can(), _irq()
3833
{
3934
// No lock needed in constructor
35+
can_init_freq(&_can, rd, td, hz);
36+
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
37+
}
4038

41-
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
42-
_irq[i] = NULL;
43-
}
39+
CAN::CAN(const can_pinmap_t &pinmap) : _can(), _irq()
40+
{
41+
// No lock needed in constructor
42+
can_init_direct(&_can, &pinmap);
43+
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
44+
}
4445

45-
can_init_freq(&_can, rd, td, hz);
46+
CAN::CAN(const can_pinmap_t &pinmap, int hz) : _can(), _irq()
47+
{
48+
// No lock needed in constructor
49+
can_init_freq_direct(&_can, &pinmap, hz);
4650
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
4751
}
4852

drivers/source/QSPI.cpp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, Pin
4949
_qspi_io3 = io3;
5050
_qspi_clk = sclk;
5151
_qspi_cs = ssel;
52+
_explicit_pinmap = NULL;
5253
_inst_width = QSPI_CFG_BUS_SINGLE;
5354
_address_width = QSPI_CFG_BUS_SINGLE;
5455
_address_size = QSPI_CFG_ADDR_SIZE_24;
@@ -59,9 +60,36 @@ QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, Pin
5960
_mode = mode;
6061
_hz = ONE_MHZ;
6162
_initialized = false;
63+
_init_func = &QSPI::_initialize;
6264

6365
//Go ahead init the device here with the default config
64-
bool success = _initialize();
66+
bool success = (this->*_init_func)();
67+
MBED_ASSERT(success);
68+
}
69+
70+
QSPI::QSPI(const qspi_pinmap_t &pinmap, int mode) : _qspi()
71+
{
72+
_qspi_io0 = pinmap.data0_pin;
73+
_qspi_io1 = pinmap.data1_pin;
74+
_qspi_io2 = pinmap.data2_pin;
75+
_qspi_io3 = pinmap.data3_pin;
76+
_qspi_clk = pinmap.sclk_pin;
77+
_qspi_cs = pinmap.ssel_pin;
78+
_explicit_pinmap = &pinmap;
79+
_inst_width = QSPI_CFG_BUS_SINGLE;
80+
_address_width = QSPI_CFG_BUS_SINGLE;
81+
_address_size = QSPI_CFG_ADDR_SIZE_24;
82+
_alt_width = QSPI_CFG_BUS_SINGLE;
83+
_alt_size = QSPI_CFG_ALT_SIZE_8;
84+
_data_width = QSPI_CFG_BUS_SINGLE;
85+
_num_dummy_cycles = 0;
86+
_mode = mode;
87+
_hz = ONE_MHZ;
88+
_initialized = false;
89+
_init_func = &QSPI::_initialize_direct;
90+
91+
//Go ahead init the device here with the default config
92+
bool success = (this->*_init_func)();
6593
MBED_ASSERT(success);
6694
}
6795

@@ -255,12 +283,30 @@ bool QSPI::_initialize()
255283
return _initialized;
256284
}
257285

286+
// Note: Private helper function to initialize qspi HAL
287+
bool QSPI::_initialize_direct()
288+
{
289+
if (_mode != 0 && _mode != 1) {
290+
_initialized = false;
291+
return _initialized;
292+
}
293+
294+
qspi_status_t ret = qspi_init_direct(&_qspi, _explicit_pinmap, _hz, _mode);
295+
if (QSPI_STATUS_OK == ret) {
296+
_initialized = true;
297+
} else {
298+
_initialized = false;
299+
}
300+
301+
return _initialized;
302+
}
303+
258304
// Note: Private function with no locking
259305
bool QSPI::_acquire()
260306
{
261307
if (_owner != this) {
262308
//This will set freq as well
263-
_initialize();
309+
(this->*_init_func)();
264310
_owner = this;
265311
}
266312

hal/can_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,22 @@ typedef enum {
5555
MODE_TEST_SILENT
5656
} CanMode;
5757

58+
typedef struct {
59+
int peripheral;
60+
PinName rd_pin;
61+
int rd_function;
62+
PinName td_pin;
63+
int td_function;
64+
} can_pinmap_t;
65+
5866
typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
5967

6068
typedef struct can_s can_t;
6169

6270
void can_init(can_t *obj, PinName rd, PinName td);
71+
void can_init_direct(can_t *obj, const can_pinmap_t *pinmap);
6372
void can_init_freq(can_t *obj, PinName rd, PinName td, int hz);
73+
void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz);
6474
void can_free(can_t *obj);
6575
int can_frequency(can_t *obj, int hz);
6676

hal/explicit_pinmap.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ MBED_WEAK void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap)
4242
#if DEVICE_ANALOGIN
4343
MBED_WEAK void analogin_init_direct(analogin_t *obj, const PinMap *pinmap)
4444
{
45-
printf("Pin: %d \r\n", pinmap->pin);
46-
//wait_ns(5000);
47-
4845
analogin_init(obj, pinmap->pin);
4946
}
5047
#endif
@@ -75,4 +72,25 @@ MBED_WEAK void serial_set_flow_control_direct(serial_t *obj, FlowControl type, c
7572
serial_set_flow_control(obj, type, pinmap->rx_flow_pin, pinmap->tx_flow_pin);
7673
}
7774
#endif
75+
76+
#if DEVICE_CAN
77+
MBED_WEAK void can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz)
78+
{
79+
can_init_freq(obj, pinmap->rd_pin, pinmap->td_pin, hz);
80+
}
81+
82+
MBED_WEAK void can_init_direct(can_t *obj, const can_pinmap_t *pinmap)
83+
{
84+
can_init(obj, pinmap->rd_pin, pinmap->td_pin);
85+
}
86+
87+
#endif
88+
89+
#if DEVICE_QSPI
90+
MBED_WEAK qspi_status_t qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_t hz, uint8_t mode)
91+
{
92+
return qspi_init(obj, pinmap->data0_pin, pinmap->data1_pin, pinmap->data2_pin, pinmap->data3_pin, pinmap->sclk_pin, pinmap->ssel_pin, hz, mode);
93+
}
94+
#endif
95+
7896
#endif

0 commit comments

Comments
 (0)