-
-
Notifications
You must be signed in to change notification settings - Fork 80
[EV3] Implement I2C support via PRU1 #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
68b9c47
413e42e
c46a978
b0004ca
e137d53
9179751
efcf8b5
dc37fb6
bb2f716
7dc9c3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,9 @@ | |
| #include <tiam1808/gpio.h> | ||
| #include <tiam1808/psc.h> | ||
|
|
||
| #include "../rproc/rproc.h" | ||
| #include "../rproc/rproc_ev3.h" | ||
|
|
||
| static uint32_t get_pin_index(const pbdrv_gpio_t *gpio) { | ||
| // TI API indexes pins from 1 to 144, so need to add 1. | ||
| pbdrv_gpio_ev3_mux_t *mux_info = gpio->bank; | ||
|
|
@@ -31,13 +34,32 @@ static void pbdrv_gpio_alt_gpio(const pbdrv_gpio_t *gpio) { | |
| pbdrv_gpio_alt(gpio, mux_info->gpio_mode); | ||
| } | ||
|
|
||
| // If the pin is not in banks 0/1, the PRU is not involved. | ||
| // Otherwise, if the PRU is initialized, do direction changes | ||
| // via the PRU in order to prevent race conditions. | ||
| // If the PRU is not initialized (i.e. doing direction changes | ||
| // during early boot), also set the direction directly via | ||
| // the ARM. The PRU code polls these direction change registers | ||
| // continuously and is not expected to block for too long, | ||
| // only on the order of microseconds. | ||
| #define PBDRV_GPIO_EV3_ARM_OWNS_GPIO_BANK(pin_index) \ | ||
| ((pin_index) > 32 || !pbdrv_rproc_is_ready()) | ||
|
|
||
| static void gpio_write(const pbdrv_gpio_t *gpio, uint8_t value) { | ||
ArcaneNibble marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!gpio) { | ||
| return; | ||
| } | ||
| pbdrv_gpio_alt_gpio(gpio); | ||
| uint32_t pin_index = get_pin_index(gpio); | ||
| GPIODirModeSet(SOC_GPIO_0_REGS, pin_index, GPIO_DIR_OUTPUT); | ||
| if (PBDRV_GPIO_EV3_ARM_OWNS_GPIO_BANK(pin_index)) { | ||
| GPIODirModeSet(SOC_GPIO_0_REGS, pin_index, GPIO_DIR_OUTPUT); | ||
| } else if (GPIODirModeGet(SOC_GPIO_0_REGS, pin_index) != GPIO_DIR_OUTPUT) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this check go as the first (I know it used to double-set it before as well, but now that we have the test we might as well cover both cases.)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured that code path was cheap enough (a single register write) that it wasn't worth bothering |
||
| uint32_t val = 1 << (pin_index - 1); | ||
| pbdrv_rproc_ev3_pru1_shared_ram.gpio_bank_01_dir_clr = val; | ||
| while (pbdrv_rproc_ev3_pru1_shared_ram.gpio_bank_01_dir_clr) { | ||
| // Wait for the PRU to process the command | ||
ArcaneNibble marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| GPIOPinWrite(SOC_GPIO_0_REGS, pin_index, value); | ||
| } | ||
|
|
||
|
|
@@ -55,7 +77,15 @@ uint8_t pbdrv_gpio_input(const pbdrv_gpio_t *gpio) { | |
| } | ||
| pbdrv_gpio_alt_gpio(gpio); | ||
| uint32_t pin_index = get_pin_index(gpio); | ||
| GPIODirModeSet(SOC_GPIO_0_REGS, pin_index, GPIO_DIR_INPUT); | ||
| if (PBDRV_GPIO_EV3_ARM_OWNS_GPIO_BANK(pin_index)) { | ||
| GPIODirModeSet(SOC_GPIO_0_REGS, pin_index, GPIO_DIR_INPUT); | ||
| } else if (GPIODirModeGet(SOC_GPIO_0_REGS, pin_index) != GPIO_DIR_INPUT) { | ||
| uint32_t val = 1 << (pin_index - 1); | ||
| pbdrv_rproc_ev3_pru1_shared_ram.gpio_bank_01_dir_set = val; | ||
| while (pbdrv_rproc_ev3_pru1_shared_ram.gpio_bank_01_dir_set) { | ||
| // Wait for the PRU to process the command | ||
| } | ||
| } | ||
| return GPIOPinRead(SOC_GPIO_0_REGS, pin_index) == GPIO_PIN_HIGH; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.