Skip to content

Commit 16fc045

Browse files
committed
atmel-samd: Add direct write access to the DAC output.
1 parent 259ae8a commit 16fc045

File tree

12 files changed

+3883
-1
lines changed

12 files changed

+3883
-1
lines changed

atmel-samd/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ INC += $(addprefix -Iasf/sam0/,\
4848
drivers/port \
4949
drivers/system \
5050
drivers/adc/adc_sam_d_r \
51+
drivers/dac \
52+
drivers/dac/dac_sam_d_c \
5153
drivers/system/clock \
5254
drivers/system/clock/clock_samd21_r21_da \
5355
drivers/system/interrupt \
@@ -93,12 +95,13 @@ endif
9395

9496

9597
SRC_ASF = $(addprefix asf/sam0/,\
98+
drivers/adc/adc_sam_d_r/adc.c \
99+
drivers/dac/dac_sam_d_c/dac.c \
96100
drivers/port/port.c \
97101
drivers/sercom/sercom.c \
98102
drivers/sercom/sercom_interrupt.c \
99103
drivers/sercom/usart/usart.c \
100104
drivers/sercom/usart/usart_interrupt.c \
101-
drivers/adc/adc_sam_d_r/adc.c \
102105
drivers/system/clock/clock_samd21_r21_da/clock.c \
103106
drivers/system/clock/clock_samd21_r21_da/gclk.c \
104107
drivers/system/interrupt/system_interrupt.c \
@@ -114,6 +117,7 @@ SRC_C = \
114117
main.c \
115118
modmachine.c \
116119
modutime.c \
120+
mpdac.c \
117121
mphalport.c \
118122
pin.c \
119123
pin_named_pins.c \

atmel-samd/asf/sam0/drivers/dac/dac.h

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* \file
3+
*
4+
* \brief SAM Peripheral Digital-to-Analog Converter Driver
5+
*
6+
* Copyright (C) 2012-2015 Atmel Corporation. All rights reserved.
7+
*
8+
* \asf_license_start
9+
*
10+
* \page License
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
*
18+
* 2. Redistributions in binary form must reproduce the above copyright notice,
19+
* this list of conditions and the following disclaimer in the documentation
20+
* and/or other materials provided with the distribution.
21+
*
22+
* 3. The name of Atmel may not be used to endorse or promote products derived
23+
* from this software without specific prior written permission.
24+
*
25+
* 4. This software may only be redistributed and used in connection with an
26+
* Atmel microcontroller product.
27+
*
28+
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31+
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38+
* POSSIBILITY OF SUCH DAMAGE.
39+
*
40+
* \asf_license_stop
41+
*
42+
*/
43+
/*
44+
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45+
*/
46+
#ifndef DAC_H_INCLUDED
47+
#define DAC_H_INCLUDED
48+
49+
50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
53+
54+
#include <compiler.h>
55+
#include <clock.h>
56+
#include <gclk.h>
57+
58+
/**
59+
* \addtogroup asfdoc_sam0_dac_group
60+
*
61+
* @{
62+
*/
63+
64+
/**
65+
* Define DAC features set according to different device families.
66+
* @{
67+
*/
68+
#if (SAMD21 || SAMD10 || SAMD11 || SAMDA1)
69+
# define FEATURE_DAC_DATABUF_WRITE_PROTECTION
70+
#endif
71+
/**@}*/
72+
73+
#ifndef DAC_TIMEOUT
74+
# define DAC_TIMEOUT 0xFFFF
75+
#endif
76+
77+
#if DAC_CALLBACK_MODE == true
78+
# include <system_interrupt.h>
79+
80+
/** Forward definition of the device instance. */
81+
struct dac_module;
82+
83+
#if !defined(__DOXYGEN__)
84+
extern struct dac_module *_dac_instances[DAC_INST_NUM];
85+
#endif
86+
87+
/** Type definition for a DAC module callback function. */
88+
typedef void (*dac_callback_t)(uint8_t channel);
89+
90+
/** Enum for the possible callback types for the DAC module. */
91+
enum dac_callback {
92+
/** Callback type for when a DAC channel data empty condition occurs
93+
* (requires event triggered mode) */
94+
DAC_CALLBACK_DATA_EMPTY,
95+
96+
/** Callback type for when a DAC channel data underrun condition occurs
97+
* (requires event triggered mode) */
98+
DAC_CALLBACK_DATA_UNDERRUN,
99+
100+
/** Callback type for when a DAC channel write buffer job complete (requires
101+
* event triggered mode) */
102+
DAC_CALLBACK_TRANSFER_COMPLETE,
103+
#if !defined(__DOXYGEN__)
104+
DAC_CALLBACK_N,
105+
#endif
106+
};
107+
108+
#endif
109+
110+
#include <dac_feature.h>
111+
112+
/**
113+
* \name Configuration and Initialization
114+
* @{
115+
*/
116+
117+
bool dac_is_syncing(
118+
struct dac_module *const dev_inst);
119+
120+
void dac_get_config_defaults(
121+
struct dac_config *const config);
122+
123+
enum status_code dac_init(
124+
struct dac_module *const dev_inst,
125+
Dac *const module,
126+
struct dac_config *const config);
127+
128+
void dac_reset(
129+
struct dac_module *const dev_inst);
130+
131+
void dac_enable(
132+
struct dac_module *const dev_inst);
133+
134+
void dac_disable(
135+
struct dac_module *const dev_inst);
136+
137+
void dac_enable_events(
138+
struct dac_module *const module_inst,
139+
struct dac_events *const events);
140+
141+
void dac_disable_events(
142+
struct dac_module *const module_inst,
143+
struct dac_events *const events);
144+
145+
/** @} */
146+
147+
/**
148+
* \name Configuration and Initialization (Channel)
149+
* @{
150+
*/
151+
152+
void dac_chan_get_config_defaults(
153+
struct dac_chan_config *const config);
154+
155+
void dac_chan_set_config(
156+
struct dac_module *const dev_inst,
157+
const enum dac_channel channel,
158+
struct dac_chan_config *const config);
159+
160+
void dac_chan_enable(
161+
struct dac_module *const dev_inst,
162+
enum dac_channel channel);
163+
164+
void dac_chan_disable(
165+
struct dac_module *const dev_inst,
166+
enum dac_channel channel);
167+
168+
/** @} */
169+
170+
/**
171+
* \name Channel Data Management
172+
* @{
173+
*/
174+
175+
enum status_code dac_chan_write(
176+
struct dac_module *const dev_inst,
177+
enum dac_channel channel,
178+
const uint16_t data);
179+
180+
enum status_code dac_chan_write_buffer_wait(
181+
struct dac_module *const module_inst,
182+
enum dac_channel channel,
183+
uint16_t *buffer,
184+
uint32_t length);
185+
186+
/** @} */
187+
188+
/**
189+
* \name Status Management
190+
* @{
191+
*/
192+
uint32_t dac_get_status(
193+
struct dac_module *const module_inst);
194+
void dac_clear_status(
195+
struct dac_module *const module_inst,
196+
uint32_t status_flags);
197+
198+
/** @} */
199+
200+
#ifdef __cplusplus
201+
}
202+
#endif
203+
204+
/** @} */
205+
206+
207+
#endif /* DAC_H_INCLUDED */
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* \file
3+
*
4+
* \brief SAM Digital-to-Analog Interrupt Driver
5+
*
6+
* Copyright (C) 2013-2015 Atmel Corporation. All rights reserved.
7+
*
8+
* \asf_license_start
9+
*
10+
* \page License
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
*
18+
* 2. Redistributions in binary form must reproduce the above copyright notice,
19+
* this list of conditions and the following disclaimer in the documentation
20+
* and/or other materials provided with the distribution.
21+
*
22+
* 3. The name of Atmel may not be used to endorse or promote products derived
23+
* from this software without specific prior written permission.
24+
*
25+
* 4. This software may only be redistributed and used in connection with an
26+
* Atmel microcontroller product.
27+
*
28+
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31+
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38+
* POSSIBILITY OF SUCH DAMAGE.
39+
*
40+
* \asf_license_stop
41+
*
42+
*/
43+
/*
44+
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45+
*/
46+
#ifndef DAC_CALLBACK_H_INCLUDED
47+
#define DAC_CALLBACK_H_INCLUDED
48+
49+
#include <compiler.h>
50+
#include "dac.h"
51+
52+
#ifdef __cplusplus
53+
extern "C" {
54+
#endif
55+
56+
/**
57+
* \addtogroup asfdoc_sam0_dac_group
58+
*
59+
* @{
60+
*/
61+
62+
/** \name Callback Configuration and Initialization
63+
* @{
64+
*/
65+
enum status_code dac_chan_write_buffer_job(
66+
struct dac_module *const module_inst,
67+
const enum dac_channel channel,
68+
uint16_t *buffer,
69+
uint32_t buffer_size);
70+
71+
enum status_code dac_chan_write_job(
72+
struct dac_module *const module_inst,
73+
const enum dac_channel channel,
74+
uint16_t data);
75+
76+
enum status_code dac_register_callback(
77+
struct dac_module *const module,
78+
const enum dac_channel channel,
79+
const dac_callback_t callback,
80+
const enum dac_callback type);
81+
82+
enum status_code dac_unregister_callback(
83+
struct dac_module *const module,
84+
const enum dac_channel channel,
85+
const enum dac_callback type);
86+
87+
/** @} */
88+
89+
/** \name Callback Enabling and Disabling (Channel)
90+
* @{
91+
*/
92+
93+
enum status_code dac_chan_enable_callback(
94+
struct dac_module *const module,
95+
const enum dac_channel channel,
96+
const enum dac_callback type);
97+
98+
enum status_code dac_chan_disable_callback(
99+
struct dac_module *const module,
100+
const enum dac_channel channel,
101+
const enum dac_callback type);
102+
103+
enum status_code dac_chan_get_job_status(
104+
struct dac_module *module_inst,
105+
const enum dac_channel channel);
106+
107+
void dac_chan_abort_job(
108+
struct dac_module *module_inst,
109+
const enum dac_channel channel);
110+
111+
/** @} */
112+
113+
/** @} */
114+
115+
#ifdef __cplusplus
116+
}
117+
#endif
118+
119+
#endif

0 commit comments

Comments
 (0)