ESPHome  2024.12.2
adc128s102.cpp
Go to the documentation of this file.
1 #include "adc128s102.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace adc128s102 {
6 
7 static const char *const TAG = "adc128s102";
8 
10 
12  ESP_LOGCONFIG(TAG, "Setting up adc128s102");
13  this->spi_setup();
14 }
15 
17  ESP_LOGCONFIG(TAG, "ADC128S102:");
18  LOG_PIN(" CS Pin:", this->cs_);
19 }
20 
21 uint16_t ADC128S102::read_data(uint8_t channel) {
22  uint8_t control = channel << 3;
23 
24  this->enable();
25  uint8_t adc_primary_byte = this->transfer_byte(control);
26  uint8_t adc_secondary_byte = this->transfer_byte(0x00);
27  this->disable();
28 
29  uint16_t digital_value = adc_primary_byte << 8 | adc_secondary_byte;
30 
31  return digital_value;
32 }
33 
34 } // namespace adc128s102
35 } // namespace esphome
GPIOPin * cs_
Definition: spi.h:378
float get_setup_priority() const override
Definition: adc128s102.cpp:9
uint16_t read_data(uint8_t channel)
Definition: adc128s102.cpp:21
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7