Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
881 theseven 1
#ifndef __PROTOCOL_I2C_I2C_H__
2
#define __PROTOCOL_I2C_I2C_H__
3
 
4
#include "global.h"
5
 
6
#ifndef ASM_FILE
7
enum i2c_result
8
{
9
    I2C_RESULT_OK = 0,
10
    I2C_RESULT_BAD_OBJECT,
11
    I2C_RESULT_INVALID_STATE,
12
    I2C_RESULT_INVALID_ARGUMENT,
13
    I2C_RESULT_UNSUPPORTED,
14
    I2C_RESULT_UNKNOWN_ERROR,
15
    I2C_RESULT_NAK,
16
};
17
 
18
struct __attribute__((packed,aligned(4))) i2c_transaction
19
{
20
    uint16_t address;
21
    uint8_t reserved;
22
    uint8_t transfercount;
23
    struct __attribute__((packed,aligned(4))) i2c_transfer
24
    {
25
        enum __attribute__((packed)) i2c_transfer_type
26
        {
27
            I2C_TRANSFER_TYPE_TX,
28
            I2C_TRANSFER_TYPE_RX,
29
            I2C_TRANSFER_TYPE_CONT,
30
        } type;
31
        uint8_t reserved;
32
        uint16_t len;
33
        union __attribute__((packed,aligned(4)))
34
        {
35
            const void* txbuf;
36
            void* rxbuf;
37
        };
38
    } transfers[];
39
};
40
 
41
struct i2c_driver;
42
 
43
struct i2c_driver_instance
44
{
45
    const struct i2c_driver* driver;
46
    const void* driver_config;
47
    void* driver_state;
48
};
49
 
50
struct i2c_driver
51
{
52
    enum i2c_result (*init)(const struct i2c_driver_instance* instance);
53
    enum i2c_result (*txn)(const struct i2c_driver_instance* instance, const struct i2c_transaction* transaction);
54
};
55
 
56
extern enum i2c_result i2c_init(const struct i2c_driver_instance* instance);
57
extern enum i2c_result i2c_txn(const struct i2c_driver_instance* instance, const struct i2c_transaction* transaction);
58
extern enum i2c_result i2c_read_regs(const struct i2c_driver_instance* instance, int address, int reg, void* buf, int len);
59
extern enum i2c_result i2c_write_regs(const struct i2c_driver_instance* instance, int address, int reg, const void* buf, int len);
60
#endif
61
 
62
#endif