|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The knob's I2C bus, its sensor's registration and the task that polls it. More...
#include "knob_task.h"#include <stdatomic.h>#include <stddef.h>#include "board_pins.h"#include "driver/i2c_master.h"#include "esp_log.h"#include "freertos/FreeRTOS.h"#include "freertos/task.h"#include "knob.h"Macros | |
| #define | KNOB_I2C_TIMEOUT_MS 5 |
| The longest one transaction waits, in milliseconds. | |
Functions | |
| static bool | knob_read (uint8_t reg, uint8_t *byte) |
| static void | knob_task (void *arg) |
| The polling task: one poll every KNOB_POLL_MS while the sensor answers, every KNOB_POLL_IDLE_MS while it does not or the setting is off. | |
| void | knob_task_attach (void) |
| Set up the knob's bus and register the sensor on it. | |
| void | knob_task_start (void) |
| void | knob_task_set_enabled (bool on) |
| int | knob_task_take (void) |
Variables | |
| static const char * | TAG = "knob" |
| static atomic_bool | s_on |
| static atomic_int | s_steps |
| static i2c_master_bus_handle_t | s_bus |
| The knob's own bus; NULL when it did not come up. | |
| static i2c_master_dev_handle_t | s_dev |
| static knob_t | s_knob |
The knob's I2C bus, its sensor's registration and the task that polls it.
SPDX-License-Identifier: MIT
| #define KNOB_I2C_TIMEOUT_MS 5 |
The longest one transaction waits, in milliseconds.
The bus is the knob's alone, so a transaction waits for nothing else. The three transactions of one poll take about 0.3ms at 400kHz. A failed one costs more: the driver resets the controller and clears the bus, which waits up to 50ms (I2C_CLR_BUS_TIMEOUT_MS) while SDA is held low.
|
static |
The polling task: one poll every KNOB_POLL_MS while the sensor answers, every KNOB_POLL_IDLE_MS while it does not or the setting is off.
Logs one line when the sensor first answers and one when it stops answering after that: a change, not a poll.
| arg | Unused. |
| void knob_task_attach | ( | void | ) |
Set up the knob's bus and register the sensor on it.
Call once, before knob_task_start(). Sends nothing. A bus or a device that does not come up is logged; the task then reads nothing.
| void knob_task_set_enabled | ( | bool | on | ) |
Poll the sensor (true) or leave the bus alone (false).
| void knob_task_start | ( | void | ) |
Create the task. Call once, after knob_task_attach().
| int knob_task_take | ( | void | ) |
The steps turned since the last call, signed; clears the count.