Prusa3d Marlin fork
twi.h
1 /*
2  twi.h - Stripped-down TWI/I2C library
3  Copyright (c) 2006 Nicholas Zambetti. All right reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #pragma once
21 
22 #include <inttypes.h>
23 #include <compat/twi.h>
24 
25 #ifndef TWI_FREQ
26 #define TWI_FREQ 400000L
27 #endif
28 
29 #define TWI_TIMEOUT_MS 10
30 
31 /*
32  * Function twi_init
33  * Desc readys twi pins and sets twi bitrate
34  * Input none
35  * Output none
36  */
37 void twi_init(void);
38 
39 /*
40  * Function twi_disable
41  * Desc disables twi pins
42  * Input none
43  * Output none
44  */
45 void twi_disable(void);
46 
47 /*
48  * Function twi_check
49  * Desc checks if a device exists on the bus
50  * Input address: 7bit i2c device address
51  * Output 0 on device found at address
52  */
53 uint8_t twi_check(uint8_t address);
54 
55 /*
56  * Function twi_r8
57  * Desc read a single byte from a device
58  * Input address: 7bit i2c device address
59  * reg: register address
60  * data: pointer to byte for result
61  * Output 0 on success
62  */
63 uint8_t twi_r8(uint8_t address, uint8_t reg, uint8_t* data);
64 
65 /*
66  * Function twi_w8
67  * Desc write a single byte from a device
68  * Input address: 7bit i2c device address
69  * reg: register address
70  * data: byte to write
71  * Output 0 on success
72  */
73 uint8_t twi_w8(uint8_t address, uint8_t reg, uint8_t data);