ESPHome
2025.9.0-dev
Loading...
Searching...
No Matches
esphome
components
mcp3008
mcp3008.cpp
Go to the documentation of this file.
1
#include "
mcp3008.h
"
2
3
#include "
esphome/core/helpers.h
"
4
#include "
esphome/core/log.h
"
5
6
namespace
esphome
{
7
namespace
mcp3008 {
8
9
static
const
char
*
const
TAG =
"mcp3008"
;
10
11
float
MCP3008::get_setup_priority
()
const
{
return
setup_priority::HARDWARE
; }
12
13
void
MCP3008::setup
() { this->
spi_setup
(); }
14
15
void
MCP3008::dump_config
() {
16
ESP_LOGCONFIG(TAG,
"MCP3008:"
);
17
LOG_PIN(
" CS Pin:"
, this->
cs_
);
18
}
19
20
float
MCP3008::read_data
(uint8_t pin) {
21
uint8_t data_msb, data_lsb = 0;
22
23
uint8_t command = ((0x01 << 7) |
// start bit
24
((pin & 0x07) << 4));
// channel number
25
26
this->
enable
();
27
this->
transfer_byte
(0x01);
28
29
data_msb = this->
transfer_byte
(command) & 0x03;
30
data_lsb = this->
transfer_byte
(0x00);
31
32
this->
disable
();
33
34
uint16_t data =
encode_uint16
(data_msb, data_lsb);
35
36
return
data / 1023.0f;
37
}
38
39
}
// namespace mcp3008
40
}
// namespace esphome
esphome::mcp3008::MCP3008::read_data
float read_data(uint8_t pin)
Definition
mcp3008.cpp:20
esphome::mcp3008::MCP3008::setup
void setup() override
Definition
mcp3008.cpp:13
esphome::mcp3008::MCP3008::dump_config
void dump_config() override
Definition
mcp3008.cpp:15
esphome::mcp3008::MCP3008::get_setup_priority
float get_setup_priority() const override
Definition
mcp3008.cpp:11
esphome::spi::SPIClient::cs_
GPIOPin * cs_
Definition
spi.h:412
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_75KHZ >::enable
void enable()
Definition
spi.h:499
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_75KHZ >::spi_setup
void spi_setup() override
Definition
spi.h:436
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_75KHZ >::disable
void disable()
Definition
spi.h:501
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_75KHZ >::transfer_byte
uint8_t transfer_byte(uint8_t data)
Definition
spi.h:485
helpers.h
log.h
mcp3008.h
esphome::setup_priority::HARDWARE
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition
component.cpp:49
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::encode_uint16
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition
helpers.h:173
Generated by
1.12.0