EFR32 Blue Gecko 1 Software Documentation  efr32bg1-doc-5.1.2
em_usbxpress.h
Go to the documentation of this file.
1 /***************************************************************************/
18 /**************************************************************************/
63 #ifndef EM_USBXPRESS_H
64 #define EM_USBXPRESS_H
65 
66 #include <stdint.h>
67 #include <stdbool.h>
68 
69 #include "em_common.h"
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 /**************************************************************************/
97 typedef void (*USBX_apiCallback_t)(void);
98 
99 
100 /***************************************************************************/
109 // Basic USBX_getCallbackSource() return value bit masks (32 bits)
110 // Note: More than one bit can be set at the same time.
111 #define USBX_RESET 0x00000001
112 #define USBX_TX_COMPLETE 0x00000002
113 #define USBX_RX_COMPLETE 0x00000004
114 #define USBX_FIFO_PURGE 0x00000008
115 #define USBX_DEV_OPEN 0x00000010
116 #define USBX_DEV_CLOSE 0x00000020
117 #define USBX_DEV_CONFIGURED 0x00000040
118 #define USBX_DEV_SUSPEND 0x00000080
119 #define USBX_RX_OVERRUN 0x00000100
120 
123 /***************************************************************************/
131 #define USBX_STATUS_OK USB_STATUS_OK
132 #define USBX_STATUS_EP_BUSY USB_STATUS_EP_BUSY
133 #define USBX_STATUS_ILLEGAL USB_STATUS_ILLEGAL
134 #define USBX_STATUS_EP_STALLED USB_STATUS_EP_STALLED
135 #define USBX_STATUS_DEVICE_UNCONFIGURED USB_STATUS_DEVICE_UNCONFIGURED
136 
138 #ifdef char16_t
140 #undef char16_t
141 #endif
142 #if defined(__GNUC__) /* GCC compilers */
143 #if defined(__CHAR16_TYPE__)
144 typedef __CHAR16_TYPE__ char16_t;
145 #else
146 typedef unsigned short char16_t;
147 #endif
148 
149 #elif defined(__ICCARM__) /* IAR compiler */
150 #include <uchar.h>
151 
152 #elif defined(__CC_ARM) /* MDK-ARM compiler */
153 typedef unsigned short char16_t;
154 #endif
155 
157 /***************************************************************************/
162 /***************************************************************************/
173 #define USBX_STRING_DESC(_name, ...) \
174 SL_PACK_START(1) \
175 typedef struct \
176 { \
177  uint8_t len; \
178  uint8_t type; \
179  char16_t name[ 1 + sizeof((char16_t[]){__VA_ARGS__}) / 2]; \
180 } SL_ATTRIBUTE_PACKED _##_name; \
181 SL_PACK_END() \
182 SL_ALIGN(4) \
183 SL_PACK_START(1) \
184 static const _##_name _name SL_ATTRIBUTE_ALIGN(4)= \
185 { \
186  .len = sizeof(_##_name) - 2, \
187  .type = 3, \
188  .name = {__VA_ARGS__}, \
189  .name[((sizeof(_##_name) - 2) / 2) - 1] = '\0' \
190 } \
191 SL_PACK_END()
192 
193 /***************************************************************************/
204 #define USBX_BUF(x, y) \
205  SL_ALIGN(4) uint8_t x[((y)+3)&~3] SL_ATTRIBUTE_ALIGN(4)
206 
207 /***************************************************************************/
218 #define STATIC_USBX_BUF(x, y) SL_ALIGN(4) \
219  static uint8_t x[((y)+3)&~3] SL_ATTRIBUTE_ALIGN(4)
220 
223 /***************************************************************************/
230 SL_PACK_START(1)
231 typedef struct
232 {
233  uint16_t vendorId;
238  uint16_t productId;
243  void const* manufacturerString;
247  void const* productString;
251  void const* serialString;
255  uint8_t maxPower;
263  uint8_t powerAttribute;
272  uint16_t releaseBcd;
279  uint8_t useFifo;
288 SL_PACK_END()
289 
290 
291 /***************************************************************************/
308 void USBX_init(USBX_Init_t* p);
309 
310 /**************************************************************************/
341 int USBX_blockWrite(uint8_t* block,
342  uint32_t numBytes,
343  uint32_t* countPtr);
344 
345 /**************************************************************************/
383 int USBX_blockRead(uint8_t* block,
384  uint32_t numBytes,
385  uint32_t* countPtr);
386 
387 /**************************************************************************/
402 uint32_t USBX_getCallbackSource(void);
403 
404 /**************************************************************************/
416 
417 /**************************************************************************/
422 void USBX_apiCallbackDisable(void);
423 
424 /**************************************************************************/
429 void USBX_disable(void);
430 
431 /**************************************************************************/
440 uint_least16_t USBX_getLibraryVersion(void);
441 
442 
447 #ifdef __cplusplus
448 }
449 #endif
450 
451 #endif // EM_USBXPRESS_H
void USBX_apiCallbackDisable(void)
Inhibits user API call-backs and does NOT disable the USB interrupt.
Definition: em_usbxpress.c:158
uint8_t useFifo
Definition: em_usbxpress.h:279
#define SL_PACK_END()
Macro for handling packed structs. Use this macro after the struct definition. With GCC...
Definition: em_common.h:157
void USBX_init(USBX_Init_t *p)
User API USB initialization function.
Definition: em_usbxpress.c:87
void const * serialString
Definition: em_usbxpress.h:251
General purpose utilities.
#define SL_PACK_START(x)
Macro for handling packed structs. Use this macro before the struct definition. X denotes the max...
Definition: em_common.h:150
void const * manufacturerString
Definition: em_usbxpress.h:243
uint16_t productId
Definition: em_usbxpress.h:238
USBXpress initialization function parameter typedef.
Definition: em_usbxpress.h:231
uint_least16_t USBX_getLibraryVersion(void)
Returns the USBXpress library version.
Definition: em_usbxpress.c:252
uint16_t vendorId
Definition: em_usbxpress.h:233
int USBX_blockRead(uint8_t *block, uint32_t numBytes, uint32_t *countPtr)
User API function to get data from host.
Definition: em_usbxpress.c:172
int USBX_blockWrite(uint8_t *block, uint32_t numBytes, uint32_t *countPtr)
User API function to send data to host.
Definition: em_usbxpress.c:226
uint32_t USBX_getCallbackSource(void)
User API function to get the call-back source.
Definition: em_usbxpress.c:239
void(* USBX_apiCallback_t)(void)
Definition: em_usbxpress.h:97
uint16_t releaseBcd
Definition: em_usbxpress.h:272
void const * productString
Definition: em_usbxpress.h:247
uint8_t powerAttribute
Definition: em_usbxpress.h:263
uint8_t maxPower
Definition: em_usbxpress.h:255
#define SL_ATTRIBUTE_PACKED
GCC style macro for handling packed structs.
Definition: em_common.h:143
void USBX_apiCallbackEnable(USBX_apiCallback_t f)
Enables user API call-backs.
Definition: em_usbxpress.c:164
void USBX_disable(void)
Disables the USB interface.
Definition: em_usbxpress.c:247