Skip to content

Commit 7a3998d

Browse files
committed
cirrus: cp9314: Migrates CP9314 sample app
Moves CP9314 sample application from zephyr-drivers into the zephyr-demos workspace. Signed-off-by: Ricardo Rivera-Matos <[email protected]>
1 parent 94bd8c7 commit 7a3998d

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

cirrus/cp9314/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(cp9314)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024 Cirrus Logic, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/gpio/gpio.h>
8+
#include <zephyr/dt-bindings/i2c/i2c.h>
9+
10+
&arduino_i2c {
11+
status = "okay";
12+
clock-frequency = <I2C_BITRATE_STANDARD>;
13+
14+
cp9314: cp9314@72 {
15+
compatible = "cirrus,cp9314";
16+
reg = <0x72>;
17+
status = "okay";
18+
19+
cirrus,initial-switched-capacitor-mode = "2:1";
20+
21+
cirrus,en-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>;
22+
};
23+
24+
cp9314_dev2: cp9314@73 {
25+
compatible = "cirrus,cp9314";
26+
reg = <0x73>;
27+
status = "okay";
28+
29+
cirrus,initial-switched-capacitor-mode = "2:1";
30+
31+
cirrus,en-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>;
32+
};
33+
};

cirrus/cp9314/prj.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_I2C=y
2+
CONFIG_LOG=y
3+
CONFIG_REGULATOR=y
4+
CONFIG_REGULATOR_CP9314=y
5+
CONFIG_CBPRINTF_FP_SUPPORT=y

cirrus/cp9314/src/main.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2024 Cirrus Logic, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "zephyr/sys/printk.h"
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/device.h>
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/drivers/regulator.h>
12+
13+
int main(void)
14+
{
15+
const struct device *dev2 = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cp9314_dev2));
16+
const struct device *host = DEVICE_DT_GET(DT_NODELABEL(cp9314));
17+
regulator_error_flags_t flags;
18+
int ret;
19+
20+
if (host == NULL) {
21+
printk("No host CP9314 found...\n");
22+
return -EIO;
23+
} else if (dev2 == NULL) {
24+
printk("No secondary CP9314 found, assuming standalone operation\n");
25+
}
26+
27+
if (!device_is_ready(host)) {
28+
printk("\nError: Device \"%s\" is not ready; "
29+
"check the driver initialization logs for errors.\n",
30+
host->name);
31+
return -EIO;
32+
}
33+
34+
printk("Found device \"%s\", getting regulator data\n", host->name);
35+
36+
if (dev2) {
37+
if (!device_is_ready(dev2)) {
38+
printk("\nError: Device \"%s\" is not ready; "
39+
"check the driver initialization logs for errors.\n",
40+
dev2->name);
41+
return -EIO;
42+
}
43+
44+
printk("Found device \"%s\", getting regulator data\n", dev2->name);
45+
}
46+
47+
while (1) {
48+
printk("Found device %s\n", host->name);
49+
if (dev2) {
50+
printk("Found device %s\n", dev2->name);
51+
}
52+
53+
ret = regulator_enable(host);
54+
if (ret == -EINVAL) {
55+
ret = regulator_get_error_flags(host, &flags);
56+
printk("Regulator fault detected: 0x%x\n", flags);
57+
return ret;
58+
} else if (ret < 0) {
59+
printk("I/O Error enabling regulator: %d\n", ret);
60+
return ret;
61+
}
62+
63+
if (dev2) {
64+
ret = regulator_enable(dev2);
65+
if (ret == -EINVAL) {
66+
ret = regulator_get_error_flags(dev2, &flags);
67+
printk("Regulator fault detected: 0x%x\n", flags);
68+
return ret;
69+
} else if (ret < 0) {
70+
printk("I/O Error enabling regulator: %d\n", ret);
71+
return ret;
72+
}
73+
}
74+
75+
printk("Converter(s) enabled\n");
76+
77+
k_sleep(K_SECONDS(10));
78+
79+
if (dev2) {
80+
ret = regulator_disable(dev2);
81+
if (ret < 0) {
82+
printk("Error disabling regulator: %d\n", ret);
83+
return ret;
84+
}
85+
}
86+
87+
ret = regulator_disable(host);
88+
if (ret < 0) {
89+
printk("Error disabling regulator: %d\n", ret);
90+
return ret;
91+
}
92+
93+
printk("Converter(s) disabled\n");
94+
95+
k_sleep(K_SECONDS(10));
96+
}
97+
98+
return 0;
99+
}

0 commit comments

Comments
 (0)