Skip to content

Commit 2f2f4b0

Browse files
committed
lvgl: Add i2c interface driver
Driver for display that have I2C interface (SDD1306) Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 8c58e82 commit 2f2f4b0

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: hw/drivers/display/lcd_itf/itf_i2c
21+
pkg.description: LCD Standard I2C interface
22+
pkg.keywords:
23+
- display
24+
25+
pkg.apis:
26+
- lcd_interface
27+
28+
pkg.deps:
29+
# - "@apache-mynewt-core/hw/bus/drivers/i2c_common"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include <bsp/bsp.h>
21+
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
22+
#include <bus/drivers/i2c_common.h>
23+
#else
24+
#include <hal/hal_i2c.h>
25+
#endif
26+
27+
#include <lv_conf.h>
28+
#include <lcd_itf.h>
29+
30+
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
31+
static struct bus_i2c_node lcd;
32+
static struct bus_i2c_node_cfg lcd_i2c_cfg = {
33+
.node_cfg.bus_name = MYNEWT_VAL(LCD_I2C_DEV_NAME),
34+
.addr = MYNEWT_VAL(LCD_I2C_ADDR),
35+
.freq = MYNEWT_VAL(LCD_I2C_FREQ),
36+
};
37+
static struct os_dev *lcd_dev;
38+
#else
39+
#endif
40+
41+
void
42+
lcd_itf_write_color_data(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void *pixels)
43+
{
44+
uint8_t *color_data = pixels;
45+
size_t size = ((x2 - x1 + 1) * (y2 - y1 + 1)) >> 3;
46+
47+
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
48+
color_data[-1] = 0x40;
49+
bus_node_write(lcd_dev, color_data - 1, size + 1, 1000, 0);
50+
#else
51+
color_data[-1] = 0x40;
52+
struct hal_i2c_master_data data = {
53+
.address = MYNEWT_VAL(LCD_I2C_ADDR),
54+
.buffer = color_data - 1,
55+
.len = size + 1,
56+
};
57+
hal_i2c_master_write(0, &data, 1000, 1);
58+
#endif
59+
}
60+
61+
void
62+
lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length)
63+
{
64+
uint8_t buf[cmd_length + 1];
65+
66+
buf[0] = 0;
67+
for (int i = 0; i < cmd_length; ++i) {
68+
buf[i + 1] = cmd[i];
69+
}
70+
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
71+
bus_node_write(lcd_dev, buf, cmd_length + 1, 1000, 0);
72+
#else
73+
struct hal_i2c_master_data data = {
74+
.address = MYNEWT_VAL(LCD_I2C_ADDR),
75+
.buffer = buf,
76+
.len = cmd_length + 1,
77+
};
78+
hal_i2c_master_write(0, &data, 1000, 1);
79+
#endif
80+
}
81+
82+
83+
void
84+
lcd_itf_init(void)
85+
{
86+
#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common
87+
int rc;
88+
struct bus_node_callbacks cbs = {};
89+
90+
bus_node_set_callbacks((struct os_dev *)&lcd, &cbs);
91+
92+
rc = bus_i2c_node_create("display", &lcd, &lcd_i2c_cfg, NULL);
93+
assert(rc == 0);
94+
lcd_dev = os_dev_open("display", 0, NULL);
95+
#endif
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
syscfg.defs:
20+
LCD_I2C_DEV_NAME:
21+
description: I2C device name that LCD is connected to.
22+
value: '"i2c0"'
23+
LCD_I2C_ADDR:
24+
description: LCD I2C address.
25+
value:
26+
restriction: $notnull
27+
LCD_I2C_FREQ:
28+
description: I2C device frequency for LCD (typical 100/400 kHz)
29+
value: 100
30+
LCD_I2C_MAX_TRANSFER:
31+
description: Maximum nuber of bytes that I2C interface supports
32+
value:
33+
34+
syscfg.restrictions:

hw/drivers/display/lcd_itf/pkg.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pkg.req_apis:
2828

2929
pkg.deps.'LCD_ITF == "spi"':
3030
- "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_spi"
31+
pkg.deps.'LCD_ITF == "i2c"':
32+
- "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_i2c"
3133
pkg.deps.'LCD_ITF == "8080_II_8_bit"':
3234
- "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_8080"
3335
pkg.deps.'LCD_ITF == "8080_II_16_bit"':

hw/drivers/display/lcd_itf/syscfg.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ syscfg.defs:
2323
choices:
2424
- custom
2525
- spi
26+
- i2c
2627
- 8080_II_8_bit
2728
- 8080_II_16_bit
2829
value: spi

0 commit comments

Comments
 (0)