1 /**
2  * \file
3  *
4  * \brief SAM SERCOM I2C Master Driver
5  *
6  * Copyright (C) 2012-2016 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 
47 #ifndef I2C_MASTER_H_INCLUDED
48 #define I2C_MASTER_H_INCLUDED
49 
50 #include "i2c_common.h"
51 #include <sercom.h>
52 #include <pinmux.h>
53 
54 #if I2C_MASTER_CALLBACK_MODE == true
55 #  include <sercom_interrupt.h>
56 #endif
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #ifndef PINMUX_DEFAULT
63 #  define PINMUX_DEFAULT 0
64 #endif
65 
66 /**
67  * \addtogroup asfdoc_sam0_sercom_i2c_group
68  *
69  * @{
70  */
71 
72 /**
73  * \brief I<SUP>2</SUP>C master packet for read/write
74  *
75  * Structure to be used when transferring I<SUP>2</SUP>C master packets.
76  */
77 struct i2c_master_packet {
78 	/** Address to slave device  */
79 	uint16_t address;
80 	/** Length of data array */
81 	uint16_t data_length;
82 	/** Data array containing all data to be transferred */
83 	uint8_t *data;
84 	/** Use 10-bit addressing. Set to false if the feature is not supported by the device  */
85 	bool ten_bit_address;
86 	/** Use high speed transfer. Set to false if the feature is not supported by the device */
87 	bool high_speed;
88 	/** High speed mode master code (0000 1XXX), valid when high_speed is true */
89 	uint8_t hs_master_code;
90 };
91 
92 /** \brief Interrupt flags
93  *
94  * Flags used when reading or setting interrupt flags.
95  */
96 enum i2c_master_interrupt_flag {
97 	/** Interrupt flag used for write */
98 	I2C_MASTER_INTERRUPT_WRITE = 0,
99 	/** Interrupt flag used for read */
100 	I2C_MASTER_INTERRUPT_READ  = 1,
101 };
102 
103 /**
104  * \brief Values for hold time after start bit.
105  *
106  * Values for the possible I<SUP>2</SUP>C master mode SDA internal hold times after start
107  * bit has been sent.
108  */
109 enum i2c_master_start_hold_time {
110 	/** Internal SDA hold time disabled */
111 	I2C_MASTER_START_HOLD_TIME_DISABLED = SERCOM_I2CM_CTRLA_SDAHOLD(0),
112 	/** Internal SDA hold time 50ns - 100ns */
113 	I2C_MASTER_START_HOLD_TIME_50NS_100NS = SERCOM_I2CM_CTRLA_SDAHOLD(1),
114 	/** Internal SDA hold time 300ns - 600ns */
115 	I2C_MASTER_START_HOLD_TIME_300NS_600NS = SERCOM_I2CM_CTRLA_SDAHOLD(2),
116 	/** Internal SDA hold time 400ns - 800ns */
117 	I2C_MASTER_START_HOLD_TIME_400NS_800NS = SERCOM_I2CM_CTRLA_SDAHOLD(3),
118 };
119 
120 /**
121  * \brief Values for inactive bus time-out.
122  *
123  * If the inactive bus time-out is enabled and the bus is inactive for
124  * longer than the time-out setting, the bus state logic will be set to idle.
125  */
126 enum i2c_master_inactive_timeout {
127 	/** Inactive bus time-out disabled */
128 	I2C_MASTER_INACTIVE_TIMEOUT_DISABLED = SERCOM_I2CM_CTRLA_INACTOUT(0),
129 	/** Inactive bus time-out 5-6 SCL cycle time-out */
130 	I2C_MASTER_INACTIVE_TIMEOUT_55US = SERCOM_I2CM_CTRLA_INACTOUT(1),
131 	/** Inactive bus time-out 10-11 SCL cycle time-out */
132 	I2C_MASTER_INACTIVE_TIMEOUT_105US = SERCOM_I2CM_CTRLA_INACTOUT(2),
133 	/** Inactive bus time-out 20-21 SCL cycle time-out */
134 	I2C_MASTER_INACTIVE_TIMEOUT_205US = SERCOM_I2CM_CTRLA_INACTOUT(3),
135 };
136 
137 /**
138  * \brief I<SUP>2</SUP>C frequencies
139  *
140  * Values for I<SUP>2</SUP>C speeds supported by the module. The driver
141  * will also support setting any other value, in which case set
142  * the value in the \ref i2c_master_config at desired value divided by 1000.
143  *
144  * Example: If 10KHz operation is required, give baud_rate in the configuration
145  * structure the value 10.
146  */
147 enum i2c_master_baud_rate {
148 	/** Baud rate at 100KHz (Standard-mode) */
149 	I2C_MASTER_BAUD_RATE_100KHZ = 100,
150 	/** Baud rate at 400KHz (Fast-mode) */
151 	I2C_MASTER_BAUD_RATE_400KHZ = 400,
152 #ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
153 	/** Baud rate at 1MHz (Fast-mode Plus) */
154 	I2C_MASTER_BAUD_RATE_1000KHZ = 1000,
155 	/** Baud rate at 3.4MHz (High-speed mode) */
156 	I2C_MASTER_BAUD_RATE_3400KHZ = 3400,
157 #endif
158 };
159 
160 #ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
161 /**
162  * \brief Enum for the transfer speed
163  *
164  * Enum for the transfer speed.
165  */
166 enum i2c_master_transfer_speed {
167 	/** Standard-mode (Sm) up to 100KHz and Fast-mode (Fm) up to 400KHz */
168 	I2C_MASTER_SPEED_STANDARD_AND_FAST = SERCOM_I2CM_CTRLA_SPEED(0),
169 	/** Fast-mode Plus (Fm+) up to 1MHz */
170 	I2C_MASTER_SPEED_FAST_MODE_PLUS = SERCOM_I2CM_CTRLA_SPEED(1),
171 	/** High-speed mode (Hs-mode) up to 3.4MHz */
172 	I2C_MASTER_SPEED_HIGH_SPEED = SERCOM_I2CM_CTRLA_SPEED(2),
173 };
174 #endif
175 
176 #if I2C_MASTER_CALLBACK_MODE == true
177 /**
178  * \brief Callback types
179  *
180  * The available callback types for the I<SUP>2</SUP>C master module.
181  */
182 enum i2c_master_callback {
183 	/** Callback for packet write complete */
184 	I2C_MASTER_CALLBACK_WRITE_COMPLETE = 0,
185 	/** Callback for packet read complete */
186 	I2C_MASTER_CALLBACK_READ_COMPLETE  = 1,
187 	/** Callback for error */
188 	I2C_MASTER_CALLBACK_ERROR          = 2,
189 #  if !defined(__DOXYGEN__)
190 	/** Total number of callbacks */
191 	_I2C_MASTER_CALLBACK_N             = 3,
192 #  endif
193 };
194 
195 #  if !defined(__DOXYGEN__)
196 /* Prototype for software module */
197 struct i2c_master_module;
198 
199 typedef void (*i2c_master_callback_t)(
200 		struct i2c_master_module *const module);
201 #  endif
202 #endif
203 
204 /**
205  * \brief SERCOM I<SUP>2</SUP>C Master driver software device instance structure.
206  *
207  * SERCOM I<SUP>2</SUP>C Master driver software instance structure, used to
208  * retain software state information of an associated hardware module instance.
209  *
210  * \note The fields of this structure should not be altered by the user
211  *       application; they are reserved for module-internal use only.
212  */
213 struct i2c_master_module {
214 #if !defined(__DOXYGEN__)
215 	/** Hardware instance initialized for the struct */
216 	Sercom *hw;
217 	/** Module lock */
218 	volatile bool locked;
219 	/** Unknown bus state timeout */
220 	uint16_t unknown_bus_state_timeout;
221 	/** Buffer write timeout value */
222 	uint16_t buffer_timeout;
223 	/** If true, stop condition will be sent after a read/write */
224 	bool send_stop;
225 	/** If true, nack signal will be sent after a read/write */
226 	bool send_nack;
227 #  if I2C_MASTER_CALLBACK_MODE == true
228 	/** Pointers to callback functions */
229 	volatile i2c_master_callback_t callbacks[_I2C_MASTER_CALLBACK_N];
230 	/** Mask for registered callbacks */
231 	volatile uint8_t registered_callback;
232 	/** Mask for enabled callbacks */
233 	volatile uint8_t enabled_callback;
234 	/** The total number of bytes to transfer */
235 	volatile uint16_t buffer_length;
236 	/**
237 	 * Counter used for bytes left to send in write and to count number of
238 	 * obtained bytes in read
239 	 */
240 	volatile uint16_t buffer_remaining;
241 	/** Data buffer for packet write and read */
242 	volatile uint8_t *buffer;
243 	/** Save direction of async request. 1 = read, 0 = write */
244 	volatile enum i2c_transfer_direction transfer_direction;
245 	/** Status for status read back in error callback */
246 	volatile enum status_code status;
247 #  endif
248 #endif
249 };
250 
251 /**
252  * \brief Configuration structure for the I<SUP>2</SUP>C Master device
253  *
254  * This is the configuration structure for the I<SUP>2</SUP>C Master device. It
255  * is used as an argument for \ref i2c_master_init to provide the desired
256  * configurations for the module. The structure should be initialized using the
257  * \ref i2c_master_get_config_defaults.
258  */
259 struct i2c_master_config {
260 	/** Baud rate (in KHz) for I<SUP>2</SUP>C operations in
261 	 * standard-mode, Fast-mode, and Fast-mode Plus Transfers,
262 	 * \ref i2c_master_baud_rate */
263 	uint32_t baud_rate;
264 #ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
265 	/** Baud rate (in KHz) for I<SUP>2</SUP>C operations in
266 	 * High-speed mode, \ref i2c_master_baud_rate */
267 	uint32_t baud_rate_high_speed;
268 	/** Transfer speed mode */
269 	enum i2c_master_transfer_speed transfer_speed;
270 #endif
271 	/** GCLK generator to use as clock source */
272 	enum gclk_generator generator_source;
273 	/** Bus hold time after start signal on data line */
274 	enum i2c_master_start_hold_time start_hold_time;
275 	/** Unknown bus state \ref asfdoc_sam0_sercom_i2c_unknown_bus_timeout "timeout" */
276 	uint16_t unknown_bus_state_timeout;
277 	/** Timeout for packet write to wait for slave */
278 	uint16_t buffer_timeout;
279 	/** Set to keep module active in sleep modes */
280 	bool run_in_standby;
281 	/** PAD0 (SDA) pinmux */
282 	uint32_t pinmux_pad0;
283 	/** PAD1 (SCL) pinmux */
284 	uint32_t pinmux_pad1;
285 	/** Set to enable SCL low time-out */
286 	bool scl_low_timeout;
287 	/** Inactive bus time out */
288 	enum i2c_master_inactive_timeout inactive_timeout;
289 #ifdef FEATURE_I2C_SCL_STRETCH_MODE
290 	/** Set to enable SCL stretch only after ACK bit (required for high speed) */
291 	bool scl_stretch_only_after_ack_bit;
292 #endif
293 #ifdef FEATURE_I2C_SCL_EXTEND_TIMEOUT
294 	/** Set to enable slave SCL low extend time-out */
295 	bool slave_scl_low_extend_timeout;
296 	/** Set to enable maser SCL low extend time-out */
297 	bool master_scl_low_extend_timeout;
298 #endif
299 	/** Get more accurate BAUD, considering rise time(required for standard-mode and Fast-mode) */
300 	uint16_t sda_scl_rise_time_ns;
301 };
302 
303 /**
304  * \name Lock/Unlock
305  * @{
306  */
307 
308 /**
309  * \brief Attempt to get lock on driver instance
310  *
311  * This function checks the instance's lock, which indicates whether or not it
312  * is currently in use, and sets the lock if it was not already set.
313  *
314  * The purpose of this is to enable exclusive access to driver instances, so
315  * that, e.g., transactions by different services will not interfere with each
316  * other.
317  *
318  * \param[in,out] module Pointer to the driver instance to lock
319  *
320  * \retval STATUS_OK If the module was locked
321  * \retval STATUS_BUSY If the module was already locked
322  */
i2c_master_lock(struct i2c_master_module * const module)323 static inline enum status_code i2c_master_lock(
324 		struct i2c_master_module *const module)
325 {
326 	enum status_code status;
327 
328 	system_interrupt_enter_critical_section();
329 
330 	if (module->locked) {
331 		status = STATUS_BUSY;
332 	} else {
333 		module->locked = true;
334 		status = STATUS_OK;
335 	}
336 
337 	system_interrupt_leave_critical_section();
338 
339 	return status;
340 }
341 
342 /**
343  * \brief Unlock driver instance
344  *
345  * This function clears the instance lock, indicating that it is available for
346  * use.
347  *
348  * \param[in,out] module Pointer to the driver instance to lock
349  *
350  * \retval STATUS_OK If the module was locked
351  * \retval STATUS_BUSY If the module was already locked
352  */
i2c_master_unlock(struct i2c_master_module * const module)353 static inline void i2c_master_unlock(struct i2c_master_module *const module)
354 {
355 	module->locked = false;
356 }
357 
358 /** @} */
359 
360 /**
361  * \name Configuration and Initialization
362  * @{
363  */
364 
365 /**
366  * \brief Returns the synchronization status of the module
367  *
368  * Returns the synchronization status of the module.
369  *
370  * \param[in]  module  Pointer to software module structure
371  *
372  * \return Status of the synchronization.
373  * \retval true   Module is busy synchronizing
374  * \retval false  Module is not synchronizing
375  */
i2c_master_is_syncing(const struct i2c_master_module * const module)376 static inline bool i2c_master_is_syncing (
377 		const struct i2c_master_module *const module)
378 {
379 	/* Sanity check */
380 	Assert(module);
381 	Assert(module->hw);
382 
383 	SercomI2cm *const i2c_hw = &(module->hw->I2CM);
384 
385 #if defined(FEATURE_SERCOM_SYNCBUSY_SCHEME_VERSION_1)
386 	return (i2c_hw->STATUS.reg & SERCOM_I2CM_STATUS_SYNCBUSY);
387 #elif defined(FEATURE_SERCOM_SYNCBUSY_SCHEME_VERSION_2)
388 	return (i2c_hw->SYNCBUSY.reg & SERCOM_I2CM_SYNCBUSY_MASK);
389 #else
390 #  error Unknown SERCOM SYNCBUSY scheme!
391 #endif
392 }
393 
394 #if !defined(__DOXYGEN__)
395 /**
396  * \internal
397  * Wait for hardware module to sync
398  *
399  * \param[in]  module  Pointer to software module structure
400  */
_i2c_master_wait_for_sync(const struct i2c_master_module * const module)401 static void _i2c_master_wait_for_sync(
402 		const struct i2c_master_module *const module)
403 {
404 	/* Sanity check */
405 	Assert(module);
406 
407 	while (i2c_master_is_syncing(module)) {
408 		/* Wait for I2C module to sync. */
409 	}
410 }
411 #endif
412 
413 /**
414  * \brief Gets the I<SUP>2</SUP>C master default configurations
415  *
416  * Use to initialize the configuration structure to known default values.
417  *
418  * The default configuration is as follows:
419  * - Baudrate 100KHz
420  * - GCLK generator 0
421  * - Do not run in standby
422  * - Start bit hold time 300ns - 600ns
423  * - Buffer timeout = 65535
424  * - Unknown bus status timeout = 65535
425  * - Do not run in standby
426  * - PINMUX_DEFAULT for SERCOM pads
427  *
428  * Those default configuration only available if the device supports it:
429  * - High speed baudrate 3.4MHz
430  * - Standard-mode and Fast-mode transfer speed
431  * - SCL stretch disabled
432  * - Slave SCL low extend time-out disabled
433  * - Master SCL low extend time-out disabled
434  *
435  * \param[out] config  Pointer to configuration structure to be initiated
436  */
i2c_master_get_config_defaults(struct i2c_master_config * const config)437 static inline void i2c_master_get_config_defaults(
438 		struct i2c_master_config *const config)
439 {
440 	/*Sanity check argument */
441 	Assert(config);
442 	config->baud_rate        = I2C_MASTER_BAUD_RATE_100KHZ;
443 #ifdef FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED
444 	config->baud_rate_high_speed = I2C_MASTER_BAUD_RATE_3400KHZ;
445 	config->transfer_speed       = I2C_MASTER_SPEED_STANDARD_AND_FAST;
446 #endif
447 	config->generator_source = GCLK_GENERATOR_0;
448 	config->run_in_standby   = false;
449 	config->start_hold_time  = I2C_MASTER_START_HOLD_TIME_300NS_600NS;
450 	config->buffer_timeout   = 65535;
451 	config->unknown_bus_state_timeout = 65535;
452 	config->pinmux_pad0      = PINMUX_DEFAULT;
453 	config->pinmux_pad1      = PINMUX_DEFAULT;
454 	config->scl_low_timeout  = false;
455 	config->inactive_timeout = I2C_MASTER_INACTIVE_TIMEOUT_DISABLED;
456 #ifdef FEATURE_I2C_SCL_STRETCH_MODE
457 	config->scl_stretch_only_after_ack_bit = false;
458 #endif
459 #ifdef FEATURE_I2C_SCL_EXTEND_TIMEOUT
460 	config->slave_scl_low_extend_timeout   = false;
461 	config->master_scl_low_extend_timeout  = false;
462 #endif
463 	/* The typical value is 215ns */
464 	config->sda_scl_rise_time_ns = 215;
465 }
466 
467 enum status_code i2c_master_init(
468 		struct i2c_master_module *const module,
469 		Sercom *const hw,
470 		const struct i2c_master_config *const config);
471 
472 /**
473  * \brief Enables the I<SUP>2</SUP>C module
474  *
475  * Enables the requested I<SUP>2</SUP>C module and set the bus state to IDLE
476  * after the specified \ref asfdoc_sam0_sercom_i2c_timeout "timeout" period if no
477  * stop bit is detected.
478  *
479  * \param[in]  module  Pointer to the software module struct
480  */
i2c_master_enable(const struct i2c_master_module * const module)481 static inline void i2c_master_enable(
482 		const struct i2c_master_module *const module)
483 {
484 	/* Sanity check of arguments */
485 	Assert(module);
486 	Assert(module->hw);
487 
488 	SercomI2cm *const i2c_module = &(module->hw->I2CM);
489 
490 	/* Timeout counter used to force bus state */
491 	uint32_t timeout_counter = 0;
492 
493 	/* Wait for module to sync */
494 	_i2c_master_wait_for_sync(module);
495 
496 	/* Enable module */
497 	i2c_module->CTRLA.reg |= SERCOM_I2CM_CTRLA_ENABLE;
498 
499 #if I2C_MASTER_CALLBACK_MODE == true
500 	/* Enable module interrupts */
501 	system_interrupt_enable(_sercom_get_interrupt_vector(module->hw));
502 #endif
503 	/* Start timeout if bus state is unknown */
504 	while (!(i2c_module->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE(1))) {
505 		timeout_counter++;
506 		if(timeout_counter >= (module->unknown_bus_state_timeout)) {
507 			/* Timeout, force bus state to idle */
508 			i2c_module->STATUS.reg = SERCOM_I2CM_STATUS_BUSSTATE(1);
509 			/* Workaround #1 */
510 			return;
511 		}
512 	}
513 }
514 
515 /**
516  * \brief Disable the I<SUP>2</SUP>C module
517  *
518  * Disables the requested I<SUP>2</SUP>C module.
519  *
520  * \param[in]  module  Pointer to the software module struct
521  */
i2c_master_disable(const struct i2c_master_module * const module)522 static inline void i2c_master_disable(
523 		const struct i2c_master_module *const module)
524 {
525 	/* Sanity check of arguments */
526 	Assert(module);
527 	Assert(module->hw);
528 
529 	SercomI2cm *const i2c_module = &(module->hw->I2CM);
530 
531 #if I2C_MASTER_CALLBACK_MODE == true
532 		/* Disable module interrupts */
533 		system_interrupt_disable(_sercom_get_interrupt_vector(module->hw));
534 #endif
535 
536 	/* Wait for module to sync */
537 	_i2c_master_wait_for_sync(module);
538 
539 	/* Disbale interrupt */
540 	i2c_module->INTENCLR.reg = SERCOM_I2CM_INTENCLR_MASK;
541 	/* Clear interrupt flag */
542 	i2c_module->INTFLAG.reg = SERCOM_I2CM_INTFLAG_MASK;
543 
544 	/* Disable module */
545 	i2c_module->CTRLA.reg &= ~SERCOM_I2CM_CTRLA_ENABLE;
546 
547 }
548 
549 void i2c_master_reset(struct i2c_master_module *const module);
550 
551 /** @} */
552 
553 /**
554 * \name Read and Write
555 * @{
556 */
557 
558 enum status_code i2c_master_read_packet_wait(
559 		struct i2c_master_module *const module,
560 		struct i2c_master_packet *const packet);
561 
562 enum status_code i2c_master_read_packet_wait_no_stop(
563 		struct i2c_master_module *const module,
564 		struct i2c_master_packet *const packet);
565 
566 enum status_code i2c_master_write_packet_wait(
567 		struct i2c_master_module *const module,
568 		struct i2c_master_packet *const packet);
569 
570 enum status_code i2c_master_write_packet_wait_no_stop(
571 		struct i2c_master_module *const module,
572 		struct i2c_master_packet *const packet);
573 
574 void i2c_master_send_stop(struct i2c_master_module *const module);
575 
576 void i2c_master_send_nack(struct i2c_master_module *const module);
577 
578 enum status_code i2c_master_read_byte(
579 		struct i2c_master_module *const module,
580 		uint8_t *byte);
581 
582 enum status_code i2c_master_write_byte(
583 		struct i2c_master_module *const module,
584 		uint8_t byte);
585 
586 enum status_code i2c_master_read_packet_wait_no_nack(
587 		struct i2c_master_module *const module,
588 		struct i2c_master_packet *const packet);
589 
590 /** @} */
591 
592 #ifdef FEATURE_I2C_DMA_SUPPORT
593 /**
594 * \name SERCOM I2C Master with DMA Interfaces
595 * @{
596 */
597 
598 /**
599  * \brief Set I<SUP>2</SUP>C for DMA transfer with slave address and transfer size.
600  *
601  * This function will set the slave address, transfer size and enable the auto transfer
602  * mode for DMA.
603  *
604  * \param[in,out] module Pointer to the driver instance to lock
605  * \param[in] addr I<SUP>2</SUP>C slave address
606  * \param[in] length I<SUP>2</SUP>C transfer length with DMA
607  * \param[in] direction I<SUP>2</SUP>C transfer direction
608  *
609  */
i2c_master_dma_set_transfer(struct i2c_master_module * const module,uint16_t addr,uint8_t length,enum i2c_transfer_direction direction)610 static inline void i2c_master_dma_set_transfer(struct i2c_master_module *const module,
611 		uint16_t addr, uint8_t length, enum i2c_transfer_direction direction)
612 {
613 	module->hw->I2CM.ADDR.reg =
614 		SERCOM_I2CM_ADDR_ADDR(addr<<1) |
615 		SERCOM_I2CM_ADDR_LENEN |
616 		SERCOM_I2CM_ADDR_LEN(length) |
617 		direction;
618 }
619 
620 /** @} */
621 #endif
622 
623 /** @} */
624 
625 #ifdef __cplusplus
626 }
627 #endif
628 
629 #endif /* I2C_MASTER_H_INCLUDED */
630