143 lines
5.2 KiB
C
143 lines
5.2 KiB
C
//
|
|
// Created by bruno on 3/30/25.
|
|
//
|
|
|
|
#include "ooksender.h"
|
|
#include "ui/ui.h"
|
|
#include "driver/uart.h"
|
|
#include "driver/systick.h"
|
|
#include "driver/bk4819.h"
|
|
#include "driver/system.h"
|
|
#include "radio.h"
|
|
#include "audio.h"
|
|
|
|
uint8_t gOOKSenderState = OOKSENDER_PROTO_CHOOSE;
|
|
|
|
uint8_t gOOKSenderProtocol = OOKSENDER_PROTO_EV1527;
|
|
|
|
uint32_t ev1527_id24 = 0;
|
|
uint8_t ev1527_btn = 0;
|
|
|
|
|
|
void OOKSENDER_TimeSlice500ms(void) {
|
|
|
|
}
|
|
|
|
void OOKSENDER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
|
if (!bKeyPressed) {
|
|
return;
|
|
}
|
|
bKeyHeld = bKeyHeld;
|
|
switch (gOOKSenderState) {
|
|
case OOKSENDER_PROTO_CHOOSE:
|
|
if (Key == KEY_EXIT) {
|
|
gRequestDisplayScreen = DISPLAY_MAIN;
|
|
}
|
|
if (Key == KEY_MENU) {
|
|
gOOKSenderState = OOKSENDER_DATA_INPUT;
|
|
}
|
|
else if (Key == KEY_UP) {
|
|
gOOKSenderProtocol++;
|
|
} else if (Key == KEY_DOWN) {
|
|
gOOKSenderProtocol--;
|
|
if (gOOKSenderProtocol == 255) {
|
|
gOOKSenderProtocol = OOKSENDER_PROTO_END - 1;
|
|
}
|
|
}
|
|
gOOKSenderProtocol %= OOKSENDER_PROTO_END;
|
|
break;
|
|
case OOKSENDER_DATA_INPUT:
|
|
if (Key == KEY_EXIT) {
|
|
gOOKSenderState = OOKSENDER_PROTO_CHOOSE;
|
|
}
|
|
if (Key == KEY_MENU) {
|
|
gOOKSenderState = OOKSENDER_SENDING;
|
|
}
|
|
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;
|
|
}
|
|
} |