Skip to content

Getting the unPhone working. #536

@jedie

Description

@jedie

I have a unPhone (spin 9) and tried to get MicroPythonOS working: MicroPythonOS/MicroPythonOS#74

Display HX8357D and XPT2046 touch works in general, but currently not together.
Seems the Problem is that both used the same SPI bus.

My setup is like: https://github.com/lvgl-micropython/lvgl_micropython?tab=readme-ov-file#spi-bus-with-spi-touch-same-spi-bus

If i use SPI Bus host = 1 for display + touch, then the touch registers are always 0xff
If i use SPI Bus host =1 for display and host = 2 for touch, then the registers are always 0x00

In both cases: The Display work.

I also tried chip select (T_CS) of touch screen, before read, but doesn't change anything.

Any idea?

EDIT: Sound like https://dmitry.gr/?r=06.%20Thoughts&proj=09.ComplexPioMachines described a similar problem.

i also tried this:

    def _read_reg(self, reg, num_bytes) -> int:
        try:
            for read_count in range(50):
                self._tx_buf[0] = reg

                self.lcd_cs.value(1)  # deselect LCD to avoid conflicts
                self.touch_cs.value(0)  # select touch chip
                self.device.write_readinto(
                    self._tx_mv[:num_bytes], self._rx_mv[:num_bytes]
                )
                if self.lcd_cs.value() == 1 and self.touch_cs.value() == 0:
                    # if still selected, we got a valid read
                    break
        finally:
            self.touch_cs.value(1)  # deselect touch chip
            self.lcd_cs.value(0)  # select LCD

        print(
            f"write_readinto {read_count=}"
            f" Channel: {reg:#04x}, Received: {[hex(b) for b in self._rx_buf]}"
        )
        return ((self._rx_buf[1] << 8) | self._rx_buf[2]) >> 3

But doesn't help, the output is always:

write_readinto read_count=0 Channel: 0xb0, Received: ['0x0', '0x0', '0x0']
write_readinto read_count=0 Channel: 0xd0, Received: ['0x0', '0x0', '0x0']
write_readinto read_count=0 Channel: 0x90, Received: ['0x0', '0x0', '0x0']

A other idea:

    def _read_reg(self, reg, num_bytes) -> int:

        # First read to get reference:
        self._tx_buf[0] = reg
        self.device.write_readinto(
            self._tx_mv[:num_bytes], self._rx_mv[:num_bytes]
        )
        reference = self._rx_buf[:num_bytes]
        
        try:
            for read_count in range(50):
                self._tx_buf[0] = reg

                self.lcd_cs.value(1)  # deselect LCD to avoid conflicts
                self.touch_cs.value(0)  # select touch chip
                self.device.write_readinto(
                    self._tx_mv[:num_bytes], self._rx_mv[:num_bytes]
                )
                if self._rx_buf[:num_bytes] != reference:
                    # we got a valid read
                    break
        finally:
            self.touch_cs.value(1)  # deselect touch chip
            self.lcd_cs.value(0)  # select LCD

        print(
            f"write_readinto {read_count=}"
            f" Channel: {reg:#04x}, Received: {[hex(b) for b in self._rx_buf]}"
        )
        return ((self._rx_buf[1] << 8) | self._rx_buf[2]) >> 3

Also doesn't help:

 write_readinto read_count=49 Channel: 0xb0, Received: ['0x0', '0x0', '0x0']
write_readinto read_count=49 Channel: 0xd0, Received: ['0x0', '0x0', '0x0']
write_readinto read_count=49 Channel: 0x90, Received: ['0x0', '0x0', '0x0']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions