Peripheral Driver API
Overview
The Snake V1 provides a unified Peripheral Driver API designed to abstract the underlying hardware complexities of the STM32WB35 and its connected modules (CC1101, IR components, etc.). This allows developers to interact with hardware via high-level functions without needing to manage register-level configurations.
Infrared (IR) Driver
The IR driver manages the Vishay TSAL6400 transmitter and TSOP38238 receiver. It supports common protocols like NEC, Samsung, and RC5.
Functions
ir_transmit
Sends an infrared signal using a specified protocol and data payload.
void ir_transmit(IRProtocol protocol, uint32_t address, uint32_t command);
- protocol: The encoding scheme (e.g.,
IR_PROTO_NEC,IR_PROTO_SAMSUNG). - address: The device address/identifier.
- command: The specific command code to send.
ir_receive_start
Enables the IR receiver to capture incoming signals. Captured data is typically handled via a callback or polled buffer.
void ir_receive_start(IRData *buffer);
- buffer: A pointer to an
IRDatastruct where decoded results are stored.
Sub-GHz Driver (CC1101)
This driver interfaces with the Texas Instruments CC1101 transceiver to enable long-range wireless communication.
Configuration Types
| Type | Description |
| :--- | :--- |
| Frequency | Frequency in Hz (e.g., 433,920,000). |
| Modulation | Modulation type (MOD_ASK_OOK, MOD_2FSK, etc.). |
| Power | Output power level in dBm. |
Functions
subghz_init
Initializes the CC1101 with default or custom radio profiles.
int8_t subghz_init(const SubGhzConfig *config);
subghz_set_frequency
Changes the operational frequency on the fly.
void subghz_set_frequency(uint32_t freq_hz);
subghz_send
Transmits a raw data packet.
bool subghz_send(uint8_t *data, size_t length);
- data: Pointer to the byte array to send.
- length: Size of the data (max 64 bytes per packet for standard FIFO).
GPIO API
The GPIO driver provides a simplified interface for interacting with the Snake V1's expansion pins and onboard peripherals.
Constants
SNAKE_PIN_D0throughSNAKE_PIN_D7PIN_MODE_INPUT,PIN_MODE_OUTPUT,PIN_MODE_PWM
Functions
gpio_write
Sets a digital pin to HIGH or LOW.
void gpio_write(uint16_t pin, PinState state);
gpio_read
Reads the current state of a digital pin.
PinState gpio_read(uint16_t pin);
Connectivity Drivers (BLE / Wi-Fi / NFC)
Snake V1 leverages the STM32WB35’s dual-core architecture for wireless stacks.
Bluetooth Low Energy (BLE)
The BLE driver uses the HCI (Host Controller Interface) to communicate with the M0+ core.
ble_start_adv(): Begins broadcasting as a peripheral.ble_send_notification(uint16_t handle, uint8_t *data): Sends data to a connected client.
NFC
Used for tag emulation or reading (depending on the specific hardware revision).
nfc_read_uid(uint8_t *uid_out): Retrieves the UID of a detected tag.
Error Handling
Most driver functions return a standard SnakeResult code to indicate success or the type of failure.
| Result Code | Meaning |
| :--- | :--- |
| SN_OK | Operation successful. |
| SN_ERR_BUSY | Peripheral is currently in use. |
| SN_ERR_TIMEOUT | Hardware did not respond in time. |
| SN_ERR_PARAM | Invalid argument provided. |
Example Usage: Sub-GHz Transmission
#include "snake_v1_hal.h"
void transmit_example() {
uint8_t payload[] = {0xDE, 0xAD, 0xBE, 0xEF};
subghz_set_frequency(433920000);
if (subghz_send(payload, sizeof(payload)) == SN_OK) {
// Transmission successful
}
}