Skip to content

Commit

Permalink
feature: modify i2s interface/implementation to better match specific…
Browse files Browse the repository at this point in the history
…ation

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 9, 2024
1 parent ec3f387 commit c9c14b3
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/examples/i2s/i2s.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ func main() {
Stereo: true,
})

data := make([]uint32, 64)
data := make([]uint16, 64)

for {
// get the next group of samples
machine.I2S0.Read(data)
machine.I2S0.ReadMono(data)

println("data", data[0], data[1], data[2], data[4], "...")
}
Expand Down
5 changes: 3 additions & 2 deletions src/machine/board_arduino_mkr1000.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ const (
// I2S pins
const (
I2S_SCK_PIN Pin = PA10
I2S_SD_PIN Pin = PA07
I2S_WS_PIN = NoPin // TODO: figure out what this is on Arduino Nano 33.
I2S_SDO_PIN Pin = PA07
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // TODO: figure out what this is on Arduino MKR1000
)

// USB CDC identifiers
Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_arduino_mkrwifi1010.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const (
// I2S pins
const (
I2S_SCK_PIN Pin = PA10
I2S_SD_PIN Pin = PA07
I2S_SDO_PIN Pin = PA07
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // TODO: figure out what this is on Arduino MKR WiFi 1010.
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_arduino_nano33.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const (
// I2S pins
const (
I2S_SCK_PIN Pin = PA10
I2S_SD_PIN Pin = PA08
I2S_SDO_PIN Pin = PA08
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // TODO: figure out what this is on Arduino Nano 33.
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_arduino_zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const (
// I2S pins - might not be exposed
const (
I2S_SCK_PIN Pin = PA10
I2S_SD_PIN Pin = PA07
I2S_SDO_PIN Pin = PA07
I2S_SDI_PIN = NoPin
I2S_WS_PIN Pin = PA11
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_circuitplay_express.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ var SPI0 = sercomSPIM3
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA08
I2S_SDO_PIN = PA08
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // no WS, instead uses SCK to sync
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_feather-m0-express.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ var SPI0 = sercomSPIM4
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA07
I2S_SDO_PIN = PA07
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // TODO: figure out what this is on Feather M0 Express.
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_feather-m0.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var SPI0 = sercomSPIM4
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA08
I2S_SDO_PIN = PA08
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // TODO: figure out what this is on Feather M0.
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_gemma-m0.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var (
// I2S (not connected, needed for atsamd21).
const (
I2S_SCK_PIN = NoPin
I2S_SD_PIN = NoPin
I2S_SDO_PIN = NoPin
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_grandcentral-m4.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ const (

I2S_SCK_PIN = I2S0_SCK_PIN // default pins
I2S_WS_PIN = I2S0_FS_PIN //
I2S_SD_PIN = I2S0_SDO_PIN //
I2S_SDO_PIN = I2S0_SDO_PIN
I2S_SDI_PIN = NoPin
)

// SD card pins
Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_itsybitsy-m0.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ var SPI1 = sercomSPIM5
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA08
I2S_SDO_PIN = PA08
I2S_SDI_PIN = NoPin
I2S_WS_PIN = NoPin // TODO: figure out what this is on ItsyBitsy M0.
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_p1am-100.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ var (
// I2S pins
const (
I2S_SCK_PIN Pin = D2
I2S_SD_PIN Pin = A6
I2S_SDO_PIN Pin = A6
I2S_SDI_PIN = NoPin
I2S_WS_PIN = D3
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_qtpy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ var (
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA08
I2S_SDO_PIN = PA08
I2S_SDI_PIN = NoPin // TODO: figure out what this is on QT Py M0.
I2S_WS_PIN = NoPin // TODO: figure out what this is on QT Py M0.
)

Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_trinket.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ var (
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA08
I2S_SDO_PIN = PA08
I2S_SDI_PIN = NoPin // TODO: figure out what this is on Trinket M0.
I2S_WS_PIN = NoPin // TODO: figure out what this is on Trinket M0.
)

Expand Down
8 changes: 8 additions & 0 deletions src/machine/board_wioterminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ var (
I2C1 = sercomI2CM3
)

// I2S pins
const (
I2S_SCK_PIN = BCM18
I2S_SDO_PIN = BCM21
I2S_SDI_PIN = BCM20
I2S_WS_PIN = BCM19
)

// SPI pins
const (
SPI0_SCK_PIN = SCK // SCK: SERCOM5/PAD[1]
Expand Down
3 changes: 2 additions & 1 deletion src/machine/board_xiao.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ var SPI0 = sercomSPIM0
// I2S pins
const (
I2S_SCK_PIN = PA10
I2S_SD_PIN = PA08
I2S_SDO_PIN = PA08
I2S_SDI_PIN = NoPin // TODO: figure out what this is on Xiao
I2S_WS_PIN = NoPin // TODO: figure out what this is on Xiao
)

Expand Down
34 changes: 30 additions & 4 deletions src/machine/i2s.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build sam
//go:build sam && atsamd21

// This is the definition for I2S bus functions.
// Actual implementations if available for any given hardware
Expand All @@ -9,6 +9,23 @@

package machine

import "errors"

// If you are getting a compile error on this line please check to see you've
// correctly implemented the methods on the I2S type. They must match
// the interface method signatures type to type perfectly.
// If not implementing the I2S type please remove your target from the build tags
// at the top of this file.
var _ interface {
SetSampleFrequency(freq uint32) error
ReadMono(b []uint16) (int, error)
ReadStereo(b []uint32) (int, error)
WriteMono(b []uint16) (int, error)
WriteStereo(b []uint32) (int, error)
Paused(disabled bool)
Stop()
} = (*I2S)(nil)

type I2SMode uint8
type I2SStandard uint8
type I2SClockSource uint8
Expand Down Expand Up @@ -39,11 +56,20 @@ const (
I2SDataFormat32bit = 32
)

var (
ErrInvalidSampleFrequency = errors.New("i2s: invalid sample frequency")
)

// All fields are optional and may not be required or used on a particular platform.
type I2SConfig struct {
SCK Pin
WS Pin
SD Pin
// clock
SCK Pin
// word select
WS Pin
// data out
SDO Pin
// data in
SDI Pin
Mode I2SMode
Standard I2SStandard
ClockSource I2SClockSource
Expand Down
Loading

0 comments on commit c9c14b3

Please sign in to comment.