Skip to content

cirrus: cp9314: Migrates CP9314 sample app #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions cirrus/cp9314/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(cp9314)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
33 changes: 33 additions & 0 deletions cirrus/cp9314/boards/nucleo_f401re.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 Cirrus Logic, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/gpio/gpio.h>
#include <zephyr/dt-bindings/i2c/i2c.h>

&arduino_i2c {
status = "okay";
clock-frequency = <I2C_BITRATE_STANDARD>;

cp9314: cp9314@72 {
compatible = "cirrus,cp9314";
reg = <0x72>;
status = "okay";

cirrus,initial-switched-capacitor-mode = "2:1";

cirrus,en-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>;
};

cp9314_dev2: cp9314@73 {
compatible = "cirrus,cp9314";
reg = <0x73>;
status = "okay";

cirrus,initial-switched-capacitor-mode = "2:1";

cirrus,en-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>;
};
};
5 changes: 5 additions & 0 deletions cirrus/cp9314/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_I2C=y
CONFIG_LOG=y
CONFIG_REGULATOR=y
CONFIG_REGULATOR_CP9314=y
CONFIG_CBPRINTF_FP_SUPPORT=y
99 changes: 99 additions & 0 deletions cirrus/cp9314/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024 Cirrus Logic, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "zephyr/sys/printk.h"
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/regulator.h>

int main(void)
{
const struct device *dev2 = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cp9314_dev2));
const struct device *host = DEVICE_DT_GET(DT_NODELABEL(cp9314));
regulator_error_flags_t flags;
int ret;

if (host == NULL) {
printk("No host CP9314 found...\n");
return -EIO;
} else if (dev2 == NULL) {
printk("No secondary CP9314 found, assuming standalone operation\n");
}

if (!device_is_ready(host)) {
printk("\nError: Device \"%s\" is not ready; "
"check the driver initialization logs for errors.\n",
host->name);
return -EIO;
}

printk("Found device \"%s\", getting regulator data\n", host->name);

if (dev2) {
if (!device_is_ready(dev2)) {
printk("\nError: Device \"%s\" is not ready; "
"check the driver initialization logs for errors.\n",
dev2->name);
return -EIO;
}

printk("Found device \"%s\", getting regulator data\n", dev2->name);
}

while (1) {
printk("Found device %s\n", host->name);
if (dev2) {
printk("Found device %s\n", dev2->name);
}

ret = regulator_enable(host);
if (ret == -EINVAL) {
ret = regulator_get_error_flags(host, &flags);
printk("Regulator fault detected: 0x%x\n", flags);
return ret;
} else if (ret < 0) {
printk("I/O Error enabling regulator: %d\n", ret);
return ret;
}

if (dev2) {
ret = regulator_enable(dev2);
if (ret == -EINVAL) {
ret = regulator_get_error_flags(dev2, &flags);
printk("Regulator fault detected: 0x%x\n", flags);
return ret;
} else if (ret < 0) {
printk("I/O Error enabling regulator: %d\n", ret);
return ret;
}
}

printk("Converter(s) enabled\n");

k_sleep(K_SECONDS(10));

if (dev2) {
ret = regulator_disable(dev2);
if (ret < 0) {
printk("Error disabling regulator: %d\n", ret);
return ret;
}
}

ret = regulator_disable(host);
if (ret < 0) {
printk("Error disabling regulator: %d\n", ret);
return ret;
}

printk("Converter(s) disabled\n");

k_sleep(K_SECONDS(10));
}

return 0;
}