Skip to content

Commit

Permalink
fix compile issues with ESP-IDF 5.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
CJCombrink committed Jul 18, 2023
1 parent 597bb1a commit 52a5906
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 63 deletions.
27 changes: 1 addition & 26 deletions include/owb_rmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,9 @@ OneWireBus bus; ///< OneWireBus instance (see owb.
* @param[in] info Pointer to an uninitialized owb_rmt_driver_info structure.
* Note: the structure must remain in scope for the lifetime of this component.
* @param[in] gpio_num The GPIO number to use as the One Wire bus data line.
* @param tx_channel NOW IGNORED: the new RMT driver allocates channels dynamically.
* @param rx_channel NOW IGNORED: the new RMT driver allocates channels dynamically.
* @return OneWireBus *, pass this into the other OneWireBus public API functions
*/
OneWireBus* owb_rmt_initialize(owb_rmt_driver_info * info, gpio_num_t gpio_num,
rmt_channel_t tx_channel, rmt_channel_t rx_channel);


/**
* @brief Legacy RMT channel IDs.
*
* These are no longer used for anything. They are defined here purely so
* that code written for the old rmt driver can still compile.
*/
typedef enum {
RMT_CHANNEL_0, /*!< RMT channel number 0 */
RMT_CHANNEL_1, /*!< RMT channel number 1 */
RMT_CHANNEL_2, /*!< RMT channel number 2 */
RMT_CHANNEL_3, /*!< RMT channel number 3 */
#if SOC_RMT_CHANNELS_PER_GROUP > 4
RMT_CHANNEL_4, /*!< RMT channel number 4 */
RMT_CHANNEL_5, /*!< RMT channel number 5 */
RMT_CHANNEL_6, /*!< RMT channel number 6 */
RMT_CHANNEL_7, /*!< RMT channel number 7 */
#endif
RMT_CHANNEL_MAX /*!< Number of RMT channels */
} rmt_channel_t;

OneWireBus* owb_rmt_initialize(owb_rmt_driver_info * info, gpio_num_t gpio_num);

#ifdef __cplusplus
}
Expand Down
68 changes: 31 additions & 37 deletions owb_rmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static owb_status _parse_reset_symbols (size_t num_symbols, rmt_symbol_word_t *s
// display raw RMT symbols
ESP_LOGI(TAG, "parse reset: %d symbols", (int)num_symbols);
for (int i = 0; i < num_symbols; i += 1) {
ESP_LOGI (TAG, "\t%u (%uus), %u (%uus)", symbols->level0, symbols->duration0,
ESP_LOGI (TAG, "\t%u (%uus), %u (%uus)", symbols->level0, symbols->duration0,
symbols->level1, symbols->duration1);
}
#endif
Expand Down Expand Up @@ -143,7 +143,7 @@ static owb_status _parse_reset_symbols (size_t num_symbols, rmt_symbol_word_t *s

/**
* @brief Parses the RMT symbols received during the transmission of up to 64 onewire bits.
* @param[in] num_symbols The number of symbols passed.
* @param[in] num_symbols The number of symbols passed.
* @param[in] symbols An array of RMT symbols.
* @param[out] result The decoded bits (max 64, lsb first)
* @return int The number of bits decoded
Expand All @@ -160,12 +160,12 @@ static int _parse_bit_symbols (size_t num_symbols, rmt_symbol_word_t *p_symbol,

while (p_symbol < p_last_symbol && bit_count < 64) {
#ifdef OWB_RMT_DEBUG
ESP_LOGI (TAG, "\t%u (%uus), %u (%uus)", p_symbol->level0, p_symbol->duration0,
ESP_LOGI (TAG, "\t%u (%uus), %u (%uus)", p_symbol->level0, p_symbol->duration0,
p_symbol->level1, p_symbol->duration1);
#endif
if (abs (p_symbol->duration0 - OWB_TIMING_PARAM_A) <= OWB_TIMING_MARGIN &&
(p_symbol->duration1 == 0 || p_symbol->duration1 >= OWB_TIMING_PARAM_E)) {
// bus was released at the sample point: detect a '1'
// bus was released at the sample point: detect a '1'
*result |= (1ull << bit_count);
bit_count += 1;

Expand All @@ -179,7 +179,7 @@ static int _parse_bit_symbols (size_t num_symbols, rmt_symbol_word_t *p_symbol,

#ifdef OWB_RMT_DEBUG
ESP_LOGI (TAG, "\t\tdetect '0' -> 0x%llx", *result);
#endif
#endif
}
p_symbol += 1; // next symbol
}
Expand All @@ -203,9 +203,9 @@ static owb_status _reset (const OneWireBus *bus, bool *is_present) {

// start the receiver before the transmitter so that it sees the leading edge of the pulse
esp_status = rmt_receive (
info->rx_channel_handle,
info->rx_channel_handle,
info->rx_buffer,
info->rx_buffer_size_in_bytes,
info->rx_buffer_size_in_bytes,
&rx_config_owb_reset);
if (esp_status != ESP_OK) {
ESP_LOGE(TAG, "owb_reset: rx err");
Expand All @@ -214,11 +214,11 @@ static owb_status _reset (const OneWireBus *bus, bool *is_present) {

// encode and transmit the reset pulse using the RMT 'copy' encoder
esp_status = rmt_transmit (
info->tx_channel_handle,
info->copy_encoder_handle,
&owb_rmt_symbol_reset,
info->tx_channel_handle,
info->copy_encoder_handle,
&owb_rmt_symbol_reset,
sizeof (owb_rmt_symbol_reset),
&owb_rmt_transmit_config);
&owb_rmt_transmit_config);
if (esp_status != ESP_OK) {
ESP_LOGE(TAG, "owb_reset: tx err");
return OWB_STATUS_HW_ERROR;
Expand All @@ -236,7 +236,7 @@ static owb_status _reset (const OneWireBus *bus, bool *is_present) {
ESP_LOGE(TAG, "owb_reset: no rx symbol"); // rx timeout
return OWB_STATUS_DEVICE_NOT_RESPONDING;
}

// parse the event data and return the result
return _parse_reset_symbols (rx_done_event_data.num_symbols, rx_done_event_data.received_symbols, is_present);
}
Expand Down Expand Up @@ -270,7 +270,7 @@ static owb_status _write_bytes(const OneWireBus *bus, uint8_t *bytes, int number
if (rmt_tx_wait_all_done (info->tx_channel_handle, OWB_RMT_TIMEOUT_MS) != ESP_OK) {
return OWB_STATUS_DEVICE_NOT_RESPONDING; // tx timeout
}
return OWB_STATUS_OK;
return OWB_STATUS_OK;
}


Expand Down Expand Up @@ -301,18 +301,18 @@ static owb_status _write_bits(const OneWireBus *bus, uint8_t out, int number_of_
esp_err_t esp_status;
for (int b = 0; b < number_of_bits_to_write; b += 1) {
if ((out & (1 << b)) == 0) {
symbol_ptr = &owb_rmt_symbol_0bit;
symbol_ptr = &owb_rmt_symbol_0bit;
} else {
symbol_ptr = &owb_rmt_symbol_1bit;
}

// send bit symbol
esp_status = rmt_transmit (
info->tx_channel_handle,
info->copy_encoder_handle,
info->tx_channel_handle,
info->copy_encoder_handle,
symbol_ptr,
sizeof (rmt_symbol_word_t),
&owb_rmt_transmit_config);
&owb_rmt_transmit_config);
if (esp_status != ESP_OK) {
ESP_LOGE(TAG, "owb_write_bit: tx err");
return OWB_STATUS_HW_ERROR;
Expand Down Expand Up @@ -349,9 +349,9 @@ static owb_status _read_bytes(const OneWireBus *bus, uint64_t *result_ptr, int n

// start the receiver before the transmitter so that it sees the first edge
esp_status = rmt_receive (
info->rx_channel_handle,
info->rx_channel_handle,
info->rx_buffer,
info->rx_buffer_size_in_bytes,
info->rx_buffer_size_in_bytes,
&rx_config_owb_bits);
if (esp_status != ESP_OK) {
ESP_LOGE(TAG, "owb_read_bytes: rx err");
Expand All @@ -369,7 +369,7 @@ static owb_status _read_bytes(const OneWireBus *bus, uint64_t *result_ptr, int n
ESP_LOGE(TAG, "owb_read_bytes: tx err");
return OWB_STATUS_HW_ERROR;
}

// wait for the transmission to finish (or timeout with an error)
if (rmt_tx_wait_all_done (info->tx_channel_handle, OWB_RMT_TIMEOUT_MS) != ESP_OK) {
return OWB_STATUS_DEVICE_NOT_RESPONDING; // tx timeout
Expand All @@ -382,7 +382,7 @@ static owb_status _read_bytes(const OneWireBus *bus, uint64_t *result_ptr, int n
return OWB_STATUS_DEVICE_NOT_RESPONDING;
}

// decode upto 64 data bits from the received RMT symbols
// decode upto 64 data bits from the received RMT symbols
if (_parse_bit_symbols(rx_done_event_data.num_symbols, rx_done_event_data.received_symbols, result_ptr) == 0) {
ESP_LOGE(TAG, "owb_read_bytes: no bits");
}
Expand Down Expand Up @@ -412,7 +412,7 @@ static owb_status _read_bits(const OneWireBus *bus, uint8_t *result, int number_
owb_status status;
status = _read_bytes (bus, &result_64, 1);
*result = (uint8_t)result_64;
return status;
return status;
}

// identify the rmt_driver_info structure that contains `bus`
Expand All @@ -427,9 +427,9 @@ static owb_status _read_bits(const OneWireBus *bus, uint8_t *result, int number_

// start the receiver before the transmitter so that it sees the first edge
esp_status = rmt_receive (
info->rx_channel_handle,
info->rx_channel_handle,
info->rx_buffer,
info->rx_buffer_size_in_bytes,
info->rx_buffer_size_in_bytes,
&rx_config_owb_bits);
if (esp_status != ESP_OK) {
ESP_LOGE(TAG, "owb_read_bits: rx err");
Expand All @@ -438,11 +438,11 @@ static owb_status _read_bits(const OneWireBus *bus, uint8_t *result, int number_

// send a '1' symbol to generate a read slot
esp_status = rmt_transmit (
info->tx_channel_handle,
info->copy_encoder_handle,
info->tx_channel_handle,
info->copy_encoder_handle,
&owb_rmt_symbol_1bit,
sizeof (rmt_symbol_word_t),
&owb_rmt_transmit_config);
&owb_rmt_transmit_config);
if (esp_status != ESP_OK) {
ESP_LOGE(TAG, "owb_read_bits: tx err");
return OWB_STATUS_HW_ERROR;
Expand Down Expand Up @@ -473,7 +473,7 @@ static owb_status _read_bits(const OneWireBus *bus, uint8_t *result, int number_
}
}

return OWB_STATUS_OK;
return OWB_STATUS_OK;
}


Expand Down Expand Up @@ -517,25 +517,19 @@ static struct owb_driver rmt_driver_functions = {

// configure and allocate resources
//
OneWireBus* owb_rmt_initialize (owb_rmt_driver_info *info, gpio_num_t gpio_num, int tx_channel, int rx_channel)
OneWireBus* owb_rmt_initialize (owb_rmt_driver_info *info, gpio_num_t gpio_num)
{
//* The function now ignores tx_channel and rx_channel as the new RMT driver allocates channels on demand.
//* The parameters are kept in the call to preserve compatibility with previous versions.

// the steps to enable the RMT resources are documented in:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/rmt.html

// Note: keeping the TX and RX initialisations together in one function simplifies the error handling

(void)tx_channel; // avoid compiler warning about unused parameter
(void)rx_channel; // avoid compiler warning about unused parameter

// sanity check
if (info == NULL) {
ESP_LOGE(TAG, "info is NULL");
goto exit_err;
}
}

// ----- receive channel -----

// channel config
Expand Down

0 comments on commit 52a5906

Please sign in to comment.