machine: Rewrite most of the GPIO functionality

Split across device types (nrf, dummy) and use registers directly
instead of the HAL.
This commit is contained in:
Ayke van Laethem
2018-05-05 20:02:00 +02:00
parent 16489c0df6
commit c4f0dc90dd
5 changed files with 77 additions and 38 deletions
+8 -16
View File
@@ -1,26 +1,18 @@
package machine
// #include "../runtime/runtime_nrf.h"
import "C"
type GPIOConfig struct {
Mode GPIOMode
}
type GPIO struct {
Pin uint32
Pin uint8
}
type GPIOConfig struct {
Mode uint8
func (p GPIO) High() {
p.Set(true)
}
const (
GPIO_INPUT = iota
GPIO_OUTPUT
)
func (p GPIO) Configure(config GPIOConfig) {
C.gpio_cfg(C.uint(p.Pin), C.gpio_mode_t(config.Mode))
}
func (p GPIO) Set(value bool) {
C.gpio_set(C.uint(p.Pin), C.bool(value))
func (p GPIO) Low() {
p.Set(false)
}