Skip to content

Commit

Permalink
Comptime USB endpoints number (#284)
Browse files Browse the repository at this point in the history
* Comptime USB endpoints number

* Minor fix

---------

Co-authored-by: Arkadiusz Wójcik <[email protected]>
  • Loading branch information
arkadiuszwojcik and Arkadiusz Wójcik authored Nov 22, 2024
1 parent cef5757 commit 9dde50b
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 413 deletions.
4 changes: 2 additions & 2 deletions core/src/core/usb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub fn Usb(comptime f: anytype) type {
var usb_config: ?*DeviceConfiguration = null;
/// The clock has been initialized [Y/n]
var clk_init: bool = false;
var itf_to_drv: [16]u8 = .{0} ** 16;
var ep_to_drv: [4][2]u8 = .{.{0} ** 2} ** 4;
var itf_to_drv: [f.cfg_max_interfaces_count]u8 = .{0} ** f.cfg_max_interfaces_count;
var ep_to_drv: [f.cfg_max_endpoints_count][2]u8 = .{.{0} ** 2} ** f.cfg_max_endpoints_count;

/// The callbacks passed provided by the caller
pub const callbacks = f;
Expand Down
8 changes: 5 additions & 3 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/usb_cdc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const baud_rate = 115200;
const uart_tx_pin = gpio.num(0);
const uart_rx_pin = gpio.num(1);

const usb_dev = rp2xxx.usb.Usb(.{});

const usb_config_len = usb.templates.config_descriptor_len + usb.templates.cdc_descriptor_len;
const usb_config_descriptor =
usb.templates.config_descriptor(1, 2, 0, usb_config_len, 0xc0, 100) ++
Expand Down Expand Up @@ -78,17 +80,17 @@ pub fn main() !void {
rp2xxx.uart.init_logger(uart);

// First we initialize the USB clock
rp2xxx.usb.Usb.init_clk();
usb_dev.init_clk();
// Then initialize the USB device using the configuration defined above
rp2xxx.usb.Usb.init_device(&DEVICE_CONFIGURATION) catch unreachable;
usb_dev.init_device(&DEVICE_CONFIGURATION) catch unreachable;
var old: u64 = time.get_time_since_boot().to_us();
var new: u64 = 0;

var i: u32 = 0;
var buf: [1024]u8 = undefined;
while (true) {
// You can now poll for USB events
rp2xxx.usb.Usb.task(
usb_dev.task(
false, // debug output over UART [Y/n]
) catch unreachable;

Expand Down
8 changes: 5 additions & 3 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const baud_rate = 115200;
const uart_tx_pin = gpio.num(0);
const uart_rx_pin = gpio.num(1);

const usb_dev = rp2xxx.usb.Usb(.{});

const usb_packet_size = 64;
const usb_config_len = usb.templates.config_descriptor_len + usb.templates.hid_in_out_descriptor_len;
const usb_config_descriptor =
Expand Down Expand Up @@ -80,14 +82,14 @@ pub fn main() !void {
rp2xxx.uart.init_logger(uart);

// First we initialize the USB clock
rp2xxx.usb.Usb.init_clk();
usb_dev.init_clk();
// Then initialize the USB device using the configuration defined above
rp2xxx.usb.Usb.init_device(&DEVICE_CONFIGURATION) catch unreachable;
usb_dev.init_device(&DEVICE_CONFIGURATION) catch unreachable;
var old: u64 = time.get_time_since_boot().to_us();
var new: u64 = 0;
while (true) {
// You can now poll for USB events
rp2xxx.usb.Usb.task(
usb_dev.task(
false, // debug output over UART [Y/n]
) catch unreachable;

Expand Down
Loading

0 comments on commit 9dde50b

Please sign in to comment.