Microchip® Advanced Software Framework

pwm_dac.c File Reference
#include <stddef.h>
#include "compiler.h"
#include "pwm_dac.h"
#include <avr32/io.h>
#include "intc.h"
#include "gpio.h"
#include "audio.h"

Macros

#define PWM_DAC_PWM_CHANNEL_LSB   6
 Least significant 8-bit PWM channel. More...
 
#define PWM_DAC_PWM_CHANNEL_LSB_PIN   _0
 Least significant 8-bit PWM channel pin. More...
 
#define PWM_DAC_PWM_CHANNEL_MSB   4
 Most significant 8-bit PWM channel. More...
 
#define PWM_DAC_PWM_CHANNEL_MSB_PIN   _1
 Most significant 8-bit PWM channel pin. More...
 

Functions

void pwm_dac_decrease_volume (void)
 Decreases the output volume of the DAC. More...
 
void pwm_dac_flush (void)
 Flushes the sample buffer being output to the DAC. More...
 
static __inline__ size_t pwm_dac_get_log2_aligned_byte_size (size_t bit_size)
 Returns the logarithm to base 2 of the aligned byte size required to store the bit_size bit size saturated to the range [|8, 32|]. More...
 
static int16_t pwm_dac_get_sample_16_bits (void)
 Generates a 16-bit sample from a sample stored in 16 bits. More...
 
static int16_t pwm_dac_get_sample_32_bits (void)
 Generates a 16-bit sample from a sample stored in 32 bits. More...
 
static int16_t pwm_dac_get_sample_8_bits (void)
 Generates a 16-bit sample from a sample stored in 8 bits. More...
 
uint8_t pwm_dac_get_volume (void)
 Return the current volume. More...
 
void pwm_dac_increase_volume (void)
 Increases the output volume of the DAC. More...
 
bool pwm_dac_is_volume_boosted (void)
 Returns the state of the boost mode of the DAC. More...
 
bool pwm_dac_is_volume_muted (void)
 Returns the state of the mute mode of the DAC. More...
 
void pwm_dac_mute (bool mute)
 Mute audio if mute set to true. More...
 
bool pwm_dac_output (void *sample_buffer, size_t sample_length)
 Outputs a sample buffer to the DAC. More...
 
static __inline__ void pwm_dac_output_sample (int16_t sample)
 Outputs a sample to the DAC. More...
 
static void pwm_dac_pwm_int_handler (void)
 PWM interrupt handler managing the DAC. More...
 
void pwm_dac_set_volume (uint8_t volume)
 Set the current volume. More...
 
void pwm_dac_setup (uint32_t sample_rate_hz, uint8_t num_channels, uint8_t bits_per_sample, bool swap_channels, void(*callback)(uint32_t arg), uint32_t callback_opt, uint32_t pba_hz)
 Sets the DAC up with new settings. More...
 
void pwm_dac_start (uint32_t sample_rate_hz, uint8_t num_channels, uint8_t bits_per_sample, bool swap_channels, void(*callback)(uint32_t arg), uint32_t callback_opt, uint32_t pba_hz)
 Starts the DAC. More...
 
void pwm_dac_stop (void)
 Stops the DAC. More...
 

Variables

static int16_t(*const PWM_DAC_GET_SAMPLE [])(void)
 Table of pointers to the functions generating 16-bit samples from stored samples. More...
 
struct {
   uint8_t   bits_per_sample
 
   void(*   callback )(uint32_t arg)
 
   uint32_t   callback_opt
 
   bool   flushing
 
   int16_t(*   get_sample )(void)
 
   uint8_t   num_channels
 
   volatile UnionPtr   reload_sample_buffer
 
   volatile size_t   reload_sample_length
 
   volatile UnionPtr   sample_buffer
 
   volatile size_t   sample_length
 
   bool   swap_channels
 
   uint8_t   volume_shift
 
pwm_dac_output_params
 Output parameters. More...
 
static const gpio_map_t PWM_DAC_PWM_GPIO_MAP
 Map of the PWM pins used by the PWM DAC. More...
 

#define PWM_DAC_PWM_CHANNEL_LSB   6
#define PWM_DAC_PWM_CHANNEL_LSB_PIN   _0

Least significant 8-bit PWM channel pin.

#define PWM_DAC_PWM_CHANNEL_MSB   4
#define PWM_DAC_PWM_CHANNEL_MSB_PIN   _1

Most significant 8-bit PWM channel pin.

static __inline__ size_t pwm_dac_get_log2_aligned_byte_size ( size_t  bit_size)
static

Returns the logarithm to base 2 of the aligned byte size required to store the bit_size bit size saturated to the range [|8, 32|].

References clz, max, and min.

Referenced by pwm_dac_output(), and pwm_dac_setup().

static int16_t pwm_dac_get_sample_16_bits ( void  )
static

Generates a 16-bit sample from a sample stored in 16 bits.

References pwm_dac_output_params.

static int16_t pwm_dac_get_sample_32_bits ( void  )
static

Generates a 16-bit sample from a sample stored in 32 bits.

References pwm_dac_output_params.

static int16_t pwm_dac_get_sample_8_bits ( void  )
static

Generates a 16-bit sample from a sample stored in 8 bits.

References pwm_dac_output_params.

static __inline__ void pwm_dac_output_sample ( int16_t  sample)
static

Outputs a sample to the DAC.

References PWM_DAC_PWM_CHANNEL_LSB, and PWM_DAC_PWM_CHANNEL_MSB.

Referenced by pwm_dac_flush(), pwm_dac_pwm_int_handler(), and pwm_dac_start().

static void pwm_dac_pwm_int_handler ( void  )
static

void(* callback)(uint32_t arg)
uint32_t callback_opt
bool flushing
int16_t(* get_sample)(void)

Referenced by dac_pwm_int_handler(), and main().

uint8_t num_channels
int16_t(*const PWM_DAC_GET_SAMPLE[])(void)
static
Initial value:
=
{
}
static int16_t pwm_dac_get_sample_8_bits(void)
Generates a 16-bit sample from a sample stored in 8 bits.
Definition: pwm_dac.c:120
static int16_t pwm_dac_get_sample_16_bits(void)
Generates a 16-bit sample from a sample stored in 16 bits.
Definition: pwm_dac.c:133
static int16_t pwm_dac_get_sample_32_bits(void)
Generates a 16-bit sample from a sample stored in 32 bits.
Definition: pwm_dac.c:146

Table of pointers to the functions generating 16-bit samples from stored samples.

Referenced by pwm_dac_setup().

struct { ... } pwm_dac_output_params
Initial value:
=
{
.num_channels = 0,
.bits_per_sample = 0,
.swap_channels = false,
.callback = NULL,
.callback_opt = 0,
.get_sample = NULL,
.sample_buffer = {NULL},
.sample_length = 0,
.reload_sample_buffer = {NULL},
.reload_sample_length = 0,
.volume_shift = 0,
.flushing = false
}
#define NULL
Definition: lwip-1.4.1/src/include/lwip/def.h:47

Output parameters.

Referenced by pwm_dac_decrease_volume(), pwm_dac_flush(), pwm_dac_get_sample_16_bits(), pwm_dac_get_sample_32_bits(), pwm_dac_get_sample_8_bits(), pwm_dac_get_volume(), pwm_dac_increase_volume(), pwm_dac_output(), pwm_dac_pwm_int_handler(), pwm_dac_set_volume(), pwm_dac_setup(), and pwm_dac_stop().

const gpio_map_t PWM_DAC_PWM_GPIO_MAP
static
Initial value:
=
{
}
#define PWM_DAC_PWM_CHANNEL_MSB
Most significant 8-bit PWM channel.
Definition: pwm_dac.c:61
#define PWM_DAC_PWM_CHANNEL_LSB_PIN
Least significant 8-bit PWM channel pin.
Definition: pwm_dac.c:57
#define ATPASTE4(a, b, c, d)
Definition: tpaste.h:84
#define PWM_DAC_PWM_CHANNEL_MSB_PIN
Most significant 8-bit PWM channel pin.
Definition: pwm_dac.c:65
#define PWM_DAC_PWM_CHANNEL_LSB
Least significant 8-bit PWM channel.
Definition: pwm_dac.c:53

Map of the PWM pins used by the PWM DAC.

volatile UnionPtr reload_sample_buffer
volatile size_t reload_sample_length
volatile size_t sample_length
uint8_t volume_shift