I2C address added to device descriptor

This commit is contained in:
UncleRus 2016-11-23 13:32:10 +05:00
parent 14c79a9ab8
commit 06086b0994
3 changed files with 14 additions and 5 deletions

View file

@ -82,7 +82,7 @@ int ssd1306_command(const ssd1306_t *dev, uint8_t cmd)
#if (SSD1306_I2C_SUPPORT)
case SSD1306_PROTO_I2C:
i2c_start();
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
if (!i2c_write(dev->addr << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;
@ -189,7 +189,7 @@ int ssd1306_load_frame_buffer(const ssd1306_t *dev, uint8_t buf[])
case SSD1306_PROTO_I2C:
for (i = 0; i < len; i++) {
i2c_start();
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
if (!i2c_write(dev->addr << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;

View file

@ -16,7 +16,10 @@
#include "config.h"
// shifted
#define SSD1306_I2C_ADDR (0x3C)
#if (SSD1306_I2C_SUPPORT)
#define SSD1306_I2C_ADDR_0 (0x3C)
#define SSD1306_I2C_ADDR_1 (0x3D)
#endif
#ifdef __cplusplus
extern "C"
@ -39,9 +42,12 @@ typedef enum
typedef struct
{
ssd1306_protocol_t protocol;
#if (SSD1306_I2C_SUPPORT)
uint8_t addr; //!< I2C address
#endif
uint8_t cs_pin; //!< Chip Select GPIO pin, used by SSD1306_PROTO_SPI3, SSD1306_PROTO_SPI4
uint8_t dc_pin; //!< Data/Command GPIO pin, used by SSD1306_PROTO_SPI4
uint8_t width; //!< Screen width, currently only 128px supported
uint8_t width; //!< Screen width, currently supported 128px, 96px
uint8_t height; //!< Screen height, currently supported 16px, 32px, 64px
} ssd1306_t;