This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52840_bitfields.h library has strange macros

Hello, here is the question about nrf52840_bitfields.h. Is there any problem with macros definition? For example we have such definition:

/* Bit 20 : Enable differential mode */
#define SAADC_CH_CONFIG_MODE_Pos (20UL) /*!< Position of MODE field. */
#define SAADC_CH_CONFIG_MODE_Msk (0x1UL << SAADC_CH_CONFIG_MODE_Pos) /*!< Bit mask of MODE field. */
#define SAADC_CH_CONFIG_MODE_SE (0UL) /*!< Single-ended, PSELN will be ignored, negative input to SAADC shorted to GND */
#define SAADC_CH_CONFIG_MODE_Diff (1UL) /*!< Differential */

I expected to see definition of SAADC_CH_CONFIG_MODE_Diff, as 0x1UL << SAADC_CH_CONFIG_MODE_Pos, but this if definition of SAADC_CH_CONFIG_MODE_Msk.

So I can't just write NRF_SAADC->CH[n]. CONFIG |= SAADC_CH_CONFIG_MODE_Diff.

And I have to write  NRF_SAADC->CH[n]. CONFIG |= SAADC_CH_CONFIG_MODE_Diff << SAADC_CH_CONFIG_MODE_Pos instead.

So here is the question: does it really comfortable to work with such macros? For me it creates some difficulties with code reading and writing, maybe it is possible to fix this in the next generation libraries?

Parents
  • Hi 

    The idea is to keep the value of a field and it's position in the register separated, just as it is in the register description in the product specification. 

    There shouldn't really be a need for the application to access these bitfields directly. Instead we provide a series of low level drivers in the nrfx module to abstract away these macros, and all direct register access. 

    Is there any reason you can't just use the nrfx_saadc driver instead?

    Best regards
    Torbjørn

Reply
  • Hi 

    The idea is to keep the value of a field and it's position in the register separated, just as it is in the register description in the product specification. 

    There shouldn't really be a need for the application to access these bitfields directly. Instead we provide a series of low level drivers in the nrfx module to abstract away these macros, and all direct register access. 

    Is there any reason you can't just use the nrfx_saadc driver instead?

    Best regards
    Torbjørn

Children
Related