I2c optimization and features (#321)

* custom delay
* Update comment
* add bus control status, add some missing include & fixed display output on sh1104 (#319)
* add some missing include
* Fixed display on SH1106
* Fix comment, add force sytem, rework flag, 16 bits data transfert
* Update all library with new I2C API
* custom delay
* Update comment, add bus control status
* fix i2c read + fix ds3231 temp + fix ssd1306 send
This commit is contained in:
Zaltora 2017-03-21 07:41:47 +01:00 committed by Ruslan V. Uss
parent 1575bac0c7
commit 813477aa8a
19 changed files with 418 additions and 335 deletions

View file

@ -88,6 +88,14 @@
#define abs(x) ((x)<0 ? -(x) : (x))
#define swap(x, y) do { typeof(x) temp##x##y = x; x = y; y = temp##x##y; } while (0)
#if (SSD1306_I2C_SUPPORT)
static int inline i2c_send(const ssd1306_t *dev, uint8_t reg, uint8_t* data, uint8_t len)
{
return i2c_slave_write(dev->addr, &reg, data, len);
}
#endif
/* Issue a command to SSD1306 device
* I2C proto format:
* |S|Slave Address|W|ACK|0x00|Command|Ack|P|
@ -101,23 +109,7 @@ int ssd1306_command(const ssd1306_t *dev, uint8_t cmd)
switch (dev->protocol) {
#if (SSD1306_I2C_SUPPORT)
case SSD1306_PROTO_I2C:
i2c_start();
if (!i2c_write(dev->addr << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(0x00)) {
debug("Error while xmitting transmission type\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(cmd)) {
debug("Error while xmitting command: 0x%02X\n", cmd);
i2c_stop();
return -EIO;
}
i2c_stop();
return i2c_send(dev, 0x00, &cmd, 1);
break;
#endif
#if (SSD1306_SPI4_SUPPORT)
@ -247,7 +239,9 @@ int ssd1306_load_frame_buffer(const ssd1306_t *dev, uint8_t buf[])
{
uint16_t i;
uint8_t j;
#if (SSD1306_I2C_SUPPORT)
uint8_t tab[16] = { 0 } ;
#endif
size_t len = dev->width * dev->height / 8;
if(dev->screen == SSD1306_SCREEN)
{
@ -258,31 +252,11 @@ int ssd1306_load_frame_buffer(const ssd1306_t *dev, uint8_t buf[])
switch (dev->protocol) {
#if (SSD1306_I2C_SUPPORT)
case SSD1306_PROTO_I2C:
for (i = 0; i < len; i++) {
for (i = 0; i < len; i++)
{
if(dev->screen == SH1106_SCREEN && i%dev->width == 0) sh1106_go_coordinate(dev,0,i/dev->width);
i2c_start();
if (!i2c_write(dev->addr << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(0x40)) {
debug("Error while xmitting transmission type\n");
i2c_stop();
return -EIO;
}
for (j = 0; j < 16; j++) {
if (!i2c_write(buf ? buf[i] : 0)) {
debug("Error while writing to GDDRAM\n");
i2c_stop();
return -EIO;
}
i++;
}
i--;
i2c_stop();
taskYIELD();
i2c_send(dev, 0x40, buf ? &buf[i] : tab, 16);
i+=15 ;
}
break;
#endif

View file

@ -192,14 +192,6 @@ int ssd1306_set_display_offset(const ssd1306_t *dev, uint8_t offset);
*/
int sh1106_set_charge_pump_voltage(const ssd1306_t *dev, sh1106_voltage_t select);
/**
* Select charge pump voltage. See value in datasheet.
* @param dev Pointer to device descriptor
* @param select Select charge pump voltage value
* @return Non-zero if error occured
*/
int sh1106_set_charge_pump_voltage(const ssd1306_t *dev, sh1106_voltage_t select);
/**
* Enable or disable the charge pump. See application note in datasheet.
* @param dev Pointer to device descriptor