Add I2C example to communication abstraction interface

This commit is contained in:
C47D 2021-11-19 21:05:39 -06:00
parent 8bdc2aed38
commit db8be8a4da
5 changed files with 33 additions and 38 deletions

View file

@ -7,6 +7,11 @@
#include "driver/gpio.h" #include "driver/gpio.h"
#include "disp_spi.h" #include "disp_spi.h"
#include "lvgl_i2c/i2c_manager.h"
/* TODO: This is ssd1306 specific */
#define OLED_I2C_PORT (CONFIG_LV_I2C_DISPLAY_PORT)
#define OLED_I2C_ADDRESS 0x3C
#define LV_DISPLAY_DC_CMD_MODE 0 #define LV_DISPLAY_DC_CMD_MODE 0
#define LV_DISPLAY_DC_DATA_MODE 1 #define LV_DISPLAY_DC_DATA_MODE 1
@ -75,6 +80,9 @@ void display_interface_send_cmd(lv_disp_drv_t *drv, uint8_t cmd, void *args, siz
disp_spi_send_data(args, args_len); disp_spi_send_data(args, args_len);
} }
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C) #elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
(void) drv;
uint8_t *data = (uint8_t *) args;
lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, cmd, data, args_len);
#endif #endif
} }
@ -86,5 +94,20 @@ void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t le
disp_spi_send_colors(data, len); disp_spi_send_colors(data, len);
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C) #elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
(void) drv;
lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, data, len);
#endif
}
void display_interface_send_data(lv_disp_drv_t *drv, void *data, size_t len)
{
#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI)
disp_wait_for_pending_transactions();
display_port_gpio_dc(drv, LV_DISPLAY_DC_DATA_MODE);
disp_spi_send_colors(data, len);
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
(void) drv;
lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, data, len);
#endif #endif
} }

View file

@ -28,7 +28,7 @@ void *disp_driver_init(lv_disp_drv_t *drv)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107 #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107
sh1107_init(); sh1107_init();
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306 #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
ssd1306_init(); ssd1306_init(drv);
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X
FT81x_init(); FT81x_init();
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820 #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820

View file

@ -57,6 +57,7 @@ void display_port_gpio_rst(lv_disp_drv_t *drv, uint8_t state);
bool display_port_gpio_is_busy(lv_disp_drv_t *drv); bool display_port_gpio_is_busy(lv_disp_drv_t *drv);
void display_interface_send_cmd(lv_disp_drv_t *drv, uint8_t cmd, void *args, size_t args_len); void display_interface_send_cmd(lv_disp_drv_t *drv, uint8_t cmd, void *args, size_t args_len);
void display_interface_send_data(lv_disp_drv_t *drv, void *data, size_t len);
void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t len); void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t len);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -15,16 +15,13 @@
*********************/ *********************/
#include "assert.h" #include "assert.h"
#include "lvgl_i2c/i2c_manager.h"
#include "ssd1306.h" #include "ssd1306.h"
#include "display_port.h"
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define OLED_I2C_PORT (CONFIG_LV_I2C_DISPLAY_PORT)
// SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000) // SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000)
#define OLED_I2C_ADDRESS 0x3C
#define OLED_WIDTH 128 #define OLED_WIDTH 128
#define OLED_HEIGHT 64 #define OLED_HEIGHT 64
#define OLED_COLUMNS 128 #define OLED_COLUMNS 128
@ -75,8 +72,6 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len);
static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t buffer_len);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -92,7 +87,7 @@ static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t b
/********************** /**********************
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
void ssd1306_init(void) void ssd1306_init(lv_disp_drv_t *disp_drv)
{ {
uint8_t orientation_1 = 0; uint8_t orientation_1 = 0;
uint8_t orientation_2 = 0; uint8_t orientation_2 = 0;
@ -127,8 +122,7 @@ void ssd1306_init(void)
OLED_CMD_DISPLAY_ON OLED_CMD_DISPLAY_ON
}; };
uint8_t err = send_data(NULL, conf, sizeof(conf)); display_interface_send_cmd(disp_drv, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], sizeof(conf) - 1);
assert(0 == err);
} }
void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
@ -162,10 +156,8 @@ void ssd1306_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t
row2, row2,
}; };
uint8_t err = send_data(disp_drv, conf, sizeof(conf)); display_interface_send_cmd(disp_drv, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], sizeof(conf) - 1);
assert(0 == err); display_interface_send_data(disp_drv, color_p, OLED_COLUMNS * (1 + row2 - row1));
err = send_pixels(disp_drv, color_p, OLED_COLUMNS * (1 + row2 - row1));
assert(0 == err);
lv_disp_flush_ready(disp_drv); lv_disp_flush_ready(disp_drv);
} }
@ -188,8 +180,7 @@ void ssd1306_sleep_in(void)
OLED_CMD_DISPLAY_OFF OLED_CMD_DISPLAY_OFF
}; };
uint8_t err = send_data(NULL, conf, sizeof(conf)); display_interface_send_cmd(NULL, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], 1);
assert(0 == err);
} }
void ssd1306_sleep_out(void) void ssd1306_sleep_out(void)
@ -199,25 +190,5 @@ void ssd1306_sleep_out(void)
OLED_CMD_DISPLAY_ON OLED_CMD_DISPLAY_ON
}; };
uint8_t err = send_data(NULL, conf, sizeof(conf)); display_interface_send_cmd(NULL, OLED_CONTROL_BYTE_CMD_STREAM, &conf[1], 1);
assert(0 == err);
}
/**********************
* STATIC FUNCTIONS
**********************/
static uint8_t send_data(lv_disp_drv_t *disp_drv, void *bytes, size_t bytes_len)
{
(void) disp_drv;
uint8_t *data = (uint8_t *) bytes;
return lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, data[0], data + 1, bytes_len - 1 );
}
static uint8_t send_pixels(lv_disp_drv_t *disp_drv, void *color_buffer, size_t buffer_len)
{
(void) disp_drv;
return lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, color_buffer, buffer_len);
} }

View file

@ -34,7 +34,7 @@ extern "C" {
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
void ssd1306_init(void); void ssd1306_init(lv_disp_drv_t *disp_drv);
void ssd1306_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map); void ssd1306_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
void ssd1306_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area); void ssd1306_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area);
void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, void ssd1306_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,