1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491 */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG. */
5 /* This program is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 2 of the License, or */
8 /* (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* You may also obtain this software under a propriety license from Microchip. */
19 /* Please contact Microchip for further information. */
20 /*------------------------------------------------------------------------------------------------*/
24 * \brief Internal header file of the I2C module.
26 * \defgroup G_UCS_I2C_TYPES I2C Referred Types
27 * \brief Referred types used by the Extended Resource Manager.
30 * \cond UCS_INTERNAL_DOC
39 /*------------------------------------------------------------------------------------------------*/
41 /*------------------------------------------------------------------------------------------------*/
43 #include "ucs_ret_pb.h"
45 #include "ucs_i2c_pb.h"
52 /*------------------------------------------------------------------------------------------------*/
53 /* Type definitions */
54 /*------------------------------------------------------------------------------------------------*/
55 /*! \brief Function signature used for I2C results in case error.
56 * \param self Reference to CI2c instance
57 * \param msg_ptr Pointer to received message
59 typedef void (*I2c_ErrResultCb_t)(void *self, void *result_ptr);
61 /*------------------------------------------------------------------------------------------------*/
63 /*------------------------------------------------------------------------------------------------*/
64 /*! \brief Stores data required by I2C during initialization. */
65 typedef struct I2c_InitData_
67 /*!< \brief Reference to INIC instance */
69 /*!< \brief Reference to NSM instance */
70 CNodeScriptManagement *nsm_ptr;
71 /*!< \brief Status function pointer for the I2C Interrupt event */
72 Ucs_I2c_IntEventReportCb_t i2c_interrupt_report_fptr;
76 /*! \brief Stores data required by I2C during initialization. */
77 typedef struct I2c_UserData_
79 /*!< \brief PinState Result callback */
80 Ucs_I2c_ReadPortResCb_t portread_res_cb;
81 /*!< \brief PortCreate Result callback */
82 Ucs_I2c_WritePortResCb_t portwrite_res_cb;
83 /*!< \brief PortCreate Result callback */
84 Ucs_I2c_CreatePortResCb_t portcreate_res_cb;
85 /*!< \brief Status function pointer for the I2c interrupt */
86 Ucs_I2c_IntEventReportCb_t i2c_interrupt_report_fptr;
87 /*!< \brief I2C interrupt pin mask on GPIO Port */
92 /*! \brief Script structure of the I2C module */
93 typedef struct I2c_Script_
96 /*! \brief script used for transmitting commands */
97 Ucs_Ns_Script_t script;
98 /*! \brief config messages used for transmitting commands */
99 Ucs_Ns_ConfigMsg_t cfg_msg;
102 /*! \brief Class structure of the I2C module */
105 /*! \brief Reference to an INIC instance */
107 /*! \brief Reference to a base instance */
109 /*!< \brief Reference to NSM instance */
110 CNodeScriptManagement *nsm_ptr;
111 /*!< \brief Current user data */
112 I2c_UserData_t curr_user_data;
113 /*!< \brief Indicates the address of target device */
114 uint16_t device_address;
115 /*! \brief Observer used for I2C to check the GPIO TriggerEvents */
116 CObserver triggerevent_observer;
117 /*!< \brief Current script to be looked for */
118 I2c_Script_t curr_script;
119 /*!< \brief Current reference to the result callback function */
120 I2c_ErrResultCb_t curr_res_cb;
124 /*------------------------------------------------------------------------------------------------*/
125 /* Prototypes of class CI2c */
126 /*------------------------------------------------------------------------------------------------*/
127 extern void I2c_Ctor(CI2c * self, I2c_InitData_t * init_ptr);
128 extern Ucs_Return_t I2c_CreatePort(CI2c * self, uint8_t index, Ucs_I2c_Speed_t speed, uint8_t i2c_int_mask, Ucs_I2c_CreatePortResCb_t res_fptr);
129 extern Ucs_Return_t I2c_WritePort(CI2c * self, uint16_t port_handle, Ucs_I2c_TrMode_t mode, uint8_t block_count, uint8_t slave_address, uint16_t timeout,
130 uint8_t data_len, uint8_t data_ptr[], Ucs_I2c_WritePortResCb_t res_fptr);
131 extern Ucs_Return_t I2c_ReadPort(CI2c * self, uint16_t port_handle, uint8_t slave_address, uint8_t data_len, uint16_t timeout, Ucs_I2c_ReadPortResCb_t res_fptr);
137 #endif /* #ifndef UCS_I2C_H */
144 /*------------------------------------------------------------------------------------------------*/
146 /*------------------------------------------------------------------------------------------------*/