blob: b79bdc75b819977b33b9f0841904d4ac4a4612a6 [file] [log] [blame]
Damjan Marionb4d89272016-05-12 22:14:45 +02001/*
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
Dave Barach9b8ffd92016-07-08 08:13:45 -040025typedef struct
26{
27 u8 addr;
28 u8 flags;
29 u16 len;
30 u8 *buffer;
Damjan Marionb4d89272016-05-12 22:14:45 +020031} i2c_msg_t;
32
Dave Barach9b8ffd92016-07-08 08:13:45 -040033typedef struct i2c_bus_t
34{
35 void (*put_bits) (struct i2c_bus_t * b, int scl, int sda);
36 void (*get_bits) (struct i2c_bus_t * b, int *scl, int *sda);
Damjan Marionb4d89272016-05-12 22:14:45 +020037
38 int timeout;
39 u32 clock;
40 f64 hold_time;
41 f64 rise_fall_time;
42
43 /* Private data */
44 uword private_data;
45
46} i2c_bus_t;
47
48void vlib_i2c_init (i2c_bus_t * bus);
49void vlib_i2c_xfer (i2c_bus_t * bus, i2c_msg_t * msgs);
Dave Barach9b8ffd92016-07-08 08:13:45 -040050void vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr,
51 u16 length, u8 * data);
Damjan Marionb4d89272016-05-12 22:14:45 +020052
53static inline int
Dave Barach9b8ffd92016-07-08 08:13:45 -040054vlib_i2c_bus_timed_out (i2c_bus_t * bus)
Damjan Marionb4d89272016-05-12 22:14:45 +020055{
56 return bus->timeout;
57}
58
59#endif /* included_vlib_i2c_h */
60
Dave Barach9b8ffd92016-07-08 08:13:45 -040061/*
62 * fd.io coding-style-patch-verification: ON
63 *
64 * Local Variables:
65 * eval: (c-set-style "gnu")
66 * End:
67 */