1 /* 2 Copyright (c) 2003, Thomas Kurschel 3 4 5 Part of DDC driver 6 7 I2C protocoll 8 */ 9 10 #ifndef _I2C_H 11 #define _I2C_H 12 13 #include <OS.h> 14 15 // timing for i2c bus 16 typedef struct i2c_timing { 17 // general timing as defined by standard 18 // (in microseconds for 100kHz/400kHz mode) 19 int buf; // bus free between start and stop (4.7/1.3) 20 int hd_sta; // hold time start condition (4.0/0.6) 21 int low; // low period of clock (4.7/1.3) 22 int high; // high period of clock (4.0/0.6) 23 int su_sta; // setup time of repeated start condition (4.7/0.6) 24 int hd_dat; // hold time data (5.0/- for CBUS, 0/0 for I2C) 25 int su_dat; // setup time data (0.250/0.100) 26 int r; // maximum raise time of clock and data signal (1.0/0.3) 27 int f; // maximum fall time of clock and data signal (0.3/0.3) 28 int su_sto; // setup time for stop condition (4.0/0.6) 29 30 // clock stretching limits, not part of i2c standard 31 int start_timeout; // max. delay of start condition 32 int byte_timeout; // max. delay of first bit of byte 33 int bit_timeout; // max. delay of one bit within a byte transmission 34 int ack_start_timeout; // max. delay of acknowledge start 35 36 // other timeouts, not part of i2c standard 37 int ack_timeout; // timeout of waiting for acknowledge 38 } i2c_timing; 39 40 41 // set signals on bus 42 typedef status_t (*i2c_set_signals)( void *cookie, int scl, int sda ); 43 // read signals from bus 44 typedef status_t (*i2c_get_signals)( void *cookie, int *scl, int *sda ); 45 46 47 // i2c bus definition 48 typedef struct i2c_bus { 49 void *cookie; // user-defined cookie 50 i2c_set_signals set_signals; // callback to set signals 51 i2c_get_signals get_signals; // callback to detect signals 52 } i2c_bus; 53 54 55 // send and receive data via i2c bus 56 status_t i2c_send_receive( const i2c_bus *bus, const i2c_timing *timing, 57 int slave_address, 58 const uint8 *write_buffer, size_t write_len, 59 uint8 *read_buffer, size_t read_len ); 60 61 62 // fill <timing> with standard 100kHz bus timing 63 void i2c_get100k_timing( i2c_timing *timing ); 64 65 // fill <timing> with standard 400kHz bus timing 66 // (as timing resolution is 1 microsecond, we cannot reach full speed!) 67 void i2c_get400k_timing( i2c_timing *timing ); 68 69 #endif 70