Skip to content

Commit

Permalink
Change formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
luqasz committed Oct 13, 2023
1 parent 7a95de3 commit e8fe9c1
Show file tree
Hide file tree
Showing 49 changed files with 931 additions and 930 deletions.
5 changes: 3 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ UseTab: Never
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
IncludeBlocks: Regroup
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
IndentPPDirectives: AfterHash
BreakConstructorInitializers: AfterColon
Expand All @@ -34,3 +34,4 @@ NamespaceIndentation: All
BreakBeforeConceptDeclarations: Always
RequiresClausePosition: OwnLine
IndentRequiresClause: false
BreakBeforeInlineASMColon: Never
16 changes: 8 additions & 8 deletions include/adc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ namespace adc {
enum class Setting {
// When Auto Triggering is used, the prescaler is reset when the trigger event occurs.
AutoTrigger = SFR::ADCSRA::ADATE,
Irq = SFR::ADCSRA::ADIE,
Irq = SFR::ADCSRA::ADIE,
Trigger_Irq = AutoTrigger | Irq,
};

enum class Clock {
Stopped = 0,
ClockDiv_2 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0,
ClockDiv_4 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS1,
ClockDiv_8 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0 | SFR::ADCSRA::ADPS1,
ClockDiv_16 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS2,
ClockDiv_32 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0 | SFR::ADCSRA::ADPS2,
ClockDiv_64 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS1 | SFR::ADCSRA::ADPS2,
Stopped = 0,
ClockDiv_2 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0,
ClockDiv_4 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS1,
ClockDiv_8 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0 | SFR::ADCSRA::ADPS1,
ClockDiv_16 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS2,
ClockDiv_32 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0 | SFR::ADCSRA::ADPS2,
ClockDiv_64 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS1 | SFR::ADCSRA::ADPS2,
ClockDiv_128 = SFR::ADCSRA::ADEN | SFR::ADCSRA::ADPS0 | SFR::ADCSRA::ADPS1 | SFR::ADCSRA::ADPS2,
};

Expand Down
32 changes: 16 additions & 16 deletions include/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace buffer {

template <typename T>
struct Span {
T * ptr;
T * ptr;
usize length;
using ContainedType = T;

Expand Down Expand Up @@ -258,9 +258,9 @@ namespace buffer {
using ContainedType = CT;

ContainedType * data_ptr;
const usize capacity;
usize head;
usize tail;
const usize capacity;
usize head;
usize tail;

CircPeek() = delete;

Expand Down Expand Up @@ -359,15 +359,15 @@ namespace buffer {
requires(BUFFER_SIZE > 1)
struct Circular {
using ContainedType = CT;
using IndexType = usize;
using IndexType = usize;
// clangd doesn't like below assertions inside requires()
static_assert(is_power_of_two(BUFFER_SIZE), "Buffer size must be power of 2.");
static_assert(BUFFER_SIZE <= usize((limits<IndexType>::max / 2) + 1), "Buffer size must be at max half of given index type.");

IndexType head = 0;
IndexType tail = 0;
IndexType head = 0;
IndexType tail = 0;
constexpr static IndexType mask = BUFFER_SIZE - 1;
ContainedType data[BUFFER_SIZE];
ContainedType data[BUFFER_SIZE];

constexpr CircPeek<ContainedType>
peek()
Expand Down Expand Up @@ -411,8 +411,8 @@ namespace buffer {
constexpr usize
copy(const Span<T> src, Span<U> dst)
{
usize copied = 0;
const usize limit = min(src.len(), dst.len());
usize copied = 0;
const usize limit = min(src.len(), dst.len());
while (copied < limit) {
dst[copied] = src[copied];
copied++;
Expand All @@ -425,8 +425,8 @@ namespace buffer {
constexpr usize
copy(const Span<T> src, W & dst)
{
usize copied = 0;
const usize limit = min(dst.free(), src.len());
usize copied = 0;
const usize limit = min(dst.free(), src.len());
while (copied < limit) {
dst.write(src[copied]);
copied++;
Expand All @@ -439,8 +439,8 @@ namespace buffer {
constexpr usize
copy(R & src, Span<T> dst)
{
usize copied = 0;
const usize limit = min(src.len(), dst.len());
usize copied = 0;
const usize limit = min(src.len(), dst.len());
while (copied < limit) {
dst[copied] = src.read();
copied++;
Expand All @@ -453,8 +453,8 @@ namespace buffer {
constexpr usize
copy(R & src, W & dst)
{
usize copied = 0;
const usize limit = min(src.len(), dst.free());
usize copied = 0;
const usize limit = min(src.len(), dst.free());
while (copied < limit) {
dst.write(src.read());
copied++;
Expand Down
6 changes: 3 additions & 3 deletions include/byte_order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "buffer.hpp"

enum class endian : usize {
little = __ORDER_LITTLE_ENDIAN__,
big = __ORDER_BIG_ENDIAN__,
native = __BYTE_ORDER__,
little = __ORDER_LITTLE_ENDIAN__,
big = __ORDER_BIG_ENDIAN__,
native = __BYTE_ORDER__,
network = __ORDER_BIG_ENDIAN__,
};

Expand Down
12 changes: 6 additions & 6 deletions include/cobs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ namespace cobs {
constexpr usize
encode(const buffer::Span<const u8> in, DST & out)
{
const u8 * current = in.begin();
const u8 * current = in.begin();
const usize free_start = out.free();
while (current < in.end()) {
const u8 * end = cobs_end(current, in.end());
const u8 len = u8(end - current);
const u8 len = u8(end - current);
out.write(len + 1);
while (current < end) {
out.write(*current++);
Expand All @@ -53,11 +53,11 @@ namespace cobs {
encode(const buffer::Span<const u8> in, buffer::Span<u8> out)
{
const u8 * current = in.begin();
usize wrote = 0;
usize wrote = 0;
while (current < in.end()) {
const u8 * end = cobs_end(current, in.end());
const u8 len = u8(end - current);
out[wrote++] = len + 1;
const u8 len = u8(end - current);
out[wrote++] = len + 1;
while (current < end) {
out[wrote++] = *current++;
}
Expand All @@ -73,7 +73,7 @@ namespace cobs {
decode(const buffer::Span<const u8> in, buffer::Span<u8> out)
{
// Out span index.
usize dst = 0;
usize dst = 0;
usize in_pos = 0;
while (in_pos < in.size()) {
// Number of bytes to copy.
Expand Down
26 changes: 13 additions & 13 deletions include/drivers/ds1337.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ namespace ds1337 {
Control, //
Status, //
};
using DateTime_Array = buffer::Array<u8, usize(u8(Register::Year) + 1)>;
using Registers_Array = buffer::Array<u8, usize(u8(Register::Status) + 1)>;
using DateTime_Array = buffer::Array<u8, usize(u8(Register::Year) + 1)>;
using Registers_Array = buffer::Array<u8, usize(u8(Register::Status) + 1)>;
constexpr inline static u8 I2C_ADDRESS = 0x68;
constexpr inline static u8 MONTH_MASK = 0x1F; // Ignore century bit.
constexpr inline static u8 HOUR_MASK = 0x1F; // Ignore AM/PM bits.
constexpr inline static u8 MONTH_MASK = 0x1F; // Ignore century bit.
constexpr inline static u8 HOUR_MASK = 0x1F; // Ignore AM/PM bits.

constexpr void
get(DateTime & dt, const buffer::Span<u8> slice)
{
dt.second = encoder::bcd_to_dec(slice[u8(Register::Seconds)]);
dt.minute = encoder::bcd_to_dec(slice[u8(Register::Minutes)]);
dt.hour = encoder::bcd_to_dec(slice[u8(Register::Hours)] & HOUR_MASK);
dt.day = encoder::bcd_to_dec(slice[u8(Register::MonthDay)]);
dt.month = encoder::bcd_to_dec(slice[u8(Register::Month)] & MONTH_MASK);
dt.year = encoder::bcd_to_dec(slice[u8(Register::Year)]) + YEAR_START;
dt.hour = encoder::bcd_to_dec(slice[u8(Register::Hours)] & HOUR_MASK);
dt.day = encoder::bcd_to_dec(slice[u8(Register::MonthDay)]);
dt.month = encoder::bcd_to_dec(slice[u8(Register::Month)] & MONTH_MASK);
dt.year = encoder::bcd_to_dec(slice[u8(Register::Year)]) + YEAR_START;
}

constexpr void
set(const DateTime & dt, buffer::Span<u8> slice)
{
slice[u8(Register::Seconds)] = encoder::dec_to_bcd(dt.second);
slice[u8(Register::Minutes)] = encoder::dec_to_bcd(dt.minute);
slice[u8(Register::Hours)] = encoder::dec_to_bcd(dt.hour) & HOUR_MASK;
slice[u8(Register::Seconds)] = encoder::dec_to_bcd(dt.second);
slice[u8(Register::Minutes)] = encoder::dec_to_bcd(dt.minute);
slice[u8(Register::Hours)] = encoder::dec_to_bcd(dt.hour) & HOUR_MASK;
slice[u8(Register::MonthDay)] = encoder::dec_to_bcd(dt.day);
slice[u8(Register::Month)] = encoder::dec_to_bcd(dt.month) & MONTH_MASK;
slice[u8(Register::Year)] = encoder::dec_to_bcd(u8(dt.year - YEAR_START));
slice[u8(Register::Month)] = encoder::dec_to_bcd(dt.month) & MONTH_MASK;
slice[u8(Register::Year)] = encoder::dec_to_bcd(u8(dt.year - YEAR_START));
}

}
54 changes: 27 additions & 27 deletions include/drivers/hd44780.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
namespace HD44780 {

// DB7 high and DB0..DB6 low, represents busy flag.
constexpr u8 BUSY_FLAG = 0x80;
constexpr u8 LINE_1_ADDRESS = 0x00;
constexpr u8 LINE_2_ADDRESS = 0x40;
constexpr u8 LINE_3_ADDRESS = 0x14;
constexpr u8 LINE_4_ADDRESS = 0x54;
constexpr u8 SET_CGRAM_ADDRESS = 0x40;
constexpr u8 SET_DDRAM_ADDRESS = 0x80;
constexpr u8 ENTRY_MODE = 0x04;
constexpr u8 DISPLAY_CONTROLL = 0x08;
constexpr u8 FUNCTION_SET = 0x20;
constexpr u8 BUSY_FLAG = 0x80;
constexpr u8 LINE_1_ADDRESS = 0x00;
constexpr u8 LINE_2_ADDRESS = 0x40;
constexpr u8 LINE_3_ADDRESS = 0x14;
constexpr u8 LINE_4_ADDRESS = 0x54;
constexpr u8 SET_CGRAM_ADDRESS = 0x40;
constexpr u8 SET_DDRAM_ADDRESS = 0x80;
constexpr u8 ENTRY_MODE = 0x04;
constexpr u8 DISPLAY_CONTROLL = 0x08;
constexpr u8 FUNCTION_SET = 0x20;
constexpr u8 ENTRY_CURSOR_RIGHT = ENTRY_MODE | 0x02;
constexpr u8 ENTRY_CURSOR_LEFT = ENTRY_MODE | 0x00;
constexpr u8 DisplayOn = DISPLAY_CONTROLL | 0x04;
constexpr u8 DisplayOff = DISPLAY_CONTROLL | 0x00;
constexpr u8 DisplayCursor = DISPLAY_CONTROLL | 0x02;
constexpr u8 HideCursor = DISPLAY_CONTROLL;
constexpr u8 CursorBlink = DISPLAY_CONTROLL | 0x01;
constexpr u8 Mode_8Bit = FUNCTION_SET | 0x10;
constexpr u8 Mode_4Bit = FUNCTION_SET | 0x00;
constexpr u8 Lines_2 = FUNCTION_SET | 0x08;
constexpr u8 Lines_1 = FUNCTION_SET | 0x00;
constexpr u8 Dots_5x10 = FUNCTION_SET | 0x04;
constexpr u8 Dots_5x8 = FUNCTION_SET | 0x00;
constexpr u8 ENTRY_CURSOR_LEFT = ENTRY_MODE | 0x00;
constexpr u8 DisplayOn = DISPLAY_CONTROLL | 0x04;
constexpr u8 DisplayOff = DISPLAY_CONTROLL | 0x00;
constexpr u8 DisplayCursor = DISPLAY_CONTROLL | 0x02;
constexpr u8 HideCursor = DISPLAY_CONTROLL;
constexpr u8 CursorBlink = DISPLAY_CONTROLL | 0x01;
constexpr u8 Mode_8Bit = FUNCTION_SET | 0x10;
constexpr u8 Mode_4Bit = FUNCTION_SET | 0x00;
constexpr u8 Lines_2 = FUNCTION_SET | 0x08;
constexpr u8 Lines_1 = FUNCTION_SET | 0x00;
constexpr u8 Dots_5x10 = FUNCTION_SET | 0x04;
constexpr u8 Dots_5x8 = FUNCTION_SET | 0x00;

enum Cmd {
ClearScreen = 0x01,
CursorHome = 0x02,
CursorHome = 0x02,
};

/*
Expand All @@ -48,16 +48,16 @@ namespace HD44780 {

class LCD {
const gpio::Bus8Bit & bus;
const gpio::Output & rs;
const gpio::Output & rw;
const gpio::Output & e;
const gpio::Output & rs;
const gpio::Output & rw;
const gpio::Output & e;
/*
RS is a Register select pin.
Low for command,
High for data,
*/
auto static constexpr COMMAND = gpio::Low;
auto static constexpr DATA = gpio::High;
auto static constexpr DATA = gpio::High;

void
busy_wait() const
Expand Down
16 changes: 8 additions & 8 deletions include/drivers/mcp4xxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
namespace mcp4xxx {

enum Channel : u16 {
A = 0,
B = 0x8080,
A = 0,
B = 0x8080,
Single = 0, // DACs with single output.
};

// VREF Input buffer control.
enum BufferCtrl : u16 {
Buffered = 0x4000,
Buffered = 0x4000,
Unbuffered = 0,
None = 0, // DACs without any buffer control.
None = 0, // DACs without any buffer control.
};

enum Gain : u16 {
Expand All @@ -25,14 +25,14 @@ namespace mcp4xxx {

enum State : u16 {
Off = 0,
On = 0x1000,
On = 0x1000,
};

struct CtrllBits {
Channel ch;
Channel ch;
BufferCtrl buf;
Gain gain;
State state;
Gain gain;
State state;

constexpr explicit
operator u16() const
Expand Down
8 changes: 4 additions & 4 deletions include/fmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace fmt {
struct LineEnd {
constexpr static char CRLF[] = "\r\n";
constexpr static char LF[] = "\n";
constexpr static char CR[] = "\r";
constexpr static char LF[] = "\n";
constexpr static char CR[] = "\r";
constexpr static char None[] = "";
};

Expand All @@ -29,8 +29,8 @@ namespace fmt {
str(buffer::Span<char> buf, u32 num)
{
constexpr char map[] = "0123456789";
usize idx = numlen10(num);
buf[idx--] = '\0';
usize idx = numlen10(num);
buf[idx--] = '\0';
do {
buf[idx--] = map[num % 10];
num /= 10;
Expand Down
6 changes: 3 additions & 3 deletions include/i2c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace i2c {
For reading from device, address will be converted into 0x91 10010001 (last bit 1 means reading)
TODO Fix this description ^ 7th bit is from left, not right.
*/
const u8 address;
const u8 start_address;
const u8 address;
const u8 start_address;
const units::Frequency speed;
};

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace i2c {
read(buffer::Span<u8> buffer, const i2c::Target target) const
{
usize elems = buffer.size();
auto elem = buffer.begin();
auto elem = buffer.begin();
set_speed(target.speed);
start_signal();
write_blocking(static_cast<u8>(target.address << 1));
Expand Down
Loading

0 comments on commit e8fe9c1

Please sign in to comment.