Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,53 @@ ENC28J60 SPI ethernet controller supports:
* - RESET
- GP10 (Pin 14)

husb238
-------

NuttShell configuration (console enabled in USB Port, at 115200 bps) with support for Hynetek HUSB238 USB Type-C
Power Delivery Sink Controller connected via I2C:

.. list-table:: HUSB238 connections
:widths: auto
:header-rows: 1

* - HUSB238
- Raspberry Pi Pico
* - GND
- GND (Pin 3 or 38 or ...)
* - SDA
- GP4 (I2C0 SDA) (Pin 6)
* - SCL
- GP5 (I2C0 SCL) (Pin 7)
* - Other pins as per datasheet
- N/A

.. code-block:: console

nsh> husb238
--- PD Status 0 ---
Source voltage: 12V
Source current: 1.25A

--- PD Status 1 ---
CC Direction: CC1 is connected to CC line or unattached mode
Attached: HUSB238 is in modes other than unattached mode
PD Response: Success
5V Voltage: 5V
5V Current: 3.0A

--- PDOs ---
5V: Detected (1.00A)
9V: Detected (1.00A)
12V: Detected (1.00A)
15V: Detected (1.00A)
18V: Not detected
20V: Detected (2.25A)

--- Selected PDO ---
Selected PDO: None
nsh>

lcd1602
-------

Expand Down
87 changes: 87 additions & 0 deletions boards/arm/rp2040/common/include/rp2040_husb238.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/****************************************************************************
* boards/arm/rp2040/common/include/rp2040_husb238.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

#ifndef __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_HUSB238_H
#define __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_HUSB238_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/i2c/i2c_master.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Type Definitions
****************************************************************************/

/****************************************************************************
* Public Types
****************************************************************************/

/****************************************************************************
* Public Data
****************************************************************************/

#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif

/****************************************************************************
* Inline Functions
****************************************************************************/

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

/****************************************************************************
* Name: board_husb238_initialize
*
* Description:
* Initialize and register the HUSB238 USB-C PD sink controller.
*
* Input Parameters:
* i2c - An instance of the I2C interface to use.
* devno - The device number, used to build the device path as /dev/usbpdN.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/

int board_husb238_initialize(FAR struct i2c_master_s *i2c, int devno);

#undef EXTERN
#ifdef __cplusplus
}
#endif

#endif /* __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_HUSB238_H */
4 changes: 4 additions & 0 deletions boards/arm/rp2040/common/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ ifeq ($(CONFIG_ADC_ADS7046),y)
CSRCS += rp2040_ads7046.c
endif

ifeq ($(CONFIG_USBPD_HUSB238),y)
CSRCS += rp2040_husb238.c
endif

DEPPATH += --dep-path src
VPATH += :src
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
Expand Down
18 changes: 18 additions & 0 deletions boards/arm/rp2040/common/src/rp2040_common_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
#include "rp2040_ads7046.h"
#endif

#ifdef CONFIG_USBPD_HUSB238
#include <nuttx/power/husb238.h>
#include "rp2040_husb238.h"
#include "rp2040_i2c.h"
#endif

#if defined(CONFIG_RP2040_BOARD_HAS_WS2812) && defined(CONFIG_WS2812)
#include "rp2040_ws2812.h"
#endif
Expand Down Expand Up @@ -797,5 +803,17 @@ int rp2040_common_bringup(void)
}

#endif

#ifdef CONFIG_USBPD_HUSB238
/* Try to register HUSB238 device at I2C0 */

ret = board_husb238_initialize(rp2040_i2cbus_initialize(0), 0);

if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize HUSB238 driver: %d\n", ret);
}
#endif

return ret;
}
104 changes: 104 additions & 0 deletions boards/arm/rp2040/common/src/rp2040_husb238.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/****************************************************************************
* boards/arm/rp2040/common/src/rp2040_husb238.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include <stdio.h>
#include <debug.h>

#include <nuttx/arch.h>
#include <nuttx/power/husb238.h>

#include "rp2040_i2c.h"
#include "rp2040_husb238.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Private Types
****************************************************************************/

/****************************************************************************
* Private Function Prototypes
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

/****************************************************************************
* Public Data
****************************************************************************/

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: board_husb238_initialize
*
* Description:
* Initialize and register the HUSB238 USB-C PD sink controller.
*
* Input Parameters:
* i2c - An instance of the I2C interface to use.
* devno - The device number, used to build the device path as /dev/usbpdN.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/

int board_husb238_initialize(FAR struct i2c_master_s *i2c, int devno)
{
char devpath[12];
int ret;

pwrinfo("Initializing HUSB238\n");

if (i2c)
{
snprintf(devpath, sizeof(devpath), "/dev/usbpd%d", devno);
ret = husb238_register(devpath, i2c);
if (ret < 0)
{
pwrerr("ERROR: Error registering HUSB238 at /dev/usbpd%d\n",
devno);
}
}
else
{
ret = -ENODEV;
}

return ret;
}
56 changes: 56 additions & 0 deletions boards/arm/rp2040/raspberrypi-pico/configs/husb238/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DEV_CONSOLE is not set
# CONFIG_LIBC_LONG_LONG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_DATE is not set
# CONFIG_NSH_DISABLE_LOSMART is not set
# CONFIG_RP2040_UART0 is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="raspberrypi-pico"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y
CONFIG_ARCH_CHIP="rp2040"
CONFIG_ARCH_CHIP_RP2040=y
CONFIG_ARCH_RAMVECTORS=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=10450
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_CDCACM_CONSOLE=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_HUSB238=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_READLINE=y
CONFIG_NSH_USBCONSOLE=y
CONFIG_RAM_SIZE=270336
CONFIG_RAM_START=0x20000000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RP2040_I2C0=y
CONFIG_RP2040_I2C=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=9
CONFIG_START_MONTH=2
CONFIG_START_YEAR=2021
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_USBDEV=y
CONFIG_USBDEV_BUSPOWERED=y
CONFIG_USBPD_HUSB238=y
4 changes: 4 additions & 0 deletions drivers/power/supply/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ if(CONFIG_REGULATOR)

endif()

if(CONFIG_USBPD_HUSB238)
list(APPEND SRCS husb238.c)
endif()

target_sources(drivers PRIVATE ${SRCS})
16 changes: 16 additions & 0 deletions drivers/power/supply/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,20 @@ endif # REGULATOR_ACT8945A

endif # REGULATOR

config USBPD_HUSB238
bool "Hynetek HUSB238 USB-C PD Sink Controller support"
default n
select I2C
---help---
Enable driver support for the Hynetek HUSB238 USB Type-C
Power Delivery (PD) sink controller.

if USBPD_HUSB238

config USBPD_HUSB238_I2C_FREQUENCY
int "HUSB238 I2C frequency"
default 400000

endif # USBPD_HUSB238

endmenu
4 changes: 4 additions & 0 deletions drivers/power/supply/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ ifeq ($(CONFIG_REGULATOR_ACT8945A), y)
CSRCS += act8945a.c
endif

endif # CONFIG_REGULATOR

ifeq ($(CONFIG_USBPD_HUSB238), y)
CSRCS += husb238.c
endif

DEPPATH += --dep-path power/supply
Expand Down
Loading
Loading