mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-10 18:03:41 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 156d6e7c9c |
@@ -10,7 +10,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
console_example.RunFor(
|
console_example.RunFor(
|
||||||
flash.NewSPI(
|
flash.NewSPI(
|
||||||
&machine.SPI1,
|
machine.SPI1,
|
||||||
machine.SPI1_SDO_PIN,
|
machine.SPI1_SDO_PIN,
|
||||||
machine.SPI1_SDI_PIN,
|
machine.SPI1_SDI_PIN,
|
||||||
machine.SPI1_SCK_PIN,
|
machine.SPI1_SCK_PIN,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI1
|
spi = machine.SPI1
|
||||||
sckPin = machine.SDCARD_SCK_PIN
|
sckPin = machine.SDCARD_SCK_PIN
|
||||||
sdoPin = machine.SDCARD_SDO_PIN
|
sdoPin = machine.SDCARD_SDO_PIN
|
||||||
sdiPin = machine.SDCARD_SDI_PIN
|
sdiPin = machine.SDCARD_SDI_PIN
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SDCARD_SPI
|
spi = machine.SDCARD_SPI
|
||||||
sckPin = machine.SDCARD_SCK_PIN
|
sckPin = machine.SDCARD_SCK_PIN
|
||||||
sdoPin = machine.SDCARD_SDO_PIN
|
sdoPin = machine.SDCARD_SDO_PIN
|
||||||
sdiPin = machine.SDCARD_SDI_PIN
|
sdiPin = machine.SDCARD_SDI_PIN
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI2
|
spi = machine.SPI2
|
||||||
sckPin = machine.SCK2
|
sckPin = machine.SCK2
|
||||||
sdoPin = machine.SDO2
|
sdoPin = machine.SDO2
|
||||||
sdiPin = machine.SDI2
|
sdiPin = machine.SDI2
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func main() {
|
|||||||
//bind csPin to driverAdddress
|
//bind csPin to driverAdddress
|
||||||
driverAddress := uint8(0) // Let's assume we are working with driver at address 0x01
|
driverAddress := uint8(0) // Let's assume we are working with driver at address 0x01
|
||||||
// Step 3. Bind the communication interface to the protocol
|
// Step 3. Bind the communication interface to the protocol
|
||||||
comm := tmc5160.NewSPIComm(*spi, csPins)
|
comm := tmc5160.NewSPIComm(spi, csPins)
|
||||||
// Step 4. Define your stepper like this below
|
// Step 4. Define your stepper like this below
|
||||||
//stepper := tmc5160.NewStepper(angle , gearRatio vSupply rCoil , lCoil , iPeak , rSense , mSteps, fclk )
|
//stepper := tmc5160.NewStepper(angle , gearRatio vSupply rCoil , lCoil , iPeak , rSense , mSteps, fclk )
|
||||||
stepper := tmc5160.NewDefaultStepper() // Default Stepper should be used only for testing.
|
stepper := tmc5160.NewDefaultStepper() // Default Stepper should be used only for testing.
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type spiDriver struct {
|
type spiDriver struct {
|
||||||
bus machine.SPI
|
bus *machine.SPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSPI(bus machine.SPI, dc, cs, rst machine.Pin) *Device {
|
func NewSPI(bus *machine.SPI, dc, cs, rst machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
dc: dc,
|
dc: dc,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type spiDriver struct {
|
type spiDriver struct {
|
||||||
bus machine.SPI
|
bus *machine.SPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSPI(bus machine.SPI, dc, cs, rst machine.Pin) *Device {
|
func NewSPI(bus *machine.SPI, dc, cs, rst machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
dc: dc,
|
dc: dc,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
|
|||||||
+4
-2
@@ -4,6 +4,8 @@ package max6675
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"machine"
|
"machine"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrThermocoupleOpen is returned when the thermocouple input is open.
|
// ErrThermocoupleOpen is returned when the thermocouple input is open.
|
||||||
@@ -11,14 +13,14 @@ import (
|
|||||||
var ErrThermocoupleOpen = errors.New("thermocouple input open")
|
var ErrThermocoupleOpen = errors.New("thermocouple input open")
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus drivers.SPI
|
||||||
cs machine.Pin
|
cs machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new Device to read from a MAX6675 thermocouple.
|
// Create a new Device to read from a MAX6675 thermocouple.
|
||||||
// Pins must be configured before use. Frequency for SPI
|
// Pins must be configured before use. Frequency for SPI
|
||||||
// should be 4.3MHz maximum.
|
// should be 4.3MHz maximum.
|
||||||
func NewDevice(bus machine.SPI, cs machine.Pin) *Device {
|
func NewDevice(bus drivers.SPI, cs machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
|
|||||||
+4
-2
@@ -4,17 +4,19 @@ package max72xx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
"machine"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus drivers.SPI
|
||||||
cs machine.Pin
|
cs machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDriver creates a new max7219 connection. The SPI wire must already be configured
|
// NewDriver creates a new max7219 connection. The SPI wire must already be configured
|
||||||
// The SPI frequency must not be higher than 10MHz.
|
// The SPI frequency must not be higher than 10MHz.
|
||||||
// parameter cs: the datasheet also refers to this pin as "load" pin.
|
// parameter cs: the datasheet also refers to this pin as "load" pin.
|
||||||
func NewDevice(bus machine.SPI, cs machine.Pin) *Device {
|
func NewDevice(bus drivers.SPI, cs machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
|
|||||||
+2
-1
@@ -14,7 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type P1AM struct {
|
type P1AM struct {
|
||||||
bus machine.SPI
|
bus *machine.SPI
|
||||||
|
|
||||||
slaveSelectPin, slaveAckPin, baseEnablePin machine.Pin
|
slaveSelectPin, slaveAckPin, baseEnablePin machine.Pin
|
||||||
|
|
||||||
// SkipAutoConfig will skip loading a default configuration into each module.
|
// SkipAutoConfig will skip loading a default configuration into each module.
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ func (d *Device) GetRadioEventChan() chan lora.RadioEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new SX127x connection. The SPI bus must already be configured.
|
// New creates a new SX127x connection. The SPI bus must already be configured.
|
||||||
func New(spi machine.SPI, rstPin machine.Pin) *Device {
|
func New(spi drivers.SPI, rstPin machine.Pin) *Device {
|
||||||
k := Device{
|
k := Device{
|
||||||
spi: spi,
|
spi: spi,
|
||||||
rstPin: rstPin,
|
rstPin: rstPin,
|
||||||
|
|||||||
+1
-1
@@ -183,7 +183,7 @@ if err != nil {
|
|||||||
|
|
||||||
## API Reference
|
## API Reference
|
||||||
|
|
||||||
NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm
|
NewSPIComm(spi *machine.SPI, csPins map[uint8]machine.Pin) *SPIComm
|
||||||
|
|
||||||
Creates a new SPI communication interface for the TMC5160.
|
Creates a new SPI communication interface for the TMC5160.
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -16,12 +16,12 @@ func (e CustomError) Error() string {
|
|||||||
|
|
||||||
// SPIComm implements RegisterComm for SPI-based communication
|
// SPIComm implements RegisterComm for SPI-based communication
|
||||||
type SPIComm struct {
|
type SPIComm struct {
|
||||||
spi machine.SPI
|
spi *machine.SPI
|
||||||
CsPins map[uint8]machine.Pin // Map to store CS pin for each Driver by its address
|
CsPins map[uint8]machine.Pin // Map to store CS pin for each Driver by its address
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSPIComm creates a new SPIComm instance.
|
// NewSPIComm creates a new SPIComm instance.
|
||||||
func NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm {
|
func NewSPIComm(spi *machine.SPI, csPins map[uint8]machine.Pin) *SPIComm {
|
||||||
return &SPIComm{
|
return &SPIComm{
|
||||||
spi: spi,
|
spi: spi,
|
||||||
CsPins: csPins,
|
CsPins: csPins,
|
||||||
@@ -31,7 +31,7 @@ func NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm {
|
|||||||
// Setup initializes the SPI communication with the Driver and configures all CS pins.
|
// Setup initializes the SPI communication with the Driver and configures all CS pins.
|
||||||
func (comm *SPIComm) Setup() error {
|
func (comm *SPIComm) Setup() error {
|
||||||
// Check if SPI is initialized
|
// Check if SPI is initialized
|
||||||
if comm.spi == (machine.SPI{}) {
|
if comm.spi == nil {
|
||||||
return CustomError("SPI not initialized")
|
return CustomError("SPI not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ func (comm *SPIComm) WriteRegister(register uint8, value uint32, driverAddress u
|
|||||||
addressWithWriteAccess := register | 0x80
|
addressWithWriteAccess := register | 0x80
|
||||||
|
|
||||||
// Send the address and the data to write (split into 4 bytes)
|
// Send the address and the data to write (split into 4 bytes)
|
||||||
_, err := spiTransfer40(&comm.spi, addressWithWriteAccess, value)
|
_, err := spiTransfer40(comm.spi, addressWithWriteAccess, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
csPin.High()
|
csPin.High()
|
||||||
return CustomError("Failed to write register")
|
return CustomError("Failed to write register")
|
||||||
@@ -88,7 +88,7 @@ func (comm *SPIComm) ReadRegister(register uint8, driverAddress uint8) (uint32,
|
|||||||
csPin.Low()
|
csPin.Low()
|
||||||
|
|
||||||
// Step 1: Send a dummy write operation to begin the read sequence
|
// Step 1: Send a dummy write operation to begin the read sequence
|
||||||
_, err := spiTransfer40(&comm.spi, register, 0x00) // Send dummy data
|
_, err := spiTransfer40(comm.spi, register, 0x00) // Send dummy data
|
||||||
if err != nil {
|
if err != nil {
|
||||||
csPin.High()
|
csPin.High()
|
||||||
return 0, CustomError("Failed to send dummy write")
|
return 0, CustomError("Failed to send dummy write")
|
||||||
@@ -97,7 +97,7 @@ func (comm *SPIComm) ReadRegister(register uint8, driverAddress uint8) (uint32,
|
|||||||
time.Sleep(176 * time.Nanosecond)
|
time.Sleep(176 * time.Nanosecond)
|
||||||
csPin.Low()
|
csPin.Low()
|
||||||
// Step 2: Send the register read request again to get the actual value
|
// Step 2: Send the register read request again to get the actual value
|
||||||
response, err := spiTransfer40(&comm.spi, register, 0x00) // Send again to get actual register data
|
response, err := spiTransfer40(comm.spi, register, 0x00) // Send again to get actual register data
|
||||||
if err != nil {
|
if err != nil {
|
||||||
csPin.High()
|
csPin.High()
|
||||||
return 0, CustomError("Failed to read register")
|
return 0, CustomError("Failed to read register")
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus *machine.SPI
|
||||||
cs machine.Pin
|
cs machine.Pin
|
||||||
dc machine.Pin
|
dc machine.Pin
|
||||||
rst machine.Pin
|
rst machine.Pin
|
||||||
@@ -79,7 +79,7 @@ var partialRefresh = [159]uint8{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
|
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
|
||||||
func New(bus machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
return Device{
|
return Device{
|
||||||
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
|
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
|
||||||
bus: bus,
|
bus: bus,
|
||||||
|
|||||||
Reference in New Issue
Block a user