Forráskód Böngészése

Rebuild for a new version of USB host

Per Mårtensson 11 hónapja
szülő
commit
a62e7fc104

+ 0 - 31
sw/key800/boards/key800/pins_arduino.h

@@ -18,37 +18,6 @@
 #define analogInputToDigitalPin(p)  (((p)<20)?(esp32_adc2gpio[(p)]):-1)
 #define digitalPinToInterrupt(p)    (((p)<48)?(p):-1)
 #define digitalPinHasPWM(p)         (p < 46)
-/*
-static const uint8_t PIN_NEOPIXEL = 1;  // D1
-static const uint8_t NEOPIXEL_POWER = 21;
-
-static const uint8_t LED_BUILTIN = 13;
-
-static const uint8_t EPD_BUSY = 5;
-static const uint8_t EPD_RESET = 6;
-static const uint8_t EPD_DC = 7;
-static const uint8_t EPD_CS = 8;
-
-static const uint8_t ACCEL_IRQ = 9;
-
-static const uint8_t BUTTON_A = 15;
-static const uint8_t BUTTON_B = 14;
-static const uint8_t BUTTON_C = 12;
-static const uint8_t BUTTON_D = 11;
-
-static const uint8_t LIGHT_SENSOR = 3;
-static const uint8_t BATT_MONITOR = 4;
-static const uint8_t SPEAKER_SHUTDOWN = 16;
-
-static const uint8_t SDA = 33;
-static const uint8_t SCL = 34;
-
-static const uint8_t SS    = 8;
-static const uint8_t MOSI  = 35;
-static const uint8_t SCK   = 36;
-static const uint8_t MISO  = 37;
-
-*/
 
 
 

+ 1 - 1
sw/key800/include/abc800_callback.h

@@ -9,4 +9,4 @@ namespace abc800 {
 		void wificonnect();
 	};
 }
-#endif // __ABC80_CALLBACK_H__
+#endif // __ABC800_CALLBACK_H__

+ 5 - 5
sw/key800/include/abc800_hidboot.h

@@ -19,7 +19,7 @@ e-mail   :  support@circuitsathome.com
 #define HIDBOOT_H_INCLUDED
 
 #include <stdint.h>
-#include "keyboardpipe.h"
+
 
 #define KEY_SPACE					0x2c
 #define KEY_ZERO					0x27
@@ -106,7 +106,7 @@ struct KBDLEDS
 class HIDReportParser
 {
 public:
-	virtual void Parse(uint32_t len, uint8_t *buf,USBHostKeyboard *port) = 0;
+	virtual void Parse( uint8_t *buf = 0);
 };
 /**
  * \class KeyboardReportParser definition.
@@ -136,11 +136,11 @@ protected:
 public:
 	KeyboardReportParser() { kbdLockingKeys.bLeds = 0; };
 
-	virtual void Parse(uint32_t len, uint8_t *buf,USBHostKeyboard *port);
+	virtual void Parse( uint8_t *buf);
 	uint8_t OemToAscii(uint8_t mod, uint8_t key);
-	uint8_t OemToABC80(uint8_t mod, uint8_t key);
+	uint8_t OemToABC800(uint8_t mod, uint8_t key);
 protected:
-	uint8_t HandleLockingKeys(uint8_t key,USBHostKeyboard *port);
+	uint8_t HandleLockingKeys(uint8_t key);
 
 	virtual void OnKeyDown	(uint8_t mod, uint8_t key)	{};
 	virtual void OnKeyUp	(uint8_t mod, uint8_t key)	{};

+ 9 - 4
sw/key800/include/abc800_usb.h

@@ -1,9 +1,14 @@
 #ifndef __ABC800_USB_H__
 #define __ABC800_USB_H__
-#include "port.h"
-
-void ctrl_pipe_cb(ext_pipe_event_msg_t event, usb_irp_t *irp);
+#include "EspUsbHost.h"
 void abc800_port_init();
 void  onRepeatTimer_out(TimerHandle_t xTimer);
-
+namespace abc800
+{
+    class UsbHost800 : public EspUsbHost {
+        void onKeyboardKey(uint8_t ascii, uint8_t keycode, uint8_t modifier);
+        void onKeyboard(hid_keyboard_report_t report, hid_keyboard_report_t last_report);
+        void ohid_datain_cb(hid_keyboard_report_t report);
+    }; 
+}
 #endif

+ 3 - 4
sw/key800/platformio.ini

@@ -4,7 +4,6 @@ boards_dir = boards
 
 [env:key800]
 platform = espressif32 @ 6.9.0
-#feature/arduino-upstream
 
 board_build.f_cpu         = 80000000L
 board_bootloader.file = bootloader_qio_80m.bin
@@ -17,8 +16,8 @@ platform_packages =
 board_build.mcu = esp32s2
 description = SweProj KEY800
 lib_deps =
-    https://git.sweproj.com/pm/esp32S2-usb-host-library.git
     me-no-dev/AsyncTCP
+    https://github.com/tanakamasayuki/EspUsbHost
     https://github.com/me-no-dev/ESPAsyncWebServer.git#master
     https://git.sweproj.com/pm/AsyncElegantOTAKEY80.git#master
     https://git.sweproj.com/pm/WebSerialKEY80.git
@@ -28,8 +27,8 @@ lib_deps =
     https://github.com/plerup/espsoftwareserial.git#master
 
 
-upload_port = /dev/ttyUSB1
-monitor_port = /dev/ttyUSB1
+upload_port = /dev/ttyUSB0
+monitor_port = /dev/ttyUSB0
 monitor_speed = 115200
 
 build_type = debug

+ 2 - 2
sw/key800/src/abc800_gpio.cpp

@@ -47,7 +47,7 @@ namespace abc800 {
     }
     uint8_t gpio::sendkey(uint8_t key){
         if (key!=0xff){
-            ESP_LOGD(TAG,"OUT CODE %02x",key);
+            ESP_LOGD(TAG,"OUT CODE KEY %02x",key);
             digitalWrite(A800_KD, HIGH);
             Serial1.write(key);
             vTaskDelay( ABC800_KEY_DELAY_LEGACY);  // Enter needs longer delay so basic has enuff time to parse
@@ -57,7 +57,7 @@ namespace abc800 {
     }
     uint8_t gpio::sendfunction(uint8_t key){
         if (key!=0xff){
-            ESP_LOGD(TAG,"OUT CODE %02x",key);
+            ESP_LOGD(TAG,"OUT CODE FUNC %02x",key);
 
             Serial1.write(key);
         }

+ 10 - 13
sw/key800/src/abc800_hidboot.cpp

@@ -17,7 +17,6 @@ e-mail   :  support@circuitsathome.com
 #include "Arduino.h"
 #include "abc800_hidboot.h"
 #include <SoftwareSerial.h>
-#include "keyboardpipe.h"
 #include "esp_log.h"
 static const char TAG[] = __FILE__;
 extern SoftwareSerial abc800_serial_keyboard;
@@ -30,20 +29,18 @@ extern SoftwareSerial abc800_serial_keyboard;
  * \param len Buffer length.
  * \param buf Buffer containing report data.
  */
-void KeyboardReportParser::Parse( uint32_t len, uint8_t *buf,USBHostKeyboard *port)
-{
+void KeyboardReportParser::Parse(uint8_t *buf){
 	// On error - return
-	if (buf[2] == 1)
+	if (buf[0] == 1)
 		return;
 
-	//KBDINFO	*pki = (KBDINFO*)buf;
 
-	for (uint32_t i = 2; i < 8; ++i)
+	for (uint32_t i = 0; i < 6; ++i)
 	{
 		bool down = false;
 		bool up	  = false;
 
-		for (uint8_t j=2; j<8; j++)
+		for (uint8_t j=0; j<6; j++)
 		{
 			if (buf[i] == prevState.bInfo[j] && buf[i] != 1)
 				down = true;
@@ -53,7 +50,7 @@ void KeyboardReportParser::Parse( uint32_t len, uint8_t *buf,USBHostKeyboard *po
 
 		if (!down)
 		{
-			HandleLockingKeys( buf[i],port);
+			HandleLockingKeys( buf[i]);
 			OnKeyDown(*buf, buf[i]);
 		}
 
@@ -61,7 +58,7 @@ void KeyboardReportParser::Parse( uint32_t len, uint8_t *buf,USBHostKeyboard *po
 			OnKeyUp(prevState.bInfo[0], prevState.bInfo[i]);
 	}
 
-	for (uint32_t i = 0; i < 8; ++i)
+	for (uint32_t i = 0; i < 6; ++i)
 		prevState.bInfo[i] = buf[i];
 };
 
@@ -74,7 +71,7 @@ void KeyboardReportParser::Parse( uint32_t len, uint8_t *buf,USBHostKeyboard *po
  *
  * \return 0 on success, error code otherwise.
  */
-uint8_t KeyboardReportParser::HandleLockingKeys( uint8_t key,USBHostKeyboard *port)
+uint8_t KeyboardReportParser::HandleLockingKeys( uint8_t key)
 {
 	uint8_t old_keys = kbdLockingKeys.bLeds;
 
@@ -102,7 +99,7 @@ uint8_t KeyboardReportParser::HandleLockingKeys( uint8_t key,USBHostKeyboard *po
 	if (old_keys != kbdLockingKeys.bLeds)
 		
 		ESP_LOGI(TAG,"%02x",kbdLockingKeys.bLeds);
-		port->sendData(&kbdLockingKeys.bLeds,1);
+		///port->sendData(&kbdLockingKeys.bLeds,1); //PMPMPM
 		return 0;
 		
 
@@ -195,9 +192,9 @@ uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key)
  * \param mod Keyboard modifier.
  * \param key Key value to convert.
  *
- * \return Keyboard corresponding ABC80 value on success, 0 otherwise.
+ * \return Keyboard corresponding ABC800 value on success, 0 otherwise.
  */
-uint8_t KeyboardReportParser::OemToABC80(uint8_t mod, uint8_t key)
+uint8_t KeyboardReportParser::OemToABC800(uint8_t mod, uint8_t key)
 {
 	uint8_t shift = (mod & 0x22);
 	uint8_t ctrl = (mod & 0x22);

+ 6 - 6
sw/key800/src/abc800_keyboard.cpp

@@ -563,22 +563,22 @@ namespace abc800
         //CTRL SHIFT modifier + char
         if (keyqueue.modifier == 0x03 || keyqueue.modifier == 0x33 ){
              switch (keyqueue.ascii) {
-                case 0x4f:      // O
+                case 0x4f:
                     return 0x1f;
                     break; 
-                case 0x50:      // P
+                case 0x50:
                     return 0x00;
                     break; 
-                case 0x4b:      // K
+                case 0x4b:
                     return 0x1b;
                     break; 
-                case 0x4c:      // L
+                case 0x4c:
                     return 0x1c;
                     break; 
-                case 0x4e:      // N
+                case 0x4e:
                     return 0x1e;
                     break; 
-                case 0x4d:      // M
+                case 0x4d:
                     return 0x1d;
                     break; 
              }

+ 73 - 91
sw/key800/src/abc800_usb.cpp

@@ -1,17 +1,15 @@
 #include <Arduino.h>
 #include "abc800_usb.h"
-#include "port.h"
-#include "keyboardpipe.h"
 #include "abc800_hidboot.h"
 #include "abc800_config.h"
 #include "abc800_gpio.h"
-extern USBHostKeyboard port;
+#include "EspUsbHost.h"
 extern TimerHandle_t repeat_delay_timer_out;
 extern TimerHandle_t repeat_timer_out;
-extern KeyboardReportParser keyparse;
 extern TaskHandle_t Keyboard_Task_Out;
 extern TaskHandle_t Keyboard_ABC800_Task_In;
 extern QueueHandle_t abc800_key_queue_out;
+ KeyboardReportParser keyparse;
 uint8_t old_key = 0x00;
 key800queue key800queueold; 
 static const char TAG[] = __FILE__;
@@ -21,19 +19,7 @@ void  onRepeatTimer_out(TimerHandle_t xTimer) {
   }
    xTimerStart(repeat_timer_out, portMAX_DELAY);
 }
-void ctrl_pipe_cb(ext_pipe_event_msg_t event, usb_irp_t *irp)
-{
-  ESP_LOGI(TAG,"CTRL EVENT: 0x%x\n", event);
-  if (event == 0xA206)
-  {
-    port.getProductString();
-    delay(100);
-    port.getManufacturerString();
-    delay(100);
-    port.inpipe->inData();
-    
-  }
-}
+
 void onProductString(char *str)
 {
   ESP_LOGI(TAG,"%s",str);
@@ -43,89 +29,17 @@ void onManufacturerString(char *str)
 {
    ESP_LOGI(TAG,"%s",str);
 }
-void usbh_keyboard_device_ready()
-{
-  port.setIdle();
-  port.getHidReportMap();
-  ESP_LOGI(TAG,"Keyboard ready");
 
-}
 
-static void hid_dataout_cb(ext_pipe_event_msg_t event, usb_irp_t *irp)
+static void hid_dataout_cb()
 {
       ESP_LOGI(TAG,"DATA out return");
 }
 
-static void hid_datain_cb(ext_pipe_event_msg_t event, usb_irp_t *irp)
-{
-    switch (event)
-    {
-    case HCD_PIPE_EVENT_IRP_DONE:
-        ESP_LOGD(TAG, "modi: %i", (int8_t)irp->data_buffer[0]);
-        ESP_LOGD(TAG, "Key1: %i", (int8_t)irp->data_buffer[2]);
-        ESP_LOGD(TAG, "Key2: %i", (int8_t)irp->data_buffer[3]);
-        ESP_LOGD(TAG, "Key3: %i", (int8_t)irp->data_buffer[4]);
-        ESP_LOGD(TAG, "Key4: %i", (int8_t)irp->data_buffer[5]);
-        ESP_LOGD(TAG, "Key5: %i", (int8_t)irp->data_buffer[6]);
-        ESP_LOGD(TAG, "Key6: %i", (int8_t)irp->data_buffer[7]);
-        if (!(int8_t)irp->data_buffer[2]){
-          xTimerStop(repeat_delay_timer_out, portMAX_DELAY);
-          xTimerStop(repeat_timer_out, portMAX_DELAY);
-        }
-        uint8_t key =irp->data_buffer[2];
-        uint8_t mod =irp->data_buffer[0];
-        keyparse.Parse(irp->num_bytes,irp->data_buffer,&port);
-        if (key!=0){
-          digitalWrite(2,1);
-          ESP_LOGD(TAG,"Key number0x%02x\r\n",(char)irp->data_buffer[2]);
-          key800queue key800queue ;
-          key800queue.ascii = keyparse.OemToAscii(mod,key);
-          key800queue.special = 0x00;
-          key800queue.modifier = mod;
-          if (key800queue.ascii== 0x00 && key!=0x00){
-            key800queue.special = key;
-          }
-          if (key!=0x00 || key800queue.special!=0x00){
-            
-            if (old_key!=key)
-            {
-              // RESET
-              if (key800queue.modifier==0x05 && key ==0x4c) 
-              {
-                if (!xTaskNotifyFromISR(Keyboard_ABC800_Task_In, ABC800_KEY_RESET, eSetValueWithoutOverwrite,NULL))
-                {
-                    ESP_LOGE(TAG,"Could not notify task");
-                }
-              }
-              else
-              {
-                if (xQueueSend(abc800_key_queue_out, (void *)&key800queue, 0) != pdTRUE) {
-                  ESP_LOGE(TAG,"Queue full");
-                }
-                key800queueold=key800queue;
-                xTimerStart(repeat_delay_timer_out, portMAX_DELAY);
-              }
-            }
-            
-          }
- 
-        }else{
-          digitalWrite(KEY800_LED,LOW);
-        }
-        old_key=key;
 
-    }
-}
 
-void usb_port_cb(port_event_msg_t msg, USBHostPort *port)
-{
-  ESP_LOGI(TAG,"PORT EVENT: 0x%x\n", msg.port_event);
-}
 void abc800_port_init(){
-        port.onPortEvent(usb_port_cb);
-    port.onControlEvent(ctrl_pipe_cb);
-    port.onDataIn(hid_datain_cb);
-    port.onDataOut(hid_dataout_cb);
+
     repeat_timer_out = xTimerCreate(
                       "Repeat Timer",        // Name of timer
                       ABC800_KEY_REPEAT_TIME / portTICK_PERIOD_MS,  // Period of timer (in ticks)
@@ -140,3 +54,71 @@ void abc800_port_init(){
                       onRepeatTimer_out); 
                       
 }
+namespace abc800 {
+
+    void UsbHost800::onKeyboardKey(uint8_t ascii, uint8_t keycode, uint8_t modifier) {
+      /*if (' ' <= ascii && ascii <= '~') {
+        Serial.printf("%c %i\n", ascii,keycode);
+      } else if (ascii == '\r') {
+        Serial.println();
+      }*/
+    };
+    void UsbHost800::onKeyboard(hid_keyboard_report_t report, hid_keyboard_report_t last_report){
+        ohid_datain_cb(report);
+      
+    };
+    void UsbHost800::ohid_datain_cb(hid_keyboard_report_t report)
+    {
+
+          ESP_LOGD(TAG, "mod: %02x", report.modifier);
+          ESP_LOGD(TAG, "Key: %02x", report.keycode[0]);
+          if (!(int8_t)report.keycode[0]){ //CHECK UP DOWN PMPMPM
+            xTimerStop(repeat_delay_timer_out, portMAX_DELAY);
+            xTimerStop(repeat_timer_out, portMAX_DELAY);
+          }
+          uint8_t key = report.keycode[0];
+          uint8_t mod = report.modifier;
+          keyparse.Parse(report.keycode);
+
+          if (key!=0){
+            digitalWrite(K800_RST,1);
+            key800queue key800queue ;
+            key800queue.special = 0x00;
+            key800queue.ascii = keyparse.OemToAscii(mod,key);
+            key800queue.modifier = mod;
+            if (key800queue.ascii== 0x00 && key!=0x00){
+              key800queue.special = key;
+            }
+            if (key!=0x00 || key800queue.special!=0x00){
+              
+              if (old_key!=key)
+              {
+                // RESET
+                if (key800queue.modifier==0x05 && key ==0x4c) 
+                {
+                  if (!xTaskNotifyFromISR(Keyboard_ABC800_Task_In, ABC800_KEY_RESET, eSetValueWithoutOverwrite,NULL))
+                  {
+                      ESP_LOGE(TAG,"Could not notify task");
+                  }
+                }
+                else
+                {
+                  if (xQueueSend(abc800_key_queue_out, (void *)&key800queue, 0) != pdTRUE) {
+                    ESP_LOGE(TAG,"Queue full");
+                  }
+                  key800queueold=key800queue;
+                  xTimerStart(repeat_delay_timer_out, portMAX_DELAY);
+                }
+              }
+              
+            }
+  
+          }else{
+            digitalWrite(KEY800_LED,LOW);
+          }
+          old_key=key;
+
+  }
+
+}
+

+ 2 - 2
sw/key800/src/abc800_web.cpp

@@ -7,7 +7,7 @@
 #include "abc800_web.h"
 #include "abc800_func.h"
 #include "abc800_webcontent.h"
-#include "abc800_hidboot.h"
+//#include "abc800_hidboot.h"
 #include "abc800_gpio.h"
 #include <WebSerial.h>
 #include "ESPAsyncWiFiManager.h"
@@ -18,7 +18,7 @@ extern AsyncWebServer server;
 extern abc800::web abc800_web;
 extern abc800::std_abc800 abc800_std;
 extern TaskHandle_t OTA_Task ;
-extern KeyboardReportParser keyparse;
+//extern KeyboardReportParser keyparse;
 extern QueueHandle_t abc800_key_queue_out;
 extern AsyncElegantOtaClass AsyncElegantOTA;
 extern DNSServer dns;

+ 1 - 1
sw/key800/src/abc800_wifi.cpp

@@ -5,7 +5,7 @@
 #include "abc800_config.h"
 #include "abc800_callback.h"
 #include "abc800_web.h"
-#include "abc800_hidboot.h"
+//#include "abc800_hidboot.h"
 #include <esp_wifi.h>
 #include <DNSServer.h>
 #include <ESPAsyncWiFiManager.h> 

+ 14 - 13
sw/key800/src/main.cpp

@@ -1,9 +1,9 @@
 #include "Arduino.h"
-#include "port.h"
-#include "keyboardpipe.h"
+//#include "port.h"
+//#include "keyboardpipe.h"
 #include "esp32-hal-log.h"
-#include "parse_hid.h"
-#include "abc800_hidboot.h"
+//include "parse_hid.h"
+//#include "abc800_hidboot.h"
 #include "WiFi.h"
 #include "abc800_func.h"
 #include "abc800_wifi.h"
@@ -17,11 +17,12 @@
 #include "esp_log.h"
 #include <AsyncElegantOTA.h>
 #include <SoftwareSerial.h>
+#include "EspUsbHost.h"
 #define DEVICE_ADDRESS 2
 static const char TAG[] = __FILE__;
 
-USBHostKeyboard port(2);
-KeyboardReportParser keyparse;
+//USBHostKeyboard port(2);
+//KeyboardReportParser keyparse;
 abc800::wifi abc800_wifi;
 abc800::std_abc800 abc800_std;
 abc800::callback abc800_callback;
@@ -30,6 +31,7 @@ abc800::keyboard abc800_keyboard;
 abc800::gpio abc800_gpio;
 abc800::littlefs abc800_littlefs;
 key800config abc800_configuration;
+abc800::UsbHost800 abc800_usbHost;
 AsyncElegantOtaClass AsyncElegantOTA;
 DNSServer dns;
 AsyncWebServer server(80);
@@ -54,8 +56,8 @@ String macaddr;
 QueueHandle_t abc800_key_queue_out = NULL;
 QueueHandle_t abc800_key_queue_in = NULL;
 
-portMUX_TYPE sync_isr = portMUX_INITIALIZER_UNLOCKED;
 
+portMUX_TYPE sync_isr = portMUX_INITIALIZER_UNLOCKED;
 void setup()
 {
   Serial.begin(KEY800_SERIAL_BAUD_RATE);
@@ -67,20 +69,19 @@ void setup()
 
   abc800_key_queue_out = xQueueCreate(ABC800_KEY_OUT_BUFFER_SIZE, sizeof(key800queue));
   abc800_key_queue_in = xQueueCreate(ABC800_KEY_IN_BUFFER_SIZE, sizeof(key800queue));               
-
-  if(port.init())
-  {
-    abc800_port_init();
-  }
+  abc800_usbHost.begin();
+  abc800_usbHost.setHIDLocal(HID_LOCAL_Swedish);
+  abc800_port_init();
   
   digitalWrite(KEY800_LED,HIGH);
   abc800_keyboard.init();
   abc800_wifi.setup();
   //digitalWrite(A800_RST,HIGH);
 
+
 }
 
 void loop()
 {
-    delay(1000);
+    abc800_usbHost.task();
 }

+ 1 - 1
sw/key800/variants/key800/pins_arduino.h

@@ -7,7 +7,7 @@
 #define USB_VID 0x239A
 #define USB_PID 0x80DF
 #define USB_MANUFACTURER "SweProj"
-#define USB_PRODUCT "KEY80 ESP32-S2"
+#define USB_PRODUCT "KEY800 ESP32-S2"
 #define USB_SERIAL ""