00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** 00031 * \file 00032 * 00033 * Interface for configuration the Two Wire Interface (TWI) peripheral. 00034 * 00035 */ 00036 00037 #ifndef _TWI_ 00038 #define _TWI_ 00039 00040 /*------------------------------------------------------------------------------ 00041 * Headers 00042 *----------------------------------------------------------------------------*/ 00043 00044 #include "chip.h" 00045 00046 #include <stdint.h> 00047 00048 /*---------------------------------------------------------------------------- 00049 * Macros 00050 *----------------------------------------------------------------------------*/ 00051 /* Returns 1 if the TXRDY bit (ready to transmit data) is set in the given 00052 status register value.*/ 00053 #define TWI_STATUS_TXRDY(status) ((status & TWIHS_SR_TXRDY) == TWIHS_SR_TXRDY) 00054 00055 /* Returns 1 if the RXRDY bit (ready to receive data) is set in the given 00056 status register value.*/ 00057 #define TWI_STATUS_RXRDY(status) ((status & TWIHS_SR_RXRDY) == TWIHS_SR_RXRDY) 00058 00059 /* Returns 1 if the TXCOMP bit (transfer complete) is set in the given 00060 status register value.*/ 00061 #define TWI_STATUS_TXCOMP(status) ((status & TWIHS_SR_TXCOMP) == TWIHS_SR_TXCOMP) 00062 00063 #ifdef __cplusplus 00064 extern "C" { 00065 #endif 00066 00067 /*---------------------------------------------------------------------------- 00068 * External function 00069 *----------------------------------------------------------------------------*/ 00070 00071 extern void TWI_ConfigureMaster(Twihs *pTwi, uint32_t twck, uint32_t mck); 00072 00073 extern void TWI_ConfigureSlave(Twihs *pTwi, uint8_t slaveAddress); 00074 00075 extern void TWI_Stop(Twihs *pTwi); 00076 00077 extern void TWI_StartRead( 00078 Twihs *pTwi, 00079 uint8_t address, 00080 uint32_t iaddress, 00081 uint8_t isize); 00082 00083 extern uint8_t TWI_ReadByte(Twihs *pTwi); 00084 00085 extern void TWI_WriteByte(Twihs *pTwi, uint8_t byte); 00086 00087 extern void TWI_StartWrite( 00088 Twihs *pTwi, 00089 uint8_t address, 00090 uint32_t iaddress, 00091 uint8_t isize, 00092 uint8_t byte); 00093 00094 extern uint8_t TWI_ByteReceived(Twihs *pTwi); 00095 00096 extern uint8_t TWI_ByteSent(Twihs *pTwi); 00097 00098 extern uint8_t TWI_TransferComplete(Twihs *pTwi); 00099 00100 extern void TWI_EnableIt(Twihs *pTwi, uint32_t sources); 00101 00102 extern void TWI_DisableIt(Twihs *pTwi, uint32_t sources); 00103 00104 extern uint32_t TWI_GetStatus(Twihs *pTwi); 00105 00106 extern uint32_t TWI_GetMaskedStatus(Twihs *pTwi); 00107 00108 extern void TWI_SendSTOPCondition(Twihs *pTwi); 00109 00110 #ifdef __cplusplus 00111 } 00112 #endif 00113 00114 #endif /* #ifndef _TWI_ */