mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_DISCO_F303VC/gpio_api.c
- Revision:
- 227:7bd0639b8911
- Parent:
- 157:90e3acc479a2
- Child:
- 250:a49055e7a707
--- a/targets/hal/TARGET_STM/TARGET_DISCO_F303VC/gpio_api.c Wed Jun 11 09:45:09 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_DISCO_F303VC/gpio_api.c Wed Jun 11 16:00:09 2014 +0100 @@ -27,31 +27,32 @@ * 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" 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(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF)); - 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 uint32_t gpio_add = Set_GPIO_Clock(port_index); 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->BSRR; @@ -63,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(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)); } else { // PIN_INPUT