Il y avait des problèmes dans la libraire...
Fork of ST_I2S by
Diff: targets/TARGET_STM/stm_i2s_api.c
- Revision:
- 27:c2fc3330d0df
- Parent:
- 26:468cdd70cd3e
--- a/targets/TARGET_STM/stm_i2s_api.c Mon Mar 27 16:15:20 2017 +0200 +++ b/targets/TARGET_STM/stm_i2s_api.c Fri Mar 31 13:44:17 2017 +0200 @@ -15,6 +15,9 @@ // #define DEBUG_STDIO 1 +#define CONTAINER_OF(ptr, type, field) \ + ((type *)(((char *)(ptr)) - offsetof(type, field))) + #ifndef DEBUG_STDIO # define DEBUG_STDIO 0 #endif @@ -697,8 +700,7 @@ // cleanup DMA (after error) dma_i2s_free(obj, direction); } else { // no error detected - size_t offset_dma_handle = offsetof(dma_extra_state_t, dma_handle); - dma_extra_state_t *extra_state = (dma_extra_state_t*)(((void*)dma_handle) - offset_dma_handle); + dma_extra_state_t *extra_state = CONTAINER_OF(dma_handle, dma_extra_state_t, dma_handle); dma_transfer_state_t dma_state = extra_state->t_state; switch(dma_state) { @@ -790,32 +792,28 @@ /*** Weak function overwrites ***/ void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { - size_t offset_i2s_handle = offsetof(i2s_dma_handles_t, i2s_handle); - i2s_dma_handles_t *i2s_dma_handle = (i2s_dma_handles_t*)(((void*)hi2s) - offset_i2s_handle); + i2s_dma_handles_t *i2s_dma_handle = CONTAINER_OF(hi2s, i2s_dma_handles_t, i2s_handle); dma_transfer_state_t *dma_t_state = &(i2s_dma_handle->dma_handles[DMA_TX].t_state); *dma_t_state = I2S_HALF_TRANSFER; } void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { - size_t offset_i2s_handle = offsetof(i2s_dma_handles_t, i2s_handle); - i2s_dma_handles_t *i2s_dma_handle = (i2s_dma_handles_t*)(((void*)hi2s) - offset_i2s_handle); + i2s_dma_handles_t *i2s_dma_handle = CONTAINER_OF(hi2s, i2s_dma_handles_t, i2s_handle); dma_transfer_state_t *dma_t_state = &(i2s_dma_handle->dma_handles[DMA_RX].t_state); *dma_t_state = I2S_HALF_TRANSFER; } void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) { - size_t offset_i2s_handle = offsetof(i2s_dma_handles_t, i2s_handle); - i2s_dma_handles_t *i2s_dma_handle = (i2s_dma_handles_t*)(((void*)hi2s) - offset_i2s_handle); + i2s_dma_handles_t *i2s_dma_handle = CONTAINER_OF(hi2s, i2s_dma_handles_t, i2s_handle); dma_transfer_state_t *dma_t_state = &(i2s_dma_handle->dma_handles[DMA_TX].t_state); *dma_t_state = I2S_FULL_TRANSFER; } void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) { - size_t offset_i2s_handle = offsetof(i2s_dma_handles_t, i2s_handle); - i2s_dma_handles_t *i2s_dma_handle = (i2s_dma_handles_t*)(((void*)hi2s) - offset_i2s_handle); + i2s_dma_handles_t *i2s_dma_handle = CONTAINER_OF(hi2s, i2s_dma_handles_t, i2s_handle); dma_transfer_state_t *dma_t_state = &(i2s_dma_handle->dma_handles[DMA_RX].t_state); *dma_t_state = I2S_FULL_TRANSFER;