Finish the OOK remote sender, fix F+EXIT
OOK sender for 433 MHz remotes: PT2262, EV1527, rc-switch protocols 1-7, Intertechno self-learning and raw Manchester. The carrier is keyed with the PA enable line through a new fast BK4819 GPIO write (~25 us instead of ~300 us), and every edge is scheduled on an absolute SysTick clock. F+EXIT never opened the OOK sender: APP_ProcessKey cancels the F state for EXIT before the screen handler runs. Open it there instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
No files matched your search
@@ -1761,6 +1761,11 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
#else
|
||||
if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2)) {
|
||||
#endif
|
||||
// F + EXIT on the main screen opens the OOK sender (handled here because the
|
||||
// F state is cleared before the screen key handler runs)
|
||||
if (Key == KEY_EXIT && bKeyPressed && !bKeyHeld && gScreenToDisplay == DISPLAY_MAIN)
|
||||
gRequestDisplayScreen = DISPLAY_OOKSENDER;
|
||||
|
||||
// cancel the F-key
|
||||
gWasFKeyPressed = false;
|
||||
gUpdateStatus = true;
|
||||
|
||||
+2
-3
@@ -575,10 +575,9 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
}
|
||||
|
||||
static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) {
|
||||
if (gWasFKeyPressed) {
|
||||
gRequestDisplayScreen = DISPLAY_OOKSENDER;
|
||||
// F + EXIT (OOK sender) is handled in APP ProcessKey, the F state is cleared before this runs
|
||||
if (gRequestDisplayScreen == DISPLAY_OOKSENDER)
|
||||
return;
|
||||
}
|
||||
if (!bKeyHeld && bKeyPressed) { // exit key pressed
|
||||
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
|
||||
|
||||
|
||||
+307
-109
@@ -1,143 +1,341 @@
|
||||
//
|
||||
// Created by bruno on 3/30/25.
|
||||
//
|
||||
// OOK remote code sender. The carrier is generated in TX mode with the audio
|
||||
// muted and keyed with the PA enable line (fast SPI write, ~25 us). Every edge
|
||||
// is scheduled on an absolute SysTick clock, so the write latency is the same
|
||||
// for every edge and does not change pulse widths, and nothing drifts.
|
||||
//
|
||||
|
||||
#include "ooksender.h"
|
||||
#include "ui/ui.h"
|
||||
#include "driver/uart.h"
|
||||
#include "driver/systick.h"
|
||||
#include <stddef.h>
|
||||
#include "ARMCM0.h"
|
||||
#include "audio.h"
|
||||
#include "driver/bk4819.h"
|
||||
#include "driver/system.h"
|
||||
#include "frequencies.h"
|
||||
#include "misc.h"
|
||||
#include "radio.h"
|
||||
#include "audio.h"
|
||||
#include "ui/ooksender.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
uint8_t gOOKSenderState = OOKSENDER_PROTO_CHOOSE;
|
||||
|
||||
uint8_t gOOKSenderProtocol = OOKSENDER_PROTO_EV1527;
|
||||
uint8_t gOOKSenderField = OOK_FIELD_CODE;
|
||||
uint32_t gOOKSenderValue[OOK_FIELD_COUNT];
|
||||
|
||||
uint32_t ev1527_id24 = 0;
|
||||
uint8_t ev1527_btn = 0;
|
||||
#define PT2262_MAX_TRITS 12U
|
||||
|
||||
// rc-switch protocols: pulse length, then (high, low) in pulses for sync, 0 and 1.
|
||||
// Data bits are sent MSB first, followed by the sync (rc-switch order).
|
||||
typedef struct {
|
||||
uint16_t pulse_us;
|
||||
uint8_t sync[2];
|
||||
uint8_t zero[2];
|
||||
uint8_t one[2];
|
||||
bool inverted;
|
||||
} OOK_RcProtocol_t;
|
||||
|
||||
static const OOK_RcProtocol_t rcProtocols[7] = {
|
||||
{350, {1, 31}, {1, 3}, {3, 1}, false}, // 1: PT2262, EV1527, most cheap remotes
|
||||
{650, {1, 10}, {1, 2}, {2, 1}, false}, // 2
|
||||
{100, {30, 71}, {4, 11}, {9, 6}, false}, // 3
|
||||
{380, {1, 6}, {1, 3}, {3, 1}, false}, // 4
|
||||
{500, {6, 14}, {1, 2}, {2, 1}, false}, // 5
|
||||
{450, {23, 1}, {1, 2}, {2, 1}, true}, // 6: HT6P20B
|
||||
{150, {2, 62}, {1, 6}, {6, 1}, false}, // 7: HS2303-PT
|
||||
};
|
||||
|
||||
static const char *const fieldLabels[OOKSENDER_PROTO_END][OOK_FIELD_COUNT] = {
|
||||
[OOKSENDER_PROTO_PT2262] = {"Code", NULL, NULL, "Pulse", "Repeat"},
|
||||
[OOKSENDER_PROTO_EV1527] = {"ID", "Key", NULL, "Pulse", "Repeat"},
|
||||
[OOKSENDER_PROTO_RCSWITCH] = {"Code", "Bits", "Proto", "Pulse", "Repeat"},
|
||||
[OOKSENDER_PROTO_INTERTECHNO] = {"ID", "Unit", "On", "Pulse", "Repeat"},
|
||||
[OOKSENDER_PROTO_MANCHESTER] = {"Code", "Bits", NULL, "Half", "Repeat"},
|
||||
};
|
||||
|
||||
static const uint32_t fieldMax[OOKSENDER_PROTO_END][OOK_FIELD_COUNT] = {
|
||||
[OOKSENDER_PROTO_PT2262] = {0x00FFFFFF, PT2262_MAX_TRITS, 0, 5000, 100},
|
||||
[OOKSENDER_PROTO_EV1527] = {0x000FFFFF, 15, 0, 5000, 100},
|
||||
[OOKSENDER_PROTO_RCSWITCH] = {0xFFFFFFFF, 32, 7, 5000, 100},
|
||||
[OOKSENDER_PROTO_INTERTECHNO] = {0x03FFFFFF, 15, 1, 5000, 100},
|
||||
[OOKSENDER_PROTO_MANCHESTER] = {0xFFFFFFFF, 32, 0, 5000, 100},
|
||||
};
|
||||
|
||||
const char *OOKSENDER_FieldLabel(const uint8_t protocol, const uint8_t field)
|
||||
{
|
||||
return fieldLabels[protocol][field];
|
||||
}
|
||||
|
||||
static void OOK_SetDefaults(void)
|
||||
{
|
||||
static const uint16_t pulse[OOKSENDER_PROTO_END] = {350, 350, 350, 260, 500};
|
||||
static const uint8_t arg[OOKSENDER_PROTO_END] = {0, 0, 24, 0, 16};
|
||||
|
||||
gOOKSenderValue[OOK_FIELD_CODE] = 0;
|
||||
gOOKSenderValue[OOK_FIELD_ARG] = arg[gOOKSenderProtocol];
|
||||
gOOKSenderValue[OOK_FIELD_EXTRA] = 1; // rc-switch protocol 1 / Intertechno "on"
|
||||
gOOKSenderValue[OOK_FIELD_PULSE] = pulse[gOOKSenderProtocol];
|
||||
gOOKSenderValue[OOK_FIELD_REPEAT] = 10;
|
||||
gOOKSenderField = OOK_FIELD_CODE;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- timing
|
||||
|
||||
#define OOK_TICKS_PER_US 48U // SysTick runs on the 48 MHz core clock
|
||||
|
||||
static uint32_t ookLastVal;
|
||||
static uint32_t ookNow;
|
||||
static uint32_t ookDue;
|
||||
|
||||
// Monotonic 48 MHz tick count. SysTick counts down and reloads every 10 ms, so this
|
||||
// must be called more often than that (the busy waits below do).
|
||||
static uint32_t OOK_Ticks(void)
|
||||
{
|
||||
const uint32_t value = SysTick->VAL;
|
||||
ookNow += (ookLastVal >= value) ? ookLastVal - value : ookLastVal + SysTick->LOAD + 1U - value;
|
||||
ookLastVal = value;
|
||||
return ookNow;
|
||||
}
|
||||
|
||||
// Switch the carrier at the scheduled time, then schedule the next edge.
|
||||
static void OOK_Level(const bool on, const uint32_t us)
|
||||
{
|
||||
while ((int32_t) (OOK_Ticks() - ookDue) < 0) {
|
||||
}
|
||||
BK4819_ToggleGpioOutFast(BK4819_GPIO1_PIN29_PA_ENABLE, on);
|
||||
ookDue += us * OOK_TICKS_PER_US;
|
||||
}
|
||||
|
||||
static void OOK_Pair(const uint8_t ratio[2], const uint32_t pulse, const bool inverted)
|
||||
{
|
||||
OOK_Level(!inverted, ratio[0] * pulse);
|
||||
OOK_Level(inverted, ratio[1] * pulse);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- encoders
|
||||
|
||||
static void OOK_SendRcBits(const OOK_RcProtocol_t *p, const uint32_t code, const uint8_t bits,
|
||||
const uint32_t pulse)
|
||||
{
|
||||
for (uint8_t i = bits; i-- > 0;)
|
||||
OOK_Pair(((code >> i) & 1U) ? p->one : p->zero, pulse, p->inverted);
|
||||
OOK_Pair(p->sync, pulse, p->inverted);
|
||||
}
|
||||
|
||||
static void OOK_SendFrame(void)
|
||||
{
|
||||
static const uint8_t itShort[2] = {1, 1}, itLong[2] = {1, 5};
|
||||
static const uint8_t itStart[2] = {1, 10}, itEnd[2] = {1, 40};
|
||||
const uint32_t code = gOOKSenderValue[OOK_FIELD_CODE];
|
||||
const uint32_t arg = gOOKSenderValue[OOK_FIELD_ARG];
|
||||
const uint32_t pulse = gOOKSenderValue[OOK_FIELD_PULSE];
|
||||
const OOK_RcProtocol_t *p1 = &rcProtocols[0];
|
||||
|
||||
switch (gOOKSenderProtocol) {
|
||||
case OOKSENDER_PROTO_PT2262:
|
||||
// trit 0 = "0 0", trit 1 = "1 1", trit F = "0 1" (2 bits per trit in code)
|
||||
for (uint32_t i = arg; i-- > 0;) {
|
||||
const uint32_t trit = (code >> (2U * i)) & 3U;
|
||||
OOK_Pair(trit == 1U ? p1->one : p1->zero, pulse, false);
|
||||
OOK_Pair(trit == 0U ? p1->zero : p1->one, pulse, false);
|
||||
}
|
||||
OOK_Pair(p1->sync, pulse, false);
|
||||
break;
|
||||
|
||||
case OOKSENDER_PROTO_EV1527:
|
||||
OOK_SendRcBits(p1, (code << 4) | (arg & 0x0FU), 24, pulse);
|
||||
break;
|
||||
|
||||
case OOKSENDER_PROTO_RCSWITCH:
|
||||
OOK_SendRcBits(&rcProtocols[gOOKSenderValue[OOK_FIELD_EXTRA] - 1U], code, (uint8_t) arg, pulse);
|
||||
break;
|
||||
|
||||
case OOKSENDER_PROTO_INTERTECHNO: {
|
||||
// 26 bit ID, group bit (0), on/off, 4 bit unit; bit 0 = short+long, 1 = long+short
|
||||
const uint32_t word = (code << 6) | ((gOOKSenderValue[OOK_FIELD_EXTRA] & 1U) << 4) | (arg & 0x0FU);
|
||||
OOK_Pair(itStart, pulse, false);
|
||||
for (uint8_t i = 32; i-- > 0;) {
|
||||
const bool one = (word >> i) & 1U;
|
||||
OOK_Pair(one ? itLong : itShort, pulse, false);
|
||||
OOK_Pair(one ? itShort : itLong, pulse, false);
|
||||
}
|
||||
OOK_Pair(itEnd, pulse, false);
|
||||
break;
|
||||
}
|
||||
|
||||
case OOKSENDER_PROTO_MANCHESTER:
|
||||
// 1 = on/off, 0 = off/on (half bit each), then a 20 half-bit gap
|
||||
for (uint32_t i = arg; i-- > 0;) {
|
||||
const bool one = (code >> i) & 1U;
|
||||
OOK_Level(one, pulse);
|
||||
OOK_Level(!one, pulse);
|
||||
}
|
||||
OOK_Level(false, 20U * pulse);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static bool OOK_Valid(void)
|
||||
{
|
||||
const uint32_t *v = gOOKSenderValue;
|
||||
|
||||
if (v[OOK_FIELD_REPEAT] == 0 || v[OOK_FIELD_PULSE] < 50U)
|
||||
return false;
|
||||
switch (gOOKSenderProtocol) {
|
||||
case OOKSENDER_PROTO_PT2262:
|
||||
return v[OOK_FIELD_ARG] > 0;
|
||||
case OOKSENDER_PROTO_RCSWITCH:
|
||||
return v[OOK_FIELD_ARG] > 0 && v[OOK_FIELD_EXTRA] >= 1U && v[OOK_FIELD_EXTRA] <= 7U;
|
||||
case OOKSENDER_PROTO_MANCHESTER:
|
||||
return v[OOK_FIELD_ARG] > 0;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void OOK_Transmit(void)
|
||||
{
|
||||
if (!OOK_Valid() || TX_freq_check(gCurrentVfo->pTX->Frequency) != 0) {
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||
return;
|
||||
}
|
||||
|
||||
gOOKSenderState = OOKSENDER_SENDING;
|
||||
OOKSENDER_Display();
|
||||
|
||||
// unmodulated carrier, PA switched off until the first pulse
|
||||
BK4819_EnterTxMute();
|
||||
RADIO_SetTxParameters();
|
||||
BK4819_WriteRegister(BK4819_REG_30,
|
||||
BK4819_REG_30_ENABLE_VCO_CALIB |
|
||||
BK4819_REG_30_ENABLE_UNKNOWN |
|
||||
BK4819_REG_30_DISABLE_RX_LINK |
|
||||
BK4819_REG_30_DISABLE_AF_DAC |
|
||||
BK4819_REG_30_ENABLE_DISC_MODE |
|
||||
BK4819_REG_30_ENABLE_PLL_VCO |
|
||||
BK4819_REG_30_ENABLE_PA_GAIN |
|
||||
BK4819_REG_30_DISABLE_MIC_ADC |
|
||||
BK4819_REG_30_ENABLE_TX_DSP |
|
||||
BK4819_REG_30_DISABLE_RX_DSP);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true);
|
||||
SYSTEM_DelayMs(20);
|
||||
|
||||
ookLastVal = SysTick->VAL;
|
||||
ookNow = 0;
|
||||
ookDue = 200U * OOK_TICKS_PER_US;
|
||||
for (uint32_t r = 0; r < gOOKSenderValue[OOK_FIELD_REPEAT]; r++)
|
||||
OOK_SendFrame();
|
||||
OOK_Level(false, 0); // end of the last pulse / gap
|
||||
|
||||
SYSTEM_DelayMs(20);
|
||||
BK4819_SetupPowerAmplifier(0, 0);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
|
||||
RADIO_SetupRegisters(true); // back to normal RX
|
||||
|
||||
gOOKSenderState = OOKSENDER_DATA_INPUT;
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- keys
|
||||
|
||||
static void OOK_NextField(const int8_t direction)
|
||||
{
|
||||
for (uint8_t n = 0; n < OOK_FIELD_COUNT; n++) {
|
||||
gOOKSenderField = (uint8_t) ((gOOKSenderField + OOK_FIELD_COUNT + direction) % OOK_FIELD_COUNT);
|
||||
if (fieldLabels[gOOKSenderProtocol][gOOKSenderField] != NULL)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void OOK_Digit(const uint8_t digit)
|
||||
{
|
||||
uint32_t *value = &gOOKSenderValue[gOOKSenderField];
|
||||
|
||||
if (gOOKSenderProtocol == OOKSENDER_PROTO_PT2262 && gOOKSenderField == OOK_FIELD_CODE) {
|
||||
// keys 0, 1 and 2 (= F) append a trit
|
||||
if (digit > 2U || gOOKSenderValue[OOK_FIELD_ARG] >= PT2262_MAX_TRITS) {
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||
return;
|
||||
}
|
||||
*value = (*value << 2) | digit;
|
||||
gOOKSenderValue[OOK_FIELD_ARG]++;
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t max = fieldMax[gOOKSenderProtocol][gOOKSenderField];
|
||||
if (*value > (max - digit) / 10U) { // value * 10 + digit > max, without overflow
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||
return;
|
||||
}
|
||||
*value = *value * 10U + digit;
|
||||
|
||||
// a new rc-switch protocol brings its own pulse length
|
||||
if (gOOKSenderProtocol == OOKSENDER_PROTO_RCSWITCH && gOOKSenderField == OOK_FIELD_EXTRA &&
|
||||
*value >= 1U && *value <= 7U)
|
||||
gOOKSenderValue[OOK_FIELD_PULSE] = rcProtocols[*value - 1U].pulse_us;
|
||||
}
|
||||
|
||||
// returns false when the field was already empty
|
||||
static bool OOK_Backspace(void)
|
||||
{
|
||||
uint32_t *value = &gOOKSenderValue[gOOKSenderField];
|
||||
|
||||
if (gOOKSenderProtocol == OOKSENDER_PROTO_PT2262 && gOOKSenderField == OOK_FIELD_CODE) {
|
||||
if (gOOKSenderValue[OOK_FIELD_ARG] == 0)
|
||||
return false;
|
||||
*value >>= 2;
|
||||
gOOKSenderValue[OOK_FIELD_ARG]--;
|
||||
return true;
|
||||
}
|
||||
if (*value == 0)
|
||||
return false;
|
||||
*value /= 10U;
|
||||
return true;
|
||||
}
|
||||
|
||||
void OOKSENDER_TimeSlice500ms(void) {
|
||||
|
||||
}
|
||||
|
||||
void OOKSENDER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
if (!bKeyPressed) {
|
||||
if (!bKeyPressed || bKeyHeld)
|
||||
return;
|
||||
}
|
||||
bKeyHeld = bKeyHeld;
|
||||
|
||||
switch (gOOKSenderState) {
|
||||
case OOKSENDER_PROTO_CHOOSE:
|
||||
if (Key == KEY_EXIT) {
|
||||
gRequestDisplayScreen = DISPLAY_MAIN;
|
||||
}
|
||||
if (Key == KEY_MENU) {
|
||||
} else if (Key == KEY_MENU) {
|
||||
OOK_SetDefaults();
|
||||
gOOKSenderState = OOKSENDER_DATA_INPUT;
|
||||
}
|
||||
else if (Key == KEY_UP) {
|
||||
gOOKSenderProtocol++;
|
||||
} else if (Key == KEY_UP) {
|
||||
gOOKSenderProtocol = (gOOKSenderProtocol + 1U) % OOKSENDER_PROTO_END;
|
||||
} else if (Key == KEY_DOWN) {
|
||||
gOOKSenderProtocol--;
|
||||
if (gOOKSenderProtocol == 255) {
|
||||
gOOKSenderProtocol = OOKSENDER_PROTO_END - 1;
|
||||
}
|
||||
gOOKSenderProtocol = (gOOKSenderProtocol + OOKSENDER_PROTO_END - 1U) % OOKSENDER_PROTO_END;
|
||||
}
|
||||
gOOKSenderProtocol %= OOKSENDER_PROTO_END;
|
||||
break;
|
||||
|
||||
case OOKSENDER_DATA_INPUT:
|
||||
if (Key == KEY_EXIT) {
|
||||
gOOKSenderState = OOKSENDER_PROTO_CHOOSE;
|
||||
}
|
||||
if (Key == KEY_MENU) {
|
||||
gOOKSenderState = OOKSENDER_SENDING;
|
||||
if (Key <= KEY_9) {
|
||||
OOK_Digit((uint8_t) (Key - KEY_0));
|
||||
} else if (Key == KEY_UP) {
|
||||
OOK_NextField(-1);
|
||||
} else if (Key == KEY_DOWN) {
|
||||
OOK_NextField(1);
|
||||
} else if (Key == KEY_EXIT) {
|
||||
if (!OOK_Backspace())
|
||||
gOOKSenderState = OOKSENDER_PROTO_CHOOSE; // EXIT on an empty field
|
||||
} else if (Key == KEY_MENU || Key == KEY_PTT) {
|
||||
OOK_Transmit();
|
||||
}
|
||||
break;
|
||||
case OOKSENDER_SENDING:
|
||||
uint8_t out[5];
|
||||
if (gOOKSenderProtocol == OOKSENDER_PROTO_OREGONSCIENTIFIC) {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
if (i & 0x01) {
|
||||
AUDIO_AudioPathOff();
|
||||
} else {
|
||||
AUDIO_AudioPathOn();
|
||||
}
|
||||
SYSTICK_DelayUs(500);
|
||||
}
|
||||
AUDIO_AudioPathOff();
|
||||
gOOKSenderState = OOKSENDER_PROTO_CHOOSE;
|
||||
gRequestDisplayScreen = DISPLAY_MESSAGES;
|
||||
break;
|
||||
}
|
||||
if (gOOKSenderProtocol == OOKSENDER_PROTO_EV1527) {
|
||||
// mask just in case
|
||||
// uint32_t id24 = 0x00A38C;
|
||||
// uint8_t btn = 0x04;
|
||||
|
||||
// 3-byte big-endian ID
|
||||
out[0] = (ev1527_id24 >> 16) & 0xFF;
|
||||
out[1] = (ev1527_id24 >> 8) & 0xFF;
|
||||
out[2] = (ev1527_id24 >> 0) & 0xFF;
|
||||
|
||||
// first nibble redundancy copy: 0xBB if btn=0xB
|
||||
out[3] = (ev1527_btn << 4) | 0x04;
|
||||
|
||||
// second copy with MSB flipped (btn ^ 0x8) in the high nibble
|
||||
out[4] = ((ev1527_btn ^ 0x8) << 4);
|
||||
} else {
|
||||
out[0] = (ev1527_id24 >> 8) & 0xFF;
|
||||
out[1] = ev1527_id24 & 0xFF;
|
||||
}
|
||||
|
||||
BK4819_EnterTxMute();
|
||||
RADIO_SetTxParameters();
|
||||
|
||||
uint16_t datX = BK4819_REG_30_ENABLE_VCO_CALIB |
|
||||
BK4819_REG_30_ENABLE_UNKNOWN |
|
||||
BK4819_REG_30_DISABLE_RX_LINK |
|
||||
BK4819_REG_30_DISABLE_AF_DAC |
|
||||
BK4819_REG_30_ENABLE_DISC_MODE |
|
||||
BK4819_REG_30_ENABLE_PLL_VCO |
|
||||
BK4819_REG_30_ENABLE_PA_GAIN |
|
||||
BK4819_REG_30_DISABLE_MIC_ADC |
|
||||
BK4819_REG_30_ENABLE_TX_DSP |
|
||||
BK4819_REG_30_DISABLE_RX_DSP;
|
||||
BK4819_WriteRegister(BK4819_REG_30,
|
||||
datX);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false);
|
||||
SYSTEM_DelayMs(20);
|
||||
|
||||
for (unsigned int x = 0; x < 15; x++) {
|
||||
//for (unsigned int y = 0; y < (dataPacket.src == 665 ? 5 : 2); y++) {
|
||||
for (unsigned int y = 0; y < 5; y++) {
|
||||
for (unsigned char i = 7; i < 8; i--) {
|
||||
if ((out[y] >> i) & 1) {
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, true);
|
||||
// SYSTICK_DelayUs(400 * (dataPacket.src == 665 ? 3 : 2) - 325);
|
||||
SYSTICK_DelayUs(400 * 3 - 325);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false);
|
||||
SYSTICK_DelayUs(400 * 1 - 325);
|
||||
} else {
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, true);
|
||||
SYSTICK_DelayUs(400 * 1 - 325);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false);
|
||||
//SYSTICK_DelayUs(400 * (dataPacket.src == 665 ? 3 : 2) - 325);
|
||||
SYSTICK_DelayUs(400 * 3 - 325);
|
||||
}
|
||||
}
|
||||
}
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false);
|
||||
//SYSTEM_DelayMs((dataPacket.src == 665 ? 3 : 15));
|
||||
SYSTEM_DelayMs(3);
|
||||
}
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_PA_ENABLE, false);
|
||||
SYSTEM_DelayMs(100);
|
||||
BK4819_WriteRegister(BK4819_REG_30, 0xC1FE);
|
||||
gOOKSenderState = OOKSENDER_PROTO_CHOOSE;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
+32
-18
@@ -1,37 +1,51 @@
|
||||
//
|
||||
// Created by bruno on 3/30/25.
|
||||
//
|
||||
// OOK (on/off keyed carrier) sender for 433 MHz style remotes: the carrier is
|
||||
// keyed with the PA enable line, pulse edges are timed against SysTick.
|
||||
//
|
||||
|
||||
//#ifndef BRNQUANFW_OOKSENDER_H
|
||||
//#define BRNQUANFW_OOKSENDER_H
|
||||
#ifndef BRNQUANFW_OOKSENDER_H
|
||||
#define BRNQUANFW_OOKSENDER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "../driver/keyboard.h"
|
||||
#include "../driver/eeprom.h"
|
||||
|
||||
extern uint8_t gOOKSenderState;
|
||||
|
||||
extern uint8_t gOOKSenderProtocol;
|
||||
|
||||
extern uint32_t ev1527_id24;
|
||||
extern uint8_t ev1527_btn;
|
||||
|
||||
typedef enum OOKSENDERSCREENSTATE {
|
||||
OOKSENDER_PROTO_CHOOSE = 0,
|
||||
OOKSENDER_DATA_INPUT,
|
||||
OOKSENDER_SENDING
|
||||
|
||||
} OOKSENDERSCREENSTATE;
|
||||
|
||||
typedef enum OOKSENDERPROTO {
|
||||
OOKSENDER_PROTO_PT2262 = 0,
|
||||
OOKSENDER_PROTO_EV1527,
|
||||
OOKSENDER_PROTO_MANCHESTER,
|
||||
OOKSENDER_PROTO_INTERTECHNO,
|
||||
OOKSENDER_PROTO_OREGONSCIENTIFIC,
|
||||
OOKSENDER_PROTO_PT2262 = 0, // tri-state code, 12 trits (0 / 1 / F)
|
||||
OOKSENDER_PROTO_EV1527, // 20 bit ID + 4 bit key
|
||||
OOKSENDER_PROTO_RCSWITCH, // rc-switch protocols 1..7, decimal code
|
||||
OOKSENDER_PROTO_INTERTECHNO, // Intertechno / KlikAanKlikUit self learning
|
||||
OOKSENDER_PROTO_MANCHESTER, // raw Manchester bits
|
||||
OOKSENDER_PROTO_END,
|
||||
|
||||
} OOKSENDERPROTO;
|
||||
|
||||
// Editable fields, meaning per protocol (labels: OOKSENDER_FieldLabel)
|
||||
enum {
|
||||
OOK_FIELD_CODE = 0, // code / ID / trits (PT2262: 2 bits per trit)
|
||||
OOK_FIELD_ARG, // bits / key / unit / trit count
|
||||
OOK_FIELD_EXTRA, // rc-switch protocol, Intertechno on/off
|
||||
OOK_FIELD_PULSE, // base pulse length in us
|
||||
OOK_FIELD_REPEAT, // number of code repetitions
|
||||
OOK_FIELD_COUNT
|
||||
};
|
||||
|
||||
extern uint8_t gOOKSenderState;
|
||||
extern uint8_t gOOKSenderProtocol;
|
||||
extern uint8_t gOOKSenderField;
|
||||
extern uint32_t gOOKSenderValue[OOK_FIELD_COUNT];
|
||||
|
||||
// NULL when the field is not used by the protocol
|
||||
const char *OOKSENDER_FieldLabel(uint8_t protocol, uint8_t field);
|
||||
|
||||
void OOKSENDER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
|
||||
void OOKSENDER_TimeSlice500ms(void);
|
||||
|
||||
//#endif //BRNQUANFW_OOKSENDER_H
|
||||
#endif //BRNQUANFW_OOKSENDER_H
|
||||
@@ -394,6 +394,49 @@ void BK4819_ToggleGpioOut(BK4819_GPIO_PIN_t Pin, bool bSet)
|
||||
BK4819_WriteRegister(BK4819_REG_33, gBK4819_GpioOutState);
|
||||
}
|
||||
|
||||
// ~250 ns at 48 MHz: keeps the bit-banged SPI clock around 1 MHz
|
||||
#define BK4819_FAST_SPI_WAIT() __asm volatile ("nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop\n nop")
|
||||
|
||||
// BK4819_WriteRegister() without the SYSTICK_DelayUs(1) calls (their overhead makes a
|
||||
// write take ~300 us).
|
||||
static void BK4819_WriteRegisterFast(BK4819_REGISTER_t Register, uint16_t Data)
|
||||
{
|
||||
uint32_t word = ((uint32_t) Register << 16) | Data;
|
||||
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
|
||||
BK4819_FAST_SPI_WAIT();
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
|
||||
|
||||
for (unsigned int i = 0; i < 24; i++) {
|
||||
if (word & 0x800000U)
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
|
||||
else
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
|
||||
BK4819_FAST_SPI_WAIT();
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
|
||||
BK4819_FAST_SPI_WAIT();
|
||||
word <<= 1;
|
||||
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
|
||||
BK4819_FAST_SPI_WAIT();
|
||||
}
|
||||
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
|
||||
BK4819_FAST_SPI_WAIT();
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
|
||||
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
|
||||
}
|
||||
|
||||
void BK4819_ToggleGpioOutFast(BK4819_GPIO_PIN_t Pin, bool bSet)
|
||||
{
|
||||
if (bSet)
|
||||
gBK4819_GpioOutState |= (0x40u >> Pin);
|
||||
else
|
||||
gBK4819_GpioOutState &= ~(0x40u >> Pin);
|
||||
|
||||
BK4819_WriteRegisterFast(BK4819_REG_33, gBK4819_GpioOutState);
|
||||
}
|
||||
|
||||
void BK4819_SetCDCSSCodeWord(uint32_t CodeWord)
|
||||
{
|
||||
// REG_51
|
||||
|
||||
@@ -80,6 +80,9 @@ void BK4819_SetAGC(bool enable);
|
||||
void BK4819_InitAGC(bool amModulation);
|
||||
|
||||
void BK4819_ToggleGpioOut(BK4819_GPIO_PIN_t Pin, bool bSet);
|
||||
// Same as BK4819_ToggleGpioOut() with a fast SPI write (~25 us instead of ~300 us),
|
||||
// for timing critical keying such as OOK.
|
||||
void BK4819_ToggleGpioOutFast(BK4819_GPIO_PIN_t Pin, bool bSet);
|
||||
|
||||
void BK4819_ResetFSK(void);
|
||||
void BK4819_FskClearFifo(void);
|
||||
|
||||
+47
-13
@@ -4,36 +4,70 @@
|
||||
|
||||
#include "ooksender.h"
|
||||
#include "../app/ooksender.h"
|
||||
#include "../external/printf/printf.h"
|
||||
#include "../misc.h"
|
||||
#include "../radio.h"
|
||||
|
||||
const char OOKPROTONAMES[OOKSENDER_PROTO_END][7] = {
|
||||
static const char OOKPROTONAMES[OOKSENDER_PROTO_END][7] = {
|
||||
"PT2262",
|
||||
"EV1527",
|
||||
"MANCHE",
|
||||
"RC-SW",
|
||||
"INTECH",
|
||||
"ORESCI"
|
||||
"MANCH",
|
||||
};
|
||||
|
||||
static void OOK_FormatValue(const uint8_t field, char *out)
|
||||
{
|
||||
const uint32_t value = gOOKSenderValue[field];
|
||||
|
||||
if (gOOKSenderProtocol == OOKSENDER_PROTO_PT2262 && field == OOK_FIELD_CODE) {
|
||||
const uint32_t trits = gOOKSenderValue[OOK_FIELD_ARG];
|
||||
for (uint32_t i = 0; i < trits; i++) {
|
||||
const uint32_t trit = (value >> (2U * (trits - 1U - i))) & 3U;
|
||||
out[i] = trit == 2U ? 'F' : (char) ('0' + trit);
|
||||
}
|
||||
out[trits] = '\0';
|
||||
return;
|
||||
}
|
||||
sprintf(out, "%lu", (unsigned long) value);
|
||||
}
|
||||
|
||||
void OOKSENDER_Display(void) {
|
||||
//char String[19];
|
||||
char String[22];
|
||||
UI_DisplayClear();
|
||||
switch (gOOKSenderState) {
|
||||
case OOKSENDER_PROTO_CHOOSE:
|
||||
UI_PrintStringSmallBold("OOK protocol", 0, 0, 0);
|
||||
for (uint8_t i = 0; i < OOKSENDER_PROTO_END; i++) {
|
||||
if (gOOKSenderProtocol == i) {
|
||||
UI_PrintStringSmallBold(OOKPROTONAMES[i], 0, 0, i /*, 8 */);
|
||||
}
|
||||
UI_PrintStringSmallNormal(OOKPROTONAMES[i], 0, 0, i /*, 8 */);
|
||||
sprintf(String, "%c %s", gOOKSenderProtocol == i ? '>' : ' ', OOKPROTONAMES[i]);
|
||||
UI_PrintStringSmallNormal(String, 0, 0, 1 + i);
|
||||
}
|
||||
UI_PrintStringSmallNormal("MENU select", 0, 0, 7);
|
||||
break;
|
||||
|
||||
case OOKSENDER_DATA_INPUT:
|
||||
UI_PrintString("ENTER DATA", 0, 0, 0 /*, 8 */);
|
||||
break;
|
||||
case OOKSENDER_SENDING:
|
||||
UI_PrintString("SENDING OOK", 0, 0, 0 /*, 8 */);
|
||||
case OOKSENDER_SENDING: {
|
||||
uint8_t line = 1;
|
||||
sprintf(String, "%s %lu.%05lu", OOKPROTONAMES[gOOKSenderProtocol],
|
||||
(unsigned long) (gCurrentVfo->pTX->Frequency / 100000U),
|
||||
(unsigned long) (gCurrentVfo->pTX->Frequency % 100000U));
|
||||
UI_PrintStringSmallBold(String, 0, 0, 0);
|
||||
for (uint8_t f = 0; f < OOK_FIELD_COUNT; f++) {
|
||||
const char *label = OOKSENDER_FieldLabel(gOOKSenderProtocol, f);
|
||||
char value[14];
|
||||
if (label == NULL)
|
||||
continue;
|
||||
OOK_FormatValue(f, value);
|
||||
sprintf(String, "%c%-6s %s", gOOKSenderField == f ? '>' : ' ', label, value);
|
||||
UI_PrintStringSmallNormal(String, 0, 0, line++);
|
||||
}
|
||||
UI_PrintStringSmallNormal(gOOKSenderState == OOKSENDER_SENDING ? "SENDING..." : "PTT/MENU send",
|
||||
0, 0, 7);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ST7565_BlitFullScreen();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user