make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / common / hidd.i2c / i2c.h
blob9c9d59f7239291f10fe51fe877431ca1db030501
1 #ifndef _I2C_H
2 #define _I2C_H
4 /*
5 Copyright © 2004, The AROS Development Team. All rights reserved.
6 $Id$
7 */
9 #include <exec/types.h>
10 #include <exec/libraries.h>
11 #include <exec/execbase.h>
12 #include <exec/nodes.h>
13 #include <exec/lists.h>
14 #include <exec/semaphores.h>
15 #include <dos/bptr.h>
17 #include <devices/timer.h>
19 #include <aros/libcall.h>
20 #include <aros/asmcall.h>
22 #include <oop/oop.h>
24 #include <aros/arossupportbase.h>
25 #include <exec/execbase.h>
27 #include LC_LIBDEFS_FILE
29 /* Private data and structures unavailable outside the i2c base classes */
31 typedef struct DevInstData {
32 OOP_Object *driver;
33 STRPTR name;
34 UWORD address;
35 ULONG HoldTime;
36 ULONG BitTimeout;
37 ULONG ByteTimeout;
38 ULONG AcknTimeout;
39 ULONG StartTimeout;
40 ULONG RiseFallTime;
41 } tDevData;
43 typedef struct DrvInstData {
44 struct SignalSemaphore driver_lock;
46 struct MinList devices;
48 struct MsgPort mp;
49 struct timerequest tr;
51 STRPTR name;
53 ULONG HoldTime;
54 ULONG BitTimeout;
55 ULONG ByteTimeout;
56 ULONG AcknTimeout;
57 ULONG StartTimeout;
58 ULONG RiseFallTime;
59 } tDrvData;
61 struct i2c_staticdata {
62 OOP_AttrBase hiddAB;
63 OOP_AttrBase hiddI2CAB;
64 OOP_AttrBase hiddI2CDeviceAB;
66 OOP_Class *i2cClass;
67 OOP_Class *i2cDeviceClass;
69 OOP_MethodID mid_I2C_Start;
70 OOP_MethodID mid_I2C_Stop;
71 OOP_MethodID mid_I2C_PutBits;
72 OOP_MethodID mid_I2C_GetBits;
73 OOP_MethodID mid_I2C_PutByte;
74 OOP_MethodID mid_I2C_GetByte;
75 OOP_MethodID mid_I2C_Address;
76 OOP_MethodID mid_I2C_WriteRead;
80 struct i2cbase {
81 struct Library LibNode;
82 APTR MemPool;
83 struct i2c_staticdata sd;
86 #define BASE(lib) ((struct i2cbase*)(lib))
88 #define SD(cl) (&BASE(cl->UserData)->sd)
90 #define METHOD(base, id, name) \
91 base ## __ ## id ## __ ## name (OOP_Class *cl, OOP_Object *o, struct p ## id ## _ ## name *msg)
94 #define LOCK_HW ObtainSemaphore(&drv->driver_lock);
95 #define UNLOCK_HW ReleaseSemaphore(&drv->driver_lock);
97 #define I2C_Start(__o, __timeout) \
98 ({ \
99 struct pHidd_I2C_Start __p, *__m=&__p; \
100 if (!SD(cl)->mid_I2C_Start) \
101 SD(cl)->mid_I2C_Start = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_Start); \
102 __p.mID = SD(cl)->mid_I2C_Start; \
103 __p.timeout = (__timeout); \
104 OOP_DoMethod((__o), (OOP_Msg)__m); \
107 #define I2C_Stop(__o, __device) \
108 ({ \
109 struct pHidd_I2C_Stop __p, *__m=&__p; \
110 if (!SD(cl)->mid_I2C_Stop) \
111 SD(cl)->mid_I2C_Stop = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_Stop); \
112 __p.mID = SD(cl)->mid_I2C_Stop; \
113 __p.device = (__device); \
114 OOP_DoMethod((__o), (OOP_Msg)__m); \
117 #define I2C_PutBits(__o, __scl, __sda) \
118 ({ \
119 struct pHidd_I2C_PutBits __p, *__m=&__p; \
120 if (!SD(cl)->mid_I2C_PutBits) \
121 SD(cl)->mid_I2C_PutBits = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_PutBits); \
122 __p.mID = SD(cl)->mid_I2C_PutBits; \
123 __p.scl = (__scl); \
124 __p.sda = (__sda); \
125 OOP_DoMethod((__o), (OOP_Msg)__m); \
128 #define I2C_PutByte(__o, __device, __byte) \
129 ({ \
130 struct pHidd_I2C_PutByte __p, *__m=&__p; \
131 if (!SD(cl)->mid_I2C_PutByte) \
132 SD(cl)->mid_I2C_PutByte = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_PutByte); \
133 __p.mID = SD(cl)->mid_I2C_PutByte; \
134 __p.data = (__byte); \
135 __p.device = (__device); \
136 OOP_DoMethod((__o), (OOP_Msg)__m); \
139 #define I2C_GetByte(__o, __device, __byte, __last) \
140 ({ \
141 struct pHidd_I2C_GetByte __p, *__m=&__p; \
142 if (!SD(cl)->mid_I2C_GetByte) \
143 SD(cl)->mid_I2C_GetByte = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_GetByte); \
144 __p.mID = SD(cl)->mid_I2C_GetByte; \
145 __p.data = (__byte); \
146 __p.last = (__last); \
147 __p.device = (__device); \
148 OOP_DoMethod((__o), (OOP_Msg)__m); \
151 #define I2C_GetBits(__o, __scl, __sda) \
152 ({ \
153 struct pHidd_I2C_GetBits __p, *__m=&__p; \
154 if (!SD(cl)->mid_I2C_GetBits) \
155 SD(cl)->mid_I2C_GetBits = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_GetBits); \
156 __p.mID = SD(cl)->mid_I2C_GetBits; \
157 __p.scl = (__scl); \
158 __p.sda = (__sda); \
159 OOP_DoMethod((__o), (OOP_Msg)__m); \
162 #define I2C_Address(__o, __device, __addr) \
163 ({ \
164 struct pHidd_I2C_Address __p, *__m=&__p; \
165 if (!SD(cl)->mid_I2C_Address) \
166 SD(cl)->mid_I2C_Address = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_Address); \
167 __p.mID = SD(cl)->mid_I2C_Address; \
168 __p.address = (__addr); \
169 __p.device = (__device); \
170 OOP_DoMethod((__o), (OOP_Msg)__m); \
173 #define I2C_WriteRead(__o, __device, __wb, __wl, __rb, __rl) \
174 ({ \
175 struct pHidd_I2C_WriteRead __p, *__m=&__p; \
176 if (!SD(cl)->mid_I2C_WriteRead) \
177 SD(cl)->mid_I2C_WriteRead = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_WriteRead); \
178 __p.mID = SD(cl)->mid_I2C_WriteRead; \
179 __p.device = (__device); \
180 __p.writeBuffer = (__wb); \
181 __p.writeLength = (__wl); \
182 __p.readBuffer = (__rb); \
183 __p.readLength = (__rl); \
184 OOP_DoMethod((__o), (OOP_Msg)__m); \
188 #endif /* _I2C_H */