451957d8513f3a6c6b2f69bb593c236b3713d7e4
[vpp.git] / vlib / vlib / i2c.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_vlib_i2c_h
17 #define included_vlib_i2c_h
18
19 #include <vppinfra/types.h>
20
21
22 #define I2C_MSG_FLAG_WRITE  0
23 #define I2C_MSG_FLAG_READ   1
24
25 typedef struct {
26     u8 addr;
27     u8 flags;
28     u16 len;
29     u8 * buffer;
30 } i2c_msg_t;
31
32 typedef struct i2c_bus_t {
33   void (* put_bits) (struct i2c_bus_t * b, int  scl, int  sda);
34   void (* get_bits) (struct i2c_bus_t * b, int *scl, int *sda);
35
36   int timeout;
37   u32 clock;
38   f64 hold_time;
39   f64 rise_fall_time;
40
41   /* Private data */
42   uword private_data;
43
44 } i2c_bus_t;
45
46 void vlib_i2c_init (i2c_bus_t * bus);
47 void vlib_i2c_xfer (i2c_bus_t * bus, i2c_msg_t * msgs);
48 void vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr, u16 length, u8 * data);
49
50 static inline int
51 vlib_i2c_bus_timed_out(i2c_bus_t * bus)
52 {
53   return bus->timeout;
54 }
55
56 #endif /* included_vlib_i2c_h */
57