mirror of
https://github.com/nopnop2002/esp-idf-ssd1306.git
synced 2024-10-03 18:18:47 -04:00
Added SPI BUS selection
This commit is contained in:
parent
626a019137
commit
de63804a3d
25
README.md
25
README.md
@ -47,14 +47,12 @@ You have to set this config value with menuconfig.
|
||||
![128x32](https://user-images.githubusercontent.com/6020549/56449097-6d12e880-6350-11e9-8edd-7a8fc5eaeedc.JPG)
|
||||
![config-128x32_i2c](https://user-images.githubusercontent.com/6020549/115942099-79a01d80-a4e3-11eb-9274-8746920fca78.jpg)
|
||||
|
||||
---
|
||||
|
||||
# Generic SSD1306 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/127076697-385ecafa-ccb7-4511-a862-70a6143930dd.jpg)
|
||||
|
||||
---
|
||||
|
||||
# Generic SH1106 128x64 i2c
|
||||
__Hardware scroll Not support__
|
||||
@ -64,7 +62,6 @@ Right:0.96 inch SSD1306
|
||||
![SH1106_i2c](https://user-images.githubusercontent.com/6020549/106342871-09b83780-62e6-11eb-999c-912f0e0c9f0f.JPG)
|
||||
![config-sh1106_i2c](https://user-images.githubusercontent.com/6020549/127077379-ad688621-999e-475e-b1fe-c093d7599783.jpg)
|
||||
|
||||
---
|
||||
|
||||
# 128x64 TTGO
|
||||
Unlike other ESP32 development boards, the RTC_CLOCK crystal on this board uses a 26MHz one.
|
||||
@ -75,7 +72,6 @@ You need to change the RTC CLOCK frequency to 26MHz using menuconfig.
|
||||
![128x64_Reset](https://user-images.githubusercontent.com/6020549/56449118-9e8bb400-6350-11e9-9b90-1eb1f9fa8e99.JPG)
|
||||
![config-128x64_TTGO](https://user-images.githubusercontent.com/6020549/106342639-18521f00-62e5-11eb-8afa-126cd781eb0e.jpg)
|
||||
|
||||
---
|
||||
|
||||
# 128x64 ESP-WROOM-32
|
||||
|
||||
@ -87,18 +83,16 @@ You need to change the RTC CLOCK frequency to 26MHz using menuconfig.
|
||||
# Generic SSD1306 128x32 SPI
|
||||
|
||||
![128x32_spi](https://user-images.githubusercontent.com/6020549/106338743-ef775d00-62d7-11eb-8e0c-42c09e6045b9.JPG)
|
||||
![config-128x32_spi](https://user-images.githubusercontent.com/6020549/127077082-7b60e635-e410-4324-b807-c368d03f5b5f.jpg)
|
||||
![config-128x32_spi](https://user-images.githubusercontent.com/6020549/202815621-f9d0d2c8-3b72-41bb-bf2e-59f984177f03.jpg)
|
||||
|
||||
---
|
||||
|
||||
# Generic SSD1306 128x64 SPI
|
||||
D0 is SCLK.
|
||||
D1 is MOSI.
|
||||
|
||||
![128x64_spi](https://user-images.githubusercontent.com/6020549/56844607-ee88ee80-68ed-11e9-9b20-ab5e7e0d2a99.JPG)
|
||||
![config-128x64_spi](https://user-images.githubusercontent.com/6020549/127076276-275715c7-afb4-4922-bb93-bd66f232606b.jpg)
|
||||
![config-128x64_spi](https://user-images.githubusercontent.com/6020549/202815721-189f9abe-7195-43de-b1c9-b4d1fd40af86.jpg)
|
||||
|
||||
---
|
||||
|
||||
# Generic SH1106 128x64 SPI
|
||||
__Hardware scroll Not support__
|
||||
@ -106,7 +100,20 @@ Left:1.3 inch SH1106
|
||||
Right:0.96 inch SSD1306
|
||||
|
||||
![SH1106_spi](https://user-images.githubusercontent.com/6020549/106343561-58b39c00-62e9-11eb-8ce7-913bf15cb803.JPG)
|
||||
![config-sh1106_spi](https://user-images.githubusercontent.com/6020549/127077395-d1a9b34c-6000-4aa6-a2e4-13fdbfac6fbb.jpg)
|
||||
![config-sh1106_spi](https://user-images.githubusercontent.com/6020549/202815762-f2431f59-8d21-4b9b-a822-330cb2bc9afd.jpg)
|
||||
|
||||
---
|
||||
|
||||
# SPI BUS selection
|
||||
![config-spi-bus](https://user-images.githubusercontent.com/6020549/202815807-6c2df14f-f38e-4032-94fb-da1723607279.jpg)
|
||||
|
||||
The ESP32 series has three SPI BUSs.
|
||||
SPI1_HOST is used for communication with Flash memory.
|
||||
You can use SPI2_HOST and SPI3_HOST freely.
|
||||
When you use SDSPI(SD Card via SPI), SDSPI uses SPI2_HOST BUS.
|
||||
When using this module at the same time as SDSPI or other SPI device using SPI2_HOST, it needs to be changed to SPI3_HOST.
|
||||
When you don't use SDSPI, both SPI2_HOST and SPI3_HOST will work.
|
||||
Previously it was called HSPI_HOST / VSPI_HOST, but now it is called SPI2_HOST / SPI3_HOST.
|
||||
|
||||
---
|
||||
|
||||
|
@ -57,7 +57,7 @@ menu "SSD1306 Configuration"
|
||||
default 22 if IDF_TARGET_ESP32
|
||||
default 12 if IDF_TARGET_ESP32S2
|
||||
default 12 if IDF_TARGET_ESP32S3
|
||||
default 9 if IDF_TARGET_ESP32C3
|
||||
default 6 if IDF_TARGET_ESP32C3
|
||||
help
|
||||
GPIO number (IOxx) to I2C SCL.
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to I2C.
|
||||
@ -70,25 +70,12 @@ menu "SSD1306 Configuration"
|
||||
default 21 if IDF_TARGET_ESP32
|
||||
default 11 if IDF_TARGET_ESP32S2
|
||||
default 11 if IDF_TARGET_ESP32S3
|
||||
default 10 if IDF_TARGET_ESP32C3
|
||||
default 5 if IDF_TARGET_ESP32C3
|
||||
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 RESET_GPIO
|
||||
int "RESET GPIO number"
|
||||
range -1 GPIO_RANGE_MAX
|
||||
default 33 if IDF_TARGET_ESP32
|
||||
default 38 if IDF_TARGET_ESP32S2
|
||||
default 38 if IDF_TARGET_ESP32S3
|
||||
default 3 if IDF_TARGET_ESP32C3
|
||||
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 MOSI_GPIO
|
||||
depends on SPI_INTERFACE
|
||||
int "MOSI GPIO number"
|
||||
@ -96,10 +83,10 @@ menu "SSD1306 Configuration"
|
||||
default 23 if IDF_TARGET_ESP32
|
||||
default 35 if IDF_TARGET_ESP32S2
|
||||
default 35 if IDF_TARGET_ESP32S3
|
||||
default 0 if IDF_TARGET_ESP32C3
|
||||
default 1 if IDF_TARGET_ESP32C3
|
||||
help
|
||||
GPIO number (IOxx) to SPI MOSI.
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to DC.
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to MOSI.
|
||||
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.
|
||||
|
||||
@ -110,10 +97,10 @@ menu "SSD1306 Configuration"
|
||||
default 18 if IDF_TARGET_ESP32
|
||||
default 36 if IDF_TARGET_ESP32S2
|
||||
default 36 if IDF_TARGET_ESP32S3
|
||||
default 1 if IDF_TARGET_ESP32C3
|
||||
default 2 if IDF_TARGET_ESP32C3
|
||||
help
|
||||
GPIO number (IOxx) to SPI SCLK.
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to DC.
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to SCLK.
|
||||
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.
|
||||
|
||||
@ -134,14 +121,44 @@ menu "SSD1306 Configuration"
|
||||
depends on SPI_INTERFACE
|
||||
int "DC GPIO number"
|
||||
range 0 GPIO_RANGE_MAX
|
||||
default 27 if IDF_TARGET_ESP32
|
||||
default 4 if IDF_TARGET_ESP32
|
||||
default 37 if IDF_TARGET_ESP32S2
|
||||
default 37 if IDF_TARGET_ESP32S3
|
||||
default 2 if IDF_TARGET_ESP32C3
|
||||
default 3 if IDF_TARGET_ESP32C3
|
||||
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 RESET_GPIO
|
||||
int "RESET GPIO number"
|
||||
range -1 GPIO_RANGE_MAX
|
||||
default 15 if IDF_TARGET_ESP32
|
||||
default 38 if IDF_TARGET_ESP32S2
|
||||
default 38 if IDF_TARGET_ESP32S3
|
||||
default 4 if IDF_TARGET_ESP32C3
|
||||
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.
|
||||
|
||||
choice SPI_HOST
|
||||
depends on SPI_INTERFACE
|
||||
prompt "SPI peripheral that controls this bus"
|
||||
default SPI2_HOST
|
||||
help
|
||||
Select SPI peripheral that controls this bus.
|
||||
config SPI2_HOST
|
||||
bool "SPI2_HOST"
|
||||
help
|
||||
Use SPI2_HOST. This is also called HSPI_HOST.
|
||||
config SPI3_HOST
|
||||
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
bool "SPI3_HOST"
|
||||
help
|
||||
USE SPI3_HOST. This is also called VSPI_HOST
|
||||
endchoice
|
||||
|
||||
endmenu
|
||||
|
||||
|
@ -11,14 +11,12 @@
|
||||
|
||||
#define TAG "SSD1306"
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#define LCD_HOST HSPI_HOST
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#define LCD_HOST SPI2_HOST
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define LCD_HOST SPI2_HOST
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#define LCD_HOST SPI2_HOST
|
||||
#if CONFIG_SPI2_HOST
|
||||
#define HOST_ID SPI2_HOST
|
||||
#elif CONFIG_SPI3_HOST
|
||||
#define HOST_ID SPI3_HOST
|
||||
#else
|
||||
#define HOST_ID SPI2_HOST // If i2c is selected
|
||||
#endif
|
||||
|
||||
static const int SPI_Command_Mode = 0;
|
||||
@ -58,7 +56,8 @@ void spi_master_init(SSD1306_t * dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int1
|
||||
.flags = 0
|
||||
};
|
||||
|
||||
ret = spi_bus_initialize( LCD_HOST, &spi_bus_config, SPI_DMA_CH_AUTO );
|
||||
ESP_LOGI(TAG, "SPI HOST_ID=%d", HOST_ID);
|
||||
ret = spi_bus_initialize( HOST_ID, &spi_bus_config, SPI_DMA_CH_AUTO );
|
||||
ESP_LOGI(TAG, "spi_bus_initialize=%d",ret);
|
||||
assert(ret==ESP_OK);
|
||||
|
||||
@ -69,7 +68,7 @@ void spi_master_init(SSD1306_t * dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int1
|
||||
devcfg.queue_size = 1;
|
||||
|
||||
spi_device_handle_t handle;
|
||||
ret = spi_bus_add_device( LCD_HOST, &devcfg, &handle);
|
||||
ret = spi_bus_add_device( HOST_ID, &devcfg, &handle);
|
||||
ESP_LOGI(TAG, "spi_bus_add_device=%d",ret);
|
||||
assert(ret==ESP_OK);
|
||||
dev->_dc = GPIO_DC;
|
||||
|
Loading…
Reference in New Issue
Block a user