Skip to content

Commit aedc979

Browse files
committed
fixed bugs
1 parent 76c67aa commit aedc979

File tree

24 files changed

+238
-409
lines changed

24 files changed

+238
-409
lines changed

components/peripherals/i2c/esp_ak8975/ak8975.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,14 @@ static inline esp_err_t ak8975_get_sensitivity_adjusted_axes(ak8975_handle_t han
127127
* @param size Length of buffer to store results from read transaction.
128128
* @return esp_err_t ESP_OK on success.
129129
*/
130-
static inline esp_err_t bme680_i2c_read_from(ak8975_handle_t handle, const uint8_t reg_addr, uint8_t *buffer, const uint8_t size) {
130+
static inline esp_err_t ak8975_i2c_read_from(ak8975_handle_t handle, const uint8_t reg_addr, uint8_t *buffer, const uint8_t size) {
131131
const bit8_uint8_buffer_t tx = { reg_addr };
132132

133133
/* validate arguments */
134134
ESP_ARG_CHECK( handle );
135135

136-
/* attempt i2c write transaction */
137-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
138-
139-
/* delay task before next i2c transaction */
140-
vTaskDelay(pdMS_TO_TICKS(AK8975_TX_RX_DELAY_MS));
141-
142-
/* attempt i2c read transaction */
143-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, buffer, size, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
144-
136+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, buffer, size, I2C_XFR_TIMEOUT_MS), TAG, "ak8975_i2c_read_byte_from failed" );
137+
145138
return ESP_OK;
146139
}
147140

@@ -160,14 +153,7 @@ static inline esp_err_t ak8975_i2c_read_byte_from(ak8975_handle_t handle, const
160153
/* validate arguments */
161154
ESP_ARG_CHECK( handle );
162155

163-
/* attempt i2c write transaction */
164-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
165-
166-
/* delay task before next i2c transaction */
167-
vTaskDelay(pdMS_TO_TICKS(AK8975_TX_RX_DELAY_MS));
168-
169-
/* attempt i2c read transaction */
170-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, rx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
156+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, rx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "ak8975_i2c_read_byte_from failed" );
171157

172158
/* set output parameter */
173159
*byte = rx[0];
@@ -183,7 +169,7 @@ static inline esp_err_t ak8975_i2c_read_byte_from(ak8975_handle_t handle, const
183169
* @param byte AK8975 write transaction input byte.
184170
* @return esp_err_t ESP_OK on success.
185171
*/
186-
static inline esp_err_t ak8975_i2c_write_byte_to(ak8975_handle_t handle, uint8_t reg_addr, const uint8_t byte) {
172+
static inline esp_err_t ak8975_i2c_write_byte_to(ak8975_handle_t handle, const uint8_t reg_addr, const uint8_t byte) {
187173
const bit16_uint8_buffer_t tx = { reg_addr, byte };
188174

189175
/* validate arguments */
@@ -307,7 +293,7 @@ static inline esp_err_t ak8975_get_fixed_magnetic_axes(ak8975_handle_t handle, a
307293
bit48_uint8_buffer_t rx = { 0 };
308294

309295
/* 6-byte i2c read transaction */
310-
ESP_GOTO_ON_ERROR( bme680_i2c_read_from(handle, AK8975_REG_HXL_DATA_R, rx, BIT48_UINT8_BUFFER_SIZE), err, TAG, "read axes (x, y, z) bytes failed" );
296+
ESP_GOTO_ON_ERROR( ak8975_i2c_read_from(handle, AK8975_REG_HXL_DATA_R, rx, BIT48_UINT8_BUFFER_SIZE), err, TAG, "read axes (x, y, z) bytes failed" );
311297

312298
/* delay task before next i2c transaction */
313299
vTaskDelay(pdMS_TO_TICKS(AK8975_CMD_DELAY_MS));

components/peripherals/i2c/esp_as3935/as3935.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,7 @@ static inline esp_err_t as3935_i2c_read_from(as3935_handle_t handle, const uint8
9191
/* validate arguments */
9292
ESP_ARG_CHECK( handle );
9393

94-
/* attempt i2c write transaction */
95-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
96-
97-
/* delay task before next i2c transaction */
98-
vTaskDelay(pdMS_TO_TICKS(AS3935_TX_RX_DELAY_MS));
99-
100-
/* attempt i2c read transaction */
101-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, buffer, size, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
94+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, buffer, size, I2C_XFR_TIMEOUT_MS), TAG, "as3935_i2c_read_from failed" );
10295

10396
return ESP_OK;
10497
}
@@ -119,14 +112,7 @@ static inline esp_err_t as3935_i2c_read_byte_from(as3935_handle_t handle, const
119112
/* validate arguments */
120113
ESP_ARG_CHECK( handle );
121114

122-
/* attempt i2c write transaction */
123-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
124-
125-
/* delay task before next i2c transaction */
126-
vTaskDelay(pdMS_TO_TICKS(AS3935_TX_RX_DELAY_MS));
127-
128-
/* attempt i2c read transaction */
129-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, rx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
115+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, rx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "as3935_i2c_read_byte_from failed" );
130116

131117
/* set output parameter */
132118
*byte = rx[0];
@@ -142,7 +128,7 @@ static inline esp_err_t as3935_i2c_read_byte_from(as3935_handle_t handle, const
142128
* @param byte AS3935 write transaction input byte.
143129
* @return esp_err_t ESP_OK on success.
144130
*/
145-
static inline esp_err_t as3935_i2c_write_byte_to(as3935_handle_t handle, uint8_t reg_addr, const uint8_t byte) {
131+
static inline esp_err_t as3935_i2c_write_byte_to(as3935_handle_t handle, const uint8_t reg_addr, const uint8_t byte) {
146132
const bit16_uint8_buffer_t tx = { reg_addr, byte };
147133

148134
/* validate arguments */

components/peripherals/i2c/esp_as7341/as7341.c

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static const char *TAG = "as7341";
155155
* @param byte AS7341 write transaction input byte.
156156
* @return esp_err_t ESP_OK on success.
157157
*/
158-
static inline esp_err_t as7341_i2c_write_byte_to(as7341_handle_t handle, uint8_t reg_addr, const uint8_t byte) {
158+
static inline esp_err_t as7341_i2c_write_byte_to(as7341_handle_t handle, const uint8_t reg_addr, const uint8_t byte) {
159159
const bit16_uint8_buffer_t tx = { reg_addr, byte };
160160

161161
/* validate arguments */
@@ -182,14 +182,7 @@ static inline esp_err_t as7341_i2c_read_from(as7341_handle_t handle, const uint8
182182
/* validate arguments */
183183
ESP_ARG_CHECK( handle );
184184

185-
/* attempt i2c write transaction */
186-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
187-
188-
/* delay task before next i2c transaction */
189-
vTaskDelay(pdMS_TO_TICKS(AS7341_TX_RX_DELAY_MS));
190-
191-
/* attempt i2c read transaction */
192-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, buffer, size, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
185+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, buffer, size, I2C_XFR_TIMEOUT_MS), TAG, "as7341_i2c_read_from failed" );
193186

194187
return ESP_OK;
195188
}
@@ -199,27 +192,20 @@ static inline esp_err_t as7341_i2c_read_from(as7341_handle_t handle, const uint8
199192
*
200193
* @param handle AS7341 device handle.
201194
* @param reg_addr AS7341 register address to read from.
202-
* @param halfword AS7341 read transaction return halfword.
195+
* @param word AS7341 read transaction return halfword.
203196
* @return esp_err_t ESP_OK on success.
204197
*/
205-
static inline esp_err_t as7341_i2c_read_word_from(as7341_handle_t handle, const uint8_t reg_addr, uint16_t *const halfword) {
198+
static inline esp_err_t as7341_i2c_read_word_from(as7341_handle_t handle, const uint8_t reg_addr, uint16_t *const word) {
206199
const bit8_uint8_buffer_t tx = { reg_addr };
207200
bit16_uint8_buffer_t rx = { 0 };
208201

209202
/* validate arguments */
210203
ESP_ARG_CHECK( handle );
211204

212-
/* attempt i2c write transaction */
213-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
214-
215-
/* delay task before next i2c transaction */
216-
vTaskDelay(pdMS_TO_TICKS(AS7341_TX_RX_DELAY_MS));
217-
218-
/* attempt i2c read transaction */
219-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, rx, BIT16_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
205+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, rx, BIT16_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "as7341_i2c_read_word_from failed" );
220206

221207
/* set output parameter */
222-
*halfword = (uint16_t)rx[0] | ((uint16_t)rx[1] << 8);
208+
*word = (uint16_t)rx[0] | ((uint16_t)rx[1] << 8);
223209

224210
return ESP_OK;
225211
}
@@ -239,14 +225,7 @@ static inline esp_err_t as7341_i2c_read_byte_from(as7341_handle_t handle, const
239225
/* validate arguments */
240226
ESP_ARG_CHECK( handle );
241227

242-
/* attempt i2c write transaction */
243-
ESP_RETURN_ON_ERROR( i2c_master_transmit(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_transmit, i2c read from failed" );
244-
245-
/* delay task before next i2c transaction */
246-
vTaskDelay(pdMS_TO_TICKS(AS7341_TX_RX_DELAY_MS));
247-
248-
/* attempt i2c read transaction */
249-
ESP_RETURN_ON_ERROR( i2c_master_receive(handle->i2c_handle, rx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "i2c_master_receive, i2c read from failed" );
228+
ESP_RETURN_ON_ERROR( i2c_master_transmit_receive(handle->i2c_handle, tx, BIT8_UINT8_BUFFER_SIZE, rx, BIT8_UINT8_BUFFER_SIZE, I2C_XFR_TIMEOUT_MS), TAG, "as7341_i2c_read_byte_from failed" );
250229

251230
/* set output parameter */
252231
*byte = rx[0];
@@ -968,7 +947,7 @@ esp_err_t as7341_init(i2c_master_bus_handle_t master_handle, const as7341_config
968947
return ret;
969948
}
970949

971-
esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channels_spectral_data_t *spectral_data) {
950+
esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channels_spectral_data_t *const spectral_data) {
972951
esp_err_t ret = ESP_OK;
973952
float integration_time = 0;
974953
uint64_t start_time = esp_timer_get_time();
@@ -998,7 +977,7 @@ esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channe
998977
vTaskDelay(pdMS_TO_TICKS(AS7341_DATA_READY_DELAY_MS));
999978

1000979
/* validate timeout condition */
1001-
if (ESP_TIMEOUT_CHECK(start_time, (integration_time + 20) * 1000))
980+
if (ESP_TIMEOUT_CHECK(start_time, (integration_time + 50) * 1000))
1002981
return ESP_ERR_TIMEOUT;
1003982
} while (data_is_ready == false);
1004983

@@ -1036,7 +1015,7 @@ esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channe
10361015
vTaskDelay(pdMS_TO_TICKS(AS7341_DATA_READY_DELAY_MS));
10371016

10381017
/* validate timeout condition */
1039-
if (ESP_TIMEOUT_CHECK(start_time, (integration_time + 20) * 1000))
1018+
if (ESP_TIMEOUT_CHECK(start_time, (integration_time + 50) * 1000))
10401019
return ESP_ERR_TIMEOUT;
10411020
} while (data_is_ready == false);
10421021

@@ -1060,7 +1039,7 @@ esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channe
10601039
return ret;
10611040
}
10621041

1063-
esp_err_t as7341_get_basic_counts(as7341_handle_t handle, as7341_channels_spectral_data_t spectral_data, as7341_channels_basic_counts_data_t *basic_counts_data) {
1042+
esp_err_t as7341_get_basic_counts(as7341_handle_t handle, const as7341_channels_spectral_data_t spectral_data, as7341_channels_basic_counts_data_t *const basic_counts_data) {
10641043
/* validate arguments */
10651044
ESP_ARG_CHECK( handle );
10661045

@@ -1091,7 +1070,7 @@ esp_err_t as7341_get_basic_counts(as7341_handle_t handle, as7341_channels_spectr
10911070
return ESP_OK;
10921071
}
10931072

1094-
esp_err_t as7341_get_flicker_detection_status(as7341_handle_t handle, as7341_flicker_detection_states_t *state) {
1073+
esp_err_t as7341_get_flicker_detection_status(as7341_handle_t handle, as7341_flicker_detection_states_t *const state) {
10951074
as7341_flicker_detection_status_register_t fd_status;
10961075
esp_err_t ret = ESP_OK;
10971076
uint64_t start_time = 0;
@@ -1173,7 +1152,7 @@ esp_err_t as7341_get_flicker_detection_status(as7341_handle_t handle, as7341_fli
11731152
return ret;
11741153
}
11751154

1176-
esp_err_t as7341_get_data_status(as7341_handle_t handle, bool *ready) {
1155+
esp_err_t as7341_get_data_status(as7341_handle_t handle, bool *const ready) {
11771156
as7341_status2_register_t status2;
11781157

11791158
/* validate arguments */

components/peripherals/i2c/esp_as7341/include/as7341.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ esp_err_t as7341_init(i2c_master_bus_handle_t master_handle, const as7341_config
789789
* @param[out] spectral_data Spectral sensors data from AS7341.
790790
* @return esp_err_t ESP_OK on success.
791791
*/
792-
esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channels_spectral_data_t *spectral_data);
792+
esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channels_spectral_data_t *const spectral_data);
793793

794794
/**
795795
* @brief Converts AS7341 spectral sensors measurements to basic counts.
@@ -799,7 +799,7 @@ esp_err_t as7341_get_spectral_measurements(as7341_handle_t handle, as7341_channe
799799
* @param[out] basic_counts_data Converted basic counts data from spectral sensors data.
800800
* @return esp_err_t ESP_OK on success.
801801
*/
802-
esp_err_t as7341_get_basic_counts(as7341_handle_t handle, as7341_channels_spectral_data_t spectral_data, as7341_channels_basic_counts_data_t *basic_counts_data);
802+
esp_err_t as7341_get_basic_counts(as7341_handle_t handle, const as7341_channels_spectral_data_t spectral_data, as7341_channels_basic_counts_data_t *const basic_counts_data);
803803

804804
/**
805805
* @brief Reads flicker detection status from AS7341.
@@ -808,7 +808,7 @@ esp_err_t as7341_get_basic_counts(as7341_handle_t handle, as7341_channels_spectr
808808
* @param[out] state Flicker detection state, 100Hz, 120Hz or flicker saturation was detected.
809809
* @return esp_err_t ESP_OK on success, ESP_ERR_TIMEOUT if operation timed out.
810810
*/
811-
esp_err_t as7341_get_flicker_detection_status(as7341_handle_t handle, as7341_flicker_detection_states_t *state);
811+
esp_err_t as7341_get_flicker_detection_status(as7341_handle_t handle, as7341_flicker_detection_states_t *const state);
812812

813813
/**
814814
* @brief Reads data status from AS7341.
@@ -817,7 +817,7 @@ esp_err_t as7341_get_flicker_detection_status(as7341_handle_t handle, as7341_fli
817817
* @param[out] ready Data is ready when asserted to true.
818818
* @return esp_err_t ESP_OK on success.
819819
*/
820-
esp_err_t as7341_get_data_status(as7341_handle_t handle, bool *ready);
820+
esp_err_t as7341_get_data_status(as7341_handle_t handle, bool *const ready);
821821

822822
/**
823823
* @brief Reads the number of integration steps for the ADC integration time from AS7341.

components/peripherals/i2c/esp_bh1750/bh1750.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static inline esp_err_t bh1750_i2c_write(bh1750_handle_t handle, const uint8_t *
116116
* @param reg_addr BH1750 command register address to write to.
117117
* @return esp_err_t ESP_OK on success.
118118
*/
119-
static inline esp_err_t bh1750_i2c_write_command(bh1750_handle_t handle, uint8_t reg_addr) {
119+
static inline esp_err_t bh1750_i2c_write_command(bh1750_handle_t handle, const uint8_t reg_addr) {
120120
const bit8_uint8_buffer_t tx = { reg_addr };
121121

122122
/* validate arguments */

0 commit comments

Comments
 (0)