Program Listing for File mcp3002.cpp

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

#include "mcp3002/mcp3002.hh"

using iplo::MCP3002;

std::uint8_t MCP3002::buildRequest(std::uint8_t channel, bool single, std::uint8_t* data) {
    data[0] = 0x44;  // start bit + MSB first bit

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

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

    return 2;
}

MCP3002::MCP3002(SPI& spi) : MCP3X0X(spi) {
    _channels = 2;
    _maxValue = 1023;
}