Add gpio_pad_select_gpio

This commit is contained in:
nopnop2002 2019-06-02 11:02:09 +09:00
parent edab7d4b92
commit 306c4def7b
5 changed files with 49 additions and 29 deletions

View File

@ -3,7 +3,7 @@
# project subdirectory.
#
PROJECT_NAME := app-template
PROJECT_NAME := ssd1306
include $(IDF_PATH)/make/project.mk

View File

@ -34,12 +34,12 @@ void app_main(void)
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);
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 {
@ -55,7 +55,7 @@ void app_main(void)
ssd1306_contrast(&dev, 0xff);
if (CONFIG_MODEL == SSD1306_128x64) {
top = 2;
center = 3;
center = 3;
bottom = 8;
ssd1306_display_text(&dev, 0, "SSD1306 128x64", 14, false);
ssd1306_display_text(&dev, 1, "ABCDEFGHIJKLMNOP", 16, false);
@ -82,7 +82,7 @@ void app_main(void)
ssd1306_display_text(&dev, 3, "Hello World!!", 13, true);
}
vTaskDelay(3000 / portTICK_PERIOD_MS);
// Display Count Down
uint8_t image[24];
memset(image, 0, sizeof(image));

View File

@ -138,8 +138,8 @@ void ssd1306_fadeout(SSD1306_t * dev)
uint8_t image[1];
for(int page=0; page<dev->_pages; page++) {
image[0] = 0xFF;
for(int line=0; line<8; line++) {
image[0] = 0xFF;
for(int line=0; line<8; line++) {
image[0] = image[0] << 1;
for(int seg=0; seg<128; seg++) {
(*func)(dev, page, seg, image, 1);

View File

@ -26,7 +26,6 @@ void i2c_master_init(int sda, int scl, int reset)
if (reset >= 0) {
gpio_pad_select_gpio(reset);
/* Set the GPIO as a push/pull output */
gpio_set_direction(reset, GPIO_MODE_OUTPUT);
gpio_set_level(reset, 0);
vTaskDelay(50 / portTICK_PERIOD_MS);
@ -148,6 +147,26 @@ void i2c_display_image(SSD1306_t * dev, int page, int seg, uint8_t * images, int
i2c_cmd_link_delete(cmd);
}
#if 0
void ssd1306_clear_screen(SSD1306_t * dev, bool invert) {
char zero[128];
memset(zero, 0, sizeof(zero));
for (int page = 0; page < dev->_pages; page++) {
ssd1306_display_text(dev, page, zero, 128, invert);
}
}
#endif
#if 0
void ssd1306_clear_line(SSD1306_t * dev, int page, bool invert) {
char zero[128];
memset(zero, 0, sizeof(zero));
ssd1306_display_text(dev, page, zero, 128, invert);
}
#endif
void i2c_contrast(SSD1306_t * dev, int contrast) {
i2c_cmd_handle_t cmd;
int _contrast = contrast;
@ -273,5 +292,17 @@ void i2c_scroll(SSD1306_t * dev, ssd1306_scroll_type_t scroll) {
i2c_cmd_link_delete(cmd);
}
#if 0
void ssd1306_fadeout(SSD1306_t * dev) {
uint8_t image[1];
for(int page=0; page<dev->_pages; page++) {
image[0] = 0xFF;
for(int line=0; line<8; line++) {
image[0] = image[0] << 1;
for(int seg=0; seg<128; seg++) {
ssd1306_display_image(dev, page, seg, image, 1);
}
}
}
}
#endif

View File

@ -23,13 +23,16 @@ void spi_master_init(SSD1306_t * dev, int GPIO_CS, int GPIO_DC, int GPIO_RESET)
{
esp_err_t ret;
gpio_pad_select_gpio( GPIO_CS );
gpio_set_direction( GPIO_CS, GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_CS, 0 );
gpio_pad_select_gpio( GPIO_DC );
gpio_set_direction( GPIO_DC, GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_DC, 0 );
if ( GPIO_RESET >= 0 ) {
gpio_pad_select_gpio( GPIO_RESET );
gpio_set_direction( GPIO_RESET, GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_RESET, 0 );
vTaskDelay( pdMS_TO_TICKS( 100 ) );
@ -54,20 +57,6 @@ void spi_master_init(SSD1306_t * dev, int GPIO_CS, int GPIO_DC, int GPIO_RESET)
devcfg.spics_io_num = GPIO_CS;
devcfg.queue_size = 1;
#if 0
spi_device_interface_config_t devcfg={
.command_bits=0,
.address_bits=0,
.dummy_bits=0,
.clock_speed_hz=5000000,
.duty_cycle_pos=128, //50% duty cycle
.mode=0,
.spics_io_num=GPIO_CS,
.cs_ena_posttrans=3, //Keep the CS low 3 cycles after transaction, to stop slave from missing the last bit when CS has less propagation delay than CLK
.queue_size=3
};
#endif
spi_device_handle_t handle;
ret = spi_bus_add_device( HSPI_HOST, &devcfg, &handle);
ESP_LOGI(tag, "spi_bus_add_device=%d",ret);
@ -158,7 +147,7 @@ void spi_display_text(SSD1306_t * dev, int page, char * text, int text_len, bool
uint8_t image[8];
for (uint8_t i = 0; i < _text_len; i++) {
memcpy(image, font8x8_basic_tr[(uint8_t)text[i]], 8);
if (invert) ssd1306_invert(image, 8);
if (invert) ssd1306_invert(image, 8);
spi_display_image(dev, page, seg, image, 8);
for(int j=0;j<8;j++)
dev->_page[page]._segs[seg+j] = image[j];