Rewire GPIO↔HMC472A so GPIO(n) = step bit (n-1): GPIO1→V6(0.5dB), GPIO2→V5(1dB), ... GPIO6→V1(16dB) This enables single-instruction GPIO updates: GPIO.out_w1tc = (step & 0x3F) << 1 GPIO.out_w1ts = (~step) & 0x7E Replaces 28-line loop with 4-line bitwise code.
70 lines
2.2 KiB
C
70 lines
2.2 KiB
C
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
|
|
// --- Firmware Version ---
|
|
#define FW_VERSION "2026-02-02"
|
|
#define FW_HOSTNAME "attenuator"
|
|
|
|
// --- WiFi Credentials ---
|
|
// Override via build_flags or edit directly
|
|
#ifndef WIFI_SSID
|
|
#define WIFI_SSID "your-ssid"
|
|
#endif
|
|
#ifndef WIFI_PASS
|
|
#define WIFI_PASS "your-password"
|
|
#endif
|
|
|
|
#define WIFI_TIMEOUT_MS 15000
|
|
|
|
// --- HMC472A Control Pins (active-low) ---
|
|
// Optimized mapping: GPIO number = step bit position + 1
|
|
// Enables single-instruction bitwise ops instead of loop
|
|
//
|
|
// Wiring (GPIO → HMC472A pin):
|
|
// GPIO1 → V6 (0.5 dB) = step bit 0 (LSB)
|
|
// GPIO2 → V5 (1 dB) = step bit 1
|
|
// GPIO3 → V4 (2 dB) = step bit 2
|
|
// GPIO4 → V3 (4 dB) = step bit 3
|
|
// GPIO5 → V2 (8 dB) = step bit 4
|
|
// GPIO6 → V1 (16 dB) = step bit 5 (MSB)
|
|
//
|
|
static constexpr uint8_t PIN_V6 = 1; // 0.5 dB (LSB) - step bit 0
|
|
static constexpr uint8_t PIN_V5 = 2; // 1 dB - step bit 1
|
|
static constexpr uint8_t PIN_V4 = 3; // 2 dB - step bit 2
|
|
static constexpr uint8_t PIN_V3 = 4; // 4 dB - step bit 3
|
|
static constexpr uint8_t PIN_V2 = 5; // 8 dB - step bit 4
|
|
static constexpr uint8_t PIN_V1 = 6; // 16 dB (MSB) - step bit 5
|
|
|
|
// Pin array ordered by attenuation value (V1=16dB first)
|
|
static constexpr uint8_t ATTEN_PINS[6] = {PIN_V1, PIN_V2, PIN_V3, PIN_V4, PIN_V5, PIN_V6};
|
|
static constexpr float ATTEN_DB[6] = {16.0f, 8.0f, 4.0f, 2.0f, 1.0f, 0.5f};
|
|
|
|
// Bitmask: 0b01111110 = bits 1-6 in GPIO register
|
|
static constexpr uint32_t ATTEN_PIN_MASK = 0x7E;
|
|
|
|
// --- Status LED ---
|
|
static constexpr uint8_t PIN_LED = 15; // Built-in LED, active HIGH
|
|
|
|
// --- Attenuator Limits ---
|
|
static constexpr float DB_MIN = 0.0f;
|
|
static constexpr float DB_MAX = 31.5f;
|
|
static constexpr float DB_STEP = 0.5f;
|
|
static constexpr uint8_t STEP_MIN = 0;
|
|
static constexpr uint8_t STEP_MAX = 63;
|
|
|
|
// --- Sweep Defaults ---
|
|
static constexpr uint32_t SWEEP_DWELL_MS_DEFAULT = 500;
|
|
static constexpr uint32_t SWEEP_DWELL_MS_MIN = 10;
|
|
static constexpr uint32_t SWEEP_DWELL_MS_MAX = 10000;
|
|
|
|
// --- NVS ---
|
|
#define NVS_NAMESPACE "atten"
|
|
#define NVS_KEY_STEP "step"
|
|
|
|
// --- Watchdog ---
|
|
#define WDT_TIMEOUT_S 120
|
|
|
|
// --- Web Server ---
|
|
#define WEB_PORT 80
|