Update .clang-format and apply
Update .clang-format for LLVM 14.0, available on Ubuntu 22.04. There is still plenty that clang-format sucks at or does wrong, so either add some more blocks to disable it, or just put up with it. Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
committed by
Jeremy Soller
parent
c3267fc4ad
commit
e032c5f0f2
@ -1,22 +1,25 @@
|
||||
# https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||
# https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||
# LLVM 14 used to support Ubuntu 22.04 LTS.
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveMacros: true
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveMacros: false
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: true
|
||||
AlignOperands: DontAlign
|
||||
AlignTrailingComments: false
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
@ -26,42 +29,45 @@ BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakAfterJavaFieldAnnotations: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakInheritanceList: AfterColon
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 96
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: true
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
IncludeBlocks: Preserve
|
||||
- 'foreach'
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
@ -72,14 +78,17 @@ IncludeCategories:
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainRegex: '(_test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: true
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseLabels: false
|
||||
IndentExternBlock: NoIndent
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: BeforeHash
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
InsertTrailingCommas: Wrapped
|
||||
JavaScriptQuotes: Double
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
@ -88,30 +97,29 @@ MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
|
||||
PenaltyBreakAssignment: 10
|
||||
PenaltyBreakBeforeFirstCallParameter: 10
|
||||
PenaltyBreakComment: 100
|
||||
PenaltyBreakFirstLessLess: 5
|
||||
PenaltyBreakString: 100
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakAssignment: 1000
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 5
|
||||
PenaltyReturnTypeOnItsOwnLine: 100
|
||||
|
||||
PointerAlignment: Middle
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: true
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParens: ControlStatementsExceptForEachMacros
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
@ -120,14 +128,14 @@ SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- ARRAY_SIZE
|
||||
- xstr
|
||||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- 'STRINGIZE'
|
||||
...
|
||||
|
@ -9,13 +9,11 @@ void delay_ticks(uint16_t ticks);
|
||||
|
||||
// 1 us * 9.2 MHz / 12 is 69/90
|
||||
// Warning: this will round to the nearest tick
|
||||
#define delay_us(X) \
|
||||
delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89UL) / 90UL));
|
||||
#define delay_us(X) delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89UL) / 90UL));
|
||||
|
||||
// 1 ns * 9.2 MHz / 12 is 69/90000
|
||||
// Warning: this will round to the nearest tick
|
||||
#define delay_ns(X) \
|
||||
delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89999UL) / 90000UL));
|
||||
#define delay_ns(X) delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89999UL) / 90000UL));
|
||||
|
||||
void delay_ms(uint8_t ms);
|
||||
|
||||
|
@ -19,11 +19,14 @@ int16_t i2c_start(struct I2C * i2c, uint8_t addr, bool read) {
|
||||
TWCR = BIT(TWINT) | BIT(TWSTA) | BIT(TWEN);
|
||||
// wait for end of transmission
|
||||
count = TIMEOUT;
|
||||
while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1;
|
||||
if (count == 0) return -1;
|
||||
while (!(TWCR & BIT(TWINT)) && count > 0)
|
||||
count -= 1;
|
||||
if (count == 0)
|
||||
return -1;
|
||||
|
||||
// check if the start condition was successfully transmitted
|
||||
if((TWSR & 0xF8) != TW_START) return -1;
|
||||
if ((TWSR & 0xF8) != TW_START)
|
||||
return -1;
|
||||
|
||||
// load slave addr into data register
|
||||
TWDR = ((addr << 1) | read);
|
||||
@ -31,12 +34,15 @@ int16_t i2c_start(struct I2C * i2c, uint8_t addr, bool read) {
|
||||
TWCR = BIT(TWINT) | BIT(TWEN);
|
||||
// wait for end of transmission
|
||||
count = TIMEOUT;
|
||||
while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1;
|
||||
if (count == 0) return -1;
|
||||
while (!(TWCR & BIT(TWINT)) && count > 0)
|
||||
count -= 1;
|
||||
if (count == 0)
|
||||
return -1;
|
||||
|
||||
// check if the device has acknowledged the READ / WRITE mode
|
||||
uint8_t twst = TW_STATUS & 0xF8;
|
||||
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) return -1;
|
||||
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -55,11 +61,14 @@ int16_t i2c_write(struct I2C * i2c, uint8_t * data, uint16_t length) {
|
||||
TWCR = BIT(TWINT) | BIT(TWEN);
|
||||
// wait for end of transmission
|
||||
uint32_t count = TIMEOUT;
|
||||
while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1;
|
||||
while (!(TWCR & BIT(TWINT)) && count > 0)
|
||||
count -= 1;
|
||||
// timed out
|
||||
if (count == 0) return -1;
|
||||
if (count == 0)
|
||||
return -1;
|
||||
// failed to receive ack
|
||||
if((TWSR & 0xF8) != TW_MT_DATA_ACK) return -1;
|
||||
if ((TWSR & 0xF8) != TW_MT_DATA_ACK)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return i;
|
||||
@ -77,8 +86,10 @@ int16_t i2c_read(struct I2C * i2c, uint8_t * data, uint16_t length) {
|
||||
}
|
||||
// wait for end of transmission
|
||||
uint32_t count = TIMEOUT;
|
||||
while(!(TWCR & BIT(TWINT)) && count > 0) count -= 1;
|
||||
if (count == 0) return -1;
|
||||
while (!(TWCR & BIT(TWINT)) && count > 0)
|
||||
count -= 1;
|
||||
if (count == 0)
|
||||
return -1;
|
||||
// return received data from TWDR
|
||||
data[i] = TWDR;
|
||||
}
|
||||
|
@ -15,7 +15,12 @@ static void (* volatile i2c_slave_new_cb)() = NULL;
|
||||
static void (*volatile i2c_slave_recv_cb)(uint8_t) = NULL;
|
||||
static uint8_t (*volatile i2c_slave_send_cb)() = NULL;
|
||||
|
||||
void i2c_slave_init(uint8_t address, void (*new_cb)(), void (*recv_cb)(uint8_t), uint8_t (*send_cb)()){
|
||||
void i2c_slave_init(
|
||||
uint8_t address,
|
||||
void (*new_cb)(),
|
||||
void (*recv_cb)(uint8_t),
|
||||
uint8_t (*send_cb)()
|
||||
) {
|
||||
// ensure correct behavior by stopping before changing callbacks or address
|
||||
i2c_slave_stop();
|
||||
|
||||
|
@ -3,7 +3,12 @@
|
||||
#ifndef _ARCH_I2C_SLAVE_H
|
||||
#define _ARCH_I2C_SLAVE_H
|
||||
|
||||
void i2c_slave_init(uint8_t address, void (*new_cb)(), void (*recv_cb)(uint8_t), uint8_t (*send_cb)());
|
||||
void i2c_slave_init(
|
||||
uint8_t address,
|
||||
void (*new_cb)(),
|
||||
void (*recv_cb)(uint8_t),
|
||||
uint8_t (*send_cb)()
|
||||
);
|
||||
void i2c_slave_stop();
|
||||
|
||||
#endif // _ARCH_I2C_SLAVE_H
|
||||
|
@ -68,7 +68,7 @@ uint8_t uart_can_read(struct Uart * uart) {
|
||||
}
|
||||
|
||||
uint8_t uart_read(struct Uart *uart) {
|
||||
while (!uart_can_read(uart)) ;
|
||||
while (!uart_can_read(uart)) {}
|
||||
return *(uart->data);
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ uint8_t uart_can_write(struct Uart * uart) {
|
||||
}
|
||||
|
||||
void uart_write(struct Uart *uart, uint8_t data) {
|
||||
while (!uart_can_write(uart)) ;
|
||||
while (!uart_can_write(uart)) {}
|
||||
*(uart->data) = data;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@ void battery_debug(void) {
|
||||
uint16_t data = 0;
|
||||
int16_t res = 0;
|
||||
|
||||
#define command(N, A, V) { \
|
||||
#define command(N, A, V) \
|
||||
{ \
|
||||
printf(#N ": "); \
|
||||
res = smbus_read(A, V, &data); \
|
||||
if (res < 0) { \
|
||||
|
@ -89,7 +89,6 @@ static struct Gpio GPIOS[24] = {
|
||||
GPIO(A, 0), GPIO(A, 1),
|
||||
};
|
||||
#endif // !defined(FLIP)
|
||||
// clang-format on
|
||||
|
||||
enum ParallelState {
|
||||
PARALLEL_STATE_UNKNOWN,
|
||||
@ -115,6 +114,8 @@ static struct Parallel PORT = {
|
||||
.state = PARALLEL_STATE_UNKNOWN,
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
// Set port to all high-impedance inputs
|
||||
void parallel_hiz(struct Parallel *port) {
|
||||
#define PIN(N, P) \
|
||||
@ -135,7 +136,9 @@ void parallel_data_dir(struct Parallel * port, bool dir) {
|
||||
|
||||
void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) if (!(byte & (1 << B))) gpio_set(port->d ## B, true);
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, true);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
@ -201,7 +204,9 @@ void parallel_state(struct Parallel * port, enum ParallelState state) {
|
||||
|
||||
uint8_t parallel_read_data(struct Parallel *port) {
|
||||
uint8_t byte = 0;
|
||||
#define DATA_BIT(B) if (gpio_get(port->d ## B)) byte |= (1 << B);
|
||||
#define DATA_BIT(B) \
|
||||
if (gpio_get(port->d##B)) \
|
||||
byte |= (1 << B);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
return byte;
|
||||
@ -209,13 +214,22 @@ uint8_t parallel_read_data(struct Parallel * port) {
|
||||
|
||||
void parallel_write_data(struct Parallel *port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) if (!(byte & (1 << B))) gpio_set(port->d ## B, false);
|
||||
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, false);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
|
||||
//TODO: timeout
|
||||
int16_t parallel_transaction(struct Parallel * port, uint8_t * data, int16_t length, bool read, bool addr) {
|
||||
int16_t parallel_transaction(
|
||||
struct Parallel *port,
|
||||
uint8_t *data,
|
||||
int16_t length,
|
||||
bool read,
|
||||
bool addr
|
||||
) {
|
||||
if (!read) {
|
||||
// Set write line low
|
||||
gpio_set(port->write_n, false);
|
||||
@ -341,19 +355,24 @@ int16_t parallel_ecms_read(struct Parallel *port, uint16_t addr, uint8_t * data,
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_ECMSADDR1, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_write(port, ((uint8_t *)&addr) + 1, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_ECMSADDR0, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_write(port, (uint8_t *)&addr, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_ECMSDATA, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return parallel_read(port, data, length);
|
||||
}
|
||||
@ -363,13 +382,16 @@ int16_t parallel_spi_reset(struct Parallel *port) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_write(port, &SPI_ENABLE, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDDR, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return parallel_write(port, &ZERO, 1);
|
||||
}
|
||||
@ -379,13 +401,16 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t * data, int16_t
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_write(port, &SPI_DATA, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDDR, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return parallel_transaction(port, data, length, read, false);
|
||||
}
|
||||
@ -394,7 +419,12 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t * data, int16_t
|
||||
#define parallel_spi_write(P, D, L) parallel_spi_transaction(P, D, L, false)
|
||||
|
||||
// "Hardware" accelerated SPI programming, requires ECINDARs to be set
|
||||
int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t 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 };
|
||||
int16_t res;
|
||||
int16_t i;
|
||||
@ -403,7 +433,8 @@ int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t len
|
||||
for (i = 0; (i + 1) < length; i += 2) {
|
||||
// Disable chip to begin command
|
||||
res = parallel_spi_reset(port);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
if (!initialized) {
|
||||
// If not initialized, the start address must be sent
|
||||
@ -415,7 +446,8 @@ int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t len
|
||||
aai[5] = data[i + 1];
|
||||
|
||||
res = parallel_spi_write(port, aai, 6);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
initialized = true;
|
||||
} else {
|
||||
@ -423,23 +455,28 @@ int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t len
|
||||
aai[2] = data[i + 1];
|
||||
|
||||
res = parallel_spi_write(port, aai, 3);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
|
||||
// Wait for SPI busy flag to clear
|
||||
for (;;) {
|
||||
// Disable chip to begin command
|
||||
res = parallel_spi_reset(port);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
status = 0x05;
|
||||
res = parallel_spi_write(port, &status, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_spi_read(port, &status, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
if (!(status & 1)) break;
|
||||
if (!(status & 1))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +518,8 @@ int parallel_main(void) {
|
||||
for (;;) {
|
||||
// Read command and length
|
||||
res = serial_read(data, 2);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
// Command is a character
|
||||
command = (char)data[0];
|
||||
|
||||
@ -499,7 +537,8 @@ int parallel_main(void) {
|
||||
// Length is received data + 1
|
||||
length = ((int16_t)data[1]) + 1;
|
||||
// Truncate length to size of data
|
||||
if (length > sizeof(data)) length = sizeof(data);
|
||||
if (length > sizeof(data))
|
||||
length = sizeof(data);
|
||||
|
||||
switch (command) {
|
||||
// Buffer size
|
||||
@ -515,7 +554,8 @@ int parallel_main(void) {
|
||||
|
||||
// Write data to serial
|
||||
res = serial_write(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -532,7 +572,8 @@ int parallel_main(void) {
|
||||
if (parallel_peripheral_cycle(port, data, &read, &addr)) {
|
||||
if (!read && !addr) {
|
||||
res = serial_write(data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -543,11 +584,13 @@ int parallel_main(void) {
|
||||
case 'E':
|
||||
// Read data from serial
|
||||
res = serial_read(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Write data to serial
|
||||
res = serial_write(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -562,7 +605,8 @@ int parallel_main(void) {
|
||||
for (;;) {
|
||||
// Read current position
|
||||
res = parallel_ecms_read(port, 0xF00, data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
uint16_t tail = (uint16_t)data[0];
|
||||
if (tail == 0 || head == tail) {
|
||||
@ -578,11 +622,14 @@ int parallel_main(void) {
|
||||
|
||||
while (head != tail) {
|
||||
head += 1;
|
||||
if (head >= 256) { head = 1; }
|
||||
if (head >= 256) {
|
||||
head = 1;
|
||||
}
|
||||
|
||||
// Read byte at head
|
||||
res = parallel_ecms_read(port, 0xF00 + head, data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Print read byte
|
||||
serial_write(data, 1);
|
||||
@ -598,17 +645,20 @@ int parallel_main(void) {
|
||||
// Update parallel address if necessary
|
||||
if (set_address) {
|
||||
res = parallel_set_address(port, &address, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
set_address = false;
|
||||
}
|
||||
|
||||
// Read data from parallel
|
||||
res = parallel_read(port, data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Write data to serial
|
||||
res = serial_write(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -618,17 +668,20 @@ int parallel_main(void) {
|
||||
|
||||
// Read data from serial
|
||||
res = serial_read(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Run accelerated programming function
|
||||
res = parallel_spi_program(port, data, length, program_aai);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
program_aai = true;
|
||||
|
||||
// Send ACK of data length
|
||||
data[0] = (uint8_t)(length - 1);
|
||||
res = serial_write(data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -638,23 +691,27 @@ int parallel_main(void) {
|
||||
|
||||
// Read data from serial
|
||||
res = serial_read(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Update parallel address if necessary
|
||||
if (set_address) {
|
||||
res = parallel_set_address(port, &address, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
set_address = false;
|
||||
}
|
||||
|
||||
// Write data to parallel
|
||||
res = parallel_write(port, data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Send ACK of data length
|
||||
data[0] = (uint8_t)(length - 1);
|
||||
res = serial_write(data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ void battery_debug(void) {
|
||||
uint16_t data = 0;
|
||||
int16_t res = 0;
|
||||
|
||||
#define command(N, A, V) { \
|
||||
#define command(N, A, V) \
|
||||
{ \
|
||||
printf(#N ": "); \
|
||||
res = smbus_read(A, V, &data); \
|
||||
if (res < 0) { \
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <arch/uart.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
// Mapping of 24-pin ribbon cable to parallel pins. See schematic
|
||||
#define PINS \
|
||||
/* Data (KSO0 - KSO7) - bi-directional */ \
|
||||
@ -65,6 +66,7 @@ static struct Gpio GPIOS[13] = {
|
||||
GPIO(C, 1),
|
||||
GPIO(C, 0),
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
// Parallel struct definition
|
||||
@ -102,7 +104,9 @@ void parallel_data_dir(struct Parallel * port, bool dir) {
|
||||
|
||||
void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) if (!(byte & (1 << B))) gpio_set(port->d ## B, true);
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, true);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
@ -149,7 +153,9 @@ void parallel_reset(struct Parallel * port, bool host) {
|
||||
|
||||
uint8_t parallel_read_data(struct Parallel *port) {
|
||||
uint8_t byte = 0;
|
||||
#define DATA_BIT(B) if (gpio_get(port->d ## B)) byte |= (1 << B);
|
||||
#define DATA_BIT(B) \
|
||||
if (gpio_get(port->d##B)) \
|
||||
byte |= (1 << B);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
return byte;
|
||||
@ -157,13 +163,21 @@ uint8_t parallel_read_data(struct Parallel * port) {
|
||||
|
||||
void parallel_write_data(struct Parallel *port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) if (!(byte & (1 << B))) gpio_set(port->d ## B, false);
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, false);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
|
||||
//TODO: timeout
|
||||
int16_t parallel_transaction(struct Parallel * port, uint8_t * data, int16_t length, bool read, bool addr) {
|
||||
int16_t parallel_transaction(
|
||||
struct Parallel *port,
|
||||
uint8_t *data,
|
||||
int16_t length,
|
||||
bool read,
|
||||
bool addr
|
||||
) {
|
||||
if (!read) {
|
||||
// Set write line low
|
||||
gpio_set(port->write_n, false);
|
||||
@ -283,13 +297,16 @@ int16_t parallel_spi_reset(struct Parallel *port) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_write(port, &SPI_ENABLE, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDDR, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return parallel_write(port, &ZERO, 1);
|
||||
}
|
||||
@ -299,13 +316,16 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t * data, int16_t
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_write(port, &SPI_DATA, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDDR, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return parallel_transaction(port, data, length, read, false);
|
||||
}
|
||||
@ -314,7 +334,12 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t * data, int16_t
|
||||
#define parallel_spi_write(P, D, L) parallel_spi_transaction(P, D, L, false)
|
||||
|
||||
// "Hardware" accelerated SPI programming, requires ECINDARs to be set
|
||||
int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t 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 };
|
||||
int16_t res;
|
||||
int16_t i;
|
||||
@ -323,7 +348,8 @@ int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t len
|
||||
for (i = 0; (i + 1) < length; i += 2) {
|
||||
// Disable chip to begin command
|
||||
res = parallel_spi_reset(port);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
if (!initialized) {
|
||||
// If not initialized, the start address must be sent
|
||||
@ -335,7 +361,8 @@ int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t len
|
||||
aai[5] = data[i + 1];
|
||||
|
||||
res = parallel_spi_write(port, aai, 6);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
initialized = true;
|
||||
} else {
|
||||
@ -343,23 +370,28 @@ int16_t parallel_spi_program(struct Parallel * port, uint8_t * data, int16_t len
|
||||
aai[2] = data[i + 1];
|
||||
|
||||
res = parallel_spi_write(port, aai, 3);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
}
|
||||
|
||||
// Wait for SPI busy flag to clear
|
||||
for (;;) {
|
||||
// Disable chip to begin command
|
||||
res = parallel_spi_reset(port);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
status = 0x05;
|
||||
res = parallel_spi_write(port, &status, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = parallel_spi_read(port, &status, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
if (!(status & 1)) break;
|
||||
if (!(status & 1))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,7 +433,8 @@ int16_t parallel_main(void) {
|
||||
for (;;) {
|
||||
// Read command and length
|
||||
res = serial_read(data, 2);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
// Command is a character
|
||||
command = (char)data[0];
|
||||
|
||||
@ -419,7 +452,8 @@ int16_t parallel_main(void) {
|
||||
// Length is received data + 1
|
||||
length = ((int16_t)data[1]) + 1;
|
||||
// Truncate length to size of data
|
||||
if (length > sizeof(data)) length = sizeof(data);
|
||||
if (length > sizeof(data))
|
||||
length = sizeof(data);
|
||||
|
||||
switch (command) {
|
||||
// Buffer size
|
||||
@ -435,7 +469,8 @@ int16_t parallel_main(void) {
|
||||
|
||||
// Write data to serial
|
||||
res = serial_write(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -453,7 +488,8 @@ int16_t parallel_main(void) {
|
||||
|
||||
if (ret && !read && !addr) {
|
||||
res = serial_write(data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,11 +499,13 @@ int16_t parallel_main(void) {
|
||||
case 'E':
|
||||
// Read data from serial
|
||||
res = serial_read(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Write data to serial
|
||||
res = serial_write(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -476,17 +514,20 @@ int16_t parallel_main(void) {
|
||||
// Update parallel address if necessary
|
||||
if (set_address) {
|
||||
res = parallel_set_address(port, &address, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
set_address = false;
|
||||
}
|
||||
|
||||
// Read data from parallel
|
||||
res = parallel_read(port, data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Write data to serial
|
||||
res = serial_write(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -494,17 +535,20 @@ int16_t parallel_main(void) {
|
||||
case 'P':
|
||||
// Read data from serial
|
||||
res = serial_read(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Run accelerated programming function
|
||||
res = parallel_spi_program(port, data, length, program_aai);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
program_aai = true;
|
||||
|
||||
// Send ACK of data length
|
||||
data[0] = (uint8_t)(length - 1);
|
||||
res = serial_write(data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
|
||||
@ -512,23 +556,27 @@ int16_t parallel_main(void) {
|
||||
case 'W':
|
||||
// Read data from serial
|
||||
res = serial_read(data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Update parallel address if necessary
|
||||
if (set_address) {
|
||||
res = parallel_set_address(port, &address, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
set_address = false;
|
||||
}
|
||||
|
||||
// Write data to parallel
|
||||
res = parallel_write(port, data, length);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
// Send ACK of data length
|
||||
data[0] = (uint8_t)(length - 1);
|
||||
res = serial_write(data, 1);
|
||||
if (res < 0) goto err;
|
||||
if (res < 0)
|
||||
goto err;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -40,11 +40,13 @@ void fcommand(void) {
|
||||
break;
|
||||
// Set LED color
|
||||
case 0x03:
|
||||
// clang-format off
|
||||
kbled_set_color(
|
||||
((uint32_t)fbuf[0]) |
|
||||
((uint32_t)fbuf[1] << 16) |
|
||||
((uint32_t)fbuf[2] << 8)
|
||||
);
|
||||
// clang-format on
|
||||
break;
|
||||
// Set LED brightness
|
||||
case 0x06:
|
||||
|
@ -57,16 +57,13 @@ int16_t battery_charger_configure(void) {
|
||||
if (battery_get_end_threshold() == BATTERY_END_DEFAULT) {
|
||||
// Stop threshold not configured: Always charge on AC.
|
||||
should_charge = true;
|
||||
}
|
||||
else if (battery_info.charge > battery_get_end_threshold()) {
|
||||
} else if (battery_info.charge > battery_get_end_threshold()) {
|
||||
// Stop threshold configured: Stop charging at threshold.
|
||||
should_charge = false;
|
||||
}
|
||||
else if (battery_get_start_threshold() == BATTERY_START_DEFAULT) {
|
||||
} else if (battery_get_start_threshold() == BATTERY_START_DEFAULT) {
|
||||
// Start threshold not configured: Always charge up to stop threshold.
|
||||
should_charge = true;
|
||||
}
|
||||
else if (battery_info.charge < battery_get_start_threshold()) {
|
||||
} else if (battery_info.charge < battery_get_start_threshold()) {
|
||||
// Start threshold configured: Start charging at threshold.
|
||||
should_charge = true;
|
||||
}
|
||||
@ -79,7 +76,8 @@ int16_t battery_charger_configure(void) {
|
||||
void battery_event(void) {
|
||||
int16_t res = 0;
|
||||
|
||||
#define command(N, V) { \
|
||||
#define command(N, V) \
|
||||
{ \
|
||||
res = smbus_read(BATTERY_ADDRESS, V, &N); \
|
||||
if (res < 0) { \
|
||||
N = 0; \
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <common/macro.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
// Registers
|
||||
#define REG_CHARGE_CURRENT 0x14
|
||||
#define REG_CHARGE_VOLTAGE 0x15
|
||||
@ -40,7 +42,6 @@
|
||||
// Battery depletion threshold
|
||||
#define SBC_BAT_DEPL_VTH (0b11 << 14)
|
||||
|
||||
|
||||
// Bits 0-5 are ignored. Bits 13-15 must be 0.
|
||||
#define CHARGE_CURRENT_MASK 0x1FC0
|
||||
|
||||
@ -85,35 +86,38 @@
|
||||
#error Invalid adapter:battery RSENSE ratio
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
// XXX: Assumption: ac_last is initialized high.
|
||||
static bool charger_enabled = false;
|
||||
|
||||
int16_t battery_charger_disable(void) {
|
||||
int16_t res = 0;
|
||||
|
||||
if (!charger_enabled) return 0;
|
||||
if (!charger_enabled)
|
||||
return 0;
|
||||
|
||||
// Set charge option 0 with 175s watchdog
|
||||
res = smbus_write(
|
||||
CHARGER_ADDRESS,
|
||||
REG_CHARGE_OPTION_0,
|
||||
SBC_EN_LWPWR |
|
||||
SBC_WDTMR_ADJ_175S |
|
||||
SBC_PWM_FREQ_800KHZ |
|
||||
SBC_IDCHC_GAIN
|
||||
SBC_EN_LWPWR | SBC_WDTMR_ADJ_175S | SBC_PWM_FREQ_800KHZ | SBC_IDCHC_GAIN
|
||||
);
|
||||
|
||||
// Disable charge current
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_CURRENT, 0);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Disable charge voltage
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_VOLTAGE, 0);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Disable input current
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_INPUT_CURRENT, 0);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
DEBUG("Charger disabled\n");
|
||||
charger_enabled = false;
|
||||
@ -123,40 +127,40 @@ int16_t battery_charger_disable(void) {
|
||||
int16_t battery_charger_enable(void) {
|
||||
int16_t res = 0;
|
||||
|
||||
if (charger_enabled) return 0;
|
||||
if (charger_enabled)
|
||||
return 0;
|
||||
|
||||
res = battery_charger_disable();
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge current in mA
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_CURRENT, CHARGE_CURRENT);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge voltage in mV
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_VOLTAGE, CHARGE_VOLTAGE);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set input current in mA
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_INPUT_CURRENT, INPUT_CURRENT);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge option 0 with watchdog disabled
|
||||
res = smbus_write(
|
||||
CHARGER_ADDRESS,
|
||||
REG_CHARGE_OPTION_0,
|
||||
SBC_EN_LWPWR |
|
||||
SBC_PWM_FREQ_800KHZ |
|
||||
SBC_IDCHC_GAIN
|
||||
SBC_EN_LWPWR | SBC_PWM_FREQ_800KHZ | SBC_IDCHC_GAIN
|
||||
);
|
||||
|
||||
// Set the RSENSE ratio
|
||||
res = smbus_write(
|
||||
CHARGER_ADDRESS,
|
||||
REG_CHARGE_OPTION_1,
|
||||
SBC_CMP_DEG_1US |
|
||||
SBC_PMON_RATIO |
|
||||
RSENSE_RATIO |
|
||||
SBC_BAT_DEPL_VTH
|
||||
SBC_CMP_DEG_1US | SBC_PMON_RATIO | RSENSE_RATIO | SBC_BAT_DEPL_VTH
|
||||
);
|
||||
|
||||
DEBUG("Charger enabled\n");
|
||||
@ -172,7 +176,8 @@ void battery_debug(void) {
|
||||
uint16_t data = 0;
|
||||
int16_t res = 0;
|
||||
|
||||
#define command(N, A, V) { \
|
||||
#define command(N, A, V) \
|
||||
{ \
|
||||
DEBUG(" " #N ": "); \
|
||||
res = smbus_read(A, V, &data); \
|
||||
if (res < 0) { \
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <common/debug.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
// Registers
|
||||
#define REG_CHARGE_CURRENT 0x14
|
||||
#define REG_CHARGE_VOLTAGE 0x15
|
||||
@ -54,6 +56,8 @@
|
||||
#error Invalid adapter RSENSE value
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
// Sense resistor values in milliohms.
|
||||
enum sense_resistor {
|
||||
RSENSE_10 = 0,
|
||||
@ -67,7 +71,8 @@ static bool charger_enabled = false;
|
||||
int16_t battery_charger_disable(void) {
|
||||
int16_t res = 0;
|
||||
|
||||
if (!charger_enabled) return 0;
|
||||
if (!charger_enabled)
|
||||
return 0;
|
||||
|
||||
// Set charge option 1 to converter frequency 600 KHz
|
||||
//TODO: needed when charging disabled?
|
||||
@ -76,29 +81,30 @@ int16_t battery_charger_disable(void) {
|
||||
REG_CHARGE_OPTION_1,
|
||||
CHARGE_OPTION_1_600KHZ | ADAPTER_RSENSE | BATTERY_RSENSE
|
||||
);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge option 2 to PSYS enable
|
||||
//TODO: needed when charging disabled?
|
||||
res = smbus_write(
|
||||
CHARGER_ADDRESS,
|
||||
REG_CHARGE_OPTION_2,
|
||||
CHARGE_OPTION_2_PSYS_EN
|
||||
);
|
||||
if (res < 0) return res;
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_OPTION_2, CHARGE_OPTION_2_PSYS_EN);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Disable charge current
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_CURRENT, 0);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Disable charge voltage
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_VOLTAGE, 0);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set input current in mA
|
||||
//TODO: needed when charging disabled?
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_ADAPTER_CURRENT, INPUT_CURRENT);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
DEBUG("Charger disabled\n");
|
||||
charger_enabled = false;
|
||||
@ -108,10 +114,12 @@ int16_t battery_charger_disable(void) {
|
||||
int16_t battery_charger_enable(void) {
|
||||
int16_t res = 0;
|
||||
|
||||
if (charger_enabled) return 0;
|
||||
if (charger_enabled)
|
||||
return 0;
|
||||
|
||||
res = battery_charger_disable();
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge option 1 to converter frequency 600 KHz
|
||||
res = smbus_write(
|
||||
@ -119,27 +127,28 @@ int16_t battery_charger_enable(void) {
|
||||
REG_CHARGE_OPTION_1,
|
||||
CHARGE_OPTION_1_600KHZ | ADAPTER_RSENSE | BATTERY_RSENSE
|
||||
);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge option 2 to PSYS enable
|
||||
res = smbus_write(
|
||||
CHARGER_ADDRESS,
|
||||
REG_CHARGE_OPTION_2,
|
||||
CHARGE_OPTION_2_PSYS_EN
|
||||
);
|
||||
if (res < 0) return res;
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_OPTION_2, CHARGE_OPTION_2_PSYS_EN);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge current in mA
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_CURRENT, CHARGE_CURRENT);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set charge voltage in mV
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_CHARGE_VOLTAGE, CHARGE_VOLTAGE);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
// Set input current in mA
|
||||
res = smbus_write(CHARGER_ADDRESS, REG_ADAPTER_CURRENT, INPUT_CURRENT);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
DEBUG("Charger enabled\n");
|
||||
charger_enabled = true;
|
||||
@ -158,7 +167,8 @@ void battery_debug(void) {
|
||||
uint16_t data = 0;
|
||||
int16_t res = 0;
|
||||
|
||||
#define command(N, A, V) { \
|
||||
#define command(N, A, V) \
|
||||
{ \
|
||||
DEBUG(" " #N ": "); \
|
||||
res = smbus_read(A, V, &data); \
|
||||
if (res < 0) { \
|
||||
|
@ -31,7 +31,8 @@ int16_t dgpu_temp = 0;
|
||||
|
||||
#define DGPU_TEMP(X) ((int16_t)(X))
|
||||
|
||||
#define FAN_POINT(T, D) { .temp = DGPU_TEMP(T), .duty = PWM_DUTY(D) }
|
||||
#define FAN_POINT(T, D) \
|
||||
{ .temp = DGPU_TEMP(T), .duty = PWM_DUTY(D) }
|
||||
|
||||
// Fan curve with temperature in degrees C, duty cycle in percent
|
||||
static struct FanPoint __code FAN_POINTS[] = {
|
||||
|
@ -13,33 +13,29 @@
|
||||
#include <8051.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define DEBUG_SET(REG, MASK, BITS) { \
|
||||
#define DEBUG_SET(REG, MASK, BITS) \
|
||||
{ \
|
||||
DEBUG("%s: %X", #REG, REG); \
|
||||
REG = ((REG) & ~(MASK)) | (BITS); \
|
||||
DEBUG(" set to %X\n", REG); \
|
||||
}
|
||||
|
||||
#define DEBUG_ON(REG, BITS) \
|
||||
DEBUG_SET(REG, BITS, BITS)
|
||||
#define DEBUG_ON(REG, BITS) DEBUG_SET(REG, BITS, BITS)
|
||||
|
||||
#define DEBUG_OFF(REG, BITS) \
|
||||
DEBUG_SET(REG, BITS, 0)
|
||||
#define DEBUG_OFF(REG, BITS) DEBUG_SET(REG, BITS, 0)
|
||||
|
||||
#define DEBUG_CHANGED(REG) { \
|
||||
#define DEBUG_CHANGED(REG) \
|
||||
{ \
|
||||
static uint8_t last_##REG = 0; \
|
||||
uint8_t new_##REG = REG; \
|
||||
if (new_##REG != last_##REG) { \
|
||||
DEBUG( \
|
||||
"%S: %X changed to %X\n", \
|
||||
#REG, \
|
||||
last_ ## REG, \
|
||||
new_ ## REG \
|
||||
); \
|
||||
DEBUG("%S: %X changed to %X\n", #REG, last_##REG, new_##REG); \
|
||||
last_##REG = new_##REG; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define VW_SET_DEBUG(W, V) { \
|
||||
#define VW_SET_DEBUG(W, V) \
|
||||
{ \
|
||||
DEBUG("%s = %X\n", #W, V); \
|
||||
vw_set(&W, V); \
|
||||
}
|
||||
|
@ -44,10 +44,12 @@ uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant {
|
||||
if (temp > prev->temp) {
|
||||
int16_t dtemp = (cur->temp - prev->temp);
|
||||
int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty);
|
||||
// clang-format off
|
||||
return (uint8_t)(
|
||||
((int16_t)prev->duty) +
|
||||
((temp - prev->temp) * dduty) / dtemp
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
} else {
|
||||
return prev->duty;
|
||||
@ -121,9 +123,11 @@ uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant {
|
||||
// ramping down
|
||||
if (duty < last_duty) {
|
||||
// out of bounds (lower) safeguard
|
||||
// clang-format off
|
||||
uint8_t smoothed = last_duty < MIN_FAN_SPEED + MAX_JUMP_DOWN
|
||||
? MIN_FAN_SPEED
|
||||
: last_duty - MAX_JUMP_DOWN;
|
||||
// clang-format on
|
||||
|
||||
// use smoothed value if above min and if smoothed is closer than raw
|
||||
if (last_duty > MIN_SPEED_TO_SMOOTH && smoothed > duty) {
|
||||
@ -134,9 +138,11 @@ uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant {
|
||||
// ramping up
|
||||
if (duty > last_duty) {
|
||||
// out of bounds (higher) safeguard
|
||||
// clang-format off
|
||||
uint8_t smoothed = last_duty > MAX_FAN_SPEED - MAX_JUMP_UP
|
||||
? MAX_FAN_SPEED
|
||||
: last_duty + MAX_JUMP_UP;
|
||||
// clang-format on
|
||||
|
||||
// use smoothed value if above min and if smoothed is closer than raw
|
||||
if (duty > MIN_SPEED_TO_SMOOTH && smoothed < duty) {
|
||||
|
@ -15,6 +15,7 @@ volatile uint8_t __xdata __at(0x103D) ECINDAR2;
|
||||
volatile uint8_t __xdata __at(0x103E) ECINDAR3;
|
||||
volatile uint8_t __xdata __at(0x103F) ECINDDR;
|
||||
|
||||
// clang-format off
|
||||
#define SPI_DEVICE (0x70)
|
||||
#define SPI_FOLLOW_MODE (0x0F)
|
||||
#define SPI_CHIP_SELECT (0xFD)
|
||||
@ -29,6 +30,7 @@ volatile uint8_t __xdata __at(0x103F) ECINDDR;
|
||||
#define SPI_ERASE_SECTOR_COMMAND (0xD7)
|
||||
|
||||
#define SPI_STATUS_WIP (0x01)
|
||||
// clang-format on
|
||||
|
||||
void flash_enter_follow_mode(void);
|
||||
void flash_exit_follow_mode(void);
|
||||
@ -46,11 +48,11 @@ void flash_write_enable(void);
|
||||
* NOTE: __critical to ensure interrupts are disabled. This does mean that interrupt
|
||||
* such as the timer will be block until flash acccess is complete
|
||||
*/
|
||||
// clang-format off
|
||||
void flash_entry(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) __reentrant __critical {
|
||||
// clang-format on
|
||||
// Only allow access from 64KB to 128KB.
|
||||
if ((addr < 0x10000)
|
||||
|| (length > 0x10000)
|
||||
|| ((addr + length) > 0x20000))
|
||||
if ((addr < 0x10000) || (length > 0x10000) || ((addr + length) > 0x20000))
|
||||
return;
|
||||
|
||||
if (command == FLASH_COMMAND_READ) {
|
||||
@ -93,7 +95,6 @@ void flash_entry(uint32_t addr, uint8_t * data, uint32_t length, uint8_t command
|
||||
ECINDAR1 = SPI_CHIP_DESELECT;
|
||||
ECINDDR = 0x00;
|
||||
|
||||
|
||||
// Wait WIP to be cleared
|
||||
flash_wait();
|
||||
}
|
||||
|
@ -12,9 +12,11 @@
|
||||
/** \cond INTERNAL
|
||||
* Internal defines
|
||||
*/
|
||||
// clang-format off
|
||||
#define FLASH_COMMAND_READ (0x0)
|
||||
#define FLASH_COMMAND_WRITE (0x1)
|
||||
#define FLASH_COMMAND_ERASE_1K (0x2)
|
||||
// clang-format on
|
||||
/** \endcond */
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,7 @@ static bool kbc_translate = true;
|
||||
// LED state
|
||||
uint8_t kbc_leds = 0;
|
||||
|
||||
// clang-format off
|
||||
// Values from linux/drivers/input/keyboard/atkbd.c
|
||||
static const uint16_t kbc_typematic_period[32] = {
|
||||
33, // 30.0 cps = ~33.33ms
|
||||
@ -71,6 +72,7 @@ static const uint16_t kbc_typematic_period[32] = {
|
||||
470, // 2.1 cps = ~478.19ms
|
||||
500, // 2.0 cps = 500ms
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
static uint8_t kbc_buffer[16] = { 0 };
|
||||
static uint8_t kbc_buffer_head = 0;
|
||||
@ -101,11 +103,13 @@ static bool kbc_buffer_push(uint8_t * scancodes, uint8_t len) {
|
||||
}
|
||||
|
||||
bool kbc_scancode(uint16_t key, bool pressed) {
|
||||
if (!kbc_first) return true;
|
||||
if (!kbc_first)
|
||||
return true;
|
||||
if (kbc_translate) {
|
||||
key = keymap_translate(key);
|
||||
}
|
||||
if (!key) return true;
|
||||
if (!key)
|
||||
return true;
|
||||
|
||||
uint8_t scancodes[3] = { 0, 0, 0 };
|
||||
uint8_t scancodes_len = 0;
|
||||
|
@ -28,12 +28,27 @@ void kbled_reset(void) {
|
||||
}
|
||||
|
||||
// Keep the following functions for compatibility - they are set via USB HID
|
||||
uint8_t kbled_get(void) { /*Always off*/ return 0; }
|
||||
uint8_t kbled_get(void) {
|
||||
/* Always off */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t kbled_max(void) { /*Always off*/ return 0; }
|
||||
uint8_t kbled_max(void) {
|
||||
/* Always off */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set(uint8_t level) { /*Fix unused variable*/ level = level; }
|
||||
void kbled_set(uint8_t level) {
|
||||
/* Fix unused variable */
|
||||
level = level;
|
||||
}
|
||||
|
||||
uint32_t kbled_get_color(void) { /*Always black*/ return 0; }
|
||||
uint32_t kbled_get_color(void) {
|
||||
/* Always black */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }
|
||||
void kbled_set_color(uint32_t color) {
|
||||
/* Fix unused variable */
|
||||
color = color;
|
||||
}
|
||||
|
@ -6,12 +6,27 @@ void kbled_init(void) {}
|
||||
|
||||
void kbled_reset(void) {}
|
||||
|
||||
uint8_t kbled_get(void) { /*Always off*/ return 0; }
|
||||
uint8_t kbled_get(void) {
|
||||
/* Always off */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t kbled_max(void) { /*Always off*/ return 0; }
|
||||
uint8_t kbled_max(void) {
|
||||
/* Always off */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set(uint8_t level) { /*Fix unused variable*/ level = level; }
|
||||
void kbled_set(uint8_t level) {
|
||||
/* Fix unused variable */
|
||||
level = level;
|
||||
}
|
||||
|
||||
uint32_t kbled_get_color(void) { /*Always black*/ return 0; }
|
||||
uint32_t kbled_get_color(void) {
|
||||
/* Always black */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }
|
||||
void kbled_set_color(uint32_t color) {
|
||||
/* Fix unused variable */
|
||||
color = color;
|
||||
}
|
||||
|
@ -54,6 +54,12 @@ void kbled_set(uint8_t level) {
|
||||
KBLED_DACDAT = raw;
|
||||
}
|
||||
|
||||
uint32_t kbled_get_color(void) { /* Always white */ return 0xFFFFFF; }
|
||||
uint32_t kbled_get_color(void) {
|
||||
/* Always white */
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }
|
||||
void kbled_set_color(uint32_t color) {
|
||||
/* Fix unused variable */
|
||||
color = color;
|
||||
}
|
||||
|
@ -178,25 +178,27 @@ static void hardware_hotkey(uint16_t key) {
|
||||
kbled_set(kbled_get() + 1);
|
||||
break;
|
||||
case K_KBD_COLOR:
|
||||
if (acpi_ecos != EC_OS_FULL) kbled_hotkey_color();
|
||||
if (acpi_ecos != EC_OS_FULL)
|
||||
kbled_hotkey_color();
|
||||
break;
|
||||
case K_KBD_DOWN:
|
||||
if (acpi_ecos != EC_OS_FULL) kbled_hotkey_down();
|
||||
if (acpi_ecos != EC_OS_FULL)
|
||||
kbled_hotkey_down();
|
||||
break;
|
||||
case K_KBD_UP:
|
||||
if (acpi_ecos != EC_OS_FULL) kbled_hotkey_up();
|
||||
if (acpi_ecos != EC_OS_FULL)
|
||||
kbled_hotkey_up();
|
||||
break;
|
||||
case K_KBD_TOGGLE:
|
||||
if (acpi_ecos != EC_OS_FULL) kbled_hotkey_toggle();
|
||||
if (acpi_ecos != EC_OS_FULL)
|
||||
kbled_hotkey_toggle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool kbscan_press(uint16_t key, bool pressed, uint8_t *layer) {
|
||||
// Wake from sleep on keypress
|
||||
if (pressed &&
|
||||
lid_state &&
|
||||
(power_state == POWER_STATE_S3)) {
|
||||
if (pressed && lid_state && (power_state == POWER_STATE_S3)) {
|
||||
pmc_swi();
|
||||
}
|
||||
|
||||
@ -208,8 +210,10 @@ bool kbscan_press(uint16_t key, bool pressed, uint8_t * layer) {
|
||||
break;
|
||||
case (KT_FN):
|
||||
if (layer != NULL) {
|
||||
if (pressed) *layer = 1;
|
||||
else *layer = 0;
|
||||
if (pressed)
|
||||
*layer = 1;
|
||||
else
|
||||
*layer = 0;
|
||||
} else {
|
||||
// In the case no layer can be set, reset bit
|
||||
return false;
|
||||
@ -344,8 +348,10 @@ void kbscan_event(void) {
|
||||
|
||||
// A key was pressed or released
|
||||
for (uint8_t j = 0; j < KM_IN; j++) {
|
||||
// clang-format off
|
||||
bool new_b = new & BIT(j);
|
||||
bool last_b = last & BIT(j);
|
||||
// clang-format on
|
||||
if (new_b != last_b) {
|
||||
bool reset = false;
|
||||
|
||||
|
@ -36,19 +36,29 @@ bool keymap_erase_config(void) {
|
||||
|
||||
bool keymap_load_config(void) {
|
||||
// Check signature
|
||||
if (flash_read_u16(CONFIG_ADDR) != CONFIG_SIGNATURE) return false;
|
||||
if (flash_read_u16(CONFIG_ADDR) != CONFIG_SIGNATURE)
|
||||
return false;
|
||||
|
||||
// Read the keymap if signature is valid
|
||||
flash_read(CONFIG_ADDR + sizeof(CONFIG_SIGNATURE), (uint8_t *)DYNAMIC_KEYMAP, sizeof(DYNAMIC_KEYMAP));
|
||||
flash_read(
|
||||
CONFIG_ADDR + sizeof(CONFIG_SIGNATURE),
|
||||
(uint8_t *)DYNAMIC_KEYMAP,
|
||||
sizeof(DYNAMIC_KEYMAP)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool keymap_save_config(void) {
|
||||
// Erase config region
|
||||
if (!keymap_erase_config()) return false;
|
||||
if (!keymap_erase_config())
|
||||
return false;
|
||||
|
||||
// Write the keymap
|
||||
flash_write(CONFIG_ADDR + sizeof(CONFIG_SIGNATURE), (uint8_t *)DYNAMIC_KEYMAP, sizeof(DYNAMIC_KEYMAP));
|
||||
flash_write(
|
||||
CONFIG_ADDR + sizeof(CONFIG_SIGNATURE),
|
||||
(uint8_t *)DYNAMIC_KEYMAP,
|
||||
sizeof(DYNAMIC_KEYMAP)
|
||||
);
|
||||
|
||||
// Write the length of the keymap, as a signature
|
||||
flash_write_u16(CONFIG_ADDR, CONFIG_SIGNATURE);
|
||||
|
@ -19,12 +19,14 @@
|
||||
* nWAIT = KSOH[1]
|
||||
*/
|
||||
|
||||
// clang-format off
|
||||
#define CTL_WRITE BIT(0)
|
||||
#define CTL_DATA BIT(1)
|
||||
#define CTL_RESET BIT(2)
|
||||
#define CTL_ADDR BIT(3)
|
||||
|
||||
#define STS_WAIT BIT(1)
|
||||
// clang-format on
|
||||
|
||||
// Maximum peripheral response time in ms
|
||||
#define PARALLEL_TIMEOUT 10
|
||||
|
@ -36,7 +36,9 @@ int16_t peci_temp = 0;
|
||||
|
||||
#define PECI_TEMP(X) ((int16_t)(X))
|
||||
|
||||
// clang-format off
|
||||
#define FAN_POINT(T, D) { .temp = PECI_TEMP(T), .duty = PWM_DUTY(D) }
|
||||
// clang-format on
|
||||
|
||||
// Fan curve with temperature in degrees C, duty cycle in percent
|
||||
static struct FanPoint __code FAN_POINTS[] = {
|
||||
|
@ -26,7 +26,8 @@
|
||||
#define USE_S0IX 0
|
||||
#endif
|
||||
|
||||
#define GPIO_SET_DEBUG(G, V) { \
|
||||
#define GPIO_SET_DEBUG(G, V) \
|
||||
{ \
|
||||
DEBUG("%s = %s\n", #G, V ? "true" : "false"); \
|
||||
gpio_set(&G, V); \
|
||||
}
|
||||
@ -243,8 +244,8 @@ void power_on(void) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for VW changes
|
||||
#if CONFIG_BUS_ESPI
|
||||
// Check for VW changes
|
||||
espi_event();
|
||||
#endif // CONFIG_BUS_ESPI
|
||||
|
||||
@ -482,6 +483,7 @@ void power_event(void) {
|
||||
}
|
||||
pg_last = pg_new;
|
||||
|
||||
// clang-format off
|
||||
static bool rst_last = false;
|
||||
bool rst_new = gpio_get(&BUF_PLT_RST_N);
|
||||
#if LEVEL >= LEVEL_DEBUG
|
||||
@ -498,6 +500,7 @@ void power_event(void) {
|
||||
#endif // CONFIG_BUS_ESPI
|
||||
}
|
||||
rst_last = rst_new;
|
||||
// clang-format on
|
||||
|
||||
#if HAVE_SLP_SUS_N
|
||||
#if LEVEL >= LEVEL_DEBUG
|
||||
|
@ -168,8 +168,7 @@ static enum Result cmd_keymap_set(void) {
|
||||
int16_t layer = smfi_cmd[SMFI_CMD_DATA];
|
||||
int16_t output = smfi_cmd[SMFI_CMD_DATA + 1];
|
||||
int16_t input = smfi_cmd[SMFI_CMD_DATA + 2];
|
||||
uint16_t key =
|
||||
((uint16_t)smfi_cmd[SMFI_CMD_DATA + 3]) |
|
||||
uint16_t key = ((uint16_t)smfi_cmd[SMFI_CMD_DATA + 3]) |
|
||||
(((uint16_t)smfi_cmd[SMFI_CMD_DATA + 4]) << 8);
|
||||
//TODO: consider only setting if the key has changed
|
||||
if (keymap_set(layer, output, input, key)) {
|
||||
|
@ -39,7 +39,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clange-format on
|
||||
// clang-format on
|
||||
|
||||
void gpio_init() {
|
||||
// Enable LPC reset on GPD2
|
||||
|
@ -36,7 +36,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(F, 3);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(G, 1);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clange-format on
|
||||
// clang-format on
|
||||
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@ -33,6 +34,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
|
||||
void gpio_init() {
|
||||
// Enable LPC reset on GPD2
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@ -34,6 +35,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
|
||||
void gpio_init() {
|
||||
// Enable LPC reset on GPD2
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@ -33,6 +34,7 @@ struct Gpio __code VA_EC_EN = GPIO(H, 7);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
|
||||
void gpio_init() {
|
||||
// Enable LPC reset on GPD2
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@ -33,6 +34,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(D, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
|
||||
void gpio_init() {
|
||||
// Enable LPC reset on GPD2
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <board/gpio.h>
|
||||
#include <ec/ec.h>
|
||||
|
||||
|
||||
void board_init(void) {
|
||||
espi_init();
|
||||
|
||||
|
@ -36,7 +36,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clange-format on
|
||||
// clang-format on
|
||||
|
||||
void gpio_init(void) {
|
||||
// Not documented
|
||||
|
@ -18,6 +18,9 @@ void board_init(void) {
|
||||
gpio_set(&SWI_N, true);
|
||||
}
|
||||
|
||||
void board_on_ac(bool ac) { /* Fix unused variable */ ac = ac; }
|
||||
void board_on_ac(bool ac) {
|
||||
/* Fix unused variable */
|
||||
ac = ac;
|
||||
}
|
||||
|
||||
void board_event(void) {}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@ -32,6 +33,7 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4); // renamed to EC_SLP_SUS#
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(H, 4);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
|
||||
void gpio_init() {
|
||||
// Enable LPC reset on GPD2
|
||||
|
@ -6,10 +6,12 @@ int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length)
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, true);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = i2c_read(i2c, data, length);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
i2c_stop(i2c);
|
||||
|
||||
@ -20,36 +22,44 @@ int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length)
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, false);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = i2c_write(i2c, data, length);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
i2c_stop(i2c);
|
||||
|
||||
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 *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length)
|
||||
__reentrant {
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, false);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = i2c_write(i2c, ®, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
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 *i2c, uint8_t addr, uint8_t reg, uint8_t *data, uint16_t length)
|
||||
__reentrant {
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, false);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = i2c_write(i2c, ®, 1);
|
||||
if (res < 0) return res;
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return i2c_send(i2c, addr, data, length);
|
||||
}
|
||||
|
@ -36,10 +36,14 @@ int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length)
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif // _COMMON_I2C_H
|
||||
|
@ -45,7 +45,8 @@ struct I2C __code I2C_4 = {
|
||||
void i2c_reset(struct I2C *i2c, bool kill) {
|
||||
if (*(i2c->hosta) & HOSTA_BUSY) {
|
||||
// Set kill bit
|
||||
if (kill) *(i2c->hoctl) |= BIT(1);
|
||||
if (kill)
|
||||
*(i2c->hoctl) |= BIT(1);
|
||||
// Wait for host to finish
|
||||
while (*(i2c->hosta) & HOSTA_BUSY) {}
|
||||
}
|
||||
|
@ -8,11 +8,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// clang-format off
|
||||
#define GPIO_ALT (0b00U << 6)
|
||||
#define GPIO_IN (0b10U << 6)
|
||||
#define GPIO_OUT (0b01U << 6)
|
||||
#define GPIO_UP BIT(2)
|
||||
#define GPIO_DOWN BIT(1)
|
||||
// clang-format on
|
||||
|
||||
struct Gpio {
|
||||
volatile uint8_t __xdata *data;
|
||||
|
@ -22,7 +22,8 @@ uint8_t kbc_read(struct Kbc * kbc) {
|
||||
|
||||
static bool kbc_wait(struct Kbc *kbc, uint16_t timeout) {
|
||||
while (*(kbc->status) & KBC_STS_OBF) {
|
||||
if (timeout == 0) return false;
|
||||
if (timeout == 0)
|
||||
return false;
|
||||
timeout -= 1;
|
||||
delay_us(1);
|
||||
}
|
||||
@ -30,14 +31,16 @@ static bool kbc_wait(struct Kbc * kbc, uint16_t timeout) {
|
||||
}
|
||||
|
||||
bool kbc_keyboard(struct Kbc *kbc, uint8_t data, uint16_t timeout) {
|
||||
if (!kbc_wait(kbc, timeout)) return false;
|
||||
if (!kbc_wait(kbc, timeout))
|
||||
return false;
|
||||
*(kbc->status) &= ~0x20;
|
||||
*(kbc->keyboard_out) = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool kbc_mouse(struct Kbc *kbc, uint8_t data, uint16_t timeout) {
|
||||
if (!kbc_wait(kbc, timeout)) return false;
|
||||
if (!kbc_wait(kbc, timeout))
|
||||
return false;
|
||||
*(kbc->status) |= 0x20;
|
||||
*(kbc->mouse_out) = data;
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user