I2C address added to device descriptor
This commit is contained in:
parent
14c79a9ab8
commit
06086b0994
3 changed files with 14 additions and 5 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#ifdef I2C_CONNECTION
|
#ifdef I2C_CONNECTION
|
||||||
#define PROTOCOL SSD1306_PROTO_I2C
|
#define PROTOCOL SSD1306_PROTO_I2C
|
||||||
|
#define ADDR SSD1306_I2C_ADDR_0
|
||||||
#define SCL_PIN 5
|
#define SCL_PIN 5
|
||||||
#define SDA_PIN 4
|
#define SDA_PIN 4
|
||||||
#else
|
#else
|
||||||
|
|
@ -32,7 +33,9 @@
|
||||||
/* Declare device descriptor */
|
/* Declare device descriptor */
|
||||||
static const ssd1306_t dev = {
|
static const ssd1306_t dev = {
|
||||||
.protocol = PROTOCOL,
|
.protocol = PROTOCOL,
|
||||||
#ifndef I2C_CONNECTION
|
#ifdef I2C_CONNECTION
|
||||||
|
.addr = ADDR,
|
||||||
|
#else
|
||||||
.cs_pin = CS_PIN,
|
.cs_pin = CS_PIN,
|
||||||
.dc_pin = DC_PIN,
|
.dc_pin = DC_PIN,
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ int ssd1306_command(const ssd1306_t *dev, uint8_t cmd)
|
||||||
#if (SSD1306_I2C_SUPPORT)
|
#if (SSD1306_I2C_SUPPORT)
|
||||||
case SSD1306_PROTO_I2C:
|
case SSD1306_PROTO_I2C:
|
||||||
i2c_start();
|
i2c_start();
|
||||||
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
|
if (!i2c_write(dev->addr << 1)) {
|
||||||
debug("Error while xmitting I2C slave address\n");
|
debug("Error while xmitting I2C slave address\n");
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
@ -189,7 +189,7 @@ int ssd1306_load_frame_buffer(const ssd1306_t *dev, uint8_t buf[])
|
||||||
case SSD1306_PROTO_I2C:
|
case SSD1306_PROTO_I2C:
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
i2c_start();
|
i2c_start();
|
||||||
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
|
if (!i2c_write(dev->addr << 1)) {
|
||||||
debug("Error while xmitting I2C slave address\n");
|
debug("Error while xmitting I2C slave address\n");
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
// shifted
|
// 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
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|
@ -39,9 +42,12 @@ typedef enum
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ssd1306_protocol_t protocol;
|
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 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 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
|
uint8_t height; //!< Screen height, currently supported 16px, 32px, 64px
|
||||||
} ssd1306_t;
|
} ssd1306_t;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue