-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Driver for display that have I2C interface (SDD1306) Signed-off-by: Jerzy Kasenberg <[email protected]>
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ syscfg.defs: | |
choices: | ||
- custom | ||
- spi | ||
- i2c | ||
- 8080_II_8_bit | ||
- 8080_II_16_bit | ||
value: spi | ||
|