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); BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
CHECK_EQUAL(0x25, bus_data.mask()); 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 ## Example

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,11 +65,18 @@ public:
InterruptIn(PinName pin); InterruptIn(PinName pin);
virtual ~InterruptIn(); virtual ~InterruptIn();
int read(); /** Read the input, represented as 0 or 1 (int)
#ifdef MBED_OPERATORS *
* @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(); operator int();
#endif
/** Attach a function to call when a rising edge occurs on the input /** 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(); core_util_critical_section_exit();
} }
#ifdef MBED_OPERATORS
/** A operator shorthand for write() /** A operator shorthand for write()
*/ */
PwmOut& operator= (float value) { PwmOut& operator= (float value) {
@ -170,7 +169,6 @@ public:
// Underlying call is thread safe // Underlying call is thread safe
return read(); return read();
} }
#endif
protected: protected:
pwmout_t _pwm; pwmout_t _pwm;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,6 @@ TEST(BusOut_dummy, dummy)
{ {
} }
#ifdef MBED_OPERATORS
TEST_GROUP(BusOut_digitalout_write) 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[2].read() == 0);
CHECK(bus_data[5].read() == 0); CHECK(bus_data[5].read() == 0);
} }
#endif