Skip to content

AStyle : drivers/hal/platform folders update #7008

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

Merged
merged 4 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .astyleignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ features/filesystem/fat/ChaN
features/frameworks
features/FEATURE_BLE/targets
features/unsupported/
features/FEATURE_COMMON_PAL/
hal/storage_abstraction
FEATURE_NANOSTACK/coap-service
FEATURE_NANOSTACK/sal-stack-nanostack
rtos/TARGET_CORTEX/rtx5
targets
tools
21 changes: 14 additions & 7 deletions drivers/AnalogIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class AnalogIn {
*
* @param pin AnalogIn pin to connect to
*/
AnalogIn(PinName pin) {
AnalogIn(PinName pin)
{
lock();
analogin_init(&_adc, pin);
unlock();
Expand All @@ -67,7 +68,8 @@ class AnalogIn {
*
* @returns A floating-point value representing the current input voltage, measured as a percentage
*/
float read() {
float read()
{
lock();
float ret = analogin_read(&_adc);
unlock();
Expand All @@ -79,7 +81,8 @@ class AnalogIn {
* @returns
* 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
*/
unsigned short read_u16() {
unsigned short read_u16()
{
lock();
unsigned short ret = analogin_read_u16(&_adc);
unlock();
Expand All @@ -99,22 +102,26 @@ 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:

virtual void lock() {
virtual void lock()
{
_mutex->lock();
}

virtual void unlock() {
virtual void unlock()
{
_mutex->unlock();
}

Expand Down
30 changes: 20 additions & 10 deletions drivers/AnalogOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class AnalogOut {
*
* @param pin AnalogOut pin to connect to
*/
AnalogOut(PinName pin) {
AnalogOut(PinName pin)
{
analogout_init(&_dac, pin);
}

Expand All @@ -68,7 +69,8 @@ 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) {
void write(float value)
{
lock();
analogout_write(&_dac, value);
unlock();
Expand All @@ -79,7 +81,8 @@ class AnalogOut {
* @param value 16-bit unsigned short representing the output voltage,
* normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
*/
void write_u16(unsigned short value) {
void write_u16(unsigned short value)
{
lock();
analogout_write_u16(&_dac, value);
unlock();
Expand All @@ -95,7 +98,8 @@ class AnalogOut {
* @note
* This value may not match exactly the value set by a previous write().
*/
float read() {
float read()
{
lock();
float ret = analogout_read(&_dac);
unlock();
Expand All @@ -105,7 +109,8 @@ class AnalogOut {
/** An operator shorthand for write()
* \sa AnalogOut::write()
*/
AnalogOut& operator= (float percent) {
AnalogOut &operator= (float percent)
{
// Underlying write call is thread safe
write(percent);
return *this;
Expand All @@ -114,7 +119,8 @@ class AnalogOut {
/** An operator shorthand for write()
* \sa AnalogOut::write()
*/
AnalogOut& operator= (AnalogOut& rhs) {
AnalogOut &operator= (AnalogOut &rhs)
{
// Underlying write call is thread safe
write(rhs.read());
return *this;
Expand All @@ -123,22 +129,26 @@ 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:

virtual void lock() {
virtual void lock()
{
_mutex.lock();
}

virtual void unlock() {
virtual void unlock()
{
_mutex.unlock();
}

Expand Down
37 changes: 23 additions & 14 deletions drivers/BusIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,47 @@

namespace mbed {

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) {
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};

// No lock needed in the constructor
_nc_mask = 0;
for (int i=0; i<16; i++) {
for (int i = 0; i < 16; i++) {
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
if (pins[i] != NC) {
_nc_mask |= (1 << i);
}
}
}

BusIn::BusIn(PinName pins[16]) {
BusIn::BusIn(PinName pins[16])
{
// No lock needed in the constructor
_nc_mask = 0;
for (int i=0; i<16; i++) {
for (int i = 0; i < 16; i++) {
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
if (pins[i] != NC) {
_nc_mask |= (1 << i);
}
}
}

BusIn::~BusIn() {
BusIn::~BusIn()
{
// No lock needed in the destructor
for (int i=0; i<16; i++) {
for (int i = 0; i < 16; i++) {
if (_pin[i] != 0) {
delete _pin[i];
}
}
}

int BusIn::read() {
int BusIn::read()
{
int v = 0;
lock();
for (int i=0; i<16; i++) {
for (int i = 0; i < 16; i++) {
if (_pin[i] != 0) {
v |= _pin[i]->read() << i;
}
Expand All @@ -63,30 +67,35 @@ int BusIn::read() {
return v;
}

void BusIn::mode(PinMode pull) {
void BusIn::mode(PinMode pull)
{
lock();
for (int i=0; i<16; i++) {
for (int i = 0; i < 16; i++) {
if (_pin[i] != 0) {
_pin[i]->mode(pull);
}
}
unlock();
}

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

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

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

DigitalIn& BusIn::operator[] (int index) {
DigitalIn &BusIn::operator[](int index)
{
// No lock needed since _pin is not modified outside the constructor
MBED_ASSERT(index >= 0 && index <= 16);
MBED_ASSERT(_pin[index]);
Expand Down
11 changes: 6 additions & 5 deletions drivers/BusIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class BusIn : private NonCopyable<BusIn> {
PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);


/** Create an BusIn, connected to the specified pins
*
* @param pins An array of pins to connect to bus bit
*/
BusIn(PinName pins[16]);
BusIn(PinName pins[16]);

virtual ~BusIn();

Expand All @@ -90,7 +90,8 @@ class BusIn : private NonCopyable<BusIn> {
* @returns
* Binary mask of connected pins
*/
int mask() {
int mask()
{
// No lock needed since _nc_mask is not modified outside the constructor
return _nc_mask;
}
Expand All @@ -103,10 +104,10 @@ class BusIn : private NonCopyable<BusIn> {
/** Access to particular bit in random-iterator fashion
* @param index Position of bit
*/
DigitalIn & operator[] (int index);
DigitalIn &operator[](int index);

protected:
DigitalIn* _pin[16];
DigitalIn *_pin[16];

/* Mask of bus's NC pins
* If bit[n] is set to 1 - pin is connected
Expand Down
Loading