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
pull/808/head
Przemek Wirkus 2014-12-19 14:37:00 +00:00
parent c4fc8e68eb
commit db7e92853b
4 changed files with 44 additions and 0 deletions

View File

@ -58,6 +58,16 @@ public:
*/
void mode(PinMode pull);
/** Binary mask of bus pins connected to actual pins (not NC pins)
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
*
* @returns
* Binary mask of connected pins
*/
int mask() {
return _nc_mask;
}
static DigitalIn din_dummy;
#ifdef MBED_OPERATORS
@ -73,6 +83,10 @@ public:
protected:
DigitalIn* _pin[16];
/** Mask of NC pins, if bit [n] bit is set to 1, [n] pin in bus is in NC state
*/
int _nc_mask;
/* disallow copy constructor and assignment operators */
private:
BusIn(const BusIn&);

View File

@ -56,6 +56,16 @@ public:
*/
int read();
/** Binary mask of bus pins connected to actual pins (not NC pins)
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
*
* @returns
* Binary mask of connected pins
*/
int mask() {
return _nc_mask;
}
static DigitalOut dout_dummy;
#ifdef MBED_OPERATORS
@ -76,6 +86,10 @@ public:
protected:
DigitalOut* _pin[16];
/** Mask of NC pins, if bit [n] bit is set to 1, [n] pin in bus is in NC state
*/
int _nc_mask;
/* disallow copy constructor and assignment operators */
private:
BusOut(const BusOut&);

View File

@ -22,14 +22,22 @@ DigitalIn BusIn::din_dummy(NC);
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) {
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
_nc_mask = 0;
for (int i=0; i<16; i++) {
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
if (pins[i] != NC) {
_nc_mask |= (1 << i);
}
}
}
BusIn::BusIn(PinName pins[16]) {
_nc_mask = 0;
for (int i=0; i<16; i++) {
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
if (pins[i] != NC) {
_nc_mask |= (1 << i);
}
}
}

View File

@ -22,14 +22,22 @@ DigitalOut BusOut::dout_dummy(NC);
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) {
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
_nc_mask = 0;
for (int i=0; i<16; i++) {
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
if (pins[i] != NC) {
_nc_mask |= (1 << i);
}
}
}
BusOut::BusOut(PinName pins[16]) {
_nc_mask = 0;
for (int i=0; i<16; i++) {
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
if (pins[i] != NC) {
_nc_mask |= (1 << i);
}
}
}