laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26907
)
Change subject: icE1usb fw: Add GPIO access functions
......................................................................
icE1usb fw: Add GPIO access functions
The 32 bit register is split in different fields to speed up
access to the 'in' field. The oe/out fields can't be split because
all writes are 32 bit wide (i.e. no support for byte enable in the
gateware)
Signed-off-by: Sylvain Munaut <tnt(a)246tNt.com>
Change-Id: Ic25377bb777e5d25939f0e8cfe6b7c6ef8641f6d
---
M firmware/ice40-riscv/icE1usb/misc.c
M firmware/ice40-riscv/icE1usb/misc.h
2 files changed, 38 insertions(+), 1 deletion(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/firmware/ice40-riscv/icE1usb/misc.c b/firmware/ice40-riscv/icE1usb/misc.c
index bd9198a..50aec43 100644
--- a/firmware/ice40-riscv/icE1usb/misc.c
+++ b/firmware/ice40-riscv/icE1usb/misc.c
@@ -15,7 +15,11 @@
struct misc {
uint32_t warmboot;
- uint32_t gpio;
+ struct {
+ uint16_t oe_out;
+ uint8_t in;
+ uint8_t _rsvd;
+ } gpio;
uint32_t e1_led;
uint32_t _rsvd;
struct {
@@ -47,6 +51,35 @@
void
+gpio_dir(int n, bool output)
+{
+ uint16_t mask = 256 << n;
+
+ if (output)
+ misc_regs->gpio.oe_out |= mask;
+ else
+ misc_regs->gpio.oe_out &= ~mask;
+}
+
+void
+gpio_out(int n, bool val)
+{
+ uint16_t mask = 1 << n;
+
+ if (val)
+ misc_regs->gpio.oe_out |= mask;
+ else
+ misc_regs->gpio.oe_out &= ~mask;
+}
+
+bool
+gpio_in(int n)
+{
+ return (misc_regs->gpio.in & (1 << n)) != 0;
+}
+
+
+void
e1_led_run(void)
{
misc_regs->e1_led |= 0x100;
diff --git a/firmware/ice40-riscv/icE1usb/misc.h b/firmware/ice40-riscv/icE1usb/misc.h
index b4baef1..76d5a7d 100644
--- a/firmware/ice40-riscv/icE1usb/misc.h
+++ b/firmware/ice40-riscv/icE1usb/misc.h
@@ -26,6 +26,10 @@
void pdm_set(int chan, bool enable, unsigned value, bool normalize);
+void gpio_dir(int n, bool output);
+void gpio_out(int n, bool val);
+bool gpio_in(int n);
+
void e1_led_run(void);
void e1_led_pause(void);
void e1_led_set(bool enable, uint8_t cfg);
--
To view, visit
https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26907
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-e1-hardware
Gerrit-Branch: master
Gerrit-Change-Id: Ic25377bb777e5d25939f0e8cfe6b7c6ef8641f6d
Gerrit-Change-Number: 26907
Gerrit-PatchSet: 2
Gerrit-Owner: tnt <tnt(a)246tNt.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged