Monthly Archives: December 2018

nRF5 SDK: Boards

Using the SDK with other boards (v0.9.2)
Using the SDK with other boards (v15.2.0)

$ grep -r BOARD_PCA10040 .
./components/boards/boards.h:#elif defined(BOARD_PCA10040)
./examples/peripheral/blinky/pca10040/s132/ses/blinky_pca10040_s132.emProject:
c_preprocessor_definitions="
BOARD_PCA10040;
BSP_DEFINES_ONLY;
CONFIG_GPIO_AS_PINRESET;
FLOAT_ABI_HARD;
INITIALIZE_USER_SECTIONS;
NO_VTOR_CONFIG;
NRF52;
NRF52832_XXAA;
NRF52_PAN_74;
NRF_SD_BLE_API_VERSION=6;
S132;
SOFTDEVICE_PRESENT;"

$ grep -r "CFLAGS += -DBOARD_PCA10040" .
./examples/peripheral/blinky/pca10040e/mbr/armgcc/Makefile:CFLAGS += -DBOARD_PCA10040

nRF5 SDK Preprocessor Magic


#include <stdint.h>
#include <stddef.h>


typedef uint32_t ret_code_t;
typedef uint32_t (*nrf_log_timestamp_func_t)(void);

typedef enum
{
    NRF_LOG_SEVERITY_NONE,
    NRF_LOG_SEVERITY_ERROR,
    NRF_LOG_SEVERITY_WARNING,
    NRF_LOG_SEVERITY_INFO,
    NRF_LOG_SEVERITY_DEBUG,
    NRF_LOG_SEVERITY_INFO_RAW, /* Artificial level to pass information about skipping string postprocessing.*/
} nrf_log_severity_t;

typedef struct
{
    const char *       p_module_name;    ///< Module or instance name.
    uint8_t            info_color_id;    ///< Color code of info messages.
    uint8_t            debug_color_id;   ///< Color code of debug messages.
    nrf_log_severity_t compiled_lvl;     ///< Compiled highest severity level.
    nrf_log_severity_t initial_lvl;      ///< Severity level for given module or instance set on backend initialization.
} nrf_log_module_const_data_t;

#define _CONST                              const

#define CONCAT_2(p1, p2)                    CONCAT_2_(p1, p2)
#define CONCAT_2_(p1, p2)                   p1##p2
#define CONCAT_3(p1, p2, p3)                CONCAT_3_(p1, p2, p3)
#define CONCAT_3_(p1, p2, p3)               p1##p2##p3
#define STRINGIFY_(val)                     #val
#define STRINGIFY(val)                      STRINGIFY_(val)

#define GET_VA_ARG_1(...)                   GET_VA_ARG_1_(__VA_ARGS__, )
#define GET_VA_ARG_1_(a1, ...)              a1

#define GET_ARGS_AFTER_1(...)               GET_ARGS_AFTER_1_(__VA_ARGS__, )
#define GET_ARGS_AFTER_1_(a1, ...)          __VA_ARGS__

#define NRF_SECTION_ITEM_REGISTER(section_name, section_var) \
    section_var __attribute__ ((section("." STRINGIFY(section_name)))) __attribute__((used))

#define NRF_LOG_ITEM_DATA(_name)            CONCAT_3(m_nrf_log_,_name,_logs_data)
#define NRF_LOG_ITEM_DATA_DYNAMIC(_name)    CONCAT_2(NRF_LOG_ITEM_DATA(_name),_dynamic)
#define NRF_LOG_ITEM_DATA_FILTER(_name)     CONCAT_2(NRF_LOG_ITEM_DATA(_name),_filter)
#define NRF_LOG_ITEM_DATA_CONST(_name)      CONCAT_2(NRF_LOG_ITEM_DATA(_name),_const)

#define NRF_LOG_DYNAMIC_SECTION_NAME(_module_name)  CONCAT_2(log_dynamic_data_,_module_name)
#define NRF_LOG_FILTER_SECTION_NAME(_module_name)   CONCAT_2(log_filter_data_,_module_name)
#define NRF_LOG_CONST_SECTION_NAME(_module_name)    CONCAT_2(log_const_data_,_module_name)

#define NRF_LOG_INTERNAL_CONST_ITEM_REGISTER(                                             \
            _name, _str_name, _info_color, _debug_color, _initial_lvl, _compiled_lvl)     \
            NRF_SECTION_ITEM_REGISTER(NRF_LOG_CONST_SECTION_NAME(_name),                  \
            _CONST nrf_log_module_const_data_t NRF_LOG_ITEM_DATA_CONST(_name)) = {        \
                .p_module_name   = _str_name,                                             \
                .info_color_id   = (_info_color),                                         \
                .debug_color_id  = (_debug_color),                                        \
                .compiled_lvl    = (nrf_log_severity_t)(_compiled_lvl),                   \
                .initial_lvl     = (nrf_log_severity_t)(_initial_lvl),                    \
            }

#define NRF_LOG_INTERNAL_ITEM_REGISTER( \
                         _name, _str_name, _info_color, _debug_color, _initial_lvl, _compiled_lvl) \
    NRF_LOG_INTERNAL_CONST_ITEM_REGISTER(_name,                                                    \
                                         _str_name,                                                \
                                         _info_color,                                              \
                                         _debug_color,                                             \
                                         _initial_lvl,                                             \
                                         _compiled_lvl)

#define NRF_LOG_INTERNAL_MODULE_REGISTER() \
                   NRF_LOG_INTERNAL_ITEM_REGISTER(NRF_LOG_MODULE_NAME,                 \
                                                  STRINGIFY(NRF_LOG_MODULE_NAME),      \
                                                  NRF_LOG_INFO_COLOR,                  \
                                                  NRF_LOG_DEBUG_COLOR,                 \
                                                  NRF_LOG_INITIAL_LEVEL,               \
                                                  COMPILED_LOG_LEVEL)

#define NRF_LOG_MODULE_REGISTER() NRF_LOG_INTERNAL_MODULE_REGISTER()

#define NRF_LOG_INTERNAL_INIT(...)               \
        nrf_log_init(GET_VA_ARG_1(__VA_ARGS__),  \
                     GET_VA_ARG_1(GET_ARGS_AFTER_1(__VA_ARGS__, LOG_TIMESTAMP_DEFAULT_FREQUENCY)))

#define NRF_LOG_INIT(...) NRF_LOG_INTERNAL_INIT(__VA_ARGS__)

#define NRF_LOG_MODULE_NAME                 app
#define NRF_LOG_INFO_COLOR                  NRF_LOG_COLOR_DEFAULT
#define NRF_LOG_DEBUG_COLOR                 NRF_LOG_COLOR_DEFAULT
#define NRF_LOG_INITIAL_LEVEL               NRF_LOG_LEVEL
#define NRF_LOG_LEVEL                       NRF_LOG_DEFAULT_LEVEL
#define COMPILED_LOG_LEVEL                  NRF_LOG_LEVEL
#define LOG_TIMESTAMP_DEFAULT_FREQUENCY     NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY


#define NRF_LOG_COLOR_DEFAULT               0
#define NRF_LOG_DEFAULT_LEVEL               3
#define NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY 0


NRF_LOG_MODULE_REGISTER();

ret_code_t nrf_log_init(nrf_log_timestamp_func_t timestamp_func, uint32_t timestamp_freq)
{
    (void)NRF_LOG_ITEM_DATA_CONST(app);

    return 0;
}

static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
}

int main(int argc, char *argv[])
{
    log_init();

    return 0;
}
const nrf_log_module_const_data_t m_nrf_log_app_logs_data_const
__attribute__ ((section("." "log_const_data_app")))
__attribute__((used)) = {
    .p_module_name = "app",
    .info_color_id = (0),
    .debug_color_id = (0),
    .compiled_lvl = (nrf_log_severity_t)(3),
    .initial_lvl = (nrf_log_severity_t)(3),
};

ret_code_t nrf_log_init(nrf_log_timestamp_func_t timestamp_func, uint32_t timestamp_freq)
{
    (void)m_nrf_log_app_logs_data_const;

    return 0;
}

static void log_init(void)
{
    ret_code_t err_code = nrf_log_init(
        ((void *)0),
        0
    );
}

int main(int argc, char *argv[])
{
    log_init();

    return 0;
}

Programmiersprache C (C95, C99, C11, C18)

C99 Definition
NULL Pointer
C Programming/stdint.h

inttypes.h – fixed size integer types
stdint.h – integer types

Include

NULL stddef.h
size_t stddef.h
uint32_t stdint.h
stddef.h NULL, size_t
stdbool.h bool, true, false
stdint.h uint32_t
limits.h INT_MIN, UINT_MAX
inttypes.h PRId32, PRIx32

Varianten der Programmiersprache C

Präprozessor

C preprocessor

Stop on Preprocessor

Can gcc output C code after preprocessing?

$ gcc -E test.c

Concatenation

Concatenation

struct command
{
  char *name;
  void (*function) (void);
};

#define COMMAND(NAME)  { #NAME, NAME ## _command }

struct command commands[] =
{
  COMMAND (quit),
  COMMAND (help),
  …
};

/* === RESULT === */
struct command commands[] =
{
  { "quit", quit_command },
  { "help", help_command },
  …
};

Variadic macro __VA_ARGS__

Variadic Macros
Variadic macro

#define MYLOG(FormatLiteral, ...)  \
        fprintf (stderr, "%s(%u): " FormatLiteral "\n", \
        __FILE__, __LINE__, __VA_ARGS__)

Structs

struct (C programming language)

Struct initialization

Designated Initializer

Designated Initializers
Why does C++11 not support designated initializer lists as C99?

/* Forward declare a type "point" to be a struct. */
typedef struct point point;
/* Declare the struct with integer members x, y */
struct point {
   int    x;
   int    y;
};

/* Define a variable p of type point, and
   initialize its first two members in place */
point p = {
    1,
    2
};

/* Define a variable p of type point, an
   set members using designated  initializers*/
point p = { 
    .y = 2,
    .x = 1
};

Zephyr Project – Linux Foundation Project

Project Ressources – Videos
Zephyr: Thoughts and First Steps, Erich Styger @McuOnEclipse

Documentation

Zephyr Project Documentation
Getting Started Guide

Application Development – Building an Application
Application Development – Run an Application
LVGL

Boards

ESP32
STM32 Minimum Development Board (Blue Pill Board, Black Pill Board)
ST Nucleo F103RB
ST Nucleo F411RE
ST Nucleo G474RE

Device Tree

github.com/zephyrproject-rtos/zephyr/blob/master/dts/arm/st/g4/stm32g4.dtsi
github.com/zephyrproject-rtos/zephyr/blob/master/dts/arm/st/g4/stm32g474.dtsi

GoMCU

GoMCU – Zephyr
YouTube Playlist

Swedish Embedded Group

How To Learn Embedded Systems And Go From Idea To Product Using Hardware And Firmware Design In 12 Weeks Or Less

Java 3D OpenGL

com.jogamp.opengl (OpenGL 3.x?)
vs.
javax.media.opengl (OpenGL 2.x?)

LWJGL 3 vs JOGL

Processing – Advanced OpenGL

javax.media.opengl

Where can I find the package javax.media.opengl?
jogamp.org/deployment/jogamp-current/archive/

Maven

Javax Media OpenGL
JOGL Windows AMD64

LWJGL

LWJGL – Lightweight Java Game Library 3
github.com/LWJGL/lwjgl3, LWJGL is a Java library that enables cross-platform access to popular native APIs
github.com/LWJGLX/lwjgl3-awt, AWT support for LWJGL3

LWJGL3 based on GLFW
GLFW
Wikipedia: GLFW, small C library that allows the creation and management of windows with OpenGL contexts (like FreeGLUT or SDL)

How to use OpenGL in JavaFX?
JFXGL, Glue code that allows you to use JavaFX in your OpenGL/LWJGL3 app.

JOGL

Java OpenGL (JOGL)
JogAmp

YouTube

JOGL

JavaWebAndMore

#23 Java und OpenGL Tutorial – culling und depth-test

LWJGL

GamesWithGabe

Coding a 2D Game Engine in Java

freeCodeCamp.org

Code a 2D Game Engine using Java – Full Course for Beginners
Code a 2D Game Engine using Java [Part 2]
github.com/codingminecraft/MarioYoutube/tree/master

ThinMatrix

OpenGL 3D Game Tutorial (02.08.2014)
Starting Work on my New Farming Game! (30.01.2022)

mr frozen97-OSG•noob

Java 3D game using LWJGL, OPENGL, OPENAL, e.t.c
github.com/mrfrozen97/Java-3D-game-engine-with-basic-game