i2c_master.h
Go to the documentation of this file.
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
enum i2c_master_rc {
I2C_MASTER_RC_NONE = 0,
I2C_MASTER_RC_START_STOP_IN_PROGESS,
I2C_MASTER_RC_NOT_MASTER,
I2C_MASTER_RC_NOT_TRANSMIT,
I2C_MASTER_RC_NOT_RECEIVE,
I2C_MASTER_RC_NOT_READY,
I2C_MASTER_RC_NAK,
I2C_MASTER_RC_BUS_ERROR,
};
void i2c_master_setup(uint32_t i2c, uint16_t frequency);
void i2c_master_release(uint32_t i2c);
void i2c_master_reset(uint32_t i2c);
bool i2c_master_check_signals(uint32_t i2c);
enum i2c_master_rc i2c_master_start(uint32_t i2c);
enum i2c_master_rc i2c_master_select_slave(uint32_t i2c, uint16_t slave, bool address_10bit, bool write);
enum i2c_master_rc i2c_master_read(uint32_t i2c, uint8_t* data, size_t data_size);
enum i2c_master_rc i2c_master_write(uint32_t i2c, const uint8_t* data, size_t data_size);
enum i2c_master_rc i2c_master_stop(uint32_t i2c);
enum i2c_master_rc i2c_master_slave_read(uint32_t i2c, uint16_t slave, bool address_10bit, uint8_t* data, size_t data_size);
enum i2c_master_rc i2c_master_slave_write(uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t* data, size_t data_size);
enum i2c_master_rc i2c_master_address_read(uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t* address, size_t address_size, uint8_t* data, size_t data_size);
enum i2c_master_rc i2c_master_address_write(uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t* address, size_t address_size, const uint8_t* data, size_t data_size);
i2c_master_write
enum i2c_master_rc i2c_master_write(uint32_t i2c, const uint8_t *data, size_t data_size)
write data over I2C
Definition: i2c_master.c:427
i2c_master_read
enum i2c_master_rc i2c_master_read(uint32_t i2c, uint8_t *data, size_t data_size)
read data over I2C
Definition: i2c_master.c:389
i2c_master_address_write
enum i2c_master_rc i2c_master_address_write(uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t *address, size_t address_size, const uint8_t *data, size_t data_size)
write data at specific address on an I2C memory slave
Definition: i2c_master.c:597
I2C_MASTER_RC_NOT_RECEIVE
not in receive mode
Definition: i2c_master.h:29
I2C_MASTER_RC_BUS_ERROR
an error on the I2C bus occurred
Definition: i2c_master.h:32
i2c_master_setup
void i2c_master_setup(uint32_t i2c, uint16_t frequency)
setup I2C peripheral
Definition: i2c_master.c:173
i2c_master_reset
void i2c_master_reset(uint32_t i2c)
reset I2C peripheral, fixing any locked state
Definition: i2c_master.c:254
I2C_MASTER_RC_NOT_MASTER
not in master mode
Definition: i2c_master.h:27
i2c_master_release
void i2c_master_release(uint32_t i2c)
release I2C peripheral
Definition: i2c_master.c:211
I2C_MASTER_RC_START_STOP_IN_PROGESS
a start or stop condition is already in progress
Definition: i2c_master.h:26
i2c_master_slave_read
enum i2c_master_rc i2c_master_slave_read(uint32_t i2c, uint16_t slave, bool address_10bit, uint8_t *data, size_t data_size)
read data from slave device
Definition: i2c_master.c:493
i2c_master_slave_write
enum i2c_master_rc i2c_master_slave_write(uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t *data, size_t data_size)
write data to slave device
Definition: i2c_master.c:522
i2c_master_start
enum i2c_master_rc i2c_master_start(uint32_t i2c)
send start condition
Definition: i2c_master.c:284
i2c_master_stop
enum i2c_master_rc i2c_master_stop(uint32_t i2c)
sent stop condition
Definition: i2c_master.c:464
I2C_MASTER_RC_NOT_READY
slave is not read (previous operations has been nacked)
Definition: i2c_master.h:30
i2c_master_check_signals
bool i2c_master_check_signals(uint32_t i2c)
check if SDA and SCL signals are high
Definition: i2c_master.c:225
i2c_master_select_slave
enum i2c_master_rc i2c_master_select_slave(uint32_t i2c, uint16_t slave, bool address_10bit, bool write)
select I2C slave device
Definition: i2c_master.c:311
i2c_master_rc
i2c_master_rc
I2C return codes.
Definition: i2c_master.h:24
I2C_MASTER_RC_NOT_TRANSMIT
not in transmit mode
Definition: i2c_master.h:28
I2C_MASTER_RC_NONE
no error
Definition: i2c_master.h:25
i2c_master_address_read
enum i2c_master_rc i2c_master_address_read(uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t *address, size_t address_size, uint8_t *data, size_t data_size)
read data at specific address from an I2C memory slave
Definition: i2c_master.c:551
I2C_MASTER_RC_NAK
not acknowledge received
Definition: i2c_master.h:31