Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lvgl: Add i2c interface driver #3088

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions hw/drivers/display/lcd_itf/itf_i2c/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

pkg.name: hw/drivers/display/lcd_itf/itf_i2c
pkg.description: LCD Standard I2C interface
pkg.keywords:
- display

pkg.apis:
- lcd_interface

pkg.deps:
# - "@apache-mynewt-core/hw/bus/drivers/i2c_common"
96 changes: 96 additions & 0 deletions hw/drivers/display/lcd_itf/itf_i2c/src/itf_i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <bsp/bsp.h>
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
#include <bus/drivers/i2c_common.h>
#else
#include <hal/hal_i2c.h>
#endif

#include <lv_conf.h>
#include <lcd_itf.h>

#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
static struct bus_i2c_node lcd;
static struct bus_i2c_node_cfg lcd_i2c_cfg = {
.node_cfg.bus_name = MYNEWT_VAL(LCD_I2C_DEV_NAME),
.addr = MYNEWT_VAL(LCD_I2C_ADDR),
.freq = MYNEWT_VAL(LCD_I2C_FREQ),
};
static struct os_dev *lcd_dev;
#else
#endif

void
lcd_itf_write_color_data(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void *pixels)
{
uint8_t *color_data = pixels;
size_t size = ((x2 - x1 + 1) * (y2 - y1 + 1)) >> 3;

#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
color_data[-1] = 0x40;
bus_node_write(lcd_dev, color_data - 1, size + 1, 1000, 0);
#else
color_data[-1] = 0x40;
struct hal_i2c_master_data data = {
.address = MYNEWT_VAL(LCD_I2C_ADDR),
.buffer = color_data - 1,
.len = size + 1,
};
hal_i2c_master_write(0, &data, 1000, 1);
#endif
}

void
lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length)
{
uint8_t buf[cmd_length + 1];

buf[0] = 0;
for (int i = 0; i < cmd_length; ++i) {
buf[i + 1] = cmd[i];
}
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
bus_node_write(lcd_dev, buf, cmd_length + 1, 1000, 0);
#else
struct hal_i2c_master_data data = {
.address = MYNEWT_VAL(LCD_I2C_ADDR),
.buffer = buf,
.len = cmd_length + 1,
};
hal_i2c_master_write(0, &data, 1000, 1);
#endif
}


void
lcd_itf_init(void)
{
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
int rc;
struct bus_node_callbacks cbs = {};

bus_node_set_callbacks((struct os_dev *)&lcd, &cbs);

rc = bus_i2c_node_create("display", &lcd, &lcd_i2c_cfg, NULL);
assert(rc == 0);
lcd_dev = os_dev_open("display", 0, NULL);
#endif
}
34 changes: 34 additions & 0 deletions hw/drivers/display/lcd_itf/itf_i2c/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

syscfg.defs:
LCD_I2C_DEV_NAME:
description: I2C device name that LCD is connected to.
value: '"i2c0"'
LCD_I2C_ADDR:
description: LCD I2C address.
value:
restriction: $notnull
LCD_I2C_FREQ:
description: I2C device frequency for LCD (typical 100/400 kHz)
value: 100
LCD_I2C_MAX_TRANSFER:
description: Maximum nuber of bytes that I2C interface supports
value:

syscfg.restrictions:
2 changes: 2 additions & 0 deletions hw/drivers/display/lcd_itf/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pkg.req_apis:

pkg.deps.'LCD_ITF == "spi"':
- "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_spi"
pkg.deps.'LCD_ITF == "i2c"':
- "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_i2c"
pkg.deps.'LCD_ITF == "8080_II_8_bit"':
- "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_8080"
pkg.deps.'LCD_ITF == "8080_II_16_bit"':
Expand Down
1 change: 1 addition & 0 deletions hw/drivers/display/lcd_itf/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ syscfg.defs:
choices:
- custom
- spi
- i2c
- 8080_II_8_bit
- 8080_II_16_bit
value: spi
Expand Down
28 changes: 28 additions & 0 deletions hw/drivers/display/lvgl/oled/ssd1306/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

pkg.name: hw/drivers/display/lvgl/oled/ssd1306
pkg.description: LVGL display driver for SSD1306
pkg.author: "Apache Mynewt <[email protected]>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.cflags:

pkg.deps:
- "@apache-mynewt-core/hw/drivers/display/lcd_itf"
Loading
Loading