27#include "../types_traits.h"
28#include "../utilities.h"
66 template<board::DigitalPin CS,
typename CHANNEL_, u
int16_t MASK, u
int8_t RSHIFT,
typename TYPE_ = u
int16_t>
68 CS, spi::ChipSelect::ACTIVE_LOW, spi::compute_clockrate(3'600'000UL),
69 spi::Mode::MODE_0, spi::DataOrder::MSB_FIRST>
74 static constexpr const uint16_t SIGN_MASK = ((MASK >> RSHIFT) + 1) >> 1;
75 static constexpr const uint16_t NEGATIVE = 0xFFFF & ~(MASK >> RSHIFT);
107 if (
sizeof(
CHANNEL) ==
sizeof(uint16_t))
113 result1 = this->
transfer(uint8_t(channel));
120 if (value & SIGN_MASK)
122 return TYPE(NEGATIVE | value);
Generic class to support (almost) any chip of the SPI-based MicroChip ADC chips family (MCP3001-2-4-8...
TYPE_ TYPE
The analog output type for this device, either uint16_t or int16_t.
CHANNEL_ CHANNEL
The enum class type defining all possible analog input channels handled by the device.
TYPE read_channel(CHANNEL channel)
Read an analog channel from this device.
MCP3x0x()=default
Create a new device driver for an MCP chip.
uint8_t transfer(uint8_t data)
Transfer one byte to the currently selected SPI slave device through MOSI pin, and get the byte retur...
Base class for any SPI slave device.
void start_transfer()
Start an SPI transfer to this device.
void end_transfer() INLINE
End the current SPI ransfer tot hsi device.
Defines the API for MicroChip ADC chips family support.
Defines all API for all external devices supported by FastArduino.
constexpr uint8_t high_byte(uint16_t word)
Extract the high order byte of a 16-bits word.
constexpr uint16_t as_uint16_t(uint8_t high, uint8_t low)
Convert 2 bytes into an unsigned int.
constexpr uint8_t low_byte(uint16_t word)
Extract the low order byte of a 16-bits word.
This trait allows static checks (at compile-time) of properties of various types.
static constexpr bool IS_INT
Indicates if T is an integer type.
static constexpr bool IS_SIGNED
Indicates if T is a signed integer type.
static constexpr size_t SIZE
Indicates the size in bytes of T.