firmware+controller: Initial working HID state control
This commit is contained in:
		@@ -280,7 +280,5 @@ void val_lvgl_ui(lv_display_t *disp) {
 | 
			
		||||
  lv_label_set_text(l_cfg, LV_SYMBOL_SETTINGS);
 | 
			
		||||
  lv_obj_center(l_cfg);
 | 
			
		||||
 | 
			
		||||
  // val_ui_none();
 | 
			
		||||
  // val_ui_menu(true);
 | 
			
		||||
  val_ui_idle();
 | 
			
		||||
  val_ui_none();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "usb.h"
 | 
			
		||||
#include "lcd.h"
 | 
			
		||||
#include "ui.h"
 | 
			
		||||
 | 
			
		||||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
 | 
			
		||||
 | 
			
		||||
@@ -77,24 +78,55 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance) {
 | 
			
		||||
// Invoked when received GET_REPORT control request
 | 
			
		||||
// Application must fill buffer report's content and return its length.
 | 
			
		||||
// Return zero will cause the stack to STALL request
 | 
			
		||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
 | 
			
		||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buf, uint16_t reqlen) {
 | 
			
		||||
    (void) instance;
 | 
			
		||||
    (void) report_id;
 | 
			
		||||
    (void) report_type;
 | 
			
		||||
    (void) buffer;
 | 
			
		||||
    (void) reqlen;
 | 
			
		||||
    if (report_id != 0 || reqlen < 1) {
 | 
			
		||||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
    // ESP_LOGI(TAG, "Got %hu bytes report %hhu", reqlen, report_id);
 | 
			
		||||
    // for (uint16_t i = 0; i < reqlen; i++) {
 | 
			
		||||
    //   ESP_LOGI(TAG, "b: %02hhx", buf[i]);
 | 
			
		||||
    // }
 | 
			
		||||
    buf[0] = val_ui_state_ready();
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Invoked when received SET_REPORT control request or
 | 
			
		||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
 | 
			
		||||
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
 | 
			
		||||
  assert(report_id == 0 && report_type == HID_REPORT_TYPE_OUTPUT);
 | 
			
		||||
  ESP_LOGI(TAG, "Got %hu bytes report %hhu", bufsize, report_id);
 | 
			
		||||
  for (uint16_t i = 0; i < bufsize; i++) {
 | 
			
		||||
    ESP_LOGI(TAG, "b: %02hhx", buffer[i]);
 | 
			
		||||
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buf, uint16_t bufsize) {
 | 
			
		||||
  (void) instance;
 | 
			
		||||
  assert(report_id == 0 && report_type == HID_REPORT_TYPE_OUTPUT && bufsize >= 1);
 | 
			
		||||
  if (!val_lvgl_lock(-1)) {
 | 
			
		||||
    ESP_LOGE(TAG, "Failed to grab LVGL lock");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (buf[0] > ST_IDLE) {
 | 
			
		||||
    ESP_LOGW(TAG, "Unknown state %hhu", buf[0]);
 | 
			
		||||
    goto ret;
 | 
			
		||||
  }
 | 
			
		||||
  if (!val_ui_state_ready()) {
 | 
			
		||||
    goto ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  switch (buf[0]) {
 | 
			
		||||
  case ST_NONE:
 | 
			
		||||
    val_ui_none();
 | 
			
		||||
    break;
 | 
			
		||||
  case ST_MENU:
 | 
			
		||||
    if (bufsize < 2) {
 | 
			
		||||
      ESP_LOGE(TAG, "Invalid ST_MENU command");
 | 
			
		||||
      goto ret;
 | 
			
		||||
    }
 | 
			
		||||
    val_ui_menu((bool)buf[1]);
 | 
			
		||||
    break;
 | 
			
		||||
  case ST_IDLE:
 | 
			
		||||
    val_ui_idle();
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
ret:
 | 
			
		||||
  val_lvgl_unlock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void val_usb_init(void) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,4 +5,10 @@
 | 
			
		||||
#define EPNUM_HID 0x01
 | 
			
		||||
#define USB_EP_BUFSIZE 64
 | 
			
		||||
 | 
			
		||||
typedef enum val_state {
 | 
			
		||||
  ST_NONE = 0,
 | 
			
		||||
  ST_MENU,
 | 
			
		||||
  ST_IDLE
 | 
			
		||||
} val_state_t;
 | 
			
		||||
 | 
			
		||||
void val_usb_init(void);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user