]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/irc.c
Merge branch 'master' of rtime.felk.cvut.cz:pes-rpp/rpp-lib
[pes-rpp/rpp-lib.git] / rpp / src / rpp / irc.c
1 /* Copyright (C) 2013-2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Karel Kočí
5  *
6  * This document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : irc.c
12  * Abstract:
13  *     IRC sensor input driver RPP API implementation file.
14  *
15  * References:
16  *     irc.h
17  *     RPP API documentation.
18  */
19
20 #include "rpp/rpp.h"
21
22 #if rppCONFIG_INCLUDE_IRC == 1
23
24 #if rppCONFIG_DRV == 1
25 #include "sys/ti_drv_het2.h"
26 #include "sys/sys_pinmux.h"
27 #else
28 #define setMuxForIRC(a, b)
29 #define ircEnable(a)
30 #define ircDisable(a)
31 #endif
32
33 static boolean_t initialized = FALSE;
34
35 boolean_t rpp_irc1_enabled = FALSE;
36 boolean_t rpp_irc2_enabled = FALSE;
37
38 int8_t rpp_irc_init() {
39
40     if (initialized) {
41         return FAILURE;
42     }
43
44 #if rppCONFIG_DRV == 1
45     het2Init();
46 #endif
47
48     initialized = TRUE;
49     return SUCCESS;
50 }
51
52 int8_t rpp_irc_enable(uint8_t irc) {
53
54     if (!initialized)
55         return FAILURE;
56
57     if (irc < 1 || irc > 2)
58         return -RPP_EINVAL;
59
60     switch (irc) {
61     case 1:
62         rpp_irc1_enabled = TRUE;
63         break;
64     case 2:
65         rpp_irc2_enabled = TRUE;
66         break;
67     }
68
69     setMuxForIRC(irc, TRUE);
70     ircEnable(irc);
71
72     return SUCCESS;
73 }
74
75 int8_t rpp_irc_status(uint8_t irc) {
76
77     if (!initialized)
78         return FAILURE;
79
80     if (irc < 1 || irc > 2)
81         return -RPP_EINVAL;
82
83     switch (irc) {
84     case 1:
85         return rpp_irc1_enabled ? 1 : 0;
86     case 2:
87         return rpp_irc2_enabled ? 1 : 0;
88     }
89     return FAILURE;
90 }
91
92 int32_t rpp_irc_get(uint8_t irc) {
93
94     if (!initialized)
95         return FAILURE;
96
97     if (irc < 1 || irc > 2)
98         return 0;
99
100     if (rpp_irc_status(irc) != 1)
101         return FAILURE;
102
103 #if rppCONFIG_DRV == 1
104     return ircGet(irc);
105 #else
106     return 1;
107 #endif
108 }
109
110 int8_t rpp_irc_disable(uint8_t irc) {
111
112     if (!initialized)
113         return FAILURE;
114
115     if (irc < 1 || irc > 2)
116         return -RPP_EINVAL;
117
118     if (rpp_irc_status(irc) != 1)
119         return FAILURE;
120
121     ircDisable(irc);
122     setMuxForIRC(irc, FALSE);
123     switch (irc) {
124     case 1:
125         rpp_irc1_enabled = FALSE;
126         break;
127     case 2:
128         rpp_irc2_enabled = FALSE;
129         break;
130     }
131     return FAILURE;
132 }
133
134 #endif /* rppCONFIG_INCLUDE_IRC */