Retrieve pin and port name

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

cross mob
SaGa_4641021
Level 5
Level 5
50 questions asked 50 replies posted 100 sign-ins

Hi

I have a pin defined as "SD_CD" (sd-card CD signal), and at one point, it is connected to (P10_2_PORT, P10_2_NUM).

I am writing a library function that would be passed the signal name (SD_CD) and I need to fetch the port and pin name (P10_2_PORT, P10_2_NUM) and perform action on that pin, for example: CY_GPIO_Read(P10_2_PORT, P10_2_NUM)

How would I do this ?

thanks

 

0 Likes
1 Solution

SaGa,

Using "P10_2_PORT, P10_2_NUM" hardcodes the pin location in your code (Port10 bit 2).   Later if you decide to change the pin designation, your code will still control Port10 bit 2.

However if you assigned SD_CD to the pin name, the IDE will assign a pin name alias of SD_CD_0 as Nikhil indicated.   Now if you use SD_CD_0_PORT, SD_CD_0_NUM" in place of "P10_2_PORT, P10_2_NUM", the compiler will know were the physical location of the pin and control it in your application.  Later if you change the pin assignment (but leave the name assignment), the new compiler will automatically control the newly configured pin.

This programming technique is call "abstraction".  Using abstraction methods will  make coordinating small to large changes in your code easier.

The Infineon development tools support and encourage abstraction using aliases.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

4 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @SaGa_4641021,

When an I/O pin has been defined with the name "SD_CD", then the port and pin corresponding to SD_CD will be named as "SD_CD_0_PORT" and "SD_CD_0_NUM".

Regards,
Nikhil

0 Likes

is there a way you recommend that i can call the function CY_GPIO_Read(,) and pass to it the parameters  "P10_2_PORT, P10_2_NUM" but as variables, such the only fixed is the pin name "SD_CD" but the  specific port and pin can be different ?

thanks

0 Likes

SaGa,

Using "P10_2_PORT, P10_2_NUM" hardcodes the pin location in your code (Port10 bit 2).   Later if you decide to change the pin designation, your code will still control Port10 bit 2.

However if you assigned SD_CD to the pin name, the IDE will assign a pin name alias of SD_CD_0 as Nikhil indicated.   Now if you use SD_CD_0_PORT, SD_CD_0_NUM" in place of "P10_2_PORT, P10_2_NUM", the compiler will know were the physical location of the pin and control it in your application.  Later if you change the pin assignment (but leave the name assignment), the new compiler will automatically control the newly configured pin.

This programming technique is call "abstraction".  Using abstraction methods will  make coordinating small to large changes in your code easier.

The Infineon development tools support and encourage abstraction using aliases.

Len
"Engineering is an Art. The Art of Compromise."
SaGa_4641021
Level 5
Level 5
50 questions asked 50 replies posted 100 sign-ins

thanks a lot Len 

0 Likes