ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_usb.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ___FW_USB_H___
16#define ___FW_USB_H___
17
18#include "fw_conf.h"
19#include "fw_types.h"
20
25#define FADDR 0x00
26#define POWER 0x01
27#define INTRIN1 0x02
28#define EP5INIF 0x20
29#define EP4INIF 0x10
30#define EP3INIF 0x08
31#define EP2INIF 0x04
32#define EP1INIF 0x02
33#define EP0IF 0x01
34#define INTROUT1 0x04
35#define EP5OUTIF 0x20
36#define EP4OUTIF 0x10
37#define EP3OUTIF 0x08
38#define EP2OUTIF 0x04
39#define EP1OUTIF 0x02
40#define INTRUSB 0x06
41#define SOFIF 0x08
42#define RSTIF 0x04
43#define RSUIF 0x02
44#define SUSIF 0x01
45#define INTRIN1E 0x07
46#define EP5INIE 0x20
47#define EP4INIE 0x10
48#define EP3INIE 0x08
49#define EP2INIE 0x04
50#define EP1INIE 0x02
51#define EP0IE 0x01
52#define INTROUT1E 0x09
53#define EP5OUTIE 0x20
54#define EP4OUTIE 0x10
55#define EP3OUTIE 0x08
56#define EP2OUTIE 0x04
57#define EP1OUTIE 0x02
58#define INTRUSBE 0x0B
59#define SOFIE 0x08
60#define RSTIE 0x04
61#define RSUIE 0x02
62#define SUSIE 0x01
63#define FRAME1 0x0C
64#define FRAME2 0x0D
65#define INDEX 0x0E
66#define INMAXP 0x10
67#define CSR0 0x11
68#define SSUEND 0x80 // Serviced Setup End
69#define SOPRDY 0x40 // Serviced OPRDY(Out Packet Ready)
70#define SDSTL 0x20 // Send Stall
71#define SUEND 0x10 // Setup End
72#define DATEND 0x08 // Data End
73#define STSTL 0x04 // Sent Stall
74#define IPRDY 0x02 // In Packet Ready
75#define OPRDY 0x01 // Out Packet Ready
76#define INCSR1 0x11
77#define INCLRDT 0x40
78#define INSTSTL 0x20
79#define INSDSTL 0x10
80#define INFLUSH 0x08
81#define INUNDRUN 0x04
82#define INFIFONE 0x02
83#define INIPRDY 0x01
84#define INCSR2 0x12
85#define INAUTOSET 0x80
86#define INISO 0x40
87#define INMODEIN 0x20
88#define INMODEOUT 0x00
89#define INENDMA 0x10
90#define INFCDT 0x08
91#define OUTMAXP 0x13
92#define OUTCSR1 0x14
93#define OUTCLRDT 0x80
94#define OUTSTSTL 0x40
95#define OUTSDSTL 0x20
96#define OUTFLUSH 0x10
97#define OUTDATERR 0x08
98#define OUTOVRRUN 0x04
99#define OUTFIFOFUL 0x02
100#define OUTOPRDY 0x01
101#define OUTCSR2 0x15
102#define OUTAUTOCLR 0x80
103#define OUTISO 0x40
104#define OUTENDMA 0x20
105#define OUTDMAMD 0x10
106#define COUNT0 0x16
107#define OUTCOUNT1 0x16
108#define OUTCOUNT2 0x17
109#define FIFO0 0x20
110#define FIFO1 0x21
111#define FIFO2 0x22
112#define FIFO3 0x23
113#define FIFO4 0x24
114#define FIFO5 0x25
115#define UTRKCTL 0x30
116#define UTRKSTS 0x31
117
118typedef enum _CONTROL_STATE
119{
125} USB_CtrlState_t; /* The state machine states of a control pipe */
126
127typedef enum
128{
141
142typedef enum
143{
151
152typedef enum
153{
163
164#define REQUEST_TYPE_MASK 0x60
165
166typedef enum
167{
172
173typedef enum
174{
176 USB_ClockSource_12M = 0x01, // default value
180
181typedef enum
182{
188
189#define USB_SetClockPPL(__STATE__) SFR_ASSIGN(USBCLK, 7, __STATE__)
190#define USB_SetClockSource(__SOURCE__) SFR_ASSIGN2BIT(USBCLK, 5, __SOURCE__)
191#define USB_SetClockCRE(__STATE__) SFR_ASSIGN(USBCLK, 4, __STATE__)
192#define USB_SetUSBTestMode(__STATE__) SFR_ASSIGN(USBCLK, 3, __STATE__)
193#define USB_SetPHYTestMode(__STATE__) SFR_ASSIGN(USBCLK, 2, __STATE__)
194#define USB_SetPHYTestMethod(__TEST_METHOD__) SFR_ASSIGN2BIT(USBCLK, 0, __TEST_METHOD__)
195
196#define USB_SetEnabled(__STATE__) SFR_ASSIGN(USBCON, 7, __STATE__)
197#define USB_TurnOnReset() SFR_SET(USBCON, 6)
198#define USB_TurnOffReset() SFR_RESET(USBCON, 6)
199#define USB_SetPS2Mode(__STATE__) SFR_ASSIGN(USBCON, 5, __STATE__)
203#define USB_SetDpDmPullUp(__STATE__) SFR_ASSIGN(USBCON, 4, __STATE__)
207#define USB_SetDpDmPullDown(__STATE__) SFR_ASSIGN(USBCON, 3, __STATE__)
208#define USB_GetDiffRecvMode() (USBCON & 0x04)
212#define USB_GetDp() (USBCON & 0x02)
216#define USB_SetDp(__STATE__) SFR_ASSIGN(USBCON, 1, __STATE__)
220#define USB_GetDm() (USBCON & 0x01)
224#define USB_SetDm(__STATE__) SFR_ASSIGN(USBCON, 0, __STATE__)
225
226#define USB_IsBusy() (USBADR & 0x80)
227#define USB_SetAddrForRead(__ADDR__) (USBADR = (__ADDR__) | 0x80)
228#define USB_SetAddrForWrite(__ADDR__) (USBADR = (__ADDR__) & 0x7F)
229
230#define USB_SelectEndPoint(__INDEX__) USB_WriteReg(INDEX, __INDEX__)
231
232
233typedef union
234{
236 struct _bb
237 {
240 } bb;
242
243typedef struct
244{
251
252typedef struct
253{
258
259
263void USB_WriteFIFO(uint8_t fifo, uint8_t *pdat, uint8_t cnt);
264
265#endif
__CODE int8_t dat[20]
unsigned short uint16_t
Definition: fw_types.h:19
unsigned char uint8_t
Definition: fw_types.h:18
USB_HidReq_t
Definition: fw_usb.h:143
@ USB_HidReq_GetIdle
Definition: fw_usb.h:145
@ USB_HidReq_SetIdle
Definition: fw_usb.h:148
@ USB_HidReq_SetReport
Definition: fw_usb.h:147
@ USB_HidReq_SetProtocol
Definition: fw_usb.h:149
@ USB_HidReq_GetReport
Definition: fw_usb.h:144
@ USB_HidReq_GetProtocol
Definition: fw_usb.h:146
void USB_WriteReg(uint8_t addr, uint8_t dat)
uint8_t USB_ReadReg(uint8_t addr)
void USB_WriteFIFO(uint8_t fifo, uint8_t *pdat, uint8_t cnt)
USB_RequestType_t
Definition: fw_usb.h:167
@ USB_RequestType_Vendor
Definition: fw_usb.h:170
@ USB_RequestType_Standard
Definition: fw_usb.h:168
@ USB_RequestType_Class
Definition: fw_usb.h:169
uint8_t USB_ReadFIFO(uint8_t fifo, uint8_t *pdat)
_CONTROL_STATE
Definition: fw_usb.h:119
@ USB_CtrlState_DataIn
Definition: fw_usb.h:122
@ USB_CtrlState_Stalled
Definition: fw_usb.h:124
@ USB_CtrlState_Idle
Definition: fw_usb.h:120
@ USB_CtrlState_DataOut
Definition: fw_usb.h:123
@ USB_CtrlState_SettingUp
Definition: fw_usb.h:121
USB_ClockSource_t
Definition: fw_usb.h:174
@ USB_ClockSource_12M
Definition: fw_usb.h:176
@ USB_ClockSource_24M
Definition: fw_usb.h:177
@ USB_ClockSource_IRCDiv2
Definition: fw_usb.h:178
@ USB_ClockSource_6M
Definition: fw_usb.h:175
USB_DescriptorType_t
Definition: fw_usb.h:153
@ USB_DescriptorType_String
Definition: fw_usb.h:156
@ USB_DescriptorType_Physical
Definition: fw_usb.h:161
@ USB_DescriptorType_Report
Definition: fw_usb.h:160
@ USB_DescriptorType_Interface
Definition: fw_usb.h:157
@ USB_DescriptorType_Endpoint
Definition: fw_usb.h:158
@ USB_DescriptorType_Device
Definition: fw_usb.h:154
@ USB_DescriptorType_HID
Definition: fw_usb.h:159
@ USB_DescriptorType_Configuration
Definition: fw_usb.h:155
USB_StdReq_t
Definition: fw_usb.h:128
@ USB_StdReq_GetStatus
Definition: fw_usb.h:129
@ USB_StdReq_GetDescriptor
Definition: fw_usb.h:133
@ USB_StdReq_SetDescriptor
Definition: fw_usb.h:134
@ USB_StdReq_ClearFeature
Definition: fw_usb.h:130
@ USB_StdReq_SynchFrame
Definition: fw_usb.h:139
@ USB_StdReq_SetConfiguration
Definition: fw_usb.h:136
@ USB_StdReq_SetFeature
Definition: fw_usb.h:131
@ USB_StdReq_SetAddress
Definition: fw_usb.h:132
@ USB_StdReq_GetConfiguration
Definition: fw_usb.h:135
@ USB_StdReq_GetInterface
Definition: fw_usb.h:137
@ USB_StdReq_SetInterface
Definition: fw_usb.h:138
USB_PHYTest_Method_t
Definition: fw_usb.h:182
@ USB_PHYTest_Method_Force0
Definition: fw_usb.h:185
@ USB_PHYTest_Method_ForceOneEnd0
Definition: fw_usb.h:186
@ USB_PHYTest_Method_Normal
Definition: fw_usb.h:183
@ USB_PHYTest_Method_Force1
Definition: fw_usb.h:184
enum _CONTROL_STATE USB_CtrlState_t
uint8_t addr[8]
Definition: main.c:28
uint16_t wResidue
Definition: fw_usb.h:255
uint8_t bStage
Definition: fw_usb.h:254
uint8_t * pData
Definition: fw_usb.h:256
uint16_2uint8_t wLength
Definition: fw_usb.h:249
uint8_t bmRequestType
Definition: fw_usb.h:245
uint16_2uint8_t wIndex
Definition: fw_usb.h:248
uint8_t bRequest
Definition: fw_usb.h:246
uint16_2uint8_t wValue
Definition: fw_usb.h:247
uint16_t w
Definition: fw_usb.h:235