The MCP3008 driver.
More...
#include <mcp3008_driver.h>
|
static constexpr int | CHANNELS = 8 |
| Amount of channels on the chip. More...
|
|
static constexpr uint16_t | MAX_VAL = 1023 |
| Maximum value returned by from the chip (10bits). More...
|
|
The MCP3008 driver.
This class is not thread-safe, you have to make sure the methods are called from one thread at a time only. The install() method has to be called before you can use any other methods.
◆ Driver()
mcp3008::Driver::Driver |
( |
| ) |
|
◆ ~Driver()
mcp3008::Driver::~Driver |
( |
| ) |
|
|
virtual |
◆ getChannelsMask()
uint8_t mcp3008::Driver::getChannelsMask |
( |
| ) |
const |
|
inline |
◆ install()
esp_err_t mcp3008::Driver::install |
( |
const Config & |
cfg = Config() | ) |
|
Initialize the SPI bus. Must be called before any other methods, otherwise they will return ESP_FAIL.
- Parameters
-
cfg | the SPI bus configuration. |
- Returns
- ESP_OK or any error code encountered during the inialization. Will return ESP_FAIL if called when already installed.
◆ read() [1/2]
esp_err_t mcp3008::Driver::read |
( |
std::vector< uint16_t > & |
results, |
|
|
bool |
differential = false |
|
) |
| const |
Read values from the chip. Returns values in range <0; Driver::MAX_VAL>.
- Parameters
-
results | the results will be APPENDED to this vector. It will be unchanged unless the ESP_OK result is returned (except possibly its capacity). Between 0 and Driver::CHANNELS values are appended, depending on Config::channels_mask. |
differential | return differential readings, as specified in the MCP3008 datasheet. |
- Returns
- ESP_OK or any error code encountered during reading. Will return ESP_FAIL if called when not installed.
◆ read() [2/2]
esp_err_t mcp3008::Driver::read |
( |
uint16_t * |
dest, |
|
|
bool |
differential = false |
|
) |
| const |
◆ readChannel()
uint16_t mcp3008::Driver::readChannel |
( |
uint8_t |
channel, |
|
|
bool |
differential = false , |
|
|
esp_err_t * |
result = nullptr |
|
) |
| const |
Read a single channel from the chip. Returns value is in range <0; Driver::MAX_VAL>.
- Parameters
-
differential | return differential readings, as specified in the MCP3008 datasheet. |
result | result code will be written here, may be null. |
- Returns
- measured value or 0xFFFF on error.
◆ requestToChannel()
int mcp3008::Driver::requestToChannel |
( |
int |
request | ) |
const |
|
protected |
◆ uninstall()
esp_err_t mcp3008::Driver::uninstall |
( |
| ) |
|
Free the SPI bus. Must be called last, or other methods return ESP_FAIL.
- Returns
- ESP_OK or any error code encountered during the freeing. Will return ESP_FAIL if called when not installed.
◆ CHANNELS
constexpr int mcp3008::Driver::CHANNELS = 8 |
|
staticconstexpr |
Amount of channels on the chip.
◆ MAX_VAL
constexpr uint16_t mcp3008::Driver::MAX_VAL = 1023 |
|
staticconstexpr |
Maximum value returned by from the chip (10bits).
The documentation for this class was generated from the following files: