cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4

vegan_electron
New Contributor II

Dear community,

i have a workspace containing 3 projects which are the Launcher, BLE OTA Update and Firmware. All projects with exception the launcher using BLE Component and ADC. I use the ADC to measure the battery voltage to use this value in the advertisement of 2 different projects. I would kindly like to know how i can implement my advertising-code in a separate project by using the BLE component and ADC? I would appreciate to edit this "library" code at any time. So dealing with binaries and copy them seems not a good option to me.

Thank you very much for information to solve this.

Daniel

0 Likes
1 Solution
Len_CONSULTRON
Honored Contributor II

Daniel,

It is not practical to share component code or the TopDesign schematics between projects.  Having said that, it is very easy to cut-n-paste schematic elements between separate schematics in the project's TopDesign.

If you are creating your own common code between projects, it is relatively easy to share between projects.

Steps:

  1. Create the common code in the 'first' project.
  2. Right-click on the second project and select "Add/Existing Item..."
    Len_CONSULTRON_0-1616338907933.png
  3. Using the File Explorer the opens up, find the common code located in the first project's directory.
  4. Once the common code file(s) are selected, they should be appear in the second project's space in the workspace.   They will now be referenced to the first project directory and should compile.   Note:  #include references may have an issue.  This can be fixed by the next step.
  5. Right-click on the second project and select "Build Settings..."
    Len_CONSULTRON_1-1616339262020.png

     

  6. In the "Build Settings" dialog select "Compiler/Additional Include Directories/..."
    Len_CONSULTRON_2-1616339400377.png
  7. In the "File Explorer" find and select the first project directory.   This will force the second project to also include the first project's include files.

With the above steps, you should be able to share common code and have it build without issue.  You can extend these steps across ALL your projects in the workspace.

I do this for many of my projects under one workspace.   I find it very convenient to change the common code ONCE.

Caution: Depending on your common code resource sharing requirements, you may want to perform a "Build All Projects (F6)" to make sure your code changes build across all projects.

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

View solution in original post

5 Replies
VenkataD_41
Moderator
Moderator

Hi Daniel,

>>"I would kindly like to know how i can implement my advertising-code in a separate project by using the BLE component and ADC? I would appreciate to edit this "library" code at any time. So dealing with binaries and copy them seems not a good option to me."

--> Sorry, I could not be able to understand your query. Could you please elaborate more?

Thanks and regards

Ganesh

0 Likes
vegan_electron
New Contributor II

Ok, i try it simpler.
I would like to have code which rely on components (TopDesign) shared among other projects within the same workspace. 

0 Likes
VenkataD_41
Moderator
Moderator

Hi,

Please note that in PSoC Creator generates the code for the components present in TopDesign/schematic. This generated code is present in either  <component_name>.c or either in cy_fitter_cfg.c files. 

Can you please let us know the reason behind your request of sharing the ADC functions between the Stack and application? Does your application or stack run out of space? 

The ADC and its APIs are present in ADC.c and ADC.h. In your project (stack/application) the APIs might be called at different places. So it will be difficult to share the source code completely between the two projects unless it is a single function. Also, since ADC is a fixed function block the relative space taken by the source code can be small. So you can use it separately in both stack and application projects.

Please update with your answers to our questions.

Thanks and regards

Ganesh

0 Likes
vegan_electron
New Contributor II

Dear Ganesh,

i explain what i want to achieve. During the advertisement we add for example the battery level. This functionality is used in the OTA Update Project and Firmware. A paradigm for good software is the DRY rule. And for that reason i wouldn't duplicate the code. So my question is first how to use a "library"? But then i encounter i need the ADC Component for getting the battery value. What is a good approach or strategy to handle such cases?

Thank you very much,
Daniel

0 Likes
Len_CONSULTRON
Honored Contributor II

Daniel,

It is not practical to share component code or the TopDesign schematics between projects.  Having said that, it is very easy to cut-n-paste schematic elements between separate schematics in the project's TopDesign.

If you are creating your own common code between projects, it is relatively easy to share between projects.

Steps:

  1. Create the common code in the 'first' project.
  2. Right-click on the second project and select "Add/Existing Item..."
    Len_CONSULTRON_0-1616338907933.png
  3. Using the File Explorer the opens up, find the common code located in the first project's directory.
  4. Once the common code file(s) are selected, they should be appear in the second project's space in the workspace.   They will now be referenced to the first project directory and should compile.   Note:  #include references may have an issue.  This can be fixed by the next step.
  5. Right-click on the second project and select "Build Settings..."
    Len_CONSULTRON_1-1616339262020.png

     

  6. In the "Build Settings" dialog select "Compiler/Additional Include Directories/..."
    Len_CONSULTRON_2-1616339400377.png
  7. In the "File Explorer" find and select the first project directory.   This will force the second project to also include the first project's include files.

With the above steps, you should be able to share common code and have it build without issue.  You can extend these steps across ALL your projects in the workspace.

I do this for many of my projects under one workspace.   I find it very convenient to change the common code ONCE.

Caution: Depending on your common code resource sharing requirements, you may want to perform a "Build All Projects (F6)" to make sure your code changes build across all projects.

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

View solution in original post