1 /* If you are going to abuse the preprocessor, why not ABUSE the preprocessor?
2 I stuck this header in a separate file so I don't have to look at it */
4 // FIXME Need locking or atomic ops
6 #define show_set_mbit(dname,value,bit) \
7 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
9 struct usb_interface *intf = to_usb_interface(dev); \
10 struct usb_##dname *t = usb_get_intfdata(intf); \
11 int temp = (1 && (t->value & (1 << bit))); \
12 return sprintf(buf, "%d\n", temp); \
14 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
16 struct usb_interface *intf = to_usb_interface(dev); \
17 struct usb_##dname *t = usb_get_intfdata(intf); \
18 int temp = simple_strtoul(buf, NULL, 10); \
19 if(temp > 0) { long b = 1 << bit; t->value |= b; } \
20 else { long b = ~(1 << bit); t->value &= b ; \
23 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
25 #define show_set_ebit(dname,enumname,value,bit) \
26 static ssize_t show_##bit(struct device *dev, struct device_attribute *attr, char *buf) \
28 struct usb_interface *intf = to_usb_interface(dev); \
29 struct usb_##dname *t = usb_get_intfdata(intf); \
30 enum enumname l = bit; \
31 int temp = t->value & (1 << l); \
32 return sprintf(buf, "%d\n", temp); \
34 static ssize_t set_##bit(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
36 struct usb_interface *intf = to_usb_interface(dev); \
37 struct usb_##dname *t = usb_get_intfdata(intf); \
38 int temp = simple_strtoul(buf, NULL, 10); \
39 enum enumname l = bit;\
41 if(temp > 0) { t->value |= b; } \
42 else { t->value &= ~b ; \
45 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
47 // FIXME FOR CORRECTLY SETTING HEX from a string
48 #define show_set_mcmd(dname,value) \
49 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
51 struct usb_interface *intf = to_usb_interface(dev); \
52 struct usb_##dname *t = usb_get_intfdata(intf); \
55 for (i = 0,i<sizeof(dname); i++) count += snprintf(buf, "%02x",t->dname[i]); \
58 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
60 struct usb_interface *intf = to_usb_interface(dev); \
61 struct usb_##dname *t = usb_get_intfdata(intf); \
62 int temp = simple_strtoul(buf, NULL, 10); \
66 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
68 #define show_set_mint(dname,value) \
69 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
71 struct usb_interface *intf = to_usb_interface(dev); \
72 struct usb_##dname *t = usb_get_intfdata(intf); \
73 return sprintf(buf, "%d\n", t->value); \
75 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
77 struct usb_interface *intf = to_usb_interface(dev); \
78 struct usb_##dname *t = usb_get_intfdata(intf); \
79 int temp = simple_strtoul(buf, NULL, 10); \
83 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
85 #define show_set_mchar(dname,value) \
86 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
88 struct usb_interface *intf = to_usb_interface(dev); \
89 struct usb_##dname *t = usb_get_intfdata(intf); \
90 return sprintf(buf, "%c\n", t->value); \
92 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
94 struct usb_interface *intf = to_usb_interface(dev); \
95 struct usb_##dname *t = usb_get_intfdata(intf); \
96 int temp = simple_strtoul(buf, NULL, 10); \
100 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);