@@ -157,7 +157,7 @@ func (uart UART) SetBaudRate(br uint32) {
157
157
func (uart UART ) WriteByte (c byte ) error {
158
158
stm32 .USART1 .DR .Set (uint32 (c ))
159
159
160
- for ( stm32 .USART1 .SR .Get () & stm32 .USART_SR_TXE ) == 0 {
160
+ for ! stm32 .USART1 .SR .HasBits ( stm32 .USART_SR_TXE ) {
161
161
}
162
162
return nil
163
163
}
@@ -265,15 +265,15 @@ func (spi SPI) Transfer(w byte) (byte, error) {
265
265
spi .Bus .DR .Set (uint32 (w ))
266
266
267
267
// Wait until transmit complete
268
- for ( spi .Bus .SR .Get () & stm32 .SPI_SR_TXE ) == 0 {
268
+ for ! spi .Bus .SR .HasBits ( stm32 .SPI_SR_TXE ) {
269
269
}
270
270
271
271
// Wait until receive complete
272
- for ( spi .Bus .SR .Get () & stm32 .SPI_SR_RXNE ) == 0 {
272
+ for ! spi .Bus .SR .HasBits ( stm32 .SPI_SR_RXNE ) {
273
273
}
274
274
275
275
// Wait until SPI is not busy
276
- for ( spi .Bus .SR .Get () & stm32 .SPI_SR_BSY ) > 0 {
276
+ for spi .Bus .SR .HasBits ( stm32 .SPI_SR_BSY ) {
277
277
}
278
278
279
279
// Return received data from SPI data register
@@ -439,7 +439,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
439
439
440
440
// clear timeout here
441
441
timeout := i2cTimeout
442
- for i2c .Bus .SR2 .Get () & ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) == 0 {
442
+ for ! i2c .Bus .SR2 .HasBits ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) {
443
443
timeout --
444
444
if timeout == 0 {
445
445
return errors .New ("I2C timeout on read clear address" )
@@ -450,7 +450,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
450
450
i2c .Bus .CR1 .SetBits (stm32 .I2C_CR1_STOP )
451
451
452
452
timeout = i2cTimeout
453
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_RxNE ) == 0 {
453
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_RxNE ) {
454
454
timeout --
455
455
if timeout == 0 {
456
456
return errors .New ("I2C timeout on read 1 byte" )
@@ -478,7 +478,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
478
478
479
479
// clear address here
480
480
timeout := i2cTimeout
481
- for i2c .Bus .SR2 .Get () & ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) == 0 {
481
+ for ! i2c .Bus .SR2 .HasBits ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) {
482
482
timeout --
483
483
if timeout == 0 {
484
484
return errors .New ("I2C timeout on read clear address" )
@@ -490,7 +490,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
490
490
491
491
// wait for btf. we need a longer timeout here than normal.
492
492
timeout = 1000
493
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_BTF ) == 0 {
493
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_BTF ) {
494
494
timeout --
495
495
if timeout == 0 {
496
496
return errors .New ("I2C timeout on read 2 bytes" )
@@ -524,7 +524,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
524
524
525
525
// clear address here
526
526
timeout := i2cTimeout
527
- for i2c .Bus .SR2 .Get () & ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) == 0 {
527
+ for ! i2c .Bus .SR2 .HasBits ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) {
528
528
timeout --
529
529
if timeout == 0 {
530
530
return errors .New ("I2C timeout on read clear address" )
@@ -536,7 +536,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
536
536
537
537
// wait for btf. we need a longer timeout here than normal.
538
538
timeout = 1000
539
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_BTF ) == 0 {
539
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_BTF ) {
540
540
timeout --
541
541
if timeout == 0 {
542
542
println ("I2C timeout on read 3 bytes" )
@@ -551,7 +551,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
551
551
r [0 ] = byte (i2c .Bus .DR .Get ())
552
552
553
553
timeout = 1000
554
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_BTF ) == 0 {
554
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_BTF ) {
555
555
timeout --
556
556
if timeout == 0 {
557
557
return errors .New ("I2C timeout on read 3 bytes" )
@@ -579,7 +579,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
579
579
580
580
// clear address here
581
581
timeout := i2cTimeout
582
- for i2c .Bus .SR2 .Get () & ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) == 0 {
582
+ for ! i2c .Bus .SR2 .HasBits ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY ) {
583
583
timeout --
584
584
if timeout == 0 {
585
585
return errors .New ("I2C timeout on read clear address" )
@@ -592,7 +592,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
592
592
593
593
// wait for btf. we need a longer timeout here than normal.
594
594
timeout = 1000
595
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_BTF ) == 0 {
595
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_BTF ) {
596
596
timeout --
597
597
if timeout == 0 {
598
598
println ("I2C timeout on read 3 bytes" )
@@ -606,7 +606,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
606
606
607
607
// wait for btf. we need a longer timeout here than normal.
608
608
timeout = 1000
609
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_BTF ) == 0 {
609
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_BTF ) {
610
610
timeout --
611
611
if timeout == 0 {
612
612
return errors .New ("I2C timeout on read more than 3 bytes" )
@@ -626,7 +626,7 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
626
626
r [len (r )- 2 ] = byte (i2c .Bus .DR .Get ())
627
627
628
628
timeout = i2cTimeout
629
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_RxNE ) == 0 {
629
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_RxNE ) {
630
630
timeout --
631
631
if timeout == 0 {
632
632
return errors .New ("I2C timeout on read last byte of more than 3" )
@@ -650,7 +650,7 @@ const i2cTimeout = 500
650
650
func (i2c I2C ) signalStart () error {
651
651
// Wait until I2C is not busy
652
652
timeout := i2cTimeout
653
- for ( i2c .Bus .SR2 .Get () & stm32 .I2C_SR2_BUSY ) > 0 {
653
+ for i2c .Bus .SR2 .HasBits ( stm32 .I2C_SR2_BUSY ) {
654
654
timeout --
655
655
if timeout == 0 {
656
656
return errors .New ("I2C busy on start" )
@@ -665,7 +665,7 @@ func (i2c I2C) signalStart() error {
665
665
666
666
// Wait for I2C EV5 aka SB flag.
667
667
timeout = i2cTimeout
668
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_SB ) == 0 {
668
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_SB ) {
669
669
timeout --
670
670
if timeout == 0 {
671
671
return errors .New ("I2C timeout on start" )
@@ -688,7 +688,7 @@ func (i2c I2C) signalStop() error {
688
688
func (i2c I2C ) waitForStop () error {
689
689
// Wait until I2C is stopped
690
690
timeout := i2cTimeout
691
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_STOPF ) > 0 {
691
+ for i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_STOPF ) {
692
692
timeout --
693
693
if timeout == 0 {
694
694
println ("I2C timeout on wait for stop signal" )
@@ -713,23 +713,23 @@ func (i2c I2C) sendAddress(address uint8, write bool) error {
713
713
timeout := i2cTimeout
714
714
if write {
715
715
// EV6 which is ADDR flag.
716
- for i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_ADDR == 0 {
716
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_ADDR ) {
717
717
timeout --
718
718
if timeout == 0 {
719
719
return errors .New ("I2C timeout on send write address" )
720
720
}
721
721
}
722
722
723
723
timeout = i2cTimeout
724
- for i2c .Bus .SR2 .Get () & ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY | stm32 .I2C_SR2_TRA ) == 0 {
724
+ for ! i2c .Bus .SR2 .HasBits ( stm32 .I2C_SR2_MSL | stm32 .I2C_SR2_BUSY | stm32 .I2C_SR2_TRA ) {
725
725
timeout --
726
726
if timeout == 0 {
727
727
return errors .New ("I2C timeout on send write address" )
728
728
}
729
729
}
730
730
} else {
731
731
// I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED which is ADDR flag.
732
- for ( i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_ADDR ) == 0 {
732
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_ADDR ) {
733
733
timeout --
734
734
if timeout == 0 {
735
735
return errors .New ("I2C timeout on send read address" )
@@ -749,7 +749,7 @@ func (i2c I2C) WriteByte(data byte) error {
749
749
// output on the bus.
750
750
// I2C_EVENT_MASTER_BYTE_TRANSMITTED is TXE flag.
751
751
timeout := i2cTimeout
752
- for i2c .Bus .SR1 .Get () & stm32 .I2C_SR1_TxE == 0 {
752
+ for ! i2c .Bus .SR1 .HasBits ( stm32 .I2C_SR1_TxE ) {
753
753
timeout --
754
754
if timeout == 0 {
755
755
return errors .New ("I2C timeout on write" )
0 commit comments