mirror of
https://github.com/m24h/DAPLINK_C6T6.git
synced 2026-09-27 06:26:17 +00:00
1
This commit is contained in:
@@ -0,0 +1,694 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
* RL-ARM - A P I
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RTL.H
|
||||
* Purpose: Application Programming Interface
|
||||
* Rev.: V4.73
|
||||
*----------------------------------------------------------------------------
|
||||
* This code is part of the RealView Run-Time Library.
|
||||
* Copyright (c) 2004-2014 KEIL - An ARM Company. All rights reserved.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __RTL_H__
|
||||
#define __RTL_H__
|
||||
|
||||
/* RL-ARM version number. */
|
||||
#define __RL_ARM_VER 473
|
||||
|
||||
#define __task __declspec(noreturn)
|
||||
#define __used __attribute__((used))
|
||||
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
#ifndef __size_t
|
||||
#define __size_t 1
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
|
||||
typedef signed char S8;
|
||||
typedef unsigned char U8;
|
||||
typedef short S16;
|
||||
typedef unsigned short U16;
|
||||
typedef int S32;
|
||||
typedef unsigned int U32;
|
||||
typedef long long S64;
|
||||
typedef unsigned long long U64;
|
||||
typedef unsigned char BIT;
|
||||
typedef unsigned int BOOL;
|
||||
|
||||
#ifndef __TRUE
|
||||
#define __TRUE 1
|
||||
#endif
|
||||
#ifndef __FALSE
|
||||
#define __FALSE 0
|
||||
#endif
|
||||
|
||||
#ifdef __BIG_ENDIAN
|
||||
#define U32_LE(v) (U32)(__rev(v))
|
||||
#define U16_LE(v) (U16)(__rev(v) >> 16)
|
||||
#define U32_BE(v) (U32)(v)
|
||||
#define U16_BE(v) (U16)(v)
|
||||
#else
|
||||
#define U32_BE(v) (U32)(__rev(v))
|
||||
#define U16_BE(v) (U16)(__rev(v) >> 16)
|
||||
#define U32_LE(v) (U32)(v)
|
||||
#define U16_LE(v) (U16)(v)
|
||||
#endif
|
||||
#define ntohs(v) U16_BE(v)
|
||||
#define ntohl(v) U32_BE(v)
|
||||
#define htons(v) ntohs(v)
|
||||
#define htonl(v) ntohl(v)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX Kernel API
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Definition of Semaphore type */
|
||||
typedef U32 OS_SEM[2];
|
||||
|
||||
/* Definition of Mailbox type */
|
||||
#define os_mbx_declare(name,cnt) U32 name [4 + cnt]
|
||||
typedef U32 OS_MBX[];
|
||||
|
||||
/* Definition of Mutex type */
|
||||
typedef U32 OS_MUT[4];
|
||||
|
||||
/* Task Identification number. */
|
||||
typedef U32 OS_TID;
|
||||
|
||||
/* Function return of system calls returning an object identification */
|
||||
typedef void *OS_ID;
|
||||
|
||||
/* Function return of system calls indicating an event or completion state */
|
||||
typedef U32 OS_RESULT;
|
||||
|
||||
/* Return codes */
|
||||
#define OS_R_TMO 0x01
|
||||
#define OS_R_EVT 0x02
|
||||
#define OS_R_SEM 0x03
|
||||
#define OS_R_MBX 0x04
|
||||
#define OS_R_MUT 0x05
|
||||
|
||||
#define OS_R_OK 0x00
|
||||
#define OS_R_NOK 0xff
|
||||
|
||||
#define OS_TCB_SIZE 56
|
||||
#define OS_TMR_SIZE 8
|
||||
|
||||
/* Error Codes */
|
||||
#define OS_ERR_STK_OVF 1
|
||||
#define OS_ERR_FIFO_OVF 2
|
||||
#define OS_ERR_MBX_OVF 3
|
||||
|
||||
#if !(__TARGET_ARCH_6S_M || __TARGET_ARCH_7_M || __TARGET_ARCH_7E_M)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions ARM
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Task Management */
|
||||
#define os_sys_init(tsk) os_sys_init0(tsk,0,NULL)
|
||||
#define os_sys_init_prio(tsk,prio) os_sys_init0(tsk,prio,NULL)
|
||||
#define os_sys_init_user(tsk,prio,stk,size) \
|
||||
os_sys_init0(tsk,prio|(size<<8),stk)
|
||||
#define os_tsk_create(tsk,prio) os_tsk_create0(tsk,prio,NULL,NULL)
|
||||
#define os_tsk_create_user(tsk,prio,stk,size) \
|
||||
os_tsk_create0(tsk,prio|(size<<8),stk,NULL)
|
||||
#define os_tsk_create_ex(tsk,prio,argv) os_tsk_create_ex0(tsk,prio,NULL,argv)
|
||||
#define os_tsk_create_user_ex(tsk,prio,stk,size,argv) \
|
||||
os_tsk_create_ex0(tsk,prio|(size<<8),stk,argv)
|
||||
#define os_tsk_delete_self() os_tsk_delete(0); for(;;)
|
||||
#define os_tsk_prio_self(prio) os_tsk_prio(0,prio)
|
||||
#define isr_tsk_get() os_tsk_self()
|
||||
|
||||
extern void os_sys_init0 (void (*task)(void), U32 prio_stksz, void *stk);
|
||||
extern OS_TID os_tsk_create0 (void (*task)(void), U32 prio_stksz,
|
||||
void *stk, void *argv);
|
||||
extern OS_TID os_tsk_create_ex0 (void (*task)(void *), U32 prio_stksz,
|
||||
void *stk, void *argv);
|
||||
extern OS_TID os_tsk_self (void);
|
||||
extern void os_tsk_pass (void);
|
||||
extern OS_RESULT os_tsk_prio (OS_TID task_id, U8 new_prio);
|
||||
extern OS_RESULT os_tsk_delete (OS_TID task_id);
|
||||
|
||||
/* Event flag Management */
|
||||
#define os_evt_wait_or(wflags,tmo) os_evt_wait(wflags,tmo,__FALSE)
|
||||
#define os_evt_wait_and(wflags,tmo) os_evt_wait(wflags,tmo,__TRUE)
|
||||
|
||||
extern OS_RESULT os_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait);
|
||||
extern void os_evt_set (U16 event_flags, OS_TID task_id);
|
||||
extern void os_evt_clr (U16 clear_flags, OS_TID task_id);
|
||||
extern void isr_evt_set (U16 event_flags, OS_TID task_id);
|
||||
extern U16 os_evt_get (void);
|
||||
|
||||
/* Semaphore Management */
|
||||
extern void os_sem_init (OS_ID semaphore, U16 token_count);
|
||||
extern OS_RESULT os_sem_send (OS_ID semaphore);
|
||||
extern OS_RESULT os_sem_wait (OS_ID semaphore, U16 timeout);
|
||||
extern void isr_sem_send (OS_ID semaphore);
|
||||
|
||||
/* Mailbox Management */
|
||||
#define isr_mbx_check(mbx) os_mbx_check(mbx)
|
||||
|
||||
extern void os_mbx_init (OS_ID mailbox, U16 mbx_size);
|
||||
extern OS_RESULT os_mbx_send (OS_ID mailbox, void *message_ptr, U16 timeout);
|
||||
extern OS_RESULT os_mbx_wait (OS_ID mailbox, void **message, U16 timeout);
|
||||
extern OS_RESULT os_mbx_check (OS_ID mailbox);
|
||||
extern void isr_mbx_send (OS_ID mailbox, void *message_ptr);
|
||||
extern OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message);
|
||||
|
||||
/* Mutex Management */
|
||||
extern void os_mut_init (OS_ID mutex);
|
||||
extern OS_RESULT os_mut_release (OS_ID mutex);
|
||||
extern OS_RESULT os_mut_wait (OS_ID mutex, U16 timeout);
|
||||
|
||||
/* Time Management */
|
||||
extern U32 os_time_get (void);
|
||||
extern void os_dly_wait (U16 delay_time);
|
||||
extern void os_itv_set (U16 interval_time);
|
||||
extern void os_itv_wait (void);
|
||||
|
||||
/* User Timer Management */
|
||||
extern OS_ID os_tmr_create (U16 tcnt, U16 info);
|
||||
extern OS_ID os_tmr_kill (OS_ID timer);
|
||||
|
||||
/* System Functions */
|
||||
extern U32 os_suspend (void);
|
||||
extern void os_resume (U32 sleep_time);
|
||||
extern void tsk_lock (void) __swi (5);
|
||||
extern void tsk_unlock (void);
|
||||
|
||||
/* Fixed Memory Block Management Functions */
|
||||
extern int _init_box (void *box_mem, U32 box_size, U32 blk_size);
|
||||
extern void *_alloc_box (void *box_mem) __swi (1);
|
||||
extern void *_calloc_box (void *box_mem);
|
||||
extern int _free_box (void *box_mem, void *box) __swi (2);
|
||||
|
||||
#else
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions Cortex-M
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#define __SVC_0 __svc_indirect(0)
|
||||
|
||||
/* Task Management */
|
||||
extern void os_set_env (void);
|
||||
extern void rt_sys_init (void (*task)(void), U8 priority, void *stk);
|
||||
extern void rt_tsk_pass (void);
|
||||
extern OS_TID rt_tsk_self (void);
|
||||
extern OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio);
|
||||
extern OS_TID rt_tsk_create (void (*task)(void), U8 priority, void *stk, void *argv);
|
||||
extern OS_RESULT rt_tsk_delete (OS_TID task_id);
|
||||
|
||||
#define os_sys_init(tsk) os_set_env(); \
|
||||
_os_sys_init((U32)rt_sys_init,tsk,0,NULL)
|
||||
#define os_sys_init_user(tsk,prio,stk,size) \
|
||||
os_set_env(); \
|
||||
_os_sys_init((U32)rt_sys_init,tsk,prio|(size<<8),stk)
|
||||
#define os_sys_init_prio(tsk,prio) os_set_env(); \
|
||||
_os_sys_init((U32)rt_sys_init,tsk,prio,NULL)
|
||||
#define os_tsk_create(tsk,prio) _os_tsk_create((U32)rt_tsk_create,tsk,prio,NULL,NULL)
|
||||
#define os_tsk_create_user(tsk,prio,stk,size) \
|
||||
_os_tsk_create((U32)rt_tsk_create,tsk,prio|(size<<8),stk,NULL)
|
||||
#define os_tsk_create_ex(tsk,prio,argv) _os_tsk_create_ex((U32)rt_tsk_create,tsk,prio,NULL,argv)
|
||||
#define os_tsk_create_user_ex(tsk,prio,stk,size,argv) \
|
||||
_os_tsk_create_ex((U32)rt_tsk_create,tsk,prio|(size<<8),stk,argv)
|
||||
#define os_tsk_self() _os_tsk_self((U32)rt_tsk_self)
|
||||
#define os_tsk_pass() _os_tsk_pass((U32)rt_tsk_pass)
|
||||
#define os_tsk_prio(task_id,new_prio) _os_tsk_prio((U32)rt_tsk_prio,task_id,new_prio)
|
||||
#define os_tsk_prio_self(prio) _os_tsk_prio((U32)rt_tsk_prio,0,prio)
|
||||
#define os_tsk_delete(task_id) _os_tsk_delete((U32)rt_tsk_delete,task_id)
|
||||
#define os_tsk_delete_self() _os_tsk_delete((U32)rt_tsk_delete, 0); for(;;)
|
||||
#define isr_tsk_get() rt_tsk_self()
|
||||
|
||||
extern void _os_sys_init(U32 p, void (*task)(void), U32 prio_stksz,
|
||||
void *stk) __SVC_0;
|
||||
extern OS_TID _os_tsk_create (U32 p, void (*task)(void), U32 prio_stksz,
|
||||
void *stk, void *argv) __SVC_0;
|
||||
extern OS_TID _os_tsk_create_ex (U32 p, void (*task)(void *), U32 prio_stksz,
|
||||
void *stk, void *argv) __SVC_0;
|
||||
extern OS_TID _os_tsk_self (U32 p) __SVC_0;
|
||||
extern void _os_tsk_pass (U32 p) __SVC_0;
|
||||
extern OS_RESULT _os_tsk_prio (U32 p, OS_TID task_id, U8 new_prio) __SVC_0;
|
||||
extern OS_RESULT _os_tsk_delete (U32 p, OS_TID task_id) __SVC_0;
|
||||
|
||||
/* Event flag Management */
|
||||
extern OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait);
|
||||
extern void rt_evt_set (U16 event_flags, OS_TID task_id);
|
||||
extern void rt_evt_clr (U16 clear_flags, OS_TID task_id);
|
||||
extern U16 rt_evt_get (void);
|
||||
|
||||
#define os_evt_wait_or(wflags,tmo) _os_evt_wait((U32)rt_evt_wait,wflags,tmo,__FALSE)
|
||||
#define os_evt_wait_and(wflags,tmo) _os_evt_wait((U32)rt_evt_wait,wflags,tmo,__TRUE)
|
||||
#define os_evt_set(evt_flags,task_id) _os_evt_set((U32)rt_evt_set,evt_flags,task_id)
|
||||
#define os_evt_clr(clr_flags,task_id) _os_evt_clr((U32)rt_evt_clr,clr_flags,task_id)
|
||||
#define os_evt_get() _os_evt_get((U32)rt_evt_get)
|
||||
|
||||
extern OS_RESULT _os_evt_wait(U32 p, U16 wait_flags, U16 timeout,
|
||||
BOOL and_wait) __SVC_0;
|
||||
extern void _os_evt_set (U32 p, U16 event_flags, OS_TID task_id) __SVC_0;
|
||||
extern void _os_evt_clr (U32 p, U16 clear_flags, OS_TID task_id) __SVC_0;
|
||||
extern U16 _os_evt_get (U32 p) __SVC_0;
|
||||
extern void isr_evt_set (U16 event_flags, OS_TID task_id);
|
||||
|
||||
/* Semaphore Management */
|
||||
extern void rt_sem_init (OS_ID semaphore, U16 token_count);
|
||||
extern OS_RESULT rt_sem_send (OS_ID semaphore);
|
||||
extern OS_RESULT rt_sem_wait (OS_ID semaphore, U16 timeout);
|
||||
|
||||
#define os_sem_init(sem,t_count) _os_sem_init((U32)rt_sem_init,sem,t_count)
|
||||
#define os_sem_send(sem) _os_sem_send((U32)rt_sem_send,sem)
|
||||
#define os_sem_wait(sem,tmo) _os_sem_wait((U32)rt_sem_wait,sem,tmo)
|
||||
|
||||
extern void _os_sem_init (U32 p, OS_ID semaphore,
|
||||
U16 token_count) __SVC_0;
|
||||
extern OS_RESULT _os_sem_send (U32 p, OS_ID semaphore) __SVC_0;
|
||||
extern OS_RESULT _os_sem_wait (U32 p, OS_ID semaphore, U16 timeout) __SVC_0;
|
||||
extern void isr_sem_send (OS_ID semaphore);
|
||||
|
||||
/* Mailbox Management */
|
||||
extern void rt_mbx_init (OS_ID mailbox, U16 mbx_size);
|
||||
extern OS_RESULT rt_mbx_send (OS_ID mailbox, void *p_msg, U16 timeout);
|
||||
extern OS_RESULT rt_mbx_wait (OS_ID mailbox, void **message, U16 timeout);
|
||||
extern OS_RESULT rt_mbx_check (OS_ID mailbox);
|
||||
|
||||
#define os_mbx_init(mbx,mbx_size) _os_mbx_init((U32)rt_mbx_init,mbx,mbx_size)
|
||||
#define os_mbx_send(mbx,p_msg,tmo) _os_mbx_send((U32)rt_mbx_send,mbx,p_msg,tmo)
|
||||
#define os_mbx_wait(mbx,message,tmo) _os_mbx_wait((U32)rt_mbx_wait,mbx,message,tmo)
|
||||
#define os_mbx_check(mbx) _os_mbx_check((U32)rt_mbx_check,mbx)
|
||||
#define isr_mbx_check(mbx) rt_mbx_check(mbx)
|
||||
|
||||
extern void _os_mbx_init (U32 p, OS_ID mailbox, U16 mbx_size) __SVC_0;
|
||||
extern OS_RESULT _os_mbx_send (U32 p, OS_ID mailbox, void *message_ptr,
|
||||
U16 timeout) __SVC_0;
|
||||
extern OS_RESULT _os_mbx_wait (U32 p, OS_ID mailbox, void **message,
|
||||
U16 timeout) __SVC_0;
|
||||
extern OS_RESULT _os_mbx_check (U32 p, OS_ID mailbox) __SVC_0;
|
||||
extern void isr_mbx_send (OS_ID mailbox, void *message_ptr);
|
||||
extern OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message);
|
||||
|
||||
/* Mutex Management */
|
||||
extern void rt_mut_init (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_release (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_wait (OS_ID mutex, U16 timeout);
|
||||
|
||||
#define os_mut_init(mutex) _os_mut_init((U32)rt_mut_init,mutex)
|
||||
#define os_mut_release(mutex) _os_mut_release((U32)rt_mut_release,mutex)
|
||||
#define os_mut_wait(mutex,timeout) _os_mut_wait((U32)rt_mut_wait,mutex,timeout)
|
||||
|
||||
extern void _os_mut_init (U32 p, OS_ID mutex) __SVC_0;
|
||||
extern OS_RESULT _os_mut_release (U32 p, OS_ID mutex) __SVC_0;
|
||||
extern OS_RESULT _os_mut_wait (U32 p, OS_ID mutex, U16 timeout) __SVC_0;
|
||||
|
||||
/* Time Management */
|
||||
extern U32 rt_time_get (void);
|
||||
extern void rt_dly_wait (U16 delay_time);
|
||||
extern void rt_itv_set (U16 interval_time);
|
||||
extern void rt_itv_wait (void);
|
||||
|
||||
#define os_time_get() _os_time_get((U32)rt_time_get)
|
||||
#define os_dly_wait(delay_time) _os_dly_wait((U32)rt_dly_wait,delay_time)
|
||||
#define os_itv_set(interval_time) _os_itv_set((U32)rt_itv_set,interval_time)
|
||||
#define os_itv_wait() _os_itv_wait((U32)rt_itv_wait)
|
||||
|
||||
extern U32 _os_time_get (U32 p) __SVC_0;
|
||||
extern void _os_dly_wait (U32 p, U16 delay_time) __SVC_0;
|
||||
extern void _os_itv_set (U32 p, U16 interval_time) __SVC_0;
|
||||
extern void _os_itv_wait (U32 p) __SVC_0;
|
||||
|
||||
/* User Timer Management */
|
||||
extern OS_ID rt_tmr_create (U16 tcnt, U16 info);
|
||||
extern OS_ID rt_tmr_kill (OS_ID timer);
|
||||
|
||||
#define os_tmr_create(tcnt,info) _os_tmr_create((U32)rt_tmr_create,tcnt,info)
|
||||
#define os_tmr_kill(timer) _os_tmr_kill((U32)rt_tmr_kill,timer)
|
||||
|
||||
extern OS_ID _os_tmr_create (U32 p, U16 tcnt, U16 info) __SVC_0;
|
||||
extern OS_ID _os_tmr_kill (U32 p, OS_ID timer) __SVC_0;
|
||||
|
||||
/* System Functions */
|
||||
extern U32 rt_suspend (void);
|
||||
extern void rt_resume (U32 sleep_time);
|
||||
extern void rt_tsk_lock (void);
|
||||
extern void rt_tsk_unlock (void);
|
||||
|
||||
#define os_suspend() _os_suspend((U32)rt_suspend)
|
||||
#define os_resume(sleep_time) _os_resume((U32)rt_resume,sleep_time)
|
||||
#define tsk_lock() _os_tsk_lock((U32)rt_tsk_lock)
|
||||
#define tsk_unlock() _os_tsk_unlock((U32)rt_tsk_unlock)
|
||||
|
||||
extern U32 _os_suspend (U32 p) __SVC_0;
|
||||
extern void _os_resume (U32 p, U32 sleep_time) __SVC_0;
|
||||
extern void _os_tsk_lock (U32 p) __SVC_0;
|
||||
extern void _os_tsk_unlock (U32 p) __SVC_0;
|
||||
|
||||
/* Fixed Memory Block Management Functions */
|
||||
extern int _init_box (void *box_mem, U32 box_size, U32 blk_size);
|
||||
extern void *_alloc_box (void *box_mem);
|
||||
extern void *_calloc_box (void *box_mem);
|
||||
extern int _free_box (void *box_mem, void *box);
|
||||
|
||||
#endif
|
||||
|
||||
#define BOX_ALIGN_8 0x80000000
|
||||
#define _declare_box(pool,size,cnt) U32 pool[(((size)+3)/4)*(cnt) + 3]
|
||||
#define _declare_box8(pool,size,cnt) U64 pool[(((size)+7)/8)*(cnt) + 2]
|
||||
#define _init_box8(pool,size,bsize) _init_box (pool,size,bsize | BOX_ALIGN_8)
|
||||
|
||||
/* For compatibility with older configurations.*/
|
||||
#define os_stk_overflow os_error
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Flash File System API
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* File System Type */
|
||||
typedef enum _FS_TYPE {
|
||||
FS_TYPE_NONE = 0, /* No file system (volume unformatted)*/
|
||||
FS_TYPE_UNKNOWN, /* File system type is unknown */
|
||||
FS_TYPE_FAT12, /* File system type is FAT12 */
|
||||
FS_TYPE_FAT16, /* File system type is FAT16 */
|
||||
FS_TYPE_FAT32, /* File system type is FAT32 */
|
||||
FS_TYPE_EFS /* File system type is EFS */
|
||||
} FS_TYPE;
|
||||
|
||||
typedef struct { /* RL Time format (FFS, TCPnet) */
|
||||
U8 hr; /* Hours [0..23] */
|
||||
U8 min; /* Minutes [0..59] */
|
||||
U8 sec; /* Seconds [0..59] */
|
||||
U8 day; /* Day [1..31] */
|
||||
U8 mon; /* Month [1..12] */
|
||||
U16 year; /* Year [1980..2107] */
|
||||
} RL_TIME;
|
||||
|
||||
typedef struct { /* Search info record */
|
||||
S8 name[256]; /* Name */
|
||||
U32 size; /* File size in bytes */
|
||||
U16 fileID; /* System Identification */
|
||||
U8 attrib; /* Attributes */
|
||||
RL_TIME time; /* Create/Modify Time */
|
||||
} FINFO;
|
||||
|
||||
/* Drive information */
|
||||
typedef struct {
|
||||
FS_TYPE fs_type; /* Drives file system type */
|
||||
U64 capacity; /* Drives capacity in bytes */
|
||||
} Drive_INFO;
|
||||
|
||||
extern int finit (const char *drive);
|
||||
extern int funinit (const char *drive);
|
||||
extern int fdelete (const char *filename);
|
||||
extern int frename (const char *oldname, const char *newname);
|
||||
extern int ffind (const char *pattern, FINFO *info);
|
||||
extern U64 ffree (const char *drive);
|
||||
extern int fformat (const char *drive);
|
||||
extern int fanalyse (const char *drive);
|
||||
extern int fcheck (const char *drive);
|
||||
extern int fdefrag (const char *drive);
|
||||
extern int fattrib (const char *par, const char *path);
|
||||
extern int fvol (const char *drive, char *buf);
|
||||
extern int finfo (const char *drive, Drive_INFO *info);
|
||||
|
||||
/* The following macros provide for common functions */
|
||||
#define unlink(fn) fdelete(fn);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* TCPnet API
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* UDP Options */
|
||||
#define UDP_OPT_SEND_CS 0x01 /* Calculate Checksum for UDP send frames */
|
||||
#define UDP_OPT_CHK_CS 0x02 /* Verify Checksum for received UDP frames */
|
||||
|
||||
/* TCP Socket Types */
|
||||
#define TCP_TYPE_SERVER 0x01 /* Socket Type Server (open for listening) */
|
||||
#define TCP_TYPE_CLIENT 0x02 /* Socket Type Client (initiate connect) */
|
||||
#define TCP_TYPE_DELAY_ACK 0x04 /* Socket Type Delayed Acknowledge */
|
||||
#define TCP_TYPE_FLOW_CTRL 0x08 /* Socket Type Flow Control */
|
||||
#define TCP_TYPE_KEEP_ALIVE 0x10 /* Socket Type Keep Alive */
|
||||
#define TCP_TYPE_CLIENT_SERVER (TCP_TYPE_SERVER | TCP_TYPE_CLIENT)
|
||||
|
||||
/* TCP Callback Events */
|
||||
#define TCP_EVT_CONREQ 0 /* Connect request received event */
|
||||
#define TCP_EVT_CONNECT 1 /* Connection established event */
|
||||
#define TCP_EVT_CLOSE 2 /* Connection was properly closed */
|
||||
#define TCP_EVT_ABORT 3 /* Connection is for some reason aborted */
|
||||
#define TCP_EVT_ACK 4 /* Previously send data acknowledged */
|
||||
#define TCP_EVT_DATA 5 /* Data received event */
|
||||
|
||||
/* TCP States */
|
||||
#define TCP_STATE_FREE 0 /* Entry is free and unused */
|
||||
#define TCP_STATE_CLOSED 1 /* Entry allocated, socket still closed */
|
||||
#define TCP_STATE_LISTEN 2 /* Socket waiting for incoming connection */
|
||||
#define TCP_STATE_SYN_REC 3 /* SYN frame received */
|
||||
#define TCP_STATE_SYN_SENT 4 /* SYN packet sent to establish a connect. */
|
||||
#define TCP_STATE_FINW1 5 /* Tcp_close started FIN packet was sent */
|
||||
#define TCP_STATE_FINW2 6 /* Our FIN ack-ed, waiting for remote FIN */
|
||||
#define TCP_STATE_CLOSING 7 /* Received FIN independently of our FIN */
|
||||
#define TCP_STATE_LAST_ACK 8 /* Waiting for last ACK for our FIN */
|
||||
#define TCP_STATE_TWAIT 9 /* Timed waiting for 2MSL */
|
||||
#define TCP_STATE_CONNECT 10 /* TCP Connection established */
|
||||
|
||||
/* BSD Socket Address Family */
|
||||
#define AF_UNSPEC 0 /* Unspecified */
|
||||
#define AF_INET 1 /* Internet Address Family (UDP, TCP) */
|
||||
#define AF_NETBIOS 2 /* NetBios-style addresses */
|
||||
|
||||
/* BSD Protocol families, same as address families */
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
#define PF_INET AF_INET
|
||||
#define PF_NETBIOS AF_NETBIOS
|
||||
|
||||
/* BSD Socket Type */
|
||||
#define SOCK_STREAM 1 /* Stream Socket (Connection oriented) */
|
||||
#define SOCK_DGRAM 2 /* Datagram Socket (Connectionless) */
|
||||
|
||||
/* BSD Socket Protocol */
|
||||
#define IPPROTO_TCP 1 /* TCP Protocol */
|
||||
#define IPPROTO_UDP 2 /* UDP Protocol */
|
||||
|
||||
/* BSD Internet Addresses */
|
||||
#define INADDR_ANY 0x00000000 /* All IP addresses accepted */
|
||||
#define INADDR_NONE 0xffffffff /* No IP address accepted */
|
||||
|
||||
/* BSD Socket Return values */
|
||||
#define SCK_SUCCESS 0 /* Success */
|
||||
#define SCK_ERROR (-1) /* General Error */
|
||||
#define SCK_EINVALID (-2) /* Invalid socket descriptor */
|
||||
#define SCK_EINVALIDPARA (-3) /* Invalid parameter */
|
||||
#define SCK_EWOULDBLOCK (-4) /* It would have blocked. */
|
||||
#define SCK_EMEMNOTAVAIL (-5) /* Not enough memory in memory pool */
|
||||
#define SCK_ECLOSED (-6) /* Connection is closed or aborted */
|
||||
#define SCK_ELOCKED (-7) /* Socket is locked in RTX environment */
|
||||
#define SCK_ETIMEOUT (-8) /* Socket, Host Resolver timeout */
|
||||
#define SCK_EINPROGRESS (-9) /* Host Name resolving in progress */
|
||||
#define SCK_ENONAME (-10) /* Host Name not existing */
|
||||
|
||||
/* BSD Socket flags parameter */
|
||||
#define MSG_DONTWAIT 0x01 /* Enables non-blocking operation */
|
||||
#define MSG_PEEK 0x02 /* Peeks at the incoming data */
|
||||
|
||||
/* BSD Socket ioctl commands */
|
||||
#define FIONBIO 1 /* Set mode (blocking/non-blocking) */
|
||||
#define FIO_DELAY_ACK 2 /* Set DELAY_ACK mode for stream socket */
|
||||
#define FIO_KEEP_ALIVE 3 /* Set KEEP_ALIVE mode for stream socket */
|
||||
#define FIO_FLOW_CTRL 4 /* Set FLOW_CTRL mode for stream socket */
|
||||
|
||||
/* ICMP (ping) Callback Events */
|
||||
#define ICMP_EVT_SUCCESS 0 /* Pinged Host responded */
|
||||
#define ICMP_EVT_TIMEOUT 1 /* Timeout, no ping response received */
|
||||
|
||||
/* DNS Client Callback Events */
|
||||
#define DNS_EVT_SUCCESS 0 /* Host name successfully resolved */
|
||||
#define DNS_EVT_NONAME 1 /* DNS Error, no such name */
|
||||
#define DNS_EVT_TIMEOUT 2 /* Timeout resolving host */
|
||||
#define DNS_EVT_ERROR 3 /* Erroneous response packet */
|
||||
|
||||
/* DNS 'get_host_by_name()' result codes */
|
||||
#define DNS_RES_OK 0 /* Resolver successfully started */
|
||||
#define DNS_ERROR_BUSY 1 /* Resolver busy, can't process request */
|
||||
#define DNS_ERROR_LABEL 2 /* Label in Hostname not valid */
|
||||
#define DNS_ERROR_NAME 3 /* Entire Hostname not valid */
|
||||
#define DNS_ERROR_NOSRV 4 /* Prim. DNS server not specified (0.0.0.0)*/
|
||||
#define DNS_ERROR_PARAM 5 /* Invalid parameter */
|
||||
|
||||
/* SMTP Client Callback Events */
|
||||
#define SMTP_EVT_SUCCESS 0 /* Email successfully sent */
|
||||
#define SMTP_EVT_TIMEOUT 1 /* Timeout sending email */
|
||||
#define SMTP_EVT_ERROR 2 /* Error when sending email */
|
||||
|
||||
/* FTP Client Commands */
|
||||
#define FTPC_CMD_PUT 0 /* Puts a file on FTP server */
|
||||
#define FTPC_CMD_GET 1 /* Retrieves a file from FTP server */
|
||||
#define FTPC_CMD_APPEND 2 /* Append file on FTP server (with create) */
|
||||
#define FTPC_CMD_DELETE 3 /* Deletes a file on FTP server */
|
||||
#define FTPC_CMD_LIST 4 /* Lists files stored on FTP server */
|
||||
#define FTPC_CMD_RENAME 5 /* Renames a file on FTP server */
|
||||
#define FTPC_CMD_MKDIR 6 /* Makes a directory on FTP server */
|
||||
#define FTPC_CMD_RMDIR 7 /* Removes an empty directory on FTP server*/
|
||||
#define FTPC_CMD_NLIST 8 /* Lists file names only (short format) */
|
||||
|
||||
/* FTP Client Callback Events */
|
||||
#define FTPC_EVT_SUCCESS 0 /* File operation successful */
|
||||
#define FTPC_EVT_TIMEOUT 1 /* Timeout on file operation */
|
||||
#define FTPC_EVT_LOGINFAIL 2 /* Login error, username/passw invalid */
|
||||
#define FTPC_EVT_NOACCESS 3 /* File access not allowed */
|
||||
#define FTPC_EVT_NOTFOUND 4 /* File not found */
|
||||
#define FTPC_EVT_NOPATH 5 /* Working directory path not found */
|
||||
#define FTPC_EVT_ERRLOCAL 6 /* Local file open error */
|
||||
#define FTPC_EVT_ERROR 7 /* Generic FTP client error */
|
||||
|
||||
/* TFTP Client Callback Events */
|
||||
#define TFTPC_EVT_SUCCESS 0 /* File operation successful */
|
||||
#define TFTPC_EVT_TIMEOUT 1 /* Timeout on file operation */
|
||||
#define TFTPC_EVT_NOACCESS 2 /* File access not allowed */
|
||||
#define TFTPC_EVT_NOTFOUND 3 /* File not found */
|
||||
#define TFTPC_EVT_DISKFULL 4 /* Disk full (local or remote) */
|
||||
#define TFTPC_EVT_ERROR 5 /* Generic TFTP client error */
|
||||
|
||||
/* FTP Server Notification events */
|
||||
#define FTP_EVT_LOGIN 0 /* User logged in, session is busy */
|
||||
#define FTP_EVT_LOGOUT 1 /* User logged out, session is idle */
|
||||
#define FTP_EVT_LOGFAIL 2 /* User login failed (invalid credentials) */
|
||||
#define FTP_EVT_DOWNLOAD 3 /* File download ended */
|
||||
#define FTP_EVT_UPLOAD 4 /* File upload ended */
|
||||
#define FTP_EVT_DELETE 5 /* File deleted */
|
||||
#define FTP_EVT_RENAME 6 /* File or directory renamed */
|
||||
#define FTP_EVT_MKDIR 7 /* Directory created */
|
||||
#define FTP_EVT_RMDIR 8 /* Directory removed */
|
||||
#define FTP_EVT_ERRLOCAL 9 /* Local file operation error */
|
||||
#define FTP_EVT_DENIED 10 /* Requested file operation denied */
|
||||
#define FTP_EVT_ERROR 11 /* Generic file operation error */
|
||||
|
||||
/* ARP Cache Entry types */
|
||||
#define ARP_FIXED_IP 0 /* Fixed IP adrs is refreshed after tout */
|
||||
#define ARP_TEMP_IP 1 /* Temp adrs is removed after timeout */
|
||||
|
||||
/* BSD Socket typedef's */
|
||||
typedef struct sockaddr { /* << Generic Socket Address structure >> */
|
||||
U16 sa_family; /* Address family */
|
||||
char sa_data[14]; /* Direct address (up to 14 bytes) */
|
||||
} SOCKADDR;
|
||||
|
||||
#pragma push
|
||||
#pragma anon_unions
|
||||
|
||||
typedef struct in_addr { /* << Generic IPv4 Address structure >> */
|
||||
union {
|
||||
struct {
|
||||
U8 s_b1,s_b2,s_b3,s_b4; /* IP address, byte access */
|
||||
};
|
||||
struct {
|
||||
U16 s_w1,s_w2; /* IP address, short int access */
|
||||
};
|
||||
U32 s_addr; /* IP address in network byte order */
|
||||
};
|
||||
} IN_ADDR;
|
||||
#pragma pop
|
||||
|
||||
typedef struct sockaddr_in { /* << IPv4 Socket Address structure >> */
|
||||
S16 sin_family; /* Socket domain */
|
||||
U16 sin_port; /* Port */
|
||||
IN_ADDR sin_addr; /* IP address */
|
||||
S8 sin_zero[8]; /* reserved */
|
||||
} SOCKADDR_IN;
|
||||
|
||||
typedef struct hostent { /* << BSD Host Entry structure >> */
|
||||
char *h_name; /* Official name of host */
|
||||
char **h_aliases; /* Pointer to an array of alias names */
|
||||
S16 h_addrtype; /* Address Type: AF_INET, AF_NETBIOS */
|
||||
S16 h_length; /* Length of address in bytes */
|
||||
char **h_addr_list; /* Pointer to an array of IPv4 addresses */
|
||||
} HOSTENT;
|
||||
|
||||
extern void init_TcpNet (void);
|
||||
extern BOOL main_TcpNet (void);
|
||||
extern void timer_tick (void);
|
||||
extern U8 udp_get_socket (U8 tos, U8 opt,
|
||||
U16 (*listener)(U8 socket, U8 *remip, U16 port, U8 *buf, U16 len));
|
||||
extern BOOL udp_release_socket (U8 socket);
|
||||
extern BOOL udp_open (U8 socket, U16 locport);
|
||||
extern BOOL udp_close (U8 socket);
|
||||
extern BOOL udp_mcast_ttl (U8 socket, U8 ttl);
|
||||
extern U8 *udp_get_buf (U16 size);
|
||||
extern BOOL udp_send (U8 socket, U8 *remip, U16 remport, U8 *buf, U16 dlen);
|
||||
extern U8 tcp_get_socket (U8 type, U8 tos, U16 tout,
|
||||
U16 (*listener)(U8 socket, U8 event, U8 *buf, U16 len));
|
||||
extern BOOL tcp_release_socket (U8 socket);
|
||||
extern BOOL tcp_listen (U8 socket, U16 locport);
|
||||
extern BOOL tcp_connect (U8 socket, U8 *remip, U16 remport, U16 locport);
|
||||
extern U8 *tcp_get_buf (U16 size);
|
||||
extern U16 tcp_max_dsize (U8 socket);
|
||||
extern BOOL tcp_check_send (U8 socket);
|
||||
extern U8 tcp_get_state (U8 socket);
|
||||
extern BOOL tcp_send (U8 socket, U8 *buf, U16 dlen);
|
||||
extern BOOL tcp_close (U8 socket);
|
||||
extern BOOL tcp_abort (U8 socket);
|
||||
extern void tcp_reset_window (U8 socket);
|
||||
extern BOOL arp_cache_ip (U8 *ipadr, U8 type);
|
||||
extern BOOL arp_cache_mac (U8 *hwadr);
|
||||
extern void ppp_listen (const char *user, const char *passw);
|
||||
extern void ppp_connect (const char *dialnum, const char *user, const char *passw);
|
||||
extern void ppp_close (void);
|
||||
extern BOOL ppp_is_up (void);
|
||||
extern void slip_listen (void);
|
||||
extern void slip_connect (const char *dialnum);
|
||||
extern void slip_close (void);
|
||||
extern BOOL slip_is_up (void);
|
||||
extern U8 get_host_by_name (U8 *hostn, void (*cbfunc)(U8 event, U8 *host_ip));
|
||||
extern BOOL smtp_connect (U8 *ipadr, U16 port, void (*cbfunc)(U8 event));
|
||||
extern void dhcp_disable (void);
|
||||
extern BOOL igmp_join (U8 *group_ip);
|
||||
extern BOOL igmp_leave (U8 *group_ip);
|
||||
extern BOOL snmp_trap (U8 *manager_ip, U8 gen_trap, U8 spec_trap, U16 *obj_list);
|
||||
extern BOOL snmp_set_community (const char *community);
|
||||
extern BOOL icmp_ping (U8 *remip, void (*cbfunc)(U8 event));
|
||||
extern BOOL ftpc_connect (U8 *ipadr, U16 port, U8 command, void (*cbfunc)(U8 event));
|
||||
extern BOOL tftpc_put (U8 *ipadr, U16 port,
|
||||
const char *src, const char *dst, void (*cbfunc)(U8 event));
|
||||
extern BOOL tftpc_get (U8 *ipadr, U16 port,
|
||||
const char *src, const char *dst, void (*cbfunc)(U8 event));
|
||||
extern BOOL sntp_get_time (U8 *ipadr, void (*cbfunc)(U32 utc_time));
|
||||
extern void ftp_evt_notify (U8 evt);
|
||||
|
||||
/* BSD Socket API */
|
||||
extern int socket (int family, int type, int protocol);
|
||||
extern int bind (int sock, const SOCKADDR *addr, int addrlen);
|
||||
extern int listen (int sock, int backlog);
|
||||
extern int accept (int sock, SOCKADDR *addr, int *addrlen);
|
||||
extern int connect (int sock, SOCKADDR *addr, int addrlen);
|
||||
extern int send (int sock, const char *buf, int len, int flags);
|
||||
extern int sendto (int sock, const char *buf, int len, int flags, SOCKADDR *to, int tolen);
|
||||
extern int recv (int sock, char *buf, int len, int flags);
|
||||
extern int recvfrom (int sock, char *buf, int len, int flags, SOCKADDR *from, int *fromlen);
|
||||
extern int closesocket (int sock);
|
||||
extern int getpeername (int sock, SOCKADDR *name, int *namelen);
|
||||
extern int getsockname (int sock, SOCKADDR *name, int *namelen);
|
||||
extern int ioctlsocket (int sock, long cmd, unsigned long *argp);
|
||||
extern HOSTENT *gethostbyname (const char *name, int *err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __RL_USB_H__
|
||||
#define __RL_USB_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "usb.h"
|
||||
|
||||
/***************** Functions *************************************************/
|
||||
|
||||
/* USB Device functions exported from USB Device Core module */
|
||||
extern void usbd_init (void);
|
||||
extern void usbd_connect (BOOL con);
|
||||
extern void usbd_reset_core (void);
|
||||
extern BOOL usbd_configured (void);
|
||||
|
||||
/* USB Device user functions imported to USB HID Class module */
|
||||
extern void usbd_hid_init (void);
|
||||
extern BOOL usbd_hid_get_report_trigger(U8 rid, U8 *buf, int len);
|
||||
extern int usbd_hid_get_report (U8 rtype, U8 rid, U8 *buf, U8 req);
|
||||
extern void usbd_hid_set_report (U8 rtype, U8 rid, U8 *buf, int len, U8 req);
|
||||
extern U8 usbd_hid_get_protocol (void);
|
||||
extern void usbd_hid_set_protocol (U8 protocol);
|
||||
|
||||
/* USB Device user functions imported to USB Mass Storage Class module */
|
||||
extern void usbd_msc_init (void);
|
||||
extern void usbd_msc_read_sect (U32 block, U8 *buf, U32 num_of_blocks);
|
||||
extern void usbd_msc_write_sect (U32 block, U8 *buf, U32 num_of_blocks);
|
||||
extern void usbd_msc_start_stop (BOOL start);
|
||||
|
||||
/* USB Device user functions imported to USB Audio Class module */
|
||||
extern void usbd_adc_init (void);
|
||||
|
||||
/* USB Device CDC ACM class functions called automatically by USBD Core module*/
|
||||
extern int32_t USBD_CDC_ACM_Initialize (void);
|
||||
extern int32_t USBD_CDC_ACM_Uninitialize (void);
|
||||
extern int32_t USBD_CDC_ACM_Reset (void);
|
||||
/* USB Device CDC ACM class user functions */
|
||||
extern int32_t USBD_CDC_ACM_PortInitialize (void);
|
||||
extern int32_t USBD_CDC_ACM_PortUninitialize (void);
|
||||
extern int32_t USBD_CDC_ACM_PortReset (void);
|
||||
extern int32_t USBD_CDC_ACM_PortSetLineCoding (CDC_LINE_CODING *line_coding);
|
||||
extern int32_t USBD_CDC_ACM_PortGetLineCoding (CDC_LINE_CODING *line_coding);
|
||||
extern int32_t USBD_CDC_ACM_PortSetControlLineState (uint16_t ctrl_bmp);
|
||||
extern int32_t USBD_CDC_ACM_DataSend (const uint8_t *buf, int32_t len);
|
||||
extern int32_t USBD_CDC_ACM_DataFree (void);
|
||||
extern int32_t USBD_CDC_ACM_PutChar (const uint8_t ch);
|
||||
extern int32_t USBD_CDC_ACM_DataRead ( uint8_t *buf, int32_t len);
|
||||
extern int32_t USBD_CDC_ACM_GetChar (void);
|
||||
extern int32_t USBD_CDC_ACM_DataAvailable (void);
|
||||
extern int32_t USBD_CDC_ACM_Notify (uint16_t stat);
|
||||
/* USB Device CDC ACM class overridable functions */
|
||||
extern int32_t USBD_CDC_ACM_SendEncapsulatedCommand (void);
|
||||
extern int32_t USBD_CDC_ACM_GetEncapsulatedResponse (void);
|
||||
extern int32_t USBD_CDC_ACM_SetCommFeature (uint16_t feat);
|
||||
extern int32_t USBD_CDC_ACM_GetCommFeature (uint16_t feat);
|
||||
extern int32_t USBD_CDC_ACM_ClearCommFeature (uint16_t feat);
|
||||
extern int32_t USBD_CDC_ACM_SetLineCoding (void);
|
||||
extern int32_t USBD_CDC_ACM_GetLineCoding (void);
|
||||
extern int32_t USBD_CDC_ACM_SetControlLineState (uint16_t ctrl_bmp);
|
||||
extern int32_t USBD_CDC_ACM_SendBreak (uint16_t dur);
|
||||
|
||||
/* USB Device user functions imported to USB Custom Class module */
|
||||
extern void usbd_cls_init (void);
|
||||
extern void usbd_cls_sof (void);
|
||||
extern BOOL usbd_cls_dev_req (BOOL setup);
|
||||
extern BOOL usbd_cls_if_req (BOOL setup);
|
||||
extern BOOL usbd_cls_ep_req (BOOL setup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RL_USB_H__ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_H__
|
||||
#define __USB_H__
|
||||
|
||||
/* General USB header files */
|
||||
#include "usb_def.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "usb_hid.h"
|
||||
#include "usb_msc.h"
|
||||
|
||||
/* USB Device header files */
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_core_cdc.h"
|
||||
#include "usbd_core_hid.h"
|
||||
#include "usbd_core_msc.h"
|
||||
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_event.h"
|
||||
#include "usbd_cdc_acm.h"
|
||||
#include "usbd_hid.h"
|
||||
#include "usbd_msc.h"
|
||||
#include "usbd_hw.h"
|
||||
|
||||
#endif /* __USB_H__ */
|
||||
@@ -0,0 +1,247 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_CDC_H
|
||||
#define __USB_CDC_H
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Definitions based on usbcdc11.pdf (www.usb.org)
|
||||
*----------------------------------------------------------------------------*/
|
||||
/* Communication device class specification version 1.10 */
|
||||
#define CDC_V1_10 0x0110
|
||||
|
||||
/* Communication interface class code */
|
||||
/* (usbcdc11.pdf, 4.2, Table 15) */
|
||||
#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02
|
||||
|
||||
/* Communication interface class subclass codes */
|
||||
/* (usbcdc11.pdf, 4.3, Table 16) */
|
||||
#define CDC_DIRECT_LINE_CONTROL_MODEL 0x01
|
||||
#define CDC_ABSTRACT_CONTROL_MODEL 0x02
|
||||
#define CDC_TELEPHONE_CONTROL_MODEL 0x03
|
||||
#define CDC_MULTI_CHANNEL_CONTROL_MODEL 0x04
|
||||
#define CDC_CAPI_CONTROL_MODEL 0x05
|
||||
#define CDC_ETHERNET_NETWORKING_CONTROL_MODEL 0x06
|
||||
#define CDC_ATM_NETWORKING_CONTROL_MODEL 0x07
|
||||
|
||||
/* Communication interface class control protocol codes */
|
||||
/* (usbcdc11.pdf, 4.4, Table 17) */
|
||||
#define CDC_PROTOCOL_COMMON_AT_COMMANDS 0x01
|
||||
|
||||
/* Data interface class code */
|
||||
/* (usbcdc11.pdf, 4.5, Table 18) */
|
||||
#define CDC_DATA_INTERFACE_CLASS 0x0A
|
||||
|
||||
/* Data interface class protocol codes */
|
||||
/* (usbcdc11.pdf, 4.7, Table 19) */
|
||||
#define CDC_PROTOCOL_ISDN_BRI 0x30
|
||||
#define CDC_PROTOCOL_HDLC 0x31
|
||||
#define CDC_PROTOCOL_TRANSPARENT 0x32
|
||||
#define CDC_PROTOCOL_Q921_MANAGEMENT 0x50
|
||||
#define CDC_PROTOCOL_Q921_DATA_LINK 0x51
|
||||
#define CDC_PROTOCOL_Q921_MULTIPLEXOR 0x52
|
||||
#define CDC_PROTOCOL_V42 0x90
|
||||
#define CDC_PROTOCOL_EURO_ISDN 0x91
|
||||
#define CDC_PROTOCOL_V24_RATE_ADAPTATION 0x92
|
||||
#define CDC_PROTOCOL_CAPI 0x93
|
||||
#define CDC_PROTOCOL_HOST_BASED_DRIVER 0xFD
|
||||
#define CDC_PROTOCOL_DESCRIBED_IN_PUFD 0xFE
|
||||
|
||||
/* Type values for bDescriptorType field of functional descriptors */
|
||||
/* (usbcdc11.pdf, 5.2.3, Table 24) */
|
||||
#define CDC_CS_INTERFACE 0x24
|
||||
#define CDC_CS_ENDPOINT 0x25
|
||||
|
||||
/* Type values for bDescriptorSubtype field of functional descriptors */
|
||||
/* (usbcdc11.pdf, 5.2.3, Table 25) */
|
||||
#define CDC_HEADER 0x00
|
||||
#define CDC_CALL_MANAGEMENT 0x01
|
||||
#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02
|
||||
#define CDC_DIRECT_LINE_MANAGEMENT 0x03
|
||||
#define CDC_TELEPHONE_RINGER 0x04
|
||||
#define CDC_REPORTING_CAPABILITIES 0x05
|
||||
#define CDC_UNION 0x06
|
||||
#define CDC_COUNTRY_SELECTION 0x07
|
||||
#define CDC_TELEPHONE_OPERATIONAL_MODES 0x08
|
||||
#define CDC_USB_TERMINAL 0x09
|
||||
#define CDC_NETWORK_CHANNEL 0x0A
|
||||
#define CDC_PROTOCOL_UNIT 0x0B
|
||||
#define CDC_EXTENSION_UNIT 0x0C
|
||||
#define CDC_MULTI_CHANNEL_MANAGEMENT 0x0D
|
||||
#define CDC_CAPI_CONTROL_MANAGEMENT 0x0E
|
||||
#define CDC_ETHERNET_NETWORKING 0x0F
|
||||
#define CDC_ATM_NETWORKING 0x10
|
||||
|
||||
/* CDC class-specific request codes */
|
||||
/* (usbcdc11.pdf, 6.2, Table 46) */
|
||||
/* see Table 45 for info about the specific requests. */
|
||||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define CDC_SET_COMM_FEATURE 0x02
|
||||
#define CDC_GET_COMM_FEATURE 0x03
|
||||
#define CDC_CLEAR_COMM_FEATURE 0x04
|
||||
#define CDC_SET_AUX_LINE_STATE 0x10
|
||||
#define CDC_SET_HOOK_STATE 0x11
|
||||
#define CDC_PULSE_SETUP 0x12
|
||||
#define CDC_SEND_PULSE 0x13
|
||||
#define CDC_SET_PULSE_TIME 0x14
|
||||
#define CDC_RING_AUX_JACK 0x15
|
||||
#define CDC_SET_LINE_CODING 0x20
|
||||
#define CDC_GET_LINE_CODING 0x21
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
#define CDC_SEND_BREAK 0x23
|
||||
#define CDC_SET_RINGER_PARMS 0x30
|
||||
#define CDC_GET_RINGER_PARMS 0x31
|
||||
#define CDC_SET_OPERATION_PARMS 0x32
|
||||
#define CDC_GET_OPERATION_PARMS 0x33
|
||||
#define CDC_SET_LINE_PARMS 0x34
|
||||
#define CDC_GET_LINE_PARMS 0x35
|
||||
#define CDC_DIAL_DIGITS 0x36
|
||||
#define CDC_SET_UNIT_PARAMETER 0x37
|
||||
#define CDC_GET_UNIT_PARAMETER 0x38
|
||||
#define CDC_CLEAR_UNIT_PARAMETER 0x39
|
||||
#define CDC_GET_PROFILE 0x3A
|
||||
#define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
|
||||
#define CDC_SET_ETHERNET_PMP_FILTER 0x41
|
||||
#define CDC_GET_ETHERNET_PMP_FILTER 0x42
|
||||
#define CDC_SET_ETHERNET_PACKET_FILTER 0x43
|
||||
#define CDC_GET_ETHERNET_STATISTIC 0x44
|
||||
#define CDC_SET_ATM_DATA_FORMAT 0x50
|
||||
#define CDC_GET_ATM_DEVICE_STATISTICS 0x51
|
||||
#define CDC_SET_ATM_DEFAULT_VC 0x52
|
||||
#define CDC_GET_ATM_VC_STATISTICS 0x53
|
||||
|
||||
/* Communication feature selector codes */
|
||||
/* (usbcdc11.pdf, 6.2.2..6.2.4, Table 47) */
|
||||
#define CDC_ABSTRACT_STATE 0x01
|
||||
#define CDC_COUNTRY_SETTING 0x02
|
||||
|
||||
/* Feature Status returned for ABSTRACT_STATE Selector */
|
||||
/* (usbcdc11.pdf, 6.2.3, Table 48) */
|
||||
#define CDC_IDLE_SETTING (1 << 0)
|
||||
#define CDC_DATA_MULTPLEXED_STATE (1 << 1)
|
||||
|
||||
|
||||
/* Control signal bitmap values for the SetControlLineState request */
|
||||
/* (usbcdc11.pdf, 6.2.14, Table 51) */
|
||||
#define CDC_DTE_PRESENT (1 << 0)
|
||||
#define CDC_ACTIVATE_CARRIER (1 << 1)
|
||||
|
||||
/* CDC class-specific notification codes */
|
||||
/* (usbcdc11.pdf, 6.3, Table 68) */
|
||||
/* see Table 67 for Info about class-specific notifications */
|
||||
#define CDC_NOTIFICATION_NETWORK_CONNECTION 0x00
|
||||
#define CDC_RESPONSE_AVAILABLE 0x01
|
||||
#define CDC_AUX_JACK_HOOK_STATE 0x08
|
||||
#define CDC_RING_DETECT 0x09
|
||||
#define CDC_NOTIFICATION_SERIAL_STATE 0x20
|
||||
#define CDC_CALL_STATE_CHANGE 0x28
|
||||
#define CDC_LINE_STATE_CHANGE 0x29
|
||||
#define CDC_CONNECTION_SPEED_CHANGE 0x2A
|
||||
|
||||
/* UART state bitmap values (Serial state notification). */
|
||||
/* (usbcdc11.pdf, 6.3.5, Table 69) */
|
||||
#define CDC_SERIAL_STATE_OVERRUN (1 << 6) /* receive data overrun error has occurred */
|
||||
#define CDC_SERIAL_STATE_OVERRUN_Pos ( 6)
|
||||
#define CDC_SERIAL_STATE_OVERRUN_Msk (1 << CDC_SERIAL_STATE_OVERRUN_Pos)
|
||||
#define CDC_SERIAL_STATE_PARITY (1 << 5) /* parity error has occurred */
|
||||
#define CDC_SERIAL_STATE_PARITY_Pos ( 5)
|
||||
#define CDC_SERIAL_STATE_PARITY_Msk (1 << CDC_SERIAL_STATE_PARITY_Pos)
|
||||
#define CDC_SERIAL_STATE_FRAMING (1 << 4) /* framing error has occurred */
|
||||
#define CDC_SERIAL_STATE_FRAMING_Pos ( 4)
|
||||
#define CDC_SERIAL_STATE_FRAMING_Msk (1 << CDC_SERIAL_STATE_FRAMING_Pos)
|
||||
#define CDC_SERIAL_STATE_RING (1 << 3) /* state of ring signal detection */
|
||||
#define CDC_SERIAL_STATE_RING_Pos ( 3)
|
||||
#define CDC_SERIAL_STATE_RING_Msk (1 << CDC_SERIAL_STATE_RING_Pos)
|
||||
#define CDC_SERIAL_STATE_BREAK (1 << 2) /* state of break detection */
|
||||
#define CDC_SERIAL_STATE_BREAK_Pos ( 2)
|
||||
#define CDC_SERIAL_STATE_BREAK_Msk (1 << CDC_SERIAL_STATE_BREAK_Pos)
|
||||
#define CDC_SERIAL_STATE_TX_CARRIER (1 << 1) /* state of transmission carrier */
|
||||
#define CDC_SERIAL_STATE_TX_CARRIER_Pos ( 1)
|
||||
#define CDC_SERIAL_STATE_TX_CARRIER_Msk (1 << CDC_SERIAL_STATE_TX_CARRIER_Pos)
|
||||
#define CDC_SERIAL_STATE_RX_CARRIER (1 << 0) /* state of receiver carrier */
|
||||
#define CDC_SERIAL_STATE_RX_CARRIER_Pos ( 0)
|
||||
#define CDC_SERIAL_STATE_RX_CARRIER_Msk (1 << CDC_SERIAL_STATE_RX_CARRIER_Pos)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Structures based on usbcdc11.pdf (www.usb.org)
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/* Header functional descriptor */
|
||||
/* (usbcdc11.pdf, 5.2.3.1) */
|
||||
/* This header must precede any list of class-specific descriptors. */
|
||||
typedef __packed struct _CDC_HEADER_DESCRIPTOR{
|
||||
U8 bFunctionLength; /* size of this descriptor in bytes */
|
||||
U8 bDescriptorType; /* CS_INTERFACE descriptor type */
|
||||
U8 bDescriptorSubtype; /* Header functional descriptor subtype */
|
||||
U16 bcdCDC; /* USB CDC specification release version */
|
||||
} CDC_HEADER_DESCRIPTOR;
|
||||
|
||||
/* Call management functional descriptor */
|
||||
/* (usbcdc11.pdf, 5.2.3.2) */
|
||||
/* Describes the processing of calls for the communication class interface. */
|
||||
typedef __packed struct _CDC_CALL_MANAGEMENT_DESCRIPTOR {
|
||||
U8 bFunctionLength; /* size of this descriptor in bytes */
|
||||
U8 bDescriptorType; /* CS_INTERFACE descriptor type */
|
||||
U8 bDescriptorSubtype; /* call management functional descriptor subtype */
|
||||
U8 bmCapabilities; /* capabilities that this configuration supports */
|
||||
U8 bDataInterface; /* interface number of the data class interface used for call management (optional) */
|
||||
} CDC_CALL_MANAGEMENT_DESCRIPTOR;
|
||||
|
||||
/* Abstract control management functional descriptor */
|
||||
/* (usbcdc11.pdf, 5.2.3.3) */
|
||||
/* Describes the command supported by the communication interface class with the Abstract Control Model subclass code. */
|
||||
typedef __packed struct _CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR {
|
||||
U8 bFunctionLength; /* size of this descriptor in bytes */
|
||||
U8 bDescriptorType; /* CS_INTERFACE descriptor type */
|
||||
U8 bDescriptorSubtype; /* abstract control management functional descriptor subtype */
|
||||
U8 bmCapabilities; /* capabilities supported by this configuration */
|
||||
} CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR;
|
||||
|
||||
/* Union functional descriptors */
|
||||
/* (usbcdc11.pdf, 5.2.3.8) */
|
||||
/* Describes the relationship between a group of interfaces that can be considered to form a functional unit. */
|
||||
typedef __packed struct _CDC_UNION_DESCRIPTOR {
|
||||
U8 bFunctionLength; /* size of this descriptor in bytes */
|
||||
U8 bDescriptorType; /* CS_INTERFACE descriptor type */
|
||||
U8 bDescriptorSubtype; /* union functional descriptor subtype */
|
||||
U8 bMasterInterface; /* interface number designated as master */
|
||||
} CDC_UNION_DESCRIPTOR;
|
||||
|
||||
/* Union functional descriptors with one slave interface */
|
||||
/* (usbcdc11.pdf, 5.2.3.8) */
|
||||
typedef __packed struct _CDC_UNION_1SLAVE_DESCRIPTOR {
|
||||
CDC_UNION_DESCRIPTOR sUnion; /* Union functional descriptor */
|
||||
U8 bSlaveInterfaces[1]; /* Slave interface 0 */
|
||||
} CDC_UNION_1SLAVE_DESCRIPTOR;
|
||||
|
||||
/* Line coding structure */
|
||||
/* Format of the data returned when a GetLineCoding request is received */
|
||||
/* (usbcdc11.pdf, 6.2.13) */
|
||||
typedef __packed struct _CDC_LINE_CODING {
|
||||
U32 dwDTERate; /* Data terminal rate in bits per second */
|
||||
U8 bCharFormat; /* Number of stop bits */
|
||||
U8 bParityType; /* Parity bit type */
|
||||
U8 bDataBits; /* Number of data bits */
|
||||
} CDC_LINE_CODING;
|
||||
|
||||
/* Notification header */
|
||||
/* Data sent on the notification endpoint must follow this header. */
|
||||
/* see USB_SETUP_PACKET in file usb.h */
|
||||
typedef USB_SETUP_PACKET CDC_NOTIFICATION_HEADER;
|
||||
|
||||
#endif /* __USB_CDC_H */
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_DEF_H__
|
||||
#define __USB_DEF_H__
|
||||
|
||||
#pragma anon_unions
|
||||
|
||||
|
||||
/* bmRequestType.Dir */
|
||||
#define REQUEST_HOST_TO_DEVICE 0
|
||||
#define REQUEST_DEVICE_TO_HOST 1
|
||||
|
||||
/* bmRequestType.Type */
|
||||
#define REQUEST_STANDARD 0
|
||||
#define REQUEST_CLASS 1
|
||||
#define REQUEST_VENDOR 2
|
||||
#define REQUEST_RESERVED 3
|
||||
|
||||
/* bmRequestType.Recipient */
|
||||
#define REQUEST_TO_DEVICE 0
|
||||
#define REQUEST_TO_INTERFACE 1
|
||||
#define REQUEST_TO_ENDPOINT 2
|
||||
#define REQUEST_TO_OTHER 3
|
||||
|
||||
/* bmRequestType Definition */
|
||||
typedef __packed struct _REQUEST_TYPE {
|
||||
U8 Recipient : 5; /* D4..0: Recipient */
|
||||
U8 Type : 2; /* D6..5: Type */
|
||||
U8 Dir : 1; /* D7: Data Phase Txsfer Direction */
|
||||
} REQUEST_TYPE;
|
||||
|
||||
/* USB Standard Request Codes */
|
||||
#define USB_REQUEST_GET_STATUS 0
|
||||
#define USB_REQUEST_CLEAR_FEATURE 1
|
||||
#define USB_REQUEST_SET_FEATURE 3
|
||||
#define USB_REQUEST_SET_ADDRESS 5
|
||||
#define USB_REQUEST_GET_DESCRIPTOR 6
|
||||
#define USB_REQUEST_SET_DESCRIPTOR 7
|
||||
#define USB_REQUEST_GET_CONFIGURATION 8
|
||||
#define USB_REQUEST_SET_CONFIGURATION 9
|
||||
#define USB_REQUEST_GET_INTERFACE 10
|
||||
#define USB_REQUEST_SET_INTERFACE 11
|
||||
#define USB_REQUEST_SYNC_FRAME 12
|
||||
|
||||
/* USB GET_STATUS Bit Values */
|
||||
#define USB_GETSTATUS_SELF_POWERED 0x01
|
||||
#define USB_GETSTATUS_REMOTE_WAKEUP 0x02
|
||||
#define USB_GETSTATUS_ENDPOINT_STALL 0x01
|
||||
|
||||
/* USB Standard Feature selectors */
|
||||
#define USB_FEATURE_ENDPOINT_STALL 0
|
||||
#define USB_FEATURE_REMOTE_WAKEUP 1
|
||||
|
||||
/* USB Default Control Pipe Setup Packet */
|
||||
typedef __packed struct _USB_SETUP_PACKET {
|
||||
REQUEST_TYPE bmRequestType; /* bmRequestType */
|
||||
U8 bRequest; /* bRequest */
|
||||
__packed union {
|
||||
U16 wValue; /* wValue */
|
||||
__packed struct {
|
||||
U8 wValueL;
|
||||
U8 wValueH;
|
||||
};
|
||||
};
|
||||
__packed union {
|
||||
U16 wIndex; /* wIndex */
|
||||
__packed struct {
|
||||
U8 wIndexL;
|
||||
U8 wIndexH;
|
||||
};
|
||||
};
|
||||
U16 wLength; /* wLength */
|
||||
} USB_SETUP_PACKET;
|
||||
|
||||
|
||||
/* USB Descriptor Types */
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 1
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 3
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 4
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5
|
||||
#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
|
||||
#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
|
||||
#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
|
||||
#define USB_OTG_DESCRIPTOR_TYPE 9
|
||||
#define USB_DEBUG_DESCRIPTOR_TYPE 10
|
||||
#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
|
||||
|
||||
/* USB Device Classes */
|
||||
#define USB_DEVICE_CLASS_RESERVED 0x00
|
||||
#define USB_DEVICE_CLASS_AUDIO 0x01
|
||||
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
|
||||
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
|
||||
#define USB_DEVICE_CLASS_MONITOR 0x04
|
||||
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
|
||||
#define USB_DEVICE_CLASS_POWER 0x06
|
||||
#define USB_DEVICE_CLASS_PRINTER 0x07
|
||||
#define USB_DEVICE_CLASS_STORAGE 0x08
|
||||
#define USB_DEVICE_CLASS_HUB 0x09
|
||||
#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
|
||||
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
|
||||
|
||||
/* bmAttributes in Configuration Descriptor */
|
||||
#define USB_CONFIG_POWERED_MASK 0x40
|
||||
#define USB_CONFIG_BUS_POWERED 0x80
|
||||
#define USB_CONFIG_SELF_POWERED 0xC0
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 0x20
|
||||
|
||||
/* bMaxPower in Configuration Descriptor */
|
||||
#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
|
||||
|
||||
/* bEndpointAddress in Endpoint Descriptor */
|
||||
#define USB_ENDPOINT_DIRECTION_MASK 0x80
|
||||
#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
|
||||
#define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
|
||||
|
||||
/* bmAttributes in Endpoint Descriptor */
|
||||
#define USB_ENDPOINT_TYPE_MASK 0x03
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0x00
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
|
||||
#define USB_ENDPOINT_TYPE_BULK 0x02
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
|
||||
#define USB_ENDPOINT_SYNC_MASK 0x0C
|
||||
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
|
||||
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
|
||||
#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
|
||||
#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
|
||||
#define USB_ENDPOINT_USAGE_MASK 0x30
|
||||
#define USB_ENDPOINT_USAGE_DATA 0x00
|
||||
#define USB_ENDPOINT_USAGE_FEEDBACK 0x10
|
||||
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
|
||||
#define USB_ENDPOINT_USAGE_RESERVED 0x30
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
typedef __packed struct _USB_DEVICE_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U16 bcdUSB;
|
||||
U8 bDeviceClass;
|
||||
U8 bDeviceSubClass;
|
||||
U8 bDeviceProtocol;
|
||||
U8 bMaxPacketSize0;
|
||||
U16 idVendor;
|
||||
U16 idProduct;
|
||||
U16 bcdDevice;
|
||||
U8 iManufacturer;
|
||||
U8 iProduct;
|
||||
U8 iSerialNumber;
|
||||
U8 bNumConfigurations;
|
||||
} USB_DEVICE_DESCRIPTOR;
|
||||
|
||||
/* USB 2.0 Device Qualifier Descriptor */
|
||||
typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U16 bcdUSB;
|
||||
U8 bDeviceClass;
|
||||
U8 bDeviceSubClass;
|
||||
U8 bDeviceProtocol;
|
||||
U8 bMaxPacketSize0;
|
||||
U8 bNumConfigurations;
|
||||
U8 bReserved;
|
||||
} USB_DEVICE_QUALIFIER_DESCRIPTOR;
|
||||
|
||||
/* USB Standard Configuration Descriptor */
|
||||
typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U16 wTotalLength;
|
||||
U8 bNumInterfaces;
|
||||
U8 bConfigurationValue;
|
||||
U8 iConfiguration;
|
||||
U8 bmAttributes;
|
||||
U8 bMaxPower;
|
||||
} USB_CONFIGURATION_DESCRIPTOR;
|
||||
|
||||
/* USB Standard Interface Descriptor */
|
||||
typedef __packed struct _USB_INTERFACE_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U8 bInterfaceNumber;
|
||||
U8 bAlternateSetting;
|
||||
U8 bNumEndpoints;
|
||||
U8 bInterfaceClass;
|
||||
U8 bInterfaceSubClass;
|
||||
U8 bInterfaceProtocol;
|
||||
U8 iInterface;
|
||||
} USB_INTERFACE_DESCRIPTOR;
|
||||
|
||||
/* USB Standard Endpoint Descriptor */
|
||||
typedef __packed struct _USB_ENDPOINT_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U8 bEndpointAddress;
|
||||
U8 bmAttributes;
|
||||
U16 wMaxPacketSize;
|
||||
U8 bInterval;
|
||||
} USB_ENDPOINT_DESCRIPTOR;
|
||||
|
||||
/* USB String Descriptor */
|
||||
typedef __packed struct _USB_STRING_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U16 bString/*[]*/;
|
||||
} USB_STRING_DESCRIPTOR;
|
||||
|
||||
/* USB Common Descriptor */
|
||||
typedef __packed struct _USB_COMMON_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
} USB_COMMON_DESCRIPTOR;
|
||||
|
||||
/* USB Interface Association Descriptor */
|
||||
typedef __packed struct _USB_INTERFACE_ASSOCIATION_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U8 bFirstInterface;
|
||||
U8 bInterfaceCount;
|
||||
U8 bFunctionClass;
|
||||
U8 bFunctionSubclass;
|
||||
U8 bFunctionProtocol;
|
||||
U8 iFunction;
|
||||
} USB_INTERFACE_ASSOCIATION_DESCRIPTOR;
|
||||
|
||||
|
||||
#endif /* __USB_DEF_H__ */
|
||||
@@ -0,0 +1,27 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_FOR_LIB_H__
|
||||
#define __USB_FOR_LIB_H__
|
||||
|
||||
/* USB Device header files */
|
||||
#include "usbd_lib_cdc.h"
|
||||
#include "usbd_lib_hid.h"
|
||||
#include "usbd_lib_msc.h"
|
||||
|
||||
/* USB System Configuration header file */
|
||||
#include "usb_lib.h"
|
||||
|
||||
#endif /* __USB_FOR_LIB_H__ */
|
||||
@@ -0,0 +1,374 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_HID_H__
|
||||
#define __USB_HID_H__
|
||||
|
||||
|
||||
/* HID Subclass Codes */
|
||||
#define HID_SUBCLASS_NONE 0x00
|
||||
#define HID_SUBCLASS_BOOT 0x01
|
||||
|
||||
/* HID Protocol Codes */
|
||||
#define HID_PROTOCOL_NONE 0x00
|
||||
#define HID_PROTOCOL_BOOT 0x00
|
||||
#define HID_PROTOCOL_KEYBOARD 0x01
|
||||
#define HID_PROTOCOL_REPORT 0x01
|
||||
#define HID_PROTOCOL_MOUSE 0x02
|
||||
|
||||
|
||||
/* HID Descriptor Types */
|
||||
#define HID_HID_DESCRIPTOR_TYPE 0x21
|
||||
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
|
||||
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
|
||||
|
||||
|
||||
/* HID Descriptor */
|
||||
typedef __packed struct _HID_DESCRIPTOR {
|
||||
U8 bLength;
|
||||
U8 bDescriptorType;
|
||||
U16 bcdHID;
|
||||
U8 bCountryCode;
|
||||
U8 bNumDescriptors;
|
||||
/* Array of one or more descriptors */
|
||||
__packed struct _HID_DESCRIPTOR_LIST {
|
||||
U8 bDescriptorType;
|
||||
U16 wDescriptorLength;
|
||||
} DescriptorList[1];
|
||||
} HID_DESCRIPTOR;
|
||||
|
||||
|
||||
/* HID Request Codes */
|
||||
#define HID_REQUEST_GET_REPORT 0x01
|
||||
#define HID_REQUEST_GET_IDLE 0x02
|
||||
#define HID_REQUEST_GET_PROTOCOL 0x03
|
||||
#define HID_REQUEST_SET_REPORT 0x09
|
||||
#define HID_REQUEST_SET_IDLE 0x0A
|
||||
#define HID_REQUEST_SET_PROTOCOL 0x0B
|
||||
|
||||
/* HID Report Types */
|
||||
#define HID_REPORT_INPUT 0x01
|
||||
#define HID_REPORT_OUTPUT 0x02
|
||||
#define HID_REPORT_FEATURE 0x03
|
||||
|
||||
|
||||
/* Usage Pages */
|
||||
#define HID_USAGE_PAGE_UNDEFINED 0x00
|
||||
#define HID_USAGE_PAGE_GENERIC 0x01
|
||||
#define HID_USAGE_PAGE_SIMULATION 0x02
|
||||
#define HID_USAGE_PAGE_VR 0x03
|
||||
#define HID_USAGE_PAGE_SPORT 0x04
|
||||
#define HID_USAGE_PAGE_GAME 0x05
|
||||
#define HID_USAGE_PAGE_DEV_CONTROLS 0x06
|
||||
#define HID_USAGE_PAGE_KEYBOARD 0x07
|
||||
#define HID_USAGE_PAGE_LED 0x08
|
||||
#define HID_USAGE_PAGE_BUTTON 0x09
|
||||
#define HID_USAGE_PAGE_ORDINAL 0x0A
|
||||
#define HID_USAGE_PAGE_TELEPHONY 0x0B
|
||||
#define HID_USAGE_PAGE_CONSUMER 0x0C
|
||||
#define HID_USAGE_PAGE_DIGITIZER 0x0D
|
||||
#define HID_USAGE_PAGE_UNICODE 0x10
|
||||
#define HID_USAGE_PAGE_ALPHANUMERIC 0x14
|
||||
/* ... */
|
||||
|
||||
|
||||
/* Generic Desktop Page (0x01) */
|
||||
#define HID_USAGE_GENERIC_POINTER 0x01
|
||||
#define HID_USAGE_GENERIC_MOUSE 0x02
|
||||
#define HID_USAGE_GENERIC_JOYSTICK 0x04
|
||||
#define HID_USAGE_GENERIC_GAMEPAD 0x05
|
||||
#define HID_USAGE_GENERIC_KEYBOARD 0x06
|
||||
#define HID_USAGE_GENERIC_KEYPAD 0x07
|
||||
#define HID_USAGE_GENERIC_X 0x30
|
||||
#define HID_USAGE_GENERIC_Y 0x31
|
||||
#define HID_USAGE_GENERIC_Z 0x32
|
||||
#define HID_USAGE_GENERIC_RX 0x33
|
||||
#define HID_USAGE_GENERIC_RY 0x34
|
||||
#define HID_USAGE_GENERIC_RZ 0x35
|
||||
#define HID_USAGE_GENERIC_SLIDER 0x36
|
||||
#define HID_USAGE_GENERIC_DIAL 0x37
|
||||
#define HID_USAGE_GENERIC_WHEEL 0x38
|
||||
#define HID_USAGE_GENERIC_HATSWITCH 0x39
|
||||
#define HID_USAGE_GENERIC_COUNTED_BUFFER 0x3A
|
||||
#define HID_USAGE_GENERIC_BYTE_COUNT 0x3B
|
||||
#define HID_USAGE_GENERIC_MOTION_WAKEUP 0x3C
|
||||
#define HID_USAGE_GENERIC_VX 0x40
|
||||
#define HID_USAGE_GENERIC_VY 0x41
|
||||
#define HID_USAGE_GENERIC_VZ 0x42
|
||||
#define HID_USAGE_GENERIC_VBRX 0x43
|
||||
#define HID_USAGE_GENERIC_VBRY 0x44
|
||||
#define HID_USAGE_GENERIC_VBRZ 0x45
|
||||
#define HID_USAGE_GENERIC_VNO 0x46
|
||||
#define HID_USAGE_GENERIC_SYSTEM_CTL 0x80
|
||||
#define HID_USAGE_GENERIC_SYSCTL_POWER 0x81
|
||||
#define HID_USAGE_GENERIC_SYSCTL_SLEEP 0x82
|
||||
#define HID_USAGE_GENERIC_SYSCTL_WAKE 0x83
|
||||
#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU 0x84
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU 0x85
|
||||
#define HID_USAGE_GENERIC_SYSCTL_APP_MENU 0x86
|
||||
#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU 0x87
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT 0x88
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT 0x89
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT 0x8A
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT 0x8B
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_UP 0x8C
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN 0x8D
|
||||
/* ... */
|
||||
|
||||
/* Simulation Controls Page (0x02) */
|
||||
/* ... */
|
||||
#define HID_USAGE_SIMULATION_RUDDER 0xBA
|
||||
#define HID_USAGE_SIMULATION_THROTTLE 0xBB
|
||||
/* ... */
|
||||
|
||||
/* Virtual Reality Controls Page (0x03) */
|
||||
/* ... */
|
||||
|
||||
/* Sport Controls Page (0x04) */
|
||||
/* ... */
|
||||
|
||||
/* Game Controls Page (0x05) */
|
||||
/* ... */
|
||||
|
||||
/* Generic Device Controls Page (0x06) */
|
||||
/* ... */
|
||||
|
||||
/* Keyboard/Keypad Page (0x07) */
|
||||
|
||||
/* Keyboard Usage Keys */
|
||||
extern const unsigned char HID_KEYBOARD_ID_TO_ASCII[256];
|
||||
extern const unsigned char HID_KEYBOARD_ALT_ID_TO_ASCII[57];
|
||||
|
||||
/* Error "Keys" */
|
||||
#define HID_USAGE_KEYBOARD_NOEVENT 0x00
|
||||
#define HID_USAGE_KEYBOARD_ROLLOVER 0x01
|
||||
#define HID_USAGE_KEYBOARD_POSTFAIL 0x02
|
||||
#define HID_USAGE_KEYBOARD_UNDEFINED 0x03
|
||||
|
||||
/* Letters */
|
||||
#define HID_USAGE_KEYBOARD_aA 0x04
|
||||
#define HID_USAGE_KEYBOARD_zZ 0x1D
|
||||
|
||||
/* Numbers */
|
||||
#define HID_USAGE_KEYBOARD_ONE 0x1E
|
||||
#define HID_USAGE_KEYBOARD_ZERO 0x27
|
||||
|
||||
#define HID_USAGE_KEYBOARD_RETURN 0x28
|
||||
#define HID_USAGE_KEYBOARD_ESCAPE 0x29
|
||||
#define HID_USAGE_KEYBOARD_DELETE 0x2A
|
||||
|
||||
/* Funtion Keys */
|
||||
#define HID_USAGE_KEYBOARD_F1 0x3A
|
||||
#define HID_USAGE_KEYBOARD_F12 0x45
|
||||
|
||||
#define HID_USAGE_KEYBOARD_PRINT_SCREEN 0x46
|
||||
|
||||
/* Modifier Keys */
|
||||
#define HID_USAGE_KEYBOARD_LCTRL 0xE0
|
||||
#define HID_USAGE_KEYBOARD_LSHFT 0xE1
|
||||
#define HID_USAGE_KEYBOARD_LALT 0xE2
|
||||
#define HID_USAGE_KEYBOARD_LGUI 0xE3
|
||||
#define HID_USAGE_KEYBOARD_RCTRL 0xE4
|
||||
#define HID_USAGE_KEYBOARD_RSHFT 0xE5
|
||||
#define HID_USAGE_KEYBOARD_RALT 0xE6
|
||||
#define HID_USAGE_KEYBOARD_RGUI 0xE7
|
||||
#define HID_USAGE_KEYBOARD_SCROLL_LOCK 0x47
|
||||
#define HID_USAGE_KEYBOARD_NUM_LOCK 0x53
|
||||
#define HID_USAGE_KEYBOARD_CAPS_LOCK 0x39
|
||||
|
||||
/* Modifier Keys (values) */
|
||||
#define HID_USAGE_KEYBOARD_MOD_LCTRL 0x01
|
||||
#define HID_USAGE_KEYBOARD_MOD_LSHIFT 0x02
|
||||
#define HID_USAGE_KEYBOARD_MOD_LALTL 0x04
|
||||
#define HID_USAGE_KEYBOARD_MOD_LGUI 0x08
|
||||
#define HID_USAGE_KEYBOARD_MOD_RCTRL 0x10
|
||||
#define HID_USAGE_KEYBOARD_MOD_RSHIFT 0x20
|
||||
#define HID_USAGE_KEYBOARD_MOD_RALTL 0x40
|
||||
#define HID_USAGE_KEYBOARD_MOD_RGUI 0x80
|
||||
|
||||
/* ... */
|
||||
|
||||
/* LED Page (0x08) */
|
||||
#define HID_USAGE_LED_NUM_LOCK 0x01
|
||||
#define HID_USAGE_LED_CAPS_LOCK 0x02
|
||||
#define HID_USAGE_LED_SCROLL_LOCK 0x03
|
||||
#define HID_USAGE_LED_COMPOSE 0x04
|
||||
#define HID_USAGE_LED_KANA 0x05
|
||||
#define HID_USAGE_LED_POWER 0x06
|
||||
#define HID_USAGE_LED_SHIFT 0x07
|
||||
#define HID_USAGE_LED_DO_NOT_DISTURB 0x08
|
||||
#define HID_USAGE_LED_MUTE 0x09
|
||||
#define HID_USAGE_LED_TONE_ENABLE 0x0A
|
||||
#define HID_USAGE_LED_HIGH_CUT_FILTER 0x0B
|
||||
#define HID_USAGE_LED_LOW_CUT_FILTER 0x0C
|
||||
#define HID_USAGE_LED_EQUALIZER_ENABLE 0x0D
|
||||
#define HID_USAGE_LED_SOUND_FIELD_ON 0x0E
|
||||
#define HID_USAGE_LED_SURROUND_FIELD_ON 0x0F
|
||||
#define HID_USAGE_LED_REPEAT 0x10
|
||||
#define HID_USAGE_LED_STEREO 0x11
|
||||
#define HID_USAGE_LED_SAMPLING_RATE_DETECT 0x12
|
||||
#define HID_USAGE_LED_SPINNING 0x13
|
||||
#define HID_USAGE_LED_CAV 0x14
|
||||
#define HID_USAGE_LED_CLV 0x15
|
||||
#define HID_USAGE_LED_RECORDING_FORMAT_DET 0x16
|
||||
#define HID_USAGE_LED_OFF_HOOK 0x17
|
||||
#define HID_USAGE_LED_RING 0x18
|
||||
#define HID_USAGE_LED_MESSAGE_WAITING 0x19
|
||||
#define HID_USAGE_LED_DATA_MODE 0x1A
|
||||
#define HID_USAGE_LED_BATTERY_OPERATION 0x1B
|
||||
#define HID_USAGE_LED_BATTERY_OK 0x1C
|
||||
#define HID_USAGE_LED_BATTERY_LOW 0x1D
|
||||
#define HID_USAGE_LED_SPEAKER 0x1E
|
||||
#define HID_USAGE_LED_HEAD_SET 0x1F
|
||||
#define HID_USAGE_LED_HOLD 0x20
|
||||
#define HID_USAGE_LED_MICROPHONE 0x21
|
||||
#define HID_USAGE_LED_COVERAGE 0x22
|
||||
#define HID_USAGE_LED_NIGHT_MODE 0x23
|
||||
#define HID_USAGE_LED_SEND_CALLS 0x24
|
||||
#define HID_USAGE_LED_CALL_PICKUP 0x25
|
||||
#define HID_USAGE_LED_CONFERENCE 0x26
|
||||
#define HID_USAGE_LED_STAND_BY 0x27
|
||||
#define HID_USAGE_LED_CAMERA_ON 0x28
|
||||
#define HID_USAGE_LED_CAMERA_OFF 0x29
|
||||
#define HID_USAGE_LED_ON_LINE 0x2A
|
||||
#define HID_USAGE_LED_OFF_LINE 0x2B
|
||||
#define HID_USAGE_LED_BUSY 0x2C
|
||||
#define HID_USAGE_LED_READY 0x2D
|
||||
#define HID_USAGE_LED_PAPER_OUT 0x2E
|
||||
#define HID_USAGE_LED_PAPER_JAM 0x2F
|
||||
#define HID_USAGE_LED_REMOTE 0x30
|
||||
#define HID_USAGE_LED_FORWARD 0x31
|
||||
#define HID_USAGE_LED_REVERSE 0x32
|
||||
#define HID_USAGE_LED_STOP 0x33
|
||||
#define HID_USAGE_LED_REWIND 0x34
|
||||
#define HID_USAGE_LED_FAST_FORWARD 0x35
|
||||
#define HID_USAGE_LED_PLAY 0x36
|
||||
#define HID_USAGE_LED_PAUSE 0x37
|
||||
#define HID_USAGE_LED_RECORD 0x38
|
||||
#define HID_USAGE_LED_ERROR 0x39
|
||||
#define HID_USAGE_LED_SELECTED_INDICATOR 0x3A
|
||||
#define HID_USAGE_LED_IN_USE_INDICATOR 0x3B
|
||||
#define HID_USAGE_LED_MULTI_MODE_INDICATOR 0x3C
|
||||
#define HID_USAGE_LED_INDICATOR_ON 0x3D
|
||||
#define HID_USAGE_LED_INDICATOR_FLASH 0x3E
|
||||
#define HID_USAGE_LED_INDICATOR_SLOW_BLINK 0x3F
|
||||
#define HID_USAGE_LED_INDICATOR_FAST_BLINK 0x40
|
||||
#define HID_USAGE_LED_INDICATOR_OFF 0x41
|
||||
#define HID_USAGE_LED_FLASH_ON_TIME 0x42
|
||||
#define HID_USAGE_LED_SLOW_BLINK_ON_TIME 0x43
|
||||
#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME 0x44
|
||||
#define HID_USAGE_LED_FAST_BLINK_ON_TIME 0x45
|
||||
#define HID_USAGE_LED_FAST_BLINK_OFF_TIME 0x46
|
||||
#define HID_USAGE_LED_INDICATOR_COLOR 0x47
|
||||
#define HID_USAGE_LED_RED 0x48
|
||||
#define HID_USAGE_LED_GREEN 0x49
|
||||
#define HID_USAGE_LED_AMBER 0x4A
|
||||
#define HID_USAGE_LED_GENERIC_INDICATOR 0x4B
|
||||
|
||||
/* Button Page (0x09) */
|
||||
/* There is no need to label these usages. */
|
||||
|
||||
/* Ordinal Page (0x0A) */
|
||||
/* There is no need to label these usages. */
|
||||
|
||||
/* Telephony Device Page (0x0B) */
|
||||
#define HID_USAGE_TELEPHONY_PHONE 0x01
|
||||
#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE 0x02
|
||||
#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS 0x03
|
||||
#define HID_USAGE_TELEPHONY_HANDSET 0x04
|
||||
#define HID_USAGE_TELEPHONY_HEADSET 0x05
|
||||
#define HID_USAGE_TELEPHONY_KEYPAD 0x06
|
||||
#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON 0x07
|
||||
/* ... */
|
||||
|
||||
/* Consumer Page (0x0C) */
|
||||
#define HID_USAGE_CONSUMER_CONTROL 0x01
|
||||
/* ... */
|
||||
|
||||
/* and others ... */
|
||||
|
||||
|
||||
/* HID Report Item Macros */
|
||||
|
||||
/* Main Items */
|
||||
#define HID_Input(x) 0x81,x
|
||||
#define HID_Output(x) 0x91,x
|
||||
#define HID_Feature(x) 0xB1,x
|
||||
#define HID_Collection(x) 0xA1,x
|
||||
#define HID_EndCollection 0xC0
|
||||
|
||||
/* Data (Input, Output, Feature) */
|
||||
#define HID_Data 0<<0
|
||||
#define HID_Constant 1<<0
|
||||
#define HID_Array 0<<1
|
||||
#define HID_Variable 1<<1
|
||||
#define HID_Absolute 0<<2
|
||||
#define HID_Relative 1<<2
|
||||
#define HID_NoWrap 0<<3
|
||||
#define HID_Wrap 1<<3
|
||||
#define HID_Linear 0<<4
|
||||
#define HID_NonLinear 1<<4
|
||||
#define HID_PreferredState 0<<5
|
||||
#define HID_NoPreferred 1<<5
|
||||
#define HID_NoNullPosition 0<<6
|
||||
#define HID_NullState 1<<6
|
||||
#define HID_NonVolatile 0<<7
|
||||
#define HID_Volatile 1<<7
|
||||
|
||||
/* Collection Data */
|
||||
#define HID_Physical 0x00
|
||||
#define HID_Application 0x01
|
||||
#define HID_Logical 0x02
|
||||
#define HID_Report 0x03
|
||||
#define HID_NamedArray 0x04
|
||||
#define HID_UsageSwitch 0x05
|
||||
#define HID_UsageModifier 0x06
|
||||
|
||||
/* Global Items */
|
||||
#define HID_UsagePage(x) 0x05,x
|
||||
#define HID_UsagePageVendor(x) 0x06,x,0xFF
|
||||
#define HID_LogicalMin(x) 0x15,x
|
||||
#define HID_LogicalMinS(x) 0x16,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_LogicalMinL(x) 0x17,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_LogicalMax(x) 0x25,x
|
||||
#define HID_LogicalMaxS(x) 0x26,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_LogicalMaxL(x) 0x27,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_PhysicalMin(x) 0x35,x
|
||||
#define HID_PhysicalMinS(x) 0x36,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_PhysicalMinL(x) 0x37,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_PhysicalMax(x) 0x45,x
|
||||
#define HID_PhysicalMaxS(x) 0x46,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_PhysicalMaxL(x) 0x47,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_UnitExponent(x) 0x55,x
|
||||
#define HID_Unit(x) 0x65,x
|
||||
#define HID_UnitS(x) 0x66,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_UnitL(x) 0x67,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_ReportSize(x) 0x75,x
|
||||
#define HID_ReportSizeS(x) 0x76,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_ReportSizeL(x) 0x77,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_ReportID(x) 0x85,x
|
||||
#define HID_ReportCount(x) 0x95,x
|
||||
#define HID_ReportCountS(x) 0x96,(x&0xFF),((x>>8)&0xFF)
|
||||
#define HID_ReportCountL(x) 0x97,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF)
|
||||
#define HID_Push 0xA4
|
||||
#define HID_Pop 0xB4
|
||||
|
||||
/* Local Items */
|
||||
#define HID_Usage(x) 0x09,x
|
||||
#define HID_UsageMin(x) 0x19,x
|
||||
#define HID_UsageMax(x) 0x29,x
|
||||
|
||||
|
||||
#endif /* __USB_HID_H__ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_LIB_H__
|
||||
#define __USB_LIB_H__
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* USB Device Configuration
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern U8 USBD_AltSetting[];
|
||||
extern U8 USBD_EP0Buf[];
|
||||
extern const U8 usbd_power;
|
||||
extern const U8 usbd_hs_enable;
|
||||
extern const U16 usbd_if_num;
|
||||
extern const U8 usbd_ep_num;
|
||||
extern const U8 usbd_max_packet0;
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* USB Device Class Configuration
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern const U8 usbd_hid_enable;
|
||||
extern const U8 usbd_hid_if_num;
|
||||
extern const U8 usbd_hid_ep_intin;
|
||||
extern const U8 usbd_hid_ep_intout;
|
||||
extern const U16 usbd_hid_interval [2];
|
||||
extern const U16 usbd_hid_maxpacketsize[2];
|
||||
extern const U8 usbd_hid_inreport_num;
|
||||
extern const U8 usbd_hid_outreport_num;
|
||||
extern const U16 usbd_hid_inreport_max_sz;
|
||||
extern const U16 usbd_hid_outreport_max_sz;
|
||||
extern const U16 usbd_hid_featreport_max_sz;
|
||||
extern U16 USBD_HID_PollingCnt;
|
||||
extern U16 USBD_HID_PollingReload[];
|
||||
extern U8 USBD_HID_IdleCnt [];
|
||||
extern U8 USBD_HID_IdleReload [];
|
||||
extern U8 USBD_HID_IdleSet [];
|
||||
extern U8 USBD_HID_InReport [];
|
||||
extern U8 USBD_HID_OutReport [];
|
||||
extern U8 USBD_HID_FeatReport [];
|
||||
|
||||
extern const U8 usbd_msc_enable;
|
||||
extern const U8 usbd_msc_if_num;
|
||||
extern const U8 usbd_msc_ep_bulkin;
|
||||
extern const U8 usbd_msc_ep_bulkout;
|
||||
extern const U16 usbd_msc_maxpacketsize[2];
|
||||
extern const U8 *usbd_msc_inquiry_data;
|
||||
extern U8 USBD_MSC_BulkBuf [];
|
||||
|
||||
extern const U8 usbd_adc_enable;
|
||||
extern const U8 usbd_adc_cif_num;
|
||||
extern const U8 usbd_adc_sif1_num;
|
||||
extern const U8 usbd_adc_sif2_num;
|
||||
extern const U8 usbd_adc_ep_isoout;
|
||||
extern const U32 usbd_adc_cfg_datafreq;
|
||||
extern const U32 usbd_adc_cfg_p_s;
|
||||
extern const U32 usbd_adc_cfg_p_c;
|
||||
extern const U32 usbd_adc_cfg_b_s;
|
||||
extern S16 USBD_ADC_DataBuf [];
|
||||
|
||||
extern const U8 usbd_cdc_acm_enable;
|
||||
extern const U8 usbd_cdc_acm_cif_num;
|
||||
extern const U8 usbd_cdc_acm_dif_num;
|
||||
extern const U8 usbd_cdc_acm_bufsize;
|
||||
extern const U8 usbd_cdc_acm_ep_intin;
|
||||
extern const U8 usbd_cdc_acm_ep_bulkin;
|
||||
extern const U8 usbd_cdc_acm_ep_bulkout;
|
||||
extern const U16 usbd_cdc_acm_sendbuf_sz;
|
||||
extern const U16 usbd_cdc_acm_receivebuf_sz;
|
||||
extern const U16 usbd_cdc_acm_maxpacketsize [2];
|
||||
extern const U16 usbd_cdc_acm_maxpacketsize1[2];
|
||||
extern U8 USBD_CDC_ACM_SendBuf [];
|
||||
extern U8 USBD_CDC_ACM_ReceiveBuf [];
|
||||
extern U8 USBD_CDC_ACM_NotifyBuf [10];
|
||||
|
||||
extern void usbd_os_evt_set (U16 event_flags, U32 task);
|
||||
extern U16 usbd_os_evt_get (void);
|
||||
extern U32 usbd_os_evt_wait_or (U16 wait_flags, U16 timeout);
|
||||
|
||||
extern const BOOL __rtx;
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* USB Device Descriptors
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern const U8 USBD_HID_ReportDescriptor[];
|
||||
extern const U16 USBD_HID_ReportDescriptorSize;
|
||||
extern const U16 USBD_HID_DescriptorOffset;
|
||||
extern const U8 USBD_DeviceDescriptor[];
|
||||
extern const U8 USBD_DeviceQualifier[];
|
||||
extern const U8 USBD_DeviceQualifier_HS[];
|
||||
extern const U8 USBD_ConfigDescriptor[];
|
||||
extern const U8 USBD_ConfigDescriptor_HS[];
|
||||
extern const U8 USBD_OtherSpeedConfigDescriptor[];
|
||||
extern const U8 USBD_OtherSpeedConfigDescriptor_HS[];
|
||||
extern const U8 USBD_OtherSpeedConfigDescriptor[];
|
||||
extern const U8 USBD_OtherSpeedConfigDescriptor_HS[];
|
||||
extern const U8 USBD_StringDescriptor[];
|
||||
|
||||
#endif /* __USB_LIB_H__ */
|
||||
@@ -0,0 +1,106 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USB_MSC_H__
|
||||
#define __USB_MSC_H__
|
||||
|
||||
|
||||
/* MSC Subclass Codes */
|
||||
#define MSC_SUBCLASS_RBC 0x01
|
||||
#define MSC_SUBCLASS_SFF8020I_MMC2 0x02
|
||||
#define MSC_SUBCLASS_QIC157 0x03
|
||||
#define MSC_SUBCLASS_UFI 0x04
|
||||
#define MSC_SUBCLASS_SFF8070I 0x05
|
||||
#define MSC_SUBCLASS_SCSI 0x06
|
||||
|
||||
/* MSC Protocol Codes */
|
||||
#define MSC_PROTOCOL_CBI_INT 0x00
|
||||
#define MSC_PROTOCOL_CBI_NOINT 0x01
|
||||
#define MSC_PROTOCOL_BULK_ONLY 0x50
|
||||
|
||||
|
||||
/* MSC Request Codes */
|
||||
#define MSC_REQUEST_RESET 0xFF
|
||||
#define MSC_REQUEST_GET_MAX_LUN 0xFE
|
||||
|
||||
|
||||
/* MSC Bulk-only Stage */
|
||||
#define MSC_BS_CBW 0 /* Command Block Wrapper */
|
||||
#define MSC_BS_DATA_OUT 1 /* Data Out Phase */
|
||||
#define MSC_BS_DATA_IN 2 /* Data In Phase */
|
||||
#define MSC_BS_DATA_IN_LAST 3 /* Data In Last Phase */
|
||||
#define MSC_BS_DATA_IN_LAST_STALL 4 /* Data In Last Phase with Stall */
|
||||
#define MSC_BS_CSW 5 /* Command Status Wrapper */
|
||||
#define MSC_BS_ERROR 6 /* Error */
|
||||
|
||||
|
||||
/* Bulk-only Command Block Wrapper */
|
||||
typedef __packed struct _MSC_CBW {
|
||||
U32 dSignature;
|
||||
U32 dTag;
|
||||
U32 dDataLength;
|
||||
U8 bmFlags;
|
||||
U8 bLUN;
|
||||
U8 bCBLength;
|
||||
U8 CB[16];
|
||||
} MSC_CBW;
|
||||
|
||||
/* Bulk-only Command Status Wrapper */
|
||||
typedef __packed struct _MSC_CSW {
|
||||
U32 dSignature;
|
||||
U32 dTag;
|
||||
U32 dDataResidue;
|
||||
U8 bStatus;
|
||||
} MSC_CSW;
|
||||
|
||||
#define MSC_CBW_Signature 0x43425355
|
||||
#define MSC_CSW_Signature 0x53425355
|
||||
|
||||
|
||||
/* CSW Status Definitions */
|
||||
#define CSW_CMD_PASSED 0x00
|
||||
#define CSW_CMD_FAILED 0x01
|
||||
#define CSW_PHASE_ERROR 0x02
|
||||
|
||||
|
||||
/* SCSI Commands */
|
||||
#define SCSI_TEST_UNIT_READY 0x00
|
||||
#define SCSI_REQUEST_SENSE 0x03
|
||||
#define SCSI_FORMAT_UNIT 0x04
|
||||
#define SCSI_INQUIRY 0x12
|
||||
#define SCSI_MODE_SELECT6 0x15
|
||||
#define SCSI_MODE_SENSE6 0x1A
|
||||
#define SCSI_START_STOP_UNIT 0x1B
|
||||
#define SCSI_MEDIA_REMOVAL 0x1E
|
||||
#define SCSI_READ_FORMAT_CAPACITIES 0x23
|
||||
#define SCSI_READ_CAPACITY 0x25
|
||||
#define SCSI_READ10 0x28
|
||||
#define SCSI_WRITE10 0x2A
|
||||
#define SCSI_VERIFY10 0x2F
|
||||
#define SCSI_SYNC_CACHE10 0x35
|
||||
#define SCSI_READ12 0xA8
|
||||
#define SCSI_WRITE12 0xAA
|
||||
#define SCSI_MODE_SELECT10 0x55
|
||||
#define SCSI_MODE_SENSE10 0x5A
|
||||
#define SCSI_SYNC_CACHE16 0x91
|
||||
#define SCSI_ATA_COMMAND_PASS_THROUGH12 0xA1
|
||||
#define SCSI_ATA_COMMAND_PASS_THROUGH16 0x85
|
||||
#define SCSI_SERVICE_ACTION_IN12 0xAB
|
||||
#define SCSI_SERVICE_ACTION_IN16 0x9E
|
||||
#define SCSI_SERVICE_ACTION_OUT12 0xA9
|
||||
#define SCSI_SERVICE_ACTION_OUT16 0x9F
|
||||
|
||||
|
||||
#endif /* __USB_MSC_H__ */
|
||||
@@ -0,0 +1,40 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_CDC_H__
|
||||
#define __USBD_CDC_H__
|
||||
|
||||
|
||||
/*--------------------------- Event handling routines ------------------------*/
|
||||
|
||||
extern void usbd_vcom_serial2usb (void);
|
||||
extern void usbd_vcom_chkserstate (void);
|
||||
extern void usbd_vcom_usb2serial (void);
|
||||
extern void usbd_cdc_ser_flush (void);
|
||||
|
||||
extern void USBD_CDC_SOF_Event (void);
|
||||
|
||||
extern void USBD_CDC_EP_INTIN_Event (U32 event);
|
||||
extern void USBD_CDC_EP_BULKIN_Event (U32 event);
|
||||
extern void USBD_CDC_EP_BULKOUT_Event (U32 event);
|
||||
extern void USBD_CDC_EP_BULK_Event (U32 event);
|
||||
|
||||
extern void USBD_RTX_CDC_EP_INTIN_Event (void);
|
||||
extern void USBD_RTX_CDC_EP_BULKIN_Event (void);
|
||||
extern void USBD_RTX_CDC_EP_BULKOUT_Event (void);
|
||||
extern void USBD_RTX_CDC_EP_BULK_Event (void);
|
||||
|
||||
|
||||
#endif /* __USBD_CDC_H__ */
|
||||
@@ -0,0 +1,37 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_CDC_ACM_H__
|
||||
#define __USBD_CDC_ACM_H__
|
||||
|
||||
|
||||
/*--------------------------- Event handling routines ------------------------*/
|
||||
|
||||
extern void USBD_CDC_ACM_Reset_Event (void);
|
||||
|
||||
extern void USBD_CDC_ACM_SOF_Event (void);
|
||||
|
||||
extern void USBD_CDC_ACM_EP_INTIN_Event (U32 event);
|
||||
extern void USBD_CDC_ACM_EP_BULKIN_Event (U32 event);
|
||||
extern void USBD_CDC_ACM_EP_BULKOUT_Event (U32 event);
|
||||
extern void USBD_CDC_ACM_EP_BULK_Event (U32 event);
|
||||
|
||||
extern __task void USBD_RTX_CDC_ACM_EP_INTIN_Event (void);
|
||||
extern __task void USBD_RTX_CDC_ACM_EP_BULKIN_Event (void);
|
||||
extern __task void USBD_RTX_CDC_ACM_EP_BULKOUT_Event (void);
|
||||
extern __task void USBD_RTX_CDC_ACM_EP_BULK_Event (void);
|
||||
|
||||
|
||||
#endif /* __USBD_CDC_ACM_H__ */
|
||||
@@ -0,0 +1,68 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_CORE_H__
|
||||
#define __USBD_CORE_H__
|
||||
|
||||
|
||||
/*--------------------------- Data structures --------------------------------*/
|
||||
|
||||
/* USB Device Core Endpoint Data Structure */
|
||||
typedef struct _USBD_EP_DATA {
|
||||
U8 *pData;
|
||||
U16 Count;
|
||||
} USBD_EP_DATA;
|
||||
|
||||
|
||||
/*--------------------------- Global variables -------------------------------*/
|
||||
|
||||
/* USB Device Core Global Variables */
|
||||
extern U16 USBD_DeviceStatus;
|
||||
extern U8 USBD_DeviceAddress;
|
||||
extern U8 USBD_Configuration;
|
||||
extern U32 USBD_EndPointMask;
|
||||
extern U32 USBD_EndPointHalt;
|
||||
extern U32 USBD_EndPointStall;
|
||||
extern U8 USBD_NumInterfaces;
|
||||
extern U8 USBD_HighSpeed;
|
||||
extern U8 USBD_ZLP;
|
||||
|
||||
extern USBD_EP_DATA USBD_EP0Data;
|
||||
extern USB_SETUP_PACKET USBD_SetupPacket;
|
||||
|
||||
extern OS_TID USBD_RTX_DevTask;
|
||||
extern OS_TID USBD_RTX_EPTask[];
|
||||
extern OS_TID USBD_RTX_CoreTask;
|
||||
|
||||
|
||||
/*--------------------------- Functions exported to class specific files -----*/
|
||||
|
||||
extern void USBD_SetupStage (void);
|
||||
extern void USBD_DataInStage (void);
|
||||
extern void USBD_DataOutStage (void);
|
||||
extern void USBD_StatusInStage (void);
|
||||
extern void USBD_StatusOutStage (void);
|
||||
|
||||
|
||||
/*--------------------------- Event handling routines ------------------------*/
|
||||
|
||||
extern void usbd_class_init (void);
|
||||
|
||||
extern void USBD_EndPoint0 (U32 event);
|
||||
|
||||
extern __task void USBD_RTX_EndPoint0 (void);
|
||||
|
||||
|
||||
#endif /* __USBD_CORE_H__ */
|
||||
@@ -0,0 +1,26 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_CORE_CDC_H__
|
||||
#define __USBD_CORE_CDC_H__
|
||||
|
||||
|
||||
/*--------------------------- Core overridable class specific functions ------*/
|
||||
|
||||
extern BOOL USBD_EndPoint0_Setup_CDC_ReqToIF (void);
|
||||
extern BOOL USBD_EndPoint0_Out_CDC_ReqToIF (void);
|
||||
|
||||
|
||||
#endif /* __USBD_CORE_CDC_H__ */
|
||||
@@ -0,0 +1,27 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_CORE_HID_H__
|
||||
#define __USBD_CORE_HID_H__
|
||||
|
||||
|
||||
/*--------------------------- Core overridable class specific functions ------*/
|
||||
|
||||
extern BOOL USBD_ReqGetDescriptor_HID (U8 **pD, U32 *len);
|
||||
extern BOOL USBD_EndPoint0_Setup_HID_ReqToIF (void);
|
||||
extern BOOL USBD_EndPoint0_Out_HID_ReqToIF (void);
|
||||
|
||||
|
||||
#endif /* __USBD_CORE_HID_H__ */
|
||||
@@ -0,0 +1,27 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_CORE_MSC_H__
|
||||
#define __USBD_CORE_MSC_H__
|
||||
|
||||
|
||||
/*--------------------------- Core overridable class specific functions ------*/
|
||||
|
||||
extern void USBD_ReqClrFeature_MSC (U32 EPNum);
|
||||
extern BOOL USBD_EndPoint0_Setup_MSC_ReqToIF (void);
|
||||
extern BOOL USBD_EndPoint0_Out_MSC_ReqToIF (void);
|
||||
|
||||
|
||||
#endif /* __USBD_CORE_MSC_H__ */
|
||||
@@ -0,0 +1,30 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_DESC_H__
|
||||
#define __USBD_DESC_H__
|
||||
|
||||
#define WBVAL(x) (x & 0xFF),((x >> 8) & 0xFF)
|
||||
#define B3VAL(x) (x & 0xFF),((x >> 8) & 0xFF),((x >> 16) & 0xFF)
|
||||
#define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR))
|
||||
#define USB_DEVICE_QUALI_SIZE (sizeof(USB_DEVICE_QUALIFIER_DESCRIPTOR))
|
||||
#define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))
|
||||
#define USB_INTERFACE_ASSOC_DESC_SIZE (sizeof(USB_INTERFACE_ASSOCIATION_DESCRIPTOR))
|
||||
#define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR))
|
||||
#define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR))
|
||||
#define USB_HID_DESC_SIZE (sizeof(HID_DESCRIPTOR))
|
||||
#define USB_HID_REPORT_DESC_SIZE (sizeof(USBD_HID_ReportDescriptor))
|
||||
|
||||
#endif /* __USBD_DESC_H__ */
|
||||
@@ -0,0 +1,71 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_EVENT_H__
|
||||
#define __USBD_EVENT_H__
|
||||
|
||||
|
||||
/* USB Device - Device Events */
|
||||
#define USBD_EVT_POWER_ON (1 << 0) /* USB Power On */
|
||||
#define USBD_EVT_POWER_OFF (1 << 1) /* USB Power Off */
|
||||
#define USBD_EVT_RESET (1 << 2) /* USB Bus Reset */
|
||||
#define USBD_EVT_WAKEUP (1 << 3) /* USB Remote Wakeup */
|
||||
#define USBD_EVT_SUSPEND (1 << 4) /* USB Suspend */
|
||||
#define USBD_EVT_RESUME (1 << 5) /* USB Resume */
|
||||
#define USBD_EVT_SOF (1 << 6) /* USB Start of Frame */
|
||||
#define USBD_EVT_ERROR (1 << 7) /* USB Error */
|
||||
|
||||
/* USB Device - Endpoint Events */
|
||||
#define USBD_EVT_SETUP (1 << 1) /* Setup Packet */
|
||||
#define USBD_EVT_OUT (1 << 2) /* OUT Packet */
|
||||
#define USBD_EVT_IN (1 << 3) /* IN Packet */
|
||||
#define USBD_EVT_OUT_NAK (1 << 4) /* OUT Packet - Not Acknowledged */
|
||||
#define USBD_EVT_IN_NAK (1 << 5) /* IN Packet - Not Acknowledged */
|
||||
#define USBD_EVT_OUT_STALL (1 << 6) /* OUT Packet - Stalled */
|
||||
#define USBD_EVT_IN_STALL (1 << 7) /* IN Packet - Stalled */
|
||||
#define USBD_EVT_OUT_DMA_EOT (1 << 8) /* DMA OUT EP - End of Transfer */
|
||||
#define USBD_EVT_IN_DMA_EOT (1 << 9) /* DMA IN EP - End of Transfer */
|
||||
#define USBD_EVT_OUT_DMA_NDR (1 << 10) /* DMA OUT EP - New Descriptor Request*/
|
||||
#define USBD_EVT_IN_DMA_NDR (1 << 11) /* DMA IN EP - New Descriptor Request*/
|
||||
#define USBD_EVT_OUT_DMA_ERR (1 << 12) /* DMA OUT EP - Error */
|
||||
#define USBD_EVT_IN_DMA_ERR (1 << 13) /* DMA IN EP - Error */
|
||||
|
||||
/* USB Device - Core Events */
|
||||
#define USBD_EVT_SET_CFG (1 << 0) /* Set Configuration */
|
||||
#define USBD_EVT_SET_IF (1 << 1) /* Set Interface */
|
||||
#define USBD_EVT_SET_FEATURE (1 << 2) /* Set Feature */
|
||||
#define USBD_EVT_CLR_FEATURE (1 << 3) /* Clear Feature */
|
||||
|
||||
/* USB Device - Device Events Callback Pointers */
|
||||
extern void (* const USBD_P_Power_Event )(BOOL power);
|
||||
extern void (* const USBD_P_Reset_Event )(void);
|
||||
extern void (* const USBD_P_Suspend_Event )(void);
|
||||
extern void (* const USBD_P_Resume_Event )(void);
|
||||
extern void (* const USBD_P_WakeUp_Event )(void);
|
||||
extern void (* const USBD_P_SOF_Event )(void);
|
||||
extern void (* const USBD_P_Error_Event )(U32 error);
|
||||
|
||||
/* USB Device - Endpoint Events Callback Pointers */
|
||||
extern void (* const USBD_P_EP[16]) (U32 event);
|
||||
|
||||
/* USB Device - Core Events Callback Pointers */
|
||||
extern void (* const USBD_P_Configure_Event)(void);
|
||||
extern void (* const USBD_P_Interface_Event)(void);
|
||||
extern void (* const USBD_P_Feature_Event )(void);
|
||||
|
||||
/* USB Device - RTX version RTX tasks initialization */
|
||||
extern void USBD_RTX_TaskInit (void);
|
||||
|
||||
#endif /* __USBD_EVENT_H__ */
|
||||
@@ -0,0 +1,44 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_HID_H__
|
||||
#define __USBD_HID_H__
|
||||
|
||||
|
||||
/*--------------------------- Global constants -------------------------------*/
|
||||
|
||||
/* USB HID Class API enumerated constants */
|
||||
enum {
|
||||
USBD_HID_REQ_EP_CTRL = 0, /* Request from control endpoint */
|
||||
USBD_HID_REQ_EP_INT, /* Request from interrupt endpoint */
|
||||
USBD_HID_REQ_PERIOD_UPDATE /* Request from periodic update */
|
||||
};
|
||||
|
||||
|
||||
/*--------------------------- Event handling routines ------------------------*/
|
||||
|
||||
extern void USBD_HID_Configure_Event (void);
|
||||
extern void USBD_HID_SOF_Event (void);
|
||||
|
||||
extern void USBD_HID_EP_INTIN_Event (U32 event);
|
||||
extern void USBD_HID_EP_INTOUT_Event (U32 event);
|
||||
extern void USBD_HID_EP_INT_Event (U32 event);
|
||||
|
||||
extern __task void USBD_RTX_HID_EP_INTIN_Event (void);
|
||||
extern __task void USBD_RTX_HID_EP_INTOUT_Event(void);
|
||||
extern __task void USBD_RTX_HID_EP_INT_Event (void);
|
||||
|
||||
|
||||
#endif /* __USBD_HID_H__ */
|
||||
@@ -0,0 +1,43 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_HW_H__
|
||||
#define __USBD_HW_H__
|
||||
|
||||
|
||||
/* USB Hardware Functions */
|
||||
extern void USBD_Init (void);
|
||||
extern void USBD_Connect (BOOL con);
|
||||
extern void USBD_Reset (void);
|
||||
extern void USBD_Suspend (void);
|
||||
extern void USBD_Resume (void);
|
||||
extern void USBD_WakeUp (void);
|
||||
extern void USBD_WakeUpCfg (BOOL cfg);
|
||||
extern void USBD_SetAddress (U32 adr, U32 setup);
|
||||
extern void USBD_Configure (BOOL cfg);
|
||||
extern void USBD_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD);
|
||||
extern void USBD_DirCtrlEP (U32 dir);
|
||||
extern void USBD_EnableEP (U32 EPNum);
|
||||
extern void USBD_DisableEP (U32 EPNum);
|
||||
extern void USBD_ResetEP (U32 EPNum);
|
||||
extern void USBD_SetStallEP (U32 EPNum);
|
||||
extern void USBD_ClrStallEP (U32 EPNum);
|
||||
extern void USBD_ClearEPBuf (U32 EPNum);
|
||||
extern U32 USBD_ReadEP (U32 EPNum, U8 *pData);
|
||||
extern U32 USBD_WriteEP (U32 EPNum, U8 *pData, U32 cnt);
|
||||
extern U32 USBD_GetFrame (void);
|
||||
extern U32 USBD_GetError (void);
|
||||
|
||||
#endif /* __USBD_HW_H__ */
|
||||
@@ -0,0 +1,33 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_LIB_CDC_H__
|
||||
#define __USBD_LIB_CDC_H__
|
||||
|
||||
|
||||
/*--------------------------- USB Requests -----------------------------------*/
|
||||
|
||||
extern int32_t USBD_CDC_ACM_SendEncapsulatedCommand (void);
|
||||
extern int32_t USBD_CDC_ACM_GetEncapsulatedResponse (void);
|
||||
extern int32_t USBD_CDC_ACM_SetCommFeature (uint16_t feat);
|
||||
extern int32_t USBD_CDC_ACM_GetCommFeature (uint16_t feat);
|
||||
extern int32_t USBD_CDC_ACM_ClearCommFeature (uint16_t feat);
|
||||
extern int32_t USBD_CDC_ACM_SetLineCoding (void);
|
||||
extern int32_t USBD_CDC_ACM_GetLineCoding (void);
|
||||
extern int32_t USBD_CDC_ACM_SetControlLineState (uint16_t ctrl_bmp);
|
||||
extern int32_t USBD_CDC_ACM_SendBreak (uint16_t dur);
|
||||
|
||||
|
||||
#endif /* __USBD_LIB_CDC_H__ */
|
||||
@@ -0,0 +1,30 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_LIB_HID_H__
|
||||
#define __USBD_LIB_HID_H__
|
||||
|
||||
|
||||
/*--------------------------- USB Requests -----------------------------------*/
|
||||
|
||||
extern BOOL USBD_HID_GetReport (void);
|
||||
extern BOOL USBD_HID_SetReport (void);
|
||||
extern BOOL USBD_HID_GetIdle (void);
|
||||
extern BOOL USBD_HID_SetIdle (void);
|
||||
extern BOOL USBD_HID_GetProtocol (void);
|
||||
extern BOOL USBD_HID_SetProtocol (void);
|
||||
|
||||
|
||||
#endif /* __USBD_LIB_HID_H__ */
|
||||
@@ -0,0 +1,29 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_LIB_MSC_H__
|
||||
#define __USBD_LIB_MSC_H__
|
||||
|
||||
|
||||
/*--------------------------- USB Requests -----------------------------------*/
|
||||
|
||||
extern void USBD_MSC_ClrStallEP(U32 EPNum);
|
||||
extern BOOL USBD_MSC_Reset (void);
|
||||
extern BOOL USBD_MSC_GetMaxLUN (void);
|
||||
extern void USBD_MSC_GetCBW (void);
|
||||
extern void USBD_MSC_SetCSW (void);
|
||||
|
||||
|
||||
#endif /* __USBD_LIB_MSC_H__ */
|
||||
@@ -0,0 +1,43 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __USBD_MSC_H__
|
||||
#define __USBD_MSC_H__
|
||||
|
||||
|
||||
/*--------------------------- Global variables -------------------------------*/
|
||||
|
||||
/* USB Device Mass Storage Device Class Global Variables */
|
||||
extern BOOL USBD_MSC_MediaReady;
|
||||
extern BOOL USBD_MSC_ReadOnly;
|
||||
extern U32 USBD_MSC_MemorySize;
|
||||
extern U32 USBD_MSC_BlockSize;
|
||||
extern U32 USBD_MSC_BlockGroup;
|
||||
extern U32 USBD_MSC_BlockCount;
|
||||
extern U8 *USBD_MSC_BlockBuf;
|
||||
|
||||
|
||||
/*--------------------------- Event handling routines ------------------------*/
|
||||
|
||||
extern void USBD_MSC_EP_BULKIN_Event (U32 event);
|
||||
extern void USBD_MSC_EP_BULKOUT_Event (U32 event);
|
||||
extern void USBD_MSC_EP_BULK_Event (U32 event);
|
||||
|
||||
extern __task void USBD_RTX_MSC_EP_BULKIN_Event (void);
|
||||
extern __task void USBD_RTX_MSC_EP_BULKOUT_Event (void);
|
||||
extern __task void USBD_RTX_MSC_EP_BULK_Event (void);
|
||||
|
||||
|
||||
#endif /* __USBD_MSC_H__ */
|
||||
@@ -0,0 +1,732 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <RTL.h>
|
||||
#include <rl_usb.h>
|
||||
#include <string.h>
|
||||
#include "usb_for_lib.h"
|
||||
|
||||
|
||||
/* Module global variables */
|
||||
|
||||
/** \ingroup USBD_CDC_ACM_global_variables
|
||||
\defgroup USBD_CDC_ACM_GLOBAL_VAR Global Variables (GLOBAL_VAR)
|
||||
\brief Global variables used in USBD CDC ACM module
|
||||
*/
|
||||
int32_t data_send_access; /*!< Flag active while send data (in the send intermediate buffer) is being accessed */
|
||||
int32_t data_send_active; /*!< Flag active while data is being sent */
|
||||
int32_t data_send_zlp; /*!< Flag active when ZLP needs to be sent */
|
||||
int32_t data_to_send_wr; /*!< Number of bytes written to the send intermediate buffer */
|
||||
int32_t data_to_send_rd; /*!< Number of bytes read from the send intermediate buffer */
|
||||
uint8_t *ptr_data_to_send; /*!< Pointer to the send intermediate buffer to the data to be sent */
|
||||
uint8_t *ptr_data_sent; /*!< Pointer to the send intermediate buffer to the data already sent */
|
||||
|
||||
int32_t data_read_access; /*!< Flag active while read data (in the receive intermediate buffer) is being accessed */
|
||||
int32_t data_receive_int_access; /*!< Flag active while read data (in the receive intermediate buffer) is being accessed from the IRQ function*/
|
||||
int32_t data_received_pending_pckts; /*!< Number of packets received but not handled (pending) */
|
||||
int32_t data_no_space_for_receive; /*!< Flag active while there is no more space for reception */
|
||||
uint8_t *ptr_data_received; /*!< Pointer to the receive intermediate buffer to the received unread data */
|
||||
uint8_t *ptr_data_read; /*!< Pointer to the receive intermediate buffer to the received read data */
|
||||
|
||||
uint16_t control_line_state; /*!< Control line state settings bitmap (0. bit - DTR state, 1. bit - RTS state) */
|
||||
|
||||
CDC_LINE_CODING line_coding; /*!< Communication settings */
|
||||
|
||||
/* end of group USBD_CDC_ACM_GLOBAL_VAR */
|
||||
|
||||
|
||||
/* Functions that should be provided by user to use standard Virtual COM port
|
||||
functionality */
|
||||
__weak int32_t USBD_CDC_ACM_PortInitialize (void) { return (0); };
|
||||
__weak int32_t USBD_CDC_ACM_PortUninitialize (void) { return (0); };
|
||||
__weak int32_t USBD_CDC_ACM_PortReset (void) { return (0); };
|
||||
__weak int32_t USBD_CDC_ACM_PortSetLineCoding (CDC_LINE_CODING *line_coding) { return (0); };
|
||||
__weak int32_t USBD_CDC_ACM_PortGetLineCoding (CDC_LINE_CODING *line_coding) { return (0); };
|
||||
__weak int32_t USBD_CDC_ACM_PortSetControlLineState (uint16_t ctrl_bmp) { return (0); };
|
||||
|
||||
/* Functions that can be used by user to use standard Virtual COM port
|
||||
functionality */
|
||||
int32_t USBD_CDC_ACM_DataSend (const uint8_t *buf, int32_t len);
|
||||
int32_t USBD_CDC_ACM_PutChar (const uint8_t ch);
|
||||
int32_t USBD_CDC_ACM_DataRead ( uint8_t *buf, int32_t len);
|
||||
int32_t USBD_CDC_ACM_GetChar (void);
|
||||
__weak int32_t USBD_CDC_ACM_DataReceived ( int32_t len) { return (0); };
|
||||
int32_t USBD_CDC_ACM_DataAvailable (void);
|
||||
int32_t USBD_CDC_ACM_Notify (uint16_t stat);
|
||||
|
||||
/* Functions handling CDC ACM requests (can be overridden to provide custom
|
||||
handling of CDC ACM requests) */
|
||||
__weak int32_t USBD_CDC_ACM_SendEncapsulatedCommand (void) { return (0); }
|
||||
__weak int32_t USBD_CDC_ACM_GetEncapsulatedResponse (void) { return (0); }
|
||||
__weak int32_t USBD_CDC_ACM_SetCommFeature (uint16_t feat) { return (0); }
|
||||
__weak int32_t USBD_CDC_ACM_GetCommFeature (uint16_t feat) { return (0); }
|
||||
__weak int32_t USBD_CDC_ACM_ClearCommFeature (uint16_t feat) { return (0); }
|
||||
__weak int32_t USBD_CDC_ACM_SendBreak (uint16_t dur) { return (0); }
|
||||
|
||||
|
||||
/* Local function prototypes */
|
||||
static void USBD_CDC_ACM_EP_BULKOUT_HandleData (void);
|
||||
static void USBD_CDC_ACM_EP_BULKIN_HandleData (void);
|
||||
|
||||
|
||||
/*----------------- USB CDC ACM class handling functions ---------------------*/
|
||||
|
||||
/** \brief Initialization of the USB CDC class (ACM)
|
||||
|
||||
The function calls USBD_CDC_ACM_PortInitialize function which
|
||||
initializes Virtual COM Port.
|
||||
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
__weak int32_t USBD_CDC_ACM_Initialize (void) {
|
||||
|
||||
return (USBD_CDC_ACM_PortInitialize ());
|
||||
}
|
||||
|
||||
|
||||
/** \brief Uninitialization of the USB CDC class (ACM)
|
||||
|
||||
The function calls USBD_CDC_ACM_PortUninitialize function which
|
||||
uninitializes Virtual COM Port.
|
||||
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
__weak int32_t USBD_CDC_ACM_Uninitialization (void) {
|
||||
|
||||
return (USBD_CDC_ACM_PortUninitialize ());
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reset of the USB CDC class (ACM) variables and states
|
||||
|
||||
The function resets class variables and states, it calls
|
||||
USBD_CDC_ACM_PortReset function which resets Virtual COM Port variables
|
||||
and states and calls USBD_CDC_ACM_PortSetLineCoding function with
|
||||
default parameters to set default communication settings for the
|
||||
Virtual COM Port.
|
||||
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
__weak int32_t USBD_CDC_ACM_Reset (void) {
|
||||
|
||||
data_send_access = 0;
|
||||
data_send_active = 0;
|
||||
data_send_zlp = 0;
|
||||
data_to_send_wr = 0;
|
||||
data_to_send_rd = 0;
|
||||
ptr_data_to_send = USBD_CDC_ACM_SendBuf;
|
||||
ptr_data_sent = USBD_CDC_ACM_SendBuf;
|
||||
|
||||
data_read_access = 0;
|
||||
data_receive_int_access = 0;
|
||||
data_received_pending_pckts = 0;
|
||||
data_no_space_for_receive = 0;
|
||||
ptr_data_received = USBD_CDC_ACM_ReceiveBuf;
|
||||
ptr_data_read = USBD_CDC_ACM_ReceiveBuf;
|
||||
|
||||
control_line_state = 0;
|
||||
|
||||
USBD_CDC_ACM_PortReset ();
|
||||
|
||||
line_coding.dwDTERate = 9600;
|
||||
line_coding.bCharFormat = 0;
|
||||
line_coding.bParityType = 0;
|
||||
line_coding.bDataBits = 8;
|
||||
|
||||
return (USBD_CDC_ACM_PortSetLineCoding (&line_coding));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Sets Line Coding for the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function is a callback function that forwards USB CDC ACM request
|
||||
to set communication settings to the Virtual COM Port.
|
||||
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
__weak int32_t USBD_CDC_ACM_SetLineCoding (void) {
|
||||
|
||||
line_coding.dwDTERate = (USBD_EP0Buf[0] << 0) |
|
||||
(USBD_EP0Buf[1] << 8) |
|
||||
(USBD_EP0Buf[2] << 16) |
|
||||
(USBD_EP0Buf[3] << 24) ;
|
||||
line_coding.bCharFormat = USBD_EP0Buf[4];
|
||||
line_coding.bParityType = USBD_EP0Buf[5];
|
||||
line_coding.bDataBits = USBD_EP0Buf[6];
|
||||
|
||||
return (USBD_CDC_ACM_PortSetLineCoding (&line_coding));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Gets Line Coding from the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function is a callback function that forwards USB CDC ACM request
|
||||
to get communication settings from the Virtual COM Port.
|
||||
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
__weak int32_t USBD_CDC_ACM_GetLineCoding (void) {
|
||||
|
||||
if (USBD_CDC_ACM_PortGetLineCoding (&line_coding)) {
|
||||
USBD_EP0Buf[0] = (line_coding.dwDTERate >> 0) & 0xFF;
|
||||
USBD_EP0Buf[1] = (line_coding.dwDTERate >> 8) & 0xFF;
|
||||
USBD_EP0Buf[2] = (line_coding.dwDTERate >> 16) & 0xFF;
|
||||
USBD_EP0Buf[3] = (line_coding.dwDTERate >> 24) & 0xFF;
|
||||
USBD_EP0Buf[4] = line_coding.bCharFormat;
|
||||
USBD_EP0Buf[5] = line_coding.bParityType;
|
||||
USBD_EP0Buf[6] = line_coding.bDataBits;
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Sets Control Line State for the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function is a callback function that forwards USB CDC ACM request
|
||||
to set desired control line state to the Virtual COM Port.
|
||||
|
||||
\param [in] ctrl_bmp Control line settings bitmap (
|
||||
0. bit - DTR state,
|
||||
1. bit - RTS state).
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
__weak int32_t USBD_CDC_ACM_SetControlLineState (uint16_t ctrl_bmp) {
|
||||
|
||||
control_line_state = ctrl_bmp;
|
||||
|
||||
return (USBD_CDC_ACM_PortSetControlLineState (ctrl_bmp));
|
||||
}
|
||||
|
||||
|
||||
/*----------------- USB CDC ACM user API functions ---------------------------*/
|
||||
|
||||
/** \brief Number of free bytes in the Send buffer
|
||||
*/
|
||||
int32_t USBD_CDC_ACM_DataFree(void) {
|
||||
return ((int32_t)usbd_cdc_acm_sendbuf_sz) - (data_to_send_wr - data_to_send_rd);
|
||||
}
|
||||
|
||||
/** \brief Sends data over the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function puts requested data to the send intermediate buffer and
|
||||
prepares it for sending over the Virtual COM Port.
|
||||
|
||||
\param [in] buf Buffer containing data to be sent.
|
||||
\param [in] len Maximum number of bytes to be sent.
|
||||
\return Number of bytes accepted to be sent.
|
||||
*/
|
||||
|
||||
int32_t USBD_CDC_ACM_DataSend (const uint8_t *buf, int32_t len) {
|
||||
int32_t len_data, len_available, len_before_wrap;
|
||||
uint8_t *buf_loc;
|
||||
|
||||
buf_loc = (uint8_t *)buf; /* Pointer to buf */
|
||||
len_data = data_to_send_wr - data_to_send_rd; /* Num of data in buffer*/
|
||||
len_available = ((int32_t)usbd_cdc_acm_sendbuf_sz) - len_data; /* Num of
|
||||
bytes of space available */
|
||||
if (len_available <= 0) /* If no space for data to send */
|
||||
return (0);
|
||||
|
||||
if (len > len_available) /* If more data requested for sending
|
||||
then available space */
|
||||
len = len_available; /* Correct to maximum available */
|
||||
|
||||
len_before_wrap = 0; /* Circular buffer size before wrap */
|
||||
|
||||
if ((ptr_data_to_send>=ptr_data_sent) && /* If wrap is possible to happen */
|
||||
((ptr_data_to_send + len) > (USBD_CDC_ACM_SendBuf + usbd_cdc_acm_sendbuf_sz))) {
|
||||
/* If data wraps around end of buffer */
|
||||
len_before_wrap = USBD_CDC_ACM_SendBuf + usbd_cdc_acm_sendbuf_sz - ptr_data_to_send;
|
||||
memcpy (ptr_data_to_send, buf_loc, len_before_wrap);/* Copy data till end */
|
||||
buf_loc += len_before_wrap; /* Increment buf pointer */
|
||||
len -= len_before_wrap; /* Decrement bytes to send*/
|
||||
ptr_data_to_send = USBD_CDC_ACM_SendBuf; /* Wrap send buffer
|
||||
pointer to beginning of
|
||||
the send buffer */
|
||||
}
|
||||
|
||||
if (len) { /* If there are bytes to send */
|
||||
memcpy (ptr_data_to_send, buf_loc, len); /* Copy data to send buffer */
|
||||
ptr_data_to_send += len; /* Correct position of write pointer */
|
||||
}
|
||||
len += len_before_wrap; /* Total number of bytes prepared for
|
||||
send */
|
||||
data_to_send_wr += len; /* Bytes prepared to send counter */
|
||||
|
||||
return (len); /* Number of bytes accepted for send */
|
||||
}
|
||||
|
||||
|
||||
/** \brief Sends a single character over the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function puts requested data character to the send intermediate buffer
|
||||
and prepares it for sending over the Virtual COM Port.
|
||||
|
||||
\param [in] ch Character to be sent.
|
||||
\return -1 Function failed.
|
||||
\return Character accepted to be sent.
|
||||
*/
|
||||
|
||||
int32_t USBD_CDC_ACM_PutChar (const uint8_t ch) {
|
||||
|
||||
if ((USBD_CDC_ACM_DataSend (&ch, 1)) == 1)
|
||||
return ((uint32_t) ch);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reads data received over the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function reads data from the receive intermediate buffer that was
|
||||
received over the Virtual COM Port.
|
||||
|
||||
\param [in] buf Buffer to where data will be read.
|
||||
\param [in] len Maximum number of bytes to be read.
|
||||
\return Number of bytes actually read.
|
||||
*/
|
||||
|
||||
int32_t USBD_CDC_ACM_DataRead (uint8_t *buf, int32_t len) {
|
||||
int32_t len_data;
|
||||
|
||||
if (ptr_data_received>ptr_data_read) {/*If there is already received data */
|
||||
len_data = ptr_data_received - ptr_data_read; /* Available bytes of data */
|
||||
|
||||
if (len > len_data) /* If more requested then available */
|
||||
len = len_data; /* correct to return maximum available*/
|
||||
|
||||
memcpy (buf, ptr_data_read, len); /* Copy received data to provided buf */
|
||||
ptr_data_read += len; /* Correct position of read pointer */
|
||||
} else {
|
||||
len = 0; /* No data received */
|
||||
}
|
||||
|
||||
return (len); /* Number of bytes actually read */
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reads one character of data received over the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function reads data character from the receive intermediate buffer that
|
||||
was received over the Virtual COM Port.
|
||||
|
||||
\return -1 No character available.
|
||||
\return Received character.
|
||||
*/
|
||||
|
||||
int32_t USBD_CDC_ACM_GetChar (void) {
|
||||
uint8_t ch;
|
||||
|
||||
if ((USBD_CDC_ACM_DataRead (&ch, 1)) == 1)
|
||||
return ((int32_t) ch);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Retrieves number of bytes received over the USB CDC ACM Virtual COM Port
|
||||
|
||||
The function retrieves number of bytes available in the intermediate buffer
|
||||
that were received over the Virtual COM Port.
|
||||
|
||||
\return Number of bytes available for read.
|
||||
*/
|
||||
|
||||
int32_t USBD_CDC_ACM_DataAvailable (void) {
|
||||
return (ptr_data_received - ptr_data_read);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Sends a notification of Virtual COM Port statuses and line states
|
||||
|
||||
The function sends error and line status of the Virtual COM Port over the
|
||||
Interrupt endpoint. (SerialState notification is defined in usbcdc11.pdf, 6.3.5.)
|
||||
|
||||
\param [in] stat Error and line statuses (
|
||||
6. bit - bOverRun,
|
||||
5. bit - bParity,
|
||||
4. bit - bFraming,
|
||||
3. bit - bRingSignal,
|
||||
2. bit - bBreak,
|
||||
1. bit - bTxCarrier (DSR line state),
|
||||
0. bit - bRxCarrier (DCD line status)).
|
||||
\return 0 Function failed.
|
||||
\return 1 Function succeeded.
|
||||
*/
|
||||
|
||||
int32_t USBD_CDC_ACM_Notify (uint16_t stat) {
|
||||
|
||||
if (USBD_Configuration) {
|
||||
USBD_CDC_ACM_NotifyBuf[0] = 0xA1; /* bmRequestType */
|
||||
USBD_CDC_ACM_NotifyBuf[1] = CDC_NOTIFICATION_SERIAL_STATE;/* bNotification
|
||||
(SERIAL_STATE) */
|
||||
USBD_CDC_ACM_NotifyBuf[2] = 0x00; /* wValue */
|
||||
USBD_CDC_ACM_NotifyBuf[3] = 0x00;
|
||||
USBD_CDC_ACM_NotifyBuf[4] = 0x00; /* wIndex (Interface 0) */
|
||||
USBD_CDC_ACM_NotifyBuf[5] = 0x00;
|
||||
USBD_CDC_ACM_NotifyBuf[6] = 0x02; /* wLength */
|
||||
USBD_CDC_ACM_NotifyBuf[7] = 0x00;
|
||||
USBD_CDC_ACM_NotifyBuf[8] = stat>>0;/* UART State Bitmap */
|
||||
USBD_CDC_ACM_NotifyBuf[9] = stat>>8;
|
||||
|
||||
/* Write notification to be sent */
|
||||
USBD_WriteEP (usbd_cdc_acm_ep_intin | 0x80, USBD_CDC_ACM_NotifyBuf, 10);
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*----------------- USB CDC ACM communication event handlers -----------------*/
|
||||
|
||||
/** \brief Handle Reset Events
|
||||
|
||||
The function handles Reset events.
|
||||
*/
|
||||
|
||||
void USBD_CDC_ACM_Reset_Event (void) {
|
||||
|
||||
USBD_CDC_ACM_Reset ();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle SOF Events
|
||||
|
||||
The function handles Start Of Frame events. It checks if there is pending
|
||||
data on the Bulk Out endpoint and handles it
|
||||
(USBD_CDC_ACM_EP_BULKOUT_HandleData) if there is enough space in the
|
||||
intermediate receive buffer and it calls received function callback
|
||||
(USBD_CDC_ACM_DataReceived) it also activates data send over the Bulk In
|
||||
endpoint if there is data to be sent (USBD_CDC_ACM_EP_BULKIN_HandleData).
|
||||
*/
|
||||
|
||||
void USBD_CDC_ACM_SOF_Event (void) {
|
||||
|
||||
if ((!data_read_access) && /* If not read active */
|
||||
(ptr_data_received == ptr_data_read) && /* If received and read
|
||||
pointers point to same
|
||||
the location */
|
||||
(ptr_data_received != USBD_CDC_ACM_ReceiveBuf)) { /* and if receive
|
||||
pointer does not already
|
||||
point to the start of
|
||||
the receive buffer */
|
||||
data_read_access = 1; /* Block access to read data */
|
||||
ptr_data_received = USBD_CDC_ACM_ReceiveBuf; /* Correct received pointer
|
||||
to point to the start of
|
||||
the receive buffer */
|
||||
ptr_data_read = USBD_CDC_ACM_ReceiveBuf; /* Correct read pointer to
|
||||
point to the start of the
|
||||
receive buffer */
|
||||
data_no_space_for_receive = 0; /* There is space for
|
||||
reception available */
|
||||
data_read_access = 0; /* Allow access to read data */
|
||||
}
|
||||
if (data_received_pending_pckts && /* If packets are pending */
|
||||
(!data_read_access) && /* and if not read active */
|
||||
(!data_no_space_for_receive)) { /* and if there is space to receive */
|
||||
data_read_access = 1; /* Disable access to read data */
|
||||
USBD_CDC_ACM_EP_BULKOUT_HandleData(); /* Handle received data */
|
||||
data_read_access = 0; /* Enable access to read data */
|
||||
if (ptr_data_received != ptr_data_read)
|
||||
USBD_CDC_ACM_DataReceived (ptr_data_received - ptr_data_read); /* Call
|
||||
received callback */
|
||||
}
|
||||
|
||||
if ((!data_send_access) && /* If send data is not being accessed */
|
||||
(!data_send_active) && /* and send is not active */
|
||||
(data_to_send_wr-data_to_send_rd) /* and if there is data to be sent */
|
||||
//&& ((control_line_state & 3) == 3) /* and if DTR and RTS is 1 */
|
||||
) {
|
||||
data_send_access = 1; /* Block access to send data */
|
||||
data_send_active = 1; /* Start data sending */
|
||||
USBD_CDC_ACM_EP_BULKIN_HandleData();/* Handle data to send */
|
||||
data_send_access = 0; /* Allow access to send data */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle Interrupt In Endpoint Events
|
||||
|
||||
The function handles Interrupt In endpoint events.
|
||||
|
||||
\param [in] event Type of event (USBD_EVT_IN - input event).
|
||||
*/
|
||||
|
||||
void USBD_CDC_ACM_EP_INTIN_Event (uint32_t event) {
|
||||
|
||||
/* Notification will be loadad aynchronously and sent automatically upon
|
||||
Interrupt IN token reception */
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle Bulk Out Endpoint Received Data
|
||||
|
||||
The function handles data received on the Bulk Out endpoint. It reads the
|
||||
received data to the receive intermediate buffer if there is enough space
|
||||
available.
|
||||
*/
|
||||
|
||||
static void USBD_CDC_ACM_EP_BULKOUT_HandleData () {
|
||||
int32_t len_received;
|
||||
|
||||
if ((usbd_cdc_acm_receivebuf_sz - (ptr_data_received - USBD_CDC_ACM_ReceiveBuf)) >= usbd_cdc_acm_maxpacketsize1[USBD_HighSpeed]) {
|
||||
/* If there is space for 1 max packet */
|
||||
/* Read received packet to receive buf*/
|
||||
len_received = USBD_ReadEP(usbd_cdc_acm_ep_bulkout, ptr_data_received);
|
||||
ptr_data_received += len_received; /* Correct pointer to received data */
|
||||
if (data_received_pending_pckts && /* If packet was pending */
|
||||
!data_receive_int_access) { /* and not interrupt access */
|
||||
data_received_pending_pckts--; /* Decrement pending packets number */
|
||||
}
|
||||
} else {
|
||||
data_no_space_for_receive = 1; /* There is no space in receive buffer
|
||||
for the newly received data */
|
||||
if (data_receive_int_access) { /* If this access is from interrupt
|
||||
function */
|
||||
data_received_pending_pckts++; /* then this is new unhandled packet */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle Bulk In Endpoint Data to Send
|
||||
|
||||
The function handles data to be sent on the Bulk In endpoint. It transmits
|
||||
pending data to be sent that is already in the send intermediate buffer,
|
||||
and it also sends Zero Length Packet if last packet sent was not a short
|
||||
packet.
|
||||
*/
|
||||
|
||||
static void USBD_CDC_ACM_EP_BULKIN_HandleData (void) {
|
||||
int32_t len_to_send;
|
||||
|
||||
if (!data_send_active) /* If sending is not active */
|
||||
return;
|
||||
|
||||
len_to_send = data_to_send_wr - data_to_send_rd; /* Num of data to send */
|
||||
|
||||
/* Check if sending is finished */
|
||||
if (!len_to_send && /* If all data was sent */
|
||||
!data_send_zlp) { /* and ZLP was sent if necessary also */
|
||||
data_send_active = 0; /* Sending not active any more */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if data needs to be sent */
|
||||
if (len_to_send || /* If there is data available do be
|
||||
sent */
|
||||
data_send_zlp) { /* or if ZLP should be sent */
|
||||
|
||||
if (((ptr_data_sent>ptr_data_to_send)|| /* If data before end of buf avail*/
|
||||
(len_to_send==usbd_cdc_acm_sendbuf_sz)) && /* or if buffer is full */
|
||||
((ptr_data_sent + len_to_send) > (USBD_CDC_ACM_SendBuf + usbd_cdc_acm_sendbuf_sz))) {
|
||||
/* and if available data wraps around
|
||||
the end of the send buffer */
|
||||
/* Correct bytes to send to data
|
||||
available untill end of send buf */
|
||||
len_to_send = USBD_CDC_ACM_SendBuf + usbd_cdc_acm_sendbuf_sz - ptr_data_sent;
|
||||
}
|
||||
|
||||
if (len_to_send > usbd_cdc_acm_maxpacketsize1[USBD_HighSpeed]) { /* If
|
||||
there is more data to be sent then
|
||||
can be sent in a single packet */
|
||||
/* Correct to send maximum pckt size */
|
||||
len_to_send = usbd_cdc_acm_maxpacketsize1[USBD_HighSpeed];
|
||||
}
|
||||
/* Send data */
|
||||
USBD_WriteEP(usbd_cdc_acm_ep_bulkin | 0x80, ptr_data_sent, len_to_send);
|
||||
|
||||
ptr_data_sent += len_to_send; /* Correct position of sent pointer */
|
||||
data_to_send_rd += len_to_send; /* Correct num of bytes left to send */
|
||||
if (ptr_data_sent == USBD_CDC_ACM_SendBuf + usbd_cdc_acm_sendbuf_sz)
|
||||
/* If pointer to sent data wraps */
|
||||
ptr_data_sent = USBD_CDC_ACM_SendBuf; /* Correct it to beginning of send
|
||||
buffer */
|
||||
if ((data_to_send_wr == data_to_send_rd) && /* If there are no more
|
||||
bytes available to be sent */
|
||||
(len_to_send == usbd_cdc_acm_maxpacketsize1[USBD_HighSpeed])) {
|
||||
/* If last packet size was same as
|
||||
maximum packet size */
|
||||
data_send_zlp = 1; /* ZLP packet should be sent */
|
||||
} else {
|
||||
data_send_zlp = 0; /* No ZLP packet should be sent */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle Bulk Out Endpoint Events
|
||||
|
||||
The function handles Bulk Out endpoint events. It calls
|
||||
USBD_CDC_ACM_EP_BULKOUT_HandleData function to handle received data
|
||||
unless data was being accessed in which case function just acknowledges
|
||||
that there is data to be handled later.
|
||||
|
||||
\param [in] event Type of event (USBD_EVT_OUT - output event).
|
||||
*/
|
||||
|
||||
void USBD_CDC_ACM_EP_BULKOUT_Event (uint32_t event) {
|
||||
|
||||
if (data_read_access) { /* If data is being accessed from
|
||||
read function */
|
||||
data_received_pending_pckts++; /* 1 more packet received and not
|
||||
handled */
|
||||
return;
|
||||
}
|
||||
|
||||
data_read_access = 1; /* Block access to read data */
|
||||
data_receive_int_access = 1; /* Read access from interrupt function*/
|
||||
USBD_CDC_ACM_EP_BULKOUT_HandleData ();/* Handle received data */
|
||||
data_receive_int_access = 0; /* Read access from interrupt func end*/
|
||||
data_read_access = 0; /* Allow access to read data */
|
||||
if (ptr_data_received != ptr_data_read)
|
||||
USBD_CDC_ACM_DataReceived (ptr_data_received - ptr_data_read); /* Call
|
||||
received callback */
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle Bulk In Endpoint Events
|
||||
|
||||
The function handles Bulk In endpoint events. It calls
|
||||
USBD_CDC_ACM_EP_BULKIN_HandleData function to handle send data
|
||||
unless data was being accessed in which case function just returns.
|
||||
|
||||
\param [in] event Type of event (USBD_EVT_IN - input event).
|
||||
*/
|
||||
|
||||
void USBD_CDC_ACM_EP_BULKIN_Event (uint32_t event) {
|
||||
|
||||
if (data_send_access /* If send data is being accessed */
|
||||
// ||((control_line_state & 3) != 3) /* or if DTR or RTS is 0 */
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
data_send_access = 1; /* Block access to send data */
|
||||
USBD_CDC_ACM_EP_BULKIN_HandleData (); /* Handle data to send */
|
||||
data_send_access = 0; /* Allow access to send data */
|
||||
}
|
||||
|
||||
|
||||
/** \brief Handle Bulk In/Out Endpoint Events
|
||||
|
||||
The function handles Bulk In/Out endpoint events. It is used for endpoints
|
||||
that do In and Out functionality on the same endpoint number. It dispatches
|
||||
events to appropriate In or Out event handlers.
|
||||
|
||||
\param [in] event Type of event (
|
||||
USBD_EVT_IN - input event,
|
||||
USBD_EVT_OUT - output event).
|
||||
*/
|
||||
|
||||
void USBD_CDC_ACM_EP_BULK_Event (uint32_t event) {
|
||||
if (event & USBD_EVT_OUT) {
|
||||
USBD_CDC_ACM_EP_BULKOUT_Event (event);
|
||||
}
|
||||
if (event & USBD_EVT_IN) {
|
||||
USBD_CDC_ACM_EP_BULKIN_Event (event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __RTX /* RTX tasks for handling events */
|
||||
|
||||
/** \brief Task Handling Interrupt In Endpoint Events
|
||||
|
||||
The task dispatches Interrupt In events to the Interrupt In handling
|
||||
function (USBD_CDC_ACM_EP_INTIN_Event).
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_CDC_ACM_EP_INTIN_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
USBD_CDC_ACM_EP_INTIN_Event (usbd_os_evt_get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Task Handling Bulk In Endpoint Events
|
||||
|
||||
The task dispatches Bulk In events to the Bulk In handling
|
||||
function (USBD_CDC_ACM_EP_BULKIN_Event).
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_CDC_ACM_EP_BULKIN_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
if (usbd_os_evt_get() & USBD_EVT_IN) {
|
||||
USBD_CDC_ACM_EP_BULKIN_Event (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Task Handling Bulk Out Endpoint Events
|
||||
|
||||
The task dispatches Bulk Out events to the Bulk Out handling
|
||||
function (USBD_CDC_ACM_EP_BULKOUT_Event).
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_CDC_ACM_EP_BULKOUT_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
if (usbd_os_evt_get() & USBD_EVT_OUT) {
|
||||
USBD_CDC_ACM_EP_BULKOUT_Event (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Task Handling Bulk In/Out Endpoint Events
|
||||
|
||||
The task dispatches Bulk In/Out events to the Bulk In/Out handling
|
||||
function (USBD_CDC_ACM_EP_BULK_Event).
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_CDC_ACM_EP_BULK_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
USBD_CDC_ACM_EP_BULK_Event (usbd_os_evt_get());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,878 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <RTL.h>
|
||||
#include <rl_usb.h>
|
||||
#include <string.h>
|
||||
#include "usb_for_lib.h"
|
||||
|
||||
U16 USBD_DeviceStatus;
|
||||
U8 USBD_DeviceAddress;
|
||||
U8 USBD_Configuration;
|
||||
U32 USBD_EndPointMask;
|
||||
U32 USBD_EndPointHalt;
|
||||
U32 USBD_EndPointStall; /* EP must stay stalled */
|
||||
U8 USBD_NumInterfaces;
|
||||
U8 USBD_HighSpeed;
|
||||
U8 USBD_ZLP;
|
||||
|
||||
USBD_EP_DATA USBD_EP0Data;
|
||||
USB_SETUP_PACKET USBD_SetupPacket;
|
||||
|
||||
#ifdef __RTX
|
||||
OS_TID USBD_RTX_DevTask; /* USB Device Task ID */
|
||||
OS_TID USBD_RTX_EPTask[16]; /* USB Endpoint Task ID's */
|
||||
OS_TID USBD_RTX_CoreTask; /* USB Core Task ID */
|
||||
#endif
|
||||
|
||||
|
||||
__asm void $$USBD$$version (void) {
|
||||
/* Export a version number symbol for a version control. */
|
||||
|
||||
EXPORT __RL_USBD_VER
|
||||
|
||||
__RL_USBD_VER EQU 0x470
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Init USB Device Core and Hardware
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void usbd_init (void) {
|
||||
USBD_HighSpeed = __FALSE;
|
||||
|
||||
usbd_class_init();
|
||||
USBD_RTX_TaskInit();
|
||||
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Connect/Disconnect Function
|
||||
* Called by the User to Connect/Disconnect USB Device
|
||||
* Parameters: con: Connect/Disconnect
|
||||
* Return Value: None
|
||||
*/
|
||||
void usbd_connect (BOOL con) {
|
||||
USBD_Connect (con);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reset USB Device Core
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void usbd_reset_core (void) {
|
||||
|
||||
USBD_DeviceStatus = usbd_power;
|
||||
USBD_DeviceAddress = 0;
|
||||
USBD_Configuration = 0;
|
||||
USBD_EndPointMask = 0x00010001;
|
||||
USBD_EndPointHalt = 0x00000000;
|
||||
USBD_EndPointStall = 0x00000000;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Configured Function
|
||||
* Called by the User to check id USB Device is configured
|
||||
* Parameters:
|
||||
* Return Value: Configurated state (FALSE = unconfigured, TRUE = configured)
|
||||
*/
|
||||
|
||||
BOOL usbd_configured (void) {
|
||||
|
||||
if (USBD_Configuration)
|
||||
return (__TRUE);
|
||||
|
||||
return (__FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Request - Setup Stage
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_SetupStage (void) {
|
||||
USBD_ReadEP(0x00, (U8 *)&USBD_SetupPacket);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Request - Data In Stage
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_DataInStage (void) {
|
||||
U32 cnt;
|
||||
|
||||
if (USBD_EP0Data.Count > usbd_max_packet0) {
|
||||
cnt = usbd_max_packet0;
|
||||
} else {
|
||||
cnt = USBD_EP0Data.Count;
|
||||
}
|
||||
if (!cnt) USBD_ZLP = 0;
|
||||
cnt = USBD_WriteEP(0x80, USBD_EP0Data.pData, cnt);
|
||||
USBD_EP0Data.pData += cnt;
|
||||
USBD_EP0Data.Count -= cnt;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Request - Data Out Stage
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_DataOutStage (void) {
|
||||
U32 cnt;
|
||||
|
||||
cnt = USBD_ReadEP(0x00, USBD_EP0Data.pData);
|
||||
USBD_EP0Data.pData += cnt;
|
||||
USBD_EP0Data.Count -= cnt;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Request - Status In Stage
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_StatusInStage (void) {
|
||||
USBD_WriteEP(0x80, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Request - Status Out Stage
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_StatusOutStage (void) {
|
||||
USBD_ReadEP(0x00, USBD_EP0Buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get Status USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqGetStatus (void) {
|
||||
U32 n, m;
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
USBD_EP0Data.pData = (U8 *)&USBD_DeviceStatus;
|
||||
break;
|
||||
case REQUEST_TO_INTERFACE:
|
||||
if ((USBD_Configuration != 0) && (USBD_SetupPacket.wIndexL < USBD_NumInterfaces)) {
|
||||
*((__packed U16 *)USBD_EP0Buf) = 0;
|
||||
USBD_EP0Data.pData = USBD_EP0Buf;
|
||||
} else {
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
case REQUEST_TO_ENDPOINT:
|
||||
n = USBD_SetupPacket.wIndexL & 0x8F;
|
||||
m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);
|
||||
if (((USBD_Configuration != 0) || ((n & 0x0F) == 0)) && (USBD_EndPointMask & m)) {
|
||||
*((__packed U16 *)USBD_EP0Buf) = (USBD_EndPointHalt & m) ? 1 : 0;
|
||||
USBD_EP0Data.pData = USBD_EP0Buf;
|
||||
} else {
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set/Clear Feature USB Device Request
|
||||
* Parameters: sc: 0 - Clear, 1 - Set
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqSetClrFeature (U32 sc) {
|
||||
U32 n, m;
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
if (USBD_SetupPacket.wValue == USB_FEATURE_REMOTE_WAKEUP) {
|
||||
if (sc) {
|
||||
USBD_WakeUpCfg(__TRUE);
|
||||
USBD_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP;
|
||||
} else {
|
||||
USBD_WakeUpCfg(__FALSE);
|
||||
USBD_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP;
|
||||
}
|
||||
} else {
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
case REQUEST_TO_INTERFACE:
|
||||
return (__FALSE);
|
||||
case REQUEST_TO_ENDPOINT:
|
||||
n = USBD_SetupPacket.wIndexL & 0x8F;
|
||||
m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);
|
||||
if ((USBD_Configuration != 0) && ((n & 0x0F) != 0) && (USBD_EndPointMask & m)) {
|
||||
if (USBD_SetupPacket.wValue == USB_FEATURE_ENDPOINT_STALL) {
|
||||
if (sc) {
|
||||
USBD_SetStallEP(n);
|
||||
USBD_EndPointHalt |= m;
|
||||
} else {
|
||||
if ((USBD_EndPointStall & m) != 0) {
|
||||
return (__TRUE);
|
||||
}
|
||||
USBD_ClrStallEP(n);
|
||||
USBD_ReqClrFeature_MSC (n);
|
||||
USBD_EndPointHalt &= ~m;
|
||||
}
|
||||
} else {
|
||||
return (__FALSE);
|
||||
}
|
||||
} else {
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set Address USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
__inline BOOL USBD_ReqSetAddress (void) {
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
USBD_DeviceAddress = 0x80 | USBD_SetupPacket.wValueL;
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get Descriptor USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqGetDescriptor (void) {
|
||||
U8 *pD;
|
||||
U32 len, n;
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
switch (USBD_SetupPacket.wValueH) {
|
||||
case USB_DEVICE_DESCRIPTOR_TYPE:
|
||||
USBD_EP0Data.pData = (U8 *)USBD_DeviceDescriptor;
|
||||
len = USB_DEVICE_DESC_SIZE;
|
||||
break;
|
||||
case USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE:
|
||||
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
|
||||
return (__FALSE); /* High speed request but high-speed not enabled */
|
||||
}
|
||||
if (USBD_HighSpeed == __FALSE) {
|
||||
USBD_EP0Data.pData = (U8 *)USBD_DeviceQualifier;
|
||||
} else {
|
||||
USBD_EP0Data.pData = (U8 *)USBD_DeviceQualifier_HS;
|
||||
}
|
||||
len = USB_DEVICE_QUALI_SIZE;
|
||||
break;
|
||||
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
|
||||
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
|
||||
return (__FALSE); /* High speed request but high-speed not enabled */
|
||||
}
|
||||
if (USBD_HighSpeed == __FALSE) {
|
||||
pD = (U8 *)USBD_ConfigDescriptor;
|
||||
} else {
|
||||
pD = (U8 *)USBD_ConfigDescriptor_HS;
|
||||
}
|
||||
for (n = 0; n != USBD_SetupPacket.wValueL; n++) {
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) {
|
||||
pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
|
||||
}
|
||||
}
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) {
|
||||
return (__FALSE);
|
||||
}
|
||||
USBD_EP0Data.pData = pD;
|
||||
len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
|
||||
break;
|
||||
case USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE:
|
||||
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
|
||||
return (__FALSE); /* High speed request but high-speed not enabled */
|
||||
}
|
||||
if (USBD_HighSpeed == __FALSE) {
|
||||
pD = (U8 *)USBD_OtherSpeedConfigDescriptor;
|
||||
} else {
|
||||
pD = (U8 *)USBD_OtherSpeedConfigDescriptor_HS;
|
||||
}
|
||||
for (n = 0; n != USBD_SetupPacket.wValueL; n++) {
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) {
|
||||
pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
|
||||
}
|
||||
}
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) {
|
||||
return (__FALSE);
|
||||
}
|
||||
USBD_EP0Data.pData = pD;
|
||||
len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
|
||||
break;
|
||||
case USB_STRING_DESCRIPTOR_TYPE:
|
||||
pD = (U8 *)USBD_StringDescriptor;
|
||||
|
||||
#if 0
|
||||
// added by sam to send unique id string descriptor
|
||||
if (USBD_SetupPacket.wValueL == 3) {
|
||||
USBD_EP0Data.pData = get_uid_string_interface();
|
||||
len = get_len_string_interface();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (n = 0; n != USBD_SetupPacket.wValueL; n++) {
|
||||
if (((USB_STRING_DESCRIPTOR *)pD)->bLength != 0) {
|
||||
pD += ((USB_STRING_DESCRIPTOR *)pD)->bLength;
|
||||
}
|
||||
}
|
||||
if (((USB_STRING_DESCRIPTOR *)pD)->bLength == 0) {
|
||||
return (__FALSE);
|
||||
}
|
||||
USBD_EP0Data.pData = pD;
|
||||
len = ((USB_STRING_DESCRIPTOR *)pD)->bLength;
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
case REQUEST_TO_INTERFACE:
|
||||
if (!USBD_ReqGetDescriptor_HID(&pD, &len))
|
||||
return (__FALSE);
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
|
||||
if (USBD_EP0Data.Count > len) {
|
||||
USBD_EP0Data.Count = len;
|
||||
if (!(USBD_EP0Data.Count & (usbd_max_packet0 - 1))) USBD_ZLP = 1;
|
||||
}
|
||||
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get Configuration USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqGetConfiguration (void) {
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
USBD_EP0Data.pData = &USBD_Configuration;
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set Configuration USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqSetConfiguration (void) {
|
||||
USB_CONFIGURATION_DESCRIPTOR *pD;
|
||||
U32 alt = 0;
|
||||
U32 n, m;
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
|
||||
if (USBD_SetupPacket.wValueL) {
|
||||
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
|
||||
return (__FALSE); /* High speed request but high-speed not enabled */
|
||||
}
|
||||
if (USBD_HighSpeed == __FALSE) {
|
||||
pD = (USB_CONFIGURATION_DESCRIPTOR *)USBD_ConfigDescriptor;
|
||||
} else {
|
||||
pD = (USB_CONFIGURATION_DESCRIPTOR *)USBD_ConfigDescriptor_HS;
|
||||
}
|
||||
while (pD->bLength) {
|
||||
switch (pD->bDescriptorType) {
|
||||
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == USBD_SetupPacket.wValueL) {
|
||||
USBD_Configuration = USBD_SetupPacket.wValueL;
|
||||
USBD_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces;
|
||||
for (n = 0; n < usbd_if_num; n++) {
|
||||
USBD_AltSetting[n] = 0;
|
||||
}
|
||||
for (n = 1; n < 16; n++) {
|
||||
if (USBD_EndPointMask & (1 << n)) {
|
||||
USBD_DisableEP(n);
|
||||
}
|
||||
if (USBD_EndPointMask & ((1 << 16) << n)) {
|
||||
USBD_DisableEP(n | 0x80);
|
||||
}
|
||||
}
|
||||
USBD_EndPointMask = 0x00010001;
|
||||
USBD_EndPointHalt = 0x00000000;
|
||||
USBD_EndPointStall= 0x00000000;
|
||||
USBD_Configure(__TRUE);
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_POWERED_MASK) {
|
||||
USBD_DeviceStatus |= USB_GETSTATUS_SELF_POWERED;
|
||||
} else {
|
||||
USBD_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED;
|
||||
}
|
||||
} else {
|
||||
pD = (USB_CONFIGURATION_DESCRIPTOR *)((U8 *)pD + ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case USB_INTERFACE_DESCRIPTOR_TYPE:
|
||||
alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;
|
||||
break;
|
||||
case USB_ENDPOINT_DESCRIPTOR_TYPE:
|
||||
if (alt == 0) {
|
||||
n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;
|
||||
m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);
|
||||
USBD_EndPointMask |= m;
|
||||
USBD_ConfigEP((void *)pD);
|
||||
USBD_EnableEP(n);
|
||||
USBD_ResetEP(n);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pD = (USB_CONFIGURATION_DESCRIPTOR *)((U8 *)pD + pD->bLength);
|
||||
}
|
||||
}
|
||||
else {
|
||||
USBD_Configuration = 0;
|
||||
for (n = 1; n < 16; n++) {
|
||||
if (USBD_EndPointMask & (1 << n)) {
|
||||
USBD_DisableEP(n);
|
||||
}
|
||||
if (USBD_EndPointMask & ((1 << 16) << n)) {
|
||||
USBD_DisableEP(n | 0x80);
|
||||
}
|
||||
}
|
||||
USBD_EndPointMask = 0x00010001;
|
||||
USBD_EndPointHalt = 0x00000000;
|
||||
USBD_EndPointStall = 0x00000000;
|
||||
USBD_Configure(__FALSE);
|
||||
}
|
||||
|
||||
if (USBD_Configuration != USBD_SetupPacket.wValueL) {
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get Interface USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqGetInterface (void) {
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_INTERFACE:
|
||||
if ((USBD_Configuration != 0) && (USBD_SetupPacket.wIndexL < USBD_NumInterfaces)) {
|
||||
USBD_EP0Data.pData = USBD_AltSetting + USBD_SetupPacket.wIndexL;
|
||||
} else {
|
||||
return (__FALSE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set Interface USB Device Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_ReqSetInterface (void) {
|
||||
USB_COMMON_DESCRIPTOR *pD;
|
||||
U32 ifn = 0, alt = 0, old = 0, msk = 0;
|
||||
U32 n, m;
|
||||
BOOL set;
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_INTERFACE:
|
||||
if (USBD_Configuration == 0) return (__FALSE);
|
||||
set = __FALSE;
|
||||
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
|
||||
return (__FALSE); /* High speed request but high-speed not enabled */
|
||||
}
|
||||
if (USBD_HighSpeed == __FALSE) {
|
||||
pD = (USB_COMMON_DESCRIPTOR *)USBD_ConfigDescriptor;
|
||||
} else {
|
||||
pD = (USB_COMMON_DESCRIPTOR *)USBD_ConfigDescriptor_HS;
|
||||
}
|
||||
while (pD->bLength) {
|
||||
switch (pD->bDescriptorType) {
|
||||
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
|
||||
if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != USBD_Configuration) {
|
||||
pD = (USB_COMMON_DESCRIPTOR *)((U8 *)pD+((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case USB_INTERFACE_DESCRIPTOR_TYPE:
|
||||
ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber;
|
||||
alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting;
|
||||
msk = 0;
|
||||
if ((ifn == USBD_SetupPacket.wIndexL) && (alt == USBD_SetupPacket.wValueL)) {
|
||||
set = __TRUE;
|
||||
old = USBD_AltSetting[ifn];
|
||||
USBD_AltSetting[ifn] = (U8)alt;
|
||||
}
|
||||
break;
|
||||
case USB_ENDPOINT_DESCRIPTOR_TYPE:
|
||||
if (ifn == USBD_SetupPacket.wIndexL) {
|
||||
n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F;
|
||||
m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n);
|
||||
if (alt == USBD_SetupPacket.wValueL) {
|
||||
USBD_EndPointMask |= m;
|
||||
USBD_EndPointHalt &= ~m;
|
||||
USBD_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD);
|
||||
USBD_EnableEP(n);
|
||||
USBD_ResetEP(n);
|
||||
msk |= m;
|
||||
}
|
||||
else if ((alt == old) && ((msk & m) == 0)) {
|
||||
USBD_EndPointMask &= ~m;
|
||||
USBD_EndPointHalt &= ~m;
|
||||
USBD_DisableEP(n);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
pD = (USB_COMMON_DESCRIPTOR *)((U8 *)pD + pD->bLength);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
|
||||
return (set);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 Event Callback
|
||||
* Parameters: event
|
||||
* Return Value: none
|
||||
*/
|
||||
|
||||
void USBD_EndPoint0 (U32 event) {
|
||||
|
||||
if (event & USBD_EVT_SETUP) {
|
||||
USBD_SetupStage();
|
||||
USBD_DirCtrlEP(USBD_SetupPacket.bmRequestType.Dir);
|
||||
USBD_EP0Data.Count = USBD_SetupPacket.wLength; /* Number of bytes to transfer */
|
||||
|
||||
switch (USBD_SetupPacket.bmRequestType.Type) {
|
||||
|
||||
case REQUEST_STANDARD:
|
||||
switch (USBD_SetupPacket.bRequest) {
|
||||
|
||||
case USB_REQUEST_GET_STATUS:
|
||||
if (!USBD_ReqGetStatus()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_DataInStage();
|
||||
break;
|
||||
|
||||
case USB_REQUEST_CLEAR_FEATURE:
|
||||
if (!USBD_ReqSetClrFeature(0)) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_StatusInStage();
|
||||
#ifdef __RTX
|
||||
if (__rtx) {
|
||||
if (USBD_RTX_CoreTask) {
|
||||
usbd_os_evt_set(USBD_EVT_CLR_FEATURE, USBD_RTX_CoreTask);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (USBD_P_Feature_Event) {
|
||||
USBD_P_Feature_Event();
|
||||
}
|
||||
#ifdef __RTX
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_FEATURE:
|
||||
if (!USBD_ReqSetClrFeature(1)) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_StatusInStage();
|
||||
#ifdef __RTX
|
||||
if (__rtx) {
|
||||
if (USBD_RTX_CoreTask) {
|
||||
usbd_os_evt_set(USBD_EVT_SET_FEATURE, USBD_RTX_CoreTask);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (USBD_P_Feature_Event) {
|
||||
USBD_P_Feature_Event();
|
||||
}
|
||||
#ifdef __RTX
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_ADDRESS:
|
||||
if (!USBD_ReqSetAddress()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_SetAddress(USBD_DeviceAddress & 0x7F, 1);
|
||||
USBD_StatusInStage();
|
||||
break;
|
||||
|
||||
case USB_REQUEST_GET_DESCRIPTOR:
|
||||
if (!USBD_ReqGetDescriptor()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_DataInStage();
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_DESCRIPTOR:
|
||||
goto stall;
|
||||
|
||||
case USB_REQUEST_GET_CONFIGURATION:
|
||||
if (!USBD_ReqGetConfiguration()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_DataInStage();
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_CONFIGURATION:
|
||||
if (!USBD_ReqSetConfiguration()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_StatusInStage();
|
||||
#ifdef __RTX
|
||||
if (__rtx) {
|
||||
if (USBD_RTX_CoreTask) {
|
||||
usbd_os_evt_set(USBD_EVT_SET_CFG, USBD_RTX_CoreTask);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (USBD_P_Configure_Event) {
|
||||
USBD_P_Configure_Event();
|
||||
}
|
||||
#ifdef __RTX
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case USB_REQUEST_GET_INTERFACE:
|
||||
if (!USBD_ReqGetInterface()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_DataInStage();
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_INTERFACE:
|
||||
if (!USBD_ReqSetInterface()) {
|
||||
goto stall;
|
||||
}
|
||||
USBD_StatusInStage();
|
||||
#ifdef __RTX
|
||||
if (__rtx) {
|
||||
if (USBD_RTX_CoreTask) {
|
||||
usbd_os_evt_set(USBD_EVT_SET_IF, USBD_RTX_CoreTask);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (USBD_P_Interface_Event) {
|
||||
USBD_P_Interface_Event();
|
||||
}
|
||||
#ifdef __RTX
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
goto stall;
|
||||
}
|
||||
break; /* end case REQUEST_STANDARD */
|
||||
|
||||
case REQUEST_CLASS:
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
|
||||
case REQUEST_TO_DEVICE:
|
||||
goto stall; /* not supported */
|
||||
|
||||
case REQUEST_TO_INTERFACE:
|
||||
if (USBD_EndPoint0_Setup_HID_ReqToIF())
|
||||
goto setup_class_ok;
|
||||
if (USBD_EndPoint0_Setup_MSC_ReqToIF())
|
||||
goto setup_class_ok;
|
||||
if (USBD_EndPoint0_Setup_CDC_ReqToIF())
|
||||
goto setup_class_ok;
|
||||
goto stall; /* not supported */
|
||||
/* end case REQUEST_TO_INTERFACE */
|
||||
|
||||
case REQUEST_TO_ENDPOINT:
|
||||
goto stall;
|
||||
/* end case REQUEST_TO_ENDPOINT */
|
||||
|
||||
default:
|
||||
goto stall;
|
||||
}
|
||||
setup_class_ok: /* request finished successfully */
|
||||
break; /* end case REQUEST_CLASS */
|
||||
|
||||
default:
|
||||
stall: if ((USBD_SetupPacket.bmRequestType.Dir == REQUEST_HOST_TO_DEVICE) &&
|
||||
(USBD_SetupPacket.wLength != 0)) {
|
||||
USBD_SetStallEP(0x00);
|
||||
} else {
|
||||
USBD_SetStallEP(0x80);
|
||||
}
|
||||
USBD_EP0Data.Count = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & USBD_EVT_OUT) {
|
||||
if (USBD_SetupPacket.bmRequestType.Dir == REQUEST_HOST_TO_DEVICE) {
|
||||
if (USBD_EP0Data.Count) { /* still data to receive ? */
|
||||
USBD_DataOutStage(); /* receive data */
|
||||
if (USBD_EP0Data.Count == 0) { /* data complete ? */
|
||||
switch (USBD_SetupPacket.bmRequestType.Type) {
|
||||
|
||||
case REQUEST_STANDARD:
|
||||
goto stall_i; /* not supported */
|
||||
|
||||
case REQUEST_CLASS:
|
||||
switch (USBD_SetupPacket.bmRequestType.Recipient) {
|
||||
case REQUEST_TO_DEVICE:
|
||||
goto stall_i; /* not supported */
|
||||
|
||||
case REQUEST_TO_INTERFACE:
|
||||
if (USBD_EndPoint0_Out_HID_ReqToIF())
|
||||
goto out_class_ok;
|
||||
if (USBD_EndPoint0_Out_CDC_ReqToIF())
|
||||
goto out_class_ok;
|
||||
goto stall_i;
|
||||
/* end case REQUEST_TO_INTERFACE */
|
||||
|
||||
case REQUEST_TO_ENDPOINT:
|
||||
goto stall_i;
|
||||
/* end case REQUEST_TO_ENDPOINT */
|
||||
|
||||
default:
|
||||
goto stall_i;
|
||||
}
|
||||
out_class_ok: /* request finished successfully */
|
||||
break; /* end case REQUEST_CLASS */
|
||||
|
||||
default:
|
||||
stall_i: USBD_SetStallEP(0x80);
|
||||
USBD_EP0Data.Count = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
USBD_StatusOutStage(); /* receive Acknowledge */
|
||||
}
|
||||
} /* end USBD_EVT_OUT */
|
||||
|
||||
if (event & USBD_EVT_IN) {
|
||||
if (USBD_SetupPacket.bmRequestType.Dir == REQUEST_DEVICE_TO_HOST) {
|
||||
if (USBD_EP0Data.Count || USBD_ZLP) USBD_DataInStage(); /* send data */
|
||||
} else {
|
||||
if (USBD_DeviceAddress & 0x80) {
|
||||
USBD_DeviceAddress &= 0x7F;
|
||||
USBD_SetAddress(USBD_DeviceAddress, 0);
|
||||
}
|
||||
}
|
||||
} /* end USBD_EVT_IN */
|
||||
|
||||
if (event & USBD_EVT_OUT_STALL) {
|
||||
USBD_ClrStallEP(0x00);
|
||||
}
|
||||
|
||||
if (event & USBD_EVT_IN_STALL) {
|
||||
USBD_ClrStallEP(0x80);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 RTX Task
|
||||
* Parameters: none
|
||||
* Return Value: none
|
||||
*/
|
||||
|
||||
#ifdef __RTX
|
||||
__task void USBD_RTX_EndPoint0 (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
USBD_EndPoint0 (usbd_os_evt_get());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <RTL.h>
|
||||
#include <rl_usb.h>
|
||||
#include <string.h>
|
||||
#include "usb_for_lib.h"
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 Event Callback - CDC specific handling (Setup Request To Interface)
|
||||
* Parameters: none
|
||||
* Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported
|
||||
*/
|
||||
|
||||
__weak BOOL USBD_EndPoint0_Setup_CDC_ReqToIF (void) {
|
||||
if ((USBD_SetupPacket.wIndexL == usbd_cdc_acm_cif_num) || /* IF number correct? */
|
||||
(USBD_SetupPacket.wIndexL == usbd_cdc_acm_dif_num)) {
|
||||
switch (USBD_SetupPacket.bRequest) {
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* data to be received, see USBD_EVT_OUT */
|
||||
return (__TRUE);
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
if (USBD_CDC_ACM_GetEncapsulatedResponse()) {
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
|
||||
USBD_DataInStage(); /* send requested data */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* data to be received, see USBD_EVT_OUT */
|
||||
return (__TRUE);
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
if (USBD_CDC_ACM_GetCommFeature(USBD_SetupPacket.wValue)) {
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
|
||||
USBD_DataInStage(); /* send requested data */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
if (USBD_CDC_ACM_ClearCommFeature(USBD_SetupPacket.wValue)) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_SET_LINE_CODING:
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* data to be received, see USBD_EVT_OUT */
|
||||
return (__TRUE);
|
||||
case CDC_GET_LINE_CODING:
|
||||
if (USBD_CDC_ACM_GetLineCoding()) {
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
|
||||
USBD_DataInStage(); /* send requested data */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
if (USBD_CDC_ACM_SetControlLineState(USBD_SetupPacket.wValue)) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_SEND_BREAK:
|
||||
if (USBD_CDC_ACM_SendBreak(USBD_SetupPacket.wValue)) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (__FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 Event Callback - CDC specific handling (Out Request To Interface)
|
||||
* Parameters: none
|
||||
* Return Value: TRUE - Out class request ok, FALSE - Out class request not supported
|
||||
*/
|
||||
|
||||
__weak BOOL USBD_EndPoint0_Out_CDC_ReqToIF (void) {
|
||||
if ((USBD_SetupPacket.wIndexL == usbd_cdc_acm_cif_num) || /* IF number correct? */
|
||||
(USBD_SetupPacket.wIndexL == usbd_cdc_acm_dif_num)) {
|
||||
switch (USBD_SetupPacket.bRequest) {
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
if (USBD_CDC_ACM_SendEncapsulatedCommand()) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
if (USBD_CDC_ACM_SetCommFeature(USBD_SetupPacket.wValue)) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case CDC_SET_LINE_CODING:
|
||||
if (USBD_CDC_ACM_SetLineCoding()) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (__FALSE);
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <RTL.h>
|
||||
#include <rl_usb.h>
|
||||
#include <string.h>
|
||||
#include "usb_for_lib.h"
|
||||
|
||||
|
||||
/*
|
||||
* Get Descriptor USB Device Request - HID specific handling
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
__weak BOOL USBD_ReqGetDescriptor_HID (U8 **pD, U32 *len) {
|
||||
switch (USBD_SetupPacket.wValueH) {
|
||||
case HID_HID_DESCRIPTOR_TYPE:
|
||||
if (USBD_SetupPacket.wIndexL != usbd_hid_if_num) {
|
||||
return (__FALSE); /* Only Single HID Interface is supported */
|
||||
}
|
||||
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
|
||||
return (__FALSE); /* High speed request but high-speed not enabled */
|
||||
}
|
||||
if (USBD_HighSpeed == __FALSE) {
|
||||
*pD = (U8 *)USBD_ConfigDescriptor;
|
||||
} else {
|
||||
*pD = (U8 *)USBD_ConfigDescriptor_HS;
|
||||
}
|
||||
USBD_EP0Data.pData = *pD + USBD_HID_DescriptorOffset;
|
||||
*len = USB_HID_DESC_SIZE;
|
||||
break;
|
||||
case HID_REPORT_DESCRIPTOR_TYPE:
|
||||
if (USBD_SetupPacket.wIndexL != usbd_hid_if_num) {
|
||||
return (__FALSE); /* Only Single HID Interface is supported */
|
||||
}
|
||||
USBD_EP0Data.pData = (U8 *)USBD_HID_ReportDescriptor;
|
||||
*len = USBD_HID_ReportDescriptorSize;
|
||||
break;
|
||||
case HID_PHYSICAL_DESCRIPTOR_TYPE:
|
||||
return (__FALSE); /* HID Physical Descriptor is not supported */
|
||||
default:
|
||||
return (__FALSE);
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 Event Callback - HID specific handling (Setup Request To Interface)
|
||||
* Parameters: none
|
||||
* Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported
|
||||
*/
|
||||
|
||||
__weak BOOL USBD_EndPoint0_Setup_HID_ReqToIF (void) {
|
||||
if (USBD_SetupPacket.wIndexL == usbd_hid_if_num) { /* IF number correct? */
|
||||
switch (USBD_SetupPacket.bRequest) {
|
||||
case HID_REQUEST_GET_REPORT:
|
||||
if (USBD_HID_GetReport()) {
|
||||
if (USBD_SetupPacket.wValueH == HID_REPORT_INPUT) {
|
||||
USBD_EP0Data.pData = &USBD_HID_InReport[1]; /* point to data to be sent (skip ReportID) */
|
||||
}
|
||||
else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) {
|
||||
USBD_EP0Data.pData = &USBD_HID_FeatReport[1]; /* point to data to be sent (skip ReportID) */
|
||||
}
|
||||
USBD_DataInStage(); /* send requested data */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case HID_REQUEST_SET_REPORT:
|
||||
if (USBD_SetupPacket.wValueH == HID_REPORT_OUTPUT) {
|
||||
USBD_EP0Data.pData = &USBD_HID_OutReport[1]; /* out data to be received (skip ReportID) */
|
||||
}
|
||||
else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) {
|
||||
USBD_EP0Data.pData = &USBD_HID_FeatReport[1]; /* out data to be received (skip ReportID) */
|
||||
}
|
||||
return (__TRUE);
|
||||
case HID_REQUEST_GET_IDLE:
|
||||
if (USBD_HID_GetIdle()) {
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
|
||||
USBD_DataInStage(); /* send requested data */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case HID_REQUEST_SET_IDLE:
|
||||
if (USBD_HID_SetIdle()) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case HID_REQUEST_GET_PROTOCOL:
|
||||
if (USBD_HID_GetProtocol()) {
|
||||
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
|
||||
USBD_DataInStage(); /* send requested data */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
case HID_REQUEST_SET_PROTOCOL:
|
||||
if (USBD_HID_SetProtocol()) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (__FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 Event Callback - HID specific handling (Out Request To Interface)
|
||||
* Parameters: none
|
||||
* Return Value: TRUE - Out class request ok, FALSE - Out class request not supported
|
||||
*/
|
||||
|
||||
__weak BOOL USBD_EndPoint0_Out_HID_ReqToIF (void) {
|
||||
if (USBD_SetupPacket.wIndexL == usbd_hid_if_num) { /* IF number correct? */
|
||||
switch (USBD_SetupPacket.bRequest) {
|
||||
case HID_REQUEST_SET_REPORT:
|
||||
if (USBD_HID_SetReport()) {
|
||||
USBD_StatusInStage(); /* send Acknowledge */
|
||||
return (__TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (__FALSE);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <RTL.h>
|
||||
#include <rl_usb.h>
|
||||
#include <string.h>
|
||||
#include "usb_for_lib.h"
|
||||
|
||||
|
||||
/*
|
||||
* Clear Feature USB Device Request - MSC specific handling
|
||||
* Parameters: EPNum: Endpoint number
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
__weak void USBD_ReqClrFeature_MSC (U32 EPNum) {
|
||||
USBD_MSC_ClrStallEP (EPNum);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device Endpoint 0 Event Callback - MSC specific handling (Setup Request To Interface)
|
||||
* Parameters: none
|
||||
* Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported
|
||||
*/
|
||||
|
||||
__weak BOOL USBD_EndPoint0_Setup_MSC_ReqToIF (void) {
|
||||
if (USBD_SetupPacket.wIndexL == usbd_msc_if_num) { /* IF number correct? */
|
||||
switch (USBD_SetupPacket.bRequest) {
|
||||
case MSC_REQUEST_RESET:
|
||||
if ((USBD_SetupPacket.wValue == 0) && /* RESET with invalid parameters -> STALL */
|
||||
(USBD_SetupPacket.wLength == 0)) {
|
||||
if (USBD_MSC_Reset()) {
|
||||
USBD_StatusInStage();
|
||||
return (__TRUE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MSC_REQUEST_GET_MAX_LUN:
|
||||
if ((USBD_SetupPacket.wValue == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */
|
||||
(USBD_SetupPacket.wLength == 1)) {
|
||||
if (USBD_MSC_GetMaxLUN()) {
|
||||
USBD_EP0Data.pData = USBD_EP0Buf;
|
||||
USBD_DataInStage();
|
||||
return (__TRUE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (__FALSE);
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
/* CMSIS-DAP Interface Firmware
|
||||
* Copyright (c) 2009-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <RTL.h>
|
||||
#include <rl_usb.h>
|
||||
#include <string.h>
|
||||
#include "usb_for_lib.h"
|
||||
|
||||
|
||||
U8 USBD_HID_Protocol;
|
||||
|
||||
BOOL DataOutAsyncReq;
|
||||
U32 DataOutUpdateReqMask;
|
||||
U8 *ptrDataOut;
|
||||
volatile U16 DataOutToSendLen;
|
||||
U16 DataOutSentLen;
|
||||
BOOL DataOutEndWithShortPacket;
|
||||
|
||||
U8 *ptrDataIn;
|
||||
U16 DataInReceLen;
|
||||
|
||||
U8 *ptrDataFeat;
|
||||
U16 DataFeatReceLen;
|
||||
|
||||
|
||||
/* Dummy Weak Functions that need to be provided by user */
|
||||
__weak void usbd_hid_init (void) {};
|
||||
__weak int usbd_hid_get_report (U8 rtype, U8 rid, U8 *buf, U8 req) { return (0); };
|
||||
__weak void usbd_hid_set_report (U8 rtype, U8 rid, U8 *buf, int len, U8 req) {};
|
||||
__weak U8 usbd_hid_get_protocol (void) { return (0); };
|
||||
__weak void usbd_hid_set_protocol (U8 protocol) {};
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Get Report Request Callback
|
||||
* Called automatically on USB Device HID Get Report Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_HID_GetReport (void) {
|
||||
U8 *ptr_buf = 0;
|
||||
|
||||
/* Report Type = USBD_SetupPacket.wValueH */
|
||||
/* Report ID = USBD_SetupPacket.wValueL */
|
||||
/* Report Length = USBD_SetupPacket.wLength */
|
||||
switch (USBD_SetupPacket.wValueH) {
|
||||
case HID_REPORT_INPUT:
|
||||
ptr_buf = &USBD_HID_InReport[1];
|
||||
break;
|
||||
case HID_REPORT_OUTPUT:
|
||||
return (__FALSE); /* Not Supported */
|
||||
case HID_REPORT_FEATURE:
|
||||
ptr_buf = &USBD_HID_FeatReport[1];
|
||||
break;
|
||||
}
|
||||
usbd_hid_get_report (USBD_SetupPacket.wValueH, USBD_SetupPacket.wValueL, ptr_buf, USBD_HID_REQ_EP_CTRL);
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Set Report Request Callback
|
||||
* Called automatically on USB Device HID Set Report Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_HID_SetReport (void) {
|
||||
U8 *ptr_buf = 0;
|
||||
|
||||
/* Report Type = USBD_SetupPacket.wValueH */
|
||||
/* Report ID = USBD_SetupPacket.wValueL */
|
||||
/* Report Length = USBD_SetupPacket.wLength */
|
||||
switch (USBD_SetupPacket.wValueH) {
|
||||
case HID_REPORT_INPUT:
|
||||
return (__FALSE); /* Not Supported */
|
||||
case HID_REPORT_OUTPUT:
|
||||
ptr_buf = &USBD_HID_OutReport[1];
|
||||
break;
|
||||
case HID_REPORT_FEATURE:
|
||||
ptr_buf = &USBD_HID_FeatReport[1];
|
||||
break;
|
||||
}
|
||||
usbd_hid_set_report (USBD_SetupPacket.wValueH, USBD_SetupPacket.wValueL, ptr_buf, USBD_SetupPacket.wLength, USBD_HID_REQ_EP_CTRL);
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Get Idle Request Callback
|
||||
* Called automatically on USB Device HID Get Idle Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_HID_GetIdle (void) {
|
||||
|
||||
USBD_EP0Buf[0] = USBD_HID_IdleSet[USBD_SetupPacket.wValueL];
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Set Idle Request Callback
|
||||
* Called automatically on USB Device HID Set Idle Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_HID_SetIdle (void) {
|
||||
U8 i;
|
||||
|
||||
if (USBD_SetupPacket.wValueL) { /* If > 0 Report ID specified */
|
||||
USBD_HID_IdleSet[USBD_SetupPacket.wValueL-1] = USBD_SetupPacket.wValueH;
|
||||
} else { /* If == 0 all reports */
|
||||
for (i = 0; i < usbd_hid_inreport_num; i++)
|
||||
USBD_HID_IdleSet[i] = USBD_SetupPacket.wValueH;
|
||||
}
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Get Protocol Request Callback
|
||||
* Called automatically on USB Device HID Get Protocol Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_HID_GetProtocol (void) {
|
||||
|
||||
USBD_EP0Buf[0] = usbd_hid_get_protocol ();
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Set Protocol Request Callback
|
||||
* Called automatically on USB Device HID Set Protocol Request
|
||||
* Parameters: None
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL USBD_HID_SetProtocol (void) {
|
||||
|
||||
usbd_hid_set_protocol (USBD_SetupPacket.wValueL);
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Interrupt In Endpoint Event Callback
|
||||
* Parameters: event: not used (just for compatibility)
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_HID_EP_INTIN_Event (U32 event) {
|
||||
U8 i;
|
||||
U16 bytes_to_send;
|
||||
|
||||
/* Check if sending is finished */
|
||||
if ((DataOutSentLen >= DataOutToSendLen) &&
|
||||
!DataOutEndWithShortPacket) { /* If all sent and short packet also */
|
||||
ptrDataOut = NULL;
|
||||
DataOutSentLen = 0;
|
||||
DataOutToSendLen = usbd_hid_get_report (HID_REPORT_INPUT, USBD_HID_InReport[0], &USBD_HID_InReport[1], USBD_HID_REQ_EP_INT);
|
||||
if (DataOutToSendLen) { /* If new send should be started */
|
||||
ptrDataOut = USBD_HID_InReport;
|
||||
if (usbd_hid_inreport_num <= 1) /* If only in 1 report skip ReportID */
|
||||
ptrDataOut++;
|
||||
else /* If more in reports, send ReportID */
|
||||
DataOutToSendLen++;
|
||||
}
|
||||
}
|
||||
/* Check if new data out sending should be started */
|
||||
if(!DataOutToSendLen) { /* If send not in progress */
|
||||
if (DataOutAsyncReq) { /* If asynchronous send requested */
|
||||
DataOutAsyncReq = __FALSE;
|
||||
}
|
||||
else if (DataOutUpdateReqMask) { /* If update requested */
|
||||
if (usbd_hid_inreport_num <= 1) { /* If only one in report in system */
|
||||
if (DataOutUpdateReqMask) {
|
||||
USBD_HID_InReport[0] = 0; /* ReportID = 0 */
|
||||
DataOutSentLen = 0;
|
||||
DataOutToSendLen = usbd_hid_get_report (HID_REPORT_INPUT, 0, &USBD_HID_InReport[1], USBD_HID_REQ_PERIOD_UPDATE);
|
||||
if (DataOutToSendLen) {
|
||||
ptrDataOut = &USBD_HID_InReport[1];
|
||||
}
|
||||
DataOutUpdateReqMask = 0;
|
||||
}
|
||||
} else { /* If multiple reports in system */
|
||||
for (i = USBD_HID_InReport[0]; ; i++) {
|
||||
if (i >= 32) i = 0;
|
||||
if (DataOutUpdateReqMask & (1 << i)) {
|
||||
USBD_HID_InReport[0]= i+1; /* ReportID */
|
||||
DataOutSentLen = 0;
|
||||
DataOutToSendLen = usbd_hid_get_report (HID_REPORT_INPUT, i+1, &USBD_HID_InReport[1], USBD_HID_REQ_PERIOD_UPDATE);
|
||||
if (DataOutToSendLen) {
|
||||
ptrDataOut = USBD_HID_InReport;
|
||||
DataOutToSendLen++;
|
||||
}
|
||||
DataOutUpdateReqMask &= ~(1 << i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Check if data needs to be sent */
|
||||
if (DataOutToSendLen ||
|
||||
DataOutEndWithShortPacket) { /* If sending is in progress */
|
||||
bytes_to_send = DataOutToSendLen - DataOutSentLen;
|
||||
if (bytes_to_send > usbd_hid_maxpacketsize[USBD_HighSpeed])
|
||||
bytes_to_send = usbd_hid_maxpacketsize[USBD_HighSpeed];
|
||||
USBD_WriteEP(usbd_hid_ep_intin | 0x80, ptrDataOut, bytes_to_send);
|
||||
ptrDataOut += bytes_to_send;
|
||||
DataOutSentLen += bytes_to_send;
|
||||
if ((DataOutSentLen < usbd_hid_inreport_max_sz) &&
|
||||
(bytes_to_send == usbd_hid_maxpacketsize[USBD_HighSpeed])) {
|
||||
/* If short packet should be sent also*/
|
||||
DataOutEndWithShortPacket = __TRUE;
|
||||
} else {
|
||||
DataOutEndWithShortPacket = __FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Interrupt Out Endpoint Event Callback
|
||||
* Parameters: event: not used (just for compatibility)
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_HID_EP_INTOUT_Event (U32 event) {
|
||||
U16 bytes_rece;
|
||||
|
||||
if (!DataInReceLen) { /* Check if new reception */
|
||||
ptrDataIn = USBD_HID_OutReport;
|
||||
DataInReceLen = 0;
|
||||
}
|
||||
bytes_rece = USBD_ReadEP(usbd_hid_ep_intout, ptrDataIn);
|
||||
ptrDataIn += bytes_rece;
|
||||
DataInReceLen += bytes_rece;
|
||||
if (!bytes_rece ||
|
||||
(DataInReceLen >= usbd_hid_outreport_max_sz) ||
|
||||
(bytes_rece < usbd_hid_maxpacketsize[USBD_HighSpeed])) {
|
||||
if (usbd_hid_outreport_num <= 1) { /* If only one out report in system */
|
||||
usbd_hid_set_report (HID_REPORT_OUTPUT, 0 , USBD_HID_OutReport , DataInReceLen, USBD_HID_REQ_EP_INT);
|
||||
} else {
|
||||
usbd_hid_set_report (HID_REPORT_OUTPUT, USBD_HID_OutReport[0], &USBD_HID_OutReport[1], DataInReceLen-1, USBD_HID_REQ_EP_INT);
|
||||
}
|
||||
DataInReceLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Configure Callback
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_HID_Configure_Event (void) {
|
||||
|
||||
/* Reset all variables after connect event */
|
||||
USBD_HID_Protocol = 0;
|
||||
|
||||
DataOutAsyncReq = __FALSE;
|
||||
DataOutUpdateReqMask = __FALSE;
|
||||
ptrDataOut = NULL;
|
||||
DataOutToSendLen = 0;
|
||||
DataOutSentLen = 0;
|
||||
DataOutEndWithShortPacket = __FALSE;
|
||||
|
||||
ptrDataIn = NULL;
|
||||
DataInReceLen = 0;
|
||||
|
||||
ptrDataFeat = NULL;
|
||||
DataFeatReceLen = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Interrupt In/Out Endpoint Event Callback
|
||||
* Parameters: event: USB Device Event
|
||||
* USBD_EVT_IN: Input Event
|
||||
* USBD_EVT_OUT: Output Event
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_HID_EP_INT_Event (U32 event) {
|
||||
if (event & USBD_EVT_IN) {
|
||||
USBD_HID_EP_INTIN_Event (event);
|
||||
}
|
||||
if (event & USBD_EVT_OUT) {
|
||||
USBD_HID_EP_INTOUT_Event (event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID SOF Handler (handles report timings: polling and idle times)
|
||||
* Called automatically on USB Device Start of Frame
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
void USBD_HID_SOF_Event (void) {
|
||||
static U8 cnt_for_4ms = 0;
|
||||
U8 i;
|
||||
BOOL tick_4ms, do_polling, polling_reload, idle_reload;
|
||||
|
||||
if (USBD_Configuration) {
|
||||
tick_4ms = __FALSE;
|
||||
if (cnt_for_4ms++ >= ((4 << (3 * USBD_HighSpeed))) - 1) {
|
||||
cnt_for_4ms = 0;
|
||||
tick_4ms = __TRUE;
|
||||
}
|
||||
|
||||
polling_reload = __FALSE;
|
||||
if (USBD_HID_PollingCnt < 255) USBD_HID_PollingCnt++;
|
||||
if (USBD_HID_PollingCnt == usbd_hid_interval[USBD_HighSpeed]) {
|
||||
polling_reload = __TRUE; /* If polling interval expired */
|
||||
}
|
||||
for (i = 0; i < usbd_hid_inreport_num; i++) {
|
||||
idle_reload = __FALSE;
|
||||
if (tick_4ms) {
|
||||
if (USBD_HID_IdleCnt[i] < 255) USBD_HID_IdleCnt[i]++;
|
||||
if (USBD_HID_IdleReload[i]) {
|
||||
if (USBD_HID_IdleCnt[i] >= USBD_HID_IdleReload[i]) {
|
||||
idle_reload = __TRUE; /* If idle period expired */
|
||||
}
|
||||
}
|
||||
}
|
||||
do_polling = (usbd_hid_interval[USBD_HighSpeed] > ((U16)(USBD_HID_IdleReload[i]) << (2 << (3 * USBD_HighSpeed)))) && (USBD_HID_IdleReload[i] != 0);
|
||||
if (polling_reload) {
|
||||
if (do_polling) {
|
||||
/* If polling is longer than idle */
|
||||
DataOutUpdateReqMask |= (1 << i);
|
||||
}
|
||||
}
|
||||
if (USBD_HID_IdleReload[i] != USBD_HID_IdleSet[i]) {
|
||||
if (USBD_HID_IdleCnt[i] >= USBD_HID_IdleSet[i]) {
|
||||
DataOutUpdateReqMask |= (1 << i);
|
||||
cnt_for_4ms = 0;
|
||||
}
|
||||
USBD_HID_IdleReload[i] = USBD_HID_IdleSet[i];
|
||||
}
|
||||
if (idle_reload) {
|
||||
if (!do_polling) {
|
||||
DataOutUpdateReqMask |= (1 << i);
|
||||
}
|
||||
USBD_HID_IdleCnt[i] = 0;
|
||||
}
|
||||
}
|
||||
if (polling_reload) {
|
||||
USBD_HID_PollingCnt = 0;
|
||||
}
|
||||
|
||||
if (DataOutUpdateReqMask && !DataOutToSendLen) { /* If pending */
|
||||
/* refresh request and no active data */
|
||||
/* out then start data out */
|
||||
USBD_HID_EP_INTIN_Event (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __RTX /* RTX task for handling events */
|
||||
|
||||
/*
|
||||
* USB Device HID Interrupt In Endpoint Event Handler Task
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_HID_EP_INTIN_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
if (usbd_os_evt_get() & USBD_EVT_IN) {
|
||||
USBD_HID_EP_INTIN_Event (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Interrupt Out Endpoint Event Handler Task
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_HID_EP_INTOUT_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
if (usbd_os_evt_get() & USBD_EVT_OUT) {
|
||||
USBD_HID_EP_INTOUT_Event (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Interrupt In/Out Endpoint Event Handler Task
|
||||
* Parameters: None
|
||||
* Return Value: None
|
||||
*/
|
||||
|
||||
__task void USBD_RTX_HID_EP_INT_Event (void) {
|
||||
|
||||
if (__rtx) {
|
||||
for (;;) {
|
||||
usbd_os_evt_wait_or (0xFFFF, 0xFFFF);
|
||||
USBD_HID_EP_INT_Event (usbd_os_evt_get());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* USB Device HID Get Report Trigger (asynchronous Get_Report request)
|
||||
* Parameters: rid: Report ID
|
||||
* buf: Pointer to data buffer
|
||||
* len: Number of bytes to be sent
|
||||
* Return Value: TRUE - Success, FALSE - Error
|
||||
*/
|
||||
|
||||
BOOL usbd_hid_get_report_trigger (U8 rid, U8 *buf, int len) {
|
||||
|
||||
if (len > usbd_hid_inreport_max_sz)
|
||||
return (__FALSE);
|
||||
|
||||
if (USBD_Configuration) {
|
||||
DataOutAsyncReq = __TRUE; /* Asynchronous data out request */
|
||||
while (DataOutToSendLen) {
|
||||
if (!USBD_Configuration) { /* If device not configured reject rq */
|
||||
DataOutAsyncReq = __FALSE; /* Asynchronous data out request */
|
||||
ptrDataOut = NULL;
|
||||
DataOutSentLen = 0;
|
||||
DataOutToSendLen = 0;
|
||||
return (__FALSE);
|
||||
}
|
||||
}
|
||||
USBD_HID_InReport[0] = rid;
|
||||
memcpy (&USBD_HID_InReport[1], buf, len);
|
||||
ptrDataOut = USBD_HID_InReport;
|
||||
DataOutSentLen = 0;
|
||||
DataOutToSendLen = len;
|
||||
if (usbd_hid_inreport_num <= 1) /* If only 1 in report skip ReportID */
|
||||
ptrDataOut ++;
|
||||
else /* If more in reports, send ReportID */
|
||||
DataOutToSendLen ++;
|
||||
USBD_HID_EP_INTIN_Event (0);
|
||||
USBD_HID_IdleCnt[rid] = 0;
|
||||
return (__TRUE);
|
||||
}
|
||||
|
||||
return (__FALSE);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user