C++ functions

By default, the number stored in a register is assumed to be of type uint32_t.

Write a single register

// Write number 42 into the `led` register of config
ctl.write<reg::led>(42);

// Write a 16 bit signed
ctl.write<reg::led, int16_t>(-42);

// Write a register (offset known at runtime)
ctl.write_reg(offset, 42);

Read a single register

// By default a uint32_t is read
uint32_t value = ctl.read<reg::led>();

// Read a single byte
uint8_t value = ctl.read<reg::led, uint8_t>();

// Read a register (offset known at runtime)
uint32_t value = ctl.read_reg(offset);

Write consecutive registers

std::array<uint32_t, 3> arr = {6, 7, 42};

// Write 3 consecutive registers starting from 'led'
ctl.write_array<uint32_t, 3, reg::led>(arr);

// Write registers (offset known at runtime)
ctl.write_reg_array(offset, arr);

Read consecutive registers

std::array<uint32_t, 3>& arr
    = ctl.read_array<uint32_t, 3, reg::led>();

// Read floating point values in a data buffer from offset 0
std::array<float, 2048>& values
    = data.read_array<float, 2048, 0>();

// Read 3 consecutive registers (offset known at runtime)
std::array<uint32_t, 3>& arr
    = ctl.read_reg_array<uint32_t, 3>(offset);

Turn ON a bit

// Turn on the 5th bit of the 'led' register
ctl.set_bit<reg::led, 5>();

// Offset known at runtime
ctl.set_bit_reg(offset, 5);

Turn OFF a bit

// Turn off the 5th bit of the 'led' register
ctl.clear_bit<reg::led, 5>();

// Offset known at runtime
ctl.clear_bit_reg(offset, 5);

Toggle a bit

// Invert state of the 5th bit of the 'led' register
ctl.toggle_bit<reg::led, 5>();

Write a bit value

// Write a 1 on the 10th bit of the 'led' register
ctl.write_bit<reg::led, 10>(1);

// Offset known at runtime
ctl.write_bit_reg(offset, 10, 1);

Read a bit value

// Read the 10th bit of the 'led' register
bool value = ctl.read_bit<reg::led, 10>();

// Offset known at runtime
bool value = ctl.read_bit_reg(offset, 10);

See also

[email protected]