diff options
author | Bill Richardson <wfrichar@chromium.org> | 2015-05-19 00:00:23 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-18 05:07:55 +0000 |
commit | b72a5f5e8e97ba86736c1e26b4204fc6d0c215da (patch) | |
tree | 155559713f9432bbc849bbe18a12983a672db5c6 | |
parent | dd1987051b473e74dab3490921d0cc77c76fcac3 (diff) | |
download | chrome-ec-b72a5f5e8e97ba86736c1e26b4204fc6d0c215da.tar.gz |
discovery-stm32f072: Blink the LEDs
This just makes the LEDs blink continually, because I have a
development board sitting on my desk and I like to see it doing
something.
You can still force the GPIOs on and off using the tool in
extra/usb_gpio/.
BUG=none
BRANCH=none
TEST=make buildall
Try it:
sudo make BOARD=discovery-stm32f072 flash
The LEDs blink.
Force them on and off with:
cd extra/usb_gpio
make
./usb_gpio write -1 0
./usb_gpio write 0 -1
./usb_gpio write 2 0
./usb_gpio write 4 2
To resume blinking, use
./usb_gpio write 0 0
Change-Id: Iadbe7436c02de5b6eae81885d95bad154ca3692c
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/274131
Reviewed-by: Anton Staaf <robotboy@chromium.org>
-rw-r--r-- | board/discovery-stm32f072/board.c | 14 | ||||
-rw-r--r-- | chip/stm32/usb_gpio.c | 3 | ||||
-rw-r--r-- | chip/stm32/usb_gpio.h | 11 | ||||
-rw-r--r-- | extra/usb_gpio/usb_gpio.c | 7 |
4 files changed, 30 insertions, 5 deletions
diff --git a/board/discovery-stm32f072/board.c b/board/discovery-stm32f072/board.c index c6a9b3c8a3..8303aa6a27 100644 --- a/board/discovery-stm32f072/board.c +++ b/board/discovery-stm32f072/board.c @@ -39,10 +39,22 @@ static enum gpio_signal const usb_gpio_list[] = { GPIO_LED_R, }; +/* + * This instantiates struct usb_gpio_config const usb_gpio, plus several other + * variables, all named something beginning with usb_gpio_ + */ USB_GPIO_CONFIG(usb_gpio, usb_gpio_list, USB_IFACE_GPIO, - USB_EP_GPIO) + USB_EP_GPIO); + +void usb_gpio_tick(void) +{ + if (usb_gpio.state->set_mask || usb_gpio.state->clear_mask) + return; + button_event(0); +} +DECLARE_HOOK(HOOK_TICK, usb_gpio_tick, HOOK_PRIO_DEFAULT); const void *const usb_strings[] = { [USB_STR_DESC] = usb_string_desc, diff --git a/chip/stm32/usb_gpio.c b/chip/stm32/usb_gpio.c index 027ddadaae..43cda832a8 100644 --- a/chip/stm32/usb_gpio.c +++ b/chip/stm32/usb_gpio.c @@ -39,6 +39,9 @@ void usb_gpio_rx(struct usb_gpio_config const *config) (uint32_t)(config->rx_ram[3]) << 16); uint32_t ignore_mask = set_mask & clear_mask; + config->state->set_mask = set_mask; + config->state->clear_mask = clear_mask; + if ((btable_ep[config->endpoint].rx_count & 0x3ff) == USB_GPIO_RX_PACKET_SIZE) { for (i = 0; i < config->num_gpios; ++i, mask <<= 1) { diff --git a/chip/stm32/usb_gpio.h b/chip/stm32/usb_gpio.h index 2027df9d21..56f3d72c57 100644 --- a/chip/stm32/usb_gpio.h +++ b/chip/stm32/usb_gpio.h @@ -10,12 +10,19 @@ #include "compile_time_macros.h" #include "usb.h" +struct usb_gpio_state { + uint32_t set_mask; + uint32_t clear_mask; +}; + /* * Compile time Per-USB gpio configuration stored in flash. Instances of this * structure are provided by the user of the USB gpio. This structure binds * together all information required to operate a USB gpio. */ struct usb_gpio_config { + struct usb_gpio_state *state; + /* * Endpoint index, and pointers to the USB packet RAM buffers. */ @@ -55,6 +62,7 @@ struct usb_gpio_config { static usb_uint CONCAT2(NAME, _ep_rx_buffer)[USB_GPIO_RX_PACKET_SIZE / 2] __usb_ram; \ static usb_uint CONCAT2(NAME, _ep_tx_buffer)[USB_GPIO_TX_PACKET_SIZE / 2] __usb_ram; \ struct usb_gpio_config const NAME = { \ + .state = &((struct usb_gpio_state){}), \ .endpoint = ENDPOINT, \ .rx_ram = CONCAT2(NAME, _ep_rx_buffer), \ .tx_ram = CONCAT2(NAME, _ep_tx_buffer), \ @@ -106,7 +114,8 @@ struct usb_gpio_config { USB_DECLARE_EP(ENDPOINT, \ CONCAT2(NAME, _ep_tx), \ CONCAT2(NAME, _ep_rx), \ - CONCAT2(NAME, _ep_reset)); + CONCAT2(NAME, _ep_reset)) + /* * These functions are used by the trampoline functions defined above to diff --git a/extra/usb_gpio/usb_gpio.c b/extra/usb_gpio/usb_gpio.c index 6c6d464963..70cf4a81c2 100644 --- a/extra/usb_gpio/usb_gpio.c +++ b/extra/usb_gpio/usb_gpio.c @@ -109,8 +109,9 @@ int main(int argc, char **argv) { libusb_context *context; libusb_device_handle *device; - uint16_t vendor_id = 0x18d1; - uint16_t product_id = 0x500f; + uint16_t vendor_id = 0x18d1; /* Google */ + uint16_t product_id = 0x500f; /* discovery-stm32f072 */ + int interface = 1; /* gpio interface */ if (!(argc == 2 && strcmp(argv[1], "read") == 0) && !(argc == 4 && strcmp(argv[1], "write") == 0)) { @@ -134,7 +135,7 @@ int main(int argc, char **argv) } CHECK(libusb_set_auto_detach_kernel_driver(device, 1)); - CHECK(libusb_claim_interface(device, 0)); + CHECK(libusb_claim_interface(device, interface)); if (argc == 2 && strcmp(argv[1], "read") == 0) { uint32_t mask; |