Skip to main content

Silabs CP2110 USB HID to UART bridge library

Project description

# Silicon Labs cp2110 Python library

This library provides a Python interface to the [Silicon Labs CP2110](https://www.silabs.com/documents/public/data-sheets/CP2110.pdf) HID USB to UART bridge.

At this point in time this library presents only the parts of the [available API](https://www.silabs.com/documents/public/application-notes/AN434-CP2110-4-Interface-Specification.pdf) that are required for basic UART access.

# cp2110 Installation

Install via pip: `python -m pip install cp2110`.

The cp2110 library depends on the [pyhidapi](https://github.com/apmorton/pyhidapi) Python module, which itself requires the `hidapi` shared library. On Linux distributions, this is generally in the repositories (for instance, under Debian you can install either libhidapi-hidraw0 or libhidapi-libusb0 depending on which backend you want to use).

# Example usage

```
import cp2110
import time

# This will raise an exception if a device is not found. Called with no
# parameters, this looks for the default (VID, PID) of the CP2110, which are
# (0x10c4, 0xEA80).
try:
d = cp2110.CP2110Device()
except:
pass

# In some cases the device maker will override the VID and/or PID at the
# factory, so you'll need to pass parameters
try:
cp2110.CP2110Device(vid=0xDEAD, pid=0xBEEF)
except:
pass

# You can also find a device by path.
cp2110.CP2110Device(path='/dev/hidraw0')

# If you want to avoid the exception or want to detect the presence of a
# device without creating an object as a side-effect, use the
# `cp2110.enumerate` function. This has the same default values as the
# `CP2110Device` constructor.
usb_info = cp2110.enumerate()
if usb_info:
print(usb_info.as_dict())

usb_info = cp2110.enumerate(vid=0xDEAD, pid=0xBEEF)
if usb_info:
print(usb_info.as_dict())

# Fetch the current uart configuration. This is the UART connection from the
# CP2110 to the microcontroller (or whatever) it's wired up to.
c = d.get_uart_config()

# The UART settings are dictated by the device that embeds the CP2110. It
# may be configured correctly by default, or you may need to set manually.
d.set_uart_config(UARTConfig(
baud=38400,
parity=cp2110.PARITY.NONE,
flow_control=cp2110.FLOW_CONTROL.DISABLED,
data_bits=cp2110.DATA_BITS.EIGHT,
stop_bits=STOP_BITS.SHORT))

# If you ever need to disable the UART, you can.
d.disable_uart()

# And you can clear any pending data in the on-chip I/O buffers.
d.purge_fifos() # The default is cp2110.FIFO.BOTH
d.purge_fifos(cp2110.FIFO.TX)
d.purge_fifos(cp2110.FIFO.RX)

# Check if the UART is enabled.
print(d.is_uart_enabled())

# The UART in your device may need to be explicitly enabled, particularly if
# you've already explicitly disabled it as in this example.
d.enable_uart()

# The write method accepts byte strings or arrays of ints.
d.write(b'hello world')
d.write([0x01, 0xff])

# The default read size will return 63 bytes (at most), which is the maximum
# supported by this chip. Reads do not block.
rv = d.read()

```



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycp2110-1.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycp2110-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pycp2110-1.0.0.tar.gz.

File metadata

  • Download URL: pycp2110-1.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.3

File hashes

Hashes for pycp2110-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2fd3dc03070561b12e42ec63bbcdc01bb7d9a474d940345e7a4c8f26ae3c0f8b
MD5 2b92e0924f29ecffee7ece576798fb31
BLAKE2b-256 a68f4c1ca1871e72357c1194e61db4471f2fb6639567dd95d6890ea9cc627ca5

See more details on using hashes here.

File details

Details for the file pycp2110-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycp2110-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.3

File hashes

Hashes for pycp2110-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e56e74f6dc02f36d541db88fd53d0ab120eaf374b66729c786b2807dbf44d19
MD5 240feb5ff58ec415be14e70a5ee5bb58
BLAKE2b-256 a534008e5d8211296e7ae14c216ad1d5bd3e401b5d5930b8e65a3cb9188a7702

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page