gossamer 0.0.0
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
Enumerations | Functions
i2c.h File Reference

I2C Peripheral. More...

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Enumerations

enum  I2CResult {
  I2C_RESULT_SUCCESS = 0 , I2C_RESULT_ERR_ADDR_NACK = -1 , I2C_RESULT_ERR_BUSSTATE = -2 , I2C_RESULT_ERR_BUSERR = -3 ,
  I2C_RESULT_ERR_DATA_NACK = -4
}
 

Functions

void i2c_init (void)
 Initializes the I2C peripheral for a board with defined SDA/SCL pins. Defaults to a bus speed of 100kHz. More...
 
void i2c_enable (void)
 Enables the I2C peripheral for a board with defined SDA/SCL pins.
 
I2CResult i2c_write (uint8_t address, uint8_t *data, size_t len)
 Writes data to an I2C device at the provided address. More...
 
I2CResult i2c_read (uint8_t address, uint8_t *data, size_t len)
 Reads data from an I2C device at the provided address. More...
 
void i2c_disable (void)
 Disables the I2C peripheral for a board with defined SDA/SCL pins.
 
void i2c_init_instance (uint8_t sercom, uint32_t baud)
 Initializes an I2C peripheral on the given SERCOM. More...
 
void i2c_enable_instance (uint8_t sercom)
 Enables the I2C peripheral on the given SERCOM. More...
 
I2CResult i2c_write_instance (uint8_t sercom, uint8_t address, uint8_t *data, size_t len)
 Writes data to an I2C device on the given SERCOM at the provided address. More...
 
I2CResult i2c_read_instance (uint8_t sercom, uint8_t address, uint8_t *data, size_t len)
 Reads data from an I2C device on the given SERCOM at the provided address. More...
 
void i2c_disable_instance (uint8_t sercom)
 Disables the I2C peripheral on the given SERCOM. More...
 

Detailed Description

I2C Peripheral.

Function Documentation

◆ i2c_disable_instance()

void i2c_disable_instance ( uint8_t  sercom)

Disables the I2C peripheral on the given SERCOM.

Parameters
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.

◆ i2c_enable_instance()

void i2c_enable_instance ( uint8_t  sercom)

Enables the I2C peripheral on the given SERCOM.

Parameters
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.

◆ i2c_init()

void i2c_init ( void  )

Initializes the I2C peripheral for a board with defined SDA/SCL pins. Defaults to a bus speed of 100kHz.

This function will only work if a board has pins named SDA and SCL, and relevant definitions for I2C_SERCOM. If you don't have these definitions, the build will fail at link time.

◆ i2c_init_instance()

void i2c_init_instance ( uint8_t  sercom,
uint32_t  baud 
)

Initializes an I2C peripheral on the given SERCOM.

Parameters
sercomThe SERCOM you wish to use, as numbered in the data sheet.
baudThe baud rate you wish to use.
Note
You are responsible for setting the appropriate pin mux for the SDA and SCL pins. This function does not know which pins you intend to use, or whether they are on the SERCOM or SERCOM_ALT pin mux.

◆ i2c_read()

I2CResult i2c_read ( uint8_t  address,
uint8_t *  data,
size_t  len 
)

Reads data from an I2C device at the provided address.

Parameters
addressThe I2C address of the device.
dataA pointer to the buffer to read into.
lenThe length of the data to read.

◆ i2c_read_instance()

I2CResult i2c_read_instance ( uint8_t  sercom,
uint8_t  address,
uint8_t *  data,
size_t  len 
)

Reads data from an I2C device on the given SERCOM at the provided address.

Parameters
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.
addressThe I2C address of the device.
dataA pointer to the buffer to read into.
lenThe length of the data to read.

◆ i2c_write()

I2CResult i2c_write ( uint8_t  address,
uint8_t *  data,
size_t  len 
)

Writes data to an I2C device at the provided address.

Parameters
addressThe I2C address of the device.
dataThe data to write.
lenThe length of the data to write.

◆ i2c_write_instance()

I2CResult i2c_write_instance ( uint8_t  sercom,
uint8_t  address,
uint8_t *  data,
size_t  len 
)

Writes data to an I2C device on the given SERCOM at the provided address.

Parameters
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.
addressThe I2C address of the device.
dataThe data to write.
lenThe length of the data to write.