i2cdriver/c/common/i2cdriver.h

45 lines
1.3 KiB
C
Raw Normal View History

2019-02-23 18:22:33 +00:00
#ifndef I2CDRIVER_H
#define I2CDRIVER_H
#include <stdint.h>
#if defined(WIN32)
#include <windows.h>
#else
#define HANDLE int
#endif
typedef struct {
int connected; // Set to 1 when connected
HANDLE port;
char model[16],
serial[9]; // Serial number of USB device
uint64_t uptime; // time since boot (seconds)
float voltage_v, // USB voltage (Volts)
current_ma, // device current (mA)
temp_celsius; // temperature (C)
2019-02-23 23:44:54 +00:00
unsigned int mode; // I2C 'I' or bitbang 'B' mode
unsigned int sda; // SDA state, 0 or 1
unsigned int scl; // SCL state, 0 or 1
unsigned int speed; // I2C line speed (in kHz)
unsigned int pullups; // pullup state (6 bits, 1=enabled)
2019-02-23 18:22:33 +00:00
unsigned int
ccitt_crc, // Hardware CCITT CRC
e_ccitt_crc; // Host CCITT CRC, should match
} I2CDriver;
void i2c_connect(I2CDriver *sd, const char* portname);
void i2c_disconnect(I2CDriver *sd);
2019-02-23 18:22:33 +00:00
void i2c_getstatus(I2CDriver *sd);
2019-02-23 23:44:54 +00:00
int i2c_write(I2CDriver *sd, const uint8_t bytes[], size_t nn);
void i2c_read(I2CDriver *sd, uint8_t bytes[], size_t nn);
int i2c_start(I2CDriver *sd, uint8_t dev, uint8_t op);
2019-02-23 23:44:54 +00:00
void i2c_stop(I2CDriver *sd);
2019-02-23 18:22:33 +00:00
2019-02-23 23:56:26 +00:00
void i2c_monitor(I2CDriver *sd, int enable);
void i2c_capture(I2CDriver *sd);
2019-02-23 23:56:26 +00:00
2019-02-23 18:22:33 +00:00
int i2c_commands(I2CDriver *sd, int argc, char *argv[]);
#endif