diff options
Diffstat (limited to 'board/fusb307bgevb')
-rw-r--r-- | board/fusb307bgevb/board.c | 121 | ||||
-rw-r--r-- | board/fusb307bgevb/board.h | 24 | ||||
-rw-r--r-- | board/fusb307bgevb/build.mk | 2 | ||||
-rw-r--r-- | board/fusb307bgevb/ec.tasklist | 2 | ||||
-rw-r--r-- | board/fusb307bgevb/gpio.inc | 2 | ||||
-rw-r--r-- | board/fusb307bgevb/lcd.c | 18 | ||||
-rw-r--r-- | board/fusb307bgevb/lcd.h | 68 |
7 files changed, 111 insertions, 126 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); diff --git a/board/fusb307bgevb/board.h b/board/fusb307bgevb/board.h index 3495f7125f..5e45b346b7 100644 --- a/board/fusb307bgevb/board.h +++ b/board/fusb307bgevb/board.h @@ -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. */ @@ -8,6 +8,7 @@ #ifndef __CROS_EC_BOARD_H #define __CROS_EC_BOARD_H +#define CONFIG_LTO /* 48 MHz SYSCLK clock frequency */ #define CPU_CLOCK 48000000 @@ -56,11 +57,11 @@ #define PD_OPERATING_POWER_MW 15000 #define PD_MAX_VOLTAGE_MV 20000 #define PD_MAX_CURRENT_MA 3000 -#define PD_MAX_POWER_MW ((PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA) / 1000) +#define PD_MAX_POWER_MW ((PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA) / 1000) /* Degine board specific type-C power constants */ #define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */ -#define PD_POWER_SUPPLY_TURN_ON_DELAY 160000 /* us */ +#define PD_POWER_SUPPLY_TURN_ON_DELAY 160000 /* us */ /* I2C master port connected to the TCPC */ #define I2C_PORT_TCPC 1 @@ -69,23 +70,24 @@ #define LCD_SLAVE_ADDR 0x27 /* USB interface indexes (use define rather than enum to expand them) */ -#define USB_IFACE_STREAM 0 -#define USB_IFACE_GPIO 1 -#define USB_IFACE_SPI 2 +#define USB_IFACE_STREAM 0 +#define USB_IFACE_GPIO 1 +#define USB_IFACE_SPI 2 #define USB_IFACE_CONSOLE 3 -#define USB_IFACE_COUNT 4 +#define USB_IFACE_COUNT 4 /* USB endpoint indexes (use define rather than enum to expand them) */ #define USB_EP_CONTROL 0 -#define USB_EP_STREAM 1 -#define USB_EP_GPIO 2 -#define USB_EP_SPI 3 +#define USB_EP_STREAM 1 +#define USB_EP_GPIO 2 +#define USB_EP_SPI 3 #define USB_EP_CONSOLE 4 -#define USB_EP_COUNT 5 +#define USB_EP_COUNT 5 /* Enable control of GPIOs over USB */ #define CONFIG_USB_GPIO +#undef CONFIG_CMD_GETTIME #undef CONFIG_WATCHDOG_HELP #undef CONFIG_LID_SWITCH diff --git a/board/fusb307bgevb/build.mk b/board/fusb307bgevb/build.mk index 1372562107..923b144165 100644 --- a/board/fusb307bgevb/build.mk +++ b/board/fusb307bgevb/build.mk @@ -1,5 +1,5 @@ # -*- makefile -*- -# 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. # diff --git a/board/fusb307bgevb/ec.tasklist b/board/fusb307bgevb/ec.tasklist index e25b8f7a68..bca2d075be 100644 --- a/board/fusb307bgevb/ec.tasklist +++ b/board/fusb307bgevb/ec.tasklist @@ -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. */ diff --git a/board/fusb307bgevb/gpio.inc b/board/fusb307bgevb/gpio.inc index 16a845576d..ba3b84fb08 100644 --- a/board/fusb307bgevb/gpio.inc +++ b/board/fusb307bgevb/gpio.inc @@ -1,6 +1,6 @@ /* -*- mode:c -*- * - * 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. */ diff --git a/board/fusb307bgevb/lcd.c b/board/fusb307bgevb/lcd.c index 892888329e..f907de7462 100644 --- a/board/fusb307bgevb/lcd.c +++ b/board/fusb307bgevb/lcd.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. * @@ -26,17 +26,17 @@ static struct lcd_state_info state = { /* write either command or data */ static void expander_write(uint8_t data) { - i2c_write8(I2C_PORT_TCPC, LCD_SLAVE_ADDR, 0x00, data | - state.backlightval); + i2c_write8(I2C_PORT_TCPC, LCD_SLAVE_ADDR, 0x00, + data | state.backlightval); } static void pulse_enable(uint8_t data) { - expander_write(data | LCD_EN);/* En high */ - usleep(1); /* enable pulse must be >450ns */ + expander_write(data | LCD_EN); /* En high */ + usleep(1); /* enable pulse must be >450ns */ - expander_write(data & ~LCD_EN);/* En low */ - usleep(50); /* commands need > 37us to settle */ + expander_write(data & ~LCD_EN); /* En low */ + usleep(50); /* commands need > 37us to settle */ } static void write_4bits(uint8_t value) @@ -63,8 +63,8 @@ static void command(uint8_t value) /********** high level commands, for the user! */ void lcd_clear(void) { - command(LCD_CLEAR_DISPLAY);/* clear display, set cursor to zero */ - usleep(2000); /* this command takes a long time! */ + command(LCD_CLEAR_DISPLAY); /* clear display, set cursor to zero */ + usleep(2000); /* this command takes a long time! */ } void lcd_set_cursor(uint8_t col, uint8_t row) diff --git a/board/fusb307bgevb/lcd.h b/board/fusb307bgevb/lcd.h index 21b0ee9ce9..9ed773d92f 100644 --- a/board/fusb307bgevb/lcd.h +++ b/board/fusb307bgevb/lcd.h @@ -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. * @@ -11,50 +11,50 @@ #include "common.h" /* commands */ -#define LCD_CLEAR_DISPLAY BIT(0) -#define LCD_RETURN_HOME BIT(1) -#define LCD_ENTRYMODE_SET BIT(2) -#define LCD_DISPLAY_CONTROL BIT(3) -#define LCD_CURSOR_SHIFT BIT(4) -#define LCD_FUNCTION_SET BIT(5) -#define LCD_SET_CGRAMADDR BIT(6) -#define LCD_SET_DDRAMADDR BIT(7) +#define LCD_CLEAR_DISPLAY BIT(0) +#define LCD_RETURN_HOME BIT(1) +#define LCD_ENTRYMODE_SET BIT(2) +#define LCD_DISPLAY_CONTROL BIT(3) +#define LCD_CURSOR_SHIFT BIT(4) +#define LCD_FUNCTION_SET BIT(5) +#define LCD_SET_CGRAMADDR BIT(6) +#define LCD_SET_DDRAMADDR BIT(7) /* flags for display entry mode */ -#define LCD_ENTRY_RIGHT 0x00 -#define LCD_ENTRY_LEFT BIT(1) -#define LCD_ENTRY_SHIFT_INCREMENT BIT(0) -#define LCD_ENTRY_SHIFT_DECREMENT 0x00 +#define LCD_ENTRY_RIGHT 0x00 +#define LCD_ENTRY_LEFT BIT(1) +#define LCD_ENTRY_SHIFT_INCREMENT BIT(0) +#define LCD_ENTRY_SHIFT_DECREMENT 0x00 /* flags for display on/off control */ -#define LCD_DISPLAY_ON BIT(2) -#define LCD_DISPLAY_OFF 0x00 -#define LCD_CURSOR_ON BIT(1) -#define LCD_CURSOR_OFF 0x00 -#define LCD_BLINK_ON BIT(0) -#define LCD_BLINK_OFF 0x00 +#define LCD_DISPLAY_ON BIT(2) +#define LCD_DISPLAY_OFF 0x00 +#define LCD_CURSOR_ON BIT(1) +#define LCD_CURSOR_OFF 0x00 +#define LCD_BLINK_ON BIT(0) +#define LCD_BLINK_OFF 0x00 /* flags for display/cursor shift */ -#define LCD_DISPLAY_MOVE BIT(3) -#define LCD_CURSOR_MOVE 0x00 -#define LCD_MOVE_RIGHT BIT(2) -#define LCD_MOVE_LEFT 0x00 +#define LCD_DISPLAY_MOVE BIT(3) +#define LCD_CURSOR_MOVE 0x00 +#define LCD_MOVE_RIGHT BIT(2) +#define LCD_MOVE_LEFT 0x00 /* flags for function set */ -#define LCD_8BITMODE BIT(4) -#define LCD_4BITMODE 0x00 -#define LCD_2LINE BIT(3) -#define LCD_1LINE 0x00 -#define LCD_5X10DOTS BIT(2) -#define LCD_5X8DOTS 0x00 +#define LCD_8BITMODE BIT(4) +#define LCD_4BITMODE 0x00 +#define LCD_2LINE BIT(3) +#define LCD_1LINE 0x00 +#define LCD_5X10DOTS BIT(2) +#define LCD_5X8DOTS 0x00 /* flags for backlight control */ -#define LCD_BACKLIGHT BIT(3) -#define LCD_NO_BACKLIGHT 0x00 +#define LCD_BACKLIGHT BIT(3) +#define LCD_NO_BACKLIGHT 0x00 -#define LCD_EN BIT(2) /* Enable bit */ -#define LCD_RW BIT(1) /* Read/Write bit */ -#define LCD_RS BIT(0) /* Register select bit */ +#define LCD_EN BIT(2) /* Enable bit */ +#define LCD_RW BIT(1) /* Read/Write bit */ +#define LCD_RS BIT(0) /* Register select bit */ void lcd_init(uint8_t cols, uint8_t rows, uint8_t dotsize); void lcd_set_cursor(uint8_t col, uint8_t row); |