mirror of https://github.com/ARMmbed/mbed-os.git
Removed extra checks for operator[] and replaced them with MBED_ASSERT for cleaner code
parent
d068a2b479
commit
8c50826562
|
@ -68,8 +68,6 @@ public:
|
|||
return _nc_mask;
|
||||
}
|
||||
|
||||
static DigitalIn din_dummy;
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
|
|
|
@ -82,8 +82,6 @@ public:
|
|||
return _nc_mask;
|
||||
}
|
||||
|
||||
static DigitalInOut dinout_dummy;
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
|
|
|
@ -66,8 +66,6 @@ public:
|
|||
return _nc_mask;
|
||||
}
|
||||
|
||||
static DigitalOut dout_dummy;
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
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};
|
||||
|
||||
|
@ -73,11 +71,8 @@ BusIn::operator int() {
|
|||
}
|
||||
|
||||
DigitalIn& BusIn::operator[] (int index) {
|
||||
MBED_ASSERT(index < 0 || index >= 16);
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
if (index >= 16 || _pin[index] == NULL) {
|
||||
return din_dummy;
|
||||
}
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
DigitalInOut BusInOut::dinout_dummy(NC);
|
||||
|
||||
BusInOut::BusInOut(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};
|
||||
|
||||
|
@ -103,11 +101,8 @@ BusInOut& BusInOut::operator= (BusInOut& rhs) {
|
|||
}
|
||||
|
||||
DigitalInOut& BusInOut::operator[] (int index) {
|
||||
MBED_ASSERT(index < 0 || index >= 16);
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
if (index >= 16 || _pin[index] == NULL) {
|
||||
return dinout_dummy;
|
||||
}
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
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};
|
||||
|
||||
|
@ -79,11 +77,8 @@ BusOut& BusOut::operator= (BusOut& rhs) {
|
|||
}
|
||||
|
||||
DigitalOut& BusOut::operator[] (int index) {
|
||||
MBED_ASSERT(index < 0 || index >= 16);
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
if (index >= 16 || _pin[index] == NULL) {
|
||||
return dout_dummy;
|
||||
}
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
namespace {
|
||||
BusOut bus_out(LED1, LED2, LED3, LED4);
|
||||
PinName led_pins[4] = {LED1, LED2, LED3, LED4}; // Temp, used to map pins in bus_out
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -26,21 +29,18 @@ int main()
|
|||
}
|
||||
|
||||
// Checking if DigitalOut is correctly set as connected
|
||||
for (int i=0; i<4; i++) {
|
||||
printf("MBED: BusOut.bit[%d] is %s\r\n", i, bus_out[i].is_connected() ? "connected" : "not connected");
|
||||
for (int i=0; i < 4; i++) {
|
||||
printf("MBED: BusOut.bit[%d] is %s\r\n",
|
||||
i,
|
||||
(led_pins[i] != NC && bus_out[i].is_connected())
|
||||
? "connected"
|
||||
: "not connected");
|
||||
}
|
||||
|
||||
if (LED1 != NC && bus_out[0].is_connected() == 0) {
|
||||
break;
|
||||
}
|
||||
if (LED1 != NC && bus_out[1].is_connected() == 0) {
|
||||
break;
|
||||
}
|
||||
if (LED1 != NC && bus_out[2].is_connected() == 0) {
|
||||
break;
|
||||
}
|
||||
if (LED1 != NC && bus_out[3].is_connected() == 0) {
|
||||
break;
|
||||
for (int i=0; i < 4; i++) {
|
||||
if (led_pins[i] != NC && bus_out[0].is_connected() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Write mask all LEDs
|
||||
|
@ -58,18 +58,25 @@ int main()
|
|||
break;
|
||||
}
|
||||
|
||||
printf("MBED: Blinking LEDs...\r\n");
|
||||
printf("MBED: Blinking LEDs: \r\n");
|
||||
|
||||
// Just a quick LED blinking...
|
||||
for (int i=0; i<4; i++) {
|
||||
if (bus_out[i].is_connected()) {
|
||||
if (led_pins[i] != NC && bus_out[i].is_connected()) {
|
||||
bus_out[i] = 1;
|
||||
printf("%c", 'A' + i);
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
wait(0.2);
|
||||
if (bus_out[i].is_connected()) {
|
||||
if (led_pins[i] != NC && bus_out[i].is_connected()) {
|
||||
bus_out[i] = 0;
|
||||
printf("%c", 'a' + i);
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
notify_completion(result);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue