Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
pwm.h File Reference

Go to the source code of this file.

Data Structures

struct  _PWM_PROPERTIES
struct  _PWM_DEVICE

Macros

#define PWM_NAME_PREFIX   "PWM"
 Name prefix for PWM Devices.
#define PWM_TYPE_NONE   0
#define PWM_TYPE_MAX   0
#define PWM_STATE_DISABLED   0
#define PWM_STATE_ENABLED   1
#define PWM_STATE_MAX   1
#define PWM_FLAG_NONE   0x00000000
#define PWM_FLAG_GPIO   0x00000001
 Device supports Get/Set GPIO.
#define PWM_FLAG_MODE   0x00000002
 Device supports Get/Set Mode.
#define PWM_FLAG_RANGE   0x00000004
 Device supports Get/Set Range.
#define PWM_FLAG_FREQUENCY   0x00000008
 Device supports Get/Set Frequency.
#define PWM_FLAG_POLARITY   0x00000010
 Device supports Get/Set Polarity.
#define PWM_MODE_MARKSPACE   0
 Standard PWM Mark / Space mode.
#define PWM_MODE_BALANCED   1
 Balanced mode (Device specific).
#define PWM_MODE_SERIALIZED   2
 Serialized mode (Device specific).
#define PWM_MODE_MAX   2
#define PWM_POLARITY_NORMAL   0
#define PWM_POLARITY_INVERSE   1
#define PWM_POLARITY_MAX   1

Typedefs

typedef struct _PWM_PROPERTIES PWM_PROPERTIES
typedef struct _PWM_DEVICE PWM_DEVICE
typedef uint32_t STDCALL(* pwm_enumerate_cb) (PWM_DEVICE *pwm, void *data)
typedef uint32_t STDCALL(* pwm_notification_cb) (DEVICE *device, void *data, uint32_t notification)
typedef uint32_t STDCALL(* pwm_device_start_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_stop_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_write_proc) (PWM_DEVICE *pwm, uint32_t value)
typedef uint32_t STDCALL(* pwm_device_get_gpio_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_set_gpio_proc) (PWM_DEVICE *pwm, uint32_t gpio)
typedef uint32_t STDCALL(* pwm_device_get_mode_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_set_mode_proc) (PWM_DEVICE *pwm, uint32_t mode)
typedef uint32_t STDCALL(* pwm_device_get_range_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_set_range_proc) (PWM_DEVICE *pwm, uint32_t range)
typedef uint32_t STDCALL(* pwm_device_get_frequency_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_set_frequency_proc) (PWM_DEVICE *pwm, uint32_t frequency)
typedef uint32_t STDCALL(* pwm_device_get_polarity_proc) (PWM_DEVICE *pwm)
typedef uint32_t STDCALL(* pwm_device_set_polarity_proc) (PWM_DEVICE *pwm, uint32_t polarity)
typedef uint32_t STDCALL(* pwm_device_configure_proc) (PWM_DEVICE *pwm, uint32_t dutyns, uint32_t periodns)
typedef uint32_t STDCALL(* pwm_device_get_properties_proc) (PWM_DEVICE *pwm, PWM_PROPERTIES *properties)

Functions

uint32_t STDCALL pwm_device_start (PWM_DEVICE *pwm)
 Start the specified PWM device.
uint32_t STDCALL pwm_device_stop (PWM_DEVICE *pwm)
 Stop the specified PWM device.
uint32_t STDCALL pwm_device_write (PWM_DEVICE *pwm, uint32_t value)
 Write a value to the specified PWM device.
uint32_t STDCALL pwm_device_get_gpio (PWM_DEVICE *pwm)
 Get the GPIO pin used by the specified PWM device.
uint32_t STDCALL pwm_device_set_gpio (PWM_DEVICE *pwm, uint32_t gpio)
 Set the GPIO pin used by the specified PWM device.
uint32_t STDCALL pwm_device_get_mode (PWM_DEVICE *pwm)
 Get the current mode of the specified PWM device.
uint32_t STDCALL pwm_device_set_mode (PWM_DEVICE *pwm, uint32_t mode)
 Set the current mode for the specified PWM device.
uint32_t STDCALL pwm_device_get_range (PWM_DEVICE *pwm)
 Get the current range of the specified PWM device.
uint32_t STDCALL pwm_device_set_range (PWM_DEVICE *pwm, uint32_t range)
 Set the current range for the specified PWM device.
uint32_t STDCALL pwm_device_get_frequency (PWM_DEVICE *pwm)
 Get the clock frequency of the specified PWM device.
uint32_t STDCALL pwm_device_set_frequency (PWM_DEVICE *pwm, uint32_t frequency)
 Set the clock frequency for the specified PWM device.
uint32_t STDCALL pwm_device_get_polarity (PWM_DEVICE *pwm)
 Get the current polarity of the specified PWM device.
uint32_t STDCALL pwm_device_set_polarity (PWM_DEVICE *pwm, uint32_t polarity)
 Set the current polarity for the specified PWM device.
uint32_t STDCALL pwm_device_configure (PWM_DEVICE *pwm, uint32_t dutyns, uint32_t periodns)
 Set the configuration of the specified PWM device.
uint32_t STDCALL pwm_device_properties (PWM_DEVICE *pwm, PWM_PROPERTIES *properties)
 Get the properties for the specified PWM device.
uint32_t STDCALL pwm_device_get_properties (PWM_DEVICE *pwm, PWM_PROPERTIES *properties)
 Get the properties for the specified PWM device.
PWM_DEVICE *STDCALL pwm_device_create (void)
 Create a new PWM entry.
PWM_DEVICE *STDCALL pwm_device_create_ex (uint32_t size)
 Create a new PWM entry.
uint32_t STDCALL pwm_device_destroy (PWM_DEVICE *pwm)
 Destroy an existing PWM entry.
uint32_t STDCALL pwm_device_register (PWM_DEVICE *pwm)
 Register a new PWM in the PWM table.
uint32_t STDCALL pwm_device_deregister (PWM_DEVICE *pwm)
 Deregister a PWM from the PWM table.
PWM_DEVICE *STDCALL pwm_device_find (uint32_t pwmid)
PWM_DEVICE *STDCALL pwm_device_find_by_name (const char *name)
PWM_DEVICE *STDCALL pwm_device_find_by_description (const char *description)
uint32_t STDCALL pwm_device_enumerate (pwm_enumerate_cb callback, void *data)
uint32_t STDCALL pwm_device_notification (PWM_DEVICE *pwm, pwm_notification_cb callback, void *data, uint32_t notification, uint32_t flags)
uint32_t STDCALL pwm_get_count (void)
 Get the current PWM count.
PWM_DEVICE *STDCALL pwm_device_get_default (void)
 Get the current default PWM device.
uint32_t STDCALL pwm_device_set_default (PWM_DEVICE *pwm)
 Set the current default PWM device.
PWM_DEVICE *STDCALL pwm_device_check (PWM_DEVICE *pwm)
 Check if the supplied PWM is in the PWM table.
uint32_t STDCALL pwm_type_to_string (uint32_t pwmtype, char *string, uint32_t len)
 Convert a PWM type value to a string.
uint32_t STDCALL pwm_state_to_string (uint32_t pwmstate, char *string, uint32_t len)
 Convert a PWM state value to a string.
uint32_t STDCALL pwm_mode_to_string (uint32_t pwmmode, char *string, uint32_t len)
 Convert a PWM mode value to a string.
uint32_t STDCALL pwm_polarity_to_string (uint32_t pwmpolarity, char *string, uint32_t len)
 Convert a PWM polarity value to a string.

Macro Definition Documentation

◆ PWM_NAME_PREFIX

#define PWM_NAME_PREFIX   "PWM"

Name prefix for PWM Devices.

PWM specific constants

◆ PWM_TYPE_NONE

#define PWM_TYPE_NONE   0

PWM Device Types

◆ PWM_TYPE_MAX

#define PWM_TYPE_MAX   0

◆ PWM_STATE_DISABLED

#define PWM_STATE_DISABLED   0

PWM Device States

◆ PWM_STATE_ENABLED

#define PWM_STATE_ENABLED   1

◆ PWM_STATE_MAX

#define PWM_STATE_MAX   1

◆ PWM_FLAG_NONE

#define PWM_FLAG_NONE   0x00000000

PWM Device Flags

◆ PWM_FLAG_GPIO

#define PWM_FLAG_GPIO   0x00000001

Device supports Get/Set GPIO.

◆ PWM_FLAG_MODE

#define PWM_FLAG_MODE   0x00000002

Device supports Get/Set Mode.

◆ PWM_FLAG_RANGE

#define PWM_FLAG_RANGE   0x00000004

Device supports Get/Set Range.

◆ PWM_FLAG_FREQUENCY

#define PWM_FLAG_FREQUENCY   0x00000008

Device supports Get/Set Frequency.

◆ PWM_FLAG_POLARITY

#define PWM_FLAG_POLARITY   0x00000010

Device supports Get/Set Polarity.

◆ PWM_MODE_MARKSPACE

#define PWM_MODE_MARKSPACE   0

Standard PWM Mark / Space mode.

PWM Mode Values

◆ PWM_MODE_BALANCED

#define PWM_MODE_BALANCED   1

Balanced mode (Device specific).

◆ PWM_MODE_SERIALIZED

#define PWM_MODE_SERIALIZED   2

Serialized mode (Device specific).

◆ PWM_MODE_MAX

#define PWM_MODE_MAX   2

◆ PWM_POLARITY_NORMAL

#define PWM_POLARITY_NORMAL   0

PWM Polarity Values

◆ PWM_POLARITY_INVERSE

#define PWM_POLARITY_INVERSE   1

◆ PWM_POLARITY_MAX

#define PWM_POLARITY_MAX   1

Typedef Documentation

◆ PWM_PROPERTIES

PWM specific types PWM Properties

◆ PWM_DEVICE

typedef struct _PWM_DEVICE PWM_DEVICE

PWM Device

◆ pwm_enumerate_cb

typedef uint32_t STDCALL(* pwm_enumerate_cb) (PWM_DEVICE *pwm, void *data)

PWM Enumeration Callback

◆ pwm_notification_cb

typedef uint32_t STDCALL(* pwm_notification_cb) (DEVICE *device, void *data, uint32_t notification)

PWM Notification Callback

◆ pwm_device_start_proc

typedef uint32_t STDCALL(* pwm_device_start_proc) (PWM_DEVICE *pwm)

PWM Device Methods

◆ pwm_device_stop_proc

typedef uint32_t STDCALL(* pwm_device_stop_proc) (PWM_DEVICE *pwm)

◆ pwm_device_write_proc

typedef uint32_t STDCALL(* pwm_device_write_proc) (PWM_DEVICE *pwm, uint32_t value)

◆ pwm_device_get_gpio_proc

typedef uint32_t STDCALL(* pwm_device_get_gpio_proc) (PWM_DEVICE *pwm)

◆ pwm_device_set_gpio_proc

typedef uint32_t STDCALL(* pwm_device_set_gpio_proc) (PWM_DEVICE *pwm, uint32_t gpio)

◆ pwm_device_get_mode_proc

typedef uint32_t STDCALL(* pwm_device_get_mode_proc) (PWM_DEVICE *pwm)

◆ pwm_device_set_mode_proc

typedef uint32_t STDCALL(* pwm_device_set_mode_proc) (PWM_DEVICE *pwm, uint32_t mode)

◆ pwm_device_get_range_proc

typedef uint32_t STDCALL(* pwm_device_get_range_proc) (PWM_DEVICE *pwm)

◆ pwm_device_set_range_proc

typedef uint32_t STDCALL(* pwm_device_set_range_proc) (PWM_DEVICE *pwm, uint32_t range)

◆ pwm_device_get_frequency_proc

typedef uint32_t STDCALL(* pwm_device_get_frequency_proc) (PWM_DEVICE *pwm)

◆ pwm_device_set_frequency_proc

typedef uint32_t STDCALL(* pwm_device_set_frequency_proc) (PWM_DEVICE *pwm, uint32_t frequency)

◆ pwm_device_get_polarity_proc

typedef uint32_t STDCALL(* pwm_device_get_polarity_proc) (PWM_DEVICE *pwm)

◆ pwm_device_set_polarity_proc

typedef uint32_t STDCALL(* pwm_device_set_polarity_proc) (PWM_DEVICE *pwm, uint32_t polarity)

◆ pwm_device_configure_proc

typedef uint32_t STDCALL(* pwm_device_configure_proc) (PWM_DEVICE *pwm, uint32_t dutyns, uint32_t periodns)

◆ pwm_device_get_properties_proc

typedef uint32_t STDCALL(* pwm_device_get_properties_proc) (PWM_DEVICE *pwm, PWM_PROPERTIES *properties)

Function Documentation

◆ pwm_device_start()

uint32_t STDCALL pwm_device_start ( PWM_DEVICE * pwm)

Start the specified PWM device.

PWM Functions

Parameters
PWMThe PWM device to start
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_stop()

uint32_t STDCALL pwm_device_stop ( PWM_DEVICE * pwm)

Stop the specified PWM device.

Parameters
PWMThe PWM device to stop
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_write()

uint32_t STDCALL pwm_device_write ( PWM_DEVICE * pwm,
uint32_t value )

Write a value to the specified PWM device.

Parameters
PWMThe PWM device to write to
ValueThe value to write
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
The exact meaning of value may depend on the device and other configured options, in many cases the value will represent the "on" time of each pulse with regard to the duty cycle of the waveform output by the device

◆ pwm_device_get_gpio()

uint32_t STDCALL pwm_device_get_gpio ( PWM_DEVICE * pwm)

Get the GPIO pin used by the specified PWM device.

Parameters
PWMThe PWM device to get the GPIO pin from
Returns
The current GPIO pin or GPIO_PIN_UNKNOWN on failure

◆ pwm_device_set_gpio()

uint32_t STDCALL pwm_device_set_gpio ( PWM_DEVICE * pwm,
uint32_t gpio )

Set the GPIO pin used by the specified PWM device.

Parameters
PWMThe PWM device to set the GPIO pin for
GPIOThe GPIO pin to set (eg GPIO_PIN_12)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_get_mode()

uint32_t STDCALL pwm_device_get_mode ( PWM_DEVICE * pwm)

Get the current mode of the specified PWM device.

Parameters
PWMThe PWM device to get the mode from
Returns
The current mode or a default value of PWM_MODE_MARKSPACE

◆ pwm_device_set_mode()

uint32_t STDCALL pwm_device_set_mode ( PWM_DEVICE * pwm,
uint32_t mode )

Set the current mode for the specified PWM device.

Parameters
PWMThe PWM device to set the mode for
ModeThe mode value to set (eg PWM_MODE_MARKSPACE)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_get_range()

uint32_t STDCALL pwm_device_get_range ( PWM_DEVICE * pwm)

Get the current range of the specified PWM device.

Parameters
PWMThe PWM device to get the range from
Returns
The current range or 0 on failure

◆ pwm_device_set_range()

uint32_t STDCALL pwm_device_set_range ( PWM_DEVICE * pwm,
uint32_t range )

Set the current range for the specified PWM device.

Parameters
PWMThe PWM device to set the clock rate for
RangeThe range value to set
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
The exact meaning of range may depend on the device and other configured options, in many cases the range will represent the period of one full cycle of the waveform output by the device

◆ pwm_device_get_frequency()

uint32_t STDCALL pwm_device_get_frequency ( PWM_DEVICE * pwm)

Get the clock frequency of the specified PWM device.

Parameters
PWMThe PWM device to get the clock frequency from
Returns
The clock frequency in Hz or 0 on failure

◆ pwm_device_set_frequency()

uint32_t STDCALL pwm_device_set_frequency ( PWM_DEVICE * pwm,
uint32_t frequency )

Set the clock frequency for the specified PWM device.

Parameters
PWMThe PWM device to set the clock frequency for
FrequencyThe clock frequency to set in Hz
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_get_polarity()

uint32_t STDCALL pwm_device_get_polarity ( PWM_DEVICE * pwm)

Get the current polarity of the specified PWM device.

Parameters
PWMThe PWM device to get the polarity from
Returns
The current polarity or a default value of PWM_POLARITY_NORMAL

◆ pwm_device_set_polarity()

uint32_t STDCALL pwm_device_set_polarity ( PWM_DEVICE * pwm,
uint32_t polarity )

Set the current polarity for the specified PWM device.

Parameters
PWMThe PWM device to set the polarity for
PolarityThe polarity value to set (eg PWM_POLARITY_NORMAL)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_configure()

uint32_t STDCALL pwm_device_configure ( PWM_DEVICE * pwm,
uint32_t dutyns,
uint32_t periodns )

Set the configuration of the specified PWM device.

Parameters
PWMThe PWM device to set the configuration for
DutyNSThe "on" time part of the cycle (Nanoseconds)
PeriodNSThe duration of one full cycle (Nanoseconds)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_properties()

uint32_t STDCALL pwm_device_properties ( PWM_DEVICE * pwm,
PWM_PROPERTIES * properties )

Get the properties for the specified PWM device.

Parameters
PWMThe PWM device to get properties from
PropertiesPointer to a TPWMProperties structure to fill in
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Replaced by PWMDeviceGetProperties for consistency

◆ pwm_device_get_properties()

uint32_t STDCALL pwm_device_get_properties ( PWM_DEVICE * pwm,
PWM_PROPERTIES * properties )

Get the properties for the specified PWM device.

Parameters
PWMThe PWM device to get properties from
PropertiesPointer to a TPWMProperties structure to fill in
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ pwm_device_create()

PWM_DEVICE *STDCALL pwm_device_create ( void )

Create a new PWM entry.

Returns
Pointer to new PWM entry or nil if PWM could not be created

◆ pwm_device_create_ex()

PWM_DEVICE *STDCALL pwm_device_create_ex ( uint32_t size)

Create a new PWM entry.

Parameters
SizeSize in bytes to allocate for new PWM (Including the PWM entry)
Returns
Pointer to new PWM entry or nil if PWM could not be created

◆ pwm_device_destroy()

uint32_t STDCALL pwm_device_destroy ( PWM_DEVICE * pwm)

Destroy an existing PWM entry.

◆ pwm_device_register()

uint32_t STDCALL pwm_device_register ( PWM_DEVICE * pwm)

Register a new PWM in the PWM table.

◆ pwm_device_deregister()

uint32_t STDCALL pwm_device_deregister ( PWM_DEVICE * pwm)

Deregister a PWM from the PWM table.

◆ pwm_device_find()

PWM_DEVICE *STDCALL pwm_device_find ( uint32_t pwmid)

◆ pwm_device_find_by_name()

PWM_DEVICE *STDCALL pwm_device_find_by_name ( const char * name)

◆ pwm_device_find_by_description()

PWM_DEVICE *STDCALL pwm_device_find_by_description ( const char * description)

◆ pwm_device_enumerate()

uint32_t STDCALL pwm_device_enumerate ( pwm_enumerate_cb callback,
void * data )

◆ pwm_device_notification()

uint32_t STDCALL pwm_device_notification ( PWM_DEVICE * pwm,
pwm_notification_cb callback,
void * data,
uint32_t notification,
uint32_t flags )

◆ pwm_get_count()

uint32_t STDCALL pwm_get_count ( void )

Get the current PWM count.

PWM Helper Functions

◆ pwm_device_get_default()

PWM_DEVICE *STDCALL pwm_device_get_default ( void )

Get the current default PWM device.

◆ pwm_device_set_default()

uint32_t STDCALL pwm_device_set_default ( PWM_DEVICE * pwm)

Set the current default PWM device.

◆ pwm_device_check()

PWM_DEVICE *STDCALL pwm_device_check ( PWM_DEVICE * pwm)

Check if the supplied PWM is in the PWM table.

◆ pwm_type_to_string()

uint32_t STDCALL pwm_type_to_string ( uint32_t pwmtype,
char * string,
uint32_t len )

Convert a PWM type value to a string.

◆ pwm_state_to_string()

uint32_t STDCALL pwm_state_to_string ( uint32_t pwmstate,
char * string,
uint32_t len )

Convert a PWM state value to a string.

◆ pwm_mode_to_string()

uint32_t STDCALL pwm_mode_to_string ( uint32_t pwmmode,
char * string,
uint32_t len )

Convert a PWM mode value to a string.

◆ pwm_polarity_to_string()

uint32_t STDCALL pwm_polarity_to_string ( uint32_t pwmpolarity,
char * string,
uint32_t len )

Convert a PWM polarity value to a string.