Skip to content

Commit db7e928

Browse files
committed
Added mask() function to BusIn and BusOut components
You can use BusIn::mask() or BusOut::mask() to get binary mask of all connected and NC pins in bus
1 parent c4fc8e6 commit db7e928

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

libraries/mbed/api/BusIn.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ class BusIn {
5858
*/
5959
void mode(PinMode pull);
6060

61+
/** Binary mask of bus pins connected to actual pins (not NC pins)
62+
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
63+
*
64+
* @returns
65+
* Binary mask of connected pins
66+
*/
67+
int mask() {
68+
return _nc_mask;
69+
}
70+
6171
static DigitalIn din_dummy;
6272

6373
#ifdef MBED_OPERATORS
@@ -73,6 +83,10 @@ class BusIn {
7383
protected:
7484
DigitalIn* _pin[16];
7585

86+
/** Mask of NC pins, if bit [n] bit is set to 1, [n] pin in bus is in NC state
87+
*/
88+
int _nc_mask;
89+
7690
/* disallow copy constructor and assignment operators */
7791
private:
7892
BusIn(const BusIn&);

libraries/mbed/api/BusOut.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ class BusOut {
5656
*/
5757
int read();
5858

59+
/** Binary mask of bus pins connected to actual pins (not NC pins)
60+
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
61+
*
62+
* @returns
63+
* Binary mask of connected pins
64+
*/
65+
int mask() {
66+
return _nc_mask;
67+
}
68+
5969
static DigitalOut dout_dummy;
6070

6171
#ifdef MBED_OPERATORS
@@ -76,6 +86,10 @@ class BusOut {
7686
protected:
7787
DigitalOut* _pin[16];
7888

89+
/** Mask of NC pins, if bit [n] bit is set to 1, [n] pin in bus is in NC state
90+
*/
91+
int _nc_mask;
92+
7993
/* disallow copy constructor and assignment operators */
8094
private:
8195
BusOut(const BusOut&);

libraries/mbed/common/BusIn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ DigitalIn BusIn::din_dummy(NC);
2222
BusIn::BusIn(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
2323
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
2424

25+
_nc_mask = 0;
2526
for (int i=0; i<16; i++) {
2627
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
28+
if (pins[i] != NC) {
29+
_nc_mask |= (1 << i);
30+
}
2731
}
2832
}
2933

3034
BusIn::BusIn(PinName pins[16]) {
35+
_nc_mask = 0;
3136
for (int i=0; i<16; i++) {
3237
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
38+
if (pins[i] != NC) {
39+
_nc_mask |= (1 << i);
40+
}
3341
}
3442
}
3543

libraries/mbed/common/BusOut.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ DigitalOut BusOut::dout_dummy(NC);
2222
BusOut::BusOut(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
2323
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
2424

25+
_nc_mask = 0;
2526
for (int i=0; i<16; i++) {
2627
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
28+
if (pins[i] != NC) {
29+
_nc_mask |= (1 << i);
30+
}
2731
}
2832
}
2933

3034
BusOut::BusOut(PinName pins[16]) {
35+
_nc_mask = 0;
3136
for (int i=0; i<16; i++) {
3237
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
38+
if (pins[i] != NC) {
39+
_nc_mask |= (1 << i);
40+
}
3341
}
3442
}
3543

0 commit comments

Comments
 (0)