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_controlrw.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
mbed_official 27:4206883f4cb7 63
mbed_official 27:4206883f4cb7 64 /*******************************************************************************
mbed_official 27:4206883f4cb7 65 Private global variables and functions
mbed_official 27:4206883f4cb7 66 *******************************************************************************/
mbed_official 27:4206883f4cb7 67
mbed_official 27:4206883f4cb7 68
mbed_official 27:4206883f4cb7 69 /*******************************************************************************
mbed_official 27:4206883f4cb7 70 * Function Name: usb0_host_CtrlTransStart
mbed_official 27:4206883f4cb7 71 * Description : Executes USB control transfer.
mbed_official 27:4206883f4cb7 72 * Arguments : uint16_t devadr ; device address
mbed_official 27:4206883f4cb7 73 * : uint16_t Req ; bmRequestType & bRequest
mbed_official 27:4206883f4cb7 74 * : uint16_t Val ; wValue
mbed_official 27:4206883f4cb7 75 * : uint16_t Indx ; wIndex
mbed_official 27:4206883f4cb7 76 * : uint16_t Len ; wLength
mbed_official 27:4206883f4cb7 77 * : uint8_t *Buf ; Data buffer
mbed_official 27:4206883f4cb7 78 * Return Value : DEVDRV_SUCCESS ; SUCCESS
mbed_official 27:4206883f4cb7 79 * : DEVDRV_ERROR ; ERROR
mbed_official 27:4206883f4cb7 80 *******************************************************************************/
mbed_official 27:4206883f4cb7 81 int32_t usb0_host_CtrlTransStart (uint16_t devadr, uint16_t Req, uint16_t Val,
mbed_official 27:4206883f4cb7 82 uint16_t Indx, uint16_t Len, uint8_t * Buf)
mbed_official 27:4206883f4cb7 83 {
mbed_official 27:4206883f4cb7 84 if (g_usb0_host_UsbDeviceSpeed == USB_HOST_LOW_SPEED)
mbed_official 27:4206883f4cb7 85 {
mbed_official 27:4206883f4cb7 86 RZA_IO_RegWrite_16(&USB200.SOFCFG,
mbed_official 27:4206883f4cb7 87 1,
mbed_official 27:4206883f4cb7 88 USB_SOFCFG_TRNENSEL_SHIFT,
mbed_official 27:4206883f4cb7 89 USB_SOFCFG_TRNENSEL);
mbed_official 27:4206883f4cb7 90 }
mbed_official 27:4206883f4cb7 91 else
mbed_official 27:4206883f4cb7 92 {
mbed_official 27:4206883f4cb7 93 RZA_IO_RegWrite_16(&USB200.SOFCFG,
mbed_official 27:4206883f4cb7 94 0,
mbed_official 27:4206883f4cb7 95 USB_SOFCFG_TRNENSEL_SHIFT,
mbed_official 27:4206883f4cb7 96 USB_SOFCFG_TRNENSEL);
mbed_official 27:4206883f4cb7 97 }
mbed_official 27:4206883f4cb7 98
mbed_official 27:4206883f4cb7 99 USB200.DCPMAXP = (uint16_t)((uint16_t)(devadr << 12) + g_usb0_host_default_max_packet[devadr]);
mbed_official 27:4206883f4cb7 100
mbed_official 27:4206883f4cb7 101 if (g_usb0_host_pipe_status[USB_HOST_PIPE0] == USB_HOST_PIPE_IDLE)
mbed_official 27:4206883f4cb7 102 {
mbed_official 27:4206883f4cb7 103 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_WAIT;
mbed_official 27:4206883f4cb7 104 g_usb0_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
mbed_official 27:4206883f4cb7 105 g_usb0_host_CmdStage = (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE);
mbed_official 27:4206883f4cb7 106
mbed_official 27:4206883f4cb7 107 if (Len == 0)
mbed_official 27:4206883f4cb7 108 {
mbed_official 27:4206883f4cb7 109 g_usb0_host_CmdStage |= USB_HOST_MODE_NO_DATA; /* No-data Control */
mbed_official 27:4206883f4cb7 110 }
mbed_official 27:4206883f4cb7 111 else
mbed_official 27:4206883f4cb7 112 {
mbed_official 27:4206883f4cb7 113 if ((Req & 0x0080) != 0)
mbed_official 27:4206883f4cb7 114 {
mbed_official 27:4206883f4cb7 115 g_usb0_host_CmdStage |= USB_HOST_MODE_READ; /* Control Read */
mbed_official 27:4206883f4cb7 116 }
mbed_official 27:4206883f4cb7 117 else
mbed_official 27:4206883f4cb7 118 {
mbed_official 27:4206883f4cb7 119 g_usb0_host_CmdStage |= USB_HOST_MODE_WRITE; /* Control Write */
mbed_official 27:4206883f4cb7 120 }
mbed_official 27:4206883f4cb7 121 }
mbed_official 27:4206883f4cb7 122
mbed_official 27:4206883f4cb7 123 g_usb0_host_SavReq = Req; /* save request */
mbed_official 27:4206883f4cb7 124 g_usb0_host_SavVal = Val;
mbed_official 27:4206883f4cb7 125 g_usb0_host_SavIndx = Indx;
mbed_official 27:4206883f4cb7 126 g_usb0_host_SavLen = Len;
mbed_official 27:4206883f4cb7 127 }
mbed_official 27:4206883f4cb7 128 else
mbed_official 27:4206883f4cb7 129 {
mbed_official 27:4206883f4cb7 130 if ((g_usb0_host_SavReq != Req) || (g_usb0_host_SavVal != Val)
mbed_official 27:4206883f4cb7 131 || (g_usb0_host_SavIndx != Indx) || (g_usb0_host_SavLen != Len))
mbed_official 27:4206883f4cb7 132 {
mbed_official 27:4206883f4cb7 133 return DEVDRV_ERROR;
mbed_official 27:4206883f4cb7 134 }
mbed_official 27:4206883f4cb7 135 }
mbed_official 27:4206883f4cb7 136
mbed_official 27:4206883f4cb7 137 switch ((g_usb0_host_CmdStage & (USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
mbed_official 27:4206883f4cb7 138 {
mbed_official 27:4206883f4cb7 139 /* --------------- SETUP STAGE --------------- */
mbed_official 27:4206883f4cb7 140 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE):
mbed_official 27:4206883f4cb7 141 usb0_host_SetupStage(Req, Val, Indx, Len);
mbed_official 27:4206883f4cb7 142 break;
mbed_official 27:4206883f4cb7 143
mbed_official 27:4206883f4cb7 144 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_DOING):
mbed_official 27:4206883f4cb7 145 /* do nothing */
mbed_official 27:4206883f4cb7 146 break;
mbed_official 27:4206883f4cb7 147
mbed_official 27:4206883f4cb7 148 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_DONE): /* goto next stage */
mbed_official 27:4206883f4cb7 149 g_usb0_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
mbed_official 27:4206883f4cb7 150 switch ((g_usb0_host_CmdStage & (USB_HOST_MODE_FIELD)))
mbed_official 27:4206883f4cb7 151 {
mbed_official 27:4206883f4cb7 152 case USB_HOST_MODE_WRITE:
mbed_official 27:4206883f4cb7 153 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 27:4206883f4cb7 154 g_usb0_host_CmdStage |= USB_HOST_STAGE_DATA;
mbed_official 27:4206883f4cb7 155 break;
mbed_official 27:4206883f4cb7 156
mbed_official 27:4206883f4cb7 157 case USB_HOST_MODE_READ:
mbed_official 27:4206883f4cb7 158 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 27:4206883f4cb7 159 g_usb0_host_CmdStage |= USB_HOST_STAGE_DATA;
mbed_official 27:4206883f4cb7 160 break;
mbed_official 27:4206883f4cb7 161
mbed_official 27:4206883f4cb7 162 case USB_HOST_MODE_NO_DATA:
mbed_official 27:4206883f4cb7 163 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 27:4206883f4cb7 164 g_usb0_host_CmdStage |= USB_HOST_STAGE_STATUS;
mbed_official 27:4206883f4cb7 165 break;
mbed_official 27:4206883f4cb7 166
mbed_official 27:4206883f4cb7 167 default:
mbed_official 27:4206883f4cb7 168 break;
mbed_official 27:4206883f4cb7 169 }
mbed_official 27:4206883f4cb7 170 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 171 g_usb0_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 27:4206883f4cb7 172 break;
mbed_official 27:4206883f4cb7 173
mbed_official 27:4206883f4cb7 174 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_NORES):
mbed_official 27:4206883f4cb7 175 if (g_usb0_host_PipeIgnore[USB_HOST_PIPE0] == 3)
mbed_official 27:4206883f4cb7 176 {
mbed_official 27:4206883f4cb7 177 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
mbed_official 27:4206883f4cb7 178 }
mbed_official 27:4206883f4cb7 179 else
mbed_official 27:4206883f4cb7 180 {
mbed_official 27:4206883f4cb7 181 g_usb0_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
mbed_official 27:4206883f4cb7 182 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 183 g_usb0_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 27:4206883f4cb7 184 }
mbed_official 27:4206883f4cb7 185 break;
mbed_official 27:4206883f4cb7 186
mbed_official 27:4206883f4cb7 187 /* --------------- DATA STAGE --------------- */
mbed_official 27:4206883f4cb7 188 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_IDLE):
mbed_official 27:4206883f4cb7 189 switch ((g_usb0_host_CmdStage & (USB_HOST_MODE_FIELD)))
mbed_official 27:4206883f4cb7 190 {
mbed_official 27:4206883f4cb7 191 case USB_HOST_MODE_WRITE:
mbed_official 27:4206883f4cb7 192 usb0_host_CtrlWriteStart((uint32_t)Len, Buf);
mbed_official 27:4206883f4cb7 193 break;
mbed_official 27:4206883f4cb7 194
mbed_official 27:4206883f4cb7 195 case USB_HOST_MODE_READ:
mbed_official 27:4206883f4cb7 196 usb0_host_CtrlReadStart((uint32_t)Len, Buf);
mbed_official 27:4206883f4cb7 197 break;
mbed_official 27:4206883f4cb7 198
mbed_official 27:4206883f4cb7 199 default:
mbed_official 27:4206883f4cb7 200 break;
mbed_official 27:4206883f4cb7 201 }
mbed_official 27:4206883f4cb7 202 break;
mbed_official 27:4206883f4cb7 203
mbed_official 27:4206883f4cb7 204 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
mbed_official 27:4206883f4cb7 205 /* do nothing */
mbed_official 27:4206883f4cb7 206 break;
mbed_official 27:4206883f4cb7 207
mbed_official 27:4206883f4cb7 208 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DONE): /* goto next stage */
mbed_official 27:4206883f4cb7 209 g_usb0_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
mbed_official 27:4206883f4cb7 210 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 27:4206883f4cb7 211 g_usb0_host_CmdStage |= USB_HOST_STAGE_STATUS;
mbed_official 27:4206883f4cb7 212 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 213 g_usb0_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 27:4206883f4cb7 214 break;
mbed_official 27:4206883f4cb7 215
mbed_official 27:4206883f4cb7 216 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_NORES):
mbed_official 27:4206883f4cb7 217 if (g_usb0_host_PipeIgnore[USB_HOST_PIPE0] == 3)
mbed_official 27:4206883f4cb7 218 {
mbed_official 27:4206883f4cb7 219 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
mbed_official 27:4206883f4cb7 220 }
mbed_official 27:4206883f4cb7 221 else
mbed_official 27:4206883f4cb7 222 {
mbed_official 27:4206883f4cb7 223 g_usb0_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
mbed_official 27:4206883f4cb7 224 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 225 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 27:4206883f4cb7 226 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 227 usb0_host_set_pid_buf(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 228 }
mbed_official 27:4206883f4cb7 229 break;
mbed_official 27:4206883f4cb7 230
mbed_official 27:4206883f4cb7 231 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_STALL):
mbed_official 27:4206883f4cb7 232 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
mbed_official 27:4206883f4cb7 233 break;
mbed_official 27:4206883f4cb7 234
mbed_official 27:4206883f4cb7 235 /* --------------- STATUS STAGE --------------- */
mbed_official 27:4206883f4cb7 236 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_IDLE):
mbed_official 27:4206883f4cb7 237 usb0_host_StatusStage();
mbed_official 27:4206883f4cb7 238 break;
mbed_official 27:4206883f4cb7 239
mbed_official 27:4206883f4cb7 240 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
mbed_official 27:4206883f4cb7 241 /* do nothing */
mbed_official 27:4206883f4cb7 242 break;
mbed_official 27:4206883f4cb7 243
mbed_official 27:4206883f4cb7 244 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DONE): /* end of Control transfer */
mbed_official 27:4206883f4cb7 245 usb0_host_set_pid_nak(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 246 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_DONE; /* exit DONE */
mbed_official 27:4206883f4cb7 247 break;
mbed_official 27:4206883f4cb7 248
mbed_official 27:4206883f4cb7 249 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_NORES):
mbed_official 27:4206883f4cb7 250 if (g_usb0_host_PipeIgnore[USB_HOST_PIPE0] == 3)
mbed_official 27:4206883f4cb7 251 {
mbed_official 27:4206883f4cb7 252 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
mbed_official 27:4206883f4cb7 253 }
mbed_official 27:4206883f4cb7 254 else
mbed_official 27:4206883f4cb7 255 {
mbed_official 27:4206883f4cb7 256 g_usb0_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
mbed_official 27:4206883f4cb7 257 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 258 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 27:4206883f4cb7 259 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 260 usb0_host_set_pid_buf(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 261 }
mbed_official 27:4206883f4cb7 262 break;
mbed_official 27:4206883f4cb7 263
mbed_official 27:4206883f4cb7 264 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_STALL):
mbed_official 27:4206883f4cb7 265 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
mbed_official 27:4206883f4cb7 266 break;
mbed_official 27:4206883f4cb7 267
mbed_official 27:4206883f4cb7 268 default:
mbed_official 27:4206883f4cb7 269 break;
mbed_official 27:4206883f4cb7 270 }
mbed_official 27:4206883f4cb7 271
mbed_official 27:4206883f4cb7 272 if (g_usb0_host_pipe_status[USB_HOST_PIPE0] != USB_HOST_PIPE_WAIT)
mbed_official 27:4206883f4cb7 273 {
mbed_official 27:4206883f4cb7 274 RZA_IO_RegWrite_16(&USB200.SOFCFG,
mbed_official 27:4206883f4cb7 275 0,
mbed_official 27:4206883f4cb7 276 USB_SOFCFG_TRNENSEL_SHIFT,
mbed_official 27:4206883f4cb7 277 USB_SOFCFG_TRNENSEL);
mbed_official 27:4206883f4cb7 278 }
mbed_official 27:4206883f4cb7 279
mbed_official 27:4206883f4cb7 280 return DEVDRV_SUCCESS;
mbed_official 27:4206883f4cb7 281 }
mbed_official 27:4206883f4cb7 282
mbed_official 27:4206883f4cb7 283 /*******************************************************************************
mbed_official 27:4206883f4cb7 284 * Function Name: usb0_host_SetupStage
mbed_official 27:4206883f4cb7 285 * Description : Executes USB control transfer/set up stage.
mbed_official 27:4206883f4cb7 286 * Arguments : uint16_t Req ; bmRequestType & bRequest
mbed_official 27:4206883f4cb7 287 * : uint16_t Val ; wValue
mbed_official 27:4206883f4cb7 288 * : uint16_t Indx ; wIndex
mbed_official 27:4206883f4cb7 289 * : uint16_t Len ; wLength
mbed_official 27:4206883f4cb7 290 * Return Value : none
mbed_official 27:4206883f4cb7 291 *******************************************************************************/
mbed_official 27:4206883f4cb7 292 void usb0_host_SetupStage (uint16_t Req, uint16_t Val, uint16_t Indx, uint16_t Len)
mbed_official 27:4206883f4cb7 293 {
mbed_official 27:4206883f4cb7 294 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 295 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 27:4206883f4cb7 296
mbed_official 27:4206883f4cb7 297 USB200.INTSTS1 = (uint16_t)~(USB_HOST_BITSACK | USB_HOST_BITSIGN); /* Status Clear */
mbed_official 27:4206883f4cb7 298 USB200.USBREQ = Req;
mbed_official 27:4206883f4cb7 299 USB200.USBVAL = Val;
mbed_official 27:4206883f4cb7 300 USB200.USBINDX = Indx;
mbed_official 27:4206883f4cb7 301 USB200.USBLENG = Len;
mbed_official 27:4206883f4cb7 302 USB200.DCPCTR = USB_HOST_BITSUREQ; /* PID=NAK & Send Setup */
mbed_official 27:4206883f4cb7 303 }
mbed_official 27:4206883f4cb7 304
mbed_official 27:4206883f4cb7 305 /*******************************************************************************
mbed_official 27:4206883f4cb7 306 * Function Name: usb0_host_StatusStage
mbed_official 27:4206883f4cb7 307 * Description : Executes USB control transfer/status stage.
mbed_official 27:4206883f4cb7 308 * Arguments : none
mbed_official 27:4206883f4cb7 309 * Return Value : none
mbed_official 27:4206883f4cb7 310 *******************************************************************************/
mbed_official 27:4206883f4cb7 311 void usb0_host_StatusStage (void)
mbed_official 27:4206883f4cb7 312 {
mbed_official 27:4206883f4cb7 313 uint8_t Buf1[16];
mbed_official 27:4206883f4cb7 314
mbed_official 27:4206883f4cb7 315 switch ((g_usb0_host_CmdStage & (USB_HOST_MODE_FIELD)))
mbed_official 27:4206883f4cb7 316 {
mbed_official 27:4206883f4cb7 317 case USB_HOST_MODE_READ:
mbed_official 27:4206883f4cb7 318 usb0_host_CtrlWriteStart((uint32_t)0, (uint8_t *)&Buf1);
mbed_official 27:4206883f4cb7 319 break;
mbed_official 27:4206883f4cb7 320
mbed_official 27:4206883f4cb7 321 case USB_HOST_MODE_WRITE:
mbed_official 27:4206883f4cb7 322 usb0_host_CtrlReadStart((uint32_t)0, (uint8_t *)&Buf1);
mbed_official 27:4206883f4cb7 323 break;
mbed_official 27:4206883f4cb7 324
mbed_official 27:4206883f4cb7 325 case USB_HOST_MODE_NO_DATA:
mbed_official 27:4206883f4cb7 326 usb0_host_CtrlReadStart((uint32_t)0, (uint8_t *)&Buf1);
mbed_official 27:4206883f4cb7 327 break;
mbed_official 27:4206883f4cb7 328
mbed_official 27:4206883f4cb7 329 default:
mbed_official 27:4206883f4cb7 330 break;
mbed_official 27:4206883f4cb7 331 }
mbed_official 27:4206883f4cb7 332 }
mbed_official 27:4206883f4cb7 333
mbed_official 27:4206883f4cb7 334 /*******************************************************************************
mbed_official 27:4206883f4cb7 335 * Function Name: usb0_host_CtrlWriteStart
mbed_official 27:4206883f4cb7 336 * Description : Executes USB control transfer/data stage(write).
mbed_official 27:4206883f4cb7 337 * Arguments : uint32_t Bsize ; Data Size
mbed_official 27:4206883f4cb7 338 * : uint8_t *Table ; Data Table Address
mbed_official 27:4206883f4cb7 339 * Return Value : USB_HOST_WRITESHRT ; End of data write
mbed_official 27:4206883f4cb7 340 * : USB_HOST_WRITEEND ; End of data write (not null)
mbed_official 27:4206883f4cb7 341 * : USB_HOST_WRITING ; Continue of data write
mbed_official 27:4206883f4cb7 342 * : USB_HOST_FIFOERROR ; FIFO access error
mbed_official 27:4206883f4cb7 343 *******************************************************************************/
mbed_official 27:4206883f4cb7 344 uint16_t usb0_host_CtrlWriteStart (uint32_t Bsize, uint8_t * Table)
mbed_official 27:4206883f4cb7 345 {
mbed_official 27:4206883f4cb7 346 uint16_t EndFlag_K;
mbed_official 27:4206883f4cb7 347 uint16_t mbw;
mbed_official 27:4206883f4cb7 348
mbed_official 27:4206883f4cb7 349 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 350 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 27:4206883f4cb7 351
mbed_official 27:4206883f4cb7 352 usb0_host_set_pid_nak(USB_HOST_PIPE0); /* Set NAK */
mbed_official 27:4206883f4cb7 353 g_usb0_host_data_count[USB_HOST_PIPE0] = Bsize; /* Transfer size set */
mbed_official 27:4206883f4cb7 354 g_usb0_host_data_pointer[USB_HOST_PIPE0] = Table; /* Transfer address set */
mbed_official 27:4206883f4cb7 355
mbed_official 27:4206883f4cb7 356 USB200.DCPCTR = USB_HOST_BITSQSET; /* SQSET=1, PID=NAK */
mbed_official 27:4206883f4cb7 357 #if(1) /* ohci_wrapp */
mbed_official 27:4206883f4cb7 358 Userdef_USB_usb0_host_delay_10us(3);
mbed_official 27:4206883f4cb7 359 #endif
mbed_official 27:4206883f4cb7 360 RZA_IO_RegWrite_16(&USB200.DCPCFG,
mbed_official 27:4206883f4cb7 361 1,
mbed_official 27:4206883f4cb7 362 USB_DCPCFG_DIR_SHIFT,
mbed_official 27:4206883f4cb7 363 USB_DCPCFG_DIR);
mbed_official 27:4206883f4cb7 364
mbed_official 27:4206883f4cb7 365 mbw = usb0_host_get_mbw(g_usb0_host_data_count[USB_HOST_PIPE0], (uint32_t)g_usb0_host_data_pointer[USB_HOST_PIPE0]);
mbed_official 27:4206883f4cb7 366 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_BITISEL, mbw);
mbed_official 27:4206883f4cb7 367 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
mbed_official 27:4206883f4cb7 368
mbed_official 27:4206883f4cb7 369 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 370 EndFlag_K = usb0_host_write_buffer_c(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 371 /* Host Control sequence */
mbed_official 27:4206883f4cb7 372 switch (EndFlag_K)
mbed_official 27:4206883f4cb7 373 {
mbed_official 27:4206883f4cb7 374 case USB_HOST_WRITESHRT: /* End of data write */
mbed_official 27:4206883f4cb7 375 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 27:4206883f4cb7 376 g_usb0_host_CmdStage |= USB_HOST_STAGE_STATUS;
mbed_official 27:4206883f4cb7 377 usb0_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
mbed_official 27:4206883f4cb7 378 usb0_host_enable_bemp_int(USB_HOST_PIPE0); /* Enable Empty Interrupt */
mbed_official 27:4206883f4cb7 379 break;
mbed_official 27:4206883f4cb7 380
mbed_official 27:4206883f4cb7 381 case USB_HOST_WRITEEND: /* End of data write (not null) */
mbed_official 27:4206883f4cb7 382 case USB_HOST_WRITING: /* Continue of data write */
mbed_official 27:4206883f4cb7 383 usb0_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
mbed_official 27:4206883f4cb7 384 usb0_host_enable_bemp_int(USB_HOST_PIPE0); /* Enable Empty Interrupt */
mbed_official 27:4206883f4cb7 385 break;
mbed_official 27:4206883f4cb7 386
mbed_official 27:4206883f4cb7 387 case USB_HOST_FIFOERROR: /* FIFO access error */
mbed_official 27:4206883f4cb7 388 break;
mbed_official 27:4206883f4cb7 389
mbed_official 27:4206883f4cb7 390 default:
mbed_official 27:4206883f4cb7 391 break;
mbed_official 27:4206883f4cb7 392 }
mbed_official 27:4206883f4cb7 393 usb0_host_set_pid_buf(USB_HOST_PIPE0); /* Set BUF */
mbed_official 27:4206883f4cb7 394 return (EndFlag_K); /* End or Err or Continue */
mbed_official 27:4206883f4cb7 395 }
mbed_official 27:4206883f4cb7 396
mbed_official 27:4206883f4cb7 397 /*******************************************************************************
mbed_official 27:4206883f4cb7 398 * Function Name: usb0_host_CtrlReadStart
mbed_official 27:4206883f4cb7 399 * Description : Executes USB control transfer/data stage(read).
mbed_official 27:4206883f4cb7 400 * Arguments : uint32_t Bsize ; Data Size
mbed_official 27:4206883f4cb7 401 * : uint8_t *Table ; Data Table Address
mbed_official 27:4206883f4cb7 402 * Return Value : none
mbed_official 27:4206883f4cb7 403 *******************************************************************************/
mbed_official 27:4206883f4cb7 404 void usb0_host_CtrlReadStart (uint32_t Bsize, uint8_t * Table)
mbed_official 27:4206883f4cb7 405 {
mbed_official 27:4206883f4cb7 406 uint16_t mbw;
mbed_official 27:4206883f4cb7 407
mbed_official 27:4206883f4cb7 408 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 27:4206883f4cb7 409 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 27:4206883f4cb7 410
mbed_official 27:4206883f4cb7 411 usb0_host_set_pid_nak(USB_HOST_PIPE0); /* Set NAK */
mbed_official 27:4206883f4cb7 412 g_usb0_host_data_count[USB_HOST_PIPE0] = Bsize; /* Transfer size set */
mbed_official 27:4206883f4cb7 413 g_usb0_host_data_pointer[USB_HOST_PIPE0] = Table; /* Transfer address set */
mbed_official 27:4206883f4cb7 414
mbed_official 27:4206883f4cb7 415 USB200.DCPCTR = USB_HOST_BITSQSET; /* SQSET=1, PID=NAK */
mbed_official 27:4206883f4cb7 416 #if(1) /* ohci_wrapp */
mbed_official 27:4206883f4cb7 417 Userdef_USB_usb0_host_delay_10us(3);
mbed_official 27:4206883f4cb7 418 #endif
mbed_official 27:4206883f4cb7 419 RZA_IO_RegWrite_16(&USB200.DCPCFG,
mbed_official 27:4206883f4cb7 420 0,
mbed_official 27:4206883f4cb7 421 USB_DCPCFG_DIR_SHIFT,
mbed_official 27:4206883f4cb7 422 USB_DCPCFG_DIR);
mbed_official 27:4206883f4cb7 423
mbed_official 27:4206883f4cb7 424 mbw = usb0_host_get_mbw(g_usb0_host_data_count[USB_HOST_PIPE0], (uint32_t)g_usb0_host_data_pointer[USB_HOST_PIPE0]);
mbed_official 27:4206883f4cb7 425 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_NO, mbw);
mbed_official 27:4206883f4cb7 426 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
mbed_official 27:4206883f4cb7 427
mbed_official 27:4206883f4cb7 428 usb0_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
mbed_official 27:4206883f4cb7 429 usb0_host_enable_brdy_int(USB_HOST_PIPE0); /* Ok */
mbed_official 27:4206883f4cb7 430 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 27:4206883f4cb7 431 usb0_host_set_pid_buf(USB_HOST_PIPE0); /* Set BUF */
mbed_official 27:4206883f4cb7 432 }
mbed_official 27:4206883f4cb7 433
mbed_official 27:4206883f4cb7 434 /* End of File */