Use latest version of conf.d/templates submodule.
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_i2c.h
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
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.                                                            */
9 /*                                                                                                */
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.                                                   */
14 /*                                                                                                */
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/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Internal header file of the I2C module.
25  *
26  * \defgroup   G_UCS_I2C_TYPES I2C Referred Types
27  * \brief      Referred types used by the Extended Resource Manager.
28  * \ingroup    G_UCS_I2C
29  *
30  * \cond UCS_INTERNAL_DOC
31  * \addtogroup G_I2C
32  * @{
33  */
34
35
36 #ifndef UCS_I2C_H
37 #define UCS_I2C_H
38
39 /*------------------------------------------------------------------------------------------------*/
40 /* Includes                                                                                       */
41 /*------------------------------------------------------------------------------------------------*/
42 #include "ucs_nsm.h"
43 #include "ucs_ret_pb.h"
44 #include "ucs_obs.h"
45 #include "ucs_i2c_pb.h"
46
47 #ifdef __cplusplus
48 extern "C"
49 {
50 #endif
51
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
58  */
59 typedef void (*I2c_ErrResultCb_t)(void *self, void *result_ptr);
60
61 /*------------------------------------------------------------------------------------------------*/
62 /* Structures                                                                                     */
63 /*------------------------------------------------------------------------------------------------*/
64 /*! \brief  Stores data required by I2C during initialization. */
65 typedef struct I2c_InitData_
66 {
67     /*!< \brief Reference to INIC instance */
68     CInic *inic_ptr;
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;
73
74 } I2c_InitData_t;
75
76 /*! \brief  Stores data required by I2C during initialization. */
77 typedef struct I2c_UserData_
78 {
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 */
88     uint8_t int_pin_mask;
89
90 } I2c_UserData_t;
91
92 /*! \brief  Script structure of the I2C module */
93 typedef struct I2c_Script_
94 {
95     uint8_t cfg_data[40];
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;
100 } I2c_Script_t;
101
102 /*! \brief  Class structure of the I2C module */
103 typedef struct CI2c_
104 {
105     /*! \brief Reference to an INIC instance */
106     CInic *inic_ptr;
107     /*! \brief Reference to a base instance */
108     CBase *base_ptr;
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;
121
122 } CI2c;
123
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);
132
133 #ifdef __cplusplus
134 }   /* extern "C" */
135 #endif
136
137 #endif /* #ifndef UCS_I2C_H */
138
139 /*!
140  * @}
141  * \endcond
142  */
143
144 /*------------------------------------------------------------------------------------------------*/
145 /* End of file                                                                                    */
146 /*------------------------------------------------------------------------------------------------*/
147