group::DAC

The DAC peripheral driver allows access to the MCU’s built-in DAC. More information about accessing peripheral IO is in the Device Interface section.

The following is an example of how to write the DAC in an OS environment:

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include "mcu/mcu.h"

int write_dac(dac_sample_t * src, int samples){
     int fd;
     dac_attr_t ctl;

     fd = open("/dev/dac0", O_RDWR);
     if ( fd < 0 ){
          printf("Error opening peripheral (%d)\n", errno);
     } else {
     ctl.enabled_channels = (1<<0); //enable channel zero
          ctl.freq = 20000; //20KHz output
          ctl.pin_assign = 0; //Use GPIO configuration zero (see device specific documentation for details)
          if( ioctl(fd, I_SETATTR, &ctl) < 0 ){
               printf("Failed to set peripheral configuration (%d)\n", errno);
               return -1;
     }

     //now write the samples of the DAC
     lseek(fd, 0, SEEK_SET); //this sets the channel to 0, 'c' device does not auto-increment on write
     if ( write(fd, src, sizeof(dac_sample_t)*samples) < 0 ){
          printf("Error writing peripheral (%d)\n", errno);
          return -1;
     }
     }
     close(fd);
     return 0;
}

Details

defineDAC_VERSION


defineDAC_IOC_IDENT_CHAR


defineI_DAC_GETVERSION


defineI_DAC_GETINFO

This requests reads the DAC attributes.

Example:

#include <dev/adc.h>
dac_info_t info;
int fd;
...
ioctl(fd, I_DAC_GETINFO, &info);

defineI_DAC_SETATTR

This requests writes the DAC attributes.

Example:

#include <dev/dac.h>
dac_attr_t attr;
int fd;
...
ioctl(fd, I_ADC_SETATTR, &attr);

defineI_DAC_SETACTION


defineI_DAC_GET

This IOCTL arg value causes the ioctl call to return the current output value of the DAC.

Example:

mcu_channel_t value;
value.channel = 0;
ioctl(dac_fd, I_DAC_GET, &value);

defineI_DAC_SET

This IOCTL arg value causes the ioctl call to set the output of the DAC

Example:

mcu_channel_t value;
value.channel = 0;
value.value = DAC_MAX / 2;
ioctl(dac_fd, I_DAC_SET, &value);

defineI_DAC_TOTAL


enumdac_flags

  • DAC_FLAG_NONE
  • DAC_FLAG_SET_CONVERTER
  • DAC_FLAG_IS_LEFT_JUSTIFIED
  • DAC_FLAG_IS_RIGHT_JUSTIFIED
  • DAC_FLAG_SET_CHANNELS
  • DAC_FLAG_IS_OUTPUT_BUFFERED
  • DAC_FLAG_IS_ON_CHIP
  • DAC_FLAG_IS_SAMPLE_AND_HOLD
  • DAC_FLAG_IS_TRIGGER_EINT
  • DAC_FLAG_IS_TRIGGER_EINT_RISING
  • DAC_FLAG_IS_TRIGGER_EINT_FALLING
  • DAC_FLAG_IS_TRIGGER_TMR


date: “2019-06-27” layout: post title: struct::dac_info_t katex: true

categories: struct

Methods

Details

public u32o_flags


public u32o_events


public u32freq


public u32maximum


public u32reference_mv


public u8resolution


public u8bytes_per_sample


public u16resd0


public u32resd



date: “2019-06-27” layout: post title: struct::dac_pin_assignment_t katex: true

categories: struct

Methods

Details

publicmcu_pin_tchannel



date: “2019-06-27” layout: post title: struct::dac_attr_t katex: true

categories: struct

Methods

Details

public u32o_flags


public dac_pin_assignment_tpin_assignment


public u32freq


publicmcu_pin_ttrigger

Pin or Timer trigger


public u8width


public u8channel


public u32resd


X

Thanks for Coming!

Subscribe to news and updates