Silicon Labs Host Libraries
SLABCP2114.h
1 // SLABCP2114.h
3 // For SLABHIDtoUART.dll
4 // and Silicon Labs CP2114 HID to UART
6 #ifndef SLAB_CP2114_H
7 #define SLAB_CP2114_H
8 
10 // Includes
12 
13 #include "SLABHIDtoUART.h"
14 #include "CP2114_Common.h"
15 
17 // Return Code Definitions
19 
22 #define HID_UART_INVALID_CONFIG_NUMBER kInvalidConfigNumber
23 #define HID_UART_BOOT_INDEXES_DEPLETED kBootIndicesDepleted
24 #define HID_UART_REQUESTED_CONFIG_NOT_PRESENT kRequestedConfigNotPresent
25 #define HID_UART_CONFIG_INVALID kRequestedConfigInvalid
26 #define HID_UART_CONFIG_POINTERS_DEPLETED kConfigPointersDepleted
27 #define HID_UART_CONFIG_SPACE_DEPLETED kConfigSpaceDepleted
28 #define HID_UART_BOOT_INDEX_UNCHANGED kBootIndexUnchanged
29 #define HID_UART_CONFIG_UNCHANGED kConfigUnchanged
30 #define HID_UART_INVALID_CONFIG_SEQUENCE_IDENTIFIER kConfigInvalidConfigIdentifier
31 #define HID_UART_INVALID_CONFIG_SETTINGS kConfigSettingsInvalid
32 #define HID_UART_UNSUPPORTED_CONFIG_FORMAT kUnsupportedConfigFormat
33 
35 // 'Set Parameters for Next Get' errors
36 #define HID_UART_INVALID_NUMBER_OF_CACHED_PARAMS kInvalidNumberOfCachedParams
37 #define HID_UART_UNEXPECTED_CACHE_DATA kUnexpectedCacheData
38 
39 #define HID_UART_I2C_BUSY kI2cBusy
42 #define HID_UART_I2C_TIMEOUT kI2cTimeout
43 #define HID_UART_I2C_INVALID_TOKEN kI2cInvalidToken
44 #define HID_UART_I2C_INVALID_WRITE_LENGTH kI2cInvalidWriteLength
45 #define HID_UART_I2C_INVALID_CONFIG_LENGTH kI2cInvalidConfigLength
46 #define HID_UART_I2C_SCL_STUCK_LOW kI2cSclStuckLow
47 #define HID_UART_I2C_SDA_STUCK_LOW kI2cSdaStuckLow
48 
50 
52 // Pin Definitions
57 #define CP2114_INDEX_GPIO_0 0
58 #define CP2114_INDEX_GPIO_1 1
59 #define CP2114_INDEX_GPIO_2 2
60 #define CP2114_INDEX_GPIO_3 3
61 #define CP2114_INDEX_GPIO_4 4
62 #define CP2114_INDEX_GPIO_5 5
63 #define CP2114_INDEX_GPIO_6 6
64 #define CP2114_INDEX_GPIO_7 7
65 #define CP2114_INDEX_GPIO_8 8
66 #define CP2114_INDEX_GPIO_9 9
67 #define CP2114_INDEX_TX 10
68 #define CP2114_INDEX_RX 11
69 #define CP2114_INDEX_SUSPEND 12
70 #define CP2114_INDEX_SUSPEND_BAR 13
71 // Size of the above array pointed to by pinConfig parameter in CP2114_SetPinConfig and CP2114_GetPinConfig
72 #define CP2114_PIN_CONFIG_SIZE 14
73 
75 #define CP2114_MASK_GPIO_0 0x0001
79 #define CP2114_MASK_GPIO_1 0x0002
80 #define CP2114_MASK_GPIO_2 0x0004
81 #define CP2114_MASK_GPIO_3 0x0008
82 #define CP2114_MASK_GPIO_4 0x0010
83 #define CP2114_MASK_GPIO_5 0x0020
84 #define CP2114_MASK_GPIO_6 0x0040
85 #define CP2114_MASK_GPIO_7 0x0080
86 #define CP2114_MASK_GPIO_8 0x0100
87 #define CP2114_MASK_GPIO_9 0x0200
88 #define CP2114_MASK_TX 0x0400
89 #define CP2114_MASK_RX 0x0800
90 #define CP2114_MASK_SUSPEND 0x1000
91 #define CP2114_MASK_SUSPEND_BAR 0x2000
92 
94 // DAC Definitions
97 
98 #define MAX_DAC_CONFIG_SIZE (2*512 - sizeof(CP2114_RAM_CONFIG_STRUCT))
99 
100 // 60 is the largest common multiple of 2, 3 and 4. This ensures that
101 // an I2C transactions contained in the SET/GET_DAC_REGISTERS payload
102 // will not be split across multiple frames.
103 #define DAC_REGISTERS_PAYLOAD_MAX_LEN 60
104 
105 // Typedefs
108 
110 
112 
114 // DAC Structures
118 typedef union _CP2114_OTP_CONFIG
119 {
122  struct // if config_version == CP2114_CONFIG_VERSION_B01
123  {
124  BYTE RemConfig[ RAM_CONFIG_SIZE_B01];
125  BYTE DacConfig[ MAX_DAC_CONFIG_SIZE];
126  } CP2114_B01;
127  struct // if config_version == CP2114_CONFIG_VERSION_B02
130  {
131  BYTE PemConfig[ RAM_CONFIG_SIZE_B02];
132  BYTE DacConfig[ MAX_DAC_CONFIG_SIZE];
133  } CP2114_B02;
134  BYTE Other[0xffff];
135 } CP2114_OTP_CONFIG, *PCP2114_OTP_CONFIG;
136 
140 {
143 } CP2114_OTP_CONFIG_GET, *PCP2114_OTP_CONFIG_GET;
144 
146 // Exported Library Functions
148 
149 #ifdef __cplusplus
150 extern "C"
151 {
152 #endif // __cplusplus
153 
154 // CP2114_GetVersions
167 _Check_return_
169 _Success_(return == HID_UART_SUCCESS)
171 CP2114_GetVersions(_In_ _Pre_defensive_ HID_UART_DEVICE device, _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* api_version, _Out_writes_bytes_(1) BYTE* fw_version, _Out_writes_bytes_(1) BYTE* config_version);
172 
173 // CP2114_SetPinConfig
189 _Check_return_
191 _Success_(return == HID_UART_SUCCESS)
193 CP2114_SetPinConfig(
194  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
195  _In_reads_bytes_(CP2114_PIN_CONFIG_SIZE) _Pre_defensive_ BYTE* pinConfig,
196  _In_ _Pre_defensive_ const BOOL useSuspendValues,
197  _In_ _Pre_defensive_ const WORD suspendValue,
198  _In_ _Pre_defensive_ const WORD suspendMode,
199  _In_ _Pre_defensive_ const BYTE clkDiv
200 );
201 
202 // CP2114_GetPinConfig
218 _Check_return_
220 _Success_(return == HID_UART_SUCCESS)
222 CP2114_GetPinConfig(
223  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
224  _Out_writes_bytes_(CP2114_PIN_CONFIG_SIZE) _Pre_defensive_ BYTE* pinConfig,
225  _Out_writes_bytes_(sizeof(BOOL)) _Pre_defensive_ BOOL* useSuspendValues,
226  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* suspendValue,
227  _Out_writes_bytes_(sizeof(WORD)) _Pre_defensive_ WORD* suspendMode,
228  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE* clkDiv
229 );
230 
231 // CP2114_GetDeviceStatus
232 // This function shouldn't be called in normal conditions. The other APIs call this function.
233 // However, due to possible reenumeration after HidUart_SetRamConfig, getCP2114Status can't be called
234 // immediately after HidUart_SetRamConfig, this can be used to clear possible ConfigUnchanged status
235 // prior to the next command.
248 _Check_return_
250 _Success_(return == HID_UART_SUCCESS)
252 CP2114_GetDeviceStatus(
253  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
254  _Out_writes_bytes_(sizeof(BYTE)) _Pre_defensive_ BYTE *pCP2114Status
255 );
256 
257 // CP2114_GetDeviceCaps
268 _Check_return_
270 _Success_(return == HID_UART_SUCCESS)
272 CP2114_GetDeviceCaps(
273  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
274  _Out_writes_bytes_(sizeof(CP2114_CAPS_STRUCT)) _Pre_defensive_ PCP2114_CAPS_STRUCT pCP2114CapsStruct
275 );
276 
277 // CP2114_SetRamConfig
340 _Check_return_
342 _Success_(return == HID_UART_SUCCESS)
344 CP2114_SetRamConfig(
345  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
346  _In_reads_bytes_(sizeof(CP2114_RAM_CONFIG_STRUCT)) _Pre_defensive_ const PCP2114_RAM_CONFIG_STRUCT pCP2114RamConfigStruct
347 );
348 
349 // CP2114_GetRamConfig
368 _Check_return_
370 _Success_(return == HID_UART_SUCCESS)
372 CP2114_GetRamConfig(
373  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
374  _Out_writes_bytes_(sizeof(CP2114_RAM_CONFIG_STRUCT)) _Pre_defensive_ PCP2114_RAM_CONFIG_STRUCT pCP2114RamConfigStruct
375 );
376 
377 // CP2114_SetDacRegisters
403 _Check_return_
405 _Success_(return == HID_UART_SUCCESS)
407 CP2114_SetDacRegisters(
408  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
409  _In_reads_bytes_(dacConfigBufferLengthInBytes) _Pre_defensive_ const BYTE* pDacConfigBuffer,
410  _In_ _Pre_defensive_ const BYTE dacConfigBufferLengthInBytes
411 );
412 
413 // CP2114_GetDacRegisters
434 _Check_return_
436 _Success_(return == HID_UART_SUCCESS)
438 CP2114_GetDacRegisters(
439  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
440  _In_ _Pre_defensive_ const BYTE dacStartAddress,
441  _In_ _Pre_defensive_ const BYTE dacRegistersToRead,
442  _Out_ _Pre_defensive_ BYTE* pDacConfigBuffer
443 );
444 
445 // CP2114_GetOtpConfig
457 _Check_return_
459 _Success_(return == HID_UART_SUCCESS)
461 CP2114_GetOtpConfig(
462  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
463  _In_ _Pre_defensive_ const BYTE cp2114ConfigNumber,
464  _Out_writes_bytes_(sizeof(CP2114_OTP_CONFIG_GET)) _Pre_defensive_ PCP2114_OTP_CONFIG_GET pCP2114ConfigStruct
465 );
466 
467 // CP2114_CreateOtpConfig
490 _Check_return_
492 _Success_(return == HID_UART_SUCCESS)
494 CP2114_CreateOtpConfig(
495  _In_ _Pre_defensive_ HID_UART_DEVICE device,
496  _In_ _Pre_defensive_ WORD configBufferLengthInBytes,
497  _In_reads_bytes_(configBufferLengthInBytes) _Pre_defensive_ BYTE* pConfigBuffer
498 );
499 
500 // CP2114_SetBootConfig
511 _Check_return_
513 _Success_(return == HID_UART_SUCCESS)
515 CP2114_SetBootConfig(
516  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
517  _In_ _Pre_defensive_ const BYTE cp2114ConfigNumber
518 );
519 
520 // CP2114_ReadOTP
536 _Check_return_
538 _Success_(return == HID_UART_SUCCESS)
540 CP2114_ReadOTP(
541  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
542  _In_ _Pre_defensive_ const UINT cp2114Address,
543  _Out_writes_bytes_(ReadLengthInBytes) _Pre_defensive_ BYTE* pReadBuffer,
544  _In_ _Pre_defensive_ const UINT ReadLengthInBytes
545 );
546 
547 // CP2114_WriteOTP
562 _Check_return_
564 _Success_(return == HID_UART_SUCCESS)
566 CP2114_WriteOTP(
567  _In_ _Pre_defensive_ HID_UART_DEVICE device,
568  _In_ _Pre_defensive_ UINT cp2114Address,
569  _In_reads_bytes_(writeLengthInBytes) _Pre_defensive_ BYTE* pWriteBuffer,
570  _In_ _Pre_defensive_ UINT writeLengthInBytes
571 );
572 
573 // CP2114_I2cWriteData
588 _Check_return_
590 _Success_(return == HID_UART_SUCCESS)
592 CP2114_I2cWriteData(
593  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
594  _In_ _Pre_defensive_ const BYTE slaveAddress,
595  _In_reads_bytes_(writeLength) _Pre_defensive_ const BYTE* pWriteBuffer,
596  _In_ _Pre_defensive_ const BYTE writeLengthInBytes
597 );
598 
599 // CP2114_I2cReadData
617 _Check_return_
619 _Success_(return == HID_UART_SUCCESS)
621 CP2114_I2cReadData(
622  _In_ _Pre_defensive_ const HID_UART_DEVICE device,
623  _In_ _Pre_defensive_ const BYTE slaveAddress,
624  _In_reads_bytes_(WriteLengthInBytes) _Pre_defensive_ const BYTE* pWriteBuffer,
625  _In_ _Pre_defensive_ const BYTE WriteLengthInBytes,
626  _Out_writes_bytes_(ReadLengthInBytes) _Pre_defensive_ BYTE* pReadBuffer,
627  _In_ _Pre_defensive_ const BYTE ReadLengthInBytes
628 );
629 
630 #ifdef __cplusplus
631 }
632 #endif // __cplusplus
633 
634 #endif // SLAB_CP2114_H
CP2114_OTP_CONFIG OtpConfig
otp config
Definition: SLABCP2114.h:142
if config_version == CP2114_CONFIG_VERSION_B02
tbd
Definition: CP2114_Common.h:115
Definition: SLABCP2114.h:118
HID_UART_STATUS
Definition: SLABHIDtoUART.h:85
#define CP2114_PIN_CONFIG_SIZE
Config size, number of indexes.
Definition: SLABCP2114.h:72
if config_version == CP2114_CONFIG_VERSION_B01
This value should never be returned.
Definition: SLABHIDtoUART.h:104
Success.
Definition: SLABHIDtoUART.h:86
#define WINAPI
WINAPI.
Definition: CP210xManufacturingDLL.h:70
unsigned short U16
unsigned uint 16
Definition: SLABHIDtoUART.h:351
Definition: SLABCP2114.h:139
#define HID_TO_UART_API
HID to UART API.
Definition: SLABHIDtoUART.h:72
unsigned char BYTE
Byte definition.
Definition: silabs_defs.h:41
CP2114 Capabilities.
Definition: CP2114_Common.h:91
U16 Length
length
Definition: SLABCP2114.h:141
void * HID_UART_DEVICE
HID to UART device.
Definition: SLABHIDtoUART.h:345