Close

Raspberry Pi i2c Connection

A project log for Teensy Thumb Keyboard

Handheld tactile switch keyboard for Teensy 3.2 compatible boards.

Anthony DiGirolamoAnthony DiGirolamo 06/25/2019 at 04:060 Comments

Connecting to the rpi and Hyperpixel4 screen works! I modified the hyperpixel4.dtsfile in the hyperpixel4 github repo. Thanks to the Malti project for the sample tca8418 dts file.

Here's the modified dts file. It requires the tca8418_keypad kernel module to be compiled and installed. I'll get instructions up for that eventually. Right now no interrupt pin is connected and the tca8418 interrupt is set to gpio 11 (the i2c clock line). I'd pick a different pin but there's no other ones available on the hyperpixel4 pinout. I'm also not using the touch version of the hyperpixel4 which also uses the same i2c bus. That may cause conflicts so I'll have to try that next.

Edit 2019-06-29: The keyboard and touch screen both seem to work, just not at the same time. Keys will not register if you are touching the screen / moving the cursor continuously. Likewise if you are pressing/holding keys down then touching the screen will not work. One at a time works just fine though!

/dts-v1/;
/plugin/;
/ {
  compatible = "brcm,bcm2708";
  fragment@0 {
    target = <0xdeadbeef>;
    __overlay__ {
      pinctrl-names = "default";
      pinctrl-0 = <0x1>;
    };
  };
  fragment@1 {
    target = <0xdeadbeef>;
    __overlay__ {
      dpi18_pins {
        brcm,pins = <0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9    0xc 0xd 0xe 0xf 0x10 0x11     0x14 0x15 0x16 0x17 0x18 0x19>;
        brcm,function = <0x6>;
        brcm,pull = <0x0>;
        phandle = <0x1>;
      };
    };
  };
  fragment@2 {
    target-path = "/";
    __overlay__ {
      i2c_gpio: i2c@0 {
        compatible = "i2c-gpio";
        gpios = <&gpio 10 0 /* sda */
        &gpio 11 0 /* scl */
        >;
        i2c-gpio,delay-us = <4>; /* ~100 kHz */
        #address-cells = <1>;
        #size-cells = <0>;
      };
    };
  };
  fragment@3 {
    target = <&i2c_gpio>;
    __overlay__ {
      /* needed to avoid dtc warning */
      #address-cells = <1>;
      #size-cells = <0>;

      ft6236: ft6236@5d {
        compatible = "goodix,gt911";
        reg = <0x5d>;
        interrupt-parent = <&gpio>;
        interrupts = <27 2>;
        touchscreen-size-x = <480>;
        touchscreen-size-y = <800>;
        touchscreen-x-mm = <85>;
        touchscreen-y-mm = <51>;
      };

      tca8418: tca8418@34 {
        compatible = "ti,tca8418";
        reg = <0x34>;
        irq-gpio = <&gpio 11 0x2>; // IRQF_TRIGGER_FALLING
        interrupts = <11 2>; // high-to-low edge triggered
        interrupt-parent = <&gpio>;
        interrupt-controller;
        keypad,num-rows = <6>;
        keypad,num-columns = <10>;
        // row | column | key-code  ex: 04,08,0010 q key
        linux,keymap = <
        0x00000069 // 01 0,0 left 105
        0x00010067 // 02 0,1 up 103
        0x0002006c // 03 0,2 down 108
        0x0003006a // 04 0,3 right 106
        0x00040005 // 05 0,4 4 5
        0x00050008 // 06 0,5 7 8
        0x00060009 // 07 0,6 8 9
        0x0007000a // 08 0,7 9 10
        0x0008000b // 09 0,8 0 11
        0x00090035 // 10 0,9 slash 53
        0x01000002 // 11 1,0 1 2
        0x01010006 // 12 1,1 5 6
        0x01020003 // 13 1,2 2 3
        0x01030007 // 14 1,3 6 7
        0x01040004 // 15 1,4 3 4
        0x0105000c // 16 1,5 minus 12
        0x01060027 // 17 1,6 semicolon 39
        0x0107000d // 18 1,7 equal 13
        0x01080028 // 19 1,8 apostrophe 40
        0x01090001 // 20 1,9 esc 1
        0x02000010 // 21 2,0 KEY_Q 16
        0x02010011 // 22 2,1 KEY_W 17
        0x02020012 // 23 2,2 KEY_E 18
        0x02030013 // 24 2,3 KEY_R 19
        0x02040014 // 25 2,4 KEY_T 20
        0x02050015 // 26 2,5 KEY_Y 21
        0x02060016 // 27 2,6 KEY_U 22
        0x02070017 // 28 2,7 KEY_I 23
        0x02080018 // 29 2,8 KEY_O 24
        0x02090019 // 30 2,9 KEY_P 25
        0x0300001e // 31 3,0 KEY_A 30
        0x0301001f // 32 3,1 KEY_S 31
        0x03020020 // 33 3,2 KEY_D 32
        0x03030021 // 34 3,3 KEY_F 33
        0x03040022 // 35 3,4 KEY_G 34
        0x03050023 // 36 3,5 KEY_H 35
        0x03060024 // 37 3,6 KEY_J 36
        0x03070025 // 38 3,7 KEY_K 37
        0x03080026 // 39 3,8 KEY_L 38
        0x03090029 // 40 3,9 grave 41
        0x0400002a // 41 4,0 leftshift 42
        0x0401002c // 42 4,1 KEY_Z 44
        0x0402002d // 43 4,2 KEY_X 45
        0x0403002e // 44 4,3 KEY_C 46
        0x0404002f // 45 4,4 KEY_V 47
        0x04050030 // 46 4,5 KEY_B 48
        0x04060031 // 47 4,6 KEY_N 49
        0x04070032 // 48 4,7 KEY_M 50
        0x04080036 // 49 4,8 rightshift 54
        0x0409000e // 50 4,9 backspace 14
        0x0500000f // 51 5,0 tab 15
        0x0501001d // 52 5,1 leftctrl 29
        0x05020038 // 53 5,2 leftmeta 125
        0x0503007d // 54 5,3 leftalt 56
        0x0504001a // 55 5,4 leftbrace 26
        0x05050039 // 56 5,5 space 57
        0x0506001b // 57 5,6 rightbrace 27
        0x05070033 // 58 5,7 comma 51
        0x05080034 // 59 5,8 dot 52
        0x0509001c // 60 5,9 enter 28
        >;
      };
    };
  };
  fragment@4 {
    target-path = "/";
    __overlay__ {
      rpi_backlight: rpi_backlight {
        compatible = "gpio-backlight";
        gpios = <&gpio 19 0>;
        default-on;
      };
    };
  };
  fragment@5 {
    target = <&ft6236>;
    __overlay__ {
      touchscreen-inverted-x = <1>;
      touchscreen-inverted-y = <1>;
    };
  };
  __symbols__ {
    dpi18_pins = "/fragment@1/__overlay__/dpi18_pins";
  };
  __local_fixups__ {
    fragment@0 {
      __overlay__ {
        pinctrl-0 = <0x0>;
      };
    };
  };
  __fixups__ {
    leds = "/fragment@0:target:0";
    gpio = "/fragment@1:target:0";
  };
  __overrides__ {
    rotate = <0>,"-5";
  };
};

Discussions