OLED display integrated with Zephyr

- Some fixes in DTS and pinmux settings
- Supporting different I2C address definitions of mbed and zephyr
- Thread for ext_mgr added
This commit is contained in:
Martin Jaeger
2019-12-20 10:51:00 +01:00
parent 117455390b
commit dc270372af
9 changed files with 173 additions and 68 deletions
+54 -6
View File
@@ -9,7 +9,6 @@
* Significant modifications were done by Martin Jäger (11/2019) to use it also in Zephyr
*/
#include "mbed.h"
#include "OledSSD1306.h"
#include "logo.h"
@@ -35,10 +34,31 @@
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
OledSSD1306::OledSSD1306(I2C &i2c, uint8_t i2cAddress, uint8_t brightness) :
#if defined(__MBED__)
OledSSD1306::OledSSD1306(I2C &i2c, uint8_t i2cAddress) :
Adafruit_GFX(SSD1306_WIDTH, SSD1306_HEIGHT),
mi2c(i2c),
mi2cAddress(i2cAddress)
_i2c(i2c),
_i2cAddress(i2cAddress)
{
;
}
#elif defined(__ZEPHYR__)
OledSSD1306::OledSSD1306(const char *i2c_name, uint8_t i2cAddress) :
Adafruit_GFX(SSD1306_WIDTH, SSD1306_HEIGHT),
_i2cAddress(i2cAddress)
{
_i2c = device_get_binding(i2c_name);
if (!_i2c) {
printk("I2C: Device driver not found.\n");
}
}
#endif
void OledSSD1306::init(uint8_t brightness)
{
command(SSD1306_DISPLAYOFF);
command(SSD1306_SETDISPLAYCLOCKDIV);
@@ -146,9 +166,33 @@ void OledSSD1306::splash(void)
std::copy(&logo[0], &logo[0] + sizeof(logo), buffer.begin());
}
void OledSSD1306::command(uint8_t c)
{
uint8_t buf[2];
buf[0] = 0; // Command Mode
buf[1] = c;
#if defined(__MBED__)
_i2c.write(_i2cAddress, (char *)buf, sizeof(buf));
#elif defined(__ZEPHYR__)
i2c_write(_i2c, buf, sizeof(buf), _i2cAddress);
#endif
}
void OledSSD1306::data(uint8_t c)
{
uint8_t buf[2];
buf[0] = 0x40; // Data Mode
buf[1] = c;
#if defined(__MBED__)
_i2c.write(_i2cAddress, (char *)buf, sizeof(buf));
#elif defined(__ZEPHYR__)
i2c_write(_i2c, buf, sizeof(buf), _i2cAddress);
#endif
};
void OledSSD1306::sendBuffer()
{
char buf[17];
uint8_t buf[17];
buf[0] = 0x40; // Data Mode
// send display buffer in 16 byte chunks
@@ -160,6 +204,10 @@ void OledSSD1306::sendBuffer()
buf[x] = buffer[pos];
}
}
mi2c.write(mi2cAddress, buf, sizeof(buf));
#if defined(__MBED__)
_i2c.write(_i2cAddress, (char *)buf, sizeof(buf));
#elif defined(__ZEPHYR__)
i2c_write(_i2c, buf, sizeof(buf), _i2cAddress);
#endif
}
};
+26 -21
View File
@@ -9,16 +9,22 @@
* Significant modifications were done by Martin Jäger (11/2019) to use it also in Zephyr
*/
#ifndef _OledSSD1306_H_
#define _OledSSD1306_H_
#ifndef OLEDSSD1306_H_
#define OLEDSSD1306_H_
#if defined(__MBED__)
#include "mbed.h"
#elif defined(__ZEPHYR__)
#include <zephyr.h>
#include <drivers/i2c.h>
#endif
#include "Adafruit_GFX.h"
#include <array>
#include <algorithm>
#define SSD1306_I2C_ADDRESS 0x78
#define SSD1306_I2C_ADDRESS 0x3c // needs to be left-shifted by 1 for mbed (=0x78)
#define SSD1306_WIDTH 128
#define SSD1306_HEIGHT 64
@@ -37,7 +43,13 @@ public:
* @param i2cAddress The i2c address of the display
* @param brightness Sets contrast between 0x01-0xFF or 1-255
*/
OledSSD1306(I2C &i2c, uint8_t i2cAddress = SSD1306_I2C_ADDRESS, uint8_t brightness = 0x01);
#if defined(__MBED__)
OledSSD1306(I2C &i2c, uint8_t i2cAddress = (SSD1306_I2C_ADDRESS << 1));
#elif defined(__ZEPHYR__)
OledSSD1306(const char *i2c_name, uint8_t i2cAddress = SSD1306_I2C_ADDRESS);
#endif
void init(uint8_t brightness = 0x01);
void drawPixel(int16_t x, int16_t y, uint16_t color);
@@ -51,29 +63,22 @@ public:
/// Fill the buffer with the logo splash screen.
void splash();
void command(uint8_t c)
{
char buff[2];
buff[0] = 0; // Command Mode
buff[1] = c;
mi2c.write(mi2cAddress, buff, sizeof(buff));
}
void command(uint8_t c);
void data(uint8_t c)
{
char buff[2];
buff[0] = 0x40; // Data Mode
buff[1] = c;
mi2c.write(mi2cAddress, buff, sizeof(buff));
};
void data(uint8_t c);
protected:
void sendBuffer();
std::array<uint8_t, SSD1306_HEIGHT * SSD1306_WIDTH / 8> buffer;
I2C &mi2c;
uint8_t mi2cAddress;
#if defined(__MBED__)
I2C &_i2c;
#elif defined(__ZEPHYR__)
struct device *_i2c;
#endif
uint8_t _i2cAddress;
};
#endif
#endif // OLEDSSD1306_H_