2022-07-18 03:34:20 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
|
|
|
|
|
|
|
This file is part of Savanni's AVR library.
|
|
|
|
|
|
|
|
This AVR library 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 AVR library 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 AVR library. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __I2C_H__
|
|
|
|
#define __I2C_H__
|
|
|
|
|
2022-07-20 03:00:35 +00:00
|
|
|
#include <dio.h>
|
2022-07-18 03:34:20 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2022-07-20 03:00:35 +00:00
|
|
|
i2c_ok,
|
|
|
|
i2c_arbitration_lost,
|
|
|
|
i2c_timeout,
|
|
|
|
i2c_nak,
|
2022-07-18 03:34:20 +00:00
|
|
|
} i2c_error_e;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-08-14 22:43:54 +00:00
|
|
|
bool sda_state;
|
2022-07-18 03:34:20 +00:00
|
|
|
dio_t sda;
|
2022-08-14 22:43:54 +00:00
|
|
|
|
|
|
|
bool scl_state;
|
2022-07-20 03:00:35 +00:00
|
|
|
dio_t scl;
|
|
|
|
} i2c_bus_t;
|
2022-07-18 03:34:20 +00:00
|
|
|
|
2022-07-20 03:00:35 +00:00
|
|
|
/*
|
2022-07-18 03:34:20 +00:00
|
|
|
typedef struct {
|
|
|
|
dio_t sda;
|
2022-07-20 03:00:35 +00:00
|
|
|
dio_t scl;
|
2022-07-18 03:34:20 +00:00
|
|
|
uint8_t addr;
|
2022-07-20 03:00:35 +00:00
|
|
|
} i2c_client_t;
|
|
|
|
*/
|
2022-07-18 03:34:20 +00:00
|
|
|
|
2022-08-14 22:43:54 +00:00
|
|
|
i2c_bus_t * i2c_init(dio_t, dio_t);
|
|
|
|
|
|
|
|
void i2c_start(i2c_bus_t *bus, i2c_error_e *error);
|
|
|
|
void i2c_end(i2c_bus_t *bus, i2c_error_e *error);
|
|
|
|
void i2c_restart(i2c_bus_t *bus, i2c_error_e *error);
|
|
|
|
|
|
|
|
void i2c_write_byte(i2c_bus_t *bus, uint8_t value, i2c_error_e *error);
|
|
|
|
uint8_t i2c_read_byte(i2c_bus_t *bus, bool final_nak, i2c_error_e *error);
|
2022-07-18 03:34:20 +00:00
|
|
|
|
2022-07-20 03:00:35 +00:00
|
|
|
// void i2c_host_write(i2c_host_t *, uint8_t, uint8_t, size_t, i2c_error_e);
|
2022-07-18 03:34:20 +00:00
|
|
|
|
2022-08-14 22:43:54 +00:00
|
|
|
void i2c_status_to_string(i2c_error_e status, char msg[20]);
|
|
|
|
|
2022-07-18 03:34:20 +00:00
|
|
|
#endif
|