unleashed-firmware/applications/cc1101-workaround/cc1101-workaround.cpp

614 lines
20 KiB
C++
Raw Normal View History

[FL-140] Core api dynamic records (#296) * SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
#include "cc1101.h"
#include <furi.h>
#include <api-hal.h>
[FL-140] Core api dynamic records (#296) * SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
#include <gui/gui.h>
#include <input/input.h>
2020-10-13 20:59:39 +03:00
2020-10-18 07:47:49 +03:00
#define RSSI_DELAY 5000 //rssi delay in micro second
2020-10-14 10:26:23 +03:00
#define CHAN_SPA 0.05 // channel spacing
2020-10-13 20:59:39 +03:00
2020-10-18 07:47:49 +03:00
int16_t rssi_to_dbm(uint8_t rssi_dec, uint8_t rssiOffset) {
2020-10-13 20:59:39 +03:00
int16_t rssi;
if(rssi_dec >= 128) {
rssi = (int16_t)((int16_t)(rssi_dec - 256) / 2) - rssiOffset;
} else {
rssi = (rssi_dec / 2) - rssiOffset;
}
return rssi;
}
2020-10-18 07:47:49 +03:00
typedef struct {
float base_freq;
uint8_t reg[3]; // FREQ2, FREQ1, FREQ0
uint8_t first_channel;
uint8_t last_channel;
uint8_t rssi_offset;
} Band;
2020-10-13 20:59:39 +03:00
2020-10-18 07:47:49 +03:00
typedef struct {
2020-10-18 10:47:38 +03:00
const Band* band;
2020-10-18 07:47:49 +03:00
uint16_t channel;
} FreqConfig;
2020-10-13 20:59:39 +03:00
void setup_freq(CC1101* cc1101, float freq) {
// cc1101->SpiWriteReg(CC1101_MCSM0, 0x08); // disalbe FS_AUTOCAL
// cc1101->SpiWriteReg(CC1101_AGCCTRL2, 0x43 | 0x0C); // MAX_DVGA_GAIN to 11 for fast rssi
// cc1101->SpiWriteReg(CC1101_AGCCTRL0, 0xB0); // max AGC WAIT_TIME; 0 filter_length
// cc1101->SetMod(GFSK); // set to GFSK for fast rssi measurement | +8 is dcfilter off
2020-10-13 20:59:39 +03:00
uint32_t freq_reg = freq * 1e6 / (F_OSC / 65536);
cc1101->SetFreq((freq_reg >> 16) & 0xFF, (freq_reg >> 8) & 0xFF, (freq_reg)&0xFF);
cc1101->SetChannel(0);
2020-10-13 20:59:39 +03:00
/*
2020-10-18 07:47:49 +03:00
//set test0 to 0x09
cc1101->SpiWriteReg(CC1101_TEST0, 0x09);
//set FSCAL2 to 0x2A to force VCO HIGH
cc1101->SpiWriteReg(CC1101_FSCAL2, 0x2A);
2020-10-13 20:59:39 +03:00
2020-10-18 07:47:49 +03:00
// perform a manual calibration by issuing SCAL command
cc1101->SpiStrobe(CC1101_SCAL);
*/
2020-10-13 20:59:39 +03:00
}
static GpioPin debug_0 = {GPIOB, GPIO_PIN_2};
2020-10-18 10:47:38 +03:00
int16_t rx_rssi(CC1101* cc1101, const FreqConfig* config) {
// cc1101->SpiStrobe(CC1101_SFRX);
// cc1101->SetReceive();
// uint8_t begin_size = cc1101->SpiReadStatus(CC1101_RXBYTES);
// uint8_t rx_status = cc1101->SpiReadStatus(CC1101_MARCSTATE);
// delay_us(RSSI_DELAY);
// osDelay(15);
2020-10-13 20:59:39 +03:00
// uint8_t end_size = cc1101->SpiReadStatus(CC1101_RXBYTES);
2020-10-19 09:23:49 +03:00
2020-10-18 07:47:49 +03:00
// 1.4.8) read PKTSTATUS register while the radio is in RX state
/*uint8_t _pkt_status = */ // cc1101->SpiReadStatus(CC1101_PKTSTATUS);
2020-10-19 09:23:49 +03:00
2020-10-18 07:47:49 +03:00
// 1.4.9) enter IDLE state by issuing a SIDLE command
// cc1101->SpiStrobe(CC1101_SIDLE);
2020-10-18 07:47:49 +03:00
// //read rssi value and converto to dBm form
uint8_t rssi_dec = (uint8_t)cc1101->SpiReadStatus(CC1101_RSSI);
int16_t rssi_dBm = rssi_to_dbm(rssi_dec, config->band->rssi_offset);
/*
char buf[256];
sprintf(buf, "status: %d -> %d, rssi: %d\n", rx_status, cc1101->SpiReadStatus(CC1101_MARCSTATE), rssi_dBm);
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf(buf);
sprintf(buf, "begin: %d, end: %d\n", begin_size, end_size);
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf(buf);
*/
// uint8_t rx_data[64];
// uint8_t fifo_length = end_size - begin_size;
2020-10-18 07:10:15 +03:00
/*
if(fifo_length < 64) {
// cc1101->SpiReadBurstReg(CC1101_RXFIFO, rx_data, fifo_length);
*
printf("FIFO:");
for(uint8_t i = 0; i < fifo_length; i++) {
for(uint8_t bit = 0; bit < 8; bit++) {
printf("%s", (rx_data[i] & (1 << bit)) > 0 ? "1" : "0");
}
printf(" ");
}
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("\r\n");
*
for(uint8_t i = 0; i < fifo_length; i++) {
for(uint8_t bit = 0; bit < 8; bit++) {
gpio_write((GpioPin*)&debug_0, (rx_data[i] & (1 << bit)) > 0);
delay_us(5);
}
}
} else {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("fifo size over\r\n");
}
*/
2020-10-18 10:47:38 +03:00
return rssi_dBm;
}
/*
void flp_config(CC1101* cc1101) {
cc1101->SpiWriteReg(
CC1101_MCSM0, 0x18); // calibrate when going from IDLE to RX or TX ; 149 - 155 μs timeout
// MCSM0.FS_AUTOCAL[1:0] = 1
cc1101->SpiWriteReg(CC1101_AGCCTRL2, 0x43);
cc1101->SpiWriteReg(CC1101_AGCCTRL1, 0x49);
cc1101->SpiWriteReg(CC1101_AGCCTRL0, 0x91);
//freq synthesizer calibration
cc1101->SpiWriteReg(CC1101_FSCAL3, 0xEA);
cc1101->SpiWriteReg(CC1101_FSCAL2, 0x2A);
cc1101->SpiWriteReg(CC1101_FSCAL1, 0x00);
cc1101->SpiWriteReg(CC1101_FSCAL0, 0x1F);
// async data out
cc1101->SpiSetRegValue(CC1101_IOCFG0, 13, 5, 0); // GDO0 Output Pin Configuration
cc1101->SpiSetRegValue(CC1101_IOCFG0, 13, 5, 0); // WAT
// FIFOTHR.ADC_RETENTION = 1
cc1101->SpiSetRegValue(CC1101_FIFOTHR, 1, 6, 6);
// PKTCTRL1.APPEND_STATUS = 0
cc1101->SpiSetRegValue(CC1101_PKTCTRL1, 0, 2, 2);
// PKTCTRL0.WHITE_DATA = 0
cc1101->SpiSetRegValue(CC1101_PKTCTRL0, 0, 6, 6);
// PKTCTRL0.LENGTH_CONFIG = 2 // Infinite packet length mode
cc1101->SpiSetRegValue(CC1101_PKTCTRL0, 2, 1, 0);
// PKTCTRL0.CRC_EN = 0
cc1101->SpiSetRegValue(CC1101_PKTCTRL0, 0, 2, 2);
// PKTCTRL0.PKT_FORMAT = 3
cc1101->SpiSetRegValue(CC1101_PKTCTRL0, 3, 5, 4);
// bandwidth 50-100 kHz
if(!cc1101->setRxBandwidth(75.0)) {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("wrong rx bw\r\n");
}
// datarate ~30 kbps
if(!cc1101->setBitRate(100.)) {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("wrong bitrate\r\n");
}
// mod
// MDMCFG2.MOD_FORMAT = 3 (3: OOK, 0: 2-FSK)
cc1101->SpiSetRegValue(CC1101_MDMCFG2, 3, 6, 4);
// MDMCFG2.SYNC_MODE = 0
cc1101->SpiSetRegValue(CC1101_MDMCFG2, 0, 2, 0);
}
*/
void tx_config(CC1101* cc1101) {
// cc1101->SpiWriteReg(CC1101_IOCFG2,0x0B); //GDO2 Output Pin Configuration
// cc1101->SpiWriteReg(CC1101_IOCFG0,0x0C); //GDO0 Output Pin Configuration
cc1101->SpiSetRegValue(CC1101_IOCFG0, 13, 5, 0); // GDO0 Output Pin Configuration
cc1101->SpiWriteReg(CC1101_FIFOTHR, 0x47); //RX FIFO and TX FIFO Thresholds
cc1101->SpiWriteReg(CC1101_PKTCTRL0, 0x32); //Packet Automation Control
cc1101->SpiWriteReg(CC1101_FSCTRL1, 0x06); //Frequency Synthesizer Control
cc1101->SpiWriteReg(CC1101_FREQ2, 0x10); //Frequency Control Word, High Byte
cc1101->SpiWriteReg(CC1101_FREQ1, 0xB0); //Frequency Control Word, Middle Byte
cc1101->SpiWriteReg(CC1101_FREQ0, 0x71); //Frequency Control Word, Low Byte
cc1101->SpiWriteReg(CC1101_MDMCFG4, 0x6A); //Modem Configuration
cc1101->SpiWriteReg(CC1101_MDMCFG3, 0x2E); //Modem Configuration
cc1101->SpiWriteReg(CC1101_MDMCFG2, 0x30); //Modem Configuration
cc1101->SpiWriteReg(CC1101_DEVIATN, 0x15); //Modem Deviation Setting
cc1101->SpiWriteReg(CC1101_MCSM0, 0x18); //Main Radio Control State Machine Configuration
cc1101->SpiWriteReg(CC1101_FOCCFG, 0x16); //Frequency Offset Compensation Configuration
cc1101->SpiWriteReg(CC1101_WORCTRL, 0xFB); //Wake On Radio Control
cc1101->SpiWriteReg(CC1101_FREND0, 0x11); //Front End TX Configuration
cc1101->SpiWriteReg(CC1101_FSCAL3, 0xE9); //Frequency Synthesizer Calibration
cc1101->SpiWriteReg(CC1101_FSCAL2, 0x2A); //Frequency Synthesizer Calibration
cc1101->SpiWriteReg(CC1101_FSCAL1, 0x00); //Frequency Synthesizer Calibration
cc1101->SpiWriteReg(CC1101_FSCAL0, 0x1F); //Frequency Synthesizer Calibration
/*
cc1101->SpiWriteReg(CC1101_TEST2, 0x81); //Various Test Settings
cc1101->SpiWriteReg(CC1101_TEST1, 0x35); //Various Test Settings
cc1101->SpiWriteReg(CC1101_TEST0, 0x09); //Various Test Settings
*/
}
// f = (f_osc/65536) * (FREQ + CHAN * (256 + CH_SP_M) * 2^(CH_SP_E - 2))
// FREQ = f / (f_osc/65536)
// CHAN = 0
// TODO: CHAN number not implemented!
// TODO: reg values not affetcts
const Band bands[] = {
{301., {0x00, 0x00, 0x00}, 0, 255, 74},
{315., {0x00, 0x00, 0x00}, 0, 255, 74},
{346., {0x00, 0x00, 0x00}, 0, 255, 74},
{385., {0x00, 0x00, 0x00}, 0, 255, 74},
{433.92, {0x00, 0x00, 0x00}, 0, 255, 74},
2020-12-15 00:04:44 +03:00
{438.9, {0x00, 0x00, 0x00}, 0, 255, 74},
{463., {0x00, 0x00, 0x00}, 0, 255, 74},
{781., {0x00, 0x00, 0x00}, 0, 255, 74},
{868., {0x00, 0x00, 0x00}, 0, 255, 74},
{915., {0x00, 0x00, 0x00}, 0, 255, 74},
{925., {0x00, 0x00, 0x00}, 0, 255, 74},
2020-10-18 07:10:15 +03:00
};
2020-10-18 10:47:38 +03:00
const FreqConfig FREQ_LIST[] = {
{&bands[0], 0},
{&bands[1], 0},
{&bands[2], 0},
{&bands[3], 0},
{&bands[4], 0},
{&bands[5], 0},
{&bands[6], 0},
{&bands[7], 0},
{&bands[8], 0},
{&bands[9], 0},
2020-12-15 00:04:44 +03:00
{&bands[10], 0},
2020-10-18 07:10:15 +03:00
};
extern "C" void cc1101_isr(void* _pin, void* _ctx) {
uint32_t pin = (uint32_t)_pin;
if(pin == CC1101_G0_Pin) {
gpio_write((GpioPin*)&debug_0, gpio_read(&cc1101_g0_gpio));
}
}
2020-10-18 07:10:15 +03:00
typedef enum {
EventTypeTick,
EventTypeKey,
} EventType;
typedef struct {
union {
InputEvent input;
} value;
EventType type;
} AppEvent;
2020-10-18 07:10:15 +03:00
2020-10-19 09:23:49 +03:00
typedef enum { ModeRx, ModeTx } Mode;
2020-10-18 07:10:15 +03:00
2020-10-18 10:47:38 +03:00
typedef struct {
int16_t dbm;
uint8_t reg;
} TxLevel;
const TxLevel TX_LEVELS[] = {
{-10, 0},
{-5, 0},
{0, 0},
{5, 0},
};
2020-10-18 07:10:15 +03:00
typedef struct {
Mode mode;
size_t active_freq_idx;
float active_freq;
2020-10-18 07:47:49 +03:00
int16_t last_rssi;
2020-10-18 10:47:38 +03:00
size_t tx_level;
2020-10-18 07:47:49 +03:00
bool need_cc1101_conf;
RfBand rf_band;
2020-10-18 07:10:15 +03:00
} State;
static void render_callback(Canvas* canvas, void* ctx) {
2020-10-18 07:10:15 +03:00
State* state = (State*)acquire_mutex((ValueMutex*)ctx, 25);
2020-10-13 20:59:39 +03:00
if(!state) return;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 12, "cc1101 workaround");
2020-10-18 07:10:15 +03:00
{
char buf[24];
sprintf(
buf,
"freq: %ld.%02ld MHz",
(uint32_t)state->active_freq,
(uint32_t)(state->active_freq * 100.) % 100);
2020-10-18 07:10:15 +03:00
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 25, buf);
2020-10-18 07:10:15 +03:00
}
2020-10-18 07:47:49 +03:00
{
canvas_set_font(canvas, FontSecondary);
2020-10-18 07:47:49 +03:00
if(state->need_cc1101_conf) {
canvas_draw_str(canvas, 2, 36, "mode: configuring...");
2020-10-18 07:47:49 +03:00
} else if(state->mode == ModeRx) {
canvas_draw_str(canvas, 2, 36, "mode: RX");
2020-10-18 07:47:49 +03:00
} else if(state->mode == ModeTx) {
canvas_draw_str(canvas, 2, 36, "mode: TX");
2020-10-18 07:47:49 +03:00
} else {
canvas_draw_str(canvas, 2, 36, "mode: unknown");
2020-10-18 07:47:49 +03:00
}
}
{
if(!state->need_cc1101_conf && state->mode == ModeRx) {
char buf[24];
sprintf(buf, "RSSI: %d dBm", state->last_rssi);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 48, buf);
2020-10-18 07:47:49 +03:00
}
}
2020-10-18 10:47:38 +03:00
{
char buf[24];
// sprintf(buf, "tx level: %d dBm", TX_LEVELS[state->tx_level].dbm);
sprintf(buf, "RF band: %d", (uint8_t)state->rf_band);
2020-10-18 10:47:38 +03:00
canvas_set_font(canvas, FontSecondary);
if(state->rf_band == RfBandIsolation) {
canvas_draw_str(canvas, 2, 63, "RF band: isolation");
} else {
canvas_draw_str(canvas, 2, 63, buf);
}
2020-10-18 10:47:38 +03:00
}
2020-10-18 07:10:15 +03:00
release_mutex((ValueMutex*)ctx, state);
}
static void input_callback(InputEvent* input_event, void* ctx) {
[FL-140] Core api dynamic records (#296) * SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
osMessageQueueId_t event_queue = ctx;
2020-10-18 07:10:15 +03:00
AppEvent event;
2020-10-18 07:10:15 +03:00
event.type = EventTypeKey;
event.value.input = *input_event;
osMessageQueuePut(event_queue, &event, 0, 0);
2020-10-18 05:43:09 +03:00
}
extern "C" int32_t cc1101_workaround(void* p) {
osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(AppEvent), NULL);
furi_check(event_queue);
2020-10-18 07:10:15 +03:00
State _state;
_state.mode = ModeRx;
_state.active_freq_idx = 4;
FreqConfig conf = FREQ_LIST[_state.active_freq_idx];
_state.active_freq = conf.band->base_freq + CHAN_SPA * conf.channel;
2020-10-18 07:47:49 +03:00
_state.need_cc1101_conf = true;
_state.last_rssi = 0;
2020-10-18 10:47:38 +03:00
_state.tx_level = 0;
_state.rf_band = RfBand1;
2020-10-18 07:10:15 +03:00
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, &_state, sizeof(State))) {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] cannot create mutex\r\n");
return 255;
2020-10-18 07:10:15 +03:00
}
ViewPort* view_port = view_port_alloc();
2020-10-18 05:43:09 +03:00
view_port_draw_callback_set(view_port, render_callback, &state_mutex);
view_port_input_callback_set(view_port, input_callback, event_queue);
2020-10-13 20:59:39 +03:00
// Open GUI and register view_port
[FL-140] Core api dynamic records (#296) * SYSTEM: tickless mode with deep sleep. * Move FreeRTOS ticks to lptim2 * API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source. * API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode. * NFC: support for tickless mode. * API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications. * BLE: prevent sleep while core2 starting * HAL: nap while in insomnia mode * init records work * try to implement record delete * tests and flapp * flapp subsystem * new core functions to get app stat, simplify core code * fix thread termination * add strdup to core * fix tests * Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage * Refactoring: update furi record api usage, cleanup code * Fix broken merge for freertos apps * Core, Target: fix compilation warnings * Drop firmware target local * HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode. * SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial. * delete old app example-ipc * delete old app fatfs list * fix strobe app, add input header * delete old display driver * comment old app qr-code * fix sd-card test, add forced widget update * remove unused new core test * increase heap to 128k * comment and assert old core tests * fix syntax Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
Gui* gui = (Gui*)furi_record_open("gui");
2020-10-18 05:43:09 +03:00
if(gui == NULL) {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] gui is not available\r\n");
return 255;
2020-10-14 10:26:23 +03:00
}
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
2020-10-13 20:59:39 +03:00
gpio_init(&debug_0, GpioModeOutputPushPull);
gpio_write((GpioPin*)&debug_0, false);
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] creating device\r\n");
GpioPin cs_pin = {CC1101_CS_GPIO_Port, CC1101_CS_Pin};
gpio_init(&cc1101_g0_gpio, GpioModeInput);
api_interrupt_add(cc1101_isr, InterruptTypeExternalInterrupt, NULL);
// TODO open record
GpioPin* cs_pin_record = &cs_pin;
CC1101 cc1101(cs_pin_record);
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] init device\r\n");
2020-10-13 20:59:39 +03:00
uint8_t address = cc1101.Init();
if(address > 0) {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] init done: %d\r\n", address);
2020-10-13 20:59:39 +03:00
} else {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] init fail\r\n");
return 255;
2020-10-13 20:59:39 +03:00
}
cc1101.SpiStrobe(CC1101_SIDLE);
// flp_config(&cc1101);
tx_config(&cc1101);
// setup_freq(&cc1101, &FREQ_LIST[4]);
// enable_cc1101_irq();
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("init ok\r\n");
const int16_t RSSI_THRESHOLD = -60;
2020-10-18 07:47:49 +03:00
// setup_freq(&cc1101, &FREQ_LIST[1]);
cc1101.SetReceive();
AppEvent event;
2020-10-18 07:10:15 +03:00
while(1) {
osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 100);
State* state = (State*)acquire_mutex_block(&state_mutex);
2020-10-18 07:10:15 +03:00
if(event_status == osOK) {
2020-10-18 07:10:15 +03:00
if(event.type == EventTypeKey) {
if(event.value.input.type == InputTypeShort &&
event.value.input.key == InputKeyBack) {
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] bye!\r\n");
cc1101.SpiStrobe(CC1101_SIDLE);
cc1101.SpiStrobe(CC1101_SPWD);
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311) * FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started. * Furi record, stdglue: check mutex allocation * remove unused test * Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state. * Interrupt manager: explicitly init list. * Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options. * BLE: call debug uart callback on transmission complete * FreeRTOS: add configUSE_NEWLIB_REENTRANT * API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib. * F4: update stack protection CFLAGS to match used compiller * F4: disable compiller stack protection because of incompatibility with current compiller * Makefile: return openocd logs to gdb * BLE: fixed pin, moar power, ble trace info. * Prevent sleep when connection is active * Makefile: return serial port to upload rule, add workaround for mac os * Furi: prevent usage of stack for cmsis functions. * F4: add missing includes, add debugger breakpoints * Applications: per app stack size. * Furi: honor kernel state in stdglue * FreeRTOS: remove unused hooks * Cleanup and format sources Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +03:00
printf("[cc1101] go to power down\r\n");
// TODO remove all view_ports create by app
view_port_enabled_set(view_port, false);
return 255;
2020-10-18 07:10:15 +03:00
}
if(event.value.input.type == InputTypeShort &&
event.value.input.key == InputKeyDown) {
if(state->active_freq_idx > 0) {
state->active_freq_idx--;
}
FreqConfig conf = FREQ_LIST[state->active_freq_idx];
state->active_freq = conf.band->base_freq + CHAN_SPA * conf.channel;
state->need_cc1101_conf = true;
}
if(event.value.input.type == InputTypeShort &&
event.value.input.key == InputKeyUp) {
if(state->active_freq_idx < (sizeof(FREQ_LIST) / sizeof(FREQ_LIST[0]) - 1)) {
state->active_freq_idx++;
2020-10-18 07:10:15 +03:00
}
FreqConfig conf = FREQ_LIST[state->active_freq_idx];
state->active_freq = conf.band->base_freq + CHAN_SPA * conf.channel;
state->need_cc1101_conf = true;
2020-10-18 07:10:15 +03:00
}
if(event.value.input.type == InputTypeShort &&
event.value.input.key == InputKeyRight) {
/*
if(state->tx_level < (sizeof(TX_LEVELS) / sizeof(TX_LEVELS[0]) - 1)) {
state->tx_level++;
} else {
state->tx_level = 0;
2020-10-18 07:10:15 +03:00
}
*/
if(state->rf_band < RfBand3) {
state->rf_band = (RfBand)((uint8_t)state->rf_band + 1);
} else {
state->active_freq += 0.25;
}
state->need_cc1101_conf = true;
2020-10-18 07:10:15 +03:00
}
2020-10-18 10:47:38 +03:00
if(event.value.input.type == InputTypeShort &&
event.value.input.key == InputKeyLeft) {
/*
2020-10-19 09:23:49 +03:00
if(state->tx_level < (sizeof(TX_LEVELS) / sizeof(TX_LEVELS[0]) - 1)) {
2020-10-18 10:47:38 +03:00
state->tx_level++;
} else {
state->tx_level = 0;
}
*/
2020-10-18 10:47:38 +03:00
if(state->rf_band > RfBandIsolation) {
state->rf_band = (RfBand)((uint8_t)state->rf_band - 1);
} else {
state->active_freq -= 0.25;
}
2020-10-18 10:47:38 +03:00
state->need_cc1101_conf = true;
}
if(event.value.input.key == InputKeyOk) {
if(event.value.input.type == InputTypePress) {
state->mode = ModeTx;
state->need_cc1101_conf = true;
} else if(event.value.input.type == InputTypeRelease) {
state->mode = ModeRx;
state->need_cc1101_conf = true;
}
2020-10-18 10:47:38 +03:00
}
2020-10-18 07:10:15 +03:00
}
2020-10-18 07:47:49 +03:00
} else {
}
2020-10-18 07:47:49 +03:00
if(state->need_cc1101_conf) {
if(state->mode == ModeRx) {
cc1101.SpiStrobe(CC1101_SIDLE);
gpio_init(&cc1101_g0_gpio, GpioModeInput);
setup_freq(&cc1101, state->active_freq);
cc1101.SetReceive();
state->last_rssi = rx_rssi(&cc1101, &FREQ_LIST[state->active_freq_idx]);
} else if(state->mode == ModeTx) {
cc1101.SpiStrobe(CC1101_SIDLE);
setup_freq(&cc1101, state->active_freq);
cc1101.SetTransmit();
gpio_init(&cc1101_g0_gpio, GpioModeOutputPushPull);
gpio_write(&cc1101_g0_gpio, false);
}
2020-10-18 07:47:49 +03:00
api_hal_rf_band_set(state->rf_band);
state->need_cc1101_conf = false;
2020-10-18 07:10:15 +03:00
}
if(!state->need_cc1101_conf && state->mode == ModeRx) {
// TOOD what about rssi offset
state->last_rssi = rx_rssi(&cc1101, &FREQ_LIST[state->active_freq_idx]);
api_hal_light_set(LightGreen, state->last_rssi > RSSI_THRESHOLD ? 0xFF : 0x00);
} else if(!state->need_cc1101_conf && state->mode == ModeTx) {
/*
const uint8_t data = 0xA5;
for(uint8_t i = 0; i < 8; i++) {
gpio_write(&cc1101_g0_gpio, (data & (1 << i)) > 0);
osDelay(1);
}
gpio_write(&cc1101_g0_gpio, false);
*/
2020-12-15 00:04:44 +03:00
/*
// BELL UDB-Q022-0000
const uint16_t HALF_PERIOD = 500;
for(uint8_t n = 0; n < 4; n++) {
for(uint8_t i = 0; i < 4; i++) {
gpio_write(&cc1101_g0_gpio, true);
delay_us(3 * HALF_PERIOD);
gpio_write(&cc1101_g0_gpio, false);
delay_us(HALF_PERIOD);
}
for(uint8_t i = 0; i < 40; i++) {
gpio_write(&cc1101_g0_gpio, true);
delay_us(HALF_PERIOD);
gpio_write(&cc1101_g0_gpio, false);
delay_us(HALF_PERIOD);
}
}
2020-12-15 00:04:44 +03:00
*/
// BELL ERA C61, static code
const uint16_t ONE_ON = 150;
const uint16_t ONE_OFF = 400;
const uint16_t ZERO_ON = 420;
const uint16_t ZERO_OFF = 130;
const bool SEQ[] = {true, true, false, false, true, false, true, false, true,
false, true, true, true, false, true, false, true, true,
true, true, true, false, true, false, true};
for(uint8_t n = 0; n < 10; n++) {
for(uint8_t i = 0; i < sizeof(SEQ) / sizeof(SEQ[0]); i++) {
2020-12-15 00:04:44 +03:00
if(SEQ[i]) {
gpio_write(&cc1101_g0_gpio, false);
delay_us(ONE_ON);
gpio_write(&cc1101_g0_gpio, true);
delay_us(ONE_OFF);
} else {
gpio_write(&cc1101_g0_gpio, false);
delay_us(ZERO_ON);
gpio_write(&cc1101_g0_gpio, true);
delay_us(ZERO_OFF);
}
}
osDelay(4);
}
2020-12-15 00:04:44 +03:00
gpio_write(&cc1101_g0_gpio, false);
}
release_mutex(&state_mutex, state);
view_port_update(view_port);
2020-10-18 07:10:15 +03:00
}
return 0;
2020-10-13 13:39:59 +03:00
}