mirror of https://github.com/ARMmbed/mbed-os.git
* updated port apis with corrections.
parent
0ee229aa90
commit
c7573e43ce
|
@ -22,21 +22,12 @@
|
||||||
#define PORTB_MASK 0xC0C3C30D // mask for available pins in Port B
|
#define PORTB_MASK 0xC0C3C30D // mask for available pins in Port B
|
||||||
#define PORTC_MASK 0x000D0000 // mask for available pins in Port C
|
#define PORTC_MASK 0x000D0000 // mask for available pins in Port C
|
||||||
|
|
||||||
#define PORTA_START 0 // 32 pins in a port
|
|
||||||
#define PORTB_START 32
|
|
||||||
#define PORTC_START 64
|
|
||||||
|
|
||||||
uint32_t start_pin(PortName port)
|
uint32_t start_pin(PortName port)
|
||||||
{
|
{
|
||||||
switch (port) {
|
if(port <= 2) { /* PortC value is 2*/
|
||||||
case PortA:
|
return port * 32;
|
||||||
return PORTA_START;
|
} else {
|
||||||
case PortB:
|
return NC;
|
||||||
return PORTB_START;
|
|
||||||
case PortC:
|
|
||||||
return PORTC_START;
|
|
||||||
default:
|
|
||||||
return NC;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
|
void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
|
||||||
|
@ -46,26 +37,7 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
|
||||||
int i, j;
|
int i, j;
|
||||||
int start;
|
int start;
|
||||||
|
|
||||||
PortGroup *const port_base = (PortGroup*)port_get_group_from_gpio_pin(port * 32); // 32 pins in port // function reused to get the port base
|
|
||||||
switch (port) {
|
|
||||||
case PortA:
|
|
||||||
obj->mask = (uint32_t)mask & PORTA_MASK;
|
|
||||||
break;
|
|
||||||
case PortB:
|
|
||||||
obj->mask = (uint32_t)mask & PORTB_MASK;
|
|
||||||
break;
|
|
||||||
case PortC:
|
|
||||||
obj->mask = (uint32_t)mask & PORTC_MASK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
start = start_pin(port);
|
|
||||||
if(start == NC)
|
|
||||||
return;
|
|
||||||
obj->port = port;
|
|
||||||
obj->direction = dir;
|
|
||||||
port_get_config_defaults(&pin_conf);
|
port_get_config_defaults(&pin_conf);
|
||||||
obj->powersave = pin_conf.powersave;
|
|
||||||
obj->mode = PORT_PIN_PULL_UP;
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case PIN_INPUT :
|
case PIN_INPUT :
|
||||||
pin_conf.direction = PORT_PIN_DIR_INPUT;
|
pin_conf.direction = PORT_PIN_DIR_INPUT;
|
||||||
|
@ -76,8 +48,34 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
|
||||||
case PIN_INPUT_OUTPUT:
|
case PIN_INPUT_OUTPUT:
|
||||||
pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK;
|
pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (i = start, j = 0; i < (start + 32); i++, j++) {
|
|
||||||
|
PortGroup *const port_base = (PortGroup*)port_get_group_from_gpio_pin(port * 32); // 32 pins in port // function reused to get the port base
|
||||||
|
if(port_base == NULL) return; /* returns NULL if invalid*/
|
||||||
|
switch (port) {
|
||||||
|
case PortA:
|
||||||
|
obj->mask = (uint32_t)mask & PORTA_MASK;
|
||||||
|
break;
|
||||||
|
case PortB:
|
||||||
|
obj->mask = (uint32_t)mask & PORTB_MASK;
|
||||||
|
break;
|
||||||
|
case PortC:
|
||||||
|
obj->mask = (uint32_t)mask & PORTC_MASK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
start = start_pin(port);
|
||||||
|
if(start == NC)
|
||||||
|
return;
|
||||||
|
obj->port = port;
|
||||||
|
obj->direction = dir;
|
||||||
|
obj->powersave = pin_conf.powersave;
|
||||||
|
obj->mode = PORT_PIN_PULL_UP;
|
||||||
|
|
||||||
|
for (i = start, j = 0; j < 32; i++, j++) {
|
||||||
if (obj->mask & (1<<j)) {
|
if (obj->mask & (1<<j)) {
|
||||||
port_pin_set_config((PinName)i, &pin_conf);
|
port_pin_set_config((PinName)i, &pin_conf);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +94,7 @@ void port_mode(port_t *obj, PinMode mode)
|
||||||
start = start_pin(obj->port);
|
start = start_pin(obj->port);
|
||||||
if(start == NC)
|
if(start == NC)
|
||||||
return;
|
return;
|
||||||
for (i = start, j = 0; i < (start + 32); i++, j++) {
|
for (i = start, j = 0; j < 32; i++, j++) {
|
||||||
if (obj->mask & (1<<j)) {
|
if (obj->mask & (1<<j)) {
|
||||||
pin_mode((PinName)i , mode);
|
pin_mode((PinName)i , mode);
|
||||||
}
|
}
|
||||||
|
@ -109,12 +107,7 @@ void port_dir(port_t *obj, PinDirection dir)
|
||||||
struct port_config pin_conf;
|
struct port_config pin_conf;
|
||||||
int i, j;
|
int i, j;
|
||||||
int start;
|
int start;
|
||||||
start = start_pin(obj->port);
|
|
||||||
if(start == NC)
|
|
||||||
return;
|
|
||||||
obj->direction = dir;
|
|
||||||
pin_conf.input_pull = obj->mode;
|
|
||||||
pin_conf.powersave = obj->powersave;
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case PIN_INPUT :
|
case PIN_INPUT :
|
||||||
pin_conf.direction = PORT_PIN_DIR_INPUT;
|
pin_conf.direction = PORT_PIN_DIR_INPUT;
|
||||||
|
@ -125,8 +118,17 @@ void port_dir(port_t *obj, PinDirection dir)
|
||||||
case PIN_INPUT_OUTPUT:
|
case PIN_INPUT_OUTPUT:
|
||||||
pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK;
|
pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (i = start, j = 0; i < (start + 32); i++, j++) {
|
start = start_pin(obj->port);
|
||||||
|
if(start == NC)
|
||||||
|
return;
|
||||||
|
obj->direction = dir;
|
||||||
|
pin_conf.input_pull = obj->mode;
|
||||||
|
pin_conf.powersave = obj->powersave;
|
||||||
|
|
||||||
|
for (i = start, j = 0; j < 32; i++, j++) {
|
||||||
if (obj->mask & (1<<j)) {
|
if (obj->mask & (1<<j)) {
|
||||||
port_pin_set_config((PinName)i, &pin_conf);
|
port_pin_set_config((PinName)i, &pin_conf);
|
||||||
}
|
}
|
||||||
|
@ -155,9 +157,9 @@ void port_write(port_t *obj, int value)
|
||||||
int port_read(port_t *obj)
|
int port_read(port_t *obj)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(obj);
|
MBED_ASSERT(obj);
|
||||||
if (obj->direction == PIN_INPUT) {
|
if (obj->direction == PIN_OUTPUT) {
|
||||||
return (*obj->IN & obj->mask);
|
|
||||||
} else {
|
|
||||||
return (*obj->OUT & obj->mask);
|
return (*obj->OUT & obj->mask);
|
||||||
|
} else {
|
||||||
|
return (*obj->IN & obj->mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue