Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
twi.h
Go to the documentation of this file.
1/*
2 * This file is part of the Home2L project.
3 *
4 * (C) 2015-2021 Gundolf Kiefer
5 *
6 * Home2L 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 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Home2L 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 Home2L. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21
22#ifndef _TWI_
23#define _TWI_
24
25
36#include "core.h"
37
38
39
40
41// *************************** TWI Slave ***************************************
42
43
50
51
52
53// ***** General *****
54
55void TwiSlInit ();
57void TwiSlDone ();
59
60EBrStatus TwiSlIterate ();
71
72
73
74// ***** BrRequests and replies *****
75
76extern /* const */ TBrRequest twiSlRequest;
79extern TBrReply twiSlReply;
82
83void TwiSlReplyCommit (uint8_t bytes);
89void TwiSlReplyCommitPartial (uint8_t bytes, bool complete);
97void TwiSlReplyFlush ();
99
100
101
102// ***** Host notification *****
103
104
105#if TWI_SL_NOTIFY || DOXYGEN
106
107extern bool twiSlNotifyPending;
108
109static inline void TwiSlNotify () { twiSlNotifyPending = true; }
111
112#else
113
114static inline void TwiSlNotify () {}
115
116#endif
117
118
119
120
121
122// *************************** TWI Master **************************************
123
124
131
132
133#if WITH_TWI_MASTER || DOXYGEN
134
135
136void TwiMaInit ();
137
138#if TWI_MA_PORTS > 1 || DOXYGEN
139extern int8_t twiMaPort;
140static inline void TwiMaSelectPort (int8_t port) { twiMaPort = port; }
142#else
143static inline void TwiMaSelectPort (int8_t port) {}
144#endif
145
148bool TwiMaSendByte (uint8_t data);
149uint8_t TwiMaReceiveByte (bool ack);
150
151
152#endif // WITH_TWI_MASTER
153
154
155
156
157
158// ************************** TWI Hub (Uses Master) ****************************
159
160
164
165
166#if WITH_TWIHUB || DOXYGEN
167
168
169static inline void TwiHubInit () { TwiMaInit (); }
171
172void TwiHubIterate ();
174
175static inline void TwiHubOnRegRead (uint8_t reg) {}
177static inline void TwiHubOnRegWrite (uint8_t reg, uint8_t val) {}
179
180
181#else // WITH_TWIHUB
182
183
184static inline void TwiHubInit () {}
185static inline void TwiHubIterate () {}
186static inline void TwiHubOnRegRead (uint8_t reg) {}
187static inline void TwiHubOnRegWrite (uint8_t reg, uint8_t val) {}
188
189
190#endif // WITH_TWIHUB
191
192
194
196
197
198#endif // _TWI_
void TwiMaSendStart()
Send a start condition.
void TwiMaSendStop()
Send a stop condition.
static void TwiMaSelectPort(int8_t port)
Select the TWI master port for the next operations.
Definition: twi.h:140
void TwiMaInit()
Init all TWI master ports.
bool TwiMaSendByte(uint8_t data)
Send a byte (returns the ACK bit).
uint8_t TwiMaReceiveByte(bool ack)
Receive a byte ('ack' to be set to 1 if more bytes are expected).
EBrStatus
Definition: interface.h:121
Reply message.
Definition: interface.h:160
Request message.
Definition: interface.h:140