Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up drivers header files 2 #1

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9260902
AnalogIn: Move definitions and related includes to source file
hugueskamba Jun 17, 2019
88300ee
AnalogOut: Move definitions and related includes to source file
hugueskamba Jun 17, 2019
30d30e6
CAN: Move definitions and related includes to source file
hugueskamba Jun 17, 2019
5117238
DigitalIn: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
7d6fe53
DigitalInOut: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
e2cb3d5
DigitalOut: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
35a74b5
I2C: Include only required header file
hugueskamba Jun 18, 2019
5066039
Analog: Correct syntax of method definitions outside class
hugueskamba Jun 18, 2019
633e9d6
PortIn: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
5024a0d
PortInOut: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
26edc17
PortOut: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
2380ff2
PwmOut: Move definitions and related includes to source file
hugueskamba Jun 18, 2019
e5835c5
RawSerial: Remove unused header files
hugueskamba Jun 18, 2019
a33508b
Serial: Remove unused header files
hugueskamba Jun 18, 2019
952d6a1
SerialWireOutput: Move implementation and headers to source file
hugueskamba Jun 19, 2019
34ab0ed
SPI: explicit inclusion of header file used
hugueskamba Jun 19, 2019
bc68221
Fix syntax errors thus far
hugueskamba Jun 19, 2019
d19c2b7
Ticker: Remove implementation and unused headers
hugueskamba Jun 19, 2019
32e465c
Timeout: Removed unused header file
hugueskamba Jun 19, 2019
df6e106
Timer: Move header only needed by the source from the header
hugueskamba Jun 19, 2019
c617bc7
TimerEvent: Remove unused header file inclusion
hugueskamba Jun 19, 2019
97f83c8
UARTSerial: Remove unused header file
hugueskamba Jun 19, 2019
fbe3672
CAN: Fix syntax errors
hugueskamba Jun 19, 2019
4a7443c
CAN: Expose default args values for methods
hugueskamba Jun 19, 2019
6c1f8e7
Ports: Exposed default args values
hugueskamba Jun 19, 2019
ded7529
Fix: Modified copyright notice year
hugueskamba Jun 19, 2019
24a3972
Addressing PR comments
hugueskamba Jun 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion drivers/AnalogIn.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -23,6 +23,29 @@ namespace mbed {

SingletonPtr<PlatformMutex> AnalogIn::_mutex;

AnalogIn::AnalogIn(PinName pin)
{
lock();
analogin_init(&_adc, pin);
unlock();
}

float AnalogIn::read()
{
lock();
float ret = analogin_read(&_adc);
unlock();
return ret;
}

unsigned short AnalogIn::read_u16()
{
lock();
unsigned short ret = analogin_read_u16(&_adc);
unlock();
return ret;
}

};

#endif
30 changes: 6 additions & 24 deletions drivers/AnalogIn.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -58,37 +58,20 @@ class AnalogIn {
*
* @param pin AnalogIn pin to connect to
*/
AnalogIn(PinName pin)
{
lock();
analogin_init(&_adc, pin);
unlock();
}
AnalogIn(PinName pin);

/** Read the input voltage, represented as a float in the range [0.0, 1.0]
*
* @returns A floating-point value representing the current input voltage, measured as a percentage
*/
float read()
{
lock();
float ret = analogin_read(&_adc);
unlock();
return ret;
}
float read();

/** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
*
* @returns
* 16-bit unsigned short representing the current input voltage, normalized to a 16-bit value
*/
unsigned short read_u16()
{
lock();
unsigned short ret = analogin_read_u16(&_adc);
unlock();
return ret;
}
unsigned short read_u16();

/** An operator shorthand for read()
*
Expand Down Expand Up @@ -120,7 +103,6 @@ class AnalogIn {
{
_mutex->lock();
}

virtual void unlock()
{
_mutex->unlock();
Expand All @@ -133,7 +115,7 @@ class AnalogIn {

} // namespace mbed

#endif
#endif // DEVICE_ANALOGIN || defined(DOXYGEN_ONLY)

#endif
#endif // MBED_ANALOGIN_H

62 changes: 62 additions & 0 deletions drivers/AnalogOut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "drivers/AnalogOut.h"

#if DEVICE_ANALOGOUT

namespace mbed {

void AnalogOut::write(float value)
{
lock();
analogout_write(&_dac, value);
unlock();
}

void AnalogOut::write_u16(unsigned short value)
{
lock();
analogout_write_u16(&_dac, value);
unlock();
}

float AnalogOut::read()
{
lock();
float ret = analogout_read(&_dac);
unlock();
return ret;
}

AnalogOut &AnalogOut::operator= (float percent)
{
// Underlying write call is thread safe
write(percent);
return *this;
}

AnalogOut &AnalogOut::operator= (AnalogOut &rhs)
{
// Underlying write call is thread safe
write(rhs.read());
return *this;
}

};

#endif // DEVICE_ANALOGOUT
39 changes: 6 additions & 33 deletions drivers/AnalogOut.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -70,24 +70,14 @@ class AnalogOut {
* 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
* Values outside this range will be saturated to 0.0f or 1.0f.
*/
void write(float value)
{
lock();
analogout_write(&_dac, value);
unlock();
}
void write(float value);

/** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
*
* @param value 16-bit unsigned short representing the output voltage,
* normalized to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
*/
void write_u16(unsigned short value)
{
lock();
analogout_write_u16(&_dac, value);
unlock();
}
void write_u16(unsigned short value);

/** Return the current output voltage setting, measured as a percentage (float)
*
Expand All @@ -99,33 +89,17 @@ class AnalogOut {
* @note
* This value may not match exactly the value set by a previous write().
*/
float read()
{
lock();
float ret = analogout_read(&_dac);
unlock();
return ret;
}
float read();

/** An operator shorthand for write()
* \sa AnalogOut::write()
*/
AnalogOut &operator= (float percent)
{
// Underlying write call is thread safe
write(percent);
return *this;
}
AnalogOut &operator= (float percent);

/** An operator shorthand for write()
* \sa AnalogOut::write()
*/
AnalogOut &operator= (AnalogOut &rhs)
{
// Underlying write call is thread safe
write(rhs.read());
return *this;
}
AnalogOut &operator= (AnalogOut &rhs);

/** An operator shorthand for read()
* \sa AnalogOut::read()
Expand All @@ -147,7 +121,6 @@ class AnalogOut {
{
_mutex.lock();
}

virtual void unlock()
{
_mutex.unlock();
Expand Down
48 changes: 37 additions & 11 deletions drivers/CAN.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,6 +22,42 @@

namespace mbed {

CANMessage::CANMessage() : CAN_Message()
{
len = 8U;
type = CANData;
format = CANStandard;
id = 0U;
memset(data, 0, 8);
}

CANMessage::CANMessage(unsigned int _id, const unsigned char *_data, unsigned char _len, CANType _type, CANFormat _format)
{
len = _len & 0xF;
type = _type;
format = _format;
id = _id;
memcpy(data, _data, _len);
}

CANMessage::CANMessage(unsigned int _id, const char *_data, unsigned char _len, CANType _type, CANFormat _format)
{
len = _len & 0xF;
type = _type;
format = _format;
id = _id;
memcpy(data, _data, _len);
}

CANMessage::CANMessage(unsigned int _id, CANFormat _format)
{
len = 0;
type = CANRemote;
format = _format;
id = _id;
memset(data, 0, 8);
}

CAN::CAN(PinName rd, PinName td) : _can(), _irq()
{
// No lock needed in constructor
Expand Down Expand Up @@ -157,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
49 changes: 14 additions & 35 deletions drivers/CAN.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -39,14 +39,7 @@ class CANMessage : public CAN_Message {
public:
/** Creates empty CAN message.
*/
CANMessage() : CAN_Message()
{
len = 8U;
type = CANData;
format = CANStandard;
id = 0U;
memset(data, 0, 8);
}
CANMessage();

/** Creates CAN message with specific content.
*
Expand All @@ -56,14 +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)
{
len = _len & 0xF;
type = _type;
format = _format;
id = _id;
memcpy(data, _data, _len);
}
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 @@ -74,28 +60,14 @@ 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)
{
len = _len & 0xF;
type = _type;
format = _format;
id = _id;
memcpy(data, _data, _len);
}
CANMessage(unsigned int _id, const char *_data, unsigned char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard);

/** Creates CAN remote message.
*
* @param _id Message ID
* @param _format Data Format: Use enum CANType for valid parameter values
*/
CANMessage(unsigned int _id, CANFormat _format = CANStandard)
{
len = 0;
type = CANRemote;
format = _format;
id = _id;
memset(data, 0, 8);
}
CANMessage(unsigned int _id, CANFormat _format = CANStandard);
};

/** A can bus client, used for communicating with can devices
Expand Down Expand Up @@ -313,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
Loading