tnt has uploaded this change for review. ( 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@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(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/07/26907/1
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);
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26907
to look at the new patch set (#2).
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@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(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/07/26907/2
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26907 )
Change subject: icE1usb fw: Add GPIO access functions ......................................................................
Patch Set 2: Code-Review+2
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@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);