2021-10-03 10:36:05 +00:00
|
|
|
/**
|
2022-01-05 16:10:18 +00:00
|
|
|
* @file furi_hal_subghz.h
|
2021-10-03 10:36:05 +00:00
|
|
|
* SubGhz HAL API
|
|
|
|
*/
|
|
|
|
|
2021-02-25 10:29:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2021-07-15 13:54:11 +00:00
|
|
|
#include <stddef.h>
|
2021-07-07 19:49:45 +00:00
|
|
|
#include <toolbox/level_duration.h>
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-02-25 10:29:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-11-30 11:41:23 +00:00
|
|
|
/** Low level buffer dimensions and guard times */
|
|
|
|
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
|
|
|
|
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL / 2)
|
|
|
|
#define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME 999
|
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
/** Radio Presets */
|
|
|
|
typedef enum {
|
2022-01-05 16:10:18 +00:00
|
|
|
FuriHalSubGhzPresetIDLE, /**< default configuration */
|
|
|
|
FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
|
|
|
|
FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
|
2021-10-10 14:35:10 +00:00
|
|
|
FuriHalSubGhzPreset2FSKDev238Async, /**< FM, deviation 2.380371 kHz, asynchronous */
|
2022-04-14 12:49:29 +00:00
|
|
|
FuriHalSubGhzPreset2FSKDev476Async, /**< FM, deviation 47.60742 kHz, asynchronous */
|
2021-12-01 15:44:39 +00:00
|
|
|
FuriHalSubGhzPresetMSK99_97KbAsync, /**< MSK, deviation 47.60742 kHz, 99.97Kb/s, asynchronous */
|
2022-07-26 14:16:59 +00:00
|
|
|
FuriHalSubGhzPresetGFSK9_99KbAsync, /**< GFSK, deviation 19.042969 kHz, 9.996Kb/s, asynchronous */
|
|
|
|
FuriHalSubGhzPresetCustom, /**Custom Preset*/
|
2021-08-08 18:03:25 +00:00
|
|
|
} FuriHalSubGhzPreset;
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Switchable Radio Paths */
|
2021-02-25 10:29:00 +00:00
|
|
|
typedef enum {
|
2022-01-05 16:10:18 +00:00
|
|
|
FuriHalSubGhzPathIsolate, /**< Isolate Radio from antenna */
|
|
|
|
FuriHalSubGhzPath433, /**< Center Frquency: 433MHz. Path 1: SW1RF1-SW2RF2, LCLCL */
|
|
|
|
FuriHalSubGhzPath315, /**< Center Frquency: 315MHz. Path 2: SW1RF2-SW2RF1, LCLCLCL */
|
|
|
|
FuriHalSubGhzPath868, /**< Center Frquency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
|
2021-08-08 18:03:25 +00:00
|
|
|
} FuriHalSubGhzPath;
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-07-15 13:54:11 +00:00
|
|
|
/** SubGhz state */
|
|
|
|
typedef enum {
|
2022-01-05 16:10:18 +00:00
|
|
|
SubGhzStateInit, /**< Init pending */
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
SubGhzStateIdle, /**< Idle, energy save mode */
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
SubGhzStateAsyncRx, /**< Async RX started */
|
2021-09-28 00:05:40 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
SubGhzStateAsyncTx, /**< Async TX started, DMA and timer is on */
|
|
|
|
SubGhzStateAsyncTxLast, /**< Async TX continue, DMA completed and timer got last value to go */
|
|
|
|
SubGhzStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
|
2021-07-15 13:54:11 +00:00
|
|
|
|
|
|
|
} SubGhzState;
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** SubGhz regulation, receive transmission on the current frequency for the
|
|
|
|
* region */
|
2021-09-28 00:05:40 +00:00
|
|
|
typedef enum {
|
|
|
|
SubGhzRegulationOnlyRx, /**only Rx*/
|
|
|
|
SubGhzRegulationTxRx, /**TxRx*/
|
|
|
|
} SubGhzRegulation;
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Initialize and switch to power save mode Used by internal API-HAL
|
|
|
|
* initalization routine Can be used to reinitialize device to safe state and
|
|
|
|
* send it to sleep
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_init();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Send device to sleep mode
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_sleep();
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Dump info to stdout
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_dump_state();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Load registers from preset by preset name
|
|
|
|
*
|
|
|
|
* @param preset to load
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2022-07-26 14:16:59 +00:00
|
|
|
/** Load custom registers from preset
|
|
|
|
*
|
|
|
|
* @param preset_data registers to load
|
|
|
|
*/
|
|
|
|
void furi_hal_subghz_load_custom_preset(uint8_t* preset_data);
|
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
/** Load registers
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param data Registers data
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2022-07-26 14:16:59 +00:00
|
|
|
void furi_hal_subghz_load_registers(uint8_t* data);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Load PATABLE
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param data 8 uint8_t values
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_load_patable(const uint8_t data[8]);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Write packet to FIFO
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param data bytes array
|
|
|
|
* @param size size
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size);
|
2021-02-25 10:29:00 +00:00
|
|
|
|
2021-12-01 15:44:39 +00:00
|
|
|
/** Check if recieve pipe is not empty
|
|
|
|
*
|
|
|
|
* @return true if not empty
|
|
|
|
*/
|
|
|
|
bool furi_hal_subghz_rx_pipe_not_empty();
|
|
|
|
|
|
|
|
/** Check if recieved data crc is valid
|
|
|
|
*
|
|
|
|
* @return true if valid
|
|
|
|
*/
|
|
|
|
bool furi_hal_subghz_is_rx_data_crc_valid();
|
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
/** Read packet from FIFO
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param data pointer
|
|
|
|
* @param size size
|
2021-03-24 09:35:33 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size);
|
2021-06-08 09:51:16 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Flush rx FIFO buffer
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_flush_rx();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-12-08 13:42:01 +00:00
|
|
|
/** Flush tx FIFO buffer
|
|
|
|
*/
|
|
|
|
void furi_hal_subghz_flush_tx();
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Shutdown Issue spwd command
|
|
|
|
* @warning registers content will be lost
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_shutdown();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Reset Issue reset command
|
|
|
|
* @warning registers content will be lost
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_reset();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Switch to Idle
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_idle();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Switch to Recieve
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_rx();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-09-28 00:05:40 +00:00
|
|
|
/** Switch to Transmit
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @return true if the transfer is allowed by belonging to the region
|
|
|
|
*/
|
2021-09-28 00:05:40 +00:00
|
|
|
bool furi_hal_subghz_tx();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Get RSSI value in dBm
|
|
|
|
*
|
|
|
|
* @return RSSI value
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
float furi_hal_subghz_get_rssi();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-12-08 13:42:01 +00:00
|
|
|
/** Get LQI
|
|
|
|
*
|
|
|
|
* @return LQI value
|
|
|
|
*/
|
|
|
|
uint8_t furi_hal_subghz_get_lqi();
|
|
|
|
|
2021-07-27 11:47:45 +00:00
|
|
|
/** Check if frequency is in valid range
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param value frequency in Hz
|
|
|
|
*
|
|
|
|
* @return true if frequncy is valid, otherwise false
|
2021-07-27 11:47:45 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
bool furi_hal_subghz_is_frequency_valid(uint32_t value);
|
2021-07-27 11:47:45 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Set frequency and path This function automatically selects antenna matching
|
|
|
|
* network
|
|
|
|
*
|
|
|
|
* @param value frequency in Hz
|
|
|
|
*
|
|
|
|
* @return real frequency in herz
|
2021-06-29 21:19:20 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
/** Set frequency
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param value frequency in Hz
|
|
|
|
*
|
|
|
|
* @return real frequency in herz
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
uint32_t furi_hal_subghz_set_frequency(uint32_t value);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Set path
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param path path to use
|
2021-03-31 17:52:26 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_set_path(FuriHalSubGhzPath path);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-07-15 13:54:11 +00:00
|
|
|
/* High Level API */
|
|
|
|
|
2021-06-29 21:19:20 +00:00
|
|
|
/** Signal Timings Capture callback */
|
2021-08-08 18:03:25 +00:00
|
|
|
typedef void (*FuriHalSubGhzCaptureCallback)(bool level, uint32_t duration, void* context);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Enable signal timings capture Initializes GPIO and TIM2 for timings capture
|
|
|
|
*
|
|
|
|
* @param callback FuriHalSubGhzCaptureCallback
|
|
|
|
* @param context callback context
|
2021-06-29 21:19:20 +00:00
|
|
|
*/
|
[FL-1610] SubGhz: scene based application, PT save and replay (#630)
* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-12 14:42:56 +00:00
|
|
|
void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Disable signal timings capture Resets GPIO and TIM2
|
2021-06-29 21:19:20 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_stop_async_rx();
|
2021-07-15 13:54:11 +00:00
|
|
|
|
[FL-1610] SubGhz: scene based application, PT save and replay (#630)
* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-12 14:42:56 +00:00
|
|
|
/** Async TX callback type
|
2021-10-03 10:36:05 +00:00
|
|
|
* @param context callback context
|
|
|
|
* @return LevelDuration
|
2021-07-15 13:54:11 +00:00
|
|
|
*/
|
[FL-1610] SubGhz: scene based application, PT save and replay (#630)
* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-12 14:42:56 +00:00
|
|
|
typedef LevelDuration (*FuriHalSubGhzAsyncTxCallback)(void* context);
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Start async TX Initializes GPIO, TIM2 and DMA1 for signal output
|
|
|
|
*
|
|
|
|
* @param callback FuriHalSubGhzAsyncTxCallback
|
|
|
|
* @param context callback context
|
|
|
|
*
|
|
|
|
* @return true if the transfer is allowed by belonging to the region
|
2021-07-18 18:09:00 +00:00
|
|
|
*/
|
2021-09-28 00:05:40 +00:00
|
|
|
bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void* context);
|
2021-07-18 18:09:00 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Wait for async transmission to complete
|
|
|
|
*
|
|
|
|
* @return true if TX complete
|
|
|
|
*/
|
[FL-1610] SubGhz: scene based application, PT save and replay (#630)
* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-12 14:42:56 +00:00
|
|
|
bool furi_hal_subghz_is_async_tx_complete();
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
|
2021-07-15 13:54:11 +00:00
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_stop_async_tx();
|
2021-02-25 10:29:00 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2021-03-31 17:52:26 +00:00
|
|
|
#endif
|