From 654f533f74efc363004cd9b7ba1789bd386efdaf Mon Sep 17 00:00:00 2001
From: Bartosz Golaszewski <bartosz.golaszewski@huawei.com>
Date: Wed, 4 May 2022 17:17:37 +0200
Subject: [PATCH] arduino-nano-33-ble: enable Adafruit TFT 2.8 display support

This adds a minimal set of changes required to support the 2.8 TFT display
from Adafruit. These changes are not what went upstream as Zephyr v3.1
introduced a new virtual connector for the nano form factor that we don't
have yet in v3.0.

This allows us to build the lvgl sample for Arduino Nano 33 BLE.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@huawei.com>
---
 ...no_nano_33_ble-add-support-for-the-a.patch | 70 +++++++++++++++++++
 .../zephyr-kernel/zephyr-kernel-src-3.0.0.inc |  5 +-
 .../zephyr-kernel/zephyr-lvgl.bb              |  2 +-
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 meta-zephyr-core/recipes-kernel/zephyr-kernel/files/0001-boards-arm-arduino_nano_33_ble-add-support-for-the-a.patch

diff --git a/meta-zephyr-core/recipes-kernel/zephyr-kernel/files/0001-boards-arm-arduino_nano_33_ble-add-support-for-the-a.patch b/meta-zephyr-core/recipes-kernel/zephyr-kernel/files/0001-boards-arm-arduino_nano_33_ble-add-support-for-the-a.patch
new file mode 100644
index 0000000..fbd6a98
--- /dev/null
+++ b/meta-zephyr-core/recipes-kernel/zephyr-kernel/files/0001-boards-arm-arduino_nano_33_ble-add-support-for-the-a.patch
@@ -0,0 +1,70 @@
+From eb4cb84d84ca79351eb9f882e7df82034c58a5ae Mon Sep 17 00:00:00 2001
+From: Bartosz Golaszewski <bartosz.golaszewski@huawei.com>
+Date: Wed, 16 Mar 2022 10:53:38 +0100
+Subject: [PATCH] boards: arm: arduino_nano_33_ble: add support for the
+ adafruit 2.8 TFT
+
+This is a basic set of changes needed to support the TFT display from
+adafruit on Arduino Nano 33 BLE. It's not what ended up upstream as there
+were incompatible changes in v3.1 that make 1-to-1 backporting impossible.
+
+Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@huawei.com>
+---
+ .../arduino_nano_33_ble.dts                   |  4 ++--
+ .../boards/arduino_nano_33_ble.overlay        | 22 +++++++++++++++++++
+ 2 files changed, 24 insertions(+), 2 deletions(-)
+ create mode 100644 boards/shields/adafruit_2_8_tft_touch_v2/boards/arduino_nano_33_ble.overlay
+
+diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble.dts b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble.dts
+index 7e509086d2..3db0e8203a 100644
+--- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble.dts
++++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble.dts
+@@ -84,7 +84,7 @@
+ 	tx-pin = <35>; //P1.03
+ 	rx-pin = <42>; //P1.10
+ };
+-&i2c0 {
++arduino_i2c: &i2c0 {
+ 	compatible = "nordic,nrf-twim";
+ 	status = "okay";
+ 	sda-pin = <31>; //P0.31
+@@ -97,7 +97,7 @@
+ 	scl-pin = <15>; //P0.15
+ };
+ // we use SPI2 because SPI1/0 shares conflicts with I2C1/0
+-&spi2 {
++arduino_spi: &spi2 {
+ 	compatible = "nordic,nrf-spim";
+ 	status = "okay";
+ 	sck-pin = <13>; //P0.13
+diff --git a/boards/shields/adafruit_2_8_tft_touch_v2/boards/arduino_nano_33_ble.overlay b/boards/shields/adafruit_2_8_tft_touch_v2/boards/arduino_nano_33_ble.overlay
+new file mode 100644
+index 0000000000..2f265ace4e
+--- /dev/null
++++ b/boards/shields/adafruit_2_8_tft_touch_v2/boards/arduino_nano_33_ble.overlay
+@@ -0,0 +1,22 @@
++/*
++ * Copyright (C) 2022 Huawei Inc.
++ *
++ * SPDX-License-Identifier: Apache-2.0
++ */
++
++/ {
++	/*
++	 * Arduino Nano form factor doesn't really have a Rev3 Arduino header
++	 * so this is just a "virtual" mapping for the pins used by the
++	 * Adafruit display.
++	 */
++	arduino_header: connector {
++		compatible = "arduino-header-r3";
++		#gpio-cells = <2>;
++		gpio-map-mask = <0xffffffff 0xffffffc0>;
++		gpio-map-pass-thru = <0 0x3f>;
++		gpio-map = <10 0 &gpio1 15 0>, // D4
++			   <15 0 &gpio1 2 0>,  // D10
++			   <16 0 &gpio0 27 0>; // D9
++	};
++};
+-- 
+2.34.1
+
diff --git a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-src-3.0.0.inc b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-src-3.0.0.inc
index f4ea7d3..a772355 100644
--- a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-src-3.0.0.inc
+++ b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-kernel-src-3.0.0.inc
@@ -69,4 +69,7 @@ SRCREV_zscilib = "12bfe3f0a9fcbfe3edab7eabc9678b6c62875d34"
 ZEPHYR_BRANCH = "v3.0-branch"
 PV = "3.0.0+git${SRCPV}"
 
-SRC_URI += "file://0001-lvgl-add-support-for-lvgl-v8.2.0.patch"
+SRC_URI += " \
+    file://0001-lvgl-add-support-for-lvgl-v8.2.0.patch \
+    file://0001-boards-arm-arduino_nano_33_ble-add-support-for-the-a.patch \
+"
diff --git a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-lvgl.bb b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-lvgl.bb
index efe2154..d9eaccc 100644
--- a/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-lvgl.bb
+++ b/meta-zephyr-core/recipes-kernel/zephyr-kernel/zephyr-lvgl.bb
@@ -5,4 +5,4 @@ ZEPHYR_SRC_DIR = "${S}/samples/subsys/display/lvgl"
 # TODO Once more machines and displays are supported, add a PACKAGECONFIG.
 EXTRA_OECMAKE:append =" -DSHIELD=adafruit_2_8_tft_touch_v2"
 
-COMPATIBLE_MACHINE = "(nrf52840dk-nrf52840)"
+COMPATIBLE_MACHINE = "(nrf52840dk-nrf52840|arduino-nano-33-ble)"
-- 
GitLab