SDG+USBHost(Mouse) Sample

Dependencies:   Sound_Generator USBHost_custom

Fork of SDG_Mouse_Sample by GR-PEACH_producer_meeting

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

What is this?

This program is a demonstration that sounds the sound by mouse operation by using USBHost(Mouse) and Sound Generator.

Settings

Close JP3 of GR-PEACH.
/media/uploads/RyoheiHagimoto/sdg-mouse.jpg

Operation

operationeffect
Right clickSounds
Left clickReset to base tone (C)
Moves the mouse to the rightLower the sound
Moves the mouse to the leftHigher the sound
Center cursorAdjust the sensitivity.
Reset the reference value in the click.

Others

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication


概要

このプログラムは、USBHost(Mouse) + Sound Generatorで、マウス操作による擬似笛デモです。

設定

GR-PEACHのJP3をショートする必要があります。
/media/uploads/RyoheiHagimoto/sdg-mouse.jpg

操作方法

操作内容
右クリック音出力開始
左クリック基準音(ド)にリセット
マウス右移動高音になります
マウス左移動低音になります
センターカーソル音高低の変化量調整(クリックで基準値にリセット)

Others

mbedのシリアル通信(ボーレート等)のデフォルト設定は以下のリンクに示しています。
リンクを参考に、お使いのPCターミナルソフトの設定を変更して下さい。
mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Committer:
mbed_official
Date:
Mon Jan 19 14:30:37 2015 +0000
Revision:
27:4206883f4cb7
Synchronized with git revision 0ab8d2e6b3d884137dcb5c62d29a07abe132bac7

Full URL: https://github.com/mbedmicro/mbed/commit/0ab8d2e6b3d884137dcb5c62d29a07abe132bac7/

RZ_A1H - Implement some USB functions and fix some bugs about USBHost common codes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 27:4206883f4cb7 1 /*******************************************************************************
mbed_official 27:4206883f4cb7 2 * DISCLAIMER
mbed_official 27:4206883f4cb7 3 * This software is supplied by Renesas Electronics Corporation and is only
mbed_official 27:4206883f4cb7 4 * intended for use with Renesas products. No other uses are authorized. This
mbed_official 27:4206883f4cb7 5 * software is owned by Renesas Electronics Corporation and is protected under
mbed_official 27:4206883f4cb7 6 * all applicable laws, including copyright laws.
mbed_official 27:4206883f4cb7 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
mbed_official 27:4206883f4cb7 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
mbed_official 27:4206883f4cb7 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
mbed_official 27:4206883f4cb7 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
mbed_official 27:4206883f4cb7 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
mbed_official 27:4206883f4cb7 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
mbed_official 27:4206883f4cb7 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
mbed_official 27:4206883f4cb7 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
mbed_official 27:4206883f4cb7 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
mbed_official 27:4206883f4cb7 16 * Renesas reserves the right, without notice, to make changes to this software
mbed_official 27:4206883f4cb7 17 * and to discontinue the availability of this software. By using this software,
mbed_official 27:4206883f4cb7 18 * you agree to the additional terms and conditions found by accessing the
mbed_official 27:4206883f4cb7 19 * following link:
mbed_official 27:4206883f4cb7 20 * http://www.renesas.com/disclaimer
mbed_official 27:4206883f4cb7 21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
mbed_official 27:4206883f4cb7 22 *******************************************************************************/
mbed_official 27:4206883f4cb7 23 /*******************************************************************************
mbed_official 27:4206883f4cb7 24 * File Name : usb0_host_drv_api.c
mbed_official 27:4206883f4cb7 25 * $Rev: 1116 $
mbed_official 27:4206883f4cb7 26 * $Date:: 2014-07-09 16:29:19 +0900#$
mbed_official 27:4206883f4cb7 27 * Device(s) : RZ/A1H
mbed_official 27:4206883f4cb7 28 * Tool-Chain :
mbed_official 27:4206883f4cb7 29 * OS : None
mbed_official 27:4206883f4cb7 30 * H/W Platform :
mbed_official 27:4206883f4cb7 31 * Description : RZ/A1H R7S72100 USB Sample Program
mbed_official 27:4206883f4cb7 32 * Operation :
mbed_official 27:4206883f4cb7 33 * Limitations :
mbed_official 27:4206883f4cb7 34 *******************************************************************************/
mbed_official 27:4206883f4cb7 35
mbed_official 27:4206883f4cb7 36
mbed_official 27:4206883f4cb7 37 /*******************************************************************************
mbed_official 27:4206883f4cb7 38 Includes <System Includes> , "Project Includes"
mbed_official 27:4206883f4cb7 39 *******************************************************************************/
mbed_official 27:4206883f4cb7 40 #include "usb0_host.h"
mbed_official 27:4206883f4cb7 41 #include "dev_drv.h"
mbed_official 27:4206883f4cb7 42
mbed_official 27:4206883f4cb7 43
mbed_official 27:4206883f4cb7 44 /*******************************************************************************
mbed_official 27:4206883f4cb7 45 Typedef definitions
mbed_official 27:4206883f4cb7 46 *******************************************************************************/
mbed_official 27:4206883f4cb7 47
mbed_official 27:4206883f4cb7 48
mbed_official 27:4206883f4cb7 49 /*******************************************************************************
mbed_official 27:4206883f4cb7 50 Macro definitions
mbed_official 27:4206883f4cb7 51 *******************************************************************************/
mbed_official 27:4206883f4cb7 52
mbed_official 27:4206883f4cb7 53
mbed_official 27:4206883f4cb7 54 /*******************************************************************************
mbed_official 27:4206883f4cb7 55 Imported global variables and functions (from other files)
mbed_official 27:4206883f4cb7 56 *******************************************************************************/
mbed_official 27:4206883f4cb7 57
mbed_official 27:4206883f4cb7 58
mbed_official 27:4206883f4cb7 59 /*******************************************************************************
mbed_official 27:4206883f4cb7 60 Exported global variables and functions (to be accessed by other files)
mbed_official 27:4206883f4cb7 61 *******************************************************************************/
mbed_official 27:4206883f4cb7 62 static void usb0_host_resetEP(USB_HOST_CFG_PIPETBL_t *tbl);
mbed_official 27:4206883f4cb7 63
mbed_official 27:4206883f4cb7 64
mbed_official 27:4206883f4cb7 65 /*******************************************************************************
mbed_official 27:4206883f4cb7 66 Private global variables and functions
mbed_official 27:4206883f4cb7 67 *******************************************************************************/
mbed_official 27:4206883f4cb7 68
mbed_official 27:4206883f4cb7 69
mbed_official 27:4206883f4cb7 70 /*******************************************************************************
mbed_official 27:4206883f4cb7 71 * Function Name: usb0_api_host_init
mbed_official 27:4206883f4cb7 72 * Description : Initializes USB module in the USB host mode.
mbed_official 27:4206883f4cb7 73 * : USB connection is executed when executing this function in
mbed_official 27:4206883f4cb7 74 * : the states that USB device isconnected to the USB port.
mbed_official 27:4206883f4cb7 75 * Arguments : uint8_t int_level : USB Module interrupt level
mbed_official 27:4206883f4cb7 76 * : USBU16 mode : USB_HOST_HIGH_SPEED
mbed_official 27:4206883f4cb7 77 * : USB_HOST_FULL_SPEED
mbed_official 27:4206883f4cb7 78 * : uint16_t clockmode : USB Clock mode
mbed_official 27:4206883f4cb7 79 * Return Value : USB detach or attach
mbed_official 27:4206883f4cb7 80 * : USB_HOST_ATTACH
mbed_official 27:4206883f4cb7 81 * : USB_HOST_DETACH
mbed_official 27:4206883f4cb7 82 *******************************************************************************/
mbed_official 27:4206883f4cb7 83 uint16_t usb0_api_host_init (uint8_t int_level, uint16_t mode, uint16_t clockmode)
mbed_official 27:4206883f4cb7 84 {
mbed_official 27:4206883f4cb7 85 uint16_t connect;
mbed_official 27:4206883f4cb7 86 volatile uint8_t dummy_buf;
mbed_official 27:4206883f4cb7 87
mbed_official 27:4206883f4cb7 88 CPG.STBCR7 &= 0xfd; /*The clock of USB0 modules is permitted */
mbed_official 27:4206883f4cb7 89 dummy_buf = CPG.STBCR7; /* (Dummy read) */
mbed_official 27:4206883f4cb7 90
mbed_official 27:4206883f4cb7 91 g_usb0_host_SupportUsbDeviceSpeed = mode;
mbed_official 27:4206883f4cb7 92
mbed_official 27:4206883f4cb7 93 usb0_host_setting_interrupt(int_level);
mbed_official 27:4206883f4cb7 94 usb0_host_reset_module(clockmode);
mbed_official 27:4206883f4cb7 95
mbed_official 27:4206883f4cb7 96 g_usb0_host_bchg_flag = USB_HOST_NO;
mbed_official 27:4206883f4cb7 97 g_usb0_host_detach_flag = USB_HOST_NO;
mbed_official 27:4206883f4cb7 98 g_usb0_host_attach_flag = USB_HOST_NO;
mbed_official 27:4206883f4cb7 99
mbed_official 27:4206883f4cb7 100 g_usb0_host_driver_state = USB_HOST_DRV_DETACHED;
mbed_official 27:4206883f4cb7 101 g_usb0_host_default_max_packet[USB_HOST_DEVICE_0] = 64;
mbed_official 27:4206883f4cb7 102
mbed_official 27:4206883f4cb7 103 usb0_host_InitModule();
mbed_official 27:4206883f4cb7 104
mbed_official 27:4206883f4cb7 105 connect = usb0_host_CheckAttach();
mbed_official 27:4206883f4cb7 106
mbed_official 27:4206883f4cb7 107 if (connect == USB_HOST_ATTACH)
mbed_official 27:4206883f4cb7 108 {
mbed_official 27:4206883f4cb7 109 g_usb0_host_attach_flag = USB_HOST_YES;
mbed_official 27:4206883f4cb7 110 }
mbed_official 27:4206883f4cb7 111 else
mbed_official 27:4206883f4cb7 112 {
mbed_official 27:4206883f4cb7 113 usb0_host_UsbDetach2();
mbed_official 27:4206883f4cb7 114 }
mbed_official 27:4206883f4cb7 115
mbed_official 27:4206883f4cb7 116 return connect;
mbed_official 27:4206883f4cb7 117 }
mbed_official 27:4206883f4cb7 118
mbed_official 27:4206883f4cb7 119 #if(1) /* ohci_wrapp */
mbed_official 27:4206883f4cb7 120 #else
mbed_official 27:4206883f4cb7 121 /*******************************************************************************
mbed_official 27:4206883f4cb7 122 * Function Name: usb0_api_host_enumeration
mbed_official 27:4206883f4cb7 123 * Description : Initializes USB module in the USB host mode.
mbed_official 27:4206883f4cb7 124 * : USB connection is executed when executing this function in
mbed_official 27:4206883f4cb7 125 * : the states that USB device isconnected to the USB port.
mbed_official 27:4206883f4cb7 126 * Arguments : uint16_t devadr : device address
mbed_official 27:4206883f4cb7 127 * Return Value : DEVDRV_USBH_DETACH_ERR : device detach
mbed_official 27:4206883f4cb7 128 * : DEVDRV_SUCCESS : device enumeration success
mbed_official 27:4206883f4cb7 129 * : DEVDRV_ERROR : device enumeration error
mbed_official 27:4206883f4cb7 130 *******************************************************************************/
mbed_official 27:4206883f4cb7 131 int32_t usb0_api_host_enumeration (uint16_t devadr)
mbed_official 27:4206883f4cb7 132 {
mbed_official 27:4206883f4cb7 133 int32_t ret;
mbed_official 27:4206883f4cb7 134 uint16_t driver_sts;
mbed_official 27:4206883f4cb7 135
mbed_official 27:4206883f4cb7 136 g_usb0_host_setUsbAddress = devadr;
mbed_official 27:4206883f4cb7 137
mbed_official 27:4206883f4cb7 138 while (1)
mbed_official 27:4206883f4cb7 139 {
mbed_official 27:4206883f4cb7 140 driver_sts = usb0_api_host_GetUsbDeviceState();
mbed_official 27:4206883f4cb7 141
mbed_official 27:4206883f4cb7 142 if (driver_sts == USB_HOST_DRV_DETACHED)
mbed_official 27:4206883f4cb7 143 {
mbed_official 27:4206883f4cb7 144 ret = DEVDRV_USBH_DETACH_ERR;
mbed_official 27:4206883f4cb7 145 break;
mbed_official 27:4206883f4cb7 146 }
mbed_official 27:4206883f4cb7 147 else if (driver_sts == USB_HOST_DRV_CONFIGURED)
mbed_official 27:4206883f4cb7 148 {
mbed_official 27:4206883f4cb7 149 ret = DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 150 break;
mbed_official 27:4206883f4cb7 151 }
mbed_official 27:4206883f4cb7 152 else if (driver_sts == USB_HOST_DRV_STALL)
mbed_official 27:4206883f4cb7 153 {
mbed_official 27:4206883f4cb7 154 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 155 break;
mbed_official 27:4206883f4cb7 156 }
mbed_official 27:4206883f4cb7 157 else if (driver_sts == USB_HOST_DRV_NORES)
mbed_official 27:4206883f4cb7 158 {
mbed_official 27:4206883f4cb7 159 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 160 break;
mbed_official 27:4206883f4cb7 161 }
mbed_official 27:4206883f4cb7 162 else
mbed_official 27:4206883f4cb7 163 {
mbed_official 27:4206883f4cb7 164 /* Do Nothing */
mbed_official 27:4206883f4cb7 165 }
mbed_official 27:4206883f4cb7 166 }
mbed_official 27:4206883f4cb7 167
mbed_official 27:4206883f4cb7 168 if (driver_sts == USB_HOST_DRV_NORES)
mbed_official 27:4206883f4cb7 169 {
mbed_official 27:4206883f4cb7 170 while (1)
mbed_official 27:4206883f4cb7 171 {
mbed_official 27:4206883f4cb7 172 driver_sts = usb0_api_host_GetUsbDeviceState();
mbed_official 27:4206883f4cb7 173
mbed_official 27:4206883f4cb7 174 if (driver_sts == USB_HOST_DRV_DETACHED)
mbed_official 27:4206883f4cb7 175 {
mbed_official 27:4206883f4cb7 176 break;
mbed_official 27:4206883f4cb7 177 }
mbed_official 27:4206883f4cb7 178 }
mbed_official 27:4206883f4cb7 179 }
mbed_official 27:4206883f4cb7 180
mbed_official 27:4206883f4cb7 181 return ret;
mbed_official 27:4206883f4cb7 182 }
mbed_official 27:4206883f4cb7 183
mbed_official 27:4206883f4cb7 184 /*******************************************************************************
mbed_official 27:4206883f4cb7 185 * Function Name: usb0_api_host_detach
mbed_official 27:4206883f4cb7 186 * Description : USB detach routine
mbed_official 27:4206883f4cb7 187 * Arguments : none
mbed_official 27:4206883f4cb7 188 * Return Value : USB_HOST_DETACH : USB detach
mbed_official 27:4206883f4cb7 189 * : USB_HOST_ATTACH : USB attach
mbed_official 27:4206883f4cb7 190 * : DEVDRV_ERROR : error
mbed_official 27:4206883f4cb7 191 *******************************************************************************/
mbed_official 27:4206883f4cb7 192 int32_t usb0_api_host_detach (void)
mbed_official 27:4206883f4cb7 193 {
mbed_official 27:4206883f4cb7 194 int32_t ret;
mbed_official 27:4206883f4cb7 195 uint16_t driver_sts;
mbed_official 27:4206883f4cb7 196
mbed_official 27:4206883f4cb7 197 while (1)
mbed_official 27:4206883f4cb7 198 {
mbed_official 27:4206883f4cb7 199 driver_sts = usb0_api_host_GetUsbDeviceState();
mbed_official 27:4206883f4cb7 200
mbed_official 27:4206883f4cb7 201 if (driver_sts == USB_HOST_DRV_DETACHED)
mbed_official 27:4206883f4cb7 202 {
mbed_official 27:4206883f4cb7 203 ret = USB_HOST_DETACH;
mbed_official 27:4206883f4cb7 204 break;
mbed_official 27:4206883f4cb7 205 }
mbed_official 27:4206883f4cb7 206 else if (driver_sts == USB_HOST_DRV_CONFIGURED)
mbed_official 27:4206883f4cb7 207 {
mbed_official 27:4206883f4cb7 208 ret = USB_HOST_ATTACH;
mbed_official 27:4206883f4cb7 209 break;
mbed_official 27:4206883f4cb7 210 }
mbed_official 27:4206883f4cb7 211 else if (driver_sts == USB_HOST_DRV_STALL)
mbed_official 27:4206883f4cb7 212 {
mbed_official 27:4206883f4cb7 213 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 214 break;
mbed_official 27:4206883f4cb7 215 }
mbed_official 27:4206883f4cb7 216 else if (driver_sts == USB_HOST_DRV_NORES)
mbed_official 27:4206883f4cb7 217 {
mbed_official 27:4206883f4cb7 218 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 219 break;
mbed_official 27:4206883f4cb7 220 }
mbed_official 27:4206883f4cb7 221 else
mbed_official 27:4206883f4cb7 222 {
mbed_official 27:4206883f4cb7 223 /* Do Nothing */
mbed_official 27:4206883f4cb7 224 }
mbed_official 27:4206883f4cb7 225 }
mbed_official 27:4206883f4cb7 226
mbed_official 27:4206883f4cb7 227 if (driver_sts == USB_HOST_DRV_NORES)
mbed_official 27:4206883f4cb7 228 {
mbed_official 27:4206883f4cb7 229 while (1)
mbed_official 27:4206883f4cb7 230 {
mbed_official 27:4206883f4cb7 231 driver_sts = usb0_api_host_GetUsbDeviceState();
mbed_official 27:4206883f4cb7 232
mbed_official 27:4206883f4cb7 233 if (driver_sts == USB_HOST_DRV_DETACHED)
mbed_official 27:4206883f4cb7 234 {
mbed_official 27:4206883f4cb7 235 break;
mbed_official 27:4206883f4cb7 236 }
mbed_official 27:4206883f4cb7 237 }
mbed_official 27:4206883f4cb7 238 }
mbed_official 27:4206883f4cb7 239
mbed_official 27:4206883f4cb7 240 return ret;
mbed_official 27:4206883f4cb7 241 }
mbed_official 27:4206883f4cb7 242
mbed_official 27:4206883f4cb7 243 /*******************************************************************************
mbed_official 27:4206883f4cb7 244 * Function Name: usb0_api_host_data_in
mbed_official 27:4206883f4cb7 245 * Description : Executes USB transfer as data-in in the argument specified pipe.
mbed_official 27:4206883f4cb7 246 * Arguments : uint16_t devadr ; device address
mbed_official 27:4206883f4cb7 247 * : uint16_t Pipe ; Pipe Number
mbed_official 27:4206883f4cb7 248 * : uint32_t Size ; Data Size
mbed_official 27:4206883f4cb7 249 * : uint8_t *data_buf ; Data data_buf Address
mbed_official 27:4206883f4cb7 250 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 251 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 252 *******************************************************************************/
mbed_official 27:4206883f4cb7 253 int32_t usb0_api_host_data_in (uint16_t devadr, uint16_t Pipe, uint32_t Size, uint8_t * data_buf)
mbed_official 27:4206883f4cb7 254 {
mbed_official 27:4206883f4cb7 255 int32_t ret;
mbed_official 27:4206883f4cb7 256
mbed_official 27:4206883f4cb7 257 if (Pipe == USB_HOST_PIPE0)
mbed_official 27:4206883f4cb7 258 {
mbed_official 27:4206883f4cb7 259 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 260 }
mbed_official 27:4206883f4cb7 261
mbed_official 27:4206883f4cb7 262 if (RZA_IO_RegRead_16(&g_usb0_host_pipemaxp[Pipe], USB_PIPEMAXP_DEVSEL_SHIFT, USB_PIPEMAXP_DEVSEL) != devadr)
mbed_official 27:4206883f4cb7 263 {
mbed_official 27:4206883f4cb7 264 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 265 }
mbed_official 27:4206883f4cb7 266
mbed_official 27:4206883f4cb7 267 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[Pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 1)
mbed_official 27:4206883f4cb7 268 {
mbed_official 27:4206883f4cb7 269 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 270 }
mbed_official 27:4206883f4cb7 271
mbed_official 27:4206883f4cb7 272 if (g_usb0_host_pipe_status[Pipe] == USB_HOST_PIPE_IDLE)
mbed_official 27:4206883f4cb7 273 {
mbed_official 27:4206883f4cb7 274 usb0_host_start_receive_transfer(Pipe, Size, data_buf);
mbed_official 27:4206883f4cb7 275 }
mbed_official 27:4206883f4cb7 276 else
mbed_official 27:4206883f4cb7 277 {
mbed_official 27:4206883f4cb7 278 return DEVDRV_ERROR; /* Now pipe is busy */
mbed_official 27:4206883f4cb7 279 }
mbed_official 27:4206883f4cb7 280
mbed_official 27:4206883f4cb7 281 /* waiting for completing routine */
mbed_official 27:4206883f4cb7 282 do
mbed_official 27:4206883f4cb7 283 {
mbed_official 27:4206883f4cb7 284 if (g_usb0_host_detach_flag == USB_HOST_YES)
mbed_official 27:4206883f4cb7 285 {
mbed_official 27:4206883f4cb7 286 break;
mbed_official 27:4206883f4cb7 287 }
mbed_official 27:4206883f4cb7 288
mbed_official 27:4206883f4cb7 289 if ((g_usb0_host_pipe_status[Pipe] != USB_HOST_PIPE_IDLE) && (g_usb0_host_pipe_status[Pipe] != USB_HOST_PIPE_WAIT))
mbed_official 27:4206883f4cb7 290 {
mbed_official 27:4206883f4cb7 291 break;
mbed_official 27:4206883f4cb7 292 }
mbed_official 27:4206883f4cb7 293
mbed_official 27:4206883f4cb7 294 } while (1);
mbed_official 27:4206883f4cb7 295
mbed_official 27:4206883f4cb7 296 if (g_usb0_host_detach_flag == USB_HOST_YES)
mbed_official 27:4206883f4cb7 297 {
mbed_official 27:4206883f4cb7 298 return DEVDRV_USBH_DETACH_ERR;
mbed_official 27:4206883f4cb7 299 }
mbed_official 27:4206883f4cb7 300
mbed_official 27:4206883f4cb7 301 switch (g_usb0_host_pipe_status[Pipe])
mbed_official 27:4206883f4cb7 302 {
mbed_official 27:4206883f4cb7 303 case USB_HOST_PIPE_DONE:
mbed_official 27:4206883f4cb7 304 ret = DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 305 break;
mbed_official 27:4206883f4cb7 306
mbed_official 27:4206883f4cb7 307 case USB_HOST_PIPE_STALL:
mbed_official 27:4206883f4cb7 308 ret = DEVDRV_USBH_STALL;
mbed_official 27:4206883f4cb7 309 break;
mbed_official 27:4206883f4cb7 310
mbed_official 27:4206883f4cb7 311 case USB_HOST_PIPE_NORES:
mbed_official 27:4206883f4cb7 312 ret = DEVDRV_USBH_COM_ERR;
mbed_official 27:4206883f4cb7 313 break;
mbed_official 27:4206883f4cb7 314
mbed_official 27:4206883f4cb7 315 default:
mbed_official 27:4206883f4cb7 316 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 317 break;
mbed_official 27:4206883f4cb7 318 }
mbed_official 27:4206883f4cb7 319
mbed_official 27:4206883f4cb7 320 usb0_host_stop_transfer(Pipe);
mbed_official 27:4206883f4cb7 321
mbed_official 27:4206883f4cb7 322 g_usb0_host_pipe_status[Pipe] = USB_HOST_PIPE_IDLE;
mbed_official 27:4206883f4cb7 323
mbed_official 27:4206883f4cb7 324 return ret;
mbed_official 27:4206883f4cb7 325 }
mbed_official 27:4206883f4cb7 326
mbed_official 27:4206883f4cb7 327 /*******************************************************************************
mbed_official 27:4206883f4cb7 328 * Function Name: usb0_api_host_data_out
mbed_official 27:4206883f4cb7 329 * Description : Executes USB transfer as data-out in the argument specified pipe.
mbed_official 27:4206883f4cb7 330 * Arguments : uint16_t devadr ; device address
mbed_official 27:4206883f4cb7 331 * : uint16_t Pipe ; Pipe Number
mbed_official 27:4206883f4cb7 332 * : uint32_t Size ; Data Size
mbed_official 27:4206883f4cb7 333 * : uint8_t *data_buf ; Data data_buf Address
mbed_official 27:4206883f4cb7 334 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 335 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 336 *******************************************************************************/
mbed_official 27:4206883f4cb7 337 int32_t usb0_api_host_data_out (uint16_t devadr, uint16_t Pipe, uint32_t Size, uint8_t * data_buf)
mbed_official 27:4206883f4cb7 338 {
mbed_official 27:4206883f4cb7 339 int32_t ret;
mbed_official 27:4206883f4cb7 340
mbed_official 27:4206883f4cb7 341 if (Pipe == USB_HOST_PIPE0)
mbed_official 27:4206883f4cb7 342 {
mbed_official 27:4206883f4cb7 343 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 344 }
mbed_official 27:4206883f4cb7 345
mbed_official 27:4206883f4cb7 346 if (RZA_IO_RegRead_16(&g_usb0_host_pipemaxp[Pipe], USB_PIPEMAXP_DEVSEL_SHIFT, USB_PIPEMAXP_DEVSEL) != devadr)
mbed_official 27:4206883f4cb7 347 {
mbed_official 27:4206883f4cb7 348 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 349 }
mbed_official 27:4206883f4cb7 350
mbed_official 27:4206883f4cb7 351 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[Pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
mbed_official 27:4206883f4cb7 352 {
mbed_official 27:4206883f4cb7 353 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 354 }
mbed_official 27:4206883f4cb7 355
mbed_official 27:4206883f4cb7 356 if (g_usb0_host_pipe_status[Pipe] == USB_HOST_PIPE_IDLE)
mbed_official 27:4206883f4cb7 357 {
mbed_official 27:4206883f4cb7 358 usb0_host_start_send_transfer(Pipe, Size, data_buf);
mbed_official 27:4206883f4cb7 359 }
mbed_official 27:4206883f4cb7 360 else
mbed_official 27:4206883f4cb7 361 {
mbed_official 27:4206883f4cb7 362 return DEVDRV_ERROR; /* Now pipe is busy */
mbed_official 27:4206883f4cb7 363 }
mbed_official 27:4206883f4cb7 364
mbed_official 27:4206883f4cb7 365 /* waiting for completing routine */
mbed_official 27:4206883f4cb7 366 do
mbed_official 27:4206883f4cb7 367 {
mbed_official 27:4206883f4cb7 368 if (g_usb0_host_detach_flag == USB_HOST_YES)
mbed_official 27:4206883f4cb7 369 {
mbed_official 27:4206883f4cb7 370 break;
mbed_official 27:4206883f4cb7 371 }
mbed_official 27:4206883f4cb7 372
mbed_official 27:4206883f4cb7 373 if ((g_usb0_host_pipe_status[Pipe] != USB_HOST_PIPE_IDLE) && (g_usb0_host_pipe_status[Pipe] != USB_HOST_PIPE_WAIT))
mbed_official 27:4206883f4cb7 374 {
mbed_official 27:4206883f4cb7 375 break;
mbed_official 27:4206883f4cb7 376 }
mbed_official 27:4206883f4cb7 377
mbed_official 27:4206883f4cb7 378 } while (1);
mbed_official 27:4206883f4cb7 379
mbed_official 27:4206883f4cb7 380 if (g_usb0_host_detach_flag == USB_HOST_YES)
mbed_official 27:4206883f4cb7 381 {
mbed_official 27:4206883f4cb7 382 return DEVDRV_USBH_DETACH_ERR;
mbed_official 27:4206883f4cb7 383 }
mbed_official 27:4206883f4cb7 384
mbed_official 27:4206883f4cb7 385 switch (g_usb0_host_pipe_status[Pipe])
mbed_official 27:4206883f4cb7 386 {
mbed_official 27:4206883f4cb7 387 case USB_HOST_PIPE_DONE:
mbed_official 27:4206883f4cb7 388 ret = DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 389 break;
mbed_official 27:4206883f4cb7 390
mbed_official 27:4206883f4cb7 391 case USB_HOST_PIPE_STALL:
mbed_official 27:4206883f4cb7 392 ret = DEVDRV_USBH_STALL;
mbed_official 27:4206883f4cb7 393 break;
mbed_official 27:4206883f4cb7 394
mbed_official 27:4206883f4cb7 395 case USB_HOST_PIPE_NORES:
mbed_official 27:4206883f4cb7 396 ret = DEVDRV_USBH_COM_ERR;
mbed_official 27:4206883f4cb7 397 break;
mbed_official 27:4206883f4cb7 398
mbed_official 27:4206883f4cb7 399 default:
mbed_official 27:4206883f4cb7 400 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 401 break;
mbed_official 27:4206883f4cb7 402 }
mbed_official 27:4206883f4cb7 403
mbed_official 27:4206883f4cb7 404 usb0_host_stop_transfer(Pipe);
mbed_official 27:4206883f4cb7 405
mbed_official 27:4206883f4cb7 406 g_usb0_host_pipe_status[Pipe] = USB_HOST_PIPE_IDLE;
mbed_official 27:4206883f4cb7 407
mbed_official 27:4206883f4cb7 408 return ret;
mbed_official 27:4206883f4cb7 409 }
mbed_official 27:4206883f4cb7 410
mbed_official 27:4206883f4cb7 411 /*******************************************************************************
mbed_official 27:4206883f4cb7 412 * Function Name: usb0_api_host_control_transfer
mbed_official 27:4206883f4cb7 413 * Description : Executes USB control transfer.
mbed_official 27:4206883f4cb7 414 * Arguments : uint16_t devadr ; device address
mbed_official 27:4206883f4cb7 415 * : uint16_t Req ; bmRequestType & bRequest
mbed_official 27:4206883f4cb7 416 * : uint16_t Val ; wValue
mbed_official 27:4206883f4cb7 417 * : uint16_t Indx ; wIndex
mbed_official 27:4206883f4cb7 418 * : uint16_t Len ; wLength
mbed_official 27:4206883f4cb7 419 * : uint8_t *buf ; Buffer
mbed_official 27:4206883f4cb7 420 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 421 * : DEVDRV_USBH_DETACH_ERR ; device detach
mbed_official 27:4206883f4cb7 422 * : DEVDRV_USBH_CTRL_COM_ERR ; device no response
mbed_official 27:4206883f4cb7 423 * : DEVDRV_USBH_STALL ; STALL
mbed_official 27:4206883f4cb7 424 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 425 *******************************************************************************/
mbed_official 27:4206883f4cb7 426 int32_t usb0_api_host_control_transfer (uint16_t devadr, uint16_t Req, uint16_t Val, uint16_t Indx,
mbed_official 27:4206883f4cb7 427 uint16_t Len, uint8_t * Buf)
mbed_official 27:4206883f4cb7 428 {
mbed_official 27:4206883f4cb7 429 int32_t ret;
mbed_official 27:4206883f4cb7 430
mbed_official 27:4206883f4cb7 431 do
mbed_official 27:4206883f4cb7 432 {
mbed_official 27:4206883f4cb7 433 ret = usb0_host_CtrlTransStart(devadr, Req, Val, Indx, Len, Buf);
mbed_official 27:4206883f4cb7 434
mbed_official 27:4206883f4cb7 435 if (ret == DEVDRV_SUCCESS)
mbed_official 27:4206883f4cb7 436 {
mbed_official 27:4206883f4cb7 437 if (g_usb0_host_detach_flag == USB_HOST_YES)
mbed_official 27:4206883f4cb7 438 {
mbed_official 27:4206883f4cb7 439 break;
mbed_official 27:4206883f4cb7 440 }
mbed_official 27:4206883f4cb7 441
mbed_official 27:4206883f4cb7 442 if ((g_usb0_host_pipe_status[USB_HOST_PIPE0] != USB_HOST_PIPE_IDLE)
mbed_official 27:4206883f4cb7 443 && (g_usb0_host_pipe_status[USB_HOST_PIPE0] != USB_HOST_PIPE_WAIT))
mbed_official 27:4206883f4cb7 444 {
mbed_official 27:4206883f4cb7 445 break;
mbed_official 27:4206883f4cb7 446 }
mbed_official 27:4206883f4cb7 447 }
mbed_official 27:4206883f4cb7 448 else
mbed_official 27:4206883f4cb7 449 {
mbed_official 27:4206883f4cb7 450 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 451 }
mbed_official 27:4206883f4cb7 452 } while (1);
mbed_official 27:4206883f4cb7 453
mbed_official 27:4206883f4cb7 454 if (g_usb0_host_detach_flag == USB_HOST_YES)
mbed_official 27:4206883f4cb7 455 {
mbed_official 27:4206883f4cb7 456 return DEVDRV_USBH_DETACH_ERR;
mbed_official 27:4206883f4cb7 457 }
mbed_official 27:4206883f4cb7 458
mbed_official 27:4206883f4cb7 459 switch (g_usb0_host_pipe_status[USB_HOST_PIPE0])
mbed_official 27:4206883f4cb7 460 {
mbed_official 27:4206883f4cb7 461 case USB_HOST_PIPE_DONE:
mbed_official 27:4206883f4cb7 462 ret = DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 463 break;
mbed_official 27:4206883f4cb7 464
mbed_official 27:4206883f4cb7 465 case USB_HOST_PIPE_STALL:
mbed_official 27:4206883f4cb7 466 ret = DEVDRV_USBH_STALL;
mbed_official 27:4206883f4cb7 467 break;
mbed_official 27:4206883f4cb7 468
mbed_official 27:4206883f4cb7 469 case USB_HOST_PIPE_NORES:
mbed_official 27:4206883f4cb7 470 ret = DEVDRV_USBH_CTRL_COM_ERR;
mbed_official 27:4206883f4cb7 471 break;
mbed_official 27:4206883f4cb7 472
mbed_official 27:4206883f4cb7 473 default:
mbed_official 27:4206883f4cb7 474 ret = DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 475 break;
mbed_official 27:4206883f4cb7 476 }
mbed_official 27:4206883f4cb7 477
mbed_official 27:4206883f4cb7 478 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_IDLE;
mbed_official 27:4206883f4cb7 479
mbed_official 27:4206883f4cb7 480 return ret;
mbed_official 27:4206883f4cb7 481 }
mbed_official 27:4206883f4cb7 482
mbed_official 27:4206883f4cb7 483 /*******************************************************************************
mbed_official 27:4206883f4cb7 484 * Function Name: usb0_api_host_set_endpoint
mbed_official 27:4206883f4cb7 485 * Description : Sets end point on the information specified in the argument.
mbed_official 27:4206883f4cb7 486 * Arguments : uint16_t devadr ; device address
mbed_official 27:4206883f4cb7 487 * : uint8_t *configdescriptor ; device configration descriptor
mbed_official 27:4206883f4cb7 488 * : USB_HOST_CFG_PIPETBL_t *user_table ; pipe table
mbed_official 27:4206883f4cb7 489 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 490 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 491 *******************************************************************************/
mbed_official 27:4206883f4cb7 492 int32_t usb0_api_host_set_endpoint (uint16_t devadr, USB_HOST_CFG_PIPETBL_t * user_table, uint8_t * configdescriptor)
mbed_official 27:4206883f4cb7 493 {
mbed_official 27:4206883f4cb7 494 uint16_t ret;
mbed_official 27:4206883f4cb7 495 uint32_t end_point;
mbed_official 27:4206883f4cb7 496 uint32_t offset;
mbed_official 27:4206883f4cb7 497 uint32_t totalLength;
mbed_official 27:4206883f4cb7 498 USB_HOST_CFG_PIPETBL_t * pipe_table;
mbed_official 27:4206883f4cb7 499
mbed_official 27:4206883f4cb7 500 /* End Point Search */
mbed_official 27:4206883f4cb7 501 end_point = 0;
mbed_official 27:4206883f4cb7 502 offset = configdescriptor[0];
mbed_official 27:4206883f4cb7 503 totalLength = (uint16_t)(configdescriptor[2] + ((uint16_t)configdescriptor[3] << 8));
mbed_official 27:4206883f4cb7 504
mbed_official 27:4206883f4cb7 505 do
mbed_official 27:4206883f4cb7 506 {
mbed_official 27:4206883f4cb7 507 if (configdescriptor[offset + 1] == USB_HOST_ENDPOINT_DESC)
mbed_official 27:4206883f4cb7 508 {
mbed_official 27:4206883f4cb7 509 pipe_table = &user_table[end_point];
mbed_official 27:4206883f4cb7 510
mbed_official 27:4206883f4cb7 511 if (pipe_table->pipe_number == 0xffff)
mbed_official 27:4206883f4cb7 512 {
mbed_official 27:4206883f4cb7 513 break;
mbed_official 27:4206883f4cb7 514 }
mbed_official 27:4206883f4cb7 515
mbed_official 27:4206883f4cb7 516 ret = usb0_api_host_SetEndpointTable(devadr, pipe_table, (uint8_t *)&configdescriptor[offset]);
mbed_official 27:4206883f4cb7 517
mbed_official 27:4206883f4cb7 518 if ((ret != USB_HOST_PIPE_IN) && (ret != USB_HOST_PIPE_OUT))
mbed_official 27:4206883f4cb7 519 {
mbed_official 27:4206883f4cb7 520 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 521 }
mbed_official 27:4206883f4cb7 522
mbed_official 27:4206883f4cb7 523 ++end_point;
mbed_official 27:4206883f4cb7 524 }
mbed_official 27:4206883f4cb7 525
mbed_official 27:4206883f4cb7 526 /* Next End Point Search */
mbed_official 27:4206883f4cb7 527 offset += configdescriptor[offset];
mbed_official 27:4206883f4cb7 528
mbed_official 27:4206883f4cb7 529 } while (offset < totalLength);
mbed_official 27:4206883f4cb7 530
mbed_official 27:4206883f4cb7 531 return DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 532 }
mbed_official 27:4206883f4cb7 533
mbed_official 27:4206883f4cb7 534 /*******************************************************************************
mbed_official 27:4206883f4cb7 535 * Function Name: usb0_api_host_clear_endpoint
mbed_official 27:4206883f4cb7 536 * Description : Clears the pipe definition table specified in the argument.
mbed_official 27:4206883f4cb7 537 * Arguments : USB_HOST_CFG_PIPETBL_t *user_table : pipe table
mbed_official 27:4206883f4cb7 538 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 539 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 540 *******************************************************************************/
mbed_official 27:4206883f4cb7 541 int32_t usb0_api_host_clear_endpoint (USB_HOST_CFG_PIPETBL_t * user_table)
mbed_official 27:4206883f4cb7 542 {
mbed_official 27:4206883f4cb7 543 uint16_t pipe;
mbed_official 27:4206883f4cb7 544
mbed_official 27:4206883f4cb7 545 for (pipe = USB_HOST_PIPE0; pipe <= USB_HOST_MAX_PIPE_NO; ++pipe)
mbed_official 27:4206883f4cb7 546 {
mbed_official 27:4206883f4cb7 547 if (user_table->pipe_number == 0xffff)
mbed_official 27:4206883f4cb7 548 {
mbed_official 27:4206883f4cb7 549 break;
mbed_official 27:4206883f4cb7 550 }
mbed_official 27:4206883f4cb7 551 user_table->pipe_cfg &= (USB_HOST_DBLBFIELD | USB_HOST_CNTMDFIELD);
mbed_official 27:4206883f4cb7 552 user_table->pipe_max_pktsize = 0;
mbed_official 27:4206883f4cb7 553 user_table->pipe_cycle = 0;
mbed_official 27:4206883f4cb7 554
mbed_official 27:4206883f4cb7 555 user_table++;
mbed_official 27:4206883f4cb7 556 }
mbed_official 27:4206883f4cb7 557
mbed_official 27:4206883f4cb7 558 return DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 559 }
mbed_official 27:4206883f4cb7 560
mbed_official 27:4206883f4cb7 561 /*******************************************************************************
mbed_official 27:4206883f4cb7 562 * Function Name: usb0_api_host_clear_endpoint_pipe
mbed_official 27:4206883f4cb7 563 * Description : Clears the pipe definition table specified in the argument.
mbed_official 27:4206883f4cb7 564 * Arguments : uint16_t pipe_sel : Pipe Number
mbed_official 27:4206883f4cb7 565 * : USB_HOST_CFG_PIPETBL_t *user_table : pipe table
mbed_official 27:4206883f4cb7 566 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 567 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 568 *******************************************************************************/
mbed_official 27:4206883f4cb7 569 int32_t usb0_api_host_clear_endpoint_pipe (uint16_t pipe_sel, USB_HOST_CFG_PIPETBL_t * user_table)
mbed_official 27:4206883f4cb7 570 {
mbed_official 27:4206883f4cb7 571 uint16_t pipe;
mbed_official 27:4206883f4cb7 572
mbed_official 27:4206883f4cb7 573 for (pipe = USB_HOST_PIPE0; pipe <= USB_HOST_MAX_PIPE_NO; ++pipe)
mbed_official 27:4206883f4cb7 574 {
mbed_official 27:4206883f4cb7 575 if (user_table->pipe_number == 0xffff)
mbed_official 27:4206883f4cb7 576 {
mbed_official 27:4206883f4cb7 577 break;
mbed_official 27:4206883f4cb7 578 }
mbed_official 27:4206883f4cb7 579
mbed_official 27:4206883f4cb7 580 if (user_table->pipe_number == pipe_sel)
mbed_official 27:4206883f4cb7 581 {
mbed_official 27:4206883f4cb7 582 user_table->pipe_cfg &= (USB_HOST_DBLBFIELD | USB_HOST_CNTMDFIELD);
mbed_official 27:4206883f4cb7 583 user_table->pipe_max_pktsize = 0;
mbed_official 27:4206883f4cb7 584 user_table->pipe_cycle = 0;
mbed_official 27:4206883f4cb7 585 break;
mbed_official 27:4206883f4cb7 586 }
mbed_official 27:4206883f4cb7 587
mbed_official 27:4206883f4cb7 588 user_table++;
mbed_official 27:4206883f4cb7 589 }
mbed_official 27:4206883f4cb7 590
mbed_official 27:4206883f4cb7 591 return DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 592 }
mbed_official 27:4206883f4cb7 593 #endif
mbed_official 27:4206883f4cb7 594
mbed_official 27:4206883f4cb7 595 /*******************************************************************************
mbed_official 27:4206883f4cb7 596 * Function Name: usb0_api_host_SetEndpointTable
mbed_official 27:4206883f4cb7 597 * Description : Sets the end point on the information specified by the argument.
mbed_official 27:4206883f4cb7 598 * Arguments : uint16_t devadr : device address
mbed_official 27:4206883f4cb7 599 * : USB_HOST_CFG_PIPETBL_t *user_table : pipe table
mbed_official 27:4206883f4cb7 600 * : uint8_t *Table : Endpoint descriptor
mbed_official 27:4206883f4cb7 601 * Return Value : USB_HOST_DIR_H_IN ; IN endpoint
mbed_official 27:4206883f4cb7 602 * : USB_HOST_DIR_H_OUT ; OUT endpoint
mbed_official 27:4206883f4cb7 603 * : USB_END_POINT_ERROR ; error
mbed_official 27:4206883f4cb7 604 *******************************************************************************/
mbed_official 27:4206883f4cb7 605 uint16_t usb0_api_host_SetEndpointTable (uint16_t devadr, USB_HOST_CFG_PIPETBL_t * user_table, uint8_t * Table)
mbed_official 27:4206883f4cb7 606 {
mbed_official 27:4206883f4cb7 607 uint16_t PipeCfg;
mbed_official 27:4206883f4cb7 608 uint16_t PipeMaxp;
mbed_official 27:4206883f4cb7 609 uint16_t pipe_number;
mbed_official 27:4206883f4cb7 610 uint16_t ret;
mbed_official 27:4206883f4cb7 611 uint16_t ret_flag = 0; // avoid warning.
mbed_official 27:4206883f4cb7 612
mbed_official 27:4206883f4cb7 613 pipe_number = user_table->pipe_number;
mbed_official 27:4206883f4cb7 614
mbed_official 27:4206883f4cb7 615 if (Table[1] != USB_HOST_ENDPOINT_DESC)
mbed_official 27:4206883f4cb7 616 {
mbed_official 27:4206883f4cb7 617 return USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 618 }
mbed_official 27:4206883f4cb7 619
mbed_official 27:4206883f4cb7 620 switch (Table[3] & USB_HOST_EP_TYPE)
mbed_official 27:4206883f4cb7 621 {
mbed_official 27:4206883f4cb7 622 case USB_HOST_EP_CNTRL:
mbed_official 27:4206883f4cb7 623 ret_flag = USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 624 break;
mbed_official 27:4206883f4cb7 625
mbed_official 27:4206883f4cb7 626 case USB_HOST_EP_ISO:
mbed_official 27:4206883f4cb7 627 if ((pipe_number != USB_HOST_PIPE1) && (pipe_number != USB_HOST_PIPE2))
mbed_official 27:4206883f4cb7 628 {
mbed_official 27:4206883f4cb7 629 return USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 630 }
mbed_official 27:4206883f4cb7 631
mbed_official 27:4206883f4cb7 632 PipeCfg = USB_HOST_ISO;
mbed_official 27:4206883f4cb7 633 break;
mbed_official 27:4206883f4cb7 634
mbed_official 27:4206883f4cb7 635 case USB_HOST_EP_BULK:
mbed_official 27:4206883f4cb7 636 if ((pipe_number < USB_HOST_PIPE1) || (pipe_number > USB_HOST_PIPE5))
mbed_official 27:4206883f4cb7 637 {
mbed_official 27:4206883f4cb7 638 return USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 639 }
mbed_official 27:4206883f4cb7 640
mbed_official 27:4206883f4cb7 641 PipeCfg = USB_HOST_BULK;
mbed_official 27:4206883f4cb7 642 break;
mbed_official 27:4206883f4cb7 643
mbed_official 27:4206883f4cb7 644 case USB_HOST_EP_INT:
mbed_official 27:4206883f4cb7 645 if ((pipe_number < USB_HOST_PIPE6) || (pipe_number > USB_HOST_PIPE9))
mbed_official 27:4206883f4cb7 646 {
mbed_official 27:4206883f4cb7 647 return USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 648 }
mbed_official 27:4206883f4cb7 649
mbed_official 27:4206883f4cb7 650 PipeCfg = USB_HOST_INTERRUPT;
mbed_official 27:4206883f4cb7 651 break;
mbed_official 27:4206883f4cb7 652
mbed_official 27:4206883f4cb7 653 default:
mbed_official 27:4206883f4cb7 654 ret_flag = USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 655 break;
mbed_official 27:4206883f4cb7 656 }
mbed_official 27:4206883f4cb7 657
mbed_official 27:4206883f4cb7 658 if (ret_flag == USB_END_POINT_ERROR)
mbed_official 27:4206883f4cb7 659 {
mbed_official 27:4206883f4cb7 660 return ret_flag;
mbed_official 27:4206883f4cb7 661 }
mbed_official 27:4206883f4cb7 662
mbed_official 27:4206883f4cb7 663 /* Set pipe configuration table */
mbed_official 27:4206883f4cb7 664 if ((Table[2] & USB_HOST_EP_DIR_MASK) == USB_HOST_EP_IN) /* IN(receive) */
mbed_official 27:4206883f4cb7 665 {
mbed_official 27:4206883f4cb7 666 if (PipeCfg == USB_HOST_ISO)
mbed_official 27:4206883f4cb7 667 {
mbed_official 27:4206883f4cb7 668 /* Transfer Type is ISO*/
mbed_official 27:4206883f4cb7 669 PipeCfg |= USB_HOST_DIR_H_IN;
mbed_official 27:4206883f4cb7 670
mbed_official 27:4206883f4cb7 671 switch (user_table->fifo_port)
mbed_official 27:4206883f4cb7 672 {
mbed_official 27:4206883f4cb7 673 case USB_HOST_CUSE:
mbed_official 27:4206883f4cb7 674 case USB_HOST_D0USE:
mbed_official 27:4206883f4cb7 675 case USB_HOST_D1USE:
mbed_official 27:4206883f4cb7 676 case USB_HOST_D0DMA:
mbed_official 27:4206883f4cb7 677 case USB_HOST_D1DMA:
mbed_official 27:4206883f4cb7 678 PipeCfg |= (uint16_t)(user_table->pipe_cfg & USB_HOST_DBLBFIELD);
mbed_official 27:4206883f4cb7 679 break;
mbed_official 27:4206883f4cb7 680
mbed_official 27:4206883f4cb7 681 default:
mbed_official 27:4206883f4cb7 682 ret_flag = USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 683 break;
mbed_official 27:4206883f4cb7 684 }
mbed_official 27:4206883f4cb7 685
mbed_official 27:4206883f4cb7 686 if (ret_flag == USB_END_POINT_ERROR)
mbed_official 27:4206883f4cb7 687 {
mbed_official 27:4206883f4cb7 688 return ret_flag;
mbed_official 27:4206883f4cb7 689 }
mbed_official 27:4206883f4cb7 690 }
mbed_official 27:4206883f4cb7 691 else
mbed_official 27:4206883f4cb7 692 {
mbed_official 27:4206883f4cb7 693 /* Transfer Type is BULK or INT */
mbed_official 27:4206883f4cb7 694 PipeCfg |= (USB_HOST_SHTNAKON | USB_HOST_DIR_H_IN); /* Compulsory SHTNAK */
mbed_official 27:4206883f4cb7 695
mbed_official 27:4206883f4cb7 696 switch (user_table->fifo_port)
mbed_official 27:4206883f4cb7 697 {
mbed_official 27:4206883f4cb7 698 case USB_HOST_CUSE:
mbed_official 27:4206883f4cb7 699 case USB_HOST_D0USE:
mbed_official 27:4206883f4cb7 700 case USB_HOST_D1USE:
mbed_official 27:4206883f4cb7 701 PipeCfg |= (uint16_t)(user_table->pipe_cfg & (USB_HOST_DBLBFIELD | USB_HOST_CNTMDFIELD));
mbed_official 27:4206883f4cb7 702 break;
mbed_official 27:4206883f4cb7 703
mbed_official 27:4206883f4cb7 704 case USB_HOST_D0DMA:
mbed_official 27:4206883f4cb7 705 case USB_HOST_D1DMA:
mbed_official 27:4206883f4cb7 706 PipeCfg |= (uint16_t)(user_table->pipe_cfg & (USB_HOST_DBLBFIELD | USB_HOST_CNTMDFIELD));
mbed_official 27:4206883f4cb7 707 #ifdef __USB_DMA_BFRE_ENABLE__
mbed_official 27:4206883f4cb7 708 /* this routine cannnot be perfomred if read operation is executed in buffer size */
mbed_official 27:4206883f4cb7 709 PipeCfg |= USB_HOST_BFREON;
mbed_official 27:4206883f4cb7 710 #endif
mbed_official 27:4206883f4cb7 711 break;
mbed_official 27:4206883f4cb7 712
mbed_official 27:4206883f4cb7 713 default:
mbed_official 27:4206883f4cb7 714 ret_flag = USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 715 break;
mbed_official 27:4206883f4cb7 716 }
mbed_official 27:4206883f4cb7 717
mbed_official 27:4206883f4cb7 718 if (ret_flag == USB_END_POINT_ERROR)
mbed_official 27:4206883f4cb7 719 {
mbed_official 27:4206883f4cb7 720 return ret_flag;
mbed_official 27:4206883f4cb7 721 }
mbed_official 27:4206883f4cb7 722 }
mbed_official 27:4206883f4cb7 723 ret = USB_HOST_PIPE_IN;
mbed_official 27:4206883f4cb7 724 }
mbed_official 27:4206883f4cb7 725 else /* OUT(send) */
mbed_official 27:4206883f4cb7 726 {
mbed_official 27:4206883f4cb7 727 if (PipeCfg == USB_HOST_ISO)
mbed_official 27:4206883f4cb7 728 {
mbed_official 27:4206883f4cb7 729 /* Transfer Type is ISO*/
mbed_official 27:4206883f4cb7 730 PipeCfg |= (uint16_t)(user_table->pipe_cfg & USB_HOST_DBLBFIELD);
mbed_official 27:4206883f4cb7 731 }
mbed_official 27:4206883f4cb7 732 else
mbed_official 27:4206883f4cb7 733 {
mbed_official 27:4206883f4cb7 734 /* Transfer Type is BULK or INT */
mbed_official 27:4206883f4cb7 735 PipeCfg |= (uint16_t)(user_table->pipe_cfg & (USB_HOST_DBLBFIELD | USB_HOST_CNTMDFIELD));
mbed_official 27:4206883f4cb7 736 }
mbed_official 27:4206883f4cb7 737 PipeCfg |= USB_HOST_DIR_H_OUT;
mbed_official 27:4206883f4cb7 738 ret = USB_HOST_PIPE_OUT;
mbed_official 27:4206883f4cb7 739 }
mbed_official 27:4206883f4cb7 740
mbed_official 27:4206883f4cb7 741 switch (user_table->fifo_port)
mbed_official 27:4206883f4cb7 742 {
mbed_official 27:4206883f4cb7 743 case USB_HOST_CUSE:
mbed_official 27:4206883f4cb7 744 g_usb0_host_PipeTbl[pipe_number] = (uint16_t)USB_HOST_CFIFO_USE;
mbed_official 27:4206883f4cb7 745 break;
mbed_official 27:4206883f4cb7 746
mbed_official 27:4206883f4cb7 747 case USB_HOST_D0USE:
mbed_official 27:4206883f4cb7 748 g_usb0_host_PipeTbl[pipe_number] = (uint16_t)USB_HOST_D0FIFO_USE;
mbed_official 27:4206883f4cb7 749 break;
mbed_official 27:4206883f4cb7 750
mbed_official 27:4206883f4cb7 751 case USB_HOST_D1USE:
mbed_official 27:4206883f4cb7 752 g_usb0_host_PipeTbl[pipe_number] = (uint16_t)USB_HOST_D1FIFO_USE;
mbed_official 27:4206883f4cb7 753 break;
mbed_official 27:4206883f4cb7 754
mbed_official 27:4206883f4cb7 755 case USB_HOST_D0DMA:
mbed_official 27:4206883f4cb7 756 g_usb0_host_PipeTbl[pipe_number] = (uint16_t)USB_HOST_D0FIFO_DMA;
mbed_official 27:4206883f4cb7 757 break;
mbed_official 27:4206883f4cb7 758
mbed_official 27:4206883f4cb7 759 case USB_HOST_D1DMA:
mbed_official 27:4206883f4cb7 760 g_usb0_host_PipeTbl[pipe_number] = (uint16_t)USB_HOST_D1FIFO_DMA;
mbed_official 27:4206883f4cb7 761 break;
mbed_official 27:4206883f4cb7 762
mbed_official 27:4206883f4cb7 763 default:
mbed_official 27:4206883f4cb7 764 ret_flag = USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 765 break;
mbed_official 27:4206883f4cb7 766 }
mbed_official 27:4206883f4cb7 767
mbed_official 27:4206883f4cb7 768 if (ret_flag == USB_END_POINT_ERROR)
mbed_official 27:4206883f4cb7 769 {
mbed_official 27:4206883f4cb7 770 return ret_flag;
mbed_official 27:4206883f4cb7 771 }
mbed_official 27:4206883f4cb7 772
mbed_official 27:4206883f4cb7 773 /* Endpoint number set */
mbed_official 27:4206883f4cb7 774 PipeCfg |= (uint16_t)(Table[2] & USB_HOST_EP_NUM_MASK);
mbed_official 27:4206883f4cb7 775 g_usb0_host_PipeTbl[pipe_number] |= (uint16_t)(Table[2] & USB_HOST_EP_NUM_MASK);
mbed_official 27:4206883f4cb7 776
mbed_official 27:4206883f4cb7 777 /* Max packet size set */
mbed_official 27:4206883f4cb7 778 PipeMaxp = (uint16_t)((uint16_t)Table[4] | (uint16_t)((uint16_t)Table[5] << 8));
mbed_official 27:4206883f4cb7 779
mbed_official 27:4206883f4cb7 780 if (PipeMaxp == 0u)
mbed_official 27:4206883f4cb7 781 {
mbed_official 27:4206883f4cb7 782 return USB_END_POINT_ERROR;
mbed_official 27:4206883f4cb7 783 }
mbed_official 27:4206883f4cb7 784
mbed_official 27:4206883f4cb7 785 /* Set device address */
mbed_official 27:4206883f4cb7 786 PipeMaxp |= (uint16_t)(devadr << 12);
mbed_official 27:4206883f4cb7 787
mbed_official 27:4206883f4cb7 788 user_table->pipe_cfg = PipeCfg;
mbed_official 27:4206883f4cb7 789 user_table->pipe_max_pktsize = PipeMaxp;
mbed_official 27:4206883f4cb7 790
mbed_official 27:4206883f4cb7 791 usb0_host_resetEP(user_table);
mbed_official 27:4206883f4cb7 792
mbed_official 27:4206883f4cb7 793 return ret;
mbed_official 27:4206883f4cb7 794 }
mbed_official 27:4206883f4cb7 795
mbed_official 27:4206883f4cb7 796 /*******************************************************************************
mbed_official 27:4206883f4cb7 797 * Function Name: usb0_host_resetEP
mbed_official 27:4206883f4cb7 798 * Description : Sets the end point on the information specified by the argument.
mbed_official 27:4206883f4cb7 799 * Arguments : USB_HOST_CFG_PIPETBL_t *tbl : pipe table
mbed_official 27:4206883f4cb7 800 * Return Value : none
mbed_official 27:4206883f4cb7 801 *******************************************************************************/
mbed_official 27:4206883f4cb7 802 static void usb0_host_resetEP (USB_HOST_CFG_PIPETBL_t * tbl)
mbed_official 27:4206883f4cb7 803 {
mbed_official 27:4206883f4cb7 804
mbed_official 27:4206883f4cb7 805 uint16_t pipe;
mbed_official 27:4206883f4cb7 806
mbed_official 27:4206883f4cb7 807 /* Host pipe */
mbed_official 27:4206883f4cb7 808 /* The pipe number of pipe definition table is obtained */
mbed_official 27:4206883f4cb7 809 pipe = (uint16_t)(tbl->pipe_number & USB_HOST_BITCURPIPE); /* Pipe Number */
mbed_official 27:4206883f4cb7 810
mbed_official 27:4206883f4cb7 811 /* FIFO port access pipe is set to initial value */
mbed_official 27:4206883f4cb7 812 /* The connection with FIFO should be cut before setting the pipe */
mbed_official 27:4206883f4cb7 813 if (RZA_IO_RegRead_16(&USB200.CFIFOSEL,
mbed_official 27:4206883f4cb7 814 USB_CFIFOSEL_CURPIPE_SHIFT,
mbed_official 27:4206883f4cb7 815 USB_CFIFOSEL_CURPIPE) == pipe)
mbed_official 27:4206883f4cb7 816 {
mbed_official 27:4206883f4cb7 817 usb0_host_change_fifo_port(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_NO, USB_HOST_BITMBW_16);
mbed_official 27:4206883f4cb7 818 }
mbed_official 27:4206883f4cb7 819
mbed_official 27:4206883f4cb7 820 if (RZA_IO_RegRead_16(&USB200.D0FIFOSEL,
mbed_official 27:4206883f4cb7 821 USB_DnFIFOSEL_CURPIPE_SHIFT,
mbed_official 27:4206883f4cb7 822 USB_DnFIFOSEL_CURPIPE) == pipe)
mbed_official 27:4206883f4cb7 823 {
mbed_official 27:4206883f4cb7 824 usb0_host_change_fifo_port(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, USB_HOST_BITMBW_16);
mbed_official 27:4206883f4cb7 825 }
mbed_official 27:4206883f4cb7 826
mbed_official 27:4206883f4cb7 827 if (RZA_IO_RegRead_16(&USB200.D1FIFOSEL,
mbed_official 27:4206883f4cb7 828 USB_DnFIFOSEL_CURPIPE_SHIFT,
mbed_official 27:4206883f4cb7 829 USB_DnFIFOSEL_CURPIPE) == pipe)
mbed_official 27:4206883f4cb7 830 {
mbed_official 27:4206883f4cb7 831 usb0_host_change_fifo_port(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, USB_HOST_BITMBW_16);
mbed_official 27:4206883f4cb7 832 }
mbed_official 27:4206883f4cb7 833
mbed_official 27:4206883f4cb7 834 /* Interrupt of pipe set is disabled */
mbed_official 27:4206883f4cb7 835 usb0_host_disable_brdy_int(pipe);
mbed_official 27:4206883f4cb7 836 usb0_host_disable_nrdy_int(pipe);
mbed_official 27:4206883f4cb7 837 usb0_host_disable_bemp_int(pipe);
mbed_official 27:4206883f4cb7 838
mbed_official 27:4206883f4cb7 839 /* Pipe to set is set to NAK */
mbed_official 27:4206883f4cb7 840 usb0_host_set_pid_nak(pipe);
mbed_official 27:4206883f4cb7 841
mbed_official 27:4206883f4cb7 842 /* Pipe is set */
mbed_official 27:4206883f4cb7 843 USB200.PIPESEL = pipe;
mbed_official 27:4206883f4cb7 844
mbed_official 27:4206883f4cb7 845 USB200.PIPECFG = tbl->pipe_cfg;
mbed_official 27:4206883f4cb7 846 USB200.PIPEBUF = tbl->pipe_buf;
mbed_official 27:4206883f4cb7 847 USB200.PIPEMAXP = tbl->pipe_max_pktsize;
mbed_official 27:4206883f4cb7 848 USB200.PIPEPERI = tbl->pipe_cycle;
mbed_official 27:4206883f4cb7 849
mbed_official 27:4206883f4cb7 850 g_usb0_host_pipecfg[pipe] = tbl->pipe_cfg;
mbed_official 27:4206883f4cb7 851 g_usb0_host_pipebuf[pipe] = tbl->pipe_buf;
mbed_official 27:4206883f4cb7 852 g_usb0_host_pipemaxp[pipe] = tbl->pipe_max_pktsize;
mbed_official 27:4206883f4cb7 853 g_usb0_host_pipeperi[pipe] = tbl->pipe_cycle;
mbed_official 27:4206883f4cb7 854
mbed_official 27:4206883f4cb7 855 /* Sequence bit clear */
mbed_official 27:4206883f4cb7 856 usb0_host_set_sqclr(pipe);
mbed_official 27:4206883f4cb7 857
mbed_official 27:4206883f4cb7 858 usb0_host_aclrm(pipe);
mbed_official 27:4206883f4cb7 859 usb0_host_set_csclr(pipe);
mbed_official 27:4206883f4cb7 860
mbed_official 27:4206883f4cb7 861 /* Pipe window selection is set to unused */
mbed_official 27:4206883f4cb7 862 USB200.PIPESEL = USB_HOST_PIPE0;
mbed_official 27:4206883f4cb7 863
mbed_official 27:4206883f4cb7 864 }
mbed_official 27:4206883f4cb7 865
mbed_official 27:4206883f4cb7 866 #if(1) /* ohci_wrapp */
mbed_official 27:4206883f4cb7 867 #else
mbed_official 27:4206883f4cb7 868 /*******************************************************************************
mbed_official 27:4206883f4cb7 869 * Function Name: usb0_api_host_data_count
mbed_official 27:4206883f4cb7 870 * Description : Get g_usb0_host_data_count[pipe]
mbed_official 27:4206883f4cb7 871 * Arguments : uint16_t pipe ; Pipe Number
mbed_official 27:4206883f4cb7 872 * : uint32_t *data_count ; return g_usb0_data_count[pipe]
mbed_official 27:4206883f4cb7 873 * Return Value : DEVDRV_SUCCESS ; success
mbed_official 27:4206883f4cb7 874 * : DEVDRV_ERROR ; error
mbed_official 27:4206883f4cb7 875 *******************************************************************************/
mbed_official 27:4206883f4cb7 876 int32_t usb0_api_host_data_count (uint16_t pipe, uint32_t * data_count)
mbed_official 27:4206883f4cb7 877 {
mbed_official 27:4206883f4cb7 878 if (pipe > USB_HOST_MAX_PIPE_NO)
mbed_official 27:4206883f4cb7 879 {
mbed_official 27:4206883f4cb7 880 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 881 }
mbed_official 27:4206883f4cb7 882
mbed_official 27:4206883f4cb7 883 *data_count = g_usb0_host_PipeDataSize[pipe];
mbed_official 27:4206883f4cb7 884
mbed_official 27:4206883f4cb7 885 return DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 886 }
mbed_official 27:4206883f4cb7 887 #endif
mbed_official 27:4206883f4cb7 888
mbed_official 27:4206883f4cb7 889 /* End of File */