Code beautyfication

This commit is contained in:
UncleRus 2017-10-12 04:56:53 +05:00
parent 080974ccfd
commit 0e76cf0988
3 changed files with 21 additions and 23 deletions

View file

@ -15,7 +15,7 @@ uint8_t slave_addr = 0x20;
uint8_t reg_addr = 0x1f;
uint8_t reg_data;
i2c_init(BUS, SCL_PIN, SDA_PIN);
i2c_init(BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K);
// Write 1 byte to slave register
int err = i2c_slave_write(BUS, slave_addr, &reg_addr, &data, 1);

View file

@ -50,6 +50,18 @@ const static uint8_t i2c_freq_array[][2] = {
};
static uint8_t freq; // Store CPU frequency for optimisation speed in delay function (Warning: Don't change CPU frequency during a transaction)
// Bus settings
typedef struct i2c_bus_description
{
uint8_t g_scl_pin; // SCL pin
uint8_t g_sda_pin; // SDA pin
i2c_freq_t frequency; // Frequency
bool started;
bool flag;
bool force;
} i2c_bus_description_t;
static i2c_bus_description_t i2c_bus[MAX_I2C_BUS];
inline bool i2c_status(uint8_t bus)

View file

@ -21,6 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* I2C driver for ESP8266 written for use with esp-open-rtos
* Based on https://en.wikipedia.org/wiki/I²C#Example_of_bit-banging_the_I.C2.B2C_Master_protocol
*/
#ifndef __I2C_H__
#define __I2C_H__
@ -42,10 +46,10 @@ extern "C" {
typedef enum
{
I2C_FREQ_80K = 0,
I2C_FREQ_100K,
I2C_FREQ_400K,
I2C_FREQ_500K,
I2C_FREQ_80K = 0,//!< I2C_FREQ_80K
I2C_FREQ_100K, //!< I2C_FREQ_100K
I2C_FREQ_400K, //!< I2C_FREQ_400K
I2C_FREQ_500K, //!< I2C_FREQ_500K
} i2c_freq_t;
/**
@ -57,24 +61,6 @@ typedef struct i2c_dev
uint8_t addr;
} i2c_dev_t;
/**
* Bus settings
*/
typedef struct i2c_bus_description
{
uint8_t g_scl_pin; ///< SCL pin
uint8_t g_sda_pin; ///< SDA pin
uint8_t frequency; ///< Frequency
bool started;
bool flag;
bool force;
} i2c_bus_description_t;
// I2C driver for ESP8266 written for use with esp-open-rtos
// Based on https://en.wikipedia.org/wiki/I²C#Example_of_bit-banging_the_I.C2.B2C_Master_protocol
// With calling overhead, we end up at ~320kbit/s
/// Level 0 API
/**