Damjan Marion | b4d8927 | 2016-05-12 22:14:45 +0200 | [diff] [blame] | 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 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 25 | typedef struct |
| 26 | { |
| 27 | u8 addr; |
| 28 | u8 flags; |
| 29 | u16 len; |
| 30 | u8 *buffer; |
Damjan Marion | b4d8927 | 2016-05-12 22:14:45 +0200 | [diff] [blame] | 31 | } i2c_msg_t; |
| 32 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 33 | typedef 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 Marion | b4d8927 | 2016-05-12 22:14:45 +0200 | [diff] [blame] | 37 | |
| 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 | |
| 48 | void vlib_i2c_init (i2c_bus_t * bus); |
| 49 | void vlib_i2c_xfer (i2c_bus_t * bus, i2c_msg_t * msgs); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 50 | void vlib_i2c_read_eeprom (i2c_bus_t * bus, u8 i2c_addr, u16 start_addr, |
| 51 | u16 length, u8 * data); |
Damjan Marion | b4d8927 | 2016-05-12 22:14:45 +0200 | [diff] [blame] | 52 | |
| 53 | static inline int |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 54 | vlib_i2c_bus_timed_out (i2c_bus_t * bus) |
Damjan Marion | b4d8927 | 2016-05-12 22:14:45 +0200 | [diff] [blame] | 55 | { |
| 56 | return bus->timeout; |
| 57 | } |
| 58 | |
| 59 | #endif /* included_vlib_i2c_h */ |
| 60 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 61 | /* |
| 62 | * fd.io coding-style-patch-verification: ON |
| 63 | * |
| 64 | * Local Variables: |
| 65 | * eval: (c-set-style "gnu") |
| 66 | * End: |
| 67 | */ |