File tree Expand file tree Collapse file tree 14 files changed +68
-18
lines changed Expand file tree Collapse file tree 14 files changed +68
-18
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ func (i2c *I2C) stop() {
97
97
}
98
98
99
99
// writeByte writes a single byte to the I2C bus.
100
- func (i2c * I2C ) writeByte (data byte ) {
100
+ func (i2c * I2C ) writeByte (data byte ) error {
101
101
// Write data to register.
102
102
avr .TWDR .Set (data )
103
103
@@ -107,6 +107,7 @@ func (i2c *I2C) writeByte(data byte) {
107
107
// Wait till data is transmitted.
108
108
for ! avr .TWCR .HasBits (avr .TWCR_TWINT ) {
109
109
}
110
+ return nil
110
111
}
111
112
112
113
// readByte reads a single byte from the I2C bus.
@@ -190,14 +191,16 @@ func (uart *UART) handleInterrupt(intr interrupt.Interrupt) {
190
191
}
191
192
192
193
// WriteByte writes a byte of data to the UART.
193
- func (uart * UART ) WriteByte (c byte ) error {
194
+ func (uart * UART ) writeByte (c byte ) error {
194
195
// Wait until UART buffer is not busy.
195
196
for ! uart .statusRegA .HasBits (avr .UCSR0A_UDRE0 ) {
196
197
}
197
198
uart .dataReg .Set (c ) // send char
198
199
return nil
199
200
}
200
201
202
+ func (uart * UART ) flush () {}
203
+
201
204
// SPIConfig is used to store config info for SPI.
202
205
type SPIConfig struct {
203
206
Frequency uint32
Original file line number Diff line number Diff line change @@ -626,14 +626,16 @@ func (uart *UART) SetBaudRate(br uint32) {
626
626
}
627
627
628
628
// WriteByte writes a byte of data to the UART.
629
- func (uart * UART ) WriteByte (c byte ) error {
629
+ func (uart * UART ) writeByte (c byte ) error {
630
630
// wait until ready to receive
631
631
for ! uart .Bus .INTFLAG .HasBits (sam .SERCOM_USART_INTFLAG_DRE ) {
632
632
}
633
633
uart .Bus .DATA .Set (uint16 (c ))
634
634
return nil
635
635
}
636
636
637
+ func (uart * UART ) flush () {}
638
+
637
639
// handleInterrupt should be called from the appropriate interrupt handler for
638
640
// this UART instance.
639
641
func (uart * UART ) handleInterrupt (interrupt.Interrupt ) {
Original file line number Diff line number Diff line change @@ -1114,14 +1114,16 @@ func (uart *UART) SetBaudRate(br uint32) {
1114
1114
}
1115
1115
1116
1116
// WriteByte writes a byte of data to the UART.
1117
- func (uart * UART ) WriteByte (c byte ) error {
1117
+ func (uart * UART ) writeByte (c byte ) error {
1118
1118
// wait until ready to receive
1119
1119
for ! uart .Bus .INTFLAG .HasBits (sam .SERCOM_USART_INT_INTFLAG_DRE ) {
1120
1120
}
1121
1121
uart .Bus .DATA .Set (uint32 (c ))
1122
1122
return nil
1123
1123
}
1124
1124
1125
+ func (uart * UART ) flush () {}
1126
+
1125
1127
func (uart * UART ) handleInterrupt (interrupt.Interrupt ) {
1126
1128
// should reset IRQ
1127
1129
uart .Receive (byte ((uart .Bus .DATA .Get () & 0xFF )))
Original file line number Diff line number Diff line change @@ -314,7 +314,7 @@ func (uart *UART) Configure(config UARTConfig) {
314
314
uart .Bus .CLKDIV .Set (peripheralClock / config .BaudRate )
315
315
}
316
316
317
- func (uart * UART ) WriteByte (b byte ) error {
317
+ func (uart * UART ) writeByte (b byte ) error {
318
318
for (uart .Bus .STATUS .Get ()>> 16 )& 0xff >= 128 {
319
319
// Read UART_TXFIFO_CNT from the status register, which indicates how
320
320
// many bytes there are in the transmit buffer. Wait until there are
@@ -324,6 +324,8 @@ func (uart *UART) WriteByte(b byte) error {
324
324
return nil
325
325
}
326
326
327
+ func (uart * UART ) flush () {}
328
+
327
329
// Serial Peripheral Interface on the ESP32.
328
330
type SPI struct {
329
331
Bus * esp.SPI_Type
Original file line number Diff line number Diff line change @@ -493,7 +493,7 @@ func (uart *UART) enableReceiver() {
493
493
uart .Bus .SetINT_ENA_RXFIFO_OVF_INT_ENA (1 )
494
494
}
495
495
496
- func (uart * UART ) WriteByte (b byte ) error {
496
+ func (uart * UART ) writeByte (b byte ) error {
497
497
for (uart .Bus .STATUS .Get ()& esp .UART_STATUS_TXFIFO_CNT_Msk )>> esp .UART_STATUS_TXFIFO_CNT_Pos >= 128 {
498
498
// Read UART_TXFIFO_CNT from the status register, which indicates how
499
499
// many bytes there are in the transmit buffer. Wait until there are
@@ -502,3 +502,5 @@ func (uart *UART) WriteByte(b byte) error {
502
502
uart .Bus .FIFO .Set (uint32 (b ))
503
503
return nil
504
504
}
505
+
506
+ func (uart * UART ) flush () {}
Original file line number Diff line number Diff line change @@ -181,12 +181,14 @@ func (uart *UART) Configure(config UARTConfig) {
181
181
esp .UART0 .UART_CLKDIV .Set (CPUFrequency () / config .BaudRate )
182
182
}
183
183
184
- // WriteByte writes a single byte to the output buffer. Note that the hardware
184
+ // writeByte writes a single byte to the output buffer. Note that the hardware
185
185
// includes a buffer of 128 bytes which will be used first.
186
- func (uart * UART ) WriteByte (c byte ) error {
186
+ func (uart * UART ) writeByte (c byte ) error {
187
187
for (esp .UART0 .UART_STATUS .Get ()>> 16 )& 0xff >= 128 {
188
188
// Wait until the TX buffer has room.
189
189
}
190
190
esp .UART0 .UART_FIFO .Set (uint32 (c ))
191
191
return nil
192
192
}
193
+
194
+ func (uart * UART ) flush () {}
Original file line number Diff line number Diff line change @@ -111,13 +111,16 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
111
111
uart .Receive (c )
112
112
}
113
113
114
- func (uart * UART ) WriteByte (c byte ) {
114
+ func (uart * UART ) writeByte (c byte ) error {
115
115
for sifive .UART0 .TXDATA .Get ()& sifive .UART_TXDATA_FULL != 0 {
116
116
}
117
117
118
118
sifive .UART0 .TXDATA .Set (uint32 (c ))
119
+ return nil
119
120
}
120
121
122
+ func (uart * UART ) flush () {}
123
+
121
124
// SPI on the FE310. The normal SPI0 is actually a quad-SPI meant for flash, so it is best
122
125
// to use SPI1 or SPI2 port for most applications.
123
126
type SPI struct {
Original file line number Diff line number Diff line change @@ -392,13 +392,16 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
392
392
uart .Receive (c )
393
393
}
394
394
395
- func (uart * UART ) WriteByte (c byte ) {
395
+ func (uart * UART ) writeByte (c byte ) error {
396
396
for uart .Bus .TXDATA .Get ()& kendryte .UARTHS_TXDATA_FULL != 0 {
397
397
}
398
398
399
399
uart .Bus .TXDATA .Set (uint32 (c ))
400
+ return nil
400
401
}
401
402
403
+ func (uart * UART ) flush () {}
404
+
402
405
type SPI struct {
403
406
Bus * kendryte.SPI_Type
404
407
}
Original file line number Diff line number Diff line change @@ -173,14 +173,16 @@ func (uart *UART) Sync() error {
173
173
}
174
174
175
175
// WriteByte writes a single byte of data to the UART interface.
176
- func (uart * UART ) WriteByte (c byte ) error {
176
+ func (uart * UART ) writeByte (c byte ) error {
177
177
uart .startTransmitting ()
178
178
for ! uart .txBuffer .Put (c ) {
179
179
}
180
180
uart .Bus .CTRL .SetBits (nxp .LPUART_CTRL_TIE )
181
181
return nil
182
182
}
183
183
184
+ func (uart * UART ) flush () {}
185
+
184
186
// getBaudRateDivisor finds the greatest over-sampling factor (4..32) and
185
187
// corresponding baud rate divisor (1..8191) that best partition a given baud
186
188
// rate into equal intervals.
Original file line number Diff line number Diff line change @@ -186,14 +186,16 @@ func (uart *UART) SetBaudRate(br uint32) {
186
186
}
187
187
188
188
// WriteByte writes a byte of data to the UART.
189
- func (uart * UART ) WriteByte (c byte ) error {
189
+ func (uart * UART ) writeByte (c byte ) error {
190
190
nrf .UART0 .EVENTS_TXDRDY .Set (0 )
191
191
nrf .UART0 .TXD .Set (uint32 (c ))
192
192
for nrf .UART0 .EVENTS_TXDRDY .Get () == 0 {
193
193
}
194
194
return nil
195
195
}
196
196
197
+ func (uart * UART ) flush () {}
198
+
197
199
func (uart * UART ) handleInterrupt (interrupt.Interrupt ) {
198
200
if nrf .UART0 .EVENTS_RXDRDY .Get () != 0 {
199
201
uart .Receive (byte (nrf .UART0 .RXD .Get ()))
You can’t perform that action at this time.
0 commit comments