| // Copyright 2017-2018 The Fuchsia Authors. All rights reserved. |
| // |
| // Redistribution and use in source and binary forms, with or without |
| // modification, are permitted provided that the following conditions are |
| // met: |
| // |
| // * Redistributions of source code must retain the above copyright |
| // notice, this list of conditions and the following disclaimer. |
| // * Redistributions in binary form must reproduce the above |
| // copyright notice, this list of conditions and the following disclaimer |
| // in the documentation and/or other materials provided with the |
| // distribution. |
| // * Neither the name of Google Inc. nor the names of its |
| // contributors may be used to endorse or promote products derived from |
| // this software without specific prior written permission. |
| // |
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| #include <app/zedmon/ina.h> |
| #include <err.h> |
| #include <debug.h> |
| #include <target.h> |
| #include <compiler.h> |
| #include <dev/gpio.h> |
| #include <dev/i2c.h> |
| #include <lib/console.h> |
| #include <platform.h> |
| #include <platform/exti.h> |
| #include <platform/gpio.h> |
| #include <platform/stm32.h> |
| #include <platform/usbc.h> |
| #include <target/gpioconfig.h> |
| #include <target/usb.h> |
| |
| int irqs; |
| bool stm32_exti2_irq(void) { |
| irqs++; |
| return ina_alert_irq(0, current_time_hires()); |
| } |
| |
| uint64_t ina_get_current_time(void) { |
| return current_time_hires(); |
| } |
| |
| |
| void target_early_init(void) |
| { |
| gpio_config(GPIO_UART_TX, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| gpio_config(GPIO_UART_RX, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| |
| gpio_config(GPIO_SCL, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| gpio_config(GPIO_SDA, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| |
| gpio_config(GPIO_VBUS_ALERT_L, GPIO_INPUT | GPIO_PULLUP); |
| gpio_config(GPIO_CC2_ALERT_L, GPIO_INPUT | GPIO_PULLUP); |
| |
| |
| gpio_set(GPIO_LED_RED, 1); |
| gpio_set(GPIO_LED_GREEN, 1); |
| gpio_set(GPIO_LED_BLUE, 1); |
| |
| gpio_config(GPIO_LED_RED, GPIO_OUTPUT | GPIO_STM32_OD); |
| gpio_config(GPIO_LED_GREEN, GPIO_OUTPUT | GPIO_STM32_OD); |
| gpio_config(GPIO_LED_BLUE, GPIO_OUTPUT | GPIO_STM32_OD); |
| |
| stm32_debug_early_init(); |
| i2c_init_early(); |
| |
| stm32_setup_ext_interrupt(2, EXT_INTERRUPT_PORT_B, false, true); |
| } |
| |
| void target_init(void) |
| { |
| stm32_debug_init(); |
| i2c_init(); |
| stm32_usbc_init(); |
| target_usb_setup(); |
| |
| printf("twinkie online.\n"); |
| } |
| |
| void target_set_debug_led(unsigned int led, bool on) |
| { |
| switch (led) { |
| case 0: |
| //gpio_set(GPIO_LED_RED, !on); |
| break; |
| } |
| } |
| |
| static int cmd_led(int argc, const cmd_args *argv) { |
| if (argc != 4) { |
| printf("usage: led <r> <g> <b>\n"); |
| return 1; |
| } |
| |
| gpio_set(GPIO_LED_RED, !argv[1].b); |
| gpio_set(GPIO_LED_GREEN, !argv[2].b); |
| gpio_set(GPIO_LED_BLUE, !argv[3].b); |
| |
| return 0; |
| } |
| |
| #include <stm32f0xx.h> |
| |
| static int cmd_irqs(int argc, const cmd_args *argv) { |
| printf("%d\n", irqs); |
| printf("state: %d\n", gpio_get(GPIO_VBUS_ALERT_L)); |
| printf("%08x:%08x\n", &SYSCFG->EXTICR[0], SYSCFG->EXTICR[0]); |
| |
| return 0; |
| } |
| |
| |
| STATIC_COMMAND_START |
| STATIC_COMMAND("led", "set led r, g, b.", &cmd_led) |
| STATIC_COMMAND("irqs", ".", &cmd_irqs) |
| STATIC_COMMAND_END(zedmon); |