Program Listing for File mcp3008.cpp

Return to documentation for file (src/mcp3008.cpp)

#include "mcp3008/mcp3008.hh"

using iplo::MCP3008;

std::uint8_t MCP3008::buildRequest(std::uint8_t channel, bool single, std::uint8_t* data) {
    data[0] = 0x01;  // start bit

    if (single) {
        data[1] = 0x80;  // single read | differential
    }

    if (channel) {
        data[1] |= (channel << 4);  // channel
    }

    return 3;
}

MCP3008::MCP3008(SPI& spi) : MCP3X0X(spi) {
    _channels = 8;
    _maxValue = 1023;
}