1 /** 2 * \file 3 * 4 * \brief I2C Slave Hardware Proxy Layer(HPL) declaration. 5 * 6 * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. 7 * 8 * \asf_license_start 9 * 10 * \page License 11 * 12 * Subject to your compliance with these terms, you may use Microchip 13 * software and any derivatives exclusively with Microchip products. 14 * It is your responsibility to comply with third party license terms applicable 15 * to your use of third party software (including open source software) that 16 * may accompany Microchip software. 17 * 18 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, 19 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, 20 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, 21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE 22 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL 23 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE 24 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE 25 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT 26 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY 27 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, 28 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 29 * 30 * \asf_license_stop 31 * 32 */ 33 #ifndef _HPL_I2C_S_ASYNC_H_INCLUDED 34 #define _HPL_I2C_S_ASYNC_H_INCLUDED 35 36 #include "hpl_i2c_s_sync.h" 37 #include "hpl_irq.h" 38 #include "utils.h" 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /** 45 * \brief i2c callback types 46 */ 47 enum _i2c_s_async_callback_type { I2C_S_DEVICE_ERROR, I2C_S_DEVICE_TX, I2C_S_DEVICE_RX_COMPLETE }; 48 49 /** 50 * \brief Forward declaration of I2C Slave device 51 */ 52 struct _i2c_s_async_device; 53 54 /** 55 * \brief i2c slave callback function type 56 */ 57 typedef void (*_i2c_s_async_cb_t)(struct _i2c_s_async_device *device); 58 59 /** 60 * \brief i2c slave callback pointers structure 61 */ 62 struct _i2c_s_async_callback { 63 void (*error)(struct _i2c_s_async_device *const device); 64 void (*tx)(struct _i2c_s_async_device *const device); 65 void (*rx_done)(struct _i2c_s_async_device *const device, const uint8_t data); 66 }; 67 68 /** 69 * \brief i2c slave device structure 70 */ 71 struct _i2c_s_async_device { 72 void * hw; 73 struct _i2c_s_async_callback cb; 74 struct _irq_descriptor irq; 75 }; 76 77 /** 78 * \name HPL functions 79 */ 80 81 /** 82 * \brief Initialize asynchronous I2C slave 83 * 84 * This function does low level I2C configuration. 85 * 86 * \param[in] device The pointer to i2c interrupt device structure 87 * 88 * \return Return 0 for success and negative value for error 89 */ 90 int32_t _i2c_s_async_init(struct _i2c_s_async_device *const device, void *const hw); 91 92 /** 93 * \brief Deinitialize asynchronous I2C in interrupt mode 94 * 95 * \param[in] device The pointer to i2c device structure 96 * 97 * \return Return 0 for success and negative value for error 98 */ 99 int32_t _i2c_s_async_deinit(struct _i2c_s_async_device *const device); 100 101 /** 102 * \brief Enable I2C module 103 * 104 * This function does low level I2C enable. 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_async_enable(struct _i2c_s_async_device *const device); 111 112 /** 113 * \brief Disable I2C module 114 * 115 * This function does low level I2C disable. 116 * 117 * \param[in] device The pointer to i2c slave device structure 118 * 119 * \return Return 0 for success and negative value for error 120 */ 121 int32_t _i2c_s_async_disable(struct _i2c_s_async_device *const device); 122 123 /** 124 * \brief Check if 10-bit addressing mode is on 125 * 126 * \param[in] device The pointer to i2c slave device structure 127 * 128 * \return Cheking status 129 * \retval 1 10-bit addressing mode is on 130 * \retval 0 10-bit addressing mode is off 131 */ 132 int32_t _i2c_s_async_is_10bit_addressing_on(const struct _i2c_s_async_device *const device); 133 134 /** 135 * \brief Set I2C slave address 136 * 137 * \param[in] device The pointer to i2c slave device structure 138 * \param[in] address Address to set 139 * 140 * \return Return 0 for success and negative value for error 141 */ 142 int32_t _i2c_s_async_set_address(struct _i2c_s_async_device *const device, const uint16_t address); 143 144 /** 145 * \brief Write a byte to the given I2C instance 146 * 147 * \param[in] device The pointer to i2c slave device structure 148 * \param[in] data Data to write 149 */ 150 void _i2c_s_async_write_byte(struct _i2c_s_async_device *const device, const uint8_t data); 151 152 /** 153 * \brief Retrieve I2C slave status 154 * 155 * \param[in] device The pointer to i2c slave device structure 156 * 157 *\return I2C slave status 158 */ 159 i2c_s_status_t _i2c_s_async_get_status(const struct _i2c_s_async_device *const device); 160 161 /** 162 * \brief Abort data transmission 163 * 164 * \param[in] device The pointer to i2c device structure 165 * 166 * \return Return 0 for success and negative value for error 167 */ 168 int32_t _i2c_s_async_abort_transmission(const struct _i2c_s_async_device *const device); 169 170 /** 171 * \brief Enable/disable I2C slave interrupt 172 * 173 * param[in] device The pointer to I2C slave device instance 174 * param[in] type The type of interrupt to disable/enable if applicable 175 * param[in] disable Enable or disable 176 */ 177 int32_t _i2c_s_async_set_irq_state(struct _i2c_s_async_device *const device, const enum _i2c_s_async_callback_type type, 178 const bool disable); 179 180 #ifdef __cplusplus 181 } 182 #endif 183 184 #endif /* _HPL_I2C_S_ASYNC_H_INCLUDED */ 185