blinky works for lpc1768

wch-ch32v003
Felix (xq) Queißner 3 years ago
parent 6cdf641f32
commit 26681f7b30

1
.gitignore vendored

@ -1 +1,2 @@
zig-cache/
dev-scripts/

@ -83,12 +83,30 @@ pub fn Gpio(comptime pin: type, config: anytype) type {
}
// bi-di:
fn setDirection(dir: Direction, output_state: State) void {}
fn getDirection() Direction {}
fn setDirection(dir: Direction, output_state: State) void {
switch (dir) {
.output => {
chip.gpio.setOutput(pin.source_pin);
write(output_state);
},
.input => chip.gpio.setInput(pin.source_pin),
}
}
fn getDirection() Direction {
if (chip.gpio.isOutput(pin.source_pin)) {
return .output;
} else {
return .input;
}
}
// open drain
fn setDrive(drive: Drive) void {}
fn getDrive() Drive {}
fn setDrive(drive: Drive) void {
@compileError("open drain not implemented yet!");
}
fn getDrive() Drive {
@compileError("open drain not implemented yet!");
}
};
// return only a subset of Generic for the requested pin.
switch (mode) {

@ -4,17 +4,17 @@ const micro = @import("microzig.zig");
/// Unmasks the given interrupt and enables its execution.
/// Note that interrupts must be globally enabled with `sei()` as well.
pub fn enable(comptime interrupt: anytype) void {
@panic("not implemented yet!");
@compileError("not implemented yet!");
}
/// Masks the given interrupt and disables its execution.
pub fn disable(comptime interrupt: anytype) void {
@panic("not implemented yet!");
@compileError("not implemented yet!");
}
/// Returns true when the given interrupt is unmasked.
pub fn isEnabled(comptime interrupt: anytype) bool {
@panic("not implemented yet!");
@compileError("not implemented yet!");
}
/// *Set Enable Interrupt*, will enable IRQs globally, but keep the masking done via
@ -31,7 +31,7 @@ pub fn cli() void {
/// Returns true, when interrupts are globally enabled via `sei()`.
pub fn areGloballyEnabled() bool {
@panic("not implemented yet!");
@compileError("not implemented yet!");
}
/// Enters a critical section and disables interrupts globally.

@ -33,6 +33,13 @@ pub const gpio = struct {
return @intToPtr(*volatile u8, 0x01);
}
pub fn setOutput(comptime pin: type) void {
dirReg(pin).* |= (1 << pin.pin);
}
pub fn setInput(comptime pin: type) void {
dirReg(pin).* &= ~(@as(u8, 1) << pin.pin);
}
pub fn read(comptime pin: type) u1 {
return if ((pinReg(pin).* & (1 << pin.pin)) != 0)
@as(u1, 1)

@ -26,6 +26,13 @@ pub fn parsePin(comptime spec: []const u8) type {
}
pub const gpio = struct {
pub fn setOutput(comptime pin: type) void {
pin.gpio_register.dir |= pin.gpio_mask;
}
pub fn setInput(comptime pin: type) void {
pin.gpio_register.dir &= ~pin.gpio_mask;
}
pub fn read(comptime pin: type) u1 {
return if ((pin.gpio_register.pin & pin.gpio_mask) != 0)
@as(u1, 1)

@ -74,11 +74,32 @@ pub const startup_logic = struct {
extern fn microzig_main() noreturn;
extern var microzig_data_start: c_void;
extern var microzig_data_end: c_void;
extern var microzig_bss_start: c_void;
extern var microzig_bss_end: c_void;
extern const microzig_data_load_start: c_void;
fn _start() callconv(.C) noreturn {
// TODO:
// - Load .data
// - Clear .bss
// fill .bss with zeroes
{
const bss_start = @ptrCast([*]u8, &microzig_bss_start);
const bss_end = @ptrCast([*]u8, &microzig_bss_end);
const bss_len = @ptrToInt(bss_end) - @ptrToInt(bss_start);
std.mem.set(u8, bss_start[0..bss_len], 0);
}
// load .data from flash
{
const data_start = @ptrCast([*]u8, &microzig_data_start);
const data_end = @ptrCast([*]u8, &microzig_data_end);
const data_len = @ptrToInt(data_end) - @ptrToInt(data_start);
const data_src = @ptrCast([*]const u8, &microzig_data_load_start);
std.mem.copy(u8, data_start[0..data_len], data_src[0..data_len]);
}
microzig_main();
}

Loading…
Cancel
Save