Skip to main content

python wrapper for I2C communications with ORCASEMI devices through FTDI

Project description

PYORCAI2C

INSTALL

    pip install pyorcai2c

BASIC USAGE

    import pyorcai2c
    i2c = ftdi(b'SERIAL_NUMBER')

    res = i2c.write(slave=ANY_NUMBER, target=ANY_NUMBER, data=ANY_NUMBER)
    print(res)

    res = i2c.read(slave=ANY_NUMBER, target=ANY_NUMBER)
    print(res)

RETRIEVING FTDI BOARD SERIAL NUMBER

If you don't know the serial number of the FTDI board you are using do the following:

    import ftd2xx
    available_devices = ftd2xx.createDeviceInfoList()
    available_devices = ftd2xx.listDevices()

BURST READ WRITE USAGE

i2c.write always requires the slave argument as a integer positive number. No other arguments are mandatory.

    # ping slave
    res = i2c.write(slave=ANY_NUMBER)
    print(res)

    # i2c command
    res = i2c.write(slave=ANY_NUMBER, target=COMMAND_AS_A NUMBER)
    print(res)

target argument of i2c.write can eiher be a single integer or a dictionary in the form address_as_integer: data_as_integer. i2c.write will optimize i2c communication by performing the minimum number of burst write needed to complete the request. If target argument of i2c.write is a number data argument is also needed. If target argument of i2c.write is an {int: int} dictionary the data argument will be ignored.

A burst read of n bytes can easely be performed through one of the following ways:

    # read burts by specifing start address and number of bytes
    res = i2c.read(slave=ANY_NUMBER, target=ANY_NUMBER, n=n)
    print(res)

    # read burst by specifing target as an array
    res = i2c.read(slave=ANY_NUMBER, target=[ANY_NUMBER_1, ANY_NUMBER_2, ANY_NUMBER_3])
    print(res)

target argument of i2c.read can eiher be a single integer or a list of integers. i2c.read will optimize i2c communication by performing the minimum number of burst read needed to complete the request. If target argument of i2c.read is a number n argument is defaulted to 1 if absent. If target argument of i2c.read is a list of integers the n argument will be ignored.

I2C USAGE BASED ON REGISTER MAP

To import ORCA products register map do the following:

    import os
    cwd = os.getcwd()
    regmap_filepath = os.path.join(cwd, 'regmaps', 'pmic01.json')
    regmap = i2c.load_register_map(regmap_filepath)

Loading a register map will allow for both register based and field based communication.

    res = i2c.write(slave=ANY_NUMBER, target=VALID_REGISTER_NAME, data=ANY_NUMBER)
    print(res)

    res = i2c.write(slave=ANY_NUMBER, target=VALID_FIELD_NAME, data=ANY_NUMBER)
    print(res)

    res = i2c.read(slave=ANY_NUMBER, target=VALID_REGISTER_NAME)
    print(res)

    res = i2c.read(slave=ANY_NUMBER, target=VALID_FIELD_NAME)
    print(res)

ADVANCED USAGE:

All of the above ways of communications can be mixed up without much restraint and in a pretty natual way. Mixing up integers, register_names of field_names as the target arguments. The following strange calls will simply and just work. The module will take care of optimizing the I2C communications by minimizing it through as many burst command as possible. The module response structure will reflect the request for the data part of the response while the acks part will be based on starting register address of the burst command.

    res = i2c.read(
        slave=slave, 
        target=[
            0x04, 
            0x02, 
            0x05, 
            0xA1, 
            0xA3, 
            0xA2, 
            0x06, 
            'ChargeCtrl1', 
            'ChargeCtrl2', 
            'LDO1Mode', 
            'LDO2Ctrl', 
            'LDO2Voltage', 
            'tst_bias_a',
            'TstCntrl7',
            'LDO1Voltage'
        ]
    )
    print(res)

    res = i2c.write(
        slave=slave, 
        target={
        0x02:0xAA,
        0x01:0xEA,
        0x10:0xCD,
        0x05:0xFE,
        0x06:0xBB,
        'LDO2Voltage':0x55,
        'Buck1Ctrl2':0x33,
        'unused_Buck1Ctrl2_b2':1,
        'unused_Buck1Ctrl2_b4':1,
        'unused_Buck1Ctrl2_b5':0,
        'Buck1Ton':255,
        'Buck1VRegA':0
        }
    )
    print(res)

additional code examples:

You can find additional examples here: https://github.com/orcasemi/pyorcai2c/blob/main/tests/test.py and here: https://github.com/orcasemi/pyorcai2c/blob/main/tests/debug.py

co-development (ORCA DEVELOPMENT TEAM ONLY)

  1. clone the repository locally
    git clone git@github.com:orcasemi/pyorcai2c.git

if you get an error about not having enough clearance to clone it please follow this tutorial to setup a github ssh-key and contact orcasemi github organization to be added as a member

  1. setup and activate virtual envinroment
    cd pyorcai2c
    python -m venv
  1. if you are on windows and you have never done that before you need to enable powershell to run scripts in order to activate the newly created virtual envinroment
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

run that from an admin elevated powershell

  1. activate the virtual envinroment
    .\venv\Scripts\activate 

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

pyorcai2c-0.0.5.tar.gz (84.2 kB view details)

Uploaded Source

Built Distribution

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

pyorcai2c-0.0.5-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pyorcai2c-0.0.5.tar.gz.

File metadata

  • Download URL: pyorcai2c-0.0.5.tar.gz
  • Upload date:
  • Size: 84.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for pyorcai2c-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6cc21c39820822abf8a61b1d35464732be1d774a1a307c47a48da4d7fe26c839
MD5 754a6bcba584308cccfa7df2ef36581e
BLAKE2b-256 ecfb2887f88f5551b2cafdbc72b64986a5eb59ffaeadc0465c356305e97a253c

See more details on using hashes here.

File details

Details for the file pyorcai2c-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pyorcai2c-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for pyorcai2c-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9bc9149ae6835c5a1278cdaf7160dabbb5e06c6315579a410e14b3dc4b68e19d
MD5 a4a7df5cdc00d83f67462e2c44e73c33
BLAKE2b-256 4e5001a80ebde32bbd60d946420e8d6059f44055a5760fadc886b2375d2bf0a7

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