如何定义和使用一个动态分配的数组,其成员是static const
?
背景:我需要执行上述操作,以存储运行时请求的几个事务。下面的代码片段举例说明了如何定义事务。此代码使用 Nordic Semiicondictor nRF5x SDK。
static app_twi_transfer_t const transfers[] =
{
APP_TWI_WRITE(MMA7660_ADDR, p_reg_addr, 1, APP_TWI_NO_STOP),
APP_TWI_READ (MMA7660_ADDR, p_buffer, byte_cnt, 0)
};
static app_twi_transaction_t const transaction =
{
.callback = read_mma7660_registers_cb,
.p_user_data = NULL,
.p_transfers = transfers,
.number_of_transfers = sizeof(transfers)/sizeof(transfers[0])
};
APP_ERROR_CHECK(app_twi_schedule(&m_app_twi, &transaction));