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