Skip to content

Commit 31189de

Browse files
deadprogramaykevl
authored andcommitted
machine/avr: use HasBits() method to simplify bit comparisons
Signed-off-by: Ron Evans <[email protected]>
1 parent 90cd3f8 commit 31189de

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/machine/machine_atmega.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (i2c I2C) start(address uint8, write bool) {
165165
avr.TWCR.Set((avr.TWCR_TWINT | avr.TWCR_TWSTA | avr.TWCR_TWEN))
166166

167167
// Wait till start condition is transmitted.
168-
for (avr.TWCR.Get() & avr.TWCR_TWINT) == 0 {
168+
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
169169
}
170170

171171
// Write 7-bit shifted peripheral address.
@@ -182,7 +182,7 @@ func (i2c I2C) stop() {
182182
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT | avr.TWCR_TWSTO)
183183

184184
// Wait for stop condition to be executed on bus.
185-
for (avr.TWCR.Get() & avr.TWCR_TWSTO) == 0 {
185+
for !avr.TWCR.HasBits(avr.TWCR_TWSTO) {
186186
}
187187
}
188188

@@ -195,7 +195,7 @@ func (i2c I2C) writeByte(data byte) {
195195
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT)
196196

197197
// Wait till data is transmitted.
198-
for (avr.TWCR.Get() & avr.TWCR_TWINT) == 0 {
198+
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
199199
}
200200
}
201201

@@ -205,7 +205,7 @@ func (i2c I2C) readByte() byte {
205205
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT | avr.TWCR_TWEA)
206206

207207
// Wait till read request is transmitted.
208-
for (avr.TWCR.Get() & avr.TWCR_TWINT) == 0 {
208+
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
209209
}
210210

211211
return byte(avr.TWDR.Get())
@@ -239,7 +239,7 @@ func (uart UART) Configure(config UARTConfig) {
239239
// WriteByte writes a byte of data to the UART.
240240
func (uart UART) WriteByte(c byte) error {
241241
// Wait until UART buffer is not busy.
242-
for (avr.UCSR0A.Get() & avr.UCSR0A_UDRE0) == 0 {
242+
for !avr.UCSR0A.HasBits(avr.UCSR0A_UDRE0) {
243243
}
244244
avr.UDR0.Set(c) // send char
245245
return nil
@@ -251,7 +251,7 @@ func handleUSART_RX() {
251251
data := avr.UDR0.Get()
252252

253253
// Ensure no error.
254-
if (avr.UCSR0A.Get() & (avr.UCSR0A_FE0 | avr.UCSR0A_DOR0 | avr.UCSR0A_UPE0)) == 0 {
254+
if !avr.UCSR0A.HasBits(avr.UCSR0A_FE0 | avr.UCSR0A_DOR0 | avr.UCSR0A_UPE0) {
255255
// Put data from UDR register into buffer.
256256
UART0.Receive(byte(data))
257257
}

src/machine/machine_avr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (a ADC) Get() uint16 {
7474
avr.ADCSRA.SetBits(avr.ADCSRA_ADSC)
7575

7676
// ADSC is cleared when the conversion finishes
77-
for ok := true; ok; ok = (avr.ADCSRA.Get() & avr.ADCSRA_ADSC) > 0 {
77+
for ok := true; ok; ok = avr.ADCSRA.HasBits(avr.ADCSRA_ADSC) {
7878
}
7979

8080
return uint16(avr.ADCL.Get()) | uint16(avr.ADCH.Get())<<8

0 commit comments

Comments
 (0)