caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations
cfn_hal_types.h File Reference

Common type definitions and enums for the HAL. More...

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

Go to the source code of this file.

Data Structures

struct  cfn_hal_driver_s
 Base structure for all peripheral drivers. Contains common state and polymorphic interface linkage. More...
 

Macros

#define CFN_HAL_MAKE_TYPE(a, b, c, d)
 
#define CFN_HAL_PERIPHERAL_PREFIX   'A'
 Prefix for all HAL-level peripheral types. Reserving 'A' for the base HAL layer to avoid collisions with other layers.
 
#define CFN_HAL_PERIPHERAL_TYPE(a, b, c)   CFN_HAL_MAKE_TYPE(CFN_HAL_PERIPHERAL_PREFIX, a, b, c)
 Helper macro to create a HAL-level peripheral FourCC. Packs the HAL prefix and 3 characters into a 32-bit integer.
 
#define CFN_HAL_PERIPHERAL_TYPE_UNKNOWN   0
 
#define CFN_HAL_PERIPHERAL_TYPE_ADC   CFN_HAL_PERIPHERAL_TYPE('A', 'D', 'C')
 
#define CFN_HAL_PERIPHERAL_TYPE_CAN   CFN_HAL_PERIPHERAL_TYPE('C', 'A', 'N')
 
#define CFN_HAL_PERIPHERAL_TYPE_CLOCK   CFN_HAL_PERIPHERAL_TYPE('C', 'L', 'K')
 
#define CFN_HAL_PERIPHERAL_TYPE_DAC   CFN_HAL_PERIPHERAL_TYPE('D', 'A', 'C')
 
#define CFN_HAL_PERIPHERAL_TYPE_DMA   CFN_HAL_PERIPHERAL_TYPE('D', 'M', 'A')
 
#define CFN_HAL_PERIPHERAL_TYPE_GPIO   CFN_HAL_PERIPHERAL_TYPE('G', 'P', 'O')
 
#define CFN_HAL_PERIPHERAL_TYPE_I2C   CFN_HAL_PERIPHERAL_TYPE('I', '2', 'C')
 
#define CFN_HAL_PERIPHERAL_TYPE_PWM   CFN_HAL_PERIPHERAL_TYPE('P', 'W', 'M')
 
#define CFN_HAL_PERIPHERAL_TYPE_RTC   CFN_HAL_PERIPHERAL_TYPE('R', 'T', 'C')
 
#define CFN_HAL_PERIPHERAL_TYPE_SPI   CFN_HAL_PERIPHERAL_TYPE('S', 'P', 'I')
 
#define CFN_HAL_PERIPHERAL_TYPE_TIMER   CFN_HAL_PERIPHERAL_TYPE('T', 'I', 'M')
 
#define CFN_HAL_PERIPHERAL_TYPE_UART   CFN_HAL_PERIPHERAL_TYPE('U', 'R', 'T')
 
#define CFN_HAL_PERIPHERAL_TYPE_WDT   CFN_HAL_PERIPHERAL_TYPE('W', 'D', 'T')
 
#define CFN_HAL_PERIPHERAL_TYPE_IRQ   CFN_HAL_PERIPHERAL_TYPE('I', 'R', 'Q')
 
#define CFN_HAL_PERIPHERAL_TYPE_NVM   CFN_HAL_PERIPHERAL_TYPE('N', 'V', 'M')
 
#define CFN_HAL_PERIPHERAL_TYPE_I2S   CFN_HAL_PERIPHERAL_TYPE('I', '2', 'S')
 
#define CFN_HAL_PERIPHERAL_TYPE_QSPI   CFN_HAL_PERIPHERAL_TYPE('Q', 'S', 'P')
 
#define CFN_HAL_PERIPHERAL_TYPE_CRYPTO   CFN_HAL_PERIPHERAL_TYPE('C', 'R', 'Y')
 
#define CFN_HAL_PERIPHERAL_TYPE_SDIO   CFN_HAL_PERIPHERAL_TYPE('S', 'D', 'I')
 
#define CFN_HAL_PERIPHERAL_TYPE_USB   CFN_HAL_PERIPHERAL_TYPE('U', 'S', 'B')
 
#define CFN_HAL_PERIPHERAL_TYPE_ETH   CFN_HAL_PERIPHERAL_TYPE('E', 'T', 'H')
 
#define CFN_HAL_PERIPHERAL_TYPE_COMP   CFN_HAL_PERIPHERAL_TYPE('C', 'M', 'P')
 

Typedefs

typedef enum cfn_hal_error_codes cfn_hal_error_code_t
 
typedef uint32_t cfn_hal_peripheral_type_t
 
typedef void(* cfn_hal_callback_t) (void)
 Generic function pointer for HAL callbacks. Used as a standard-compliant carrier in the base layer.
 
typedef struct cfn_hal_driver_s cfn_hal_driver_t
 Base structure for all peripheral drivers. Contains common state and polymorphic interface linkage.
 

Enumerations

enum  cfn_hal_config_phase_t { CFN_HAL_CONFIG_PHASE_DEINIT = 0 , CFN_HAL_CONFIG_PHASE_INIT }
 
enum  cfn_hal_error_codes {
  CFN_HAL_ERROR_OK = 0x00 , CFN_HAL_ERROR_FAIL = 0x01 , CFN_HAL_ERROR_BAD_PARAM , CFN_HAL_ERROR_NOT_READY ,
  CFN_HAL_ERROR_NOT_FOUND , CFN_HAL_ERROR_OUT_OF_BOUND , CFN_HAL_ERROR_NOT_SUPPORTED , CFN_HAL_ERROR_EXTERNAL ,
  CFN_HAL_ERROR_BUSY , CFN_HAL_ERROR_BAD_CONFIG , CFN_HAL_ERROR_PERIPHERAL_FAIL = 0x40 , CFN_HAL_ERROR_TIMING_TIMEOUT = 0x80 ,
  CFN_HAL_ERROR_DRIVER_GENERAL = 0xC0 , CFN_HAL_ERROR_DRIVER_NOT_INIT , CFN_HAL_ERROR_DRIVER_ALREADY_INIT , CFN_HAL_ERROR_DATA_CRC = 0x100 ,
  CFN_HAL_ERROR_DATA_BAD_FORMAT , CFN_HAL_ERROR_DATA_MISMATCH , CFN_HAL_ERROR_MEMORY_NULL = 0x140 , CFN_HAL_ERROR_MEMORY_FULL ,
  CFN_HAL_ERROR_MEMORY_ALLOC , CFN_HAL_ERROR_MEMORY_EMPTY , CFN_HAL_ERROR_DEVICE_FAIL = 0x180 , CFN_HAL_ERROR_DEVICE_NOT_FOUND ,
  CFN_HAL_ERROR_UNKNOWN
}
 
enum  cfn_hal_driver_status_t { CFN_HAL_DRIVER_STATUS_UNKNOWN = 0 , CFN_HAL_DRIVER_STATUS_CONSTRUCTED , CFN_HAL_DRIVER_STATUS_INITIALIZED , CFN_HAL_DRIVER_STATUS_ERROR }
 
enum  cfn_hal_power_state_t { CFN_HAL_POWER_STATE_UNKNOWN = 0 , CFN_HAL_POWER_STATE_ON , CFN_HAL_POWER_STATE_LOW_POWER , CFN_HAL_POWER_STATE_OFF }
 

Detailed Description

Common type definitions and enums for the HAL.

Copyright (c) 2026 Hisham Moussa Daou https://www.whileone.me

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ CFN_HAL_MAKE_TYPE

#define CFN_HAL_MAKE_TYPE (   a,
  b,
  c,
 
)
Value:
(((uint32_t) (uint8_t) (a)) | ((uint32_t) (uint8_t) (b) << 8U) | ((uint32_t) (uint8_t) (c) << 16U) | \
((uint32_t) (uint8_t) (d) << 24U))

◆ CFN_HAL_PERIPHERAL_PREFIX

#define CFN_HAL_PERIPHERAL_PREFIX   'A'

Prefix for all HAL-level peripheral types. Reserving 'A' for the base HAL layer to avoid collisions with other layers.

◆ CFN_HAL_PERIPHERAL_TYPE

#define CFN_HAL_PERIPHERAL_TYPE (   a,
  b,
 
)    CFN_HAL_MAKE_TYPE(CFN_HAL_PERIPHERAL_PREFIX, a, b, c)

Helper macro to create a HAL-level peripheral FourCC. Packs the HAL prefix and 3 characters into a 32-bit integer.

◆ CFN_HAL_PERIPHERAL_TYPE_ADC

#define CFN_HAL_PERIPHERAL_TYPE_ADC   CFN_HAL_PERIPHERAL_TYPE('A', 'D', 'C')

◆ CFN_HAL_PERIPHERAL_TYPE_CAN

#define CFN_HAL_PERIPHERAL_TYPE_CAN   CFN_HAL_PERIPHERAL_TYPE('C', 'A', 'N')

◆ CFN_HAL_PERIPHERAL_TYPE_CLOCK

#define CFN_HAL_PERIPHERAL_TYPE_CLOCK   CFN_HAL_PERIPHERAL_TYPE('C', 'L', 'K')

◆ CFN_HAL_PERIPHERAL_TYPE_COMP

#define CFN_HAL_PERIPHERAL_TYPE_COMP   CFN_HAL_PERIPHERAL_TYPE('C', 'M', 'P')

◆ CFN_HAL_PERIPHERAL_TYPE_CRYPTO

#define CFN_HAL_PERIPHERAL_TYPE_CRYPTO   CFN_HAL_PERIPHERAL_TYPE('C', 'R', 'Y')

◆ CFN_HAL_PERIPHERAL_TYPE_DAC

#define CFN_HAL_PERIPHERAL_TYPE_DAC   CFN_HAL_PERIPHERAL_TYPE('D', 'A', 'C')

◆ CFN_HAL_PERIPHERAL_TYPE_DMA

#define CFN_HAL_PERIPHERAL_TYPE_DMA   CFN_HAL_PERIPHERAL_TYPE('D', 'M', 'A')

◆ CFN_HAL_PERIPHERAL_TYPE_ETH

#define CFN_HAL_PERIPHERAL_TYPE_ETH   CFN_HAL_PERIPHERAL_TYPE('E', 'T', 'H')

◆ CFN_HAL_PERIPHERAL_TYPE_GPIO

#define CFN_HAL_PERIPHERAL_TYPE_GPIO   CFN_HAL_PERIPHERAL_TYPE('G', 'P', 'O')

◆ CFN_HAL_PERIPHERAL_TYPE_I2C

#define CFN_HAL_PERIPHERAL_TYPE_I2C   CFN_HAL_PERIPHERAL_TYPE('I', '2', 'C')

◆ CFN_HAL_PERIPHERAL_TYPE_I2S

#define CFN_HAL_PERIPHERAL_TYPE_I2S   CFN_HAL_PERIPHERAL_TYPE('I', '2', 'S')

◆ CFN_HAL_PERIPHERAL_TYPE_IRQ

#define CFN_HAL_PERIPHERAL_TYPE_IRQ   CFN_HAL_PERIPHERAL_TYPE('I', 'R', 'Q')

◆ CFN_HAL_PERIPHERAL_TYPE_NVM

#define CFN_HAL_PERIPHERAL_TYPE_NVM   CFN_HAL_PERIPHERAL_TYPE('N', 'V', 'M')

◆ CFN_HAL_PERIPHERAL_TYPE_PWM

#define CFN_HAL_PERIPHERAL_TYPE_PWM   CFN_HAL_PERIPHERAL_TYPE('P', 'W', 'M')

◆ CFN_HAL_PERIPHERAL_TYPE_QSPI

#define CFN_HAL_PERIPHERAL_TYPE_QSPI   CFN_HAL_PERIPHERAL_TYPE('Q', 'S', 'P')

◆ CFN_HAL_PERIPHERAL_TYPE_RTC

#define CFN_HAL_PERIPHERAL_TYPE_RTC   CFN_HAL_PERIPHERAL_TYPE('R', 'T', 'C')

◆ CFN_HAL_PERIPHERAL_TYPE_SDIO

#define CFN_HAL_PERIPHERAL_TYPE_SDIO   CFN_HAL_PERIPHERAL_TYPE('S', 'D', 'I')

◆ CFN_HAL_PERIPHERAL_TYPE_SPI

#define CFN_HAL_PERIPHERAL_TYPE_SPI   CFN_HAL_PERIPHERAL_TYPE('S', 'P', 'I')

◆ CFN_HAL_PERIPHERAL_TYPE_TIMER

#define CFN_HAL_PERIPHERAL_TYPE_TIMER   CFN_HAL_PERIPHERAL_TYPE('T', 'I', 'M')

◆ CFN_HAL_PERIPHERAL_TYPE_UART

#define CFN_HAL_PERIPHERAL_TYPE_UART   CFN_HAL_PERIPHERAL_TYPE('U', 'R', 'T')

◆ CFN_HAL_PERIPHERAL_TYPE_UNKNOWN

#define CFN_HAL_PERIPHERAL_TYPE_UNKNOWN   0

◆ CFN_HAL_PERIPHERAL_TYPE_USB

#define CFN_HAL_PERIPHERAL_TYPE_USB   CFN_HAL_PERIPHERAL_TYPE('U', 'S', 'B')

◆ CFN_HAL_PERIPHERAL_TYPE_WDT

#define CFN_HAL_PERIPHERAL_TYPE_WDT   CFN_HAL_PERIPHERAL_TYPE('W', 'D', 'T')

Typedef Documentation

◆ cfn_hal_callback_t

typedef void(* cfn_hal_callback_t) (void)

Generic function pointer for HAL callbacks. Used as a standard-compliant carrier in the base layer.

Warning
Calling this pointer directly as a void(void) function is UNDEFINED BEHAVIOR if the original callback has a different signature. Hardware port implementers MUST cast this pointer back to the peripheral-specific callback type (e.g., cfn_hal_uart_callback_t) before execution.

◆ cfn_hal_driver_t

Base structure for all peripheral drivers. Contains common state and polymorphic interface linkage.

◆ cfn_hal_error_code_t

◆ cfn_hal_peripheral_type_t

typedef uint32_t cfn_hal_peripheral_type_t

Enumeration Type Documentation

◆ cfn_hal_config_phase_t

Enumerator
CFN_HAL_CONFIG_PHASE_DEINIT 
CFN_HAL_CONFIG_PHASE_INIT 

◆ cfn_hal_driver_status_t

Enumerator
CFN_HAL_DRIVER_STATUS_UNKNOWN 

Memory state is unknown or explicitly unconstructed.

CFN_HAL_DRIVER_STATUS_CONSTRUCTED 

Driver is constructed (VMT linked) but hardware is NOT initialized.

CFN_HAL_DRIVER_STATUS_INITIALIZED 

Hardware is initialized and ready for use.

CFN_HAL_DRIVER_STATUS_ERROR 

A fatal hardware error occurred; requires a _deinit/_init cycle to recover.

◆ cfn_hal_error_codes

Enumerator
CFN_HAL_ERROR_OK 
CFN_HAL_ERROR_FAIL 
CFN_HAL_ERROR_BAD_PARAM 
CFN_HAL_ERROR_NOT_READY 
CFN_HAL_ERROR_NOT_FOUND 
CFN_HAL_ERROR_OUT_OF_BOUND 
CFN_HAL_ERROR_NOT_SUPPORTED 
CFN_HAL_ERROR_EXTERNAL 
CFN_HAL_ERROR_BUSY 
CFN_HAL_ERROR_BAD_CONFIG 
CFN_HAL_ERROR_PERIPHERAL_FAIL 
CFN_HAL_ERROR_TIMING_TIMEOUT 
CFN_HAL_ERROR_DRIVER_GENERAL 
CFN_HAL_ERROR_DRIVER_NOT_INIT 
CFN_HAL_ERROR_DRIVER_ALREADY_INIT 
CFN_HAL_ERROR_DATA_CRC 
CFN_HAL_ERROR_DATA_BAD_FORMAT 
CFN_HAL_ERROR_DATA_MISMATCH 
CFN_HAL_ERROR_MEMORY_NULL 
CFN_HAL_ERROR_MEMORY_FULL 
CFN_HAL_ERROR_MEMORY_ALLOC 
CFN_HAL_ERROR_MEMORY_EMPTY 
CFN_HAL_ERROR_DEVICE_FAIL 
CFN_HAL_ERROR_DEVICE_NOT_FOUND 
CFN_HAL_ERROR_UNKNOWN 

◆ cfn_hal_power_state_t

Enumerator
CFN_HAL_POWER_STATE_UNKNOWN 
CFN_HAL_POWER_STATE_ON 

Fully powered and clocked

CFN_HAL_POWER_STATE_LOW_POWER 

Clock gated, retention mode, or suspended

CFN_HAL_POWER_STATE_OFF 

Physically unpowered or fully disabled