57 lines
2.3 KiB
C
57 lines
2.3 KiB
C
|
/* 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/>.
|
||
|
*
|
||
|
*/
|
||
|
/** library to communicate using I2C as master or slave (API)
|
||
|
* @file i2c_general.h
|
||
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||
|
* @date 2018
|
||
|
* @note peripherals used: I2C @ref i2c_general_i2c, timer @ref i2c_general_timer
|
||
|
* @warning only 7-byte I2C slave addresses are supported
|
||
|
*/
|
||
|
#pragma once
|
||
|
|
||
|
/** setup I2C peripheral
|
||
|
* @param[in] fast use standard (100 kHz) or fast (400 kHz) mode
|
||
|
*/
|
||
|
void i2c_general_setup_master(bool fast);
|
||
|
/** check if SDA and SCL signals are high
|
||
|
* @return SDA and SCL signals are high
|
||
|
*/
|
||
|
bool i2c_general_check(void);
|
||
|
/** send start condition
|
||
|
* @return if start condition was sent successfully (true) or error occurred (false)
|
||
|
*/
|
||
|
bool i2c_general_start(void);
|
||
|
/** select slave device
|
||
|
* @warning a start condition should be sent before this operation
|
||
|
* @param[in] slave 7-bit I2C address of slave device to select
|
||
|
* @param[in] write this transaction will be followed by a read (false) or write (true) operation
|
||
|
* @return if slave was selected successfully (true) or error occurred (false)
|
||
|
*/
|
||
|
bool i2c_general_select_slave(uint8_t slave, bool write);
|
||
|
/** read data
|
||
|
* @warning the slave device must be selected before this operation
|
||
|
* @param[out] data array to store bytes read
|
||
|
* @param[in] data_size number of bytes to read
|
||
|
*/
|
||
|
bool i2c_general_read(uint8_t* data, size_t data_size);
|
||
|
/** write data
|
||
|
* @warning the slave device must be selected before this operation
|
||
|
* @param[in] data array of byte to write to slave
|
||
|
* @param[in] data_size number of bytes to write
|
||
|
*/
|
||
|
bool i2c_general_write(const uint8_t* data, size_t data_size);
|
||
|
/** sent stop condition */
|
||
|
void i2c_general_stop(void);
|