浏览代码

RN42 driver: small cleanups (#18310)

* RN42 driver: small cleanups

* Include header

* Fix mouse report per RN42 UG

* Spacing for consistency
Ryan 2 年之前
父节点
当前提交
f20883fef1
共有 2 个文件被更改,包括 21 次插入15 次删除
  1. 18 14
      drivers/bluetooth/rn42.c
  2. 3 1
      drivers/bluetooth/rn42.h

+ 18 - 14
drivers/bluetooth/rn42.c

@@ -14,6 +14,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "rn42.h"
+
 #include "report.h"
 #include "uart.h"
 
@@ -69,33 +71,35 @@ void rn42_send_keyboard(report_keyboard_t *report) {
     uart_write(0xFD);
     uart_write(0x09);
     uart_write(0x01);
+
     uart_write(report->mods);
     uart_write(0x00);
-    for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
-        uart_write(report->keys[i]);
-    }
+    uart_write(report->keys[0]);
+    uart_write(report->keys[1]);
+    uart_write(report->keys[2]);
+    uart_write(report->keys[3]);
+    uart_write(report->keys[4]);
+    uart_write(report->keys[5]);
 }
 
 void rn42_send_mouse(report_mouse_t *report) {
     uart_write(0xFD);
-    uart_write(0x00);
-    uart_write(0x03);
+    uart_write(0x05);
+    uart_write(0x02);
+
     uart_write(report->buttons);
     uart_write(report->x);
     uart_write(report->y);
-    uart_write(report->v); // should try sending the wheel v here
-    uart_write(report->h); // should try sending the wheel h here
-    uart_write(0x00);
+    uart_write(report->v);
 }
 
-void rn42_send_consumer(uint16_t data) {
-    static uint16_t last_data = 0;
-    if (data == last_data) return;
-    last_data       = data;
-    uint16_t bitmap = rn42_consumer_usage_to_bitmap(data);
+void rn42_send_consumer(uint16_t usage) {
+    uint16_t bitmap = rn42_consumer_usage_to_bitmap(usage);
+
     uart_write(0xFD);
     uart_write(0x03);
     uart_write(0x03);
+
     uart_write(bitmap & 0xFF);
-    uart_write((bitmap >> 8) & 0xFF);
+    uart_write(bitmap >> 8);
 }

+ 3 - 1
drivers/bluetooth/rn42.h

@@ -14,6 +14,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <stdint.h>
+
 #include "report.h"
 
 void rn42_init(void);
@@ -22,4 +24,4 @@ void rn42_send_keyboard(report_keyboard_t *report);
 
 void rn42_send_mouse(report_mouse_t *report);
 
-void rn42_send_consumer(uint16_t data);
+void rn42_send_consumer(uint16_t usage);