From 3c19c7c8bd6b8c4d47bb3acba9e5b0ab2abe6a53 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Sun, 1 Apr 2012 01:37:41 +0200 Subject: [PATCH] Speed tweek for gpioSetValue --- core/gpio/gpio.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/core/gpio/gpio.c b/core/gpio/gpio.c index a7154e1..89e4c95 100644 --- a/core/gpio/gpio.c +++ b/core/gpio/gpio.c @@ -284,26 +284,29 @@ void gpioSetValue (uint32_t portNum, uint32_t bitPos, uint32_t bitVal) { if (!_gpioInitialised) gpioInit(); - // Get the appropriate register (handled this way to optimise code size) - REG32 *gpiodata = &GPIO_GPIO0DATA; - switch (portNum) - { - case 0: - gpiodata = &GPIO_GPIO0DATA; - break; - case 1: - gpiodata = &GPIO_GPIO1DATA; - break; - case 2: - gpiodata = &GPIO_GPIO2DATA; - break; - case 3: - gpiodata = &GPIO_GPIO3DATA; - break; - } - - // Toggle value - bitVal == 1 ? (*gpiodata |= (1 << bitPos)) : (*gpiodata &= ~(1 << bitPos)); + // // Get the appropriate register (handled this way to optimise code size) + // REG32 *gpiodata = &GPIO_GPIO0DATA; + // switch (portNum) + // { + // case 0: + // gpiodata = &GPIO_GPIO0DATA; + // break; + // case 1: + // gpiodata = &GPIO_GPIO1DATA; + // break; + // case 2: + // gpiodata = &GPIO_GPIO2DATA; + // break; + // case 3: + // gpiodata = &GPIO_GPIO3DATA; + // break; + // } + // + // // Toggle value + // bitVal == 1 ? (*gpiodata |= (1 << bitPos)) : (*gpiodata &= ~(1 << bitPos)); + + // Take advantage of the fact the GPIO registers are bit-banded + (*(pREG32 ((GPIO_GPIO0_BASE + (portNum << 16)) + ((1 << bitPos) << 2)))) = bitVal ? 0xFFF : 0; } /**************************************************************************/ -- 2.20.1