blob: 92fa4e6682dea1ca1dfe6935f821bae282e1746a [file] [log] [blame]
Christina Quast637ace92014-11-28 13:28:37 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/**
31 * \file
32 *
33 * Interface for configuration the Two Wire Interface (TWI) peripheral.
34 *
35 */
36
37#ifndef _TWI_
38#define _TWI_
39
40/*------------------------------------------------------------------------------
41 * Headers
42 *------------------------------------------------------------------------------*/
43
44#include "chip.h"
45
46#include <stdint.h>
47
48/*----------------------------------------------------------------------------
49 * Macros
50 *----------------------------------------------------------------------------*/
51/* Returns 1 if the TXRDY bit (ready to transmit data) is set in the given status register value.*/
52#define TWI_STATUS_TXRDY(status) ((status & TWI_SR_TXRDY) == TWI_SR_TXRDY)
53
54/* Returns 1 if the RXRDY bit (ready to receive data) is set in the given status register value.*/
55#define TWI_STATUS_RXRDY(status) ((status & TWI_SR_RXRDY) == TWI_SR_RXRDY)
56
57/* Returns 1 if the TXCOMP bit (transfer complete) is set in the given status register value.*/
58#define TWI_STATUS_TXCOMP(status) ((status & TWI_SR_TXCOMP) == TWI_SR_TXCOMP)
59
60#ifdef __cplusplus
61 extern "C" {
62#endif
63
64/*----------------------------------------------------------------------------
65 * External function
66 *----------------------------------------------------------------------------*/
67
68extern void TWI_ConfigureMaster(Twi *pTwi, uint32_t twck, uint32_t mck);
69
70extern void TWI_ConfigureSlave(Twi *pTwi, uint8_t slaveAddress);
71
72extern void TWI_Stop(Twi *pTwi);
73
74extern void TWI_StartRead(
75 Twi *pTwi,
76 uint8_t address,
77 uint32_t iaddress,
78 uint8_t isize);
79
80extern uint8_t TWI_ReadByte(Twi *pTwi);
81
82extern void TWI_WriteByte(Twi *pTwi, uint8_t byte);
83
84extern void TWI_StartWrite(
85 Twi *pTwi,
86 uint8_t address,
87 uint32_t iaddress,
88 uint8_t isize,
89 uint8_t byte);
90
91extern uint8_t TWI_ByteReceived(Twi *pTwi);
92
93extern uint8_t TWI_ByteSent(Twi *pTwi);
94
95extern uint8_t TWI_TransferComplete(Twi *pTwi);
96
97extern void TWI_EnableIt(Twi *pTwi, uint32_t sources);
98
99extern void TWI_DisableIt(Twi *pTwi, uint32_t sources);
100
101extern uint32_t TWI_GetStatus(Twi *pTwi);
102
103extern uint32_t TWI_GetMaskedStatus(Twi *pTwi);
104
105extern void TWI_SendSTOPCondition(Twi *pTwi);
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif /* #ifndef _TWI_ */