Skip to content

Commit c63a9b7

Browse files
Ahmet AlincakAhmet Alincak
authored andcommitted
Maxim targets; Add USB stack implementation
1 parent 4eaabc5 commit c63a9b7

File tree

5 files changed

+707
-0
lines changed

5 files changed

+707
-0
lines changed

targets/TARGET_Maxim/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ target_include_directories(mbed-core
1313
INTERFACE
1414
.
1515
)
16+
17+
target_sources(mbed-core
18+
INTERFACE
19+
USBPhy_Maxim.cpp
20+
)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*******************************************************************************
2+
* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
18+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* Except as contained in this notice, the name of Maxim Integrated
23+
* Products, Inc. shall not be used except as stated in the Maxim Integrated
24+
* Products, Inc. Branding Policy.
25+
*
26+
* The mere transfer of this software does not imply any licenses
27+
* of trade secrets, proprietary technology, copyrights, patents,
28+
* trademarks, maskwork rights, or any other form of intellectual
29+
* property whatsoever. Maxim Integrated Products, Inc. retains all
30+
* ownership rights.
31+
*******************************************************************************
32+
*/
33+
34+
#ifndef USBENDPOINTS_H
35+
#define USBENDPOINTS_H
36+
37+
/* SETUP packet size */
38+
#define SETUP_PACKET_SIZE (8)
39+
40+
/* Options flags for configuring endpoints */
41+
#define DEFAULT_OPTIONS (0)
42+
#define SINGLE_BUFFERED (1U << 0)
43+
#define ISOCHRONOUS (1U << 1)
44+
#define RATE_FEEDBACK_MODE (1U << 2) /* Interrupt endpoints only */
45+
46+
#define NUMBER_OF_LOGICAL_ENDPOINTS (8)
47+
#define NUMBER_OF_PHYSICAL_ENDPOINTS (NUMBER_OF_LOGICAL_ENDPOINTS * 2)
48+
49+
#define EP_TO_INDEX(endpoint) (((endpoint & 0xf) << 1) | (endpoint & 0x80 ? 1 : 0))
50+
51+
#define DIR_OUT 0x00
52+
#define DIR_IN 0x80
53+
#define EP_NUM(ep) (ep & 0x0F)
54+
#define IN_EP(ep) (ep & DIR_IN)
55+
#define OUT_EP(ep) (!(ep & DIR_IN))
56+
57+
/* Define physical endpoint numbers */
58+
59+
/* Endpoint No. */
60+
/* ---------------- */
61+
#define EP0OUT ((0 << 1) | DIR_OUT)
62+
#define EP0IN ((0 << 1) | DIR_IN)
63+
#define EP1OUT ((1 << 1) | DIR_OUT)
64+
#define EP1IN ((1 << 1) | DIR_IN)
65+
#define EP2OUT ((2 << 1) | DIR_OUT)
66+
#define EP2IN ((2 << 1) | DIR_IN)
67+
#define EP3OUT ((3 << 1) | DIR_OUT)
68+
#define EP3IN ((3 << 1) | DIR_IN)
69+
#define EP4OUT ((4 << 1) | DIR_OUT)
70+
#define EP4IN ((4 << 1) | DIR_IN)
71+
#define EP5OUT ((5 << 1) | DIR_OUT)
72+
#define EP5IN ((5 << 1) | DIR_IN)
73+
#define EP6OUT ((6 << 1) | DIR_OUT)
74+
#define EP6IN ((6 << 1) | DIR_IN)
75+
#define EP7OUT ((7 << 1) | DIR_OUT)
76+
#define EP7IN ((7 << 1) | DIR_IN)
77+
78+
/* Maximum Packet sizes */
79+
80+
#define MAX_PACKET_SIZE_EP0 (64)
81+
#define MAX_PACKET_SIZE_EP1 (64)
82+
#define MAX_PACKET_SIZE_EP2 (64)
83+
#define MAX_PACKET_SIZE_EP3 (64)
84+
#define MAX_PACKET_SIZE_EP4 (64)
85+
#define MAX_PACKET_SIZE_EP5 (64)
86+
#define MAX_PACKET_SIZE_EP6 (64)
87+
#define MAX_PACKET_SIZE_EP7 (64)
88+
89+
/* Generic endpoints - intended to be portable accross devices */
90+
/* and be suitable for simple USB devices. */
91+
92+
/* Bulk endpoints */
93+
#define EPBULK_OUT (EP1OUT)
94+
#define EPBULK_IN (EP2IN)
95+
96+
/* Interrupt endpoints */
97+
#define EPINT_OUT (EP3OUT)
98+
#define EPINT_IN (EP4IN)
99+
100+
/* Isochronous endpoints */
101+
/* NOT SUPPORTED - use invalid endpoint number to prevent built errors */
102+
#define EPISO_OUT (EP0OUT)
103+
#define EPISO_IN (EP0IN)
104+
105+
#define MAX_PACKET_SIZE_EPBULK (64)
106+
#define MAX_PACKET_SIZE_EPINT (64)
107+
108+
#endif

targets/TARGET_Maxim/USBPhyHw.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2018-2019, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef USBPHYHW_H
19+
#define USBPHYHW_H
20+
21+
#include "mbed.h"
22+
#include "USBPhy.h"
23+
24+
25+
class USBPhyHw : public USBPhy {
26+
public:
27+
USBPhyHw();
28+
virtual ~USBPhyHw();
29+
virtual void init(USBPhyEvents *events);
30+
virtual void deinit();
31+
virtual bool powered();
32+
virtual void connect();
33+
virtual void disconnect();
34+
virtual void configure();
35+
virtual void unconfigure();
36+
virtual void sof_enable();
37+
virtual void sof_disable();
38+
virtual void set_address(uint8_t address);
39+
virtual void remote_wakeup();
40+
virtual const usb_ep_table_t *endpoint_table();
41+
42+
virtual uint32_t ep0_set_max_packet(uint32_t max_packet);
43+
virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size);
44+
virtual void ep0_read(uint8_t *data, uint32_t size);
45+
virtual uint32_t ep0_read_result();
46+
virtual void ep0_write(uint8_t *buffer, uint32_t size);
47+
virtual void ep0_stall();
48+
49+
virtual bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type);
50+
virtual void endpoint_remove(usb_ep_t endpoint);
51+
virtual void endpoint_stall(usb_ep_t endpoint);
52+
virtual void endpoint_unstall(usb_ep_t endpoint);
53+
54+
virtual bool endpoint_read(usb_ep_t endpoint, uint8_t *data, uint32_t size);
55+
virtual uint32_t endpoint_read_result(usb_ep_t endpoint);
56+
virtual bool endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size);
57+
virtual void endpoint_abort(usb_ep_t endpoint);
58+
59+
virtual void process();
60+
61+
private:
62+
USBPhyEvents *events;
63+
64+
static void _usbisr(void);
65+
};
66+
67+
#endif

0 commit comments

Comments
 (0)