Mark pointers as const

Resulting binaries are identical.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2024-03-01 07:59:13 -07:00
committed by Jeremy Soller
parent d60a8e4c8e
commit 9fb08ffa46
38 changed files with 213 additions and 147 deletions

View File

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

View File

@ -10,7 +10,7 @@
#define TIMEOUT (F_CPU / 1000)
int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) {
int16_t i2c_start(struct I2C *const i2c, uint8_t addr, bool read) {
uint32_t count;
// reset TWI control register
@ -47,12 +47,12 @@ int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) {
return 0;
}
void i2c_stop(struct I2C *i2c) {
void i2c_stop(struct I2C *const i2c) {
// transmit STOP condition
TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO);
}
int16_t i2c_write(struct I2C *i2c, uint8_t *data, uint16_t length) {
int16_t i2c_write(struct I2C *const i2c, uint8_t *const data, uint16_t length) {
uint16_t i;
for (i = 0; i < length; i++) {
// load data into data register
@ -74,7 +74,7 @@ int16_t i2c_write(struct I2C *i2c, uint8_t *data, uint16_t length) {
return i;
}
int16_t i2c_read(struct I2C *i2c, uint8_t *data, uint16_t length) {
int16_t i2c_read(struct I2C *const i2c, uint8_t *const data, uint16_t length) {
uint16_t i;
for (i = 0; i < length; i++) {
if ((i + 1) < length) {

View File

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

View File

@ -19,16 +19,16 @@ struct Uart {
uint8_t c_init;
};
void uart_init(struct Uart *uart, uint32_t baud);
void uart_init(struct Uart *const uart, uint32_t baud);
int16_t uart_count(void);
struct Uart *uart_new(int16_t num);
uint8_t uart_can_read(struct Uart *uart);
uint8_t uart_can_write(struct Uart *uart);
uint8_t uart_can_read(struct Uart *const uart);
uint8_t uart_can_write(struct Uart *const uart);
uint8_t uart_read(struct Uart *uart);
void uart_write(struct Uart *uart, uint8_t data);
uint8_t uart_read(struct Uart *const uart);
void uart_write(struct Uart *const uart, uint8_t data);
extern struct Uart *uart_stdio;
void uart_stdio_init(int16_t num, uint32_t baud);

View File

@ -54,7 +54,7 @@ struct Uart *uart_new(int16_t num) {
}
}
void uart_init(struct Uart *uart, uint32_t baud) {
void uart_init(struct Uart *const uart, uint32_t baud) {
uint32_t baud_prescale = (F_CPU / (baud * 16UL)) - 1;
*(uart->baud_h) = (uint8_t)(baud_prescale >> 8);
*(uart->baud_l) = (uint8_t)(baud_prescale);
@ -63,20 +63,20 @@ void uart_init(struct Uart *uart, uint32_t baud) {
*(uart->c) = uart->c_init;
}
uint8_t uart_can_read(struct Uart *uart) {
uint8_t uart_can_read(struct Uart *const uart) {
return (*(uart->a)) & uart->a_read;
}
uint8_t uart_read(struct Uart *uart) {
uint8_t uart_read(struct Uart *const uart) {
while (!uart_can_read(uart)) {}
return *(uart->data);
}
uint8_t uart_can_write(struct Uart *uart) {
uint8_t uart_can_write(struct Uart *const uart) {
return (*(uart->a)) & uart->a_write;
}
void uart_write(struct Uart *uart, uint8_t data) {
void uart_write(struct Uart *const uart, uint8_t data) {
while (!uart_can_write(uart)) {}
*(uart->data) = data;
}

View File

@ -4,7 +4,7 @@
#include <common/i2c.h>
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data) {
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data) {
return i2c_get(NULL, address, command, (uint8_t *)data, 2);
}

View File

@ -117,7 +117,7 @@ static struct Parallel PORT = {
// clang-format on
// Set port to all high-impedance inputs
void parallel_hiz(struct Parallel *port) {
void parallel_hiz(struct Parallel *const port) {
#define PIN(N, P) \
gpio_set_dir(port->N, false); \
gpio_set(port->N, false);
@ -126,7 +126,7 @@ void parallel_hiz(struct Parallel *port) {
}
// Place all data lines in high or low impendance state
void parallel_data_dir(struct Parallel *port, bool dir) {
void parallel_data_dir(struct Parallel *const port, bool dir) {
#define DATA_BIT(B) gpio_set_dir(port->d##B, dir);
DATA_BITS
#undef DATA_BIT
@ -134,7 +134,7 @@ void parallel_data_dir(struct Parallel *port, bool dir) {
#define parallel_data_forward(P) parallel_data_dir(P, true)
#define parallel_data_reverse(P) parallel_data_dir(P, false)
void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
void parallel_data_set_high(struct Parallel *const port, uint8_t byte) {
// By convention all lines are high, so only set the ones needed
#define DATA_BIT(B) \
if (!(byte & (1 << B))) \
@ -144,7 +144,7 @@ void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
}
// Set port to initial state required before being able to perform cycles
void parallel_reset(struct Parallel *port, bool host) {
void parallel_reset(struct Parallel *const port, bool host) {
parallel_hiz(port);
// nRESET: output on host, input on peripherals
@ -183,7 +183,7 @@ void parallel_reset(struct Parallel *port, bool host) {
}
}
void parallel_state(struct Parallel *port, enum ParallelState state) {
void parallel_state(struct Parallel *const port, enum ParallelState state) {
if (port->state != state) {
switch (state) {
case PARALLEL_STATE_UNKNOWN:
@ -202,7 +202,7 @@ void parallel_state(struct Parallel *port, enum ParallelState state) {
}
}
uint8_t parallel_read_data(struct Parallel *port) {
uint8_t parallel_read_data(struct Parallel *const port) {
uint8_t byte = 0;
#define DATA_BIT(B) \
if (gpio_get(port->d##B)) \
@ -212,7 +212,7 @@ uint8_t parallel_read_data(struct Parallel *port) {
return byte;
}
void parallel_write_data(struct Parallel *port, uint8_t byte) {
void parallel_write_data(struct Parallel *const port, uint8_t byte) {
// By convention all lines are high, so only set the ones needed
#define DATA_BIT(B) \
@ -224,8 +224,8 @@ void parallel_write_data(struct Parallel *port, uint8_t byte) {
//TODO: timeout
int16_t parallel_transaction(
struct Parallel *port,
uint8_t *data,
struct Parallel *const port,
uint8_t *const data,
int16_t length,
bool read,
bool addr
@ -299,7 +299,12 @@ int16_t parallel_transaction(
// host write -> peripheral read
// host read -> peripheral write
bool parallel_peripheral_cycle(struct Parallel *port, uint8_t *data, bool *read, bool *addr) {
bool parallel_peripheral_cycle(
struct Parallel *const port,
uint8_t *const data,
bool *const read,
bool *const addr
) {
if (!gpio_get(port->reset_n)) {
// XXX: Give host some time to get ready
_delay_ms(1);
@ -351,7 +356,12 @@ static uint8_t ZERO = 0x00;
static uint8_t SPI_ENABLE = 0xFE;
static uint8_t SPI_DATA = 0xFD;
int16_t parallel_ecms_read(struct Parallel *port, uint16_t addr, uint8_t *data, int16_t length) {
int16_t parallel_ecms_read(
struct Parallel *const port,
uint16_t addr,
uint8_t *const data,
int16_t length
) {
int16_t res;
res = parallel_set_address(port, &ADDRESS_ECMSADDR1, 1);
@ -378,7 +388,7 @@ int16_t parallel_ecms_read(struct Parallel *port, uint16_t addr, uint8_t *data,
}
// Disable chip
int16_t parallel_spi_reset(struct Parallel *port) {
int16_t parallel_spi_reset(struct Parallel *const port) {
int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
@ -397,7 +407,12 @@ int16_t parallel_spi_reset(struct Parallel *port) {
}
// Enable chip and read or write data
int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t length, bool read) {
int16_t parallel_spi_transaction(
struct Parallel *const port,
uint8_t *const data,
int16_t length,
bool read
) {
int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
@ -420,8 +435,8 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t l
// "Hardware" accelerated SPI programming, requires ECINDARs to be set
int16_t parallel_spi_program(
struct Parallel *port,
uint8_t *data,
struct Parallel *const port,
uint8_t *const data,
int16_t length,
bool initialized
) {
@ -483,7 +498,7 @@ int16_t parallel_spi_program(
return i;
}
int16_t serial_transaction(uint8_t *data, int16_t length, bool read) {
int16_t serial_transaction(uint8_t *const data, int16_t length, bool read) {
int16_t i;
for (i = 0; i < length; i++) {
if (read) {

View File

@ -85,7 +85,7 @@ static struct Parallel PORT = {
};
// Set port to all high-impedance inputs
void parallel_hiz(struct Parallel *port) {
void parallel_hiz(struct Parallel *const port) {
#define PIN(N, P) \
gpio_set_dir(port->N, false); \
gpio_set(port->N, false);
@ -94,7 +94,7 @@ void parallel_hiz(struct Parallel *port) {
}
// Place all data lines in high or low impendance state
void parallel_data_dir(struct Parallel *port, bool dir) {
void parallel_data_dir(struct Parallel *const port, bool dir) {
#define DATA_BIT(B) gpio_set_dir(port->d##B, dir);
DATA_BITS
#undef DATA_BIT
@ -102,7 +102,7 @@ void parallel_data_dir(struct Parallel *port, bool dir) {
#define parallel_data_forward(P) parallel_data_dir(P, true)
#define parallel_data_reverse(P) parallel_data_dir(P, false)
void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
void parallel_data_set_high(struct Parallel *const port, uint8_t byte) {
// By convention all lines are high, so only set the ones needed
#define DATA_BIT(B) \
if (!(byte & (1 << B))) \
@ -112,7 +112,7 @@ void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
}
// Set port to initial state required before being able to perform cycles
void parallel_reset(struct Parallel *port, bool host) {
void parallel_reset(struct Parallel *const port, bool host) {
parallel_hiz(port);
// nRESET: output on host, input on peripherals
@ -151,7 +151,7 @@ void parallel_reset(struct Parallel *port, bool host) {
}
}
uint8_t parallel_read_data(struct Parallel *port) {
uint8_t parallel_read_data(struct Parallel *const port) {
uint8_t byte = 0;
#define DATA_BIT(B) \
if (gpio_get(port->d##B)) \
@ -161,7 +161,7 @@ uint8_t parallel_read_data(struct Parallel *port) {
return byte;
}
void parallel_write_data(struct Parallel *port, uint8_t byte) {
void parallel_write_data(struct Parallel *const port, uint8_t byte) {
// By convention all lines are high, so only set the ones needed
#define DATA_BIT(B) \
if (!(byte & (1 << B))) \
@ -172,8 +172,8 @@ void parallel_write_data(struct Parallel *port, uint8_t byte) {
//TODO: timeout
int16_t parallel_transaction(
struct Parallel *port,
uint8_t *data,
struct Parallel *const port,
uint8_t *const data,
int16_t length,
bool read,
bool addr
@ -248,7 +248,12 @@ int16_t parallel_transaction(
// host write -> peripheral read
// host read -> peripheral write
bool parallel_peripheral_cycle(struct Parallel *port, uint8_t *data, bool *read, bool *addr) {
bool parallel_peripheral_cycle(
struct Parallel *const port,
uint8_t *const data,
bool *const read,
bool *const addr
) {
if (!gpio_get(port->reset_n)) {
// XXX: Give host some time to get ready
_delay_ms(1);
@ -293,7 +298,7 @@ static uint8_t SPI_ENABLE = 0xFE;
static uint8_t SPI_DATA = 0xFD;
// Disable chip
int16_t parallel_spi_reset(struct Parallel *port) {
int16_t parallel_spi_reset(struct Parallel *const port) {
int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
@ -312,7 +317,12 @@ int16_t parallel_spi_reset(struct Parallel *port) {
}
// Enable chip and read or write data
int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t length, bool read) {
int16_t parallel_spi_transaction(
struct Parallel *const port,
uint8_t *const data,
int16_t length,
bool read
) {
int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
@ -335,8 +345,8 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t l
// "Hardware" accelerated SPI programming, requires ECINDARs to be set
int16_t parallel_spi_program(
struct Parallel *port,
uint8_t *data,
struct Parallel *const port,
uint8_t *const data,
int16_t length,
bool initialized
) {
@ -398,7 +408,7 @@ int16_t parallel_spi_program(
return i;
}
int16_t serial_transaction(uint8_t *data, int16_t length, bool read) {
int16_t serial_transaction(uint8_t *const data, int16_t length, bool read) {
int16_t i;
for (i = 0; i < length; i++) {
if (read) {

View File

@ -25,7 +25,7 @@ void fan_reset(void) {
// Get duty cycle based on temperature, adapted from
// https://github.com/pop-os/system76-power/blob/master/src/fan.rs
uint8_t fan_duty(const struct Fan *fan, int16_t temp) __reentrant {
uint8_t fan_duty(const struct Fan *const fan, int16_t temp) __reentrant {
for (uint8_t i = 0; i < fan->points_size; i++) {
const struct FanPoint *cur = &fan->points[i];
@ -85,7 +85,7 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant {
}
}
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant {
uint8_t fan_heatup(const struct Fan *const fan, uint8_t duty) __reentrant {
uint8_t lowest = duty;
uint8_t i;
@ -101,7 +101,7 @@ uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant {
return lowest;
}
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant {
uint8_t fan_cooldown(const struct Fan *const fan, uint8_t duty) __reentrant {
uint8_t highest = duty;
uint8_t i;

View File

@ -15,7 +15,7 @@ uint8_t __code __at(FLASH_OFFSET) flash_rom[] = {
#include <flash.h>
};
static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) {
static void flash_api(uint32_t addr, uint8_t *const data, uint32_t length, uint8_t command) {
// Use DMA mapping to copy flash ROM to scratch ROM
SCARH = 0x80;
SCARL = (uint8_t)(FLASH_OFFSET);
@ -29,7 +29,7 @@ static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t com
SCARH = 0x07;
}
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length) {
void flash_read(uint32_t addr, __xdata uint8_t *const data, uint32_t length) {
flash_api(addr, data, length, FLASH_COMMAND_READ);
}
@ -57,7 +57,7 @@ uint8_t flash_read_u8(uint32_t addr) {
return data;
}
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length) {
void flash_write(uint32_t addr, __xdata uint8_t *const data, uint32_t length) {
flash_api(addr, data, length, FLASH_COMMAND_WRITE);
}

View File

@ -50,10 +50,10 @@ extern bool fan_max;
void fan_reset(void);
uint8_t fan_duty(const struct Fan *fan, int16_t temp) __reentrant;
uint8_t fan_duty(const struct Fan *const fan, int16_t temp) __reentrant;
void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant;
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant;
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant;
uint8_t fan_heatup(const struct Fan *const fan, uint8_t duty) __reentrant;
uint8_t fan_cooldown(const struct Fan *const fan, uint8_t duty) __reentrant;
uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant;
#endif // _BOARD_FAN_H

View File

@ -26,7 +26,7 @@
* \param[out] data The memory area to copy to.
* \param[in] length The number of bytes to copy.
*/
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length);
void flash_read(uint32_t addr, __xdata uint8_t *const data, uint32_t length);
/**
* Read a single byte from flash.
@ -62,7 +62,7 @@ uint32_t flash_read_u32(uint32_t addr);
* \param[in] data The memory area to copy from.
* \param[in] length The number of bytes to copy.
*/
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length);
void flash_write(uint32_t addr, __xdata uint8_t *const data, uint32_t length);
/**
* Write a single byte to flash.

View File

@ -12,6 +12,6 @@ extern uint8_t kbc_leds;
void kbc_init(void);
void kbc_reset(void);
bool kbc_scancode(uint16_t key, bool pressed);
void kbc_event(struct Kbc *kbc);
void kbc_event(struct Kbc *const kbc);
#endif // _BOARD_KBC_H

View File

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

View File

@ -6,8 +6,8 @@
#include <ec/pmc.h>
void pmc_init(void);
bool pmc_sci(struct Pmc *pmc, uint8_t sci);
bool pmc_sci(struct Pmc *const pmc, uint8_t sci);
void pmc_swi(void);
void pmc_event(struct Pmc *pmc);
void pmc_event(struct Pmc *const pmc);
#endif // _BOARD_PMC_H

View File

@ -6,7 +6,7 @@
#include <ec/smbus.h>
void smbus_init(void);
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data);
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data);
int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data);
#endif // _BOARD_SMBUS_H

View File

@ -83,7 +83,7 @@ static uint8_t kbc_buffer[16] = { 0 };
static uint8_t kbc_buffer_head = 0;
static uint8_t kbc_buffer_tail = 0;
static bool kbc_buffer_pop(uint8_t *scancode) {
static bool kbc_buffer_pop(uint8_t *const scancode) {
if (kbc_buffer_head == kbc_buffer_tail) {
return false;
}
@ -92,7 +92,7 @@ static bool kbc_buffer_pop(uint8_t *scancode) {
return true;
}
static bool kbc_buffer_push(uint8_t *scancodes, uint8_t len) {
static bool kbc_buffer_push(uint8_t *const scancodes, uint8_t len) {
//TODO: make this test more efficient
for (uint8_t i = 0; i < len; i++) {
if ((kbc_buffer_tail + i + 1U) % ARRAY_SIZE(kbc_buffer) == kbc_buffer_head) {
@ -165,13 +165,13 @@ static uint8_t state_data = 0;
static enum KbcState state_next = KBC_STATE_NORMAL;
// Clear output buffer
static void kbc_clear_output(struct Kbc *kbc) {
static void kbc_clear_output(struct Kbc *const kbc) {
*(kbc->control) |= BIT(5);
*(kbc->control) |= BIT(6);
*(kbc->control) &= ~BIT(5);
}
static void kbc_on_input_command(struct Kbc *kbc, uint8_t data) {
static void kbc_on_input_command(struct Kbc *const kbc, uint8_t data) {
TRACE("kbc cmd: %02X\n", data);
// Controller commands always reset the state
state = KBC_STATE_NORMAL;
@ -254,7 +254,7 @@ static void kbc_on_input_command(struct Kbc *kbc, uint8_t data) {
}
}
static void kbc_on_input_data(struct Kbc *kbc, uint8_t data) {
static void kbc_on_input_data(struct Kbc *const kbc, uint8_t data) {
TRACE("kbc data: %02X\n", data);
switch (state) {
case KBC_STATE_TOUCHPAD:
@ -415,7 +415,7 @@ static void kbc_on_input_data(struct Kbc *kbc, uint8_t data) {
}
}
static void kbc_on_output_empty(struct Kbc *kbc) {
static void kbc_on_output_empty(struct Kbc *const kbc) {
switch (state) {
case KBC_STATE_KEYBOARD:
TRACE("kbc keyboard: %02X\n", state_data);
@ -454,7 +454,7 @@ static void kbc_on_output_empty(struct Kbc *kbc) {
}
}
void kbc_event(struct Kbc *kbc) {
void kbc_event(struct Kbc *const kbc) {
uint8_t sts;
// Read from scancode buffer when possible

View File

@ -86,7 +86,7 @@ static inline uint8_t kbscan_get_row(void) {
}
#if KM_NKEY
static bool kbscan_row_has_ghost(uint8_t *matrix, uint8_t col) {
static bool kbscan_row_has_ghost(uint8_t *const matrix, uint8_t col) {
(void)matrix;
(void)col;
return false;
@ -96,7 +96,7 @@ static inline bool popcount_more_than_one(uint8_t rowdata) {
return rowdata & (rowdata - 1);
}
static bool kbscan_row_has_ghost(uint8_t *matrix, uint8_t col) {
static bool kbscan_row_has_ghost(uint8_t *const matrix, uint8_t col) {
uint8_t rowdata = matrix[col];
// No ghosts exist when less than 2 keys in the row are active.
@ -155,7 +155,7 @@ static void hardware_hotkey(uint16_t key) {
}
}
bool kbscan_press(uint16_t key, bool pressed, uint8_t *layer) {
bool kbscan_press(uint16_t key, bool pressed, uint8_t *const layer) {
// Wake from sleep on keypress
if (pressed && (power_state == POWER_STATE_S3)) {
pmc_swi();

View File

@ -69,7 +69,7 @@ bool keymap_save_config(void) {
return flash_read_u16(CONFIG_ADDR) == CONFIG_SIGNATURE;
}
bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) {
bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *const value) {
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
if (keymap_fnlock && keymap_is_f_key(output, input))
layer ^= 1;

View File

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

View File

@ -96,7 +96,7 @@ bool peci_available(void) {
void peci_init(void) {}
// Returns true on success, false on error
bool peci_get_temp(int16_t *data) {
bool peci_get_temp(int16_t *const data) {
//TODO: Wait for completion?
// Clear upstream status
ESUCTRL0 = ESUCTRL0;
@ -289,7 +289,7 @@ void peci_init(void) {
}
// Returns true on success, false on error
bool peci_get_temp(int16_t *data) {
bool peci_get_temp(int16_t *const data) {
// Wait for any in-progress transaction to complete
uint32_t start = time_get();
while (HOSTAR & BIT(0)) {

View File

@ -54,7 +54,7 @@ static void pmc_sci_interrupt(void) {
#endif // CONFIG_BUS_ESPI
}
bool pmc_sci(struct Pmc *pmc, uint8_t sci) {
bool pmc_sci(struct Pmc *const pmc, uint8_t sci) {
// Set SCI pending bit
pmc_set_status(pmc, pmc_status(pmc) | BIT(5));
@ -101,7 +101,7 @@ void pmc_swi(void) {
static enum PmcState state = PMC_STATE_DEFAULT;
static uint8_t state_data = 0;
static void pmc_on_input_command(struct Pmc *pmc, uint8_t data) {
static void pmc_on_input_command(struct Pmc *const pmc, uint8_t data) {
TRACE("pmc cmd: %02X\n", data);
state = PMC_STATE_DEFAULT;
switch (data) {
@ -169,7 +169,7 @@ static void pmc_on_input_data(uint8_t data) {
}
}
static void pmc_on_output_empty(struct Pmc *pmc) {
static void pmc_on_output_empty(struct Pmc *const pmc) {
switch (state) {
case PMC_STATE_WRITE:
TRACE("pmc write: %02X\n", state_data);
@ -181,7 +181,7 @@ static void pmc_on_output_empty(struct Pmc *pmc) {
}
}
void pmc_event(struct Pmc *pmc) {
void pmc_event(struct Pmc *const pmc) {
uint8_t sts;
// Read command/data if available

View File

@ -22,10 +22,10 @@ void smbus_init(void) {
i2c_reset(&I2C_SMBUS, true);
}
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data) {
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2);
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data) {
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *const)data, 2);
}
int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2);
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *const)&data, 2);
}

View File

@ -2,7 +2,9 @@
#include <common/i2c.h>
int16_t i2c_recv(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length) __reentrant {
// clang-format off
int16_t i2c_recv(struct I2C *const i2c, uint8_t addr, uint8_t *const data, uint16_t length) __reentrant {
// clang-format on
int16_t res = 0;
res = i2c_start(i2c, addr, true);
@ -18,7 +20,9 @@ int16_t i2c_recv(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length)
return res;
}
int16_t i2c_send(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length) __reentrant {
// clang-format off
int16_t i2c_send(struct I2C *const i2c, uint8_t addr, uint8_t *const data, uint16_t length) __reentrant {
// clang-format on
int16_t res = 0;
res = i2c_start(i2c, addr, false);
@ -34,8 +38,13 @@ int16_t i2c_send(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length)
return res;
}
int16_t i2c_get(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length)
__reentrant {
int16_t i2c_get(
struct I2C *const i2c,
uint8_t addr,
uint8_t reg,
uint8_t *const data,
uint16_t length
) __reentrant {
int16_t res = 0;
res = i2c_start(i2c, addr, false);
@ -49,8 +58,13 @@ int16_t i2c_get(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint1
return i2c_recv(i2c, addr, data, length);
}
int16_t i2c_set(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length)
__reentrant {
int16_t i2c_set(
struct I2C *const i2c,
uint8_t addr,
uint8_t reg,
uint8_t *const data,
uint16_t length
) __reentrant {
int16_t res = 0;
res = i2c_start(i2c, addr, false);

View File

@ -16,34 +16,56 @@ struct I2C;
// Start i2c transaction
// Must be defined by arch, board, or ec
int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) __reentrant;
int16_t i2c_start(struct I2C *const i2c, uint8_t addr, bool read) __reentrant;
// Stop i2c transaction
// Must be defined by arch, board, or ec
void i2c_stop(struct I2C *i2c) __reentrant;
void i2c_stop(struct I2C *const i2c) __reentrant;
// Send a byte on i2c bus
// Must be defined by arch, board, or ec
int16_t i2c_write(struct I2C *i2c, uint8_t *data, uint16_t length) __reentrant;
int16_t i2c_write(struct I2C *const i2c, uint8_t *const data, uint16_t length) __reentrant;
// Read bytes from bus
// Must be defined by arch, board, or ec
int16_t i2c_read(struct I2C *i2c, uint8_t *data, uint16_t length) __reentrant;
// Read multiple bytes from address in one transaction
int16_t i2c_recv(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length) __reentrant;
// Write multiple bytes to address in one transaction
int16_t i2c_send(struct I2C *i2c, uint8_t addr, uint8_t *data, uint16_t length) __reentrant;
int16_t i2c_read(struct I2C *const i2c, uint8_t *const data, uint16_t length) __reentrant;
// clang-format off
// Read multiple bytes from a register in one transaction
int16_t i2c_get(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length) __reentrant;
// Read multiple bytes from address in one transaction
int16_t i2c_recv(
struct I2C *const i2c,
uint8_t addr,
uint8_t *const data,
uint16_t length
) __reentrant;
// Write multiple bytes to a register in one transaction
int16_t i2c_set(struct I2C *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length) __reentrant;
// Write multiple bytes to address in one transaction
int16_t i2c_send(
struct I2C *const i2c,
uint8_t addr,
uint8_t *const data,
uint16_t length
) __reentrant;
// clang-format on
// Read multiple bytes from a register in one transaction
int16_t i2c_get(
struct I2C *const i2c,
uint8_t addr,
uint8_t reg,
uint8_t *const data,
uint16_t length
) __reentrant;
// Write multiple bytes to a register in one transaction
int16_t i2c_set(
struct I2C *const i2c,
uint8_t addr,
uint8_t reg,
uint8_t *const data,
uint16_t length
) __reentrant;
#endif // _COMMON_I2C_H

View File

@ -30,7 +30,7 @@ bool keymap_load_config(void);
// Save dynamic keymap to flash
bool keymap_save_config(void);
// Get a keycode from the dynamic keymap
bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value);
bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *const value);
// Set a keycode in the dynamic keymap
bool keymap_set(uint8_t layer, uint8_t output, uint8_t input, uint16_t value);
#endif

View File

@ -37,7 +37,7 @@ struct VirtualWire __code VW_SUS_PWRDN_ACK = VIRTUAL_WIRE(41, 1);
// Index 47 - AP to EC (platform specific)
struct VirtualWire __code VW_HOST_C10 = VIRTUAL_WIRE(47, 0);
enum VirtualWireState vw_get(struct VirtualWire *vw) __critical {
enum VirtualWireState vw_get(struct VirtualWire *const vw) __critical {
uint8_t index = *vw->index;
if (index & vw->valid_mask) {
if (index & vw->data_mask) {
@ -50,7 +50,7 @@ enum VirtualWireState vw_get(struct VirtualWire *vw) __critical {
}
}
void vw_set(struct VirtualWire *vw, enum VirtualWireState state) __critical {
void vw_set(struct VirtualWire *const vw, enum VirtualWireState state) __critical {
uint8_t index = *vw->index;
switch (state) {
case VWS_LOW:

View File

@ -3,7 +3,7 @@
#include <ec/gpio.h>
#include <common/debug.h>
bool gpio_get(struct Gpio *gpio) {
bool gpio_get(struct Gpio *const gpio) {
if (*(gpio->data) & gpio->value) {
return true;
} else {
@ -11,7 +11,7 @@ bool gpio_get(struct Gpio *gpio) {
}
}
void gpio_set(struct Gpio *gpio, bool value) {
void gpio_set(struct Gpio *const gpio, bool value) {
if (value) {
*(gpio->data) |= gpio->value;
} else {
@ -21,11 +21,11 @@ void gpio_set(struct Gpio *gpio, bool value) {
#ifdef GPIO_DEBUG
static void gpio_debug_bank(
char *bank,
char *const bank,
uint8_t data,
uint8_t mirror,
uint8_t pot,
volatile uint8_t *control
volatile uint8_t *const control
) {
for (char i = 0; i < 8; i++) {
DEBUG(

View File

@ -42,7 +42,7 @@ struct I2C __code I2C_4 = {
};
#endif
void i2c_reset(struct I2C *i2c, bool kill) {
void i2c_reset(struct I2C *const i2c, bool kill) {
if (*(i2c->hosta) & HOSTA_BUSY) {
// Set kill bit
if (kill)
@ -58,7 +58,7 @@ void i2c_reset(struct I2C *i2c, bool kill) {
*(i2c->hoctl2) = 0;
}
int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) __reentrant {
int16_t i2c_start(struct I2C *const i2c, uint8_t addr, bool read) __reentrant {
// If we are already in a transaction
if (*(i2c->hosta) & HOSTA_BYTE_DONE) {
// If we are switching direction
@ -86,7 +86,7 @@ int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) __reentrant {
return 0;
}
void i2c_stop(struct I2C *i2c) {
void i2c_stop(struct I2C *const i2c) {
// Disable i2c compatibility
*(i2c->hoctl2) &= ~BIT(1);
// Clear status
@ -95,7 +95,12 @@ void i2c_stop(struct I2C *i2c) {
i2c_reset(i2c, false);
}
static int16_t i2c_transaction(struct I2C *i2c, uint8_t *data, uint16_t length, bool read) {
static int16_t i2c_transaction(
struct I2C *const i2c,
uint8_t *const data,
uint16_t length,
bool read
) {
uint16_t i;
for (i = 0; i < length; i++) {
if (read) {
@ -154,10 +159,10 @@ static int16_t i2c_transaction(struct I2C *i2c, uint8_t *data, uint16_t length,
return i;
}
int16_t i2c_read(struct I2C *i2c, uint8_t *data, uint16_t length) __reentrant {
int16_t i2c_read(struct I2C *const i2c, uint8_t *const data, uint16_t length) __reentrant {
return i2c_transaction(i2c, data, length, true);
}
int16_t i2c_write(struct I2C *i2c, uint8_t *data, uint16_t length) __reentrant {
int16_t i2c_write(struct I2C *const i2c, uint8_t *const data, uint16_t length) __reentrant {
return i2c_transaction(i2c, data, length, false);
}

View File

@ -27,9 +27,9 @@ enum VirtualWireState {
VWS_HIGH = 0x11,
};
enum VirtualWireState vw_get(struct VirtualWire *vw) __critical;
enum VirtualWireState vw_get(struct VirtualWire *const vw) __critical;
void vw_set(struct VirtualWire *vw, enum VirtualWireState state) __critical;
void vw_set(struct VirtualWire *const vw, enum VirtualWireState state) __critical;
// Not all wires are defined or implemented
// Index 2 - AP to EC

View File

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

View File

@ -11,6 +11,6 @@ extern struct I2C __code I2C_1;
extern struct I2C __code I2C_4;
#endif
void i2c_reset(struct I2C *i2c, bool kill);
void i2c_reset(struct I2C *const i2c, bool kill);
#endif // _EC_I2C_H

View File

@ -29,10 +29,10 @@ extern struct Kbc __code KBC;
#define KBC_STS_IBF BIT(1)
#define KBC_STS_CMD BIT(3)
uint8_t kbc_status(struct Kbc *kbc);
uint8_t kbc_read(struct Kbc *kbc);
bool kbc_keyboard(struct Kbc *kbc, uint8_t data, uint16_t timeout);
bool kbc_mouse(struct Kbc *kbc, uint8_t data, uint16_t timeout);
uint8_t kbc_status(struct Kbc *const kbc);
uint8_t kbc_read(struct Kbc *const kbc);
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);
volatile uint8_t __xdata __at(0x1300) KBHICR;
volatile uint8_t __xdata __at(0x1302) KBIRQR;

View File

@ -33,10 +33,10 @@ extern struct Pmc __code PMC_5;
#define PMC_STS_IBF BIT(1)
#define PMC_STS_CMD BIT(3)
uint8_t pmc_status(struct Pmc *pmc);
void pmc_set_status(struct Pmc *pmc, uint8_t status);
uint8_t pmc_read(struct Pmc *pmc);
void pmc_write(struct Pmc *pmc, uint8_t data);
uint8_t pmc_status(struct Pmc *const pmc);
void pmc_set_status(struct Pmc *const pmc, uint8_t status);
uint8_t pmc_read(struct Pmc *const pmc);
void pmc_write(struct Pmc *const pmc, uint8_t data);
volatile uint8_t __xdata __at(0x1500) PM1STS;
volatile uint8_t __xdata __at(0x1501) PM1DO;

View File

@ -22,7 +22,7 @@ extern struct Ps2 __code PS2_1;
extern struct Ps2 __code PS2_2;
extern struct Ps2 __code PS2_3;
void ps2_reset(struct Ps2 *ps2);
void ps2_reset(struct Ps2 *const ps2);
volatile uint8_t __xdata __at(0x1700) PSCTL1;
volatile uint8_t __xdata __at(0x1701) PSCTL2;

View File

@ -12,15 +12,15 @@ struct Kbc __code KBC = {
.data_in = &KBHIDIR,
};
uint8_t kbc_status(struct Kbc *kbc) {
uint8_t kbc_status(struct Kbc *const kbc) {
return *(kbc->status);
}
uint8_t kbc_read(struct Kbc *kbc) {
uint8_t kbc_read(struct Kbc *const kbc) {
return *(kbc->data_in);
}
static bool kbc_wait(struct Kbc *kbc, uint16_t timeout) {
static bool kbc_wait(struct Kbc *const kbc, uint16_t timeout) {
while (*(kbc->status) & KBC_STS_OBF) {
if (timeout == 0)
return false;
@ -30,7 +30,7 @@ static bool kbc_wait(struct Kbc *kbc, uint16_t timeout) {
return true;
}
bool kbc_keyboard(struct Kbc *kbc, uint8_t data, uint16_t timeout) {
bool kbc_keyboard(struct Kbc *const kbc, uint8_t data, uint16_t timeout) {
if (!kbc_wait(kbc, timeout))
return false;
*(kbc->status) &= ~0x20;
@ -38,7 +38,7 @@ bool kbc_keyboard(struct Kbc *kbc, uint8_t data, uint16_t timeout) {
return true;
}
bool kbc_mouse(struct Kbc *kbc, uint8_t data, uint16_t timeout) {
bool kbc_mouse(struct Kbc *const kbc, uint8_t data, uint16_t timeout) {
if (!kbc_wait(kbc, timeout))
return false;
*(kbc->status) |= 0x20;

View File

@ -19,18 +19,18 @@ struct Pmc __code PMC_3 = PMC(3);
struct Pmc __code PMC_4 = PMC(4);
struct Pmc __code PMC_5 = PMC(5);
uint8_t pmc_status(struct Pmc *pmc) {
uint8_t pmc_status(struct Pmc *const pmc) {
return *(pmc->status);
}
void pmc_set_status(struct Pmc *pmc, uint8_t status) {
void pmc_set_status(struct Pmc *const pmc, uint8_t status) {
*(pmc->status) = status;
}
uint8_t pmc_read(struct Pmc *pmc) {
uint8_t pmc_read(struct Pmc *const pmc) {
return *(pmc->data_in);
}
void pmc_write(struct Pmc *pmc, uint8_t data) {
void pmc_write(struct Pmc *const pmc, uint8_t data) {
*(pmc->data_out) = data;
}

View File

@ -15,7 +15,7 @@ struct Ps2 __code PS2_1 = PS2(1);
struct Ps2 __code PS2_2 = PS2(2);
struct Ps2 __code PS2_3 = PS2(3);
void ps2_reset(struct Ps2 *ps2) {
void ps2_reset(struct Ps2 *const ps2) {
// Reset interface to defaults
*(ps2->control) = 1;
// Clear status