summaryrefslogtreecommitdiff
path: root/chip/stm32/usb_hid.c
diff options
context:
space:
mode:
authorWei-Ning Huang <wnhuang@google.com>2017-07-26 17:43:46 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-09-01 12:39:19 -0700
commit235d9a18c14dbfccaa48dd344d88fb3ba4309052 (patch)
tree9025147ec32937dbb40922c05320176d688fff8f /chip/stm32/usb_hid.c
parent72252db3425a88f404f6d76eb15d02ace06747b7 (diff)
downloadchrome-ec-235d9a18c14dbfccaa48dd344d88fb3ba4309052.tar.gz
chip/stm32/usb_hid_keyboard: implement keyboard backlight control
Implement keyboard backlight control through HID output report. One could enable CONFIG_USB_HID_KEYBOARD_BACKLIGHT to enable keyboard backlight support for a given board. Target board must implement the `void board_set_backlight(int brightness)` function in order correctly set backlight. BRANCH=none BUG=b:37971411,b:63364143 TEST=with follow up CLs 1. `make BOARD=hammer -j` 2. `echo 10 > /sys/class/leds/hammer\:\:kbd_backlight/brightness` console shows 'Keyboard backlight set to 10%' Change-Id: Ibeff510a0d996ddebf61b54ed6b500b02c35564a Signed-off-by: Wei-Ning Huang <wnhuang@google.com> Reviewed-on: https://chromium-review.googlesource.com/586348 Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org> Tested-by: Wei-Ning Huang <wnhuang@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'chip/stm32/usb_hid.c')
-rw-r--r--chip/stm32/usb_hid.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/chip/stm32/usb_hid.c b/chip/stm32/usb_hid.c
index 4a89d9573c..f24bdd5982 100644
--- a/chip/stm32/usb_hid.c
+++ b/chip/stm32/usb_hid.c
@@ -28,18 +28,33 @@ void hid_tx(int ep)
STM32_USB_EP(ep) = (STM32_USB_EP(ep) & EP_MASK);
}
-void hid_reset(int ep, usb_uint *hid_ep_buf, int len)
+void hid_reset(int ep, usb_uint *hid_ep_tx_buf, int tx_len,
+ usb_uint *hid_ep_rx_buf, int rx_len)
{
int i;
- /* HID interrupt endpoint 1 */
- btable_ep[ep].tx_addr = usb_sram_addr(hid_ep_buf);
- btable_ep[ep].tx_count = len;
- for (i = 0; i < (len+1)/2; i++)
- hid_ep_buf[i] = 0;
- STM32_USB_EP(ep) = (ep << 0) /* Endpoint Address */ |
- (3 << 4) /* TX Valid */ |
+ uint16_t ep_reg;
+
+ btable_ep[ep].tx_addr = usb_sram_addr(hid_ep_tx_buf);
+ btable_ep[ep].tx_count = tx_len;
+
+ /* STM32 USB SRAM needs to be accessed one U16 at a time */
+ for (i = 0; i < DIV_ROUND_UP(tx_len, 2); i++)
+ hid_ep_tx_buf[i] = 0;
+
+ ep_reg = (ep << 0) /* Endpoint Address */ |
+ EP_TX_VALID |
(3 << 9) /* interrupt EP */ |
- (0 << 12) /* RX Disabled */;
+ EP_RX_DISAB;
+
+ /* Enable RX for output reports */
+ if (hid_ep_rx_buf && rx_len > 0) {
+ btable_ep[ep].rx_addr = usb_sram_addr(hid_ep_rx_buf);
+ btable_ep[ep].rx_count = ((rx_len + 1) / 2) << 10;
+
+ ep_reg |= EP_RX_VALID; /* RX Valid */
+ }
+
+ STM32_USB_EP(ep) = ep_reg;
}
/*