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
This commit is contained in:
parent
394748ab86
commit
be5a53a4fe
|
@ -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 {
|
||||
|
@ -46,6 +50,35 @@ pdm_set(int chan, bool enable, unsigned value, bool normalize)
|
|||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,10 @@ enum pdm_chan {
|
|||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue