Re-Compile Raspbian Kernel for Touch Rotation of Waveshare HDMI LCD

   Several months ago, if users of Waveshare HDMI LCD ask about how could I rotate the LCD not only the display but as well as the touch. We always said that you need to re-compile the kernel but we have no instruction about it. And two months ago we provided another method that modify the libinput paramters which you can visit on our wiki website.
   Here I want to share you the way that compiling kernel.
  1.  Install the newest Raspbain to your Raspberry Pi, here we take 2017-11-29-raspbian-stretch and Waveshare 7inch HDMI LCD (C)as examples
  2. Start up your Raspberry Pi and connect it to network and make sure the network is available
  3.  Install Git and related tool
    sudo apt-get install git bc
    sudo apt-get install libncurses5-dev
  4. Clone the source code, it may cost several minutes
    git clone --depth=1
  5. Execute corresponding commands according to your Raspberry Pi version
    #Raspberry Pi 1, Pi 0, Pi 0W and Compute Module use these commands
    cd linux
    make bcmrpi_defconfig

    #Raspberry Pi 2, Pi 3 and the Compute Module 3 please use these commands
    cd linux
    make bcm2709_defconfig
  6. Compile the kernel, module and device tree, it will cost several hours for this step and your Pi may became hot.
  7. make -j4 zImage modules dtbs
  8. Finish compiling, execute commands below to install module and replace related files.
  9. sudo make modules_install
    sudo cp arch/arm/boot/dts/*.dtb /boot/
    sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
    sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
    sudo cp arch/arm/boot/zImage /boot/$KERNEL.img
  10. Reboot your Pi, if reboot successfully, means that the compilation above is successful
  11. Add touch driver for 7inch HDMI LCD (C) . Download and copy WS_7inch_C.c to linux/drivers/input/touchscreen
    • Edit the linux/drivers/input/touchscreen.Makefile, append these statements to it: obj-$(CONFIG_USB_WaveShare_WS_7inch_C)  += WS_7inch_C.o
    • Append these statements to file linux\drivers\input\touchscreen\Kconfig
      config USB_WaveShare_WS_7inch_C
       tristate "WaveShare_WS_7inch_C"
       depends on USB && INPUT
  12. If you want to rotate the LCD, just change the Waveshare_Rotate value on WS_7inch_C.c
    Waveshare_Rotate=0, #0 degree rotation
    Waveshare_Rotate=90, #90 degree rotation
    Waveshare_Rotate=180, #180 degree rotation
    Waveshare_Rotate=270, #270 degree rotation

    And add related statement to /boot/config.txt file
    display_rotate=0, #0 degree rotation
    display_rotate=90, #90 degree rotation
    display_rotate=180, #180 degree rotation
    display_rotate=270, #270 degree rotation
  13. Back to the root directory of linux, execute make menuconfig to open the config page of kernel. Select Device Drivers --> Input device support --> Touchscreen. Choose WaveShare_WS_7inch_C and press "y", to compile the WaveShare_WS_7inch_C module to kernel.

  14. Compile kernel, install the module and copy related files as we do before. and finally restart your Pi.
    make -j4 zImage modules dtbs
    sudo make modules_install
    sudo cp arch/arm/boot/dts/*.dtb /boot/
    sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
    sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/

    #for Raspberry Pi 1, Pi0, Pi 0W and Compute Module:
    sudo cp arch/arm/boot/zImage /boot/kernel.img

    #for Raspberry Pi 2, Pi3 and Compute Module 3
    sudo cp arch/arm/boot/zImage /boot/kernel7.img

reference resource:

PS:If you find any errors on this article, please kindly let me know.



Make a new larger font for Waveshare SPI e-Paper

Raspberry Pi drive 1.44inch LCD HAT with fbtft