@@ -76,11 +76,13 @@ LOG_MODULE_REGISTER(hid_target);
7676 */
7777#define ALS_HID_UNIT 0x00
7878
79- #define HID_ALS_MAX 33000
79+ #define HID_ALS_MAX 10000
8080#define HID_ALS_MIN 0
8181/* Note sensitivity is scaled by exponent 0.01*/
8282#define HID_ALS_SENSITIVITY 100
8383
84+ #define HID_ALS_REPORT_INTERVAL 1000
85+
8486/* HID_USAGE_SENSOR_PROPERTY_SENSOR_CONNECTION_TYPE */
8587#define HID_INTEGRATED 1
8688#define HID_ATTACHED 2
@@ -296,7 +298,7 @@ static const uint8_t als_report_desc[] = {
296298 0x26 , 0x10 , 0x27 , /* LOGICAL_MAXIMUM (0x2710) */
297299 0x75 , 0x10 , /* Report Size (16) */
298300 0x95 , 0x01 , /* Report Count (1) */
299- 0x55 , 0x0E , /* UNIT EXPONENT (0x0E) */
301+ 0x55 , 0x0E , /* UNIT EXPONENT (0x0E 0.01 ) */
300302 0xB1 , 0x02 , /* Feature (Data,Var,Abs) */
301303
302304 0x0A , 0xD1 , 0x24 , /* USAGE ID (Modified Maximum) */
@@ -350,7 +352,7 @@ static const uint8_t als_report_desc[] = {
350352 0x0A , 0xD1 , 0x04 , /* USAGE (Data Field: Illuminance) */
351353 0x15 , 0x00 , /* LOGICAL_MINIMUN (0x00) */
352354 0x26 , 0xFF , 0xFF , /* LOGICAL_MAXIMUM (0XFFFF) */
353- 0x55 , 0x00 , /* UNIT EXPONENT (0x00) */
355+ 0x55 , ALS_HID_UNIT , /* UNIT EXPONENT (0x00) */
354356 0x75 , 0x10 , /* Report Size (16) */
355357 0x95 , 0x01 , /* Report Count (1) */
356358 0x81 , 0x02 , /* Input (Data,Arr,Abs) */
@@ -456,16 +458,16 @@ static void hid_target_als_irq(void)
456458void i2c_hid_als_init (void )
457459{
458460 als_feature .connection_type = HID_INTEGRATED ;
459- als_feature .reporting_state = HID_ALL_EVENTS ;
461+ als_feature .reporting_state = HID_NO_EVENTS ;
460462 als_feature .power_state = HID_D0_FULL_POWER ;
461463 als_feature .sensor_state = HID_READY ;
462- als_feature .report_interval = 1000 ;
464+ als_feature .report_interval = HID_ALS_REPORT_INTERVAL ;
463465 als_feature .sensitivity = HID_ALS_SENSITIVITY ;
464466 als_feature .maximum = HID_ALS_MAX ;
465467 als_feature .minimum = HID_ALS_MIN ;
466468
467- als_sensor .event_type = 0x04 ; /* HID_DATA_UPDATED */
468- als_sensor .sensor_state = 0x02 ; /* HID READY */
469+ als_sensor .event_type = HID_DATA_UPDATED ;
470+ als_sensor .sensor_state = HID_READY ;
469471 als_sensor .illuminanceValue = 0x0000 ;
470472}
471473DECLARE_HOOK (HOOK_INIT , i2c_hid_als_init , HOOK_PRIO_DEFAULT );
@@ -475,19 +477,17 @@ DECLARE_DEFERRED(report_illuminance_value);
475477void report_illuminance_value (void )
476478{
477479 uint16_t newIlluminaceValue = * (uint16_t * )host_get_memmap (EC_MEMMAP_ALS );
478- int granularity = als_feature .sensitivity * ( HID_ALS_MAX / 10000 ) ;
480+ int granularity = als_feature .sensitivity * als_sensor . illuminanceValue / 10000 ;
479481 uint32_t report_interval = als_feature .report_interval ;
480- /* We need to polling the ALS value at least 6 seconds */
481482 switch (als_feature .reporting_state ) {
482- case HID_ALL_EVENTS :
483- case HID_ALL_EVENTS_WAKE :
484- als_sensor .illuminanceValue = newIlluminaceValue ;
485- hid_target_als_irq ();
486- break ;
483+ /* we did not implement threshold reporting in our HID descriptor */
487484 case HID_THRESHOLD_EVENTS :
488485 case HID_THRESHOLD_EVENTS_WAKE :
486+ case HID_ALL_EVENTS :
487+ case HID_ALL_EVENTS_WAKE :
489488 if (ABS (als_sensor .illuminanceValue - newIlluminaceValue ) > granularity ) {
490489 als_sensor .illuminanceValue = newIlluminaceValue ;
490+ als_sensor .event_type = HID_DATA_UPDATED ;
491491 hid_target_als_irq ();
492492 }
493493 break ;
@@ -497,7 +497,7 @@ void report_illuminance_value(void)
497497
498498 if (report_interval == 0 ) {
499499 /* per hid spec report interval should be sensor default when 0 */
500- report_interval = 250 ;
500+ report_interval = HID_ALS_REPORT_INTERVAL ;
501501 }
502502 hook_call_deferred (& report_illuminance_value_data ,
503503 report_interval * MSEC );
@@ -640,6 +640,7 @@ static int hid_target_process_write(struct i2c_target_config *config)
640640 #endif
641641 case REPORT_ID_SENSOR :
642642 if (report_type == 0x01 ) {
643+ als_sensor .event_type = HID_POLL_RESPONSE ;
643644 response_size = fill_report (data -> buffer , report_id ,
644645 & als_sensor ,
645646 sizeof (struct als_input_report ));
@@ -809,18 +810,32 @@ static int hid_target_read_requested(struct i2c_target_config *config,
809810}
810811
811812
812- static int cmd_hid_status (int argc , const char * * argv )
813+ static int cmd_hidals_status (int argc , const char * * argv )
813814{
815+ int i ;
816+ char * e ;
817+
818+ if (argc == 2 ) {
819+ i = strtoi (argv [1 ], & e , 0 );
820+ if (* e )
821+ return EC_ERROR_PARAM1 ;
822+ als_sensor .illuminanceValue = i ;
823+ als_sensor .event_type = HID_DATA_UPDATED ;
824+ hid_target_als_irq ();
825+ }
826+
814827 ccprintf ("ALS Feature\n" );
828+ ccprintf (" report_state:%d\n" , als_feature .reporting_state );
815829 ccprintf (" Power:%d\n" , als_feature .power_state );
830+ ccprintf (" Sensor:%d\n" , als_feature .sensor_state );
816831 ccprintf (" Interval:%dms\n" , als_feature .report_interval );
817832 ccprintf (" sensitivity:%d\n" , als_feature .sensitivity );
818- ccprintf (" report_state :%d\n" , als_feature . reporting_state );
833+ ccprintf (" illuminance :%d\n" , als_sensor . illuminanceValue );
819834
820835 return EC_SUCCESS ;
821836}
822- DECLARE_CONSOLE_COMMAND (hidstatus , cmd_hid_status , "" ,
823- "Get hid device status" );
837+ DECLARE_CONSOLE_COMMAND (hidals , cmd_hidals_status , "[lux] " ,
838+ "Get als device status" );
824839
825840static int hid_target_stop (struct i2c_target_config * config )
826841{
0 commit comments