YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
i2c_interface.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// This file defines a generic and abstract C++
15// interface for a I2C interface.
16
17#ifndef _I2C_INTERFACE_H_
18#define _I2C_INTERFACE_H_
19
20#include <stdint.h>
21
23public:
24 // Read max. len bytes from the I2C interface.
25 // The number of bytes read is returned, or a
26 // negative value in case of errors. The last
27 // parameter specifies if a I2C STOP condition
28 // is generated at the end.
29 virtual int16_t i2cRead (uint16_t addr,
30 uint8_t *rxbuf, uint16_t len,
31 bool sendStop = true) = 0;
32
33 // Write len bytes from txbuf to the I2C interface.
34 // The number of bytes written is returned, or a
35 // negative value in case of errors. The last parameter
36 // specifies if a I2C STOP condition is generated at the end.
37 virtual int16_t i2cWrite(uint16_t addr,
38 uint8_t *txbuf, uint16_t len,
39 bool sendStop = true) = 0;
40
41 // Set the speed in Hz. Typical values are
42 // 100000 (100 kHz),
43 // 400000 (400 KHz) or
44 // 1000000 (1 MHz)
45 virtual void setSpeed(uint32_t Hz) = 0;
46
47protected:
48 virtual ~i2c_interface() = default;
49};
50
51#endif // _I2C_INTERFACE_H_
52