vfs: check userland buffers before reading them.
[haiku.git] / headers / private / graphics / common / i2c.h
blobe048b6d60e4d2048d33efbde51ffe4bee4f8b517
1 /*
2 * Copyright 2003, Thomas Kurschel. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _I2C_H
6 #define _I2C_H
9 #include <OS.h>
12 // timing for i2c bus
13 typedef struct i2c_timing {
14 // general timing as defined by standard
15 // (in microseconds for 100kHz/400kHz mode)
16 int buf; // bus free between start and stop (4.7/1.3)
17 int hd_sta; // hold time start condition (4.0/0.6)
18 int low; // low period of clock (4.7/1.3)
19 int high; // high period of clock (4.0/0.6)
20 int su_sta; // setup time of repeated start condition (4.7/0.6)
21 int hd_dat; // hold time data (5.0/- for CBUS, 0/0 for I2C)
22 int su_dat; // setup time data (0.250/0.100)
23 int r; // maximum raise time of clock and data signal (1.0/0.3)
24 int f; // maximum fall time of clock and data signal (0.3/0.3)
25 int su_sto; // setup time for stop condition (4.0/0.6)
27 // clock stretching limits, not part of i2c standard
28 int start_timeout; // max. delay of start condition
29 int byte_timeout; // max. delay of first bit of byte
30 int bit_timeout; // max. delay of one bit within a byte transmission
31 int ack_start_timeout; // max. delay of acknowledge start
33 // other timeouts, not part of i2c standard
34 int ack_timeout; // timeout of waiting for acknowledge
35 } i2c_timing;
38 // set signals on bus
39 typedef status_t (*i2c_set_signals)(void *cookie, int clock, int data);
40 // read signals from bus
41 typedef status_t (*i2c_get_signals)(void *cookie, int *clock, int *data);
43 // i2c bus definition
44 typedef struct i2c_bus {
45 void *cookie; // user-defined cookie
46 i2c_timing timing;
47 i2c_set_signals set_signals; // callback to set signals
48 i2c_get_signals get_signals; // callback to detect signals
49 } i2c_bus;
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
56 // send and receive data via i2c bus
57 status_t i2c_send_receive(const i2c_bus *bus, int slave_address,
58 const uint8 *writeBuffer, size_t writeLength, uint8 *readBuffer,
59 size_t readLength);
61 // fill <timing> with standard 100kHz bus timing
62 void i2c_get100k_timing(i2c_timing *timing);
64 // fill <timing> with standard 400kHz bus timing
65 // (as timing resolution is 1 microsecond, we cannot reach full speed!)
66 void i2c_get400k_timing(i2c_timing *timing);
68 #ifdef __cplusplus
70 #endif
72 #endif /* _I2C_H */