Skip to content

Commit

Permalink
Merge branch 'feature/z4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
valeros committed Nov 28, 2024
2 parents 810b08c + 5c0f918 commit 6a4b320
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
python-version: "3.10"
- name: Install dependencies
run: |
pip install -U https://github.com/platformio/platformio/archive/develop.zip
Expand Down
28 changes: 15 additions & 13 deletions examples/zephyr-blink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 300
#define SLEEP_TIME_MS 1000

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
Expand All @@ -19,28 +20,29 @@
*/
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

void main(void)
int main(void)
{
int ret;
bool led_state = true;

if (!gpio_is_ready_dt(&led))
{
return;
if (!gpio_is_ready_dt(&led)) {
return 0;
}

ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0)
{
return;
if (ret < 0) {
return 0;
}

while (1)
{
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0)
{
return;
if (ret < 0) {
return 0;
}

led_state = !led_state;
printf("LED state: %s\n", led_state ? "ON" : "OFF");
k_msleep(SLEEP_TIME_MS);
}
return 0;
}
4 changes: 2 additions & 2 deletions examples/zephyr-blink/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(blinky)

target_sources(app PRIVATE ../src/main.c)
4 changes: 2 additions & 2 deletions examples/zephyr-cpp-synchronization/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(cpp_synchronization)

target_sources(app PRIVATE ../src/main.cpp)
10 changes: 5 additions & 5 deletions examples/zephyr-drivers-can/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

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

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(CAN)

target_sources(app PRIVATE ../src/main.c)
FILE(GLOB app_sources ../src/*.c)
target_sources(app PRIVATE ${app_sources})
13 changes: 9 additions & 4 deletions examples/zephyr-net-https-client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ static int connect_socket(sa_family_t family, const char *server, int port,
LOG_ERR("Cannot connect to %s remote (%d)",
family == AF_INET ? "IPv4" : "IPv6",
-errno);
close(*sock);
*sock = -1;
ret = -errno;
}

Expand Down Expand Up @@ -360,20 +362,23 @@ int main(void)
{
int iterations = CONFIG_NET_SAMPLE_SEND_ITERATIONS;
int i = 0;
int ret;
int ret = 0;

while (iterations == 0 || i < iterations) {
ret = run_queries();
if (ret < 0) {
exit(1);
ret = 1;
break;
}

if (iterations > 0) {
i++;
if (i >= iterations) {
ret = 0;
break;
}
} else {
ret = 0;
break;
}
}
Expand All @@ -382,6 +387,6 @@ int main(void)
k_sleep(K_FOREVER);
}

exit(0);
return 0;
exit(ret);
return ret;
}
9 changes: 3 additions & 6 deletions examples/zephyr-net-https-client/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

set (CONF_FILE "prj.conf overlay-tls.conf")

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(http_client)

FILE(GLOB app_sources ../src/*.c)
Expand All @@ -16,4 +13,4 @@ generate_inc_file_for_target(
app
../src/https-cert.der
${gen_dir}/https-cert.der.inc
)
)
22 changes: 16 additions & 6 deletions examples/zephyr-net-https-client/zephyr/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# General config
CONFIG_MAIN_STACK_SIZE=3072
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
Expand All @@ -7,12 +11,19 @@ CONFIG_NET_SHELL=y

# Sockets
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_POLL_MAX=4
CONFIG_ZVFS_POLL_MAX=4
CONFIG_POSIX_API=y

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y

# Network buffers
CONFIG_NET_PKT_RX_COUNT=16
CONFIG_NET_PKT_TX_COUNT=16
CONFIG_NET_BUF_RX_COUNT=128
CONFIG_NET_BUF_TX_COUNT=128
CONFIG_NET_CONTEXT_NET_PKT_POOL=y

# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
Expand All @@ -30,9 +41,8 @@ CONFIG_HTTP_CLIENT=y

# Network debug config
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_NET_LOG=y
CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=n
CONFIG_NET_HTTP_LOG_LEVEL_DBG=y

CONFIG_MAIN_STACK_SIZE=2048
CONFIG_NET_HTTP_LOG_LEVEL_DBG=n
CONFIG_NET_IPV6_LOG_LEVEL_DBG=n
CONFIG_NET_IPV6_ND_LOG_LEVEL_DBG=n
32 changes: 32 additions & 0 deletions examples/zephyr-subsys-usb-hid-mouse/include/sample_usbd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_SAMPLES_SUBSYS_USB_COMMON_SAMPLE_USBD_H
#define ZEPHYR_SAMPLES_SUBSYS_USB_COMMON_SAMPLE_USBD_H

#include <stdint.h>
#include <zephyr/usb/usbd.h>

/*
* The scope of this header is limited to use in USB samples together with the
* new experimental USB device stack, you should not use it in your own
* application. However, you can use the code as a template.
*/

/*
* This function uses Kconfig.sample_usbd options to configure and initialize a
* USB device. It configures sample's device context, default string descriptors,
* USB device configuration, registers any available class instances, and
* finally initializes USB device. It is limited to a single device with a
* single configuration instantiated in sample_usbd_init.c, which should be
* enough for a simple USB device sample.
*
* It returns the configured and initialized USB device context on success,
* otherwise it returns NULL.
*/
struct usbd_context *sample_usbd_init_device(usbd_msg_cb_t msg_cb);

#endif /* ZEPHYR_SAMPLES_SUBSYS_USB_COMMON_SAMPLE_USBD_H */
10 changes: 6 additions & 4 deletions examples/zephyr-subsys-usb-hid-mouse/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ static ALWAYS_INLINE void rwup_if_suspended(void)
}
}

static void input_cb(struct input_event *evt)
static void input_cb(struct input_event *evt, void *user_data)
{
static uint8_t tmp[MOUSE_REPORT_COUNT];

ARG_UNUSED(user_data);

switch (evt->code) {
case INPUT_KEY_0:
rwup_if_suspended();
Expand Down Expand Up @@ -95,7 +97,7 @@ static void input_cb(struct input_event *evt)

}

INPUT_CALLBACK_DEFINE(NULL, input_cb);
INPUT_CALLBACK_DEFINE(NULL, input_cb, NULL);

#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
static int enable_usb_device_next(void)
Expand Down Expand Up @@ -174,11 +176,11 @@ int main(void)
}

while (true) {
uint8_t __aligned(sizeof(void *)) report[MOUSE_REPORT_COUNT];
UDC_STATIC_BUF_DEFINE(report, MOUSE_REPORT_COUNT);

k_msgq_get(&mouse_msgq, &report, K_FOREVER);

ret = hid_int_ep_write(hid_dev, report, sizeof(report), NULL);
ret = hid_int_ep_write(hid_dev, report, MOUSE_REPORT_COUNT, NULL);
if (ret) {
LOG_ERR("HID write error, %d", ret);
} else {
Expand Down
12 changes: 8 additions & 4 deletions examples/zephyr-subsys-usb-hid-mouse/src/sample_usbd_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ USBD_DESC_PRODUCT_DEFINE(sample_product, CONFIG_SAMPLE_USBD_PRODUCT);
USBD_DESC_SERIAL_NUMBER_DEFINE(sample_sn);
/* doc string instantiation end */

USBD_DESC_CONFIG_DEFINE(fs_cfg_desc, "FS Configuration");
USBD_DESC_CONFIG_DEFINE(hs_cfg_desc, "HS Configuration");

/* doc configuration instantiation start */
static const uint8_t attributes = (IS_ENABLED(CONFIG_SAMPLE_USBD_SELF_POWERED) ?
USB_SCD_SELF_POWERED : 0) |
Expand All @@ -42,12 +45,12 @@ static const uint8_t attributes = (IS_ENABLED(CONFIG_SAMPLE_USBD_SELF_POWERED) ?
/* Full speed configuration */
USBD_CONFIGURATION_DEFINE(sample_fs_config,
attributes,
CONFIG_SAMPLE_USBD_MAX_POWER);
CONFIG_SAMPLE_USBD_MAX_POWER, &fs_cfg_desc);

/* High speed configuration */
USBD_CONFIGURATION_DEFINE(sample_hs_config,
attributes,
CONFIG_SAMPLE_USBD_MAX_POWER);
CONFIG_SAMPLE_USBD_MAX_POWER, &hs_cfg_desc);
/* doc configuration instantiation end */

/*
Expand All @@ -69,6 +72,7 @@ static void sample_fix_code_triple(struct usbd_context *uds_ctx,
/* Always use class code information from Interface Descriptors */
if (IS_ENABLED(CONFIG_USBD_CDC_ACM_CLASS) ||
IS_ENABLED(CONFIG_USBD_CDC_ECM_CLASS) ||
IS_ENABLED(CONFIG_USBD_CDC_NCM_CLASS) ||
IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
/*
* Class with multiple interfaces have an Interface
Expand Down Expand Up @@ -159,8 +163,8 @@ struct usbd_context *sample_usbd_init_device(usbd_msg_cb_t msg_cb)
}

if (IS_ENABLED(CONFIG_SAMPLE_USBD_20_EXTENSION_DESC)) {
(void)usbd_device_set_bcd(&sample_usbd, USBD_SPEED_FS, 0x0201);
(void)usbd_device_set_bcd(&sample_usbd, USBD_SPEED_HS, 0x0201);
(void)usbd_device_set_bcd_usb(&sample_usbd, USBD_SPEED_FS, 0x0201);
(void)usbd_device_set_bcd_usb(&sample_usbd, USBD_SPEED_HS, 0x0201);

err = usbd_add_descriptor(&sample_usbd, &sample_usbext);
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/zephyr-subsys-usb-hid-mouse/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hid-keyboard)
project(hid-mouse)

include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
FILE(GLOB app_sources ../src/*.c)
Expand Down
2 changes: 1 addition & 1 deletion platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"type": "framework",
"optional": true,
"owner": "platformio",
"version": "~2.30700.0"
"version": "~2.40000.0"
},
"tool-stm32duino": {
"type": "uploader",
Expand Down

0 comments on commit 6a4b320

Please sign in to comment.