Skip to content

Commit

Permalink
Refactor functions to use const pointers
Browse files Browse the repository at this point in the history
Refactored multiple functions across various files
to use `const` pointers for parameters, enhancing
code safety and readability. Made minor formatting
changes for consistency and improved readability,
particularly in `sha204_library.cpp`.
  • Loading branch information
virtual-maker committed Dec 31, 2024
1 parent 65f62da commit 0a703d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/AirQualitySensor/AirQualitySensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Remarks: By using the slope and a point of the line. The x(logarithmic value of
logarithmic coordinate, power of 10 is used to convert the result to non-logarithmic
value.
************************************************************************************/
int MQGetPercentage(float rs_ro_ratio, float *pcurve)
int MQGetPercentage(float rs_ro_ratio, const float *pcurve)
{
return (pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0])));
}
11 changes: 6 additions & 5 deletions examples/SecurityPersonalizer/sha204_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ uint8_t atsha204Class::getSerialNumber(uint8_t * response)

/* Calculates CRC16 value of provided data (and optionally including provided existing CRC16 data)
returns the calculated CRC16 value */
uint16_t atsha204Class::calculateAndUpdateCrc(uint8_t length, uint8_t *data, uint16_t current_crc)
uint16_t atsha204Class::calculateAndUpdateCrc(uint8_t length, const uint8_t *data,
uint16_t current_crc)
{
uint8_t counter;
uint16_t crc_register = current_crc;
Expand Down Expand Up @@ -96,7 +97,7 @@ void atsha204Class::swi_set_signal_pin(uint8_t is_high)

}

uint8_t atsha204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
uint8_t atsha204Class::swi_send_bytes(uint8_t count, const uint8_t *buffer)
{
uint8_t i, bit_mask;

Expand Down Expand Up @@ -707,9 +708,9 @@ uint8_t atsha204Class::sha204m_execute(uint8_t op_code, uint8_t param1, uint16_t
}

uint8_t atsha204Class::sha204m_check_parameters(uint8_t op_code, uint8_t param1, uint16_t param2,
uint8_t datalen1, uint8_t *data1, uint8_t datalen2, uint8_t *data2, uint8_t datalen3,
uint8_t *data3,
uint8_t tx_size, uint8_t *tx_buffer, uint8_t rx_size, uint8_t *rx_buffer)
uint8_t datalen1, const uint8_t *data1, uint8_t datalen2, const uint8_t *data2, uint8_t datalen3,
const uint8_t *data3, uint8_t tx_size, const uint8_t *tx_buffer, uint8_t rx_size,
const uint8_t *rx_buffer)
{
#ifdef SHA204_CHECK_PARAMETERS

Expand Down
4 changes: 2 additions & 2 deletions hal/crypto/generic/drivers/AES/AES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void inv_shift_sub_rows (byte st[N_BLOCK])

/* SUB COLUMNS PHASE */

static void mix_sub_columns (byte dt[N_BLOCK], byte st[N_BLOCK])
static void mix_sub_columns (byte dt[N_BLOCK], const byte st[N_BLOCK])
{
byte j = 5 ;
byte k = 10 ;
Expand All @@ -223,7 +223,7 @@ static void mix_sub_columns (byte dt[N_BLOCK], byte st[N_BLOCK])
}
}

static void inv_mix_sub_columns (byte dt[N_BLOCK], byte st[N_BLOCK])
static void inv_mix_sub_columns (byte dt[N_BLOCK], const byte st[N_BLOCK])
{
for (byte i = 0 ; i < N_BLOCK ; i += N_COL) {
byte a1 = st [i] ;
Expand Down

0 comments on commit 0a703d5

Please sign in to comment.