machine/avr: use HasBits() method to simplify bit comparisons
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
90cd3f8ea5
коммит
31189deb3b
2 изменённых файлов: 7 добавлений и 7 удалений
|
@ -165,7 +165,7 @@ func (i2c I2C) start(address uint8, write bool) {
|
||||||
avr.TWCR.Set((avr.TWCR_TWINT | avr.TWCR_TWSTA | avr.TWCR_TWEN))
|
avr.TWCR.Set((avr.TWCR_TWINT | avr.TWCR_TWSTA | avr.TWCR_TWEN))
|
||||||
|
|
||||||
// Wait till start condition is transmitted.
|
// Wait till start condition is transmitted.
|
||||||
for (avr.TWCR.Get() & avr.TWCR_TWINT) == 0 {
|
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write 7-bit shifted peripheral address.
|
// Write 7-bit shifted peripheral address.
|
||||||
|
@ -182,7 +182,7 @@ func (i2c I2C) stop() {
|
||||||
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT | avr.TWCR_TWSTO)
|
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT | avr.TWCR_TWSTO)
|
||||||
|
|
||||||
// Wait for stop condition to be executed on bus.
|
// Wait for stop condition to be executed on bus.
|
||||||
for (avr.TWCR.Get() & avr.TWCR_TWSTO) == 0 {
|
for !avr.TWCR.HasBits(avr.TWCR_TWSTO) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ func (i2c I2C) writeByte(data byte) {
|
||||||
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT)
|
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT)
|
||||||
|
|
||||||
// Wait till data is transmitted.
|
// Wait till data is transmitted.
|
||||||
for (avr.TWCR.Get() & avr.TWCR_TWINT) == 0 {
|
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ func (i2c I2C) readByte() byte {
|
||||||
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT | avr.TWCR_TWEA)
|
avr.TWCR.Set(avr.TWCR_TWEN | avr.TWCR_TWINT | avr.TWCR_TWEA)
|
||||||
|
|
||||||
// Wait till read request is transmitted.
|
// Wait till read request is transmitted.
|
||||||
for (avr.TWCR.Get() & avr.TWCR_TWINT) == 0 {
|
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return byte(avr.TWDR.Get())
|
return byte(avr.TWDR.Get())
|
||||||
|
@ -239,7 +239,7 @@ func (uart UART) Configure(config UARTConfig) {
|
||||||
// WriteByte writes a byte of data to the UART.
|
// WriteByte writes a byte of data to the UART.
|
||||||
func (uart UART) WriteByte(c byte) error {
|
func (uart UART) WriteByte(c byte) error {
|
||||||
// Wait until UART buffer is not busy.
|
// Wait until UART buffer is not busy.
|
||||||
for (avr.UCSR0A.Get() & avr.UCSR0A_UDRE0) == 0 {
|
for !avr.UCSR0A.HasBits(avr.UCSR0A_UDRE0) {
|
||||||
}
|
}
|
||||||
avr.UDR0.Set(c) // send char
|
avr.UDR0.Set(c) // send char
|
||||||
return nil
|
return nil
|
||||||
|
@ -251,7 +251,7 @@ func handleUSART_RX() {
|
||||||
data := avr.UDR0.Get()
|
data := avr.UDR0.Get()
|
||||||
|
|
||||||
// Ensure no error.
|
// Ensure no error.
|
||||||
if (avr.UCSR0A.Get() & (avr.UCSR0A_FE0 | avr.UCSR0A_DOR0 | avr.UCSR0A_UPE0)) == 0 {
|
if !avr.UCSR0A.HasBits(avr.UCSR0A_FE0 | avr.UCSR0A_DOR0 | avr.UCSR0A_UPE0) {
|
||||||
// Put data from UDR register into buffer.
|
// Put data from UDR register into buffer.
|
||||||
UART0.Receive(byte(data))
|
UART0.Receive(byte(data))
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (a ADC) Get() uint16 {
|
||||||
avr.ADCSRA.SetBits(avr.ADCSRA_ADSC)
|
avr.ADCSRA.SetBits(avr.ADCSRA_ADSC)
|
||||||
|
|
||||||
// ADSC is cleared when the conversion finishes
|
// ADSC is cleared when the conversion finishes
|
||||||
for ok := true; ok; ok = (avr.ADCSRA.Get() & avr.ADCSRA_ADSC) > 0 {
|
for ok := true; ok; ok = avr.ADCSRA.HasBits(avr.ADCSRA_ADSC) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return uint16(avr.ADCL.Get()) | uint16(avr.ADCH.Get())<<8
|
return uint16(avr.ADCL.Get()) | uint16(avr.ADCH.Get())<<8
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче