Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
IndentWidth: 4
---
Language: Cpp
ColumnLimit: 80
BreakBeforeBraces: Linux
SpaceBeforeParens: ControlStatements
IncludeBlocks: Merge
IncludeCategories:
- Regex: 'osdep.h"$'
Priority: -2
- Regex: '^<'
Priority: -1
- Regex: '.*'
Priority: 1
---
Language: JavaScript
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Always
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: c++03
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
...

107 changes: 107 additions & 0 deletions hw/arm/amazfit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

#include "qemu/osdep.h"
#include "hw/arm/boot.h"
#include "hw/arm/stm32l467_soc.h"
#include "hw/boards.h"
#include "hw/i2c/i2c.h"
#include "hw/irq.h"
#include "hw/loader.h"
#include "hw/qdev-properties.h"
#include "hw/qdev-clock.h"
#include "hw/ssi/ssi.h"
#include "qapi/error.h"
#include "ui/console.h"

static uint32_t readu32(hwaddr addr)
{
uint32_t ret;
ARMCPU *cpu = ARM_CPU(first_cpu);
cpu_memory_rw_debug(cpu, addr, &ret, 4, false);

return ret;
}
qemu_irq buttonIrq;
qemu_irq buttonExtiIrq;
qemu_irq touchIrq;
qemu_irq touchExtiIrq;
void amazfit_key_event(void *opaque, int keycode)
{
bool pressed = (keycode & 0x80) == 0;
printf("KEY: %d | 0x%x\n", keycode & 0x7F, keycode & 0x80);

switch (keycode & 0x7F) {
case 31: /* S */
// LOW = pressed, HIGH = unpressed
qemu_set_irq(buttonIrq, !pressed);
qemu_set_irq(buttonExtiIrq, !pressed);
break;

default:
return;
}
}

/* Main SYSCLK frequency in Hz (120MHz) */
#define SYSCLK_FRQ 120000000ULL

static void bip_init(MachineState *machine)
{
Clock *sysclk;

/* This clock doesn't need migration because it is fixed-frequency */
sysclk = clock_new(OBJECT(machine), "SYSCLK");
clock_set_hz(sysclk, SYSCLK_FRQ);

STM32L467State *dev = STM32L467_SOC(qdev_new(TYPE_STM32L467_SOC));
qdev_connect_clock_in(dev, "sysclk", sysclk);
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);

SSIBus *spi_bus = (SSIBus *)qdev_get_child_bus(&dev->spi[2], "ssi"); // SPI3
DeviceState *display = ssi_create_peripheral(spi_bus, "jdi-lpm013m126c");

qemu_irq cs_line = qdev_get_gpio_in_named(display, SSI_GPIO_CS, 0);
qdev_connect_gpio_out(dev->gpio['G' - 'A'], 12, cs_line);

buttonIrq = qdev_get_gpio_in(dev->gpio['A' - 'A'], 0);
buttonExtiIrq = qdev_get_gpio_in(dev->exti, 0);
qemu_add_kbd_event_handler(amazfit_key_event, NULL);


touchIrq = qdev_get_gpio_in(dev->gpio['B' - 'B'], 3);
touchExtiIrq = qdev_get_gpio_in(dev->exti, 3);

/* --- QSPI Flash --------------------------------------------- */
SSIBus *qspi = (SSIBus *)qdev_get_child_bus(&dev->qspi, "qspi");
DeviceState *qspi_flash = qdev_new("w25q64fw");

DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
BlockBackend *blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
qdev_prop_set_drive(qspi_flash, "drive", blk);
ssi_realize_and_unref(qspi_flash, qspi, &error_fatal);

qemu_irq mx25u_cs = qdev_get_gpio_in_named(qspi_flash, SSI_GPIO_CS, 0);
sysbus_connect_irq(SYS_BUS_DEVICE(&dev->qspi), 1, mx25u_cs);

if (false) {
load_image_targphys("/Users/Marijn/Projects/_pebble/"
"Amazfitbip-FreeRTOS/bin/lcd_test.bin",
0, FLASH_SIZE);
} else {
load_image_targphys("/Users/hamster/Projects/Bip/FW/out/rom.bin", 0,
FLASH_SIZE);
}

I2CBus *i2c = (I2CBus *)qdev_get_child_bus(&dev->i2c[0], "i2c");
DeviceState *ts = DEVICE(i2c_slave_create_simple(i2c, "it7259", 0x46));
qdev_connect_gpio_out(ts, 0, qemu_irq_split(touchIrq,touchExtiIrq));

armv7m_load_kernel(ARM_CPU(first_cpu), NULL, 0);
}

static void bip_machine_init(MachineClass *mc)
{
mc->desc = "Amazfit Bip";
mc->init = bip_init;
}

DEFINE_MACHINE("amazfitbip", bip_machine_init)
Loading