Appiko
Data Structures | Macros | Enumerations | Functions

Hardware abstraction layer of the PWM peripheral in the nRF52 SoCs. More...

Data Structures

struct  hal_pwm_sequence_config_t
 Configuration for a sequence of PWM values. Note that the buffer pointed to in this structure needs to have a lifetime longer than the duration of the PWM. More...
 
struct  hal_pwm_init_t
 Struct for initializing the hal pwm module. More...
 
struct  hal_pwm_start_t
 Struct containing the configuration for starting the hal pwm module. More...
 

Macros

#define PWM_USED   HAL_PWM_PERIPH_USED
 
#define HAL_PWM_MAX_PIN_NUM   4
 

Enumerations

enum  hal_pwm_freq_t { ,
  HAL_PWM_FREQ_8MHz = PWM_PRESCALER_PRESCALER_DIV_2, HAL_PWM_FREQ_4MHz = PWM_PRESCALER_PRESCALER_DIV_4, HAL_PWM_FREQ_2MHz = PWM_PRESCALER_PRESCALER_DIV_8, HAL_PWM_FREQ_1MHz = PWM_PRESCALER_PRESCALER_DIV_16,
  HAL_PWM_FREQ_500kHz = PWM_PRESCALER_PRESCALER_DIV_32, HAL_PWM_FREQ_250kHz = PWM_PRESCALER_PRESCALER_DIV_64, HAL_PWM_FREQ_125kHz = PWM_PRESCALER_PRESCALER_DIV_128
}
 Select the PWM frequency to operate at. More...
 
enum  hal_pwm_mode_t { HAL_PWM_MODE_UP = PWM_MODE_UPDOWN_Up, HAL_PWM_MODE_UP_DOWN = PWM_MODE_UPDOWN_UpAndDown }
 Select the operating mode of the PWM wave counter. More...
 
enum  hal_pwm_short_mask_t {
  HAL_PWM_SHORT_SEQEND0_STOP_MASK = PWM_SHORTS_SEQEND0_STOP_Msk, HAL_PWM_SHORT_SEQEND1_STOP_MASK = PWM_SHORTS_SEQEND1_STOP_Msk, HAL_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK = PWM_SHORTS_LOOPSDONE_SEQSTART0_Msk, HAL_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK = PWM_SHORTS_LOOPSDONE_SEQSTART1_Msk,
  HAL_PWM_SHORT_LOOPSDONE_STOP_MASK = PWM_SHORTS_LOOPSDONE_STOP_Msk
}
 Bit masks for the PWM shortcuts. Or the appropriate ones for the required shortcuts. More...
 
enum  hal_pwm_decoder_load_t { HAL_PWM_LOAD_COMMON = PWM_DECODER_LOAD_Common, HAL_PWM_LOAD_GROUPED = PWM_DECODER_LOAD_Grouped, HAL_PWM_LOAD_INDIVIDUAL = PWM_DECODER_LOAD_Individual, HAL_PWM_LOAD_WAVE_FORM = PWM_DECODER_LOAD_WaveForm }
 PWM decoder's data load modes. This mode selects how the different channels' next value is loaded from the data read from the RAM. More...
 
enum  hal_pwm_dec_trigger_t { HAL_PWM_STEP_INTERNAL = PWM_DECODER_MODE_RefreshCount, HAL_PWM_STEP_EXTERNAL = PWM_DECODER_MODE_NextStep }
 PWM decoder's next load trigger modes. This selects when the next value is loaded from RAM. More...
 
enum  hal_pwm_irq_mask_t {
  HAL_PWM_IRQ_STOPPED_MASK = PWM_INTENSET_STOPPED_Msk, HAL_PWM_IRQ_SEQSTARTED0_MASK = PWM_INTENSET_SEQSTARTED0_Msk, HAL_PWM_IRQ_SEQSTARTED1_MASK = PWM_INTENSET_SEQSTARTED1_Msk, HAL_PWM_IRQ_SEQEND0_MASK = PWM_INTENSET_SEQEND0_Msk,
  HAL_PWM_IRQ_SEQEND1_MASK = PWM_INTENSET_SEQEND1_Msk, HAL_PWM_IRQ_PWMPERIODEND_MASK = PWM_INTENSET_PWMPERIODEND_Msk, HAL_PWM_IRQ_LOOPSDONE_MASK = PWM_INTENSET_LOOPSDONE_Msk
}
 PWM interrupts. More...
 

Functions

void hal_pwm_init (hal_pwm_init_t *init_config)
 Initialize the HAL PWM module. Can be called again to change the initialization configuration. More...
 
void hal_pwm_start (hal_pwm_start_t *start_config)
 Start the PWM generation based on the configuration provided. More...
 
void hal_pwm_stop (void)
 Stop the PWM generation.
 

Detailed Description

Macro Definition Documentation

◆ HAL_PWM_MAX_PIN_NUM

#define HAL_PWM_MAX_PIN_NUM   4

The maximum number of pins supported by this module

Definition at line 51 of file hal_pwm.h.

◆ PWM_USED

#define PWM_USED   HAL_PWM_PERIPH_USED

Specify which TWIM peripheral is used for this HAL module

Definition at line 48 of file hal_pwm.h.

Enumeration Type Documentation

◆ hal_pwm_dec_trigger_t

Enumerator
HAL_PWM_STEP_INTERNAL 

After the loaded value is repeated for the number of times in REFRESH register.

HAL_PWM_STEP_EXTERNAL 

When the Next Step task is set.

Definition at line 109 of file hal_pwm.h.

◆ hal_pwm_decoder_load_t

Enumerator
HAL_PWM_LOAD_COMMON 

A 16-bit value is used in all four (0-3) PWM channels.

HAL_PWM_LOAD_GROUPED 

1st 16-bit value used in channels 0 and 1; 2nd one in channels 2 and 3.

HAL_PWM_LOAD_INDIVIDUAL 

Each channel has its own 16 bit value.

HAL_PWM_LOAD_WAVE_FORM 

1st three channels have their own 16 bit values, 4th one is the wave counter.

Definition at line 95 of file hal_pwm.h.

◆ hal_pwm_freq_t

Enumerator
HAL_PWM_FREQ_8MHz 

16 MHz / 1 = 16 MHz.

HAL_PWM_FREQ_4MHz 

16 MHz / 2 = 8 MHz.

HAL_PWM_FREQ_2MHz 

16 MHz / 4 = 4 MHz.

HAL_PWM_FREQ_1MHz 

16 MHz / 8 = 2 MHz.

HAL_PWM_FREQ_500kHz 

16 MHz / 16 = 1 MHz.

HAL_PWM_FREQ_250kHz 

16 MHz / 32 = 500 kHz.

HAL_PWM_FREQ_125kHz 

16 MHz / 64 = 250 kHz.

Definition at line 54 of file hal_pwm.h.

◆ hal_pwm_irq_mask_t

Enumerator
HAL_PWM_IRQ_STOPPED_MASK 

Interrupt on STOPPED event.

HAL_PWM_IRQ_SEQSTARTED0_MASK 

Interrupt on SEQSTARTED[0] event.

HAL_PWM_IRQ_SEQSTARTED1_MASK 

Interrupt on SEQSTARTED[1] event.

HAL_PWM_IRQ_SEQEND0_MASK 

Interrupt on SEQEND[0] event.

HAL_PWM_IRQ_SEQEND1_MASK 

Interrupt on SEQEND[1] event.

HAL_PWM_IRQ_PWMPERIODEND_MASK 

Interrupt on PWMPERIODEND event.

HAL_PWM_IRQ_LOOPSDONE_MASK 

Interrupt on LOOPSDONE event.

Definition at line 142 of file hal_pwm.h.

◆ hal_pwm_mode_t

Enumerator
HAL_PWM_MODE_UP 

Up counter, reset to 0 on incrementing to CounterTop.

HAL_PWM_MODE_UP_DOWN 

Up & down counter, decrement back to 0 on reaching CounterTop.

Definition at line 67 of file hal_pwm.h.

◆ hal_pwm_short_mask_t

Enumerator
HAL_PWM_SHORT_SEQEND0_STOP_MASK 

Short between SEQEND[0] event and STOP task.

HAL_PWM_SHORT_SEQEND1_STOP_MASK 

Short between SEQEND[1] event and STOP task.

HAL_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK 

Short between LOOPSDONE event and SEQSTART[0] task.

HAL_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK 

Short between LOOPSDONE event and SEQSTART[1] task.

HAL_PWM_SHORT_LOOPSDONE_STOP_MASK 

Short between LOOPSDONE event and STOP task.

Definition at line 79 of file hal_pwm.h.

Function Documentation

◆ hal_pwm_init()

void hal_pwm_init ( hal_pwm_init_t init_config)
Parameters
init_configPointer to the configuration for the initialization

Definition at line 126 of file hal_pwm.c.

References ASSERT, HAL_PWM_MAX_PIN_NUM, and hal_pwm_init_t::pin_num.

◆ hal_pwm_start()

void hal_pwm_start ( hal_pwm_start_t start_config)