Skip to content

Commit 162668e

Browse files
authored
Merge pull request #442 from FrameworkComputer/hx30.HID_power_state
Used HID power state to control ALS HID report
2 parents 462c65d + 856acce commit 162668e

1 file changed

Lines changed: 49 additions & 16 deletions

File tree

board/hx30/i2c_hid_mediakeys.c

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121

2222
#define HID_SLAVE_CTRL 3
2323

24-
#define REPORT_ID_RADIO 0x01
25-
#define REPORT_ID_CONSUMER 0x02
26-
#define REPORT_ID_SENSOR 0x03
24+
#define REPORT_ID_RADIO 0x01
25+
#define REPORT_ID_CONSUMER 0x02
26+
#define REPORT_ID_SENSOR 0x03
27+
28+
#define ALS_REPORT_STOP 0x00
29+
#define ALS_REPORT_POLLING 0x01
30+
#define ALS_REPORT_THRES 0x02
2731

2832
/*
2933
* See hid usage tables for consumer page
@@ -346,11 +350,39 @@ void i2c_hid_als_init(void)
346350
als_sensor.illuminanceValue = 0x0000;
347351
}
348352

353+
void report_illuminance_value(void)
354+
{
355+
/* bypass the EC_MEMMAP_ALS value to input report */
356+
als_sensor.illuminanceValue = *(uint16_t *)host_get_memmap(EC_MEMMAP_ALS);
357+
358+
/* wait 6s to change mode from polling to threshold */
359+
360+
361+
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) |
362+
EVENT_REPORT_ILLUMINANCE_VALUE), 0);
363+
}
364+
DECLARE_DEFERRED(report_illuminance_value);
365+
349366
static void i2c_hid_send_response(void)
350367
{
351-
task_set_event(TASK_ID_HID,
352-
EVENT_HID_HOST_IRQ | EVENT_REPORT_ILLUMINANCE_VALUE, 0);
368+
task_set_event(TASK_ID_HID, EVENT_HID_HOST_IRQ, 0);
353369
}
370+
371+
static void als_report_control(uint8_t report_mode)
372+
{
373+
if (report_mode == 0x01) {
374+
/* als report mode = polling */
375+
hook_call_deferred(&report_illuminance_value_data,
376+
((int) als_feature.report_interval) * MSEC);
377+
} else if (report_mode == 0x02) {
378+
/* als report mode = threshold */
379+
;
380+
} else {
381+
/* stop report als value */
382+
hook_call_deferred(&report_illuminance_value_data, -1);
383+
}
384+
}
385+
354386
static size_t fill_report(uint8_t *buffer, uint8_t report_id, const void *data,
355387
size_t data_len)
356388
{
@@ -384,7 +416,6 @@ static int i2c_hid_touchpad_command_process(size_t len, uint8_t *buffer)
384416
switch (command) {
385417
case I2C_HID_CMD_RESET:
386418
i2c_hid_mediakeys_init();
387-
i2c_hid_als_init();
388419

389420
/* Wait for the 2-bytes I2C read following the protocol reset. */
390421
pending_probe = false;
@@ -442,6 +473,13 @@ static int i2c_hid_touchpad_command_process(size_t len, uint8_t *buffer)
442473
*/
443474
*buffer = power_state;
444475
response_len = 1;
476+
477+
if (power_state == 0x00) {
478+
i2c_hid_als_init();
479+
als_report_control(ALS_REPORT_POLLING);
480+
} else
481+
als_report_control(ALS_REPORT_STOP);
482+
445483
break;
446484
default:
447485
return 0;
@@ -557,15 +595,6 @@ void hid_irq_to_host(void)
557595
usleep(10);
558596
}
559597

560-
void report_illuminance_value(void)
561-
{
562-
/* bypass the EC_MEMMAP_ALS value to input report */
563-
als_sensor.illuminanceValue = *(uint16_t *)host_get_memmap(EC_MEMMAP_ALS);
564-
565-
task_set_event(TASK_ID_HID, ((1 << HID_ALS_REPORT_LUX) | 0x4000), 0);
566-
}
567-
DECLARE_DEFERRED(report_illuminance_value);
568-
569598
void hid_handler_task(void *p)
570599
{
571600
uint32_t event;
@@ -589,7 +618,11 @@ void hid_handler_task(void *p)
589618
if (event & 0xFFFF) {
590619

591620
for (i = 0; i < 15; i++) {
592-
if (event & (1<<i)) {
621+
/**
622+
* filter EVENT_REPORT_ILLUMINANCE_VALUE
623+
* this event only call deferred
624+
*/
625+
if ((event & 0xBFFF) & (1<<i)) {
593626
update_key = i;
594627
switch (i) {
595628
case HID_KEY_DISPLAY_BRIGHTNESS_UP:

0 commit comments

Comments
 (0)