mbed library sources
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_DISCO_F407VG/gpio_api.c
- Revision:
- 227:7bd0639b8911
- Parent:
- 133:d4dda5c437f0
- Child:
- 242:7074e42da0b2
diff -r b062af740e40 -r 7bd0639b8911 targets/hal/TARGET_STM/TARGET_DISCO_F407VG/gpio_api.c --- a/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/gpio_api.c Wed Jun 11 09:45:09 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/gpio_api.c Wed Jun 11 16:00:09 2014 +0100 @@ -27,6 +27,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ +#include "mbed_assert.h" #include "gpio_api.h" #include "pinmap.h" #include "error.h" @@ -34,17 +35,17 @@ extern uint32_t Set_GPIO_Clock(uint32_t port_idx); -uint32_t gpio_set(PinName pin) { - if (pin == NC) return 0; +uint32_t gpio_set(PinName pin) { + MBED_ASSERT(pin != (PinName)NC); pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); - return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask } void gpio_init(gpio_t *obj, PinName pin) { - if (pin == NC) return; - + obj->pin = pin; + if (pin == (PinName)NC) + return; uint32_t port_index = STM_PORT(pin); // Enable GPIO clock @@ -52,7 +53,6 @@ GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add; // Fill GPIO object structure for future use - obj->pin = pin; obj->mask = gpio_set(pin); obj->reg_in = &gpio->IDR; obj->reg_set = &gpio->BSRRL; @@ -64,6 +64,7 @@ } void gpio_dir(gpio_t *obj, PinDirection direction) { + MBED_ASSERT(obj->pin != (PinName)NC); if (direction == PIN_OUTPUT) { pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); }