mkbp: Consider max_code requested when returning button/key codes

Currently, button codes are returned without considering the max codes
requested by the caller and key code handling checks for overflow
after adding a key. Fix that by creating a common function for adding
key/button codes that checks total against max_codes. Also, update
changed to be 0 or 1 only since we only use that as a boolean flag.

BUG=None
BRANCH=None
TEST=Verified that buttons still work on poppy.

Change-Id: I2e5672fa00c49a5e72a5997dcad1768c1e6228b3
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/516543
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
1 file changed