summaryrefslogtreecommitdiffstats
path: root/ucs2-lib/inc/ucs_i2c.h
blob: 5146e784100cc1fc7e1eb9f31c9cc07c10f7296d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*------------------------------------------------------------------------------------------------*/
/* UNICENS V2.1.0-3491                                                                            */
/* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
/*                                                                                                */
/* This program is free software: you can redistribute it and/or modify                           */
/* it under the terms of the GNU General Public License as published by                           */
/* the Free Software Foundation, either version 2 of the License, or                              */
/* (at your option) any later version.                                                            */
/*                                                                                                */
/* This program is distributed in the hope that it will be useful,                                */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
/* GNU General Public License for more details.                                                   */
/*                                                                                                */
/* You should have received a copy of the GNU General Public License                              */
/* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
/*                                                                                                */
/* You may also obtain this software under a propriety license from Microchip.                    */
/* Please contact Microchip for further information.                                              */
/*------------------------------------------------------------------------------------------------*/

/*!
 * \file
 * \brief Internal header file of the I2C module.
 *
 * \defgroup   G_UCS_I2C_TYPES I2C Referred Types
 * \brief      Referred types used by the Extended Resource Manager.
 * \ingroup    G_UCS_I2C
 *
 * \cond UCS_INTERNAL_DOC
 * \addtogroup G_I2C
 * @{
 */


#ifndef UCS_I2C_H
#define UCS_I2C_H

/*------------------------------------------------------------------------------------------------*/
/* Includes                                                                                       */
/*------------------------------------------------------------------------------------------------*/
#include "ucs_nsm.h"
#include "ucs_ret_pb.h"
#include "ucs_obs.h"
#include "ucs_i2c_pb.h"

#ifdef __cplusplus
extern "C"
{
#endif

/*------------------------------------------------------------------------------------------------*/
/* Type definitions                                                                               */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Function signature used for I2C results in case error.
 *  \param   self      Reference to CI2c instance
 *  \param   msg_ptr   Pointer to received message
 */
typedef void (*I2c_ErrResultCb_t)(void *self, void *result_ptr);

/*------------------------------------------------------------------------------------------------*/
/* Structures                                                                                     */
/*------------------------------------------------------------------------------------------------*/
/*! \brief  Stores data required by I2C during initialization. */
typedef struct I2c_InitData_
{
    /*!< \brief Reference to INIC instance */
    CInic *inic_ptr;
    /*!< \brief Reference to NSM instance */
    CNodeScriptManagement *nsm_ptr;
    /*!< \brief Status function pointer for the I2C Interrupt event */
    Ucs_I2c_IntEventReportCb_t i2c_interrupt_report_fptr;

} I2c_InitData_t;

/*! \brief  Stores data required by I2C during initialization. */
typedef struct I2c_UserData_
{
    /*!< \brief PinState Result callback */
    Ucs_I2c_ReadPortResCb_t portread_res_cb;
    /*!< \brief PortCreate Result callback */
    Ucs_I2c_WritePortResCb_t portwrite_res_cb;
    /*!< \brief PortCreate Result callback */
    Ucs_I2c_CreatePortResCb_t portcreate_res_cb;
    /*!< \brief Status function pointer for the I2c interrupt */
    Ucs_I2c_IntEventReportCb_t i2c_interrupt_report_fptr;
    /*!< \brief I2C interrupt pin mask on GPIO Port */
    uint8_t int_pin_mask;

} I2c_UserData_t;

/*! \brief  Script structure of the I2C module */
typedef struct I2c_Script_
{
    uint8_t cfg_data[40];
    /*! \brief script used for transmitting commands */
    Ucs_Ns_Script_t script;
    /*! \brief config messages used for transmitting commands */
    Ucs_Ns_ConfigMsg_t cfg_msg;
} I2c_Script_t;

/*! \brief  Class structure of the I2C module */
typedef struct CI2c_
{
    /*! \brief Reference to an INIC instance */
    CInic *inic_ptr;
    /*! \brief Reference to a base instance */
    CBase *base_ptr;
    /*!< \brief Reference to NSM instance */
    CNodeScriptManagement *nsm_ptr;
    /*!< \brief Current user data */
    I2c_UserData_t curr_user_data;
    /*!< \brief Indicates the address of target device */
    uint16_t device_address;
    /*! \brief Observer used for I2C to check the GPIO TriggerEvents  */
    CObserver triggerevent_observer;
    /*!< \brief Current script to be looked for */
    I2c_Script_t curr_script;
    /*!< \brief Current reference to the result callback function */
    I2c_ErrResultCb_t curr_res_cb;

} CI2c;

/*------------------------------------------------------------------------------------------------*/
/* Prototypes of class CI2c                                                                       */
/*------------------------------------------------------------------------------------------------*/
extern void I2c_Ctor(CI2c * self, I2c_InitData_t * init_ptr);
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);
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, 
                                  uint8_t data_len, uint8_t data_ptr[], Ucs_I2c_WritePortResCb_t res_fptr);
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);

#ifdef __cplusplus
}   /* extern "C" */
#endif

#endif /* #ifndef UCS_I2C_H */

/*!
 * @}
 * \endcond
 */

/*------------------------------------------------------------------------------------------------*/
/* End of file                                                                                    */
/*------------------------------------------------------------------------------------------------*/