Skip to content
Merged
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
4 changes: 2 additions & 2 deletions drivers/stepper/ULN2003.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const Direction = enum { forward, backward };
pub const ULN2003 = struct {
const Self = @This();
const STEP_MIN_US = 2;
const STEP_TABLE_FULL = [_]u4{ 0b1010, 0b0110, 0b0101, 0b1001 };
const STEP_TABLE_HALF = [_]u4{ 0b1000, 0b1010, 0b0010, 0b0110, 0b0100, 0b0101, 0b0001, 0b1001 };
const STEP_TABLE_FULL = [_]u4{ 0b1000, 0b0100, 0b0010, 0b0001 };
const STEP_TABLE_HALF = [_]u4{ 0b1000, 0b1100, 0b0100, 0b0110, 0b0010, 0b0011, 0b0001, 0b1001 };

in: [4]mdf.base.Digital_IO,
clock: mdf.base.Clock_Device,
Expand Down
1 change: 1 addition & 0 deletions examples/espressif/esp/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn build(b: *std.Build) void {
.{ .name = "custom_clock_config", .file = "src/custom_clock_config.zig" },
.{ .name = "interrupts", .file = "src/interrupts.zig" },
.{ .name = "stepper_driver", .file = "src/stepper_driver.zig" },
.{ .name = "stepper_driver_dumb", .file = "src/stepper_driver_dumb.zig" },
};

for (available_examples) |example| {
Expand Down
56 changes: 56 additions & 0 deletions examples/espressif/esp/src/stepper_driver_dumb.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const std = @import("std");
const microzig = @import("microzig");
const hal = microzig.hal;
const gpio = hal.gpio;
const time = hal.time;

const GPIO_Device = hal.drivers.GPIO_Device;
const ClockDevice = hal.drivers.ClockDevice;
const ULN2003 = microzig.drivers.stepper.ULN2003;

const usb_serial_jtag = hal.usb_serial_jtag;

pub const microzig_options = microzig.Options{
.logFn = usb_serial_jtag.logger.logFn,
};

pub fn main() !void {
var cd = ClockDevice{};

// Setup all pins for the stepper driver
var pins: struct {
in1: GPIO_Device,
in2: GPIO_Device,
in3: GPIO_Device,
in4: GPIO_Device,
} = undefined;
inline for (std.meta.fields(@TypeOf(pins)), .{ 5, 6, 7, 8 }) |field, num| {
const pin = gpio.num(num);
// Give the pin a sane default config
pin.apply(.{});
@field(pins, field.name) = GPIO_Device.init(pin);
}

var stepper = ULN2003.init(.{
.in1_pin = pins.in1.digital_io(),
.in2_pin = pins.in2.digital_io(),
.in3_pin = pins.in3.digital_io(),
.in4_pin = pins.in4.digital_io(),
.clock_device = cd.clock_device(),
});

try stepper.begin(20, 1);

while (true) {
// Try different microsteps
inline for (.{ 1, 2 }) |ms| {
_ = try stepper.set_microstep(ms);
std.log.info("microsteps: {}", .{ms});
try stepper.rotate(360);
time.sleep_ms(250);
try stepper.rotate(-360);
time.sleep_ms(250);
}
time.sleep_ms(1000);
}
}
Loading