mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_NORDIC/TARGET_NRF51822/gpio_api.c
- Revision:
- 227:7bd0639b8911
- Parent:
- 113:65a335a675de
diff -r b062af740e40 -r 7bd0639b8911 targets/hal/TARGET_NORDIC/TARGET_NRF51822/gpio_api.c --- a/targets/hal/TARGET_NORDIC/TARGET_NRF51822/gpio_api.c Wed Jun 11 09:45:09 2014 +0100 +++ b/targets/hal/TARGET_NORDIC/TARGET_NRF51822/gpio_api.c Wed Jun 11 16:00:09 2014 +0100 @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "mbed_assert.h" #include "gpio_api.h" #include "pinmap.h" void gpio_init(gpio_t *obj, PinName pin) { - if(pin == NC) return; + obj->pin = pin; + if (pin == (PinName)NC) + return; - obj->pin = pin; - obj->mask = (1ul<<pin); + obj->mask = (1ul << pin); obj->reg_set = &NRF_GPIO->OUTSET; obj->reg_clr = &NRF_GPIO->OUTCLR; @@ -33,20 +35,21 @@ } void gpio_dir(gpio_t *obj, PinDirection direction) { + MBED_ASSERT(obj->pin != (PinName)NC); switch (direction) { case PIN_INPUT : - NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) + NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); - break; - case PIN_OUTPUT: - NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) + break; + case PIN_OUTPUT: + NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); - break; + break; } }