Mark pointed-to data const where possible

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2024-03-01 08:19:25 -07:00
committed by Jeremy Soller
parent 9fb08ffa46
commit 16e4f93f2c
14 changed files with 19 additions and 19 deletions

View File

@ -2,7 +2,7 @@
#include <arch/gpio.h> #include <arch/gpio.h>
bool gpio_get_dir(struct Gpio *const gpio) { bool gpio_get_dir(const struct Gpio *const gpio) {
if (*gpio->ddr & gpio->value) { if (*gpio->ddr & gpio->value) {
return true; return true;
} else { } else {
@ -18,7 +18,7 @@ void gpio_set_dir(struct Gpio *const gpio, bool value) {
} }
} }
bool gpio_get(struct Gpio *const gpio) { bool gpio_get(const struct Gpio *const gpio) {
if (*gpio->pin & gpio->value) { if (*gpio->pin & gpio->value) {
return true; return true;
} else { } else {

View File

@ -52,7 +52,7 @@ void i2c_stop(struct I2C *const i2c) {
TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO); TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO);
} }
int16_t i2c_write(struct I2C *const i2c, uint8_t *const data, uint16_t length) { int16_t i2c_write(struct I2C *const i2c, const uint8_t *const data, uint16_t length) {
uint16_t i; uint16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
// load data into data register // load data into data register

View File

@ -25,9 +25,9 @@ struct Gpio {
} }
// clang-format on // clang-format on
bool gpio_get(struct Gpio *const gpio); bool gpio_get(const struct Gpio *const gpio);
void gpio_set(struct Gpio *const gpio, bool value); void gpio_set(struct Gpio *const gpio, bool value);
bool gpio_get_dir(struct Gpio *const gpio); bool gpio_get_dir(const struct Gpio *const gpio);
void gpio_set_dir(struct Gpio *const gpio, bool value); void gpio_set_dir(struct Gpio *const gpio, bool value);
#endif // _ARCH_GPIO_H #endif // _ARCH_GPIO_H

View File

@ -436,7 +436,7 @@ int16_t parallel_spi_transaction(
// "Hardware" accelerated SPI programming, requires ECINDARs to be set // "Hardware" accelerated SPI programming, requires ECINDARs to be set
int16_t parallel_spi_program( int16_t parallel_spi_program(
struct Parallel *const port, struct Parallel *const port,
uint8_t *const data, const uint8_t *const data,
int16_t length, int16_t length,
bool initialized bool initialized
) { ) {

View File

@ -346,7 +346,7 @@ int16_t parallel_spi_transaction(
// "Hardware" accelerated SPI programming, requires ECINDARs to be set // "Hardware" accelerated SPI programming, requires ECINDARs to be set
int16_t parallel_spi_program( int16_t parallel_spi_program(
struct Parallel *const port, struct Parallel *const port,
uint8_t *const data, const uint8_t *const data,
int16_t length, int16_t length,
bool initialized bool initialized
) { ) {

View File

@ -8,6 +8,6 @@
extern bool parallel_debug; extern bool parallel_debug;
bool parallel_init(void); bool parallel_init(void);
int16_t parallel_write(uint8_t *const data, uint16_t length); int16_t parallel_write(const uint8_t *const data, uint16_t length);
#endif // _BOARD_PARALLEL_H #endif // _BOARD_PARALLEL_H

View File

@ -92,7 +92,7 @@ static bool kbc_buffer_pop(uint8_t *const scancode) {
return true; return true;
} }
static bool kbc_buffer_push(uint8_t *const scancodes, uint8_t len) { static bool kbc_buffer_push(const uint8_t *const scancodes, uint8_t len) {
//TODO: make this test more efficient //TODO: make this test more efficient
for (uint8_t i = 0; i < len; i++) { for (uint8_t i = 0; i < len; i++) {
if ((kbc_buffer_tail + i + 1U) % ARRAY_SIZE(kbc_buffer) == kbc_buffer_head) { if ((kbc_buffer_tail + i + 1U) % ARRAY_SIZE(kbc_buffer) == kbc_buffer_head) {

View File

@ -96,7 +96,7 @@ static inline bool popcount_more_than_one(uint8_t rowdata) {
return rowdata & (rowdata - 1); return rowdata & (rowdata - 1);
} }
static bool kbscan_row_has_ghost(uint8_t *const matrix, uint8_t col) { static bool kbscan_row_has_ghost(const uint8_t *const matrix, uint8_t col) {
uint8_t rowdata = matrix[col]; uint8_t rowdata = matrix[col];
// No ghosts exist when less than 2 keys in the row are active. // No ghosts exist when less than 2 keys in the row are active.

View File

@ -84,7 +84,7 @@ bool parallel_init(void) {
return parallel_wait_peripheral(STS_WAIT, 0); return parallel_wait_peripheral(STS_WAIT, 0);
} }
int16_t parallel_write(uint8_t *const data, uint16_t length) { int16_t parallel_write(const uint8_t *const data, uint16_t length) {
// Assert nWRITE // Assert nWRITE
KSIGDAT &= ~CTL_WRITE; KSIGDAT &= ~CTL_WRITE;

View File

@ -24,7 +24,7 @@ void i2c_stop(struct I2C *const i2c) __reentrant;
// Send a byte on i2c bus // Send a byte on i2c bus
// Must be defined by arch, board, or ec // Must be defined by arch, board, or ec
int16_t i2c_write(struct I2C *const i2c, uint8_t *const data, uint16_t length) __reentrant; int16_t i2c_write(struct I2C *const i2c, const uint8_t *const data, uint16_t length) __reentrant;
// Read bytes from bus // Read bytes from bus
// Must be defined by arch, board, or ec // Must be defined by arch, board, or ec

View File

@ -3,7 +3,7 @@
#include <ec/gpio.h> #include <ec/gpio.h>
#include <common/debug.h> #include <common/debug.h>
bool gpio_get(struct Gpio *const gpio) { bool gpio_get(const struct Gpio *const gpio) {
if (*(gpio->data) & gpio->value) { if (*(gpio->data) & gpio->value) {
return true; return true;
} else { } else {

View File

@ -32,7 +32,7 @@ struct Gpio {
} }
// clang-format on // clang-format on
bool gpio_get(struct Gpio *const gpio); bool gpio_get(const struct Gpio *const gpio);
void gpio_set(struct Gpio *const gpio, bool value); void gpio_set(struct Gpio *const gpio, bool value);
#ifdef GPIO_DEBUG #ifdef GPIO_DEBUG

View File

@ -29,8 +29,8 @@ extern struct Kbc __code KBC;
#define KBC_STS_IBF BIT(1) #define KBC_STS_IBF BIT(1)
#define KBC_STS_CMD BIT(3) #define KBC_STS_CMD BIT(3)
uint8_t kbc_status(struct Kbc *const kbc); uint8_t kbc_status(const struct Kbc *const kbc);
uint8_t kbc_read(struct Kbc *const kbc); uint8_t kbc_read(const struct Kbc *const kbc);
bool kbc_keyboard(struct Kbc *const kbc, uint8_t data, uint16_t timeout); bool kbc_keyboard(struct Kbc *const kbc, uint8_t data, uint16_t timeout);
bool kbc_mouse(struct Kbc *const kbc, uint8_t data, uint16_t timeout); bool kbc_mouse(struct Kbc *const kbc, uint8_t data, uint16_t timeout);

View File

@ -12,15 +12,15 @@ struct Kbc __code KBC = {
.data_in = &KBHIDIR, .data_in = &KBHIDIR,
}; };
uint8_t kbc_status(struct Kbc *const kbc) { uint8_t kbc_status(const struct Kbc *const kbc) {
return *(kbc->status); return *(kbc->status);
} }
uint8_t kbc_read(struct Kbc *const kbc) { uint8_t kbc_read(const struct Kbc *const kbc) {
return *(kbc->data_in); return *(kbc->data_in);
} }
static bool kbc_wait(struct Kbc *const kbc, uint16_t timeout) { static bool kbc_wait(const struct Kbc *const kbc, uint16_t timeout) {
while (*(kbc->status) & KBC_STS_OBF) { while (*(kbc->status) & KBC_STS_OBF) {
if (timeout == 0) if (timeout == 0)
return false; return false;