Program Listing for File mcp3208.cpp
↰ Return to documentation for file (src/mcp3208.cpp
)
#include "mcp3208/mcp3208.hh"
using iplo::MCP3208;
uint8_t MCP3208::buildRequest(std::uint8_t channel, bool single, std::uint8_t* data) {
data[0] = 0x04; // start bit
if (single) {
data[0] |= 0x02; // single read | differential
}
if (channel > 3) {
data[0] |= 0x01; // msb channel (D2)
}
if (channel) {
data[1] |= (channel << 6); // other 2 bits (D1 D0)
}
return 3;
}
MCP3208::MCP3208(SPI& spi) : MCP3X0X(spi) {
_channels = 8;
_maxValue = 4095;
}