libDaisy
Hardware Library for Daisy
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
daisy::PWMHandle Class Reference

Hardware PWM using the timer peripheral. More...

Detailed Description

Hardware PWM using the timer peripheral.

  • Supports the following TIM peripherals:
  • TIM3, TIM4, TIM5

A single TIM peripheral can be used to control up to four PWM output channels, which share the same resolution and frequency but have independent duty cycles.

Note that PWM interferes with the use of a TimerHandle on the same timer.

Some channels have the option to choose which output pin they connect to. Only one pin can be connected to a given channel. Use the following table to determine which pin corresponds to each timer and channel.

TIM3:

  • Channel 1: PA6 or PB4 (Daisy Seed – D19, D9; default PA6/D19)
  • Channel 2: PA7, PB5, or PC7 (D18, D10, internal LED; default PC7/LED)
  • Channel 3: PC8 (D4)
  • Channel 4: PB1 or PC9 (D17, D3; default PB1/D17)

TIM4:

TIM5:

Future work:

  • Support other timers, including HRTIM, TIM1, TIM8
  • DMA

#include <pwm.h>

Classes

class  Channel
 
struct  Config
 Configuration struct for the timer peripheral. More...
 

Public Types

enum class  Result { OK = 0 , ERR = 1 }
 Return values for PWM functions. More...
 

Public Member Functions

 PWMHandle ()
 
 PWMHandle (const PWMHandle &other)=default
 
PWMHandleoperator= (const PWMHandle &other)=default
 
 ~PWMHandle ()
 
Result Init (const Config &config)
 Initialize the PWM peripheral according to the config.
 
Result DeInit ()
 Deinitialize the peripheral.
 
const ConfigGetConfig () const
 Returns a const reference to the Config struct.
 
ChannelChannel1 ()
 Get a reference to CH1 of this peripheral. Must be initialized before use.
 
ChannelChannel2 ()
 Get a reference to CH2 of this peripheral. Must be initialized before use.
 
ChannelChannel3 ()
 Get a reference to CH3 of this peripheral. Must be initialized before use.
 
ChannelChannel4 ()
 Get a reference to CH4 of this peripheral. Must be initialized before use.
 
void SetPrescaler (uint32_t prescaler)
 Set the prescaler.
 
void SetPeriod (uint32_t period)
 Set the period.
 

Member Enumeration Documentation

◆ Result

enum class daisy::PWMHandle::Result
strong

Return values for PWM functions.

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ PWMHandle() [1/2]

daisy::PWMHandle::PWMHandle ( )

◆ PWMHandle() [2/2]

daisy::PWMHandle::PWMHandle ( const PWMHandle & other)
default

◆ ~PWMHandle()

daisy::PWMHandle::~PWMHandle ( )
inline

Member Function Documentation

◆ Channel1()

Channel & daisy::PWMHandle::Channel1 ( )
inline

Get a reference to CH1 of this peripheral. Must be initialized before use.

◆ Channel2()

Channel & daisy::PWMHandle::Channel2 ( )
inline

Get a reference to CH2 of this peripheral. Must be initialized before use.

◆ Channel3()

Channel & daisy::PWMHandle::Channel3 ( )
inline

Get a reference to CH3 of this peripheral. Must be initialized before use.

◆ Channel4()

Channel & daisy::PWMHandle::Channel4 ( )
inline

Get a reference to CH4 of this peripheral. Must be initialized before use.

◆ DeInit()

Result daisy::PWMHandle::DeInit ( )

Deinitialize the peripheral.

◆ GetConfig()

const Config & daisy::PWMHandle::GetConfig ( ) const

Returns a const reference to the Config struct.

◆ Init()

Result daisy::PWMHandle::Init ( const Config & config)

Initialize the PWM peripheral according to the config.

◆ operator=()

PWMHandle & daisy::PWMHandle::operator= ( const PWMHandle & other)
default

◆ SetPeriod()

void daisy::PWMHandle::SetPeriod ( uint32_t period)

Set the period.

◆ SetPrescaler()

void daisy::PWMHandle::SetPrescaler ( uint32_t prescaler)

Set the prescaler.


The documentation for this class was generated from the following file: