IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit ac349b0bc0340d47c7764e60fde7a13bd930e53a created 13 years 7 months ago. By Werner Almesberger, Introduce library with ATSPI access functions (largely untested) | |
---|---|
1 | /* |
2 | * lib/atspi.c - ATSPI access functions library |
3 | * |
4 | * Written 2010 by Werner Almesberger |
5 | * Copyright 2010 Werner Almesberger |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | */ |
12 | |
13 | |
14 | #include <stdio.h> |
15 | #include <usb.h> |
16 | |
17 | #include "f32xbase/usb.h" |
18 | #include "atspi/ep0.h" |
19 | #include "atspi/usb-ids.h" |
20 | |
21 | #include "atspi.h" |
22 | |
23 | |
24 | #define FROM_DEV ATSPI_FROM_DEV(0) |
25 | #define TO_DEV ATSPI_TO_DEV(0) |
26 | |
27 | |
28 | /* ----- error handling ---------------------------------------------------- */ |
29 | |
30 | |
31 | static int error; |
32 | |
33 | |
34 | int atspi_error(void) |
35 | { |
36 | return error; |
37 | } |
38 | |
39 | |
40 | int atspi_clear_error(void) |
41 | { |
42 | int ret; |
43 | |
44 | ret = error; |
45 | error = 0; |
46 | return ret; |
47 | } |
48 | |
49 | |
50 | /* ----- open/close -------------------------------------------------------- */ |
51 | |
52 | |
53 | usb_dev_handle *atspi_open(void) |
54 | { |
55 | usb_dev_handle *dev; |
56 | |
57 | dev = open_usb(USB_VENDOR, USB_PRODUCT); |
58 | if (dev) { |
59 | error = 0; |
60 | } else { |
61 | fprintf(stderr, ":-(\n"); |
62 | error = 1; |
63 | } |
64 | return dev; |
65 | } |
66 | |
67 | |
68 | void atspi_close(usb_dev_handle *dev) |
69 | { |
70 | /* to do */ |
71 | } |
72 | |
73 | |
74 | /* ----- register access --------------------------------------------------- */ |
75 | |
76 | |
77 | void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value) |
78 | { |
79 | int res; |
80 | |
81 | if (error) |
82 | return; |
83 | |
84 | res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg, |
85 | NULL, 0, 1000); |
86 | if (res < 0) { |
87 | fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res); |
88 | error = 1; |
89 | } |
90 | } |
91 | |
92 | |
93 | uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg) |
94 | { |
95 | uint8_t value = 0; |
96 | int res; |
97 | |
98 | if (error) |
99 | return 0; |
100 | |
101 | res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg, |
102 | (void *) &value, 1, 1000); |
103 | if (res < 0) { |
104 | fprintf(stderr, "ATSPI_REG_READ: %d\n", res); |
105 | error = 1; |
106 | } |
107 | return value; |
108 | } |
109 |