machine/nrf: implement reading GPIO pins
Этот коммит содержится в:
родитель
ab6757fe11
коммит
752332ff13
1 изменённых файлов: 18 добавлений и 10 удалений
|
@ -9,8 +9,10 @@ import (
|
||||||
type GPIOMode uint8
|
type GPIOMode uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GPIO_INPUT = nrf.P0_PIN_CNF_DIR_Input
|
GPIO_INPUT = (nrf.P0_PIN_CNF_DIR_Input << nrf.P0_PIN_CNF_DIR_Pos) | (nrf.P0_PIN_CNF_INPUT_Connect << nrf.P0_PIN_CNF_INPUT_Pos)
|
||||||
GPIO_OUTPUT = nrf.P0_PIN_CNF_DIR_Output
|
GPIO_INPUT_PULLUP = GPIO_INPUT | (nrf.P0_PIN_CNF_PULL_Pullup << nrf.P0_PIN_CNF_PULL_Pos)
|
||||||
|
GPIO_INPUT_PULLDOWN = GPIO_INPUT | (nrf.P0_PIN_CNF_PULL_Pulldown << nrf.P0_PIN_CNF_PULL_Pos)
|
||||||
|
GPIO_OUTPUT = (nrf.P0_PIN_CNF_DIR_Output << nrf.P0_PIN_CNF_DIR_Pos) | (nrf.P0_PIN_CNF_INPUT_Disconnect << nrf.P0_PIN_CNF_INPUT_Pos)
|
||||||
)
|
)
|
||||||
|
|
||||||
// LEDs on the PCA10040 (nRF52832 dev board)
|
// LEDs on the PCA10040 (nRF52832 dev board)
|
||||||
|
@ -22,16 +24,23 @@ const (
|
||||||
LED4 = 20
|
LED4 = 20
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Buttons on the PCA10040 (nRF52832 dev board)
|
||||||
|
const (
|
||||||
|
BUTTON = BUTTON1
|
||||||
|
BUTTON1 = 13
|
||||||
|
BUTTON2 = 14
|
||||||
|
BUTTON3 = 15
|
||||||
|
BUTTON4 = 16
|
||||||
|
)
|
||||||
|
|
||||||
|
// Configure this pin with the given configuration.
|
||||||
func (p GPIO) Configure(config GPIOConfig) {
|
func (p GPIO) Configure(config GPIOConfig) {
|
||||||
cfg := config.Mode | nrf.P0_PIN_CNF_PULL_Disabled | nrf.P0_PIN_CNF_DRIVE_S0S1 | nrf.P0_PIN_CNF_SENSE_Disabled
|
cfg := config.Mode | nrf.P0_PIN_CNF_DRIVE_S0S1 | nrf.P0_PIN_CNF_SENSE_Disabled
|
||||||
if config.Mode == GPIO_INPUT {
|
|
||||||
cfg |= nrf.P0_PIN_CNF_INPUT_Connect
|
|
||||||
} else {
|
|
||||||
cfg |= nrf.P0_PIN_CNF_INPUT_Disconnect
|
|
||||||
}
|
|
||||||
nrf.P0.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
|
nrf.P0.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the pin to high or low.
|
||||||
|
// Warning: only use this on an output pin!
|
||||||
func (p GPIO) Set(high bool) {
|
func (p GPIO) Set(high bool) {
|
||||||
if high {
|
if high {
|
||||||
nrf.P0.OUTSET = 1 << p.Pin
|
nrf.P0.OUTSET = 1 << p.Pin
|
||||||
|
@ -42,6 +51,5 @@ func (p GPIO) Set(high bool) {
|
||||||
|
|
||||||
// Get returns the current value of a GPIO pin.
|
// Get returns the current value of a GPIO pin.
|
||||||
func (p GPIO) Get() bool {
|
func (p GPIO) Get() bool {
|
||||||
// TODO: implement
|
return (nrf.P0.IN>>p.Pin)&1 != 0
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче