How enable ads7846


Recommended Posts

Got Orange Pi Plus 2 and LCD 5"monitor Waveshare.
Use armbian OS 5.14 on Debian Jessie 3.4.112.
All good with 800x480 resolution, but still cant use touchscreen.
Will be happy if you help me with it:
Monitor got interface

 

1, 17        3.3V        Power positive (3.3V power input)

2, 4          5V           Power positive (5V power input)

3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 24   NC    NC

6, 9, 14, 20, 25       GND      Ground

19           TP_SI      SPI data input of Touch Panel

21           TP_SO    SPI data output of Touch Panel

22           TP_IRQ   Touch Panel interrupt, low level while the Touch Panel detects touching

23           TP_SCK  SPI clock of Touch Panel

26           TP_CS    Touch Panel chip selection, low active

 

Connect it to
PIN LCD                          PIN OpiPlus2
1                                             1
17                                            17
2                                             2
4                                             4
6                                             6
9                                             9
14                                           14
20                                           20
25                                           25
19                                           19
21                                            21
22                                            22
23                                            23
26                                            26

Make next changes to script.bin:
[spi0]
spi_used = 1
spi_cs_bitmap = 1
spi_mosi = port:PC00<3><default><default><default>
spi_miso = port:PC01<3><default><default><default>
spi_sclk = port:PC02<3><default><default><default>
spi_cs0 = port:PA21<1><1><default><default>

[spi1]
spi_used = 0
spi_cs_bitmap = 1
spi_cs0 = port:PA13<2><1><default><default>
spi_sclk = port:PA14<2><default><default><default>
spi_mosi = port:PA15<2><default><default><default>
spi_miso = port:PA16<2><default><default><default>

[spi_devices]
spi_dev_num = 1

[spi_board0]
modalias = "ads7846"
max_speed_hz = 1500000
bus_num = 0
chip_select = 0
mode = 0
full_duplex = 1
manual_cs = 0

[uart2]
uart_used = 0
uart_port = 2
uart_type = 4
uart_tx = port:PA00<2><1><default><default>
uart_rx = port:PA01<2><1><default><default>
uart_rts = port:PA02<2><1><default><default>
uart_cts = port:PA03<2><1><default><default>

BUT TOUCHSCREEN STILL DONT WORK !!!
Please help me.
 

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?

Dear all,

 

I would like to kindly ask you for a help. My goal is to enable touchscreen. I was able to run the display according to this connection and command:

MOSI - 19, MISO - 21, SCK (SPI_CLK) - 23, CS - 24, RESET, DC and LED - 11, 13, 15. power supply and ground as usual

sudo modprobe fbtft_device custom name=fb_ili9341 gpios=reset:1,dc:0,led:3 speed=48000000 fps=25 rotate=90 bgr=1 txbuflen=65536

I understood that the pin layout is slightly different from Raspberry Pi and I have to follow pinout table on:

https://linux-sunxi.org/Xunlong_Orange_Pi_One

BUT I also wanted to touch layer to be working, therefore I installed package 'linux-firmware-image-sun8i' which contains driver ads7846 which should be compatible with xpt2046.

Connected the touch and tft layer pins according to pin layout found for Raspberry PI :

T_IRQ Panel Touch Interrupt = GPIO25 (corresponding to Orange Pi pin 22 = PA2)
T_DO Touch Data Out = GPIO09
T_DIN Touch Data In = GPIO10
T_CS Touch Chip Select = SPI_CE1_N
T_CLK Touch Clock = GPIO11
SDO (MISO) TFT Data Out SPI_MISO = GPIO09
LED Backlight GPIO18 -- see note (corresponding to Orange Pi pin 15 = PA3)
SCK TFT Clock SPI_CLK = GPIO11
SDI (MOSI) TFT Data In SPI_MOSI = GPIO10
D/C TFT Data / Command = GPIO24 (corresponding to Orange Pi pin 13 = PA0)
RESET Reset = GPIO23 (corresponding to Orange Pi pin 11 = PA1)
CS TFT Chip Select = SPI_CE0_N = GPIO08
GND Ground = GND
VCC 3V3 supply +3V3

 

And ran command sudo modprobe ads7846, but with no success

 

I also followed page https://forum.armbian.com/index.php?/topic/1384-please-add-new-hardware/,

compiling and installing ads7846_device, went to directory /lib/modules/3.4.113-sun8i/extra and ran command:

sudo modprobe ads7846_device model=7846 cs=1 gpio_pendown=2 speed=2000000 keep_vref_on=1 x_plate_ohms=60 pressure_max=255 x_min=200 x_max=3900 y_min=200 y_max=3900

OR

sudo modprobe ./ads7846_device pressure_max=255 y_min=190 y_max=3850 gpio_pendown=2 x_max=3850 x_min=230 x_plate_ohms=60

 

Again no success, therefore I tried to change T_CLK Touch Clock pin to pin 10 (PA14)  T_CS Touch Chip Select to pin 8 (PA13) and I thought it requires SPI1 and repeated to commands, again no success.

 

When I ran the TFT screen without touch layer pins connected, it works very good but with pins for touch layer connected even the display is not working, only LED backlight is on, moreover there is no modifo result for proper module parameters neither dmesg output when invoking modprobe related to both ads7846 and ads7846_device modules, I guess there might be some SPI devices collision, but I am SPI newbie. I guess no need to install overlays as this is legacy kernel with modules calling via command line.

The display is OK, I tested both functionalities on different device.

 

 

Thank you very much for any help


Best regards,

Ivo

 

 

 

 

 

Link to post
Share on other sites

spi xp2046 device needs patching and recompiling even though SPI ili9341 works from scratch on the same board with  spi xpt2046 which does not work?

There is even a kernel driver ads7846 in kernel firmware package, I guess those are the proper externally compiled modules to the same kernel, just loadable, not packaged to the distribution due to space issues. I am a newbie so I don't see the reason why display on SPI is working and touchscreen on SPI is not working and needs a lot of extra work to be done.

I opened a new topic about this here just to see what I have done so far. Thank you very much for all the help

 

 

Best regards,

 

Ivo

Link to post
Share on other sites
1 hour ago, horai said:

 

spi xp2046 device needs patching and recompiling even though SPI ili9341 works from scratch on the same board with  spi xpt2046 which does not work?

 

fbtft_device driver can be configured through module parameters. ads7846 doesn't support this kind of configuration.

 

And in addition there is only one hardware chip select on the H3 SPI controllers, so connecting 2 SPI devices will require even more work to support software/GPIO based CS.

Link to post
Share on other sites

Ok, I was confused by a pinout image I found for Orange Pi:

https://github.com/rm-hull/luma.led_matrix/issues/27

There are SPI_CE0 and SPI_CE1, but on the picture, there is only one chip select depicted, I thought that there are SPI_CE1,2 are two chip selects, I thought that maybe the other one is configurable.

Could you also please explain to me one more thing?

In this documentation http://dl.linux-sunxi.org/H3/Allwinner_H3_Datasheet_V1.0.pdf

page 454, there is reference to SPI and there is mentioned:

Four chip selects to support multiple peripheral

Polarity and phase of the Chip Select (SPI_SS) and SPI Clock (SPI_SCLK) are configurable

 

That does not mean that there are no more chip selects?

 

And if you type dmesg | grep spi, I get this output:

lisunxi_spi_chan_cfg()1376 - [spi-0] has no spi_regulator.
sunxi_spi_chan_cfg()1376 - [spi-1] has no spi_regulator.ke this:

 

Please, could you also tell me why there is spi-0 and spi-1? I thought that it might have 2 SPI masters each with 2 slaves altogether 4 chipselects.

Two slaves are sharing one master.

 

 

 

Link to post
Share on other sites
8 minutes ago, horai said:

Could you also please explain to me one more thing?

In this documentation http://dl.linux-sunxi.org/H3/Allwinner_H3_Datasheet_V1.0.pdf

page 454, there is reference to SPI and there is mentioned:

Four chip selects to support multiple peripheral

Yes, controller supports up to 4 CS. But only one CS for each controller is exposed - please check the section 3.2 "GPIO multiplexing functions"

It should be possible to use software/GPIO chip selects, but it's much easier to configure and test on mainline kernel.

Link to post
Share on other sites

Ok, just to sum it up. The device has 2x master SPI controller and to each master there are two SPI slaves therefore we have up to 4 CS, but we have two physical pins one PIN SPI0_CS1 (pin 8) and SPI1_CS0 (pin 24) (Raspberry which has two physical PINS SPI0_CE1(CS1) and SPI0_CE0(CS0), but only one master.

In case we have 4 SPI devices for Orange Pi, we place all 2 CS pins from those  SPI0_CS (pin 24) and the other 2 pins to SPI1_CS (pin 8), but 0 and 1 are multiplexed.

In my case where I need to connect display driver and touchscreen driver, can't I connect display driver on SPI0 and touchscreen driver on SPI1? Chipselect set for both to 0 as they are each on different master?

But from the 3.2 section I see that SPI1_CS is disconnected by default therefore I have to enable it and configure as function SPI1_CS, right?

Because of the fact that the display worked, I think SPI0_CS works as CS for spi bus 0 by default.

 

The key point for me is that ads7846_device kernel module has a parameter called 'bus' so I think I can tell kernel that it should seek for touchscreen on bus 1.The only thing I am worried about is that even though I load this module and also the module ads7846 via modprobe, no output comes out, no message in dmesg and also ads7846_device is not loaded in lsmod. Do you think that because it does not have CS connected, it does not register the module?

What I don't understand is the two masters share MOSI, MISO, DO,DI?

 

Sorry to ask stupid questions, but I am a newbie.

Link to post
Share on other sites

I would love to use mainline kernel, but so far it will be way too much complicated for me as I have Mali400 hardware acceleration (I am not sure whether it is possible to have it on mainline kernel, some sites say yes, I even saw source code to build the driver) set up already. Moreove there is no stable release for OP Lite yet and I only need to resolve the touchscreen for me than I'll play with mainline on differend SD card.

Link to post
Share on other sites
9 minutes ago, horai said:

The device has 2x master SPI controller and to each master there are two SPI slaves therefore we have up to 4 CS, but we have two physical pins one PIN SPI0_CS1 (pin 8) and SPI1_CS0 (pin 24)

2 SPI controllers, each controller can in theory (Table 8.2.5.2 SPI transfer control register) have up to 4 CS (so up to 4 slave devices, 1 CS = 1 slave).

 

11 minutes ago, horai said:

In case we have 4 SPI devices for Orange Pi, we place all 2 CS pins from those  SPI0_CS (pin 24) and the other 2 pins to SPI1_CS (pin 8), but 0 and 1 are multiplexed.

In case we want to use 4 SPI devices, we would have to use 1 hardware CS (SPI0_CS if we are using SPI0 or SPI1_CS if we are using SPI1) and 3 GPIO chip selects.

Please note that SPI1 is not wired to the pin headers on all H3 Orange Pi boards, so only one SPI controller can be used.

 

14 minutes ago, horai said:

In my case where I need to connect display driver and touchscreen driver, can't I connect display driver on SPI0 and touchscreen driver on SPI1? Chipselect set for both to 0 as they are each on different master?

It would work in this configuration if SPI1 was accessible on the pin headers. But PA15 (MOSI) is used for the status LED, and PA16 (MISO) is not wired anywhere (it says "mute" on the schematic but there is no amplifier on the H3 Orange Pi boards).

 

19 minutes ago, horai said:

But from the 3.2 section I see that SPI1_CS is disconnected by default therefore I have to enable it and configure as function SPI1_CS, right?

In case of the legacy kernel please look at the FEX definitions:

[spi0]
spi_used = 1
spi_cs_bitmap = 1
spi_mosi = port:PC00<3><default><default><default>
spi_miso = port:PC01<3><default><default><default>
spi_sclk = port:PC02<3><default><default><default>
spi_cs0 = port:PC03<3><1><default><default>

[spi1]
spi_used = 0
spi_cs_bitmap = 1
spi_cs0 = port:PA13<2><1><default><default>
spi_sclk = port:PA14<2><default><default><default>
spi_mosi = port:PA15<2><default><default><default>
spi_miso = port:PA16<2><default><default><default>

<3> in case of SPI0 and <2> in case of SPI1 after the pin name configures pin functions.

 

23 minutes ago, horai said:

What I don't understand is the two masters share MOSI, MISO, DO,DI?

No, you can see that SPI0 pins and SPI1 pins are different.

 

24 minutes ago, horai said:

The key point for me is that ads7846_device kernel module has a parameter called 'bus' so I think I can tell kernel that it should seek for touchscreen on bus 1.The only thing I am worried about is that even though I load this module and also the module ads7846 via modprobe, no output comes out, no message in dmesg and also ads7846_device is not loaded in lsmod.

As I said, most likely it needs platform data (compared to fbtft which can be configured via module parameters)

Searching for the module name in kernel sources gives some examples. For example, arch/arm/mach-at91/board-neocore926.c


/*
 * ADS7846 Touchscreen
 */
#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
static int ads7843_pendown_state(void)
{
	return !at91_get_gpio_value(AT91_PIN_PA15);	/* Touchscreen PENIRQ */
}

static struct ads7846_platform_data ads_info = {
	.model			= 7843,
	.x_min			= 150,
	.x_max			= 3830,
	.y_min			= 190,
	.y_max			= 3830,
	.vref_delay_usecs	= 100,
	.x_plate_ohms		= 450,
	.y_plate_ohms		= 250,
	.pressure_max		= 15000,
	.debounce_max		= 1,
	.debounce_rep		= 0,
	.debounce_tol		= (~0),
	.get_pendown_state	= ads7843_pendown_state,
};

static void __init neocore926_add_device_ts(void)
{
	at91_set_B_periph(AT91_PIN_PA15, 1);	/* External IRQ1, with pullup */
	at91_set_gpio_input(AT91_PIN_PC13, 1);	/* Touchscreen BUSY signal */
}
#else
static void __init neocore926_add_device_ts(void) {}
#endif

/*
 * SPI devices.
 */
static struct spi_board_info neocore926_spi_devices[] = {
#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
	{	/* DataFlash card */
		.modalias	= "mtd_dataflash",
		.chip_select	= 0,
		.max_speed_hz	= 15 * 1000 * 1000,
		.bus_num	= 0,
	},
#endif
#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
	{
		.modalias	= "ads7846",
		.chip_select	= 1,
		.max_speed_hz	= 125000 * 16,
		.bus_num	= 0,
		.platform_data	= &ads_info,
		.irq		= AT91SAM9263_ID_IRQ1,
	},
#endif
};


static void __init neocore926_board_init(void)
{
	/* Serial */
	at91_add_device_serial();

	/* USB Host */
	at91_add_device_usbh(&neocore926_usbh_data);

	/* USB Device */
	at91_add_device_udc(&neocore926_udc_data);

	/* SPI */
	at91_set_gpio_output(AT91_PIN_PE20, 1);		/* select spi0 clock */
	at91_add_device_spi(neocore926_spi_devices, ARRAY_SIZE(neocore926_spi_devices));

	/* Touchscreen */
	neocore926_add_device_ts();

	/* MMC */
	at91_add_device_mmc(1, &neocore926_mmc_data);

	/* Ethernet */
	at91_add_device_eth(&neocore926_macb_data);

	/* NAND */
	neocore926_add_device_nand();

	/* I2C */
	at91_add_device_i2c(NULL, 0);

	/* LCD Controller */
	at91_add_device_lcdc(&neocore926_lcdc_data);

	/* Push Buttons */
	neocore926_add_device_buttons();

	/* AC97 */
	at91_add_device_ac97(&neocore926_ac97_data);
}

 

Link to post
Share on other sites

For the display there is fbtft_device loadable module which chains the fbtft module and loads it automatically (when parameters of fbtft_device set up properly)

 

I guess the same applies to touch layer via https://github.com/notro/fbtft_tools/wiki/ads7846_device 

where all the parameters are specified.

which probably loads the module ads7846 automatically,

I guess my problem is that I have both attached to SPI0, but no CS is provided for touchscreen, data are probably mangled it it cannot register the module, but I also connected the touch layer alone as I have done with display and alone the display works, but touch device alone does not work, maybe I have set up CS incorrectly.

SPI1 is of no issue as there is no PIN for MOSI and MISO pins exposed on the header, I did not notice, moreover I thought  they both SPI0 and SPI1 can share MOSI, MISO lines, but this probably applies only to Master - Slave, not to two masters.

So we end up on what you have said in the beginning that for this purpose we will need to multiplex SPI0_CS.

Just one last question, it is not  possible to tell kernel how to multiplex it in some configuration file, to assign CS=0 to screen and CS=1 to touch? If we would have 4 SPI devices, we would connect all their 4 CS hardware pins to Orange PI hardware pin PI SPI0_CS  (pin 24)  and tell the OS to multiplex it or we will assing some arbitrary 3 other hardware GPIO pins for CS1,2,3? According to the documentation, I did not see any other hardware pin to be possible to alternate the function of SPI0_CS of any enumeration, only PIN 24 (PC3) .

If I understand all that correctly, the only way to run both these devices is to place their CS pins together on SPI0_CS  hardware pin of Orange Pi and tell the kernel to multiplex CS on one hardware PIN 24 (PC3), is it correct?

Link to post
Share on other sites
16 minutes ago, horai said:

I guess the same applies to touch layer via https://github.com/notro/fbtft_tools/wiki/ads7846_device 

where all the parameters are specified.

which probably loads the module ads7846 automatically,

This module (from fbtft) was not ported to this kernel - only display modules were added: https://github.com/igorpecovnik/lib/blob/master/patch/kernel/sun8i-default/02-0011-fbtft_for_older.patch

 

So you have only stock ads7846 module which doesn't support parameters: https://github.com/igorpecovnik/linux/blob/sun8i/drivers/input/touchscreen/ads7846.c

 

22 minutes ago, horai said:

So we end up on what you have said in the beginning that for this purpose we will need to multiplex SPI0_CS.

Not multiplex, but use "software" GPIO for the chip select. Again, as I said, legacy kernel SPI driver doesn't support this, but in theory it can be implemented by rewriting the driver.

Link to post
Share on other sites

Ok, great, thank you very much, as soon as possible, I'll try the mainline kernel for software GPIO chip select, hopefully it will work. I hope I'll find a tutorial, how to perform it, if you have a hint how to perform it or a link, I would be very grateful if you could share it. Hopefully the display will work with the new kernel, I'll sacrifice OpenGL acceleration.

Anyway, with the ads7846_device module, I noticed it's not compiled as a module for the 3.4.113 kernel, therefore I downloaded the source code from

https://github.com/notro/fbtft/wiki/fbtft_device.

It also has a Makefile which looks like it is compiling it as a module and also installs it as a module to kernel directory.I ran modprobe for the module with only one exception that I had to put ./ in from of the module name and be present in the kernel directory with module, but the behaviour while loading was anyway strange.

 

Link to post
Share on other sites
1 minute ago, Łukasz Żyłkowski said:

@zador.blood.stained I'm using mainline, any help with GPIO CS?

Based on this overlay you can add up to 3 GPIO chip selects (in addition to hardware CS 0): https://github.com/armbian/sunxi-DT-overlays/blob/master/sun8i-h3/sun8i-h3-spi-add-cs1.dts

So cs-gpios property may look like this:

cs-gpios = <0>, <&pio 0 9 0>, <&pio 0 10 0>, <&pio 0 21 0>; /* CS0 HW, CS1 PA9, CS2 PA10, CS3 PA21 */

and pinmux block may look like this:

			spi0_cs_gpios: spi0_cs_gpios {
				pins = "PA9", "PA10", "PA21";
				function = "gpio_out";
				output-high;
			};

So you will need to use this overlay as a template and include cs-gpios changes and the pinctrl/pinmux changes to add more chip selects. Then resulting overlay can be installed via "armbian-add-overlay" if you updated the packages recently.

 

Armbian DT overlays documentation: https://docs.armbian.com/User-Guide_Allwinner_overlays/

Please note that your image must include fresh enough boot script and environment file (check for overlay_prefix line in /boot/armbianEnv.txt, otherwise you may need to update them manually.

Link to post
Share on other sites

Hey guys,

 

I have a 3.5" waveshare clone lcd with me. I managed to enable LCD display with the following commands on my orange pi lite.

 

modprobe fbtft_device debug=3 rotate=90 name=flexfb speed=16000000 gpios=reset:2,dc:71 txbuflen=32768

modprobe flexfb width=320 height=480 regwidth=16 init=-1,0xb0,0x0,-1,0x11,-2,250,-1,0x3A,0x55,-1,0xC2,0x44,-1,0xC5,0x00,0x00,0x00,0x00,-1,0xE0,0x0F,0x1F,0x1C,0x0C,0x0F,0x08,0x48,0x98,0x37,0x0A,0x13,0x04,0x11,0x0D,0x00,-1,0xE1,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0xE2,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0x36,0x28,-1,0x11,-1,0x29,-3

con2fbmap 1 8

 

I've tried following the instructions on https://github.com/Tomasz-Mankowski/ADS7846-X11-daemon github page however, i got stuck when i ran the file

./ADS7846-X11: Error connecting to SPI dev: /dev/spidev0.0
All closed...

 

I am using legacy kernel 3.4.113 orange pi lite armbian (FRESH installation)

Could anyone help me... My touch screen is using XPT2046 but from what i searched, it is similar to ADS7846.

 

I do have /dev/spidev0.0 in /dev

Link to post
Share on other sites
On 3/11/2017 at 9:02 PM, horai said:

(I am not sure whether it is possible to have it on mainline kernel, some sites say yes, I even saw source code to build the driver)

It's definitely possible ( I've done it on orange pi zero with kernel 4.11 :) ) and relatively simple - all you need is proper device tree and stock drivers (in my case ili9431 and ads7846). Basically everything you need to know, zador already told you (for second SPI CS you need to select GPIO pin, and the same for ads7846 irq).

Link to post
Share on other sites

Ok, you mean the display, that's the NOTRO driver, but I guess my note was about hardware 3D acceleration and most of the sites at the time I was trying  to run it were claiming that hardware 3D acceleration is possible only with legacy kernel not with the mainline kernel.

With legacy kernel, it's possible to accelerate 3D graphics and image it on ILI9431, but adding touch capability of the display was an issue for me.

Link to post
Share on other sites

Both kernel have pretty much the same drivers (regarding to SPI and ADS7846), you just need to configure them differently.

 

What I would do for "initial stage" is, disable LCD and make ads7846 run alone on spi bus.

Link to post
Share on other sites
On 5/5/2017 at 9:12 PM, Grzegorz Smaga said:

Hello.

I've got working ads7846 touch with this method: https://github.com/Tomasz-Mankowski/ADS7846-X11-daemon but i don't know how to run touch on system start.

OPI ONE and lcd http://www.waveshare.com/wiki/5inch_HDMI_LCD.

Armbian_5.20_Orangepione_Debian_jessie_3.4.112_desktop

I am using Armbian_5.30_Orangepione_ubuntu_xenial_default_3.4.113_desktop for orangepi zero and am able to drive the LCD in GUI mode.

I have tried  https://github.com/Tomasz-Mankowski/ADS7846-X11-daemon 

to install the touch driver but i dont see my touch working. Do i need to make any change in the hardware pins?

Link to post
Share on other sites

if somebody have dificulties with running touch here is related topics.

I am confirm that it is working with orange pi one

 

legacy kernel

 

 

mainline kernel 5" display, see sun8i-h3-spi-ads7846.dts

 

 

mainline 7" display from waveshare, see sun8i-h3-spi-ads7846.dts

 

 

 

here is also original dts for mainline

https://github.com/armbian/sunxi-DT-overlays/blob/master/examples/spi-ads7846.dts

 

 

For now, I am using mainline, and I don't found any stability problems or glithes.

 

Link to post
Share on other sites
Guest
This topic is now closed to further replies.