32ESPecial Version 1.00 (#9)

This release reworked the initialization code to provide more robust initialization, especially when no USB stick is present.

It incorporates [Version 1.0 of SystemK](Software/SystemK#9).

This is the first release for the [32ESPecial Blaster Kits](https://link.clubk.club/2025002).

Co-authored-by: Joe Kearney <joe@clubk.club>
Reviewed-on: #9
This commit is contained in:
Joe Kearney 2025-11-30 21:46:46 +00:00
parent 14ec8fe280
commit e12ee17973
67 changed files with 1232 additions and 649 deletions

View file

@ -1,5 +1,27 @@
/*
* This program source code file is part of the KTag project, a DIY laser tag
* game with customizable features and wide interoperability.
*
* 🛡 <https://ktag.clubk.club> 🃞
*
* Copyright © 2024-2025 Joseph P. Kearney and the KTag developers.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* There should be a copy of the GNU Affero General Public License in the LICENSE
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
*/
#include <SystemK.h>
#include <System_Events.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <string.h>
@ -18,11 +40,11 @@ static TaskHandle_t xTaskHandle;
static muxed_led_strip_handle_t NeoPixel_Out;
// GPIO assignments
#define NEOPIXEL_OUT_GPIO GPIO_NUM_48
#define BARREL_ENABLE_GPIO GPIO_NUM_18
#define RECEIVER_ENABLE_GPIO GPIO_NUM_45
#define DISPLAY_ENABLE_GPIO GPIO_NUM_10
#define EFFECTS_ENABLE_GPIO GPIO_NUM_17
#define NEOPIXEL_OUT_GPIO GPIO_NUM_48
#define BARREL_ENABLE_GPIO GPIO_NUM_18
#define RECEIVER_ENABLE_GPIO GPIO_NUM_45
#define DISPLAY_ENABLE_GPIO GPIO_NUM_10
#define EFFECTS_ENABLE_GPIO GPIO_NUM_17
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
@ -127,12 +149,12 @@ static led_strip_rmt_config_t rmt_config_noDMA = {
};
static led_strip_spi_config_t spi_config_withDMA __attribute__((unused)) = {
.clk_src = RMT_CLK_SRC_XTAL, // different clock source can lead to different power consumption
.flags.with_dma = true, // Using DMA can improve performance and help drive more LEDs
.spi_bus = SPI2_HOST, // SPI bus ID
.clk_src = RMT_CLK_SRC_XTAL, // different clock source can lead to different power consumption
.flags.with_dma = true, // Using DMA can improve performance and help drive more LEDs
.spi_bus = SPI2_HOST, // SPI bus ID
};
void Initialize_SystemK_NeoPixels(SemaphoreHandle_t init_complete)
void Initialize_SystemK_NeoPixels(void)
{
xStack = (uint8_t *)heap_caps_calloc(1, NEOPIXELS_STACK_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT | MALLOC_CAP_32BIT);
@ -147,13 +169,14 @@ void Initialize_SystemK_NeoPixels(SemaphoreHandle_t init_complete)
&xTaskBuffer, // Variable to hold the task's data structure.
APP_CPU_NUM); // Specify the task's core affinity.
xEventGroupSetBits(Get_System_Events(), SYS_NEOPIXELS_READY);
KLOG_INFO(TAG, "Initialization complete.");
xSemaphoreGive(init_complete);
}
SystemKResult_T HW_NeoPixels_Init(void)
{
KLOG_INFO(TAG, "Initializing NeoPixels...");
if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS > 0)
{
// Initialize the NeoPixel Out and the Barrel Enable.
@ -220,11 +243,11 @@ color_t HW_NeoPixels_Get_My_Color(void)
uint8_t Player_ID;
uint8_t Weapon_ID;
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &Team_ID);
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_PLAYERID, &Player_ID);
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_WEAPONID, &Weapon_ID);
(void)SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &Team_ID);
(void)SETTINGS_get_uint8_t(SYSTEMK_SETTING_PLAYERID, &Player_ID);
(void)SETTINGS_get_uint8_t(SYSTEMK_SETTING_WEAPONID, &Weapon_ID);
result = PROTOCOLS_GetColor(GetWeaponFromID(Weapon_ID).Protocol, Team_ID, Player_ID);
result = PROTOCOLS_GetColor(GetWeaponFromID(Weapon_ID).Protocol, Team_ID, Player_ID);
return result;
}

View file

@ -1,6 +1,28 @@
/*
* This program source code file is part of the KTag project, a DIY laser tag
* game with customizable features and wide interoperability.
*
* 🛡 <https://ktag.clubk.club> 🃞
*
* Copyright © 2024-2025 Joseph P. Kearney and the KTag developers.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* There should be a copy of the GNU Affero General Public License in the LICENSE
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HW_NEOPIXELS_H
#define HW_NEOPIXELS_H
void Initialize_SystemK_NeoPixels(SemaphoreHandle_t init_complete);
void Initialize_SystemK_NeoPixels(void);
#endif // HW_NEOPIXELS_H
#endif // HW_NEOPIXELS_H

View file

@ -23,11 +23,11 @@
#ifndef VERSION_H
#define VERSION_H
#define VERSION_MAJOR 00
#define VERSION_MINOR 44
#define VERSION_MAJOR 01
#define VERSION_MINOR 00
#define STRINGIFY(number) #number
#define VERSION_STRING(major, minor) STRINGIFY(major) "." STRINGIFY(minor)
#define VERSION_AS_STR() "Version " VERSION_STRING(VERSION_MAJOR, VERSION_MINOR) " " __DATE__ " " __TIME__
#endif // VERSION_H
#endif // VERSION_H

View file

@ -3,8 +3,8 @@ dependencies:
chmorgan/esp-libhelix-mp3: "^1.0.3"
chmorgan/esp-audio-player: "^1.0.7"
espressif/button: "^3.5.0"
espressif/mdns: "^1.8.2"
espressif/usb_host_msc: "^1.1.3"
espressif/mdns: "^1.9.1"
espressif/usb_host_msc: "^1.1.4"
## Required IDF version (>=5.1 is required for the SPI backend of the led-strip component.)
## We tested with 5.5.1.

View file

@ -41,8 +41,8 @@
#include <string.h>
#include <SystemK.h>
#include <SPIFFS.h>
#include <USB.h>
#include <System_Events.h>
#include <NVM.h>
#include <I2S_Audio.h>
#include <Switches.h>
#include <BLE.h>
@ -54,7 +54,6 @@
#include "Reprogramming.h"
static const char *TAG = "KTag 2024A";
static SemaphoreHandle_t init_complete_semaphore;
static const uint16_t INITIALIZATION_TIMEOUT_IN_ms = 10 * 1000;
void app_main(void)
@ -62,7 +61,8 @@ void app_main(void)
KLOG_INFO(TAG, VERSION_AS_STR());
KLOG_INFO(TAG, "Initializing app...");
init_complete_semaphore = xSemaphoreCreateBinary();
Initialize_System_Events();
// Initialize NVS — it is used by both the BLE and WiFi drivers.
esp_err_t ret = nvs_flash_init();
@ -71,19 +71,25 @@ void app_main(void)
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
Initialize_SPIFFS(init_complete_semaphore);
if (xSemaphoreTake(init_complete_semaphore, pdMS_TO_TICKS(INITIALIZATION_TIMEOUT_IN_ms)) != pdTRUE)
if (ret == ESP_OK)
{
KLOG_ERROR(TAG, "Timeout initializing SPIFFS!");
xEventGroupSetBits(Get_System_Events(), SYS_NVS_READY);
KLOG_INFO(TAG, "NVS initialized.");
}
else
{
KLOG_ERROR(TAG, "Error initializing NVS: %s", esp_err_to_name(ret));
}
Initialize_USB(init_complete_semaphore);
if (xSemaphoreTake(init_complete_semaphore, pdMS_TO_TICKS(INITIALIZATION_TIMEOUT_IN_ms)) != pdTRUE)
{
KLOG_ERROR(TAG, "Timeout initializing USB!");
}
Initialize_SPIFFS();
Wait_For_System_Event(SYS_SPIFFS_READY, "Timeout initializing SPIFFS!", INITIALIZATION_TIMEOUT_IN_ms);
Initialize_USB();
Wait_For_System_Event(SYS_USB_FS_PRESENT, "Timeout initializing USB!", INITIALIZATION_TIMEOUT_IN_ms);
Initialize_Settings();
Wait_For_System_Event(SYS_SETTINGS_READY, "Timeout initializing Settings!", INITIALIZATION_TIMEOUT_IN_ms);
if (OTA_File_Exists() == true)
{
@ -94,20 +100,17 @@ void app_main(void)
else
{
Initialize_Audio();
Wait_For_System_Event(SYS_AUDIO_READY, "Timeout initializing Audio!", INITIALIZATION_TIMEOUT_IN_ms);
Initialize_SystemK_NeoPixels(init_complete_semaphore);
if (xSemaphoreTake(init_complete_semaphore, pdMS_TO_TICKS(INITIALIZATION_TIMEOUT_IN_ms)) != pdTRUE)
{
KLOG_ERROR(TAG, "Timeout initializing NeoPixels!");
}
Initialize_SystemK_NeoPixels();
Wait_For_System_Event(SYS_NEOPIXELS_READY, "Timeout initializing NeoPixels!", INITIALIZATION_TIMEOUT_IN_ms);
Initialize_BLE();
Wait_For_System_Event(SYS_BLE_READY, "Timeout initializing BLE!", INITIALIZATION_TIMEOUT_IN_ms);
Initialize_IR();
Wait_For_System_Event(SYS_IR_READY, "Timeout initializing IR!", INITIALIZATION_TIMEOUT_IN_ms);
Initialize_IR(init_complete_semaphore);
if (xSemaphoreTake(init_complete_semaphore, pdMS_TO_TICKS(INITIALIZATION_TIMEOUT_IN_ms)) != pdTRUE)
{
KLOG_ERROR(TAG, "Timeout initializing IR!");
}
if (Initialize_SystemK() != SYSTEMK_RESULT_SUCCESS)
{
KLOG_ERROR(TAG, "Error initializing SystemK!");
@ -116,7 +119,6 @@ void app_main(void)
// Initialize the switches after SystemK, so xQueueEvents will have already been created.
Initialize_Switches();
vSemaphoreDelete(init_complete_semaphore);
KLOG_INFO(TAG, "Initialization complete.");
}