Skip to content

Commit

Permalink
fix comptime var issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Apr 25, 2024
1 parent 1a8f76e commit 01b496d
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 28 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
MICROZIG_VERSION=$(zig build package -- get-version)
echo microzig version: $MICROZIG_VERSION
zig build package -- http://localhost:8000
python3 -m http.server 8000 --directory boxzer-out > http.log &
python3 -m http.server 8000 --directory boxzer-out &
sleep 1
cd tools/package-test
Expand All @@ -48,9 +48,3 @@ jobs:
# clean up server
jobs -p | xargs kill
#- name: Upload HTTP logs
# uses: actions/upload-artifact@v3
# with:
# name: http.log
# path: http.log
6 changes: 3 additions & 3 deletions bsp/raspberrypi/rp2040/src/hal/gpio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ pub const IrqLevel = enum(u2) {

pub const IrqCallback = fn (gpio: u32, events: u32) callconv(.C) void;

pub const Override = enum {
pub const Override = enum(u2) {
normal,
invert,
low,
high,
};

pub const SlewRate = enum {
pub const SlewRate = enum(u1) {
slow,
fast,
};

pub const DriveStrength = enum {
pub const DriveStrength = enum(u2) {
@"2mA",
@"4mA",
@"8mA",
Expand Down
2 changes: 1 addition & 1 deletion bsp/raspberrypi/rp2040/src/hal/pio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const PIO1 = microzig.chip.peripherals.PIO1;
const gpio = @import("gpio.zig");
const resets = @import("resets.zig");
const hw = @import("hw.zig");
const assembler = @import("pio/assembler.zig");
pub const assembler = @import("pio/assembler.zig");
const encoder = @import("pio/assembler/encoder.zig");

// global state for keeping track of used things
Expand Down
3 changes: 2 additions & 1 deletion bsp/raspberrypi/rp2040/src/hal/pio/assembler/encoder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ pub fn Encoder(comptime options: Options) type {
}) catch unreachable;
}

break :blk tmp.constSlice();
const defines_const = tmp;
break :blk defines_const.constSlice();
},
.instructions = @as([]const u16, @ptrCast(bounded.instructions.constSlice())),
.origin = bounded.origin,
Expand Down
17 changes: 1 addition & 16 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@ const Build = std.Build;

const MicroZig = @import("build/definitions");

// TODO: fix this issue with AVR. For some reason we fail wasi assertions?
//
// error: the following command failed with 1 compilation errors:
//Users/mattnite/zig/0.12.0-dev.3097+5c0766b6c/files/zig build-exe -freference-trace=256 -OReleaseSmall -target avr-freestanding-eabi -mcpu avr5 --dep app --dep microzig -Mroot=/Users/mattnite/code/microzig/core/src/start.zig --dep microzig -Mapp=/Users/mattnite/code/microzig/examples/microchip/avr/src/blinky.zig --dep config --dep chip --dep cpu --dep hal --dep board -Mmicrozig=/Users/mattnite/code/microzig/core/src/microzig.zig -Mconfig=/Users/mattnite/code/microzig/zig-cache/c/303c67fccae4ec4bb03ec2180082b67b/options.zig --dep microzig -Mchip=/Users/mattnite/code/microzig/zig-cache/o/2c86b0de714a8b4409eb761d16297c00/chip.zig --dep microzig -Mcpu=/Users/mattnite/code/microzig/core/src/cpus/avr5.zig --dep microzig -Mhal=/Users/mattnite/code/microzig/bsp/microchip/avr/src/hals/ATmega328P.zig --dep microzig -Mboard=/Users/mattnite/code/microzig/bsp/microchip/avr/src/boards/arduino_uno.zig --cache-dir /Users/mattnite/code/microzig/zig-cache --global-cache-dir /Users/mattnite/.cache/zig --name arduino-nano_blinky -static -fcompiler-rt --script /Users/mattnite/code/microzig/zig-cache/o/2c186d936508aa71bea517796451c3f9/linker.ld --listen=-
//install
//mq install
// mq install generated to arduino-nano_blinky.hex
// mq objcopy generated
// mq zig build-exe arduino-nano_blinky ReleaseSmall avr-freestanding-eabi 1 errors
///Users/mattnite/zig/0.12.0-dev.3097+5c0766b6c/files/lib/std/debug.zig:403:14: error: reached unreachable code
// if (!ok) unreachable; // assertion failure
// ^~~~~~~~~~~
///Users/mattnite/zig/0.12.0-dev.3097+5c0766b6c/files/lib/std/os/wasi.zig:12:11: note: called from here
// assert(@alignOf(i16) == 2);
// ~~~~~~^~~~~~~~~~~~~~~~~~~~
const example_dep_names: []const []const u8 = &.{
"examples/nordic/nrf5x",
"examples/nxp/lpc",
Expand All @@ -26,7 +11,7 @@ const example_dep_names: []const []const u8 = &.{
"examples/gigadevice/gd32",
"examples/stmicro/stm32",
//"examples/espressif/esp",
//"examples/raspberrypi/rp2040",
"examples/raspberrypi/rp2040",
};

const bsps = .{
Expand Down
112 changes: 112 additions & 0 deletions core/src/core/usb/descriptors.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/// Describes a device. This is the most broad description in USB and is
/// typically the first thing the host asks for.
pub const Device = extern struct {
/// Version of the device descriptor / USB protocol, in binary-coded
/// decimal. This is typically `0x01_10` for USB 1.1.
bcdUSB: u16,
/// Class of device, giving a broad functional area.
bDeviceClass: u8,
/// SubClass of device, refining the class.
bDeviceSubClass: u8,
/// Protocol within the subclass.
bDeviceProtocol: u8,
/// Maximum unit of data this device can move.
bMaxPacketSize0: u8,
/// ID of product vendor.
idVendor: u16,
/// ID of product.
idProduct: u16,
/// Device version number, as BCD again.
bcdDevice: u16,
/// Index of manufacturer name in string descriptor table.
iManufacturer: u8,
/// Index of product name in string descriptor table.
iPRoduct: u8,
/// Index of serial number in string descriptor table.
iSerialNumber: u8,
/// Number of configurations supported by this device.
bNumConfigurations: u8,
};

pub const Interface = extern struct {
bInterfaceNumber: u8,
bAlternateSetting: u8,
bNumEndpoints: u8,
bInterfaceClass: u8,
bInterfaceSubClass: u8,
bInterfaceProtocol: u8,
iInterface: u8,
};

/// Description of a single available device configuration.
pub const Configuration = extern struct {
/// Total length of all descriptors in this configuration, concatenated.
/// This will include this descriptor, plus at least one interface
/// descriptor, plus each interface descriptor's endpoint descriptors.
wTotalLength: u16,
/// Number of interface descriptors in this configuration.
bNumInterfaces: u8,
/// Number to use when requesting this configuration via a
/// `SetConfiguration` request.
bConfigurationValue: u8,
/// Index of this configuration's name in the string descriptor table.
iConfiguration: u8,
/// Bit set of device attributes:
///
/// - Bit 7 should be set (indicates that device can be bus powered in USB
/// 1.0).
/// - Bit 6 indicates that the device can be self-powered.
/// - Bit 5 indicates that the device can signal remote wakeup of the host
/// (like a keyboard).
/// - The rest are reserved and should be zero.
bmAttributes: u8,
/// Maximum device power consumption in units of 2mA.
bMaxPower: u8,
};

pub const InterfaceAssociation = extern struct {
bFirstInterface: u8,
bInterfaceCount: u8,
bFunctionClass: u8,
bFunctionSubClass: u8,
bFunctionProtocol: u8,
iFunction: u8,
};

/// Describes an endpoint within an interface
pub const Endpoint = extern struct {
/// Address of this endpoint, where the bottom 4 bits give the endpoint
/// number (0..15) and the top bit distinguishes IN (1) from OUT (0).
bEndpointAddress: u8,
/// Endpoint attributes; the most relevant part is the bottom 2 bits, which
/// control the transfer type using the values from `TransferType`.
bmAttributes: u8,
/// Maximum packet size this endpoint can accept/produce.
wMaxPacketSize: u16,
/// Interval for polling interrupt/isochronous endpoints (which we don't
/// currently support) in milliseconds.
bInterval: u8,
};

pub const BOS = extern struct {
/// The number of bytes in this descriptor and all of its subordinate
/// descriptors
wTotalLength: u16,
/// The numbre of device capability descriptors subordinate to this BOS
/// descriptor
bNumDeviceCaps: u8,

};

pub const Utf16Le = struct {
bytes: []const u8,
};

/// For string descriptor zero: an array of one or more language identifier
/// codes, for other string descriptors, a unicode UTF-16LE string
pub const String = extern struct {
string_or_lang: union {
bSTRING: Utf16Le,
wLANGID: []const u8,
};
};
1 change: 1 addition & 0 deletions tools/uf2/src/uf2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub const Archive = struct {
var it = header.program_header_iterator(file);
while (try it.next()) |prog_hdr|
if (prog_hdr.p_type == std.elf.PT_LOAD and prog_hdr.p_memsz > 0 and prog_hdr.p_filesz > 0) {
std.log.debug("segment: {}", .{prog_hdr});
try segments.append(.{
.addr = @as(u32, @intCast(prog_hdr.p_paddr)),
.file_offset = @as(u32, @intCast(prog_hdr.p_offset)),
Expand Down

0 comments on commit 01b496d

Please sign in to comment.