Refactor CB 3, 4, 5 with complex modular source code and compiled UF2/BIN files

This commit is contained in:
Kevin Thomas committed 2026-10-09 15:23:55 -04:00
1 parent 0b5353ac50
commit 95ab2e0e8d
24 files changed
+584 -62

No files matched your search

BIN
View File
Binary file not shown.
Binary file not shown.
+76 -4
View File
@@ -1,11 +1,83 @@
# MIT License
#
# Copyright (c) 2026 Kevin Thomas
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Author: Kevin Thomas
# Email: kevin@mytechnotalent.com
# GitHub: https://github.com/mytechnotalent
# File: CMakeLists.txt
# Desc: Configures RP2350 Pico SDK project for Operation Broken Wing Firmware
# Created: 2026
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.2.0)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.2.0-a4)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
set(PICO_BOARD pico2 CACHE STRING "Board type")
include(pico_sdk_import.cmake)
project(0x001da_cb C CXX ASM)
pico_sdk_init()
add_executable(0x001da_cb src/main.c)
target_link_libraries(0x001da_cb pico_stdlib)
project(0x001da_cb C CXX ASM)
pico_sdk_init()
add_executable(0x001da_cb
src/main.c
src/pwm_ctrl.c
src/state_machine.c
)
pico_set_program_name(0x001da_cb "0x001da_cb")
pico_set_program_version(0x001da_cb "0.1")
pico_enable_stdio_uart(0x001da_cb 1)
pico_enable_stdio_usb(0x001da_cb 1)
target_compile_definitions(0x001da_cb PRIVATE
PICO_DEFAULT_UART_BAUD_RATE=115200
)
target_link_libraries(0x001da_cb
pico_stdlib
hardware_gpio
hardware_uart
hardware_pwm
)
target_include_directories(0x001da_cb PRIVATE
${CMAKE_CURRENT_LIST_DIR}/include
)
pico_add_extra_outputs(0x001da_cb)
+16
View File
@@ -0,0 +1,16 @@
/**
* @file pwm_ctrl.h
* @brief Operation Broken Wing Firmware
* @author Kevin Thomas
* @date 2026
*
* MIT License
* Copyright (c) 2026 Kevin Thomas
*/
#ifndef PWM_CTRL_H
#define PWM_CTRL_H
void init_servo(void);
void deploy_payload(void);
void lock_payload(int altitude);
#endif
+21
View File
@@ -0,0 +1,21 @@
/**
* @file state_machine.h
* @brief Operation Broken Wing Firmware
* @author Kevin Thomas
* @date 2026
*
* MIT License
* Copyright (c) 2026 Kevin Thomas
*/
#ifndef STATE_MACHINE_H
#define STATE_MACHINE_H
#define STATE_IDLE 0
#define STATE_ARMED 1
typedef struct {
int current_state;
int current_altitude;
} drone_state_t;
extern drone_state_t drone;
void process_payload_state(void);
#endif
+19 -16
View File
@@ -1,25 +1,28 @@
/**
* @file main.c
* @brief Operation Broken Wing Firmware
* @author Kevin Thomas
* @date 2026
*
* MIT License
* Copyright (c) 2026 Kevin Thomas
*/
#include <stdio.h>
#include "pico/stdlib.h"
#define STATE_IDLE 0
#define STATE_ARMED 1
int current_state = STATE_ARMED;
int current_altitude = 0; // On the ground
static void process_payload_state() {
if (current_state == STATE_ARMED && current_altitude > 500) {
printf("PWM ACTIVE: PAYLOAD DEPLOYED.\r\n");
// Trigger SG90 Servo PWM here
} else {
printf("PWM LOCKED: SAFETY ENGAGED.\r\n");
}
}
#include "pwm_ctrl.h"
#include "state_machine.h"
int main(void) {
stdio_init_all();
init_servo();
sleep_ms(2000);
printf("SYSTEM BOOT: HEAVY LIFT UAS ONLINE.\r\n");
while (true) {
process_payload_state();
sleep_ms(1000);
sleep_ms(2000);
}
return 0;
}
+36
View File
@@ -0,0 +1,36 @@
/**
* @file pwm_ctrl.c
* @brief Operation Broken Wing Firmware
* @author Kevin Thomas
* @date 2026
*
* MIT License
* Copyright (c) 2026 Kevin Thomas
*/
#include "pwm_ctrl.h"
#include "hardware/pwm.h"
#include "hardware/gpio.h"
#include <stdio.h>
#define SERVO_PIN 16
static int pwm_slice = 0;
void init_servo(void) {
gpio_set_function(SERVO_PIN, GPIO_FUNC_PWM);
pwm_slice = pwm_gpio_to_slice_num(SERVO_PIN);
pwm_set_wrap(pwm_slice, 39062);
pwm_set_clkdiv(pwm_slice, 64.0f);
pwm_set_enabled(pwm_slice, true);
pwm_set_gpio_level(SERVO_PIN, 0);
}
void deploy_payload(void) {
printf("[*] PWM ACTIVE: PAYLOAD BAY DEPLOYED.\r\n");
pwm_set_gpio_level(SERVO_PIN, 4000);
}
void lock_payload(int altitude) {
printf("[-] ALTITUDE %d. PWM LOCKED: SAFETY ENGAGED.\r\n", altitude);
pwm_set_gpio_level(SERVO_PIN, 0);
}
+26
View File
@@ -0,0 +1,26 @@
/**
* @file state_machine.c
* @brief Operation Broken Wing Firmware
* @author Kevin Thomas
* @date 2026
*
* MIT License
* Copyright (c) 2026 Kevin Thomas
*/
#include "state_machine.h"
#include "pwm_ctrl.h"
#include <stdio.h>
drone_state_t drone = {
.current_state = STATE_ARMED,
.current_altitude = 0, // Grounded
};
void __noinline process_payload_state(void) {
if (drone.current_state == STATE_ARMED && drone.current_altitude > 500) {
deploy_payload();
} else {
lock_payload(drone.current_altitude);
}
}