Skip to content

pn532: remove redundant #ifdefs#8164

Closed
miri64 wants to merge 1 commit intoRIOT-OS:masterfrom
miri64:pn532/cleanup/redundant-ifdefs
Closed

pn532: remove redundant #ifdefs#8164
miri64 wants to merge 1 commit intoRIOT-OS:masterfrom
miri64:pn532/cleanup/redundant-ifdefs

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Nov 28, 2017

Some #ifdefs in this file are redundant and weirdly placed inside the
respective branches of an if { } else { }.

This PR puts the #ifdef around the if { } else { }, reducing the
number of #ifdefs in this file, and making it more readable for humans
and tools like cppcheck alike ;-).

This is a follow-up on #7994 (comment)

Some `#ifdef`s in this file are redundant and weirdly placed inside the
respective branches of an `if {  } else {  }`.

This PR puts the `#ifdef` *around* the `if {  } else {  }`, reducing the
number of `#ifdef`s in this file, and making it more readable for humans
and tools like `cppcheck` alike ;-).
@miri64 miri64 added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Area: drivers Area: Device drivers labels Nov 28, 2017
@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 28, 2017
gpio_init(dev->conf->reset, GPIO_OUT);
gpio_set(dev->conf->reset);
dev->mode = mode;
if (mode == PN532_I2C) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure of the fix here. This may increase the generated code size.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabadie If anything, the contrary is the case. The if is now in the #ifdef, so we get a condition check and 2 jump instructions less, even if the optimizer wouldn't already deal with that.

Copy link
Copy Markdown
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the two ifdefs are for different bus types (i2c vs spi)
I don't think this PR will work properly.

#endif
}
else {
#ifdef PN532_SUPPORT_SPI
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note i2c vs spi here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of this, the 2 blocks are built depending on these 2 bus flags.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 28, 2017

Note that the two ifdefs are for different bus types (i2c vs spi)
I don't think this PR will work properly.

Arghs, you are right. Nevermind then!

@miri64 miri64 closed this Nov 28, 2017
@miri64 miri64 deleted the pn532/cleanup/redundant-ifdefs branch November 28, 2017 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants