quasar_i2c.h

This module configures I2C and provides functions to write and read into a I2C device register with or without interrupts.

Copyright

Copyright (C) 2026 SPARK Microsystems International Inc. All rights reserved.

License

This source code is proprietary and subject to the SPARK Microsystems Software EULA found in this package in file EULA.txt.

Author

SPARK FW Team.

Typedefs

typedef enum quasar_i2c_clk_source quasar_i2c_clk_source_t

List of all available clock sources for the I2C instances.

Note

From the reference manual:

  • 0b00 : PCLK1 -> set 0

  • 0b01 : SYSCLK -> set 1

  • 0b10 : HSI16 -> set 2

  • 0b11 : MSIK -> set 3

typedef enum quasar_i2c_selection quasar_i2c_selection_t

List of all available I2C instances and used as an index into Quasar FIFO buffer array.

typedef struct quasar_i2c_config quasar_i2c_config_t

Quasar BSP I2C configuration.

Enums

enum quasar_i2c_clk_source

List of all available clock sources for the I2C instances.

Note

From the reference manual:

  • 0b00 : PCLK1 -> set 0

  • 0b01 : SYSCLK -> set 1

  • 0b10 : HSI16 -> set 2

  • 0b11 : MSIK -> set 3

Values:

enumerator QUASAR_I2C_CLK_SOURCE_PCLK1 = 0

Select PCLK1 as clock source.

enumerator QUASAR_I2C_CLK_SOURCE_SYSCLK = 1

Select SYSCLK as clock source.

enumerator QUASAR_I2C_CLK_SOURCE_HSI16 = 2

Select HSI16 as clock source.

enumerator QUASAR_I2C_CLK_SOURCE_MSIK = 3

Select MSIK as clock source.

enum quasar_i2c_selection

List of all available I2C instances and used as an index into Quasar FIFO buffer array.

Values:

enumerator QUASAR_I2C_SELECTION_I2C1 = 0

Select I2C1 instance.

enumerator QUASAR_I2C_SELECTION_I2C2 = 1

Select I2C2 instance.

enumerator QUASAR_I2C_SELECTION_I2C3 = 2

Select I2C3 instance.

enumerator QUASAR_I2C_SELECTION_I2C4 = 3

Select I2C4 instance.

enumerator QUASAR_I2C_SELECTION_I2C5 = 4

Select I2C5 instance.

enumerator QUASAR_I2C_SELECTION_I2C6 = 5

Select I2C6 instance.

enumerator _QUASAR_I2C_SELECTION_COUNT = 6

Indicate the number of possible I2C selections.

Functions

void quasar_i2c_init(quasar_i2c_config_t i2c_config)

Initialize the I2C peripheral.

Parameters:

i2c_config[in] Configuration of the I2C peripheral.

void quasar_i2c_deinit(quasar_i2c_config_t i2c_config)

Deinitialize the I2C peripheral and its associated GPIOs.

Parameters:

i2c_config[in] Configuration of the I2C peripheral.

void quasar_i2c_write(quasar_i2c_selection_t i2c_selection, uint8_t device_addr, uint8_t reg_addr, uint8_t reg_value, quasar_bsp_status_t *err)

Initiate I2C transmission in order to write a value in a specific register of an I2C device using interrupts.

Note

The selected I2C instance must have been initialized with a valid IRQ priority.

Parameters:
  • i2c_selection[in] Selected I2C peripheral.

  • device_addr[in] Address of the target I2C device.

  • reg_addr[in] Address of the register within the I2C device to which the value will be written.

  • reg_value[in] Value to be written to the specified register.

  • err[out] Pointer to store the error status.

void quasar_i2c_read(quasar_i2c_selection_t i2c_selection, uint8_t device_addr, uint8_t reg_addr, uint8_t *reg_value_ptr, quasar_bsp_status_t *err)

Initiate I2C read to retrieve a value from a specific register of an I2C device using interrupts.

Note

The selected I2C instance must have been initialized with a valid IRQ priority.

Parameters:
  • i2c_selection[in] Selected I2C peripheral.

  • device_addr[in] Address of the target I2C device.

  • reg_addr[in] Address of the register within the I2C device from which the value will be read.

  • reg_value_ptr[out] Pointer to store the retrieved value.

  • err[out] Pointer to store the error status.

void quasar_i2c_write_blocking(quasar_i2c_selection_t i2c_selection, uint8_t device_addr, uint8_t reg_addr, uint8_t reg_value, uint16_t retry_count, quasar_bsp_status_t *err)

Initiate I2C transmission in order to write a value in a specific register of an I2C device.

Note

The selected I2C instance must have been initialized without IRQ priority (QUASAR_IRQ_NONE).

Parameters:
  • i2c_selection[in] Selected I2C peripheral.

  • device_addr[in] Address of the target I2C device.

  • reg_addr[in] Address of the register within the I2C device to which the value will be written.

  • reg_value[in] Value to be written to the specified register.

  • retry_count[in] Number of loop iterations expected in each cycle of the I2C transaction.

  • err[out] Pointer to store the error status.

void quasar_i2c_read_blocking(quasar_i2c_selection_t i2c_selection, uint8_t device_addr, uint8_t reg_addr, uint8_t *reg_value_ptr, uint16_t retry_count, quasar_bsp_status_t *err)

Initiate I2C read to retrieve a value from a specific register of an I2C device.

Note

The selected I2C instance must have been initialized without IRQ priority (QUASAR_IRQ_NONE).

Parameters:
  • i2c_selection[in] Selected I2C peripheral.

  • device_addr[in] Address of the target I2C device.

  • reg_addr[in] Address of the register within the I2C device from which the value will be read.

  • reg_value_ptr[out] Pointer to store the retrieved value.

  • retry_count[in] Number of loop iterations expected in each cycle of the I2C transaction.

  • err[out] Pointer to store the error status.

void quasar_i2c_write_burst_blocking(quasar_i2c_selection_t i2c_selection, uint8_t device_addr, uint8_t reg_addr_start, uint8_t *reg_values_array, uint8_t size, uint16_t retry_count, quasar_bsp_status_t *err)

Initiate I2C transmission in order to write a value in a specific register of an I2C device.

Note

The selected I2C instance must have been initialized without IRQ priority (QUASAR_IRQ_NONE).

Parameters:
  • i2c_selection[in] Selected I2C peripheral.

  • device_addr[in] Address of the target I2C device.

  • reg_addr_start[in] Address of the register to start the burst transaction.

  • reg_values_array[in] Array of the values to be written to the registers.

  • size[in] Size of the array which also indicate the number of registers to be written.

  • retry_count[in] Number of loop iterations expected in each cycle of the I2C transaction.

  • err[out] Pointer to store the error status.

void quasar_i2c_read_burst_blocking(quasar_i2c_selection_t i2c_selection, uint8_t device_addr, uint8_t reg_addr_start, uint8_t *reg_values_array, uint8_t size, uint16_t retry_count, quasar_bsp_status_t *err)

Initiate I2C read to retrieve a value from a specific register of an I2C device.

Note

The selected I2C instance must have been initialized without IRQ priority (QUASAR_IRQ_NONE).

Parameters:
  • i2c_selection[in] Selected I2C peripheral.

  • device_addr[in] Address of the target I2C device.

  • reg_addr_start[in] Address of the register to start the burst transaction.

  • reg_values_array[in] Array to store the values of registers that are to be read.

  • size[in] Size of the array which also indicate the number of registers to be read.

  • retry_count[in] Number of loop iterations expected in each cycle of the I2C transaction.

  • err[out] Pointer to store the error status.

struct quasar_i2c_config
#include <quasar_i2c.h>

Quasar BSP I2C configuration.

Public Members

quasar_i2c_selection_t i2c_selection

Selected I2C instance.

quasar_gpio_config_t gpio_config_sda

Selected GPIO configuration used for SDA.

quasar_gpio_config_t gpio_config_scl

Selected GPIO configuration used for SCL.

quasar_irq_priority_t irq_priority

Available IRQ priority.