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 <devices/timer.h>
19 #include <aros/libcall.h>
20 #include <aros/asmcall.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
{
43 typedef struct DrvInstData
{
44 struct SignalSemaphore driver_lock
;
46 struct MinList devices
;
49 struct timerequest tr
;
61 struct i2c_staticdata
{
63 OOP_AttrBase hiddI2CAB
;
64 OOP_AttrBase hiddI2CDeviceAB
;
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
;
81 struct Library LibNode
;
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) \
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) \
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) \
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; \
125 OOP_DoMethod((__o), (OOP_Msg)__m); \
128 #define I2C_PutByte(__o, __device, __byte) \
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) \
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) \
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; \
159 OOP_DoMethod((__o), (OOP_Msg)__m); \
162 #define I2C_Address(__o, __device, __addr) \
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) \
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); \