Allow the I2C slace address to be dynamic, as it should be.
This commit is contained in:
parent
53984c3d93
commit
8886a46588
11 changed files with 70 additions and 51 deletions
18
I2CModem.cpp
18
I2CModem.cpp
|
@ -22,7 +22,8 @@
|
|||
|
||||
|
||||
CI2CModem::CI2CModem(IModem* modem) :
|
||||
m_modem(modem)
|
||||
m_modem(modem),
|
||||
m_address(0x00U)
|
||||
{
|
||||
assert(modem != NULL);
|
||||
}
|
||||
|
@ -36,6 +37,11 @@ bool CI2CModem::open(unsigned char displayType)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CI2CModem::setAddress(unsigned char address)
|
||||
{
|
||||
m_address = address;
|
||||
}
|
||||
|
||||
void CI2CModem::setDataMode()
|
||||
{
|
||||
}
|
||||
|
@ -49,7 +55,7 @@ void CI2CModem::sendCommand(uint8_t c0, uint8_t c1, uint8_t c2)
|
|||
buff[2U] = c2;
|
||||
|
||||
// Write Data on I2C
|
||||
m_modem->writeI2CCommand(buff, 3U);
|
||||
m_modem->writeI2CCommand(m_address, buff, 3U);
|
||||
}
|
||||
|
||||
void CI2CModem::sendCommand(uint8_t c0, uint8_t c1)
|
||||
|
@ -60,23 +66,23 @@ void CI2CModem::sendCommand(uint8_t c0, uint8_t c1)
|
|||
buff[1U] = c1;
|
||||
|
||||
// Write Data on I2C
|
||||
m_modem->writeI2CCommand(buff, 2U);
|
||||
m_modem->writeI2CCommand(m_address, buff, 2U);
|
||||
}
|
||||
|
||||
void CI2CModem::sendCommand(uint8_t c)
|
||||
{
|
||||
// Write Data on I2C
|
||||
m_modem->writeI2CCommand(&c, 1U);
|
||||
m_modem->writeI2CCommand(m_address, &c, 1U);
|
||||
}
|
||||
|
||||
void CI2CModem::writeData(const uint8_t* data, uint16_t length)
|
||||
{
|
||||
m_modem->writeI2CData(data, length);
|
||||
m_modem->writeI2CData(m_address, data, length);
|
||||
}
|
||||
|
||||
void CI2CModem::writeData(uint8_t c)
|
||||
{
|
||||
m_modem->writeI2CData(&c, 1U);
|
||||
m_modem->writeI2CData(m_address, &c, 1U);
|
||||
}
|
||||
|
||||
void CI2CModem::close()
|
||||
|
|
|
@ -29,6 +29,8 @@ public:
|
|||
|
||||
virtual bool open(unsigned char displayType);
|
||||
|
||||
virtual void setAddress(unsigned char addr);
|
||||
|
||||
virtual void setDataMode();
|
||||
|
||||
virtual void sendCommand(uint8_t c0, uint8_t c1, uint8_t c2);
|
||||
|
@ -41,7 +43,8 @@ public:
|
|||
virtual void close();
|
||||
|
||||
private:
|
||||
IModem* m_modem;
|
||||
IModem* m_modem;
|
||||
unsigned char m_address;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
32
I2CPi.cpp
32
I2CPi.cpp
|
@ -26,7 +26,6 @@ const unsigned char OLED_ADAFRUIT_SPI_128x64 = 1U;
|
|||
|
||||
|
||||
CI2CPi::CI2CPi() :
|
||||
m_displayType(0U),
|
||||
m_spi(false)
|
||||
{
|
||||
}
|
||||
|
@ -37,8 +36,6 @@ CI2CPi::~CI2CPi()
|
|||
|
||||
bool CI2CPi::open(unsigned char displayType)
|
||||
{
|
||||
m_displayType = displayType;
|
||||
|
||||
if (displayType == OLED_ADAFRUIT_SPI_128x32 ||
|
||||
displayType == OLED_ADAFRUIT_SPI_128x64) {
|
||||
m_spi = true;
|
||||
|
@ -83,27 +80,6 @@ bool CI2CPi::open(unsigned char displayType)
|
|||
if (!bcm2835_i2c_begin())
|
||||
return false;
|
||||
|
||||
switch (displayType) {
|
||||
case OLED_ADAFRUIT_I2C_128x32:
|
||||
case OLED_ADAFRUIT_I2C_128x64:
|
||||
i2cAddr = ADAFRUIT_I2C_ADDRESS;
|
||||
break;
|
||||
|
||||
case OLED_SEEED_I2C_128x64:
|
||||
case OLED_SEEED_I2C_96x96:
|
||||
i2cAddr = SEEED_I2C_ADDRESS ;
|
||||
break;
|
||||
|
||||
case OLED_SH1106_I2C_128x64:
|
||||
i2cAddr = SH1106_I2C_ADDRESS;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
bcm2835_i2c_setSlaveAddress(i2cAddr);
|
||||
|
||||
// Setup reset pin direction as output
|
||||
bcm2835_gpio_fsel(OLED_I2C_RESET, BCM2835_GPIO_FSEL_OUTP);
|
||||
|
||||
|
@ -127,7 +103,13 @@ bool CI2CPi::open(unsigned char displayType)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CI2CMPi::setDataMode()
|
||||
void CI2CPi::setAddress(unsigned char address)
|
||||
{
|
||||
if (!m_spi)
|
||||
bcm2835_i2c_setSlaveAddress(address);
|
||||
}
|
||||
|
||||
void CI2CPi::setDataMode()
|
||||
{
|
||||
if (m_spi) {
|
||||
// Setup D/C line to high to switch to data mode
|
||||
|
|
5
I2CPi.h
5
I2CPi.h
|
@ -28,6 +28,8 @@ public:
|
|||
|
||||
virtual bool open(unsigned char displayType);
|
||||
|
||||
virtual void setAddress(unsigned char addr);
|
||||
|
||||
virtual void setDataMode();
|
||||
|
||||
virtual void sendCommand(uint8_t c0, uint8_t c1, uint8_t c2);
|
||||
|
@ -40,8 +42,7 @@ public:
|
|||
virtual void close();
|
||||
|
||||
private:
|
||||
unsigned char m_displayType;
|
||||
bool m_spi;
|
||||
bool m_spi;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
|
||||
virtual bool open(unsigned char displayType) = 0;
|
||||
|
||||
virtual void setAddress(unsigned char addr) = 0;
|
||||
|
||||
virtual void setDataMode() = 0;
|
||||
|
||||
virtual void sendCommand(uint8_t c0, uint8_t c1, uint8_t c2) = 0;
|
||||
|
|
4
Modem.h
4
Modem.h
|
@ -104,8 +104,8 @@ public:
|
|||
virtual bool writeSerial(const unsigned char* data, unsigned int length) = 0;
|
||||
virtual unsigned int readSerial(unsigned char* data, unsigned int length) = 0;
|
||||
|
||||
virtual bool writeI2CCommand(const unsigned char* data, unsigned int length) = 0;
|
||||
virtual bool writeI2CData(const unsigned char* data, unsigned int length) = 0;
|
||||
virtual bool writeI2CCommand(unsigned char address, const unsigned char* data, unsigned int length) = 0;
|
||||
virtual bool writeI2CData(unsigned char address, const unsigned char* data, unsigned int length) = 0;
|
||||
|
||||
virtual unsigned char getMode() const = 0;
|
||||
virtual bool setMode(unsigned char mode) = 0;
|
||||
|
|
|
@ -106,8 +106,8 @@ public:
|
|||
virtual bool writeSerial(const unsigned char* data, unsigned int length) { return true; };
|
||||
virtual unsigned int readSerial(unsigned char* data, unsigned int length) { return 0U; };
|
||||
|
||||
virtual bool writeI2CCommand(const unsigned char* data, unsigned int length) { return true; };
|
||||
virtual bool writeI2CData(const unsigned char* data, unsigned int length) { return true; };
|
||||
virtual bool writeI2CCommand(unsigned char address, const unsigned char* data, unsigned int length) { return true; };
|
||||
virtual bool writeI2CData(unsigned char address, const unsigned char* data, unsigned int length) { return true; };
|
||||
|
||||
virtual unsigned char getMode() const { return MODE_IDLE; };
|
||||
virtual bool setMode(unsigned char mode) { return true; };
|
||||
|
|
23
OLED.cpp
23
OLED.cpp
|
@ -105,6 +105,12 @@ const unsigned char OLED_SEEED_I2C_128x64 = 4U;
|
|||
const unsigned char OLED_SEEED_I2C_96x96 = 5U;
|
||||
const unsigned char OLED_SH1106_I2C_128x64 = 6U;
|
||||
|
||||
// OLED type I2C Address
|
||||
const unsigned char ADAFRUIT_I2C_ADDRESS = 0x3CU; /* 011110+SA0+RW - 0x3C or 0x3D */
|
||||
const unsigned char SEEED_I2C_ADDRESS = 0x3CU; /* 011110+SA0+RW - 0x3C or 0x3D */
|
||||
const unsigned char SH1106_I2C_ADDRESS = 0x3CU;
|
||||
|
||||
|
||||
// standard ascii 5x7 font
|
||||
const uint8_t FONT[] = {
|
||||
0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
|
||||
|
@ -547,21 +553,38 @@ m_grayL(0x00U) // XXX
|
|||
switch (displayType) {
|
||||
case OLED_ADAFRUIT_SPI_128x32:
|
||||
case OLED_ADAFRUIT_I2C_128x32:
|
||||
port->setAddress(ADAFRUIT_I2C_ADDRESS);
|
||||
m_width = 128U;
|
||||
m_height = 32U;
|
||||
break;
|
||||
|
||||
case OLED_ADAFRUIT_SPI_128x64:
|
||||
case OLED_ADAFRUIT_I2C_128x64:
|
||||
port->setAddress(ADAFRUIT_I2C_ADDRESS);
|
||||
m_width = 128U;
|
||||
m_height = 64U;
|
||||
break;
|
||||
|
||||
case OLED_SEEED_I2C_128x64:
|
||||
port->setAddress(SEEED_I2C_ADDRESS);
|
||||
m_width = 128U;
|
||||
m_height = 64U;
|
||||
break;
|
||||
|
||||
case OLED_SH1106_I2C_128x64:
|
||||
port->setAddress(SH1106_I2C_ADDRESS);
|
||||
m_width = 128U;
|
||||
m_height = 64U;
|
||||
break;
|
||||
|
||||
case OLED_SEEED_I2C_96x96:
|
||||
port->setAddress(SEEED_I2C_ADDRESS);
|
||||
m_width = 96U;
|
||||
m_height = 96U;
|
||||
break;
|
||||
|
||||
default:
|
||||
port->setAddress(0x00U);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1628,7 +1628,7 @@ bool CSerialModem::writeSerial(const unsigned char* data, unsigned int length)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CSerialModem::writeI2CCommand(const unsigned char* data, unsigned int length)
|
||||
bool CSerialModem::writeI2CCommand(unsigned char address, const unsigned char* data, unsigned int length)
|
||||
{
|
||||
assert(m_serial != NULL);
|
||||
assert(data != NULL);
|
||||
|
@ -1637,19 +1637,20 @@ bool CSerialModem::writeI2CCommand(const unsigned char* data, unsigned int lengt
|
|||
unsigned char buffer[255U];
|
||||
|
||||
buffer[0U] = MMDVM_FRAME_START;
|
||||
buffer[1U] = length + 4U;
|
||||
buffer[1U] = length + 5U;
|
||||
buffer[2U] = MMDVM_I2C_DATA;
|
||||
|
||||
buffer[3U] = SSD_Command_Mode;
|
||||
buffer[3U] = address;
|
||||
buffer[4U] = SSD_Command_Mode;
|
||||
|
||||
::memcpy(buffer + 4U, data, length);
|
||||
::memcpy(buffer + 5U, data, length);
|
||||
|
||||
m_serial->write(buffer, length + 4U);
|
||||
m_serial->write(buffer, length + 5U);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSerialModem::writeI2CData(const unsigned char* data, unsigned int length)
|
||||
bool CSerialModem::writeI2CData(unsigned char address, const unsigned char* data, unsigned int length)
|
||||
{
|
||||
assert(m_serial != NULL);
|
||||
assert(data != NULL);
|
||||
|
@ -1658,14 +1659,15 @@ bool CSerialModem::writeI2CData(const unsigned char* data, unsigned int length)
|
|||
unsigned char buffer[255U];
|
||||
|
||||
buffer[0U] = MMDVM_FRAME_START;
|
||||
buffer[1U] = length + 4U;
|
||||
buffer[1U] = length + 5U;
|
||||
buffer[2U] = MMDVM_I2C_DATA;
|
||||
|
||||
buffer[3U] = SSD_Data_Mode;
|
||||
buffer[3U] = address;
|
||||
buffer[4U] = SSD_Data_Mode;
|
||||
|
||||
::memcpy(buffer + 4U, data, length);
|
||||
::memcpy(buffer + 5U, data, length);
|
||||
|
||||
m_serial->write(buffer, length + 4U);
|
||||
m_serial->write(buffer, length + 5U);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -124,8 +124,8 @@ public:
|
|||
virtual bool writeSerial(const unsigned char* data, unsigned int length);
|
||||
virtual unsigned int readSerial(unsigned char* data, unsigned int length);
|
||||
|
||||
virtual bool writeI2CCommand(const unsigned char* data, unsigned int length);
|
||||
virtual bool writeI2CData(const unsigned char* data, unsigned int length);
|
||||
virtual bool writeI2CCommand(unsigned char address, const unsigned char* data, unsigned int length);
|
||||
virtual bool writeI2CData(unsigned char address, const unsigned char* data, unsigned int length);
|
||||
|
||||
virtual unsigned char getMode() const;
|
||||
virtual bool setMode(unsigned char mode);
|
||||
|
|
|
@ -19,6 +19,6 @@
|
|||
#if !defined(VERSION_H)
|
||||
#define VERSION_H
|
||||
|
||||
const char* VERSION = "20201118";
|
||||
const char* VERSION = "20201124";
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue