Skip to content

Commit 8bd2233

Browse files
committed
machine/rp: use the blockReset() and unresetBlockWait() helper functions for all peripheral reset/unreset operations
Signed-off-by: deadprogram <[email protected]>
1 parent ff58c50 commit 8bd2233

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

src/machine/machine_rp2_adc.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ var adcAref uint32
1919

2020
// InitADC resets the ADC peripheral.
2121
func InitADC() {
22-
rp.RESETS.RESET.SetBits(rp.RESETS_RESET_ADC)
23-
rp.RESETS.RESET.ClearBits(rp.RESETS_RESET_ADC)
24-
for !rp.RESETS.RESET_DONE.HasBits(rp.RESETS_RESET_ADC) {
25-
}
22+
resetBlock(rp.RESETS_RESET_ADC)
23+
unresetBlockWait(rp.RESETS_RESET_ADC)
2624
// enable ADC
2725
rp.ADC.CS.Set(rp.ADC_CS_EN)
2826
adcAref = 3300

src/machine/machine_rp2_i2c.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ func (i2c *I2C) init(config I2CConfig) error {
259259
//go:inline
260260
func (i2c *I2C) reset() {
261261
resetVal := i2c.deinit()
262-
rp.RESETS.RESET.ClearBits(resetVal)
263-
// Wait until reset is done.
264-
for !rp.RESETS.RESET_DONE.HasBits(resetVal) {
265-
}
262+
unresetBlockWait(resetVal)
266263
}
267264

268265
// deinit sets reset bit for I2C. Must call reset to reenable I2C after deinit.
@@ -276,7 +273,7 @@ func (i2c *I2C) deinit() (resetVal uint32) {
276273
resetVal = rp.RESETS_RESET_I2C1
277274
}
278275
// Perform I2C reset.
279-
rp.RESETS.RESET.SetBits(resetVal)
276+
resetBlock(resetVal)
280277

281278
return resetVal
282279
}

src/machine/machine_rp2_spi.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ func (spi *SPI) setFormat(mode uint8) {
212212
//go:inline
213213
func (spi *SPI) reset() {
214214
resetVal := spi.deinit()
215-
rp.RESETS.RESET.ClearBits(resetVal)
216-
// Wait until reset is done.
217-
for !rp.RESETS.RESET_DONE.HasBits(resetVal) {
218-
}
215+
unresetBlockWait(resetVal)
219216
}
220217

221218
//go:inline
@@ -227,7 +224,7 @@ func (spi *SPI) deinit() (resetVal uint32) {
227224
resetVal = rp.RESETS_RESET_SPI1
228225
}
229226
// Perform SPI reset.
230-
rp.RESETS.RESET.SetBits(resetVal)
227+
resetBlock(resetVal)
231228
return resetVal
232229
}
233230

src/machine/machine_rp2_uart.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,8 @@ func initUART(uart *UART) {
148148
}
149149

150150
// reset UART
151-
rp.RESETS.RESET.SetBits(resetVal)
152-
rp.RESETS.RESET.ClearBits(resetVal)
153-
for !rp.RESETS.RESET_DONE.HasBits(resetVal) {
154-
}
151+
resetBlock(resetVal)
152+
unresetBlockWait(resetVal)
155153
}
156154

157155
// handleInterrupt should be called from the appropriate interrupt handler for

0 commit comments

Comments
 (0)