unleashed-firmware/targets/f7/furi_hal/furi_hal_subghz.h

293 lines
7.5 KiB
C
Raw Normal View History

/**
* @file furi_hal_subghz.h
* SubGhz HAL API
*/
#pragma once
2023-06-18 20:25:40 +03:00
#include <lib/subghz/devices/preset.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <toolbox/level_duration.h>
#include <furi_hal_gpio.h>
2023-06-18 20:25:40 +03:00
// #include <furi_hal_spi_types.h>
#ifdef __cplusplus
extern "C" {
#endif
/** 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
/** Switchable Radio Paths */
typedef enum {
FuriHalSubGhzPathIsolate, /**< Isolate Radio from antenna */
FuriHalSubGhzPath433, /**< Center Frequency: 433MHz. Path 1: SW1RF1-SW2RF2, LCLCL */
FuriHalSubGhzPath315, /**< Center Frequency: 315MHz. Path 2: SW1RF2-SW2RF1, LCLCLCL */
FuriHalSubGhzPath868, /**< Center Frequency: 868MHz. Path 3: SW1RF3-SW2RF3, LCLC */
2021-08-08 21:03:25 +03:00
} FuriHalSubGhzPath;
/* Mirror RX/TX async modulation signal to specified pin
*
* @warning Configures pin to output mode. Make sure it is not connected
* directly to power or ground.
*
* @param[in] pin pointer to the gpio pin structure or NULL to disable
*/
void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin);
2023-06-18 20:25:40 +03:00
/** Get data GPIO
*
* @return pointer to the gpio pin structure
*/
2023-06-18 20:25:40 +03:00
const GpioPin* furi_hal_subghz_get_data_gpio();
2023-02-02 22:47:50 +03:00
/** Initialize and switch to power save mode Used by internal API-HAL
* initialization routine Can be used to reinitialize device to safe state and
* send it to sleep
*/
2023-06-18 20:25:40 +03:00
void furi_hal_subghz_init();
2023-02-02 22:47:50 +03:00
/** Send device to sleep mode
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_sleep();
/** Dump info to stdout
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_dump_state();
/** Load custom registers from preset
*
* @param preset_data registers to load
*/
void furi_hal_subghz_load_custom_preset(const uint8_t* preset_data);
/** Load registers
*
* @param data Registers data
*/
void furi_hal_subghz_load_registers(const uint8_t* data);
/** Load PATABLE
*
* @param data 8 uint8_t values
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_load_patable(const uint8_t data[8]);
/** Write packet to FIFO
*
* @param data bytes array
* @param size size
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size);
/** Check if receive pipe is not empty
*
* @return true if not empty
*/
bool furi_hal_subghz_rx_pipe_not_empty();
/** Check if received data crc is valid
*
* @return true if valid
*/
bool furi_hal_subghz_is_rx_data_crc_valid();
/** Read packet from FIFO
*
* @param data pointer
* @param size size
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size);
/** Flush rx FIFO buffer
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_flush_rx();
/** Flush tx FIFO buffer
*/
void furi_hal_subghz_flush_tx();
/** Shutdown Issue SPWD command
* @warning registers content will be lost
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_shutdown();
/** Reset Issue reset command
* @warning registers content will be lost
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_reset();
/** Switch to Idle
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_idle();
/** Switch to Receive
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_rx();
/** Switch to Transmit
*
* @return true if the transfer is allowed by belonging to the region
*/
bool furi_hal_subghz_tx();
/** Get RSSI value in dBm
*
* @return RSSI value
*/
2021-08-08 21:03:25 +03:00
float furi_hal_subghz_get_rssi();
/** Get LQI
*
* @return LQI value
*/
uint8_t furi_hal_subghz_get_lqi();
/** Check if frequency is in valid range
*
* @param value frequency in Hz
*
* @return true if frequency is valid, otherwise false
*/
2021-08-08 21:03:25 +03:00
bool furi_hal_subghz_is_frequency_valid(uint32_t value);
/** Set frequency and path This function automatically selects antenna matching
* network
*
* @param value frequency in Hz
*
* @return real frequency in Hz
*/
2021-08-08 21:03:25 +03:00
uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
/** Сheck if transmission is allowed on this frequency with your current config
*
* @param value frequency in Hz
*
* @return true if allowed
*/
bool furi_hal_subghz_is_tx_allowed(uint32_t value);
/** Get the current rolling protocols counter ++/-- value
* @return int8_t current value
2023-06-18 20:25:40 +03:00
*/
int8_t furi_hal_subghz_get_rolling_counter_mult(void);
2023-06-18 20:25:40 +03:00
/** Set the current rolling protocols counter ++/-- value
* @param mult int8_t = -1, -10, -100, 0, 1, 10, 100
2023-06-18 20:25:40 +03:00
*/
void furi_hal_subghz_set_rolling_counter_mult(int8_t mult);
2023-08-24 19:23:05 +03:00
/** Set frequency
*
* @param value frequency in Hz
*
* @return real frequency in Hz
*/
2021-08-08 21:03:25 +03:00
uint32_t furi_hal_subghz_set_frequency(uint32_t value);
/** Set path
*
* @param path path to use
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_set_path(FuriHalSubGhzPath path);
/* High Level API */
/** Signal Timings Capture callback */
2021-08-08 21:03:25 +03:00
typedef void (*FuriHalSubGhzCaptureCallback)(bool level, uint32_t duration, void* context);
/** Enable signal timings capture Initializes GPIO and TIM2 for timings capture
*
* @param callback FuriHalSubGhzCaptureCallback
* @param context callback context
*/
2021-08-12 17:42:56 +03:00
void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context);
/** Disable signal timings capture Resets GPIO and TIM2
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_stop_async_rx();
2021-08-12 17:42:56 +03:00
/** Async TX callback type
* @param context callback context
* @return LevelDuration
*/
2021-08-12 17:42:56 +03:00
typedef LevelDuration (*FuriHalSubGhzAsyncTxCallback)(void* context);
/** 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
*/
bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void* context);
/** Wait for async transmission to complete
*
* @return true if TX complete
*/
2021-08-12 17:42:56 +03:00
bool furi_hal_subghz_is_async_tx_complete();
/** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
*/
2021-08-08 21:03:25 +03:00
void furi_hal_subghz_stop_async_tx();
2023-06-18 20:25:40 +03:00
// /** Initialize and switch to power save mode Used by internal API-HAL
// * initialization routine Can be used to reinitialize device to safe state and
// * send it to sleep
// * @return true if initialisation is successfully
// */
// bool furi_hal_subghz_init_check(void);
// /** Switching between internal and external radio
// * @param state SubGhzRadioInternal or SubGhzRadioExternal
// * @return true if switching is successful
// */
// bool furi_hal_subghz_init_radio_type(SubGhzRadioType state);
// /** Get current radio
// * @return SubGhzRadioInternal or SubGhzRadioExternal
// */
// SubGhzRadioType furi_hal_subghz_get_radio_type(void);
// /** Check for a radio module
// * @return true if check is successful
// */
// bool furi_hal_subghz_check_radio(void);
// /** Turn on the power of the external radio module
// * @return true if power-up is successful
// */
// bool furi_hal_subghz_enable_ext_power(void);
// /** Turn off the power of the external radio module
// */
// void furi_hal_subghz_disable_ext_power(void);
// /** If true - disable 5v power of the external radio module
// */
// void furi_hal_subghz_set_external_power_disable(bool state);
// /** Get the current state of the external power disable flag
// */
// bool furi_hal_subghz_get_external_power_disable(void);
// /** Set what radio module we will be using
// */
// void furi_hal_subghz_select_radio_type(SubGhzRadioType state);
2023-04-24 01:56:43 +03:00
// External CC1101 Ebytes power amplifier control
void furi_hal_subghz_set_ext_power_amp(bool enabled);
bool furi_hal_subghz_get_ext_power_amp();
#ifdef __cplusplus
}
#endif