8000 Merge pull request #133 from chegewara/master · kebot-embedded/esp32-snippets@c58f228 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit c58f228

Browse files
authored
Merge pull request nkolban#133 from chegewara/master
Optimization in display function to speed up drawing, added esp-idf example
2 parents b40811f + 0acf6a3 commit c58f228

File tree

5 files changed

+415
-23
lines changed

5 files changed

+415
-23
lines changed

hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
195195
dev_config.duty_cycle_pos = 0;
196196
dev_config.cs_ena_posttrans = 0;
197197
dev_config.cs_ena_pretrans = 0;
198-
dev_config.clock_speed_hz = 100000; // 100KHz
198+
dev_config.clock_speed_hz = 1000000; // 1MHz
199199
dev_config.spics_io_num = cs;
200200
dev_config.flags = 0;
201201
dev_config.queue_size = 1;
@@ -393,27 +393,33 @@ void Adafruit_SSD1306::dim(boolean dim) {
393393
}
394394

395395
void Adafruit_SSD1306::display(void) {
396-
ssd1306_command(SSD1306_COLUMNADDR);
397-
ssd1306_command(0); // Column start address (0 = reset)
398-
ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)
399-
400-
ssd1306_command(SSD1306_PAGEADDR);
401-
ssd1306_command(0); // Page start address (0 = reset)
402-
#if SSD1306_LCDHEIGHT == 64
403-
ssd1306_command(7); // Page end address
404-
#endif
405-
#if SSD1306_LCDHEIGHT == 32
406-
ssd1306_command(3); // Page end address
407-
#endif
408-
#if SSD1306_LCDHEIGHT == 16
409-
ssd1306_command(1); // Page end address
410-
#endif
396+
397+
gpio_set_level((gpio_num_t)dc, 0);
398+
uint8_t cmd_buffer[] = {SSD1306_COLUMNADDR, 0, SSD1306_LCDWIDTH-1, SSD1306_PAGEADDR, 0, (SSD1306_LCDHEIGHT/8-1)};
399+
spi_transaction_t trans_desc;
400+
trans_desc.addr= 0;
401+
trans_desc.cmd = 0;
402+
trans_desc.flags = 0;
403+
trans_desc.length = 6 * 8;
404+
trans_desc.rxlength = 0;
405+
trans_desc.tx_buffer = cmd_buffer;
406+
trans_desc.rx_buffer = NULL;
407+
408+
ESP_ERROR_CHECK(spi_device_transmit(spi_handle, &trans_desc));
411409

412410
gpio_set_level((gpio_num_t)dc, 1);
413411

414-
for (uint16_t i=0; i<(SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT/8); i++) {
415-
fastSPIwrite(buffer[i]);
416-
}
412+
//spi_transaction_t trans_desc;
413+
trans_desc.addr= 0;
414+
trans_desc.cmd = 0;
415+
trans_desc.flags = 0;
416+
trans_desc.length = SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH;
417+
trans_desc.rxlength = 0;
418+
trans_desc.tx_buffer = buffer;
419+
trans_desc.rx_buffer = NULL;
420+
421+
ESP_ERROR_CHECK(spi_device_transmit(spi_handle, &trans_desc));
422+
417423
}
418424

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

425431
inline void Adafruit_SSD1306::fastSPIwrite(uint8_t d) {
426432
spi_transaction_t trans_desc;
427-
trans_desc.address = 0;
428-
trans_desc.command = 0;
433+
trans_desc.addr= 0;
434+
trans_desc.cmd = 0;
429435
trans_desc.flags = 0;
430436
trans_desc.length = 8;
431437
trans_desc.rxlength = 0;
@@ -651,3 +657,15 @@ void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h
651657
}
652658
}
653659
}
660+
#ifndef ARDUINO
661+
void Adafruit_SSD1306::println(char* text){
662+
print(text);
663+
print((char*)"\n");
664+
}
665+
void Adafruit_SSD1306::print(char* text){
666+
while(*text != 0) {
667+
write(*text);
668+
text++;
669+
}
670+
}
671+
#endif

hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ All text above, and the splash screen must be included in any redistribution
4444
SSD1306_96_16
4545
4646
-----------------------------------------------------------------------*/
47-
// #define SSD1306_128_64
48-
#define SSD1306_128_32
47+
#define SSD1306_128_64
48+
// #define SSD1306_128_32
4949
// #define SSD1306_96_16
5050
/*=========================================================================*/
5151

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

127+
#ifndef ARDUINO
128+
void print(char*);
129+
void println(char*);
130+
#endif
127131
void clearDisplay(void);
128132
void invertDisplay(uint8_t i);
129133
void display();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Main component makefile.
3+
#
4+
# This Makefile can be left empty. By default, it will take the sources in the
5+
# src/ directory, compile them and link them into lib(subdirectory_name).a
6+
# in the build directory. This behaviour is entirely configurable,
7+
# please read the ESP-IDF documents if you need to do this.
8+
#
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "freertos/FreeRTOS.h"
2+
#include "esp_event.h"
3+
4+
extern "C"{
5+
void app_main(void);
6+
}
7+
void test_task(void*);
8+
9+
void app_main(void)
10+
{
11+
xTaskCreate(&test_task, "test", 2048, NULL, 5, NULL);
12+
}
13+

0 commit comments

Comments
 (0)
0