mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-22 19:20:52 +00:00
rename tuh_device_is_configured() to tuh_device_configured()
- remove tuh_device_get_state() - more hid mouse clean up
This commit is contained in:
parent
69defb5edc
commit
b7a8b278c8
@ -1,59 +0,0 @@
|
||||
#ifndef KEYBOARD_HELPER_H
|
||||
#define KEYBAORD_HELPER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
// look up new key in previous keys
|
||||
inline bool find_key_in_report(hid_keyboard_report_t const *p_report, uint8_t keycode)
|
||||
{
|
||||
for(uint8_t i = 0; i < 6; i++)
|
||||
{
|
||||
if (p_report->keycode[i] == keycode) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode)
|
||||
{
|
||||
return keycode > 128 ? 0 :
|
||||
hid_keycode_to_ascii_tbl [keycode][modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT) ? 1 : 0];
|
||||
}
|
||||
|
||||
void print_kbd_report(hid_keyboard_report_t *prev_report, hid_keyboard_report_t const *new_report)
|
||||
{
|
||||
|
||||
printf("Report: ");
|
||||
uint8_t c;
|
||||
|
||||
// I assume it's possible to have up to 6 keypress events per report?
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
{
|
||||
// Check for key presses
|
||||
if (new_report->keycode[i])
|
||||
{
|
||||
// If not in prev report then it is newly pressed
|
||||
if ( !find_key_in_report(prev_report, new_report->keycode[i]) )
|
||||
c = keycode_to_ascii(new_report->modifier, new_report->keycode[i]);
|
||||
printf("press %c ", c);
|
||||
}
|
||||
|
||||
// Check for key depresses (i.e. was present in prev report but not here)
|
||||
if (prev_report->keycode[i])
|
||||
{
|
||||
// If not present in the current report then depressed
|
||||
if (!find_key_in_report(new_report, prev_report->keycode[i]))
|
||||
{
|
||||
c = keycode_to_ascii(prev_report->modifier, prev_report->keycode[i]);
|
||||
printf("depress %c ", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
@ -156,16 +156,18 @@ static inline void process_kbd_report(hid_keyboard_report_t const *p_new_report)
|
||||
|
||||
void tuh_hid_mounted_cb(uint8_t dev_addr, uint8_t instance)
|
||||
{
|
||||
// application set-up
|
||||
printf("A Keyboard device (address %d) is mounted\r\n", dev_addr);
|
||||
printf("HID device address = %d, instance = %d is mounted\r\n", dev_addr, instance);
|
||||
// printf("A Keyboard device (address %d) is mounted\r\n", dev_addr);
|
||||
|
||||
if (instance == 0) {
|
||||
tuh_hid_keyboard_get_report(dev_addr, &usb_keyboard_report);
|
||||
}
|
||||
}
|
||||
|
||||
void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance)
|
||||
{
|
||||
// application tear-down
|
||||
printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr);
|
||||
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
|
||||
// printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -255,7 +257,7 @@ void hid_task(void)
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if ( tuh_hid_mouse_mounted(addr) )
|
||||
if ( tuh_n_hid_n_mouse_mounted(addr, 0) )
|
||||
{
|
||||
if ( !tuh_hid_mouse_is_busy(addr) )
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int
|
||||
{
|
||||
//------------- parameters validation -------------//
|
||||
// TODO change to use is configured function
|
||||
TU_ASSERT(TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
TU_ASSERT(tuh_device_configured(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
TU_VERIFY(report, TUSB_ERROR_INVALID_PARA);
|
||||
TU_VERIFY(!hcd_edpt_busy(dev_addr, p_hid->ep_in), TUSB_ERROR_INTERFACE_IS_BUSY);
|
||||
|
||||
@ -113,32 +113,45 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
//bool tuh_n_hid_n_mounted(uint8_t daddr, uint8_t instance)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
bool tuh_n_hid_n_keyboard_mounted(uint8_t dev_addr, uint8_t instance)
|
||||
bool tuh_n_hid_n_mounted(uint8_t daddr, uint8_t instance)
|
||||
{
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||
hidh_interface_t* hid_itf = get_instance(daddr, instance);
|
||||
|
||||
// TODO check rid_keyboard
|
||||
return tuh_device_is_configured(dev_addr) && (hid_itf->ep_in != 0);
|
||||
return tuh_device_configured(daddr) && (hid_itf->ep_in != 0);
|
||||
}
|
||||
|
||||
bool tuh_n_hid_n_keyboard_mounted(uint8_t daddr, uint8_t instance)
|
||||
{
|
||||
hidh_interface_t* hid_itf = get_instance(daddr, instance);
|
||||
|
||||
// TODO check rid_keyboard
|
||||
return tuh_device_configured(daddr) && (hid_itf->ep_in != 0);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* buffer)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, itf);
|
||||
uint8_t inst = 0;
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, inst);
|
||||
|
||||
return hidh_interface_get_report(dev_addr, buffer, hid_itf);
|
||||
}
|
||||
|
||||
bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
uint8_t instance = 0;
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||
uint8_t inst = 0;
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, inst);
|
||||
|
||||
return tuh_n_hid_n_keyboard_mounted(dev_addr, instance) && hcd_edpt_busy(dev_addr, hid_itf->ep_in);
|
||||
return tuh_n_hid_n_keyboard_mounted(dev_addr, inst) && hcd_edpt_busy(dev_addr, hid_itf->ep_in);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -149,14 +162,15 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
static hidh_interface_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- Public API -------------//
|
||||
bool tuh_hid_mouse_mounted(uint8_t dev_addr)
|
||||
bool tuh_n_hid_n_mouse_mounted(uint8_t dev_addr, uint8_t instance)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && (mouseh_data[dev_addr-1].ep_in != 0);
|
||||
// hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||
return tuh_device_configured(dev_addr) && (mouseh_data[dev_addr-1].ep_in != 0);
|
||||
}
|
||||
|
||||
bool tuh_hid_mouse_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_mouse_mounted(dev_addr) && hcd_edpt_busy(dev_addr, mouseh_data[dev_addr-1].ep_in);
|
||||
return tuh_n_hid_n_mouse_mounted(dev_addr, 0) && hcd_edpt_busy(dev_addr, mouseh_data[dev_addr-1].ep_in);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report)
|
||||
|
@ -60,10 +60,14 @@
|
||||
// Get the number of HID instances
|
||||
uint8_t tuh_n_hid_instance_count(uint8_t daddr);
|
||||
|
||||
// Check if HID instance has keyboard
|
||||
// Check if HID instance is mounted
|
||||
//bool tuh_n_hid_n_mounted(uint8_t daddr, uint8_t instance);
|
||||
|
||||
// Check if HID instance with Keyboard is mounted
|
||||
bool tuh_n_hid_n_keyboard_mounted(uint8_t daddr, uint8_t instance);
|
||||
|
||||
|
||||
// Check if HID instance with Mouse is mounted
|
||||
bool tuh_n_hid_n_mouse_mounted(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Single device)
|
||||
@ -101,10 +105,6 @@ TU_ATTR_WEAK void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance);
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
|
||||
// TODO used weak attr if build failed without KEYBOARD enabled
|
||||
// TODO remove
|
||||
extern uint8_t const hid_keycode_to_ascii_tbl[2][128];
|
||||
|
||||
/** \brief Check if device supports Keyboard interface or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if device supports Keyboard interface
|
||||
@ -170,13 +170,6 @@ void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr);
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
|
||||
/** \brief Check if device supports Mouse interface or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if device supports Mouse interface
|
||||
* \retval false if device does not support Mouse interface or is not mounted
|
||||
*/
|
||||
bool tuh_hid_mouse_mounted(uint8_t dev_addr);
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to device
|
||||
|
@ -152,10 +152,9 @@ uint8_t* usbh_get_enum_buf(void)
|
||||
//--------------------------------------------------------------------+
|
||||
// PUBLIC API (Parameter Verification is required)
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_device_state_t tuh_device_get_state (uint8_t const dev_addr)
|
||||
bool tuh_device_configured(uint8_t dev_addr)
|
||||
{
|
||||
TU_ASSERT( dev_addr <= CFG_TUSB_HOST_DEVICE_MAX, TUSB_DEVICE_STATE_UNPLUG);
|
||||
return (tusb_device_state_t) _usbh_devices[dev_addr].state;
|
||||
return _usbh_devices[dev_addr].configured;
|
||||
}
|
||||
|
||||
tusb_speed_t tuh_device_get_speed (uint8_t const dev_addr)
|
||||
|
@ -88,13 +88,9 @@ void tuh_task(void);
|
||||
extern void hcd_int_handler(uint8_t rhport);
|
||||
#define tuh_int_handler hcd_int_handler
|
||||
|
||||
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr);
|
||||
tusb_speed_t tuh_device_get_speed (uint8_t dev_addr);
|
||||
static inline bool tuh_device_is_configured(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_get_state(dev_addr) == TUSB_DEVICE_STATE_CONFIGURED;
|
||||
}
|
||||
|
||||
bool tuh_device_configured(uint8_t dev_addr);
|
||||
bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
Loading…
x
Reference in New Issue
Block a user