Skip to content

File webusb_controller.c

FileList > neuralSPOT > neuralspot > ns-usb > src > overrides > webusb_controller.c

Go to the source code of this file

web usb controller. More...

  • #include <stdlib.h>
  • #include <stdio.h>
  • #include <string.h>
  • #include "webusb_controller.h"
  • #include "usb_descriptors.h"
  • #include "ns_usb.h"
  • #include "tusb.h"
  • #include "am_util_debug.h"
  • #include "ns_ambiqsuite_harness.h"

Classes

Type Name
struct webusb_parameter_t

Public Types

Type Name
enum @3

Public Static Attributes

Type Name
uint8_t rx_buf
bool webusb_connected = = false
webusb_parameter_t webusb_parameter = = {
.rx_msg_cb = NULL,
.rx_raw_cb = NULL,
.rx_msg_param = NULL,
.rx_raw_param = NULL,
}

Public Functions

Type Name
void tud_mount_cb (void)
void tud_resume_cb (void)
void tud_suspend_cb (bool remote_wakeup_en)
void tud_umount_cb (void)
bool tud_vendor_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
void tud_vendor_rx_cb (uint8_t itf)
void webusb_register_msg_cb (webusb_rx_cb cb, void * param)
Register message callback function and pass to callback pointer.
void webusb_register_raw_cb (webusb_rx_cb cb, void * param)
Register raw callback function and pass to callback pointer.
uint32_t webusb_send_data (uint8_t * buf, uint32_t bufsize)
Blocking USB Send Data.

Macros

Type Name
define BSTREAM_TO_UINT16 (n, p)
define BYTES_TO_UINT16 (n, p) { n = (((uint16_t)(p)[0] << 8) + (uint16_t)(p)[1]); }
define DESC_MS_OS_20 7
define REWRIT_NUMBER 40
define WEBUSB_REQUEST_SET_CONTROL_LINE_STATE 0x22

Detailed Description

This example demonstrates how to use the USB CDC-ACM device class. it will echo back the the input from the terminal tool.

Public Types Documentation

enum @3

enum @3 {
    RX_INVALID = 0,
    RX_ACORE_MSG = 1,
    RX_RAW_DATA = 2
};

Public Static Attributes Documentation

variable rx_buf

uint8_t rx_buf[512];

variable webusb_connected

bool webusb_connected;

variable webusb_parameter

webusb_parameter_t webusb_parameter;

Public Functions Documentation

function tud_mount_cb

void tud_mount_cb (
    void
) 

The functions in the array below are prototyped as TU_ATTR_WEAK in Tinyusb. The linkers were not always including these functions in the executable. Using this array forces the linker to keep the function.

In summary,the Tinyusb functions prototyped as weak (macro TU_ATTR_WEAK) and implemented in the user code should be added to the array below.

function tud_resume_cb

void tud_resume_cb (
    void
) 

function tud_suspend_cb

void tud_suspend_cb (
    bool remote_wakeup_en
) 

function tud_umount_cb

void tud_umount_cb (
    void
) 

function tud_vendor_control_xfer_cb

bool tud_vendor_control_xfer_cb (
    uint8_t rhport,
    uint8_t stage,
    tusb_control_request_t const * request
) 

function tud_vendor_rx_cb

void tud_vendor_rx_cb (
    uint8_t itf
) 

function webusb_register_msg_cb

Register message callback function and pass to callback pointer.

void webusb_register_msg_cb (
    webusb_rx_cb cb,
    void * param
) 

Parameters:

  • cd Callback function
  • param Pointer to user parameter which will be passed to callback

function webusb_register_raw_cb

Register raw callback function and pass to callback pointer.

void webusb_register_raw_cb (
    webusb_rx_cb cb,
    void * param
) 

Parameters:

  • cd Callback function
  • param Pointer to user parameter which will be passed to callback

function webusb_send_data

Blocking USB Send Data.

uint32_t webusb_send_data (
    uint8_t * buf,
    uint32_t bufsize
) 

Parameters:

  • buf Pointer to buffer with data to be sent
  • bufsize Requested number of bytes

Returns:

uint32_t The amount of data written to the ring-buffer.

Macro Definition Documentation

define BSTREAM_TO_UINT16

#define BSTREAM_TO_UINT16 (
    n,
    p
) {                                                                                              \
        BYTES_TO_UINT16(n, p);                                                                     \
        p += 2;                                                                                    \
    }

define BYTES_TO_UINT16

#define BYTES_TO_UINT16 (
    n,
    p
) { n = (((uint16_t)(p)[0] << 8) + (uint16_t)(p)[1]); }

define DESC_MS_OS_20

#define DESC_MS_OS_20 7

define REWRIT_NUMBER

#define REWRIT_NUMBER 40

define WEBUSB_REQUEST_SET_CONTROL_LINE_STATE

#define WEBUSB_REQUEST_SET_CONTROL_LINE_STATE 0x22

The documentation for this class was generated from the following file neuralSPOT/neuralspot/ns-usb/src/overrides/webusb_controller.c