mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 02:33:28 +00:00
machine: refactor pins to be of Pin type
This commit is contained in:
committed by
Ron Evans
parent
421ef04efb
commit
94b8214529
@@ -10,17 +10,17 @@ import (
|
||||
const CPU_FREQUENCY = 64000000
|
||||
|
||||
// Get peripheral and pin number for this GPIO pin.
|
||||
func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
|
||||
if p.Pin >= 32 {
|
||||
return nrf.P1, p.Pin - 32
|
||||
func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
|
||||
if p >= 32 {
|
||||
return nrf.P1, uint32(p - 32)
|
||||
} else {
|
||||
return nrf.P0, p.Pin
|
||||
return nrf.P0, uint32(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx uint32) {
|
||||
nrf.UART0.PSEL.TXD.Set(tx)
|
||||
nrf.UART0.PSEL.RXD.Set(rx)
|
||||
func (uart UART) setPins(tx, rx Pin) {
|
||||
nrf.UART0.PSEL.TXD.Set(uint32(tx))
|
||||
nrf.UART0.PSEL.RXD.Set(uint32(rx))
|
||||
}
|
||||
|
||||
//go:export UARTE0_UART0_IRQHandler
|
||||
@@ -28,13 +28,13 @@ func handleUART0() {
|
||||
UART0.handleInterrupt()
|
||||
}
|
||||
|
||||
func (i2c I2C) setPins(scl, sda uint8) {
|
||||
func (i2c I2C) setPins(scl, sda Pin) {
|
||||
i2c.Bus.PSEL.SCL.Set(uint32(scl))
|
||||
i2c.Bus.PSEL.SDA.Set(uint32(sda))
|
||||
}
|
||||
|
||||
// SPI
|
||||
func (spi SPI) setPins(sck, mosi, miso uint8) {
|
||||
func (spi SPI) setPins(sck, mosi, miso Pin) {
|
||||
if sck == 0 {
|
||||
sck = SPI0_SCK_PIN
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user