Commit d784adbc authored by Sahaj Sarup's avatar Sahaj Sarup Committed by Benjamin Cabé
Browse files

shield: m5stack_cardputer: initial support



Added initial support for the M5Stack Cardputer shield for
M5 Stamp S3. The following features are supported:

- uSD
- st7789 LCD
- Analog input from VBAT
- I2C on the grove connector

Signed-off-by: default avatarSahaj Sarup <sahaj.sarup@linaro.org>
parent 8f9dc66f
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 Linaro Limited
# SPDX-License-Identifier: Apache-2.0

if SHIELD_M5STACK_CARDPUTER

config INPUT
	default y

if DISK_DRIVERS

config DISK_DRIVER_SDMMC
	default y

endif # DISK_DRIVERS

if DISPLAY

choice ST7789V_PIXEL_FORMAT
	default ST7789V_RGB565
endchoice

if LVGL

config LV_Z_BITS_PER_PIXEL
	default 16

choice LV_COLOR_DEPTH
	default LV_COLOR_DEPTH_16
endchoice

configdefault LV_COLOR_16_SWAP
	default y

endif # LVGL

endif # DISPLAY

endif # SHIELD_M5STACK_CARDPUTER
+5 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 Linaro Limited
# SPDX-License-Identifier: Apache-2.0

config SHIELD_M5STACK_CARDPUTER
	def_bool $(shields_list_contains,m5stack_cardputer)
+74.2 KiB
Loading image diff...
+87 −0
Original line number Diff line number Diff line
.. _m5stack_cardputer:

M5Stack-Cardputer base shield
#############################

Overview
********

`M5Stack-Cardputer`_ is a card-sized portable computer that is perfect for engineers.
At the heart of Cardputer is the M5StampS3, a mini development board based on the ESP32-S3
chip.

The 56-key keyboard and 1.14" TFT screen allow users to easily enter and view
information. The on-board SPM1423 digital MEMS microphone and built-in speaker
enable voice operations such as recording, wake-up and audio playback. The
infrared emitter allows infrared control interaction with external devices such
as TVs or air conditioners. And Cardputer offers a HY2.0-4P interface for
expanding I2C sensors such as temperature and humidity sensors, light sensors
and pressure sensors. It also includes a Micro SD card slot for expanding storage.

The device is powered by an internal 120mAh+1400mAh (in the base) lithium
battery solution.

.. figure:: img/m5stack_cardputer.webp
        :align: center
        :alt: M5Stack-Cardputer
        :width: 400 px

        M5Stack-Cardputer

.. note::
   The NS4186 I2S Codec, SPM1423 microphone, IR LED and Keyboard functionality is not implemented yet.

Pins Assignments
================

+-------------------+---------------+
| ESP32-S3 GPIO Pin | Function      |
+===================+======+========+
| 0                 | User Button   |
+-------------------+---------------+
| 1                 | I2C SCL       |
+-------------------+---------------+
| 2                 | I2C SDA       |
+-------------------+---------------+
| 10                | VBAT Voltage  |
+-------------------+---------------+
| 33                | LCD RST       |
+-------------------+---------------+
| 34                | LCD RS/DC     |
+-------------------+---------------+
| 35                | LCD MOSI      |
+-------------------+---------------+
| 36                | LCD SCLK      |
+-------------------+---------------+
| 37                | LCD CS        |
+-------------------+---------------+
| 38                | LCD Backlight |
+-------------------+---------------+
| 39                | uSD MISO      |
+-------------------+---------------+
| 40                | uSD SCLK      |
+-------------------+---------------+
| 12                | uSD CS        |
+-------------------+---------------+
| 14                | uSD MOSI      |
+-------------------+---------------+

Programming
***********

Set ``--shield m5stack_cardputer`` when you invoke ``west build``.
For example:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/display
   :board: m5stack_stamps3/esp32s3/procpu
   :shield: m5stack_cardputer
   :goals: build

References
**********

.. target-notes::

.. _M5Stack-Cardputer:
   https://docs.m5stack.com/en/core/Cardputer
+143 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Linaro Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/ {
	zephyr,user {
		io-channels = <&adc0 9>;
	};

	aliases {
		/delete-property/ led-strip;
	};

	chosen {
		zephyr,display = &st7789v;
	};

	mipi_dbi {
		compatible = "zephyr,mipi-dbi-spi";
		spi-dev = <&spi2>;
		dc-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
		write-only;
		#address-cells = <1>;
		#size-cells = <0>;

		st7789v: st7789v@0 {
			compatible = "sitronix,st7789v";
			reg = <0>;
			mipi-max-frequency = <20000000>;

			width = <135>;
			height = <240>;
			x-offset = <53>;
			y-offset = <40>;

			vcom = <0x28>;
			gctrl = <0x35>;
			vrhs = <0x10>;
			vdvs = <0x20>;
			mdac = <0x00>;
			gamma = <0x01>;
			colmod = <0x55>;
			lcm = <0x2c>;
			porch-param = [0c 0c 00 33 33];
			cmd2en-param = [5a 69 02 00];
			pwctrl1-param = [a4 a1];
			pvgam-param = [d0 00 02 07 0a 28 32 44 42 06 0e 12 14 17];
			nvgam-param = [d0 00 02 07 0a 28 31 54 47 0e 1c 17 1b 1e];
			ram-param = [00 F0];
			rgb-param = [40 02 14];
			mipi-mode = "MIPI_DBI_MODE_SPI_4WIRE";
		};
	};
};

/delete-node/ &status_rgb_led;

&pinctrl {
	spim2_default: spim2_default {
		group1 {
			pinmux = <SPIM2_SCLK_GPIO36>,
				 <SPIM2_CSEL_GPIO37>;
		};

		group2 {
			pinmux = <SPIM2_MOSI_GPIO35>;
			output-low;
		};
	};

	spim3_default: spim3_default {
		group1 {
			pinmux = <SPIM3_SCLK_GPIO40>,
				 <SPIM3_MISO_GPIO39>;
		};

		group2 {
			pinmux = <SPIM3_MOSI_GPIO14>;
			output-low;
		};
	};

	i2c1_default: i2c1_default {
		group1 {
			pinmux = <I2C1_SDA_GPIO1>,
				 <I2C1_SCL_GPIO2>;
			bias-pull-up;
			drive-open-drain;
			output-high;
		};
	};
};

&adc0 {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;

	channel@9 {
		reg = <9>;
		zephyr,gain = "ADC_GAIN_1_4";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
		zephyr,resolution = <12>;
	};
};

&spi3 {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";
	pinctrl-0 = <&spim3_default>;
	pinctrl-names = "default";
	clock-frequency = <25000000>;
	cs-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; /* TF-CARD */

	sd0: sd@0 {
		compatible = "zephyr,sdhc-spi-slot";
		reg = <0>;
		status = "okay";
		spi-max-frequency = <25000000>;

		mmc {
			compatible = "zephyr,sdmmc-disk";
			disk-name = "SD";
			status = "okay";
		};
	};
};

&gpio1 {
	status = "okay";

	lcd-backlight {
		gpio-hog;
		gpios = <6 GPIO_ACTIVE_HIGH>;
		output-high;
	};
};