Skip to content

MAX32630FTHR: Port USBSerial from mbed6.x #14830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions targets/TARGET_Maxim/USBEndpoints_Maxim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* mbed Microcontroller Library
* Copyright (c) 2018-2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef USBENDPOINTS_H
#define USBENDPOINTS_H

/* SETUP packet size */
#define SETUP_PACKET_SIZE (8)

/* Options flags for configuring endpoints */
#define DEFAULT_OPTIONS (0)
#define SINGLE_BUFFERED (1U << 0)
#define ISOCHRONOUS (1U << 1)
#define RATE_FEEDBACK_MODE (1U << 2) /* Interrupt endpoints only */

#define NUMBER_OF_LOGICAL_ENDPOINTS (8)
#define NUMBER_OF_PHYSICAL_ENDPOINTS (NUMBER_OF_LOGICAL_ENDPOINTS * 2)

#define EP_TO_INDEX(endpoint) (((endpoint & 0xf) << 1) | (endpoint & 0x80 ? 1 : 0))

#define DIR_OUT 0x00
#define DIR_IN 0x80
#define EP_NUM(ep) (ep & 0x0F)
#define IN_EP(ep) (ep & DIR_IN)
#define OUT_EP(ep) (!(ep & DIR_IN))

/* Define physical endpoint numbers */

/* Endpoint No. */
/* ---------------- */
#define EP0OUT ((0 << 1) | DIR_OUT)
#define EP0IN ((0 << 1) | DIR_IN)
#define EP1OUT ((1 << 1) | DIR_OUT)
#define EP1IN ((1 << 1) | DIR_IN)
#define EP2OUT ((2 << 1) | DIR_OUT)
#define EP2IN ((2 << 1) | DIR_IN)
#define EP3OUT ((3 << 1) | DIR_OUT)
#define EP3IN ((3 << 1) | DIR_IN)
#define EP4OUT ((4 << 1) | DIR_OUT)
#define EP4IN ((4 << 1) | DIR_IN)
#define EP5OUT ((5 << 1) | DIR_OUT)
#define EP5IN ((5 << 1) | DIR_IN)
#define EP6OUT ((6 << 1) | DIR_OUT)
#define EP6IN ((6 << 1) | DIR_IN)
#define EP7OUT ((7 << 1) | DIR_OUT)
#define EP7IN ((7 << 1) | DIR_IN)

/* Maximum Packet sizes */

#define MAX_PACKET_SIZE_EP0 (64)
#define MAX_PACKET_SIZE_EP1 (64)
#define MAX_PACKET_SIZE_EP2 (64)
#define MAX_PACKET_SIZE_EP3 (64)
#define MAX_PACKET_SIZE_EP4 (64)
#define MAX_PACKET_SIZE_EP5 (64)
#define MAX_PACKET_SIZE_EP6 (64)
#define MAX_PACKET_SIZE_EP7 (64)

/* Generic endpoints - intended to be portable accross devices */
/* and be suitable for simple USB devices. */

/* Bulk endpoints */
#define EPBULK_OUT (EP1OUT)
#define EPBULK_IN (EP2IN)

/* Interrupt endpoints */
#define EPINT_OUT (EP3OUT)
#define EPINT_IN (EP4IN)

/* Isochronous endpoints */
/* NOT SUPPORTED - use invalid endpoint number to prevent built errors */
#define EPISO_OUT (EP0OUT)
#define EPISO_IN (EP0IN)

#define MAX_PACKET_SIZE_EPBULK (64)
#define MAX_PACKET_SIZE_EPINT (64)

#endif
66 changes: 66 additions & 0 deletions targets/TARGET_Maxim/USBPhyHw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2018-2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef USBPHYHW_H
#define USBPHYHW_H

#include "USBPhy.h"


class USBPhyHw : public USBPhy {
public:
USBPhyHw();
virtual ~USBPhyHw();
virtual void init(USBPhyEvents *events);
virtual void deinit();
virtual bool powered();
virtual void connect();
virtual void disconnect();
virtual void configure();
virtual void unconfigure();
virtual void sof_enable();
virtual void sof_disable();
virtual void set_address(uint8_t address);
virtual void remote_wakeup();
virtual const usb_ep_table_t *endpoint_table();

virtual uint32_t ep0_set_max_packet(uint32_t max_packet);
virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size);
virtual void ep0_read(uint8_t *data, uint32_t size);
virtual uint32_t ep0_read_result();
virtual void ep0_write(uint8_t *buffer, uint32_t size);
virtual void ep0_stall();

virtual bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type);
virtual void endpoint_remove(usb_ep_t endpoint);
virtual void endpoint_stall(usb_ep_t endpoint);
virtual void endpoint_unstall(usb_ep_t endpoint);

virtual bool endpoint_read(usb_ep_t endpoint, uint8_t *data, uint32_t size);
virtual uint32_t endpoint_read_result(usb_ep_t endpoint);
virtual bool endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size);
virtual void endpoint_abort(usb_ep_t endpoint);

virtual void process();

private:
USBPhyEvents *events;

static void _usbisr(void);
};

#endif
Loading