summaryrefslogtreecommitdiff
path: root/chip/nrf51/gpio.c
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-07-17 10:57:54 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-19 20:38:37 +0000
commit1f7ab338b10d65ddaf05d1b4650270d10580a932 (patch)
treef17c9418004809a96996f12d9c66a378299d631f /chip/nrf51/gpio.c
parent86192137049c269838241acc5dd5a2a41e5b71af (diff)
downloadchrome-ec-1f7ab338b10d65ddaf05d1b4650270d10580a932.tar.gz
cleanup: GPIO: Use common macro for converting mask to GPIO
The same calculation is used across the code, so move it to a common macro. BUG=chrome-os-partner:42104 TEST=Verify Glados still boots AP. BRANCH=None Change-Id: I90da348f37fc670971737cfc5ddcfb9c34096c4b Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/286169 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'chip/nrf51/gpio.c')
-rw-r--r--chip/nrf51/gpio.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/chip/nrf51/gpio.c b/chip/nrf51/gpio.c
index 22a7d95fa1..3ad55f2b38 100644
--- a/chip/nrf51/gpio.c
+++ b/chip/nrf51/gpio.c
@@ -58,7 +58,7 @@ BUILD_ASSERT(NRF51_MAX_ALT_FUNCS == ARRAY_SIZE(nrf51_alt_funcs));
void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags)
{
uint32_t val = 0;
- uint32_t bit = 31 - __builtin_clz(mask);
+ uint32_t bit = GPIO_MASK_TO_NUM(mask);
if (flags & GPIO_OUTPUT)
val |= NRF51_PIN_CNF_DIR_OUTPUT;
@@ -162,7 +162,7 @@ void gpio_pre_init(void)
*/
void gpio_set_alternate_function(uint32_t port, uint32_t mask, int func)
{
- uint32_t bit = 31 - __builtin_clz(mask);
+ uint32_t bit = GPIO_MASK_TO_NUM(mask);
ASSERT((~mask & (1 << bit)) == 0); /* Only one bit set. */
ASSERT(port == GPIO_0);
@@ -212,7 +212,7 @@ int gpio_enable_interrupt(enum gpio_signal signal)
ASSERT(free_slot != -1);
gpio_ints[free_slot] = g;
- pin = 31 - __builtin_clz(g->mask);
+ pin = GPIO_MASK_TO_NUM(g->mask);
event_config = (pin << NRF51_GPIOTE_PSEL_POS) |
NRF51_GPIOTE_MODE_EVENT;