Naming and coding style convention, new linter tool. (#945)
* Makefile, Scripts: new linter * About: remove ID from IC * Firmware: remove double define for DIVC/DIVR * Scripts: check folder names too. Docker: replace syntax check with make lint. * Reformat Sources and Migrate to new file naming convention * Docker: symlink clang-format-12 to clang-format * Add coding style guide
This commit is contained in:
@@ -6,12 +6,13 @@
|
||||
#include "irda_i.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static IrdaStatus irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
static IrdaStatus
|
||||
irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
IrdaStatus status = encoder->protocol->encode(encoder, duration, level);
|
||||
furi_assert(status == IrdaStatusOk);
|
||||
++encoder->timings_encoded;
|
||||
encoder->timings_sum += *duration;
|
||||
if ((encoder->bits_encoded == encoder->bits_to_encode) && *level) {
|
||||
if((encoder->bits_encoded == encoder->bits_to_encode) && *level) {
|
||||
status = IrdaStatusDone;
|
||||
}
|
||||
|
||||
@@ -32,23 +33,24 @@ static IrdaStatus irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t*
|
||||
* 0 1 2 | 3 4 |
|
||||
* _____-------_____---___
|
||||
*/
|
||||
IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
IrdaStatus
|
||||
irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
furi_assert(encoder);
|
||||
furi_assert(duration);
|
||||
furi_assert(level);
|
||||
|
||||
const IrdaTimings* timings = &encoder->protocol->timings;
|
||||
uint8_t index = encoder->bits_encoded / 8;
|
||||
uint8_t shift = encoder->bits_encoded % 8; // LSB first
|
||||
uint8_t shift = encoder->bits_encoded % 8; // LSB first
|
||||
bool logic_value = !!(encoder->data[index] & (0x01 << shift));
|
||||
bool even_timing = !(encoder->timings_encoded % 2);
|
||||
|
||||
*level = even_timing ^ logic_value;
|
||||
*duration = timings->bit1_mark;
|
||||
if (even_timing)
|
||||
if(even_timing)
|
||||
++encoder->bits_encoded;
|
||||
else if (*level && (encoder->bits_encoded + 1 == encoder->bits_to_encode))
|
||||
++encoder->bits_encoded; /* don't encode last space */
|
||||
else if(*level && (encoder->bits_encoded + 1 == encoder->bits_to_encode))
|
||||
++encoder->bits_encoded; /* don't encode last space */
|
||||
|
||||
return IrdaStatusOk;
|
||||
}
|
||||
@@ -60,20 +62,18 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio
|
||||
|
||||
const IrdaTimings* timings = &encoder->protocol->timings;
|
||||
uint8_t index = encoder->bits_encoded / 8;
|
||||
uint8_t shift = encoder->bits_encoded % 8; // LSB first
|
||||
uint8_t shift = encoder->bits_encoded % 8; // LSB first
|
||||
bool logic_value = !!(encoder->data[index] & (0x01 << shift));
|
||||
bool pwm = timings->bit1_space == timings->bit0_space;
|
||||
|
||||
if (encoder->timings_encoded % 2) { /* start encoding from space */
|
||||
if(encoder->timings_encoded % 2) { /* start encoding from space */
|
||||
*duration = logic_value ? timings->bit1_mark : timings->bit0_mark;
|
||||
*level = true;
|
||||
if (pwm)
|
||||
++encoder->bits_encoded;
|
||||
if(pwm) ++encoder->bits_encoded;
|
||||
} else {
|
||||
*duration = logic_value ? timings->bit1_space : timings->bit0_space;
|
||||
*level = false;
|
||||
if (!pwm)
|
||||
++encoder->bits_encoded;
|
||||
if(!pwm) ++encoder->bits_encoded;
|
||||
}
|
||||
|
||||
return IrdaStatusOk;
|
||||
@@ -86,7 +86,7 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
|
||||
IrdaStatus status = IrdaStatusOk;
|
||||
const IrdaTimings* timings = &encoder->protocol->timings;
|
||||
|
||||
switch (encoder->state) {
|
||||
switch(encoder->state) {
|
||||
case IrdaCommonEncoderStateSilence:
|
||||
*duration = encoder->protocol->timings.silence_time;
|
||||
*level = false;
|
||||
@@ -96,8 +96,8 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
|
||||
encoder->timings_sum = 0;
|
||||
break;
|
||||
case IrdaCommonEncoderStatePreamble:
|
||||
if (timings->preamble_mark) {
|
||||
if (encoder->timings_encoded == 1) {
|
||||
if(timings->preamble_mark) {
|
||||
if(encoder->timings_encoded == 1) {
|
||||
*duration = timings->preamble_mark;
|
||||
*level = true;
|
||||
} else {
|
||||
@@ -114,8 +114,8 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
|
||||
/* FALLTHROUGH */
|
||||
case IrdaCommonEncoderStateEncode:
|
||||
status = irda_common_encode_bits(encoder, duration, level);
|
||||
if (status == IrdaStatusDone) {
|
||||
if (encoder->protocol->encode_repeat) {
|
||||
if(status == IrdaStatusDone) {
|
||||
if(encoder->protocol->encode_repeat) {
|
||||
encoder->state = IrdaCommonEncoderStateEncodeRepeat;
|
||||
} else {
|
||||
encoder->timings_encoded = 0;
|
||||
@@ -135,18 +135,19 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
|
||||
|
||||
void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol) {
|
||||
furi_assert(protocol);
|
||||
if (protocol->decode == irda_common_decode_pdwm) {
|
||||
furi_assert((protocol->timings.bit1_mark == protocol->timings.bit0_mark) ^ (protocol->timings.bit1_space == protocol->timings.bit0_space));
|
||||
if(protocol->decode == irda_common_decode_pdwm) {
|
||||
furi_assert(
|
||||
(protocol->timings.bit1_mark == protocol->timings.bit0_mark) ^
|
||||
(protocol->timings.bit1_space == protocol->timings.bit0_space));
|
||||
}
|
||||
|
||||
/* protocol->databit_len[0] has to contain biggest value of bits that can be decoded */
|
||||
for (int i = 1; i < COUNT_OF(protocol->databit_len); ++i) {
|
||||
for(int i = 1; i < COUNT_OF(protocol->databit_len); ++i) {
|
||||
furi_assert(protocol->databit_len[i] <= protocol->databit_len[0]);
|
||||
}
|
||||
|
||||
uint32_t alloc_size = sizeof(IrdaCommonDecoder)
|
||||
+ protocol->databit_len[0] / 8
|
||||
+ !!(protocol->databit_len[0] % 8);
|
||||
uint32_t alloc_size = sizeof(IrdaCommonDecoder) + protocol->databit_len[0] / 8 +
|
||||
!!(protocol->databit_len[0] % 8);
|
||||
IrdaCommonEncoder* encoder = furi_alloc(alloc_size);
|
||||
memset(encoder, 0, alloc_size);
|
||||
encoder->protocol = protocol;
|
||||
@@ -169,12 +170,10 @@ void irda_common_encoder_reset(IrdaCommonEncoder* encoder) {
|
||||
|
||||
uint8_t max_databit_len = 0;
|
||||
|
||||
for (int i = 0; i < COUNT_OF(encoder->protocol->databit_len); ++i) {
|
||||
for(int i = 0; i < COUNT_OF(encoder->protocol->databit_len); ++i) {
|
||||
max_databit_len = MAX(max_databit_len, encoder->protocol->databit_len[i]);
|
||||
}
|
||||
|
||||
uint8_t bytes_to_clear = max_databit_len / 8
|
||||
+ !!(max_databit_len % 8);
|
||||
uint8_t bytes_to_clear = max_databit_len / 8 + !!(max_databit_len % 8);
|
||||
memset(encoder->data, 0, bytes_to_clear);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user