Article: NuttX RTOS for PinePhone: Feature Phone UI in LVGL, Zig and WebAssembly
#44
Code:
pub const I2S_PCM0 = IRQ(45);
pub const I2S_PCM1 = IRQ(46);
pub const I2S_PCM2 = IRQ(47);
pub const PG_EINT = IRQ(49);
pub const TIMER0 = IRQ(50);
pub const TIMER1 = IRQ(51);

fn IRQ(comptime irq: u8) type {
    const cache = struct {
        var lookup: [IRQ_LIMIT]*const fn () void = undefined;

        pub export fn zigInterruptHandler(id: c_int) void {
            const handler = lookup[@intCast(u8, id)];
            handler();
            debug.green(true);
        }
    };
    return struct {
        const irqNo: u8 = irq;
        var enabled: bool = false;

        pub fn enable(handler: *const fn () void) void {
            if (!enabled) {
                c.enableIRQ(irqNo);
                cache.lookup[irqNo] = handler;
                enabled = true;
            }
        }
    };
}

Oh and the code if you are interested.  It works if I move the exported fn and lookup table up to the file level, but since that is also just a 'struct' in Zig, I thought this might work.
  Reply


Messages In This Thread
RE: Article: NuttX RTOS for PinePhone: Feature Phone UI in LVGL, Zig and WebAssembly - by WhiteHexagon - 07-31-2023, 04:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Movuan distribution for PinePhone merom 4 710 04-07-2025, 12:32 AM
Last Post: tllim
  How-To: Remote Control Your Phone from Desktop via VNC biketool 6 1,783 03-05-2025, 06:18 AM
Last Post: Kevin Kofler
  Latest firmware for PinePhone modem! Subsentient 105 168,960 02-02-2025, 08:47 PM
Last Post: bacydentir85
  Slarm64 on PinePhone [Unofficial Slackware ARM - 64 bit] acid andy 40 40,791 12-28-2024, 12:19 AM
Last Post: mara
  Office applications for the Pinephone Peter Gamma 2 1,214 09-05-2024, 09:22 AM
Last Post: Peter Gamma
  Struggle to install LibreOffice on the PinePhone Peter Gamma 50 44,150 07-26-2024, 10:35 PM
Last Post: Peter Gamma
  Why does Pine64 sabotage office on the Pinephone? Peter Gamma 5 2,158 07-04-2024, 07:34 AM
Last Post: Kevin Kofler
  Which word processor to choose for the Pinephone? Peter Gamma 16 8,488 06-22-2024, 07:28 AM
Last Post: Peter Gamma
  Samba share on the Pinephone? Peter Gamma 0 1,017 06-16-2024, 10:26 PM
Last Post: Peter Gamma
  Possible Free Backup Carrier for PinePhone PineFone 0 944 06-13-2024, 03:45 PM
Last Post: PineFone

Forum Jump:


Users browsing this thread: 2 Guest(s)