Need help with component gpio definition

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

cross mob
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I want to create a component with a non-fixed number of output pins (eg: 1 to 10 pins).

For instance: In the component dialog I want to specify 3 pins and the component needs to generate MyPin_0, MyPin_1 and MyPin_2.

I have done that before using pins on a single port, but this time I have to assign the pins freely to any available port.

One of the gurus can help me?

Bob

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi Bob,

Attached is a demo component with variable number of buried pins (1 to 10).

Have a nice weekend

/odissey1

View solution in original post

0 Likes
9 Replies
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi Bob,

Attached is a demo component with variable number of buried pins (1 to 10).

Have a nice weekend

/odissey1

0 Likes

Thank you odissey1! That will do the trick.

Bob

0 Likes
lock attach
Attachments are accessible only for community members.

Bob,

there is another solution available (project attached).

I have a question though. In such arrangement, pins can be accessed like

CyPins_SetPin(myPins_1_REG_0_0);

which is not very convenient.

Is there any way to access pins through their index? like

CyPins_SetPin(myPins_1_REG_0[0]);  // this won't work

odissey1

Pin number_Congigure_1a.png

0 Likes

As a standard there is not an option as you want.

My workaround is to define an array of pointers to functions and assign the wanted Pin_Write() APIs.

typedef void (*PinWrite)(uint8);

PinWrite const WritePins[] = {

   {
   &Servo_0_Write,
   &Servo_1_Write,
   &Servo_2_Write,
   &Servo_3_Write,
   &Servo_4_Write,
   &Servo_5_Write,
   };

Bob

lock attach
Attachments are accessible only for community members.

Bob,

I managed to itemize pins in non-contiguous (spanning) mode. It is not quite the same as you mentioned above, but it works. Demo Project attached. The pointer array declaration came out way ugly, but it was the only way I managed it to work. Problem was due to the fact that the number of pins is variable, so its impossible to make pointers to non-existing pins.

Appreciate if you can point to a better solution.

/odissey1

0 Likes

As you could see in my attached project regarding the text-field expansion. My solution does not differ much from your approach.

Bob

0 Likes
PeVo_1249246
Level 3
Level 3
10 replies posted 5 replies posted Welcome!

It is matter of taste of-course: you could use one control register of PSOC3/5 and wire connect the bits to the pins you want. Then you may need to modify the specific bit of the control register or can modify several bits at once.

0 Likes

Thank you for the hint, but here I am working to create a component where the user will specify how many pins the component is actually using. The control register does not help in this case.

Bob

0 Likes

It will get much more difficult as needed indeed but SHOULD still be possible for up to 32 IO-s. Some more hints: combining UDB-s and preprogrammed muxes which can be configured according to the selection from user. Never mind if no help from it.

0 Likes