1 /*****************************************************************************
2  *
3  * \file
4  *
5  * \brief TWI Master driver for SAM.
6  *
7  * This file defines a useful set of functions for the TWIM interface on SAM
8  * devices.
9  *
10  * Copyright (c) 2012-2015 Atmel Corporation. All rights reserved.
11  *
12  * \asf_license_start
13  *
14  * \page License
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions are met:
18  *
19  * 1. Redistributions of source code must retain the above copyright notice,
20  *    this list of conditions and the following disclaimer.
21  *
22  * 2. Redistributions in binary form must reproduce the above copyright notice,
23  *    this list of conditions and the following disclaimer in the documentation
24  *    and/or other materials provided with the distribution.
25  *
26  * 3. The name of Atmel may not be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  * 4. This software may only be redistributed and used in connection with an
30  *    Atmel microcontroller product.
31  *
32  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
33  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
35  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
36  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
41  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGE.
43  *
44  * \asf_license_stop
45  *
46  ******************************************************************************/
47 /*
48  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
49  */
50 
51 
52 #ifndef _TWI_MASTER_H_
53 #define _TWI_MASTER_H_
54 
55 #include "compiler.h"
56 #include "sysclk.h"
57 #include "status_codes.h"
58 #include "twim.h"
59 
60 typedef twi_options_t twi_master_options_t;
61 
twi_master_setup(Twim * twi,twi_master_options_t * opt)62 static inline uint32_t twi_master_setup(Twim *twi, twi_master_options_t *opt)
63 {
64 	opt->twim_clk = sysclk_get_pba_hz();
65 	/* Initialize the TWIM Module */
66 	twim_set_callback(twi, 0, twim_default_callback, 1);
67 	return twi_master_init(twi, (twi_master_options_t *)opt);
68 }
69 
70 #endif  // _TWI_MASTER_H_
71