Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 6 Forum Discussions

aliissa02
Level 4
5 likes given 25 replies posted 50 sign-ins
Level 4

Hello,

I am trying to assign a list of pins to a variable. Is it possible to do it like this?(Please see picture attached)

Thank you

0 Likes
1 Solution
Srivastav
Moderator
Moderator 100 sign-ins 10 likes received 5 likes given
Moderator

Hi @aliissa02 ,

 

You can do it. This won't be an issue but if you assign the port macros as an element in the Array, while calling a function you cannot simply write LED_ports[i]. You always have to check what that macro is pointing to, Sometimes it may point to some memory location through a pointer, then you have to type cast the the argument.

Refer to below mentioned code:
int LED_PORT[2]={LED_Blue_P11_1_PORT, LED_Blue_P11_1_NUM};

Cy_GPIO_Clr((GPIO_PRT_Type*)LED_PORT[0], LED_PORT[1]);

Cy_GPIO_Set((GPIO_PRT_Type*)LED_PORT[0], LED_PORT[1]);



Above mentioned line is code is equivalent to below mentioned code:

Cy_GPIO_Clr(LED_Blue_P11_1_PORT, LED_Blue_P11_1_NUM);

Cy_GPIO_Set(LED_Blue_P11_1_PORT, LED_Blue_P11_1_NUM);

 

Kind regards

Arpit Srivastav

View solution in original post

0 Likes
1 Reply
Srivastav
Moderator
Moderator 100 sign-ins 10 likes received 5 likes given
Moderator

Hi @aliissa02 ,

 

You can do it. This won't be an issue but if you assign the port macros as an element in the Array, while calling a function you cannot simply write LED_ports[i]. You always have to check what that macro is pointing to, Sometimes it may point to some memory location through a pointer, then you have to type cast the the argument.

Refer to below mentioned code:
int LED_PORT[2]={LED_Blue_P11_1_PORT, LED_Blue_P11_1_NUM};

Cy_GPIO_Clr((GPIO_PRT_Type*)LED_PORT[0], LED_PORT[1]);

Cy_GPIO_Set((GPIO_PRT_Type*)LED_PORT[0], LED_PORT[1]);



Above mentioned line is code is equivalent to below mentioned code:

Cy_GPIO_Clr(LED_Blue_P11_1_PORT, LED_Blue_P11_1_NUM);

Cy_GPIO_Set(LED_Blue_P11_1_PORT, LED_Blue_P11_1_NUM);

 

Kind regards

Arpit Srivastav

0 Likes