Skip to content
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
98 changes: 96 additions & 2 deletions examples/hello/hello_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

/****************************************************************************
* Public Functions
Expand All @@ -33,8 +35,100 @@
* hello_main
****************************************************************************/

int main(int argc, FAR char *argv[])
{
static int hello(int argc, FAR char *argv[]) {

Check failure on line 38 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Left bracket not on separate line
printf("Hello, World!!\n");
return 0;
}

static int breakpoint(int argc, FAR char *argv[]) {

Check failure on line 43 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Left bracket not on separate line
printf("Breakpoint\n");
return 0;
}

static int step(int argc, FAR char *argv[]) {

Check failure on line 48 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Left bracket not on separate line
int i = 0;
printf("Next, World!!\n");
while (i < 10) {

Check failure on line 51 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Left bracket not on separate line
printf("Step %d\n", i);
i++;
}

Check failure on line 54 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Right brace must be followed by a blank line

Check failure on line 54 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Bad right brace alignment
return 0;
}

static char *g_wild_pointer;
static int print(int argc, FAR char *argv[]) {

Check failure on line 59 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Left bracket not on separate line
static char g_buffer[64];
int i = 0;

g_wild_pointer = g_buffer;
snprintf(g_buffer, sizeof(g_buffer), "%d buffer\n", i);
while (i < 10) {

Check failure on line 65 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Left bracket not on separate line
g_buffer[0] = '0' + i % 10;
printf("%s", g_buffer);
fflush(stdout);
i++;
sleep(1);
}

Check failure on line 71 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Right brace must be followed by a blank line

Check failure on line 71 in examples/hello/hello_main.c

View workflow job for this annotation

GitHub Actions / checkpatch / checkpatch

Bad right brace alignment
return 0;
}

static int watchpoint(int argc, FAR char *argv[]) {
printf("Watchpoint\n");
if (g_wild_pointer == NULL)
return 0;

strcpy(g_wild_pointer, "Wild pointer write.\n");
return 0;
}

nooptimiziation_function
static int corruption(int argc, FAR char *argv[]) {
printf("Corruption\n");
int *p = (int *)malloc(1024);
for (int i = 0; i < 12; i++)
{
p[-i] = 0xdeadbeef;
}

return 0;
}

nooptimiziation_function
static int leak(int argc, FAR char *argv[]) {
size_t size = rand() % 1024;
int *p = (int *)malloc(size);
printf("Leak: %p: %zu\n", p, size);
return 0;
}

#define ADD_COMMAND(name) {#name, name}

static const struct {
const char *cmd;
int (*func)(int argc, FAR char *argv[]);
} g_commands[] = {
ADD_COMMAND(hello),
ADD_COMMAND(breakpoint),
ADD_COMMAND(step),
ADD_COMMAND(print),
ADD_COMMAND(watchpoint),
ADD_COMMAND(corruption),
ADD_COMMAND(leak),
};

int main(int argc, FAR char *argv[]) {
int i;
if (argc < 2) {
printf("Usage: %s <command>\n", argv[0]);
return 1;
}

for (i = 0; i < sizeof(g_commands) / sizeof(g_commands[0]); i++) {
if (strcmp(argv[1], g_commands[i].cmd) == 0) {
return g_commands[i].func(argc, argv);
}
}

printf("Unknown command: %s\n", argv[1]);
return 0;
}
2 changes: 2 additions & 0 deletions examples/hourglass/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*.zip
/lv_demos
35 changes: 35 additions & 0 deletions examples/hourglass/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ##############################################################################
# apps/examples/lvgldemo/CMakeLists.txt
#
# 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.
#
# ##############################################################################

if(CONFIG_EXAMPLES_HOURGLASS)
nuttx_add_application(
NAME
hourglass
PRIORITY
${CONFIG_EXAMPLES_HOURGLASS_PRIORITY}
STACKSIZE
${CONFIG_EXAMPLES_HOURGLASS_STACKSIZE}
MODULE
${CONFIG_EXAMPLES_HOURGLASS}
DEPENDS
lvgl
SRCS
hourglass_main.c hourglass_page.c)
endif()
30 changes: 30 additions & 0 deletions examples/hourglass/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

menuconfig EXAMPLES_HOURGLASS
tristate "HOURGLASS Demo"
default n
depends on GRAPHICS_LVGL
---help---
Enable build the Light and Versatile Graphics Library Demo programs

if EXAMPLES_HOURGLASS

config EXAMPLES_HOURGLASS_PRIORITY
int "hourglass task priority"
default 100

config EXAMPLES_HOURGLASS_STACKSIZE
int "hourglass stack size"
default 16384

config EXAMPLES_HOURGLASS_INPUT_DEVPATH
string "Touchscreen device path"
default "/dev/input0"
depends on INPUT_TOUCHSCREEN
---help---
The path to the touchscreen device. Default: "/dev/input0"

endif # EXAMPLES_HOURGLASS
23 changes: 23 additions & 0 deletions examples/hourglass/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/examples/lvgldemo/Make.defs
#
# 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.
#
############################################################################

ifneq ($(CONFIG_EXAMPLES_HOURGLASSDEMO),)
CONFIGURED_APPS += $(APPDIR)/examples/hourglass
endif
36 changes: 36 additions & 0 deletions examples/hourglass/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
############################################################################
# apps/examples/lvgldemo/Makefile
#
# 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.
#
############################################################################

include $(APPDIR)/Make.defs

ifeq ($(CONFIG_EXAMPLES_HOURGLASS), y)
PROGNAME = hourglass
PRIORITY = $(CONFIG_EXAMPLES_HOURGLASS_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_HOURGLASS_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_HOURGLASS)

# HOURGLASS demo Example

# CXXEXT := .cpp
CSRCS = hourglass_page.c hourglass_control.c
MAINSRC = hourglass_main.c
endif

include $(APPDIR)/Application.mk
Loading
Loading