Merge pull request #2137 from sg-/operators

Remove macro for operators. Enable these as default behavior
pull/2133/head
Sam Grove 2016-07-22 19:01:24 -05:00 committed by GitHub
commit 542fcca670
20 changed files with 47 additions and 123 deletions

View File

@ -717,53 +717,6 @@ TEST(BusOut_mask, led_1_nc_2_nc_nc_3)
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
CHECK_EQUAL(0x25, bus_data.mask());
}
///////////////////////////////////////////////////////////////////////////////
#ifdef MBED_OPERATORS
TEST_GROUP(BusOut_digitalout_write)
{
};
TEST(BusOut_digitalout_write, led_nc)
{
BusOut bus_data(NC);
CHECK_EQUAL(false, bus_data[0].is_connected())
}
TEST(BusOut_digitalout_write, led_1_2_3)
{
BusOut bus_data(LED1, LED2, LED3);
bus_data[0].write(1);
bus_data[1].write(1);
bus_data[2].write(1);
CHECK(bus_data[0].read());
CHECK(bus_data[1].read());
CHECK(bus_data[2].read());
}
TEST(BusOut_digitalout_write, led_1_2_3_nc_nc)
{
BusOut bus_data(LED1, LED2, LED3, NC, NC);
bus_data[0].write(0);
bus_data[1].write(0);
bus_data[2].write(0);
CHECK(bus_data[0].read() == 0);
CHECK(bus_data[1].read() == 0);
CHECK(bus_data[2].read() == 0);
}
TEST(BusOut_digitalout_write, led_1_nc_2_nc_nc_3)
{
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
bus_data[0].write(1);
bus_data[2].write(0);
bus_data[5].write(0);
CHECK(bus_data[0].read());
CHECK(bus_data[2].read() == 0);
CHECK(bus_data[5].read() == 0);
}
#endif
```
## Example

View File

@ -84,7 +84,6 @@ public:
return ret;
}
#ifdef MBED_OPERATORS
/** An operator shorthand for read()
*
* The float() operator can be used as a shorthand for read() to simplify common code sequences
@ -102,7 +101,6 @@ public:
// Underlying call is thread safe
return read();
}
#endif
virtual ~AnalogIn() {
// Do nothing

View File

@ -99,7 +99,6 @@ public:
return ret;
}
#ifdef MBED_OPERATORS
/** An operator shorthand for write()
*/
AnalogOut& operator= (float percent) {
@ -120,7 +119,6 @@ public:
// Underlying read call is thread safe
return read();
}
#endif
virtual ~AnalogOut() {
// Do nothing

View File

@ -71,7 +71,6 @@ public:
return _nc_mask;
}
#ifdef MBED_OPERATORS
/** A shorthand for read()
*/
operator int();
@ -79,7 +78,6 @@ public:
/** Access to particular bit in random-iterator fashion
*/
DigitalIn & operator[] (int index);
#endif
protected:
DigitalIn* _pin[16];

View File

@ -85,7 +85,6 @@ public:
return _nc_mask;
}
#ifdef MBED_OPERATORS
/** A shorthand for write()
*/
BusInOut& operator= (int v);
@ -98,7 +97,6 @@ public:
/** A shorthand for read()
*/
operator int();
#endif
protected:
virtual void lock();

View File

@ -69,7 +69,6 @@ public:
return _nc_mask;
}
#ifdef MBED_OPERATORS
/** A shorthand for write()
*/
BusOut& operator= (int v);
@ -82,7 +81,6 @@ public:
/** A shorthand for read()
*/
operator int();
#endif
protected:
virtual void lock();

View File

@ -154,14 +154,12 @@ public:
*/
void call();
#ifdef MBED_OPERATORS
void operator ()(void) {
call();
}
pFunctionPointer_t operator [](int i) const {
return get(i);
}
#endif
/* disallow copy constructor and assignment operators */
private:
@ -173,4 +171,3 @@ private:
} // namespace mbed
#endif

View File

@ -99,14 +99,12 @@ public:
return gpio_is_connected(&gpio);
}
#ifdef MBED_OPERATORS
/** An operator shorthand for read()
*/
operator int() {
// Underlying read is thread safe
return read();
}
#endif
protected:
gpio_t gpio;

View File

@ -109,7 +109,6 @@ public:
return gpio_is_connected(&gpio);
}
#ifdef MBED_OPERATORS
/** A shorthand for write()
*/
DigitalInOut& operator= (int value) {
@ -131,7 +130,6 @@ public:
// Underlying call is thread safe
return read();
}
#endif
protected:
gpio_t gpio;

View File

@ -95,7 +95,6 @@ public:
return gpio_is_connected(&gpio);
}
#ifdef MBED_OPERATORS
/** A shorthand for write()
*/
DigitalOut& operator= (int value) {
@ -117,7 +116,6 @@ public:
// Underlying call is thread safe
return read();
}
#endif
protected:
gpio_t gpio;

View File

@ -65,11 +65,18 @@ public:
InterruptIn(PinName pin);
virtual ~InterruptIn();
int read();
#ifdef MBED_OPERATORS
/** Read the input, represented as 0 or 1 (int)
*
* @returns
* An integer representing the state of the input pin,
* 0 for logical 0, 1 for logical 1
*/
int read();
/** An operator shorthand for read()
*/
operator int();
#endif
/** Attach a function to call when a rising edge occurs on the input
*

View File

@ -149,7 +149,6 @@ public:
core_util_critical_section_exit();
}
#ifdef MBED_OPERATORS
/** A operator shorthand for write()
*/
PwmOut& operator= (float value) {
@ -170,7 +169,6 @@ public:
// Underlying call is thread safe
return read();
}
#endif
protected:
pwmout_t _pwm;

View File

@ -76,9 +76,9 @@ public:
*/
int read_us();
#ifdef MBED_OPERATORS
/** An operator shorthand for read()
*/
operator float();
#endif
protected:
int slicetime();

View File

@ -16,8 +16,6 @@
#ifndef MBED_PLATFORM_H
#define MBED_PLATFORM_H
#define MBED_OPERATORS 1
#include "device.h"
#include "PinNames.h"
#include "PeripheralNames.h"

View File

@ -81,7 +81,6 @@ void BusIn::unlock() {
_mutex.unlock();
}
#ifdef MBED_OPERATORS
BusIn::operator int() {
// Underlying read is thread safe
return read();
@ -94,6 +93,4 @@ DigitalIn& BusIn::operator[] (int index) {
return *_pin[index];
}
#endif
} // namespace mbed

View File

@ -103,7 +103,6 @@ void BusInOut::mode(PinMode pull) {
unlock();
}
#ifdef MBED_OPERATORS
BusInOut& BusInOut::operator= (int v) {
// Underlying write is thread safe
write(v);
@ -127,7 +126,6 @@ BusInOut::operator int() {
// Underlying read is thread safe
return read();
}
#endif
void BusInOut::lock() {
_mutex.lock();

View File

@ -73,7 +73,6 @@ int BusOut::read() {
return v;
}
#ifdef MBED_OPERATORS
BusOut& BusOut::operator= (int v) {
// Underlying write is thread safe
write(v);
@ -97,7 +96,6 @@ BusOut::operator int() {
// Underlying read is thread safe
return read();
}
#endif
void BusOut::lock() {
_mutex.lock();

View File

@ -89,12 +89,10 @@ void InterruptIn::disable_irq() {
core_util_critical_section_exit();
}
#ifdef MBED_OPERATORS
InterruptIn::operator int() {
// Underlying call is atomic
return read();
}
#endif
} // namespace mbed

View File

@ -76,10 +76,8 @@ void Timer::reset() {
core_util_critical_section_exit();
}
#ifdef MBED_OPERATORS
Timer::operator float() {
return read();
}
#endif
} // namespace mbed

View File

@ -40,7 +40,6 @@ TEST(BusOut_dummy, dummy)
{
}
#ifdef MBED_OPERATORS
TEST_GROUP(BusOut_digitalout_write)
{
};
@ -84,4 +83,3 @@ TEST(BusOut_digitalout_write, led_1_nc_2_nc_nc_3)
CHECK(bus_data[2].read() == 0);
CHECK(bus_data[5].read() == 0);
}
#endif