Silicon Labs Host Libraries
slabiop.h
1 //-----------------------------------------------------------------------------
2 // slabiop.h
3 //-----------------------------------------------------------------------------
4 // Copyright 2017 Silicon Laboratories Inc.
5 // http://www.silabs.com
6 //-----------------------------------------------------------------------------
7 
9 
10 #if (_MSC_VER > 1000)
11 #pragma once
12 #endif
13 
14 #ifndef HOST_LIB_SLABIOP_INCLUDE_SLABIOP_H_INCLUDED_PV1HTEYUPA
15 #define HOST_LIB_SLABIOP_INCLUDE_SLABIOP_H_INCLUDED_PV1HTEYUPA
16 
55 
56 #include <stddef.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <stdio.h>
60 #include <stdint.h> // For C99 fixed sized types
61 #include <stdbool.h> // For C99 _Bool
62 
63 #include "silabs_defs.h"
64 #include "silabs_sal.h"
65 
66 #ifdef _WIN32
67 #if defined(SLABIOPLIB_EXPORTS)
68 #define SLABIOPLIB_API
69 #else
70 #if defined(SILABS_STATIC_LINK_ALL_LIBS)
71 #define SLABIOPLIB_API
72 #pragma comment (lib, "slabiop.static.lib")
73 #else // defined(SILABS_STATIC_LINK_ALL_LIBS)
74 #define SLABIOPLIB_API __declspec(dllimport)
75 #pragma comment (lib, "slabiop.lib")
76 #endif // defined(SILABS_STATIC_LINK_ALL_LIBS)
77 #endif // defined(SLABIOPLIB_EXPORTS)
78 #else // !_WIN32
79 #define SLABIOPLIB_API
80 #define WINAPI
81 #endif // !_WIN32
82 
85 typedef enum _SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS {
87  , SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS_UART = ((uint8_t)(0xFF & 0x01))
88  , SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS_IOP = ((uint8_t)(0xFF & 0x02))
91 _Check_return_
92 _Success_(return == TRUE)
93 __inline static BOOL IsValidSILABS_IOP_INTERFACE_ALTERNATE_SETTINGS(_In_ const SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS _a) { return (SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS_IDLE <= _a) && (_a <= SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS_IOP); }
96 typedef enum _DEVICE_I2C_STATUS {
104 
106 // Structures
110 
112 #pragma pack(1)
113 typedef _Struct_size_bytes_(6) struct _SILABS_IOP_ACCESSORY_INFO {
114  uint16_t PartID;
115  uint16_t OptionID;
116  uint16_t ProtocolVersion;
118 #pragma pack()
119 
121 #pragma pack(1)
122 typedef _Struct_size_bytes_(7) struct _SILABS_IOP_PORT_CONFIGURATION {
123  uint8_t PortNumber;
124  uint16_t PinFunction;
125  uint16_t PinDirection;
126  uint16_t PinOutMode;
128 #pragma pack()
129 
131 #pragma pack(1)
132 typedef _Struct_size_bytes_(5) struct _SILABS_IOP_DIGITAL_PORT_VALUE {
133  uint8_t PortNumber;
134  uint16_t PinMask;
135  uint16_t PortValue;
137 #pragma pack()
138 
140 #pragma pack(1)
141 typedef _Struct_size_bytes_(7) struct _SILABS_IOP_ANALOG_PIN_VALUE {
142  uint8_t PinNumber;
143  uint16_t PinValue;
144  uint32_t TimeStamp;
146 #pragma pack()
147 
149 #pragma pack(1)
150 typedef _Struct_size_bytes_(1) struct _SILABS_IOP_SERIAL_STATE {
151  uint8_t ReceiveError;
153 #pragma pack()
154 
156 
158 // Exported API Functions
160 
163 
164 #ifdef __cplusplus
165 extern "C" {
166 #endif // __cplusplus
167 
177 _Check_return_
179 _Success_(return == SILABS_STATUS_SUCCESS)
182  _Out_writes_bytes_opt_(sizeof(uint8_t)) _Pre_defensive_ uint8_t* major,
183  _Out_writes_bytes_opt_(sizeof(uint8_t)) _Pre_defensive_ uint8_t* minor,
184  _Out_writes_bytes_opt_(sizeof(BOOL)) _Pre_defensive_ BOOL* pbIsReleaseBuild
185 );
186 
187 
197 _Check_return_
199 _Success_(return == SILABS_STATUS_SUCCESS)
202  _In_ _Pre_defensive_ const uint16_t Vid,
203  _In_ _Pre_defensive_ const uint16_t Pid,
204  _Out_writes_bytes_(sizeof(uint32_t)) _Pre_defensive_ uint32_t *pNumDevices
205 );
206 
222 _Check_return_
224 _Success_(return == SILABS_STATUS_SUCCESS)
227  _In_ _Pre_defensive_ const uint32_t DeviceIndex,
228  _Out_writes_bytes_(*pLenInBytes) char *pDevicePathString,
229  _In_ _Pre_defensive_ const size_t DevicePathStringLenInBytes,
230  _Out_writes_bytes_(sizeof(size_t)) _Pre_defensive_ size_t *pLenInBytes
231 );
232 
242 _Check_return_
244 _Success_(return == SILABS_STATUS_SUCCESS)
247  _In_ _Pre_defensive_ const uint32_t DeviceIndex,
248  _Out_writes_bytes_(sizeof(uint16_t)) _Pre_defensive_ uint16_t *pVid,
249  _Out_writes_bytes_(sizeof(uint16_t)) _Pre_defensive_ uint16_t *pPid
250 );
251 
264 _Check_return_
266 _Success_(return == SILABS_STATUS_SUCCESS)
269  _In_ _Pre_defensive_ const uint32_t DeviceIndex,
270  _Out_writes_bytes_(*pLenInBytes) char *pSerialNumberString,
271  _In_ _Pre_defensive_ const size_t SerialNumberStringLenInBytes,
272  _Out_writes_bytes_(sizeof(size_t)) _Pre_defensive_ size_t *pLenInBytes
273 );
274 
275 
284 _Check_return_
286 _Success_(SILABS_STATUS_SUCCESS)
288 IOP_Open(
289  _In_ _Pre_defensive_ const uint32_t DeviceIndex,
290  _Out_writes_bytes_(sizeof(HANDLE)) _Pre_defensive_ PHANDLE pHandle
291 );
292 
301 _Check_return_
303 _Success_(SILABS_STATUS_SUCCESS)
306  _In_ _Pre_defensive_ const char *pDevicePath,
307  _Out_writes_bytes_(sizeof(HANDLE)) _Pre_defensive_ PHANDLE pHandle
308 );
309 
310 
322 _Success_(SILABS_STATUS_SUCCESS)
324 IOP_Close(
325  _In_ _Pre_defensive_ const HANDLE hHandle
326 );
327 
337 _Check_return_
339 _Success_(SILABS_STATUS_SUCCESS)
342  _In_ _Pre_defensive_ const HANDLE hHandle,
343  _Out_writes_bytes_(sizeof(SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS)) _Pre_defensive_ SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS *pAlternateSettingNumber
344 );
354 _Check_return_
356 _Success_(SILABS_STATUS_SUCCESS)
359  _In_ _Pre_defensive_ const HANDLE hHandle,
360  _In_ _Pre_defensive_ const SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS AlternateSettingNumber
361 );
369 _Check_return_
371 _Success_(SILABS_STATUS_SUCCESS)
374  _In_ _Pre_defensive_ const HANDLE hHandle
375 );
383 _Check_return_
385 _Success_(SILABS_STATUS_SUCCESS)
388  _In_ _Pre_defensive_ const HANDLE hHandle
389 );
397 _Check_return_
399 _Success_(SILABS_STATUS_SUCCESS)
402  _In_ _Pre_defensive_ const HANDLE hHandle
403 );
404 
407 
424 _Check_return_
426 _Success_(SILABS_STATUS_SUCCESS)
428 IOP_Read(
429  _In_ _Pre_defensive_ const HANDLE hHandle,
430  _Out_writes_bytes_(BufferLenInBytes) uint8_t *pBuffer,
431  _In_range_(0, 222) const size_t BufferLenInBytes,
432  _Out_range_(0, BufferLenInBytes) size_t *pBytesRead,
433  _In_opt_ LPOVERLAPPED o = NULL
434 );
435 
452 _Check_return_
454 _Success_(SILABS_STATUS_SUCCESS)
456 IOP_Write(
457  _In_ _Pre_defensive_ const HANDLE hHandle,
458  _In_reads_bytes_(BufferLenInBytes) _Pre_defensive_ uint8_t *pBuffer,
459  _In_range_(0, 222) _Pre_defensive_ const size_t BufferLenInBytes,
460  _Out_range_(0, BufferLenInBytes) _Pre_defensive_ size_t *pBytesWritten,
461  _In_opt_ LPOVERLAPPED o = NULL
462 );
464 
467 
468 
482 _Check_return_
484 _Success_(SILABS_STATUS_SUCCESS)
487  _In_ _Pre_defensive_ const HANDLE hHandle,
488  _Out_writes_bytes_(sizeof(SILABS_IOP_ACCESSORY_INFO)) _Pre_defensive_ SILABS_IOP_ACCESSORY_INFO *pAccessoryInfo
489 );
490 
507 _Check_return_
509 _Success_(SILABS_STATUS_SUCCESS)
512  _In_ _Pre_defensive_ const HANDLE hHandle,
513  _In_ _Pre_defensive_ const uint8_t PortNumber,
514  _Out_writes_bytes_(sizeof(SILABS_IOP_PORT_CONFIGURATION)) _Pre_defensive_ SILABS_IOP_PORT_CONFIGURATION *pPortConfiguration
515 );
516 
535 _Check_return_
537 _Success_(SILABS_STATUS_SUCCESS)
540  _In_ _Pre_defensive_ const HANDLE hHandle,
541  _In_ _Pre_defensive_ const uint8_t PortNumber,
542  _In_ _Pre_defensive_ const uint16_t PinMask,
543  _Out_writes_bytes_(sizeof(SILABS_IOP_DIGITAL_PORT_VALUE)) _Pre_defensive_ SILABS_IOP_DIGITAL_PORT_VALUE *pDigitalPortValue
544 );
563 _Check_return_
565 _Success_(SILABS_STATUS_SUCCESS)
568  _In_ _Pre_defensive_ const HANDLE hHandle,
569  _In_ _Pre_defensive_ const uint8_t PortNumber,
570  _In_reads_bytes_(sizeof(SILABS_IOP_DIGITAL_PORT_VALUE)) _Pre_defensive_ SILABS_IOP_DIGITAL_PORT_VALUE *pDigitalPortValue
571 );
572 
587 _Check_return_
589 _Success_(SILABS_STATUS_SUCCESS)
592  _In_ _Pre_defensive_ const HANDLE hHandle,
593  _In_ _Pre_defensive_ const uint8_t PinNumber,
594  _Out_writes_bytes_(sizeof(SILABS_IOP_ANALOG_PIN_VALUE)) _Pre_defensive_ SILABS_IOP_ANALOG_PIN_VALUE *pAnalogPinValue
595 );
596 
610 _Check_return_
612 _Success_(SILABS_STATUS_SUCCESS)
615  _In_ _Pre_defensive_ const HANDLE hHandle,
616  _Out_writes_bytes_(sizeof(SILABS_IOP_SERIAL_STATE)) _Pre_defensive_ SILABS_IOP_SERIAL_STATE *pSerialState
617 );
618 
646 _Check_return_
648 _Success_(SILABS_STATUS_SUCCESS)
651  _In_ _Pre_defensive_ const HANDLE hHandle,
652  _In_ _Pre_defensive_ const uint8_t SlaveAddress,
653  _In_reads_bytes_opt_(WriteMsgLength) _Pre_defensive_ const uint8_t *WriteMsg,
654  _In_opt_ _Pre_defensive_ const uint8_t WriteMsgLength,
655  _Out_writes_bytes_opt_(ReadMsgLength) _Pre_defensive_ uint8_t *ReadMsg,
656  _In_opt_ _Pre_defensive_ const uint8_t ReadMsgLength,
657  _Out_writes_bytes_opt_(sizeof(uint8_t)) _Pre_defensive_ uint8_t *pNumBytesRead,
658  _Out_writes_bytes_opt_(sizeof(DEVICE_I2C_STATUS)) _Pre_defensive_ DEVICE_I2C_STATUS *pDeviceI2CStatus
659 );
660 
662 
663 
664 
678 _Check_return_
680 _Success_(return == SILABS_STATUS_SUCCESS)
683  _In_ _Pre_defensive_ const HANDLE hHandle,
684  _Out_writes_bytes_(DeviceStringLenInBytes) char *pDeviceString,
685  _In_ _Pre_defensive_ const size_t DeviceStringLenInBytes,
686  _Out_writes_bytes_(sizeof(size_t)) _Pre_defensive_ size_t * pLenInBytes
687 );
688 
702 _Check_return_
704 _Success_(return == SILABS_STATUS_SUCCESS)
707  _In_ _Pre_defensive_ const HANDLE hHandle,
708  _Out_writes_bytes_(DeviceStringLenInBytes) char *pDeviceString,
709  _In_ _Pre_defensive_ const size_t DeviceStringLenInBytes,
710  _Out_writes_bytes_(sizeof(size_t)) _Pre_defensive_ size_t *pLenInBytes
711 );
712 
726 _Check_return_
728 _Success_(return == SILABS_STATUS_SUCCESS)
731  _In_ _Pre_defensive_ const HANDLE hHandle,
732  _Out_writes_bytes_(DeviceStringLenInBytes) char *pDeviceString,
733  _In_ _Pre_defensive_ const size_t DeviceStringLenInBytes,
734  _Out_writes_bytes_(sizeof(size_t)) _Pre_defensive_ size_t * pLenInBytes
735 );
736 
737 
751 _Check_return_
753 _Success_(return == SILABS_STATUS_SUCCESS)
756  _In_ _Pre_defensive_ const HANDLE hHandle,
757  _Out_writes_bytes_(DeviceStringLenInBytes) char *pDeviceString,
758  _In_ _Pre_defensive_ const size_t DeviceStringLenInBytes,
759  _Out_writes_bytes_(sizeof(size_t)) _Pre_defensive_ size_t *pLenInBytes
760 );
761 
762 
763 #ifdef __cplusplus
764 }
765 #endif // __cplusplus
766 
768 
770 
771 #endif // HOST_LIB_SLABIOP_INCLUDE_SLABIOP_H_INCLUDED_PV1HTEYUPA
772 
774 // End of file
SILABS_STATUS IOP_GetNumDevices(const uint16_t Vid, const uint16_t Pid, uint32_t *pNumDevices)
Determines the number of devices of interest connected to the system.
Idle. Has no endpoints and is used to disable the IO link.
Definition: slabiop.h:86
SILABS_STATUS IOP_SetCurrentAlternateSetting(const HANDLE hHandle, const SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS AlternateSettingNumber)
Set the current Alternate Setting on the device.
SILABS_STATUS IOP_GetDigitalPort(const HANDLE hHandle, const uint8_t PortNumber, const uint16_t PinMask, SILABS_IOP_DIGITAL_PORT_VALUE *pDigitalPortValue)
Returns current digital port value of the device.
SILABS_STATUS IOP_GetVIDPIDFromDevicePath(const uint32_t DeviceIndex, uint16_t *pVid, uint16_t *pPid)
derives the device instance&#39;s VID and PID from the device instance&#39;s DevicePath returned by IOP_GetDe...
SILABS_STATUS IOP_GetSerialState(const HANDLE hHandle, SILABS_IOP_SERIAL_STATE *pSerialState)
Returns error status for serial session.
uint16_t ProtocolVersion
IOP protocol version.
Definition: slabiop.h:116
SILABS_STATUS IOP_DoI2CTransfer(const HANDLE hHandle, const uint8_t SlaveAddress, _In_reads_bytes_opt_(WriteMsgLength) const uint8_t *WriteMsg, const uint8_t WriteMsgLength, uint8_t *ReadMsg, const uint8_t ReadMsgLength, uint8_t *pNumBytesRead, DEVICE_I2C_STATUS *pDeviceI2CStatus)
Requests that the specified I2C transfer be completed and the results returned.
SILABS_STATUS IOP_GetPortConfiguration(const HANDLE hHandle, const uint8_t PortNumber, SILABS_IOP_PORT_CONFIGURATION *pPortConfiguration)
Returns pin configuration for digital port of the device.
uint8_t PinNumber
The target analog pin.
Definition: slabiop.h:142
uint8_t ReceiveError
Receive stream errors. 0 = no errors, non-zero = receive overflow.
Definition: slabiop.h:151
#define WINAPI
WIN API.
Definition: slabiop.h:80
an unknown Alternate Settings
Definition: slabiop.h:89
SILABS_STATUS IOP_GetDeviceSerialNumberString(const HANDLE hHandle, char *pDeviceString, const size_t DeviceStringLenInBytes, size_t *pLenInBytes)
Return the device-defined string that contains a manufacturer-determined serial number for the device...
SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS
Definition: slabiop.h:85
SILABS_STATUS IOP_SetCurrentAlternateSettingIOP(const HANDLE hHandle)
Set the current Alternate Setting on the device to IOP.
DEVICE_I2C_STATUS
Definition: slabiop.h:96
no error
Definition: silabs_defs.h:262
SILABS_STATUS IOP_GetDeviceManufacturerString(const HANDLE hHandle, char *pDeviceString, const size_t DeviceStringLenInBytes, size_t *pLenInBytes)
Return the device-defined string containing the name of the manufacturer of this device.
SILABS_STATUS IOP_SetCurrentAlternateSettingIDLE(const HANDLE hHandle)
Set the current Alternate Setting on the device to IDLE.
Serial State.
Definition: slabiop.h:150
uint16_t PinOutMode
Bitmask: 0 = Open-Drain, 1 = Push-Pull.
Definition: slabiop.h:126
SILABS_STATUS IOP_SetCurrentAlternateSettingUART(const HANDLE hHandle)
Set the current Alternate Setting on the device to UART.
uint8_t PortNumber
The target digital port.
Definition: slabiop.h:123
SILABS_STATUS IOP_GetAnalogPin(const HANDLE hHandle, const uint8_t PinNumber, SILABS_IOP_ANALOG_PIN_VALUE *pAnalogPinValue)
Returns current analog pin value of the device.
uint16_t OptionID
Customer specified value read from the configuration.
Definition: slabiop.h:115
uint32_t TimeStamp
32-bit Timestamp. 1 msec resolution.
Definition: slabiop.h:144
SILABS_STATUS IOP_GetLibraryVersion(uint8_t *major, uint8_t *minor, BOOL *pbIsReleaseBuild)
Reads and returns the interface library version from the DLL or static library.
SILABS_STATUS IOP_GetDeviceFirmwareVersionString(const HANDLE hHandle, char *pDeviceString, const size_t DeviceStringLenInBytes, size_t *pLenInBytes)
Return the device-defined string that contains a manufacturer-determined Firmware Version for the dev...
uint16_t PinDirection
Bitmask: 0 = Input, 1 = Output.
Definition: slabiop.h:125
Digital Port Value.
Definition: slabiop.h:132
Analog Pin Value.
Definition: slabiop.h:141
SILABS_STATUS IOP_Read(const HANDLE hHandle, uint8_t *pBuffer, const size_t BufferLenInBytes, size_t *pBytesRead, LPOVERLAPPED o=NULL)
Reads from the device into a buffer.
SILABS_STATUS IOP_Open(const uint32_t DeviceIndex, PHANDLE pHandle)
Opens a handle to the device.
uint8_t PortNumber
The target digital port.
Definition: slabiop.h:133
Accessory Information.
Definition: slabiop.h:113
I/O Protocol. Has one Bulk IN and one Bulk OUT endpoint for transporting IOP messages.
Definition: slabiop.h:88
an otherwise unclassified error occurred
Definition: silabs_defs.h:280
Parameter error (read or write count out of range).
Definition: slabiop.h:101
uint16_t PinMask
Bitmask indicates which pins changed or were queried by the iop_GetDigitalPort message.
Definition: slabiop.h:134
I2C transfer completed without errors.
Definition: slabiop.h:97
Port Configuration.
Definition: slabiop.h:122
UART. Has one Bulk IN and one Bulk OUT endpoint for transporting UART data.
Definition: slabiop.h:87
uint16_t PortValue
Bitfield returns current digital pin values (all pins are returned).
Definition: slabiop.h:135
SILABS_STATUS IOP_SetDigitalPort(const HANDLE hHandle, const uint8_t PortNumber, SILABS_IOP_DIGITAL_PORT_VALUE *pDigitalPortValue)
writes one or more digital output pins in a port.
uint16_t PartID
Encoded part number of the chip (0x1400 for CP2615 Rev 1.0).
Definition: slabiop.h:114
SILABS_STATUS IOP_GetDeviceProductString(const HANDLE hHandle, char *pDeviceString, const size_t DeviceStringLenInBytes, size_t *pLenInBytes)
Return the device-defined string that contains a description of the device.
uint16_t PinFunction
Bitmask: 0 = Alternate, 1 = GPIO.
Definition: slabiop.h:124
SILABS_STATUS IOP_OpenByDevicePath(const char *pDevicePath, PHANDLE pHandle)
Opens a handle to the device.
SILABS_STATUS IOP_GetCurrentAlternateSetting(const HANDLE hHandle, SILABS_IOP_INTERFACE_ALTERNATE_SETTINGS *pAlternateSettingNumber)
Returns an indication of the current Alternate Setting in use.
uint16_t PinValue
Value read from the analog pin. (10-bit right-justified, Vdd fullscale for CP2615) ...
Definition: slabiop.h:143
SILABS_STATUS IOP_GetDevicePathString(const uint32_t DeviceIndex, char *pDevicePathString, const size_t DevicePathStringLenInBytes, size_t *pLenInBytes)
return the device instance&#39;s DevicePath string
SILABS_STATUS IOP_Write(const HANDLE hHandle, uint8_t *pBuffer, const size_t BufferLenInBytes, size_t *pBytesWritten, LPOVERLAPPED o=NULL)
Write buffer to device.
SILABS_STATUS
Definition: silabs_defs.h:261
I2C transfer timed out (slave did not respond).
Definition: slabiop.h:100
#define SLABIOPLIB_API
Silabs IOP lib API.
Definition: slabiop.h:79
SILABS_STATUS IOP_Close(const HANDLE hHandle)
Closes an open handle to the device.
I2C bus error (NAK received).
Definition: slabiop.h:98
SILABS_STATUS IOP_GetAccessoryInfo(const HANDLE hHandle, SILABS_IOP_ACCESSORY_INFO *pAccessoryInfo)
Returns accessory identification information of the device.
SILABS_STATUS IOP_GetSerialNumberStringFromDevicePath(const uint32_t DeviceIndex, char *pSerialNumberString, const size_t SerialNumberStringLenInBytes, size_t *pLenInBytes)
derives the device instance&#39;s Serial Number string from the device instance&#39;s DevicePath returned by ...
Writing to configuration memory failed because the configuration is locked.
Definition: slabiop.h:102
I2C bus was busy.
Definition: slabiop.h:99