all targets - gpio - NC guard

- gpio init enables to set pin to NC, thus the rest of gpio HAL should not do any action
	  if pin is set to NC.
pull/316/head
0xc0170 2014-05-14 15:44:33 +01:00
parent 1ec0c1564c
commit 4c61464ee7
53 changed files with 294 additions and 119 deletions

View File

@ -22,7 +22,7 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC)
if(pin == (PinName)NC)
return;
obj->pin = pin;
@ -42,6 +42,9 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;

View File

@ -31,6 +31,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -39,6 +41,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -22,7 +22,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == (PinName)NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -41,8 +42,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
}
}

View File

@ -31,6 +31,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +40,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -17,7 +17,8 @@
#include "error.h"
void pin_function(PinName pin, int function) {
if (pin == (PinName)NC) return;
if (pin == (PinName)NC)
return;
uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
@ -30,7 +31,8 @@ void pin_function(PinName pin, int function) {
}
void pin_mode(PinName pin, PinMode mode) {
if (pin == (PinName)NC) { return; }
if (pin == (PinName)NC)
return;
__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);

View File

@ -27,9 +27,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) {
if (pin == (PinName)NC)
return;
}
obj->pinName = pin;
uint32_t port = pin >> GPIO_PORT_SHIFT;
@ -43,6 +42,8 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
uint32_t pin_num = obj->pinName & 0xFF;

View File

@ -27,6 +27,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
uint32_t pin = obj->pinName & 0xFF;
@ -34,6 +36,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
uint32_t pin = obj->pinName & 0xFF;

View File

@ -17,10 +17,11 @@
#include "pinmap.h"
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
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,6 +34,8 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT :
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
@ -40,7 +43,7 @@ void gpio_dir(gpio_t *obj, PinDirection direction) {
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
break;
case PIN_OUTPUT:
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)

View File

@ -31,6 +31,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +40,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -16,31 +16,21 @@
#include "gpio_api.h"
#include "pinmap.h"
static int gpio_enabled = 0;
static void gpio_enable(void) {
gpio_enabled = 1;
uint32_t gpio_set(PinName pin) {
/* Enable AHB clock to the GPIO and IOCON domain. */
LPC_SYSCON->SYSAHBCLKCTRL |= ((1 << 16) | (1 << 6));
}
uint32_t gpio_set(PinName pin) {
if (!gpio_enabled)
gpio_enable();
return (1UL << ((int)pin >> PIN_SHIFT & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
unsigned int port = (unsigned int)(pin >> PORT_SHIFT);
obj->reg_set = &LPC_GPIO_PORT->SET[port];
obj->reg_clr = &LPC_GPIO_PORT->CLR[port];
obj->reg_in = &LPC_GPIO_PORT->PIN[port];
@ -52,8 +42,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
}
}

View File

@ -31,6 +31,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +41,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -17,18 +17,16 @@
#include "pinmap.h"
uint32_t gpio_set(PinName pin) {
int f = ((pin == P0_11) ||
(pin == P0_12) ||
(pin == P0_13) ||
(pin == P0_14)) ? (1) : (0);
int f = ((pin == P0_11) || (pin == P0_12) ||
(pin == P0_13) || (pin == P0_14)) ? (1) : (0);
pin_function(pin, f);
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -46,8 +44,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
}
}

View File

@ -31,6 +31,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +41,9 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -35,7 +35,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
@ -50,6 +51,9 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
int pin_number = ((obj->pin & 0x0F00) >> 8);
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~(1 << pin_number); break;

View File

@ -28,6 +28,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
uint32_t pin_number = ((obj->pin & 0x0F00) >> 8);
if (value)
*obj->reg_write |= (1 << pin_number);
@ -36,6 +38,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return;
return ((*obj->reg_mask_read) ? 1 : 0);
}

View File

@ -17,18 +17,16 @@
#include "pinmap.h"
uint32_t gpio_set(PinName pin) {
int f = ((pin == P0_11) ||
(pin == P0_12) ||
(pin == P0_13) ||
(pin == P0_14)) ? (1) : (0);
int f = ((pin == P0_11) || (pin == P0_12) ||
(pin == P0_13) || (pin == P0_14)) ? (1) : (0);
pin_function(pin, f);
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -46,6 +44,8 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;

View File

@ -31,6 +31,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +40,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -16,26 +16,15 @@
#include "gpio_api.h"
#include "pinmap.h"
static int gpio_enabled = 0;
static void gpio_enable(void) {
gpio_enabled = 1;
/* Enable AHB clock to the GPIO0/1/2 and IOCON domain. */
LPC_SYSCON->SYSAHBCLKCTRL0 |= (0xFUL << 13);
}
uint32_t gpio_set(PinName pin) {
if (!gpio_enabled)
gpio_enable();
LPC_SYSCON->SYSAHBCLKCTRL0 |= (0xFUL << 13);
return (1UL << ((int)pin & 0x1f));
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -52,8 +41,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
}
}

View File

@ -31,6 +31,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +41,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -22,8 +22,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -39,6 +39,8 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;

View File

@ -31,6 +31,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +40,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -25,8 +25,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -43,6 +43,8 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;

View File

@ -31,6 +31,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +40,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -22,8 +22,9 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -40,8 +41,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
}
}

View File

@ -31,6 +31,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +41,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -29,8 +29,9 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -48,6 +49,9 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;

View File

@ -31,6 +31,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +41,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -40,8 +40,9 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -56,8 +57,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
if (obj->pin == (PinName)NC)
return;
switch (direction) {
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;
break;
case PIN_OUTPUT:
*obj->reg_dir |= obj->mask;
break;
}
}

View File

@ -31,6 +31,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -38,6 +41,9 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -33,16 +33,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) {
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
}
@ -57,6 +60,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -33,16 +33,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) {
if (pin == (PinName)NC)
return 0;
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
}
@ -57,6 +60,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -33,23 +33,24 @@
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) {
if (pin == (PinName)NC)
return 0;
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;
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);

View File

@ -48,6 +48,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +59,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,17 +34,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) {
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);
// Enable GPIO clock

View File

@ -48,6 +48,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
}
@ -57,6 +59,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -33,16 +33,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) {
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
}
@ -57,6 +59,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,15 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;
if (pin == (PinName)NC)
return 0;
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +58,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,15 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +59,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,15 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +58,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,15 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,9 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +59,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,16 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;
if (pin == (PinName)NC)
return 0;
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;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);
// Enable GPIO clock

View File

@ -48,6 +48,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +58,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -34,7 +34,8 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) {
if (pin == NC) return 0;
if (pin == (PinName)NC)
return 0;
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
@ -42,7 +43,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
if (pin == (PinName)NC)
return;
uint32_t port_index = STM_PORT(pin);

View File

@ -48,6 +48,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -56,6 +58,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}

View File

@ -27,7 +27,8 @@ uint32_t gpio_set(PinName pin) {
}
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
if (pin == (PinName)NC)
return;
obj->pin = pin;
obj->mask = gpio_set(pin);
@ -47,7 +48,11 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
void gpio_dir(gpio_t *obj, PinDirection direction) {
switch (direction) {
case PIN_INPUT : pin_function(obj->pin, STM_PIN_DATA(0, 0)); break;
case PIN_OUTPUT: pin_function(obj->pin, STM_PIN_DATA(1, 0)); break;
case PIN_INPUT :
pin_function(obj->pin, STM_PIN_DATA(0, 0));
break;
case PIN_OUTPUT:
pin_function(obj->pin, STM_PIN_DATA(1, 0));
break;
}
}

View File

@ -32,6 +32,8 @@ typedef struct {
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value) {
if (obj->pin == (PinName)NC)
return;
if (value)
*obj->reg_set = obj->mask;
else
@ -39,6 +41,8 @@ static inline void gpio_write(gpio_t *obj, int value) {
}
static inline int gpio_read(gpio_t *obj) {
if (obj->pin == (PinName)NC)
return 0;
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}