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

PSoC™ 4

JeSy_1305731
Level 4
First like received
Level 4

in psoc creator, if you use the schematic tool to create 4 input switches,  and name them SW1, SW2, SW3, SW4,  the tool autogenerates 4 instances of the exact same code, the only difference is the name of the function,  it creates API  SW1_Read  SW1_Write,  SW2_Read, SW2_Write, SW3_Read  SW3_Write,  SW4_Read, SW4_Write,

Is there a way to get the tool to generate one copy of the API then you pass it the port.  for instance just having Read_Port, and Write_Port, then pass the port as variable. instead of having 4 coppies of the same code?

0 Likes
6 Replies
HeLi_263931
Level 8
100 likes received 50 likes received 25 likes received
Level 8

With Creator 4.3, there is the start of PDL components for PSoC6. I have no checked how much of that also applies also to PSoC4, but it might be worth a try.

I know that the PDL are also part of earlier Creator version, but I cannot tell how much of it applies to PSoC4.

PDL (peripheral driver libraries) follow a different API style than the component-based API, so you can hand in a port- and a pin number in the generic GPIO-functions instead of having one function per component.

0 Likes
Owen_Zhang123
Moderator
Moderator 500 solutions authored 250 sign-ins 1000 replies posted
Moderator

Hi

If you are using the continue pin such as P1_1 to P1_4, then you can set the Pin configure as follows.

Then you can use the "void SW_Write(uint8 value)" function.

pastedImage_0.png

0 Likes
JeSy_1305731
Level 4
First like received
Level 4

thanks this would help but my application has all different pins that are not on the same port and not in order.  I have 4 input switches and 3 output leds. 

P0_4, P0_5 is Uart

P5_0, P5_1 is I2C connected to FRAM

P0_6, P0_7 is SWD

Switch on P1_5, P1_6, P1_7, P3_4,

Led on P4_0, P4_1, P1_4,

P3_5, P3_6, P3_7 is A2D

0 Likes
Anonymous
Not applicable

Two simple functions written to map the pins with specific values would do what you are wanting:

uint8 Read_SW(uint8 port)

{

    switch(port) {

        case 0:

        return Pin_1_Read();

        //return Pin_1

        break;

        case 1:

        return Pin_2_Read();

        //return Pin_2

        break; 

        case 2:

        return Pin_3_Read();

        //return Pin_3

        break; 

        case 3:

        return Pin_4_Read();

        //return Pin_4

        break; 

        default:

        return 0xFF;

        break; 

    }

}

void Write_SW(uint8 port, uint8 value)

{

    switch(port) {

        case 0:

        Pin_5_Write(value);

        //write Pin_5

        break;

        case 1:

        Pin_6_Write(value);

        //write Pin_6

        break;

        case 2:

        Pin_7_Write(value);

        //write Pin_7

        break;

    }

}

This would not be automatic however, and you would have to write which pins map to which values...

0 Likes
JeSy_1305731
Level 4
First like received
Level 4

yes thank you, I understand this,  but my question is related to code space.  the BLE stack almost takes up the entire 128K of code space.   for instance,  If I build and compile the OTA bootloader (which I plan to use in my end applicaion) it takes 120K of 128K leaving me very little resources for my application, so my original intent for posting was to eliminate code redundancy,  and I noticed that the API in PSoC creator was basically creating coppies of the same code for every digital input and output with the only difference being they change the name of the calling function.    I have noticed in tools with competitor of cypress, that they compress their code by generating the API differently.   and they do as mentioned,  create one function.  and when you call it, you specify the port and pin and logic level, and input or output.   this creates one driver (set of code) .    I know I can duplicate this process manually.  I was just wondering if there is a way to get the tool to do this automatically.    for instance if you create or load one of the example projects, and have a Red led, a green led, and a blue led,  the tool does automatic generation of Red_led_Write(x), Green_led_Write(x), Blue_led_Write(x),   basically creating 3 copies of the same code.   likewise the same for the switches,  SW1, SW2, SW3, SW4,   i get 4 coppies of the same code again. so ultimately I just want to save code space.

0 Likes
Anonymous
Not applicable

Ouch. Yeah, from what I've seen of the OTA BLE bootloader, if you don't use the 256k chips then you get almost no room for program space

After building the project to generate the code for the pins/components, you could then consolidate it using the above mentioned functions of combining a single routine to handle port flipping, but it would get deleted on rebuilds and would, unfortunately, need to be manually changed to work as desired.

You could do this by modifying the generated source files for the pins and components to consolidate the code space;

Alternatively, I believe there is a way to create your own custom component that would allow custom code/pin behavior while properly regenerating the object code upon rebuilding the project.

0 Likes