wip cc1101 work
This commit is contained in:
parent
b007b9cb60
commit
3020a2a6b9
@ -70,7 +70,8 @@ endif
|
|||||||
APP_CC1101 ?= 0
|
APP_CC1101 ?= 0
|
||||||
ifeq ($(APP_CC1101), 1)
|
ifeq ($(APP_CC1101), 1)
|
||||||
CFLAGS += -DAPP_CC1101
|
CFLAGS += -DAPP_CC1101
|
||||||
C_SOURCES += $(APP_DIR)/cc1101-workaround/cc1101-workaround.c
|
CPP_SOURCES += $(APP_DIR)/cc1101-workaround/cc1101-workaround.cpp
|
||||||
|
CPP_SOURCES += $(APP_DIR)/cc1101-workaround/cc1101.cpp
|
||||||
APP_INPUT = 1
|
APP_INPUT = 1
|
||||||
APP_DISPLAY = 1
|
APP_DISPLAY = 1
|
||||||
endif
|
endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "u8g2.h"
|
#include "u8g2.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "cc1101/cc1101.h"
|
#include "cc1101-workaround/cc1101.h"
|
||||||
|
|
||||||
#define MIN_DBM -120
|
#define MIN_DBM -120
|
||||||
#define STEP_DBM 10
|
#define STEP_DBM 10
|
||||||
@ -23,6 +23,7 @@ uint8_t rssi_offset[NUM_OF_SUB_BANDS] = {74, 74, 74, 74, 74, 74, 74};
|
|||||||
#define CHAN_SPA 0.05 // channel spacing
|
#define CHAN_SPA 0.05 // channel spacing
|
||||||
|
|
||||||
float base_freq[NUM_OF_SUB_BANDS] = {387, 399.8, 412.6, 425.4, 438.2, 451, 463.8};
|
float base_freq[NUM_OF_SUB_BANDS] = {387, 399.8, 412.6, 425.4, 438.2, 451, 463.8};
|
||||||
|
|
||||||
// FREQ2,FREQ1,FREQ0
|
// FREQ2,FREQ1,FREQ0
|
||||||
uint8_t freqSettings[NUM_OF_SUB_BANDS][3] = {
|
uint8_t freqSettings[NUM_OF_SUB_BANDS][3] = {
|
||||||
{0x0E, 0xE2, 0x76}, // band0
|
{0x0E, 0xE2, 0x76}, // band0
|
||||||
@ -32,25 +33,31 @@ uint8_t freqSettings[NUM_OF_SUB_BANDS][3] = {
|
|||||||
{0x10, 0xDA, 0x76},
|
{0x10, 0xDA, 0x76},
|
||||||
{0x11, 0x58, 0x8F},
|
{0x11, 0x58, 0x8F},
|
||||||
{0x11, 0xD6, 0x8F}}; // band2
|
{0x11, 0xD6, 0x8F}}; // band2
|
||||||
|
|
||||||
// no change in TEST0 WHERE (>430.5MHz) one should change from TEST0=0x0B to 0x09
|
// no change in TEST0 WHERE (>430.5MHz) one should change from TEST0=0x0B to 0x09
|
||||||
uint16_t limitTest0Reg[NUM_OF_SUB_BANDS] = {256, 256, 256, 103, 0, 0, 0};
|
uint16_t limitTest0Reg[NUM_OF_SUB_BANDS] = {256, 256, 256, 103, 0, 0, 0};
|
||||||
|
|
||||||
/* setting to use 50khz channel spacing whole band*****************************************/
|
/* setting to use 50khz channel spacing whole band*****************************************/
|
||||||
|
|
||||||
//int16_t rssiData[NUM_OF_SUB_BANDS][256];
|
|
||||||
int16_t rssiTable[256];
|
int16_t rssiTable[256];
|
||||||
uint16_t channelNumber[256];
|
uint16_t channelNumber[256];
|
||||||
uint8_t carrierSenseCounter = 0; //counter used to keep track on how many CS has been asserted
|
|
||||||
|
// counter used to keep track on how many CS has been asserted
|
||||||
|
uint8_t carrierSenseCounter = 0;
|
||||||
|
|
||||||
uint8_t firstChannel[NUM_OF_SUB_BANDS] = {0, 0, 0, 160, 0, 0, 0};
|
uint8_t firstChannel[NUM_OF_SUB_BANDS] = {0, 0, 0, 160, 0, 0, 0};
|
||||||
|
|
||||||
// stop channel in each subband
|
// stop channel in each subband
|
||||||
uint8_t lastChannel[NUM_OF_SUB_BANDS] = {255, 255, 255, 180, 255, 255, 4};
|
uint8_t lastChannel[NUM_OF_SUB_BANDS] = {255, 255, 255, 180, 255, 255, 4};
|
||||||
|
|
||||||
// initialized to a value lower than the rssi threshold/ higher than channel number
|
// initialized to a value lower than the rssi threshold/ higher than channel number
|
||||||
int16_t highRSSI[NUM_OF_SUB_BANDS] =
|
int16_t highRSSI[NUM_OF_SUB_BANDS] =
|
||||||
{MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM};
|
{MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM, MIN_DBM};
|
||||||
|
|
||||||
uint16_t selectedChannel[NUM_OF_SUB_BANDS] = {300, 300, 300, 300, 300, 300, 300};
|
uint16_t selectedChannel[NUM_OF_SUB_BANDS] = {300, 300, 300, 300, 300, 300, 300};
|
||||||
|
|
||||||
int8_t activeBand; // store subband that contains strongest signal
|
int8_t activeBand; // store subband that contains strongest signal
|
||||||
uint16_t activeChannel; //
|
uint16_t activeChannel;
|
||||||
|
|
||||||
int16_t calRSSI(uint8_t rssi_dec, uint8_t rssiOffset) {
|
int16_t calRSSI(uint8_t rssi_dec, uint8_t rssiOffset) {
|
||||||
int16_t rssi;
|
int16_t rssi;
|
||||||
@ -65,7 +72,7 @@ int16_t calRSSI(uint8_t rssi_dec, uint8_t rssiOffset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void scanFreq(CC1101* cc1101) {
|
void scanFreq(CC1101* cc1101) {
|
||||||
uint8_t calCounter; //to deterin when to calibrate
|
uint8_t calCounter; // to determine when to calibrate
|
||||||
uint8_t subBand;
|
uint8_t subBand;
|
||||||
uint16_t channel;
|
uint16_t channel;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
@ -135,14 +142,16 @@ void scanFreq(CC1101* cc1101) {
|
|||||||
#endif
|
#endif
|
||||||
} // end channel lop
|
} // end channel lop
|
||||||
|
|
||||||
//1.5)before moving to next sub band, scan through rssiTable to find highest rssi value
|
// 1.5)before moving to next sub band,
|
||||||
|
// scan through rssiTable to find highest rssi value
|
||||||
for(i = 0; i < carrierSenseCounter; i++) {
|
for(i = 0; i < carrierSenseCounter; i++) {
|
||||||
if(rssiTable[i] > highRSSI[subBand]) {
|
if(rssiTable[i] > highRSSI[subBand]) {
|
||||||
highRSSI[subBand] = rssiTable[i];
|
highRSSI[subBand] = rssiTable[i];
|
||||||
selectedChannel[subBand] = channelNumber[i];
|
selectedChannel[subBand] = channelNumber[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Serial.print("subBand:------------------>");
|
|
||||||
|
// printf("subBand:------------------>");
|
||||||
// Serial.println(subBand);
|
// Serial.println(subBand);
|
||||||
// Serial.print("selectedChannel:");
|
// Serial.print("selectedChannel:");
|
||||||
// Serial.println(selectedChannel[subBand]);
|
// Serial.println(selectedChannel[subBand]);
|
||||||
@ -180,16 +189,20 @@ void jamming(CC1101* cc1101, uint8_t band, uint16_t channel, uint16_t miniSec) {
|
|||||||
cc1101->SpiStrobe(CC1101_SIDLE);
|
cc1101->SpiStrobe(CC1101_SIDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern QueueHandle_t event_queue;
|
extern "C" void cc1101_workaround(void* p) {
|
||||||
|
FuriRecordSubscriber* fb_record =
|
||||||
|
furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
||||||
|
|
||||||
bool jamm_on = false;
|
if(fb_record == NULL) {
|
||||||
|
printf("[cc1101] cannot create fb record\n");
|
||||||
void set_jam(bool state) {
|
furiac_exit(NULL);
|
||||||
jamm_on = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void radio() {
|
printf("[cc1101] creating device\n");
|
||||||
CC1101 cc1101(SS_PIN, GDO0, GDO2);
|
|
||||||
|
CC1101 cc1101(GpioPin{CC1101_CS_GPIO_Port, CC1101_CS_Pin});
|
||||||
|
|
||||||
|
printf("[cc1101] init device\n");
|
||||||
|
|
||||||
uint8_t address = cc1101.Init();
|
uint8_t address = cc1101.Init();
|
||||||
|
|
||||||
@ -199,66 +212,17 @@ extern "C" void radio() {
|
|||||||
printf("CC1101 init fail\n");
|
printf("CC1101 init fail\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setting to use 50khz channel spacing**************************************/
|
// RX filter bandwidth 58.035714(0xFD) 100k(0xCD) 200k(0x8D)
|
||||||
cc1101.SpiWriteReg(
|
cc1101.SpiWriteReg(CC1101_MDMCFG4, 0xCD);
|
||||||
CC1101_MDMCFG4, 0xCD); // RX filter bandwidth 58.035714(0xFD) 100k(0xCD) 200k(0x8D)
|
// datarate config 250kBaud for the purpose of fast rssi measurement
|
||||||
cc1101.SpiWriteReg(
|
cc1101.SpiWriteReg(CC1101_MDMCFG3, 0x3B);
|
||||||
CC1101_MDMCFG3, 0x3B); //datarate config 250kBaud for the purpose of fast rssi measurement
|
// FEC preamble etc. last 2 bits for channel spacing
|
||||||
cc1101.SpiWriteReg(CC1101_MDMCFG1, 0x20); //FEC preamble etc. last 2 bits for channel spacing
|
cc1101.SpiWriteReg(CC1101_MDMCFG1, 0x20);
|
||||||
cc1101.SpiWriteReg(CC1101_MDMCFG0, 0xF8); //50khz channel spacing
|
// 50khz channel spacing
|
||||||
|
cc1101.SpiWriteReg(CC1101_MDMCFG0, 0xF8);
|
||||||
Event event;
|
|
||||||
event.type = EventTypeRadio;
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
for(uint8_t i = 0; i <= NUM_OF_SUB_BANDS; i++) {
|
u8g2_t* fb = (u8g2_t*)furi_take(fb_record);
|
||||||
highRSSI[i] = MIN_DBM;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeChannel = 300;
|
|
||||||
|
|
||||||
scanFreq(&cc1101);
|
|
||||||
|
|
||||||
if(activeChannel < 256 && highRSSI[activeBand] > RSSI_THRESHOLD) {
|
|
||||||
float freq = base_freq[activeBand] + CHAN_SPA * activeChannel;
|
|
||||||
|
|
||||||
/*
|
|
||||||
printf(
|
|
||||||
"channel: %d, freq: %d, RSSI: %d\n",
|
|
||||||
activeChannel,
|
|
||||||
(uint32_t)(freq * 1000),
|
|
||||||
highRSSI[activeBand]
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
event.value.radio.freq = freq;
|
|
||||||
event.value.radio.rssi_db = highRSSI[activeBand];
|
|
||||||
xQueueSend(event_queue, (void*)&event, 0);
|
|
||||||
|
|
||||||
if(jamm_on) {
|
|
||||||
jamming(&cc1101, activeBand, activeChannel, 500);
|
|
||||||
} else {
|
|
||||||
osDelay(1000);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// printf("0 carrier sensed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cc1101_workaround(void* p) {
|
|
||||||
FuriRecordSubscriber* fb_record =
|
|
||||||
furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
if(fb_record == NULL) {
|
|
||||||
printf("[cc1101] cannot create fb record\n");
|
|
||||||
furiac_exit(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
u8g2_t* fb = furi_take(fb_record);
|
|
||||||
if(fb != NULL) {
|
if(fb != NULL) {
|
||||||
u8g2_SetFont(fb, u8g2_font_6x10_mf);
|
u8g2_SetFont(fb, u8g2_font_6x10_mf);
|
||||||
u8g2_SetDrawColor(fb, 1);
|
u8g2_SetDrawColor(fb, 1);
|
||||||
@ -267,6 +231,51 @@ void cc1101_workaround(void* p) {
|
|||||||
}
|
}
|
||||||
furi_commit(fb_record);
|
furi_commit(fb_record);
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(uint8_t i = 0; i <= NUM_OF_SUB_BANDS; i++) {
|
||||||
|
highRSSI[i] = MIN_DBM;
|
||||||
|
}
|
||||||
|
|
||||||
|
activeChannel = 300;
|
||||||
|
|
||||||
|
jamming(&cc1101, activeBand, activeChannel, 500);
|
||||||
|
|
||||||
|
scanFreq(&cc1101);
|
||||||
|
|
||||||
|
if(activeChannel < 256 && highRSSI[activeBand] > RSSI_THRESHOLD) {
|
||||||
|
float freq = base_freq[activeBand] + CHAN_SPA * activeChannel;
|
||||||
|
|
||||||
|
printf(
|
||||||
|
"channel: %d, freq: %d, RSSI: %d\n",
|
||||||
|
activeChannel,
|
||||||
|
(uint32_t)(freq * 1000),
|
||||||
|
highRSSI[activeBand]
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(jamm_on) {
|
||||||
|
jamming(&cc1101, activeBand, activeChannel, 500);
|
||||||
|
} else {
|
||||||
|
osDelay(1000);
|
||||||
|
}
|
||||||
|
*
|
||||||
|
} else {
|
||||||
|
// printf("0 carrier sensed\n");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t band = 4; // 438.2 MHz
|
||||||
|
|
||||||
|
/*
|
||||||
|
cc1101.SetFreq(freqSettings[band][0], freqSettings[band][1], freqSettings[band][2]);
|
||||||
|
cc1101.SetChannel(0);
|
||||||
|
cc1101.SetTransmit();
|
||||||
|
|
||||||
|
delay(5000);
|
||||||
|
|
||||||
|
cc1101.SpiStrobe(CC1101_SIDLE);
|
||||||
|
*/
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -124,7 +124,7 @@ typedef struct {
|
|||||||
static void handle_fb_change(const void* fb, size_t fb_size, void* raw_ctx) {
|
static void handle_fb_change(const void* fb, size_t fb_size, void* raw_ctx) {
|
||||||
DisplayCtx* ctx = (DisplayCtx*)raw_ctx; // make right type
|
DisplayCtx* ctx = (DisplayCtx*)raw_ctx; // make right type
|
||||||
|
|
||||||
fuprintf(ctx->log, "[display_u8g2] change fb\n");
|
// fuprintf(ctx->log, "[display_u8g2] change fb\n");
|
||||||
|
|
||||||
// send update to app thread
|
// send update to app thread
|
||||||
xSemaphoreGive(ctx->update);
|
xSemaphoreGive(ctx->update);
|
||||||
|
@ -125,6 +125,8 @@ void Error_Handler(void);
|
|||||||
#define BUTTON_OK_EXTI_IRQn EXTI9_5_IRQn
|
#define BUTTON_OK_EXTI_IRQn EXTI9_5_IRQn
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
|
#define MISO_PIN GpioPin{.port = GPIOC, .pin = GPIO_PIN_11}
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
x
Reference in New Issue
Block a user