blob: 4ccf997dddc216fab092cd979904c11110c9c367 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2015 Brian Swetland
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25#include <app.h>
26#include <debug.h>
27#include <string.h>
28#include <stdlib.h>
29#include <printf.h>
30#include <dev/udc.h>
31
32udc_request_t *txreq;
33udc_request_t *rxreq;
34udc_endpoint_t *txept;
35udc_endpoint_t *rxept;
36
37static char rxbuf[4096];
38
39static void rx_complete(udc_request_t *req, unsigned actual, int status) {
40 //printf("rx done %d %d\n", actual, status);
41 if (status == 0) {
42 udc_request_queue(rxept, rxreq);
43 }
44}
45
46static void tx_complete(udc_request_t *req, unsigned actual, int status) {
47 //printf("tx done %d %d\n", actual, status);
48 if (status == 0) {
49 udc_request_queue(txept, txreq);
50 }
51}
52
53static void udctest_notify(udc_gadget_t *gadget, unsigned event) {
54 printf("event %d\n", event);
55 if (event == UDC_EVENT_ONLINE) {
56 udc_request_queue(rxept, rxreq);
57 udc_request_queue(txept, txreq);
58 }
59}
60
61static udc_device_t udctest_device = {
62 .vendor_id = 0x18d1,
63 .product_id = 0xdb01,
64 .version_id = 0x0100,
65 .manufacturer = "Frobozz Magic USB Device Company",
66 .product = "Frobozzco USB Device",
67 .serialno = "00000005",
68};
69
70static udc_endpoint_t *udctest_endpoints[2];
71
72static udc_gadget_t udctest_gadget = {
73 .notify = udctest_notify,
74 .ifc_class = 0xFF,
75 .ifc_subclass = 0x42,
76 .ifc_protocol = 0x01,
77 .ifc_endpoints = 2,
78 .ifc_string = "string",
79 .ept = udctest_endpoints,
80};
81
82static void udctest_init(const struct app_descriptor *app)
83{
84 printf("usbtest_init()\n");
85 udc_init(&udctest_device);
86 udctest_endpoints[0] = txept = udc_endpoint_alloc(UDC_BULK_IN, 512);
87 udctest_endpoints[1] = rxept = udc_endpoint_alloc(UDC_BULK_OUT, 512);
88 txreq = udc_request_alloc();
89 rxreq = udc_request_alloc();
90 rxreq->buffer = rxbuf;
91 rxreq->length = sizeof(rxbuf);
92 rxreq->complete = rx_complete;
93 txreq->buffer = rxbuf;
94 txreq->length = sizeof(rxbuf);
95 txreq->complete = tx_complete;
96 udc_register_gadget(&udctest_gadget);
97}
98
99static void udctest_entry(const struct app_descriptor *app, void *args)
100{
101 printf("udctest_entry()\n");
102 udc_start();
103}
104
105APP_START(usbtest)
106 .init = udctest_init,
107 .entry = udctest_entry,
108APP_END
109
110