1 /** 2 * \file 3 * 4 * \brief I2C Slave Hardware Proxy Layer(HPL) declaration. 5 * 6 * Copyright (C) 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 #ifndef _HPL_I2C_S_SYNC_H_INCLUDED 44 #define _HPL_I2C_S_SYNC_H_INCLUDED 45 46 #include <compiler.h> 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 /** 53 * \brief I2C Slave status type 54 */ 55 typedef uint32_t i2c_s_status_t; 56 57 /** 58 * \brief i2c slave device structure 59 */ 60 struct _i2c_s_sync_device { 61 void *hw; 62 }; 63 64 #include <compiler.h> 65 66 /** 67 * \name HPL functions 68 */ 69 70 /** 71 * \brief Initialize synchronous I2C slave 72 * 73 * This function does low level I2C configuration. 74 * 75 * \param[in] device The pointer to i2c slave device structure 76 * 77 * \return Return 0 for success and negative value for error 78 */ 79 int32_t _i2c_s_sync_init(struct _i2c_s_sync_device *const device, void *const hw); 80 81 /** 82 * \brief Deinitialize synchronous I2C slave 83 * 84 * \param[in] device The pointer to i2c slave device structure 85 * 86 * \return Return 0 for success and negative value for error 87 */ 88 int32_t _i2c_s_sync_deinit(struct _i2c_s_sync_device *const device); 89 90 /** 91 * \brief Enable I2C module 92 * 93 * This function does low level I2C enable. 94 * 95 * \param[in] device The pointer to i2c slave device structure 96 * 97 * \return Return 0 for success and negative value for error 98 */ 99 int32_t _i2c_s_sync_enable(struct _i2c_s_sync_device *const device); 100 101 /** 102 * \brief Disable I2C module 103 * 104 * This function does low level I2C disable. 105 * 106 * \param[in] device The pointer to i2c slave device structure 107 * 108 * \return Return 0 for success and negative value for error 109 */ 110 int32_t _i2c_s_sync_disable(struct _i2c_s_sync_device *const device); 111 112 /** 113 * \brief Check if 10-bit addressing mode is on 114 * 115 * \param[in] device The pointer to i2c slave device structure 116 * 117 * \return Cheking status 118 * \retval 1 10-bit addressing mode is on 119 * \retval 0 10-bit addressing mode is off 120 */ 121 int32_t _i2c_s_sync_is_10bit_addressing_on(const struct _i2c_s_sync_device *const device); 122 123 /** 124 * \brief Set I2C slave address 125 * 126 * \param[in] device The pointer to i2c slave device structure 127 * \param[in] address Address to set 128 * 129 * \return Return 0 for success and negative value for error 130 */ 131 int32_t _i2c_s_sync_set_address(struct _i2c_s_sync_device *const device, const uint16_t address); 132 133 /** 134 * \brief Write a byte to the given I2C instance 135 * 136 * \param[in] device The pointer to i2c slave device structure 137 * \param[in] data Data to write 138 */ 139 void _i2c_s_sync_write_byte(struct _i2c_s_sync_device *const device, const uint8_t data); 140 141 /** 142 * \brief Retrieve I2C slave status 143 * 144 * \param[in] device The pointer to i2c slave device structure 145 * 146 *\return I2C slave status 147 */ 148 i2c_s_status_t _i2c_s_sync_get_status(const struct _i2c_s_sync_device *const device); 149 150 /** 151 * \brief Read a byte from the given I2C instance 152 * 153 * \param[in] device The pointer to i2c slave device structure 154 * 155 * \return Data received via I2C interface. 156 */ 157 uint8_t _i2c_s_sync_read_byte(const struct _i2c_s_sync_device *const device); 158 159 /** 160 * \brief Check if I2C is ready to send next byte 161 * 162 * \param[in] device The pointer to i2c slave device structure 163 * 164 * \return Status of the ready check. 165 * \retval true if the I2C is ready to send next byte 166 * \retval false if the I2C is not ready to send next byte 167 */ 168 bool _i2c_s_sync_is_byte_sent(const struct _i2c_s_sync_device *const device); 169 170 /** 171 * \brief Check if there is data received by I2C 172 * 173 * \param[in] device The pointer to i2c slave device structure 174 * 175 * \return Status of the data received check. 176 * \retval true if the I2C has received a byte 177 * \retval false if the I2C has not received a byte 178 */ 179 bool _i2c_s_sync_is_byte_received(const struct _i2c_s_sync_device *const device); 180 181 #ifdef __cplusplus 182 } 183 #endif 184 185 #endif /* _HPL_I2C_S_SYNC_H_INCLUDED */ 186