summaryrefslogtreecommitdiff
path: root/board/fusb307bgevb/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/fusb307bgevb/board.c')
-rw-r--r--board/fusb307bgevb/board.c121
1 files changed, 52 insertions, 69 deletions
diff --git a/board/fusb307bgevb/board.c b/board/fusb307bgevb/board.c
index f3f4da1a74..1388aef49a 100644
--- a/board/fusb307bgevb/board.c
+++ b/board/fusb307bgevb/board.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -24,8 +24,8 @@
#include "usb_common.h"
#include "util.h"
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ##args)
static void tcpc_alert_event(enum gpio_signal signal)
{
@@ -72,10 +72,13 @@ static void button_refresh_event_deferred(void)
/* Display supply voltage on first page. */
lcd_clear();
for (i = 0; i < MIN(pd_get_src_cap_cnt(0), 4); i++) {
+ int rv;
pd_extract_pdo_power(pd_get_src_caps(0)[i], &ma, &mv, &unused);
- snprintf(c, ARRAY_SIZE(c), "[%d] %dmV %dmA", i, mv, ma);
- lcd_set_cursor(0, i);
- lcd_print_string(c);
+ rv = snprintf(c, ARRAY_SIZE(c), "[%d] %dmV %dmA", i, mv, ma);
+ if (rv > 0) {
+ lcd_set_cursor(0, i);
+ lcd_print_string(c);
+ }
}
/* Display selector */
@@ -107,21 +110,29 @@ static void button_down_event_deferred(void)
if (count == 0) {
lcd_clear();
for (i = 0; i < MIN(pd_get_src_cap_cnt(0), 4); i++) {
+ int rv;
pd_extract_pdo_power(pd_get_src_caps(0)[i], &ma, &mv,
&unused);
- snprintf(c, ARRAY_SIZE(c), "[%d] %dmV %dmA", i, mv, ma);
- lcd_set_cursor(0, i);
- lcd_print_string(c);
+ rv = snprintf(c, ARRAY_SIZE(c), "[%d] %dmV %dmA", i, mv,
+ ma);
+ if (rv > 0) {
+ lcd_set_cursor(0, i);
+ lcd_print_string(c);
+ }
}
}
if (count == 4) {
lcd_clear();
for (i = 4; i < pd_get_src_cap_cnt(0); i++) {
+ int rv;
pd_extract_pdo_power(pd_get_src_caps(0)[i], &ma, &mv,
&unused);
- snprintf(c, ARRAY_SIZE(c), "[%d] %dmV %dmA", i, mv, ma);
- lcd_set_cursor(0, i - 4);
- lcd_print_string(c);
+ rv = snprintf(c, ARRAY_SIZE(c), "[%d] %dmV %dmA", i, mv,
+ ma);
+ if (rv > 0) {
+ lcd_set_cursor(0, i - 4);
+ lcd_print_string(c);
+ }
}
}
@@ -156,20 +167,15 @@ static enum gpio_signal const usb_gpio_list[] = {
* 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_GPIO_CONFIG(usb_gpio, usb_gpio_list, USB_IFACE_GPIO, USB_EP_GPIO);
/******************************************************************************
* Setup USART1 as a loopback device, it just echo's back anything sent to it.
*/
static struct usart_config const loopback_usart;
-static struct queue const loopback_queue =
- QUEUE_DIRECT(64, uint8_t,
- loopback_usart.producer,
- loopback_usart.consumer);
+static struct queue const loopback_queue = QUEUE_DIRECT(
+ 64, uint8_t, loopback_usart.producer, loopback_usart.consumer);
static struct usart_rx_dma const loopback_rx_dma =
USART_RX_DMA(STM32_DMAC_CH3, 8);
@@ -177,14 +183,9 @@ static struct usart_rx_dma const loopback_rx_dma =
static struct usart_tx_dma const loopback_tx_dma =
USART_TX_DMA(STM32_DMAC_CH2, 16);
-static struct usart_config const loopback_usart =
- USART_CONFIG(usart1_hw,
- loopback_rx_dma.usart_rx,
- loopback_tx_dma.usart_tx,
- 115200,
- 0,
- loopback_queue,
- loopback_queue);
+static struct usart_config const loopback_usart = USART_CONFIG(
+ usart1_hw, loopback_rx_dma.usart_rx, loopback_tx_dma.usart_tx, 115200,
+ 0, loopback_queue, loopback_queue);
/******************************************************************************
* Forward USART4 as a simple USB serial interface.
@@ -192,46 +193,34 @@ static struct usart_config const loopback_usart =
static struct usart_config const forward_usart;
struct usb_stream_config const forward_usb;
-static struct queue const usart_to_usb = QUEUE_DIRECT(64, uint8_t,
- forward_usart.producer,
- forward_usb.consumer);
-static struct queue const usb_to_usart = QUEUE_DIRECT(64, uint8_t,
- forward_usb.producer,
- forward_usart.consumer);
+static struct queue const usart_to_usb =
+ QUEUE_DIRECT(64, uint8_t, forward_usart.producer, forward_usb.consumer);
+static struct queue const usb_to_usart =
+ QUEUE_DIRECT(64, uint8_t, forward_usb.producer, forward_usart.consumer);
static struct usart_tx_dma const forward_tx_dma =
USART_TX_DMA(STM32_DMAC_CH7, 16);
static struct usart_config const forward_usart =
- USART_CONFIG(usart4_hw,
- usart_rx_interrupt,
- forward_tx_dma.usart_tx,
- 115200,
- 0,
- usart_to_usb,
- usb_to_usart);
-
-#define USB_STREAM_RX_SIZE 16
-#define USB_STREAM_TX_SIZE 16
-
-USB_STREAM_CONFIG(forward_usb,
- USB_IFACE_STREAM,
- USB_STR_STREAM_NAME,
- USB_EP_STREAM,
- USB_STREAM_RX_SIZE,
- USB_STREAM_TX_SIZE,
- usb_to_usart,
- usart_to_usb)
+ USART_CONFIG(usart4_hw, usart_rx_interrupt, forward_tx_dma.usart_tx,
+ 115200, 0, usart_to_usb, usb_to_usart);
+
+#define USB_STREAM_RX_SIZE 16
+#define USB_STREAM_TX_SIZE 16
+
+USB_STREAM_CONFIG(forward_usb, USB_IFACE_STREAM, USB_STR_STREAM_NAME,
+ USB_EP_STREAM, USB_STREAM_RX_SIZE, USB_STREAM_TX_SIZE,
+ usb_to_usart, usart_to_usb)
/******************************************************************************
* Define the strings used in our USB descriptors.
*/
const void *const usb_strings[] = {
- [USB_STR_DESC] = usb_string_desc,
- [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
- [USB_STR_PRODUCT] = USB_STRING_DESC("fusb307bgevb"),
- [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
- [USB_STR_STREAM_NAME] = USB_STRING_DESC("Forward"),
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google LLC"),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("fusb307bgevb"),
+ [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+ [USB_STR_STREAM_NAME] = USB_STRING_DESC("Forward"),
[USB_STR_CONSOLE_NAME] = USB_STRING_DESC("Shell"),
};
@@ -240,15 +229,11 @@ BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
/******************************************************************************
* I2C interface.
*/
-const struct i2c_port_t i2c_ports[] = {
- {
- .name = "tcpc",
- .port = I2C_PORT_TCPC,
- .kbps = 400 /* kHz */,
- .scl = GPIO_I2C2_SCL,
- .sda = GPIO_I2C2_SDA
- }
-};
+const struct i2c_port_t i2c_ports[] = { { .name = "tcpc",
+ .port = I2C_PORT_TCPC,
+ .kbps = 400 /* kHz */,
+ .scl = GPIO_I2C2_SCL,
+ .sda = GPIO_I2C2_SDA } };
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/******************************************************************************
@@ -265,7 +250,6 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
},
};
-
uint16_t tcpc_get_alert_status(void)
{
uint16_t status = 0;
@@ -329,6 +313,5 @@ static void board_init(void)
queue_init(&usb_to_usart);
usart_init(&loopback_usart);
usart_init(&forward_usart);
-
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);