Skip to content

Group ns-i2c

Modules > ns-i2c

Modules

Type Name
module Ns-MAX86150
module Ns-MPU6050

Classes

Type Name
struct ns_i2c_config_t
i2c configuration
struct ns_i2c_msg_t

Public Types

Type Name
enum ns_i2c_status_e
enum ns_i2c_xfer_flag_e

Public Attributes

Type Name
const ns_core_api_t ns_i2c_V0_0_1
const ns_core_api_t ns_i2c_V1_0_0
const ns_core_api_t ns_i2c_current_version
const ns_core_api_t ns_i2c_oldest_supported_version

Public Functions

Type Name
uint32_t ns_i2c_interface_init (ns_i2c_config_t * cfg, uint32_t speed)
Initialize I2C on one of the IOM (IO managers)
uint32_t ns_i2c_read (ns_i2c_config_t * cfg, const void * buf, uint32_t size, uint16_t addr)
Perform low-level I2C read using IOM transfer.
uint32_t ns_i2c_read_reg (ns_i2c_config_t * cfg, uint32_t devAddr, uint8_t regAddr, uint8_t * value, uint8_t mask)
Read 8-bit register over I2C.
uint32_t ns_i2c_read_sequential_regs (ns_i2c_config_t * cfg, uint32_t devAddr, uint32_t regAddr, void * buf, uint32_t size)
Read sequential 8-bit registers over I2C.
uint32_t ns_i2c_transfer (ns_i2c_config_t * cfg, ns_i2c_msg_t * msgs, size_t numMsgs)
Perform sequence of low-level I2C transfers (similar to Linux)
uint32_t ns_i2c_write (ns_i2c_config_t * cfg, const void * buf, uint32_t size, uint16_t addr)
Perform low-level I2C write using IOM transfer.
uint32_t ns_i2c_write_read (ns_i2c_config_t * cfg, uint16_t addr, const void * writeBuf, size_t numWrite, void * readBuf, size_t numRead)
Perform low-level I2C write followed by immediate read.
uint32_t ns_i2c_write_reg (ns_i2c_config_t * cfg, uint32_t devAddr, uint8_t regAddr, uint8_t value, uint8_t mask)
Write 8-bit register over I2C.
uint32_t ns_i2c_write_sequential_regs (ns_i2c_config_t * cfg, uint32_t devAddr, uint32_t regAddr, void * buf, uint32_t size)
Write sequential 8-bit registers over I2C.

Macros

Type Name
define NS_I2C_API_ID 0xCA0004
define NS_I2C_CURRENT_VERSION NS_I2C_V1_0_0
define NS_I2C_OLDEST_SUPPORTED_VERSION NS_I2C_V0_0_1
define NS_I2C_V0_0_1 { .major = 0, .minor = 0, .revision = 1 }
define NS_I2C_V1_0_0 { .major = 1, .minor = 0, .revision = 0 }

Public Types Documentation

enum ns_i2c_status_e

enum ns_i2c_status_e {
    NS_I2C_STATUS_SUCCESS = 0,
    NS_I2C_STATUS_ERROR = 1
};

enum ns_i2c_xfer_flag_e

enum ns_i2c_xfer_flag_e {
    NS_I2C_XFER_WR = 0,
    NS_I2C_XFER_RD = (1u << 0)
};

Public Attributes Documentation

variable ns_i2c_V0_0_1

const ns_core_api_t ns_i2c_V0_0_1;

variable ns_i2c_V1_0_0

const ns_core_api_t ns_i2c_V1_0_0;

variable ns_i2c_current_version

const ns_core_api_t ns_i2c_current_version;

variable ns_i2c_oldest_supported_version

const ns_core_api_t ns_i2c_oldest_supported_version;

Public Functions Documentation

function ns_i2c_interface_init

Initialize I2C on one of the IOM (IO managers)

uint32_t ns_i2c_interface_init (
    ns_i2c_config_t * cfg,
    uint32_t speed
) 

Parameters:

  • cfg I2C configuration
  • speed I2C speed in Hz

Returns:

uint32_t status

function ns_i2c_read

Perform low-level I2C read using IOM transfer.

uint32_t ns_i2c_read (
    ns_i2c_config_t * cfg,
    const void * buf,
    uint32_t size,
    uint16_t addr
) 

Parameters:

  • cfg I2C configuration
  • buf Buffer to store read bytes
  • size Number of bytes to read
  • addr I2C device address

function ns_i2c_read_reg

Read 8-bit register over I2C.

uint32_t ns_i2c_read_reg (
    ns_i2c_config_t * cfg,
    uint32_t devAddr,
    uint8_t regAddr,
    uint8_t * value,
    uint8_t mask
) 

Parameters:

  • cfg I2C configuration
  • devAddr Device address
  • regAddr Register address
  • value Register Value
  • mask Read mask

Returns:

uint32_t status

Parameters:

  • cfg Handle obtained from ns_i2c_interface_init
  • devAddr Device address
  • regAddr 8-bit register address
  • value Register value
  • mask Read mask

Returns:

uint32_t status

function ns_i2c_read_sequential_regs

Read sequential 8-bit registers over I2C.

uint32_t ns_i2c_read_sequential_regs (
    ns_i2c_config_t * cfg,
    uint32_t devAddr,
    uint32_t regAddr,
    void * buf,
    uint32_t size
) 

Parameters:

  • cfg I2C configuration
  • devAddr Device address
  • regAddr First register address
  • buf Buffer to store register values
  • size Number of registers to read

Returns:

uint32_t status

Parameters:

  • cfg I2C configuration
  • devAddr Device address
  • regAddr First 8-bit register address
  • buf Buffer to store register values
  • size Number of registers to read

Returns:

uint32_t status

function ns_i2c_transfer

Perform sequence of low-level I2C transfers (similar to Linux)

uint32_t ns_i2c_transfer (
    ns_i2c_config_t * cfg,
    ns_i2c_msg_t * msgs,
    size_t numMsgs
) 

Parameters:

  • cfg I2C configuration
  • msgs I2C messages to transfer
  • numMsgs Number of I2C messsages

function ns_i2c_write

Perform low-level I2C write using IOM transfer.

uint32_t ns_i2c_write (
    ns_i2c_config_t * cfg,
    const void * buf,
    uint32_t size,
    uint16_t addr
) 

Parameters:

  • cfg I2C configuration
  • buf Buffer of bytes to write
  • size Number of bytes to write
  • addr I2C device address

function ns_i2c_write_read

Perform low-level I2C write followed by immediate read.

uint32_t ns_i2c_write_read (
    ns_i2c_config_t * cfg,
    uint16_t addr,
    const void * writeBuf,
    size_t numWrite,
    void * readBuf,
    size_t numRead
) 

Parameters:

  • cfg I2C configuration
  • writeBuf Write buffer
  • numWrite Number of bytes to write
  • readBuf Read buffer
  • numRead Number of bytes to read
  • addr I2C device address

function ns_i2c_write_reg

Write 8-bit register over I2C.

uint32_t ns_i2c_write_reg (
    ns_i2c_config_t * cfg,
    uint32_t devAddr,
    uint8_t regAddr,
    uint8_t value,
    uint8_t mask
) 

Parameters:

  • cfg I2C configuration
  • devAddr Device address
  • regAddr Register address
  • value Register Value
  • mask Write mask

Returns:

uint32_t status

Parameters:

  • cfg Handle obtained from ns_i2c_interface_init
  • devAddr Device address
  • regAddr 8-bit register address
  • value Register value
  • mask Write mask

Returns:

uint32_t status

function ns_i2c_write_sequential_regs

Write sequential 8-bit registers over I2C.

uint32_t ns_i2c_write_sequential_regs (
    ns_i2c_config_t * cfg,
    uint32_t devAddr,
    uint32_t regAddr,
    void * buf,
    uint32_t size
) 

Parameters:

  • cfg I2C configuration
  • devAddr Device address
  • regAddr First register address
  • buf Pointer to buffer of values to be written
  • size Number of bytes to write

Returns:

uint32_t status

Parameters:

  • cfg I2C configuration
  • devAddr Device address
  • regAddr First 8-bit register address
  • buf Pointer to buffer of values to be written
  • size Number of bytes to write

Returns:

uint32_t status

Macro Definition Documentation

define NS_I2C_API_ID

#define NS_I2C_API_ID 0xCA0004

define NS_I2C_CURRENT_VERSION

#define NS_I2C_CURRENT_VERSION NS_I2C_V1_0_0

define NS_I2C_OLDEST_SUPPORTED_VERSION

#define NS_I2C_OLDEST_SUPPORTED_VERSION NS_I2C_V0_0_1

define NS_I2C_V0_0_1

#define NS_I2C_V0_0_1 { .major = 0, .minor = 0, .revision = 1 }

define NS_I2C_V1_0_0

#define NS_I2C_V1_0_0 { .major = 1, .minor = 0, .revision = 0 }