API GUIDE / I2C / LL
G32S10 I2C LL 接口
LL 层接口:LL 层接口均为 static inline,不返回统一错误码。
1. LL 接口规范
LL 层接口均为 static inline,不返回统一错误码。调用方必须传入有效 i2c_regs_t * 实例,并保证参数范围合法。
1.1 实例与参数检查辅助
| 接口 | 返回类型 | 说明 |
|---|
ll_i2c_is_instance(const i2c_regs_t *i2cx) | bool | 判断实例是否为 I2C0、I2C1 或 I2C2 |
ll_i2c_is_address_7bit_valid(uint16_t address) | bool | 判断地址是否在 0 到 0x7F 范围内 |
ll_i2c_is_address_10bit_valid(uint16_t address) | bool | 判断地址是否在 0 到 0x3FF 范围内 |
ll_i2c_is_hs_master_code_valid(uint8_t hs_master_code) | bool | 判断高速主机码是否在 0 到 7 范围内 |
1.2 控制器使能与角色
| 接口 | 说明 |
|---|
ll_i2c_disable(i2c_regs_t *i2cx) | 写 ENABLE = 0 禁用控制器 |
ll_i2c_enable(i2c_regs_t *i2cx) | 置位 ENABLE.CONTROLLER 使能控制器 |
ll_i2c_abort_master_transfer(i2c_regs_t *i2cx) | 置位 ENABLE.ABORT 请求中止当前主机传输 |
ll_i2c_is_enabled(const i2c_regs_t *i2cx) | 读取 ENABLE_STATUS.ENABLED |
ll_i2c_is_abort_in_progress(const i2c_regs_t *i2cx) | 检查 ENABLE.ABORT 是否仍为 1 |
ll_i2c_set_master_role(i2c_regs_t *i2cx) | 配置 master mode 并 disable slave |
ll_i2c_set_slave_role(i2c_regs_t *i2cx) | 清除 master mode 和 slave disable |
ll_i2c_reset_control_config(i2c_regs_t *i2cx) | 清空控制寄存器配置 |
1.3 RESTART、地址模式与速度
| 接口 | 说明 |
|---|
ll_i2c_restart_enable(i2c_regs_t *i2cx) | 使能 repeated START |
ll_i2c_restart_disable(i2c_regs_t *i2cx) | 禁用 repeated START |
ll_i2c_slave_address_10bit_enable(i2c_regs_t *i2cx) | 从机地址匹配选择 10 bit |
ll_i2c_slave_address_10bit_disable(i2c_regs_t *i2cx) | 从机地址匹配选择 7 bit |
ll_i2c_set_speed_standard(i2c_regs_t *i2cx) | 配置 CON.SPEED 为 standard |
ll_i2c_set_speed_fast(i2c_regs_t *i2cx) | 配置 CON.SPEED 为 fast |
ll_i2c_set_speed_high(i2c_regs_t *i2cx) | 配置 CON.SPEED 为 high |
1.4 目标地址、从机地址和特殊目标
| 接口 | 说明 |
|---|
ll_i2c_set_target_address_7bit(i2c_regs_t *i2cx, uint16_t target_address) | 编程 7 bit 主机目标地址 |
ll_i2c_set_target_address_10bit(i2c_regs_t *i2cx, uint16_t target_address) | 编程 10 bit 主机目标地址并置位 master 10 bit |
ll_i2c_set_general_call_target(i2c_regs_t *i2cx) | 选择 general call 特殊目标 |
ll_i2c_set_start_byte_target(i2c_regs_t *i2cx) | 选择 START byte 特殊目标 |
ll_i2c_clear_special_target(i2c_regs_t *i2cx) | 清除特殊目标选择位 |
ll_i2c_get_target_address(const i2c_regs_t *i2cx) | 读取目标地址字段 |
ll_i2c_is_target_10bit(const i2c_regs_t *i2cx) | 判断当前目标是否为 10 bit |
ll_i2c_is_special_target(const i2c_regs_t *i2cx) | 判断是否选中特殊目标 |
ll_i2c_set_slave_address(i2c_regs_t *i2cx, uint16_t slave_address) | 编程从机地址 |
ll_i2c_get_slave_address(const i2c_regs_t *i2cx) | 读取从机地址字段 |
ll_i2c_set_hs_master_code(i2c_regs_t *i2cx, uint8_t hs_master_code) | 编程高速主机码 |
ll_i2c_get_hs_master_code(const i2c_regs_t *i2cx) | 读取高速主机码 |
1.5 时序与滤波
| 接口 | 说明 |
|---|
ll_i2c_set_standard_scl_counts(i2c_regs_t *i2cx, uint16_t high_count, uint16_t low_count) | 编程标准模式 SCL high/low count |
ll_i2c_set_fast_scl_counts(i2c_regs_t *i2cx, uint16_t high_count, uint16_t low_count) | 编程快速/快速增强模式 SCL high/low count |
ll_i2c_set_high_scl_counts(i2c_regs_t *i2cx, uint16_t high_count, uint16_t low_count) | 编程高速模式 SCL high/low count |
ll_i2c_set_sda_hold(i2c_regs_t *i2cx, uint16_t hold_count) | 编程 SDA hold count |
ll_i2c_set_sda_setup(i2c_regs_t *i2cx, uint8_t setup_count) | 编程 SDA setup count |
ll_i2c_set_fs_spike_length(i2c_regs_t *i2cx, uint8_t cycles) | 编程 standard/fast spike suppression length |
ll_i2c_set_hs_spike_length(i2c_regs_t *i2cx, uint8_t cycles) | 编程 high speed spike suppression length |
1.6 FIFO、DATA_CMD 与 DMA
| 接口 | 说明 |
|---|
ll_i2c_set_rx_threshold(i2c_regs_t *i2cx, uint32_t level) | 编程 RX FIFO 阈值 |
ll_i2c_set_tx_threshold(i2c_regs_t *i2cx, uint32_t level) | 编程 TX FIFO 阈值 |
ll_i2c_write_data_cmd(i2c_regs_t *i2cx, uint8_t data, uint32_t flags) | 写一条 DATA_CMD entry |
ll_i2c_queue_master_write(i2c_regs_t *i2cx, uint8_t data, bool restart, bool stop) | 投递一条主机写 DATA_CMD |
ll_i2c_queue_master_read(i2c_regs_t *i2cx, bool restart, bool stop) | 投递一条主机读 DATA_CMD |
ll_i2c_read_data(const i2c_regs_t *i2cx) | 从 DATA_CMD 读取一个 RX 数据字节 |
ll_i2c_get_data_register_address(const i2c_regs_t *i2cx) | 返回 DATA_CMD 寄存器地址 |
ll_i2c_configure_dma(i2c_regs_t *i2cx, uint32_t dma_cr_flags, uint8_t tx_level, uint8_t rx_level) | 配置 I2C DMA 请求使能和阈值 |
ll_i2c_write_data_cmd() 的 flags 可使用以下位:
1.7 general call ACK
| 接口 | 说明 |
|---|
ll_i2c_ack_general_call_enable(i2c_regs_t *i2cx) | 从机模式 ACK general call 地址 |
ll_i2c_ack_general_call_disable(i2c_regs_t *i2cx) | 从机模式不 ACK general call 地址 |
1.8 中断寄存器访问
| 接口 | 说明 |
|---|
ll_i2c_get_interrupt_status(const i2c_regs_t *i2cx) | 读取屏蔽后的中断状态 |
ll_i2c_get_interrupt_mask(const i2c_regs_t *i2cx) | 读取中断 mask |
ll_i2c_get_raw_interrupt_status(const i2c_regs_t *i2cx) | 读取原始中断状态 |
ll_i2c_set_interrupt_mask(i2c_regs_t *i2cx, uint32_t mask) | 替换中断 mask,自动限制到 I2C_INT_ALL_MASK |
ll_i2c_enable_interrupts(i2c_regs_t *i2cx, uint32_t mask) | 使能选定中断,自动限制到 I2C_INT_ALL_MASK |
ll_i2c_disable_interrupts(i2c_regs_t *i2cx, uint32_t mask) | 禁用选定中断 |
ll_i2c_mask_all_interrupts(i2c_regs_t *i2cx) | mask 全部中断 |
1.9 中断清除
| 接口 | 说明 |
|---|
ll_i2c_clear_interrupts(const i2c_regs_t *i2cx) | 读取 CLR_INTR 清除全部可清中断 |
ll_i2c_clear_rx_under(const i2c_regs_t *i2cx) | 清除 RX underflow 中断 |
ll_i2c_clear_rx_over(const i2c_regs_t *i2cx) | 清除 RX overflow 中断 |
ll_i2c_clear_tx_over(const i2c_regs_t *i2cx) | 清除 TX overflow 中断 |
ll_i2c_clear_rd_req(const i2c_regs_t *i2cx) | 清除 read request 中断 |
ll_i2c_clear_tx_abort(const i2c_regs_t *i2cx) | 清除 TX abort 中断 |
ll_i2c_clear_rx_done(const i2c_regs_t *i2cx) | 清除 RX done 中断 |
ll_i2c_clear_activity(const i2c_regs_t *i2cx) | 清除 activity 中断 |
ll_i2c_clear_stop_detect(const i2c_regs_t *i2cx) | 清除 STOP detect 中断 |
ll_i2c_clear_start_detect(const i2c_regs_t *i2cx) | 清除 START detect 中断 |
ll_i2c_clear_general_call(const i2c_regs_t *i2cx) | 清除 general call 中断 |
说明:上述接口通过读取硬件 clear 寄存器完成清除。
1.10 状态与 FIFO 水位
| 接口 | 返回类型 | 说明 |
|---|
ll_i2c_get_status(const i2c_regs_t *i2cx) | uint32_t | 读取 STATUS 寄存器 |
ll_i2c_is_tx_fifo_not_full(const i2c_regs_t *i2cx) | bool | TX FIFO 是否可接收至少 1 条 entry |
ll_i2c_is_tx_fifo_empty(const i2c_regs_t *i2cx) | bool | TX FIFO 是否为空 |
ll_i2c_is_rx_fifo_not_empty(const i2c_regs_t *i2cx) | bool | RX FIFO 是否非空 |
ll_i2c_is_rx_fifo_full(const i2c_regs_t *i2cx) | bool | RX FIFO 是否满 |
ll_i2c_is_activity(const i2c_regs_t *i2cx) | bool | 控制器是否报告 activity |
ll_i2c_is_master_activity(const i2c_regs_t *i2cx) | bool | 主机状态机是否活动 |
ll_i2c_is_slave_activity(const i2c_regs_t *i2cx) | bool | 从机状态机是否活动 |
ll_i2c_get_tx_fifo_level(const i2c_regs_t *i2cx) | uint32_t | 读取 TX FIFO 水位 |
ll_i2c_get_rx_fifo_level(const i2c_regs_t *i2cx) | uint32_t | 读取 RX FIFO 水位 |
ll_i2c_get_tx_abort_source(const i2c_regs_t *i2cx) | uint32_t | 读取 TX abort source |