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
  baremetal via Zig on PinePhone - JumpDrive help please WhiteHexagon 1 274 07-07-2025, 10:33 AM
Last Post: WhiteHexagon
  Jami on the Pine phone ? bcnaz 8 8,640 06-09-2025, 04:17 PM
Last Post: j_s
  Movuan distribution for PinePhone merom 4 1,044 04-07-2025, 12:32 AM
Last Post: tllim
  How-To: Remote Control Your Phone from Desktop via VNC biketool 6 2,346 03-05-2025, 06:18 AM
Last Post: Kevin Kofler
  Latest firmware for PinePhone modem! Subsentient 105 175,955 02-02-2025, 08:47 PM
Last Post: bacydentir85
  Slarm64 on PinePhone [Unofficial Slackware ARM - 64 bit] acid andy 40 43,417 12-28-2024, 12:19 AM
Last Post: mara
  Office applications for the Pinephone Peter Gamma 2 1,462 09-05-2024, 09:22 AM
Last Post: Peter Gamma
  Struggle to install LibreOffice on the PinePhone Peter Gamma 50 47,337 07-26-2024, 10:35 PM
Last Post: Peter Gamma
  Why does Pine64 sabotage office on the Pinephone? Peter Gamma 5 2,490 07-04-2024, 07:34 AM
Last Post: Kevin Kofler
  Which word processor to choose for the Pinephone? Peter Gamma 16 9,666 06-22-2024, 07:28 AM
Last Post: Peter Gamma

Forum Jump:


Users browsing this thread: 1 Guest(s)