Skip to content

Commit 6b04bb3

Browse files
committed
Update port api driver to add missing ports
This patch updates port api driver to add missing ports. Signed-off-by: Marc Moreno <[email protected]>
1 parent 8de4c53 commit 6b04bb3

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/PortNames.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ extern "C" {
2222

2323
typedef enum {
2424
Port0 = 0,
25-
Port1 = 1
25+
Port1,
26+
Port2,
27+
Port3,
2628
} PortName;
2729

2830
#ifdef __cplusplus

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/port_api.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,45 @@
1717
#include "pinmap.h"
1818
#include "gpio_api.h"
1919

20+
#define MAX_GPIO_PINS 16
21+
2022
PinName port_pin(PortName port, int pin_n)
2123
{
24+
if (pin_n < 0 || pin_n > MAX_GPIO_PINS) {
25+
error("Invalid GPIO pin number %d", pin_n);
26+
}
27+
2228
return (PinName)((port << PORT_SHIFT) | pin_n);
2329
}
2430

2531
void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
2632
{
27-
obj->port = port;
28-
obj->mask = mask;
33+
uint32_t i;
34+
CMSDK_GPIO_TypeDef *port_reg;
2935

30-
CMSDK_GPIO_TypeDef *port_reg = (CMSDK_GPIO_TypeDef *)(CMSDK_GPIO0_BASE
31-
+ ((int)port * 0x10));
36+
switch (port) {
37+
case Port0:
38+
port_reg = (CMSDK_GPIO_TypeDef *)(CMSDK_GPIO0_BASE);
39+
break;
40+
case Port1:
41+
port_reg = (CMSDK_GPIO_TypeDef *)(CMSDK_GPIO1_BASE);
42+
break;
43+
case Port2:
44+
port_reg = (CMSDK_GPIO_TypeDef *)(CMSDK_GPIO2_BASE);
45+
break;
46+
case Port3:
47+
port_reg = (CMSDK_GPIO_TypeDef *)(CMSDK_GPIO3_BASE);
48+
break;
49+
}
3250

33-
obj->reg_in = &port_reg->DATAOUT;
34-
obj->reg_dir = &port_reg->OUTENABLESET;
51+
obj->port = port;
52+
obj->mask = mask;
53+
obj->reg_in = &port_reg->DATAOUT;
54+
obj->reg_dir = &port_reg->OUTENABLESET;
3555
obj->reg_dirclr = &port_reg->OUTENABLECLR;
3656

37-
uint32_t i;
38-
// The function is set per pin: reuse gpio logic
39-
for (i=0; i<16; i++) {
57+
/* The function is set per pin: reuse gpio logic */
58+
for (i=0; i < MAX_GPIO_PINS; i++) {
4059
if (obj->mask & (1<<i)) {
4160
gpio_set(port_pin(obj->port, i));
4261
}
@@ -48,9 +67,9 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
4867
void port_mode(port_t *obj, PinMode mode)
4968
{
5069
uint32_t i;
51-
// The mode is set per pin: reuse pinmap logic
52-
for (i=0; i<32; i++) {
53-
if (obj->mask & (1<<i)) {
70+
/* The mode is set per pin: reuse pinmap logic */
71+
for (i=0; i < MAX_GPIO_PINS; i++) {
72+
if (obj->mask & (1 << i)) {
5473
pin_mode(port_pin(obj->port, i), mode);
5574
}
5675
}

0 commit comments

Comments
 (0)