QDEC HAL

group nrf_qdec_hal

Hardware access layer for managing the Quadrature Decoder (QDEC) peripheral.

Defines

NRF_QDEC_PIN_NOT_CONNECTED

This value can be provided as a parameter for the nrf_qdec_pins_set function call to specify that a LED signal shall not be use by the QDEC and connected to a physical pin.

NRF_QDEC_HAS_TASK_RDCLRACC

Presence of the RDCLRACC task.

NRF_QDEC_HAS_TASK_RDCLRDBL

Presence of the RDCLRDBL task.

NRF_QDEC_HAS_EVENT_DBLRDY

Presence of the DBLRDY event.

NRF_QDEC_HAS_EVENT_STOPPED

Presence of the STOPPED event.

NRF_QDEC_LEDPRE_DEFAULT

Reset value of LEDPRE register.

Enums

enum nrf_qdec_task_t

QDEC tasks.

Values:

enumerator NRF_QDEC_TASK_START

Starting the quadrature decoder.

enumerator NRF_QDEC_TASK_STOP

Stopping the quadrature decoder.

enumerator NRF_QDEC_TASK_READCLRACC

Reading and clearing ACC and ACCDBL registers.

enumerator NRF_QDEC_TASK_RDCLRACC

Reading and clearing ACC register.

enumerator NRF_QDEC_TASK_RDCLRDBL

Reading and clearing ACCDBL register.

enum nrf_qdec_event_t

QDEC events.

Values:

enumerator NRF_QDEC_EVENT_SAMPLERDY

Event generated for every new sample.

enumerator NRF_QDEC_EVENT_REPORTRDY

Event generated for every new report.

enumerator NRF_QDEC_EVENT_ACCOF

Event generated for every accumulator overflow.

enumerator NRF_QDEC_EVENT_DBLRDY

Event generated for every double displacement(s) detected.

enumerator NRF_QDEC_EVENT_STOPPED

Event generated for every QDEC stop.

enum nrf_qdec_short_mask_t

QDEC shortcuts.

Values:

enumerator NRF_QDEC_SHORT_REPORTRDY_READCLRACC_MASK

Shortcut between REPORTRDY event and READCLRACC task.

enumerator NRF_QDEC_SHORT_SAMPLERDY_STOP_MASK

Shortcut between SAMPLERDY event and STOP task.

enum nrf_qdec_int_mask_t

QDEC interrupts.

Values:

enumerator NRF_QDEC_INT_SAMPLERDY_MASK

Mask for enabling or disabling an interrupt on SAMPLERDY event.

enumerator NRF_QDEC_INT_REPORTRDY_MASK

Mask for enabling or disabling an interrupt on REPORTRDY event.

enumerator NRF_QDEC_INT_ACCOF_MASK

Mask for enabling or disabling an interrupt on ACCOF event.

enum nrf_qdec_enable_t

States of the enable bit.

Values:

enumerator NRF_QDEC_DISABLE

Mask for disabling the QDEC periperal. When disabled, the QDEC decoder pins are not active.

enumerator NRF_QDEC_ENABLE

Mask for enabling the QDEC periperal. When enabled, the QDEC pins are active.

enum nrf_qdec_dbfen_t

States of the debounce filter enable bit.

Values:

enumerator NRF_QDEC_DBFEN_DISABLE

Mask for disabling the debounce filter.

enumerator NRF_QDEC_DBFEN_ENABLE

Mask for enabling the debounce filter.

enum nrf_qdec_ledpol_t

Active LED polarity.

Values:

enumerator NRF_QDEC_LEPOL_ACTIVE_LOW

QDEC LED active on output pin low.

enumerator NRF_QDEC_LEPOL_ACTIVE_HIGH

QDEC LED active on output pin high.

enum nrf_qdec_sampleper_t

Available sampling periods.

Values:

enumerator NRF_QDEC_SAMPLEPER_128US

QDEC sampling period 128 microseconds.

enumerator NRF_QDEC_SAMPLEPER_256US

QDEC sampling period 256 microseconds.

enumerator NRF_QDEC_SAMPLEPER_512US

QDEC sampling period 512 microseconds.

enumerator NRF_QDEC_SAMPLEPER_1024US

QDEC sampling period 1024 microseconds.

enumerator NRF_QDEC_SAMPLEPER_2048US

QDEC sampling period 2048 microseconds.

enumerator NRF_QDEC_SAMPLEPER_4096US

QDEC sampling period 4096 microseconds.

enumerator NRF_QDEC_SAMPLEPER_8192US

QDEC sampling period 8192 microseconds.

enumerator NRF_QDEC_SAMPLEPER_16384US

QDEC sampling period 16384 microseconds.

enum nrf_qdec_reportper_t

Available report periods.

Values:

enumerator NRF_QDEC_REPORTPER_1

QDEC report period 1 sample.

enumerator NRF_QDEC_REPORTPER_10

QDEC report period 10 samples.

enumerator NRF_QDEC_REPORTPER_40

QDEC report period 40 samples.

enumerator NRF_QDEC_REPORTPER_80

QDEC report period 80 samples.

enumerator NRF_QDEC_REPORTPER_120

QDEC report period 120 samples.

enumerator NRF_QDEC_REPORTPER_160

QDEC report period 160 samples.

enumerator NRF_QDEC_REPORTPER_200

QDEC report period 200 samples.

enumerator NRF_QDEC_REPORTPER_240

QDEC report period 240 samples.

enumerator NRF_QDEC_REPORTPER_280

QDEC report period 280 samples.

Functions

NRF_STATIC_INLINE void nrf_qdec_enable(NRF_QDEC_Type *p_reg)

Function for enabling QDEC.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_qdec_disable(NRF_QDEC_Type *p_reg)

Function for disabling QDEC.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE uint32_t nrf_qdec_enable_get(NRF_QDEC_Type const *p_reg)

Function for returning the enable state of QDEC.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

State of the register.

NRF_STATIC_INLINE void nrf_qdec_int_enable(NRF_QDEC_Type *p_reg, uint32_t mask)

Function for enabling QDEC interrupts by mask.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be enabled. Use nrf_qdec_int_mask_t values for bit masking.

NRF_STATIC_INLINE void nrf_qdec_int_disable(NRF_QDEC_Type *p_reg, uint32_t mask)

Function for disabling QDEC interrupts by mask.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be disabled. Use nrf_qdec_int_mask_t values for bit masking.

NRF_STATIC_INLINE uint32_t nrf_qdec_int_enable_check(NRF_QDEC_Type const *p_reg, uint32_t mask)

Function for checking if the specified interrupts are enabled.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be checked. Use nrf_qdec_int_mask_t values for bit masking.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE void nrf_qdec_dbfen_enable(NRF_QDEC_Type *p_reg)

Function for enabling the QDEC debouncing filter.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_qdec_dbfen_disable(NRF_QDEC_Type *p_reg)

Function for disabling the QDEC debouncing filter.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE uint32_t nrf_qdec_dbfen_get(NRF_QDEC_Type const *p_reg)

Function for getting the state of the QDEC debouncing filter.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Return values:
  • NRF_QDEC_DBFEN_DISABLE – The debouncing filter is disabled.

  • NRF_QDEC_DBFEN_ENABLE – The debouncing filter is enabled.

NRF_STATIC_INLINE void nrf_qdec_pins_set(NRF_QDEC_Type *p_reg, uint32_t phase_a_pin, uint32_t phase_b_pin, uint32_t led_pin)

Function for configuring QDEC pins.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • phase_a_pin[in] Phase A pin number.

  • phase_b_pin[in] Phase B pin number.

  • led_pin[in] LED pin number.

NRF_STATIC_INLINE uint32_t nrf_qdec_phase_a_pin_get(NRF_QDEC_Type const *p_reg)

Function for getting the Phase A pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Phase A pin selection.

NRF_STATIC_INLINE uint32_t nrf_qdec_phase_b_pin_get(NRF_QDEC_Type const *p_reg)

Function for getting the Phase B pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Phase B pin selection.

NRF_STATIC_INLINE uint32_t nrf_qdec_led_pin_get(NRF_QDEC_Type const *p_reg)

Function for getting the LED pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

LED pin selection.

NRF_STATIC_INLINE void nrf_qdec_task_trigger(NRF_QDEC_Type *p_reg, nrf_qdec_task_t task)

Function for setting the specified QDEC task.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] QDEC task to be triggered.

NRF_STATIC_INLINE uint32_t nrf_qdec_task_address_get(NRF_QDEC_Type const *p_reg, nrf_qdec_task_t task)

Function for retrieving the address of a QDEC task register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] QDEC task to get its address.

Returns:

Address of the specified QDEC task.

NRF_STATIC_INLINE void nrf_qdec_event_clear(NRF_QDEC_Type *p_reg, nrf_qdec_event_t event)

Function for clearing the specified QDEC event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] QDEC event to be cleared.

NRF_STATIC_INLINE bool nrf_qdec_event_check(NRF_QDEC_Type const *p_reg, nrf_qdec_event_t event)

Function for getting the state of the specified QDEC event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] QDEC event to be checked.

Returns:

State of the specified QDEC event.

NRF_STATIC_INLINE uint32_t nrf_qdec_event_address_get(NRF_QDEC_Type const *p_reg, nrf_qdec_event_t event)

Function for retrieving the address of the specified QDEC event register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] QDEC event to get its address.

Returns:

Address of the specified QDEC event.

NRF_STATIC_INLINE void nrf_qdec_shorts_enable(NRF_QDEC_Type *p_reg, uint32_t mask)

Function for setting QDEC shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of QDEC shortcuts to be set.

NRF_STATIC_INLINE void nrf_qdec_shorts_disable(NRF_QDEC_Type *p_reg, uint32_t mask)

Function for clearing shortcuts of the QDEC by mask.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of QDEC shortcuts to be cleared.

NRF_STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(nrf_qdec_sampleper_t sampleper)

Function for converting return value of the nrf_qdec_sampleper_get function to microseconds.

Parameters:
  • sampleper[in] The sampling period.

Returns:

Period in microseconds.

NRF_STATIC_INLINE void nrf_qdec_sampleper_set(NRF_QDEC_Type *p_reg, nrf_qdec_sampleper_t sampleper)

Function for setting value of the QDEC sampling period.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • sampleper[in] The sampling period.

NRF_STATIC_INLINE nrf_qdec_sampleper_t nrf_qdec_sampleper_get(NRF_QDEC_Type const *p_reg)

Function for retrieving value of the QDEC sampling period.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Sampling period.

NRF_STATIC_INLINE int32_t nrf_qdec_sample_get(NRF_QDEC_Type const *p_reg)

Function for retrieving value of the QDEC SAMPLE register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Value of the SAMPLE register.

NRF_STATIC_INLINE int32_t nrf_qdec_acc_get(NRF_QDEC_Type const *p_reg)

Function for retrieving value of the QDEC ACC register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Value of the ACC register.

NRF_STATIC_INLINE int32_t nrf_qdec_accread_get(NRF_QDEC_Type const *p_reg)

Function for retrieving value of the QDEC ACCREAD register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Value of the ACCREAD register.

NRF_STATIC_INLINE uint32_t nrf_qdec_accdbl_get(NRF_QDEC_Type const *p_reg)

Function for retrieving value of the QDEC ACCDBL register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Value of the ACCDBL register.

NRF_STATIC_INLINE uint32_t nrf_qdec_accdblread_get(NRF_QDEC_Type const *p_reg)

Function for retrieving value of the QDEC ACCDBLREAD register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Value of the ACCDBLREAD register.

NRF_STATIC_INLINE void nrf_qdec_ledpre_set(NRF_QDEC_Type *p_reg, uint32_t time_us)

Function for setting delay time between setting LED active state and start sampling.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • time_us[in] Delay time (in microseconds) between setting LED active state and start sampling.

NRF_STATIC_INLINE uint32_t nrf_qdec_ledpre_get(NRF_QDEC_Type const *p_reg)

Function for retrieving how long the LED is switched on before sampling.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

The gap in time in microseconds between switched LED to active state and start sampling.

NRF_STATIC_INLINE void nrf_qdec_reportper_set(NRF_QDEC_Type *p_reg, nrf_qdec_reportper_t reportper)

Function for setting the report period (in samples).

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • reportper[in] The number of samples.

NRF_STATIC_INLINE nrf_qdec_reportper_t nrf_qdec_reportper_get(NRF_QDEC_Type const *p_reg)

Function for retrieving the report period.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

The report period.

NRF_STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(nrf_qdec_reportper_t reportper)

Function for retrieving the value of QDEC SAMPLEPER register.

Parameters:
  • reportper[in] Reportper to be converted to amount of samples per report.

Returns:

Number of samples per report.

NRF_STATIC_INLINE void nrf_qdec_ledpol_set(NRF_QDEC_Type *p_reg, nrf_qdec_ledpol_t pol)

Function for setting the active level for the LED.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • pol[in] Level of the active signal of the LED.

NRF_STATIC_INLINE uint32_t nrf_qdec_ledpol_get(NRF_QDEC_Type const *p_reg)

Function for retrieving the active level for the LED.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Level of the active signal of the LED.