Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PCA10056 Board Definition

Hi,

I'm using nrf52840 and trying to define the pin mappings for my custom board. In order to do this I'm studying the board definition of pca10056 (pca10056.h).

In that file I saw some definitions are mapped to single pin number, for example 

#define BSP_LED_0   13
#define BUTTON_1    11
.

However, there are also some definitions mapped using the macro 

NRF_GPIO_PIN_MAP(port, pin) (((port) << 5) | ((pin) & 0x1F))
.

My questions are the followings:

1. Just to confirm --- if I want to define a pin, for instance P1.13, I should do #define MY_PIN NRF_GPIO_PIN_MAP(1, 13), correct?

2. By looking at this macro, it seems that it should be used when I want to map to a pin on port 1. If it's on port 0, I can simply use the pin number (such as BSP_LED_0 and BUTTON_1 above)?

3. If my second point holds, why am I seeing some pins are also mapped, for example, using NRF_GPIO_PIN_MAP(0, 27)? Wouldn't this be redundant or is there something I've missed?

Thank you!

Parents
  • Hi,

    1. NRF_GPIO_PIN_MAP() is a utility-macro that can be used to define the correct pin numbers. You are not forced to use this, but it will likely make the code more readable. When a GPIO is assigned to a peripheral pin, pins on port 1 are given by setting bit 5 of the register. This is equal to adding 32 to the pin number, i.e. P1.13 would be 32+13=45. The output from the NRF_GPIO_PIN_MAP() macro would be the same.
    2. It can be used for pins on both port 0 and port 1. The port argument (0 or 1) is simply left-shifted 5 places.
    3. As mentioned before, it is not strictly necessary, but it increases readability of the code. It may also help for future maintenance/compatibility to be consistent with use of macros like this.

    Best regards,
    Jørgen

Reply
  • Hi,

    1. NRF_GPIO_PIN_MAP() is a utility-macro that can be used to define the correct pin numbers. You are not forced to use this, but it will likely make the code more readable. When a GPIO is assigned to a peripheral pin, pins on port 1 are given by setting bit 5 of the register. This is equal to adding 32 to the pin number, i.e. P1.13 would be 32+13=45. The output from the NRF_GPIO_PIN_MAP() macro would be the same.
    2. It can be used for pins on both port 0 and port 1. The port argument (0 or 1) is simply left-shifted 5 places.
    3. As mentioned before, it is not strictly necessary, but it increases readability of the code. It may also help for future maintenance/compatibility to be consistent with use of macros like this.

    Best regards,
    Jørgen

Children
No Data
Related