🔧 HAL - Hardware Abstraction Layer
Gömülü Sistemler için Donanım Soyutlama Katmanı
📋 HAL Modülleri (21 Modül)
🔌 gpio
381 satır - GPIO Pin Control
Digital I/O, input/output modes, interrupts, pull-up/down
📊 adc
400 satır - Analog-to-Digital Converter
ADC channels, sampling, resolution, DMA support
📈 dac
391 satır - Digital-to-Analog Converter
DAC output, waveform generation, voltage control
🔄 spi
394 satır - Serial Peripheral Interface
SPI master/slave, full-duplex, DMA transfers
🔗 i2c
396 satır - Inter-Integrated Circuit
I2C bus, multi-master, 7/10-bit addressing
📡 usart
407 satır - Universal Serial Communication
UART/USART, baud rates, parity, DMA
🚗 can
383 satır - Controller Area Network
CAN bus, filters, message queues, error handling
⏱️ timer
366 satır - Hardware Timers
PWM, input capture, output compare, encoder mode
🕐 rtc
379 satır - Real-Time Clock
Date/time, alarms, calendar, backup registers
💾 dma
391 satır - Direct Memory Access
Memory-to-memory, peripheral-to-memory transfers
⚡ int
366 satır - Interrupt Controller
NVIC, interrupt priorities, enable/disable
🧠 core
367 satır - CPU Core Functions
System init, clock config, power modes
🎛️ regs
366 satır - Register Access
Memory-mapped registers, bit manipulation
🔧 hw
366 satır - Hardware Utilities
Delays, atomic operations, critical sections
📦 dev
371 satır - Device Management
Device tree, resource allocation
🖥️ host
367 satır - Host Communication
USB host, debugging interface
🔀 pipe
369 satır - Data Pipes
Stream processing, buffering
📝 enum
366 satır - Enumerations
Hardware enums, constants
⚠️ ie
366 satır - Interrupt Events
Event handling, callbacks
🎵 transc
366 satır - Transceivers
RF transceivers, wireless communication
📚 std
366 satır - Standard HAL Library
Common types, utilities
🚀 Hızlı Başlangıç
içe_aktar hal::gpio, hal::timer
// GPIO LED blink
değişken led_pin = gpio.pin_init(gpio.PORT_A, 5, gpio.MODE_OUTPUT)
gpio.pin_write(led_pin, gpio.HIGH)
// Timer PWM
değişken pwm = timer.pwm_init(timer.TIM1, timer.CH1, 1000) // 1kHz
timer.pwm_set_duty(pwm, 50) // 50% duty cycle
timer.pwm_start(pwm)
💡 Örnek: STM32 LED Blink
içe_aktar hal::core, hal::gpio, hal::timer
fonksiyon ana() yap
// System initialization
core.system_init()
core.clock_config(72_000_000) // 72MHz
// GPIO setup
gpio.clock_enable(gpio.PORT_C)
değişken led = gpio.pin_init(gpio.PORT_C, 13, yap
mode: gpio.MODE_OUTPUT,
speed: gpio.SPEED_LOW,
pull: gpio.PULL_NONE
son)
// Blink loop
döngü yap
gpio.pin_toggle(led)
core.delay_ms(500)
son
son
💡 Örnek: ADC Reading
içe_aktar hal::adc, hal::gpio, hal::core
fonksiyon sıcaklık_oku() -> kesir yap
// ADC setup
adc.clock_enable()
değişken adc1 = adc.init(adc.ADC1, yap
resolution: adc.RESOLUTION_12BIT,
align: adc.ALIGN_RIGHT
son)
// GPIO for analog input
değişken pin = gpio.pin_init(gpio.PORT_A, 0, gpio.MODE_ANALOG)
// Configure channel
adc.channel_config(adc1, adc.CHANNEL_0, yap
sampling_time: adc.SAMPLETIME_480CYCLES
son)
// Read value
adc.start(adc1)
değişken raw = adc.read(adc1)
// Convert to temperature (example)
değişken voltage = raw.kesir() * 3.3 / 4095.0
değişken temp = (voltage - 0.76) / 0.0025 + 25.0
dön temp
son
fonksiyon ana() yap
core.system_init()
döngü yap
değişken temp = sıcaklık_oku()
io.println("Sıcaklık: " + temp.yazıya() + "°C")
core.delay_ms(1000)
son
son
💡 Örnek: I2C OLED Display
içe_aktar hal::i2c, hal::gpio
sabit OLED_ADDR = 0x3C
fonksiyon oled_init(i2c: I2CHandle) yap
// Initialization sequence
değişken init_cmds = [
0xAE, // Display off
0xD5, 0x80, // Clock divide
0xA8, 0x3F, // Multiplex
0xD3, 0x00, // Display offset
0x40, // Start line
0x8D, 0x14, // Charge pump
0x20, 0x00, // Memory mode
0xA1, // Segment remap
0xC8, // COM scan direction
0xDA, 0x12, // COM pins
0x81, 0xCF, // Contrast
0xD9, 0xF1, // Pre-charge
0xDB, 0x40, // VCOMH deselect
0xA4, // Display resume
0xA6, // Normal display
0xAF // Display on
]
her cmd içinde init_cmds için yap
i2c.write_byte(i2c, OLED_ADDR, 0x00, cmd)
son
son
fonksiyon ana() yap
// I2C setup
gpio.pin_init(gpio.PORT_B, 6, gpio.MODE_AF_OD) // SCL
gpio.pin_init(gpio.PORT_B, 7, gpio.MODE_AF_OD) // SDA
değişken i2c1 = i2c.init(i2c.I2C1, yap
speed: i2c.SPEED_100KHZ,
mode: i2c.MODE_I2C
son)
oled_init(i2c1)
// Display text
oled_print(i2c1, "BERK v1.0.0")
oled_print(i2c1, "Embedded!")
son
📚 Platform Desteği
- STM32: F0, F1, F2, F3, F4, F7, H7, L0, L1, L4, L5
- ESP32: ESP32, ESP32-S2, ESP32-S3, ESP32-C3
- Nordic: nRF51, nRF52, nRF53
- RISC-V: GD32VF103, CH32V103
- ARM Cortex-M: M0, M0+, M3, M4, M7, M33