- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
PSoC 6 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot Len