跳转至

lib/oled/oled.h

Generic OLED object and operations exposed to application code.

Classes

Name
struct _CFBD_OLED_OPS
struct _CFBD_OLED

Types

Name
enum CFBD_OLEDDriverType { CFBD_OLEDDriverType_IIC, CFBD_OLEDDriverType_SPI}
Transport/driver type used to communicate with the OLED device.
typedef void * CFBD_OLEDHandle
Opaque handle type referencing driver-specific state.
typedef struct _CFBD_OLED CFBD_OLED
Forward declaration for the OLED object.
typedef CFBD_Bool(*)(CFBD_OLED *oled, uint16_t x, uint16_t y, uint16_t width, uint16_t height) AreaOperations
Function pointer type for area-based display operations.
typedef CFBD_Bool(*)(CFBD_OLED *oled) FrameOperation
Function pointer type for full-frame display operations.
typedef CFBD_Bool(*)(CFBD_OLED *oled) OLEDSelfOperation
Function pointer type for device lifecycle operations.
typedef CFBD_Bool(*)(CFBD_OLED *oled, const char *property, void *args, void *request_data) OLED_QueryOperation
Function pointer type for querying device-specific properties.
typedef CFBD_Bool(*)(CFBD_OLED *oled, const char *property, void *args, void *request_data) OLED_SetPropertyOperation
typedef struct _CFBD_OLED_OPS CFBD_OLEDOperations
typedef void * CFBDOLED_Params_Inits
Opaque pointer type for transport-specific initialization parameters.

Functions

Name
CFBD_Bool CFBD_GetOLEDHandle(CFBD_OLED * oled, const CFBD_OLEDDriverType driver_type, CFBDOLED_Params_Inits args, CFBD_Bool request_immediate_init)

Types Documentation

enum CFBD_OLEDDriverType

Enumerator Value Description
CFBD_OLEDDriverType_IIC I2C (IIC) transport - suitable for displays with I2C interface
CFBD_OLEDDriverType_SPI SPI transport - suitable for displays with SPI interface

Transport/driver type used to communicate with the OLED device.

See: CFBD_GetOLEDHandle()for usage when creating device handles

Specifies the underlying communication protocol used to interface with the OLED controller. Different transport types may have different initialization parameters and performance characteristics.

typedef CFBD_OLEDHandle

CFBD_OLEDHandle;

Opaque handle type referencing driver-specific state.

typedef CFBD_OLED

typedef struct _CFBD_OLED CFBD_OLED;

Forward declaration for the OLED object.

typedef AreaOperations

AreaOperations;

Function pointer type for area-based display operations.

Parameters:

  • oled Pointer to the CFBD_OLED instance being operated on.
  • x X coordinate of the area's top-left corner (origin 0,0 at top-left).
  • y Y coordinate of the area's top-left corner.
  • width Width of the area in pixels. Combined with x must not exceed display width.
  • height Height of the area in pixels. Combined with y must not exceed display height.

See: CFBD_OLEDOperationsfor operation table definition

Return: CFBD_Bool CFBD_TRUE on success, CFBD_FALSE on failure. Failures may include invalid coordinates or driver errors.

This function pointer signature is used for operations that target a rectangular area of the display (e.g., update_area, clear_area, revert_area). Implementations should use clipping to handle areas that extend beyond display boundaries.

typedef FrameOperation

FrameOperation;

Function pointer type for full-frame display operations.

Parameters:

  • oled Pointer to the CFBD_OLED instance being operated on.

See: CFBD_OLEDOperationsfor operation table definition

Return: CFBD_Bool CFBD_TRUE on success, CFBD_FALSE on failure.

B

This function pointer signature handles operations that affect the entire display frame (update, clear, revert operations). Typically used to push local buffer changes to the display, clear all pixels, or restore the previous frame content if supported by the device.

typedef OLEDSelfOperation

OLEDSelfOperation;

Function pointer type for device lifecycle operations.

Parameters:

  • oled Pointer to the CFBD_OLED instance being operated on.

See: CFBD_OLEDOperationsfor operation table definition

Return: CFBD_Bool CFBD_TRUE on success, CFBD_FALSE on failure.

This function pointer signature is used for operations that manage the device lifecycle (open/close/enable/disable). These operations typically handle resource allocation, hardware initialization, and cleanup.

typedef OLED_QueryOperation

OLED_QueryOperation;

Function pointer type for querying device-specific properties.

Parameters:

  • oled Pointer to the CFBD_OLED instance being queried.
  • property Null-terminated string naming the queried property.
  • args Optional input arguments for the query (implementation-defined). Pass NULL if the query doesn't require additional arguments.
  • request_data Output pointer where query results are written. Caller must allocate appropriate buffer based on property type.

Return: CFBD_Bool CFBD_TRUE on success (property found and returned), CFBD_FALSE on failure (unknown property or error).

This function pointer signature handles runtime queries for device capabilities and properties. Implementations must support standard properties ("width", "height", "rgb") and may support additional device-specific properties.

Supported standard properties:

  • "width": returns uint16_t display width in pixels
  • "height": returns uint16_t display height in pixels
  • "rgb": returns CFBD_Bool indicating RGB vs monochrome support

typedef OLED_SetPropertyOperation

typedef CFBD_Bool(* OLED_SetPropertyOperation) (CFBD_OLED *oled, const char *property, void *args, void *request_data);

typedef CFBD_OLEDOperations

typedef struct _CFBD_OLED_OPS CFBD_OLEDOperations;

typedef CFBDOLED_Params_Inits

CFBDOLED_Params_Inits;

Opaque pointer type for transport-specific initialization parameters.

See: CFBD_GetOLEDHandle()for usage

This typedef abstracts transport-specific parameter structures. For I2C transport: point to CFBD_OLED_IICInitsParams For SPI transport: point to device-specific SPI parameter structure For other transports: point to relevant parameter structure

Functions Documentation

function CFBD_GetOLEDHandle

CFBD_Bool CFBD_GetOLEDHandle(
    CFBD_OLED * oled,
    const CFBD_OLEDDriverType driver_type,
    CFBDOLED_Params_Inits args,
    CFBD_Bool request_immediate_init
)

Source code

#pragma once
#include "cfbd_define.h"

typedef enum
{
    CFBD_OLEDDriverType_IIC, 
    CFBD_OLEDDriverType_SPI  
} CFBD_OLEDDriverType;

typedef void* CFBD_OLEDHandle;

typedef struct _CFBD_OLED CFBD_OLED;

typedef CFBD_Bool (
        *AreaOperations)(CFBD_OLED* oled, uint16_t x, uint16_t y, uint16_t width, uint16_t height);

typedef CFBD_Bool (*FrameOperation)(CFBD_OLED* oled);

typedef CFBD_Bool (*OLEDSelfOperation)(CFBD_OLED* oled);

typedef CFBD_Bool (*OLED_QueryOperation)(CFBD_OLED* oled,
                                         const char* property,
                                         void* args,
                                         void* request_data);

typedef CFBD_Bool (*OLED_SetPropertyOperation)(CFBD_OLED* oled,
                                               const char* property,
                                               void* args,
                                               void* request_data); // What to write?

typedef struct _CFBD_OLED_OPS
{
    int (*init)(CFBD_OLED* oled, void* init_args);

    CFBD_Bool (*setPixel)(CFBD_OLED* oled, uint16_t x, uint16_t y);

    CFBD_Bool (*setArea)(CFBD_OLED* device,
                         uint16_t x,
                         uint16_t y,
                         uint16_t width,
                         uint16_t height,
                         uint8_t* source);

    FrameOperation update;

    FrameOperation clear;

    FrameOperation revert;

    AreaOperations update_area;

    AreaOperations clear_area;

    AreaOperations revert_area;

    OLEDSelfOperation open;

    OLEDSelfOperation close;

    OLED_QueryOperation self_consult;

    OLED_SetPropertyOperation self_property_setter;
} CFBD_OLEDOperations;

typedef struct _CFBD_OLED
{
    const CFBD_OLEDOperations* ops;

    CFBD_OLEDDriverType driver_type;

    CFBD_OLEDHandle oled_internal_handle;
} CFBD_OLED;

typedef void* CFBDOLED_Params_Inits;

CFBD_Bool CFBD_GetOLEDHandle(CFBD_OLED* oled,
                             const CFBD_OLEDDriverType driver_type,
                             CFBDOLED_Params_Inits args,
                             CFBD_Bool request_immediate_init);

 // end of OLED group

Updated on 2026-02-03 at 13:21:55 +0000