diff --git a/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.cpp b/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.cpp index 12a7404a..daa4ec22 100644 --- a/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.cpp +++ b/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.cpp @@ -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; @@ -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 @@ -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; @@ -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 diff --git a/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.h b/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.h index e25c03f8..98ef0227 100644 --- a/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.h +++ b/hardware/displays/Adafruit_SSD1306-Library/Adafruit_SSD1306.h @@ -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 /*=========================================================================*/ @@ -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(); diff --git a/hardware/displays/Adafruit_SSD1306-Library/examples/main/component.mk b/hardware/displays/Adafruit_SSD1306-Library/examples/main/component.mk new file mode 100644 index 00000000..61f8990c --- /dev/null +++ b/hardware/displays/Adafruit_SSD1306-Library/examples/main/component.mk @@ -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. +# diff --git a/hardware/displays/Adafruit_SSD1306-Library/examples/main/main.cpp b/hardware/displays/Adafruit_SSD1306-Library/examples/main/main.cpp new file mode 100644 index 00000000..bc0bd5aa --- /dev/null +++ b/hardware/displays/Adafruit_SSD1306-Library/examples/main/main.cpp @@ -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); +} + diff --git a/hardware/displays/Adafruit_SSD1306-Library/examples/main/tests.cpp b/hardware/displays/Adafruit_SSD1306-Library/examples/main/tests.cpp new file mode 100644 index 00000000..c93fc522 --- /dev/null +++ b/hardware/displays/Adafruit_SSD1306-Library/examples/main/tests.cpp @@ -0,0 +1,349 @@ +/* + * tests.cpp + * + * Created on: Oct 9, 2017 + * Author: chegewara + */ +#define enablePartialUpdate + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/gpio.h" +//#include "math.h" +#include "sdkconfig.h" + +#include "Adafruit_SSD1306.h" +#define SCLK_PIN GPIO_NUM_18 +#define DIN_PIN GPIO_NUM_23 +#define DC_PIN GPIO_NUM_16 +#define CS_PIN GPIO_NUM_5 +#define RST_PIN GPIO_NUM_14 + +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#define NUMFLAKES 10 +#define XPOS 0 +#define YPOS 1 +#define DELTAY 2 +#define delay(x) vTaskDelay(x/portTICK_PERIOD_MS) + +#define LOGO16_GLCD_HEIGHT 16 +#define LOGO16_GLCD_WIDTH 16 + +static const unsigned char logo16_glcd_bmp[] = +{ 0b00000000, 0b11000000, + 0b00000001, 0b11000000, + 0b00000001, 0b11000000, + 0b00000011, 0b11100000, + 0b11110011, 0b11100000, + 0b11111110, 0b11111000, + 0b01111110, 0b11111111, + 0b00110011, 0b10011111, + 0b00011111, 0b11111100, + 0b00001101, 0b01110000, + 0b00011011, 0b10100000, + 0b00111111, 0b11100000, + 0b00111111, 0b11110000, + 0b01111100, 0b11110000, + 0b01110000, 0b01110000, + 0b00000000, 0b00110000 }; + +Adafruit_SSD1306 display = Adafruit_SSD1306(DIN_PIN, SCLK_PIN, DC_PIN, RST_PIN, CS_PIN); + +void testdrawchar(void) { + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(0,0); + + for (uint8_t i=0; i < 168; i++) { + if (i == '\n') continue; + display.write(i); + //if ((i > 0) && (i % 14 == 0)) + //display.println(); + } + display.display(); +} + +void testdrawcircle(void) { + for (int16_t i=0; i0; i-=5) { + display.fillTriangle(display.width()/2, display.height()/2-i, + display.width()/2-i, display.height()/2+i, + display.width()/2+i, display.height()/2+i, color); + if (color == WHITE) color = BLACK; + else color = WHITE; + display.display(); + } +} + +void testdrawroundrect(void) { + for (int16_t i=0; i=0; i-=4) { + display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); + display.display(); + } + delay(25); + + display.clearDisplay(); + for (int16_t i=display.width()-1; i>=0; i-=4) { + display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); + display.display(); + } + for (int16_t i=display.height()-1; i>=0; i-=4) { + display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); + display.display(); + } + delay(25); + + display.clearDisplay(); + for (int16_t i=0; i display.height()) { + icons[f][XPOS] = rand()%(display.width()); + icons[f][YPOS] = 0; + icons[f][DELTAY] = rand()%(5) + 1; + } + } + } +} + +void test_task(void*) { + while(1){ + display.begin(); + //display.setContrast(50); + display.display(); + + delay(2000); + display.clearDisplay(); // clears the screen and buffer + + // draw a single pixel + display.drawPixel(10, 10, WHITE); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw many lines + testdrawline(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw rectangles + testdrawrect(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw multiple rectangles + testfillrect(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw mulitple circles + testdrawcircle(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw a circle, 10 pixel radius + display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); + display.display(); + delay(2000); + display.clearDisplay(); + + testdrawroundrect(); + delay(2000); + display.clearDisplay(); + + testfillroundrect(); + delay(2000); + display.clearDisplay(); + + testdrawtriangle(); + delay(2000); + display.clearDisplay(); + + testfilltriangle(); + delay(2000); + display.clearDisplay(); + + // draw the first ~12 characters in the font + testdrawchar(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw scrolling text + testscrolltext(); + delay(2000); + display.clearDisplay(); + + // text display tests + display.setTextSize(2); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println((char*)"Hello, world!"); + display.setTextColor(WHITE, BLACK); // 'inverted' text + display.println((char*)"3.141592"); + display.setTextSize(1); + display.setTextColor(WHITE); + display.print((char*)"0x"); + display.println((char*)"DEADBEEF"); + display.display(); + delay(2000); + + // rotation example + display.clearDisplay(); + display.setRotation(1); // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further. + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println((char*)"Rotation"); + display.setTextSize(1); + display.println((char*)"Example!"); + display.display(); + delay(2000); + + // revert back to no rotation + display.setRotation(0); + + // miniature bitmap display + display.clearDisplay(); + display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, WHITE); + display.display(); + + // invert the display + display.invertDisplay(true); + delay(1000); + display.invertDisplay(false); + delay(1000); + + // draw a bitmap icon and 'animate' movement + testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT); + } +} + +