Support ESP32-S2

This commit is contained in:
nopnop2002 2020-12-06 18:11:27 +09:00
parent 75eef1ce3a
commit e54691c5b0
6 changed files with 153 additions and 110 deletions

View File

@ -1,45 +1,56 @@
# esp-idf-ssd1306
Example code for driving OLED display with SSD1306 driver using ESP-IDF.
SSD1306 driver for esp-idf
I used [this](https://github.com/yanbe/ssd1306-esp-idf-i2c) repository as a reference.
I used [this](https://github.com/dhepper/font8x8) font file.
# Installation for ESP32
```
git clone https://github.com/nopnop2002/esp-idf-ssd1306
cd esp-idf-ssd1306/
idf.py set-target esp32
idf.py menuconfig
idf.py flash
```
# Installation for ESP32-S2
```
git clone https://github.com/nopnop2002/esp-idf-ssd1306
cd esp-idf-ssd1306/
idf.py set-target esp32s2
idf.py menuconfig
idf.py flash
```
You have to set this config value with menuconfig.
- CONFIG_INTERFACE
- CONFIG_PANEL
- CONFIG_SDA_GPIO
- CONFIG_SCL_GPIO
- CONFIG_RESET_GPIO
- CONFIG_MOSI_GPIO
- CONFIG_SCLK_GPIO
- CONFIG_CS_GPIO
- CONFIG_DC_GPIO
```
git clone https://github.com/nopnop2002/esp-idf-ssd1306
cd esp-idf-ssd1306/
make menuconfig
make flash
```
![config](https://user-images.githubusercontent.com/6020549/56449085-4f458380-6350-11e9-95f8-8583c3f78e80.jpg)
![config-main](https://user-images.githubusercontent.com/6020549/101276030-7387f980-37ed-11eb-85af-3babe939f0a1.jpg)
---
# 128x32 i2c
# Generic 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/58878909-5c0b1480-870f-11e9-90db-20d3d103415b.jpg)
RESET GPIO is not use.
![config-128x32_i2c](https://user-images.githubusercontent.com/6020549/101276039-85699c80-37ed-11eb-8cc5-07426c60e7de.jpg)
---
# 128x64 i2c
# Generic 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/58878927-69c09a00-870f-11e9-9dee-72e5647a0004.jpg)
RESET GPIO is not use.
![config-128x64_i2c](https://user-images.githubusercontent.com/6020549/101276050-961a1280-37ed-11eb-8b85-b8e1de585832.jpg)
---
@ -48,27 +59,20 @@ RESET GPIO is not use.
![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/58879031-a4c2cd80-870f-11e9-941b-05c6a14e3e9f.jpg)
RESET GPIO is use.
![config-128x64_TTGO](https://user-images.githubusercontent.com/6020549/101276064-b8139500-37ed-11eb-8e10-59447903cb80.jpg)
---
# 128x64 ESP-WROOM-32
![ESP32-OLED-2](https://user-images.githubusercontent.com/6020549/57063327-d229ef00-6cfd-11e9-98ab-8448e14d81e2.JPG)
![config-ESP-WROOM-32](https://user-images.githubusercontent.com/6020549/58879064-b4421680-870f-11e9-94c6-c3008fb56203.jpg)
RESET GPIO is not use.
![config-ESP-WROOM-32](https://user-images.githubusercontent.com/6020549/101276069-c5c91a80-37ed-11eb-98bf-c32207d3346f.jpg)
---
# 128x64 SPI
# Generic 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/58879091-cae86d80-870f-11e9-82da-6e757fbe2f20.jpg)
MOSI(D0) is GPIO13.
SCLK(D1) is GPIO14.
![config-128x64_spi](https://user-images.githubusercontent.com/6020549/101276076-cd88bf00-37ed-11eb-9183-c8b9f4ee4974.jpg)

View File

@ -1,86 +1,115 @@
menu "SSD1306 Configuration"
choice INTERFACE
prompt "Interface"
default I2C_INTERFACE
help
Select Interface.
config I2C_INTERFACE
bool "I2C Interface"
help
I2C Interface.
config SPI_INTERFACE
bool "SPI Interface"
help
SPI Interface.
endchoice
choice INTERFACE
prompt "Interface"
default I2C_INTERFACE
help
Select Interface.
config I2C_INTERFACE
bool "I2C Interface"
help
I2C Interface.
config SPI_INTERFACE
bool "SPI Interface"
help
SPI Interface.
endchoice
if I2C_INTERFACE
choice PANEL
prompt "Panel Type"
default SSD1306_128x64
help
Select Panel Type.
config SSD1306_128x32
bool "128x32 Panel"
help
Panel is 128x32.
config SSD1306_128x64
bool "128x64 Panel"
help
Panel is 128x64.
endchoice
choice PANEL
depends on I2C_INTERFACE
prompt "Panel Type"
default SSD1306_128x64
help
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"
range 0 34
default 22
help
GPIO number (IOxx) to I2C SCL.
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.
config SCL_GPIO
depends on I2C_INTERFACE
int "SCL GPIO number"
range 0 46
default 22 if IDF_TARGET_ESP32
default 12 if IDF_TARGET_ESP32S2
help
GPIO number (IOxx) to I2C SCL.
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.
config SDA_GPIO
int "SDA GPIO number"
range 0 34
default 21
help
GPIO number (IOxx) to I2C SDA.
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.
config SDA_GPIO
depends on I2C_INTERFACE
int "SDA GPIO number"
range 0 46
default 21 if IDF_TARGET_ESP32
default 11 if IDF_TARGET_ESP32S2
help
GPIO number (IOxx) to I2C SDA.
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
default -1
help
GPIO number (IOxx) to RESET.
When it is -1, RESET isn't performed.
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.
config RESET_GPIO
int "RESET GPIO number"
range -1 46
default -1
help
GPIO number (IOxx) to RESET.
When it is -1, RESET isn't performed.
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
default 15
help
GPIO number (IOxx) to SPI CS.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to CS.
GPIOs 35-39 are input-only so cannot be used as outputs.
config MOSI_GPIO
depends on SPI_INTERFACE
int "MOSI GPIO number"
range 0 46
default 23 if IDF_TARGET_ESP32
default 35 if IDF_TARGET_ESP32S2
help
GPIO number (IOxx) to SPI MOSI.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to DC.
On the ESP32, GPIOs 35-39 are input-only so cannot be used as outputs.
On the ESP32-S2, GPIO 46 is input-only so cannot be used as outputs.
config DC_GPIO
int "DC GPIO number"
range 0 34
default 33
help
GPIO number (IOxx) to SPI DC.
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.
config SCLK_GPIO
depends on SPI_INTERFACE
int "SCLK GPIO number"
range 0 46
default 18 if IDF_TARGET_ESP32
default 36 if IDF_TARGET_ESP32S2
help
GPIO number (IOxx) to SPI SCLK.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to DC.
On the ESP32, GPIOs 35-39 are input-only so cannot be used as outputs.
On the ESP32-S2, GPIO 46 is input-only so cannot be used as outputs.
config CS_GPIO
depends on SPI_INTERFACE
int "CS GPIO number"
range 0 34
default 5 if IDF_TARGET_ESP32
default 34 if IDF_TARGET_ESP32S2
help
GPIO number (IOxx) to SPI CS.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to CS.
GPIOs 35-39 are input-only so cannot be used as outputs.
config DC_GPIO
depends on SPI_INTERFACE
int "DC GPIO number"
range 0 34
default 2
help
GPIO number (IOxx) to SPI DC.
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

View File

@ -50,10 +50,12 @@ void app_main(void)
#if CONFIG_SPI_INTERFACE
ESP_LOGI(tag, "INTERFACE is SPI");
ESP_LOGI(tag, "CONFIG_MOSI_GPIO=%d",CONFIG_MOSI_GPIO);
ESP_LOGI(tag, "CONFIG_SCLK_GPIO=%d",CONFIG_SCLK_GPIO);
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_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO);
spi_init(&dev, 128, 64);
#endif // CONFIG_SPI_INTERFACE

View File

@ -110,14 +110,14 @@ void ssd1306_invert(uint8_t *buf, size_t blen);
void ssd1306_fadeout(SSD1306_t * dev);
void ssd1306_dump(SSD1306_t dev);
void i2c_master_init(int sda, int scl, int reset);
void i2c_master_init(int16_t sda, int16_t scl, int16_t reset);
void i2c_init(SSD1306_t * dev, int width, int height, int I2CAddress);
void i2c_display_text(SSD1306_t * dev, int page, char * text, int text_len, bool invert);
void i2c_display_image(SSD1306_t * dev, int page, int seg, uint8_t * images, int width);
void i2c_contrast(SSD1306_t * dev, int contrast);
void i2c_hardware_scroll(SSD1306_t * dev, ssd1306_scroll_type_t scroll);
void spi_master_init(SSD1306_t * dev, int GPIO_CS, int GPIO_DC, int GPIO_RESET);
void spi_master_init(SSD1306_t * dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int16_t GPIO_CS, int16_t GPIO_DC, int16_t GPIO_RESET);
bool spi_master_write_byte(spi_device_handle_t SPIHandle, const uint8_t* Data, size_t DataLength );
bool spi_master_write_command(SSD1306_t * dev, uint8_t Command );
bool spi_master_write_data(SSD1306_t * dev, const uint8_t* Data, size_t DataLength );

View File

@ -11,7 +11,7 @@
#define tag "SSD1306"
void i2c_master_init(int sda, int scl, int reset)
void i2c_master_init(int16_t sda, int16_t scl, int16_t reset)
{
i2c_config_t i2c_config = {
.mode = I2C_MODE_MASTER,

View File

@ -12,14 +12,22 @@
#define tag "SSD1306"
static const int GPIO_MOSI = 13;
static const int GPIO_SCLK = 14;
//static const int GPIO_MOSI = 23;
//static const int GPIO_SCLK = 18;
#ifdef CONFIG_IDF_TARGET_ESP32
#define LCD_HOST HSPI_HOST
#define DMA_CHAN 2
#elif defined CONFIG_IDF_TARGET_ESP32S2
#define LCD_HOST SPI2_HOST
#define DMA_CHAN LCD_HOST
#endif
static const int SPI_Command_Mode = 0;
static const int SPI_Data_Mode = 1;
static const int SPI_Frequency = 1000000;
void spi_master_init(SSD1306_t * dev, int GPIO_CS, int GPIO_DC, int GPIO_RESET)
void spi_master_init(SSD1306_t * dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int16_t GPIO_CS, int16_t GPIO_DC, int16_t GPIO_RESET)
{
esp_err_t ret;
@ -47,7 +55,7 @@ void spi_master_init(SSD1306_t * dev, int GPIO_CS, int GPIO_DC, int GPIO_RESET)
.quadhd_io_num = -1
};
ret = spi_bus_initialize( HSPI_HOST, &spi_bus_config, 1 );
ret = spi_bus_initialize( LCD_HOST, &spi_bus_config, DMA_CHAN );
ESP_LOGI(tag, "spi_bus_initialize=%d",ret);
assert(ret==ESP_OK);
@ -58,7 +66,7 @@ void spi_master_init(SSD1306_t * dev, int GPIO_CS, int GPIO_DC, int GPIO_RESET)
devcfg.queue_size = 1;
spi_device_handle_t handle;
ret = spi_bus_add_device( HSPI_HOST, &devcfg, &handle);
ret = spi_bus_add_device( LCD_HOST, &devcfg, &handle);
ESP_LOGI(tag, "spi_bus_add_device=%d",ret);
assert(ret==ESP_OK);
dev->_dc = GPIO_DC;