]> code.bitgloo.com Git - clyne/stm-game.git/commitdiff
initial upload
authorClyne Sullivan <clyne@bitgloo.com>
Fri, 27 Nov 2020 15:30:59 +0000 (10:30 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Fri, 27 Nov 2020 15:30:59 +0000 (10:30 -0500)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
buttons.c [new file with mode: 0644]
buttons.h [new file with mode: 0644]
cfg/chconf.h [new file with mode: 0644]
cfg/halconf.h [new file with mode: 0644]
cfg/mcuconf.h [new file with mode: 0644]
dogs.c [new file with mode: 0644]
dogs.h [new file with mode: 0644]
main.c [new file with mode: 0644]
openocd.sh [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..9d75526
--- /dev/null
@@ -0,0 +1,3 @@
+ChibiOS_*/
+build
+.dep
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..efef021
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,191 @@
+##############################################################################\r
+# Build global options\r
+# NOTE: Can be overridden externally.\r
+#\r
+\r
+# Compiler options here.\r
+ifeq ($(USE_OPT),)\r
+  USE_OPT = -Os -ggdb -fomit-frame-pointer -falign-functions=16\r
+endif\r
+\r
+# C specific options here (added to USE_OPT).\r
+ifeq ($(USE_COPT),)\r
+  USE_COPT = \r
+endif\r
+\r
+# C++ specific options here (added to USE_OPT).\r
+ifeq ($(USE_CPPOPT),)\r
+  USE_CPPOPT = -fno-rtti\r
+endif\r
+\r
+# Enable this if you want the linker to remove unused code and data.\r
+ifeq ($(USE_LINK_GC),)\r
+  USE_LINK_GC = yes\r
+endif\r
+\r
+# Linker extra options here.\r
+ifeq ($(USE_LDOPT),)\r
+  USE_LDOPT = \r
+endif\r
+\r
+# Enable this if you want link time optimizations (LTO).\r
+ifeq ($(USE_LTO),)\r
+  USE_LTO = yes\r
+endif\r
+\r
+# Enable this if you want to see the full log while compiling.\r
+ifeq ($(USE_VERBOSE_COMPILE),)\r
+  USE_VERBOSE_COMPILE = no\r
+endif\r
+\r
+# If enabled, this option makes the build process faster by not compiling\r
+# modules not used in the current configuration.\r
+ifeq ($(USE_SMART_BUILD),)\r
+  USE_SMART_BUILD = yes\r
+endif\r
+\r
+#\r
+# Build global options\r
+##############################################################################\r
+\r
+##############################################################################\r
+# Architecture or project specific options\r
+#\r
+\r
+# Stack size to be allocated to the Cortex-M process stack. This stack is\r
+# the stack used by the main() thread.\r
+ifeq ($(USE_PROCESS_STACKSIZE),)\r
+  USE_PROCESS_STACKSIZE = 0x80\r
+endif\r
+\r
+# Stack size to the allocated to the Cortex-M main/exceptions stack. This\r
+# stack is used for processing interrupts and exceptions.\r
+ifeq ($(USE_EXCEPTIONS_STACKSIZE),)\r
+  USE_EXCEPTIONS_STACKSIZE = 0x100\r
+endif\r
+\r
+# Enables the use of FPU (no, softfp, hard).\r
+ifeq ($(USE_FPU),)\r
+  USE_FPU = no\r
+endif\r
+\r
+# FPU-related options.\r
+ifeq ($(USE_FPU_OPT),)\r
+  USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16\r
+endif\r
+\r
+#\r
+# Architecture or project specific options\r
+##############################################################################\r
+\r
+##############################################################################\r
+# Project, target, sources and paths\r
+#\r
+\r
+# Define project name here\r
+PROJECT = ch\r
+\r
+# Target settings.\r
+MCU  = cortex-m0\r
+\r
+# Imported source files and paths.\r
+CHIBIOS  := ./ChibiOS_20.3.2\r
+CONFDIR  := ./cfg\r
+BUILDDIR := ./build\r
+DEPDIR   := ./.dep\r
+\r
+# Licensing files.\r
+include $(CHIBIOS)/os/license/license.mk\r
+# Startup files.\r
+include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32l0xx.mk\r
+# HAL-OSAL files (optional).\r
+include $(CHIBIOS)/os/hal/hal.mk\r
+include $(CHIBIOS)/os/hal/ports/STM32/STM32L0xx/platform.mk\r
+include $(CHIBIOS)/os/hal/boards/ST_NUCLEO32_L011K4/board.mk\r
+include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk\r
+# RTOS files (optional).\r
+include $(CHIBIOS)/os/nil/nil.mk\r
+include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk\r
+# Auto-build files in ./source recursively.\r
+include $(CHIBIOS)/tools/mk/autobuild.mk\r
+# Other files (optional).\r
+#include $(CHIBIOS)/test/lib/test.mk\r
+#include $(CHIBIOS)/test/nil/nil_test.mk\r
+#include $(CHIBIOS)/test/oslib/oslib_test.mk\r
+\r
+# Define linker script file here\r
+LDSCRIPT= $(STARTUPLD)/STM32L011x4.ld\r
+\r
+# C sources that can be compiled in ARM or THUMB mode depending on the global\r
+# setting.\r
+CSRC = $(ALLCSRC) \\r
+       $(TESTSRC) \\r
+          dogs.c \\r
+          buttons.c \\r
+       main.c\r
+\r
+# C++ sources that can be compiled in ARM or THUMB mode depending on the global\r
+# setting.\r
+CPPSRC = $(ALLCPPSRC)\r
+\r
+# List ASM source files here.\r
+ASMSRC = $(ALLASMSRC)\r
+\r
+# List ASM with preprocessor source files here.\r
+ASMXSRC = $(ALLXASMSRC)\r
+\r
+# Inclusion directories.\r
+INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)\r
+\r
+# Define C warning options here.\r
+CWARN = -Wall -Wextra -Wundef -pedantic #-Wstrict-prototypes\r
+\r
+# Define C++ warning options here.\r
+CPPWARN = -Wall -Wextra -Wundef\r
+\r
+#\r
+# Project, target, sources and paths\r
+##############################################################################\r
+\r
+##############################################################################\r
+# Start of user section\r
+#\r
+\r
+# List all user C define here, like -D_DEBUG=1\r
+UDEFS =\r
+\r
+# Define ASM defines here\r
+UADEFS =\r
+\r
+# List all user directories here\r
+UINCDIR =\r
+\r
+# List the user directory to look for the libraries here\r
+ULIBDIR =\r
+\r
+# List all user libraries here\r
+ULIBS =\r
+\r
+#\r
+# End of user section\r
+##############################################################################\r
+\r
+##############################################################################\r
+# Common rules\r
+#\r
+\r
+RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk\r
+include $(RULESPATH)/arm-none-eabi.mk\r
+include $(RULESPATH)/rules.mk\r
+\r
+#\r
+# Common rules\r
+##############################################################################\r
+\r
+##############################################################################\r
+# Custom rules\r
+#\r
+\r
+#\r
+# Custom rules\r
+##############################################################################\r
diff --git a/buttons.c b/buttons.c
new file mode 100644 (file)
index 0000000..c792494
--- /dev/null
+++ b/buttons.c
@@ -0,0 +1,59 @@
+/**
+ * buttons.c - Provides ability to read button state.
+ * Copyright (C) 2020  Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * See the GNU General Public License for more details.
+ */
+
+#include "buttons.h"
+#include "ch.h"
+#include "hal.h"
+
+unsigned char button_state = 0;
+
+static void buttonStateHandler(void *arg)
+{
+    int pad = (unsigned int)arg & 0xFF;
+    int bit = 1 << ((unsigned int)arg >> 8);
+
+    if (!palReadPad(GPIOA, pad)) {
+        if ((button_state & bit) != bit)
+            button_state |= bit;
+    } else {
+        if ((button_state & bit) == bit)
+            button_state &= ~(bit);
+    }
+}
+
+void buttons_init()
+{
+    palSetPadMode(GPIOA, 0, PAL_MODE_INPUT_PULLUP);   // Joy A (UL)
+    palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_PULLUP);   // Joy B (UR)
+    palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLUP);   // Joy C (DR)
+    palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_PULLUP);   // Joy D (DL)
+    palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLUP);   // Joy button
+    palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLUP);   // Button 1
+    palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLUP);   // Button 2
+    palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLUP);  // Button 3
+    palEnablePadEvent(GPIOA, 0, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 1, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 2, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 3, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 6, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 7, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 9, PAL_EVENT_MODE_BOTH_EDGES);
+    palEnablePadEvent(GPIOA, 10, PAL_EVENT_MODE_BOTH_EDGES);
+    palSetPadCallback(GPIOA, 0, buttonStateHandler, 0x0700);
+    palSetPadCallback(GPIOA, 1, buttonStateHandler, 0x0601);
+    palSetPadCallback(GPIOA, 2, buttonStateHandler, 0x0502);
+    palSetPadCallback(GPIOA, 3, buttonStateHandler, 0x0403);
+    palSetPadCallback(GPIOA, 6, buttonStateHandler, 0x0306);
+    palSetPadCallback(GPIOA, 7, buttonStateHandler, 0x0207);
+    palSetPadCallback(GPIOA, 9, buttonStateHandler, 0x0109);
+    palSetPadCallback(GPIOA, 10, buttonStateHandler, 0x000A);
+}
+
diff --git a/buttons.h b/buttons.h
new file mode 100644 (file)
index 0000000..bade3cf
--- /dev/null
+++ b/buttons.h
@@ -0,0 +1,20 @@
+/**
+ * buttons.h - Provides ability to read button state.
+ * Copyright (C) 2020  Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * See the GNU General Public License for more details.
+ */
+
+#ifndef BUTTONS_H_
+#define BUTTONS_H_
+
+extern unsigned char button_state;
+
+void buttons_init();
+
+#endif // BUTTONS_H_
+
diff --git a/cfg/chconf.h b/cfg/chconf.h
new file mode 100644 (file)
index 0000000..1ad623b
--- /dev/null
@@ -0,0 +1,479 @@
+/*\r
+    ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio\r
+\r
+    Licensed under the Apache License, Version 2.0 (the "License");\r
+    you may not use this file except in compliance with the License.\r
+    You may obtain a copy of the License at\r
+\r
+        http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+    Unless required by applicable law or agreed to in writing, software\r
+    distributed under the License is distributed on an "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+    See the License for the specific language governing permissions and\r
+    limitations under the License.\r
+*/\r
+\r
+/**\r
+ * @file    nil/templates/chconf.h\r
+ * @brief   Configuration file template.\r
+ * @details A copy of this file must be placed in each project directory, it\r
+ *          contains the application specific kernel settings.\r
+ *\r
+ * @addtogroup NIL_CONFIG\r
+ * @details Kernel related settings and hooks.\r
+ * @{\r
+ */\r
+\r
+#ifndef CHCONF_H\r
+#define CHCONF_H\r
+\r
+#define _CHIBIOS_NIL_CONF_\r
+#define _CHIBIOS_NIL_CONF_VER_4_0_\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Kernel parameters and options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Maximum number of user threads in the application.\r
+ * @note    This number is not inclusive of the idle thread which is\r
+ *          implicitly handled.\r
+ * @note    Set this value to be exactly equal to the number of threads you\r
+ *          will use or you would be wasting RAM and cycles.\r
+ * @note    This values also defines the number of available priorities\r
+ *          (0..CH_CFG_MAX_THREADS-1).\r
+ */\r
+#if !defined(CH_CFG_MAX_THREADS)\r
+#define CH_CFG_MAX_THREADS                  1\r
+#endif\r
+\r
+/**\r
+ * @brief   Auto starts threads when @p chSysInit() is invoked.\r
+ */\r
+#if !defined(CH_CFG_AUTOSTART_THREADS)\r
+#define CH_CFG_AUTOSTART_THREADS            TRUE\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name System timer settings\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   System time counter resolution.\r
+ * @note    Allowed values are 16 or 32 bits.\r
+ */\r
+#if !defined(CH_CFG_ST_RESOLUTION)\r
+#define CH_CFG_ST_RESOLUTION                16      // Using TIM21, a 16-bit ultra-low-power timer\r
+#endif\r
+\r
+/**\r
+ * @brief   System tick frequency.\r
+ * @note    This value together with the @p CH_CFG_ST_RESOLUTION\r
+ *          option defines the maximum amount of time allowed for\r
+ *          timeouts.\r
+ */\r
+#if !defined(CH_CFG_ST_FREQUENCY)\r
+#define CH_CFG_ST_FREQUENCY                 1000\r
+#endif\r
+\r
+/**\r
+ * @brief   Time delta constant for the tick-less mode.\r
+ * @note    If this value is zero then the system uses the classic\r
+ *          periodic tick. This value represents the minimum number\r
+ *          of ticks that is safe to specify in a timeout directive.\r
+ *          The value one is not valid, timeouts are rounded up to\r
+ *          this value.\r
+ */\r
+#if !defined(CH_CFG_ST_TIMEDELTA)\r
+#define CH_CFG_ST_TIMEDELTA                 2\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Subsystem options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Threads synchronization APIs.\r
+ * @details If enabled then the @p chThdWait() function is included in\r
+ *          the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_WAITEXIT)\r
+#define CH_CFG_USE_WAITEXIT                 TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Semaphores APIs.\r
+ * @details If enabled then the Semaphores APIs are included in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_SEMAPHORES)\r
+#define CH_CFG_USE_SEMAPHORES               TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Mutexes APIs.\r
+ * @details If enabled then the mutexes APIs are included in the kernel.\r
+ *\r
+ * @note    Feature not currently implemented.\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_CFG_USE_MUTEXES)\r
+#define CH_CFG_USE_MUTEXES                  FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Events Flags APIs.\r
+ * @details If enabled then the event flags APIs are included in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_EVENTS)\r
+#define CH_CFG_USE_EVENTS                   TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Synchronous Messages APIs.\r
+ * @details If enabled then the synchronous messages APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_MESSAGES)\r
+#define CH_CFG_USE_MESSAGES                 TRUE\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name OSLIB options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Mailboxes APIs.\r
+ * @details If enabled then the asynchronous messages (mailboxes) APIs are\r
+ *          included in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ * @note    Requires @p CH_CFG_USE_SEMAPHORES.\r
+ */\r
+#if !defined(CH_CFG_USE_MAILBOXES)\r
+#define CH_CFG_USE_MAILBOXES                TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Core Memory Manager APIs.\r
+ * @details If enabled then the core memory manager APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_MEMCORE)\r
+#define CH_CFG_USE_MEMCORE                  FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Managed RAM size.\r
+ * @details Size of the RAM area to be managed by the OS. If set to zero\r
+ *          then the whole available RAM is used. The core memory is made\r
+ *          available to the heap allocator and/or can be used directly through\r
+ *          the simplified core memory allocator.\r
+ *\r
+ * @note    In order to let the OS manage the whole RAM the linker script must\r
+ *          provide the @p __heap_base__ and @p __heap_end__ symbols.\r
+ * @note    Requires @p CH_CFG_USE_MEMCORE.\r
+ */\r
+#if !defined(CH_CFG_MEMCORE_SIZE)\r
+#define CH_CFG_MEMCORE_SIZE                 0\r
+#endif\r
+\r
+/**\r
+ * @brief   Heap Allocator APIs.\r
+ * @details If enabled then the memory heap allocator APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_HEAP)\r
+#define CH_CFG_USE_HEAP                     FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Memory Pools Allocator APIs.\r
+ * @details If enabled then the memory pools allocator APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_MEMPOOLS)\r
+#define CH_CFG_USE_MEMPOOLS                 FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief  Objects FIFOs APIs.\r
+ * @details If enabled then the objects FIFOs APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_OBJ_FIFOS)\r
+#define CH_CFG_USE_OBJ_FIFOS                FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Pipes APIs.\r
+ * @details If enabled then the pipes APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_PIPES)\r
+#define CH_CFG_USE_PIPES                    FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Objects Caches APIs.\r
+ * @details If enabled then the objects caches APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_OBJ_CACHES)\r
+#define CH_CFG_USE_OBJ_CACHES               FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Delegate threads APIs.\r
+ * @details If enabled then the delegate threads APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_DELEGATES)\r
+#define CH_CFG_USE_DELEGATES                FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Jobs Queues APIs.\r
+ * @details If enabled then the jobs queues APIs are included\r
+ *          in the kernel.\r
+ *\r
+ * @note    The default is @p TRUE.\r
+ */\r
+#if !defined(CH_CFG_USE_JOBS)\r
+#define CH_CFG_USE_JOBS                     FALSE\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Objects factory options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Objects Factory APIs.\r
+ * @details If enabled then the objects factory APIs are included in the\r
+ *          kernel.\r
+ *\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_CFG_USE_FACTORY)\r
+#define CH_CFG_USE_FACTORY                  FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Maximum length for object names.\r
+ * @details If the specified length is zero then the name is stored by\r
+ *          pointer but this could have unintended side effects.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_MAX_NAMES_LENGTH)\r
+#define CH_CFG_FACTORY_MAX_NAMES_LENGTH     8\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the registry of generic objects.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY)\r
+#define CH_CFG_FACTORY_OBJECTS_REGISTRY     TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables factory for generic buffers.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS)\r
+#define CH_CFG_FACTORY_GENERIC_BUFFERS      TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables factory for semaphores.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_SEMAPHORES)\r
+#define CH_CFG_FACTORY_SEMAPHORES           TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables factory for mailboxes.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_MAILBOXES)\r
+#define CH_CFG_FACTORY_MAILBOXES            TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables factory for objects FIFOs.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_OBJ_FIFOS)\r
+#define CH_CFG_FACTORY_OBJ_FIFOS            TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables factory for Pipes.\r
+ */\r
+#if !defined(CH_CFG_FACTORY_PIPES)\r
+#define CH_CFG_FACTORY_PIPES                TRUE\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Debug options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Debug option, kernel statistics.\r
+ *\r
+ * @note    Feature not currently implemented.\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_DBG_STATISTICS)\r
+#define CH_DBG_STATISTICS                   FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Debug option, system state check.\r
+ *\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_DBG_SYSTEM_STATE_CHECK)\r
+#define CH_DBG_SYSTEM_STATE_CHECK           FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Debug option, parameters checks.\r
+ *\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_DBG_ENABLE_CHECKS)\r
+#define CH_DBG_ENABLE_CHECKS                FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   System assertions.\r
+ *\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_DBG_ENABLE_ASSERTS)\r
+#define CH_DBG_ENABLE_ASSERTS               FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Stack check.\r
+ *\r
+ * @note    The default is @p FALSE.\r
+ */\r
+#if !defined(CH_DBG_ENABLE_STACK_CHECK)\r
+#define CH_DBG_ENABLE_STACK_CHECK           FALSE\r
+#endif\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Kernel hooks\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   System initialization hook.\r
+ */\r
+#define CH_CFG_SYSTEM_INIT_HOOK() {                                         \\r
+}\r
+\r
+/**\r
+ * @brief   Threads descriptor structure extension.\r
+ * @details User fields added to the end of the @p thread_t structure.\r
+ */\r
+#define CH_CFG_THREAD_EXT_FIELDS                                            \\r
+  /* Add threads custom fields here.*/\r
+\r
+/**\r
+ * @brief   Threads initialization hook.\r
+ */\r
+#define CH_CFG_THREAD_EXT_INIT_HOOK(tr) {                                   \\r
+  /* Add custom threads initialization code here.*/                         \\r
+}\r
+\r
+/**\r
+ * @brief   Threads finalization hook.\r
+ * @details User finalization code added to the @p chThdExit() API.\r
+ */\r
+#define CH_CFG_THREAD_EXIT_HOOK(tp) {}\r
+\r
+/**\r
+ * @brief   Idle thread enter hook.\r
+ * @note    This hook is invoked within a critical zone, no OS functions\r
+ *          should be invoked from here.\r
+ * @note    This macro can be used to activate a power saving mode.\r
+ */\r
+#define CH_CFG_IDLE_ENTER_HOOK() {                                          \\r
+}\r
+\r
+/**\r
+ * @brief   Idle thread leave hook.\r
+ * @note    This hook is invoked within a critical zone, no OS functions\r
+ *          should be invoked from here.\r
+ * @note    This macro can be used to deactivate a power saving mode.\r
+ */\r
+#define CH_CFG_IDLE_LEAVE_HOOK() {                                          \\r
+}\r
+\r
+/**\r
+ * @brief   System halt hook.\r
+ */\r
+#define CH_CFG_SYSTEM_HALT_HOOK(reason) {                                   \\r
+}\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/* Port-specific settings (override port settings defaulted in nilcore.h).   */\r
+/*===========================================================================*/\r
+\r
+#endif  /* CHCONF_H */\r
+\r
+/** @} */\r
diff --git a/cfg/halconf.h b/cfg/halconf.h
new file mode 100644 (file)
index 0000000..4d6ea7e
--- /dev/null
@@ -0,0 +1,531 @@
+/*\r
+    ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio\r
+\r
+    Licensed under the Apache License, Version 2.0 (the "License");\r
+    you may not use this file except in compliance with the License.\r
+    You may obtain a copy of the License at\r
+\r
+        http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+    Unless required by applicable law or agreed to in writing, software\r
+    distributed under the License is distributed on an "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+    See the License for the specific language governing permissions and\r
+    limitations under the License.\r
+*/\r
+\r
+/**\r
+ * @file    templates/halconf.h\r
+ * @brief   HAL configuration header.\r
+ * @details HAL configuration file, this file allows to enable or disable the\r
+ *          various device drivers from your application. You may also use\r
+ *          this file in order to override the device drivers default settings.\r
+ *\r
+ * @addtogroup HAL_CONF\r
+ * @{\r
+ */\r
+\r
+#ifndef HALCONF_H\r
+#define HALCONF_H\r
+\r
+#define _CHIBIOS_HAL_CONF_\r
+#define _CHIBIOS_HAL_CONF_VER_7_1_\r
+\r
+#include "mcuconf.h"\r
+\r
+/**\r
+ * @brief   Enables the PAL subsystem.\r
+ */\r
+#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)\r
+#define HAL_USE_PAL                         TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the ADC subsystem.\r
+ */\r
+#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)\r
+#define HAL_USE_ADC                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the CAN subsystem.\r
+ */\r
+#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)\r
+#define HAL_USE_CAN                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the cryptographic subsystem.\r
+ */\r
+#if !defined(HAL_USE_CRY) || defined(__DOXYGEN__)\r
+#define HAL_USE_CRY                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the DAC subsystem.\r
+ */\r
+#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)\r
+#define HAL_USE_DAC                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the EFlash subsystem.\r
+ */\r
+#if !defined(HAL_USE_EFL) || defined(__DOXYGEN__)\r
+#define HAL_USE_EFL                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the GPT subsystem.\r
+ */\r
+#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)\r
+#define HAL_USE_GPT                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the I2C subsystem.\r
+ */\r
+#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)\r
+#define HAL_USE_I2C                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the I2S subsystem.\r
+ */\r
+#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)\r
+#define HAL_USE_I2S                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the ICU subsystem.\r
+ */\r
+#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)\r
+#define HAL_USE_ICU                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the MAC subsystem.\r
+ */\r
+#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)\r
+#define HAL_USE_MAC                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the MMC_SPI subsystem.\r
+ */\r
+#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)\r
+#define HAL_USE_MMC_SPI                     FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the PWM subsystem.\r
+ */\r
+#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)\r
+#define HAL_USE_PWM                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the RTC subsystem.\r
+ */\r
+#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)\r
+#define HAL_USE_RTC                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the SDC subsystem.\r
+ */\r
+#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)\r
+#define HAL_USE_SDC                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the SERIAL subsystem.\r
+ */\r
+#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)\r
+#define HAL_USE_SERIAL                      TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the SERIAL over USB subsystem.\r
+ */\r
+#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)\r
+#define HAL_USE_SERIAL_USB                  FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the SIO subsystem.\r
+ */\r
+#if !defined(HAL_USE_SIO) || defined(__DOXYGEN__)\r
+#define HAL_USE_SIO                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the SPI subsystem.\r
+ */\r
+#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)\r
+#define HAL_USE_SPI                         TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the TRNG subsystem.\r
+ */\r
+#if !defined(HAL_USE_TRNG) || defined(__DOXYGEN__)\r
+#define HAL_USE_TRNG                        FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the UART subsystem.\r
+ */\r
+#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)\r
+#define HAL_USE_UART                        FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the USB subsystem.\r
+ */\r
+#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)\r
+#define HAL_USE_USB                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the WDG subsystem.\r
+ */\r
+#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)\r
+#define HAL_USE_WDG                         FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the WSPI subsystem.\r
+ */\r
+#if !defined(HAL_USE_WSPI) || defined(__DOXYGEN__)\r
+#define HAL_USE_WSPI                        FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* PAL driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(PAL_USE_CALLBACKS) || defined(__DOXYGEN__)\r
+#define PAL_USE_CALLBACKS                   TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(PAL_USE_WAIT) || defined(__DOXYGEN__)\r
+#define PAL_USE_WAIT                        FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* ADC driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)\r
+#define ADC_USE_WAIT                        TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)\r
+#define ADC_USE_MUTUAL_EXCLUSION            TRUE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* CAN driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Sleep mode related APIs inclusion switch.\r
+ */\r
+#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)\r
+#define CAN_USE_SLEEP_MODE                  TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enforces the driver to use direct callbacks rather than OSAL events.\r
+ */\r
+#if !defined(CAN_ENFORCE_USE_CALLBACKS) || defined(__DOXYGEN__)\r
+#define CAN_ENFORCE_USE_CALLBACKS           FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* CRY driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables the SW fall-back of the cryptographic driver.\r
+ * @details When enabled, this option, activates a fall-back software\r
+ *          implementation for algorithms not supported by the underlying\r
+ *          hardware.\r
+ * @note    Fall-back implementations may not be present for all algorithms.\r
+ */\r
+#if !defined(HAL_CRY_USE_FALLBACK) || defined(__DOXYGEN__)\r
+#define HAL_CRY_USE_FALLBACK                FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Makes the driver forcibly use the fall-back implementations.\r
+ */\r
+#if !defined(HAL_CRY_ENFORCE_FALLBACK) || defined(__DOXYGEN__)\r
+#define HAL_CRY_ENFORCE_FALLBACK            FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* DAC driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(DAC_USE_WAIT) || defined(__DOXYGEN__)\r
+#define DAC_USE_WAIT                        TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the @p dacAcquireBus() and @p dacReleaseBus() APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(DAC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)\r
+#define DAC_USE_MUTUAL_EXCLUSION            TRUE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* I2C driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables the mutual exclusion APIs on the I2C bus.\r
+ */\r
+#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)\r
+#define I2C_USE_MUTUAL_EXCLUSION            TRUE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* MAC driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables the zero-copy API.\r
+ */\r
+#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)\r
+#define MAC_USE_ZERO_COPY                   FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables an event sources for incoming packets.\r
+ */\r
+#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)\r
+#define MAC_USE_EVENTS                      TRUE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* MMC_SPI driver related settings.                                          */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Delays insertions.\r
+ * @details If enabled this options inserts delays into the MMC waiting\r
+ *          routines releasing some extra CPU time for the threads with\r
+ *          lower priority, this may slow down the driver a bit however.\r
+ *          This option is recommended also if the SPI driver does not\r
+ *          use a DMA channel and heavily loads the CPU.\r
+ */\r
+#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)\r
+#define MMC_NICE_WAITING                    TRUE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* SDC driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Number of initialization attempts before rejecting the card.\r
+ * @note    Attempts are performed at 10mS intervals.\r
+ */\r
+#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)\r
+#define SDC_INIT_RETRY                      100\r
+#endif\r
+\r
+/**\r
+ * @brief   Include support for MMC cards.\r
+ * @note    MMC support is not yet implemented so this option must be kept\r
+ *          at @p FALSE.\r
+ */\r
+#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)\r
+#define SDC_MMC_SUPPORT                     FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Delays insertions.\r
+ * @details If enabled this options inserts delays into the MMC waiting\r
+ *          routines releasing some extra CPU time for the threads with\r
+ *          lower priority, this may slow down the driver a bit however.\r
+ */\r
+#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)\r
+#define SDC_NICE_WAITING                    TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   OCR initialization constant for V20 cards.\r
+ */\r
+#if !defined(SDC_INIT_OCR_V20) || defined(__DOXYGEN__)\r
+#define SDC_INIT_OCR_V20                    0x50FF8000U\r
+#endif\r
+\r
+/**\r
+ * @brief   OCR initialization constant for non-V20 cards.\r
+ */\r
+#if !defined(SDC_INIT_OCR) || defined(__DOXYGEN__)\r
+#define SDC_INIT_OCR                        0x80100000U\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* SERIAL driver related settings.                                           */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Default bit rate.\r
+ * @details Configuration parameter, this is the baud rate selected for the\r
+ *          default configuration.\r
+ */\r
+#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)\r
+#define SERIAL_DEFAULT_BITRATE              38400\r
+#endif\r
+\r
+/**\r
+ * @brief   Serial buffers size.\r
+ * @details Configuration parameter, you can change the depth of the queue\r
+ *          buffers depending on the requirements of your application.\r
+ * @note    The default is 16 bytes for both the transmission and receive\r
+ *          buffers.\r
+ */\r
+#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)\r
+#define SERIAL_BUFFERS_SIZE                 16\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* SERIAL_USB driver related setting.                                        */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Serial over USB buffers size.\r
+ * @details Configuration parameter, the buffer size must be a multiple of\r
+ *          the USB data endpoint maximum packet size.\r
+ * @note    The default is 256 bytes for both the transmission and receive\r
+ *          buffers.\r
+ */\r
+#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)\r
+#define SERIAL_USB_BUFFERS_SIZE             256\r
+#endif\r
+\r
+/**\r
+ * @brief   Serial over USB number of buffers.\r
+ * @note    The default is 2 buffers.\r
+ */\r
+#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__)\r
+#define SERIAL_USB_BUFFERS_NUMBER           2\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* SPI driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)\r
+#define SPI_USE_WAIT                        TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables circular transfers APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(SPI_USE_CIRCULAR) || defined(__DOXYGEN__)\r
+#define SPI_USE_CIRCULAR                    FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)\r
+#define SPI_USE_MUTUAL_EXCLUSION            TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Handling method for SPI CS line.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(SPI_SELECT_MODE) || defined(__DOXYGEN__)\r
+#define SPI_SELECT_MODE                     SPI_SELECT_MODE_NONE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* UART driver related settings.                                             */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__)\r
+#define UART_USE_WAIT                       FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)\r
+#define UART_USE_MUTUAL_EXCLUSION           FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* USB driver related settings.                                              */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)\r
+#define USB_USE_WAIT                        FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* WSPI driver related settings.                                             */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief   Enables synchronous APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(WSPI_USE_WAIT) || defined(__DOXYGEN__)\r
+#define WSPI_USE_WAIT                       TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief   Enables the @p wspiAcquireBus() and @p wspiReleaseBus() APIs.\r
+ * @note    Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(WSPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)\r
+#define WSPI_USE_MUTUAL_EXCLUSION           TRUE\r
+#endif\r
+\r
+#endif /* HALCONF_H */\r
+\r
+/** @} */\r
diff --git a/cfg/mcuconf.h b/cfg/mcuconf.h
new file mode 100644 (file)
index 0000000..ccb4a6f
--- /dev/null
@@ -0,0 +1,171 @@
+/*\r
+    ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio\r
+\r
+    Licensed under the Apache License, Version 2.0 (the "License");\r
+    you may not use this file except in compliance with the License.\r
+    You may obtain a copy of the License at\r
+\r
+        http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+    Unless required by applicable law or agreed to in writing, software\r
+    distributed under the License is distributed on an "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+    See the License for the specific language governing permissions and\r
+    limitations under the License.\r
+*/\r
+\r
+#ifndef MCUCONF_H\r
+#define MCUCONF_H\r
+\r
+#define STM32_USB_CLOCK_ENABLED FALSE\r
+\r
+/*\r
+ * STM32L0xx drivers configuration.\r
+ * The following settings override the default settings present in\r
+ * the various device driver implementation headers.\r
+ * Note that the settings for each driver only have effect if the whole\r
+ * driver is enabled in halconf.h.\r
+ *\r
+ * IRQ priorities:\r
+ * 3...0       Lowest...Highest.\r
+ *\r
+ * DMA priorities:\r
+ * 0...3        Lowest...Highest.\r
+ */\r
+\r
+#define STM32L0xx_MCUCONF\r
+\r
+/*\r
+ * HAL driver system settings.\r
+ */\r
+#define STM32_NO_INIT                       FALSE\r
+#define STM32_VOS                           STM32_VOS_1P8\r
+#define STM32_PVD_ENABLE                    FALSE\r
+#define STM32_PLS                           STM32_PLS_LEV0\r
+#define STM32_HSI16_ENABLED                 FALSE\r
+#define STM32_HSI16_DIVIDER_ENABLED         FALSE\r
+#define STM32_LSI_ENABLED                   TRUE\r
+#define STM32_HSE_ENABLED                   FALSE\r
+#define STM32_LSE_ENABLED                   FALSE\r
+#define STM32_ADC_CLOCK_ENABLED             FALSE\r
+#define STM32_MSIRANGE                      STM32_MSIRANGE_2M\r
+#define STM32_SW                            STM32_SW_MSI\r
+#define STM32_PLLSRC                        STM32_PLLSRC_HSI16\r
+#define STM32_PLLMUL_VALUE                  4\r
+#define STM32_PLLDIV_VALUE                  2\r
+#define STM32_HPRE                          STM32_HPRE_DIV1\r
+#define STM32_PPRE1                         STM32_PPRE1_DIV1\r
+#define STM32_PPRE2                         STM32_PPRE2_DIV1\r
+#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK\r
+#define STM32_MCOPRE                        STM32_MCOPRE_DIV1\r
+#define STM32_RTCSEL                        STM32_RTCSEL_LSI\r
+#define STM32_RTCPRE                        STM32_RTCPRE_DIV2\r
+#define STM32_USART2SEL                     STM32_USART2SEL_APB\r
+#define STM32_LPUART1SEL                    STM32_LPUART1SEL_APB\r
+#define STM32_I2C1SEL                       STM32_I2C1SEL_APB\r
+#define STM32_LPTIM1SEL                     STM32_LPTIM1SEL_APB\r
+\r
+/*\r
+ * IRQ system settings.\r
+ */\r
+#define STM32_IRQ_EXTI0_1_PRIORITY          3\r
+#define STM32_IRQ_EXTI2_3_PRIORITY          3\r
+#define STM32_IRQ_EXTI4_15_PRIORITY         3\r
+#define STM32_IRQ_EXTI16_PRIORITY           3\r
+#define STM32_IRQ_EXTI17_20_PRIORITY        3\r
+#define STM32_IRQ_EXTI21_22_PRIORITY        3\r
+\r
+#define STM32_IRQ_USART2_PRIORITY           3\r
+#define STM32_IRQ_LPUART1_PRIORITY          3\r
+\r
+#define STM32_IRQ_TIM2_PRIORITY             1\r
+#define STM32_IRQ_TIM21_PRIORITY            1\r
+\r
+/*\r
+ * ADC driver system settings.\r
+ * Note, IRQ is shared with EXT channels 21 and 22.\r
+ */\r
+#define STM32_ADC_USE_ADC1                  FALSE\r
+#define STM32_ADC_ADC1_CKMODE               STM32_ADC_CKMODE_ADCCLK\r
+#define STM32_ADC_ADC1_DMA_PRIORITY         2\r
+#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY     2\r
+#define STM32_ADC_ADC1_DMA_STREAM           STM32_DMA_STREAM_ID(1, 1)\r
+#define STM32_ADC_PRESCALER_VALUE           1\r
+\r
+/*\r
+ * GPT driver system settings.\r
+ */\r
+#define STM32_GPT_USE_TIM2                  FALSE\r
+#define STM32_GPT_USE_TIM21                 FALSE\r
+\r
+/*\r
+ * I2C driver system settings.\r
+ */\r
+#define STM32_I2C_USE_I2C1                  FALSE\r
+#define STM32_I2C_USE_I2C2                  FALSE\r
+#define STM32_I2C_BUSY_TIMEOUT              50\r
+#define STM32_I2C_I2C1_IRQ_PRIORITY         3\r
+#define STM32_I2C_I2C2_IRQ_PRIORITY         3\r
+#define STM32_I2C_USE_DMA                   TRUE\r
+#define STM32_I2C_I2C1_DMA_PRIORITY         1\r
+#define STM32_I2C_I2C2_DMA_PRIORITY         1\r
+#define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 3)\r
+#define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 2)\r
+#define STM32_I2C_I2C2_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 5)\r
+#define STM32_I2C_I2C2_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 4)\r
+#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")\r
+\r
+/*\r
+ * ICU driver system settings.\r
+ */\r
+#define STM32_ICU_USE_TIM2                  FALSE\r
+#define STM32_ICU_USE_TIM21                 FALSE\r
+\r
+/*\r
+ * PWM driver system settings.\r
+ */\r
+#define STM32_PWM_USE_TIM2                  FALSE\r
+#define STM32_PWM_USE_TIM21                 FALSE\r
+\r
+/*\r
+ * SERIAL driver system settings.\r
+ */\r
+#define STM32_SERIAL_USE_USART2             FALSE\r
+#define STM32_SERIAL_USE_LPUART1            TRUE\r
+\r
+/*\r
+ * SPI driver system settings.\r
+ */\r
+#define STM32_SPI_USE_SPI1                  TRUE\r
+#define STM32_SPI_USE_SPI2                  FALSE\r
+#define STM32_SPI_SPI1_DMA_PRIORITY         1\r
+#define STM32_SPI_SPI2_DMA_PRIORITY         1\r
+#define STM32_SPI_SPI1_IRQ_PRIORITY         1\r
+#define STM32_SPI_SPI2_IRQ_PRIORITY         1\r
+#define STM32_SPI_SPI1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 2)\r
+#define STM32_SPI_SPI1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 3)\r
+#define STM32_SPI_SPI2_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 4)\r
+#define STM32_SPI_SPI2_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 5)\r
+#define STM32_SPI_DMA_ERROR_HOOK(spip)      osalSysHalt("DMA failure")\r
+\r
+/*\r
+ * ST driver system settings.\r
+ */\r
+#define STM32_ST_IRQ_PRIORITY               2\r
+#define STM32_ST_USE_TIMER                  21\r
+\r
+/*\r
+ * UART driver system settings.\r
+ */\r
+#define STM32_UART_USE_USART2               FALSE\r
+#define STM32_UART_USART2_DMA_PRIORITY      0\r
+#define STM32_UART_USART2_RX_DMA_STREAM     STM32_DMA_STREAM_ID(1, 6)\r
+#define STM32_UART_USART2_TX_DMA_STREAM     STM32_DMA_STREAM_ID(1, 7)\r
+#define STM32_UART_DMA_ERROR_HOOK(uartp)    osalSysHalt("DMA failure")\r
+\r
+/*\r
+ * WDG driver system settings.\r
+ */\r
+#define STM32_WDG_USE_IWDG                  FALSE\r
+\r
+#endif /* MCUCONF_H */\r
diff --git a/dogs.c b/dogs.c
new file mode 100644 (file)
index 0000000..9f754d6
--- /dev/null
+++ b/dogs.c
@@ -0,0 +1,165 @@
+/**
+ * dogs.c - Interface for drawing to the EADOGS102N-6 display.
+ * Copyright (C) 2020  Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * See the GNU General Public License for more details.
+ */
+
+#include "ch.h"
+#include "dogs.h"
+#include "hal.h"
+
+#define SET_DATA palSetPad(GPIOC, 15)
+#define SET_CMD  palClearPad(GPIOC, 15)
+#define CS_HIGH  palSetPad(GPIOA, 4)
+#define CS_LOW   palClearPad(GPIOA, 4)
+
+unsigned char dogs_buffer[DISP_WIDTH * DISP_HEIGHT / 8];
+
+static void dogs_init_display();
+
+void dogs_init()
+{
+    // SPI
+    palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(1));     // MOSI
+    palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(0));     // CLK
+    palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL);  // nCS
+    palSetPadMode(GPIOC, 14, PAL_MODE_OUTPUT_PUSHPULL); // nRST
+    palSetPadMode(GPIOC, 15, PAL_MODE_OUTPUT_PUSHPULL); // CD
+
+    palSetPad(GPIOA, 4);
+    palSetPad(GPIOC, 14);
+    palClearPad(GPIOC, 15);
+
+    static const SPIConfig ls_spicfg = {
+        false,
+        NULL,
+        SPI_CR1_BR_2 | SPI_CR1_BR_1,
+        0
+    };
+    spiStart(&SPID1, &ls_spicfg);
+
+    dogs_init_display();
+    dogs_clear();
+}
+
+void dogs_write_data(unsigned char byte)
+{
+    SET_DATA;
+    spiSend(&SPID1, 1, &byte);
+}
+void dogs_write_cmd(unsigned char byte)
+{
+    SET_CMD;
+    spiSend(&SPID1, 1, &byte);
+}
+
+void dogs_set_column(unsigned int col)
+{
+    //if (col < DISP_WIDTH) {
+        dogs_write_cmd(0x10 | ((col >> 4) & 0xF));
+        dogs_write_cmd(0x00 | (col & 0xF));
+    //}
+}
+void dogs_set_power(unsigned int bits)
+{
+    dogs_write_cmd(0x28 | (bits & 0x7));
+}
+void dogs_set_scroll_line(unsigned int startline)
+{
+    dogs_write_cmd(0x40 | (startline & 0x3F));
+}
+void dogs_set_page(unsigned int page)
+{
+    dogs_write_cmd(0xB0 | (page & 0xF));
+}
+void dogs_set_vlcd_ratio(unsigned int ratio)
+{
+    dogs_write_cmd(0x20 | (ratio & 0x7));
+}
+void dogs_set_contrast(unsigned int value)
+{
+    dogs_write_cmd(0x81);
+    dogs_write_cmd(0x00 | (value & 0x3F));
+}
+void dogs_set_pixelson(bool on)
+{
+    dogs_write_cmd(on ? 0xA5 : 0xA4);
+}
+void dogs_set_invert(bool invert)
+{
+    dogs_write_cmd(invert ? 0xA7 : 0xA6);
+}
+void dogs_set_sleep(bool sleep)
+{
+    dogs_write_cmd(sleep ? 0xAE : 0xAF);
+}
+void dogs_set_segdir(bool normal)
+{
+    dogs_write_cmd(normal ? 0xA0 : 0xA1);
+}
+void dogs_set_comdir(bool normal)
+{
+    dogs_write_cmd(normal ? 0xC0 : 0xC8);
+}
+void dogs_reset()
+{
+    dogs_write_cmd(0xE2);
+}
+void dogs_set_bias(bool higher)
+{
+    dogs_write_cmd(higher ? 0xA2 : 0xA3);
+}
+void dogs_set_advanced(unsigned int bits)
+{
+    dogs_write_cmd(0xFA);
+    dogs_write_cmd(0x10 | bits);
+}
+
+void dogs_init_display()
+{
+    CS_LOW;
+    dogs_reset();
+    CS_HIGH;
+    chThdSleepMilliseconds(100);
+    CS_LOW;
+    dogs_set_scroll_line(0);
+    dogs_set_segdir(true);
+    dogs_set_comdir(false);
+    dogs_set_pixelson(false);
+    dogs_set_invert(false);
+    dogs_set_bias(true);
+    dogs_set_power(0x07);
+    dogs_set_vlcd_ratio(7);
+    dogs_set_contrast(0x10);
+    dogs_set_advanced(0x83);
+    dogs_set_sleep(false);
+    CS_HIGH;
+}
+
+void dogs_clear()
+{
+    unsigned char *ptr = dogs_buffer;
+    for (unsigned int i = 0; i < sizeof(dogs_buffer); i++) {
+        *ptr++ = 0;
+    }
+    dogs_flush();
+}
+
+void dogs_flush()
+{
+    unsigned char *ptr = dogs_buffer;
+    CS_LOW;
+    for (int page = 0; page < 8; page++) {
+        dogs_set_page(page);
+        dogs_set_column(30);
+        for (int i = 0; i < 102; i++)
+            dogs_write_data(*ptr++);
+    }
+    CS_HIGH;
+}
+
diff --git a/dogs.h b/dogs.h
new file mode 100644 (file)
index 0000000..2660bf1
--- /dev/null
+++ b/dogs.h
@@ -0,0 +1,25 @@
+/**
+ * dogs.h - Interface for drawing to the EADOGS102N-6 display.
+ * Copyright (C) 2020  Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * See the GNU General Public License for more details.
+ */
+
+#ifndef DOGS_H_
+#define DOGS_H_
+
+#define DISP_WIDTH  102
+#define DISP_HEIGHT 64
+
+extern unsigned char dogs_buffer[DISP_WIDTH * DISP_HEIGHT / 8];
+
+void dogs_init();
+void dogs_clear();
+void dogs_flush();
+
+#endif // DOGS_H_
+
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..126c47e
--- /dev/null
+++ b/main.c
@@ -0,0 +1,67 @@
+/**\r
+ * main.c - Firmware entry point and main loop for game or testing.\r
+ * Copyright (C) 2020  Clyne Sullivan\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * See the GNU General Public License for more details.\r
+ */\r
+\r
+#include "buttons.h"\r
+#include "ch.h"\r
+#include "dogs.h"\r
+#include "hal.h"\r
+\r
+/*\r
+ * Progress:\r
+ *  - Serial through LPUART1 works (38400 baud, takes over swdio pins)\r
+ *  - Display comm. over SPI, can clear screen\r
+ *  - Can read buttons through PAL (through interrupts now)\r
+ */\r
+\r
+THD_WORKING_AREA(waThread2, 96);\r
+THD_FUNCTION(Thread2, arg)\r
+{\r
+    (void)arg;\r
+\r
+    dogs_init();\r
+\r
+    while (1) {\r
+        chThdSleepMilliseconds(100);\r
+        dogs_buffer[0] = button_state;\r
+        dogs_buffer[1] = button_state;\r
+        dogs_buffer[2] = button_state;\r
+        dogs_buffer[3] = button_state;\r
+        dogs_flush();\r
+    }\r
+}\r
+\r
+THD_TABLE_BEGIN\r
+    THD_TABLE_THREAD(0, "game", waThread2, Thread2, NULL)\r
+THD_TABLE_END\r
+\r
+int main(void)\r
+{\r
+    halInit();\r
+    chSysInit();\r
+\r
+    buttons_init();\r
+\r
+    // Below code for serial -- note that it cuts off debugging, and MUST be used in a thread\r
+    //chThdSleepMilliseconds(2000);\r
+    //palSetPadMode(GPIOA, 13, PAL_MODE_ALTERNATE(6));\r
+    //palSetPadMode(GPIOA, 14, PAL_MODE_ALTERNATE(6));\r
+    //sdStart(&LPSD1, NULL);\r
+    //chnWrite(&LPSD1, (const uint8_t *)"Hello World!\r\n", 14);\r
+\r
+\r
+\r
+    /* This is now the idle thread loop, you may perform here a low priority\r
+       task but YOU MUST NEVER TRY TO SLEEP OR WAIT in this loop. Note that\r
+       this tasks runs at the lowest priority level so any instruction added\r
+       here will be executed after all other tasks have been started. */\r
+    while (1);\r
+}\r
+\r
diff --git a/openocd.sh b/openocd.sh
new file mode 100755 (executable)
index 0000000..6cf8e57
--- /dev/null
@@ -0,0 +1 @@
+sudo openocd -f /usr/local/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/local/share/openocd/scripts/target/stm32l0.cfg