remove unused API

This commit is contained in:
soypat
2024-01-15 01:51:22 -03:00
parent 677f8ed297
commit 45e207fe2e
3 changed files with 7 additions and 57 deletions
-33
View File
@@ -95,39 +95,6 @@ func (d *SPICard) CSD() CSD { return d.csd }
func (d *SPICard) yield() { time.Sleep(d.wait) }
func (d *SPICard) waitNotBusy(timeout time.Duration) error {
if _, ok := d.waitToken(timeout, 0xff); ok {
return nil
}
return errBusyTimeout
}
func (d *SPICard) waitStartBlock() error {
if _, ok := d.waitToken(d.timeout, tokSTART_BLOCK); ok {
return nil
}
return errWaitStartBlock
}
// waitToken transmits over SPI waiting to read a given byte token. If argument tok
// is 0xff then waitToken will wait for a token that does NOT match 0xff.
func (d *SPICard) waitToken(timeout time.Duration, tok byte) (byte, bool) {
tm := d.timers[1].setTimeout(timeout)
for {
received, err := d.bus.Transfer(0xFF)
if err != nil {
return received, false
}
matchTok := received == tok
if matchTok || (!matchTok && tok == 0xff) {
return received, true
} else if tm.expired() {
return received, false
}
d.yield()
}
}
var timeoutTimer [2]timer
type timer struct {
-17
View File
@@ -84,23 +84,6 @@ func makeResponseError(status response1) error {
}
}
// func (c *SPICard) lastR1() r1 { return c.lastr1 }
// is part of specification but not used in every implementation out there...
func (d *SPICard) readR1() (resp r1, err error) {
first, ok := d.waitToken(d.timeout, 0xff)
if !ok {
return resp, errBusyTimeout
}
err = d.bus.Tx(nil, d.buf[1:6])
if err != nil {
return resp, err
}
d.buf[0] = first
copy(resp.data[:], d.buf[:6])
return resp, nil
}
// Commands used to help generate this file:
// - stringer -type=state -trimprefix=state -output=state_string.go
// - stringer -type=status -trimprefix=status -output=status_string.go
+7 -7
View File
@@ -200,7 +200,7 @@ func (d *SPICard) WriteBlocks(data []byte, startBlockIdx int64) error {
}
d.csEnable(true)
defer d.csEnable(false)
writeTimeout := 2 * d.timeout
if numblocks == 1 {
_, err = d.card_command(cmdWriteBlock, uint32(startBlockIdx))
if err != nil {
@@ -210,7 +210,7 @@ func (d *SPICard) WriteBlocks(data []byte, startBlockIdx int64) error {
if err != nil {
return err
}
err = d.wait_not_busy()
err = d.wait_not_busy(writeTimeout)
if err != nil {
return err
}
@@ -238,7 +238,7 @@ func (d *SPICard) WriteBlocks(data []byte, startBlockIdx int64) error {
for i := 0; i < numblocks; i++ {
offset := i * blocksize
err = d.waitNotBusy(d.timeout)
err = d.wait_not_busy(writeTimeout)
if err != nil {
return err
}
@@ -248,7 +248,7 @@ func (d *SPICard) WriteBlocks(data []byte, startBlockIdx int64) error {
}
}
// Stop the multi write operation.
err = d.waitNotBusy(d.timeout)
err = d.wait_not_busy(writeTimeout)
if err != nil {
return err
}
@@ -310,7 +310,7 @@ func (d *SPICard) card_acmd(acmd appcommand, args uint32) (uint8, error) {
func (d *SPICard) card_command(cmd command, args uint32) (uint8, error) {
const transmitterBit = 1 << 6
err := d.wait_not_busy()
err := d.wait_not_busy(d.timeout)
if err != nil {
return 0, err
}
@@ -364,8 +364,8 @@ func (d *SPICard) read_data(data []byte) (err error) {
return nil
}
func (s *SPICard) wait_not_busy() error {
tm := s.timers[1].setTimeout(s.timeout)
func (s *SPICard) wait_not_busy(timeout time.Duration) error {
tm := s.timers[1].setTimeout(timeout)
for {
tok, err := s.receive()
if err != nil {