-
1. Re: Is there a way to address GPIO pins by using an index with the pin numbers in an array on a PSoC6?
user_1377889 Jul 6, 2018 6:37 AM (in response to chrisvn_1477726)Easiest approach will be to use a const array of functions to access the pins. This has the advantage that you can span ports.
Bob
-
2. Re: Is there a way to address GPIO pins by using an index with the pin numbers in an array on a PSoC6?
chrisvn_1477726 Jul 6, 2018 6:40 AM (in response to user_1377889)Thanks Bob, I will look into it.
-
3. Re: Is there a way to address GPIO pins by using an index with the pin numbers in an array on a PSoC6?
MeenakshiR_71 Jul 10, 2018 9:07 PM (in response to chrisvn_1477726)Chris,
If you can design/select the pins such that if they all fit in one port, then you can use the Port registers (GPIO_PRT[i]) directly to read the status or update the pin output. This will not only reduce the complexity but also improves efficiency.
If you cannot design/select the pins in the same port, then the PDL does not provide much options. As bob suggested, you can use an array of functions to get the status or update the pin output by indexing the array based on your pin number as index. You can even define your own function to get the combined status (something like below). Or in similar fashion, define APIs for all your needs - set output, drive mode, interrupt status etc. You can even define interrupt APIs and use the IRQ15 (GPIO all ports interrupt) for executing interrupt related processes.
#define NUMBER_OF_PINS 5
typedef struct {
GPIO_PRT_Type *port;
uint32 pin;
} gpio_pins;
gpio_pins pinsArray[NUMBER_OF_PINS] =
{
{GPIO_PRT0, 0},
{GPIO_PRT1, 1},
{GPIO_PRT9, 2},
{GPIO_PRT6, 3},
{GPIO_PRT10, 4}
};
uint32 Custom_GetAllPinStatus(void)
{
uint32 retStatus = 0;
for(uint32 index = 0; index < NUMBER_OF_PINS; index++)
{
retStatus |= ((Cy_GPIO_Read(pinsArray[index].port, pinsArray[index].pin))<<index);
}
return retStatus;
}
Let me know if this helps or you need further clarifications.
Regards,
Meenakshi Sundaram R
-
4. Re: Is there a way to address GPIO pins by using an index with the pin numbers in an array on a PSoC6?
chrisvn_1477726 Jul 11, 2018 3:33 AM (in response to MeenakshiR_71)Hi Meenakshi
I have already done what you are suggesting on the array of structure. It works very well. I have to make provision for not being able to place all inputs on one port. For developing on a CY8CKIT-062 it is especially important as many pins are already allocated to certain functions. Unless you want to butcher the kit to re-assign the pins by removing and adding components.
Great minds think alike.
Thank you for your response.
Regards
Chris