On Wed, Jun 14, 2017 at 04:22:52PM +0200, Ugo Mastracchio wrote:
> Hello everyone, may I throw an absolute beginner's question ? 
> 
> How do I conditionally compile based on the BSP the target is
> associated with ?I want to use different GPIO pins depending on the board....
> 
> Is there a system configuration setting valued with the BSP name ?

After writing my previous response, I am thinking I may have
misunderstood the question.  Generally, the PIN mappings are defined in
the BSP package itself, so there should be no need to remap pins based
on the BSP being used.  Are you perhaps trying to use the same BSP
package for two slightly different boards?

If this is what you want to do, you may want to take a look at how the
arduino_zero BSP handles this.  The 1) arduino zero and 2) arduino zero
pro hardware is very similar.  I believe the only difference are a few
GPIO mappings.  Rather than create a separate BSP for each board, the
arduino BSP package code uses conditional compilation.

Within the arduino repo
(https://github.com/runtimeco/mynewt_arduino_zero), the arduino_zero BSP
defines these settings:

    BSP_ARDUINO_ZERO:
        description: 'TBD'
        value: 0
        restrictions:
            - "!BSP_ARDUINO_ZERO_PRO"

    BSP_ARDUINO_ZERO_PRO:
        description: 'TBD'
        value: 0
        restrictions:
            - "!BSP_ARDUINO_ZERO"

Then, in hw/bsp/arduino_zero/include/bsp/bsp.h, pins are mapped as
follows:

    #if MYNEWT_VAL(BSP_ARDUINO_ZERO_PRO)
         ARDUINO_ZERO_D2 =     (8),
         ARDUINO_ZERO_D4 =     (14),
    #endif

    #if MYNEWT_VAL(BSP_ARDUINO_ZERO)
         ARDUINO_ZERO_D2 =     (14),
         ARDUINO_ZERO_D4 =     (8),
    #endif

It is up to the target package to define one (and only one) of
BSP_ARDUINO_ZERO_PRO or BSP_ARDUINO_ZERO.

This approach is nice because it eliminates the need for a lot of
duplicate code in a second BSP package.  One hassle involved is the
necessity to define the appropriate syscfg setting in the target
package.

Chris

Reply via email to