px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_dac.h
1#ifndef __PX_DAC_H__
2#define __PX_DAC_H__
3/* =============================================================================
4 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
5 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
6 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
7 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
8 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
9
10 Copyright (c) 2018 Pieter Conradie <https://piconomix.com>
11
12 License: MIT
13 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
14
15 Title: px_dac.h : DAC peripheral driver
16 Author(s): Pieter Conradie
17 Creation Date: 2018-11-15
18
19============================================================================= */
20
21/**
22 * @ingroup STM32
23 * @defgroup STM32_DAC px_dac.h : DAC peripheral driver
24 *
25 * Driver to output analogue values.
26 *
27 * File(s):
28 * - arch/arm/stm32/inc/px_dac.h
29 * - arch/arm/stm32/inc/px_dac_cfg_template.h
30 * - arch/arm/stm32/src/px_dac.c
31 *
32 * The driver must be configured by supplying a project specific "px_dac_cfg.h".
33 * "px_dac_cfg_template.h" can be copied, renamed and modified to supply
34 * compile time options.
35 *
36 * @par Example:
37 * @include arch/arm/stm32/test/px_dac_test.c
38 *
39 * @{
40 */
41
42/* _____STANDARD INCLUDES____________________________________________________ */
43
44/* _____PROJECT INCLUDES_____________________________________________________ */
45#include "px_defs.h"
46
47// Include project specific configuration. See "px_dac_cfg_template.h"
48#include "px_dac_cfg.h"
49
50// Check that all project specific options have been specified in "px_dac_cfg.h"
51#if ( !defined(PX_DAC_CFG_DAC1_EN ) \
52 || !defined(PX_DAC_CFG_DAC1_CH1_EN) \
53 || !defined(PX_DAC_CFG_DAC1_CH2_EN) )
54#error "One or more options not defined in 'px_dac_cfg.h'"
55#endif
56#if ( (PX_DAC_CFG_DAC1_EN > 1) \
57 ||(PX_DAC_CFG_DAC1_CH1_EN > 1) \
58 ||(PX_DAC_CFG_DAC1_CH2_EN > 1) )
59#error "PX_DAC_CFG_DACx_EN must be 0 or 1"
60#endif
61
62/// Number of enabled peripherals
63#define PX_DAC_CFG_PER_COUNT (PX_DAC_CFG_DAC1_EN)
64#if (PX_DAC_CFG_PER_COUNT == 0)
65#error "No peripherals enabled"
66#endif
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71/* _____DEFINITIONS__________________________________________________________ */
72/// Specify DAC peripheral
73typedef enum
74{
75 PX_DAC_NR_1 = 1,
77
78/// Specify DAC channel
79typedef enum
80{
81 PX_DAC_CHANNEL_1 = 0,
82 PX_DAC_CHANNEL_2 = 1,
84
85/// Define DAC handle
86typedef struct
87{
88 struct px_dac_per_s * dac_per; ///< DAC peripheral data
90
91/* _____TYPE DEFINITIONS_____________________________________________________ */
92
93/* _____GLOBAL VARIABLES_____________________________________________________ */
94
95/* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
96/**
97 * Initialise DAC driver.
98 */
99void px_dac_init(void);
100
101/**
102 * Open DAC peripheral using predefined (default) parameters.
103 *
104 * @param handle Pointer to handle data structure
105 * @param dac_nr DAC peripheral number
106 *
107 * @retval false Error: peripheral was not opened
108 * @retval true Success: peripheral was opened
109 */
110bool px_dac_open(px_dac_handle_t * handle,
111 px_dac_nr_t dac_nr);
112
113/**
114 * Close specified device.
115 *
116 * @param handle Pointer to handle data structure
117 *
118 * @retval true Success
119 * @retval false Specified device was already closed (or not opened)
120 */
121bool px_dac_close(px_dac_handle_t * handle);
122
123/**
124 * Perform a single output on the specified DAC channel
125 *
126 * @param handle Pointer to handle data structure
127 * @param channel DAC channel (1 or 2)
128 * @param data Data value to output
129 *
130 */
131void px_dac_wr(px_dac_handle_t * handle,
132 px_dac_channel_t channel,
133 uint16_t data);
134
135/* _____MACROS_______________________________________________________________ */
136
137#ifdef __cplusplus
138}
139#endif
140
141/// @}
142#endif
struct px_dac_per_s * dac_per
DAC peripheral data.
Definition: px_dac.h:88
bool px_dac_close(px_dac_handle_t *handle)
Close specified device.
Definition: px_dac.c:154
px_dac_channel_t
Specify DAC channel.
Definition: px_dac.h:80
void px_dac_wr(px_dac_handle_t *handle, px_dac_channel_t channel, uint16_t data)
Perform a single output on the specified DAC channel.
Definition: px_dac.c:211
void px_dac_init(void)
Initialise DAC driver.
Definition: px_dac.c:101
px_dac_nr_t
Specify DAC peripheral.
Definition: px_dac.h:74
bool px_dac_open(px_dac_handle_t *handle, px_dac_nr_t dac_nr)
Open DAC peripheral using predefined (default) parameters.
Definition: px_dac.c:109
Define DAC handle.
Definition: px_dac.h:87