Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
* Revert coding style changes
* Leave/put one-line method in header files as inline
* Use range for copyright notice year for modified existing files
  • Loading branch information
hugueskamba committed Jun 22, 2019
1 parent ded7529 commit 24a3972
Show file tree
Hide file tree
Showing 50 changed files with 493 additions and 727 deletions.
21 changes: 0 additions & 21 deletions drivers/AnalogIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,6 @@ unsigned short AnalogIn::read_u16()
return ret;
}

AnalogIn::operator float()
{
// Underlying call is thread safe
return read();
}

AnalogIn::~AnalogIn()
{
// Do nothing
}

void AnalogIn::lock()
{
_mutex->lock();
}

void AnalogIn::unlock()
{
_mutex->unlock();
}

};

#endif
21 changes: 17 additions & 4 deletions drivers/AnalogIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,27 @@ class AnalogIn {
* if(volume > 0.25) { ... }
* @endcode
*/
operator float();
operator float()
{
// Underlying call is thread safe
return read();
}

virtual ~AnalogIn();
virtual ~AnalogIn()
{
// Do nothing
}

protected:
#if !defined(DOXYGEN_ONLY)
virtual void lock();
virtual void unlock();
virtual void lock()
{
_mutex->lock();
}
virtual void unlock()
{
_mutex->unlock();
}

analogin_t _adc;
static SingletonPtr<PlatformMutex> _mutex;
Expand Down
26 changes: 0 additions & 26 deletions drivers/AnalogOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@

namespace mbed {

AnalogOut::AnalogOut(PinName pin)
{
analogout_init(&_dac, pin);
}

void AnalogOut::write(float value)
{
lock();
Expand Down Expand Up @@ -62,27 +57,6 @@ AnalogOut &AnalogOut::operator= (AnalogOut &rhs)
return *this;
}

AnalogOut::operator float()
{
// Underlying read call is thread safe
return read();
}

AnalogOut::~AnalogOut()
{
// Do nothing
}

void AnalogOut::lock()
{
_mutex.lock();
}

void AnalogOut::unlock()
{
_mutex.unlock();
}

};

#endif // DEVICE_ANALOGOUT
26 changes: 21 additions & 5 deletions drivers/AnalogOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class AnalogOut {
*
* @param pin AnalogOut pin to connect to
*/
AnalogOut(PinName pin);
AnalogOut(PinName pin)
{
analogout_init(&_dac, pin);
}

/** Set the output voltage, specified as a percentage (float)
*
Expand Down Expand Up @@ -101,14 +104,27 @@ class AnalogOut {
/** An operator shorthand for read()
* \sa AnalogOut::read()
*/
operator float();
operator float()
{
// Underlying read call is thread safe
return read();
}

virtual ~AnalogOut();
virtual ~AnalogOut()
{
// Do nothing
}

protected:
#if !defined(DOXYGEN_ONLY)
virtual void lock();
virtual void unlock();
virtual void lock()
{
_mutex.lock();
}
virtual void unlock()
{
_mutex.unlock();
}

dac_t _dac;
PlatformMutex _mutex;
Expand Down
20 changes: 2 additions & 18 deletions drivers/CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ CANMessage::CANMessage() : CAN_Message()
memset(data, 0, 8);
}

CANMessage::CANMessage(
unsigned int _id, const unsigned char *_data, unsigned char _len,
CANType _type, CANFormat _format
)
CANMessage::CANMessage(unsigned int _id, const unsigned char *_data, unsigned char _len, CANType _type, CANFormat _format)
{
len = _len & 0xF;
type = _type;
Expand All @@ -43,10 +40,7 @@ CANMessage::CANMessage(
memcpy(data, _data, _len);
}

CANMessage::CANMessage(
unsigned int _id, const char *_data, unsigned char _len,
CANType _type, CANFormat _format
)
CANMessage::CANMessage(unsigned int _id, const char *_data, unsigned char _len, CANType _type, CANFormat _format)
{
len = _len & 0xF;
type = _type;
Expand Down Expand Up @@ -199,16 +193,6 @@ void CAN::_irq_handler(uint32_t id, CanIrqType type)
}
}

void CAN::lock()
{
_mutex.lock();
}

void CAN::unlock()
{
_mutex.unlock();
}

} // namespace mbed

#endif
21 changes: 11 additions & 10 deletions drivers/CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ class CANMessage : public CAN_Message {
* @param _type Type of Data: Use enum CANType for valid parameter values
* @param _format Data Format: Use enum CANFormat for valid parameter values
*/
CANMessage(
unsigned int _id, const unsigned char *_data, unsigned char _len = 8,
CANType _type = CANData, CANFormat _format = CANStandard
);
CANMessage(unsigned int _id, const unsigned char *_data, unsigned char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard);


/** Creates CAN message with specific content.
Expand All @@ -63,10 +60,7 @@ class CANMessage : public CAN_Message {
* @param _type Type of Data: Use enum CANType for valid parameter values
* @param _format Data Format: Use enum CANFormat for valid parameter values
*/
CANMessage(
unsigned int _id, const char *_data, unsigned char _len = 8,
CANType _type = CANData, CANFormat _format = CANStandard
);
CANMessage(unsigned int _id, const char *_data, unsigned char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard);

/** Creates CAN remote message.
*
Expand Down Expand Up @@ -291,8 +285,15 @@ class CAN : private NonCopyable<CAN> {

#if !defined(DOXYGEN_ONLY)
protected:
virtual void lock();
virtual void unlock();
virtual void lock()
{
_mutex.lock();
}
virtual void unlock()
{
_mutex.unlock();
}

can_t _can;
Callback<void()> _irq[IrqCnt];
PlatformMutex _mutex;
Expand Down
30 changes: 0 additions & 30 deletions drivers/DigitalIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,11 @@

namespace mbed {

DigitalIn::DigitalIn(PinName pin) : gpio()
{
// No lock needed in the constructor
gpio_init_in(&gpio, pin);
}

DigitalIn::DigitalIn(PinName pin, PinMode mode) : gpio()
{
// No lock needed in the constructor
gpio_init_in_ex(&gpio, pin, mode);
}

int DigitalIn::read()
{
// Thread safe / atomic HAL call
return gpio_read(&gpio);
}

void DigitalIn::mode(PinMode pull)
{
core_util_critical_section_enter();
gpio_mode(&gpio, pull);
core_util_critical_section_exit();
}

int DigitalIn::is_connected()
{
// Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
}

DigitalIn::operator int()
{
// Underlying read is thread safe
return read();
}

};
30 changes: 25 additions & 5 deletions drivers/DigitalIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,34 @@ class DigitalIn {
*
* @param pin DigitalIn pin to connect to
*/
DigitalIn(PinName pin);
DigitalIn(PinName pin) : gpio()
{
// No lock needed in the constructor
gpio_init_in(&gpio, pin);
}

/** Create a DigitalIn connected to the specified pin
*
* @param pin DigitalIn pin to connect to
* @param mode the initial mode of the pin
*/
DigitalIn(PinName pin, PinMode mode);
DigitalIn(PinName pin, PinMode mode) : gpio()
{
// No lock needed in the constructor
gpio_init_in_ex(&gpio, pin, mode);
}

/** 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();
int read()
{
// Thread safe / atomic HAL call
return gpio_read(&gpio);
}

/** Set the input pin mode
*
Expand All @@ -84,7 +96,11 @@ class DigitalIn {
* Non zero value if pin is connected to uc GPIO
* 0 if gpio object was initialized with NC
*/
int is_connected();
int is_connected()
{
// Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
}

/** An operator shorthand for read()
* \sa DigitalIn::read()
Expand All @@ -94,7 +110,11 @@ class DigitalIn {
* led = button; // Equivalent to led.write(button.read())
* @endcode
*/
operator int();
operator int()
{
// Underlying read is thread safe
return read();
}

protected:
#if !defined(DOXYGEN_ONLY)
Expand Down
38 changes: 0 additions & 38 deletions drivers/DigitalInOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,6 @@

namespace mbed {

DigitalInOut::DigitalInOut(PinName pin) : gpio()
{
// No lock needed in the constructor
gpio_init_in(&gpio, pin);
}

DigitalInOut::DigitalInOut(
PinName pin, PinDirection direction, PinMode mode, int value
) : gpio()
{
// No lock needed in the constructor
gpio_init_inout(&gpio, pin, direction, mode, value);
}

void DigitalInOut::write(int value)
{
// Thread safe / atomic HAL call
gpio_write(&gpio, value);
}

int DigitalInOut::read()
{
// Thread safe / atomic HAL call
return gpio_read(&gpio);
}

void DigitalInOut::output()
{
core_util_critical_section_enter();
Expand All @@ -68,12 +42,6 @@ void DigitalInOut::mode(PinMode pull)
core_util_critical_section_exit();
}

int DigitalInOut::is_connected()
{
// Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
}

DigitalInOut &DigitalInOut::operator= (int value)
{
// Underlying write is thread safe
Expand All @@ -89,10 +57,4 @@ DigitalInOut &DigitalInOut::operator= (DigitalInOut &rhs)
return *this;
}

DigitalInOut::operator int()
{
// Underlying call is thread safe
return read();
}

};
Loading

0 comments on commit 24a3972

Please sign in to comment.