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
|
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
/** Radio Presets */
|
|
|
|
typedef enum {
|
2021-08-08 18:03:25 +00:00
|
|
|
FuriHalSubGhzPresetOokAsync, /** OOK, asynchronous */
|
|
|
|
} FuriHalSubGhzPreset;
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Switchable Radio Paths */
|
2021-02-25 10:29:00 +00:00
|
|
|
typedef enum {
|
2021-08-08 18:03:25 +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 */
|
|
|
|
} FuriHalSubGhzPath;
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-07-15 13:54:11 +00:00
|
|
|
/** SubGhz state */
|
|
|
|
typedef enum {
|
|
|
|
SubGhzStateInit, /** Init pending */
|
|
|
|
|
|
|
|
SubGhzStateIdle, /** Idle, energy save mode */
|
|
|
|
|
|
|
|
SubGhzStateAsyncRx, /** Async RX started */
|
|
|
|
|
|
|
|
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 */
|
|
|
|
} SubGhzState;
|
|
|
|
|
2021-03-31 17:52:26 +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-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_init();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-07-15 13:54:11 +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-03-31 17:52:26 +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
|
|
|
|
|
|
|
/** Load registers from preset by preset name
|
|
|
|
* @param preset to load
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-06-08 09:51:16 +00:00
|
|
|
/** Get status */
|
2021-08-08 18:03:25 +00:00
|
|
|
uint8_t furi_hal_subghz_get_status();
|
2021-06-08 09:51:16 +00:00
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
/** Load registers
|
|
|
|
* @param register-value pairs array, terminated with {0,0}
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_load_registers(const uint8_t data[][2]);
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Load PATABLE
|
|
|
|
* @param data, 8 uint8_t values
|
|
|
|
*/
|
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
|
|
|
|
* @param data, bytes array
|
|
|
|
* @param size, size
|
|
|
|
*/
|
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-03-31 17:52:26 +00:00
|
|
|
/** Read packet from FIFO
|
|
|
|
* @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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** Shutdown
|
|
|
|
* Issue spwd command
|
|
|
|
* @warning registers content will be lost
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_shutdown();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Reset
|
|
|
|
* Issue reset command
|
|
|
|
* @warning registers content will be lost
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_reset();
|
2021-03-31 17:52:26 +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
|
|
|
|
|
|
|
/** Switch to Recieve */
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_rx();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Switch to Transmit */
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_tx();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
|
|
|
/** Get RSSI value in dBm */
|
2021-08-08 18:03:25 +00:00
|
|
|
float furi_hal_subghz_get_rssi();
|
2021-03-31 17:52:26 +00:00
|
|
|
|
2021-07-27 11:47:45 +00:00
|
|
|
/** Check if frequency is in valid range
|
|
|
|
* @return true if frequncy is valid, otherwise false
|
|
|
|
*/
|
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-06-29 21:19:20 +00:00
|
|
|
/** Set frequency and path
|
|
|
|
* This function automatically selects antenna matching network
|
|
|
|
* @param frequency in herz
|
|
|
|
* @return real frequency in herz
|
|
|
|
*/
|
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
|
|
|
|
* @param frequency in herz
|
|
|
|
* @return real frequency in herz
|
|
|
|
*/
|
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
|
|
|
|
* @param radio path to use
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
/** Set signal timings capture callback
|
|
|
|
* @param callback - your callback for front capture
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_set_async_rx_callback(FuriHalSubGhzCaptureCallback callback, void* context);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
|
|
|
/** Enable signal timings capture
|
|
|
|
* Initializes GPIO and TIM2 for timings capture
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_start_async_rx();
|
2021-06-29 21:19:20 +00:00
|
|
|
|
|
|
|
/** Disable signal timings capture
|
|
|
|
* Resets GPIO and TIM2
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_stop_async_rx();
|
2021-07-15 13:54:11 +00:00
|
|
|
|
|
|
|
/** Send buffer
|
|
|
|
* Initializes GPIO, TIM2 and DMA1 for signal output
|
|
|
|
* @param buffer - pointer to data buffer
|
|
|
|
* @param buffer_size - buffer size in bytes
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_start_async_tx(uint32_t* buffer, size_t buffer_size, size_t repeat);
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
/** Get repeats left count for async tx
|
|
|
|
* @return packets left to send
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
size_t furi_hal_subghz_get_async_tx_repeat_left();
|
2021-07-18 18:09:00 +00:00
|
|
|
|
2021-07-15 13:54:11 +00:00
|
|
|
/** Wait for async transmission to complete */
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_subghz_wait_async_tx();
|
2021-07-15 13:54:11 +00:00
|
|
|
|
|
|
|
/** Stop async transmission and cleanup resources
|
|
|
|
* Resets GPIO, TIM2, and DMA1
|
|
|
|
*/
|
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
|