Added IR Lib, samples and specification
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
This commit is contained in:
@@ -2,4 +2,5 @@
|
||||
# Build ble_mgmt and thread_mgmt first since lasertag_utils depends on them
|
||||
add_subdirectory(ble_mgmt)
|
||||
add_subdirectory(thread_mgmt)
|
||||
add_subdirectory(lasertag_utils)
|
||||
add_subdirectory(lasertag_utils)
|
||||
add_subdirectory(ir_send)
|
||||
@@ -1,4 +1,5 @@
|
||||
# Main entry point for custom project Kconfigs
|
||||
rsource "lasertag_utils/Kconfig"
|
||||
rsource "thread_mgmt/Kconfig"
|
||||
rsource "ble_mgmt/Kconfig"
|
||||
rsource "ble_mgmt/Kconfig"
|
||||
rsource "ir_send/Kconfig"
|
||||
5
firmware/libs/ir_send/CMakeLists.txt
Normal file
5
firmware/libs/ir_send/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
if(CONFIG_IR_SEND)
|
||||
zephyr_library()
|
||||
zephyr_sources(src/ir_send.c)
|
||||
zephyr_include_directories(include)
|
||||
endif()
|
||||
61
firmware/libs/ir_send/Kconfig
Normal file
61
firmware/libs/ir_send/Kconfig
Normal file
@@ -0,0 +1,61 @@
|
||||
config IR_SEND
|
||||
bool "IR Send Library"
|
||||
help
|
||||
Enable IR transmission library for laser tag system.
|
||||
Provides PWM-based IR carrier generation with pulse-distance coding.
|
||||
|
||||
if IR_SEND
|
||||
|
||||
menu "IR Protocol Configuration"
|
||||
|
||||
config IR_SEND_CARRIER_HZ
|
||||
int "IR carrier frequency (Hz)"
|
||||
default 38000
|
||||
range 30000 45000
|
||||
help
|
||||
Carrier frequency for PWM generation. Standard value is 38 kHz
|
||||
for TSOP48xx receivers. Adjust only if using different receivers.
|
||||
|
||||
config IR_SEND_DUTY_CYCLE_PERCENT
|
||||
int "Carrier duty cycle (%)"
|
||||
default 50
|
||||
range 25 75
|
||||
help
|
||||
PWM duty cycle percentage. Some receivers prefer 33%, others 50%.
|
||||
Default 50% works with most TSOP-series receivers.
|
||||
|
||||
config IR_SEND_MARK_US
|
||||
int "Mark duration (microseconds)"
|
||||
default 600
|
||||
range 300 1000
|
||||
help
|
||||
Duration of carrier burst (mark) for each bit. Standard is 600 µs
|
||||
following Sony SIRC timing.
|
||||
|
||||
config IR_SEND_SPACE0_US
|
||||
int "Space duration for bit 0 (microseconds)"
|
||||
default 600
|
||||
range 300 1000
|
||||
help
|
||||
Carrier-off duration (space) after mark for logical 0.
|
||||
Default 600 µs creates 1.2 ms total bit time.
|
||||
|
||||
config IR_SEND_SPACE1_US
|
||||
int "Space duration for bit 1 (microseconds)"
|
||||
default 1200
|
||||
range 800 2000
|
||||
help
|
||||
Carrier-off duration (space) after mark for logical 1.
|
||||
Default 1200 µs creates 1.8 ms total bit time.
|
||||
|
||||
config IR_SEND_START_BURST_US
|
||||
int "Start burst duration (microseconds)"
|
||||
default 2400
|
||||
range 1500 4000
|
||||
help
|
||||
Initial synchronization burst at frame start. Receivers detect
|
||||
this to sync on incoming frames. Default 2400 µs = 4× mark time.
|
||||
|
||||
endmenu
|
||||
|
||||
endif
|
||||
45
firmware/libs/ir_send/include/ir_send.h
Normal file
45
firmware/libs/ir_send/include/ir_send.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef IR_SEND_H
|
||||
#define IR_SEND_H
|
||||
|
||||
/**
|
||||
* @file ir_send.h
|
||||
* @brief Infrared transmission library for laser tag system.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize IR output hardware (PWM backend).
|
||||
* @return 0 on success, negative error code otherwise.
|
||||
*/
|
||||
int ir_send_init(void);
|
||||
|
||||
/**
|
||||
* @brief Send a single IR pulse (carrier burst).
|
||||
* @param duration_us Pulse duration in microseconds.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int ir_send_pulse(uint32_t duration_us);
|
||||
|
||||
/**
|
||||
* @brief Send a carrier burst of given duration (us) at configured frequency.
|
||||
* @param burst_us Duration in microseconds.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int ir_send_burst_us(uint32_t burst_us);
|
||||
|
||||
/**
|
||||
* @brief Send IR message (sequence of pulses and gaps).
|
||||
* @param data IR payload (e.g., shooter ID, power-up type).
|
||||
* @param len Length of data in bytes.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int ir_send_message(const uint8_t *data, uint8_t len);
|
||||
|
||||
/**
|
||||
* @brief Set IR carrier frequency.
|
||||
* @param freq_hz Carrier frequency in Hz (typically 38000 Hz).
|
||||
*/
|
||||
void ir_send_set_frequency(uint32_t freq_hz);
|
||||
|
||||
#endif /* IR_SEND_H */
|
||||
78
firmware/libs/ir_send/src/ir_send.c
Normal file
78
firmware/libs/ir_send/src/ir_send.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* IR Send Library - PWM-based carrier generation
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/drivers/pwm.h>
|
||||
|
||||
#include "ir_send.h"
|
||||
|
||||
LOG_MODULE_REGISTER(ir_send_lib);
|
||||
|
||||
static const struct pwm_dt_spec ir_pwm = PWM_DT_SPEC_GET(DT_ALIAS(ir_output));
|
||||
static uint32_t carrier_freq = 38000; /* Standard IR carrier frequency in Hz */
|
||||
|
||||
int ir_send_init(void)
|
||||
{
|
||||
if (!device_is_ready(ir_pwm.dev)) {
|
||||
LOG_ERR("IR PWM device not ready!");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
LOG_INF("IR output PWM ready: dev=%p, channel=%u", ir_pwm.dev, ir_pwm.channel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ir_send_pulse(uint32_t duration_us)
|
||||
{
|
||||
return ir_send_burst_us(duration_us);
|
||||
}
|
||||
|
||||
int ir_send_message(const uint8_t *data, uint8_t len)
|
||||
{
|
||||
if (!device_is_ready(ir_pwm.dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
LOG_DBG("Sending IR message (%u bytes)", len);
|
||||
|
||||
/* TODO: Implement IR protocol encoding (e.g., NEC, custom protocol)
|
||||
* For now, just a placeholder that sends a test pulse.
|
||||
*/
|
||||
ir_send_pulse(1000); /* 1ms test pulse */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ir_send_set_frequency(uint32_t freq_hz)
|
||||
{
|
||||
carrier_freq = freq_hz;
|
||||
LOG_DBG("IR carrier frequency set to %u Hz", carrier_freq);
|
||||
}
|
||||
|
||||
int ir_send_burst_us(uint32_t burst_us)
|
||||
{
|
||||
if (!device_is_ready(ir_pwm.dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
uint64_t period_ns = PWM_HZ(carrier_freq);
|
||||
uint64_t duty_ns = period_ns / 2U; /* 50% duty cycle */
|
||||
|
||||
int ret = pwm_set_dt(&ir_pwm, period_ns, duty_ns);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to enable PWM burst: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
k_usleep(burst_us);
|
||||
|
||||
/* Stop carrier after burst */
|
||||
ret = pwm_set_dt(&ir_pwm, period_ns, 0);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to stop PWM after burst: %d", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user