Use explicitly sized types from stdint

Replace bare int types with stdint types. This was done with:

    grep -rwl 'int' src/ | xargs sed -i 's/\<int\>/int16_t/g'
    grep -rwl 'unsigned long' src/ | xargs sed -i 's/\<unsigned long\>/uint32_t/g'
    grep -rwl 'unsigned char' src/ | xargs sed -i 's/\<unsigned char\>/uint8_t/g'

Then reverted for *main(), putchar(), and getchar().

The Arduino declarations for parallel_main() were also corrected to
match their definitions.

SDCC does *not* generate the same code in all instances, due to `int`
being treated different than `short int`.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2021-07-28 07:36:42 -06:00
committed by Jeremy Soller
parent 38b2a628f9
commit 99af8a35f5
41 changed files with 169 additions and 167 deletions

View File

@ -10,7 +10,7 @@
#define TIMEOUT (F_CPU/1000) #define TIMEOUT (F_CPU/1000)
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) { int16_t i2c_start(struct I2C * i2c, uint8_t addr, bool read) {
uint32_t count; uint32_t count;
// reset TWI control register // reset TWI control register
@ -46,8 +46,8 @@ void i2c_stop(struct I2C * i2c) {
TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO); TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO);
} }
int i2c_write(struct I2C * i2c, uint8_t * data, int length) { int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_t length) {
int i; int16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
// load data into data register // load data into data register
TWDR = data[i]; TWDR = data[i];
@ -65,8 +65,8 @@ int i2c_write(struct I2C * i2c, uint8_t * data, int length) {
return i; return i;
} }
int i2c_read(struct I2C * i2c, uint8_t * data, int length) { int16_t i2c_read(struct I2C * i2c, uint8_t * data, int16_t length) {
int i; int16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if ((i + 1) < length) { if ((i + 1) < length) {
// start TWI module and acknowledge data after reception // start TWI module and acknowledge data after reception

View File

@ -19,18 +19,18 @@ struct Uart {
uint8_t c_init; uint8_t c_init;
}; };
void uart_init(struct Uart * uart, unsigned long baud); void uart_init(struct Uart * uart, uint32_t baud);
int uart_count(); int16_t uart_count();
struct Uart * uart_new(int num); struct Uart * uart_new(int16_t num);
unsigned char uart_can_read(struct Uart * uart); uint8_t uart_can_read(struct Uart * uart);
unsigned char uart_can_write(struct Uart * uart); uint8_t uart_can_write(struct Uart * uart);
unsigned char uart_read(struct Uart * uart); uint8_t uart_read(struct Uart * uart);
void uart_write(struct Uart * uart, unsigned char data); void uart_write(struct Uart * uart, uint8_t data);
extern struct Uart * uart_stdio; extern struct Uart * uart_stdio;
void uart_stdio_init(int num, unsigned long baud); void uart_stdio_init(int16_t num, uint32_t baud);
#endif // _ARCH_UART_H #endif // _ARCH_UART_H

View File

@ -40,11 +40,11 @@
#error "Could not find UART definitions" #error "Could not find UART definitions"
#endif #endif
int uart_count() { int16_t uart_count() {
return sizeof(UARTS)/sizeof(struct Uart); return sizeof(UARTS)/sizeof(struct Uart);
} }
struct Uart * uart_new(int num) { struct Uart * uart_new(int16_t num) {
if (num < uart_count()) { if (num < uart_count()) {
return &UARTS[num]; return &UARTS[num];
} else { } else {
@ -52,8 +52,8 @@ struct Uart * uart_new(int num) {
} }
} }
void uart_init(struct Uart * uart, unsigned long baud) { void uart_init(struct Uart * uart, uint32_t baud) {
unsigned long baud_prescale = (F_CPU / (baud * 16UL)) - 1; uint32_t baud_prescale = (F_CPU / (baud * 16UL)) - 1;
*(uart->baud_h) = (uint8_t)(baud_prescale>>8); *(uart->baud_h) = (uint8_t)(baud_prescale>>8);
*(uart->baud_l) = (uint8_t)(baud_prescale); *(uart->baud_l) = (uint8_t)(baud_prescale);
*(uart->a) = uart->a_init; *(uart->a) = uart->a_init;
@ -61,38 +61,38 @@ void uart_init(struct Uart * uart, unsigned long baud) {
*(uart->c) = uart->c_init; *(uart->c) = uart->c_init;
} }
unsigned char uart_can_read(struct Uart * uart) { uint8_t uart_can_read(struct Uart * uart) {
return (*(uart->a)) & uart->a_read; return (*(uart->a)) & uart->a_read;
} }
unsigned char uart_read(struct Uart * uart) { uint8_t uart_read(struct Uart * uart) {
while (!uart_can_read(uart)) ; while (!uart_can_read(uart)) ;
return *(uart->data); return *(uart->data);
} }
unsigned char uart_can_write(struct Uart * uart) { uint8_t uart_can_write(struct Uart * uart) {
return (*(uart->a)) & uart->a_write; return (*(uart->a)) & uart->a_write;
} }
void uart_write(struct Uart * uart, unsigned char data) { void uart_write(struct Uart * uart, uint8_t data) {
while (!uart_can_write(uart)) ; while (!uart_can_write(uart)) ;
*(uart->data) = data; *(uart->data) = data;
} }
struct Uart * uart_stdio = NULL; struct Uart * uart_stdio = NULL;
int uart_stdio_get(FILE * stream) { int16_t uart_stdio_get(FILE * stream) {
return (int)uart_read(uart_stdio); return (int16_t)uart_read(uart_stdio);
} }
int uart_stdio_put(char data, FILE * stream) { int16_t uart_stdio_put(char data, FILE * stream) {
uart_write(uart_stdio, (unsigned char)data); uart_write(uart_stdio, (uint8_t)data);
return 0; return 0;
} }
FILE uart_stdio_file = FDEV_SETUP_STREAM(uart_stdio_put, uart_stdio_get, _FDEV_SETUP_RW); FILE uart_stdio_file = FDEV_SETUP_STREAM(uart_stdio_put, uart_stdio_get, _FDEV_SETUP_RW);
void uart_stdio_init(int num, unsigned long baud) { void uart_stdio_init(int16_t num, uint32_t baud) {
struct Uart * uart = uart_new(num); struct Uart * uart = uart_new(num);
if(uart != NULL) { if(uart != NULL) {
uart_init(uart, baud); uart_init(uart, baud);

View File

@ -4,17 +4,17 @@
#include <common/i2c.h> #include <common/i2c.h>
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { int16_t smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(NULL, address, command, (uint8_t *)data, 2); return i2c_get(NULL, address, command, (uint8_t *)data, 2);
} }
int smbus_write(uint8_t address, uint8_t command, uint16_t data) { int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(NULL, address, command, (uint8_t *)&data, 2); return i2c_set(NULL, address, command, (uint8_t *)&data, 2);
} }
void battery_debug(void) { void battery_debug(void) {
uint16_t data = 0; uint16_t data = 0;
int res = 0; int16_t res = 0;
#define command(N, A, V) { \ #define command(N, A, V) { \
printf(#N ": "); \ printf(#N ": "); \

View File

@ -5,7 +5,7 @@
#include <board/cpu.h> #include <board/cpu.h>
#include <board/i2c.h> #include <board/i2c.h>
void i2c_init(unsigned long baud) { void i2c_init(uint32_t baud) {
TWAR = 0; TWAR = 0;
TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2);
TWCR = 0; TWCR = 0;

View File

@ -3,6 +3,6 @@
#ifndef _BOARD_I2C_H #ifndef _BOARD_I2C_H
#define _BOARD_I2C_H #define _BOARD_I2C_H
void i2c_init(unsigned long baud); void i2c_init(uint32_t baud);
#endif // _BOARD_I2C_H #endif // _BOARD_I2C_H

View File

@ -12,7 +12,7 @@ void init(void) {
struct Gpio LED = GPIO(B, 7); struct Gpio LED = GPIO(B, 7);
//TODO: .h file //TODO: .h file
void parallel_main(void); int parallel_main(void);
int main(void) { int main(void) {
init(); init();

View File

@ -213,7 +213,7 @@ void parallel_write_data(struct Parallel * port, uint8_t byte) {
} }
//TODO: timeout //TODO: timeout
int parallel_transaction(struct Parallel * port, uint8_t * data, int length, bool read, bool addr) { int16_t parallel_transaction(struct Parallel * port, uint8_t * data, int16_t length, bool read, bool addr) {
if (!read) { if (!read) {
// Set write line low // Set write line low
gpio_set(port->write_n, false); gpio_set(port->write_n, false);
@ -222,7 +222,7 @@ int parallel_transaction(struct Parallel * port, uint8_t * data, int length, boo
parallel_data_forward(port); parallel_data_forward(port);
} }
int i; int16_t i;
uint8_t byte = 0; uint8_t byte = 0;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
// Wait for peripheral to indicate it's ready for next cycle // Wait for peripheral to indicate it's ready for next cycle
@ -333,8 +333,8 @@ static uint8_t SPI_ENABLE = 0xFE;
static uint8_t SPI_DATA = 0xFD; static uint8_t SPI_DATA = 0xFD;
// Disable chip // Disable chip
int parallel_spi_reset(struct Parallel *port) { int16_t parallel_spi_reset(struct Parallel *port) {
int res; int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1); res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
if (res < 0) return res; if (res < 0) return res;
@ -349,8 +349,8 @@ int parallel_spi_reset(struct Parallel *port) {
} }
// Enable chip and read or write data // Enable chip and read or write data
int parallel_spi_transaction(struct Parallel *port, uint8_t * data, int length, bool read) { int16_t parallel_spi_transaction(struct Parallel *port, uint8_t * data, int16_t length, bool read) {
int res; int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1); res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
if (res < 0) return res; if (res < 0) return res;
@ -368,10 +368,10 @@ int parallel_spi_transaction(struct Parallel *port, uint8_t * data, int length,
#define parallel_spi_write(P, D, L) parallel_spi_transaction(P, D, L, false) #define parallel_spi_write(P, D, L) parallel_spi_transaction(P, D, L, false)
// "Hardware" accelerated SPI programming, requires ECINDARs to be set // "Hardware" accelerated SPI programming, requires ECINDARs to be set
int parallel_spi_program(struct Parallel * port, uint8_t * data, int length, bool initialized) { int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t length, bool initialized) {
static uint8_t aai[6] = { 0xAD, 0, 0, 0, 0, 0 }; static uint8_t aai[6] = { 0xAD, 0, 0, 0, 0, 0 };
int res; int16_t res;
int i; int16_t i;
uint8_t status; uint8_t status;
for(i = 0; (i + 1) < length; i+=2) { for(i = 0; (i + 1) < length; i+=2) {
@ -420,13 +420,13 @@ int parallel_spi_program(struct Parallel * port, uint8_t * data, int length, boo
return i; return i;
} }
int serial_transaction(uint8_t * data, int length, bool read) { int16_t serial_transaction(uint8_t * data, int16_t length, bool read) {
int i; int16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (read) { if (read) {
data[i] = (uint8_t)uart_read(uart_stdio); data[i] = (uint8_t)uart_read(uart_stdio);
} else { } else {
uart_write(uart_stdio, (unsigned char)data[i]); uart_write(uart_stdio, (uint8_t)data[i]);
} }
} }
@ -437,20 +437,20 @@ int serial_transaction(uint8_t * data, int length, bool read) {
#define serial_write(D, L) serial_transaction(D, L, false) #define serial_write(D, L) serial_transaction(D, L, false)
int parallel_main(void) { int parallel_main(void) {
int res = 0; int16_t res = 0;
struct Parallel * port = &PORT; struct Parallel * port = &PORT;
parallel_state(port, PARALLEL_STATE_HIZ); parallel_state(port, PARALLEL_STATE_HIZ);
static uint8_t data[128]; static uint8_t data[128];
char command; char command;
int length; int16_t length;
int i; int16_t i;
uint8_t address; uint8_t address;
bool set_address = false; bool set_address = false;
bool program_aai = false; bool program_aai = false;
unsigned char console_msg[] = "Entering console mode\n"; uint8_t console_msg[] = "Entering console mode\n";
for (;;) { for (;;) {
// Read command and length // Read command and length
@ -471,7 +471,7 @@ int parallel_main(void) {
} }
// Length is received data + 1 // Length is received data + 1
length = ((int)data[1]) + 1; length = ((int16_t)data[1]) + 1;
// Truncate length to size of data // Truncate length to size of data
if (length > sizeof(data)) length = sizeof(data); if (length > sizeof(data)) length = sizeof(data);

View File

@ -4,17 +4,17 @@
#include <common/i2c.h> #include <common/i2c.h>
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { int16_t smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(NULL, address, command, (uint8_t *)data, 2); return i2c_get(NULL, address, command, (uint8_t *)data, 2);
} }
int smbus_write(uint8_t address, uint8_t command, uint16_t data) { int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(NULL, address, command, (uint8_t *)&data, 2); return i2c_set(NULL, address, command, (uint8_t *)&data, 2);
} }
void battery_debug(void) { void battery_debug(void) {
uint16_t data = 0; uint16_t data = 0;
int res = 0; int16_t res = 0;
#define command(N, A, V) { \ #define command(N, A, V) { \
printf(#N ": "); \ printf(#N ": "); \

View File

@ -5,7 +5,7 @@
#include <board/cpu.h> #include <board/cpu.h>
#include <board/i2c.h> #include <board/i2c.h>
void i2c_init(unsigned long baud) { void i2c_init(uint32_t baud) {
TWAR = 0; TWAR = 0;
TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2); TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2);
TWCR = 0; TWCR = 0;

View File

@ -3,6 +3,6 @@
#ifndef _BOARD_I2C_H #ifndef _BOARD_I2C_H
#define _BOARD_I2C_H #define _BOARD_I2C_H
void i2c_init(unsigned long baud); void i2c_init(uint32_t baud);
#endif // _BOARD_I2C_H #endif // _BOARD_I2C_H

View File

@ -12,7 +12,7 @@ void init(void) {
struct Gpio LED = GPIO(B, 5); struct Gpio LED = GPIO(B, 5);
//TODO: .h file //TODO: .h file
void parallel_main(void); int parallel_main(void);
int main(void) { int main(void) {
init(); init();

View File

@ -162,7 +162,7 @@ void parallel_write_data(struct Parallel * port, uint8_t byte) {
} }
//TODO: timeout //TODO: timeout
int parallel_transaction(struct Parallel * port, uint8_t * data, int length, bool read, bool addr) { int16_t parallel_transaction(struct Parallel * port, uint8_t * data, int16_t length, bool read, bool addr) {
if (!read) { if (!read) {
// Set write line low // Set write line low
gpio_set(port->write_n, false); gpio_set(port->write_n, false);
@ -171,7 +171,7 @@ int parallel_transaction(struct Parallel * port, uint8_t * data, int length, boo
parallel_data_forward(port); parallel_data_forward(port);
} }
int i; int16_t i;
uint8_t byte = 0; uint8_t byte = 0;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
// Wait for peripheral to indicate it's ready for next cycle // Wait for peripheral to indicate it's ready for next cycle
@ -278,8 +278,8 @@ static uint8_t SPI_ENABLE = 0xFE;
static uint8_t SPI_DATA = 0xFD; static uint8_t SPI_DATA = 0xFD;
// Disable chip // Disable chip
int parallel_spi_reset(struct Parallel *port) { int16_t parallel_spi_reset(struct Parallel *port) {
int res; int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1); res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
if (res < 0) return res; if (res < 0) return res;
@ -294,8 +294,8 @@ int parallel_spi_reset(struct Parallel *port) {
} }
// Enable chip and read or write data // Enable chip and read or write data
int parallel_spi_transaction(struct Parallel *port, uint8_t * data, int length, bool read) { int16_t parallel_spi_transaction(struct Parallel *port, uint8_t * data, int16_t length, bool read) {
int res; int16_t res;
res = parallel_set_address(port, &ADDRESS_INDAR1, 1); res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
if (res < 0) return res; if (res < 0) return res;
@ -313,10 +313,10 @@ int parallel_spi_transaction(struct Parallel *port, uint8_t * data, int length,
#define parallel_spi_write(P, D, L) parallel_spi_transaction(P, D, L, false) #define parallel_spi_write(P, D, L) parallel_spi_transaction(P, D, L, false)
// "Hardware" accelerated SPI programming, requires ECINDARs to be set // "Hardware" accelerated SPI programming, requires ECINDARs to be set
int parallel_spi_program(struct Parallel * port, uint8_t * data, int length, bool initialized) { int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t length, bool initialized) {
static uint8_t aai[6] = { 0xAD, 0, 0, 0, 0, 0 }; static uint8_t aai[6] = { 0xAD, 0, 0, 0, 0, 0 };
int res; int16_t res;
int i; int16_t i;
uint8_t status; uint8_t status;
for(i = 0; (i + 1) < length; i+=2) { for(i = 0; (i + 1) < length; i+=2) {
@ -365,13 +365,13 @@ int parallel_spi_program(struct Parallel * port, uint8_t * data, int length, boo
return i; return i;
} }
int serial_transaction(uint8_t * data, int length, bool read) { int16_t serial_transaction(uint8_t * data, int16_t length, bool read) {
int i; int16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (read) { if (read) {
data[i] = (uint8_t)uart_read(uart_stdio); data[i] = (uint8_t)uart_read(uart_stdio);
} else { } else {
uart_write(uart_stdio, (unsigned char)data[i]); uart_write(uart_stdio, (uint8_t)data[i]);
} }
} }
@ -381,21 +381,21 @@ int serial_transaction(uint8_t * data, int length, bool read) {
#define serial_read(D, L) serial_transaction(D, L, true) #define serial_read(D, L) serial_transaction(D, L, true)
#define serial_write(D, L) serial_transaction(D, L, false) #define serial_write(D, L) serial_transaction(D, L, false)
int parallel_main(void) { int16_t parallel_main(void) {
int res = 0; int16_t res = 0;
struct Parallel * port = &PORT; struct Parallel * port = &PORT;
parallel_reset(port, true); parallel_reset(port, true);
static uint8_t data[128]; static uint8_t data[128];
char command; char command;
int length; int16_t length;
int i; int16_t i;
uint8_t address; uint8_t address;
bool set_address = false; bool set_address = false;
bool program_aai = false; bool program_aai = false;
unsigned char console_msg[] = "Entering console mode\n"; uint8_t console_msg[] = "Entering console mode\n";
for (;;) { for (;;) {
// Read command and length // Read command and length
@ -416,7 +416,7 @@ int parallel_main(void) {
} }
// Length is received data + 1 // Length is received data + 1
length = ((int)data[1]) + 1; length = ((int16_t)data[1]) + 1;
// Truncate length to size of data // Truncate length to size of data
if (length > sizeof(data)) length = sizeof(data); if (length > sizeof(data)) length = sizeof(data);

View File

@ -49,7 +49,7 @@ bool battery_set_end_threshold(uint8_t value) {
/** /**
* Configure the charger based on charging threshold values. * Configure the charger based on charging threshold values.
*/ */
int battery_charger_configure(void) { int16_t battery_charger_configure(void) {
static bool should_charge = true; static bool should_charge = true;
if (battery_get_end_threshold() == BATTERY_END_DEFAULT) { if (battery_get_end_threshold() == BATTERY_END_DEFAULT) {
@ -85,7 +85,7 @@ uint16_t battery_design_capacity = 0;
uint16_t battery_design_voltage = 0; uint16_t battery_design_voltage = 0;
void battery_event(void) { void battery_event(void) {
int res = 0; int16_t res = 0;
#define command(N, V) { \ #define command(N, V) { \
res = smbus_read(BATTERY_ADDRESS, V, &N); \ res = smbus_read(BATTERY_ADDRESS, V, &N); \

View File

@ -21,8 +21,8 @@
// XXX: Assumption: ac_last is initialized high. // XXX: Assumption: ac_last is initialized high.
static bool charger_enabled = false; static bool charger_enabled = false;
int battery_charger_disable(void) { int16_t battery_charger_disable(void) {
int res = 0; int16_t res = 0;
if (!charger_enabled) return 0; if (!charger_enabled) return 0;
@ -53,8 +53,8 @@ int battery_charger_disable(void) {
return 0; return 0;
} }
int battery_charger_enable(void) { int16_t battery_charger_enable(void) {
int res = 0; int16_t res = 0;
if (charger_enabled) return 0; if (charger_enabled) return 0;
@ -93,7 +93,7 @@ void battery_charger_event(void) {
void battery_debug(void) { void battery_debug(void) {
uint16_t data = 0; uint16_t data = 0;
int res = 0; int16_t res = 0;
#define command(N, A, V) { \ #define command(N, A, V) { \
DEBUG(" " #N ": "); \ DEBUG(" " #N ": "); \

View File

@ -20,8 +20,8 @@
// XXX: Assumption: ac_last is initialized high. // XXX: Assumption: ac_last is initialized high.
static bool charger_enabled = false; static bool charger_enabled = false;
int battery_charger_disable(void) { int16_t battery_charger_disable(void) {
int res = 0; int16_t res = 0;
if (!charger_enabled) return 0; if (!charger_enabled) return 0;
@ -61,8 +61,8 @@ int battery_charger_disable(void) {
return 0; return 0;
} }
int battery_charger_enable(void) { int16_t battery_charger_enable(void) {
int res = 0; int16_t res = 0;
if (charger_enabled) return 0; if (charger_enabled) return 0;
@ -112,7 +112,7 @@ void battery_charger_event(void) {
void battery_debug(void) { void battery_debug(void) {
uint16_t data = 0; uint16_t data = 0;
int res = 0; int16_t res = 0;
#define command(N, A, V) { \ #define command(N, A, V) { \
DEBUG(" " #N ": "); \ DEBUG(" " #N ": "); \

View File

@ -66,7 +66,7 @@ uint8_t dgpu_get_fan_duty(void) {
if (power_state == POWER_STATE_S0 && gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) { if (power_state == POWER_STATE_S0 && gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
// Use I2CS if in S0 state // Use I2CS if in S0 state
int8_t rlts; int8_t rlts;
int res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1); int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1);
if (res == 1) { if (res == 1) {
dgpu_temp = (int16_t)rlts; dgpu_temp = (int16_t)rlts;
duty = fan_duty(&FAN, dgpu_temp); duty = fan_duty(&FAN, dgpu_temp);

View File

@ -26,7 +26,7 @@ void fan_reset(void) {
// Get duty cycle based on temperature, adapted from // Get duty cycle based on temperature, adapted from
// https://github.com/pop-os/system76-power/blob/master/src/fan.rs // 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 * fan, int16_t temp) __reentrant {
for (int i = 0; i < fan->points_size; i++) { for (int16_t i = 0; i < fan->points_size; i++) {
const struct FanPoint * cur = &fan->points[i]; const struct FanPoint * cur = &fan->points[i];
// If exactly the current temp, return the current duty // If exactly the current temp, return the current duty
@ -86,7 +86,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 * fan, uint8_t duty) __reentrant {
uint8_t lowest = duty; uint8_t lowest = duty;
int i; int16_t i;
for (i = 0; (i + 1) < fan->heatup_size; i++) { for (i = 0; (i + 1) < fan->heatup_size; i++) {
uint8_t value = fan->heatup[i + 1]; uint8_t value = fan->heatup[i + 1];
if (value < lowest) { if (value < lowest) {
@ -102,7 +102,7 @@ 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_cooldown(const struct Fan * fan, uint8_t duty) __reentrant {
uint8_t highest = duty; uint8_t highest = duty;
int i; int16_t i;
for (i = 0; (i + 1) < fan->cooldown_size; i++) { for (i = 0; (i + 1) < fan->cooldown_size; i++) {
uint8_t value = fan->cooldown[i + 1]; uint8_t value = fan->cooldown[i + 1];
if (value > highest) { if (value > highest) {

View File

@ -34,13 +34,13 @@ bool battery_set_start_threshold(uint8_t value);
uint8_t battery_get_end_threshold(void); uint8_t battery_get_end_threshold(void);
bool battery_set_end_threshold(uint8_t value); bool battery_set_end_threshold(uint8_t value);
int battery_charger_configure(void); int16_t battery_charger_configure(void);
void battery_event(void); void battery_event(void);
void battery_reset(void); void battery_reset(void);
// Defined by charger/*.c // Defined by charger/*.c
int battery_charger_disable(void); int16_t battery_charger_disable(void);
int battery_charger_enable(void); int16_t battery_charger_enable(void);
void battery_charger_event(void); void battery_charger_event(void);
void battery_debug(void); void battery_debug(void);

View File

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

View File

@ -9,7 +9,7 @@ extern bool peci_on;
extern int16_t peci_temp; extern int16_t peci_temp;
void peci_init(void); void peci_init(void);
int peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data); int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data);
uint8_t peci_get_fan_duty(void); uint8_t peci_get_fan_duty(void);
#endif // _BOARD_PECI_H #endif // _BOARD_PECI_H

View File

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

View File

@ -3,9 +3,11 @@
#ifndef _BOARD_SMFI_H #ifndef _BOARD_SMFI_H
#define _BOARD_SMFI_H #define _BOARD_SMFI_H
#include <stdint.h>
void smfi_init(void); void smfi_init(void);
void smfi_watchdog(void); void smfi_watchdog(void);
void smfi_event(void); void smfi_event(void);
void smfi_debug(unsigned char byte); void smfi_debug(uint8_t byte);
#endif // _BOARD_SMFI_H #endif // _BOARD_SMFI_H

View File

@ -3,7 +3,7 @@
#include <board/kbled.h> #include <board/kbled.h>
#include <common/macro.h> #include <common/macro.h>
static int LEVEL_I = 1; static int16_t LEVEL_I = 1;
static const uint8_t __code LEVELS[] = { static const uint8_t __code LEVELS[] = {
48, 48,
72, 72,
@ -13,7 +13,7 @@ static const uint8_t __code LEVELS[] = {
255 255
}; };
static int COLOR_I = 0; static int16_t COLOR_I = 0;
static const uint32_t __code COLORS[] = { static const uint32_t __code COLORS[] = {
0xFFFFFF, 0xFFFFFF,
0x0000FF, 0x0000FF,

View File

@ -15,7 +15,7 @@ void kbled_init(void) {
void kbled_reset(void) { void kbled_reset(void) {
uint8_t value = 0xE4; uint8_t value = 0xE4;
int res = i2c_set(&I2C_DGPU, 0x2D, 0xA0, &value, 1); int16_t res = i2c_set(&I2C_DGPU, 0x2D, 0xA0, &value, 1);
DEBUG("kbled_reset 0x2D: %d\n", res); DEBUG("kbled_reset 0x2D: %d\n", res);
//value = 0xC4; //value = 0xC4;

View File

@ -30,11 +30,11 @@ uint8_t kbscan_matrix[KM_OUT] = { 0 };
uint8_t sci_extra = 0; uint8_t sci_extra = 0;
static inline bool matrix_position_is_esc(int row, int col) { static inline bool matrix_position_is_esc(int16_t row, int16_t col) {
return (row == MATRIX_ESC_OUTPUT) && (col == MATRIX_ESC_INPUT); return (row == MATRIX_ESC_OUTPUT) && (col == MATRIX_ESC_INPUT);
} }
static inline bool matrix_position_is_fn(int row, int col) { static inline bool matrix_position_is_fn(int16_t row, int16_t col) {
return (row == MATRIX_FN_OUTPUT) && (col == MATRIX_FN_INPUT); return (row == MATRIX_FN_OUTPUT) && (col == MATRIX_FN_INPUT);
} }
@ -60,7 +60,7 @@ void kbscan_init(void) {
// Debounce time in milliseconds // Debounce time in milliseconds
#define DEBOUNCE_DELAY 15 #define DEBOUNCE_DELAY 15
static uint8_t kbscan_get_row(int i) { static uint8_t kbscan_get_row(int16_t i) {
// Report all keys as released when lid is closed // Report all keys as released when lid is closed
if (!lid_state) { if (!lid_state) {
return 0; return 0;
@ -118,7 +118,7 @@ static uint8_t kbscan_get_row(int i) {
} }
#if KM_NKEY #if KM_NKEY
static bool kbscan_has_ghost_in_row(int row, uint8_t rowdata) { static bool kbscan_has_ghost_in_row(int16_t row, uint8_t rowdata) {
// Use arguments // Use arguments
row = row; row = row;
rowdata = rowdata; rowdata = rowdata;
@ -129,7 +129,7 @@ static inline bool popcount_more_than_one(uint8_t rowdata) {
return rowdata & (rowdata - 1); return rowdata & (rowdata - 1);
} }
static uint8_t kbscan_get_real_keys(int row, uint8_t rowdata) { static uint8_t kbscan_get_real_keys(int16_t row, uint8_t rowdata) {
// Remove any "active" blanks from the matrix. // Remove any "active" blanks from the matrix.
uint8_t realdata = 0; uint8_t realdata = 0;
for (uint8_t col = 0; col < KM_IN; col++) { for (uint8_t col = 0; col < KM_IN; col++) {
@ -143,7 +143,7 @@ static uint8_t kbscan_get_real_keys(int row, uint8_t rowdata) {
return realdata; return realdata;
} }
static bool kbscan_has_ghost_in_row(int row, uint8_t rowdata) { static bool kbscan_has_ghost_in_row(int16_t row, uint8_t rowdata) {
rowdata = kbscan_get_real_keys(row, rowdata); rowdata = kbscan_get_real_keys(row, rowdata);
// 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.
@ -152,7 +152,7 @@ static bool kbscan_has_ghost_in_row(int row, uint8_t rowdata) {
} }
// Check against other rows to see if more than one column matches. // Check against other rows to see if more than one column matches.
for (int i = 0; i < KM_OUT; i++) { for (int16_t i = 0; i < KM_OUT; i++) {
uint8_t otherrow = kbscan_get_real_keys(i, kbscan_get_row(i)); uint8_t otherrow = kbscan_get_real_keys(i, kbscan_get_row(i));
if (i != row && popcount_more_than_one(otherrow & rowdata)) { if (i != row && popcount_more_than_one(otherrow & rowdata)) {
return true; return true;
@ -315,7 +315,7 @@ void kbscan_event(void) {
} }
} }
int i; int16_t i;
for (i = 0; i < KM_OUT; i++) { for (i = 0; i < KM_OUT; i++) {
uint8_t new = kbscan_get_row(i); uint8_t new = kbscan_get_row(i);
uint8_t last = kbscan_matrix[i]; uint8_t last = kbscan_matrix[i];
@ -331,7 +331,7 @@ void kbscan_event(void) {
} }
// A key was pressed or released // A key was pressed or released
int j; int16_t j;
for (j = 0; j < KM_IN; j++) { for (j = 0; j < KM_IN; j++) {
bool new_b = new & BIT(j); bool new_b = new & BIT(j);
bool last_b = last & BIT(j); bool last_b = last & BIT(j);

View File

@ -17,9 +17,9 @@ void keymap_init(void) {
} }
void keymap_load_default(void) { void keymap_load_default(void) {
for (int layer = 0; layer < KM_LAY; layer++) { for (int16_t layer = 0; layer < KM_LAY; layer++) {
for (int output = 0; output < KM_OUT; output++) { for (int16_t output = 0; output < KM_OUT; output++) {
for (int input = 0; input < KM_IN; input++) { for (int16_t input = 0; input < KM_IN; input++) {
DYNAMIC_KEYMAP[layer][output][input] = KEYMAP[layer][output][input]; DYNAMIC_KEYMAP[layer][output][input] = KEYMAP[layer][output][input];
} }
} }
@ -57,7 +57,7 @@ bool keymap_save_config(void) {
return flash_read_u16(CONFIG_ADDR) == CONFIG_SIGNATURE; return flash_read_u16(CONFIG_ADDR) == CONFIG_SIGNATURE;
} }
bool keymap_get(int layer, int output, int input, uint16_t * value) { bool keymap_get(int16_t layer, int16_t output, int16_t input, uint16_t * value) {
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) { if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
*value = DYNAMIC_KEYMAP[layer][output][input]; *value = DYNAMIC_KEYMAP[layer][output][input];
return true; return true;
@ -66,7 +66,7 @@ bool keymap_get(int layer, int output, int input, uint16_t * value) {
} }
} }
bool keymap_set(int layer, int output, int input, uint16_t value) { bool keymap_set(int16_t layer, int16_t output, int16_t input, uint16_t value) {
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) { if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
DYNAMIC_KEYMAP[layer][output][input] = value; DYNAMIC_KEYMAP[layer][output][input] = value;
return true; return true;

View File

@ -82,14 +82,14 @@ bool parallel_init(void) {
return parallel_wait_peripheral(STS_WAIT, 0); return parallel_wait_peripheral(STS_WAIT, 0);
} }
int parallel_write(uint8_t * data, int length) { int16_t parallel_write(uint8_t * data, int16_t length) {
// Assert nWRITE // Assert nWRITE
KSIGDAT &= ~CTL_WRITE; KSIGDAT &= ~CTL_WRITE;
// Set data lines as outputs // Set data lines as outputs
KSOLGOEN = 0xFF; KSOLGOEN = 0xFF;
int i; int16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
// Wait for peripheral to indicate it's ready for next cycle // Wait for peripheral to indicate it's ready for next cycle
if (!parallel_wait_peripheral(STS_WAIT, 0)) { if (!parallel_wait_peripheral(STS_WAIT, 0)) {

View File

@ -69,7 +69,7 @@ void peci_init(void) {
// Returns positive completion code on success, negative completion code or // Returns positive completion code on success, negative completion code or
// negative (0x1000 | status register) on PECI hardware error // negative (0x1000 | status register) on PECI hardware error
int peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) { int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
// Wait for completion // Wait for completion
while (HOSTAR & 1) {} while (HOSTAR & 1) {}
// Clear status // Clear status
@ -105,9 +105,9 @@ int peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
// Wait for completion // Wait for completion
while (HOSTAR & 1) {} while (HOSTAR & 1) {}
int status = (int)HOSTAR; int16_t status = (int16_t)HOSTAR;
if (status & BIT(1)) { if (status & BIT(1)) {
int cc = (int)HORDDR; int16_t cc = (int16_t)HORDDR;
if (cc & 0x80) { if (cc & 0x80) {
return -cc; return -cc;
} else { } else {

View File

@ -294,7 +294,7 @@ void power_on_s5(void) {
// Wait for SUSPWRDNACK validity // Wait for SUSPWRDNACK validity
tPLT01; tPLT01;
for (int i = 0; i < 5000; i++) { for (int16_t i = 0; i < 5000; i++) {
// If we reached S0, exit this loop // If we reached S0, exit this loop
update_power_state(); update_power_state();
if (power_state == POWER_STATE_S0) { if (power_state == POWER_STATE_S0) {
@ -361,9 +361,9 @@ void power_off_s5(void) {
static void power_peci_limit(bool ac) { static void power_peci_limit(bool ac) {
uint8_t watts = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC; uint8_t watts = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC;
// Retry, timeout errors happen occasionally // Retry, timeout errors happen occasionally
for (int i = 0; i < 16; i++) { for (int16_t i = 0; i < 16; i++) {
// Set PL4 using PECI // Set PL4 using PECI
int res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8); int16_t res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8);
DEBUG("power_peci_limit %d = %d\n", watts, res); DEBUG("power_peci_limit %d = %d\n", watts, res);
if (res == 0x40) { if (res == 0x40) {
break; break;
@ -466,7 +466,7 @@ void power_event(void) {
bool ps_new = gpio_get(&PWR_SW_N); bool ps_new = gpio_get(&PWR_SW_N);
if (!ps_new && ps_last) { if (!ps_new && ps_last) {
// Ensure press is not spurious // Ensure press is not spurious
for (int i = 0; i < 100; i++) { for (int16_t i = 0; i < 100; i++) {
delay_ms(1); delay_ms(1);
if (gpio_get(&PWR_SW_N) != ps_new) { if (gpio_get(&PWR_SW_N) != ps_new) {
DEBUG("%02X: Spurious press\n", main_cycle); DEBUG("%02X: Spurious press\n", main_cycle);

View File

@ -5,7 +5,7 @@
#include <board/smfi.h> #include <board/smfi.h>
int putchar(int c) { int putchar(int c) {
unsigned char byte = (unsigned char)c; uint8_t byte = (uint8_t)c;
smfi_debug(byte); smfi_debug(byte);
return (int)byte; return (int)byte;
} }

View File

@ -22,10 +22,10 @@ void smbus_init(void) {
i2c_reset(&I2C_SMBUS, true); i2c_reset(&I2C_SMBUS, true);
} }
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { int16_t smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2); return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2);
} }
int smbus_write(uint8_t address, uint8_t command, uint16_t data) { 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 *)&data, 2);
} }

View File

@ -71,7 +71,7 @@ static volatile uint8_t __xdata __at(0xF00) smfi_dbg[256];
#if !defined(__SCRATCH__) #if !defined(__SCRATCH__)
void smfi_init(void) { void smfi_init(void) {
int i; int16_t i;
// Clear command region // Clear command region
for (i = (SMFI_CMD_CMD + 1); i < ARRAY_SIZE(smfi_cmd); i++) { for (i = (SMFI_CMD_CMD + 1); i < ARRAY_SIZE(smfi_cmd); i++) {
@ -151,9 +151,9 @@ static enum Result cmd_fan_set(void) {
} }
static enum Result cmd_keymap_get(void) { static enum Result cmd_keymap_get(void) {
int layer = smfi_cmd[SMFI_CMD_DATA]; int16_t layer = smfi_cmd[SMFI_CMD_DATA];
int output = smfi_cmd[SMFI_CMD_DATA + 1]; int16_t output = smfi_cmd[SMFI_CMD_DATA + 1];
int input = smfi_cmd[SMFI_CMD_DATA + 2]; int16_t input = smfi_cmd[SMFI_CMD_DATA + 2];
uint16_t key = 0; uint16_t key = 0;
if (keymap_get(layer, output, input, &key)) { if (keymap_get(layer, output, input, &key)) {
smfi_cmd[SMFI_CMD_DATA + 3] = (uint8_t)key; smfi_cmd[SMFI_CMD_DATA + 3] = (uint8_t)key;
@ -165,9 +165,9 @@ static enum Result cmd_keymap_get(void) {
} }
static enum Result cmd_keymap_set(void) { static enum Result cmd_keymap_set(void) {
int layer = smfi_cmd[SMFI_CMD_DATA]; int16_t layer = smfi_cmd[SMFI_CMD_DATA];
int output = smfi_cmd[SMFI_CMD_DATA + 1]; int16_t output = smfi_cmd[SMFI_CMD_DATA + 1];
int input = smfi_cmd[SMFI_CMD_DATA + 2]; int16_t input = smfi_cmd[SMFI_CMD_DATA + 2];
uint16_t key = uint16_t key =
((uint16_t)smfi_cmd[SMFI_CMD_DATA + 3]) | ((uint16_t)smfi_cmd[SMFI_CMD_DATA + 3]) |
(((uint16_t)smfi_cmd[SMFI_CMD_DATA + 4]) << 8); (((uint16_t)smfi_cmd[SMFI_CMD_DATA + 4]) << 8);
@ -389,8 +389,8 @@ void smfi_event(void) {
} }
} }
void smfi_debug(unsigned char byte) { void smfi_debug(uint8_t byte) {
int tail = (int)smfi_dbg[SMFI_DBG_TAIL]; int16_t tail = (int16_t)smfi_dbg[SMFI_DBG_TAIL];
tail++; tail++;
if (tail >= ARRAY_SIZE(smfi_dbg)) { if (tail >= ARRAY_SIZE(smfi_dbg)) {
tail = SMFI_DBG_TAIL + 1; tail = SMFI_DBG_TAIL + 1;

View File

@ -17,7 +17,7 @@
#endif // PARALLEL_DEBUG #endif // PARALLEL_DEBUG
int putchar(int c) { int putchar(int c) {
unsigned char byte = (unsigned char)c; uint8_t byte = (uint8_t)c;
smfi_debug(byte); smfi_debug(byte);

View File

@ -2,8 +2,8 @@
#include <common/i2c.h> #include <common/i2c.h>
int i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentrant { int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant {
int res = 0; int16_t res = 0;
res = i2c_start(i2c, addr, true); res = i2c_start(i2c, addr, true);
if (res < 0) return res; if (res < 0) return res;
@ -16,8 +16,8 @@ int i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentr
return res; return res;
} }
int i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentrant { int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant {
int res = 0; int16_t res = 0;
res = i2c_start(i2c, addr, false); res = i2c_start(i2c, addr, false);
if (res < 0) return res; if (res < 0) return res;
@ -30,8 +30,8 @@ int i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentr
return res; return res;
} }
int i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int length) __reentrant { int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant {
int res = 0; int16_t res = 0;
res = i2c_start(i2c, addr, false); res = i2c_start(i2c, addr, false);
if (res < 0) return res; if (res < 0) return res;
@ -42,8 +42,8 @@ int i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int leng
return i2c_recv(i2c, addr, data, length); return i2c_recv(i2c, addr, data, length);
} }
int i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int length) __reentrant { int16_t i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant {
int res = 0; int16_t res = 0;
res = i2c_start(i2c, addr, false); res = i2c_start(i2c, addr, false);
if (res < 0) return res; if (res < 0) return res;

View File

@ -16,7 +16,7 @@ struct I2C;
// Start i2c transaction // Start i2c transaction
// Must be defined by arch, board, or ec // Must be defined by arch, board, or ec
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant; int16_t i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant;
// Stop i2c transaction // Stop i2c transaction
// Must be defined by arch, board, or ec // Must be defined by arch, board, or ec
@ -24,22 +24,22 @@ void i2c_stop(struct I2C * 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
int i2c_write(struct I2C * i2c, uint8_t * data, int length) __reentrant; int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_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
int i2c_read(struct I2C * i2c, uint8_t * data, int length) __reentrant; int16_t i2c_read(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant;
// Read multiple bytes from address in one transaction // Read multiple bytes from address in one transaction
int i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentrant; int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant;
// Write multiple bytes to address in one transaction // Write multiple bytes to address in one transaction
int i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int length) __reentrant; int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant;
// Read multiple bytes from a register in one transaction // Read multiple bytes from a register in one transaction
int i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int length) __reentrant; int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant;
// Write multiple bytes to a register in one transaction // Write multiple bytes to a register in one transaction
int i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int length) __reentrant; int16_t i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant;
#endif // _COMMON_I2C_H #endif // _COMMON_I2C_H

View File

@ -27,9 +27,9 @@
// Save dynamic keymap to flash // Save dynamic keymap to flash
bool keymap_save_config(void); bool keymap_save_config(void);
// Get a keycode from the dynamic keymap // Get a keycode from the dynamic keymap
bool keymap_get(int layer, int output, int input, uint16_t * value); bool keymap_get(int16_t layer, int16_t output, int16_t input, uint16_t * value);
// Set a keycode in the dynamic keymap // Set a keycode in the dynamic keymap
bool keymap_set(int layer, int output, int input, uint16_t value); bool keymap_set(int16_t layer, int16_t output, int16_t input, uint16_t value);
#endif #endif
// Translate a keycode from PS/2 set 2 to PS/2 set 1 // Translate a keycode from PS/2 set 2 to PS/2 set 1

View File

@ -57,7 +57,7 @@ void i2c_reset(struct I2C * i2c, bool kill) {
*(i2c->hoctl2) = 0; *(i2c->hoctl2) = 0;
} }
int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant { int16_t i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
// If we are already in a transaction // If we are already in a transaction
if (*(i2c->hosta) & HOSTA_BYTE_DONE) { if (*(i2c->hosta) & HOSTA_BYTE_DONE) {
// If we are switching direction // If we are switching direction
@ -94,8 +94,8 @@ void i2c_stop(struct I2C * i2c) {
i2c_reset(i2c, false); i2c_reset(i2c, false);
} }
static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool read) { static int16_t i2c_transaction(struct I2C * i2c, uint8_t * data, int16_t length, bool read) {
int i; int16_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (read) { if (read) {
// If last byte // If last byte
@ -131,7 +131,7 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
// If error occured, kill transaction and return error // If error occured, kill transaction and return error
if (status & HOSTA_ERR) { if (status & HOSTA_ERR) {
i2c_reset(i2c, true); i2c_reset(i2c, true);
return -(int)(status); return -(int16_t)(status);
} else } else
// If byte done, break // If byte done, break
if (status & HOSTA_BYTE_DONE) { if (status & HOSTA_BYTE_DONE) {
@ -141,7 +141,7 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
// If timeout occured, kill transaction and return error // If timeout occured, kill transaction and return error
if (timeout == 0) { if (timeout == 0) {
i2c_reset(i2c, true); i2c_reset(i2c, true);
return -(0x1000 | (int)status); return -(0x1000 | (int16_t)status);
} }
if (read) { if (read) {
@ -153,10 +153,10 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
return i; return i;
} }
int i2c_read(struct I2C * i2c, uint8_t * data, int length) __reentrant { int16_t i2c_read(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant {
return i2c_transaction(i2c, data, length, true); return i2c_transaction(i2c, data, length, true);
} }
int i2c_write(struct I2C * i2c, uint8_t * data, int length) __reentrant { int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant {
return i2c_transaction(i2c, data, length, false); return i2c_transaction(i2c, data, length, false);
} }

View File

@ -33,8 +33,8 @@ extern struct Kbc __code KBC;
uint8_t kbc_status(struct Kbc * kbc); uint8_t kbc_status(struct Kbc * kbc);
uint8_t kbc_read(struct Kbc * kbc); uint8_t kbc_read(struct Kbc * kbc);
bool kbc_keyboard(struct Kbc * kbc, uint8_t data, int timeout); bool kbc_keyboard(struct Kbc * kbc, uint8_t data, int16_t timeout);
bool kbc_mouse(struct Kbc * kbc, uint8_t data, int timeout); bool kbc_mouse(struct Kbc * kbc, uint8_t data, int16_t timeout);
volatile uint8_t __xdata __at(0x1300) KBHICR; volatile uint8_t __xdata __at(0x1300) KBHICR;
volatile uint8_t __xdata __at(0x1302) KBIRQR; volatile uint8_t __xdata __at(0x1302) KBIRQR;

View File

@ -20,7 +20,7 @@ uint8_t kbc_read(struct Kbc * kbc) {
return *(kbc->data_in); return *(kbc->data_in);
} }
static bool kbc_wait(struct Kbc * kbc, int timeout) { static bool kbc_wait(struct Kbc * kbc, int16_t timeout) {
while (*(kbc->status) & KBC_STS_OBF) { while (*(kbc->status) & KBC_STS_OBF) {
if (timeout == 0) return false; if (timeout == 0) return false;
timeout -= 1; timeout -= 1;
@ -29,14 +29,14 @@ static bool kbc_wait(struct Kbc * kbc, int timeout) {
return true; return true;
} }
bool kbc_keyboard(struct Kbc * kbc, uint8_t data, int timeout) { bool kbc_keyboard(struct Kbc * kbc, uint8_t data, int16_t timeout) {
if (!kbc_wait(kbc, timeout)) return false; if (!kbc_wait(kbc, timeout)) return false;
*(kbc->status) &= ~0x20; *(kbc->status) &= ~0x20;
*(kbc->keyboard_out) = data; *(kbc->keyboard_out) = data;
return true; return true;
} }
bool kbc_mouse(struct Kbc * kbc, uint8_t data, int timeout) { bool kbc_mouse(struct Kbc * kbc, uint8_t data, int16_t timeout) {
if (!kbc_wait(kbc, timeout)) return false; if (!kbc_wait(kbc, timeout)) return false;
*(kbc->status) |= 0x20; *(kbc->status) |= 0x20;
*(kbc->mouse_out) = data; *(kbc->mouse_out) = data;

View File

@ -4,13 +4,13 @@
#if EC_ESPI #if EC_ESPI
// eSPI signature (byte 7 = 0xA4) // eSPI signature (byte 7 = 0xA4)
static __code const unsigned char __at(0x40) SIGNATURE[16] = { static __code const uint8_t __at(0x40) SIGNATURE[16] = {
0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA4, 0x95, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA4, 0x95,
0x85, 0x12, 0x5A, 0x5A, 0xAA, 0x00, 0x55, 0x55, 0x85, 0x12, 0x5A, 0x5A, 0xAA, 0x00, 0x55, 0x55,
}; };
#else // EC_ESPI #else // EC_ESPI
// LPC signature (byte 7 = 0xA5) // LPC signature (byte 7 = 0xA5)
static __code const unsigned char __at(0x40) SIGNATURE[16] = { static __code const uint8_t __at(0x40) SIGNATURE[16] = {
0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0x94, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0x94,
0x85, 0x12, 0x5A, 0x5A, 0xAA, 0x00, 0x55, 0x55, 0x85, 0x12, 0x5A, 0x5A, 0xAA, 0x00, 0x55, 0x55,
}; };