added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / common / hidd.i2c / i2c.h
blob5f7bd8ab77de8417d4cf2da330bfacd14d0fd4ca
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 <aros/libcall.h>
18 #include <aros/asmcall.h>
20 #include <oop/oop.h>
22 #include <aros/arossupportbase.h>
23 #include <exec/execbase.h>
25 #include LC_LIBDEFS_FILE
27 /* Private data and structures unavailable outside the i2c base classes */
29 typedef struct DevInstData {
30 OOP_Object *driver;
31 STRPTR name;
32 UWORD address;
33 ULONG HoldTime;
34 ULONG BitTimeout;
35 ULONG ByteTimeout;
36 ULONG AcknTimeout;
37 ULONG StartTimeout;
38 ULONG RiseFallTime;
39 } tDevData;
41 struct i2c_staticdata {
42 struct SignalSemaphore driver_lock;
43 struct MinList devices;
45 STRPTR name;
47 ULONG HoldTime;
48 ULONG BitTimeout;
49 ULONG ByteTimeout;
50 ULONG AcknTimeout;
51 ULONG StartTimeout;
52 ULONG RiseFallTime;
54 OOP_AttrBase hiddAB;
55 OOP_AttrBase hiddI2CAB;
56 OOP_AttrBase hiddI2CDeviceAB;
58 OOP_Class *i2cClass;
59 OOP_Class *i2cDeviceClass;
61 OOP_MethodID mid_I2C_Start;
62 OOP_MethodID mid_I2C_Stop;
63 OOP_MethodID mid_I2C_PutBits;
64 OOP_MethodID mid_I2C_GetBits;
65 OOP_MethodID mid_I2C_PutByte;
66 OOP_MethodID mid_I2C_GetByte;
67 OOP_MethodID mid_I2C_Address;
68 OOP_MethodID mid_I2C_WriteRead;
72 struct i2cbase {
73 struct Library LibNode;
74 APTR MemPool;
75 struct i2c_staticdata sd;
78 #define BASE(lib) ((struct i2cbase*)(lib))
80 #define SD(cl) (&BASE(cl->UserData)->sd)
82 #define METHOD(base, id, name) \
83 base ## __ ## id ## __ ## name (OOP_Class *cl, OOP_Object *o, struct p ## id ## _ ## name *msg)
86 #define LOCK_HW ObtainSemaphore(&SD(cl)->driver_lock);
87 #define UNLOCK_HW ReleaseSemaphore(&SD(cl)->driver_lock);
89 #define I2C_Start(__o, __timeout) \
90 ({ \
91 struct pHidd_I2C_Start __p, *__m=&__p; \
92 if (!SD(cl)->mid_I2C_Start) \
93 SD(cl)->mid_I2C_Start = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_Start); \
94 __p.mID = SD(cl)->mid_I2C_Start; \
95 __p.timeout = (__timeout); \
96 OOP_DoMethod((__o), (OOP_Msg)__m); \
99 #define I2C_Stop(__o, __device) \
100 ({ \
101 struct pHidd_I2C_Stop __p, *__m=&__p; \
102 if (!SD(cl)->mid_I2C_Stop) \
103 SD(cl)->mid_I2C_Stop = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_Stop); \
104 __p.mID = SD(cl)->mid_I2C_Stop; \
105 __p.device = (__device); \
106 OOP_DoMethod((__o), (OOP_Msg)__m); \
109 #define I2C_PutBits(__o, __scl, __sda) \
110 ({ \
111 struct pHidd_I2C_PutBits __p, *__m=&__p; \
112 if (!SD(cl)->mid_I2C_PutBits) \
113 SD(cl)->mid_I2C_PutBits = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_PutBits); \
114 __p.mID = SD(cl)->mid_I2C_PutBits; \
115 __p.scl = (__scl); \
116 __p.sda = (__sda); \
117 OOP_DoMethod((__o), (OOP_Msg)__m); \
120 #define I2C_PutByte(__o, __device, __byte) \
121 ({ \
122 struct pHidd_I2C_PutByte __p, *__m=&__p; \
123 if (!SD(cl)->mid_I2C_PutByte) \
124 SD(cl)->mid_I2C_PutByte = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_PutByte); \
125 __p.mID = SD(cl)->mid_I2C_PutByte; \
126 __p.data = (__byte); \
127 __p.device = (__device); \
128 OOP_DoMethod((__o), (OOP_Msg)__m); \
131 #define I2C_GetByte(__o, __device, __byte, __last) \
132 ({ \
133 struct pHidd_I2C_GetByte __p, *__m=&__p; \
134 if (!SD(cl)->mid_I2C_GetByte) \
135 SD(cl)->mid_I2C_GetByte = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_GetByte); \
136 __p.mID = SD(cl)->mid_I2C_GetByte; \
137 __p.data = (__byte); \
138 __p.last = (__last); \
139 __p.device = (__device); \
140 OOP_DoMethod((__o), (OOP_Msg)__m); \
143 #define I2C_GetBits(__o, __scl, __sda) \
144 ({ \
145 struct pHidd_I2C_GetBits __p, *__m=&__p; \
146 if (!SD(cl)->mid_I2C_GetBits) \
147 SD(cl)->mid_I2C_GetBits = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_GetBits); \
148 __p.mID = SD(cl)->mid_I2C_GetBits; \
149 __p.scl = (__scl); \
150 __p.sda = (__sda); \
151 OOP_DoMethod((__o), (OOP_Msg)__m); \
154 #define I2C_Address(__o, __device, __addr) \
155 ({ \
156 struct pHidd_I2C_Address __p, *__m=&__p; \
157 if (!SD(cl)->mid_I2C_Address) \
158 SD(cl)->mid_I2C_Address = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_Address); \
159 __p.mID = SD(cl)->mid_I2C_Address; \
160 __p.address = (__addr); \
161 __p.device = (__device); \
162 OOP_DoMethod((__o), (OOP_Msg)__m); \
165 #define I2C_WriteRead(__o, __device, __wb, __wl, __rb, __rl) \
166 ({ \
167 struct pHidd_I2C_WriteRead __p, *__m=&__p; \
168 if (!SD(cl)->mid_I2C_WriteRead) \
169 SD(cl)->mid_I2C_WriteRead = OOP_GetMethodID((STRPTR)IID_Hidd_I2C, moHidd_I2C_WriteRead); \
170 __p.mID = SD(cl)->mid_I2C_WriteRead; \
171 __p.device = (__device); \
172 __p.writeBuffer = (__wb); \
173 __p.writeLength = (__wl); \
174 __p.readBuffer = (__rb); \
175 __p.readLength = (__rl); \
176 OOP_DoMethod((__o), (OOP_Msg)__m); \
180 #endif /* _I2C_H */