From 8ef9d9539c917e5808e12dfcccbec32eeeba2a40 Mon Sep 17 00:00:00 2001 From: nopnop2002 Date: Tue, 4 Jun 2019 21:32:54 +0900 Subject: [PATCH] change menu structure --- README.md | 28 ++++-------- main/Kconfig.projbuild | 45 ++++++++++++++----- main/main.c | 99 ++++++++++++++++++++++-------------------- main/ssd1306.h | 7 --- 4 files changed, 95 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index b0b1a59..6a45d33 100644 --- a/README.md +++ b/README.md @@ -31,22 +31,18 @@ make flash # 128x32 i2c ![128x32](https://user-images.githubusercontent.com/6020549/56449097-6d12e880-6350-11e9-8edd-7a8fc5eaeedc.JPG) -![config-128x32_i2c](https://user-images.githubusercontent.com/6020549/56844597-c5685e00-68ed-11e9-9969-0f7b39434a21.jpg) +![config-128x32_i2c](https://user-images.githubusercontent.com/6020549/58878909-5c0b1480-870f-11e9-90db-20d3d103415b.jpg) -RESET GPIO not used. -CS GPIO not used. -DC GPIO not used. +RESET GPIO is not use. --- # 128x64 i2c ![128x64](https://user-images.githubusercontent.com/6020549/56449101-7dc35e80-6350-11e9-8579-32fff38369c0.JPG) -![config-128x64_i2c](https://user-images.githubusercontent.com/6020549/56844601-d1542000-68ed-11e9-9331-8b478cf53c8c.jpg) +![config-128x64_i2c](https://user-images.githubusercontent.com/6020549/58878927-69c09a00-870f-11e9-9dee-72e5647a0004.jpg) -RESET GPIO not used. -CS GPIO not used. -DC GPIO not used. +RESET GPIO is not use. --- @@ -55,33 +51,27 @@ DC GPIO not used. ![ESP32-TTGO-1](https://user-images.githubusercontent.com/6020549/56449111-9764a600-6350-11e9-9902-e2ad1c4aefb0.JPG) ![ESP32-TTGO-2](https://user-images.githubusercontent.com/6020549/56449116-9a5f9680-6350-11e9-86ec-e06648118add.JPG) ![128x64_Reset](https://user-images.githubusercontent.com/6020549/56449118-9e8bb400-6350-11e9-9b90-1eb1f9fa8e99.JPG) -![config-128x64_TTGO](https://user-images.githubusercontent.com/6020549/56844603-d5803d80-68ed-11e9-9de5-fb475630ca1d.jpg) +![config-128x64_TTGO](https://user-images.githubusercontent.com/6020549/58879031-a4c2cd80-870f-11e9-941b-05c6a14e3e9f.jpg) -CS GPIO not used. -DC GPIO not used. +RESET GPIO is use. --- # 128x64 ESP-WROOM-32 ![ESP32-OLED-2](https://user-images.githubusercontent.com/6020549/57063327-d229ef00-6cfd-11e9-98ab-8448e14d81e2.JPG) -![config-128x64_esp32](https://user-images.githubusercontent.com/6020549/57063338-dc4bed80-6cfd-11e9-90b5-7b3e7ed74c00.jpg) +![config-ESP-WROOM-32](https://user-images.githubusercontent.com/6020549/58879064-b4421680-870f-11e9-94c6-c3008fb56203.jpg) -RESET GPIO not used. -CS GPIO not used. -DC GPIO not used. +RESET GPIO is not use. --- # 128x64 SPI ![128x64_spi](https://user-images.githubusercontent.com/6020549/56844607-ee88ee80-68ed-11e9-9b20-ab5e7e0d2a99.JPG) -![config-128x64_spi](https://user-images.githubusercontent.com/6020549/56844609-f34da280-68ed-11e9-995e-4aedae207eac.jpg) +![config-128x64_spi](https://user-images.githubusercontent.com/6020549/58879091-cae86d80-870f-11e9-82da-6e757fbe2f20.jpg) MOSI is GPIO13. SCLK is GPIO14. -SSD1306 Model not used. -SCL GPIO not used. -SDA GPIO not used. diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index da93338..63323a0 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -1,20 +1,36 @@ menu "SSD1306 Configuration" - config INTERFACE - int "SSD1306 Interface" - range 1 2 - default 1 + choice INTERFACE + prompt "Interface" + default I2C_INTERFACE help - 1 : i2c Interface - 2 : SPI interface + Select Interface. + config I2C_INTERFACE + bool "I2C Interface" + help + I2C Interface. + config SPI_INTERFACE + bool "SPI Interface" + help + SPI Interface. + endchoice - config MODEL - int "SSD1306 Model" - range 1 2 - default 1 +if I2C_INTERFACE + + choice PANEL + prompt "Panel Type" + default SSD1306_128x64 help - 1 : SSD1306_128x64 (128x64 panel) - 2 : SSD1306_128x32 (128x32 panel) + Select Panel Type. + config SSD1306_128x32 + bool "128x32 Panel" + help + Panel is 128x32. + config SSD1306_128x64 + bool "128x64 Panel" + help + Panel is 128x64. + endchoice config SCL_GPIO int "SCL GPIO number" @@ -34,6 +50,8 @@ menu "SSD1306 Configuration" Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to I2C. GPIOs 35-39 are input-only so cannot be used as outputs. +endif + config RESET_GPIO int "RESET GPIO number" range -1 34 @@ -44,6 +62,7 @@ menu "SSD1306 Configuration" Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to Reset. GPIOs 35-39 are input-only so cannot be used as outputs. +if SPI_INTERFACE config CS_GPIO int "CS GPIO number" range 0 34 @@ -62,4 +81,6 @@ menu "SSD1306 Configuration" Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to DC. GPIOs 35-39 are input-only so cannot be used as outputs. +endif + endmenu diff --git a/main/main.c b/main/main.c index 08a8c99..ff1ff89 100644 --- a/main/main.c +++ b/main/main.c @@ -32,55 +32,62 @@ void app_main(void) int center, top, bottom; char lineChar[16]; - ESP_LOGI(tag, "CONFIG_INTERFACE=%d",CONFIG_INTERFACE); - if (CONFIG_INTERFACE == I2C_INTERFACE) { - ESP_LOGI(tag, "INTERFACE=i2c"); - ESP_LOGI(tag, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO); - ESP_LOGI(tag, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO); - ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); - ESP_LOGI(tag, "CONFIG_MODEL=%d",CONFIG_MODEL); - i2c_master_init(CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO); - if (CONFIG_MODEL == SSD1306_128x64) i2c_init(&dev, 128, 64, 0x3C); - if (CONFIG_MODEL == SSD1306_128x32) i2c_init(&dev, 128, 32, 0x3C); - } else { - ESP_LOGI(tag, "INTERFACE=SPI"); - ESP_LOGI(tag, "CONFIG_CS_GPIO=%d",CONFIG_CS_GPIO); - ESP_LOGI(tag, "CONFIG_DC_GPIO=%d",CONFIG_DC_GPIO); - ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); - spi_master_init(&dev, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO); - spi_init(&dev, 128, 64); - } +#if CONFIG_I2C_INTERFACE + ESP_LOGI(tag, "INTERFACE is i2c"); + ESP_LOGI(tag, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO); + ESP_LOGI(tag, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO); + ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); + i2c_master_init(CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO); +#if CONFIG_SSD1306_128x64 + ESP_LOGI(tag, "Panel is 128x64"); + i2c_init(&dev, 128, 64, 0x3C); +#endif // CONFIG_SSD1306_128x64 +#if CONFIG_SSD1306_128x32 + ESP_LOGI(tag, "Panel is 128x32"); + i2c_init(&dev, 128, 32, 0x3C); +#endif // CONFIG_SSD1306_128x32 +#endif // CONFIG_I2C_INTERFACE + +#if CONFIG_SPI_INTERFACE + ESP_LOGI(tag, "INTERFACE is SPI"); + ESP_LOGI(tag, "CONFIG_CS_GPIO=%d",CONFIG_CS_GPIO); + ESP_LOGI(tag, "CONFIG_DC_GPIO=%d",CONFIG_DC_GPIO); + ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); + spi_master_init(&dev, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO); + spi_init(&dev, 128, 64); +#endif // CONFIG_SPI_INTERFACE ssd1306_clear_screen(&dev, false); ssd1306_contrast(&dev, 0xff); - if (CONFIG_MODEL == SSD1306_128x64) { - top = 2; - center = 3; - bottom = 8; - ssd1306_display_text(&dev, 0, "SSD1306 128x64", 14, false); - ssd1306_display_text(&dev, 1, "ABCDEFGHIJKLMNOP", 16, false); - ssd1306_display_text(&dev, 2, "abcdefghijklmnop",16, false); - ssd1306_display_text(&dev, 3, "Hello World!!", 13, false); - ssd1306_clear_line(&dev, 4, true); - ssd1306_clear_line(&dev, 5, true); - ssd1306_clear_line(&dev, 6, true); - ssd1306_clear_line(&dev, 7, true); - ssd1306_display_text(&dev, 4, "SSD1306 128x64", 14, true); - ssd1306_display_text(&dev, 5, "ABCDEFGHIJKLMNOP", 16, true); - ssd1306_display_text(&dev, 6, "abcdefghijklmnop",16, true); - ssd1306_display_text(&dev, 7, "Hello World!!", 13, true); - } - if (CONFIG_MODEL == SSD1306_128x32) { - top = 1; - center = 1; - bottom = 4; - ssd1306_display_text(&dev, 0, "SSD1306 128x32", 14, false); - ssd1306_display_text(&dev, 1, "Hello World!!", 13, false); - ssd1306_clear_line(&dev, 2, true); - ssd1306_clear_line(&dev, 3, true); - ssd1306_display_text(&dev, 2, "SSD1306 128x32", 14, true); - ssd1306_display_text(&dev, 3, "Hello World!!", 13, true); - } +#if CONFIG_SSD1306_128x64 || CONFIG_SPI_INTERFACE + top = 2; + center = 3; + bottom = 8; + ssd1306_display_text(&dev, 0, "SSD1306 128x64", 14, false); + ssd1306_display_text(&dev, 1, "ABCDEFGHIJKLMNOP", 16, false); + ssd1306_display_text(&dev, 2, "abcdefghijklmnop",16, false); + ssd1306_display_text(&dev, 3, "Hello World!!", 13, false); + ssd1306_clear_line(&dev, 4, true); + ssd1306_clear_line(&dev, 5, true); + ssd1306_clear_line(&dev, 6, true); + ssd1306_clear_line(&dev, 7, true); + ssd1306_display_text(&dev, 4, "SSD1306 128x64", 14, true); + ssd1306_display_text(&dev, 5, "ABCDEFGHIJKLMNOP", 16, true); + ssd1306_display_text(&dev, 6, "abcdefghijklmnop",16, true); + ssd1306_display_text(&dev, 7, "Hello World!!", 13, true); +#endif // CONFIG_SSD1306_128x64 + +#if CONFIG_SSD1306_128x32 + top = 1; + center = 1; + bottom = 4; + ssd1306_display_text(&dev, 0, "SSD1306 128x32", 14, false); + ssd1306_display_text(&dev, 1, "Hello World!!", 13, false); + ssd1306_clear_line(&dev, 2, true); + ssd1306_clear_line(&dev, 3, true); + ssd1306_display_text(&dev, 2, "SSD1306 128x32", 14, true); + ssd1306_display_text(&dev, 3, "Hello World!!", 13, true); +#endif // CONFIG_SSD1306_128x32 vTaskDelay(3000 / portTICK_PERIOD_MS); // Display Count Down diff --git a/main/ssd1306.h b/main/ssd1306.h index 0eaa8b1..5bf71a8 100644 --- a/main/ssd1306.h +++ b/main/ssd1306.h @@ -68,13 +68,6 @@ Usage: #define OLED_CMD_VERTICAL 0xA3 #define SPIAddress 0xFF -#define I2C_INTERFACE 1 -#define SPI_INTERFACE 2 - -typedef enum { - SSD1306_128x64 = 1, // 128x64 panel - SSD1306_128x32 = 2 // 128x32 panel -} ssd1306_panel_type_t; typedef enum { SCROLL_RIGHT = 1,