diff options
author | Ayke van Laethem <[email protected]> | 2021-05-11 13:39:14 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-05-13 16:43:37 +0200 |
commit | 7c949ad386ef36eb0be100eb54a4190740f6f24d (patch) | |
tree | cb2c910468b67f96ee81583fded96d242abd3bd7 /src/machine/machine_atsamd21.go | |
parent | 164632616496e21f5f11098316c650ab5ad9356c (diff) | |
download | tinygo-7c949ad386ef36eb0be100eb54a4190740f6f24d.tar.gz tinygo-7c949ad386ef36eb0be100eb54a4190740f6f24d.zip |
machine: make USBCDC global a pointer
Make the USBCDC use a pointer receiver everywhere. This makes it easier
to pass around the object in the future.
This commit sometimes changes code size, but not significantly (a few
bytes) and usually in a positive way.
My eventual goal is the following:
- Declare `machine.USB` (or similar, name TBD) as a pointer receiver
for the USB-CDC interface.
- Let `machine.UART0` always point to an UART, never actually to a
USBCDC object.
- Define `machine.Serial`, which is either a real UART or an USB-CDC,
depending on the board.
This way, if you want a real UART you can use machine.UARTx and if you
just want to print to the default serial port, you can use
machine.Serial.
This change does have an effect on code size and memory consumption.
There is often a small reduction (-8 bytes) in RAM consumption and an
increase in flash consumption.
Diffstat (limited to 'src/machine/machine_atsamd21.go')
-rw-r--r-- | src/machine/machine_atsamd21.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index 4bacd2aab..058099cde 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -506,7 +506,7 @@ type UART struct { var ( // UART0 is actually a USB CDC interface. - UART0 = USBCDC{Buffer: NewRingBuffer()} + UART0 = &USBCDC{Buffer: NewRingBuffer()} ) const ( @@ -1788,7 +1788,7 @@ func (usbcdc *USBCDC) Flush() error { // send data by setting bank ready setEPSTATUSSET(usb_CDC_ENDPOINT_IN, sam.USB_DEVICE_EPSTATUSSET_BK1RDY) - UART0.sent = true + usbcdc.sent = true } } return nil @@ -1802,10 +1802,10 @@ func (usbcdc *USBCDC) WriteByte(c byte) error { for { mask := interrupt.Disable() - idx := UART0.TxIdx.Get() + idx := usbcdc.TxIdx.Get() if (idx & usbcdcTxSizeMask) < usbcdcTxSizeMask { udd_ep_in_cache_buffer[usb_CDC_ENDPOINT_IN][idx] = c - UART0.TxIdx.Set(idx + 1) + usbcdc.TxIdx.Set(idx + 1) ok = true } @@ -1813,26 +1813,26 @@ func (usbcdc *USBCDC) WriteByte(c byte) error { if ok { break - } else if usbcdcTxMaxRetriesAllowed < UART0.waitTxcRetryCount { + } else if usbcdcTxMaxRetriesAllowed < usbcdc.waitTxcRetryCount { mask := interrupt.Disable() - UART0.waitTxc = false - UART0.waitTxcRetryCount = 0 - UART0.TxIdx.Set(0) + usbcdc.waitTxc = false + usbcdc.waitTxcRetryCount = 0 + usbcdc.TxIdx.Set(0) usbLineInfo.lineState = 0 interrupt.Restore(mask) break } else { mask := interrupt.Disable() - if UART0.sent { - if UART0.waitTxc { + if usbcdc.sent { + if usbcdc.waitTxc { if (getEPINTFLAG(usb_CDC_ENDPOINT_IN) & sam.USB_DEVICE_EPINTFLAG_TRCPT1) != 0 { setEPSTATUSCLR(usb_CDC_ENDPOINT_IN, sam.USB_DEVICE_EPSTATUSCLR_BK1RDY) setEPINTFLAG(usb_CDC_ENDPOINT_IN, sam.USB_DEVICE_EPINTFLAG_TRCPT1) - UART0.waitTxc = false - UART0.Flush() + usbcdc.waitTxc = false + usbcdc.Flush() } } else { - UART0.Flush() + usbcdc.Flush() } } interrupt.Restore(mask) @@ -1843,11 +1843,11 @@ func (usbcdc *USBCDC) WriteByte(c byte) error { return nil } -func (usbcdc USBCDC) DTR() bool { +func (usbcdc *USBCDC) DTR() bool { return (usbLineInfo.lineState & usb_CDC_LINESTATE_DTR) > 0 } -func (usbcdc USBCDC) RTS() bool { +func (usbcdc *USBCDC) RTS() bool { return (usbLineInfo.lineState & usb_CDC_LINESTATE_RTS) > 0 } @@ -1882,7 +1882,7 @@ var ( ) // Configure the USB CDC interface. The config is here for compatibility with the UART interface. -func (usbcdc USBCDC) Configure(config UARTConfig) { +func (usbcdc *USBCDC) Configure(config UARTConfig) { // reset USB interface sam.USB_DEVICE.CTRLA.SetBits(sam.USB_DEVICE_CTRLA_SWRST) for sam.USB_DEVICE.SYNCBUSY.HasBits(sam.USB_DEVICE_SYNCBUSY_SWRST) || |