updated app-templates
[apps/agl-service-unicens.git] / ucs2-vol / src / callbacks.cpp
1 /*
2  * libmostvolume example
3  *
4  * Copyright (C) 2017 Microchip Technology Germany II GmbH & Co. KG
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * You may also obtain this software under a propriety license from Microchip.
20  * Please contact Microchip for further information.
21  *
22  */
23
24 #include "callbacks.h"
25 #include "device_value.h"
26
27 typedef void (*i2c_result_t)(Ucs_I2c_Result_t result, void *obj_ptr);
28
29 static clb_i2c_result_cb_t i2c_result_fptr;
30 static void *i2_obj_ptr;
31
32 #define CLB_UNUSED(a)     (a = a)
33
34 extern "C" void Clb_RegisterI2CResultCB(clb_i2c_result_cb_t result_fptr, void *obj_ptr)
35 {
36     i2c_result_fptr = result_fptr;
37     i2_obj_ptr = obj_ptr;
38 }
39
40 extern "C" void Clb_OnWriteI2CPortResult(uint16_t node_address, uint16_t i2c_port_handle, uint8_t i2c_slave_address, uint8_t data_len, Ucs_I2c_Result_t result, void *user_ptr)
41 {
42     CLB_UNUSED(user_ptr);
43     CLB_UNUSED(data_len);
44     CLB_UNUSED(i2c_slave_address);
45     CLB_UNUSED(i2c_port_handle);
46     CLB_UNUSED(node_address);
47
48     if (i2c_result_fptr != NULL)
49     {
50         clb_i2c_result_cb_t tmp_i2c_result_fptr = i2c_result_fptr;
51         void *tmp_i2_obj_ptr = i2_obj_ptr;
52
53         i2c_result_fptr = NULL;     /* reset references before callback to allow synchronous registration of a new callback */
54         i2_obj_ptr = NULL;
55
56         tmp_i2c_result_fptr(result, tmp_i2_obj_ptr);
57     }
58 }