5 Copyright © 2004, The AROS Development Team. All rights reserved.
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>
17 #include <aros/libcall.h>
18 #include <aros/asmcall.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
{
41 struct i2c_staticdata
{
42 struct SignalSemaphore driver_lock
;
43 struct MinList devices
;
55 OOP_AttrBase hiddI2CAB
;
56 OOP_AttrBase hiddI2CDeviceAB
;
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
;
73 struct Library LibNode
;
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) \
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) \
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) \
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; \
117 OOP_DoMethod((__o), (OOP_Msg)__m); \
120 #define I2C_PutByte(__o, __device, __byte) \
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) \
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) \
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; \
151 OOP_DoMethod((__o), (OOP_Msg)__m); \
154 #define I2C_Address(__o, __device, __addr) \
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) \
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); \