11 #ifndef HOST_LIB_SLABUSBSPI_INCLUDE_SLAB_USB_SPI_H_INCLUDED_9QK7BKA9FX 12 #define HOST_LIB_SLABUSBSPI_INCLUDE_SLAB_USB_SPI_H_INCLUDED_9QK7BKA9FX 18 #include "silabs_defs.h" 19 #include "silabs_sal.h" 29 #ifdef SLAB_USB_SPI_EXPORTS 30 #define SLAB_USB_SPI_API 32 #define SLAB_USB_SPI_API __declspec(dllimport) 33 #pragma comment (lib, "SLAB_USB_SPI.lib") 34 #endif // USB_SPI_EXPORTS 36 #define SLAB_USB_SPI_API 48 #define CALLBACK __stdcall 50 #define WINAPI __stdcall 66 #define BULK_PACKETSIZE 64 67 #define EP_BUFSIZE BULK_PACKETSIZE 69 #define CMD_TIMEOUT_MS 1000 70 #define STRING_DESCRIPTOR_SIZE 256 71 #define SIZE_PIN_CONFIG 20 75 #define WRITEREAD_MAX_BLOCKSIZE 256 78 #define CP213x_NUM_GPIO 11 82 #define CSMODE_ACTIVE 1 83 #define CSMODE_ACTIVE_OTHERS_IDLE 2 86 #define GPIO_MODE_INPUT 0 87 #define GPIO_MODE_OUTPUT_OD 1 88 #define GPIO_MODE_OUTPUT_PP 2 89 #define GPIO_MODE_CHIPSELECT 3 91 #define GPIO_MODE__RTR_ACTLOW 4 92 #define GPIO_MODE__RTR_ACTHIGH 5 94 #define GPIO_MODE__EVTCNTR_RISING 4 95 #define GPIO_MODE__EVTCNTR_FALLING 5 96 #define GPIO_MODE__EVTCNTR_NEGPULSE 6 97 #define GPIO_MODE__EVTCNTR_POSPULSE 7 99 #define GPIO_MODE__CLK_OUT 4 100 #define GPIO_MODE__SPI_ACTIVITY 4 101 #define GPIO_MODE__SUSPEND 4 102 #define GPIO_MODE__SUSPENDBAR 4 108 #define SHORT_STRING_LEN 60 109 #define LONG_STRING_LEN_1 61 110 #define LONG_STRING_LEN_2 63 119 #define CMD_TRANSFER_DATA 0x0000 120 // Subcommand definitions for TRANSFER_DATA command 121 #define SUBCMD_READ 0 122 #define SUBCMD_WRITE 1 123 #define SUBCMD_WRITEREAD 2 124 #define SUBCMD_RTREAD 4 125 #define SUBCMD_MSB_RELEASE_BUS 0x80 128 _Success_(
return == TRUE)
136 #define SPICTL_CPHA_SHIFT 5 137 #define SPICTL_CPHA_MASK 0x20 138 #define SPICTL_CPHA_LEADING_EDGE 0 139 #define SPICTL_CPHA_TRAILING_EDGE 1 142 #define SPICTL_CPOL_SHIFT 4 143 #define SPICTL_CPOL_MASK 0x10 144 #define SPICTL_CPOL_ACTIVE_HIGH 0 145 #define SPICTL_CPOL_ACTIVE_LOW 1 148 #define SPICTL_CSMODE_SHIFT 3 149 #define SPICTL_CSMODE_MASK 0x08 150 #define SPICTL_CSMODE_OPENDRAIN 0 151 #define SPICTL_CSMODE_PUSHPULL 1 154 #define SPICTL_CLKRATE_SHIFT 0 155 #define SPICTL_CLKRATE_MASK 0x07 156 #define SPICTL_CLKRATE_12M 0 157 #define SPICTL_CLKRATE_6M 1 158 #define SPICTL_CLKRATE_3M 2 159 #define SPICTL_CLKRATE_1M5 3 160 #define SPICTL_CLKRATE_750K 4 161 #define SPICTL_CLKRATE_375K 5 162 #define SPICTL_CLKRATE_187K5 6 163 #define SPICTL_CLKRATE_93K75 7 172 #define bRESULT_PASS TRUE 173 #define bRESULT_FAIL FALSE 178 typedef enum _USB_SPI_STATUS {
238 #define CP213x_LOCK_PRODUCT_STR_1 0x0001 239 #define CP213x_LOCK_PRODUCT_STR_2 0x0002 240 #define CP213x_LOCK_SERIAL_STR 0x0004 241 #define CP213x_LOCK_PIN_CONFIG 0x0008 243 #define CP213x_LOCK_VID 0x0100 244 #define CP213x_LOCK_PID 0x0200 245 #define CP213x_LOCK_POWER 0x0400 246 #define CP213x_LOCK_POWER_MODE 0x0800 247 #define CP213x_LOCK_RELEASE_VERSION 0x1000 248 #define CP213x_LOCK_MFG_STR_1 0x2000 249 #define CP213x_LOCK_MFG_STR_2 0x4000 250 #define CP213x_LOCK_TRANSFER_PRIORITY 0x8000 253 #define CP213x_SET_VID 0x01 254 #define CP213x_SET_PID 0x02 255 #define CP213x_SET_POWER 0x04 256 #define CP213x_SET_POWER_MODE 0x08 257 #define CP213x_SET_RELEASE_VERSION 0x10 258 #define CP213x_SET_TRANSFER_PRIORITY 0x80 261 #define MFG_STRLEN 62 262 #define PRODUCT_STRLEN 62 263 #define SERIAL_STRLEN 30 281 #define CP213x_INDEX_GPIO_0 0 282 #define CP213x_INDEX_GPIO_1 1 283 #define CP213x_INDEX_GPIO_2 2 284 #define CP213x_INDEX_GPIO_3 3 285 #define CP213x_INDEX_GPIO_4 4 286 #define CP213x_INDEX_GPIO_5 5 287 #define CP213x_INDEX_GPIO_6 6 288 #define CP213x_INDEX_GPIO_7 7 289 #define CP213x_INDEX_GPIO_8 8 290 #define CP213x_INDEX_GPIO_9 9 291 #define CP213x_INDEX_GPIO_10 10 294 #define CP213x_MASK_SCK 0x0001 295 #define CP213x_MASK_MISO 0x0002 296 #define CP213x_MASK_MOSI 0x0004 297 #define CP213x_MASK_GPIO_0 0x0008 298 #define CP213x_MASK_GPIO_1 0x0010 299 #define CP213x_MASK_GPIO_2 0x0020 300 #define CP213x_MASK_GPIO_3 0x0040 301 #define CP213x_MASK_GPIO_4 0x0080 302 #define CP213x_MASK_GPIO_5 0x0100 303 #define CP213x_MASK_GPIO_6 0x0400 304 #define CP213x_MASK_GPIO_7 0x0800 305 #define CP213x_MASK_GPIO_8 0x1000 306 #define CP213x_MASK_GPIO_9 0x2000 307 #define CP213x_MASK_GPIO_10 0x4000 320 typedef struct _DEVICE_DESCRIPTOR
323 BYTE bDescriptorType;
326 BYTE bDeviceSubClass;
327 BYTE bDeviceProtocol;
328 BYTE bMaxPacketSize0;
335 BYTE bNumConfigurations;
354 #define SPI_INTERBYTE_DELAY_MASK 0x01 355 #define SPI_CS_POSTASSERT_DELAY_MASK 0x02 356 #define SPI_CS_PREDEASSERT_DELAY_MASK 0x04 357 #define SPI_CS_TOGGLE_MASK 0x08 370 #endif // __cplusplus 498 CP213x_OpenByIndex ( DWORD deviceIndex,
520 CP213x_OpenByDevicePath ( LPCSTR devicePath,
565 CP213x_GetVidPid(_In_
const DWORD deviceIndex, _Out_writes_bytes_(4) WORD* vid, _Out_writes_bytes_(4) WORD* pid );
681 PDEVICE_DESCRIPTOR pDescriptor );
724 _Out_writes_bytes_opt_(2) WORD* vid,
725 _Out_writes_bytes_opt_(2) WORD* pid,
726 _Out_writes_bytes_opt_(1)
BYTE* pMaxPower,
727 _Out_writes_bytes_opt_(1)
BYTE* pPowerMode,
728 _Out_writes_bytes_opt_(2) WORD* releaseVersion,
729 _Out_writes_bytes_opt_(1)
BYTE* transferPriority );
757 _In_
const BYTE MaxPower,
758 _In_
const BYTE PowerMode,
759 _In_
const WORD releaseVersion,
760 _In_
const BYTE transferPriority,
761 _In_
const BYTE mask );
1056 _In_
const BYTE channel,
1058 WORD* interByteDelay,
1059 WORD* postAssertDelay,
1060 WORD* preDeassertDelay );
1082 _In_
const BYTE channel,
1083 _In_
const BYTE delayMode,
1084 _In_
const WORD interByteDelay,
1085 _In_
const WORD postAssertDelay,
1086 _In_
const WORD preDeassertDelay );
1105 WORD* channelCsEnable,
1106 WORD* pinCsEnable );
1147 _In_
const DWORD length,
1148 _In_
const BOOL releaseBusAfterTransfer,
1149 _In_
const DWORD timeoutMs,
1150 DWORD * pBytesActuallyWritten);
1176 _In_
const DWORD length,
1177 _In_
const BOOL releaseBusAfterTransfer,
1178 _In_
const DWORD timeoutMs,
1179 DWORD* pBytesActuallyTransferred );
1210 BOOL releaseBusAfterTransfer );
1234 BOOL releaseBusAfterTransfer,
1236 DWORD* pBytesActuallyRead );
1258 BOOL releaseBusAfterTransfer );
1284 BOOL releaseBusAfterTransfer,
1286 DWORD* pBytesActuallyRead );
1344 DWORD* pBytesActuallyRead );
1617 #endif // __cplusplus 1621 #endif // HOST_LIB_SLABUSBSPI_INCLUDE_SLAB_USB_SPI_H_INCLUDED_9QK7BKA9FX Invalid enumeration value.
Definition: SLAB_USB_SPI.h:182
USB_SPI_STATUS CP213x_GetSerialString(const CP213x_DEVICE hDevice, LPSTR serialString, BYTE *serialStringlen)
Get the USB device Serial Number string.
#define SUBCMD_WRITEREAD
Sub-command write read.
Definition: SLAB_USB_SPI.h:123
USB SPI error code pipe init fail.
Definition: SLAB_USB_SPI.h:217
#define STRING_DESCRIPTOR_SIZE
String descriptor size.
Definition: SLAB_USB_SPI.h:70
USB SPI error code read thread create failure.
Definition: SLAB_USB_SPI.h:225
USB SPI error code read thread start failure.
Definition: SLAB_USB_SPI.h:227
enum _USB_SPI_STATUS * PUSB_SPI_STATUS
API Status return codes pointer.
USB SPI error code invalid transfer size.
Definition: SLAB_USB_SPI.h:215
USB_SPI_STATUS CP213x_SetEventCounter(const CP213x_DEVICE hDevice, const BYTE mode, const WORD eventCount)
what it does in brief
USB SPI error code pipe read fail.
Definition: SLAB_USB_SPI.h:220
USB_SPI_STATUS CP213x_SetSpiControlByte(const CP213x_DEVICE hDevice, const BYTE channel, const BYTE controlByte)
what it does in brief
USB_SPI_STATUS CP213x_TransferWrite(const CP213x_DEVICE hDevice, BYTE pWriteBuf[], const DWORD length, const BOOL releaseBusAfterTransfer, const DWORD timeoutMs, DWORD *pBytesActuallyWritten)
what it does in brief
USB_SPI_STATUS CP213x_ReadAbort(const CP213x_DEVICE hDevice)
Abort an asynchronous Read or ReadRTR operation.
Allocation error.
Definition: SLAB_USB_SPI.h:181
USB_SPI_STATUS CP213x_GetProductString(const CP213x_DEVICE hDevice, LPSTR productString, BYTE *productStringLen)
Get the USB device Product string.
USB_SPI_STATUS CP213x_GetClockDivider(const CP213x_DEVICE hDevice, BYTE *clockDivider)
what it does in brief
USB_SPI_STATUS CP213x_GetDevicePath(const DWORD deviceIndex, LPSTR path)
what it does in brief
USB_SPI_STATUS CP213x_GetOpenedDevicePath(const CP213x_DEVICE device, LPSTR path)
what it does in brief
USB_SPI_STATUS CP213x_AbortInputPipe(const CP213x_DEVICE hDevice)
what it does in brief
void * CP213x_DEVICE
CP213X_DEVICE opaque object.
Definition: SLAB_USB_SPI.h:58
Null pointer.
Definition: SLAB_USB_SPI.h:183
USB_SPI_STATUS CP213x_AbortOutputPipe(const CP213x_DEVICE hDevice)
what it does in brief
USB_SPI_STATUS CP213x_GetDeviceVersion(const CP213x_DEVICE hDevice, BYTE *majorVersion, BYTE *minorVersion)
what it does in brief
USB_SPI_STATUS CP213x_GetLibraryVersion(BYTE *major, BYTE *minor, BOOL *release)
what it does in brief
USB_SPI_STATUS CP213x_SetGpioModeAndLevel(const CP213x_DEVICE hDevice, const BYTE channel, const BYTE mode, const BYTE level)
what it does in brief
USB_SPI_STATUS CP213x_Reset(const CP213x_DEVICE hDevice)
what it does in brief
no error
Definition: silabs_defs.h:262
USB_SPI_STATUS CP213x_TransferReadAsync(const CP213x_DEVICE hDevice, DWORD totalSize, DWORD blockSize, BOOL releaseBusAfterTransfer)
Perform SPI Read (asynchronous)
USB SPI error code pipe write fail.
Definition: SLAB_USB_SPI.h:219
USB_SPI_STATUS CP213x_GetGpioModeAndLevel(const CP213x_DEVICE hDevice, const BYTE channel, BYTE *mode, BYTE *level)
what it does in brief
#define SUBCMD_RTREAD
Sub-command RT read.
Definition: SLAB_USB_SPI.h:124
USB SPI error code system error.
Definition: SLAB_USB_SPI.h:231
Definition: SLAB_USB_SPI.h:320
#define SLAB_USB_SPI_API
Silabs USB to SPI API.
Definition: SLAB_USB_SPI.h:36
USB_SPI_STATUS CP213x_SetSerialString(const CP213x_DEVICE hDevice, LPCSTR serialString, const BYTE serialStringlen)
Set the USB device Serial Number string.
char PRODUCT_STR[62]
Product string.
Definition: SLAB_USB_SPI.h:266
USB SPI error code control transfer error.
Definition: SLAB_USB_SPI.h:214
USB_SPI_STATUS CP213x_GetSpiDelay(const CP213x_DEVICE hDevice, const BYTE channel, BYTE *delayMode, WORD *interByteDelay, WORD *postAssertDelay, WORD *preDeassertDelay)
what it does in brief
USB_SPI_STATUS CP213x_GetRtrState(const CP213x_DEVICE hDevice, BYTE *isStopped)
what it does in brief
The current USB device is not opened.
Definition: SLAB_USB_SPI.h:200
#define SERIAL_STRLEN
Serial string length.
Definition: SLAB_USB_SPI.h:263
USB_SPI_STATUS CP213x_SetManufacturingString(const CP213x_DEVICE hDevice, LPCSTR manufacturingString, const BYTE manufacturingStringlen)
Set the USB device Manufacturer string.
USB_SPI_STATUS CP213x_GetDeviceDescriptor(const CP213x_DEVICE hDevice, PDEVICE_DESCRIPTOR pDescriptor)
what it does in brief
USB_SPI_STATUS CP213x_TransferWriteRead(const CP213x_DEVICE hDevice, BYTE pWriteBuf[], BYTE pReadBuf[], const DWORD length, const BOOL releaseBusAfterTransfer, const DWORD timeoutMs, DWORD *pBytesActuallyTransferred)
what it does in brief
USB SPI error code device returned too much data.
Definition: SLAB_USB_SPI.h:229
USB_SPI_STATUS CP213x_GetFifoFullThreshold(const CP213x_DEVICE hDevice, BYTE *pFifoFullThreshold)
what it does in brief
USB_SPI_STATUS CP213x_SetGuid(LPGUID guid)
what it does in brief
char SERIAL_STR[30]
Serial string.
Definition: SLAB_USB_SPI.h:267
USB SPI error code pipe abort fail.
Definition: SLAB_USB_SPI.h:221
USB_SPI_STATUS
API Status return codes.
Definition: SLAB_USB_SPI.h:178
USB_SPI_STATUS CP213x_TransferReadRtrSync(const CP213x_DEVICE hDevice, BYTE pReadBuf[], DWORD totalSize, DWORD blockSize, BOOL releaseBusAfterTransfer, DWORD timeoutMs, DWORD *pBytesActuallyRead)
what it does in brief
#define WINAPI
Win API.
Definition: SLAB_USB_SPI.h:37
USB_SPI_STATUS CP213x_SetLock(const CP213x_DEVICE hDevice, const WORD lockValue)
Set the Lock values.
Mode != INPUT, OUTPUT_OD, or OUTPUT_PP.
Definition: SLAB_USB_SPI.h:185
unsigned char BYTE
Byte definition.
Definition: silabs_defs.h:41
USB_SPI_STATUS CP213x_SetFifoFullThreshold(const CP213x_DEVICE hDevice, const BYTE fifoFullThreshold)
what it does in brief
USB_SPI_STATUS CP213x_GetNumDevices(DWORD *numDevices, DWORD VID, DWORD PID)
what it does in brief
USB_SPI_STATUS CP213x_GetGpioValues(const CP213x_DEVICE hDevice, WORD *gpioValues)
what it does in brief
char MFG_STR[62]
Manufacture string.
Definition: SLAB_USB_SPI.h:265
#define MFG_STRLEN
Manufacture string length.
Definition: SLAB_USB_SPI.h:261
USB_SPI_STATUS CP213x_ReadPoll(const CP213x_DEVICE hDevice, BYTE pReadBuf[], DWORD maxLength, DWORD *pBytesActuallyRead)
Read bytes received during an asynchronous Read or ReadRTR operation.
Invalid function parameter.
Definition: SLAB_USB_SPI.h:192
USB_SPI_STATUS CP213x_Open(DWORD deviceIndex, CP213x_DEVICE *phDevice, DWORD VID, DWORD PID)
Opens a USB device using a device index and returns a device object pointer which will be used for su...
#define SUBCMD_WRITE
Sub-command write.
Definition: SLAB_USB_SPI.h:122
USB_SPI_STATUS CP213x_FlushOutputPipe(const CP213x_DEVICE hDevice)
what it does in brief
An error occurred while communicating with the device or while retrieving device information.
Definition: SLAB_USB_SPI.h:207
The specified USB device could not be found.
Definition: SLAB_USB_SPI.h:199
USB_SPI_STATUS CP213x_GetStringDescriptor(const CP213x_DEVICE hDevice, BYTE index, BYTE stringDescriptor[256])
what it does in brief
USB_SPI_STATUS CP213x_TransferReadSync(const CP213x_DEVICE hDevice, BYTE pReadBuf[], DWORD length, BOOL releaseBusAfterTransfer, DWORD timeoutMs, DWORD *pBytesActuallyRead)
what it does in brief
USB_SPI_STATUS CP213x_GetLock(const CP213x_DEVICE hDevice, WORD *lockValue)
Get the Lock values.
BOOL CP213x_IsOpened(const CP213x_DEVICE hDevice)
what it does in brief
USB_SPI_STATUS CP213x_SetPinConfig(const CP213x_DEVICE hDevice, BYTE pinConfig[20])
Set the USB device Pin Configuration info.
The function returned successfully.
Definition: SLAB_USB_SPI.h:180
USB SPI error code pipe query fail.
Definition: SLAB_USB_SPI.h:218
USB_SPI_STATUS CP213x_GetUsbConfig(const CP213x_DEVICE hDevice, WORD *vid, WORD *pid, BYTE *pMaxPower, BYTE *pPowerMode, WORD *releaseVersion, BYTE *transferPriority)
Get the USB Device Configuration info.
USB_SPI_STATUS CP213x_GetChipSelect(const CP213x_DEVICE hDevice, WORD *channelCsEnable, WORD *pinCsEnable)
what it does in brief
USB_SPI_STATUS CP213x_Close(const CP213x_DEVICE hDevice)
what it does in brief
USB_SPI_STATUS CP213x_SetChipSelect(const CP213x_DEVICE hDevice, const BYTE channel, const BYTE mode)
what it does in brief
USB_SPI_STATUS CP213x_GetManufacturingString(const CP213x_DEVICE hDevice, LPSTR manufacturingString, BYTE *manufacturingStringLen)
Get the USB device Manufacturer string.
USB SPI error code pipe invalid id.
Definition: SLAB_USB_SPI.h:223
#define SIZE_PIN_CONFIG
Config pin size.
Definition: SLAB_USB_SPI.h:71
#define PRODUCT_STRLEN
Product string length.
Definition: SLAB_USB_SPI.h:262
SPI Command Word. Alias of this struct is SPI_CMD.
#define SUBCMD_READ
Sub-command read.
Definition: SLAB_USB_SPI.h:121
USB_SPI_STATUS CP213x_SetGpioValues(const CP213x_DEVICE hDevice, const WORD mask, const WORD gpioValues)
what it does in brief
The handle is invalid.
Definition: SLAB_USB_SPI.h:201
Channel index is not in range.
Definition: SLAB_USB_SPI.h:184
USB_SPI_STATUS CP213x_GetOpenedVidPid(const CP213x_DEVICE device, WORD *vid, WORD *pid)
what it does in brief
#define CP213x_NUM_GPIO
Number of GPIO/CS pins.
Definition: SLAB_USB_SPI.h:78
USB_SPI_STATUS CP213x_FlushInputPipe(const CP213x_DEVICE hDevice)
what it does in brief
The specified device object pointer is invalid.
Definition: SLAB_USB_SPI.h:194
#define MAX_PATH
Max string path length.
Definition: SLAB_USB_SPI.h:47
USB_SPI_STATUS CP213x_TransferReadRtrAsync(const CP213x_DEVICE hDevice, DWORD totalSize, DWORD blockSize, BOOL releaseBusAfterTransfer)
what it does in brief
USB_SPI_STATUS CP213x_SetUsbConfig(const CP213x_DEVICE hDevice, const WORD vid, const WORD pid, const BYTE MaxPower, const BYTE PowerMode, const WORD releaseVersion, const BYTE transferPriority, const BYTE mask)
Set the USB device Configuration info.
USB_SPI_STATUS CP213x_GetGuid(LPGUID guid)
what it does in brief
USB_SPI_STATUS CP213x_SetClockDivider(const CP213x_DEVICE hDevice, const BYTE clockDivider)
what it does in brief
USB_SPI_STATUS CP213x_SetSpiDelay(const CP213x_DEVICE hDevice, const BYTE channel, const BYTE delayMode, const WORD interByteDelay, const WORD postAssertDelay, const WORD preDeassertDelay)
what it does in brief
A control transfer operation timed out.
Definition: SLAB_USB_SPI.h:210
USB_SPI_STATUS CP213x_GetSpiControlBytes(const CP213x_DEVICE hDevice, BYTE controlBytes[11])
what it does in brief
USB_SPI_STATUS CP213x_GetEventCounter(const CP213x_DEVICE hDevice, BYTE *mode, WORD *eventCount)
what it does in brief
USB_SPI_STATUS CP213x_ReadProm(const CP213x_DEVICE hDevice, BYTE pReadBuf[])
what it does in brief
USB SPI error code read thread not running.
Definition: SLAB_USB_SPI.h:226
Unknown/unspecified error. TODO: No, not all-F's, how about 0xFF?
Definition: SLAB_USB_SPI.h:187
USB_SPI_STATUS CP213x_WriteProm(const CP213x_DEVICE hDevice, BYTE pWriteBuf[])
what it does in brief
USB_SPI_STATUS CP213x_SetRtrStop(const CP213x_DEVICE hDevice, BYTE stopRtr)
what it does in brief
Definition: SLAB_USB_SPI.h:341
USB_SPI_STATUS CP213x_GetVidPid(const DWORD deviceIndex, WORD *vid, WORD *pid)
what it does in brief
USB_SPI_STATUS CP213x_GetPinConfig(const CP213x_DEVICE hDevice, BYTE pinConfig[20])
Get the USB device Pin Configuration info.
USB_SPI_STATUS CP213x_SetProductString(const CP213x_DEVICE hDevice, LPCSTR productString, const BYTE productStringlen)
Set the USB device Product string.
SET_STATUS
Set status return.
Definition: SLAB_USB_SPI.h:274
USB SPI error code pipe flush fail.
Definition: SLAB_USB_SPI.h:222