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_ASYNC_H_INCLUDED 44 #define _HPL_I2C_S_ASYNC_H_INCLUDED 45 46 #include "hpl_i2c_s_sync.h" 47 #include "hpl_irq.h" 48 #include "utils.h" 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 /** 55 * \brief i2c callback types 56 */ 57 enum _i2c_s_async_callback_type { I2C_S_DEVICE_ERROR, I2C_S_DEVICE_TX, I2C_S_DEVICE_RX_COMPLETE }; 58 59 /** 60 * \brief Forward declaration of I2C Slave device 61 */ 62 struct _i2c_s_async_device; 63 64 /** 65 * \brief i2c slave callback function type 66 */ 67 typedef void (*_i2c_s_async_cb_t)(struct _i2c_s_async_device *device); 68 69 /** 70 * \brief i2c slave callback pointers structure 71 */ 72 struct _i2c_s_async_callback { 73 void (*error)(struct _i2c_s_async_device *const device); 74 void (*tx)(struct _i2c_s_async_device *const device); 75 void (*rx_done)(struct _i2c_s_async_device *const device, const uint8_t data); 76 }; 77 78 /** 79 * \brief i2c slave device structure 80 */ 81 struct _i2c_s_async_device { 82 void * hw; 83 struct _i2c_s_async_callback cb; 84 struct _irq_descriptor irq; 85 }; 86 87 /** 88 * \name HPL functions 89 */ 90 91 /** 92 * \brief Initialize asynchronous I2C slave 93 * 94 * This function does low level I2C configuration. 95 * 96 * \param[in] device The pointer to i2c interrupt device structure 97 * 98 * \return Return 0 for success and negative value for error 99 */ 100 int32_t _i2c_s_async_init(struct _i2c_s_async_device *const device, void *const hw); 101 102 /** 103 * \brief Deinitialize asynchronous I2C in interrupt mode 104 * 105 * \param[in] device The pointer to i2c device structure 106 * 107 * \return Return 0 for success and negative value for error 108 */ 109 int32_t _i2c_s_async_deinit(struct _i2c_s_async_device *const device); 110 111 /** 112 * \brief Enable I2C module 113 * 114 * This function does low level I2C enable. 115 * 116 * \param[in] device The pointer to i2c slave device structure 117 * 118 * \return Return 0 for success and negative value for error 119 */ 120 int32_t _i2c_s_async_enable(struct _i2c_s_async_device *const device); 121 122 /** 123 * \brief Disable I2C module 124 * 125 * This function does low level I2C disable. 126 * 127 * \param[in] device The pointer to i2c slave device structure 128 * 129 * \return Return 0 for success and negative value for error 130 */ 131 int32_t _i2c_s_async_disable(struct _i2c_s_async_device *const device); 132 133 /** 134 * \brief Check if 10-bit addressing mode is on 135 * 136 * \param[in] device The pointer to i2c slave device structure 137 * 138 * \return Cheking status 139 * \retval 1 10-bit addressing mode is on 140 * \retval 0 10-bit addressing mode is off 141 */ 142 int32_t _i2c_s_async_is_10bit_addressing_on(const struct _i2c_s_async_device *const device); 143 144 /** 145 * \brief Set I2C slave address 146 * 147 * \param[in] device The pointer to i2c slave device structure 148 * \param[in] address Address to set 149 * 150 * \return Return 0 for success and negative value for error 151 */ 152 int32_t _i2c_s_async_set_address(struct _i2c_s_async_device *const device, const uint16_t address); 153 154 /** 155 * \brief Write a byte to the given I2C instance 156 * 157 * \param[in] device The pointer to i2c slave device structure 158 * \param[in] data Data to write 159 */ 160 void _i2c_s_async_write_byte(struct _i2c_s_async_device *const device, const uint8_t data); 161 162 /** 163 * \brief Retrieve I2C slave status 164 * 165 * \param[in] device The pointer to i2c slave device structure 166 * 167 *\return I2C slave status 168 */ 169 i2c_s_status_t _i2c_s_async_get_status(const struct _i2c_s_async_device *const device); 170 171 /** 172 * \brief Abort data transmission 173 * 174 * \param[in] device The pointer to i2c device structure 175 * 176 * \return Return 0 for success and negative value for error 177 */ 178 int32_t _i2c_s_async_abort_transmission(const struct _i2c_s_async_device *const device); 179 180 /** 181 * \brief Enable/disable I2C slave interrupt 182 * 183 * param[in] device The pointer to I2C slave device instance 184 * param[in] type The type of interrupt to disable/enable if applicable 185 * param[in] disable Enable or disable 186 */ 187 int32_t _i2c_s_async_set_irq_state(struct _i2c_s_async_device *const device, const enum _i2c_s_async_callback_type type, 188 const bool disable); 189 190 #ifdef __cplusplus 191 } 192 #endif 193 194 #endif /* _HPL_I2C_S_ASYNC_H_INCLUDED */ 195