Skip to content

Commit 1fef940

Browse files
committed
WIP
1 parent c99e34e commit 1fef940

35 files changed

+4508
-5
lines changed

.clang-format

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
IndentWidth: 4
3+
---
4+
Language: Cpp
5+
ColumnLimit: 80
6+
BreakBeforeBraces: Linux
7+
SpaceBeforeParens: ControlStatements
8+
IncludeBlocks: Merge
9+
IncludeCategories:
10+
- Regex: 'osdep.h"$'
11+
Priority: -2
12+
- Regex: '^<'
13+
Priority: -1
14+
- Regex: '.*'
15+
Priority: 1
16+
---
17+
Language: JavaScript
18+
AccessModifierOffset: -2
19+
AlignAfterOpenBracket: Align
20+
AlignConsecutiveMacros: false
21+
AlignConsecutiveAssignments: false
22+
AlignConsecutiveBitFields: false
23+
AlignConsecutiveDeclarations: false
24+
AlignEscapedNewlines: Right
25+
AlignOperands: Align
26+
AlignTrailingComments: true
27+
AllowAllArgumentsOnNextLine: true
28+
AllowAllConstructorInitializersOnNextLine: true
29+
AllowAllParametersOfDeclarationOnNextLine: true
30+
AllowShortEnumsOnASingleLine: true
31+
AllowShortBlocksOnASingleLine: Never
32+
AllowShortCaseLabelsOnASingleLine: false
33+
AllowShortFunctionsOnASingleLine: All
34+
AllowShortLambdasOnASingleLine: All
35+
AllowShortIfStatementsOnASingleLine: Never
36+
AllowShortLoopsOnASingleLine: false
37+
AlwaysBreakAfterDefinitionReturnType: All
38+
AlwaysBreakAfterReturnType: AllDefinitions
39+
AlwaysBreakBeforeMultilineStrings: false
40+
AlwaysBreakTemplateDeclarations: MultiLine
41+
BinPackArguments: true
42+
BinPackParameters: true
43+
BraceWrapping:
44+
AfterCaseLabel: true
45+
AfterClass: true
46+
AfterControlStatement: Always
47+
AfterEnum: true
48+
AfterFunction: true
49+
AfterNamespace: true
50+
AfterObjCDeclaration: true
51+
AfterStruct: true
52+
AfterUnion: true
53+
AfterExternBlock: true
54+
BeforeCatch: true
55+
BeforeElse: true
56+
BeforeLambdaBody: false
57+
BeforeWhile: true
58+
IndentBraces: true
59+
SplitEmptyFunction: true
60+
SplitEmptyRecord: true
61+
SplitEmptyNamespace: true
62+
BreakBeforeBinaryOperators: All
63+
BreakBeforeInheritanceComma: false
64+
BreakInheritanceList: BeforeColon
65+
BreakBeforeTernaryOperators: true
66+
BreakConstructorInitializersBeforeComma: false
67+
BreakConstructorInitializers: BeforeColon
68+
BreakAfterJavaFieldAnnotations: false
69+
BreakStringLiterals: true
70+
CommentPragmas: '^ IWYU pragma:'
71+
CompactNamespaces: false
72+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
73+
ConstructorInitializerIndentWidth: 4
74+
ContinuationIndentWidth: 4
75+
Cpp11BracedListStyle: false
76+
DeriveLineEnding: true
77+
DerivePointerAlignment: false
78+
DisableFormat: false
79+
ExperimentalAutoDetectBinPacking: false
80+
FixNamespaceComments: false
81+
ForEachMacros:
82+
- foreach
83+
- Q_FOREACH
84+
- BOOST_FOREACH
85+
IncludeIsMainRegex: '(Test)?$'
86+
IncludeIsMainSourceRegex: ''
87+
IndentCaseLabels: false
88+
IndentCaseBlocks: false
89+
IndentGotoLabels: true
90+
IndentPPDirectives: None
91+
IndentExternBlock: AfterExternBlock
92+
IndentWidth: 2
93+
IndentWrappedFunctionNames: false
94+
InsertTrailingCommas: None
95+
JavaScriptQuotes: Leave
96+
JavaScriptWrapImports: true
97+
KeepEmptyLinesAtTheStartOfBlocks: true
98+
MacroBlockBegin: ''
99+
MacroBlockEnd: ''
100+
MaxEmptyLinesToKeep: 1
101+
NamespaceIndentation: None
102+
ObjCBinPackProtocolList: Auto
103+
ObjCBlockIndentWidth: 2
104+
ObjCBreakBeforeNestedBlockParam: true
105+
ObjCSpaceAfterProperty: false
106+
ObjCSpaceBeforeProtocolList: true
107+
PenaltyBreakAssignment: 2
108+
PenaltyBreakBeforeFirstCallParameter: 19
109+
PenaltyBreakComment: 300
110+
PenaltyBreakFirstLessLess: 120
111+
PenaltyBreakString: 1000
112+
PenaltyBreakTemplateDeclaration: 10
113+
PenaltyExcessCharacter: 1000000
114+
PointerAlignment: Right
115+
ReflowComments: true
116+
SortIncludes: true
117+
SortUsingDeclarations: true
118+
SpaceAfterCStyleCast: false
119+
SpaceAfterLogicalNot: false
120+
SpaceAfterTemplateKeyword: true
121+
SpaceBeforeAssignmentOperators: true
122+
SpaceBeforeCpp11BracedList: false
123+
SpaceBeforeCtorInitializerColon: true
124+
SpaceBeforeInheritanceColon: true
125+
SpaceBeforeParens: Always
126+
SpaceBeforeRangeBasedForLoopColon: true
127+
SpaceInEmptyBlock: false
128+
SpaceInEmptyParentheses: false
129+
SpacesBeforeTrailingComments: 1
130+
SpacesInAngles: false
131+
SpacesInConditionalStatement: false
132+
SpacesInContainerLiterals: true
133+
SpacesInCStyleCastParentheses: false
134+
SpacesInParentheses: false
135+
SpacesInSquareBrackets: false
136+
SpaceBeforeSquareBrackets: false
137+
Standard: c++03
138+
StatementMacros:
139+
- Q_UNUSED
140+
- QT_REQUIRE_VERSION
141+
TabWidth: 8
142+
UseCRLF: false
143+
UseTab: Never
144+
WhitespaceSensitiveMacros:
145+
- STRINGIZE
146+
- PP_STRINGIZE
147+
- BOOST_PP_STRINGIZE
148+
...
149+

hw/arm/amazfit.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
#include "qemu/osdep.h"
3+
#include "hw/arm/boot.h"
4+
#include "hw/arm/stm32l467_soc.h"
5+
#include "hw/boards.h"
6+
#include "hw/i2c/i2c.h"
7+
#include "hw/irq.h"
8+
#include "hw/loader.h"
9+
#include "hw/qdev-properties.h"
10+
#include "hw/qdev-clock.h"
11+
#include "hw/ssi/ssi.h"
12+
#include "qapi/error.h"
13+
#include "ui/console.h"
14+
15+
static uint32_t readu32(hwaddr addr)
16+
{
17+
uint32_t ret;
18+
ARMCPU *cpu = ARM_CPU(first_cpu);
19+
cpu_memory_rw_debug(cpu, addr, &ret, 4, false);
20+
21+
return ret;
22+
}
23+
qemu_irq buttonIrq;
24+
qemu_irq buttonExtiIrq;
25+
qemu_irq touchIrq;
26+
qemu_irq touchExtiIrq;
27+
void amazfit_key_event(void *opaque, int keycode)
28+
{
29+
bool pressed = (keycode & 0x80) == 0;
30+
printf("KEY: %d | 0x%x\n", keycode & 0x7F, keycode & 0x80);
31+
32+
switch (keycode & 0x7F) {
33+
case 31: /* S */
34+
// LOW = pressed, HIGH = unpressed
35+
qemu_set_irq(buttonIrq, !pressed);
36+
qemu_set_irq(buttonExtiIrq, !pressed);
37+
break;
38+
39+
default:
40+
return;
41+
}
42+
}
43+
44+
/* Main SYSCLK frequency in Hz (120MHz) */
45+
#define SYSCLK_FRQ 120000000ULL
46+
47+
static void bip_init(MachineState *machine)
48+
{
49+
Clock *sysclk;
50+
51+
/* This clock doesn't need migration because it is fixed-frequency */
52+
sysclk = clock_new(OBJECT(machine), "SYSCLK");
53+
clock_set_hz(sysclk, SYSCLK_FRQ);
54+
55+
STM32L467State *dev = STM32L467_SOC(qdev_new(TYPE_STM32L467_SOC));
56+
qdev_connect_clock_in(dev, "sysclk", sysclk);
57+
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
58+
59+
SSIBus *spi_bus = (SSIBus *)qdev_get_child_bus(&dev->spi[2], "ssi"); // SPI3
60+
DeviceState *display = ssi_create_peripheral(spi_bus, "jdi-lpm013m126c");
61+
62+
qemu_irq cs_line = qdev_get_gpio_in_named(display, SSI_GPIO_CS, 0);
63+
qdev_connect_gpio_out(dev->gpio['G' - 'A'], 12, cs_line);
64+
65+
buttonIrq = qdev_get_gpio_in(dev->gpio['A' - 'A'], 0);
66+
buttonExtiIrq = qdev_get_gpio_in(dev->exti, 0);
67+
qemu_add_kbd_event_handler(amazfit_key_event, NULL);
68+
69+
70+
touchIrq = qdev_get_gpio_in(dev->gpio['B' - 'B'], 3);
71+
touchExtiIrq = qdev_get_gpio_in(dev->exti, 3);
72+
73+
/* --- QSPI Flash --------------------------------------------- */
74+
SSIBus *qspi = (SSIBus *)qdev_get_child_bus(&dev->qspi, "qspi");
75+
DeviceState *qspi_flash = qdev_new("w25q64fw");
76+
77+
DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
78+
BlockBackend *blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
79+
qdev_prop_set_drive(qspi_flash, "drive", blk);
80+
ssi_realize_and_unref(qspi_flash, qspi, &error_fatal);
81+
82+
qemu_irq mx25u_cs = qdev_get_gpio_in_named(qspi_flash, SSI_GPIO_CS, 0);
83+
sysbus_connect_irq(SYS_BUS_DEVICE(&dev->qspi), 1, mx25u_cs);
84+
85+
if (false) {
86+
load_image_targphys("/Users/Marijn/Projects/_pebble/"
87+
"Amazfitbip-FreeRTOS/bin/lcd_test.bin",
88+
0, FLASH_SIZE);
89+
} else {
90+
load_image_targphys("/Users/hamster/Projects/Bip/FW/out/rom.bin", 0,
91+
FLASH_SIZE);
92+
}
93+
94+
I2CBus *i2c = (I2CBus *)qdev_get_child_bus(&dev->i2c[0], "i2c");
95+
DeviceState *ts = DEVICE(i2c_slave_create_simple(i2c, "it7259", 0x46));
96+
qdev_connect_gpio_out(ts, 0, qemu_irq_split(touchIrq,touchExtiIrq));
97+
98+
armv7m_load_kernel(ARM_CPU(first_cpu), NULL, 0);
99+
}
100+
101+
static void bip_machine_init(MachineClass *mc)
102+
{
103+
mc->desc = "Amazfit Bip";
104+
mc->init = bip_init;
105+
}
106+
107+
DEFINE_MACHINE("amazfitbip", bip_machine_init)

0 commit comments

Comments
 (0)