// initCore initializes a free USB core with given operating mode on the USB
// port at given index, if available. Returns a reference to the initialized
// core or nil if the core is unavailable.
initCore initializes a free USB core with given operating mode on the USB
port at given index, if available. Returns a reference to the initialized
core or nil if the core is unavailable.
// initCore initializes a free USB core with given operating mode on the USB // port at given index if available . Returns a reference to the initialized // core or nil if the core is unavailable .
func initCore(port int, class class) (*core, status) {
	iv := disableInterrupts()
	defer enableInterrupts(iv)
	if port < 0 || port >= CoreCount || 0 == class.config {
		return nil, statusInvalid
	}
	if modeIdle != coreInstance[port].mode {
		 This will allow, for instance, TinyGo examples that try to reconfigure
		 the USB (CDC-ACM) UART port (which is already configured by the runtime)
		 to continue without error.
		if coreInstance[port].mode == class.mode() {
			switch class.mode() {
			case modeDevice:
				if coreInstance[port].dc.class().equals(class) {
					return &coreInstance[port], statusOK
				}
			case modeHost:
				if coreInstance[port].hc.class().equals(class) {
					return &coreInstance[port], statusOK
				}
			}
		}
		return nil, statusBusy
	}
	switch class.mode() {
	case modeDevice:
		 Allocate a free device controller and install interrupts
		dc, st := initDCD(port, class)
		if !st.ok() {
			return nil, st
		}
		 Initialize buffers and device descriptors
		if st = dc.init(); !st.ok() {
			return nil, st
		}
		coreInstance[port].port = port
		coreInstance[port].mode = modeDevice
		coreInstance[port].dc = dc
		dc.enable(true)  Enable interrupts and enter runtime
	case modeHost:
		 Allocate a free host controller and install interrupts
		hc, st := initHCD(port, class)
		if !st.ok() {
			return nil, st
		}
		 Initialize buffers and device descriptors
		if st = hc.init(); !st.ok() {
			return nil, st
		}
		coreInstance[port].port = port
		coreInstance[port].mode = modeHost
		coreInstance[port].hc = hc
		hc.enable(true)  Enable interrupts and enter runtime
	default:
		return nil, statusInvalid
	}
	return &coreInstance[port], statusOK
}
func initCore ( port int , class class ) ( * core , status ) { iv := disableInterrupts ( ) defer enableInterrupts ( iv ) if port < 0 || port >= CoreCount || 0 == class . config { return nil , statusInvalid } if modeIdle != coreInstance [ port ] . mode { if coreInstance [ port ] . mode == class . mode ( ) { switch class . mode ( ) { case modeDevice : if coreInstance [ port ] . dc . class ( ) . equals ( class ) { return & coreInstance [ port ] , statusOK } case modeHost : if coreInstance [ port ] . hc . class ( ) . equals ( class ) { return & coreInstance [ port ] , statusOK } } } return nil , statusBusy } switch class . mode ( ) { case modeDevice : dc , st := initDCD ( port , class ) if ! st . ok ( ) { return nil , st } if st = dc . init ( ) ; ! st . ok ( ) { return nil , st } coreInstance [ port ] . port = port coreInstance [ port ] . mode = modeDevice coreInstance [ port ] . dc = dc dc . enable ( true ) case modeHost : hc , st := initHCD ( port , class ) if ! st . ok ( ) { return nil , st } if st = hc . init ( ) ; ! st . ok ( ) { return nil , st } coreInstance [ port ] . port = port coreInstance [ port ] . mode = modeHost coreInstance [ port ] . hc = hc hc . enable ( true ) default : return nil , statusInvalid } return & coreInstance [ port ] , statusOK }
initCore initializes a free USB core with given operating mode on the USB
port at given index, if available.
initCore initializes a free USB core with given operating mode on the USB port at given index if available .
// Check if requested port is already configured as requested class. If so, // just return a reference to the existing core instead of an error. // // This will allow, for instance, TinyGo examples that try to reconfigure // the USB (CDC-ACM) UART port (which is already configured by the runtime) // to continue without error. // Allocate a free device controller and install interrupts // Initialize buffers and device descriptors // Enable interrupts and enter runtime // Allocate a free host controller and install interrupts // Initialize buffers and device descriptors // Enable interrupts and enter runtime