• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 #include "usbhw.h"
19 /**
20  * @brief      This function disables the manual interrupt
21  *             (Endpont8 is the alias of endpoint0)
22  * @param[in]  m - the irq mode needs to set
23  * @return     none
24  */
usbhw_disable_manual_interrupt(int m)25 void usbhw_disable_manual_interrupt(int m)
26 {
27     BM_SET(reg_ctrl_ep_irq_mode, m);
28 }
29 
30 /**
31  * @brief      This function enable the manual interrupt
32  * @param[in]  m - the irq mode needs to set
33  * @return     none
34  */
usbhw_enable_manual_interrupt(int m)35 void usbhw_enable_manual_interrupt(int m)
36 {
37     BM_CLR(reg_ctrl_ep_irq_mode, m);
38 }
39 
40 /**
41  * @brief      This function sends a bulk of data to host via the specified endpoint
42  * @param[in]  ep - the number of the endpoint
43  * @param[in]  data - pointer to the data need to send
44  * @param[in]  len - length in byte of the data need to send
45  * @return     none
46  */
usbhw_write_ep(unsigned int ep,unsigned char * data,int len)47 void usbhw_write_ep(unsigned int ep, unsigned char *data, int len)
48 {
49     reg_usb_ep_ptr(ep) = 0;
50 
51     for (int i = 0; i < (len); ++i) {
52         reg_usb_ep_dat(ep) = data[i];
53     }
54     reg_usb_ep_ctrl(ep) = FLD_EP_DAT_ACK;  // ACK
55 }
56 
57 /**
58  * @brief      This function sends two bytes data to host via the control endpoint
59  *             (handy help function)
60  * @param[in]  v - the two bytes data need to send
61  * @return     none
62  */
usbhw_write_ctrl_ep_u16(unsigned short v)63 void usbhw_write_ctrl_ep_u16(unsigned short v)
64 {
65     usbhw_write_ctrl_ep_data(v & 0xff);
66     usbhw_write_ctrl_ep_data(v >> 8);
67 }
68 
69 /**
70  * @brief   This function reads two bytes data from host via the control endpoint
71  * @param   none
72  * @return  the two bytes data read from the control endpoint
73  */
usbhw_read_ctrl_ep_u16(void)74 unsigned short usbhw_read_ctrl_ep_u16(void)
75 {
76     unsigned short v = usbhw_read_ctrl_ep_data();
77     return (usbhw_read_ctrl_ep_data() << 8) | v;
78 }
79