HAL  v0.6.1
Hardware Abstraction Layer
Loading...
Searching...
No Matches
PWM

Pulse-Width Modulation. More...

Collaboration diagram for PWM:

Data Structures

struct  pwm_channel_attr_t
 

Macros

#define PWM_MIN_PCNT   (0.0f)
 
#define PWM_MAX_PCNT   (100.0f)
 

Enumerations

enum  pwm_result_t {
  PWM_RESULT_OK ,
  PWM_RESULT_INVALID ,
  PWM_RESULT_UNSUPPORTED ,
  PWM_RESULT_BUSY ,
  PWM_RESULT_ERR ,
  TOTAL_PWM_RESULT
}
 
enum  pwm_alignment_t {
  PWM_ALIGNMENT_EDGE ,
  PWM_ALIGNMENT_CENTER ,
  TOTAL_PWM_ALIGNMENT
}
 

Functions

pwm_result_t hal_pwm_init (const pwm_channel_attr_t attr)
 Configure PWM channel with specific attributes.
 
pwm_result_t hal_pwm_start (const gpio_pin_t pin)
 Start generate PWM pulses.
 
pwm_result_t hal_pwm_update (const gpio_pin_t pin, const float duty_cycle_pcnt)
 Update PWM duty cycles.
 
pwm_result_t hal_pwm_stop (const gpio_pin_t pin)
 Stop PWM operation.
 
pwm_result_t hal_pwm_mutex_take (const gpio_pin_t pin, const uint32_t timeout_ms)
 Try acquire RTOS mutex for specified pin.
 
pwm_result_t hal_pwm_mutex_give (const gpio_pin_t pin)
 Release RTOS mutex for specified pin.
 

Detailed Description

Pulse-Width Modulation.

Macro Definition Documentation

◆ PWM_MAX_PCNT

#define PWM_MAX_PCNT   (100.0f)

◆ PWM_MIN_PCNT

#define PWM_MIN_PCNT   (0.0f)

Enumeration Type Documentation

◆ pwm_alignment_t

#include <pwm/public_inc/hal_pwm.h>

Enumerator
PWM_ALIGNMENT_EDGE 
PWM_ALIGNMENT_CENTER 
TOTAL_PWM_ALIGNMENT 

◆ pwm_result_t

#include <pwm/public_inc/hal_pwm.h>

Enumerator
PWM_RESULT_OK 

No error.

PWM_RESULT_INVALID 

Operation invalid.

PWM_RESULT_UNSUPPORTED 

Operation not supported.

PWM_RESULT_BUSY 

Busy busy.

PWM_RESULT_ERR 

Error occurred.

TOTAL_PWM_RESULT 

Function Documentation

◆ hal_pwm_init()

pwm_result_t hal_pwm_init ( const pwm_channel_attr_t attr)

#include <pwm/public_inc/hal_pwm.h>

Configure PWM channel with specific attributes.

.pin = 13U;
.duty_cycle_pcnt = 10.5f,
.freq = 24000U,
.alignment = PWM_ALIGNMENT_EDGE,
};
pwm_result_t result = hal_pwm_init( attr );
pwm_result_t hal_pwm_init(const pwm_channel_attr_t attr)
Configure PWM channel with specific attributes.
pwm_result_t
Definition hal_pwm.h:45
@ PWM_ALIGNMENT_EDGE
Definition hal_pwm.h:57
Definition hal_pwm.h:64
gpio_pin_t pin
Definition hal_pwm.h:65
Parameters
[in]attrPWM channel attributes
Return values
PWM_RESULT_OKSuccess configure PWM channel
PWM_RESULT_INVALIDConfiguration attributes invalid
PWM_RESULT_UNSUPPORTEDOperation not supported
PWM_RESULT_ERRFailed configure PWM channel

◆ hal_pwm_mutex_give()

pwm_result_t hal_pwm_mutex_give ( const gpio_pin_t pin)

#include <pwm/public_inc/hal_pwm.h>

Release RTOS mutex for specified pin.

pwm_result_t hal_pwm_mutex_give(const gpio_pin_t pin)
Release RTOS mutex for specified pin.
Parameters
[in]pinPWM pin's mutex to be released
Return values
PWM_RESULT_OKSuccess release mutex
PWM_RESULT_INVALIDInvalid pin
PWM_RESULT_UNSUPPORTEDOperation not supported
PWM_RESULT_ERRFailed release mutex

◆ hal_pwm_mutex_take()

pwm_result_t hal_pwm_mutex_take ( const gpio_pin_t pin,
const uint32_t timeout_ms )

#include <pwm/public_inc/hal_pwm.h>

Try acquire RTOS mutex for specified pin.

pwm_result_t result = hal_pwm_mutex_take( 13U, 10U );
pwm_result_t hal_pwm_mutex_take(const gpio_pin_t pin, const uint32_t timeout_ms)
Try acquire RTOS mutex for specified pin.
Parameters
[in]pinPWM pin's mutex to be locked
[in]timeout_msMutex acquiring timeout in milliseconds
Return values
PWM_RESULT_OKSuccess acquire mutex
PWM_RESULT_INVALIDInvalid pin
PWM_RESULT_UNSUPPORTEDOperation not supported
PWM_RESULT_ERRFailed acquire mutex

◆ hal_pwm_start()

pwm_result_t hal_pwm_start ( const gpio_pin_t pin)

#include <pwm/public_inc/hal_pwm.h>

Start generate PWM pulses.

pwm_result_t result = hal_pwm_start( 13U );
pwm_result_t hal_pwm_start(const gpio_pin_t pin)
Start generate PWM pulses.
Parameters
[in]pinPWM pin
Return values
PWM_RESULT_OKSuccess start PWM
PWM_RESULT_ERRFailed to start PWM

◆ hal_pwm_stop()

pwm_result_t hal_pwm_stop ( const gpio_pin_t pin)

#include <pwm/public_inc/hal_pwm.h>

Stop PWM operation.

pwm_result_t result = hal_pwm_stop( 13U );
pwm_result_t hal_pwm_stop(const gpio_pin_t pin)
Stop PWM operation.
Parameters
[in]pinPWM pin
Return values
SPI_RESULT_OKSuccess stop PWM operation
SPI_RESULT_UNSUPPORTEDOperation not supported
SPI_RESULT_ERRFailed stop PWM operation

◆ hal_pwm_update()

pwm_result_t hal_pwm_update ( const gpio_pin_t pin,
const float duty_cycle_pcnt )

#include <pwm/public_inc/hal_pwm.h>

Update PWM duty cycles.

pwm_result_t result = hal_pwm_update( 13U, 50.2f );
pwm_result_t hal_pwm_update(const gpio_pin_t pin, const float duty_cycle_pcnt)
Update PWM duty cycles.
Parameters
[in]pinPWM pin
[in]duty_cycle_pcntPWM duty cycle in percent to be set
Return values
PWM_RESULT_OKSuccess update PWM duty cycle
PWM_RESULT_ERRFailed to update PWM duty cycle