ec: fix button/powerbtn behavior

This changes does 2 things:
- it unifies volume up/down/up_down_hold and pwr_button_hold all under
one ec driver function and uses the parameters to indicate how to invoke
it. This is to reduce code and also have common error guarding (below)
- it guards against assertion errors in the EC by overwriting anything
less than 1 as the value (1ms) with 1ms.

BUG=b:123212205
TEST=manual testing
dut-control pwr_button_hold:10

> powerbtn  10
Simulating 10 ms power button press.
[936.095299 power button pressed]
[936.095475 buttons: 5]
[936.095666 SW 0x07]
[936.095932 event set 0x0000000000000004]
Simulating power button release.
> [936.104859 power button released]
[936.105017 buttons: 4]
[936.105208 SW 0x05]

dut-control volume_up_hold:10

> button vup 10
[948.650757 Button 'Volume Up' was pressed]
[948.650962 buttons: 6]

dut-control volume_down_hold:10

> [953.951354 Battery 48% (Display 0.0 %) / 2h:0 to full]
[958.651181 DEBUG MODE: Active!]
button vdown 10
[965.652122 Button 'Volume Down' was released]
[965.652333 buttons: 2]
> [968.651407 DEBUG MODE: Exit!]

dut-control volume_up_down_hold:100

> button vup vdown 100
[973.135337 Button 'Volume Up' was released]
[973.135545 buttons: 0]
[973.143246 Button 'Volume Down' was pressed]
[973.143455 buttons: 4]
[973.250463 Button 'Volume Up' was pressed]
[973.250668 buttons: 6]
[973.258372 Button 'Volume Down' was released]
[973.258583 buttons: 2]
[973.258753 DEBUG MODE: Exit!]
>

dut-control volume_up_down_hold:0
2019-01-22 18:49:43,270 - ec - ERROR - Trying to set ec button press to 0 ms.
Overwriting the value to be 1ms. // Servod logs.

// EC console

> button vup vdown 1
[1165.667043 Button 'Volume Up' was released]
[1165.667256 buttons: 0]
[1165.674961 Button 'Volume Down' was pressed]
[1165.675176 buttons: 4]

Change-Id: Icd9895e8da16c74a0e60156393d3b8cfd0fe43b3
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1426284
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Todd Broch <tbroch@chromium.org>
3 files changed