Naming and coding style convention, new linter tool. (#945)

* Makefile, Scripts: new linter
* About: remove ID from IC
* Firmware: remove double define for DIVC/DIVR
* Scripts: check folder names too. Docker: replace syntax check with make lint.
* Reformat Sources and Migrate to new file naming convention
* Docker: symlink clang-format-12 to clang-format
* Add coding style guide
This commit is contained in:
あく
2022-01-05 19:10:18 +03:00
committed by GitHub
parent c98e54da10
commit 389ff92cc1
899 changed files with 379245 additions and 373421 deletions
@@ -0,0 +1,46 @@
/**
* @file furi_hal.h
* Furi HAL API
*/
#pragma once
#ifdef __cplusplus
template <unsigned int N> struct STOP_EXTERNING_ME {};
#endif
#include "furi_hal_bootloader.h"
#include "furi_hal_clock.h"
#include "furi_hal_crypto.h"
#include "furi_hal_console.h"
#include "furi_hal_os.h"
#include "furi_hal_sd.h"
#include "furi_hal_i2c.h"
#include "furi_hal_resources.h"
#include "furi_hal_rtc.h"
#include "furi_hal_gpio.h"
#include "furi_hal_light.h"
#include "furi_hal_delay.h"
#include "furi_hal_pwm.h"
#include "furi_hal_task.h"
#include "furi_hal_power.h"
#include "furi_hal_vcp.h"
#include "furi_hal_interrupt.h"
#include "furi_hal_version.h"
#include "furi_hal_bt.h"
#include "furi_hal_spi.h"
#include "furi_hal_flash.h"
#include "furi_hal_subghz.h"
#include "furi_hal_vibro.h"
#include "furi_hal_ibutton.h"
#include "furi_hal_rfid.h"
#include "furi_hal_nfc.h"
#include "furi_hal_usb.h"
#include "furi_hal_usb_hid.h"
#include "furi_hal_compress.h"
#include "furi_hal_uart.h"
#include "furi_hal_info.h"
#include "furi_hal_random.h"
/** Init furi_hal */
void furi_hal_init();
@@ -0,0 +1,29 @@
/**
* @file furi_hal_bootloader.h
* Bootloader HAL API
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Boot modes */
typedef enum { FuriHalBootloaderModeNormal, FuriHalBootloaderModeDFU } FuriHalBootloaderMode;
/** Initialize boot subsystem
*/
void furi_hal_bootloader_init();
/** Set bootloader mode
*
* @param[in] mode FuriHalBootloaderMode
*/
void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,200 @@
/**
* @file furi_hal_bt.h
* BT/BLE HAL API
*/
#pragma once
#include <m-string.h>
#include <stdbool.h>
#include <gap.h>
#include <serial_service.h>
#include <ble_glue.h>
#include <ble_app.h>
#include "furi_hal_bt_serial.h"
#define FURI_HAL_BT_STACK_VERSION_MAJOR (1)
#define FURI_HAL_BT_STACK_VERSION_MINOR (13)
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FuriHalBtStackUnknown,
FuriHalBtStackHciLayer,
FuriHalBtStackLight,
} FuriHalBtStack;
typedef enum {
FuriHalBtProfileSerial,
FuriHalBtProfileHidKeyboard,
// Keep last for Profiles number calculation
FuriHalBtProfileNumber,
} FuriHalBtProfile;
/** Initialize
*/
void furi_hal_bt_init();
/** Lock core2 state transition */
void furi_hal_bt_lock_core2();
/** Lock core2 state transition */
void furi_hal_bt_unlock_core2();
/** Start radio stack
*
* @return true on successfull radio stack start
*/
bool furi_hal_bt_start_radio_stack();
/** Get radio stack type
*
* @return FuriHalBtStack instance
*/
FuriHalBtStack furi_hal_bt_get_radio_stack();
/** Start BLE app
*
* @param profile FuriHalBtProfile instance
* @param event_cb GapEventCallback instance
* @param context pointer to context
*
* @return true on success
*/
bool furi_hal_bt_start_app(FuriHalBtProfile profile, GapEventCallback event_cb, void* context);
/** Change BLE app
* Restarts 2nd core
*
* @param profile FuriHalBtProfile instance
* @param event_cb GapEventCallback instance
* @param context pointer to context
*
* @return true on success
*/
bool furi_hal_bt_change_app(FuriHalBtProfile profile, GapEventCallback event_cb, void* context);
/** Update battery level
*
* @param battery_level battery level
*/
void furi_hal_bt_update_battery_level(uint8_t battery_level);
/** Start advertising
*/
void furi_hal_bt_start_advertising();
/** Stop advertising
*/
void furi_hal_bt_stop_advertising();
/** Get BT/BLE system component state
*
* @param[in] buffer string_t buffer to write to
*/
void furi_hal_bt_dump_state(string_t buffer);
/** Get BT/BLE system component state
*
* @return true if core2 is alive
*/
bool furi_hal_bt_is_alive();
/** Get key storage buffer address and size
*
* @param key_buff_addr pointer to store buffer address
* @param key_buff_size pointer to store buffer size
*/
void furi_hal_bt_get_key_storage_buff(uint8_t** key_buff_addr, uint16_t* key_buff_size);
/** Get SRAM2 hardware semaphore
* @note Must be called before SRAM2 read/write operations
*/
void furi_hal_bt_nvm_sram_sem_acquire();
/** Release SRAM2 hardware semaphore
* @note Must be called after SRAM2 read/write operations
*/
void furi_hal_bt_nvm_sram_sem_release();
/** Set key storage change callback
*
* @param callback BleGlueKeyStorageChangedCallback instance
* @param context pointer to context
*/
void furi_hal_bt_set_key_storage_change_callback(
BleGlueKeyStorageChangedCallback callback,
void* context);
/** Start ble tone tx at given channel and power
*
* @param[in] channel The channel
* @param[in] power The power
*/
void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
/** Stop ble tone tx
*/
void furi_hal_bt_stop_tone_tx();
/** Start sending ble packets at a given frequency and datarate
*
* @param[in] channel The channel
* @param[in] pattern The pattern
* @param[in] datarate The datarate
*/
void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
/** Stop sending ble packets
*
* @return sent packet count
*/
uint16_t furi_hal_bt_stop_packet_test();
/** Start receiving packets
*
* @param[in] channel RX channel
* @param[in] datarate Datarate
*/
void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
/** Set up the RF to listen to a given RF channel
*
* @param[in] channel RX channel
*/
void furi_hal_bt_start_rx(uint8_t channel);
/** Stop RF listenning
*/
void furi_hal_bt_stop_rx();
/** Get RSSI
*
* @return RSSI in dBm
*/
float furi_hal_bt_get_rssi();
/** Get number of transmitted packets
*
* @return packet count
*/
uint32_t furi_hal_bt_get_transmitted_packets();
/** Start MAC addresses scan
* @note Works only with HciLayer 2nd core firmware
*
* @param callback GapScanCallback instance
* @param context pointer to context
*/
bool furi_hal_bt_start_scan(GapScanCallback callback, void* context);
/** Stop MAC addresses scan */
void furi_hal_bt_stop_scan();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,63 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
enum FuriHalBtHidMediKeys {
FuriHalBtHidMediaScanNext,
FuriHalBtHidMediaScanPrevious,
FuriHalBtHidMediaStop,
FuriHalBtHidMediaEject,
FuriHalBtHidMediaPlayPause,
FuriHalBtHidMediaMute,
FuriHalBtHidMediaVolumeUp,
FuriHalBtHidMediaVolumeDown,
};
/** Start Hid Keyboard Profile
*/
void furi_hal_bt_hid_start();
/** Stop Hid Keyboard Profile
*/
void furi_hal_bt_hid_stop();
/** Press keyboard button
*
* @param button button code from HID specification
*
* @return true on success
*/
bool furi_hal_bt_hid_kb_press(uint16_t button);
/** Release keyboard button
*
* @param button button code from HID specification
*
* @return true on success
*/
bool furi_hal_bt_hid_kb_release(uint16_t button);
/** Release all keyboard buttons
*
* @return true on success
*/
bool furi_hal_bt_hid_kb_release_all();
/** Release all media buttons
*
* @return true on success
*/
bool furi_hal_bt_hid_media_press(uint8_t button);
/** Release all media buttons
*
* @return true on success
*/
bool furi_hal_bt_hid_media_release(uint8_t button);
/** Release all media buttons
*
* @return true on success
*/
bool furi_hal_bt_hid_media_release_all();
@@ -0,0 +1,40 @@
#pragma once
#include "serial_service.h"
#define FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX SERIAL_SVC_DATA_LEN_MAX
/** Serial service callback type */
typedef SerialServiceEventCallback FuriHalBtSerialCallback;
/** Start Serial Profile
*/
void furi_hal_bt_serial_start();
/** Stop Serial Profile
*/
void furi_hal_bt_serial_stop();
/** Set Serial service events callback
*
* @param buffer_size Applicaition buffer size
* @param calback FuriHalBtSerialCallback instance
* @param context pointer to context
*/
void furi_hal_bt_serial_set_event_callback(
uint16_t buff_size,
FuriHalBtSerialCallback callback,
void* context);
/** Notify that application buffer is empty
*/
void furi_hal_bt_serial_notify_buffer_is_empty();
/** Send data through BLE
*
* @param data data buffer
* @param size data buffer size
*
* @return true on success
*/
bool furi_hal_bt_serial_tx(uint8_t* data, uint16_t size);
@@ -0,0 +1,79 @@
/**
* @file furi_hal_compress.h
* LZSS based compression HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
/** Defines encoder and decoder window size */
#define FURI_HAL_COMPRESS_EXP_BUFF_SIZE_LOG (8)
/** Defines encoder and decoder lookahead buffer size */
#define FURI_HAL_COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG (4)
/** FuriHalCompress control structure */
typedef struct FuriHalCompress FuriHalCompress;
/** Initialize icon decoder
*/
void furi_hal_compress_icon_init();
/** Icon decoder
*
* @param icon_data pointer to icon data
* @param decoded_buff pointer to decoded buffer
*/
void furi_hal_compress_icon_decode(const uint8_t* icon_data, uint8_t** decoded_buff);
/** Allocate encoder and decoder
*
* @param compress_buff_size size of decoder and encoder buffer to allocate
*
* @return FuriHalCompress instance
*/
FuriHalCompress* furi_hal_compress_alloc(uint16_t compress_buff_size);
/** Free encoder and decoder
*
* @param compress FuriHalCompress instance
*/
void furi_hal_compress_free(FuriHalCompress* compress);
/** Encode data
*
* @param compress FuriHalCompress instance
* @param data_in pointer to input data
* @param data_in_size size of input data
* @param data_out maximum size of output data
* @param data_res_size pointer to result output data size
*
* @return true on success
*/
bool furi_hal_compress_encode(
FuriHalCompress* compress,
uint8_t* data_in,
size_t data_in_size,
uint8_t* data_out,
size_t data_out_size,
size_t* data_res_size);
/** Decode data
*
* @param compress FuriHalCompress instance
* @param data_in pointer to input data
* @param data_in_size size of input data
* @param data_out maximum size of output data
* @param data_res_size pointer to result output data size
*
* @return true on success
*/
bool furi_hal_compress_decode(
FuriHalCompress* compress,
uint8_t* data_in,
size_t data_in_size,
uint8_t* data_out,
size_t data_out_size,
size_t* data_res_size);
@@ -0,0 +1,84 @@
/**
* @file furi_hal_crypto.h
* Cryptography HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
/** FuriHalCryptoKey Type */
typedef enum {
FuriHalCryptoKeyTypeMaster, /**< Master key */
FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
} FuriHalCryptoKeyType;
/** FuriHalCryptoKey Size in bits */
typedef enum {
FuriHalCryptoKeySize128,
FuriHalCryptoKeySize256,
} FuriHalCryptoKeySize;
/** FuriHalCryptoKey */
typedef struct {
FuriHalCryptoKeyType type;
FuriHalCryptoKeySize size;
uint8_t* data;
} FuriHalCryptoKey;
/** Initialize cryptography layer This includes AES engines, PKA and RNG
*/
void furi_hal_crypto_init();
bool furi_hal_crypto_verify_enclave(uint8_t* keys_nb, uint8_t* valid_keys_nb);
bool furi_hal_crypto_verify_key(uint8_t key_slot);
/** Store key in crypto storage
*
* @param key FuriHalCryptoKey to store. Only Master, Simple or
* Encrypted
* @param slot pinter to int where store slot number will be saved
*
* @return true on success
*/
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
/** Init AES engine and load key from crypto store
*
* @param slot store slot number
* @param[in] iv pointer to 16 bytes Initialization Vector data
*
* @return true on success
*/
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
/** Unload key engine and deinit AES engine
*
* @param slot store slot number
*
* @return true on success
*/
bool furi_hal_crypto_store_unload_key(uint8_t slot);
/** Encrypt data
*
* @param input pointer to input data
* @param output pointer to output data
* @param size input/output buffer size in bytes
*
* @return true on success
*/
bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size);
/** Decrypt data
*
* @param input pointer to input data
* @param output pointer to output data
* @param size input/output buffer size in bytes
*
* @return true on success
*/
bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size);
@@ -0,0 +1,41 @@
/**
* @file furi_hal_delay.h
* Delay HAL API
*/
#pragma once
#include "main.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Init DWT
*/
void furi_hal_delay_init(void);
/** Delay in milliseconds
* @warning Cannot be used from ISR
*
* @param[in] milliseconds milliseconds to wait
*/
void delay(float milliseconds);
/** Delay in microseconds
*
* @param[in] microseconds microseconds to wait
*/
void delay_us(float microseconds);
/** Get current millisecond
*
* System uptime, pProvided by HAL, may overflow.
*
* @return Current milliseconds
*/
uint32_t millis(void);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,89 @@
/**
* @file furi_hal_i2c.h
* I2C HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <furi_hal_i2c_config.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Init I2C
*/
void furi_hal_i2c_init();
/** Acquire i2c bus handle
*
* @return Instance of FuriHalI2cBus
*/
void furi_hal_i2c_acquire(FuriHalI2cBusHandle* handle);
/** Release i2c bus handle
*
* @param bus instance of FuriHalI2cBus aquired in `furi_hal_i2c_acquire`
*/
void furi_hal_i2c_release(FuriHalI2cBusHandle* handle);
/** Perform I2C tx transfer
*
* @param handle pointer to FuriHalI2cBusHandle instance
* @param address I2C slave address
* @param data pointer to data buffer
* @param size size of data buffer
* @param timeout timeout in ticks
*
* @return true on successful transfer, false otherwise
*/
bool furi_hal_i2c_tx(
FuriHalI2cBusHandle* handle,
const uint8_t address,
const uint8_t* data,
const uint8_t size,
uint32_t timeout);
/** Perform I2C rx transfer
*
* @param handle pointer to FuriHalI2cBusHandle instance
* @param address I2C slave address
* @param data pointer to data buffer
* @param size size of data buffer
* @param timeout timeout in ticks
*
* @return true on successful transfer, false otherwise
*/
bool furi_hal_i2c_rx(
FuriHalI2cBusHandle* handle,
const uint8_t address,
uint8_t* data,
const uint8_t size,
uint32_t timeout);
/** Perform I2C tx and rx transfers
*
* @param handle pointer to FuriHalI2cBusHandle instance
* @param address I2C slave address
* @param tx_data pointer to tx data buffer
* @param tx_size size of tx data buffer
* @param rx_data pointer to rx data buffer
* @param rx_size size of rx data buffer
* @param timeout timeout in ticks
*
* @return true on successful transfer, false otherwise
*/
bool furi_hal_i2c_trx(
FuriHalI2cBusHandle* handle,
const uint8_t address,
const uint8_t* tx_data,
const uint8_t tx_size,
uint8_t* rx_data,
const uint8_t rx_size,
uint32_t timeout);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,26 @@
/**
* @file furi_hal_ibutton.h
* iButton HAL API
*/
#pragma once
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
void furi_hal_ibutton_start();
void furi_hal_ibutton_stop();
void furi_hal_ibutton_pin_low();
void furi_hal_ibutton_pin_high();
bool furi_hal_ibutton_pin_get_level();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,34 @@
/**
* @file furi_hal_info.h
* Device info HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Callback type called every time another key-value pair of device information is ready
*
* @param key[in] device information type identifier
* @param value[in] device information value
* @param last[in] whether the passed key-value pair is the last one
* @param context[in] to pass to callback
*/
typedef void (
*FuriHalInfoValueCallback)(const char* key, const char* value, bool last, void* context);
/** Get device information
*
* @param[in] callback callback to provide with new data
* @param[in] context context to pass to callback
*/
void furi_hal_info_get(FuriHalInfoValueCallback callback, void* context);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,148 @@
/**
* @file furi_hal_irda.h
* IRDA HAL API
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define IRDA_MAX_FREQUENCY 56000
#define IRDA_MIN_FREQUENCY 10000
typedef enum {
FuriHalIrdaTxGetDataStateOk, /**< New data obtained */
FuriHalIrdaTxGetDataStateDone, /**< New data obtained, and this is end of package */
FuriHalIrdaTxGetDataStateLastDone, /**< New data obtained, and this is end of package and no more data available */
} FuriHalIrdaTxGetDataState;
/** Callback type for providing data to IRDA DMA TX system. It is called every tim */
typedef FuriHalIrdaTxGetDataState (
*FuriHalIrdaTxGetDataISRCallback)(void* context, uint32_t* duration, bool* level);
/** Callback type called every time signal is sent by DMA to Timer.
*
* Actually, it means there are 2 timings left to send for this signal, which is
* almost end. Don't use this callback to stop transmission, as far as there are
* next signal is charged for transmission by DMA.
*/
typedef void (*FuriHalIrdaTxSignalSentISRCallback)(void* context);
/** Signature of callback function for receiving continuous IRDA rx signal.
*
* @param ctx[in] context to pass to callback
* @param level[in] level of input IRDA rx signal
* @param duration[in] duration of continuous rx signal level in us
*/
typedef void (*FuriHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration);
/** Signature of callback function for reaching silence timeout on IRDA port.
*
* @param ctx[in] context to pass to callback
*/
typedef void (*FuriHalIrdaRxTimeoutCallback)(void* ctx);
/** Initialize IRDA RX timer to receive interrupts.
*
* It provides interrupts for every RX-signal edge changing with its duration.
*/
void furi_hal_irda_async_rx_start(void);
/** Deinitialize IRDA RX interrupt.
*/
void furi_hal_irda_async_rx_stop(void);
/** Setup hal for receiving silence timeout.
*
* Should be used with 'furi_hal_irda_timeout_irq_set_callback()'.
*
* @param[in] timeout_us time to wait for silence on IRDA port before
* generating IRQ.
*/
void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us);
/** Setup callback for previously initialized IRDA RX interrupt.
*
* @param[in] callback callback to call when RX signal edge changing occurs
* @param[in] ctx context for callback
*/
void furi_hal_irda_async_rx_set_capture_isr_callback(
FuriHalIrdaRxCaptureCallback callback,
void* ctx);
/** Setup callback for reaching silence timeout on IRDA port.
*
* Should setup hal with 'furi_hal_irda_setup_rx_timeout_irq()' first.
*
* @param[in] callback callback for silence timeout
* @param[in] ctx context to pass to callback
*/
void furi_hal_irda_async_rx_set_timeout_isr_callback(
FuriHalIrdaRxTimeoutCallback callback,
void* ctx);
/** Check if IRDA is in use now.
*
* @return true if IRDA is busy, false otherwise.
*/
bool furi_hal_irda_is_busy(void);
/** Set callback providing new data.
*
* This function has to be called before furi_hal_irda_async_tx_start().
*
* @param[in] callback function to provide new data
* @param[in] context context for callback
*/
void furi_hal_irda_async_tx_set_data_isr_callback(
FuriHalIrdaTxGetDataISRCallback callback,
void* context);
/** Start IR asynchronous transmission.
*
* It can be stopped by 2 reasons:
* 1. implicit call for furi_hal_irda_async_tx_stop()
* 2. callback can provide FuriHalIrdaTxGetDataStateLastDone response which
* means no more data available for transmission.
*
* Any func (furi_hal_irda_async_tx_stop() or
* furi_hal_irda_async_tx_wait_termination()) has to be called to wait end of
* transmission and free resources.
*
* @param[in] freq frequency for PWM
* @param[in] duty_cycle duty cycle for PWM
*/
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle);
/** Stop IR asynchronous transmission and free resources.
*
* Transmission will stop as soon as transmission reaches end of package
* (FuriHalIrdaTxGetDataStateDone or FuriHalIrdaTxGetDataStateLastDone).
*/
void furi_hal_irda_async_tx_stop(void);
/** Wait for end of IR asynchronous transmission and free resources.
*
* Transmission will stop as soon as transmission reaches end of transmission
* (FuriHalIrdaTxGetDataStateLastDone).
*/
void furi_hal_irda_async_tx_wait_termination(void);
/** Set callback for end of signal transmission
*
* @param[in] callback function to call when signal is sent
* @param[in] context context for callback
*/
void furi_hal_irda_async_tx_set_signal_sent_isr_callback(
FuriHalIrdaTxSignalSentISRCallback callback,
void* context);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,29 @@
/**
* @file furi_hal_light.h
* Light control HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <furi_hal_resources.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Init light driver
*/
void furi_hal_light_init();
/** Set light value
*
* @param light Light
* @param value light brightness [0-255]
*/
void furi_hal_light_set(Light light, uint8_t value);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,118 @@
/**
* @file furi_hal_nfc.h
* NFC HAL API
*/
#pragma once
#include <rfal_nfc.h>
#include <st_errno.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define FURI_HAL_NFC_UID_MAX_LEN 10
/** Init nfc
*/
void furi_hal_nfc_init();
/** Check if nfc worker is busy
*
* @return true if busy
*/
bool furi_hal_nfc_is_busy();
/** NFC field on
*/
void furi_hal_nfc_field_on();
/** NFC field off
*/
void furi_hal_nfc_field_off();
/** NFC start sleep
*/
void furi_hal_nfc_start_sleep();
/** NFC stop sleep
*/
void furi_hal_nfc_exit_sleep();
/** NFC poll
*
* @param dev_list pointer to rfalNfcDevice buffer
* @param dev_cnt pointer device count
* @param timeout timeout in ms
* @param deactivate deactivate flag
*
* @return true on success
*/
bool furi_hal_nfc_detect(
rfalNfcDevice** dev_list,
uint8_t* dev_cnt,
uint32_t timeout,
bool deactivate);
/** NFC listen
*
* @param uid pointer to uid buffer
* @param uid_len uid length
* @param atqa pointer to atqa
* @param sak sak
* @param activate_after_sak activate after sak flag
* @param timeout timeout in ms
*
* @return true on success
*/
bool furi_hal_nfc_listen(
uint8_t* uid,
uint8_t uid_len,
uint8_t* atqa,
uint8_t sak,
bool activate_after_sak,
uint32_t timeout);
/** Get first command from reader after activation in emulation mode
*
* @param rx_buff pointer to receive buffer
* @param rx_len receive buffer length
*
* @return true on success
*/
bool furi_hal_nfc_get_first_frame(uint8_t** rx_buff, uint16_t** rx_len);
/** NFC data exchange
*
* @param tx_buff transmit buffer
* @param tx_len transmit buffer length
* @param rx_buff receive buffer
* @param rx_len receive buffer length
* @param deactivate deactivate flag
*
* @return ST ReturnCode
*/
ReturnCode furi_hal_nfc_data_exchange(
uint8_t* tx_buff,
uint16_t tx_len,
uint8_t** rx_buff,
uint16_t** rx_len,
bool deactivate);
ReturnCode furi_hal_nfc_raw_bitstream_exchange(
uint8_t* tx_buff,
uint16_t tx_bit_len,
uint8_t** rx_buff,
uint16_t** rx_bit_len,
bool deactivate);
/** NFC deactivate and start sleep
*/
void furi_hal_nfc_deactivate();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,172 @@
/**
* @file furi_hal_power.h
* Power HAL API
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <m-string.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Power IC type */
typedef enum {
FuriHalPowerICCharger,
FuriHalPowerICFuelGauge,
} FuriHalPowerIC;
/** Initialize drivers
*/
void furi_hal_power_init();
/** Get current insomnia level
*
* @return insomnia level: 0 - no insomnia, >0 - insomnia, bearer count.
*/
uint16_t furi_hal_power_insomnia_level();
/** Enter insomnia mode Prevents device from going to sleep
* @warning Internally increases insomnia level Must be paired with
* furi_hal_power_insomnia_exit
*/
void furi_hal_power_insomnia_enter();
/** Exit insomnia mode Allow device to go to sleep
* @warning Internally decreases insomnia level. Must be paired with
* furi_hal_power_insomnia_enter
*/
void furi_hal_power_insomnia_exit();
/** Check if sleep availble
*
* @return true if available
*/
bool furi_hal_power_sleep_available();
/** Check if deep sleep availble
*
* @return true if available
*/
bool furi_hal_power_deep_sleep_available();
/** Go to sleep
*/
void furi_hal_power_sleep();
/** Get predicted remaining battery capacity in percents
*
* @return remaining battery capacity in percents
*/
uint8_t furi_hal_power_get_pct();
/** Get battery health state in percents
*
* @return health in percents
*/
uint8_t furi_hal_power_get_bat_health_pct();
/** Get charging status
*
* @return true if charging
*/
bool furi_hal_power_is_charging();
/** Poweroff device
*/
void furi_hal_power_off();
/** Reset device
*/
void furi_hal_power_reset();
/** OTG enable
*/
void furi_hal_power_enable_otg();
/** OTG disable
*/
void furi_hal_power_disable_otg();
/** Get OTG status
*
* @return true if enabled
*/
bool furi_hal_power_is_otg_enabled();
/** Get remaining battery battery capacity in mAh
*
* @return capacity in mAh
*/
uint32_t furi_hal_power_get_battery_remaining_capacity();
/** Get full charge battery capacity in mAh
*
* @return capacity in mAh
*/
uint32_t furi_hal_power_get_battery_full_capacity();
/** Get battery voltage in V
*
* @param ic FuriHalPowerIc to get measurment
*
* @return voltage in V
*/
float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic);
/** Get battery current in A
*
* @param ic FuriHalPowerIc to get measurment
*
* @return current in A
*/
float furi_hal_power_get_battery_current(FuriHalPowerIC ic);
/** Get temperature in C
*
* @param ic FuriHalPowerIc to get measurment
*
* @return temperature in C
*/
float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic);
/** Get System voltage in V
*
* @return voltage in V
*/
float furi_hal_power_get_system_voltage();
/** Get USB voltage in V
*
* @return voltage in V
*/
float furi_hal_power_get_usb_voltage();
/** Get power system component state
*/
void furi_hal_power_dump_state();
/** Enable 3.3v on external gpio and sd card
*/
void furi_hal_power_enable_external_3_3v();
/** Disable 3.3v on external gpio and sd card
*/
void furi_hal_power_disable_external_3_3v();
/** Enter supress charge mode.
*
* Use this function when your application need clean power supply.
*/
void furi_hal_power_suppress_charge_enter();
/** Exit supress charge mode
*/
void furi_hal_power_suppress_charge_exit();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,24 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Get random value
*
* @return random value
*/
uint32_t furi_hal_random_get();
/** Fill buffer with random data
*
* @param buf buffer pointer
* @param data buffer len
*/
void furi_hal_random_fill_buf(uint8_t* buf, uint32_t len);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,114 @@
/**
* @file furi_hal_rfid.h
* RFID HAL API
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <main.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Initialize RFID subsystem
*/
void furi_hal_rfid_init();
/** Config rfid pins to reset state
*/
void furi_hal_rfid_pins_reset();
/** Config rfid pins to emulate state
*/
void furi_hal_rfid_pins_emulate();
/** Config rfid pins to read state
*/
void furi_hal_rfid_pins_read();
/** Release rfid pull pin
*/
void furi_hal_rfid_pin_pull_release();
/** Pulldown rfid pull pin
*/
void furi_hal_rfid_pin_pull_pulldown();
/** Config rfid timer to read state
*
* @param freq timer frequency
* @param duty_cycle timer duty cycle, 0.0-1.0
*/
void furi_hal_rfid_tim_read(float freq, float duty_cycle);
/** Start read timer
*/
void furi_hal_rfid_tim_read_start();
/** Stop read timer
*/
void furi_hal_rfid_tim_read_stop();
/** Config rfid timer to emulate state
*
* @param freq timer frequency
*/
void furi_hal_rfid_tim_emulate(float freq);
/** Start emulation timer
*/
void furi_hal_rfid_tim_emulate_start();
/** Stop emulation timer
*/
void furi_hal_rfid_tim_emulate_stop();
/** Config rfid timers to reset state
*/
void furi_hal_rfid_tim_reset();
/** Check that timer instance is emulation timer
*
* @param hw timer instance
*
* @return true if instance is emulation timer
*/
bool furi_hal_rfid_is_tim_emulate(TIM_HandleTypeDef* hw);
/** Set emulation timer period
*
* @param period overall duration
*/
void furi_hal_rfid_set_emulate_period(uint32_t period);
/** Set emulation timer pulse
*
* @param pulse duration of high level
*/
void furi_hal_rfid_set_emulate_pulse(uint32_t pulse);
/** Set read timer period
*
* @param period overall duration
*/
void furi_hal_rfid_set_read_period(uint32_t period);
/** Set read timer pulse
*
* @param pulse duration of high level
*/
void furi_hal_rfid_set_read_pulse(uint32_t pulse);
/** Сhanges the configuration of the RFID timer "on a fly"
*
* @param freq new frequency
* @param duty_cycle new duty cycle
*/
void furi_hal_rfid_change_read_config(float freq, float duty_cycle);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,72 @@
/**
* @file furi_hal_rtc.h
* Furi Hal RTC API
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <main.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
// Time
uint8_t hour; /**< Hour in 24H format: 0-23 */
uint8_t minute; /**< Minute: 0-59 */
uint8_t second; /**< Second: 0-59 */
// Date
uint8_t day; /**< Current day: 1-31 */
uint8_t month; /**< Current month: 1-12 */
uint16_t year; /**< Current year: 2000-2099 */
uint8_t weekday; /**< Current weekday: 1-7 */
} FuriHalRtcDateTime;
typedef enum {
FuriHalRtcFlagDebug = (1 << 0),
FuriHalRtcFlagFactoryReset = (1 << 1),
FuriHalRtcFlagLock = (1 << 2),
} FuriHalRtcFlag;
typedef enum {
FuriHalRtcRegisterBoot,
FuriHalRtcRegisterBootVersion,
FuriHalRtcRegisterSystem,
FuriHalRtcRegisterSystemVersion,
FuriHalRtcRegisterLfsFingerprint,
FuriHalRtcRegisterFaultData,
} FuriHalRtcRegister;
/** Initialize RTC subsystem */
void furi_hal_rtc_init();
uint32_t furi_hal_rtc_get_register(FuriHalRtcRegister reg);
void furi_hal_rtc_set_register(FuriHalRtcRegister reg, uint32_t value);
void furi_hal_rtc_set_log_level(uint8_t level);
uint8_t furi_hal_rtc_get_log_level();
void furi_hal_rtc_set_flag(FuriHalRtcFlag flag);
void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag);
bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag);
void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime);
void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime);
bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime);
void furi_hal_rtc_set_fault_data(uint32_t value);
uint32_t furi_hal_rtc_get_fault_data();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,33 @@
/**
* @file furi_hal_sd.h
* SD Card HAL API
*/
#include <stdint.h>
#include <stdbool.h>
#include <furi_hal_spi_types.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Init SD card detect
*/
void hal_sd_detect_init(void);
/** Set SD card detect pin to low
*/
void hal_sd_detect_set_low(void);
/** Get SD card status
*
* @return true if SD card present, false if SD card not present
*/
bool hal_sd_detect(void);
/** Pointer to currently used SPI Handle */
extern FuriHalSpiBusHandle* furi_hal_sd_spi_handle;
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,102 @@
#pragma once
#include <furi_hal_spi_config.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Initialize SPI HAL */
void furi_hal_spi_init();
/** Initialize SPI Bus
*
* @param handle pointer to FuriHalSpiBus instance
*/
void furi_hal_spi_bus_init(FuriHalSpiBus* bus);
/** Deinitialize SPI Bus
*
* @param handle pointer to FuriHalSpiBus instance
*/
void furi_hal_spi_bus_deinit(FuriHalSpiBus* bus);
/** Initialize SPI Bus Handle
*
* @param handle pointer to FuriHalSpiBusHandle instance
*/
void furi_hal_spi_bus_handle_init(FuriHalSpiBusHandle* handle);
/** Deinitialize SPI Bus Handle
*
* @param handle pointer to FuriHalSpiBusHandle instance
*/
void furi_hal_spi_bus_handle_deinit(FuriHalSpiBusHandle* handle);
/** Acquire SPI bus
*
* @warning blocking, calls `furi_crash` on programming error, CS transition is up to handler event routine
*
* @param handle pointer to FuriHalSpiBusHandle instance
*/
void furi_hal_spi_acquire(FuriHalSpiBusHandle* handle);
/** Release SPI bus
*
* @warning calls `furi_crash` on programming error, CS transition is up to handler event routine
*
* @param handle pointer to FuriHalSpiBusHandle instance
*/
void furi_hal_spi_release(FuriHalSpiBusHandle* handle);
/** SPI Receive
*
* @param handle pointer to FuriHalSpiBusHandle instance
* @param buffer receive buffer
* @param size transaction size (buffer size)
* @param timeout operation timeout in ms
*
* @return true on sucess
*/
bool furi_hal_spi_bus_rx(
FuriHalSpiBusHandle* handle,
uint8_t* buffer,
size_t size,
uint32_t timeout);
/** SPI Transmit
*
* @param handle pointer to FuriHalSpiBusHandle instance
* @param buffer transmit buffer
* @param size transaction size (buffer size)
* @param timeout operation timeout in ms
*
* @return true on success
*/
bool furi_hal_spi_bus_tx(
FuriHalSpiBusHandle* handle,
uint8_t* buffer,
size_t size,
uint32_t timeout);
/** SPI Transmit and Receive
*
* @param handle pointer to FuriHalSpiBusHandle instance
* @param tx_buffer pointer to tx buffer
* @param rx_buffer pointer to rx buffer
* @param size transaction size (buffer size)
* @param timeout operation timeout in ms
*
* @return true on success
*/
bool furi_hal_spi_bus_trx(
FuriHalSpiBusHandle* handle,
uint8_t* tx_buffer,
uint8_t* rx_buffer,
size_t size,
uint32_t timeout);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,241 @@
/**
* @file furi_hal_subghz.h
* SubGhz HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <toolbox/level_duration.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Radio Presets */
typedef enum {
FuriHalSubGhzPresetIDLE, /**< default configuration */
FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
FuriHalSubGhzPreset2FSKDev238Async, /**< FM, deviation 2.380371 kHz, asynchronous */
FuriHalSubGhzPreset2FSKDev476Async, /**< FM, deviation 4.760742 kHz, asynchronous */
FuriHalSubGhzPresetMSK99_97KbAsync, /**< MSK, deviation 47.60742 kHz, 99.97Kb/s, asynchronous */
FuriHalSubGhzPresetGFSK9_99KbAsync /**< GFSK, deviation 19.042969 kHz, 9.996Kb/s, asynchronous */
} FuriHalSubGhzPreset;
/** Switchable Radio Paths */
typedef enum {
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;
/** 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;
/** SubGhz regulation, receive transmission on the current frequency for the
* region */
typedef enum {
SubGhzRegulationOnlyRx, /**only Rx*/
SubGhzRegulationTxRx, /**TxRx*/
} SubGhzRegulation;
/** 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
*/
void furi_hal_subghz_init();
/** Send device to sleep mode
*/
void furi_hal_subghz_sleep();
/** Dump info to stdout
*/
void furi_hal_subghz_dump_state();
/** Load registers from preset by preset name
*
* @param preset to load
*/
void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset);
/** Load registers
*
* @param data Registers data
*/
void furi_hal_subghz_load_registers(const uint8_t data[][2]);
/** Load PATABLE
*
* @param data 8 uint8_t values
*/
void furi_hal_subghz_load_patable(const uint8_t data[8]);
/** Write packet to FIFO
*
* @param data bytes array
* @param size size
*/
void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size);
/** 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();
/** Read packet from FIFO
*
* @param data pointer
* @param size size
*/
void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size);
/** Flush rx FIFO buffer
*/
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
*/
void furi_hal_subghz_shutdown();
/** Reset Issue reset command
* @warning registers content will be lost
*/
void furi_hal_subghz_reset();
/** Switch to Idle
*/
void furi_hal_subghz_idle();
/** Switch to Recieve
*/
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
*/
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 frequncy is valid, otherwise false
*/
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 herz
*/
uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value);
/** Сheck if transmission is allowed on this frequency for your flipper region
*
* @param value frequency in Hz
*
* @return true if allowed
*/
bool furi_hal_subghz_is_tx_allowed(uint32_t value);
/** Set frequency
*
* @param value frequency in Hz
*
* @return real frequency in herz
*/
uint32_t furi_hal_subghz_set_frequency(uint32_t value);
/** Set path
*
* @param path path to use
*/
void furi_hal_subghz_set_path(FuriHalSubGhzPath path);
/* High Level API */
/** Signal Timings Capture callback */
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
*/
void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context);
/** Disable signal timings capture Resets GPIO and TIM2
*/
void furi_hal_subghz_stop_async_rx();
/** Async TX callback type
* @param context callback context
* @return LevelDuration
*/
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
*/
bool furi_hal_subghz_is_async_tx_complete();
/** Stop async transmission and cleanup resources Resets GPIO, TIM2, and DMA1
*/
void furi_hal_subghz_stop_async_tx();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,50 @@
#pragma once
#include "usb.h"
typedef struct UsbInterface UsbInterface;
struct UsbInterface {
void (*init)(usbd_device* dev, UsbInterface* intf);
void (*deinit)(usbd_device* dev);
void (*wakeup)(usbd_device* dev);
void (*suspend)(usbd_device* dev);
struct usb_device_descriptor* dev_descr;
void* str_manuf_descr;
void* str_prod_descr;
void* str_serial_descr;
void* cfg_descr;
};
/** USB device interface modes */
extern UsbInterface usb_cdc_single;
extern UsbInterface usb_cdc_dual;
extern UsbInterface usb_hid;
extern UsbInterface usb_hid_u2f;
/** USB device low-level initialization
*/
void furi_hal_usb_init();
/** Set USB device configuration
*
* @param mode new USB device mode
*/
void furi_hal_usb_set_config(UsbInterface* new_if);
/** Get USB device configuration
*
* @return current USB device mode
*/
UsbInterface* furi_hal_usb_get_config();
/** Disable USB device
*/
void furi_hal_usb_disable();
/** Enable USB device
*/
void furi_hal_usb_enable();
@@ -0,0 +1,343 @@
#pragma once
/** HID keyboard key codes */
enum HidKeyboardKeys {
KEY_NONE = 0x00,
KEY_ERROR_ROLLOVER = 0x01,
KEY_POST_FAIL = 0x02,
KEY_ERROR_UNDEFINED = 0x03,
KEY_A = 0x04,
KEY_B = 0x05,
KEY_C = 0x06,
KEY_D = 0x07,
KEY_E = 0x08,
KEY_F = 0x09,
KEY_G = 0x0A,
KEY_H = 0x0B,
KEY_I = 0x0C,
KEY_J = 0x0D,
KEY_K = 0x0E,
KEY_L = 0x0F,
KEY_M = 0x10,
KEY_N = 0x11,
KEY_O = 0x12,
KEY_P = 0x13,
KEY_Q = 0x14,
KEY_R = 0x15,
KEY_S = 0x16,
KEY_T = 0x17,
KEY_U = 0x18,
KEY_V = 0x19,
KEY_W = 0x1A,
KEY_X = 0x1B,
KEY_Y = 0x1C,
KEY_Z = 0x1D,
KEY_1 = 0x1E,
KEY_2 = 0x1F,
KEY_3 = 0x20,
KEY_4 = 0x21,
KEY_5 = 0x22,
KEY_6 = 0x23,
KEY_7 = 0x24,
KEY_8 = 0x25,
KEY_9 = 0x26,
KEY_0 = 0x27,
KEY_ENTER = 0x28,
KEY_ESC = 0x29,
KEY_BACKSPACE = 0x2A,
KEY_TAB = 0x2B,
KEY_SPACE = 0x2C,
KEY_MINUS = 0x2D,
KEY_EQUAL = 0x2E,
KEY_LEFT_BRACE = 0x2F,
KEY_RIGHT_BRACE = 0x30,
KEY_BACKSLASH = 0x31,
KEY_NON_US_NUM = 0x32,
KEY_SEMICOLON = 0x33,
KEY_QUOTE = 0x34,
KEY_TILDE = 0x35,
KEY_COMMA = 0x36,
KEY_PERIOD = 0x37,
KEY_SLASH = 0x38,
KEY_CAPS_LOCK = 0x39,
KEY_F1 = 0x3A,
KEY_F2 = 0x3B,
KEY_F3 = 0x3C,
KEY_F4 = 0x3D,
KEY_F5 = 0x3E,
KEY_F6 = 0x3F,
KEY_F7 = 0x40,
KEY_F8 = 0x41,
KEY_F9 = 0x42,
KEY_F10 = 0x43,
KEY_F11 = 0x44,
KEY_F12 = 0x45,
KEY_PRINT = 0x46,
KEY_SCROLL_LOCK = 0x47,
KEY_PAUSE = 0x48,
KEY_INSERT = 0x49,
KEY_HOME = 0x4A,
KEY_PAGE_UP = 0x4B,
KEY_DELETE = 0x4C,
KEY_END = 0x4D,
KEY_PAGE_DOWN = 0x4E,
KEY_RIGHT_ARROW = 0x4F,
KEY_LEFT_ARROW = 0x50,
KEY_DOWN_ARROW = 0x51,
KEY_UP_ARROW = 0x52,
KEY_NUM_LOCK = 0x53,
KEYPAD_DIVIDE = 0x54,
KEYPAD_MULTIPLY = 0x55,
KEYPAD_SUBTRACT = 0x56,
KEYPAD_ADD = 0x57,
KEYPAD_ENTER = 0x58,
KEYPAD_1 = 0x59,
KEYPAD_2 = 0x5A,
KEYPAD_3 = 0x5B,
KEYPAD_4 = 0x5C,
KEYPAD_5 = 0x5D,
KEYPAD_6 = 0x5E,
KEYPAD_7 = 0x5F,
KEYPAD_8 = 0x60,
KEYPAD_9 = 0x61,
KEYPAD_0 = 0x62,
KEYPAD_DOT = 0x63,
KEY_NON_US = 0x64,
KEY_APPLICATION = 0x65,
};
/** HID keyboard modifier keys */
enum HidKeyboardMods {
KEY_MOD_LEFT_CTRL = (1 << 8),
KEY_MOD_LEFT_SHIFT = (1 << 9),
KEY_MOD_LEFT_ALT = (1 << 10),
KEY_MOD_LEFT_GUI = (1 << 11),
KEY_MOD_RIGHT_CTRL = (1 << 12),
KEY_MOD_RIGHT_SHIFT = (1 << 13),
KEY_MOD_RIGHT_ALT = (1 << 14),
KEY_MOD_RIGHT_GUI = (1 << 15),
};
/** ASCII to keycode conversion table */
static const uint16_t hid_asciimap[] = {
KEY_NONE, // NUL
KEY_NONE, // SOH
KEY_NONE, // STX
KEY_NONE, // ETX
KEY_NONE, // EOT
KEY_NONE, // ENQ
KEY_NONE, // ACK
KEY_NONE, // BEL
KEY_BACKSPACE, // BS Backspace
KEY_TAB, // TAB Tab
KEY_ENTER, // LF Enter
KEY_NONE, // VT
KEY_NONE, // FF
KEY_NONE, // CR
KEY_NONE, // SO
KEY_NONE, // SI
KEY_NONE, // DEL
KEY_NONE, // DC1
KEY_NONE, // DC2
KEY_NONE, // DC3
KEY_NONE, // DC4
KEY_NONE, // NAK
KEY_NONE, // SYN
KEY_NONE, // ETB
KEY_NONE, // CAN
KEY_NONE, // EM
KEY_NONE, // SUB
KEY_NONE, // ESC
KEY_NONE, // FS
KEY_NONE, // GS
KEY_NONE, // RS
KEY_NONE, // US
KEY_SPACE, // ' ' Space
KEY_1 | KEY_MOD_LEFT_SHIFT, // !
KEY_QUOTE | KEY_MOD_LEFT_SHIFT, // "
KEY_3 | KEY_MOD_LEFT_SHIFT, // #
KEY_4 | KEY_MOD_LEFT_SHIFT, // $
KEY_5 | KEY_MOD_LEFT_SHIFT, // %
KEY_7 | KEY_MOD_LEFT_SHIFT, // &
KEY_QUOTE, // '
KEY_9 | KEY_MOD_LEFT_SHIFT, // (
KEY_0 | KEY_MOD_LEFT_SHIFT, // )
KEY_8 | KEY_MOD_LEFT_SHIFT, // *
KEY_EQUAL | KEY_MOD_LEFT_SHIFT, // +
KEY_COMMA, // ,
KEY_MINUS, // -
KEY_PERIOD, // .
KEY_SLASH, // /
KEY_0, // 0
KEY_1, // 1
KEY_2, // 2
KEY_3, // 3
KEY_4, // 4
KEY_5, // 5
KEY_6, // 6
KEY_7, // 7
KEY_8, // 8
KEY_9, // 9
KEY_SEMICOLON | KEY_MOD_LEFT_SHIFT, // :
KEY_SEMICOLON, // ;
KEY_COMMA | KEY_MOD_LEFT_SHIFT, // <
KEY_EQUAL, // =
KEY_PERIOD | KEY_MOD_LEFT_SHIFT, // >
KEY_SLASH | KEY_MOD_LEFT_SHIFT, // ?
KEY_2 | KEY_MOD_LEFT_SHIFT, // @
KEY_A | KEY_MOD_LEFT_SHIFT, // A
KEY_B | KEY_MOD_LEFT_SHIFT, // B
KEY_C | KEY_MOD_LEFT_SHIFT, // C
KEY_D | KEY_MOD_LEFT_SHIFT, // D
KEY_E | KEY_MOD_LEFT_SHIFT, // E
KEY_F | KEY_MOD_LEFT_SHIFT, // F
KEY_G | KEY_MOD_LEFT_SHIFT, // G
KEY_H | KEY_MOD_LEFT_SHIFT, // H
KEY_I | KEY_MOD_LEFT_SHIFT, // I
KEY_J | KEY_MOD_LEFT_SHIFT, // J
KEY_K | KEY_MOD_LEFT_SHIFT, // K
KEY_L | KEY_MOD_LEFT_SHIFT, // L
KEY_M | KEY_MOD_LEFT_SHIFT, // M
KEY_N | KEY_MOD_LEFT_SHIFT, // N
KEY_O | KEY_MOD_LEFT_SHIFT, // O
KEY_P | KEY_MOD_LEFT_SHIFT, // P
KEY_Q | KEY_MOD_LEFT_SHIFT, // Q
KEY_R | KEY_MOD_LEFT_SHIFT, // R
KEY_S | KEY_MOD_LEFT_SHIFT, // S
KEY_T | KEY_MOD_LEFT_SHIFT, // T
KEY_U | KEY_MOD_LEFT_SHIFT, // U
KEY_V | KEY_MOD_LEFT_SHIFT, // V
KEY_W | KEY_MOD_LEFT_SHIFT, // W
KEY_X | KEY_MOD_LEFT_SHIFT, // X
KEY_Y | KEY_MOD_LEFT_SHIFT, // Y
KEY_Z | KEY_MOD_LEFT_SHIFT, // Z
KEY_LEFT_BRACE, // [
KEY_BACKSLASH, // bslash
KEY_RIGHT_BRACE, // ]
KEY_6 | KEY_MOD_LEFT_SHIFT, // ^
KEY_MINUS | KEY_MOD_LEFT_SHIFT, // _
KEY_TILDE, // `
KEY_A, // a
KEY_B, // b
KEY_C, // c
KEY_D, // d
KEY_E, // e
KEY_F, // f
KEY_G, // g
KEY_H, // h
KEY_I, // i
KEY_J, // j
KEY_K, // k
KEY_L, // l
KEY_M, // m
KEY_N, // n
KEY_O, // o
KEY_P, // p
KEY_Q, // q
KEY_R, // r
KEY_S, // s
KEY_T, // t
KEY_U, // u
KEY_V, // v
KEY_W, // w
KEY_X, // x
KEY_Y, // y
KEY_Z, // z
KEY_LEFT_BRACE | KEY_MOD_LEFT_SHIFT, // {
KEY_BACKSLASH | KEY_MOD_LEFT_SHIFT, // |
KEY_RIGHT_BRACE | KEY_MOD_LEFT_SHIFT, // }
KEY_TILDE | KEY_MOD_LEFT_SHIFT, // ~
KEY_NONE, // DEL
};
typedef void (*HidStateCallback)(bool state, void* context);
/** ASCII to keycode conversion macro */
#define HID_ASCII_TO_KEY(x) (((uint8_t)x < 128) ? (hid_asciimap[(uint8_t)x]) : KEY_NONE)
/** HID keyboard leds */
enum HidKeyboardLeds {
HID_KB_LED_NUM = (1 << 0),
HID_KB_LED_CAPS = (1 << 1),
HID_KB_LED_SCROLL = (1 << 2),
};
/** HID mouse buttons */
enum HidMouseButtons {
HID_MOUSE_BTN_LEFT = (1 << 0),
HID_MOUSE_BTN_RIGHT = (1 << 1),
HID_MOUSE_BTN_WHEEL = (1 << 2),
};
/** Get USB HID connection state
*
* @return true / false
*/
bool furi_hal_hid_is_connected();
/** Get USB HID keyboard leds state
*
* @return leds state
*/
uint8_t furi_hal_hid_get_led_state();
/** Set USB HID connect/disconnect callback
*
* @param cb callback
* @param ctx callback context
*/
void furi_hal_hid_set_state_callback(HidStateCallback cb, void* ctx);
/** Set the following key to pressed state and send HID report
*
* @param button key code
*/
bool furi_hal_hid_kb_press(uint16_t button);
/** Set the following key to released state and send HID report
*
* @param button key code
*/
bool furi_hal_hid_kb_release(uint16_t button);
/** Clear all pressed keys and send HID report
*
*/
bool furi_hal_hid_kb_release_all();
/** Set mouse movement and send HID report
*
* @param dx x coordinate delta
* @param dy y coordinate delta
*/
bool furi_hal_hid_mouse_move(int8_t dx, int8_t dy);
/** Set mouse button to pressed state and send HID report
*
* @param button key code
*/
bool furi_hal_hid_mouse_press(uint8_t button);
/** Set mouse button to released state and send HID report
*
* @param button key code
*/
bool furi_hal_hid_mouse_release(uint8_t button);
/** Set mouse wheel position and send HID report
*
* @param delta number of scroll steps
*/
bool furi_hal_hid_mouse_scroll(int8_t delta);
/** Set the following consumer key to pressed state and send HID report
*
* @param button key code
*/
bool furi_hal_hid_consumer_key_press(uint16_t button);
/** Set the following consumer key to released state and send HID report
*
* @param button key code
*/
bool furi_hal_hid_consumer_key_release(uint16_t button);
@@ -0,0 +1,36 @@
#pragma once
#define HID_U2F_PACKET_LEN 64
typedef enum {
HidU2fDisconnected,
HidU2fConnected,
HidU2fRequest,
} HidU2fEvent;
typedef void (*HidU2fCallback)(HidU2fEvent ev, void* context);
/** Get HID U2F connection state
*
* @return true / false
*/
bool furi_hal_hid_u2f_is_connected();
/** Set HID U2F event callback
*
* @param cb callback
* @param ctx callback context
*/
void furi_hal_hid_u2f_set_callback(HidU2fCallback cb, void* ctx);
/** Get received U2F HID packet
*
*/
uint32_t furi_hal_hid_u2f_get_request(uint8_t* data);
/** Send U2F HID response packet
*
* @param data response data
* @param len packet length
*/
void furi_hal_hid_u2f_send_response(uint8_t* data, uint8_t len);
@@ -0,0 +1,63 @@
/**
* @file furi_hal_vcp.h
* VCP HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Init VCP HAL Allocates ring buffer and initializes state
*/
void furi_hal_vcp_init();
/** Disable VCP to make CDC interface usable by other application
*/
void furi_hal_vcp_disable();
/** Enable VCP
*/
void furi_hal_vcp_enable();
/** Recieve data from VCP Waits till some data arrives, never returns 0
*
* @param buffer pointer to buffer
* @param size buffer size
*
* @return items copied in buffer, 0 if channel closed
*/
size_t furi_hal_vcp_rx(uint8_t* buffer, size_t size);
/** Recieve data from VCP with timeout Waits till some data arrives during
* timeout
*
* @param buffer pointer to buffer
* @param size buffer size
* @param timeout rx timeout in ms
*
* @return items copied in buffer, 0 if channel closed or timeout occurs
*/
size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeout);
/** Transmit data to VCP
*
* @param buffer pointer to buffer
* @param size buffer size
*/
void furi_hal_vcp_tx(const uint8_t* buffer, size_t size);
/** Check whether VCP is connected
*
* @return true if connected
*/
bool furi_hal_vcp_is_connected(void);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,173 @@
/**
* @file furi_hal_version.h
* Version HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <lib/toolbox/version.h>
#ifdef __cplusplus
extern "C" {
#endif
#define FURI_HAL_VERSION_NAME_LENGTH 8
#define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1)
/** BLE symbol + "Flipper " + name */
#define FURI_HAL_VERSION_DEVICE_NAME_LENGTH (1 + 8 + FURI_HAL_VERSION_ARRAY_NAME_LENGTH)
/** OTP Versions enum */
typedef enum {
FuriHalVersionOtpVersion0 = 0x00,
FuriHalVersionOtpVersion1 = 0x01,
FuriHalVersionOtpVersion2 = 0x02,
FuriHalVersionOtpVersionEmpty = 0xFFFFFFFE,
FuriHalVersionOtpVersionUnknown = 0xFFFFFFFF,
} FuriHalVersionOtpVersion;
/** Device Colors */
typedef enum {
FuriHalVersionColorUnknown = 0x00,
FuriHalVersionColorBlack = 0x01,
FuriHalVersionColorWhite = 0x02,
} FuriHalVersionColor;
/** Device Regions */
typedef enum {
FuriHalVersionRegionUnknown = 0x00,
FuriHalVersionRegionEuRu = 0x01,
FuriHalVersionRegionUsCaAu = 0x02,
FuriHalVersionRegionJp = 0x03,
} FuriHalVersionRegion;
/** Device Display */
typedef enum {
FuriHalVersionDisplayUnknown = 0x00,
FuriHalVersionDisplayErc = 0x01,
FuriHalVersionDisplayMgg = 0x02,
} FuriHalVersionDisplay;
/** Init flipper version
*/
void furi_hal_version_init();
/** Check target firmware version
*
* @return true if target and real matches
*/
bool furi_hal_version_do_i_belong_here();
/** Get model name
*
* @return model name C-string
*/
const char* furi_hal_version_get_model_name();
/** Get OTP version
*
* @return OTP Version
*/
const FuriHalVersionOtpVersion furi_hal_version_get_otp_version();
/** Get hardware version
*
* @return Hardware Version
*/
const uint8_t furi_hal_version_get_hw_version();
/** Get hardware target
*
* @return Hardware Target
*/
const uint8_t furi_hal_version_get_hw_target();
/** Get hardware body
*
* @return Hardware Body
*/
const uint8_t furi_hal_version_get_hw_body();
/** Get hardware body color
*
* @return Hardware Color
*/
const FuriHalVersionColor furi_hal_version_get_hw_color();
/** Get hardware connect
*
* @return Hardware Interconnect
*/
const uint8_t furi_hal_version_get_hw_connect();
/** Get hardware region
*
* @return Hardware Region
*/
const FuriHalVersionRegion furi_hal_version_get_hw_region();
/** Get hardware display id
*
* @return Display id
*/
const FuriHalVersionDisplay furi_hal_version_get_hw_display();
/** Get hardware timestamp
*
* @return Hardware Manufacture timestamp
*/
const uint32_t furi_hal_version_get_hw_timestamp();
/** Get pointer to target name
*
* @return Hardware Name C-string
*/
const char* furi_hal_version_get_name_ptr();
/** Get pointer to target device name
*
* @return Hardware Device Name C-string
*/
const char* furi_hal_version_get_device_name_ptr();
/** Get pointer to target ble local device name
*
* @return Ble Device Name C-string
*/
const char* furi_hal_version_get_ble_local_device_name_ptr();
/** Get BLE MAC address
*
* @return pointer to BLE MAC address
*/
const uint8_t* furi_hal_version_get_ble_mac();
/** Get address of version structure of bootloader, stored in chip flash.
*
* @return Address of boot version structure.
*/
const struct Version* furi_hal_version_get_bootloader_version();
/** Get address of version structure of firmware.
*
* @return Address of firmware version structure.
*/
const struct Version* furi_hal_version_get_firmware_version();
/** Get platform UID size in bytes
*
* @return UID size in bytes
*/
size_t furi_hal_version_uid_size();
/** Get const pointer to UID
*
* @return pointer to UID
*/
const uint8_t* furi_hal_version_uid();
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,28 @@
/**
* @file furi_hal_vibro.h
* Vibro HAL API
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <furi_hal_resources.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Initialize vibro
*/
void furi_hal_vibro_init();
/** Turn on/off vibro
*
* @param[in] value new state
*/
void furi_hal_vibro_on(bool value);
#ifdef __cplusplus
}
#endif