Skip to content

Optimization in display function to speed up drawing, added esp-idf example #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
dev_config.duty_cycle_pos = 0;
dev_config.cs_ena_posttrans = 0;
dev_config.cs_ena_pretrans = 0;
dev_config.clock_speed_hz = 100000; // 100KHz
dev_config.clock_speed_hz = 1000000; // 1MHz
dev_config.spics_io_num = cs;
dev_config.flags = 0;
dev_config.queue_size = 1;
Expand Down Expand Up @@ -393,27 +393,33 @@ void Adafruit_SSD1306::dim(boolean dim) {
}

void Adafruit_SSD1306::display(void) {
ssd1306_command(SSD1306_COLUMNADDR);
ssd1306_command(0); // Column start address (0 = reset)
ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

ssd1306_command(SSD1306_PAGEADDR);
ssd1306_command(0); // Page start address (0 = reset)
#if SSD1306_LCDHEIGHT == 64
ssd1306_command(7); // Page end address
#endif
#if SSD1306_LCDHEIGHT == 32
ssd1306_command(3); // Page end address
#endif
#if SSD1306_LCDHEIGHT == 16
ssd1306_command(1); // Page end address
#endif

gpio_set_level((gpio_num_t)dc, 0);
uint8_t cmd_buffer[] = {SSD1306_COLUMNADDR, 0, SSD1306_LCDWIDTH-1, SSD1306_PAGEADDR, 0, (SSD1306_LCDHEIGHT/8-1)};
spi_transaction_t trans_desc;
trans_desc.addr= 0;
trans_desc.cmd = 0;
trans_desc.flags = 0;
trans_desc.length = 6 * 8;
trans_desc.rxlength = 0;
trans_desc.tx_buffer = cmd_buffer;
trans_desc.rx_buffer = NULL;

ESP_ERROR_CHECK(spi_device_transmit(spi_handle, &trans_desc));

gpio_set_level((gpio_num_t)dc, 1);

for (uint16_t i=0; i<(SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT/8); i++) {
fastSPIwrite(buffer[i]);
}
//spi_transaction_t trans_desc;
trans_desc.addr= 0;
trans_desc.cmd = 0;
trans_desc.flags = 0;
trans_desc.length = SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH;
trans_desc.rxlength = 0;
trans_desc.tx_buffer = buffer;
trans_desc.rx_buffer = NULL;

ESP_ERROR_CHECK(spi_device_transmit(spi_handle, &trans_desc));

}

// clear everything
Expand All @@ -424,8 +430,8 @@ void Adafruit_SSD1306::clearDisplay(void) {

inline void Adafruit_SSD1306::fastSPIwrite(uint8_t d) {
spi_transaction_t trans_desc;
trans_desc.address = 0;
trans_desc.command = 0;
trans_desc.addr= 0;
trans_desc.cmd = 0;
trans_desc.flags = 0;
trans_desc.length = 8;
trans_desc.rxlength = 0;
Expand Down Expand Up @@ -651,3 +657,15 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h
}
}
}
#ifndef ARDUINO
void Adafruit_SSD1306::println(char* text){
print(text);
print((char*)"\n");
}
void Adafruit_SSD1306::print(char* text){
while(*text != 0) {
write(*text);
text++;
}
}
#endif
8 changes: 6 additions & 2 deletions hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ All text above, and the splash screen must be included in any redistribution
SSD1306_96_16

-----------------------------------------------------------------------*/
// #define SSD1306_128_64
#define SSD1306_128_32
#define SSD1306_128_64
// #define SSD1306_128_32
// #define SSD1306_96_16
/*=========================================================================*/

Expand Down Expand Up @@ -124,6 +124,10 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true);
void ssd1306_command(uint8_t c);

#ifndef ARDUINO
void print(char*);
void println(char*);
#endif
void clearDisplay(void);
void invertDisplay(uint8_t i);
void display();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Main component makefile.
#
# This Makefile can be left empty. By default, it will take the sources in the
# src/ directory, compile them and link them into lib(subdirectory_name).a
# in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
13 changes: 13 additions & 0 deletions hardware/displays/Adafruit_SSD1306-Library/examples/main/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "freertos/FreeRTOS.h"
#include "esp_event.h"

extern "C"{
void app_main(void);
}
void test_task(void*);

void app_main(void)
{
xTaskCreate(&test_task, "test", 2048, NULL, 5, NULL);
}

Loading