Blame view

RIOT/drivers/include/periph/dac.h 3.07 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  /*
   * Copyright (C) 2014 Simon Brummer
   *               2015-2016 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    drivers_periph_dac DAC
   * @ingroup     drivers_periph
   * @brief       DAC peripheral driver interface
   *
   * Similar to the ADC driver interface (@ref drivers_periph_adc), the DAC
   * interface uses the concept of lines, corresponds to a tuple of a DAC device
   * and a DAC output channel.
   *
   * The DAC interface expects data to be served as a 16-bit unsigned integer,
   * independent of the actual resolution of the hardware device. It is up to the
   * DAC driver, to scale the given value to the maximal width that can be
   * handled. The device driver should, on the other hand, implement the DAC in a
   * way, that it will use the bit width, that comes closest to 16-bit.
   *
   * This kind of 'auto-scaling' is quite sufficient for this interface, as
   * standard DAC peripherals use a fixed conversion resolution internally anyway,
   * so that any particular bit-width configuration on this driver level would not
   * have much effect...
   *
   * @{
   * @file
   * @brief       DAC peripheral driver interface definition
   *
   * @author      Simon Brummer <simon.brummer@haw-hamburg.de>
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   */
  
  #ifndef PERIPH_DAC_H
  #define PERIPH_DAC_H
  
  #include <stdint.h>
  #include <limits.h>
  
  #include "periph_cpu.h"
  #include "periph_conf.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   Define default DAC type identifier
   */
  #ifndef HAVE_DAC_T
  typedef unsigned int dac_t;
  #endif
  
  /**
   * @brief   Return codes used by the DAC driver interface
   */
  enum {
      DAC_OK     = 0,
      DAC_NOLINE = -1
  };
  
  /**
   * @brief   Default DAC undefined value
   */
  #ifndef DAC_UNDEF
  #define DAC_UNDEF           (UINT_MAX)
  #endif
  
  /**
   * @brief   Default DAC access macro
   */
  #ifndef DAC_LINE
  #define DAC_LINE(x)         (x)
  #endif
  
  /**
   * @brief   Initialize the given DAC line
   *
   * After initialization, the corresponding DAC line is active and its output is
   * set to 0.
   *
   * @param[in] line         DAC line to initialize
   *
   * @return  DAC_OK on success
   * @return  DAC_NOLINE on invalid DAC line
   */
  int8_t dac_init(dac_t line);
  
  /**
   * @brief   Write a value onto DAC Device on a given Channel
   *
   * The value is always given as 16-bit value and is internally scaled to the
   * actual resolution that the DAC unit provides (e.g. 12-bit). So to get the
   * maximum output voltage, this function has to be called with @p value set to
   * 65535 (UINT16_MAX).
   *
   * @param[in] line         DAC line to set
   * @param[in] value        value to set @p line to
   */
  void dac_set(dac_t line, uint16_t value);
  
  /**
   * @brief   Enable the given DAC line
   *
   * @param[in] line          DAC line to power on
   */
  void dac_poweron(dac_t line);
  
  /**
   * @brief   Disable the given DAC line
   *
   * @param[in] line          DAC line to power off
   */
  void dac_poweroff(dac_t line);
  
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* PERIPH_DAC_H */
  /** @} */