diff options
| author | Nathan Conrad <[email protected]> | 2019-09-14 18:07:12 -0400 |
|---|---|---|
| committer | Nathan Conrad <[email protected]> | 2019-09-14 18:11:07 -0400 |
| commit | 64bfec79b2d1d75b5c06be2dc2fff83ee385a720 (patch) | |
| tree | d9cf0c0ded83ee06bca0cd8c73e10f754c065ff9 /examples/device | |
| parent | 6e00886ffbbc552cf91be73d57fe8ad0a4842d0b (diff) | |
Change requset type parameter back to uint8_t (fix type cast), support USB indicator pulse
Diffstat (limited to 'examples/device')
| -rw-r--r-- | examples/device/usbtmc/src/main.c | 47 | ||||
| -rw-r--r-- | examples/device/usbtmc/src/main.h | 5 | ||||
| -rw-r--r-- | examples/device/usbtmc/src/usbtmc_app.c | 13 |
3 files changed, 52 insertions, 13 deletions
diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c index 0293261ad..8bc2a8398 100644 --- a/examples/device/usbtmc/src/main.c +++ b/examples/device/usbtmc/src/main.c @@ -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 + } } diff --git a/examples/device/usbtmc/src/main.h b/examples/device/usbtmc/src/main.h new file mode 100644 index 000000000..673247ec7 --- /dev/null +++ b/examples/device/usbtmc/src/main.h @@ -0,0 +1,5 @@ +#ifndef MAIN_H +#define MAIN_H +void led_indicator_pulse(void); + +#endif diff --git a/examples/device/usbtmc/src/usbtmc_app.c b/examples/device/usbtmc/src/usbtmc_app.c index 4ec6ad90c..6b72bb360 100644 --- a/examples/device/usbtmc/src/usbtmc_app.c +++ b/examples/device/usbtmc/src/usbtmc_app.c @@ -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(); +} |
