mirror of https://github.com/tinygo-org/tinygo.git
Ron Evans
6 years ago
committed by
Ayke
6 changed files with 333 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||
// Example using the i2s hardware interface on the Adafruit Circuit Playground Express
|
|||
// to read data from the onboard MEMS microphone.
|
|||
//
|
|||
package main |
|||
|
|||
import ( |
|||
"machine" |
|||
) |
|||
|
|||
func main() { |
|||
machine.I2S0.Configure(machine.I2SConfig{ |
|||
Mode: machine.I2SModePDM, |
|||
ClockSource: machine.I2SClockSourceExternal, |
|||
Stereo: true, |
|||
}) |
|||
|
|||
data := make([]uint32, 64) |
|||
|
|||
for { |
|||
// get the next group of samples
|
|||
machine.I2S0.Read(data) |
|||
|
|||
println("data", data[0], data[1], data[2], data[4], "...") |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
// +build sam
|
|||
|
|||
// This is the definition for I2S bus functions.
|
|||
// Actual implementations if available for any given hardware
|
|||
// are to be found in its the board definition.
|
|||
//
|
|||
// For more info about I2S, see: https://en.wikipedia.org/wiki/I%C2%B2S
|
|||
//
|
|||
|
|||
package machine |
|||
|
|||
type I2SMode uint8 |
|||
type I2SStandard uint8 |
|||
type I2SClockSource uint8 |
|||
type I2SDataFormat uint8 |
|||
|
|||
const ( |
|||
I2SModeMaster I2SMode = iota |
|||
I2SModeSlave |
|||
I2SModePDM |
|||
) |
|||
|
|||
const ( |
|||
I2StandardPhilips I2SStandard = iota |
|||
I2SStandardMSB |
|||
I2SStandardLSB |
|||
) |
|||
|
|||
const ( |
|||
I2SClockSourceInternal I2SClockSource = iota |
|||
I2SClockSourceExternal |
|||
) |
|||
|
|||
const ( |
|||
I2SDataFormatDefault I2SDataFormat = 0 |
|||
I2SDataFormat8bit = 8 |
|||
I2SDataFormat16bit = 16 |
|||
I2SDataFormat24bit = 24 |
|||
I2SDataFormat32bit = 32 |
|||
) |
|||
|
|||
// All fields are optional and may not be required or used on a particular platform.
|
|||
type I2SConfig struct { |
|||
SCK uint8 |
|||
WS uint8 |
|||
SD uint8 |
|||
Mode I2SMode |
|||
Standard I2SStandard |
|||
ClockSource I2SClockSource |
|||
DataFormat I2SDataFormat |
|||
AudioFrequency uint32 |
|||
MasterClockOutput bool |
|||
Stereo bool |
|||
} |
Loading…
Reference in new issue