36 #include "freertos/FreeRTOS.h" |
36 #include "freertos/FreeRTOS.h" |
37 #include "freertos/task.h" |
37 #include "freertos/task.h" |
38 #include "esp_log.h" |
38 #include "esp_log.h" |
39 #include "sdkconfig.h" |
39 #include "sdkconfig.h" |
40 #include "driver/gpio.h" |
40 #include "driver/gpio.h" |
|
41 #include "rom/ets_sys.h" // for ets_delay_us() |
|
42 #include "rom/gpio.h" // for gpio_pad_select_gpio() |
41 |
43 |
42 #include "owb.h" |
44 #include "owb.h" |
43 #include "owb_gpio.h" |
45 #include "owb_gpio.h" |
44 |
46 |
45 static const char * TAG = "owb_gpio"; |
47 static const char * TAG = "owb_gpio"; |
61 /// @cond ignore |
63 /// @cond ignore |
62 struct _OneWireBus_Timing |
64 struct _OneWireBus_Timing |
63 { |
65 { |
64 uint32_t A, B, C, D, E, F, G, H, I, J; |
66 uint32_t A, B, C, D, E, F, G, H, I, J; |
65 }; |
67 }; |
66 //// @endcond |
68 /// @endcond |
67 |
69 |
68 // 1-Wire timing delays (standard) in microseconds. |
70 // 1-Wire timing delays (standard) in microseconds. |
69 // Labels and values are from https://www.maximintegrated.com/en/app-notes/index.mvp/id/126 |
71 // Labels and values are from https://www.maximintegrated.com/en/app-notes/index.mvp/id/126 |
70 static const struct _OneWireBus_Timing _StandardTiming = { |
72 static const struct _OneWireBus_Timing _StandardTiming = { |
71 6, // A - read/write "1" master pull DQ low duration |
73 6, // A - read/write "1" master pull DQ low duration |
83 static void _us_delay(uint32_t time_us) |
85 static void _us_delay(uint32_t time_us) |
84 { |
86 { |
85 ets_delay_us(time_us); |
87 ets_delay_us(time_us); |
86 } |
88 } |
87 |
89 |
|
90 /// @cond ignore |
88 #define info_from_bus(owb) container_of(owb, owb_gpio_driver_info, bus) |
91 #define info_from_bus(owb) container_of(owb, owb_gpio_driver_info, bus) |
|
92 /// @endcond |
89 |
93 |
90 /** |
94 /** |
91 * @brief Generate a 1-Wire reset (initialization). |
95 * @brief Generate a 1-Wire reset (initialization). |
92 * @param[in] bus Initialised bus instance. |
96 * @param[in] bus Initialised bus instance. |
93 * @param[out] is_present true if device is present, otherwise false. |
97 * @param[out] is_present true if device is present, otherwise false. |
257 .reset = _reset, |
261 .reset = _reset, |
258 .write_bits = _write_bits, |
262 .write_bits = _write_bits, |
259 .read_bits = _read_bits |
263 .read_bits = _read_bits |
260 }; |
264 }; |
261 |
265 |
262 OneWireBus* owb_gpio_initialize(owb_gpio_driver_info *driver_info, int gpio) |
266 OneWireBus* owb_gpio_initialize(owb_gpio_driver_info * driver_info, int gpio) |
263 { |
267 { |
264 ESP_LOGI(TAG, "%s(): gpio %d\n", __func__, gpio); |
268 ESP_LOGD(TAG, "%s(): gpio %d\n", __func__, gpio); |
265 |
269 |
266 driver_info->gpio = gpio; |
270 driver_info->gpio = gpio; |
267 driver_info->bus.driver = &gpio_function_table; |
271 driver_info->bus.driver = &gpio_function_table; |
268 driver_info->bus.timing = &_StandardTiming; |
272 driver_info->bus.timing = &_StandardTiming; |
|
273 driver_info->bus.strong_pullup_gpio = GPIO_NUM_NC; |
269 |
274 |
270 // platform specific: |
275 // platform specific: |
271 gpio_pad_select_gpio(driver_info->gpio); |
276 gpio_pad_select_gpio(driver_info->gpio); |
272 |
277 |
273 #ifdef PHY_DEBUG |
278 #ifdef PHY_DEBUG |