binary Clock
Macros | Functions
i2c.c File Reference

High level I2C functions to interface with an I2C driver. More...

#include "i2c.h"
#include "i2c_drvr_4313.h"
#include "global_defines.h"
#include <stdint.h>

Macros

#define WRITE_MASK   0x00
 Mask for writing to a chip. More...
 
#define READ_MASK   0x01
 Mask for reading from a chip. More...
 

Functions

retval_t i2c_init (void)
 
retval_t i2c_write_byte (uint8_t chip_addr, uint8_t reg_addr, uint8_t data)
 
retval_t i2c_write (uint8_t chip_addr, uint8_t start_adr, uint8_t *data_to_write_ptr, uint8_t data_len)
 
retval_t i2c_read_byte (uint8_t chip_addr, uint8_t start_adr, uint8_t *data_out_ptr)
 
retval_t i2c_read (uint8_t chip_addr, uint8_t start_adr, uint8_t *data_out_ptr, uint8_t data_len)
 

Detailed Description

High level I2C functions to interface with an I2C driver.

Macro Definition Documentation

◆ READ_MASK

#define READ_MASK   0x01

Mask for reading from a chip.

◆ WRITE_MASK

#define WRITE_MASK   0x00

Mask for writing to a chip.

Function Documentation

◆ i2c_init()

retval_t i2c_init ( void  )

Initializes the I2C driver.

Parameters
[out]retval(retval_t): Returns the initialization status of the I2C driver.

◆ i2c_read()

retval_t i2c_read ( uint8_t  chip_addr,
uint8_t  start_adr,
uint8_t *  data_out_ptr,
uint8_t  data_len 
)

Reads N bytes from a chip. Handles starting and stopping of communication.

Parameters
[in]chip_addr(uint8_t): The address of the chip to be read from.
[in]start_adr(uint8_t): The starting register of the read.
[in]data_out_ptr(uint8_t *): Location to store the read values.
[in]data_len(uint8_t): amount of bytes to read.
[out]retval(retval_t): Returns the success or failure of starting communication & reading the byte.

◆ i2c_read_byte()

retval_t i2c_read_byte ( uint8_t  chip_addr,
uint8_t  start_adr,
uint8_t *  data_out_ptr 
)

Reads a byte from a chip. Handles starting and stopping of communication.

Parameters
[in]chip_addr(uint8_t): The address of the chip to be read from.
[in]start_adr(uint8_t): The starting register of the read.
[in]data_out_ptr(uint8_t *): Location to store the read value.
[out]retval(retval_t): Returns the success or failure of starting communication & reading the byte.

◆ i2c_write()

retval_t i2c_write ( uint8_t  chip_addr,
uint8_t  start_adr,
uint8_t *  data_to_write_ptr,
uint8_t  data_len 
)

Starts communication with a chip and writes N bytes to the chip. Handles starting and ending communication as well.

Parameters
[in]chip_addr(uint8_t): The address of the chip to be written to.
[in]start_adr(uint8_t): The starting register of the write.
[in]data_to_write_ptr(uint8_t *): The data to be written array.
[in]data_len(uint8_t): How many bytes to be written.
[out]retval(retval_t): Returns the success or failure of starting communication and writing to the device.

◆ i2c_write_byte()

retval_t i2c_write_byte ( uint8_t  chip_addr,
uint8_t  reg_addr,
uint8_t  data 
)

Writes a byte to a chip. Handles starting and stopping of communication.

Parameters
[in]chip_addr(uint8_t): The chip's address without the read/write bit set.
[in]reg_addr(uint8_t): Address of the register you want to write to.
[in]data(uint8_t): Data you want to write.
[out]retval(retval_t): Returns the success or failure of starting communication & sending the byte.