mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-23 04:20:47 +00:00
Change requset type parameter back to uint8_t (fix type cast), support USB indicator pulse
This commit is contained in:
parent
6e00886ffb
commit
64bfec79b2
@ -36,12 +36,12 @@
|
||||
|
||||
/* Blink pattern
|
||||
* - 250 ms : device not mounted
|
||||
* - 1000 ms : device mounted
|
||||
* - 0 ms : device mounted
|
||||
* - 2500 ms : device is suspended
|
||||
*/
|
||||
enum {
|
||||
BLINK_NOT_MOUNTED = 250,
|
||||
BLINK_MOUNTED = 1000,
|
||||
BLINK_MOUNTED = 0,
|
||||
BLINK_SUSPENDED = 2500,
|
||||
};
|
||||
|
||||
@ -97,17 +97,46 @@ void tud_resume_cb(void)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BLINKING TASK
|
||||
// BLINKING TASK + Indicator pulse
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
volatile uint8_t doPulse = false;
|
||||
// called from USB context
|
||||
void led_indicator_pulse(void) {
|
||||
doPulse = true;
|
||||
}
|
||||
|
||||
void led_blinking_task(void)
|
||||
{
|
||||
static uint32_t start_ms = 0;
|
||||
static bool led_state = false;
|
||||
if(blink_interval_ms == BLINK_MOUNTED) // Mounted
|
||||
{
|
||||
if(doPulse)
|
||||
{
|
||||
led_state = true;
|
||||
board_led_write(true);
|
||||
start_ms = board_millis();
|
||||
doPulse = false;
|
||||
}
|
||||
else if (led_state == true)
|
||||
{
|
||||
if ( board_millis() - start_ms < 750) //Spec says blink must be between 500 and 1000 ms.
|
||||
{
|
||||
return; // not enough time
|
||||
}
|
||||
led_state = false;
|
||||
board_led_write(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blink every interval ms
|
||||
if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
|
||||
start_ms += blink_interval_ms;
|
||||
|
||||
// Blink every interval ms
|
||||
if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
|
||||
start_ms += blink_interval_ms;
|
||||
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
}
|
||||
}
|
||||
|
5
examples/device/usbtmc/src/main.h
Normal file
5
examples/device/usbtmc/src/main.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
void led_indicator_pulse(void);
|
||||
|
||||
#endif
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <strings.h>
|
||||
#include "class/usbtmc/usbtmc_device.h"
|
||||
#include "main.h"
|
||||
|
||||
#if (USBTMC_CFG_ENABLE_488)
|
||||
usbtmc_response_capabilities_488_t const
|
||||
@ -39,7 +40,7 @@ usbtmcd_app_capabilities =
|
||||
{
|
||||
.listenOnly = 0,
|
||||
.talkOnly = 0,
|
||||
.supportsIndicatorPulse = 0
|
||||
.supportsIndicatorPulse = 1
|
||||
},
|
||||
.bmDevCapabilities = {
|
||||
.canEndBulkInOnTermChar = 0
|
||||
@ -63,7 +64,7 @@ usbtmcd_app_capabilities =
|
||||
#endif
|
||||
};
|
||||
|
||||
static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer";
|
||||
static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer\n";
|
||||
static uint8_t status;
|
||||
static bool queryReceived = false;
|
||||
|
||||
@ -96,7 +97,7 @@ bool usbtmcd_app_msgBulkIn_complete(uint8_t rhport)
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint8_t noQueryMsg[] = "ERR: No query";
|
||||
static uint8_t noQueryMsg[] = "ERR: No query\n";
|
||||
bool usbtmcd_app_msgBulkIn_request(uint8_t rhport, usbtmc_msg_request_dev_dep_in const * request)
|
||||
{
|
||||
usbtmc_msg_dev_dep_msg_in_header_t hdr = {
|
||||
@ -127,7 +128,7 @@ bool usbtmcd_app_msgBulkIn_request(uint8_t rhport, usbtmc_msg_request_dev_dep_in
|
||||
}
|
||||
|
||||
// Return status byte, but put the transfer result status code in the rspResult argument.
|
||||
uint8_t usbtmcd_app_get_stb(uint8_t rhport, usbtmc_status_enum *rspResult)
|
||||
uint8_t usbtmcd_app_get_stb(uint8_t rhport, uint8_t *rspResult)
|
||||
{
|
||||
(void)rhport;
|
||||
*rspResult = USBTMC_STATUS_SUCCESS;
|
||||
@ -137,3 +138,7 @@ uint8_t usbtmcd_app_get_stb(uint8_t rhport, usbtmc_status_enum *rspResult)
|
||||
return status;
|
||||
}
|
||||
|
||||
bool usbtmcd_app_indicator_pluse(uint8_t rhport, tusb_control_request_t const * msg)
|
||||
{
|
||||
led_indicator_pulse();
|
||||
}
|
||||
|
@ -39,17 +39,18 @@
|
||||
|
||||
//Limitations (not planned to be implemented):
|
||||
// "vendor-specific" commands are not handled
|
||||
// Dealing with "termchar" must be handled by the application layer,
|
||||
// though additional error checking is does in this module.
|
||||
|
||||
// TODO:
|
||||
// USBTMC 3.2.2 error conditions not strictly followed
|
||||
// No local lock-out, REN, or GTL.
|
||||
// Cannot issue clear.
|
||||
// No "capabilities" supported
|
||||
// Interrupt-IN endpoint
|
||||
// 488 MsgID=Trigger
|
||||
// Cannot handle clear.
|
||||
// Not all "capabilities" supported
|
||||
// Clear message available status byte at the correct time? (488 4.3.1.3)
|
||||
// Split transfers
|
||||
// No CLEAR_FEATURE/HALT (yet)
|
||||
// No CLEAR_FEATURE/HALT no EP (yet)
|
||||
// No aborting transfers.
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_USBTMC)
|
||||
|
||||
@ -156,8 +157,11 @@ void usbtmcd_init(void)
|
||||
{
|
||||
#if USBTMC_CFG_ENABLE_488
|
||||
if(usbtmcd_app_capabilities.bmIntfcCapabilities488.supportsTrigger)
|
||||
TU_ASSERT(usbtmcd_app_msg_trigger != NULL,);
|
||||
TU_ASSERT(&usbtmcd_app_msg_trigger != NULL,);
|
||||
#endif
|
||||
if(usbtmcd_app_capabilities.bmIntfcCapabilities.supportsIndicatorPulse)
|
||||
TU_ASSERT(&usbtmcd_app_indicator_pluse != NULL,);
|
||||
|
||||
}
|
||||
|
||||
bool usbtmcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
|
||||
@ -400,8 +404,9 @@ bool usbtmcd_control_request(uint8_t rhport, tusb_control_request_t const * requ
|
||||
return true;
|
||||
// USBTMC Optional Requests
|
||||
case USBTMC_bREQUEST_INDICATOR_PULSE: // Optional
|
||||
TU_VERIFY(false);
|
||||
return false;
|
||||
TU_VERIFY(usbtmcd_app_capabilities.bmIntfcCapabilities.supportsIndicatorPulse);
|
||||
TU_VERIFY(usbtmcd_app_indicator_pluse(rhport, request));
|
||||
return true;
|
||||
|
||||
#if (USBTMC_CFG_ENABLE_488)
|
||||
// USB488 required requests
|
||||
|
@ -64,8 +64,10 @@ bool usbtmcd_app_msgBulkIn_request(uint8_t rhport, usbtmc_msg_request_dev_dep_in
|
||||
|
||||
bool usbtmcd_app_msgBulkIn_complete(uint8_t rhport);
|
||||
|
||||
TU_ATTR_WEAK bool usbtmcd_app_indicator_pluse(uint8_t rhport, tusb_control_request_t const * msg);
|
||||
|
||||
#if (USBTMC_CFG_ENABLE_488)
|
||||
uint8_t usbtmcd_app_get_stb(uint8_t rhport, usbtmc_status_enum *rspResult);
|
||||
uint8_t usbtmcd_app_get_stb(uint8_t rhport, uint8_t *rspResult);
|
||||
TU_ATTR_WEAK bool usbtmcd_app_msg_trigger(uint8_t rhport, usbtmc_msg_generic_t* msg);
|
||||
//TU_ATTR_WEAK bool usbtmcd_app_go_to_local(uint8_t rhport);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user