This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e621b5ae146ce0d8c0c9173e2f24336d2bef7381
Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
AuthorDate: Fri Apr 21 10:41:22 2023 +0200

    lvgl: Add support for SPI and 8080 MIPI DSI
    
    This adds general interface for communication with
    LCD display.
    
    Two implementations are ready:
    - Four wire SPI
    - Parallel 8080
---
 hw/drivers/display/lcd_itf/include/lcd_itf.h       | 101 +++++++++++++++++++
 hw/drivers/display/lcd_itf/itf_8080/pkg.yml        |  28 ++++++
 hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c | 110 ++++++++++++++++++++
 hw/drivers/display/lcd_itf/itf_8080/syscfg.yml     |  60 +++++++++++
 hw/drivers/display/lcd_itf/itf_spi/pkg.yml         |  29 ++++++
 hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c   | 111 +++++++++++++++++++++
 hw/drivers/display/lcd_itf/itf_spi/syscfg.yml      |  37 +++++++
 hw/drivers/display/lcd_itf/pkg.yml                 |  33 ++++++
 hw/drivers/display/lcd_itf/src/lcd_itf.c           |  77 ++++++++++++++
 hw/drivers/display/lcd_itf/syscfg.yml              |  40 ++++++++
 hw/drivers/display/lvgl/pkg.yml                    |   2 +-
 11 files changed, 627 insertions(+), 1 deletion(-)

diff --git a/hw/drivers/display/lcd_itf/include/lcd_itf.h 
b/hw/drivers/display/lcd_itf/include/lcd_itf.h
new file mode 100644
index 000000000..dfa7f0256
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/include/lcd_itf.h
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+#ifndef LCD_ITF_H
+#define LCD_ITF_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <syscfg/syscfg.h>
+
+#ifdef LCD_ITF_INCLUDE
+#include LCD_ITF_INCLUDE
+#endif
+
+#ifndef LCD_CS_PIN_ACTIVE
+#if MYNEWT_VAL(LCD_CS_PIN) >= 0
+#define LCD_CS_PIN_ACTIVE() hal_gpio_write(MYNEWT_VAL(LCD_CS_PIN), 0)
+#else
+#define LCD_CS_PIN_ACTIVE()
+#endif
+#endif
+
+#ifndef LCD_CS_PIN_INACTIVE
+#if MYNEWT_VAL(LCD_CS_PIN) >= 0
+#define LCD_CS_PIN_INACTIVE() hal_gpio_write(MYNEWT_VAL(LCD_CS_PIN), 1)
+#else
+#define LCD_CS_PIN_INACTIVE()
+#endif
+#endif
+
+#ifndef LCD_DC_PIN_DATA
+#define LCD_DC_PIN_DATA() hal_gpio_write(MYNEWT_VAL(LCD_DC_PIN), 1)
+#endif
+
+#ifndef LCD_DC_PIN_COMMAND
+#define LCD_DC_PIN_COMMAND() hal_gpio_write(MYNEWT_VAL(LCD_DC_PIN), 0)
+#endif
+
+#ifndef LCD_RESET_PIN_INACTIVE
+#if MYNEWT_VAL(LCD_RESET_PIN) >= 0
+#define LCD_RESET_PIN_INACTIVE() hal_gpio_write(MYNEWT_VAL(LCD_RESET_PIN), 1)
+#else
+#define LCD_RESET_PIN_INACTIVE()
+#endif
+#endif
+
+#ifndef LCD_RESET_PIN_ACTIVE
+#if MYNEWT_VAL(LCD_RESET_PIN) >= 0
+#define LCD_RESET_PIN_ACTIVE() hal_gpio_write(MYNEWT_VAL(LCD_RESET_PIN), 0)
+#else
+#define LCD_RESET_PIN_ACTIVE()
+#endif
+#endif
+
+#define LCD_SEQUENCE_DELAY_REQ                  0xFE
+#define LCD_SEQUENCE_DELAY_US_REQ               0xFD
+#define LCD_SEQUENCE_LCD_CS_ACTIVATE_REQ        0xFC
+#define LCD_SEQUENCE_LCD_CS_INACTIVATE_REQ      0xFB
+#define LCD_SEQUENCE_LCD_DC_DATA_REQ            0xFA
+#define LCD_SEQUENCE_LCD_DC_COMMAND_REQ         0xF9
+#define LCD_SEQUENCE_LCD_RESET_ACTIVATE_REQ     0xF8
+#define LCD_SEQUENCE_LCD_RESET_INACTIVATE_REQ   0xF7
+#define LCD_SEQUENCE_GPIO_REQ                   0xF6
+#define LCD_SEQUENCE(name) \
+static const uint8_t name[] = {
+#define LCD_SEQUENCE_DELAY(n) LCD_SEQUENCE_DELAY_REQ, (uint8_t)n, ((uint8_t)(n 
>> 8))
+#define LCD_SEQUENCE_DELAY_US(n) LCD_SEQUENCE_DELAY_US_REQ, (uint8_t)n, 
((uint8_t)(n >> 8))
+#define LCD_SEQUENCE_GPIO(pin, val) LCD_SEQUENCE_GPIO_REQ, n, val
+#define LCD_SEQUENCE_LCD_CS_ACTIVATE() LCD_SEQUENCE_LCD_CS_ACTIVATE_REQ
+#define LCD_SEQUENCE_LCD_CS_INACTIVATE() LCD_SEQUENCE_LCD_CS_INACTIVATE_REQ
+#define LCD_SEQUENCE_LCD_DC_DATA() LCD_SEQUENCE_LCD_DC_DATA_REQ
+#define LCD_SEQUENCE_LCD_DC_COMMAND() LCD_SEQUENCE_LCD_DC_COMMAND_REQ
+#define LCD_SEQUENCE_LCD_RESET_ACTIVATE() LCD_SEQUENCE_LCD_RESET_ACTIVATE_REQ
+#define LCD_SEQUENCE_LCD_RESET_INACTIVATE() 
LCD_SEQUENCE_LCD_RESET_INACTIVATE_REQ
+#define LCD_SEQUENCE_END 0xFF };
+
+void lcd_command_sequence(const uint8_t *cmds);
+
+void lcd_itf_init(void);
+
+/* Function implemented by LCD interface driver */
+void lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length);
+void lcd_itf_write_color_data(const void *data, size_t size);
+
+#endif /* LCD_ITF_H */
diff --git a/hw/drivers/display/lcd_itf/itf_8080/pkg.yml 
b/hw/drivers/display/lcd_itf/itf_8080/pkg.yml
new file mode 100644
index 000000000..e387823b5
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/itf_8080/pkg.yml
@@ -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/lcd_itf/itf_8080
+pkg.description: LCD Standard 8080 parallel interface
+pkg.keywords:
+    - display
+
+pkg.apis:
+    - lcd_interface
+
+pkg.deps:
diff --git a/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c 
b/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c
new file mode 100644
index 000000000..a1a503b66
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c
@@ -0,0 +1,110 @@
+/*
+ * 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>
+#include <hal/hal_gpio.h>
+
+#include <lv_conf.h>
+#include <lcd_itf.h>
+
+#define PIN(b, pin) ((b >> pin) & 1)
+
+#ifndef LCD_ITF_8080_WRITE_BYTE
+#define LCD_ITF_8080_WRITE_BYTE(n) lcd_itf_8080_write_byte(n)
+
+void
+lcd_itf_8080_write_byte(uint8_t b)
+{
+    hal_gpio_write(MYNEWT_VAL(LCD_D0_PIN), PIN(b, 0));
+    hal_gpio_write(MYNEWT_VAL(LCD_D1_PIN), PIN(b, 1));
+    hal_gpio_write(MYNEWT_VAL(LCD_D2_PIN), PIN(b, 2));
+    hal_gpio_write(MYNEWT_VAL(LCD_D3_PIN), PIN(b, 3));
+    hal_gpio_write(MYNEWT_VAL(LCD_D4_PIN), PIN(b, 4));
+    hal_gpio_write(MYNEWT_VAL(LCD_D5_PIN), PIN(b, 5));
+    hal_gpio_write(MYNEWT_VAL(LCD_D6_PIN), PIN(b, 6));
+    hal_gpio_write(MYNEWT_VAL(LCD_D7_PIN), PIN(b, 7));
+    hal_gpio_write(MYNEWT_VAL(LCD_WR_PIN), 0);
+    hal_gpio_write(MYNEWT_VAL(LCD_WR_PIN), 1);
+}
+#endif
+
+void
+lcd_itf_write_bytes(const uint8_t *bytes, size_t size)
+{
+    for (size_t i = 0; i < size; ++i) {
+        LCD_ITF_8080_WRITE_BYTE(*bytes++);
+    }
+}
+
+void
+lcd_itf_write_color_data(const void *pixels, size_t size)
+{
+    const uint16_t *data = (const uint16_t *)pixels;
+
+    LCD_DC_PIN_DATA();
+    LCD_CS_PIN_ACTIVE();
+    if (LV_COLOR_16_SWAP == 0) {
+        for (size_t i = 0; i < size; i += 2, data++) {
+            LCD_ITF_8080_WRITE_BYTE(*data >> 8);
+            LCD_ITF_8080_WRITE_BYTE((uint8_t)*data);
+        }
+    } else {
+        lcd_itf_write_bytes((const uint8_t *)pixels, size);
+    }
+    LCD_CS_PIN_INACTIVE();
+}
+
+void
+lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length)
+{
+    LCD_DC_PIN_COMMAND();
+    LCD_CS_PIN_ACTIVE();
+    LCD_ITF_8080_WRITE_BYTE(*cmd);
+    if (cmd_length > 1) {
+        LCD_DC_PIN_DATA();
+        lcd_itf_write_bytes(cmd + 1, cmd_length - 1);
+    }
+    LCD_CS_PIN_INACTIVE();
+}
+
+
+void
+lcd_itf_init(void)
+{
+    hal_gpio_init_out(MYNEWT_VAL(LCD_DC_PIN), 0);
+    if (MYNEWT_VAL(LCD_CS_PIN) >= 0) {
+        hal_gpio_init_out(MYNEWT_VAL(LCD_CS_PIN), 1);
+    }
+    if (MYNEWT_VAL(LCD_RD_PIN) >= 0) {
+        hal_gpio_init_out(MYNEWT_VAL(LCD_RD_PIN), 1);
+    }
+    if (MYNEWT_VAL(LCD_RESET_PIN) >= 0) {
+        hal_gpio_init_out(MYNEWT_VAL(LCD_RESET_PIN), 1);
+    }
+    hal_gpio_init_out(MYNEWT_VAL(LCD_WR_PIN), 1);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_DC_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D0_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D1_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D2_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D3_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D4_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D5_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D6_PIN), 0);
+    hal_gpio_init_out(MYNEWT_VAL(LCD_D7_PIN), 0);
+}
diff --git a/hw/drivers/display/lcd_itf/itf_8080/syscfg.yml 
b/hw/drivers/display/lcd_itf/itf_8080/syscfg.yml
new file mode 100644
index 000000000..51d73807b
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/itf_8080/syscfg.yml
@@ -0,0 +1,60 @@
+# 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_D0_PIN:
+        description: D0 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D1_PIN:
+        description: D1 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D2_PIN:
+        description: D2 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D3_PIN:
+        description: D3 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D4_PIN:
+        description: D4 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D5_PIN:
+        description: D5 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D6_PIN:
+        description: D6 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_D7_PIN:
+        description: D7 pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_WR_PIN:
+        description: WR pin for LCD.
+        value:
+        restrictions: $notnull
+    LCD_RD_PIN:
+        description: DR pin for LCD.
+        value: -1
+
+syscfg.restrictions:
diff --git a/hw/drivers/display/lcd_itf/itf_spi/pkg.yml 
b/hw/drivers/display/lcd_itf/itf_spi/pkg.yml
new file mode 100644
index 000000000..972635872
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/itf_spi/pkg.yml
@@ -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_spi
+pkg.description: LCD Standard 4 line SPI interface
+pkg.keywords:
+    - display
+
+pkg.apis:
+    - lcd_interface
+
+pkg.deps:
+    - "@apache-mynewt-core/hw/bus/drivers/spi_common"
diff --git a/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c 
b/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c
new file mode 100644
index 000000000..a8b44c5e8
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c
@@ -0,0 +1,111 @@
+/*
+ * 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>
+#include <hal/hal_gpio.h>
+#include <bus/drivers/spi_common.h>
+
+#include <lv_conf.h>
+#include <lcd_itf.h>
+
+static struct bus_spi_node lcd;
+static struct bus_spi_node_cfg lcd_spi_cfg = {
+    .node_cfg.bus_name = MYNEWT_VAL(LCD_SPI_DEV_NAME),
+    .pin_cs = MYNEWT_VAL(LCD_CS_PIN),
+    .mode = MYNEWT_VAL(LCD_SPI_MODE),
+    .data_order = HAL_SPI_MSB_FIRST,
+    .freq = MYNEWT_VAL(LCD_SPI_FREQ),
+};
+static struct os_dev *lcd_dev;
+
+static uint8_t *lv_color_16_swap_buffer;
+static size_t lv_color_16_swap_buffer_size;
+
+void
+lcd_itf_write_color_data(const void *pixels, size_t size)
+{
+    const void *color_data = pixels;
+    size_t i;
+
+    LCD_DC_PIN_DATA();
+    LCD_CS_PIN_ACTIVE();
+    if (LV_COLOR_16_SWAP == 0) {
+        if (size > lv_color_16_swap_buffer_size) {
+            lv_color_16_swap_buffer = realloc(lv_color_16_swap_buffer, size);
+            if (lv_color_16_swap_buffer) {
+                lv_color_16_swap_buffer_size = size;
+            } else {
+                lv_color_16_swap_buffer_size = 0;
+            }
+        }
+        if (lv_color_16_swap_buffer) {
+            color_data = lv_color_16_swap_buffer;
+            for (i = 0; i < size; i += 2) {
+                lv_color_16_swap_buffer[i] = ((uint8_t *)pixels)[i + 1];
+                lv_color_16_swap_buffer[i + 1] = ((uint8_t *)pixels)[i];
+            }
+        }
+    }
+    bus_node_write(lcd_dev, color_data, size, 1000, BUS_F_NOSTOP);
+    LCD_CS_PIN_INACTIVE();
+}
+
+void
+lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length)
+{
+#if MYNEWT_VAL(LCD_SPI_WITH_SHIFT_REGISTER)
+    uint16_t buf[cmd_length];
+#else
+    uint8_t buf[cmd_length];
+#endif
+
+    if (MYNEWT_VAL(LCD_SPI_WITH_SHIFT_REGISTER)) {
+        for (int i = 0; i < cmd_length; ++i) {
+            buf[i] = htobe16(cmd[i]);
+        }
+    } else {
+        memcpy(buf, cmd, cmd_length);
+    }
+    LCD_DC_PIN_COMMAND();
+    LCD_CS_PIN_ACTIVE();
+    bus_node_write(lcd_dev, buf, sizeof(buf[0]), 1000, cmd_length == 1 ? 
BUS_F_NOSTOP : 0);
+    if (cmd_length > 1) {
+        LCD_DC_PIN_DATA();
+        bus_node_write(lcd_dev, buf + 1, (cmd_length - 1) * sizeof(buf[0]), 
1000, 0);
+    }
+    LCD_CS_PIN_INACTIVE();
+}
+
+
+void
+lcd_itf_init(void)
+{
+    int rc;
+    struct bus_node_callbacks cbs = {};
+
+    hal_gpio_init_out(MYNEWT_VAL(LCD_DC_PIN), 0);
+    if (MYNEWT_VAL(LCD_CS_PIN) >= 0) {
+        hal_gpio_init_out(MYNEWT_VAL(LCD_CS_PIN), 1);
+    }
+    bus_node_set_callbacks((struct os_dev *)&lcd, &cbs);
+
+    rc = bus_spi_node_create("display", &lcd, &lcd_spi_cfg, NULL);
+    assert(rc == 0);
+    lcd_dev = os_dev_open("display", 0, NULL);
+}
diff --git a/hw/drivers/display/lcd_itf/itf_spi/syscfg.yml 
b/hw/drivers/display/lcd_itf/itf_spi/syscfg.yml
new file mode 100644
index 000000000..91619f3ca
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/itf_spi/syscfg.yml
@@ -0,0 +1,37 @@
+# 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_SPI_DEV_NAME:
+        description: SPI device name that LCD is connected to.
+        value: '"spi0"'
+    LCD_SPI_MODE:
+        description: LCD SPI mode.
+        value: BUS_SPI_MODE_0
+    LCD_SPI_FREQ:
+        description: SPI device frequency for LCD
+        value: 8000
+    LCD_SPI_WITH_SHIFT_REGISTER:
+        description: >
+            On some designs LCD working in parallel 16 bit mode is connected
+            to SPI interface that with additional shift register(s).
+            As a consequence commands and their arguments have to be sent as
+            16 bits values.
+        value: 0
+
+syscfg.restrictions:
diff --git a/hw/drivers/display/lcd_itf/pkg.yml 
b/hw/drivers/display/lcd_itf/pkg.yml
new file mode 100644
index 000000000..58db2b9e6
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/pkg.yml
@@ -0,0 +1,33 @@
+#
+# 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
+pkg.description: LCD
+pkg.keywords:
+    - display
+    - LCD
+
+pkg.req_apis:
+    - lcd_interface
+
+pkg.deps.'LCD_ITF == "spi"':
+    - "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_spi"
+pkg.deps.'LCD_ITF == "8080_II_8_bit"':
+    - "@apache-mynewt-core/hw/drivers/display/lcd_itf/itf_8080"
+
diff --git a/hw/drivers/display/lcd_itf/src/lcd_itf.c 
b/hw/drivers/display/lcd_itf/src/lcd_itf.c
new file mode 100644
index 000000000..f8b18c6b5
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/src/lcd_itf.c
@@ -0,0 +1,77 @@
+/*
+ * 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 <os/os_time.h>
+#include <os/os_cputime.h>
+#include <bsp/bsp.h>
+#include <lcd_itf.h>
+#include <hal/hal_gpio.h>
+
+static void
+lcd_delay(uint32_t delay_us)
+{
+    if (os_time_ticks_to_ms32(2) * 1000 < delay_us) {
+        os_time_delay(os_time_ms_to_ticks32(delay_us / 1000));
+    } else {
+        os_cputime_delay_usecs(delay_us);
+    }
+}
+
+void
+lcd_command_sequence(const uint8_t *cmds)
+{
+    const uint8_t *cmd;
+    int cmd_length;
+
+    /* Send all the commands */
+    for (cmd = cmds; cmd[0] != 0xFF; ) {
+        if (cmd[0] == LCD_SEQUENCE_DELAY_REQ) {
+            lcd_delay((cmd[1] | (cmd[2] << 8)) * 1000);
+            cmd += 3;
+        } else if (cmd[0] == LCD_SEQUENCE_DELAY_US_REQ) {
+            lcd_delay(cmd[1] | (cmd[2] << 8));
+            cmd += 3;
+        } else if (cmd[0] == LCD_SEQUENCE_GPIO_REQ) {
+            hal_gpio_write(cmd[1], cmd[2]);
+            cmd += 3;
+        } else if (cmd[0] == LCD_SEQUENCE_LCD_RESET_ACTIVATE_REQ) {
+            LCD_RESET_PIN_ACTIVE();
+            ++cmd;
+        } else if (cmd[0] == LCD_SEQUENCE_LCD_RESET_INACTIVATE_REQ) {
+            LCD_RESET_PIN_INACTIVE();
+            ++cmd;
+        } else if (cmd[0] == LCD_SEQUENCE_LCD_CS_ACTIVATE_REQ) {
+            LCD_CS_PIN_ACTIVE();
+            ++cmd;
+        } else if (cmd[0] == LCD_SEQUENCE_LCD_CS_INACTIVATE_REQ) {
+            LCD_CS_PIN_INACTIVE();
+            ++cmd;
+        } else if (cmd[0] == LCD_SEQUENCE_LCD_DC_DATA_REQ) {
+            LCD_DC_PIN_DATA();
+            ++cmd;
+        } else if (cmd[0] == LCD_SEQUENCE_LCD_DC_COMMAND_REQ) {
+            LCD_DC_PIN_COMMAND();
+            ++cmd;
+        } else {
+            cmd_length = cmd[0];
+            lcd_ift_write_cmd(cmd + 1, cmd_length);
+            cmd += cmd_length + 1;
+        }
+    }
+}
diff --git a/hw/drivers/display/lcd_itf/syscfg.yml 
b/hw/drivers/display/lcd_itf/syscfg.yml
new file mode 100644
index 000000000..cab3c7263
--- /dev/null
+++ b/hw/drivers/display/lcd_itf/syscfg.yml
@@ -0,0 +1,40 @@
+# 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_ITF:
+        description: >
+            Selects built-in implementation of LCD interface
+        choices:
+            - custom
+            - spi
+            - 8080_II_8_bit
+        value: spi
+    LCD_CS_PIN:
+        description: LCD chip select pin for SPI.
+        value: -1
+    LCD_DC_PIN:
+        description: LCD command/data pin for SPI.
+        value:
+        restrictions: -1
+    LCD_BL_PIN:
+        description: LCD backlight pin.
+        value: -1
+    LCD_RESET_PIN:
+        description: LCD command/data pin for SPI or parallel port.
+        value: -1
diff --git a/hw/drivers/display/lvgl/pkg.yml b/hw/drivers/display/lvgl/pkg.yml
index 17f2a63ff..6a026fcb2 100644
--- a/hw/drivers/display/lvgl/pkg.yml
+++ b/hw/drivers/display/lvgl/pkg.yml
@@ -56,7 +56,7 @@ pkg.ign_dirs:
 
 pkg.deps:
     - "@apache-mynewt-core/hw/hal"
-    - "@apache-mynewt-core/hw/cmsis-core"
+    - "@apache-mynewt-core/hw/drivers/display/lcd_itf"
 
 pkg.cflags:
     - -DLV_CONF_INCLUDE_SIMPLE=1

Reply via email to