Flipper Zero Firmware
Loading...
Searching...
No Matches
expansion_protocol.h File Reference

Flipper Expansion Protocol parser reference implementation. More...

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  ExpansionFrameHeader
 Frame header structure. More...
 
struct  ExpansionFrameHeartbeat
 Heartbeat frame contents. More...
 
struct  ExpansionFrameStatus
 Status frame contents. More...
 
struct  ExpansionFrameBaudRate
 Baud rate frame contents. More...
 
struct  ExpansionFrameControl
 Control frame contents. More...
 
struct  ExpansionFrameData
 Data frame contents. More...
 
struct  ExpansionFrame
 Expansion protocol frame structure. More...
 

Macros

#define EXPANSION_PROTOCOL_DEFAULT_BAUD_RATE   (9600UL)
 Default baud rate to start all communications at.
 
#define EXPANSION_PROTOCOL_MAX_DATA_SIZE   (64U)
 Maximum data size per frame, in bytes.
 
#define EXPANSION_PROTOCOL_TIMEOUT_MS   (250U)
 Maximum allowed inactivity period, in milliseconds.
 
#define EXPANSION_PROTOCOL_BAUD_CHANGE_DT_MS   (25U)
 Dead time after changing connection baud rate.
 

Typedefs

typedef uint8_t ExpansionFrameChecksum
 Expansion checksum type.
 
typedef size_t(* ExpansionFrameReceiveCallback) (uint8_t *data, size_t data_size, void *context)
 Receive function type declaration.
 
typedef size_t(* ExpansionFrameSendCallback) (const uint8_t *data, size_t data_size, void *context)
 Send function type declaration.
 

Enumerations

enum  ExpansionFrameType {
  ExpansionFrameTypeHeartbeat = 1 , ExpansionFrameTypeStatus = 2 , ExpansionFrameTypeBaudRate = 3 , ExpansionFrameTypeControl = 4 ,
  ExpansionFrameTypeData = 5 , ExpansionFrameTypeReserved
}
 Enumeration of supported frame types. More...
 
enum  ExpansionFrameError { ExpansionFrameErrorNone = 0x00 , ExpansionFrameErrorUnknown = 0x01 , ExpansionFrameErrorBaudRate = 0x02 }
 Enumeration of possible error types. More...
 
enum  ExpansionFrameControlCommand { ExpansionFrameControlCommandStartRpc = 0x00 , ExpansionFrameControlCommandStopRpc = 0x01 }
 Enumeration of suported control commands. More...
 
enum  ExpansionProtocolStatus { ExpansionProtocolStatusOk , ExpansionProtocolStatusErrorFormat , ExpansionProtocolStatusErrorChecksum , ExpansionProtocolStatusErrorCommunication }
 Enumeration of protocol parser statuses. More...
 

Detailed Description

Flipper Expansion Protocol parser reference implementation.

This file is licensed separately under The Unlicense. See https://unlicense.org/ for more details.

This parser is written with low-spec hardware in mind. It does not use dynamic memory allocation or Flipper-specific libraries and can be included directly into any module's firmware's sources.

Typedef Documentation

◆ ExpansionFrameReceiveCallback

typedef size_t(* ExpansionFrameReceiveCallback) (uint8_t *data, size_t data_size, void *context)

Receive function type declaration.

See also
expansion_frame_decode().
Parameters
[out]datapointer to the buffer to reveive the data into.
[in]data_sizemaximum output buffer capacity, in bytes.
[in,out]contextpointer to a user-defined context object.
Returns
number of bytes written into the output buffer.

◆ ExpansionFrameSendCallback

typedef size_t(* ExpansionFrameSendCallback) (const uint8_t *data, size_t data_size, void *context)

Send function type declaration.

See also
expansion_frame_encode().
Parameters
[in]datapointer to the buffer containing the data to be sent.
[in]data_sizesize of the data to send, in bytes.
[in,out]contextpointer to a user-defined context object.
Returns
number of bytes actually sent.

Enumeration Type Documentation

◆ ExpansionFrameControlCommand

Enumeration of suported control commands.

Enumerator
ExpansionFrameControlCommandStartRpc 

Start an RPC session.

ExpansionFrameControlCommandStopRpc 

Stop an open RPC session.

◆ ExpansionFrameError

Enumeration of possible error types.

Enumerator
ExpansionFrameErrorNone 

No error occurred.

ExpansionFrameErrorUnknown 

An unknown error has occurred (generic response).

ExpansionFrameErrorBaudRate 

Requested baud rate is not supported.

◆ ExpansionFrameType

Enumeration of supported frame types.

Enumerator
ExpansionFrameTypeHeartbeat 

Heartbeat frame.

ExpansionFrameTypeStatus 

Status report frame.

ExpansionFrameTypeBaudRate 

Baud rate negotiation frame.

ExpansionFrameTypeControl 

Control frame.

ExpansionFrameTypeData 

Data frame.

ExpansionFrameTypeReserved 

Special value.

◆ ExpansionProtocolStatus

Enumeration of protocol parser statuses.

Enumerator
ExpansionProtocolStatusOk 

No error has occurred.

ExpansionProtocolStatusErrorFormat 

Invalid frame type.

ExpansionProtocolStatusErrorChecksum 

Checksum mismatch.

ExpansionProtocolStatusErrorCommunication 

Input/output error.