You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

/*
"THE BEER/MATE-WARE LICENSE":
<xil@xil.se> wrote this file. As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy us a ( > 0 ) beer/mate in return - The Xil TEAM
*/
#ifndef I2C_H
#define I2C_H
#include <stdint.h>
#include <stdbool.h>
#if defined(TARGET_ESP8266)
#include "osapi.h"
#include "ets_sys.h"
#define I2C_DELAY_US(x) os_delay_us(x)
typedef struct {
// Configuration
uint8_t gpio_sda;
uint8_t gpio_scl;
// Internal data
uint8_t sda_last;
uint8_t scl_last;
} i2c_t;
#elif defined(TARGET_SMT32F0)
#include <stm32f0xx_hal.h>
#define I2C_DELAY_US(x) HAL_Delay(((x)/1000)+((x)%1000 == 0 ? 0 : 1))
typedef struct {
} i2c_t;
#elif defined(TARGET_RASPBERRY_PI)
#include <unistd.h>
#define I2C_DELAY_US(x) usleep(x)
typedef struct {
} i2c_t;
#else
#error "No target defined"
#endif
#ifndef ICACHE_FLASH_ATTR
#define ICACHE_FLASH_ATTR
#endif
/*
* address is 7 bit address
*/
int i2c_transmit(i2c_t* i2c, uint8_t address, uint8_t* data, uint8_t length);
int i2c_transmit_no_stop(i2c_t* i2c, uint8_t address, uint8_t* data, uint8_t length);
int i2c_receive(i2c_t* i2c, uint8_t address, uint8_t* data, uint8_t length);
#endif // I2C_H