Skip to content

Commit 7343d12

Browse files
authored
Merge pull request #735 from FrameworkComputer/azalea.i2chid
dual i2c hid interface
2 parents 839e89e + 6e27f42 commit 7343d12

File tree

11 files changed

+1017
-13
lines changed

11 files changed

+1017
-13
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
description: |
4+
Zephyr I2C target HID implements the i2c-hid
5+
protocol as a i2c slave device.
6+
7+
compatible: "cros-ec,i2c-target-hid"
8+
9+
include: [i2c-device.yaml]
10+
11+
properties:
12+
reg:
13+
required: true
14+
15+
max_report_size:
16+
type: int
17+
required: true
18+
19+
alert_gpios:
20+
required: true
21+
type: phandle-array
22+
description:
23+
Active low GPIO to notify the i2c master to
24+
service a request.
25+
26+
hid_descriptor:
27+
type: string
28+
description:
29+
The C function name that will be called to
30+
populate the hid report
31+
32+
hid_report_descriptor:
33+
type: string
34+
description:
35+
The C function name that will be called to
36+
populate the hid report
37+
38+
get_report_handler:
39+
type: string
40+
description:
41+
The C function name that will be called to
42+
populate the hid report
43+
44+
set_report_handler:
45+
type: string
46+
description:
47+
The C function name that will be called to
48+
act on a set report from the host
49+
50+
power_state_handler:
51+
type: string
52+
description:
53+
The C function name that will be called when
54+
the host updates the power state

zephyr/program/lotus/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ zephyr_library_sources("src/factory.c")
1414
zephyr_library_sources("src/diagnostics.c")
1515
zephyr_library_sources("src/ucsi.c")
1616
zephyr_library_sources("src/als.c")
17+
zephyr_library_sources("src/hid_device.c")
18+
1719

1820
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON
1921
"src/led_pwm.c")

zephyr/program/lotus/azalea/gpio.dtsi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@
151151
i2c_int_tp_l {
152152
gpios = <&gpioa 4 GPIO_INPUT>; /* HUB board TP module */
153153
};
154-
apu_ec_int_l {
154+
gpio_apu_ec_int_l: apu_ec_int_l {
155155
gpios = <&gpio9 6 GPIO_ODR_HIGH>; /* EC notify host HID interrupt */
156156
};
157+
gpio_apu_ec_int2_l: apu_ec_int2_l {
158+
gpios = <&gpio7 4 GPIO_ODR_HIGH>; /* EC notify host HID interrupt 2*/
159+
};
157160
cam_sw {
158161
gpios = <&gpio9 3 GPIO_INPUT>;
159162
};

zephyr/program/lotus/azalea/i2c.dtsi

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,24 @@
5656
pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>;
5757
pinctrl-names = "default";
5858

59-
/* TODO: Add the device on this bus */
59+
i2chid0: i2chid@50 {
60+
compatible = "cros-ec,i2c-target-hid";
61+
reg = <0x50>;
62+
alert_gpios = <&gpio9 6 GPIO_OPEN_DRAIN>;
63+
max_report_size = <32>;
64+
hid_descriptor = "keyboard_hid_desc";
65+
hid_report_descriptor = "keyboard_report_desc";
66+
};
67+
68+
i2chid1: i2chid@51 {
69+
compatible = "cros-ec,i2c-target-hid";
70+
reg = <0x51>;
71+
alert_gpios = <&gpio7 4 GPIO_OPEN_DRAIN>;
72+
max_report_size = <32>;
73+
hid_descriptor = "als_hid_desc";
74+
hid_report_descriptor = "als_report_desc";
75+
};
76+
6077
};
6178

6279
&i2c_ctrl0 {

zephyr/program/lotus/azalea/overlay.dtsi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* found in the LICENSE file.
44
*/
55

6+
#include <freq.h>
7+
8+
69
/ {
710
named-gpios {
811
/* Lotus-specific GPIO customizations */
@@ -158,5 +161,3 @@
158161
>;
159162
pinctrl-names = "default";
160163
};
161-
162-

zephyr/program/lotus/azalea/src/keyboard_customization.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "pwm.h"
1919
#include "hooks.h"
2020
#include "system.h"
21+
#include "hid_device.h"
2122

2223
/* Console output macros */
2324
#define CPUTS(outstr) cputs(CC_KEYBOARD, outstr)
@@ -281,15 +282,13 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t fn, int8_t pressed)
281282
break;
282283
case SCANCODE_F7: /* TODO: DIM_SCREEN */
283284
if (fn_table_media_set(pressed, KB_FN_F7)) {
284-
/* TODO HID API */
285-
/*update_hid_key(HID_KEY_DISPLAY_BRIGHTNESS_DN, pressed);*/
285+
hid_consumer(BUTTON_ID_BRIGHTNESS_DECREMENT, pressed);
286286
return EC_ERROR_UNIMPLEMENTED;
287287
}
288288
break;
289289
case SCANCODE_F8: /* TODO: BRIGHTEN_SCREEN */
290290
if (fn_table_media_set(pressed, KB_FN_F8)) {
291-
/* TODO HID API */
292-
/*update_hid_key(HID_KEY_DISPLAY_BRIGHTNESS_UP, pressed);*/
291+
hid_consumer(BUTTON_ID_BRIGHTNESS_INCREMENT, pressed);
293292
return EC_ERROR_UNIMPLEMENTED;
294293
}
295294
break;
@@ -307,8 +306,7 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t fn, int8_t pressed)
307306
break;
308307
case SCANCODE_F10: /* FLIGHT_MODE */
309308
if (fn_table_media_set(pressed, KB_FN_F10)) {
310-
/* TODO HID API */
311-
/*update_hid_key(HID_KEY_AIRPLANE_MODE, pressed);*/
309+
hid_airplane(pressed);
312310
return EC_ERROR_UNIMPLEMENTED;
313311
}
314312
break;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Copyright 2021 The ChromiumOS Authors
2+
* Use of this source code is governed by a BSD-style license that can be
3+
* found in the LICENSE file.
4+
*/
5+
6+
#ifndef __CROS_EC_I2C_HID_DEVICE_H
7+
#define __CROS_EC_I2C_HID_DEVICE_H
8+
9+
#include "util.h"
10+
11+
/*
12+
* See hid usage tables for consumer page
13+
* https://www.usb.org/hid
14+
*/
15+
#define BUTTON_ID_BRIGHTNESS_INCREMENT 0x006F
16+
#define BUTTON_ID_BRIGHTNESS_DECREMENT 0x0070
17+
18+
void hid_consumer(uint16_t id, bool pressed);
19+
void hid_airplane(bool pressed);
20+
21+
22+
#endif /* __CROS_EC_I2C_HID_DEVICE_H */

zephyr/program/lotus/lotus/gpio.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120
gpio_gpu_vsys_vadp_en: gpu_vsys_vadp_en {
121121
gpios = <&gpio1 5 GPIO_OUTPUT_LOW>; /* Enable GPIO Vsys/VADP PWR */
122122
};
123-
apu_ec_int_l {
124-
gpios = <&gpio1 4 GPIO_ODR_LOW>; /* HID over I2C interrupt */
123+
gpio_apu_ec_int_l: apu_ec_int_l {
124+
gpios = <&gpio1 4 GPIO_ODR_HIGH>; /* HID over I2C interrupt */
125125
};
126126
ec_disen2 {
127127
gpios = <&gpio1 3 GPIO_OUTPUT_LOW>; /* Disable LM5143 Ph2 */

zephyr/program/lotus/lotus/i2c.dtsi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@
6767
pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>;
6868
pinctrl-names = "default";
6969

70-
/* TODO: Add the device on this bus */
70+
i2chid1: i2chid@51 {
71+
compatible = "cros-ec,i2c-target-hid";
72+
reg = <0x51>;
73+
alert_gpios = <&gpio1 4 GPIO_OPEN_DRAIN>;
74+
max_report_size = <32>;
75+
hid_descriptor = "als_hid_desc";
76+
hid_report_descriptor = "als_report_desc";
77+
};
7178
};
7279

7380
&i2c_ctrl0 {

zephyr/program/lotus/program.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ CONFIG_PLATFORM_EC_LED_DT=n
8686
CONFIG_PLATFORM_EC_BACKLIGHT_LID=n
8787
CONFIG_PLATFORM_EC_VBOOT_EFS2=n
8888
CONFIG_PLATFORM_EC_CBI=n
89+
90+
#i2c hid
91+
CONFIG_I2C_TARGET=y

0 commit comments

Comments
 (0)