Skip to content

Commit

Permalink
0.2.rev.A. Update firmware source formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonsmartins committed Jan 8, 2024
1 parent ddf55f5 commit d2b674f
Show file tree
Hide file tree
Showing 60 changed files with 1,346 additions and 1,256 deletions.
10 changes: 10 additions & 0 deletions firmware/usbflashprog/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BasedOnStyle: Google
IndentWidth: 4
UseTab: Never
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: true
SeparateDefinitionBlocks: Leave
IncludeBlocks: Merge
SortIncludes: Never
EmptyLineBeforeAccessModifier: Always
AccessModifierOffset: -2
43 changes: 24 additions & 19 deletions firmware/usbflashprog/circuits/74hc165.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @ingroup Firmware
* @file circuits/74hc165.cpp
* @brief Implementation of the 74HC165 Class.
*
*
* @author Robson Martins (https://www.robsonmartins.com)
*/
// ---------------------------------------------------------------------------
Expand All @@ -19,22 +19,23 @@

// ---------------------------------------------------------------------------

HC165::HC165(): ce_(false) {
HC165::HC165() : ce_(false) {
configure();
}

HC165::HC165(uint plPin, uint clkPin, uint cePin, uint q7Pin,
uint nq7Pin, uint pulseTime): ce_(false) {
HC165::HC165(uint plPin, uint clkPin, uint cePin, uint q7Pin, uint nq7Pin,
uint pulseTime)
: ce_(false) {
configure(plPin, clkPin, cePin, q7Pin, nq7Pin, pulseTime);
}

void HC165::configure(uint plPin, uint clkPin, uint cePin,
uint q7Pin, uint nq7Pin, uint pulseTime) {
plPin_ = plPin;
clkPin_ = clkPin;
cePin_ = cePin;
q7Pin_ = q7Pin;
nq7Pin_ = nq7Pin;
void HC165::configure(uint plPin, uint clkPin, uint cePin, uint q7Pin,
uint nq7Pin, uint pulseTime) {
plPin_ = plPin;
clkPin_ = clkPin;
cePin_ = cePin;
q7Pin_ = q7Pin;
nq7Pin_ = nq7Pin;
pulseTime_ = pulseTime;
}

Expand Down Expand Up @@ -65,8 +66,7 @@ void HC165::load() {
}

bool HC165::getBit(uint index) {
if (clkPin_ == 0xFF ||
(q7Pin_ == 0xFF && nq7Pin_ == 0xFF)) {
if (clkPin_ == 0xFF || (q7Pin_ == 0xFF && nq7Pin_ == 0xFF)) {
return false;
}
for (uint i = 0; i < index; i++) {
Expand Down Expand Up @@ -117,9 +117,10 @@ uint32_t HC165::readDWord(bool reverse) {
}

uint HC165::readData(uint8_t* buffer, uint size, bool reverse) {
if (!buffer || !size) { return 0; }
if (clkPin_ == 0xFF ||
(q7Pin_ == 0xFF && nq7Pin_ == 0xFF)) {
if (!buffer || !size) {
return 0;
}
if (clkPin_ == 0xFF || (q7Pin_ == 0xFF && nq7Pin_ == 0xFF)) {
return 0;
}
TData bits;
Expand All @@ -135,22 +136,26 @@ uint HC165::readData(uint8_t* buffer, uint size, bool reverse) {
sleep_us(pulseTime_);
}
std::size_t start = reverse ? 0 : bits.size() - 1;
std::size_t end = reverse ? bits.size() - 1: 0;
std::size_t end = reverse ? bits.size() - 1 : 0;
std::size_t nbit = start;
for (uint nbyte = 0; nbyte < size; nbyte++) {
buffer[nbyte] = 0;
for (uint b = 0; b < 8; b++) {
if (bits[nbit]) {
buffer[nbyte] |= (1 << b);
}
if (nbit == end) { break; }
if (nbit == end) {
break;
}
if (reverse) {
nbit++;
} else {
nbit--;
}
}
if (nbit == end) { break; }
if (nbit == end) {
break;
}
}
return size;
}
21 changes: 10 additions & 11 deletions firmware/usbflashprog/circuits/74hc165.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// This work is licensed under a Creative Commons Attribution-NonCommercial-
// ShareAlike 4.0 International License.
// ---------------------------------------------------------------------------
/**
/**
* @ingroup Firmware
* @file circuits/74hc165.hpp
* @brief Header of the 74HC165 Class.
*
*
* @author Robson Martins (https://www.robsonmartins.com)
*/
// ---------------------------------------------------------------------------
Expand All @@ -29,12 +29,12 @@
* @ingroup Firmware
* @brief 74xx165 Shift Register Class.
* @details The purpose of this class is to interface a 74xx165
* Shift Register.
* Shift Register.
* Datasheet available on: https://tinyurl.com/bdzmty8v.
* @nosubgrouping
*/
class HC165 {
public:
public:
/** @brief Type of Data buffer. */
typedef std::vector<bool> TData;
/** @brief Default value to pulse time, in microseconds. */
Expand All @@ -56,9 +56,8 @@ class HC165 {
* @param pulseTime Pulse time, in microseconds
* (default = kDefaultPulseTime).
*/
HC165(uint plPin, uint clkPin = 0xFF, uint cePin = 0xFF,
uint q7Pin = 0xFF, uint nq7Pin = 0xFF,
uint pulseTime = kDefaultPulseTime);
HC165(uint plPin, uint clkPin = 0xFF, uint cePin = 0xFF, uint q7Pin = 0xFF,
uint nq7Pin = 0xFF, uint pulseTime = kDefaultPulseTime);
/**
* @brief Configures the HC165 class object.
* @param plPin GPIO Pin number of ~Parallel Load
Expand All @@ -79,14 +78,14 @@ class HC165 {
uint pulseTime = kDefaultPulseTime);
/**
* @brief Changes the Chip Enable pin of the HC165.
* @param value If true, activate CE.
* @param value If true, activate CE.
* Else, disables the chip.
*/
void chipEnable(bool value = true);
/** @brief Disables the chip. */
void chipDisable(void);
/**
* @brief Gets the Chip Enable status.
* @brief Gets the Chip Enable status.
* @return Value of Chip Enable ("software stored").
*/
const bool getCE(void) const;
Expand Down Expand Up @@ -126,7 +125,7 @@ class HC165 {
/**
* @brief Reads data from the arbitrary HC165 units in cascade.
* Shifts data in units if need.
* @param buffer Pointer to buffer to receive data.
* @param buffer Pointer to buffer to receive data.
* First is the LSB byte.
* @param size Size of buffer.
* @param reverse If true, reverses the bit order (Q0 to Q7).
Expand All @@ -135,7 +134,7 @@ class HC165 {
*/
uint readData(uint8_t* buffer, uint size, bool reverse = false);

private:
private:
/* @brief GPIO handler. */
Gpio gpio_;
/* @brief ~CE GPIO pin number. */
Expand Down
55 changes: 33 additions & 22 deletions firmware/usbflashprog/circuits/74hc595.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @ingroup Firmware
* @file circuits/74hc595.cpp
* @brief Implementation of the 74HC595 Class.
*
*
* @author Robson Martins (https://www.robsonmartins.com)
*/
// ---------------------------------------------------------------------------
Expand All @@ -19,22 +19,23 @@

// ---------------------------------------------------------------------------

HC595::HC595(): oe_(false) {
HC595::HC595() : oe_(false) {
configure();
}

HC595::HC595(uint sinPin, uint clkPin, uint clrPin,
uint rckPin, uint oePin, uint pulseTime): oe_(false) {
HC595::HC595(uint sinPin, uint clkPin, uint clrPin, uint rckPin, uint oePin,
uint pulseTime)
: oe_(false) {
configure(sinPin, clkPin, clrPin, rckPin, oePin, pulseTime);
}

void HC595::configure(uint sinPin, uint clkPin, uint clrPin,
uint rckPin, uint oePin, uint pulseTime) {
sinPin_ = sinPin;
clkPin_ = clkPin;
clrPin_ = clrPin;
rckPin_ = rckPin;
oePin_ = oePin;
void HC595::configure(uint sinPin, uint clkPin, uint clrPin, uint rckPin,
uint oePin, uint pulseTime) {
sinPin_ = sinPin;
clkPin_ = clkPin;
clrPin_ = clrPin;
rckPin_ = rckPin;
oePin_ = oePin;
pulseTime_ = pulseTime;
}

Expand Down Expand Up @@ -65,13 +66,17 @@ void HC595::outputDisable() {

void HC595::writeByte(uint8_t value) {
clear();
if (!value) { return; }
if (!value) {
return;
}
writeData(&value, 1);
}

void HC595::writeWord(uint16_t value) {
clear();
if (!value) { return; }
if (!value) {
return;
}
if (value <= 0xFF) {
writeByte(value & 0xFF);
return;
Expand All @@ -84,7 +89,9 @@ void HC595::writeWord(uint16_t value) {

void HC595::writeDWord(uint32_t value) {
clear();
if (!value) { return; }
if (!value) {
return;
}
if (value <= 0xFF) {
writeByte(value & 0xFF);
return;
Expand All @@ -101,12 +108,18 @@ void HC595::writeDWord(uint32_t value) {
}

void HC595::writeData(const uint8_t* buffer, uint size) {
if (!size || !buffer) { return; }
if (buffer_.size() < size) { buffer_.resize(size); }
if (rckPin_ != 0xFF) { gpio_.resetPin(rckPin_); }
if (!size || !buffer) {
return;
}
if (buffer_.size() < size) {
buffer_.resize(size);
}
if (rckPin_ != 0xFF) {
gpio_.resetPin(rckPin_);
}
buffer += size - 1;
for (uint8_t* pData = buffer_.data() + size - 1;
size != 0; size--, pData--, buffer--) {
for (uint8_t* pData = buffer_.data() + size - 1; size != 0;
size--, pData--, buffer--) {
*pData = *buffer;
if (sinPin_ != 0xFF && clkPin_ != 0xFF) {
gpio_.resetPin(clkPin_);
Expand Down Expand Up @@ -164,9 +177,7 @@ const HC595::TData& HC595::getData(void) const {

const bool HC595::getBit(uint bit) const {
uint index = bit / 8;
uint8_t data = (index < buffer_.size())
? buffer_[index]
: 0;
uint8_t data = (index < buffer_.size()) ? buffer_[index] : 0;
uint8_t mask = 0x01 << (bit - (index * 8));
return (data & mask);
}
Expand Down
20 changes: 10 additions & 10 deletions firmware/usbflashprog/circuits/74hc595.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// This work is licensed under a Creative Commons Attribution-NonCommercial-
// ShareAlike 4.0 International License.
// ---------------------------------------------------------------------------
/**
/**
* @ingroup Firmware
* @file circuits/74hc595.hpp
* @brief Header of the 74HC595 Class.
*
*
* @author Robson Martins (https://www.robsonmartins.com)
*/
// ---------------------------------------------------------------------------
Expand All @@ -28,13 +28,13 @@
/**
* @ingroup Firmware
* @brief 74xx595 Shift Register Class.
* @details The purpose of this class is to interface a 74xx595
* Shift Register.
* @details The purpose of this class is to interface a 74xx595
* Shift Register.
* Datasheet available on: https://tinyurl.com/5crbkb52.
* @nosubgrouping
*/
class HC595 {
public:
public:
/** @brief Type of Data buffer. */
typedef std::vector<uint8_t> TData;
/** @brief Default value to pulse time, in microseconds. */
Expand All @@ -48,7 +48,7 @@ class HC595 {
* @param clkPin GPIO Pin number of Data Clock
* (default = 0xFF, no pin).
* @param clrPin GPIO Pin number of ~Clear
* (default = 0xFF, no pin).
* (default = 0xFF, no pin).
* @param rckPin GPIO Pin number of Latch Clock
* (default = 0xFF, no pin).
* @param oePin GPIO Pin number of Output Enable
Expand All @@ -66,7 +66,7 @@ class HC595 {
* @param clkPin GPIO Pin number of Data Clock
* (default = 0xFF, no pin).
* @param clrPin GPIO Pin number of ~Clear
* (default = 0xFF, no pin).
* (default = 0xFF, no pin).
* @param rckPin GPIO Pin number of Latch Clock
* (default = 0xFF, no pin).
* @param oePin GPIO Pin number of Output Enable
Expand All @@ -81,7 +81,7 @@ class HC595 {
void clear();
/**
* @brief Changes the Output Enable pin of the HC595.
* @param value If true, activate OE.
* @param value If true, activate OE.
* Else, disables the output (put its in tristate).
*/
void outputEnable(bool value = true);
Expand Down Expand Up @@ -139,12 +139,12 @@ class HC595 {
*/
const bool getBit(uint bit) const;
/**
* @brief Gets the Output Enable status.
* @brief Gets the Output Enable status.
* @return Value of Output Enable ("software stored").
*/
const bool getOE(void) const;

private:
private:
/* @brief Pulse time, in microseconds. */
uint pulseTime_;
/* @brief ~OE GPIO pin number. */
Expand Down
Loading

0 comments on commit d2b674f

Please sign in to comment.